1. Import
This commit is contained in:
237
html/admin/GA_generateBarcode.php
Normal file
237
html/admin/GA_generateBarcode.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
TOTP :: Register a new code
|
||||
*/
|
||||
|
||||
include_once "../include/global.inc.php";
|
||||
$authDoNotCheck2FA = true;
|
||||
include_once "../include/auth.inc.php";
|
||||
require_once "../include/GoogleAuthenticator.php";
|
||||
|
||||
|
||||
getSecHttpVars("1", array("f_act", "statusMessage", "deactivateMenu", "activated2FA", "f_2faCode"));
|
||||
|
||||
|
||||
getLanguage(__FILE__);
|
||||
|
||||
$deactivateMenuStatic = "1";
|
||||
$pageTitel = getLngt("[2FA]-Registrierung");
|
||||
include_once ("../admin/menu.php");
|
||||
include_once ("../include/html.inc.php");
|
||||
getCurrentScript(__FILE__);
|
||||
|
||||
|
||||
$debug = false;
|
||||
if ($debug) : echo "usr_id = " . $usr_id . "</br>"; endif;
|
||||
if ($debug) : echo "hq_id = " . $hq_id . "</br>"; endif;
|
||||
$usrAccount = "";
|
||||
$jsAction = "";
|
||||
|
||||
if (isset($usr_id) && $usr_id != "" && is_numeric($usr_id) && $usr_id > 0 &&
|
||||
isset($hq_id) && $hq_id != "" && is_numeric($hq_id) && $hq_id > 0) :
|
||||
|
||||
$usrHqId = getFieldValueFromId("user", "usr_id", $usr_id, "hq_id");
|
||||
$usrAccount = getFieldValueFromId("user", "usr_id", $usr_id, "usr_account");
|
||||
$usrTotpSecretOld = getFieldValueFromId("user", "usr_id", $usr_id, "usr_totp_secret");
|
||||
if ($debug) : echo "usrHqId = " . $usrHqId . "</br>"; endif;
|
||||
if ($debug) : echo "usrAccount = " . $usrAccount . "</br>"; endif;
|
||||
if ($debug) : echo "usrTotpSecretOld = " . $usrTotpSecretOld . "</br>"; endif;
|
||||
|
||||
if (!isset($activated2FA) || $activated2FA == "") : $activated2FA = "0"; endif;
|
||||
if (!isset($f_2faCode)) : $f_2faCode = ""; endif;
|
||||
|
||||
$ga = new GoogleAuthenticator();
|
||||
|
||||
if ($f_act == "verify" && $f_2faCode != "") :
|
||||
|
||||
// Verify code to check the user scanned code with authentication app
|
||||
|
||||
$verificationOK = false;
|
||||
$usrTotpSecret = getFieldValueFromId("user", "usr_id", $usr_id, "usr_totp_secret");
|
||||
if ($usrTotpSecret != "") :
|
||||
|
||||
$currentCode = $ga->getCode($usrTotpSecret);
|
||||
|
||||
if ($f_2faCode == $currentCode) :
|
||||
$verificationOK = true;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ($verificationOK) :
|
||||
$res = updateStmt("user","usr_id",$usr_id,array("usr_totp_activated", "1"), "usr_totp_secret != ''");
|
||||
if ($res > 0) :
|
||||
$tmpNum = rand(0,getrandmax());
|
||||
$tmpSessionHash = md5($tmpNum);
|
||||
updateStmt("user", "usr_id", $usr_id, array("usr_totp_sessionkey", $tmpSessionHash));
|
||||
$_SESSION["sessionkey_2fa"] = $tmpSessionHash;
|
||||
|
||||
$jsAction = "opener.location.reload(); alert('" . getLngt("Das hat geklappt! Eine Deaktivierung können Sie auf der Startseite vornehmen!") . "'); this.close();";
|
||||
else :
|
||||
$statusMessage = getLngt("Die Aktivierung hat leider nicht geklappt! Beginnen Sie bitte erneut oder wenden Sie sich bitte an Ihren Ansprechpartner!");
|
||||
$res = updateStmt("user","usr_id",$usr_id,array("usr_totp_secret", "", "usr_totp_activated", "0"));
|
||||
endif;
|
||||
else :
|
||||
$statusMessage = getLngt("Das war leider nicht der korrekte Code. Geben Sie bitte die in der App angezeigte Zahlenfolge erneut ein!");
|
||||
if ($debug) : echo "VERIFICATION NOT OK:</br>"; endif;
|
||||
if ($debug) : echo "f_2faCode = " . $f_2faCode . "</br>"; endif;
|
||||
if ($debug) : echo "currentCode = " . $currentCode . "</br>"; endif;
|
||||
endif;
|
||||
|
||||
else :
|
||||
|
||||
// Generate secret
|
||||
|
||||
$secret = $ga->createSecret();
|
||||
if ($debug) : echo "secret = " . $secret . "</br>"; endif;
|
||||
|
||||
if ($hq_id == $usrHqId) :
|
||||
|
||||
$res = updateStmt("user","usr_id",$usr_id,array("usr_totp_secret", $secret));
|
||||
if ($res > 0) :
|
||||
|
||||
$qrCodeUrl = $ga->getQRCodeGoogleUrl("Stadtbote:votian", $secret);
|
||||
if ($debug) : echo "qrCodeUrl = " . $qrCodeUrl . "</br>"; endif;
|
||||
|
||||
$oneCode = $ga->getCode($secret);
|
||||
if ($debug) : echo "Checking Code '$oneCode' and Secret '$secret':</br>"; endif;
|
||||
|
||||
$checkResult = $ga->verifyCode($secret, $oneCode, 2); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
if ($debug) : echo 'OK'; endif;
|
||||
} else {
|
||||
if ($debug) : echo 'FAILED'; endif;
|
||||
}
|
||||
else :
|
||||
$statusMessage = getLngt("Ein Schlüssel konnte nicht erstellt werden!");
|
||||
endif;
|
||||
else :
|
||||
$statusMessage = getLngt("Ihre aktuelle Niederlassung entspricht nicht der Ihrem Account zugeordneten! Ggfs. vor Aufruf bitte wechseln!");
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<?php if ($usrAccount != "") : ?>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title><?php echo $pageTitel ?></title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
|
||||
<style type="text/css">
|
||||
<?php include_once ("../css/navigation.css.php"); ?>
|
||||
</style>
|
||||
|
||||
<?php include_once ("../include/js_framework.inc.php"); ?>
|
||||
|
||||
<script src="../include/checkFormTags.js" type="text/javascript"></script>
|
||||
<script src="../include/searchLists.js" type="text/javascript"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
// NAVIGATION
|
||||
<?php echo $jsMenuOut; ?>
|
||||
|
||||
<?php echo $jsAction ?>
|
||||
|
||||
function finishPage() {
|
||||
if (document.forms[0].f_2faCode.value != '') {
|
||||
document.forms[0].f_act.value = 'verify';
|
||||
document.forms[0].submit();
|
||||
} else {
|
||||
alert('<?php echo getLngt("Bitte geben Sie den 2-FA-Code ein!"); ?>');
|
||||
}
|
||||
};
|
||||
|
||||
function bodyOnLoad () {
|
||||
// Key event listener
|
||||
document.forms[0].addEventListener("keydown", function(event) {
|
||||
// Return key (13)
|
||||
if (event.keyCode === 13) {
|
||||
finishPage();
|
||||
}
|
||||
});
|
||||
// Set focus
|
||||
document.forms[0].f_2faCode.focus();
|
||||
};
|
||||
-->
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>bodyOnLoad();displayStatusMessage();">
|
||||
|
||||
<?php echo $phpMenuOut ?>
|
||||
<?php echo $phpReducedMenuOut ?>
|
||||
<?php echo $phpPageTitelOut ?>
|
||||
|
||||
<div class="maincontent" name="maincontent" id="maincontent">
|
||||
|
||||
<form action="../admin/GA_generateBarcode.php" method="post">
|
||||
<input type="hidden" name="f_act" value="">
|
||||
<input type="hidden" name="activated2FA" value="<?php echo $activated2FA ?>">
|
||||
<input type="hidden" name="customerId" value="<?php echo $customerId ?>">
|
||||
<input type="hidden" name="cscIdRoot" value="<?php echo $cscIdRoot ?>">
|
||||
<input type="hidden" name="cscIdActual" value="<?php echo $cscIdActual ?>">
|
||||
<?php echo $phpCurrentNavigationInputHidden ?>
|
||||
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
|
||||
|
||||
<?php echo htmlDivLineSpacer("20px"); ?>
|
||||
|
||||
<div>
|
||||
<center>
|
||||
<table border="0" cellpadding="0">
|
||||
<tr>
|
||||
<td class="f12np1" align="center" width="300"></br></br><span class="f12bp1_blue"><?php echo $pageTitel ?></span></br></br></br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo getLngt("Öffnen Sie die Authenticator-App und richten Sie</br>ein neues Konto ein. Scannen Sie dazu mit der App</br>den folgenden QR-Code:") ?>
|
||||
</br></br>
|
||||
</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td align="center"><img src="<?php echo $qrCodeUrl ?>" border="0"></br></br></br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo getLngt("Bitte geben Sie den Code ein, der in</br>Ihrer 2-Faktor-Authentifizierzungs-App</br>angezeigt wird, und bestätigen Sie diesen!") ?>
|
||||
</br></br>
|
||||
</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<span class="f10bp1_red">>></span>
|
||||
<input type="text" id="f_2faCode" name="f_2faCode" value="" maxlength="6" size="6">
|
||||
<span class="f10bp1_blue"><a href="javascript:finishPage();"><?php echo getLngt("Bestätigen") ?></a></span>
|
||||
<span class="f10bp1_red"><<</span>
|
||||
</br></br></br>
|
||||
</td>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo getLngt("Sie können einen neuen Code erzeugen,</br>falls der angezeigte sich nicht scannen lässt.") ?>
|
||||
</br></br>
|
||||
</td>
|
||||
<tr>
|
||||
<td align="center"><span class="f10bp1_blue"><a href="javascript:document.forms[0].submit();"><?php echo getLngt("Neuen QR-Code generieren") ?></a></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"></br></br></br><span class="f10bp1_blue"><a href="javascript:this.close();"><?php echo getLngt("Schließen") ?></a></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
</div>
|
||||
<?php echo htmlDivLineSpacer("15px"); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<?php else :
|
||||
|
||||
header("Location: ../admin/start.php");
|
||||
|
||||
endif; ?>
|
||||
Reference in New Issue
Block a user