Skip to content
Snippets Groups Projects
Commit 1169ad78 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

improve logging

parent 613458ad
No related branches found
No related tags found
1 merge request!42Imporove logging
...@@ -16,10 +16,10 @@ if(count($_POST)){ ...@@ -16,10 +16,10 @@ if(count($_POST)){
if(($_POST['action']??false) == "verify"){ if(($_POST['action']??false) == "verify"){
if($_SESSION['mfa_emailcode']!==$_POST['code']){ if($_SESSION['mfa_emailcode']!==$_POST['code']){
$oUser->log("error", "User entered wrong code for TOTP verification"); $oUser->log("error", "challenge $sMethod: wrong code.");
$CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div>"; $CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div>";
} else { } else {
$oUser->log("ok", "Email verification succeeded."); $oUser->log("ok", "challenge $sMethod: succeeded.");
$oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??''); $oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??'');
session_start(); session_start();
...@@ -31,7 +31,6 @@ if(count($_POST)){ ...@@ -31,7 +31,6 @@ if(count($_POST)){
header("location: " . $_SESSION['mfa_backurl']); header("location: " . $_SESSION['mfa_backurl']);
} }
// OK // OK
$oUser->log("debug", "TOTP verification succeeded.");
$CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>"; $CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>";
return true; return true;
......
...@@ -18,12 +18,12 @@ if(count($_POST)){ ...@@ -18,12 +18,12 @@ if(count($_POST)){
$bCodeOK=false; $bCodeOK=false;
if (ahTotp::verify_key($aMethodConfig['secret'], $_POST['code'])){ if (ahTotp::verify_key($aMethodConfig['secret'], $_POST['code'])){
$bCodeOK=true; $bCodeOK=true;
$oUser->log("ok", "TOTP verification succeeded."); $oUser->log("ok", "challenge $sMethod: succeeded - TOTP code verified.");
} else { } else {
$aCodes=$aMethodConfig['backupcodes']??[]; $aCodes=$aMethodConfig['backupcodes']??[];
if (isset($aCodes[$_POST['code']]) && $aCodes[$_POST['code']]==false){ if (isset($aCodes[$_POST['code']]) && $aCodes[$_POST['code']]==false){
$bCodeOK=true; $bCodeOK=true;
$oUser->log("ok", "TOTP backup code succeeded."); $oUser->log("ok", "challenge $sMethod: succeeded - backup code was used.");
$aMethodConfig['backupcodes'][$_POST['code']]=time(); $aMethodConfig['backupcodes'][$_POST['code']]=time();
$oUser->mfaAdd($sMethod, $aMethodConfig, true); $oUser->mfaAdd($sMethod, $aMethodConfig, true);
} }
...@@ -35,13 +35,12 @@ if(count($_POST)){ ...@@ -35,13 +35,12 @@ if(count($_POST)){
header("location: " . $_SESSION['mfa_backurl']); header("location: " . $_SESSION['mfa_backurl']);
} }
// OK // OK
$oUser->log("debug", "TOTP verification succeeded.");
$CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>"; $CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>";
return true; return true;
} else { } else {
// ERROR ... and show the form again // ERROR ... and show the form again
$oUser->log("error", "User entered wrong code for TOTP verification"); $oUser->log("error", "challenge $sMethod: TOTP was wrong.");
$CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div>"; $CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div>";
} }
} }
......
...@@ -22,6 +22,7 @@ if(count($_POST)){ ...@@ -22,6 +22,7 @@ if(count($_POST)){
session_start(); session_start();
if($_SESSION['mfa_setup_emailcode']!==$_POST['code']){ if($_SESSION['mfa_setup_emailcode']!==$_POST['code']){
$oUser->log("error", "setup $sMethod: $sAction wrong code.");
$CONTENT.="<div class=\"msg error\">{{setup.email.code-failed}}</div><br>"; $CONTENT.="<div class=\"msg error\">{{setup.email.code-failed}}</div><br>";
} else { } else {
if ($oUser->mfaAdd($sMethod, [ if ($oUser->mfaAdd($sMethod, [
...@@ -33,6 +34,7 @@ if(count($_POST)){ ...@@ -33,6 +34,7 @@ if(count($_POST)){
<br> <br>
<a class=\"pure-button\" href=\"?page=setup\">{{ico.back}} {{back}}</a> <a class=\"pure-button\" href=\"?page=setup\">{{ico.back}} {{back}}</a>
"; ";
$oUser->log("ok", "setup $sMethod: $sAction ok.");
$oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??''); $oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??'');
unset($_SESSION['mfa_setup_emailcode']); unset($_SESSION['mfa_setup_emailcode']);
unset($_SESSION['mfa_setup_emailaddress']); unset($_SESSION['mfa_setup_emailaddress']);
......
...@@ -37,6 +37,7 @@ if(count($_POST)){ ...@@ -37,6 +37,7 @@ if(count($_POST)){
if (ahTotp::verify_key($_POST['secret'], $_POST['code'])){ if (ahTotp::verify_key($_POST['secret'], $_POST['code'])){
// OK // OK
// $CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>"; // $CONTENT.="<div class=\"msg success\">{{mfa.verification-ok}}</div>";
$oUser->log("ok", "setup $sMethod: $sAction ok.");
$oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??''); $oUser->mfaSolved($sMethod, $_SESSION['mfa_ip']??'');
if ($oUser->mfaAdd($sMethod, [ if ($oUser->mfaAdd($sMethod, [
"secret" => $sSecret, "secret" => $sSecret,
...@@ -54,6 +55,7 @@ if(count($_POST)){ ...@@ -54,6 +55,7 @@ if(count($_POST)){
} }
} else { } else {
// ERROR // ERROR
$oUser->log("error", "setup $sMethod: $sAction wrong code.");
$CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div> $CONTENT.="<div class=\"msg error\">{{mfa.verification-failed}}</div>
<br> <br>
"; ";
...@@ -63,6 +65,7 @@ if(count($_POST)){ ...@@ -63,6 +65,7 @@ if(count($_POST)){
// ----- delete TOTP // ----- delete TOTP
case 'delete': case 'delete':
if ($oUser->mfaDelete($sMethod)){ if ($oUser->mfaDelete($sMethod)){
$oUser->log("ok", "setup $sMethod: $sAction ok.");
$CONTENT.="<div class=\"msg success\">{{mfa.save-ok}}</div> $CONTENT.="<div class=\"msg success\">{{mfa.save-ok}}</div>
<br> <br>
{{mfa.deleted}}<br> {{mfa.deleted}}<br>
...@@ -72,6 +75,7 @@ if(count($_POST)){ ...@@ -72,6 +75,7 @@ if(count($_POST)){
"; ";
return true; return true;
} else { } else {
$oUser->log("error", "setup $sMethod: $sAction failed.");
$CONTENT.="<div class=\"msg error\">{{mfa.save-failed}}</div>"; $CONTENT.="<div class=\"msg error\">{{mfa.save-failed}}</div>";
} }
break; break;
...@@ -80,13 +84,16 @@ if(count($_POST)){ ...@@ -80,13 +84,16 @@ if(count($_POST)){
case "renewbackupcodes": case "renewbackupcodes":
$aTotpSettings['backupcodes']=generateBackupcodes(); $aTotpSettings['backupcodes']=generateBackupcodes();
if($oUser->mfaAdd($sMethod, $aTotpSettings, true)){ if($oUser->mfaAdd($sMethod, $aTotpSettings, true)){
$oUser->log("ok", "setup $sMethod: $sAction ok.");
$CONTENT.="<div class=\"msg success\">{{mfa.save-ok}}</div>"; $CONTENT.="<div class=\"msg success\">{{mfa.save-ok}}</div>";
} else { } else {
$oUser->log("error", "setup $sMethod: $sAction failed.");
$CONTENT.="<div class=\"msg error\">{{mfa.save-failed}}</div>"; $CONTENT.="<div class=\"msg error\">{{mfa.save-failed}}</div>";
} }
break; break;
// ----- unknown action // ----- unknown action
default: default:
$oUser->log("error", "setup $sMethod: $sAction does not exist.");
$CONTENT.="<div class=\"msg error\">{{mfa.unknown-action}}</div>"; $CONTENT.="<div class=\"msg error\">{{mfa.unknown-action}}</div>";
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment