From 91488a7a0e4115ac2a25d53ad0b0e36efd3b30d4 Mon Sep 17 00:00:00 2001 From: Halcy0nic Date: Mon, 28 Oct 2024 11:03:33 -0600 Subject: [PATCH] Fix: Fixing client side regex for gateway ids --- app.py | 19 ++- templates/index.html | 390 +++++++++++++++++++++++-------------------- 2 files changed, 216 insertions(+), 193 deletions(-) diff --git a/app.py b/app.py index 5ceaca6..e2d83ac 100644 --- a/app.py +++ b/app.py @@ -386,7 +386,7 @@ def index(): Returns: str: The rendered HTML content for the index page. """ - return render_template('index.html') + return render_template('index.html', gateway_ips=gateway_ips) @app.route('/analysis') def analysis(): @@ -727,21 +727,22 @@ def set_gateways(): """ global gateway_ips data = request.form - for key in [f'gateway{i}' for i in range(1, 11)]: + + # Create an ordered dictionary of gateways + ordered_gateways = {} + for i in range(1, 11): + key = f'gateway{i}' input_ip = data.get(key, '').strip() - if input_ip: - try: - ipaddress.ip_address(input_ip) - gateway_ips[key] = input_ip - except ValueError: - return jsonify({"error": f"Invalid IP address provided for {key}"}), 400 + ordered_gateways[key] = input_ip + + # Update the global gateway_ips with ordered data + gateway_ips.update(ordered_gateways) for gateway, ip_address in gateway_ips.items(): print(f"Gateway {gateway} has IP address: {ip_address}") return jsonify({"message": "Gateway IPs updated successfully"}), 200 - @app.route('/get_gateways', methods=['GET']) def get_gateways(): return jsonify(gateway_ips) diff --git a/templates/index.html b/templates/index.html index 0481b8b..d712c8e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -682,189 +682,192 @@

-
-

Configure LoRaWAN Gateways

-
-

- The Configure LoRaWAN Gateway section allows you to set up to ten Dragino LPS8N LoRaWAN gateways. -

-
    -
  • Enter the IP address for each gateway you want to configure.
  • -
  • Leave the input field empty to keep the current IP or disconnect an existing one.
  • -
  • All entered IP addresses are validated for correct formatting.
  • -
  • Once configured, the application automatically retrieves and stores LoRaWAN traffic from each active gateway.
  • -
  • Access and analyze stored traffic in 'survey mode'.
  • -
-

Empty values will be ignored, and the Gateway IP address will remain unchanged

-
-
-
- -
-
- - + + + + async init() { + await this.loadGatewayIPs(); // Load IPs first + this.createGatewayInputs(); // Then create inputs with loaded values + this.setupEventListeners(); + await this.checkAllGateways(); // Check gateway statuses + } + + } + + // Initialize the gateway manager + document.addEventListener('DOMContentLoaded', () => { + new GatewayManager(); + }); + +