From: Stefan Schantl Date: Thu, 27 Sep 2012 17:43:03 +0000 (+0000) Subject: Add class to handle SOA records and parse the content. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abccf64a9398c6711bc243bdb2e92278d4678305;p=people%2Fstevee%2Fpypdns.git Add class to handle SOA records and parse the content. --- diff --git a/backend.py b/backend.py index 9f9e85b..4acdd20 100644 --- a/backend.py +++ b/backend.py @@ -105,12 +105,32 @@ class Domain(object): records = [] """Fetch all records from domain, line by line and add them to the previous created empty list.""" - for row in self.db.query("SELECT id FROM records WHERE domain_id = ?", self.id): - record = Record(self, row.id) + for row in self.db.query("SELECT id, type FROM records WHERE domain_id = ?", self.id): + if row.type == "SOA": + record = SOARecord(self, row.id) + elif row.type == "A": + record = ARecord(self, row.id) + else: + record = Record(self, row.id) records.append(record) return records + # Get records by a specified type. + def get_records_by_type(self, type): + records = [] + for record in self.records: + if record.type == type: + records.append(record) + + return records + + # Quick function to get the first SOA record from the domain. + @property + def SOA(self): + records = self.get_records_by_type("SOA") + if records: + return records[0] # Create class for domain records. @@ -169,8 +189,63 @@ class Record(object): row = self.db.get("SELECT ordername FROM records WHERE id = ?" , self.id) return row.ordername - # Gain all information about records authification. + # Gain all information about records authentication. @property - def authification(self): + def authentication(self): row = self.db.get("SELECT auth FROM records WHERE id = ?" , self.id) return row.auth + + +# Create an own class to deal with "SOA" records. +"""Use splitt() to generate a list of the original content string from the database, and return the requested entries.""" +class SOARecord(Record): + def __init__(self, domain, record_id): + Record.__init__(self, domain, record_id) + + self.soa_attrs = self.content.split() + + # Check if the content from database is valid (It contains all 7 required information). + if not len(self.soa_attrs) == 7: + #XXX Add something like an error message or log output. + pass + + # Primary NS - the domain name of the name server that was the original source of the data. + @property + def mname(self): + return self.soa_attrs[0] + + # E-mail address of the person which is responsible for this domain. + @property + def email(self): + return self.soa_attrs[1] + + # The serial which increases allways after a change on the domain has been made. + @property + def serial(self): + return self.soa_attrs[2] + + # The number of seconds between the time that a secondary name server gets a copy of the domain. + @property + def refresh(self): + return self.soa_attrs[3] + + # The number of seconds during the next refresh attempt if the previous fails. + @property + def retry(self): + return self.soa_attrs[4] + + # The number of seconds that lets the secondary name server(s) know how long they can hold the information. + @property + def expire(self): + return self.soa_attrs[5] + + # The number of seconds that the records in the domain are valid. + @property + def minimum(self): + return self.soa_attrs[6] + + + +class ARecord(Record): + pass +