dnmgmt/whoisdb/helpers.py

43 lines
1.5 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 = []
if getattr(obj, "handle"):
_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)))
_addFields(fields, obj, ["description", "mnt_by", "mnt_lower", "admin_c"])
elif c == whoisdb.models.ASNumber:
_addFields(fields, obj, ["name", "number", "description", "mnt_by", "mnt_lower", "admin_c"])
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