354 lines
16 KiB
PHP
354 lines
16 KiB
PHP
<?php
|
|
|
|
include '../managers/menu.php';
|
|
$totp = new TOTP();
|
|
|
|
$sql = mysqli_query($conn,"SELECT * FROM users WHERE uid = '$userID'");
|
|
$userDataSQL = mysqli_fetch_array($sql);
|
|
|
|
if ($userDataSQL == null) {
|
|
StopAndDie("Váratlan hiba lépett fel a fiók adatainak lekérésekor! Próbálja újra!");
|
|
}
|
|
|
|
if (isset($_POST['f']) && isset($_POST['anticsrfid']) && $_POST['anticsrfid'] == $_SESSION["anticsrfid"]) {
|
|
if (htmlspecialchars($_POST['f']) == 'SavePass') {
|
|
$oldpass = md5($_POST['oldpass']);
|
|
$pass = md5($_POST['pass']);
|
|
|
|
$realoldpass = $userDataSQL["upass"];
|
|
|
|
if (md5($_POST['repass']) != $pass) {
|
|
echo "A két jelszó nem egyezik!";
|
|
} else if (strlen(htmlspecialchars($_POST['repass'])) < 6) {
|
|
echo "A jelszónak minimum 6 karakter hosszúnak kell lennie!";
|
|
} else if (!(preg_match('/[a-z]/', $_POST['repass']) && preg_match('/[A-Z]/', $_POST['repass']) && preg_match('/[0-9]/', $_POST['repass']))) {
|
|
echo "A jelszónak tartamaznia kell egy kis és nagy karaktert, és legalább egy számot!";
|
|
} else if ($realoldpass != $oldpass) {
|
|
echo "A régi jelszó helytelen!";
|
|
} else {
|
|
mysqli_query($conn,"UPDATE users SET upass='$pass' WHERE uid = ".$userID);
|
|
echo "ok";
|
|
}
|
|
|
|
} elseif (htmlspecialchars($_POST['f']) == 'Activate2fa') {
|
|
$otckey = $_POST['otckey'];
|
|
$otc = $_POST['otc'];
|
|
$pass = md5($_POST['pass']);
|
|
|
|
if ($pass != $userDataSQL["upass"]) {
|
|
echo "A jelszó helytelen!";
|
|
} else if($totp->isValidKey($otckey) == false) {
|
|
echo "Váratlan hiba történt az egyedik kód generálásában, kérem vegye fel újra a kódot a hitelesítő alkalmazásába, és frissítse az oldalt!";
|
|
} else if($totp->getOtp($otckey) == $otc) {
|
|
$hashto2fa = $coderclass->encode($otckey, "J57A");
|
|
$sql = mysqli_query($conn,"UPDATE users SET otphash = '$hashto2fa' WHERE uid = '$userID'");
|
|
echo "ok";
|
|
} else {
|
|
echo "A hitelesítő kód nem egyezik!";
|
|
}
|
|
|
|
} else if (htmlspecialchars($_POST['f']) == 'Settings2fa') {
|
|
$type = '<option value="0">Új eszköz esetén, vagy 1 hét inaktivitás után</option>';
|
|
$type .= '<option value="1">Minden belépés esetén</option>';
|
|
$type = str_replace('value="'.$userDataSQL["otptype"].'"', 'value="'.$userDataSQL["otptype"].'" selected', $type);
|
|
|
|
if ($userDataSQL["otptype"] == 2) {$type = "NOEDIT 1";} else if ($userDataSQL["otptype"] == 3) {$type = "NOEDIT 2";}
|
|
|
|
echo json_encode(["status" => "ok", "type" => $type]);
|
|
|
|
} else if (htmlspecialchars($_POST['f']) == 'Delete2fa') {
|
|
$pass = md5($_POST['pass']);
|
|
if ($pass != $userDataSQL["upass"]) {
|
|
echo "A jelszó helytelen!";
|
|
} else if ($type == 2 || $type == 3) {
|
|
echo "A fiók valamilyen ok miatt megköveteli a kétfaktoros hitelesítést, ezért nem deaktiválható!";
|
|
} else {
|
|
$sql = mysqli_query($conn,"UPDATE users SET otphash = '' WHERE uid = '$userID'");
|
|
echo 'ok';
|
|
}
|
|
} else if (htmlspecialchars($_POST['f']) == 'Save2fa') {
|
|
$pass = md5($_POST['pass']);
|
|
$type = $_POST['type'];
|
|
if ($pass != $userDataSQL["upass"]) {
|
|
echo "A jelszó helytelen!";
|
|
} else if ($type != 0 && $type != 1) {
|
|
echo "Váratlan hiba történt, töltse újra az oldalt, és próbálja újra!";
|
|
}else {
|
|
$sql = mysqli_query($conn,"UPDATE users SET otptype = $type WHERE uid = '$userID'");
|
|
setcookie("otpauth", "", time() - 3600, "/");
|
|
echo 'ok';
|
|
}
|
|
}
|
|
|
|
die();
|
|
} else if (isset($_POST['f'])) {
|
|
echo "Titkos token hiba! Frissítse az oldalt, és próbálja újra!";
|
|
die();
|
|
}
|
|
|
|
$usermail = $coderclass->decode($userDataSQL["mail"], "A7SO");
|
|
$userPosition = $coderclass->decode($userDataSQL["position"], "SWI2");
|
|
|
|
$userPerms = "<ul>";
|
|
$userPermListArr = explode(", ", $userPermsList);
|
|
|
|
$CurrentUserPermList = array();
|
|
for ($i=0; $i < count($userPermListArr); $i++) {
|
|
$cpid = $userPermListArr[$i];
|
|
$sql = mysqli_query($conn,"SELECT short_name, risk_factor, perm_status FROM perm_database WHERE perm_id = '$cpid'");
|
|
$tempSQL = mysqli_fetch_array($sql);
|
|
$name = $coderclass->decode($tempSQL[0], "HA98");
|
|
array_push($CurrentUserPermList, $tempSQL[1]."|".$name."|".$tempSQL[2]);
|
|
}
|
|
|
|
sort($CurrentUserPermList);
|
|
//$CurrentUserPermList = array_values(array_reverse($CurrentUserPermList));
|
|
$CurrentUserPermListSliced = array_slice($CurrentUserPermList, 0, 12);
|
|
|
|
for ($x=0; $x < count($CurrentUserPermListSliced); $x++) {
|
|
$templist = explode("|", $CurrentUserPermListSliced[$x]);
|
|
if ($templist[2] == "1") {
|
|
$userPerms .= '<li><span style="color: var(--panelcolor);">'.$templist[1].'</span></li>';
|
|
} else if ($templist[0] == "0") {
|
|
$userPerms .= '<li><span class="redtext">'.$templist[1].'</span></li>';
|
|
} else {
|
|
$userPerms .= '<li><span style="opacity: 0.8;">'.$templist[1].'</span></li>';
|
|
}
|
|
}
|
|
|
|
$userPerms .= "</ul>";
|
|
|
|
|
|
$anticsrfid = bin2hex(random_bytes(24));
|
|
$_SESSION["anticsrfid"] = $anticsrfid;
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="hu" dir="ltr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="stylesheet" href="../css/panel.css">
|
|
<title>Kezelőfelület</title>
|
|
</head>
|
|
<body>
|
|
<?php echo $menuhtml;?>
|
|
<div class="window closed" id="win">
|
|
<div class="topbar">
|
|
<p id="wintitle">Title</p>
|
|
<div class="btn fullscrn" onclick="fullscrn();" id="fullscrnbtn"></div>
|
|
<div class="btn close" onclick="closewin();"></div>
|
|
</div>
|
|
<div class="wapp" id="winapp"><div id="errorDIV"></div></div>
|
|
<div class="loading" id="winloading"></div>
|
|
</div>
|
|
<div class="loadingBG" id="loadingBG"><img class="svg" src="../img/Saturnus.svg"></div>
|
|
<div class="content">
|
|
<div id="errorDIV" style="z-index: 100; top: 50px; position: fixed; width: calc(100% - 260px);"></div>
|
|
|
|
<!-- Tartalmi rész kezdete -->
|
|
|
|
<div class="box">
|
|
<h2>Fiókom adatlapja</h2>
|
|
<p style="margin-bottom: 0px;"><b>Felhasználó neve:</b><span style="color: var(--panelcolor);"> <?php echo $userName;?></span></p>
|
|
<p style="margin-bottom: 0px; margin-top: 0px;"><b>Felhasználó email címe:</b><span style="color: var(--panelcolor);"> <?php echo $usermail;?></span></p>
|
|
<p style="margin-bottom: 0px; margin-top: 0px;"><b>Beosztása:</b><span style="color: var(--panelcolor);"> <?php echo $userPosition;?></span></p>
|
|
<p style="margin-top: 0px;"><b>Jelszó módosítása:</b></p>
|
|
<input type="password" id="oldpsw" placeholder="Jelenlegi jelszó" autocomplete="off" spellcheck="false" class="pass" autocapitalize="off" autocorrect="off"><br><br>
|
|
<input type="password" id="psw" placeholder="Új jelszó" autocomplete="off" spellcheck="false" class="pass" autocapitalize="off" autocorrect="off"><br><br>
|
|
<input type="password" id="repsw" placeholder="Új jelszó ismét" autocomplete="off" spellcheck="false" class="pass" autocapitalize="off" autocorrect="off"><br><br>
|
|
<button onclick="SaveNewPass();">Mentés</button><button onclick="window.location='../managers/logout.php';" style="position: absolute; right: 15px; background-color: #c0392b;">Kijelentkezés</button>
|
|
</div>
|
|
|
|
<div class="box">
|
|
<h2>Fiókomhoz társított jogok</h2>
|
|
<p style="opacity: 0.6;"><?php if (count($CurrentUserPermList) > 13) {echo "Az első 12 legfontosabb jog";}?></p>
|
|
<?php echo $userPerms;?>
|
|
</div>
|
|
|
|
<div class="box">
|
|
<h2>Kétlépcsős hitelesítés</h2>
|
|
<?php
|
|
|
|
$totpQRCode = "";
|
|
|
|
if ($userDataSQL["otphash"] != "") {
|
|
echo "<p style='color: #66A182;'><b>Aktív!</b> <a style='color: var(--panelcolor); padding-left: 15px;' onclick='Settings2fa();'>Módosítás</a></p>";
|
|
} else {
|
|
$totpKey = $totp->generateKey();
|
|
|
|
$totpQRCode = 'otpauth://totp/Szaturnusz?secret='.$totpKey.'&issuer=saturn&algorithm=SHA1&digits=6&period=30';
|
|
|
|
echo '<p>Scannelje be a QR kódot hitelesítő alkalmazásában,<br><i style="opacity: 0.8;">(pl: Google Authenticator, Authy, Microsoft Authenticator)</i><br>majd írja be a kapott kódot.</p><br>';
|
|
echo '<div style="display: flex; justify-content: center; align-items: center; height: 160px;"><div id="qrcode" style="width: 160px; height: 160px;"></div></div>';
|
|
echo '<p style="text-align: center;">'.$totpKey.'</p>';
|
|
echo '<input style="margin: auto;" type="text" id="otc" class="otc" maxlength="6" autocomplete="off">
|
|
<div style="display: flex; justify-content: center; align-items: center; margin-top: 15px;">
|
|
<input type="password" id="pass" placeholder="Jelenlegi jelszó..." autocomplete="off">
|
|
<input type="hidden" id="otckey" value="'.$totpKey.'">
|
|
<button style="margin-left: 15px;" onclick="Activate2fa();">Aktiválás</button></div>';
|
|
}
|
|
|
|
?>
|
|
</div>
|
|
|
|
<!-- Tartalmi rész vége -->
|
|
|
|
</div>
|
|
<script src="../js/default.js" type="text/javascript"></script>
|
|
<script src="../js/qrcode.js" type="text/javascript"></script>
|
|
<script type="text/javascript">
|
|
|
|
var GlobalAntiCSRFId = "<?php echo $anticsrfid;?>";
|
|
|
|
function SaveNewPass() {
|
|
Loading();
|
|
|
|
var oldpass = document.getElementById("oldpsw").value;
|
|
var pass = document.getElementById("psw").value;
|
|
var repass = document.getElementById("repsw").value;
|
|
|
|
const body = 'f=SavePass&oldpass=' + encodeURIComponent(oldpass).replace(/%20/g, '+') + '&pass=' + encodeURIComponent(pass).replace(/%20/g, '+') + '&repass=' + encodeURIComponent(repass).replace(/%20/g, '+') + '&anticsrfid=' + GlobalAntiCSRFId;
|
|
get_POST_information("profile.php", body, function(text) {
|
|
Loading(false);
|
|
|
|
if (text == "ok") {
|
|
GenerateAlerts("success", "Sikeresen frissítette a jelszavát!");
|
|
document.getElementById("oldpsw").value = "";
|
|
document.getElementById("psw").value = "";
|
|
document.getElementById("repsw").value = "";
|
|
} else {
|
|
GenerateAlerts("error", text);
|
|
}
|
|
}, function() {
|
|
GenerateAlerts("error", "Hálózati hiba történt, próbálja újra!");
|
|
Loading(false);
|
|
});
|
|
}
|
|
function Activate2fa() {
|
|
Loading();
|
|
|
|
var otc = document.getElementById("otc").value;
|
|
var otckey = document.getElementById("otckey").value;
|
|
var pass = document.getElementById("pass").value;
|
|
|
|
const body = 'f=Activate2fa&otc=' + encodeURIComponent(otc).replace(/%20/g, '+') + '&otckey=' + encodeURIComponent(otckey).replace(/%20/g, '+') + '&pass=' + encodeURIComponent(pass).replace(/%20/g, '+') + '&anticsrfid=' + GlobalAntiCSRFId;
|
|
get_POST_information("profile.php", body, function(text) {
|
|
Loading(false);
|
|
|
|
if (text == "ok") {
|
|
GenerateAlerts("success", "Sikeresen aktiválta a kétlépcsős hitelesítést!");
|
|
setTimeout(() => {window.location.reload();}, 2000);
|
|
} else {
|
|
GenerateAlerts("error", text);
|
|
}
|
|
}, function() {
|
|
GenerateAlerts("error", "Hálózati hiba történt, próbálja újra!");
|
|
Loading(false);
|
|
});
|
|
}
|
|
if (document.getElementById('qrcode')) {
|
|
new QRCode(document.getElementById("qrcode"), {
|
|
text: "<?php echo $totpQRCode;?>",
|
|
width: 160,
|
|
height: 160,
|
|
colorDark : "#000000",
|
|
colorLight : "#ffffff",
|
|
correctLevel : QRCode.CorrectLevel.H
|
|
});
|
|
}
|
|
|
|
function Settings2fa() {
|
|
Loading();
|
|
openwin();
|
|
wintitle.innerHTML = "Kétlépcsős hitelesítés - Beállítások";
|
|
|
|
const body = 'f=Settings2fa&anticsrfid=' + GlobalAntiCSRFId;
|
|
get_POST_information("profile.php", body, function(text) {
|
|
Loading(false);
|
|
winapp.innerHTML = '<div id="errorDIV"></div>';
|
|
let response = JSON.parse(text);
|
|
if (response.status == "ok") {
|
|
winapp.innerHTML += '<h1>Kétlépcsős hitelesítés beállításai</h1>';
|
|
winapp.innerHTML += '<p style="width: calc(100% - 35px); border-bottom: 1px solid #bdc3c7; display: inline-block; margin-right: 15px; "></p>';
|
|
winapp.innerHTML += '<p style="font-weight: bold;">Mikor kérje a 6 számjegyű kódot:</p>';
|
|
|
|
var CanDelete = true;
|
|
if (response.type != "NOEDIT 1" && response.type != "NOEDIT 2") {
|
|
winapp.innerHTML += '<select id="type">'+response.type+'</select>';
|
|
winapp.innerHTML += '<br><br><input type="password" id="settingspass" placeholder="Jelenlegi jelszó..." autocomplete="off" style="height: 17px;">';
|
|
winapp.innerHTML += '<button onclick="Save2fa();" style="margin-left: 19px;">Mentés</button>';
|
|
} else if (response.type == "NOEDIT 1") {
|
|
winapp.innerHTML += '<p style="color: var(--panelcolor);">Új eszköz esetén, vagy 1 hét inaktivitás után - <span style="opacity: 0.7; font-style: italic; color: #333;">Nem módosítható</span></p><br><br>';
|
|
CanDelete = false;
|
|
} else {
|
|
winapp.innerHTML += '<p style="color: var(--panelcolor);">Minden belépés esetén - <span style="opacity: 0.7; font-style: italic; color: #333;">Nem módosítható</span></p><br><br>';
|
|
CanDelete = false;
|
|
}
|
|
winapp.innerHTML += '<button onclick="Delete2fa('+CanDelete+');" style="position: absolute; right: 50px; background-color: #c0392b; color: #f5f5f5;">Deaktiválás</button>';
|
|
|
|
} else {
|
|
GenerateAlerts("error", response.message);
|
|
}
|
|
}, function() {
|
|
GenerateAlerts("error", "Hálózati hiba történt, próbálja újra!");
|
|
Loading(false);
|
|
});
|
|
}
|
|
function Save2fa() {
|
|
Loading();
|
|
var pass = document.getElementById("settingspass").value; document.getElementById("settingspass").value = "";
|
|
var type = document.getElementById("type").value;
|
|
const body = 'f=Save2fa&anticsrfid=' + GlobalAntiCSRFId + '&pass=' + encodeURIComponent(pass).replace(/%20/g, '+') + '&type=' + type;
|
|
get_POST_information("profile.php", body, function(text) {
|
|
Loading(false);
|
|
|
|
if (text == "ok") {
|
|
GenerateAlerts("success", "Sikeresen elmentette a változásokat!");
|
|
} else {
|
|
GenerateAlerts("error", text);
|
|
}
|
|
}, function() {
|
|
GenerateAlerts("error", "Hálózati hiba történt, próbálja újra!");
|
|
Loading(false);
|
|
});
|
|
}
|
|
function Delete2fa(CanDelete, text = 'DefaultText') {
|
|
if (!CanDelete) {
|
|
GenerateAlerts('warning', 'A fiók valamilyen ok miatt megköveteli a kétfaktoros hitelesítést, ezért nem deaktiválható!');
|
|
} else if (text == "igen") {
|
|
var pass = document.getElementById("settingspass").value; document.getElementById("settingspass").value = "";
|
|
const body = 'f=Delete2fa&anticsrfid=' + GlobalAntiCSRFId + '&pass=' + encodeURIComponent(pass).replace(/%20/g, '+');
|
|
Loading();
|
|
get_POST_information("profile.php", body, function(text) {
|
|
Loading(false);
|
|
|
|
if (text == "ok") {
|
|
GenerateAlerts("success", "Sikeresen deaktiválta a kétlépcsős hitelesítést!");
|
|
setTimeout(() => {window.location.reload();}, 2000);
|
|
} else {
|
|
GenerateAlerts("error", text);
|
|
}
|
|
}, function() {
|
|
GenerateAlerts("error", "Hálózati hiba történt, próbálja újra!");
|
|
Loading(false);
|
|
});
|
|
|
|
} else if (text == 'DefaultText') {
|
|
var html = `
|
|
<p><b>Kérjük, amennyiben biztos abban, hogy deaktiválni szeretné a kétlépcsős hitelesítést, írja be, hogy 'igen'</b><br><br>Bármikor visszakapcsolhatja ezt a szolgáltatást!</p><br>
|
|
<input type="text" id="AlertTextInput" placeholder="Indoklás..." autocomplete="off" autocapitalize="off" spellcheck="false" autocorrect="off">
|
|
<br clear="all"><br>
|
|
<button id="AlertBtnNo" style="float: right; margin-left: 15px; width: 80;">Mégsem</button>
|
|
<button id="AlertBtnYes" style="float: right; width: 60px; background: var(--panelcolor); color: #f5f5f5; border: unset;">Mentés</button>
|
|
`;
|
|
const overlay = CreateAlertBox('Kétlépcsős hitelesítő!', html, false);
|
|
document.getElementById('AlertBtnYes').onclick = function () { Delete2fa(CanDelete, (document.getElementById("AlertTextInput").value).toLowerCase()); CloseAlertBox(overlay); };
|
|
document.getElementById('AlertBtnNo').onclick = function () { CloseAlertBox(overlay); FeedbackButtonStatus('failed', Statement_id + '_button'); };
|
|
return;
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|