mirror of https://github.com/rscmbbng/Border-Check
rscmbbng
11 years ago
10 changed files with 156 additions and 155 deletions
@ -1,20 +0,0 @@ |
|||||
#!/usr/bin/env 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 main_gtk import GuiStarter, GuiUtils |
|
||||
|
|
||||
try: |
|
||||
import gtk, gtk.glade |
|
||||
except: |
|
||||
print ("\nError importing: Gtk/Glade libs. \n\nOn Debian based systems, please try like root:\n\n $ apt-get install python-gtk2\n") |
|
||||
sys.exit(2) |
|
||||
|
|
||||
class BCGTK(): |
|
||||
@staticmethod |
|
||||
def run(): |
|
||||
GuiStarter() |
|
||||
gtk.main() |
|
||||
|
|
@ -1,18 +0,0 @@ |
|||||
<?xml version="1.0"?> |
|
||||
<interface> |
|
||||
<!-- interface-requires gtk+ 2.12 --> |
|
||||
<!-- interface-naming-policy toplevel-contextual --> |
|
||||
<object class="GtkTextBuffer" id="textbuffer1"/> |
|
||||
<object class="GtkAction" id="action1"/> |
|
||||
<object class="GtkWindow" id="window"> |
|
||||
<property name="visible">True</property> |
|
||||
<property name="title" translatable="yes">Border Check - GTK Version</property> |
|
||||
<property name="window_position">center</property> |
|
||||
<child> |
|
||||
<object class="GtkImage" id="map1"> |
|
||||
<property name="visible">True</property> |
|
||||
<property name="pixbuf">WM1.svg</property> |
|
||||
</object> |
|
||||
</child> |
|
||||
</object> |
|
||||
</interface> |
|
@ -1,108 +0,0 @@ |
|||||
#!/usr/bin/env 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 sys |
|
||||
try: |
|
||||
import gtk, gtk.glade |
|
||||
except: |
|
||||
print ("\nError importing: Gtk/Glade libs. \n\nOn Debian based systems, please try like root:\n\n $ apt-get install python-gtk2\n") |
|
||||
sys.exit(2) |
|
||||
|
|
||||
class GuiUtils(object): |
|
||||
@staticmethod |
|
||||
def GetBuilder(name): |
|
||||
builder = gtk.Builder() |
|
||||
if not builder.add_from_file('builder.xml'): |
|
||||
print 'XML file not found!' |
|
||||
sys.exit(1) |
|
||||
else: |
|
||||
return builder |
|
||||
|
|
||||
@staticmethod |
|
||||
def Error(title, text): |
|
||||
"""Show error popup""" |
|
||||
dialog = gtk.MessageDialog( |
|
||||
parent = None, |
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT, |
|
||||
type = gtk.MESSAGE_ERROR, |
|
||||
buttons = gtk.BUTTONS_OK, |
|
||||
message_format = text) |
|
||||
dialog.set_title(title) |
|
||||
dialog.connect('response', lambda dialog, response: dialog.destroy()) |
|
||||
dialog.show() |
|
||||
print text |
|
||||
|
|
||||
@staticmethod |
|
||||
def Info(title, text): |
|
||||
"""Show info popup""" |
|
||||
dialog = gtk.MessageDialog( |
|
||||
parent = None, |
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT, |
|
||||
type = gtk.MESSAGE_INFO, |
|
||||
buttons = gtk.BUTTONS_OK, |
|
||||
message_format = text) |
|
||||
dialog.set_title(title) |
|
||||
dialog.connect('response', lambda dialog, response: dialog.destroy()) |
|
||||
dialog.show() |
|
||||
|
|
||||
@staticmethod |
|
||||
def Loading(title, text): |
|
||||
"""Show loading popup""" |
|
||||
dialog = gtk.MessageDialog( |
|
||||
parent = None, |
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT, |
|
||||
type = gtk.MESSAGE_INFO, |
|
||||
buttons = gtk.BUTTONS_NONE, |
|
||||
message_format = text) |
|
||||
dialog.set_title(title) |
|
||||
dialog.connect('response', lambda dialog, response: dialog.destroy()) |
|
||||
dialog.show() |
|
||||
return dialog |
|
||||
|
|
||||
@staticmethod |
|
||||
def Warning(title, text): |
|
||||
"""Show warning popup""" |
|
||||
dialog = gtk.MessageDialog( |
|
||||
parent = None, |
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT, |
|
||||
type = gtk.MESSAGE_WARNING, |
|
||||
buttons = gtk.BUTTONS_OK, |
|
||||
message_format = text) |
|
||||
dialog.set_title(title) |
|
||||
dialog.connect('response', lambda dialog, response: dialog.destroy()) |
|
||||
dialog.show() |
|
||||
return dialog |
|
||||
|
|
||||
@staticmethod |
|
||||
def Question(title, text): |
|
||||
"""Show question popup""" |
|
||||
dialog = gtk.MessageDialog( |
|
||||
parent = None, |
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT, |
|
||||
type = gtk.MESSAGE_QUESTION, |
|
||||
buttons = gtk.BUTTONS_YES_NO, |
|
||||
message_format = text) |
|
||||
dialog.set_title(title) |
|
||||
dialog.connect('response', lambda dialog, response: dialog.destroy()) |
|
||||
dialog.show() |
|
||||
return dialog |
|
||||
|
|
||||
class GuiStarter(object): |
|
||||
""" |
|
||||
Init the starter GUI box. |
|
||||
""" |
|
||||
def __init__(self): |
|
||||
""" |
|
||||
Start the GUI up and set the connections with the components. |
|
||||
""" |
|
||||
builder = GuiUtils.GetBuilder('builder') |
|
||||
|
|
||||
# get objects |
|
||||
self.window = builder.get_object('builder') |
|
||||
|
|
||||
# defaults |
|
||||
|
|
||||
# signals |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
@ -0,0 +1,12 @@ |
|||||
|
output = """ |
||||
|
<html> |
||||
|
<head> |
||||
|
<title>Border Check</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div> |
||||
|
<center><img src="images/WM1.svg"><center> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
||||
|
""" |
@ -0,0 +1,137 @@ |
|||||
|
#!/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 os |
||||
|
import sys |
||||
|
from SocketServer import ForkingMixIn, ThreadingMixIn |
||||
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer |
||||
|
from runpy import run_module |
||||
|
from urlparse import urlparse |
||||
|
from cgi import parse_qs #, parse_header, parse_multipart |
||||
|
import cgi |
||||
|
|
||||
|
port = 8080 |
||||
|
wwwroot = "web/" |
||||
|
http = {} # global storage |
||||
|
|
||||
|
class ForkingTCPServer(ForkingMixIn, HTTPServer): pass |
||||
|
class ThreadingTCPServer(ThreadingMixIn, HTTPServer): pass |
||||
|
|
||||
|
def print_exception(type=None, value=None, tb=None, limit=None): |
||||
|
if type is None: |
||||
|
type, value, tb = sys.exc_info() |
||||
|
import traceback |
||||
|
ret = "<html><body><h2>Traceback (most recent call last):<h2 />" |
||||
|
ret += "<pre>" |
||||
|
list = traceback.format_tb(tb, limit) + \ |
||||
|
traceback.format_exception_only(type, value) |
||||
|
ret += "exception error" |
||||
|
ret += "%s: %s<br/>\n" % ( ("\n".join(list[:-1])), (list[-1])) |
||||
|
ret +="</body></html>" |
||||
|
del tb |
||||
|
return ret |
||||
|
|
||||
|
class HttpHandler(BaseHTTPRequestHandler): |
||||
|
|
||||
|
# TODO: whitelist out there |
||||
|
def client_not_allowed(self, addr): |
||||
|
return False |
||||
|
if addr == "127.0.0.1": |
||||
|
return False |
||||
|
print ("Client not allowed ",addr) |
||||
|
return True |
||||
|
|
||||
|
def serve(self): |
||||
|
output = "" |
||||
|
uri = self.path |
||||
|
tmp = uri.find ('?') |
||||
|
args = parse_qs(urlparse(uri)[4]) |
||||
|
|
||||
|
#from ipdb import set_trace;set_trace() |
||||
|
if tmp != -1: |
||||
|
uri = uri[0:tmp] |
||||
|
for a in uri[tmp:-1].split("&"): |
||||
|
sep = a.find ("=") |
||||
|
if sep != -1: |
||||
|
print "%s)(%s"%(a[0:sep],a[sep:-1]) |
||||
|
args[a[0:sep]]=a[sep:-1] |
||||
|
|
||||
|
file = wwwroot + "/" + uri |
||||
|
if self.client_not_allowed (self.client_address[0]): |
||||
|
self.wfile.write ("HTTP/1.0 503 Not allowed\r\n\r\nYou are not whitelisted") |
||||
|
return |
||||
|
content = "" |
||||
|
try: |
||||
|
ctype,pdict = cgi.parse_header(self.headers.getheader('content-type')) |
||||
|
print "CTYPE IS ",ctype |
||||
|
if ctype == 'multipart/form-data': |
||||
|
query = cgi.parse_multipart(self.rfile, pdict) |
||||
|
content = query.get('upfile') |
||||
|
except: |
||||
|
pass |
||||
|
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"): |
||||
|
file = file + ".py" |
||||
|
if file.find("py") != -1: |
||||
|
modname = file.replace(".py", "") |
||||
|
cwd = modname[0:modname.rfind('/')]+"/" |
||||
|
modname = modname.replace("/", ".") |
||||
|
while modname.find("..") != -1: |
||||
|
modname = modname.replace("..",".") |
||||
|
globals = { |
||||
|
"output": output, |
||||
|
"http": http, |
||||
|
"uri": uri, |
||||
|
"args": args, |
||||
|
"cwd": cwd, |
||||
|
"headers": self.headers, |
||||
|
"content": content |
||||
|
} |
||||
|
try: |
||||
|
a = run_module(modname, init_globals=globals) |
||||
|
output = a["output"] |
||||
|
except: |
||||
|
output = print_exception() |
||||
|
else: |
||||
|
try: |
||||
|
f = open (file, "r") |
||||
|
output = f.read () |
||||
|
f.close () |
||||
|
except: |
||||
|
output = "404" |
||||
|
if output == "404": |
||||
|
self.wfile.write ("HTTP/1.0 404 Not found\r\n\r\n") |
||||
|
else: |
||||
|
self.wfile.write ("HTTP/1.0 200 OK\r\n\r\n") |
||||
|
self.wfile.write (output) |
||||
|
|
||||
|
def do_POST (self): |
||||
|
self.serve () |
||||
|
|
||||
|
def do_GET (self): |
||||
|
self.serve () |
||||
|
|
||||
|
class BorderCheckWebserver(): |
||||
|
def __init__(self, ref, *args): |
||||
|
HttpHandler.ref = ref |
||||
|
httpd = HTTPServer(('', port), HttpHandler) |
||||
|
print "http://127.0.0.1:%d/ : Serving directory '%s/www'" % (port, os.getcwd()) |
||||
|
try: |
||||
|
httpd.serve_forever() |
||||
|
except KeyboardInterrupt: |
||||
|
print 'Server killed on user request (keyboard interrupt).' |
||||
|
|
||||
|
if __name__=="__main__": |
||||
|
wwwroot = "www" |
||||
|
httpd = HTTPServer(('', port), HttpHandler) |
||||
|
print "http://127.0.0.1:%d/ : Serving directory '%s/www'" % (port, os.getcwd()) |
||||
|
|
||||
|
try: |
||||
|
httpd.serve_forever() |
||||
|
except KeyboardInterrupt: |
||||
|
print 'Server killed on user request (keyboard interrupt).' |
Loading…
Reference in new issue