diff --git a/docs/img/device_details.png b/docs/img/device_details.png index 6c4308fd1..167a4005b 100755 Binary files a/docs/img/device_details.png and b/docs/img/device_details.png differ diff --git a/front/index.php b/front/index.php index 2e3473262..261ab93c0 100755 --- a/front/index.php +++ b/front/index.php @@ -3,76 +3,185 @@ 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)); } -// Password without Cookie check -> pass and set initial cookie -if (isset ($_POST["loginpassword"]) && $nax_Password === hash('sha256',$_POST["loginpassword"])) -{ - header('Location: devices.php'); - $_SESSION["login"] = 1; - if (isset($_POST['PWRemember'])) {setcookie($CookieSaveLoginName, hash('sha256',$_POST["loginpassword"]), time()+604800);} +/* ===================================================== + Login Attempt +===================================================== */ + +if (!empty($_POST['loginpassword'])) { + + $incomingHash = hash('sha256', $_POST['loginpassword']); + + if (hash_equals($nax_Password, $incomingHash)) { + + login_user(); + + if (!empty($_POST['PWRemember'])) { + $token = bin2hex(random_bytes(32)); + + $_SESSION['remember_token'] = hash('sha256',$token); + + setcookie(COOKIE_NAME,$token,[ + 'expires'=>time()+604800, + 'path'=>'/', + 'secure'=>is_https_request(), + 'httponly'=>true, + 'samesite'=>'Strict' + ]); + } + + safe_redirect(append_hash($redirectTo)); + } } -// active Session or valid cookie (cookie not extends) -if (( isset ($_SESSION["login"]) && ($_SESSION["login"] == 1)) || (isset ($_COOKIE[$CookieSaveLoginName]) && $nax_Password === $_COOKIE[$CookieSaveLoginName])) -{ - header('Location: devices.php'); - $_SESSION["login"] = 1; - if (isset($_POST['PWRemember'])) {setcookie($CookieSaveLoginName, hash('sha256',$_POST["loginpassword"]), time()+604800);} +/* ===================================================== + Remember Me Validation +===================================================== */ + +if (!is_authenticated() && !empty($_COOKIE[COOKIE_NAME]) && !empty($_SESSION['remember_token'])) { + + if (hash_equals($_SESSION['remember_token'], hash('sha256',$_COOKIE[COOKIE_NAME]))) { + 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 = 'danger'; -$login_display_mode = 'display: block;'; -$login_icon = 'fa-info'; - -// no active session, cookie not checked -if (isset ($_SESSION["login"]) == FALSE || $_SESSION["login"] != 1) -{ - if ($nax_Password === '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92') - { +$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_display_mode = 'display:block;'; $login_headline = lang('Login_Toggle_Alert_headline'); $login_icon = 'fa-ban'; - } - else - { - $login_mode = 'info'; - $login_display_mode = 'display: none;'; - $login_headline = lang('Login_Toggle_Info_headline'); - $login_icon = 'fa-info'; - } } - -// ################################################## -// ## Login Processing end -// ################################################## ?> @@ -109,8 +218,13 @@

-
+
+
@@ -119,7 +233,7 @@