dnmgmt/whoisdb/helpers.py

46 lines
1.6 KiB
Python
Raw Normal View History

2017-03-20 00:16:33 +01:00
import whoisdb.models
2017-03-21 02:36:07 +01:00
import domains.models
2017-03-20 00:16:33 +01:00
def _addFields(fields, obj, fieldNames):
for fieldName in fieldNames:
2017-03-21 02:36:07 +01:00
fields.append((fieldName.capitalize().replace("_", " "), getattr(obj, fieldName)))
2017-03-20 00:16:33 +01:00
def getWhoisObjectFields(obj, owner):
fields = []
2017-03-21 19:34:02 +01:00
if hasattr(obj, "handle"):
2017-03-20 00:16:33 +01:00
_addFields(fields, obj, ["handle"])
c = type(obj)
if c == whoisdb.models.Maintainer:
_addFields(fields, obj, ["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)))
2017-03-21 19:34:02 +01:00
_addFields(fields, obj, ["description", "parent_block", "mnt_by", "mnt_lower", "admin_c"])
2017-03-20 00:16:33 +01:00
elif c == whoisdb.models.ASNumber:
2017-03-21 19:34:02 +01:00
_addFields(fields, obj, ["name", "number", "description", "volatile", "mnt_by", "mnt_lower", "admin_c"])
2017-03-20 00:16:33 +01:00
elif c == whoisdb.models.InetNum:
_addFields(fields, obj, ["name"])
fields.append(("Address CIDR", obj.prefix()))
2017-03-21 02:36:07 +01:00
_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"])
2017-03-20 00:16:33 +01:00
return fields
2017-03-21 19:34:02 +01:00
def guessWhoisObject(self, handle):
# is it a normal handle?
pass