Ejemplo n.º 1
0
    def Go(self):
        if self.RecordName:
            ttl, rds = self._getRds()
            self.changed = False
        else:
            ttl = 86400
            self.rds = None
            self.changed = True
            cls = RdataClass(rdataclass.IN, self.rdtype)
            rds = Rdataset(ttl, rdataclass.IN, self.rdtype)

        typestr = rdatatype.to_text(self.rdtype)
        self.SetTitle(DnsSupportedTypes[typestr])
        self.RecordNameStatic = typestr

        self.slots = rds[0].__slots__
        self.slotvals = []
        for slot in self.slots:
            self.slotvals.append(eval("rds[0].%s" % slot))

        self.grid.CreateGrid(1, len(self.slots))
        self.grid.SetRowLabelSize(0)
        for col in range(len(self.slots)):
            self.grid.SetColLabelValue(col, self.slots[col].capitalize())
            self.grid.AutoSizeColLabelSize(col)
            colsize = self.grid.GetColSize(col)
            if isinstance(self.slotvals[col], int):
                minwidth, _h = self.grid.GetTextExtent("99999")
                self.grid.SetColFormatNumber(col)
            else:
                minwidth, _h = self.grid.GetTextExtent(
                    "TheSampleTarget.admin.org")
            MARGIN = 8
            minwidth += MARGIN
            if colsize < minwidth:
                self.grid.SetColSize(col, minwidth)

        if self.RecordName:
            row = 0
            for _rd in self.rds:
                for col in range(len(self.slots)):
                    val = eval("_rd.%s" % self.slots[col])
                    if isinstance(val, list):
                        val = " ".join(val)
                    self.grid.SetCellValue(row, col, str(val))
                self.grid.AppendRows(1)
                row += 1
        self.TTL = floatToTime(ttl, -1)

        self.Show()
        self.grid.AutoSizeColumns()

        maxwidth, _h = self.grid.GetSize()
        width = 0
        cn = self.grid.GetNumberCols() - 1
        for col in range(cn + 1):
            width += self.grid.GetColSize(col)
        if width < maxwidth:
            self.grid.SetColSize(cn,
                                 self.grid.GetColSize(cn) + maxwidth - width)
Ejemplo n.º 2
0
    def Go(self):
        if self.RecordName:
            ttl, rds = self._getRds()
            vlist = []
            for rd in self.rds:
                value = eval("rd.%s" % rd.__slots__[0])
                if isinstance(value, list):
                    value = " ".join(map(quoteIfNeeded, value))
                vlist.append(str(value))
            self.value = "\n".join(vlist)
        else:
            ttl = 86400
            rds = Rdataset(ttl, rdataclass.IN, self.rdtype)
            self.rds = None

        typestr = rdatatype.to_text(self.rdtype)
        self.SetTitle(DnsSupportedTypes[typestr])
        self.RecordNameStatic = typestr
        self.ValueStatic = rds[0].__slots__[0].capitalize()
        self.dataclass = type(eval("rds[0].%s" % rds[0].__slots__[0]))
        if self.dataclass == int:
            validatorClass = Validator.Get("uint")
            if validatorClass:
                self['Value'].validator = validatorClass(self['Value'], "uint")
        elif self.dataclass == Name:
            self.dataclass = DnsName
        self.TTL = floatToTime(ttl, -1)
Ejemplo n.º 3
0
 def Save(self):
   ttl=int(timeToFloat(self.TTL))
   rds=None
   for value in self.Value.splitlines():
     value=value.strip()
     if not value:
       continue
     if self.dataclass == list:
       value=removeSmartQuote(value)
       data=shlexSplit(value, ' ')
     else:
       data=self.dataclass(value)
     if not rds:
       rds=Rdataset(ttl, rdataclass.IN, self.rdtype, data)
     else:
       rds.add(Rdata(rds, data), ttl)
   return self._save(rds)
Ejemplo n.º 4
0
 def Save(self):
     ttl = int(timeToFloat(self.TTL))
     rds = None
     for value in self.Value.splitlines():
         value = value.strip()
         if not value:
             continue
         if self.dataclass == list:
             value = removeSmartQuote(value)
             data = shlexSplit(value, ' ')
         else:
             data = self.dataclass(value)
         if not rds:
             rds = Rdataset(ttl, rdataclass.IN, self.rdtype, data)
         else:
             rds.add(Rdata(rds, data), ttl)
     return self._save(rds)
Ejemplo n.º 5
0
  def Save(self):
    self.grid.SaveEditControlValue()
    ttl=int(timeToFloat(self.TTL))
    rds=None
    
    for row in range(self.grid.GetNumberRows()-1):
      vals=[]
      for col in range(self.grid.GetNumberCols()):
        val=self.grid.GetCellValue(row, col).strip()
        coltype=type(self.slotvals[col])
        if coltype == Name:
          vals.append(DnsName(val))
        elif coltype == list:
          vals.append(val.split(' '))
        else:
          vals.append(coltype(val))
        
      if not rds:
        rds=Rdataset(ttl, rdataclass.IN, self.rdtype, *tuple(vals))
      else:
        rds.add(Rdata(rds, *tuple(vals)), ttl)

    return self._save(rds)
Ejemplo n.º 6
0
    def Save(self):
        self.grid.SaveEditControlValue()
        ttl = int(timeToFloat(self.TTL))
        rds = None

        for row in range(self.grid.GetNumberRows() - 1):
            vals = []
            for col in range(self.grid.GetNumberCols()):
                val = self.grid.GetCellValue(row, col).strip()
                coltype = type(self.slotvals[col])
                if coltype == Name:
                    vals.append(DnsName(val))
                elif coltype == list:
                    vals.append(val.split(' '))
                else:
                    vals.append(coltype(val))

            if not rds:
                rds = Rdataset(ttl, rdataclass.IN, self.rdtype, *tuple(vals))
            else:
                rds.add(Rdata(rds, *tuple(vals)), ttl)

        return self._save(rds)
Ejemplo n.º 7
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