From ab31b191a94a08fe4fe177a3321f14a00c5a8949 Mon Sep 17 00:00:00 2001 From: Jonathan Flueren Date: Wed, 16 Aug 2023 16:53:38 +0200 Subject: [PATCH] Error on unknown dev, format --- README.md | 2 +- website/index.php | 9 ++++++++- website/update.php | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 32cc93d..a8066cc 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Dependencies: Configs to change: - `scanner/scan.sh`: - WiFi adapter name - - network restart routines + - network restart routines (front-end) - `scanner/upload.py`: - URLs for webhook and identities - webhook secret diff --git a/website/index.php b/website/index.php index 0700fc4..fa84f0a 100644 --- a/website/index.php +++ b/website/index.php @@ -71,6 +71,8 @@ function remove_identity($mac) $hashed_mac = hash_mac($mac); + $url = strtok($_SERVER['REQUEST_URI'], '?'); + $identities = json_decode(file_get_contents(IDENTITIES_FILE), true); $new_identities = array(); @@ -84,9 +86,14 @@ function remove_identity($mac) $_SESSION['form_success'] = true; $_SESSION['form_success_message'] = 'Identity successfully removed.'; - header("Location: " . strtok($_SERVER['REQUEST_URI'], '?'), true, 303); + header("Location: " . $url, true, 303); exit(); } + + $_SESSION['form_success'] = false; + $_SESSION['form_success_message'] = 'Identity not found.'; + header("Location: " . $url, true, 303); + exit(); } if ($_SERVER['REQUEST_METHOD'] == "POST") { diff --git a/website/update.php b/website/update.php index 4955543..c670da4 100644 --- a/website/update.php +++ b/website/update.php @@ -5,7 +5,7 @@ $present_file = 'present.json'; // check for POST request if ($_SERVER['REQUEST_METHOD'] != 'POST') { - error_log('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']); + error_log('FAILED - not POST - ' . $_SERVER['REQUEST_METHOD']); http_response_code(405); exit(); } @@ -14,7 +14,7 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST') { $content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : ''; if ($content_type != 'application/json') { - error_log('FAILED - not application/json - '. $content_type); + error_log('FAILED - not application/json - ' . $content_type); http_response_code(400); exit(); } @@ -51,7 +51,7 @@ $decoded = json_decode($payload, true); // check for json decode errors if (json_last_error() !== JSON_ERROR_NONE) { - error_log('FAILED - json decode - '. json_last_error()); + error_log('FAILED - json decode - ' . json_last_error()); http_response_code(400); exit(); } @@ -64,4 +64,4 @@ $present = array( "names" => $decoded ); -file_put_contents($present_file, json_encode($present)); \ No newline at end of file +file_put_contents($present_file, json_encode($present));