From 5eda1b47d31fb7afa586a8ff5c935bd47828827d Mon Sep 17 00:00:00 2001 From: Mehdi ABAAKOUK Date: Fri, 16 Dec 2011 19:05:16 +0100 Subject: [PATCH] More pretty output and url handling --- lg.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lg.py b/lg.py index f32be15..a0d5d9d 100755 --- a/lg.py +++ b/lg.py @@ -37,14 +37,18 @@ 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=""): +def prefix(host, proto, prefix="", mask=""): qprefix = prefix + # security check allowed = True - if not check_mask(mask): + if not prefix: + allowed = False + elif not check_mask(mask): allowed = False elif proto == "ipv6": if not check_ipv6(prefix): @@ -61,7 +65,8 @@ def prefix(host, proto, prefix, mask=""): allowed = False 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 '' ) + '

' if allowed: if mask: qprefix = qprefix +"/"+mask if mask: prefix = prefix +"/"+mask @@ -72,25 +77,35 @@ def prefix(host, proto, prefix, mask=""): else: output += string else: - output += prefix + ' not allowed' + if prefix: + output += prefix + ' not allowed' + else: + output += 'prefix missing' return render_template('index.html', output=output, typ="prefix", host=host+"/"+proto, prefix=prefix) +@app.route("///detail/") @app.route("///detail/") -def detail(host, proto, name): - output = '

' + host + '(' + proto + ') show protocols all ' + name + '

' +def detail(host, proto, name=""): + output = '

' + host + ' (' + proto + ') show protocols all ' + name + '

' - ok, string = get_cmd_result(host , proto, "show protocols all " + name) - if ok: - string = "\n".join([ s.strip() for s in string.split("\n") if s.startswith(" ")]) - output +='
' + string + '
' + if name: + ok, string = get_cmd_result(host , proto, "show protocols all " + name) + if ok: + string = "\n".join([ s.strip() for s in string.split("\n") if s.startswith(" ")]) + output +='
' + string + '
' + else: + output += string else: - output += string + output += "name missing" + return render_template('index.html', output=output, typ="detail", host=host+"/"+proto, name=name) +@app.route("//") +@app.route("///") @app.route("///summary") -def summary(host, proto): - output = '

' + host + '(' + proto + ') show protocols

' +def summary(host, proto="ipv4"): + output = '

' + host + ' (' + proto + ') show protocols

' ok, string = get_cmd_result(host , proto, "show protocols") if ok: