1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-22 06:54:43 +01:00

Add history and traceroute

This commit is contained in:
Mehdi Abaakouk 2012-01-22 23:06:52 +01:00
parent bf6dbe8d73
commit 914eb489bf
5 changed files with 59 additions and 8 deletions

5
lg.cfg
View file

@ -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'

29
lg.py
View file

@ -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'<a href="/whois/\1" class="whois">\1</a>',line))
else:
line = re.sub(r'([a-zA-Z0-9\-]*\.([a-zA-Z]{2,3}){1,2})(\s|$)', r'<a href="/whois/\1" class="whois">\1</a>',line)
line = re.sub(r'AS(\d+)', r'<a href="/whois/\1" class="whois">AS\1</a>',line)
line = re.sub(r'(\d+\.\d+\.\d+\.\d+)', r'<a href="/whois/\1" class="whois">\1</a>',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/<hosts>/<proto>")
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/<hosts>/<proto>")
def show_route_where(hosts, proto):
return show_route("where", hosts, proto)

View file

@ -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;
}

View file

@ -31,8 +31,15 @@ $( function() {
$("#submit").click()
break;
default:
txt = $("#" + $("#req_type").val() ).html().replace("...", '<input type="text" id="ipopup" name="ipopup" value="' + $("#request_args").val() + '">')
menu_html = ""
data = {{session.history|tojson|safe}}[next_req_type]
for (var item in data){
menu_html += "<li>" + data[item] + "</li>"
}
txt = $("#" + $("#req_type").val() ).html().replace("...",
'<input type="text" id="ipopup" name="ipopup" value="' + $("#request_args").val() + '">') +
'<br />History:' +
'<ul id="popup_menu">' + menu_html + '</ul>'
$.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() {
</script>
<div id="page">
<div id="header">
<h1>Tetaneutral.net<br />Looking Glass</h1>
<form>
<h1>{{config.DOMAIN|capitalize}}<br />Looking Glass</h1>
<form id="menu">
<input id="hosts" type="hidden" value="{{session.hosts}}" />
<input id="proto" type="hidden" value="{{session.proto}}" />
<input id="req_type" type="hidden" value="{{session.req_type}}" />
@ -123,6 +133,7 @@ $( function() {
{% endfor %}
</ul>
<ul class="req_type">
<li id="traceroute">traceroute ...</li>
<li id="summary">show protocols</li>
<li id="detail">show protocols ... all</li>
<li id="prefix">show route for ...</li>

View file

@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block body %}
{% for host in infos %}
<h2 id="traceroute_cmd_{{host}}">{{host}}/{{session.proto}}: traceroute {{session.request_args}}</h3>
<div class="detail">{{infos[host]|safe}}</div>
{% endfor %}
{% endblock %}