| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\INIT; |
| 4 |
|
| 5 |
use htmlButton; |
| 6 |
use htmlOutputText; |
| 7 |
use htmlResponsiveInputField; |
| 8 |
use htmlResponsiveRow; |
| 9 |
use htmlStatusMessage; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
include_once(__DIR__ . "/../lib/security.inc"); |
| 41 |
|
| 42 |
include_once(__DIR__ . "/../lib/config.inc"); |
| 43 |
|
| 44 |
include_once(__DIR__ . "/../lib/ldap.inc"); |
| 45 |
|
| 46 |
include_once(__DIR__ . "/../lib/status.inc"); |
| 47 |
|
| 48 |
|
| 49 |
startSecureSession(); |
| 50 |
enforceUserIsLoggedIn(); |
| 51 |
|
| 52 |
if (!checkIfWriteAccessIsAllowed()) { |
| 53 |
die(); |
| 54 |
} |
| 55 |
|
| 56 |
setlanguage(); |
| 57 |
|
| 58 |
if (!empty($_POST)) { |
| 59 |
validateSecurityToken(); |
| 60 |
} |
| 61 |
|
| 62 |
$message = null; |
| 63 |
|
| 64 |
|
| 65 |
if (isset($_POST['changePassword'])) { |
| 66 |
|
| 67 |
$password1 = $_POST['password1']; |
| 68 |
$password2 = $_POST['password2']; |
| 69 |
if ($password1 == '') { |
| 70 |
$message = new htmlStatusMessage('ERROR', _('No password was entered!')); |
| 71 |
printContent($message); |
| 72 |
exit(); |
| 73 |
} |
| 74 |
|
| 75 |
if ($password1 != $password2) { |
| 76 |
$message = new htmlStatusMessage('ERROR', _('Passwords are different!')); |
| 77 |
printContent($message); |
| 78 |
exit(); |
| 79 |
} |
| 80 |
|
| 81 |
$userDn = $_SESSION['ldap']->getUserName(); |
| 82 |
$rdnAttr = extractRDNAttribute($userDn); |
| 83 |
$userName = null; |
| 84 |
if ($rdnAttr === 'uid') { |
| 85 |
$userName = extractRDNValue($userDn); |
| 86 |
} |
| 87 |
$pwdPolicyResult = checkPasswordStrength($password1, $userName, []); |
| 88 |
if (!$pwdPolicyResult->isValid()) { |
| 89 |
$message = new htmlStatusMessage('ERROR', $pwdPolicyResult->getTextMessage()); |
| 90 |
printContent($message); |
| 91 |
exit(); |
| 92 |
} |
| 93 |
|
| 94 |
$modifyResult = @ldap_exop_passwd($_SESSION['ldap']->server(), $userDn, $_SESSION['ldap']->getPassword(), $password1); |
| 95 |
if ($modifyResult === true) { |
| 96 |
$_SESSION['ldap']->tryAndApplyNewPassword($password1); |
| 97 |
$message = new htmlStatusMessage('INFO', _('Password changed.')); |
| 98 |
printContent($message, false); |
| 99 |
exit(); |
| 100 |
} |
| 101 |
else { |
| 102 |
$message = new htmlStatusMessage('ERROR', _('Unable to set password'), getExtendedLDAPErrorMessage($_SESSION['ldap']->server())); |
| 103 |
printContent($message); |
| 104 |
exit(); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
printContent($message); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
function printContent($message = null, $showPasswordInputs = true): void { |
| 117 |
include_once __DIR__ . '/../lib/adminHeader.inc'; |
| 118 |
echo '<div class="smallPaddingContent">'; |
| 119 |
echo "<form action=\"changePassword.php\" method=\"post\">\n"; |
| 120 |
$container = new htmlResponsiveRow(); |
| 121 |
if ($message !== null) { |
| 122 |
$container->addVerticalSpacer('1rem'); |
| 123 |
$container->add($message, 12); |
| 124 |
} |
| 125 |
$container->addVerticalSpacer('2rem'); |
| 126 |
if ($showPasswordInputs) { |
| 127 |
$container->add(new htmlOutputText(_("It seems your password expired. You can set a new one here.")), 12, 12, 12, 'text-center'); |
| 128 |
$container->addVerticalSpacer('2rem'); |
| 129 |
$pwdInput1 = new htmlResponsiveInputField(_('New password'), 'password1', ''); |
| 130 |
$pwdInput1->setIsPassword(true, true, true); |
| 131 |
$container->add($pwdInput1, 12); |
| 132 |
$pwdInput2 = new htmlResponsiveInputField(_('Repeat password'), 'password2', ''); |
| 133 |
$pwdInput2->setIsPassword(true); |
| 134 |
$pwdInput2->setSameValueFieldID('password1'); |
| 135 |
$container->add($pwdInput2, 12); |
| 136 |
$container->addVerticalSpacer('1rem'); |
| 137 |
$container->add(new htmlButton('changePassword', _("Submit")), 12, 12, 12, 'text-center'); |
| 138 |
addSecurityTokenToMetaHTML($container); |
| 139 |
} |
| 140 |
|
| 141 |
parseHtml(null, $container, [], false); |
| 142 |
|
| 143 |
echo "</form><br>\n"; |
| 144 |
echo "</div>\n"; |
| 145 |
include_once __DIR__ . '/../lib/adminFooter.inc'; |
| 146 |
} |