You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

13 years ago
# See #A
# = IPv4 Address Record (A)
#
# Defined in RFC 1035. Forward maps a host name to IPv4 address. The only
# parameter is an IP address in dotted decimal format. The IP address in not
# terminated with a '.' (dot). Valid host name format (a.k.a 'label' in DNS
# jargon). If host name is BLANK (or space) then the last valid name (or label)
# is substituted.
#
# Obtained from http://www.zytrax.com/books/dns/ch8/a.html
#
class A < Record
has_paper_trail ignore: [:content, :updated_at]
validates :name, :hostname => {:allow_underscore => true, :allow_wildcard_hostname => true}
validates :content, :presence => true, :ip => {:ip_type => :v4} # Only accept valid IPv4 addresses
13 years ago
13 years ago
attr_accessor :host_domain
13 years ago
validates :host_domain, :inclusion => {:in => Settings.host_domains}, :allow_blank => true
validates :name,
:length => {:minimum => 4},
:uniqueness => {:scope => [:domain_id, :type]},
:if => :host?
validate do
13 years ago
if host? && Settings.protected_hostnames.any? {|hn| name =~ /^#{hn}/i}
errors[:name] << "cannot be used, please try another"
end
end
13 years ago
before_validation do
if host_domain.present? && Settings.host_domains.include?(host_domain)
self.domain_id = Domain.find_by_name(host_domain).try(:id)
end
end
13 years ago
def host?; domain.present? && Settings.host_domains.include?(domain.name) end
13 years ago
end