setTimestamp($present["timestamp"]); function hash_mac($mac) { $normalized_mac = str_replace('-', ':', strtolower($mac)); $hashed_mac = hash('sha256', $normalized_mac); return $hashed_mac; } function add_identity($name, $mac) { if ( preg_match('/' . NAME_PATTERN . '/', $name) != 1 || preg_match('/' . MAC_PATTERN . '/', $mac) != 1 ) { http_response_code(400); die("Bad data"); } $hashed_mac = hash_mac($mac); $identities = json_decode(file_get_contents(IDENTITIES_FILE), true); $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['mac_hash'] == $hashed_mac) { $_SESSION['form_success'] = false; $_SESSION['form_success_message'] = 'MAC already set up, please remove it first to change name.'; header("Location: " . $url, true, 303); exit(); } } array_push($identities, array("name" => $name, "mac_hash" => $hashed_mac)); file_put_contents(IDENTITIES_FILE, json_encode($identities)); $_SESSION['form_success'] = true; $_SESSION['form_success_message'] = 'Identity successfully saved.'; header("Location: " . $url, true, 303); exit(); } function remove_identity($name) { if (preg_match('/' . NAME_PATTERN . '/', $name) != 1) { http_response_code(400); die("Bad data"); } $url = strtok($_SERVER['REQUEST_URI'], '?'); $identities = json_decode(file_get_contents(IDENTITIES_FILE), true); $new_identities = array(); foreach ($identities as $identity) { if ($identity['name'] != $name) { array_push($new_identities, $identity); } } file_put_contents(IDENTITIES_FILE, json_encode($new_identities)); if (count($identities) > count($new_identities)) { $_SESSION['form_success'] = true; $_SESSION['form_success_message'] = 'Identity successfully removed.'; } else { $_SESSION['form_success'] = false; $_SESSION['form_success_message'] = 'Identity not found.'; } header("Location: " . $url, true, 303); exit(); } if ($_SERVER['REQUEST_METHOD'] == "POST") { if ( isset($_POST['name']) && isset($_POST['mac']) ) { add_identity($_POST['name'], $_POST['mac']); } else if (isset($_POST['remove-name'])) { remove_identity($_POST['remove-name']); } } ?> <?php echo PAGE_TITLE; ?>

Jetzt gerade im CZI (letztes Update von format('H:i:s d.m.Y'); ?>)


Name


Neues Gerät tracken


Gerät entfernen