From 25fdf5f978c6f086b8bd1a088ba755827795cd95 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 1 Jun 2025 18:05:21 +0200 Subject: [PATCH] #441 SMS sending --- lam/help/help.inc | 3 +++ lam/lib/modules.inc | 29 ++++++++++++++++++++++------- lam/templates/lib/500_lam.js | 6 ++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lam/help/help.inc b/lam/help/help.inc index 368e1bf75..4f3983d68 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -435,6 +435,9 @@ $helpArray = [ "411" => ["Headline" => _("Font"), "Text" => _("Please select the font for the PDF file. Dejavu will work on all systems but does not support e.g. Chinese and Japanese. The other fonts require that an appropriate font is installed on the system where the PDF is opened.") ], + "412" => ["Headline" => _("Send via SMS"), + "Text" => _("Sends the password to the user via SMS.") + ], // 500 - 599 // LAM Pro "501" => ["Headline" => _("LDAP suffix"), diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index f996a08a0..285199971 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -835,8 +835,10 @@ class accountContainer { private $titleBarTitle; /** subtitle in title bar */ private $titleBarSubtitle; - /** send password via mail */ + /** password to send via mail */ private $sendPasswordViaMail; + /** password to send via SMS */ + private $sendPasswordViaSms; /** send password via mail to this alternate address */ private $sendPasswordViaMailAlternateAddress; @@ -1180,9 +1182,9 @@ class accountContainer { } $forcePwdGroup->addElement(new htmlHelpLink('406')); $container->addField($forcePwdGroup); + $container->addVerticalSpacer('0.25rem'); } if (isLAMProVersion() && (isset($this->attributes_orig['mail'][0]) || $this->anyModuleManagesMail())) { - $container->addVerticalSpacer('0.25rem'); $pwdMailCheckbox = new htmlResponsiveInputCheckbox('lamPasswordChangeSendMail', false, _('Send via mail'), '407'); $pwdMailCheckbox->setTableRowsToShow(['lamPasswordChangeMailAddress']); $container->add($pwdMailCheckbox); @@ -1199,6 +1201,9 @@ class accountContainer { $container->add($alternateMailInput); } } + if (isLAMProVersion() && (getSmsPhoneNumber($this->attributes_orig) !== null)) { + $container->add(new htmlResponsiveInputCheckbox('lamPasswordChangeSendSms', false, _('Send via SMS'), '412')); + } $container->addVerticalSpacer('0.25rem'); // password modules $moduleContainer = new htmlGroup(); @@ -1265,13 +1270,11 @@ class accountContainer { 'messages' => '', 'errorsOccurred' => 'false' ]; - $sendMail = false; - if (isset($input['sendMail']) && ($input['sendMail'] == 'true')) { - $sendMail = true; - } + $sendMail = isset($input['sendMail']) && ($input['sendMail'] == 'true'); + $sendSms = isset($input['sendSms']) && ($input['sendSms'] == 'true'); if ($random) { $password1 = generateRandomPassword(); - if (!$sendMail) { + if (!$sendMail && !$sendSms) { $return['messages'] .= StatusMessage('INFO', _('The password was set to:') . ' ' . htmlspecialchars($password1), '', [], true); } } @@ -1325,6 +1328,9 @@ class accountContainer { $this->sendPasswordViaMailAlternateAddress = $input['sendMailAlternateAddress']; } } + if (isLAMProVersion() && $sendSms) { + $this->sendPasswordViaSms = $password1; + } if ($return['errorsOccurred'] === 'false') { $return['messages'] .= StatusMessage('INFO', _('The new password will be stored in the directory after you save this account.'), '', [], true); $this->extraInfoAttributes['INFO.passwordUpdated'] = 'yes'; @@ -1332,6 +1338,7 @@ class accountContainer { $this->extraInfoAttributes['INFO.passwordChangeModules'] = implode(', ', $modules); $this->extraInfoAttributes['INFO.passwordChangeType'] = $random ? 'random' : 'manual'; $this->extraInfoAttributes['INFO.sendPasswordViaEmail'] = $sendMail ? 'yes' : 'no'; + $this->extraInfoAttributes['INFO.sendPasswordViaSms'] = $sendSms ? 'yes' : 'no'; if (!empty($input['sendMailAlternateAddress'])) { $this->extraInfoAttributes['INFO.sendPasswordAlternateAddress'] = $input['sendMailAlternateAddress']; } @@ -2106,6 +2113,14 @@ class accountContainer { $this->sendPasswordViaMail = null; $this->sendPasswordViaMailAlternateAddress = null; } + // send password SMS + if (!$stopprocessing && isLAMProVersion() && ($this->sendPasswordViaSms != null)) { + $smsMessages = sendPasswordSms($this->sendPasswordViaSms, $prePostModifyAttributes); + if (count($smsMessages) > 0) { + $errors = array_merge($errors, $smsMessages); + } + $this->sendPasswordViaSms = null; + } if (!$stopprocessing) { // post modify actions foreach ($module as $singlemodule) { diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index eeaa5c6e9..6c82e62c4 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -232,6 +232,11 @@ function passwordHandleInput(random, ajaxURL, tokenName, tokenValue, okText) { if (lamPasswordChangeSendMailBox && lamPasswordChangeSendMailBox.checked) { sendMail = true; } + let sendSms = false; + const lamPasswordChangeSendSmsBox = passwordDialog.querySelector('input[name=lamPasswordChangeSendSms]'); + if (lamPasswordChangeSendSmsBox && lamPasswordChangeSendSmsBox.checked) { + sendSms = true; + } let sendMailAlternateAddress = ''; const lamPasswordChangeMailAddress = passwordDialog.querySelector('[name=lamPasswordChangeMailAddress]'); @@ -245,6 +250,7 @@ function passwordHandleInput(random, ajaxURL, tokenName, tokenValue, okText) { "random": random, "forcePasswordChange": forcePasswordChange, "sendMail": sendMail, + "sendSms": sendSms, "sendMailAlternateAddress": sendMailAlternateAddress }; let data = new FormData();