Skip to content

Commit

Permalink
fix resending mail requests (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Jul 24, 2024
1 parent 234b399 commit fd4feff
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 2 deletions.
1 change: 1 addition & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
if (isset($question)) { $smarty->assign('question', $question); }

if (isset($login)) { $smarty->assign('login', $login); }
if (isset($formtoken)) { $smarty->assign('formtoken', $formtoken); }
if (isset($usermail)) { $smarty->assign('usermail', $usermail); }
if (isset($displayname[0])) { $smarty->assign('displayname', $displayname[0]); }
if (isset($encrypted_sms_login)) { $smarty->assign('encrypted_sms_login', $encrypted_sms_login); }
Expand Down
50 changes: 49 additions & 1 deletion htdocs/sendtoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$userdn = "";
$token = "";
$usermail = "";
$formtoken = "";

if (!$mail_address_use_ldap) {
if (isset($_POST["mail"]) and $_POST["mail"]) {
Expand All @@ -48,7 +49,26 @@
if (isset($_REQUEST["login"]) and $_REQUEST["login"]) { $login = strval($_REQUEST["login"]);}
else { $result = "loginrequired";}

if (! isset($_POST["mail"]) and ! isset($_REQUEST["login"])) { $result = "emptysendtokenform"; }
if ( $result === "" and ( ! isset($_REQUEST["formtoken"]) or ! $_REQUEST["formtoken"] ) ) {
$result = "missingformtoken";
}

if (! isset($_POST["mail"]) and ! isset($_REQUEST["login"])) {

$result = "emptysendtokenform";

# Generate formtoken
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",1);
ini_set("session.use_strict_mode",0);
session_name("formtoken");
session_id(session_create_id());
session_start();
$formtoken = session_id();
$_SESSION['formtoken'] = $formtoken;
error_log("generated token: " . $formtoken);
session_write_close();
}

# Check the entered username for characters that our installation doesn't support
if ( $result === "" ) {
Expand Down Expand Up @@ -162,14 +182,42 @@
} else {
$token = session_id();
}
session_write_close();
}


#==============================================================================
# Check tokenform
#==============================================================================

if ( !$result ) {
$formtoken = strval($_REQUEST["formtoken"]);
ini_set("session.use_cookies",0);
ini_set("session.use_only_cookies",1);
ini_set("session.use_strict_mode",0);
session_name("formtoken");
session_id($formtoken);
session_start();
if( $_SESSION['formtoken'] == $formtoken )
{
# Remove session
session_unset();
session_destroy();
}
else
{
error_log("Invalid form token: sent: $formtoken, stored: " . $_SESSION['formtoken']);
$result = "invalidformtoken";
}
session_write_close();
}

#==============================================================================
# Send token by mail
#==============================================================================
if ( !$result ) {


$reset_url .= "?action=resetbytoken&token=".urlencode($token);

if ( !empty($reset_request_log) ) {
Expand Down
2 changes: 2 additions & 0 deletions lang/ar.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "رقم الرسائل القصيرة لا يتطابق مع اسم المستخدم.";
$messages['sameasaccountpassword'] = "كلمة المرور الجديدة مطابقة لكلمة مرور تسجيل الدخول";
$messages['policynoreusecustompwdfield'] = "لا يجب ان تكون كلمة المرور الجديدة هي نفسها كلمة مرور تسجيل الدخول";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/ca.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/cn.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/cs.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/de.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/ee.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/el.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/en.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/es.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/eu.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/fr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "Le numéro de téléphone ne correspond pas à l'identifiant donné.";
$messages['sameasaccountpassword'] = "Votre nouveau mot de passe est identique à votre mot de passe de connexion";
$messages['policynoreusecustompwdfield'] = "Votre nouveau mot de passe ne devrait pas être le même que le mot de passe de connexion";
$messages['missingformtoken'] = "Jeton manquant";
$messages['invalidformtoken'] = "Jeton invalide";
2 changes: 2 additions & 0 deletions lang/hu.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/it.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/ja.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/nb-NO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/nl.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/pl.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/pt-BR.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/pt-PT.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/rs.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/ru.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/sk.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/sl.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/sv.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/tr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/uk.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/zh-CN.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 2 additions & 0 deletions lang/zh-TW.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@
$messages['smsnomatch'] = "The SMS number does not match the submitted login.";
$messages['sameasaccountpassword'] = "Your new password is identical to your login password";
$messages['policynoreusecustompwdfield'] = "Your new password may not be the same as your login password";
$messages['missingformtoken'] = "Missing token";
$messages['invalidformtoken'] = "Invalid token";
2 changes: 1 addition & 1 deletion lib/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function generate_sms_token( $sms_token_length ) {
# Get message criticity
function get_criticity( $msg ) {

if ( preg_match( "/nophpldap|phpupgraderequired|nophpmhash|nokeyphrase|ldaperror|nomatch|badcredentials|passworderror|tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|answermoderror|answernomatch|mailnomatch|tokennotsent|tokennotvalid|notcomplex|smsnonumber|smscrypttokensrequired|nophpmbstring|nophpxml|smsnotsent|sameaslogin|pwned|invalidsshkey|sshkeyerror|specialatends|forbiddenwords|forbiddenldapfields|diffminchars|badquality|tooyoung|inhistory|throttle|attributesmoderror|insufficiententropy|noreseturl|nocrypttokens|smsnomatch|unknowncustompwdfield|sameascustompwd/" , $msg ) ) {
if ( preg_match( "/nophpldap|phpupgraderequired|nophpmhash|nokeyphrase|ldaperror|nomatch|badcredentials|passworderror|tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|answermoderror|answernomatch|mailnomatch|tokennotsent|tokennotvalid|notcomplex|smsnonumber|smscrypttokensrequired|nophpmbstring|nophpxml|smsnotsent|sameaslogin|pwned|invalidsshkey|sshkeyerror|specialatends|forbiddenwords|forbiddenldapfields|diffminchars|badquality|tooyoung|inhistory|throttle|attributesmoderror|insufficiententropy|noreseturl|nocrypttokens|smsnomatch|unknowncustompwdfield|sameascustompwd|missingformtoken|invalidformtoken/" , $msg ) ) {
return "danger";
}

Expand Down
1 change: 1 addition & 0 deletions templates/sendtoken.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" name="login" id="login" value="{$login}" class="form-control" placeholder="{$msg_login}" autocomplete="off" />
<input type="hidden" name="formtoken" id="formtoken" value="{$formtoken}" />
</div>
</div>
</div>
Expand Down

0 comments on commit fd4feff

Please sign in to comment.