Compare commits
No commits in common. "522a49a7f60c2562dad0565282c7437b3d6abc92" and "5af65b5f31674bbfef0ad5823da820f4b1072612" have entirely different histories.
522a49a7f6
...
5af65b5f31
2 changed files with 15 additions and 13 deletions
|
@ -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,13 +62,15 @@ function add_identity($name, $mac)
|
|||
exit();
|
||||
}
|
||||
|
||||
function remove_identity($name)
|
||||
function remove_identity($mac)
|
||||
{
|
||||
if (preg_match('/' . NAME_PATTERN . '/', $name) != 1) {
|
||||
if (preg_match('/' . MAC_PATTERN . '/', $mac) != 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);
|
||||
|
@ -76,7 +78,7 @@ function remove_identity($name)
|
|||
$new_identities = array();
|
||||
|
||||
foreach ($identities as $identity) {
|
||||
if ($identity['name'] != $name) {
|
||||
if ($identity['mac_hash'] != $hashed_mac) {
|
||||
array_push($new_identities, $identity);
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +101,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||
isset($_POST['mac'])
|
||||
) {
|
||||
add_identity($_POST['name'], $_POST['mac']);
|
||||
} else if (isset($_POST['remove-name'])) {
|
||||
remove_identity($_POST['remove-name']);
|
||||
} else if (isset($_POST['remove-mac'])) {
|
||||
remove_identity($_POST['remove-mac']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -174,7 +176,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-name" pattern="<?php echo NAME_PATTERN; ?>" placeholder="Name" value="" required /><br>
|
||||
<input class="form-control" type="text" name="remove-mac" pattern="<?php echo MAC_PATTERN; ?>" placeholder="MAC-Adresse" value="" required /><br>
|
||||
<button class="btn btn-primary" type="submit">Entfernen</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -61,7 +61,7 @@ http_response_code(200);
|
|||
|
||||
$present = array(
|
||||
"timestamp" => time(),
|
||||
"names" => sort($decoded)
|
||||
"names" => $decoded
|
||||
);
|
||||
|
||||
file_put_contents($present_file, json_encode($present));
|
||||
|
|
Loading…
Reference in a new issue