Browse Source

more permisive domain names

pull/1/head
Nicolae Claudius 10 years ago
parent
commit
62adf6a0c0
  1. 2
      app/models/a.rb
  2. 2
      app/models/aaaa.rb
  3. 2
      app/models/cname.rb
  4. 10
      app/models/mx.rb
  5. 4
      app/models/ns.rb
  6. 2
      app/models/soa.rb
  7. 7
      app/models/srv.rb
  8. 2
      app/models/txt.rb
  9. 13
      app/validators/hostname2_validator.rb

2
app/models/a.rb

@ -13,7 +13,7 @@
class A < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :presence => true, :ip => {:ip_type => :v4} # Only accept valid IPv4 addresses
attr_accessor :host_domain

2
app/models/aaaa.rb

@ -8,7 +8,7 @@
class AAAA < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :presence => true, :ip => {:ip_type => :v6}
end

2
app/models/cname.rb

@ -10,7 +10,7 @@
class CNAME < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :presence => true, :length => { :maximum => 20000 }, :hostname2 => true
end

10
app/models/mx.rb

@ -9,14 +9,8 @@
class MX < Record
has_paper_trail
validates :name, :hostname => {
:allow_underscore => true,
:allow_wildcard_hostname => true
}
validates :content, :presence => true, :hostname => {
:allow_underscore => true,
:allow_wildcard_hostname => true
}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :presence => true, :hostname2 => {:allow_wildcard_hostname => true}
validates :prio, :presence => true, :numericality => {
:greater_than_or_equal_to => 0,
:less_than_or_equal_to => 65535,

4
app/models/ns.rb

@ -22,8 +22,8 @@
class NS < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true}
validates :content, :presence => true, :hostname => true #, :inclusion => {:in => Settings.ns}
validates :name, :hostname2 => true
validates :content, :presence => true, :hostname2 => true #, :inclusion => {:in => Settings.ns}
def to_label; "#{content}" end
end

2
app/models/soa.rb

@ -11,7 +11,7 @@ class SOA < Record
validates :domain, :presence => true
validates :domain_id, :uniqueness => true # one SOA per domain
validates :name, :presence => true, :hostname => true
validates :name, :presence => true, :hostname2 => true
validate :name_equals_domain_name
validates :content, :presence => true
validates :primary_ns, :presence => true

7
app/models/srv.rb

@ -7,7 +7,7 @@
class SRV < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :format => /\A\d+ \d+ [A-Za-z0-9\-_.]+\z/
# RFC 2872
validates :prio, :presence => true, :numericality => {
@ -25,10 +25,7 @@ class SRV < Record
:less_than_or_equal_to => 65535,
:only_integer => true
}
validates :host, :presence => true, :hostname => {
:allow_underscore => true,
:allow_wildcard_hostname => true
}
validates :host, :presence => true, :hostname2 => {:allow_wildcard_hostname => true}
attr_accessor :weight, :port, :host

2
app/models/txt.rb

@ -11,7 +11,7 @@
class TXT < Record
has_paper_trail
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :name, :hostname2 => {:allow_wildcard_hostname => true}
validates :content, :presence => true, :length => { :maximum => 255 }
def to_label; type end

13
app/validators/hostname2_validator.rb

@ -1,6 +1,17 @@
# skips length validations
# skips length validations, more permissive defaults
class Hostname2Validator < PAK::ValidatesHostname::HostnameValidator
def initialize(options)
opts = {
:allow_underscore => true,
:require_valid_tld => false,
:valid_tlds => ALLOWED_TLDS,
:allow_numeric_hostname => true,
:allow_wildcard_hostname => false
}.merge(options)
super(opts)
end
def validate_each(record, attribute, value)
value ||= ''

Loading…
Cancel
Save