Browse Source

added xml engine + web xml output results + more fancy interface

pull/3/head
psy 11 years ago
parent
commit
80aa7cee7d
  1. 4
      main.py
  2. 54
      web/index.py
  3. 3
      webserver.py
  4. 31
      xml_exporter.py

4
main.py

@ -20,6 +20,7 @@ except:
import subprocess, socket, threading
from options import BCOptions
from webserver import BorderCheckWebserver
from xml_exporter import xml_reporting
import webbrowser
# set to emit debug messages about errors (0 = off).
@ -360,6 +361,9 @@ class bc(object):
pass
else:
traces = self.try_running(self.traces, "\nInternal error tracerouting.")
# export data to XML
xml_results = xml_reporting(self)
xml_results.print_xml_results('data.xml')
print '='*45 + "\n"
print "Status: Waiting for new urls ...\n"
# stay latent waiting for new urls

54
web/index.py

@ -1,12 +1,58 @@
#!/usr/local/bin/python
# -*- coding: iso-8859-15 -*-
"""
BC (Border-Check) is a tool to retrieve info of traceroute tests over website navigation routes.
GPLv3 - 2013 by psy (epsylon@riseup.net)
"""
from xml.dom.minidom import parseString
# extract data from a xml file
file = open('data.xml','r')
data = file.read()
file.close()
dom = parseString(data)
xmlTag = dom.getElementsByTagName('travel')[0].toxml()
xmlData= xmlTag.replace('<travel>','').replace('</travel>','')
xmlHost = dom.getElementsByTagName('host')[0].toxml()
xmlIP = dom.getElementsByTagName('ip')[0].toxml()
xmlRoutes = dom.getElementsByTagName('routes')[0].toxml()
xmlMeta = dom.getElementsByTagName('meta')[0].toxml()
output = """
<html>
<head>
<title>Border Check</title>
<title>Border Check - Web Visualizator</title>
</head>
<body>
<div>
<center><img src="images/WM1.svg"><center>
</div>
<center>
<table>
<tr>
<td><div><center><img src="images/WM1.svg"></center></div></td>
</tr>
<tr>
<td>
<center>
<table border="1">
<tr>
<td><b>Host:</b></td>
<td>"""+xmlHost+"""</td>
</tr>
<tr>
<td><b>IP:</b></td>
<td>"""+xmlIP+"""</td>
</tr>
<tr>
<td><b>Packages Route:</b></td>
<td>"""+xmlRoutes+"""</td>
</tr>
<tr>
<td><b>Metadata:</b></td>
<td>"""+xmlMeta+"""</td>
</tr>
</table>
</center>
</tr>
</table>
</center>
</body>
</html>
"""

3
webserver.py

@ -69,7 +69,8 @@ class HttpHandler(BaseHTTPRequestHandler):
content = query.get('upfile')
except:
pass
print "Request from %s:%d"%self.client_address + " " + uri
# only for debug mode
#print "Request from %s:%d"%self.client_address + " " + uri
if uri[-1] == '/' or os.path.isdir(file):
file = file + "/index.py"
if os.path.isfile(file + ".py"):

31
xml_exporter.py

@ -0,0 +1,31 @@
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
"""
BC (Border-Check) is a tool to retrieve info of traceroute tests over website navigation routes.
GPLv3 - 2013 by psy (epsylon@riseup.net)
"""
import xml.etree.ElementTree as ET
class xml_reporting(object):
"""
Print results from a traceroute in an XML fashion
"""
def __init__(self, bc):
# initialize main BC
self.instance = bc
def print_xml_results(self, filename):
root = ET.Element("travel")
host = ET.SubElement(root, "host")
ip = ET.SubElement(root, "ip")
routes = ET.SubElement(root, "routes")
meta = ET.SubElement(root, "meta")
host.text = self.instance.url[0]
ip.text = self.instance.ip
routes.text = self.instance.routes
meta.text = "Connect here XML metadata"
tree = ET.ElementTree(root)
tree.write(filename)
Loading…
Cancel
Save