Files
assetmgt/login.php
2025-03-13 12:25:59 +01:00

167 lines
5.5 KiB
PHP

<?php ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
include './assets/functions.php';
include './settings/settings.php';
include './settings/config_redirector.php';
include_once './settings/translations/translations_US.php';
//=========================================
//GET DOMAIN FOR CORRECT STYLING AND SETTINGS
$domain = getDomainName($_SERVER['SERVER_NAME']);
$custom_css = (file_exists(dirname(__FILE__).'/style/'.$domain.'/'.$domain.'_login.css') ? './style/'.$domain.'/'.$domain.'_login.css' : './style/admin_login.css');
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: index.php");
exit();
}
// Define variables and initialize with empty values
$username = $password = '';
$username_err = $password_err = '';
$retry = 0;
// Process submitted form data
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if username is empty
if(empty(trim($_POST['username']))){
$username_err = 'Please enter username.';
} else{
$username = trim($_POST['username']);
}
// Check if password is empty
if(empty(trim($_POST['password']))){
$password_err = 'Please enter your password.';
} else{
$password = trim($_POST['password']);
}
// Validate credentials
if (empty($username_err) && empty($password_err) && $retry < 3) {
$data = json_encode(array("username" => $username, "password" => $password), JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v1/authorization', $payload);
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
if ($responses === 'NOK'){
$retry++;
$password_err = 'Not authorized, please retry';
} elseif ($responses == '1'){
$password_err = 'Too many login attempts. User blocked, please contact your administrator';
} else {
// Start a new session
session_start();
// Store data in sessions
$_SESSION['loggedin'] = true;
$_SESSION['id'] = $responses->id;
$_SESSION['username'] = $responses->username;
$_SESSION['email'] = $responses->email;
$_SESSION['salesID'] = $responses->salesID;
$_SESSION['partnerhierarchy'] = $responses->partnerhierarchy; //clean;
$_SESSION['permission'] = $responses->permission;
$_SESSION['profile_name'] = $responses->profile_name;
$_SESSION['profile'] = $responses->profile;
$_SESSION['userkey'] = $responses->userkey;
$_SESSION['language'] = $responses->language;
$_SESSION['token'] = $responses->token;
$language_user = trim($responses->language) ?? 'US';
if($responses->profile == 'firmwaretool,products_software,application'){
header('location: index.php?page=firmwaretool');
exit();
} else {
header('location: index.php?language='.$language_user.'');
exit();
}
}
}
else {
// Display an error for passord mismatch
$password_err = 'Not authorized';
}
}
echo'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>'.site_title.'</title>
<link rel="shortcut icon" href="'.icon_image.'" type="image/x-icon" />
<link href="'.$custom_css.'" rel="stylesheet" type="text/css">
</head>
<body>
';
//Maintenance mode notification message
if (maintenance_mode_communication){
echo'
<p style="text-align: center;">
<small>'.maintenance_mode_notification.'</small>
</p>';
}
//Logon view
echo'
<div class="logon">
<div class="logon_center" style="position: static;">
<div id="imagelogon"></div>
<div class="login-box">
<small style="color:#fff;">'.site_title.'</small>
<h1>'.site_name.'</h1>
';
if (maintenance_mode)
{
//Maintenance mode is on => Show maintenance mode text
echo '
<p style="margin-top: 10%;color: white;">'.maintenance_mode_text.'</p>
';
} else {
//Maintenance mode is off => Show login
echo '
<form style="margin-top:15px;" action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="text" id="username" name="username" placeholder="Username" value="'; echo $username; echo '" autofocus>
<input type="password" id="password" name="password" placeholder="Password" value="'; echo $password; echo '">
<div id="reset"><a href="reset.php">'.$button2.'</a></div>
<input type="submit" value="'.$button1.'">
</form>
<div id="message"><p>'.$username_err.''.$password_err.'<p></div>';
}
echo '
</div>';
// -----------------------
//DISPLAY REDIRECT SLIDER
/* -----------------------
echo '
<section title="">
<div class="slider-checkbox">
<input id="my-check-box" type="checkbox" onchange="location.href=\'https://legacy.veliti.nl\'"/>
<label for="my-check-box">
<span id="ball"></span>
</label>
</div>
<p style="text-align:center;margin-top:-20px;color:#ffffff7a;font-size:12px;">use legacy portal</p>
</section>
';
// -----------------------
// END - REDIRECT SLIDER
// -----------------------
*/
echo '
</div>
</div>
</body>
</html>
';
?>