Ejemplo n.º 1
0
def _is_record_valid(name, irecord, rec_list):
    # maybe do other sanity checking here
    if not rec_list:
        return (True, "New hostname")
    type_ = mapper.get_typestring(irecord)
    # if current rec is CNAME or NS check for root name
    if not name and type_ in ('CNAME', 'NS'):
        return (False, "Root hostname not allowed in this zone")
    # if current rec is CNAME, can't clash
    if rec_list and type_ == 'CNAME':
        return (False, "CNAME can't use existing hostname")
    # check for existing CNAME
    sub_rec_list = [
        rec for rec in rec_list if mapper.get_typestring(rec) == 'CNAME'
    ]
    if sub_rec_list:
        return (False, "CNAME already exists with this hostname")
    match_rec_list = [rec for rec in rec_list if rec.TYPE == irecord.TYPE]
    # if matching records of same type, check TTL
    if match_rec_list and match_rec_list[0].ttl != irecord.ttl:
        return (False,
                "TTL is different from existing entry for this hostname")
    log.msg("checking for uniqueness")
    # if hostname matches, check that unique attrs differ
    for rec in match_rec_list:
        match_attr = mapper.unique_attr_map[type_]
        if getattr(rec, match_attr) == getattr(irecord, match_attr):
            return (False,
                    "%s already exists for this host with same information" %
                    type_)
    return (True, "OK")
Ejemplo n.º 2
0
def _is_record_valid(name, irecord, rec_list):
    # maybe do other sanity checking here
    if not rec_list:
        return (True, "New hostname")
    type_ = mapper.get_typestring(irecord)
    # if current rec is CNAME or NS check for root name
    if not name and type_ in ('CNAME', 'NS'):
        return (False, "Root hostname not allowed in this zone")
    # if current rec is CNAME, can't clash
    if rec_list and type_ == 'CNAME':
        return (False, "CNAME can't use existing hostname")
    # check for existing CNAME
    sub_rec_list = [rec for rec in rec_list if mapper.get_typestring(rec) == 'CNAME']
    if sub_rec_list:
        return (False, "CNAME already exists with this hostname")
    match_rec_list = [rec for rec in rec_list if rec.TYPE == irecord.TYPE]
    # if matching records of same type, check TTL
    if match_rec_list and match_rec_list[0].ttl != irecord.ttl:
        return (False, "TTL is different from existing entry for this hostname")
    log.msg("checking for uniqueness")
    # if hostname matches, check that unique attrs differ
    for rec in match_rec_list:
        match_attr = mapper.unique_attr_map[type_]
        if getattr(rec,match_attr) == getattr(irecord,match_attr):
            return (False, "%s already exists for this host with same information" % type_)
    return (True, "OK")
Ejemplo n.º 3
0
 def get_record_details(self, name, record):
     details = (mapper.get_typestring(record),
                name,
                mapper.get_values(record)
                )
     log.msg("Retreived Record: %s %s %s" % details)
     return details
Ejemplo n.º 4
0
 def get_record_details(self, name, record):
     details = (mapper.get_typestring(record),
                name,
                mapper.get_values(record)
                )
     log.msg("Retreived Record: %s %s %s" % details)
     return details
Ejemplo n.º 5
0
 def get_records_by_type(self, type_):
     data = []
     for k, v in self.records.items():
         data.extend([
             self.get_record_details(k, item) for item in v
             if mapper.get_typestring(item) == type_
         ])
     return data
Ejemplo n.º 6
0
 def save(self):
     if self.savefile is None: return
     # needs to be list, as can have multiple As for same host/sub, e.g.
     data = []
     # record type encodes itself as in mapper
     for name, rec_items in self.records.items():
         name = _getsubdomain(name, self.domain.lower())
         for irecord in rec_items:
             type_ = mapper.get_typestring(irecord)
             values = mapper.get_attrs(irecord)
             values['type'] = type_
             if values:
                 data.append({name: values})
     # only save if data exists
     if data:
         f = open(self.savefile + ".tmp", "w")
         json.dump(data, f)
         f.close()
         os.rename(self.savefile + ".tmp", self.savefile)
Ejemplo n.º 7
0
 def save(self):
     if self.savefile is None: return
     # needs to be list, as can have multiple As for same host/sub, e.g.
     data = []
     # record type encodes itself as in mapper
     for name, rec_items in self.records.items():
         name = _getsubdomain(name, self.domain.lower())
         for irecord in rec_items:
             type_ = mapper.get_typestring(irecord)
             values = mapper.get_attrs(irecord)
             values['type'] = type_
             if values:
                 data.append({name: values})
     # only save if data exists
     if data:
         f = open(self.savefile + ".tmp", "w")
         json.dump(data, f)
         f.close()
         os.rename(self.savefile + ".tmp", self.savefile)
Ejemplo n.º 8
0
 def get_records_by_type(self, type_):
     data = []
     for k,v in self.records.items():
         data.extend([self.get_record_details(k, item) for item in v if mapper.get_typestring(item)== type_])
     return data