From fb22ef2ff8d6aba8a30b74fb7a97ea204cf981be Mon Sep 17 00:00:00 2001 From: Mehdi ABAAKOUK Date: Sun, 18 Dec 2011 12:32:00 +0100 Subject: [PATCH] Add show route for all --- lg.py | 14 +++++++------- templates/layout.html | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lg.py b/lg.py index 4759b4b..7e1131c 100755 --- a/lg.py +++ b/lg.py @@ -37,10 +37,10 @@ def check_ipv6(n): def hello(): return render_template('index.html') -@app.route("///prefix/") -@app.route("///prefix/") -@app.route("///prefix//") -def prefix(host, proto, prefix="", mask=""): +@app.route("///prefix/") +@app.route("///prefix/") +@app.route("///prefix//") +def prefix(host, proto, prefix="", mask="", all=False): qprefix = prefix @@ -69,11 +69,11 @@ def prefix(host, proto, prefix="", mask=""): else: allowed = False - output = '

' + host + ' (' + proto + ') show route for ' + prefix + (prefix != qprefix and " (%s)"%qprefix or "") + (mask and '/' + mask or '' ) + '

' + output = '

' + host + ' (' + proto + ') show route for ' + prefix + (prefix != qprefix and " (%s)"%qprefix or "") + (mask and '/' + mask or '' ) + (all and " all" or "") + '

' if allowed: if mask: qprefix = qprefix +"/"+mask if mask: prefix = prefix +"/"+mask - ok, string = get_cmd_result(host , proto, "show route for " + qprefix) + ok, string = get_cmd_result(host , proto, "show route for " + qprefix + (all and "all" or "")) if ok: string = "\n".join([ s.replace("1007-"," ") for s in string.split("\n") if not s.startswith("0000") ]) output +='
' + string + '
' @@ -87,7 +87,7 @@ def prefix(host, proto, prefix="", mask=""): else: output += 'prefix missing' - return render_template('index.html', output=output, typ="prefix", host=host+"/"+proto, prefix=prefix) + return render_template('index.html', output=output, typ="prefix" + (all and "_detail" or ""), host=host+"/"+proto, prefix=prefix) @app.route("///detail/") @app.route("///detail/") diff --git a/templates/layout.html b/templates/layout.html index 388111c..10a4a80 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -30,6 +30,13 @@ $("#submit").click() } break; + case "prefix_detail": + $("#submit").show() + $("#prefix").show() + if ($("#prefix").val()) { + $("#submit").click() + } + break; } }); @@ -46,6 +53,9 @@ case "prefix": document.location = "/" + $("#host").val() + "/prefix/" + $("#prefix").val() ; break; + case "prefix_detail": + document.location = "/" + $("#host").val() + "/prefix_detail/" + $("#prefix").val() ; + break; } }); @@ -72,6 +82,10 @@ if ($("#prefix").val()) { $("#submit").click() } + case "prefix_detail": + if ($("#prefix").val()) { + $("#submit").click() + } break; } }); @@ -91,6 +105,7 @@ +