<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once("config.php");
@session_set_cookie_params(604800,"/");
session_start();

$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
$server_path = dirname($_SERVER['REQUEST_URI']);
$server_path = $server_path === '/' ? $server_path : $server_path . '/';
$server_name = $protocol . "://" . $_SERVER['HTTP_HOST'] . $server_path;
$url="https://eslcore.com/l/v.php?k=".$l1."&u=".base64_encode($server_name)."&h=".$l2;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
curl_close($ch);

if (substr($ret, 0, 5)=="ERROR"){
	echo ($ret);
	exit();
} else {
	$calc=hash('sha256',base64_encode($server_name).$l1.$ret);
	if ($calc!=$l2){
		exit();
	}
}



if (isset($_POST["email"])) {
  require "user/user-lib.php";
  $USR->login($_POST["email"], $_POST["password"]);
}


if (isset($_SESSION["user".$l1])) {
	header("Location: projects.php");
	exit();
}

?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<link rel="icon" type="image/x-icon" href="favicon.ico">
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>Login</title>
		<!-- Custom fonts for this template-->
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css" integrity="sha512-q3eWabyZPc1XTCmF+8/LuE1ozpg5xxn7iO89yfSOd5/oKvyqLngoNGsx8jq92Y8eXJ/IRxQbEC+FGSYxtk2oiw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
		<!-- <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css"> -->
		<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
		<!-- Custom styles for this template-->
		<link href="libs/sbadmin2/css/sb-admin-2.min.css" rel="stylesheet">
	</head>
	<body class="bg-gradient-dark">
		<div class="container">
			<!-- Outer Row -->
			<div class="row justify-content-center">
				<div class="col-xl-10 col-lg-12 col-md-9">
					<div class="card o-hidden border-0 shadow-lg my-5">
						<div class="card-body p-0">
							<!-- Nested Row within Card Body -->
							<div class="row bg-gray-100">
								<div class="col-lg-6 d-none d-lg-block" style="text-align:center;"><img style="padding:20px; max-height: 100%; max-width: 100%; width: auto; height: auto; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto;" src="img/logo.png"></div>
								<div class="col-lg-6">
									<div class="p-5">
										<div class="text-center">
											<h1 class="h4 text-gray-900 mb-4">Login</h1>
										</div>
										<form class="user" id="login" method="post">
											<div class="form-group">
												<input type="email" class="form-control form-control-user" name="email" required aria-describedby="emailHelp" placeholder="Enter Email Address..." autofocus>
											</div>
											<div class="form-group">
												<input type="password" class="form-control form-control-user" name="password" required placeholder="Password">
											</div>
											<div class="form-group"></div>
											<button type="submit" class="btn btn-primary btn-user btn-block"> Login </button>
										</form>
										<hr>
										<div class="text-center">
											<a class="small" href="forgotpassword.php">Forgot Password?</a>
										</div>
										<div class="text-center">
											<a class="small" href="register.php">Create an Account!</a>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- Footer -->
						<footer class="sticky-footer bg-white">
							<div class="container my-auto">
								<div class="copyright text-center my-auto">
									<?php echo $footer; ?>
								</div>
							</div>
						</footer>
						<!-- End of Footer -->
					</div>
				</div>
			</div>
		</div>
		<!-- Bootstrap core JavaScript-->
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/js/bootstrap.min.js" integrity="sha512-7rusk8kGPFynZWu26OKbTeI+QPoYchtxsmPeBqkHIEXJxeun4yJ4ISYe7C6sz9wdxeE1Gk3VxsIWgCZTc+vX3g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<!-- Core plugin JavaScript-->
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js" integrity="sha512-0QbL0ph8Tc8g5bLhfVzSqxe9GERORsKhIn1IrpxDAgUsbBGz/V7iSav2zzW325XGd1OMLdL4UiqRJj702IeqnQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<!-- Custom scripts for all pages-->
		<script src="libs/sbadmin2/js/sb-admin-2.min.js"></script>
	</body>
</html>