#441 SMS sending

This commit is contained in:
Roland Gruber 2025-06-01 17:23:47 +02:00
parent 6c310da489
commit d87931d1f4
4 changed files with 61 additions and 10 deletions

View file

@ -1668,6 +1668,28 @@ function isCommandlineSafeEmailAddress($address) {
return true;
}
/**
* Sends the password SMS.
*
* @param string $pwd new password
* @param array $user LDAP attributes of user
* @return array list of arrays that can be used to create status messages
*/
function sendPasswordSms(string $pwd, array $user): array {
$errors = [];
$phoneNumber = getSmsPhoneNumber($user);
include_once __DIR__ . '/plugins/sms/SmsService.inc';
$smsService = new SmsService();
try {
$smsService->sendSms(sprintf(_('Your new password: %s'), $pwd), $phoneNumber);
}
catch (LAMException $e) {
logNewMessage(LOG_ERR, 'SMS sending failed: ' . $e->getMessage());
$errors[] = ['ERROR', _('Unable to send SMS.'), $e->getMessage()];
}
return $errors;
}
/**
* Sends an SMS test message.
*
@ -1691,6 +1713,23 @@ function sendSmsTestMessage(string $providerId, ?string $apiKey, ?string $apiTok
}
}
/**
* Returns the SMS phone number of a user.
*
* @param array $attributes LDAP attributes
* @return string|null phone number if found
*/
function getSmsPhoneNumber(array $attributes): ?string {
$phoneAttributes = array_change_key_case($_SESSION['cfgMain']->getSmsAttributes());
$attributes = array_change_key_case($attributes);
foreach ($phoneAttributes as $phoneAttribute) {
if (!empty($attributes[$phoneAttribute][0])) {
return $attributes[$phoneAttribute][0];
}
}
return null;
}
/**
* Caches module objects.
* This improves performance if the same module does not need to be created multiple times (calling get_metaData() each time).

View file

@ -868,23 +868,25 @@ class ServerProfilePersistenceStrategyPdo implements ServerProfilePersistenceStr
class LAMConfig {
/* access levels */
const ACCESS_ALL = 100;
const ACCESS_PASSWORD_CHANGE = 20;
const ACCESS_READ_ONLY = 0;
public const ACCESS_ALL = 100;
public const ACCESS_PASSWORD_CHANGE = 20;
public const ACCESS_READ_ONLY = 0;
/* login method: predefined list or LDAP search */
const LOGIN_LIST = 'list';
const LOGIN_SEARCH = 'search';
public const LOGIN_LIST = 'list';
public const LOGIN_SEARCH = 'search';
/** line separator */
const LINE_SEPARATOR = '+::+';
public const LINE_SEPARATOR = '+::+';
/** show password on screen by default */
const PWDRESET_DEFAULT_SCREEN = 1;
public const PWDRESET_DEFAULT_SCREEN = 1;
/** send password via email by default */
const PWDRESET_DEFAULT_MAIL = 2;
public const PWDRESET_DEFAULT_MAIL = 2;
/** send password via SMS by default */
public const PWDRESET_DEFAULT_SMS = 4;
/** show password on screen and send via email by default */
const PWDRESET_DEFAULT_BOTH = 3;
public const PWDRESET_DEFAULT_ALL = 3;
/** Server address (e.g. ldap://127.0.0.1:389) */
private $ServerURL;

View file

@ -3951,6 +3951,10 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
$row->addLabel(new htmlOutputText(_('Telephone number')));
$row->addField(new htmlOutputText($this->attributes['telephoneNumber'][0]));
}
if (!empty($this->attributes['mobile'][0])) {
$row->addLabel(new htmlOutputText(_('Mobile number')));
$row->addField(new htmlOutputText($this->attributes['mobile'][0]));
}
}
/**

View file

@ -3,6 +3,7 @@
namespace LAM\CONFIG;
use LAM\LIB\TWO_FACTOR\TwoFactorProviderService;
use LAMCfgMain;
use LAMConfig;
use htmlTable;
use htmlAccordion;
@ -187,6 +188,8 @@ if ($errorsToDisplay !== []) {
echo "<br>";
}
$cfgMain = new LAMCfgMain();
// display formular
echo "<form enctype=\"multipart/form-data\" action=\"confmain.php\" method=\"post\" autocomplete=\"off\" novalidate=\"novalidate\">\n";
@ -412,8 +415,11 @@ if (isLAMProVersion()) {
$pwdResetDefaultPasswordOutputOptions = [
_('Display on screen') => LAMConfig::PWDRESET_DEFAULT_SCREEN,
_('Send via mail') => LAMConfig::PWDRESET_DEFAULT_MAIL,
_('Both') => LAMConfig::PWDRESET_DEFAULT_BOTH
_('All') => LAMConfig::PWDRESET_DEFAULT_ALL
];
if (!empty($cfgMain->smsProvider)) {
$pwdResetDefaultPasswordOutputOptions[_('Send via SMS')] = LAMConfig::PWDRESET_DEFAULT_SMS;
}
$pwdResetDefaultPasswordOutputSelect = new htmlResponsiveSelect('pwdResetDefaultPasswordOutput', $pwdResetDefaultPasswordOutputOptions, [$conf->getPwdResetDefaultPasswordOutput()], _("Default password output"), '282');
$pwdResetDefaultPasswordOutputSelect->setHasDescriptiveElements(true);
$row->add($pwdResetDefaultPasswordOutputSelect);