mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-22 06:54:43 +01:00
Add progress bar
This commit is contained in:
parent
581b3a9090
commit
d01dd9ac1e
19
lg.py
19
lg.py
|
@ -3,7 +3,7 @@
|
||||||
# vim: ts=4
|
# vim: ts=4
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
# Copyright (c) 2006 Mehdi Abaakouk
|
# Copyright (c) 2012 Mehdi Abaakouk
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 3 as
|
# it under the terms of the GNU General Public License version 3 as
|
||||||
|
@ -36,6 +36,8 @@ app = Flask(__name__)
|
||||||
app.config.from_pyfile('lg.cfg')
|
app.config.from_pyfile('lg.cfg')
|
||||||
|
|
||||||
def add_links(text):
|
def add_links(text):
|
||||||
|
"""Browser a string and replace ipv4, ipv6, as number, with a whois link """
|
||||||
|
|
||||||
if type(text) in [ str, unicode ]:
|
if type(text) in [ str, unicode ]:
|
||||||
text = text.split("\n")
|
text = text.split("\n")
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ def add_links(text):
|
||||||
line.strip().startswith("Neighbor AS:") :
|
line.strip().startswith("Neighbor AS:") :
|
||||||
ret_text.append(re.sub(r'(\d+)',r'<a href="/whois/\1" class="whois">\1</a>',line))
|
ret_text.append(re.sub(r'(\d+)',r'<a href="/whois/\1" class="whois">\1</a>',line))
|
||||||
else:
|
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'([a-zA-Z0-9\-]*\.([a-zA-Z]{2,3}){1,2})(\s|$)', r'<a href="/whois/\1" class="whois">\1</a>\3',line)
|
||||||
line = re.sub(r'AS(\d+)', r'<a href="/whois/\1" class="whois">AS\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)
|
line = re.sub(r'(\d+\.\d+\.\d+\.\d+)', r'<a href="/whois/\1" class="whois">\1</a>',line)
|
||||||
hosts = "/".join(request.path.split("/")[2:])
|
hosts = "/".join(request.path.split("/")[2:])
|
||||||
|
@ -56,6 +58,7 @@ def add_links(text):
|
||||||
return "\n".join(ret_text)
|
return "\n".join(ret_text)
|
||||||
|
|
||||||
def set_session(request_type, hosts, proto, request_args):
|
def set_session(request_type, hosts, proto, request_args):
|
||||||
|
""" Store all data from user in the user session """
|
||||||
session.permanent = True
|
session.permanent = True
|
||||||
session.update( {
|
session.update( {
|
||||||
"request_type": request_type,
|
"request_type": request_type,
|
||||||
|
@ -75,9 +78,19 @@ def set_session(request_type, hosts, proto, request_args):
|
||||||
session["history"] = history[:20]
|
session["history"] = history[:20]
|
||||||
|
|
||||||
def bird_command(host, proto, query):
|
def bird_command(host, proto, query):
|
||||||
|
"""Alias to bird_proxy for bird service"""
|
||||||
return bird_proxy(host, proto, "bird", query)
|
return bird_proxy(host, proto, "bird", query)
|
||||||
|
|
||||||
def bird_proxy(host, proto, service, query):
|
def bird_proxy(host, proto, service, query):
|
||||||
|
"""Retreive data of a service from a running lg-proxy on a remote node
|
||||||
|
|
||||||
|
First and second arguments are the node and the port of the running lg-proxy
|
||||||
|
Third argument is the service, can be "traceroute" or "bird"
|
||||||
|
Last argument, the query to pass to the service
|
||||||
|
|
||||||
|
return tuple with the success of the command and the returned data
|
||||||
|
"""
|
||||||
|
|
||||||
path = ""
|
path = ""
|
||||||
if proto == "ipv6": path = service + "6"
|
if proto == "ipv6": path = service + "6"
|
||||||
elif proto == "ipv4": path = service
|
elif proto == "ipv4": path = service
|
||||||
|
@ -124,7 +137,7 @@ def error_page(text):
|
||||||
return render_template('error.html', error = text ), 500
|
return render_template('error.html', error = text ), 500
|
||||||
|
|
||||||
@app.errorhandler(400)
|
@app.errorhandler(400)
|
||||||
def page_not_found(e):
|
def incorrect_request(e):
|
||||||
return render_template('error.html', warning="The server could not understand the request"), 400
|
return render_template('error.html', warning="The server could not understand the request"), 400
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
|
|
||||||
|
|
||||||
|
$(window).unload(function(){
|
||||||
|
$(".progress").show()
|
||||||
|
});
|
||||||
|
|
||||||
|
function change_url(loc){
|
||||||
|
$(".progress").show(0, function(){
|
||||||
|
document.location = loc;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function reload(){
|
function reload(){
|
||||||
loc = "/" + request_type + "/" + hosts + "/" + proto;
|
loc = "/" + request_type + "/" + hosts + "/" + proto;
|
||||||
if (request_type != "summary" ){
|
if (request_type != "summary" ){
|
||||||
if( request_args != undefined && request_args != ""){
|
if( request_args != undefined && request_args != ""){
|
||||||
loc = loc + "?q=" + request_args;
|
loc = loc + "?q=" + request_args;
|
||||||
document.location = loc;
|
change_url(loc)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
document.location = loc;
|
change_url(loc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function update_view(){
|
function update_view(){
|
||||||
|
@ -36,6 +46,10 @@ function update_view(){
|
||||||
$(".request_args").select();
|
$(".request_args").select();
|
||||||
}
|
}
|
||||||
$(function(){
|
$(function(){
|
||||||
|
$(".history a").click(function (event){
|
||||||
|
event.preventDefault();
|
||||||
|
change_url(this.href)
|
||||||
|
});
|
||||||
$(".modal .modal-footer .btn").click(function(){
|
$(".modal .modal-footer .btn").click(function(){
|
||||||
$(".modal").modal('hide');
|
$(".modal").modal('hide');
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,6 +93,9 @@
|
||||||
<p>bird looking glass, <a href="https://github.com/sileht/bird-lg/">source code</a> under GPL 3.0, powered by <a href="http://flask.pocoo.org">Flask</a>, <a href="http://jquery.com/">jQuery</a> and <a href="http://twitter.github.com/bootstrap/">Bootstrap</a></p>
|
<p>bird looking glass, <a href="https://github.com/sileht/bird-lg/">source code</a> under GPL 3.0, powered by <a href="http://flask.pocoo.org">Flask</a>, <a href="http://jquery.com/">jQuery</a> and <a href="http://twitter.github.com/bootstrap/">Bootstrap</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="progress progress-info progress-striped active" style="position:fixed;bottom:0px;right:10px;display:none;height:10px;width:200px;">
|
||||||
|
<div class="bar" style="width: 100%;"></div>
|
||||||
|
</div>
|
||||||
<div class="modal fade" style="display:none;">
|
<div class="modal fade" style="display:none;">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<a class="close" data-dismiss="modal">×</a>
|
<a class="close" data-dismiss="modal">×</a>
|
||||||
|
|
Loading…
Reference in a new issue