<?php

include('includes/functions.php');

if (session_status() == PHP_SESSION_NONE) {

    session_start();

}

$log_check = $db->select('users', '*', 'id = :id', '', [':id' => 1]);

$loggedinuser = !empty($log_check) ? $log_check[0]['username'] : null;



if (!empty($loggedinuser) && isset($_SESSION['name']) && $_SESSION['name'] === $loggedinuser) {

    header("Location: dns.php");

    exit;

}



$data = ['id' => '1','username' => 'admin','password' => 'admin',];

$db->insertIfEmpty('users', $data);



if (isset($_POST["login"])){

	$username = $_POST["username"];

	$userData = $db->select('users', '*', 'username = :username', '', [':username' => $username]);

	if ($userData) {

		$storedPassword = $userData[0]['password'];

		$enteredPassword = $_POST["password"];

		if ($enteredPassword == $storedPassword) {

			session_regenerate_id();

			$_SESSION['loggedin'] = TRUE;

			$_SESSION['name'] = $_POST['username'];

			if ($_POST['username'] == 'admin'){

				header('Location: user.php');

			}else{

				header('Location: dns.php');

			}

		}else{

			header('Location: ./api/index.php');

		}

	}else{

		header('Location: ./api/index.php');

	}

	$db->close();

}

?>

<!DOCTYPE html>

<html lang="pt-br">

<head><meta charset="utf-8">

  

  <title>IBO PRO Login</title>

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap" rel="stylesheet">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">

  <style>

    * {

      box-sizing: border-box;

    }

    body {

      margin: 0;

      font-family: 'Orbitron', sans-serif;

      background: #0d0d0d;

      color: #fff;

      overflow: hidden;

    }

    #particles-js {

      position: absolute;

      width: 100%;

      height: 100%;

      background-color: #0d0d0d;

      background-size: cover;

      z-index: -1;

    }

    .login-box {

      background: rgba(255, 255, 255, 0.05);

      border: 1px solid rgba(255, 0, 0, 0.2);

      border-radius: 20px;

      backdrop-filter: blur(15px);

      padding: 40px;

      width: 100%;

      max-width: 400px;

      margin: 100px auto;

      box-shadow: 0 0 40px rgba(255, 0, 0, 0.4);

    }

    .login-box h2 {

      text-align: center;

      color: #ff0000;

      margin-bottom: 30px;

    }

    .input-box {

      position: relative;

      margin-bottom: 30px;

    }

    .input-box input {

      width: 100%;

      padding: 12px 40px 12px 15px;

      background: rgba(255, 255, 255, 0.1);

      border: none;

      border-radius: 10px;

      color: #fff;

      font-size: 16px;

    }

    .input-box i {

      position: absolute;

      right: 15px;

      top: 12px;

      color: #ff0000;

    }

    .btn-login {

      width: 100%;

      padding: 12px;

      background: linear-gradient(135deg, #ff0000, #7e0000);

      border: none;

      border-radius: 10px;

      color: #fff;

      font-weight: bold;

      font-size: 16px;

      cursor: pointer;

      transition: background 0.3s ease;

    }

    .btn-login:hover {

      background: linear-gradient(135deg, #7e0000, #ff0000);

    }

    .footer-text {

      text-align: center;

      margin-top: 25px;

      font-size: 14px;

      color: #aaa;

    }

    .footer-text a {

      color: #ff0000;

      text-decoration: none;

    }

  </style>

</head>

<body>

  <div id="particles-js"></div>



  <div class="login-box">

    <h2>IBO PRO V4.3</h2>

    <form method="post">

      <div class="input-box">

        <input type="text" name="username" placeholder="Username" required>

        <i class="fas fa-user"></i>

      </div>

      <div class="input-box">

        <input type="password" name="password" placeholder="Password" required>

        <i class="fas fa-lock"></i>

      </div>

      <button type="submit" class="btn-login" name="login">

        <i class="fas fa-sign-in-alt"></i> Login

      </button>

    </form>

    <div class="footer-text">

    </div>

  </div>



  <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>

  <script>

    particlesJS("particles-js", {

      particles: {

        number: {

          value: 80,

          density: {

            enable: true,

            value_area: 800

          }

        },

        color: {

          value: "#ff0000"

        },

        shape: {

          type: "circle",

          stroke: {

            width: 0,

            color: "#000000"

          }

        },

        opacity: {

          value: 0.5,

          random: false

        },

        size: {

          value: 3,

          random: true

        },

        line_linked: {

          enable: true,

          distance: 150,

          color: "#ff0000",

          opacity: 0.4,

          width: 1

        },

        move: {

          enable: true,

          speed: 2,

          direction: "none",

          random: false,

          straight: false,

          out_mode: "out"

        }

      },

      interactivity: {

        detect_on: "canvas",

        events: {

          onhover: {

            enable: true,

            mode: "grab"

          },

          onclick: {

            enable: true,

            mode: "push"

          }

        },

        modes: {

          grab: {

            distance: 140,

            line_linked: {

              opacity: 0.7

            }

          },

          push: {

            particles_nb: 4

          }

        }

      },

      retina_detect: true

    });

  </script>

</body>

</html>