<?php



  require './XX_readsettings.php';
  $usepassword = $ShieldSetting_01;
  
  if($usepassword == ""){$usepassword="admin";}

	$ts = time();
  $ip = "none";
  if (!empty($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
  } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  } else {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  session_start();
  if (isset($_POST['login_password'])){
    // Get the form data
    $username = "relayup"; //$_POST['login_username'];
    $password = $_POST['login_password'];
    // echo $_POST['login_password'];
    // echo "usepassword: " . $usepassword . "<br>";
    // echo "password from POST: " . $_POST['login_password'];
    // echo json_encode(['success' => false]);
    // print_r($_SESSION); // Outputs all the session data
    if($password == $usepassword){
      // echo json_encode(['success' => $usepassword]);
        $_SESSION['loggedin'] = true;
        $_SESSION[$username] = "open";
        $_SESSION['username'] = $username;
        echo json_encode(['success' => true]);
        // header("Location: ./home");
        exit;
      } else {
        // echo "Incorrect username!";
        echo json_encode(['success' => false, 'message' => 'Incorrect username or password!']);
        exit;
      }
  }
  session_destroy();
  // header("Location: ./index.html?ts=$ts");
  die('All done!');
  exit;
?>