Created
August 2, 2011 09:32
-
-
Save fbettag/1119890 to your computer and use it in GitHub Desktop.
DNS Zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DnsRecord | |
include DataMapper::Resource | |
# property <name>, <type> | |
property :id, Serial | |
property :name, String, :required => false, :length => 255, | |
:index => [:name, :name_active_zone, :name_active_rtype_zone] | |
property :type, String, :required => true, :default => 'a', :length => 10, | |
:index => [:name_active_rtype_zone] | |
property :content, String, :required => true, :length => 255 | |
property :prio, Integer | |
property :ttl, Integer | |
property :active, Boolean, :required => true, :default => true, | |
:index => [:name_active_zone, :name_active_rtype_zone] | |
belongs_to :customer, :required => false | |
belongs_to :dns_zone #, :index => [:name_active_zone, :name_active_rtype_zone] | |
before :valid?, :cleanup | |
before :save, :cleanup | |
def cleanup | |
self.prio = nil if self.prio == "" | |
self.ttl = nil if self.ttl == "" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DnsZone | |
include DataMapper::Resource | |
# property <name>, <type> | |
property :id, Serial | |
property :name, String, :required => true, :length => 255 | |
property :mail, String, :required => true, :default => '[email protected]', :length => 255 | |
property :ttl, Integer, :required => true, :default => 86400 | |
property :serial, Integer, :required => true, :default => lambda { DateTime.now.strftime("%Y%m%d00").to_i } | |
property :refresh, Integer, :required => true, :default => 10800 | |
property :retry, Integer, :required => true, :default => 3600 | |
property :expire, Integer, :required => true, :default => 604800 | |
property :minimum, Integer, :required => true, :default => 3600 | |
property :active, Boolean, :required => true, :default => true | |
belongs_to :customer | |
has n, :dns_records | |
def generate_serial | |
today = Time.now.strftime('%Y%m%d') | |
self.serial = (self.serial.to_s[0..7] == today ? self.serial += 1 : today + '00') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW domains AS | |
SELECT dns_zones.id, dns_zones.name, NULL::character varying AS master, NULL::integer AS last_check, 'NATIVE'::character varying AS type, NULL::integer AS notified_serial, dns_zones.customer_id AS account FROM dns_zones; | |
CREATE VIEW records AS | |
SELECT dns_records.id, dns_records.name, dns_records.content, dns_records.ttl, dns_records.prio, dns_records.type, NULL::integer AS change_date, dns_records.dns_zone_id AS domain_id FROM dns_records; | |
ALTER TABLE public.domains OWNER TO pdns; | |
ALTER TABLE public.records OWNER TO pdns; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment