summaryrefslogtreecommitdiff
path: root/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'core.py')
-rw-r--r--core.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/core.py b/core.py
index 44e3f90..300f6ff 100644
--- a/core.py
+++ b/core.py
@@ -26,7 +26,16 @@ class Daemon():
"""Receive a dictionary and return a string"""
result = ""
for k, v in values.items():
- result += '{0}: {1}\n'.format(k, v)
+ if k == 'domains':
+ result += '\nAssociated domains\n'
+ for i, dom in enumerate(v):
+ result += ' {0}\n'.format(dom.name)
+ elif k == 'admins':
+ result += '\nAssociated administrator/s\n '
+ for i, adm in enumerate(v):
+ result += ' {0} {1} <{2}>\n'.format(adm.name, adm.surname, adm.email)
+ else:
+ result += '{0}: {1}\n'.format(k, v)
return result
@@ -38,19 +47,21 @@ class Daemon():
for key in networks:
for block in networks[key].ip_blocks:
if ipaddr.IPAddress(ip) in ipaddr.IPNetwork(block):
- result['name'] = networks[key].name
- for k in networks[key].data:
- result[k] = networks[key].data[k]
-
- return result
+ return networks[key].as_dict(self.data)
- result['error'] = "Red no encontrada"
+ result['error'] = "Network not found"
return result
- # TODO
def search_domain(self, domain):
- pass
-
+ # Iterate over all network and check its domains
+ networks = self.data.get_networks()
+ domains = self.data.get_domains()
+ for network in networks.values():
+ if any(domains[d].name == domain for d in network.domains):
+ return network.as_dict(self.data)
+
+ return {'error':'Domain not found'}
+
# TODO
def search_person(self, query):
@@ -93,9 +104,9 @@ class WhoisHandler(socketserver.BaseRequestHandler):
data = str(self.request.recv(100).strip(), 'utf-8')
print('Received: {}'.format(data))
- response = self.daemon.get_header() + " \n"
- response += self.daemon.query(data)
- response += self.daemon.get_footer() + "\n"
+ #response = self.daemon.get_header() + " \n"
+ response = self.daemon.query(data)
+ #response += self.daemon.get_footer() + "\n"
self.request.sendall(bytes(response, 'utf-8'))
nihil fit ex nihilo