From 7875b06fd6d4ad8c9521b2492c59be15a1bf3452 Mon Sep 17 00:00:00 2001 From: martinaabojensen Date: Sat, 30 Aug 2025 22:31:26 +0000 Subject: [PATCH] Updated vpn_status.html to handle silent API failures without showing an error. --- core_functions.py | 3 +- hello.py | 0 system_info.json | 2 +- templates/pages/users.html | 2 - templates/pages/vpn_status.html | 92 ++++++++++++++++++++++++++++++++- 5 files changed, 93 insertions(+), 6 deletions(-) delete mode 100644 hello.py diff --git a/core_functions.py b/core_functions.py index 054cf59..e5a8fa1 100644 --- a/core_functions.py +++ b/core_functions.py @@ -18,7 +18,8 @@ SERIAL_PASSWORDS = { "3M1D2211Z3": "EP5G!f15878b4af20", "3M1D10146B": "EP5G!076689528baf", "3M1D10146G": "EP5G!c3b0072cabf5", "3M1D2211Z1": "EP5G!65b22ae8617a", "3M1D19125H": "EP5G!da3c04fde559", "3M1D19125G": "EP5G!b73f98633108", - "3M1D19125F": "EP5G!e61201fb9234", "3M1D1R16M4": "EP5G!ca439b544329" + "3M1D19125F": "EP5G!e61201fb9234", "3M1D1R16M4": "EP5G!ca439b544329", + "3M1D10146F": "EP5G!d1343c34875d" } def list_home_network_keys(host_ip, token): diff --git a/hello.py b/hello.py deleted file mode 100644 index e69de29..0000000 diff --git a/system_info.json b/system_info.json index 79e1ab0..726ab3d 100644 --- a/system_info.json +++ b/system_info.json @@ -16,7 +16,7 @@ "machine_id": "7ebd37b3c5a44ff7acafc84fa3af449d", "num_cpu": 4, "virtualization": "kvm", - "target_host_ip": "100.93.1.43", + "target_host_ip": "100.92.0.238", "mgmt": { "cidr": "192.168.105.156/24", "gw": "192.168.105.1" diff --git a/templates/pages/users.html b/templates/pages/users.html index 4bd0b29..63f73e7 100644 --- a/templates/pages/users.html +++ b/templates/pages/users.html @@ -12,8 +12,6 @@ diff --git a/templates/pages/vpn_status.html b/templates/pages/vpn_status.html index 83e279a..8d6b102 100644 --- a/templates/pages/vpn_status.html +++ b/templates/pages/vpn_status.html @@ -12,8 +12,6 @@ @@ -29,7 +27,28 @@

Results

Loading...
+ +
+ +
+ + + +
+
+
+
+ {% endblock %} {% block extra_scripts %} @@ -76,5 +95,74 @@ actionLink.innerHTML = ` Restart`; } }); + + // Helper to safely call API and handle non-JSON errors + async function apiCall(url, data, showAlert = true) { + try { + const res = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data) + }); + const text = await res.text(); + try { + return JSON.parse(text); + } catch (e) { + if (showAlert) { + alert("Error: Server returned invalid response. Check server logs."); + } + return null; + } + } catch (err) { + if (showAlert) { + alert("Error: Could not reach server."); + } + return null; + } + } + + document.getElementById('restart-ipv6-btn').addEventListener('click', async () => { + const serial = document.getElementById('serial-input').value.trim(); + const subnet = document.getElementById('ipv6-subnet-input').value.trim(); + const dashboard = document.getElementById('dashboard-select').value; + const btn = document.getElementById('restart-ipv6-btn'); + const resultDiv = document.getElementById('serial-password-result'); + + // Validate input + if (!serial) { + alert('Please enter a Serial.'); + return; + } + if (!subnet || !subnet.match(/^fd[0-9a-fA-F:]+\/\d+$/)) { + alert('Please enter a valid IPv6 subnet (e.g. fd14:6666::45:0/112).'); + return; + } + + btn.disabled = true; + btn.innerHTML = ` Sending...`; + resultDiv.innerHTML = ''; + + // Lookup password first + const pwResult = await apiCall('/api/m2000/lookup_password', { dashboard, serial }, false); + if (pwResult && pwResult.password) { + resultDiv.innerHTML = `Password: ${pwResult.password}`; + } else if (pwResult && pwResult.error) { + resultDiv.innerHTML = `Password not found.`; + } else { + // Do not show anything if the API failed silently + resultDiv.innerHTML = ''; + } + + // Restart VPN + const result = await apiCall('/api/m2000/restart', { dashboard, serial, subnet }, false); + if (result && result.message) { + alert(result.message); + } else if (!result) { + alert("Error: Could not restart VPN. Check server logs."); + } + + btn.disabled = false; + btn.innerHTML = 'Restart VPN'; + }); {% endblock %} \ No newline at end of file