mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
converted network list to jinja instead of ajax query, leaving only 1 ajax query needed
This commit is contained in:
@@ -87,19 +87,6 @@ def testRoute():
|
||||
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
|
||||
@app.route("/routers/<asn>", methods=["GET"])
|
||||
def get_routers(asn):
|
||||
|
@@ -10,7 +10,7 @@ import vars
|
||||
import cmd_parser as parser
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
# Load TOML config file
|
||||
# Load TOML devices file
|
||||
devices = toml.load(open("./config/devices.toml"))
|
||||
# Filter config to router list
|
||||
routers_list = devices["router"]
|
||||
|
@@ -4,7 +4,6 @@ var progress = ($('#progress'));
|
||||
var resultsbox = ($('#resultsbox'));
|
||||
resultsbox.hide();
|
||||
progress.hide();
|
||||
listNetworks ();
|
||||
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(){
|
||||
var defaultasn = $ ( "#network" ).val();
|
||||
$.ajax({
|
||||
@@ -45,6 +31,7 @@ $( document ).ready(function(){
|
||||
|
||||
$('#network').on('change', () => {
|
||||
var asn = $("select[id=network").val()
|
||||
$('#router').children(":not(#text_location)").remove();
|
||||
$.ajax({
|
||||
url: `/routers/${asn}`,
|
||||
type: 'get',
|
||||
|
@@ -29,7 +29,7 @@ class html:
|
||||
elif t == "test":
|
||||
template = env.get_template("templates/429.html")
|
||||
return template.render(
|
||||
site_title=vars.brand.site_title(),
|
||||
# General
|
||||
primary_asn=vars.gen.primary_asn(),
|
||||
google_analytics=vars.gen.google_analytics(),
|
||||
enable_recaptcha=vars.gen.enable_recaptcha(),
|
||||
@@ -38,6 +38,10 @@ class html:
|
||||
enable_bgp_aspath=vars.gen.enable_bgp_aspath(),
|
||||
enable_ping=vars.gen.enable_ping(),
|
||||
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(),
|
||||
subtitle=vars.brand.subtitle(),
|
||||
title_mode=vars.brand.title_mode(),
|
||||
@@ -60,10 +64,12 @@ class html:
|
||||
text_help_bgp_aspath=vars.brand.text_help_bgp_aspath(),
|
||||
text_help_ping=vars.brand.text_help_ping(),
|
||||
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_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="select is-medium is-rounded">
|
||||
<select id="network" name="network">
|
||||
<option value="" disabled></option>
|
||||
{% for net in device_networks %}
|
||||
<option value="{{ net }}">AS{{ net }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<span class="icon is-left"><i class="icofont-cloudapp"></i></span>
|
||||
@@ -93,7 +95,7 @@
|
||||
<div class="control has-icons-left">
|
||||
<div class="select is-medium is-rounded">
|
||||
<select id="router">
|
||||
<option selected disabled>{{ text_location }}</option>
|
||||
<option id="text_location" selected disabled>{{ text_location }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<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
|
||||
branding = config["branding"]
|
||||
|
||||
# Filter config to generale variables
|
||||
# Filter config to general variables
|
||||
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:
|
||||
"""Functions to import config variables and return default values if undefined"""
|
||||
|
||||
def primary_asn():
|
||||
list = []
|
||||
for g in general:
|
||||
@@ -144,6 +171,8 @@ class gen:
|
||||
|
||||
|
||||
class brand:
|
||||
"""Functions to import branding variables and return default values if undefined"""
|
||||
|
||||
def site_title():
|
||||
list = []
|
||||
for t in branding:
|
||||
|
Reference in New Issue
Block a user