def SortedByHost(self): hostnames = self.lastNode.hosts4.keys() hostnames.extend(self.lastNode.hosts6.keys()) hostnames = sorted(set(hostnames), key=lambda n: n.lower()) self.control.DeleteAllItems() for name in hostnames: h4 = self.lastNode.hosts4.get(name) h6 = self.lastNode.hosts6.get(name) icon = self.lastNode.GetImageId('host') if h4: ttl = floatToTime(h4.ttl, -1) for h in h4: self.control.AppendItem(icon, [name, h.address, ttl]) icon = 0 name = "" ttl = "" if h6: ttl = floatToTime(h6.ttl, -1) for h in h6: self.control.AppendItem(icon, [name, h.address, ttl]) icon = 0 name = "" ttl = ""
def SortedByHost(self): hostnames=self.lastNode.hosts4.keys() hostnames.extend(self.lastNode.hosts6.keys()) hostnames = sorted(set(hostnames), key=lambda n: n.lower()) self.control.DeleteAllItems() for name in hostnames: h4=self.lastNode.hosts4.get(name) h6=self.lastNode.hosts6.get(name) icon=self.lastNode.GetImageId('host') if h4: ttl=floatToTime(h4.ttl, -1) for h in h4: self.control.AppendItem(icon, [name, h.address, ttl]) icon=0 name="" ttl="" if h6: ttl=floatToTime(h6.ttl, -1) for h in h6: self.control.AppendItem(icon, [name, h.address, ttl]) icon=0 name="" ttl=""
def SortedByIp(self): ip4 = [] for name, h4 in self.lastNode.hosts4.items(): if h4: for h in h4: ip4.append((name, h.address, h4.ttl, 4)) ip6 = [] for name, h6 in self.lastNode.hosts6.items(): if h6: for h in h6: ip6.append((name, h.address, h6.ttl, 6)) ips = sorted(ip4, key=lambda x: filledIp(x[1])) ips.extend(sorted(ip6, key=lambda x: filledIp(x[1]))) self.control.DeleteAllItems() last = None for name, addr, ttl, protocol in ips: icon = self.lastNode.GetImageId('ipaddr%d' % protocol) if last == name: self.control.AppendItem(0, ["", addr, ""]) else: last = name self.control.AppendItem( icon, [name, addr, floatToTime(ttl, -1)])
def Display(self, node, _detached): if not node or node != self.lastNode: self.storeLastItem() if not self.prepare(node): return node=self.lastNode self.control.AddColumn(xlt("Name"), 10) self.control.AddColumn(xlt("Type"), 5) self.control.AddColumn(xlt("Values"), 40) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() for other in sorted(node.others.keys()): rdss=node.others[other] for rds in rdss.values(): icon=node.GetImageId('other') dnstype=rdatatype.to_text(rds.rdtype) name=other for rd in rds: values=[] for slot in rd.__slots__: value=eval("rd.%s" % slot) if isinstance(value, list): if len(value) > 1: logger.debug("Value list dimensions > 1: %s", str(value)) value=" ".join(value) values.append("%s=%s" % (slot, value)) self.control.AppendItem(icon, [name, dnstype, ", ".join(values), floatToTime(rds.ttl, -1)]) icon=0 name="" dnstype="" self.restoreLastItem()
def SortedByIp(self): ip4=[] for name, h4 in self.lastNode.hosts4.items(): if h4: for h in h4: ip4.append( (name, h.address, h4.ttl, 4)) ip6=[] for name, h6 in self.lastNode.hosts6.items(): if h6: for h in h6: ip6.append( (name, h.address, h6.ttl, 6)) ips = sorted(ip4, key=lambda x: filledIp(x[1])) ips.extend(sorted(ip6, key=lambda x: filledIp(x[1]))) self.control.DeleteAllItems() last=None for name, addr, ttl, protocol in ips: icon=self.lastNode.GetImageId('ipaddr%d' % protocol) if last==name: self.control.AppendItem(0, ["", addr, ""]) else: last=name self.control.AppendItem(icon, [name, addr, floatToTime(ttl, -1)])
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)
def Display(self, node, _detached): if not node or node != self.lastNode: self.storeLastItem() if not self.prepare(node): return node=self.lastNode self.control.AddColumn(xlt("Address"), 10) self.control.AddColumn(xlt("Target"), 30) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() icon=node.GetImageId('ptr') ips=[] for ptr in node.ptrs.keys(): rds=node.ptrs[ptr] name=DnsAbsName(ptr, node.partialZonename) try: adr=DnsRevAddress(name) except: adr="%s <invalid>" % ptr ips.append( (adr, rds[0].target, floatToTime(rds.ttl, -1))) for ip in sorted(ips, key=(lambda x: filledIp(x[0]))): self.control.AppendItem(icon, list(ip)) self.restoreLastItem()
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)
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)
def Display(self, node, _detached): if not node or node != self.lastNode: self.storeLastItem() if not self.prepare(node): return node = self.lastNode self.control.AddColumn(xlt("Address"), 10) self.control.AddColumn(xlt("Target"), 30) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() icon = node.GetImageId('ptr') ips = [] for ptr in node.ptrs.keys(): rds = node.ptrs[ptr] name = DnsAbsName(ptr, node.partialZonename) try: adr = DnsRevAddress(name) except: adr = "%s <invalid>" % ptr ips.append((adr, rds[0].target, floatToTime(rds.ttl, -1))) for ip in sorted(ips, key=(lambda x: filledIp(x[0]))): self.control.AppendItem(icon, list(ip)) self.restoreLastItem()
def prettyTime(val): if not val: value = 0 else: value = val.total_seconds() if value < 0: value = 0 return floatToTime(value)
def prettyTime(val): if not val: value=0 else: value=val.total_seconds() if value < 0: value=0 return floatToTime(value)
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)
def pollWorker(self): while self.worker.IsRunning(): elapsed=wx.GetLocalTimeMillis() - self.startTime self.SetStatusText(floatToTime(elapsed/1000.), self.STATUSPOS_SECS) wx.Yield() if elapsed < 200: wx.MilliSleep(10); elif elapsed < 10000: wx.MilliSleep(100); else: wx.MilliSleep(500) wx.Yield() elapsed=wx.GetLocalTimeMillis() - self.startTime if elapsed: txt=floatToTime(elapsed/1000.) else: txt="0 ms" self.SetStatusText(txt, self.STATUSPOS_SECS) return txt
def pollWorker(self): while self.worker.IsRunning(): elapsed=localTimeMillis() - self.startTime self.SetStatusText(floatToTime(elapsed/1000.), self.STATUSPOS_SECS) wx.Yield() if elapsed < 200: wx.MilliSleep(10); elif elapsed < 10000: wx.MilliSleep(100); else: wx.MilliSleep(500) wx.Yield() elapsed=localTimeMillis() - self.startTime if elapsed: txt=floatToTime(elapsed/1000.) else: txt="0 ms" self.SetStatusText(txt, self.STATUSPOS_SECS) return txt
def Go(self): ttl=86400 ttl6=None if self.Hostname: self.isNew=False hasPtr=False query=self.node.GetConnection().Query name="%s.%s." % (self.Hostname, self.node.zonename) h4=self.node.hosts4.get(self.Hostname) h6=self.node.hosts6.get(self.Hostname) adr=[] def _handleAddress(h, hasPtr): adr.append(h.address) if not hasPtr: rrs=query(DnsRevName(h.address), rdatatype.PTR) if rrs and rrs[0].target.to_text() == name: return True return hasPtr if h4: ttl=h4.ttl for h in h4: hasPtr=_handleAddress(h, hasPtr) if h6: ttl6=h6.ttl for h in h6: hasPtr=_handleAddress(h, hasPtr) self['Hostname'].Disable() self.IpAddress="\n".join(adr) self.CreatePtr=hasPtr else: self.isNew=True self.TTL=floatToTime(ttl, -1) if ttl6 and ttl6 != ttl: self.TTL6=floatToTime(ttl6, -1) self.SetUnchanged()
def valFmt(val, unit): if not unit: return val ul=unit.lower() if ul == "8kb": return floatToSize(int(val)*8192) val="%s %s" % (val, unit) if ul in ['kb', 'mb', 'gb']: return floatToSize(sizeToFloat(val[:-1] + "iB")) elif ul in ['ms', 's', 'h', 'min']: return floatToTime(timeToFloat(val)) else: return val
def valFmt(val, unit): if not unit: return val ul = unit.lower() if ul == "8kb": return floatToSize(int(val) * 8192) val = "%s %s" % (val, unit) if ul in ['kb', 'mb', 'gb']: return floatToSize(sizeToFloat(val[:-1] + "iB")) elif ul in ['ms', 's', 'h', 'min']: return floatToTime(timeToFloat(val)) else: return val
def Go(self): ttl = 86400 ttl6 = None if self.Hostname: self.isNew = False hasPtr = False query = self.node.GetConnection().Query name = "%s.%s." % (self.Hostname, self.node.zonename) h4 = self.node.hosts4.get(self.Hostname) h6 = self.node.hosts6.get(self.Hostname) adr = [] def _handleAddress(h, hasPtr): adr.append(h.address) if not hasPtr: rrs = query(DnsRevName(h.address), rdatatype.PTR) if rrs and rrs[0].target.to_text() == name: return True return hasPtr if h4: ttl = h4.ttl for h in h4: hasPtr = _handleAddress(h, hasPtr) if h6: ttl6 = h6.ttl for h in h6: hasPtr = _handleAddress(h, hasPtr) self['Hostname'].Disable() self.IpAddress = "\n".join(adr) self.CreatePtr = hasPtr else: self.isNew = True self.TTL = floatToTime(ttl, -1) if ttl6 and ttl6 != ttl: self.TTL6 = floatToTime(ttl6, -1) self.SetUnchanged()
def _OnOK(self): if not self.Check(): return False if not self.DoSave(): return False if self.IsModal(): self.EndModal(wx.ID_OK) if hasattr(self, "startTime"): elapsed=localTimeMillis() - self.startTime adm.SetStatus(xlt("Ok: %s execution time.") % floatToTime(elapsed/1000.)) else: adm.SetStatus(xlt("Ok.")) return True
def _OnOK(self): if not self.Check(): return False if not self.DoSave(): return False if self.IsModal(): self.EndModal(wx.ID_OK) if hasattr(self, "startTime"): elapsed = localTimeMillis() - self.startTime adm.SetStatus( xlt("Ok: %s execution time.") % floatToTime(elapsed / 1000.)) else: adm.SetStatus(xlt("Ok.")) return True
def Display(self, node, _detached): if not node or node != self.lastNode: if not self.prepare(node): return self.storeLastItem() node=self.lastNode self.control.AddColumn(xlt("Name"), 30) self.control.AddColumn(xlt("Target"), 30) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() icon=node.GetImageId('cname') for cname in sorted(node.cnames.keys()): rds=node.cnames[cname] self.control.AppendItem(icon, [cname, rds[0].target, floatToTime(rds.ttl, -1)]) self.restoreLastItem()
def Display(self, node, _detached): if not node or node != self.lastNode: if not self.prepare(node): return self.storeLastItem() node = self.lastNode self.control.AddColumn(xlt("Name"), 30) self.control.AddColumn(xlt("Target"), 30) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() icon = node.GetImageId('cname') for cname in sorted(node.cnames.keys()): rds = node.cnames[cname] self.control.AppendItem( icon, [cname, rds[0].target, floatToTime(rds.ttl, -1)]) self.restoreLastItem()
def Display(self, node, _detached): if not node or node != self.lastNode: self.storeLastItem() if not self.prepare(node): return node = self.lastNode self.control.AddColumn(xlt("Name"), 10) self.control.AddColumn(xlt("Type"), 5) self.control.AddColumn(xlt("Values"), 40) self.control.AddColumn(xlt("TTL"), 5) self.RestoreListcols() for other in sorted(node.others.keys()): rdss = node.others[other] for rds in rdss.values(): icon = node.GetImageId('other') dnstype = rdatatype.to_text(rds.rdtype) name = other for rd in rds: values = [] for slot in rd.__slots__: value = eval("rd.%s" % slot) if isinstance(value, list): if len(value) > 1: logger.debug( "Value list dimensions > 1: %s", str(value)) value = " ".join(value) values.append("%s=%s" % (slot, value)) self.control.AppendItem(icon, [ name, dnstype, ", ".join(values), floatToTime(rds.ttl, -1) ]) icon = 0 name = "" dnstype = "" self.restoreLastItem()
def GetProperties(self): if not self.properties: self.properties=[ (xlt("Zone not available"))] # if a first attempt to read the zone failed we don't try again self.zone=self.GetServer().GetZone(self.zonename) if self.zone: self.hosts4={} self.hosts6={} self.cnames={} self.ptrs={} self.others={} for name, rds in self.zone.iterate_rdatasets(): name=name.to_text() if rds.rdtype == rdatatype.A: self.hosts4[name] = rds elif rds.rdtype == rdatatype.AAAA: self.hosts6[name] = rds elif rds.rdtype == rdatatype.CNAME: self.cnames[name] = rds elif rds.rdtype == rdatatype.PTR: self.ptrs[name] = rds else: if name == "@": if rds.rdtype == rdatatype.NS: self.ns=rds elif rds.rdtype == rdatatype.MX: self.mx=rds elif rds.rdtype == rdatatype.SOA: self.soa=rds if not self.others.get(name): self.others[name]={rds.rdtype: rds} else: self.others[name][rds.rdtype] = rds s0=self.soa[0] self.properties=[ ( xlt(self.shortname), self.name), ( xlt("Serial"), s0.serial), ( "TTL", floatToTime(self.soa.ttl, -1)), ( "Master Name Server", s0.mname), ( "Admin Mail", s0.rname), ( xlt("Retry"), floatToTime(s0.retry, -1)), ( "Expire", floatToTime(s0.expire, -1)), ( "Refresh", floatToTime(s0.refresh, -1)), ( "Default TTL", floatToTime(s0.minimum, -1)), ] if self.ns: self.AddChildrenProperty(map(lambda x: str(x.target), self.ns), "NS Records", -1) if self.mx: self.AddChildrenProperty(map(lambda x: "%(mx)s (priority %(prio)d)" % {'prio': x.preference, 'mx': str(x.exchange) }, self.mx), "MX Records", -1) if isinstance(self, RevZone): self.AddProperty(xlt("PTR record count"), len(self.ptrs), -1) else: self.AddProperty(xlt("Host record count"), len(self.hosts4)+len(self.hosts6), -1) self.AddProperty(xlt("CNAME record count"), len(self.cnames), -1) cnt=0 for lst in self.others.items(): cnt += len(lst) self.AddProperty(xlt("Other record count"), cnt, -1) return self.properties
def GetProperties(self): if not self.properties: self.properties = [(xlt("Zone not available"))] # if a first attempt to read the zone failed we don't try again self.zone = self.GetServer().GetZone(self.zonename) if self.zone: self.hosts4 = {} self.hosts6 = {} self.cnames = {} self.ptrs = {} self.others = {} for name, rds in self.zone.iterate_rdatasets(): name = name.to_text() if rds.rdtype == rdatatype.A: self.hosts4[name] = rds elif rds.rdtype == rdatatype.AAAA: self.hosts6[name] = rds elif rds.rdtype == rdatatype.CNAME: self.cnames[name] = rds elif rds.rdtype == rdatatype.PTR: self.ptrs[name] = rds else: if name == "@": if rds.rdtype == rdatatype.NS: self.ns = rds elif rds.rdtype == rdatatype.MX: self.mx = rds elif rds.rdtype == rdatatype.SOA: self.soa = rds if not self.others.get(name): self.others[name] = {rds.rdtype: rds} else: self.others[name][rds.rdtype] = rds s0 = self.soa[0] self.properties = [ (xlt(self.shortname), self.name), (xlt("Serial"), s0.serial), ("TTL", floatToTime(self.soa.ttl, -1)), ("Master Name Server", s0.mname), ("Admin Mail", s0.rname), (xlt("Retry"), floatToTime(s0.retry, -1)), ("Expire", floatToTime(s0.expire, -1)), ("Refresh", floatToTime(s0.refresh, -1)), ("Default TTL", floatToTime(s0.minimum, -1)), ] if self.ns: self.AddChildrenProperty( map(lambda x: str(x.target), self.ns), "NS Records", -1) if self.mx: self.AddChildrenProperty( map( lambda x: "%(mx)s (priority %(prio)d)" % { 'prio': x.preference, 'mx': str(x.exchange) }, self.mx), "MX Records", -1) if isinstance(self, RevZone): self.AddProperty(xlt("PTR record count"), len(self.ptrs), -1) else: self.AddProperty(xlt("Host record count"), len(self.hosts4) + len(self.hosts6), -1) self.AddProperty(xlt("CNAME record count"), len(self.cnames), -1) cnt = 0 for lst in self.others.items(): cnt += len(lst) self.AddProperty(xlt("Other record count"), cnt, -1) return self.properties