diff --git a/src/defaults.py b/src/defaults.py index 23877ad564c46308fc2084257363a8aa7cb284a9..e9d9cf91bf36d36b8bbf7450c5397306d65fef19 100644 --- a/src/defaults.py +++ b/src/defaults.py @@ -33,10 +33,12 @@ usage_counter_file = '/tmp/ulg.lock' log_file = '/tmp/ulg.log' default_bird_sock = '/var/run/bird.ctl' default_bird_sock_timeout = 30 +bin_whois = '/usr/bin/whois' # Template dir relative to the index.py script template_dir = 'templates' index_template_file = 'index.html' +whois_template_file = 'whois.html' table_decorator_template_file = 'tabledecorator.html' # Paths to external programs @@ -58,10 +60,11 @@ STRING_INTERFACE = "Interface" STRING_SOCKET_TIMEOUT = "Socket communication timed out. See log." STRING_PEERID = "Peer ID" STRING_RTABLE = "Routing Table" +STRING_DETAILS = "Details of" # URL generator functions 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): 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 diff --git a/src/templates/whois.html b/src/templates/whois.html new file mode 100644 index 0000000000000000000000000000000000000000..4d1273e0ad0dc2f11e31f16ed17c1deb89bf51a9 --- /dev/null +++ b/src/templates/whois.html @@ -0,0 +1,24 @@ + + + + Universal Looking Glass - Whois + + +
+ + ${url_caption} +
+
+
+
+ +
+${result}
+	
+
+
+ + + diff --git a/src/ulg.py b/src/ulg.py index c2a1881c0a2c2750bbdd8a4c08a6c32d932fef65..9a1aa931c14c5e9493eeb7e125da3150109cb5c0 100755 --- a/src/ulg.py +++ b/src/ulg.py @@ -32,6 +32,7 @@ import urllib import md5 import time import random +import subprocess import config import defaults @@ -273,6 +274,12 @@ class DecoratorHelper: def getSpecialContentURL(self,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): for ridx,r in enumerate(config.routers): if(r == router): @@ -308,10 +315,10 @@ class DecoratorHelper: return """%s""" % (url,label) 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): - return self.mwin(defaults.getIPPrefixURL(ip),ip) + return self.mwin(self.getWhoisURL(ip,'IP'),ip) def annotatePrefixes(self,line): s=0 @@ -629,6 +636,41 @@ class ULGCgi: # speciality here: the function is responsible for printing the output itself 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): self.print_text_html() @@ -648,6 +690,13 @@ class ULGCgi: def getfile(self,sessionid=None,**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): self.print_text_html() print self.renderULGError(sessionid,**params) @@ -675,6 +724,8 @@ if __name__=="__main__": handler.display(**params) elif(action == 'getfile'): handler.getfile(**params) + elif(action == 'whois'): + handler.whois(**params) elif(action == 'error'): handler.error(**params) elif(action == 'debug'):