forked from mirrors/thatmattlove-hyperglass
converted network list to jinja instead of ajax query, leaving only 1 ajax query needed
This commit is contained in:
parent
3f44747948
commit
04e94462fe
6 changed files with 46 additions and 35 deletions
|
|
@ -87,19 +87,6 @@ def testRoute():
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
# Flask GET route to provides a JSON list of all networks/ASNs from the config file
|
|
||||||
@app.route("/networks", methods=["GET"])
|
|
||||||
def get_networks():
|
|
||||||
results = []
|
|
||||||
results_dedup = set(results)
|
|
||||||
for r in routers_list:
|
|
||||||
if not r["asn"] in results_dedup:
|
|
||||||
results_dedup.add(r["asn"])
|
|
||||||
results.append(dict(network=r["asn"]))
|
|
||||||
results_json = json.dumps(results, sort_keys=True)
|
|
||||||
return results_json
|
|
||||||
|
|
||||||
|
|
||||||
# Flask GET route provides a JSON list of all routers for the selected network/ASN
|
# Flask GET route provides a JSON list of all routers for the selected network/ASN
|
||||||
@app.route("/routers/<asn>", methods=["GET"])
|
@app.route("/routers/<asn>", methods=["GET"])
|
||||||
def get_routers(asn):
|
def get_routers(asn):
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import vars
|
||||||
import cmd_parser as parser
|
import cmd_parser as parser
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
# Load TOML config file
|
# Load TOML devices file
|
||||||
devices = toml.load(open("./config/devices.toml"))
|
devices = toml.load(open("./config/devices.toml"))
|
||||||
# Filter config to router list
|
# Filter config to router list
|
||||||
routers_list = devices["router"]
|
routers_list = devices["router"]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ var progress = ($('#progress'));
|
||||||
var resultsbox = ($('#resultsbox'));
|
var resultsbox = ($('#resultsbox'));
|
||||||
resultsbox.hide();
|
resultsbox.hide();
|
||||||
progress.hide();
|
progress.hide();
|
||||||
listNetworks ();
|
|
||||||
clientIP ();
|
clientIP ();
|
||||||
|
|
||||||
function clientIP () {
|
function clientIP () {
|
||||||
|
|
@ -13,19 +12,6 @@ function clientIP () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function listNetworks () {
|
|
||||||
let networklist = $('#network');
|
|
||||||
networklist.empty();
|
|
||||||
networklist.prop('selectedIndex', 0);
|
|
||||||
const url = '/networks';
|
|
||||||
$.getJSON(url, function (data) {
|
|
||||||
$.each(data, function (key, entry) {
|
|
||||||
networklist.append($('<option></option>').attr('value', entry.network).text('AS'+entry.network));
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the list of routers for the *default* selected network
|
|
||||||
$( document ).ready(function(){
|
$( document ).ready(function(){
|
||||||
var defaultasn = $ ( "#network" ).val();
|
var defaultasn = $ ( "#network" ).val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
@ -45,6 +31,7 @@ $( document ).ready(function(){
|
||||||
|
|
||||||
$('#network').on('change', () => {
|
$('#network').on('change', () => {
|
||||||
var asn = $("select[id=network").val()
|
var asn = $("select[id=network").val()
|
||||||
|
$('#router').children(":not(#text_location)").remove();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `/routers/${asn}`,
|
url: `/routers/${asn}`,
|
||||||
type: 'get',
|
type: 'get',
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class html:
|
||||||
elif t == "test":
|
elif t == "test":
|
||||||
template = env.get_template("templates/429.html")
|
template = env.get_template("templates/429.html")
|
||||||
return template.render(
|
return template.render(
|
||||||
site_title=vars.brand.site_title(),
|
# General
|
||||||
primary_asn=vars.gen.primary_asn(),
|
primary_asn=vars.gen.primary_asn(),
|
||||||
google_analytics=vars.gen.google_analytics(),
|
google_analytics=vars.gen.google_analytics(),
|
||||||
enable_recaptcha=vars.gen.enable_recaptcha(),
|
enable_recaptcha=vars.gen.enable_recaptcha(),
|
||||||
|
|
@ -38,6 +38,10 @@ class html:
|
||||||
enable_bgp_aspath=vars.gen.enable_bgp_aspath(),
|
enable_bgp_aspath=vars.gen.enable_bgp_aspath(),
|
||||||
enable_ping=vars.gen.enable_ping(),
|
enable_ping=vars.gen.enable_ping(),
|
||||||
enable_traceroute=vars.gen.enable_traceroute(),
|
enable_traceroute=vars.gen.enable_traceroute(),
|
||||||
|
cache_timeout=vars.gen.cache_timeout(),
|
||||||
|
message_rate_limit_query=vars.gen.message_rate_limit_query(),
|
||||||
|
# Branding
|
||||||
|
site_title=vars.brand.site_title(),
|
||||||
title=vars.brand.title(),
|
title=vars.brand.title(),
|
||||||
subtitle=vars.brand.subtitle(),
|
subtitle=vars.brand.subtitle(),
|
||||||
title_mode=vars.brand.title_mode(),
|
title_mode=vars.brand.title_mode(),
|
||||||
|
|
@ -60,10 +64,12 @@ class html:
|
||||||
text_help_bgp_aspath=vars.brand.text_help_bgp_aspath(),
|
text_help_bgp_aspath=vars.brand.text_help_bgp_aspath(),
|
||||||
text_help_ping=vars.brand.text_help_ping(),
|
text_help_ping=vars.brand.text_help_ping(),
|
||||||
text_help_traceroute=vars.brand.text_help_traceroute(),
|
text_help_traceroute=vars.brand.text_help_traceroute(),
|
||||||
message_rate_limit_query=vars.gen.message_rate_limit_query(),
|
|
||||||
text_limiter_title=vars.brand.text_limiter_title(),
|
text_limiter_title=vars.brand.text_limiter_title(),
|
||||||
text_limiter_subtitle=vars.brand.text_limiter_subtitle(),
|
text_limiter_subtitle=vars.brand.text_limiter_subtitle(),
|
||||||
cache_timeout=vars.gen.cache_timeout(),
|
# Devices
|
||||||
|
device_networks=vars.dev.networks(),
|
||||||
|
# device_location=vars.dev.location(),
|
||||||
|
device_name=vars.dev.name(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@
|
||||||
<div class="control has-icons-left">
|
<div class="control has-icons-left">
|
||||||
<div class="select is-medium is-rounded">
|
<div class="select is-medium is-rounded">
|
||||||
<select id="network" name="network">
|
<select id="network" name="network">
|
||||||
<option value="" disabled></option>
|
{% for net in device_networks %}
|
||||||
|
<option value="{{ net }}">AS{{ net }}</option>
|
||||||
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<span class="icon is-left"><i class="icofont-cloudapp"></i></span>
|
<span class="icon is-left"><i class="icofont-cloudapp"></i></span>
|
||||||
|
|
@ -93,7 +95,7 @@
|
||||||
<div class="control has-icons-left">
|
<div class="control has-icons-left">
|
||||||
<div class="select is-medium is-rounded">
|
<div class="select is-medium is-rounded">
|
||||||
<select id="router">
|
<select id="router">
|
||||||
<option selected disabled>{{ text_location }}</option>
|
<option id="text_location" selected disabled>{{ text_location }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<span class="icon is-left"><i class="icofont-globe"></i></span>
|
<span class="icon is-left"><i class="icofont-globe"></i></span>
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,38 @@ config = toml.load(open("./config/config.toml"))
|
||||||
# Filter config to branding variables
|
# Filter config to branding variables
|
||||||
branding = config["branding"]
|
branding = config["branding"]
|
||||||
|
|
||||||
# Filter config to generale variables
|
# Filter config to general variables
|
||||||
general = config["general"]
|
general = config["general"]
|
||||||
|
|
||||||
# Functions to import config variables and return default values if undefined
|
# Load TOML devices file
|
||||||
|
devices = toml.load(open("./config/devices.toml"))
|
||||||
|
# Filter config to router list
|
||||||
|
routers_list = devices["router"]
|
||||||
|
|
||||||
|
|
||||||
|
class dev:
|
||||||
|
"""Functions to import device variables"""
|
||||||
|
|
||||||
|
def networks():
|
||||||
|
asn_dict = dict()
|
||||||
|
for r in routers_list:
|
||||||
|
asn = r["asn"]
|
||||||
|
if asn in asn_dict:
|
||||||
|
asn_dict[asn].append(r["location"])
|
||||||
|
else:
|
||||||
|
asn_dict[asn] = [r["location"]]
|
||||||
|
return asn_dict
|
||||||
|
|
||||||
|
def name():
|
||||||
|
list = []
|
||||||
|
for r in routers_list:
|
||||||
|
list.append(str(r["name"]))
|
||||||
|
return list
|
||||||
|
|
||||||
|
|
||||||
class gen:
|
class gen:
|
||||||
|
"""Functions to import config variables and return default values if undefined"""
|
||||||
|
|
||||||
def primary_asn():
|
def primary_asn():
|
||||||
list = []
|
list = []
|
||||||
for g in general:
|
for g in general:
|
||||||
|
|
@ -144,6 +171,8 @@ class gen:
|
||||||
|
|
||||||
|
|
||||||
class brand:
|
class brand:
|
||||||
|
"""Functions to import branding variables and return default values if undefined"""
|
||||||
|
|
||||||
def site_title():
|
def site_title():
|
||||||
list = []
|
list = []
|
||||||
for t in branding:
|
for t in branding:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue