Add app.py
This commit is contained in:
parent
063eeaa14e
commit
1579212485
1 changed files with 597 additions and 0 deletions
597
app.py
Normal file
597
app.py
Normal file
|
|
@ -0,0 +1,597 @@
|
|||
import json
|
||||
import subprocess
|
||||
from jinja2 import Template
|
||||
from flask import Flask, render_template_string, jsonify, url_for
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def run_bgp_curl_command():
|
||||
curl_command = [
|
||||
"curl", "-k", "--location", "--request", "POST", "https://ip:port/show",
|
||||
"--form", "data={\"op\": \"show\", \"path\": [\"bgp\", \"summ\"]}",
|
||||
"--form", "key=key"
|
||||
]
|
||||
response = subprocess.check_output(curl_command, text=True)
|
||||
return json.loads(response)
|
||||
|
||||
def run_arp_curl_command():
|
||||
curl_command = [
|
||||
"curl", "-k", "--location", "--request", "POST", "https://ip:port/show",
|
||||
"--form", "data={\"op\": \"show\", \"path\": [\"arp\"]}",
|
||||
"--form", "key=key"
|
||||
]
|
||||
response = subprocess.check_output(curl_command, text=True)
|
||||
return json.loads(response)
|
||||
|
||||
def run_interfaces_curl_command():
|
||||
curl_command = [
|
||||
"curl", "-k", "--location", "--request", "POST", "https://ip:port/show",
|
||||
"--form", "data={\"op\": \"show\", \"path\": [\"interfaces\"]}",
|
||||
"--form", "key=key"
|
||||
]
|
||||
response = subprocess.check_output(curl_command, text=True)
|
||||
return json.loads(response)
|
||||
|
||||
def parse_bgp_data(data):
|
||||
ipv4_section = ""
|
||||
ipv6_section = ""
|
||||
ipv4_info = {}
|
||||
ipv6_info = {}
|
||||
|
||||
if "data" in data:
|
||||
raw_data = data["data"]
|
||||
|
||||
if "IPv4 Unicast Summary" in raw_data:
|
||||
ipv4_raw = raw_data.split("IPv4 Unicast Summary (VRF default):")[1]
|
||||
ipv4_section = ipv4_raw.split("IPv6 Unicast Summary (VRF default):")[0].strip()
|
||||
ipv4_info = extract_bgp_info(ipv4_raw)
|
||||
|
||||
if "IPv6 Unicast Summary" in raw_data:
|
||||
ipv6_raw = raw_data.split("IPv6 Unicast Summary (VRF default):")[1].strip()
|
||||
ipv6_section = ipv6_raw
|
||||
ipv6_info = extract_bgp_info(ipv6_raw)
|
||||
|
||||
def process_peers(peer_data):
|
||||
peers = []
|
||||
for line in peer_data.split("\n"):
|
||||
if line.strip().startswith("Neighbor"):
|
||||
continue
|
||||
if line.strip():
|
||||
peer_info = line.split()
|
||||
if len(peer_info) >= 12:
|
||||
peers.append({
|
||||
"neighbor": peer_info[0],
|
||||
"version": peer_info[1],
|
||||
"as_number": peer_info[2],
|
||||
"msg_received": peer_info[3],
|
||||
"msg_sent": peer_info[4],
|
||||
"table_version": peer_info[5],
|
||||
"in_queue": peer_info[6],
|
||||
"out_queue": peer_info[7],
|
||||
"up_down": peer_info[8],
|
||||
"state_pfx_rcd": peer_info[9],
|
||||
"prefix_sent": peer_info[10],
|
||||
"description": " ".join(peer_info[11:])
|
||||
})
|
||||
return peers
|
||||
|
||||
ipv4_peers = process_peers(ipv4_section)
|
||||
ipv6_peers = process_peers(ipv6_section)
|
||||
|
||||
return ipv4_info, ipv4_peers, ipv6_info, ipv6_peers
|
||||
|
||||
def extract_bgp_info(raw_data):
|
||||
lines = raw_data.split("\n")
|
||||
info = {}
|
||||
for line in lines:
|
||||
if "BGP router identifier" in line:
|
||||
parts = line.split(",")
|
||||
info["router_id"] = parts[0].split("identifier")[1].strip()
|
||||
info["local_as"] = parts[1].split("number")[1].strip().split(" ")[0]
|
||||
if "vrf-id" in parts[-1]:
|
||||
info["vrf_id"] = parts[-1].split("vrf-id")[1].strip()
|
||||
if "BGP table version" in line:
|
||||
info["table_version"] = line.split("version")[1].strip()
|
||||
if "RIB entries" in line:
|
||||
parts = line.split(",")
|
||||
info["rib_entries"] = parts[0].split("entries")[1].strip()
|
||||
info["rib_memory"] = parts[1].split("using")[1].strip()
|
||||
if "Peers" in line:
|
||||
parts = line.split(",")
|
||||
info["peers"] = parts[0].split("Peers")[1].strip()
|
||||
info["peers_memory"] = parts[1].split("using")[1].strip()
|
||||
return info
|
||||
|
||||
def parse_arp_data(data):
|
||||
arp_table = []
|
||||
|
||||
if "data" in data:
|
||||
raw_data = data["data"]
|
||||
|
||||
for line in raw_data.split("\n"):
|
||||
if line.strip() and not line.startswith("Address") and "---" not in line:
|
||||
arp_info = line.split()
|
||||
if len(arp_info) >= 4:
|
||||
arp_table.append({
|
||||
"address": arp_info[0],
|
||||
"interface": arp_info[1],
|
||||
"link_layer_address": arp_info[2],
|
||||
"state": arp_info[3]
|
||||
})
|
||||
|
||||
return arp_table
|
||||
|
||||
def parse_interface_data(data):
|
||||
interface_table = []
|
||||
|
||||
if "data" in data:
|
||||
raw_data = data["data"]
|
||||
|
||||
for line in raw_data.split("\n"):
|
||||
if line.startswith("Interface") and "IP Address" in line:
|
||||
continue
|
||||
|
||||
if line.startswith("Codes:"):
|
||||
continue
|
||||
|
||||
if line.strip().startswith('-'):
|
||||
continue
|
||||
|
||||
if line.strip():
|
||||
interface_info = line.split()
|
||||
if len(interface_info) >= 6:
|
||||
interface_table.append({
|
||||
"interface": interface_info[0],
|
||||
"ip_address": interface_info[1] if interface_info[1] != '-' else 'N/A',
|
||||
"mac_address": interface_info[2],
|
||||
"vrf": interface_info[3],
|
||||
"mtu": interface_info[4],
|
||||
"status": interface_info[5],
|
||||
"description": " ".join(interface_info[6:])
|
||||
})
|
||||
|
||||
return interface_table
|
||||
|
||||
def generate_bgp_html_table(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers):
|
||||
html_template = """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>BGP Table</title>
|
||||
<link rel="icon" type="image/png" href="../static/img/cropped-Pixelhosting-logo-favicon-32x32.png">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="../static/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Core1.Doet.pixelHosting.nl</h1>
|
||||
<p>BGP Table</p>
|
||||
</header>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #07AAF9;">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav justify-content-center w-100">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/bgp">BGP Summary</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/arp">ARP Tabel</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/interfaces">Interfaces Table</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
|
||||
<section id="bgp-v4">
|
||||
<h4>IPv4 Unicast Summary</h4>
|
||||
<p>BGP Router ID: {{ ipv4_info.router_id }}, Local AS Number: {{ ipv4_info.local_as }} VRF ID: {{ ipv4_info.vrf_id }}</p>
|
||||
<p>BGP Table Version: {{ ipv4_info.table_version }}</p>
|
||||
<p>RIB Entries: {{ ipv4_info.rib_entries }}, using {{ ipv4_info.rib_memory }}</p>
|
||||
<p>Peers: {{ ipv4_info.peers }}, using {{ ipv4_info.peers_memory }}</p>
|
||||
<input type="text" id="ipv4Search" class="form-control w-100" placeholder="Search in IPv4 table..." onkeyup="filterTable('ipv4Search', 'ipv4Table')">
|
||||
<table class="striped" id="ipv4Table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Neighbor</th>
|
||||
<th>Version (V)</th>
|
||||
<th>AS Number</th>
|
||||
<th>Messages Received</th>
|
||||
<th>Messages Sent</th>
|
||||
<th>Table Version</th>
|
||||
<th>Inbound Queue (InQ)</th>
|
||||
<th>Outbound Queue (OutQ)</th>
|
||||
<th>Up/Down</th>
|
||||
<th>State/PfxRcd</th>
|
||||
<th>Prefix Sent (PfxSnt)</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for peer in ipv4_peers %}
|
||||
<tr>
|
||||
<td>{{ peer.neighbor }}</td>
|
||||
<td>{{ peer.version }}</td>
|
||||
<td>{{ peer.as_number }}</td>
|
||||
<td>{{ peer.msg_received }}</td>
|
||||
<td>{{ peer.msg_sent }}</td>
|
||||
<td>{{ peer.table_version }}</td>
|
||||
<td>{{ peer.in_queue }}</td>
|
||||
<td>{{ peer.out_queue }}</td>
|
||||
<td>{{ peer.up_down }}</td>
|
||||
<td>{{ peer.state_pfx_rcd }}</td>
|
||||
<td>{{ peer.prefix_sent }}</td>
|
||||
<td>{{ peer.description }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="/bgp/json">JSON version</a></p>
|
||||
</section>
|
||||
|
||||
<section id="bgp-v6">
|
||||
<h4>IPv6 Unicast Summary</h4>
|
||||
<p>BGP Router ID: {{ ipv6_info.router_id }}, Local AS Number: {{ ipv6_info.local_as }} VRF ID: {{ ipv6_info.vrf_id }}</p>
|
||||
<p>BGP Table Version: {{ ipv6_info.table_version }}</p>
|
||||
<p>RIB Entries: {{ ipv6_info.rib_entries }}, using {{ ipv6_info.rib_memory }}</p>
|
||||
<p>Peers: {{ ipv6_info.peers }}, using {{ ipv6_info.peers_memory }}</p>
|
||||
<input type="text" id="ipv6Search" class="form-control w-100" placeholder="Search in IPv6 table..." onkeyup="filterTable('ipv6Search', 'ipv6Table')">
|
||||
<table class="striped" id="ipv6Table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Neighbor</th>
|
||||
<th>Version (V)</th>
|
||||
<th>AS Number</th>
|
||||
<th>Messages Received</th>
|
||||
<th>Messages Sent</th>
|
||||
<th>Table Version</th>
|
||||
<th>Inbound Queue (InQ)</th>
|
||||
<th>Outbound Queue (OutQ)</th>
|
||||
<th>Up/Down</th>
|
||||
<th>State/PfxRcd</th>
|
||||
<th>Prefix Sent (PfxSnt)</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for peer in ipv6_peers %}
|
||||
<tr>
|
||||
<td>{{ peer.neighbor }}</td>
|
||||
<td>{{ peer.version }}</td>
|
||||
<td>{{ peer.as_number }}</td>
|
||||
<td>{{ peer.msg_received }}</td>
|
||||
<td>{{ peer.msg_sent }}</td>
|
||||
<td>{{ peer.table_version }}</td>
|
||||
<td>{{ peer.in_queue }}</td>
|
||||
<td>{{ peer.out_queue }}</td>
|
||||
<td>{{ peer.up_down }}</td>
|
||||
<td>{{ peer.state_pfx_rcd }}</td>
|
||||
<td>{{ peer.prefix_sent }}</td>
|
||||
<td>{{ peer.description }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="/bgp/json">JSON version</a></p>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2025 AS215085 (PixelHosting). All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
||||
<script>
|
||||
function filterTable(searchInputId, tableId) {
|
||||
var input, filter, table, tr, td, i, j, txtValue;
|
||||
input = document.getElementById(searchInputId);
|
||||
filter = input.value.toUpperCase();
|
||||
table = document.getElementById(tableId);
|
||||
tr = table.getElementsByTagName("tr");
|
||||
|
||||
for (i = 1; i < tr.length; i++) {
|
||||
tr[i].style.display = "none";
|
||||
td = tr[i].getElementsByTagName("td");
|
||||
for (j = 0; j < td.length; j++) {
|
||||
if (td[j]) {
|
||||
txtValue = td[j].textContent || td[j].innerText;
|
||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
||||
tr[i].style.display = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
template = Template(html_template)
|
||||
html_output = template.render(ipv4_info=ipv4_info, ipv4_peers=ipv4_peers, ipv6_info=ipv6_info, ipv6_peers=ipv6_peers)
|
||||
|
||||
return html_output
|
||||
|
||||
def generate_arp_html_table(arp_table):
|
||||
html_template = """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ARP Table</title>
|
||||
<link rel="icon" type="image/png" href="../static/img/cropped-Pixelhosting-logo-favicon-32x32.png">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="../static/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Core1.Doet.pixelHosting.nl</h1>
|
||||
<p>ARP Table</p>
|
||||
</header>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #07AAF9;">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav justify-content-center w-100">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/bgp">BGP Summary</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/arp">ARP Tabel</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/interfaces">Interfaces Table</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
|
||||
<section id="arp">
|
||||
<input type="text" id="arpSearch" class="form-control w-100" placeholder="Search in ARP table..." onkeyup="filterTable('arpSearch', 'arpTable')">
|
||||
<table class="striped" id="arpTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<th>Interface</th>
|
||||
<th>Link Layer Address</th>
|
||||
<th>State</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for entry in arp_table %}
|
||||
<tr>
|
||||
<td>{{ entry.address }}</td>
|
||||
<td>{{ entry.interface }}</td>
|
||||
<td>{{ entry.link_layer_address }}</td>
|
||||
<td>{{ entry.state }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="/arp/json">JSON version</a></p>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2025 AS215085 (PixelHosting). All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
||||
<script>
|
||||
function filterTable(searchInputId, tableId) {
|
||||
var input, filter, table, tr, td, i, j, txtValue;
|
||||
input = document.getElementById(searchInputId);
|
||||
filter = input.value.toUpperCase();
|
||||
table = document.getElementById(tableId);
|
||||
tr = table.getElementsByTagName("tr");
|
||||
|
||||
for (i = 1; i < tr.length; i++) {
|
||||
tr[i].style.display = "none";
|
||||
td = tr[i].getElementsByTagName("td");
|
||||
for (j = 0; j < td.length; j++) {
|
||||
if (td[j]) {
|
||||
txtValue = td[j].textContent || td[j].innerText;
|
||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
||||
tr[i].style.display = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
template = Template(html_template)
|
||||
html_output = template.render(arp_table=arp_table)
|
||||
|
||||
return html_output
|
||||
|
||||
def generate_interfaces_html_table(interface_table):
|
||||
html_template = """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Interface Table</title>
|
||||
<link rel="icon" type="image/png" href="../static/img/cropped-Pixelhosting-logo-favicon-32x32.png">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="../static/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Core1.Doet.pixelHosting.nl</h1>
|
||||
<p>Interface Table</p>
|
||||
</header>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #07AAF9;">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav justify-content-center w-100">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/bgp">BGP Summary</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/arp">ARP Tabel</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white" href="/interfaces">Interfaces Table</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
|
||||
<section id="interfaces">
|
||||
<input type="text" id="interfaceSearch" class="form-control w-100" placeholder="Search in Interface table..." onkeyup="filterTable('interfaceSearch', 'interfaceTable')">
|
||||
<p>Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down</p>
|
||||
<table class="striped" id="interfaceTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Interface</th>
|
||||
<th>IP Address</th>
|
||||
<th>MAC Address</th>
|
||||
<th>VRF</th>
|
||||
<th>MTU</th>
|
||||
<th>Status</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for entry in interface_table %}
|
||||
<tr>
|
||||
<td>{{ entry.interface }}</td>
|
||||
<td>{{ entry.ip_address }}</td>
|
||||
<td>{{ entry.mac_address }}</td>
|
||||
<td>{{ entry.vrf }}</td>
|
||||
<td>{{ entry.mtu }}</td>
|
||||
<td>{{ entry.status }}</td>
|
||||
<td>{{ entry.description }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="/interfaces/json">JSON version</a></p>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2025 AS215085 (PixelHosting). All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
||||
<script>
|
||||
function filterTable(searchInputId, tableId) {
|
||||
var input, filter, table, tr, td, i, j, txtValue;
|
||||
input = document.getElementById(searchInputId);
|
||||
filter = input.value.toUpperCase();
|
||||
table = document.getElementById(tableId);
|
||||
tr = table.getElementsByTagName("tr");
|
||||
|
||||
for (i = 1; i < tr.length; i++) {
|
||||
tr[i].style.display = "none";
|
||||
td = tr[i].getElementsByTagName("td");
|
||||
for (j = 0; j < td.length; j++) {
|
||||
if (td[j]) {
|
||||
txtValue = td[j].textContent || td[j].innerText;
|
||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
||||
tr[i].style.display = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
template = Template(html_template)
|
||||
html_output = template.render(interface_table=interface_table)
|
||||
|
||||
return html_output
|
||||
|
||||
def generate_bgp_json(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers):
|
||||
return {
|
||||
"ipv4_info": ipv4_info,
|
||||
"ipv4_peers": ipv4_peers,
|
||||
"ipv6_info": ipv6_info,
|
||||
"ipv6_peers": ipv6_peers
|
||||
}
|
||||
|
||||
def generate_arp_json(arp_table):
|
||||
return {"arp_table": arp_table}
|
||||
|
||||
@app.route("/bgp")
|
||||
def bgp():
|
||||
bgp_data = run_bgp_curl_command()
|
||||
ipv4_info, ipv4_peers, ipv6_info, ipv6_peers = parse_bgp_data(bgp_data)
|
||||
bgp_html = generate_bgp_html_table(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers)
|
||||
return render_template_string(bgp_html)
|
||||
|
||||
@app.route("/bgp/json")
|
||||
def bgp_json():
|
||||
bgp_data = run_bgp_curl_command()
|
||||
ipv4_info, ipv4_peers, ipv6_info, ipv6_peers = parse_bgp_data(bgp_data)
|
||||
return jsonify(generate_bgp_json(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers))
|
||||
|
||||
@app.route("/arp")
|
||||
def arp():
|
||||
arp_data = run_arp_curl_command()
|
||||
arp_table = parse_arp_data(arp_data)
|
||||
arp_html = generate_arp_html_table(arp_table)
|
||||
return render_template_string(arp_html)
|
||||
|
||||
@app.route("/arp/json")
|
||||
def arp_json():
|
||||
arp_data = run_arp_curl_command()
|
||||
arp_table = parse_arp_data(arp_data)
|
||||
return jsonify(generate_arp_json(arp_table))
|
||||
|
||||
@app.route('/interfaces')
|
||||
def interface_table_page():
|
||||
data = run_interfaces_curl_command()
|
||||
interface_table = parse_interface_data(data)
|
||||
interfaces_html = generate_interfaces_html_table(interface_table) # Correct variable name
|
||||
return render_template_string(interfaces_html) # Render the correct variable
|
||||
|
||||
@app.route('/interfaces/json')
|
||||
def interface_table_summary_json():
|
||||
data = run_interfaces_curl_command()
|
||||
interface_table = parse_interface_data(data)
|
||||
return jsonify({"interface_table": interface_table})
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, host="0.0.0.0", port=5000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue