diff --git a/lg.cfg b/lg.cfg index 7aafb8f..fe37bce 100644 --- a/lg.cfg +++ b/lg.cfg @@ -1,8 +1,9 @@ +DOMAIN = "tetaneutral.net" HOST_MAPPING={ - "gw": { "ipv4" : 9994, "ipv6": 9996 }, - "h3": { "ipv4" : 9994, "ipv6": 9996 }, + "gw": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 }, + "h3": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 }, } SESSION_KEY = '\xd77\xf9\xfa\xc2\xb5\xcd\x85)`+H\x9d\xeeW\\%\xbe/\xbaT\x89\xe8\xa7' diff --git a/lg.py b/lg.py index 3091d72..232a415 100755 --- a/lg.py +++ b/lg.py @@ -4,6 +4,7 @@ import sys import os import subprocess import re +import urllib2 from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve @@ -14,6 +15,13 @@ app = Flask(__name__) app.config.from_pyfile('lg.cfg') +#def same_origin_policy_hander(resp): +# resp.headers["Access-Control-Allow-Origin"] = "*" +# return resp +# +#app.after_request(same_origin_policy_hander) +# + def add_links(text): if type(text) in [ str, unicode ]: text = text.split("\n") @@ -24,6 +32,7 @@ def add_links(text): line.strip().startswith("Neighbor AS:") : ret_text.append(re.sub(r'(\d+)',r'\1',line)) else: + line = re.sub(r'([a-zA-Z0-9\-]*\.([a-zA-Z]{2,3}){1,2})(\s|$)', r'\1',line) line = re.sub(r'AS(\d+)', r'AS\1',line) line = re.sub(r'(\d+\.\d+\.\d+\.\d+)', r'\1',line) ret_text.append(line) @@ -36,6 +45,11 @@ def set_session(req_type, hosts, proto, request_args): "proto": proto, "request_args": request_args, }) + history = session.get("history", {}) + req_hist = history.get(req_type, []) + if request_args and request_args not in req_hist: req_hist.insert(0, request_args) + if not history: session["history"] = {} + session["history"][req_type] = req_hist[:10] def bird_command(host, proto, command): conf = app.config["HOST_MAPPING"].get(host, None) @@ -116,6 +130,21 @@ def detail(hosts, proto): return render_template('detail.html', detail=detail, command=command) +@app.route("/traceroute//") +def traceroute(hosts, proto): + q = request.args.get('q', '') + set_session("traceroute", hosts, proto, q) + + infos = {} + for host in hosts.split("+"): + url = "http://%s.%s:%s/traceroute%s?q=%s" % ( host, app.config["DOMAIN"], app.config["HOST_MAPPING"].get(host).get("traceroute","5000"), (proto == "ipv6" and "6" or ""), q) + try: + f = urllib2.urlopen(url) + infos[host] = add_links(f.read()) + except IOError: + infos[host] = "Failed retreive url: %s" % url + return render_template('traceroute.html', infos=infos) + @app.route("/where//") def show_route_where(hosts, proto): return show_route("where", hosts, proto) diff --git a/static/style.css b/static/style.css index 0123004..22bae5a 100644 --- a/static/style.css +++ b/static/style.css @@ -66,6 +66,9 @@ ul li{ background: #FFF; border-bottom: 1px solid #AFAFAF; } +ul#popup_menu li{ + font-weight: normal; +} ul li.current{ font-weight: bold; } diff --git a/templates/layout.html b/templates/layout.html index 356f4d0..dc30621 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -31,8 +31,15 @@ $( function() { $("#submit").click() break; default: - txt = $("#" + $("#req_type").val() ).html().replace("...", '') - + menu_html = "" + data = {{session.history|tojson|safe}}[next_req_type] + for (var item in data){ + menu_html += "
  • " + data[item] + "
  • " + } + txt = $("#" + $("#req_type").val() ).html().replace("...", + '') + + '
    History:' + + '' $.prompt(txt, { prefix: 'popup', @@ -43,7 +50,10 @@ $( function() { } } }); - + $("#popup_menu li").click(function(event){ + $("#ipopup").val($(this).html()) + $("#ipopup").focus() + }); $("#ipopup").keyup(function(event) { if (event.which == 13) { event.preventDefault(); @@ -57,7 +67,7 @@ $( function() { } } - $("ul li").click(function(){ + $("#menu ul li").click(function(){ // set hiddent field with class value p = $(this).parent() // lu c = p.attr("class") @@ -107,8 +117,8 @@ $( function() {