Error on unknown dev, format

This commit is contained in:
Jonathan Flueren 2023-08-16 16:53:38 +02:00
parent e5b95ad84a
commit ab31b191a9
3 changed files with 13 additions and 6 deletions

View file

@ -15,7 +15,7 @@ Dependencies:
Configs to change: Configs to change:
- `scanner/scan.sh`: - `scanner/scan.sh`:
- WiFi adapter name - WiFi adapter name
- network restart routines - network restart routines (front-end)
- `scanner/upload.py`: - `scanner/upload.py`:
- URLs for webhook and identities - URLs for webhook and identities
- webhook secret - webhook secret

View file

@ -71,6 +71,8 @@ function remove_identity($mac)
$hashed_mac = hash_mac($mac); $hashed_mac = hash_mac($mac);
$url = strtok($_SERVER['REQUEST_URI'], '?');
$identities = json_decode(file_get_contents(IDENTITIES_FILE), true); $identities = json_decode(file_get_contents(IDENTITIES_FILE), true);
$new_identities = array(); $new_identities = array();
@ -84,9 +86,14 @@ function remove_identity($mac)
$_SESSION['form_success'] = true; $_SESSION['form_success'] = true;
$_SESSION['form_success_message'] = 'Identity successfully removed.'; $_SESSION['form_success_message'] = 'Identity successfully removed.';
header("Location: " . strtok($_SERVER['REQUEST_URI'], '?'), true, 303); header("Location: " . $url, true, 303);
exit(); exit();
} }
$_SESSION['form_success'] = false;
$_SESSION['form_success_message'] = 'Identity not found.';
header("Location: " . $url, true, 303);
exit();
} }
if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_SERVER['REQUEST_METHOD'] == "POST") {

View file

@ -5,7 +5,7 @@ $present_file = 'present.json';
// check for POST request // check for POST request
if ($_SERVER['REQUEST_METHOD'] != 'POST') { 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); http_response_code(405);
exit(); exit();
} }
@ -14,7 +14,7 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : ''; $content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : '';
if ($content_type != 'application/json') { 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); http_response_code(400);
exit(); exit();
} }
@ -51,7 +51,7 @@ $decoded = json_decode($payload, true);
// check for json decode errors // check for json decode errors
if (json_last_error() !== JSON_ERROR_NONE) { 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); http_response_code(400);
exit(); exit();
} }
@ -64,4 +64,4 @@ $present = array(
"names" => $decoded "names" => $decoded
); );
file_put_contents($present_file, json_encode($present)); file_put_contents($present_file, json_encode($present));