Commit 4a6c29e8 authored by Tomas Hlavacek's avatar Tomas Hlavacek

Implement whois client and link it to decorators.

Implement whois CGI action.
Link decorator helper functions to this new action instead of RIPE DB
web interface.
Put link to URLs to RIPE DB web interface frol old defaults.getANSURL()
and defaults.getIPPrefixURL() functions to the header of the new Whois
output in the modal window. Open the links to RIPE DB in new
windows/tabs.
parent 5cdd91c8
...@@ -33,10 +33,12 @@ usage_counter_file = '/tmp/ulg.lock' ...@@ -33,10 +33,12 @@ usage_counter_file = '/tmp/ulg.lock'
log_file = '/tmp/ulg.log' log_file = '/tmp/ulg.log'
default_bird_sock = '/var/run/bird.ctl' default_bird_sock = '/var/run/bird.ctl'
default_bird_sock_timeout = 30 default_bird_sock_timeout = 30
bin_whois = '/usr/bin/whois'
# Template dir relative to the index.py script # Template dir relative to the index.py script
template_dir = 'templates' template_dir = 'templates'
index_template_file = 'index.html' index_template_file = 'index.html'
whois_template_file = 'whois.html'
table_decorator_template_file = 'tabledecorator.html' table_decorator_template_file = 'tabledecorator.html'
# Paths to external programs # Paths to external programs
...@@ -58,10 +60,11 @@ STRING_INTERFACE = "Interface" ...@@ -58,10 +60,11 @@ STRING_INTERFACE = "Interface"
STRING_SOCKET_TIMEOUT = "Socket communication timed out. See log." STRING_SOCKET_TIMEOUT = "Socket communication timed out. See log."
STRING_PEERID = "Peer ID" STRING_PEERID = "Peer ID"
STRING_RTABLE = "Routing Table" STRING_RTABLE = "Routing Table"
STRING_DETAILS = "Details of"
# URL generator functions # URL generator functions
def getASNURL(asn): def getASNURL(asn):
return 'https://apps.db.ripe.net/search/query.html?searchtext=AS%s&flags=C&sources=&grssources=RIPE;AFRINIC;APNIC;ARIN;LACNIC;JPIRR;RADB&inverse=&types=AUT_NUM' % asn return 'https://apps.db.ripe.net/search/query.html?searchtext=%s&flags=C&sources=&grssources=RIPE;AFRINIC;APNIC;ARIN;LACNIC;JPIRR;RADB&inverse=&types=AUT_NUM' % asn
def getIPPrefixURL(prefix): def getIPPrefixURL(prefix):
return 'https://apps.db.ripe.net/search/query.html?searchtext=%s&flags=C&sources=&grssources=RIPE;AFRINIC;APNIC;ARIN;LACNIC;JPIRR;RADB&inverse=&types=INET6NUM;INETNUM' % prefix return 'https://apps.db.ripe.net/search/query.html?searchtext=%s&flags=C&sources=&grssources=RIPE;AFRINIC;APNIC;ARIN;LACNIC;JPIRR;RADB&inverse=&types=INET6NUM;INETNUM' % prefix
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/">
<head>
<title>Universal Looking Glass - Whois</title>
</head>
<body class="whois">
<div id="begin">
<py:if test="defined('url') and url != None">
<a href="${url}" target="_blank">${url_caption}</a>
<hr/>
</py:if>
</div>
<div id="content">
<py:if test="defined('result') and result != None">
<pre>
${result}
</pre>
</py:if>
</div>
<div id="footer">
</div>
</body>
</html>
...@@ -32,6 +32,7 @@ import urllib ...@@ -32,6 +32,7 @@ import urllib
import md5 import md5
import time import time
import random import random
import subprocess
import config import config
import defaults import defaults
...@@ -273,6 +274,12 @@ class DecoratorHelper: ...@@ -273,6 +274,12 @@ class DecoratorHelper:
def getSpecialContentURL(self,sessionid,parameters={}): def getSpecialContentURL(self,sessionid,parameters={}):
return self.getURL('getfile',dict({'sessionid':sessionid},**parameters)) return self.getURL('getfile',dict({'sessionid':sessionid},**parameters))
def getWhoisURL(self,key,objtype=None):
if(objtype):
return self.getURL('whois',dict({'key':key,'objtype':objtype}))
else:
return self.getURL('whois',dict({'key':key}))
def getRouterID(self,router): def getRouterID(self,router):
for ridx,r in enumerate(config.routers): for ridx,r in enumerate(config.routers):
if(r == router): if(r == router):
...@@ -308,10 +315,10 @@ class DecoratorHelper: ...@@ -308,10 +315,10 @@ class DecoratorHelper:
return """<span style="cursor: pointer" onclick="TINY.box.show({iframe:'%s',boxid:'frameless',fixed:false,width:750,height:450,closejs:function(){closeJS()}})"><u>%s</u></span>""" % (url,label) return """<span style="cursor: pointer" onclick="TINY.box.show({iframe:'%s',boxid:'frameless',fixed:false,width:750,height:450,closejs:function(){closeJS()}})"><u>%s</u></span>""" % (url,label)
def decorateASN(self,asn,prefix="AS"): def decorateASN(self,asn,prefix="AS"):
return self.mwin(defaults.getASNURL(str(asn)),prefix+str(asn)) return self.mwin(self.getWhoisURL('AS'+str(asn),'AS'),prefix+str(asn))
def decoratePrefix(self,ip): def decoratePrefix(self,ip):
return self.mwin(defaults.getIPPrefixURL(ip),ip) return self.mwin(self.getWhoisURL(ip,'IP'),ip)
def annotatePrefixes(self,line): def annotatePrefixes(self,line):
s=0 s=0
...@@ -629,6 +636,41 @@ class ULGCgi: ...@@ -629,6 +636,41 @@ class ULGCgi:
# speciality here: the function is responsible for printing the output itself # speciality here: the function is responsible for printing the output itself
session.getCommand().getSpecialContent(session,**params) session.getCommand().getSpecialContent(session,**params)
def runULGWhois(self,key,objtype):
url=None
urlc=None
if(objtype == 'IP'):
ot='inetnum,inet6num'
url=defaults.getIPPrefixURL(key)
urlc=defaults.STRING_DETAILS+' '+str(key)
elif(objtype == 'AS'):
ot='aut-num'
url=defaults.getASNURL(key)
urlc=defaults.STRING_DETAILS+' '+key
else:
ot='aut-num,inetnum,inet6num'
template = self.loader.load(defaults.whois_template_file)
s = subprocess.Popen([defaults.bin_whois,
'-r',
'-H',
'-T '+ot,
key], stdout=subprocess.PIPE)
res=''
begin = False
for l in s.stdout.readlines():
if(re.match('^\s*$',l) and not begin):
continue
if(l[0] != '%'):
res=res+l
begin = True
return template.generate(result=Markup(res),
url=url,
url_caption=urlc,
).render('html', doctype='html')
def index(self, **params): def index(self, **params):
self.print_text_html() self.print_text_html()
...@@ -648,6 +690,13 @@ class ULGCgi: ...@@ -648,6 +690,13 @@ class ULGCgi:
def getfile(self,sessionid=None,**params): def getfile(self,sessionid=None,**params):
self.getULGSpecialContent(sessionid,**params) self.getULGSpecialContent(sessionid,**params)
def whois(self,key,objtype=None):
self.print_text_html()
if(key):
print self.runULGWhois(key,objtype)
else:
print self.HTTPRedirect(self.decorator_helper.getErrorURL())
def error(self,sessionid=None,**params): def error(self,sessionid=None,**params):
self.print_text_html() self.print_text_html()
print self.renderULGError(sessionid,**params) print self.renderULGError(sessionid,**params)
...@@ -675,6 +724,8 @@ if __name__=="__main__": ...@@ -675,6 +724,8 @@ if __name__=="__main__":
handler.display(**params) handler.display(**params)
elif(action == 'getfile'): elif(action == 'getfile'):
handler.getfile(**params) handler.getfile(**params)
elif(action == 'whois'):
handler.whois(**params)
elif(action == 'error'): elif(action == 'error'):
handler.error(**params) handler.error(**params)
elif(action == 'debug'): elif(action == 'debug'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment