Files
ICEcoder/lib/login.php
2020-08-13 11:35:57 +01:00

149 lines
6.1 KiB
PHP

<?php
include "headers.php";
include "settings.php";
$t = $text['login'];
$settingPW = $ICEcoder["enableRegistration"] && ($ICEcoder["multiUser"] || "" === $ICEcoder["password"]);
?>
<!DOCTYPE html>
<html>
<head>
<title>ICEcoder <?php
echo $ICEcoder["versionNo"] . " : ";
echo $settingPW ? "Setup" : "Login";
?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="../assets/css/resets.css?microtime=<?php echo microtime(true);?>">
<link rel="stylesheet" type="text/css" href="../assets/css/icecoder.css?microtime=<?php echo microtime(true);?>">
<link rel="icon" type="image/png" href="../assets/images/favicon.png">
</head>
<body style="background-color: #181817" onLoad="<?php if (false === isset($_GET["get"])) {$inputFocus = true === $ICEcoder["multiUser"] ? "username" : "password"; echo "document.settingsUpdate." . $inputFocus . ".focus(); ";}; ?>setTimeout(function(){document.getElementById('screenContainer').style.opacity = '1'}, 50)">
<div class="screenContainer" id="screenContainer" style="background-color: #181817; opacity: 0; transition: opacity 0.1s ease-out">
<div class="screenVCenter">
<div class="screenCenter">
<img src="../assets/images/icecoder.png" alt="ICEcoder">
<div class="version" style="margin-bottom: 22px">v <?php echo $ICEcoder["versionNo"];?></div>
<form name="settingsUpdate" action="login.php" method="POST"<?php if ($settingPW) {?> onsubmit="return checkCanSubmit();"<?php } ?>>
<?php
if ($ICEcoder["multiUser"]) {echo '<input type="text" name="username" class="password"><br><br>';};
?>
<input type="password" name="password" class="password" id="password"<?php
if ($settingPW) {
?> onkeyup="checkCase(event); pwStrength(this.value)" onchange="pwStrength(this.value)" onpaste="pwStrength(this.value)"<?php
} else {
?> onkeyup="checkCase(event)"<?php
}
?>><div class="icon" style="display: none" id="capsLockDisplay" title="Caps lock on"><?php echo file_get_contents("../assets/images/icons/alert-triangle.svg");?></div><br>
<?php
if ($settingPW) {
echo '<div id="pwReqs">'.
'<div class="text" style="display: inline-block" id="pwChars">10+</div> &nbsp; ' .
'<div class="text" style="display: inline-block" id="pwUpper">upper</div> &nbsp; ' .
'<div class="text" style="display: inline-block" id="pwLower">lower</div> &nbsp; ' .
'<div class="text" style="display: inline-block" id="pwNum">number</div> &nbsp; ' .
'<div class="text" style="display: inline-block" id="pwSpecial">special</div>' .
'</div>';
}
?><br>
<input type="submit" name="submit" value="<?php
// Multi-user
if ($ICEcoder["multiUser"]) {
echo $ICEcoder["enableRegistration"] ? $t['set password'] . " / " . $t['login'] : $t['login'];
// Single-user
} else {
echo $ICEcoder["enableRegistration"] && "" === $ICEcoder["password"] ? $t['set password'] : $t['login'];
}; ?>" class="button">
<?php
if(empty($_SERVER['HTTPS'])) {
echo '<div class="text">Using over non-https connection.<br>TLS is recommended!</div>';
}
if($ICEcoder["multiUser"] && $ICEcoder["enableRegistration"]){
echo '<div class="text">' . $t['Registration mode enabled'] . '</div>';
}
?>
<?php
if ("" === $ICEcoder["password"] && false === $ICEcoder["multiUser"]) {
echo '<div class="text" style="position: relative"><input type="checkbox" name="disableFurtherRegistration" value="true" style="position: absolute; margin: -1px 0 0 -20px" checked> ' . $t['disable further registrations'] . '</div>';
}
if ("" === $ICEcoder["password"] || true === $ICEcoder["multiUser"]) {
echo '<div class="text" style="position: relative"><input type="checkbox" name="checkUpdates" value="true" style="position: absolute; margin: -1px 0 0 -20px" checked> ' . $t['auto-check for updates'] . '</div>';
}
if (false === $ICEcoder["multiUser"]) { echo '<div class="text"><a href="javascript:alert(\'' . $t['To put into...'] . '\'); document.settingsUpdate.' . $inputFocus . '.focus();">' . $t['multi-user'] . '?</a></div>';};
?>
<input type="hidden" name="csrf" value="<?php echo $_SESSION["csrf"]; ?>">
</form>
</div>
</div>
</div>
<script>
// Get any elem by ID
const get = function(elem) {
return document.getElementById(elem);
};
// Check password strength and color requirements not met
const pwStrength = function(pw) {
// Set variables
const hlCol = "rgba(0, 198, 255, 0.7)";
let chars, upper, lower, num, special;
// Test password for requirements
chars = pw.length >= 10;
upper = pw.replace(/[A-Z]/g, "").length < pw.length;
lower = pw.replace(/[a-z]/g, "").length < pw.length;
num = pw.replace(/[0-9]/g, "").length < pw.length;
special = pw.replace(/[A-Za-z0-9]/g, "").length > 0;
// Set colors based on each requirements
get("pwChars").style.color = true === chars ? hlCol : "";
get("pwUpper").style.color = true === upper ? hlCol : "";
get("pwLower").style.color = true === lower ? hlCol : "";
get("pwNum").style.color = true === num ? hlCol : "";
get("pwSpecial").style.color = true === special ? hlCol : "";
// Return a bool based on meeting the requirements
return (true === chars && true === upper && true === lower && true === num && true === special);
};
const checkCase = function(evt) {
const key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
// Not caps lock key
if (20 !== key) {
get("capsLockDisplay").style.display = true === evt.getModifierState("CapsLock")
? "inline-block"
: "none";
}
};
// Check if we can submit, else shake requirements
const checkCanSubmit = function() {
// Password isn't strong enough, shake requirements
if(false === pwStrength(get("password").value)) {
var posArray = [6, -6, 3, -3, 0];
var pos = -1;
var anim = setInterval(function() {
if (pos < posArray.length) {
pos++;
get("pwReqs").style.marginLeft = posArray[pos] + "px";
} else {
clearInterval(anim);
}
}, 50);
return false;
}
return true;
}
</script>
</body>
</html>