dnmgmt/whoisdb/helpers.py

48 lines
1.6 KiB
Python

import whoisdb.models
import domains.models
def _addFields(fields, obj, fieldNames):
for fieldName in fieldNames:
fields.append((fieldName.capitalize().replace("_", " "), getattr(obj, fieldName)))
def getWhoisObjectFields(obj, owner):
fields = []
if getattr(obj, "handle", None):
_addFields(fields, obj, ["handle"])
c = type(obj)
if c == whoisdb.models.Maintainer:
_addFields(fields, obj, ["description", "admin_c"])
if owner:
_addFields(fields, obj, ["auth"])
elif c == whoisdb.models.Contact:
_addFields(fields, obj, ["name", "mnt_by"])
elif c == whoisdb.models.ASBlock:
_addFields(fields, obj, ["name"])
fields.append(("AS Range", "%s - %s" % (obj.asBegin, obj.asEnd)))
_addFields(fields, obj, ["description", "parent_block", "mnt_by", "mnt_lower", "admin_c"])
elif c == whoisdb.models.ASNumber:
_addFields(fields, obj, ["name", "number", "description", "volatile", "mnt_by", "mnt_lower", "admin_c"])
elif c == whoisdb.models.InetNum:
_addFields(fields, obj, ["name"])
fields.append(("Address CIDR", obj.prefix()))
_addFields(fields, obj, ["description", "parent_range", "mnt_by", "mnt_lower", "admin_c"])
elif c == domains.models.Domain:
_addFields(fields, obj, ["name", "nameservers", "mnt_by", "admin_c"])
elif c == domains.models.Nameserver:
_addFields(fields, obj, ["name", "glueIPv4", "glueIPv6", "mnt_by", "admin_c"])
elif c == domains.models.ReverseZone:
#_addFields(fields, obj, ["name"])
fields.append(("Address CIDR", obj.prefix()))
_addFields(fields, obj, ["parentNet", "nameservers"])
return fields
def guessWhoisObject(self, handle):
# is it a normal handle?
pass