true, CURLOPT_TIMEOUT => 5, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Accept: application/json' ] ]); if (!empty($data)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } $response = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpcode !== 200 || !$response) { return null; } return json_decode($response, true); } catch (Exception $e) { return null; } } function logout_user(): void { $_SESSION = []; session_destroy(); setcookie(COOKIE_NAME,'',[ 'expires'=>time()-3600, 'path'=>'/', 'secure'=>is_https_request(), 'httponly'=>true, 'samesite'=>'Strict' ]); } /* ===================================================== Redirect Handling ===================================================== */ $redirectTo = validate_local_path($_GET['next'] ?? null); /* ===================================================== Web Protection Disabled ===================================================== */ if ($nax_WebProtection !== 'true') { if (!is_authenticated()) { login_user(); } safe_redirect(append_hash($redirectTo)); } /* ===================================================== Login Attempt ===================================================== */ if (!empty($_POST['loginpassword'])) { $incomingHash = hash('sha256', $_POST['loginpassword']); if (hash_equals($nax_Password, $incomingHash)) { login_user(); // Handle "Remember Me" if checked if (!empty($_POST['PWRemember'])) { // Generate random token (64-byte hex = 128 chars, use 64 chars) $token = bin2hex(random_bytes(32)); // Call API to save token hash to Parameters table $save_response = call_api('/auth/remember-me/save', [ 'token' => $token ]); // If API call successful, set persistent cookie if ($save_response && isset($save_response['success']) && $save_response['success']) { setcookie(COOKIE_NAME, $token, [ 'expires' => time() + 604800, 'path' => '/', 'secure' => is_https_request(), 'httponly' => true, 'samesite' => 'Strict' ]); } } safe_redirect(append_hash($redirectTo)); } } /* ===================================================== Remember Me Validation ===================================================== */ if (!is_authenticated() && !empty($_COOKIE[COOKIE_NAME])) { // Call API to validate token against stored hash $validate_response = call_api('/auth/validate-remember', [ 'token' => $_COOKIE[COOKIE_NAME] ]); // If API returns valid token, authenticate and redirect if ($validate_response && isset($validate_response['valid']) && $validate_response['valid'] === true) { login_user(); safe_redirect(append_hash($redirectTo)); } } /* ===================================================== Already Logged In ===================================================== */ if (is_authenticated()) { safe_redirect(append_hash($redirectTo)); } /* ===================================================== Login UI Variables ===================================================== */ $login_headline = lang('Login_Toggle_Info_headline'); $login_info = lang('Login_Info'); $login_mode = 'info'; $login_display_mode = 'display:none;'; $login_icon = 'fa-info'; if ($nax_Password === '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92') { $login_info = lang('Login_Default_PWD'); $login_mode = 'danger'; $login_display_mode = 'display:block;'; $login_headline = lang('Login_Toggle_Alert_headline'); $login_icon = 'fa-ban'; } ?> NetAlert X | Log in