Compare commits

..

2 commits

Author SHA1 Message Date
Jonathan Flueren
522a49a7f6 Sort names 2023-08-17 17:12:28 +02:00
Jonathan Flueren
840ef38779 Use name to remove, allow duplicate names 2023-08-17 17:12:28 +02:00
2 changed files with 13 additions and 15 deletions

View file

@ -39,12 +39,12 @@ function add_identity($name, $mac)
$url = strtok($_SERVER['REQUEST_URI'], '?');
foreach ($identities as $identity) {
if ($identity['name'] == $name) {
$_SESSION['form_success'] = false;
$_SESSION['form_success_message'] = 'Name already in use, please choose a different one.';
header("Location: " . $url, true, 303);
exit();
}
//if ($identity['name'] == $name) {
// $_SESSION['form_success'] = false;
// $_SESSION['form_success_message'] = 'Name already in use, please choose a different one.';
// header("Location: " . $url, true, 303);
// exit();
//}
if ($identity['mac_hash'] == $hashed_mac) {
$_SESSION['form_success'] = false;
$_SESSION['form_success_message'] = 'MAC already set up, please remove it first to change name.';
@ -62,15 +62,13 @@ function add_identity($name, $mac)
exit();
}
function remove_identity($mac)
function remove_identity($name)
{
if (preg_match('/' . MAC_PATTERN . '/', $mac) != 1) {
if (preg_match('/' . NAME_PATTERN . '/', $name) != 1) {
http_response_code(400);
die("Bad data");
}
$hashed_mac = hash_mac($mac);
$url = strtok($_SERVER['REQUEST_URI'], '?');
$identities = json_decode(file_get_contents(IDENTITIES_FILE), true);
@ -78,7 +76,7 @@ function remove_identity($mac)
$new_identities = array();
foreach ($identities as $identity) {
if ($identity['mac_hash'] != $hashed_mac) {
if ($identity['name'] != $name) {
array_push($new_identities, $identity);
}
}
@ -101,8 +99,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
isset($_POST['mac'])
) {
add_identity($_POST['name'], $_POST['mac']);
} else if (isset($_POST['remove-mac'])) {
remove_identity($_POST['remove-mac']);
} else if (isset($_POST['remove-name'])) {
remove_identity($_POST['remove-name']);
}
}
?>
@ -176,7 +174,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
<div class="card-body">
<h5 class="card-title">Gerät entfernen</h5>
<form method="POST">
<input class="form-control" type="text" name="remove-mac" pattern="<?php echo MAC_PATTERN; ?>" placeholder="MAC-Adresse" value="" required /><br>
<input class="form-control" type="text" name="remove-name" pattern="<?php echo NAME_PATTERN; ?>" placeholder="Name" value="" required /><br>
<button class="btn btn-primary" type="submit">Entfernen</button>
</form>
</div>

View file

@ -61,7 +61,7 @@ http_response_code(200);
$present = array(
"timestamp" => time(),
"names" => $decoded
"names" => sort($decoded)
);
file_put_contents($present_file, json_encode($present));