diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb index 2ec5238..5b5fada 100644 --- a/app/controllers/domains_controller.rb +++ b/app/controllers/domains_controller.rb @@ -5,7 +5,7 @@ class DomainsController < ApplicationController conf.list.columns = [:name, :soa_record, :ns_records, :records] conf.create.columns = [:name, :soa_record, :ns_records] conf.update.columns = [:name, :soa_record, :ns_records] - conf.columns[:name].description = 'yourdomain.com' + conf.columns[:name].description = 'domain.com' conf.columns[:ns_records].show_blank_record = false conf.actions.exclude :show conf.list.sorting = { :name => :asc } @@ -18,8 +18,7 @@ class DomainsController < ApplicationController def do_new super - session[:sample_ns] = nil - @record.setup(current_user.email, sample_ns) + @record.setup(current_user.email) end def before_create_save(record) @@ -27,12 +26,7 @@ class DomainsController < ApplicationController end def after_create_save(record) - session[:sample_ns] = nil @record.reload end - - def sample_ns - session[:sample_ns] ||= Settings.ns.sample(2) - end end diff --git a/app/controllers/mxes_controller.rb b/app/controllers/mxes_controller.rb index 73e2d7a..7616700 100644 --- a/app/controllers/mxes_controller.rb +++ b/app/controllers/mxes_controller.rb @@ -1,10 +1,10 @@ class MxesController < ApplicationController active_scaffold :mx do |conf| conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date] - conf.create.columns = [:name, :content, :ttl, :prio] - conf.update.columns = [:name, :content, :ttl, :prio] + conf.create.columns = [:content, :ttl, :prio] + conf.update.columns = [:content, :ttl, :prio] conf.columns[:content].label = 'MX' - conf.columns[:name].description = 'Ex: mail or mx etc' + conf.columns[:content].description = 'Ex. mail.domain.com' conf.columns[:change_date].list_ui = :timestamp conf.actions.exclude :show end diff --git a/app/models/domain.rb b/app/models/domain.rb index c3b7abf..a4c5125 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -28,7 +28,7 @@ class Domain < ActiveRecord::Base def slave?; self.type == 'SLAVE' end - def setup(email, sample_ns) + def setup(email) build_soa_record soa = soa_record soa.contact ||= email @@ -36,7 +36,7 @@ class Domain < ActiveRecord::Base ns_records.build ns_records.build ns1, ns2 = ns_records - ns1.content = sample_ns.first - ns2.content = sample_ns.second + ns1.content = Settings.ns.first + ns2.content = (Settings.ns - [ns1.content]).sample end end diff --git a/app/models/ns.rb b/app/models/ns.rb index 8b1f83f..88858f8 100644 --- a/app/models/ns.rb +++ b/app/models/ns.rb @@ -20,10 +20,9 @@ # Obtained from http://www.zytrax.com/books/dns/ch8/ns.html # class NS < Record - validates :content, :presence => true, :hostname => true + validates :content, :presence => true, :hostname => true, :inclusion => {:in => Settings.ns} def to_label; "#{content}" end - end Ns = NS diff --git a/app/models/record.rb b/app/models/record.rb index bea2c6a..c66e56f 100644 --- a/app/models/record.rb +++ b/app/models/record.rb @@ -6,6 +6,7 @@ class Record < ActiveRecord::Base validates :domain, :name, :presence => true validates :type, :inclusion => {:in => @@types, :message => "Unknown record type"} + validates :content, :uniqueness => {:scope => [:domain_id, :type]} # RFC 2181, 8 validates :ttl, :numericality => { # :greater_than_or_equal_to => 0,