Made all hosts available at /all, much shorter URLs when using many hosts

This commit is contained in:
TimStallard 2019-01-27 23:42:16 +00:00
parent 49ab7b003b
commit 3c76d1679f
No known key found for this signature in database
GPG Key ID: E18E975C6A734F07
2 changed files with 19 additions and 11 deletions

28
lg.py
View File

@ -187,14 +187,12 @@ def inject_commands():
return dict(commands=commands, commands_dict=commands_dict)
@app.context_processor
def inject_all_host():
return dict(all_hosts="+".join(app.config["PROXY"].keys()))
@app.route("/")
def hello():
return redirect("/summary/%s/ipv4" % "+".join(app.config["PROXY"].keys()))
if app.config.get("UNIFIED_DAEMON", False):
return redirect("/summary/all")
else:
return redirect("/summary/all/ipv4")
def error_page(text):
@ -237,13 +235,15 @@ SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device", "BFD"]
@app.route("/summary/<hosts>")
@app.route("/summary/<hosts>/<proto>")
def summary(hosts, proto="ipv4"):
set_session("summary", hosts, proto, "")
command = "show protocols"
summary = {}
errors = []
for host in hosts.split("+"):
hosts = hosts.split("+")
if hosts == ["all"]:
hosts = app.config["PROXY"].keys()
for host in hosts:
ret, res = bird_command(host, proto, command)
res = res.split("\n")
@ -298,7 +298,10 @@ def detail(hosts, proto):
detail = {}
errors = []
for host in hosts.split("+"):
hosts = hosts.split("+")
if hosts == ["all"]:
hosts = app.config["PROXY"].keys()
for host in hosts:
ret, res = bird_command(host, proto, command)
res = res.split("\n")
@ -344,7 +347,10 @@ def traceroute(hosts, proto):
errors = []
infos = {}
for host in hosts.split("+"):
hosts = hosts.split("+")
if hosts == ["all"]:
hosts = app.config["PROXY"].keys()
for host in hosts:
status, resultat = bird_proxy(host, proto, "traceroute", q)
if status is False:
errors.append("%s" % resultat)
@ -689,6 +695,8 @@ def show_route(request_type, hosts, proto):
detail = {}
errors = []
hosts = hosts.split("+")
if hosts == ["all"]:
hosts = app.config["PROXY"].keys()
allhosts = hosts[:]
for host in allhosts:
ret, res = bird_command(host, proto, command)

View File

@ -18,7 +18,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<a class="navbar-brand" href="/">{{config.DOMAIN|capitalize}}</a>
<ul class="nav nav-pills">
<li class="nav-item hosts mr-1"><a class="nav-link" id="{{all_hosts}}" href="#">all</a></li>
<li class="nav-item hosts mr-1"><a class="nav-link" id="all" href="#">all</a></li>
{% for host in config.PROXY %}
<li class="nav-item hosts mr-1"><a class="nav-link" id="{{host}}" href="#">{{host}}</a></li>