mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Merge branch 'master' of github.com:internetee/registry
Conflicts: db/schema.rb
This commit is contained in:
commit
907ef1edf7
33 changed files with 629 additions and 288 deletions
2
app/models/cached_nameserver.rb
Normal file
2
app/models/cached_nameserver.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class CachedNameserver < ActiveRecord::Base
|
||||
end
|
|
@ -2,4 +2,10 @@ class Country < ActiveRecord::Base
|
|||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
class << self
|
||||
def estonia
|
||||
find_by(iso: 'EE')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -306,35 +306,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def generate_zonefile
|
||||
zf = Zonefile.new
|
||||
zf.ttl = '3600'
|
||||
zf.origin = "#{name}."
|
||||
ns = nameservers.first
|
||||
zf.soa[:primary_ns] = "#{ns.hostname}."
|
||||
zf.soa[:email] = 'hostmaster.internet.ee'
|
||||
zf.soa[:origin] = "#{name}."
|
||||
zf.soa[:refresh] = '10800'
|
||||
zf.soa[:retry] = '3600'
|
||||
zf.soa[:expire] = '604800'
|
||||
zf.soa[:minimumTTL] = '3600'
|
||||
|
||||
nameservers.each do |x|
|
||||
zf.ns << { name: "#{name}.", class: 'IN', host: "#{x.hostname}." }
|
||||
end
|
||||
|
||||
dnskeys.each do |x|
|
||||
zf.ds << { name: "#{name}.", ttl: '86400', class: 'IN', key_tag: x.ds_key_tag, algorithm: x.ds_alg,
|
||||
digest_type: x.ds_digest_type, digest: x.ds_digest }
|
||||
|
||||
zf.dnskey << { name: "#{name}.", ttl: '86400', class: 'IN', flag: x.flags,
|
||||
protocol: x.protocol, algorithm: x.alg, public_key: x.public_key }
|
||||
end
|
||||
|
||||
zf.new_serial
|
||||
zf.generate
|
||||
end
|
||||
|
||||
class << self
|
||||
def convert_period_to_time(period, unit)
|
||||
return period.to_i.days if unit == 'd'
|
||||
|
|
|
@ -10,6 +10,10 @@ class Nameserver < ActiveRecord::Base
|
|||
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
||||
# rubocop: enable Metrics/LineLength
|
||||
|
||||
# caching
|
||||
after_commit :clear_cache
|
||||
after_commit :create_cache, on: [:create, :update]
|
||||
|
||||
# archiving
|
||||
has_paper_trail class_name: 'NameserverVersion'
|
||||
after_destroy :domain_version
|
||||
|
@ -52,6 +56,16 @@ class Nameserver < ActiveRecord::Base
|
|||
domain.create_version if domain
|
||||
end
|
||||
|
||||
def create_cache
|
||||
CachedNameserver.create(snapshot)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
logger.info('Nameserver already exists in cache; not caching')
|
||||
end
|
||||
|
||||
def clear_cache
|
||||
CachedNameserver.find_by(snapshot).try(:delete)
|
||||
end
|
||||
|
||||
def to_s
|
||||
hostname
|
||||
end
|
||||
|
|
7
app/models/zonefile_setting.rb
Normal file
7
app/models/zonefile_setting.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class ZonefileSetting < ActiveRecord::Base
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
def to_s
|
||||
origin
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue