Exemple #1
0
  def Delete(self, _parentWin, names, types):
    node=self.lastNode
    updater=node.Updater()
    for i in range(len(names)):
      if isinstance(types, list):
        type=types[i]
      else:
        type=types
      updater.delete(names[i], type)

    msg=node.GetServer().Send(updater)
    if msg.rcode() != rcode.NOERROR:
      self.SetStatus(xlt("DNS delete failed: %s") % rcode.to_text(msg.rcode()))
      return False
    for i in range(len(names)):
      name=names[i]
      if isinstance(types, list):
        rdtype=rdatatype.from_text(types[i])
        rdsl=node.others.get(name)
        if rdsl:
          if rdtype in rdsl:
            del rdsl[rdtype]
      elif types == rdatatype.CNAME:
        if node.cnames.get(name):
          del node.cnames[name]
      elif types == rdatatype.PTR:  
        if node.ptrs.get(name):
          del node.ptrs[name]
    return True
Exemple #2
0
 def _save(self, rds):
   updater=self.node.Updater()
   if self.rdtype == rdatatype.SOA:
     updater.replace(self.RecordName, rds)
   elif self.rdtype == rdatatype.NS:
     targets=[]
     for rd in self.rds:
       targets.append(rd.target)
     for rd in rds:
       if rd.target in targets:
         targets.remove(rd.target)
     for target in targets:
       updater.delete(self.RecordName, self.rdtype, target.to_text())
     updater.add(self.RecordName, rds)
   else:
     if self.rds:
       updater.delete(self.Recordname, self.rdtype)
     updater.add(self.Recordname, rds)
   msg=self.node.GetServer().Send(updater)
   if msg.rcode() == rcode.NOERROR:
     self.page.SetRdata(self.RecordName, self.rdtype, rds)
     self.page.Display(None, False)
     return True
   else:
     self.SetStatus(xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
     return False
Exemple #3
0
 def _save(self, rds):
     updater = self.node.Updater()
     if self.rdtype == rdatatype.SOA:
         updater.replace(self.RecordName, rds)
     elif self.rdtype == rdatatype.NS:
         targets = []
         for rd in self.rds:
             targets.append(rd.target)
         for rd in rds:
             if rd.target in targets:
                 targets.remove(rd.target)
         for target in targets:
             updater.delete(self.RecordName, self.rdtype, target.to_text())
         updater.add(self.RecordName, rds)
     else:
         if self.rds:
             updater.delete(self.Recordname, self.rdtype)
         updater.add(self.Recordname, rds)
     msg = self.node.GetServer().Send(updater)
     if msg.rcode() == rcode.NOERROR:
         self.page.SetRdata(self.RecordName, self.rdtype, rds)
         self.page.Display(None, False)
         return True
     else:
         self.SetStatus(
             xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
         return False
Exemple #4
0
    def Delete(self, _parentWin, names, types):
        node = self.lastNode
        updater = node.Updater()
        for i in range(len(names)):
            if isinstance(types, list):
                type = types[i]
            else:
                type = types
            updater.delete(names[i], type)

        msg = node.GetServer().Send(updater)
        if msg.rcode() != rcode.NOERROR:
            self.SetStatus(
                xlt("DNS delete failed: %s") % rcode.to_text(msg.rcode()))
            return False
        for i in range(len(names)):
            name = names[i]
            if isinstance(types, list):
                rdtype = rdatatype.from_text(types[i])
                rdsl = node.others.get(name)
                if rdsl:
                    if rdtype in rdsl:
                        del rdsl[rdtype]
            elif types == rdatatype.CNAME:
                if node.cnames.get(name):
                    del node.cnames[name]
            elif types == rdatatype.PTR:
                if node.ptrs.get(name):
                    del node.ptrs[name]
        return True
Exemple #5
0
    def OnExecute(parentWin, node):
        candidates = []

        for name in node.ptrs.keys():
            try:
                address = DnsRevAddress(DnsAbsName(name, node.partialZonename))
                target = node.ptrs[name][0].target
                if checkIpAddress(address) == 4:
                    rdtype = rdatatype.A
                else:
                    rdtype = rdatatype.AAAA
                rrset = node.GetConnection().Query(target, rdtype)
                if not rrset:
                    candidates.append("%s %s" % (name, target))
            except:
                candidates.append("%s <invalid>" % name)

        if candidates:
            dlg = wx.MultiChoiceDialog(
                parentWin, xlt("Select PTR records to clean"),
                xlt("%d dangling PTR records") % len(candidates), candidates)
            cleaned = []
            if not dlg.ShowModal() == wx.ID_OK:
                return False
            for i in dlg.GetSelections():
                name = candidates[i].split(' ')[0]
                cleaned.append(name)
                updater = node.Updater()
                updater.delete(DnsAbsName(name, node.partialZonename),
                               rdatatype.PTR)
                msg = node.GetServer().Send(updater)
                if msg.rcode() == rcode.NOERROR:
                    del node.ptrs[name]
                else:
                    parentWin.SetStatus(
                        xlt("DNS update failed: %s") %
                        rcode.to_text(msg.rcode()))
                    return False
                parentWin.SetStatus(
                    xlt("%d dangling PTR records cleaned (%s)") %
                    (len(cleaned), ", ".join(cleaned)))
            return True

        else:
            wx.MessageBox(xlt("No dangling PTR record."), xlt("DNS Cleanup"))

        return True
Exemple #6
0
  def OnExecute(_parentWin, node):
    now=time.localtime(time.time())
    new=((now.tm_year*100 + now.tm_mon)*100 + now.tm_mday) *100
    if node.soa[0].serial < new:
      node.soa[0].serial = new
    else:
      node.soa[0].serial += 1

    updater=node.Updater()
    updater.replace("@", node.soa)

    msg=node.GetServer().Send(updater)
    if msg.rcode() == rcode.NOERROR:
      wx.MessageBox(xlt("Incremented SOA serial number to %d") % node.soa[0].serial, xlt("New SOA serial number"))
    else:
      adm.SetStatus(xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
      
    return True
Exemple #7
0
 def Delete(self, _parentWin, names, _types):
   node=self.lastNode
   updater=node.Updater()
   for name in names:
     if name in node.hosts4:
       updater.delete(name, "A")
     if name in node.hosts6:
       updater.delete(name, "AAAA")
   msg=node.GetServer().Send(updater)
   if msg.rcode() != rcode.NOERROR:
     adm.SetStatus(xlt("DNS delete failed: %s") % rcode.to_text(msg.rcode()))
     return False
   for name in names:
     if name in node.hosts4:
       del node.hosts4[name]
     if name in node.hosts6:
       del node.hosts6[name]
   return True
Exemple #8
0
 def Delete(self, _parentWin, names, _types):
     node = self.lastNode
     updater = node.Updater()
     for name in names:
         if name in node.hosts4:
             updater.delete(name, "A")
         if name in node.hosts6:
             updater.delete(name, "AAAA")
     msg = node.GetServer().Send(updater)
     if msg.rcode() != rcode.NOERROR:
         adm.SetStatus(
             xlt("DNS delete failed: %s") % rcode.to_text(msg.rcode()))
         return False
     for name in names:
         if name in node.hosts4:
             del node.hosts4[name]
         if name in node.hosts6:
             del node.hosts6[name]
     return True
Exemple #9
0
  def OnExecute(parentWin, node):
    candidates=[]

    for name in node.ptrs.keys():
      try:
        address=DnsRevAddress(DnsAbsName(name, node.partialZonename))
        target=node.ptrs[name][0].target
        if checkIpAddress(address) == 4:
          rdtype=rdatatype.A
        else:
          rdtype=rdatatype.AAAA
        rrset=node.GetConnection().Query(target, rdtype)
        if not rrset:
          candidates.append("%s %s" % (name, target))
      except:
        candidates.append("%s <invalid>" % name)

    if candidates:
      dlg=wx.MultiChoiceDialog(parentWin, xlt("Select PTR records to clean"), xlt("%d dangling PTR records") % len(candidates), candidates)
      cleaned=[]
      if not dlg.ShowModal() == wx.ID_OK:
        return False
      for i in dlg.GetSelections():
        name=candidates[i].split(' ')[0]
        cleaned.append(name)
        updater=node.Updater()
        updater.delete(DnsAbsName(name, node.partialZonename), rdatatype.PTR)
        msg=node.GetServer().Send(updater)
        if msg.rcode() == rcode.NOERROR:
          del node.ptrs[name]
        else:
          parentWin.SetStatus(xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
          return False
        parentWin.SetStatus(xlt("%d dangling PTR records cleaned (%s)") % (len(cleaned), ", ".join(cleaned)))
      return True
    
    else:
      wx.MessageBox(xlt("No dangling PTR record."), xlt("DNS Cleanup"))
    

    return True
Exemple #10
0
    def OnExecute(_parentWin, node):
        now = time.localtime(time.time())
        new = ((now.tm_year * 100 + now.tm_mon) * 100 + now.tm_mday) * 100
        if node.soa[0].serial < new:
            node.soa[0].serial = new
        else:
            node.soa[0].serial += 1

        updater = node.Updater()
        updater.replace("@", node.soa)

        msg = node.GetServer().Send(updater)
        if msg.rcode() == rcode.NOERROR:
            wx.MessageBox(
                xlt("Incremented SOA serial number to %d") %
                node.soa[0].serial, xlt("New SOA serial number"))
        else:
            adm.SetStatus(
                xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))

        return True
Exemple #11
0
  def Save(self):
    ttl4=int(timeToFloat(self.TTL))
    if self.ttl6:
      ttl6=int(timeToFloat(self.TTL6))
    else:
      ttl6=ttl4
    name=str(self.Hostname)
    updater=self.node.Updater()
    if self.node.hosts4.get(name):
      updater.delete(name, "A")
    if self.node.hosts4.get(name):
      updater.delete(name, "AAAA")
    
    h4=None
    h6=None
    addresses=self.IpAddress.splitlines()
    for address in addresses:
      address=address.strip()
      if not address:
        continue
      if checkIpAddress(address) == 4:
        if h4:
          h4.add(Rdata(h4, address), ttl4)
        else:
          h4=Rdataset(ttl4, rdataclass.IN, rdatatype.A, address)
      else:
        if h6:
          h6.add(Rdata(h6, address), ttl6)
        else:
          h6=Rdataset(ttl6, rdataclass.IN, rdatatype.AAAA, address)
      
    if h4:
      updater.add(name, h4)
    if h6:
      updater.add(name, h6)
    msg=self.node.GetServer().Send(updater)
    if msg.rcode() != rcode.NOERROR:
      self.SetStatus(xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
      return False
    self.node.hosts4[name] = h4
    self.node.hosts6[name] = h6
    
    
    prevAddresses=self['IpAddress'].unchangedValue.splitlines()
    if self.CreatePtr:
      dnsName=DnsAbsName(name, self.node.zonename)

      for address in addresses:
        if address in prevAddresses:
          prevAddresses.remove(address)
        ptr, zone=self.node.GetServer().GetZoneName(DnsRevName(address))
        if zone:
          if zone.endswith("in-addr.arpa"):
            ttl=ttl4
          else:
            ttl=ttl6
          updater=self.node.GetConnection().Updater(zone)
          updater.delete(ptr, 'PTR')
          
          updater.add(ptr, Rdataset(ttl, rdataclass.IN, rdatatype.PTR, dnsName))
          _msg=self.node.GetServer().Send(updater)
      for address in prevAddresses:
        ptr, zone=self.node.GetServer().GetZoneName(DnsRevName(address))
        if zone:
          updater=self.node.GetConnection().Updater(zone)
          updater.delete(ptr, 'PTR')
          _msg=self.node.GetServer().Send(updater)
    return True
Exemple #12
0
    def Save(self):
        ttl4 = int(timeToFloat(self.TTL))
        if self.ttl6:
            ttl6 = int(timeToFloat(self.TTL6))
        else:
            ttl6 = ttl4
        name = str(self.Hostname)
        updater = self.node.Updater()
        if self.node.hosts4.get(name):
            updater.delete(name, "A")
        if self.node.hosts4.get(name):
            updater.delete(name, "AAAA")

        h4 = None
        h6 = None
        addresses = self.IpAddress.splitlines()
        for address in addresses:
            address = address.strip()
            if not address:
                continue
            if checkIpAddress(address) == 4:
                if h4:
                    h4.add(Rdata(h4, address), ttl4)
                else:
                    h4 = Rdataset(ttl4, rdataclass.IN, rdatatype.A, address)
            else:
                if h6:
                    h6.add(Rdata(h6, address), ttl6)
                else:
                    h6 = Rdataset(ttl6, rdataclass.IN, rdatatype.AAAA, address)

        if h4:
            updater.add(name, h4)
        if h6:
            updater.add(name, h6)
        msg = self.node.GetServer().Send(updater)
        if msg.rcode() != rcode.NOERROR:
            self.SetStatus(
                xlt("DNS update failed: %s") % rcode.to_text(msg.rcode()))
            return False
        self.node.hosts4[name] = h4
        self.node.hosts6[name] = h6

        prevAddresses = self['IpAddress'].unchangedValue.splitlines()
        if self.CreatePtr:
            dnsName = DnsAbsName(name, self.node.zonename)

            for address in addresses:
                if address in prevAddresses:
                    prevAddresses.remove(address)
                ptr, zone = self.node.GetServer().GetZoneName(
                    DnsRevName(address))
                if zone:
                    if zone.endswith("in-addr.arpa"):
                        ttl = ttl4
                    else:
                        ttl = ttl6
                    updater = self.node.GetConnection().Updater(zone)
                    updater.delete(ptr, 'PTR')

                    updater.add(
                        ptr,
                        Rdataset(ttl, rdataclass.IN, rdatatype.PTR, dnsName))
                    _msg = self.node.GetServer().Send(updater)
            for address in prevAddresses:
                ptr, zone = self.node.GetServer().GetZoneName(
                    DnsRevName(address))
                if zone:
                    updater = self.node.GetConnection().Updater(zone)
                    updater.delete(ptr, 'PTR')
                    _msg = self.node.GetServer().Send(updater)
        return True