From 21b30636a8f0b511978510ad8298a305efe8581b Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Tue, 25 Oct 2011 11:14:57 -0700 Subject: [PATCH] true ownership --- app/models/domain.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/domain.rb b/app/models/domain.rb index 38aeea6..156f817 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -1,3 +1,5 @@ +require 'resolv' + class Domain < ActiveRecord::Base set_inheritance_column "sti_disabled" nilify_blanks @@ -42,6 +44,16 @@ class Domain < ActiveRecord::Base errors.add :base, "as a security measure, you cannot have more than #{max} domains on one account" end end + + validate :domain_ownership, :on => :create + def domain_ownership # at least one NS is among ours + Resolv::DNS.open do |dns| + ress = dns.getresources name, Resolv::DNS::Resource::IN::NS + if (Settings.ns & ress.map{|r| r.name.to_s}).blank? + errors.add :base, "You must delegate #{name} to one of our NS servers before adding it" + end + end + end def slave?; self.type == 'SLAVE' end