| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) |
| 5 |
Copyright (C) 2010 Pavel Pozdnyak |
| 6 |
2010 - 2026 Roland Gruber |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 2 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program; if not, write to the Free Software |
| 20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 |
|
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Manages the Asterisk extension of user accounts. |
| 27 |
* |
| 28 |
* @package modules |
| 29 |
* |
| 30 |
* @author Pavel Pozdnyak |
| 31 |
* @author Roland Gruber |
| 32 |
*/ |
| 33 |
|
| 34 |
use LAM\TYPES\ConfiguredType; |
| 35 |
|
| 36 |
/** |
| 37 |
* Manages the Asterisk extension of user accounts. |
| 38 |
* |
| 39 |
* @package modules |
| 40 |
*/ |
| 41 |
class asteriskVoicemail extends baseModule implements passwordService { |
| 42 |
|
| 43 |
/** |
| 44 |
* These attributes will be ignored by default if a new account is copied from an existing one. |
| 45 |
*/ |
| 46 |
private const ATTRIBUTES_TO_IGNORE_ON_COPY = ['AstVoicemailMailbox', 'AstVoicemailPassword', |
| 47 |
'AstVoicemailEmail', 'AstVoicemailPager', 'AstVoicemailFullname']; |
| 48 |
|
| 49 |
/** |
| 50 |
* Creates a new asteriskVoicemail object. |
| 51 |
* |
| 52 |
* @param string $scope account type (user, group, host) |
| 53 |
*/ |
| 54 |
public function __construct($scope) { |
| 55 |
// call parent constructor |
| 56 |
parent::__construct($scope); |
| 57 |
$this->autoAddObjectClasses = false; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* {@inheritDoc} |
| 62 |
*/ |
| 63 |
public function can_manage(): bool { |
| 64 |
return $this->get_scope() === 'user'; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* {@inheritDoc} |
| 69 |
*/ |
| 70 |
public function get_metaData(): array { |
| 71 |
$return = []; |
| 72 |
$return["is_base"] = false; |
| 73 |
// alias name |
| 74 |
$return["alias"] = _("Asterisk voicemail"); |
| 75 |
// module dependencies |
| 76 |
$return['dependencies'] = ['depends' => ['inetOrgPerson'], 'conflicts' => []]; |
| 77 |
// managed object classes |
| 78 |
$return['objectClasses'] = ['AsteriskVoiceMail']; |
| 79 |
// managed attributes |
| 80 |
$return['attributes'] = ['AstContext', 'AstVoicemailMailbox', |
| 81 |
'AstVoicemailPassword', 'AstVoicemailFullname', 'AstVoicemailEmail', |
| 82 |
'AstVoicemailPager', 'AstVoicemailOptions', 'AstVoicemailContext']; |
| 83 |
// icon |
| 84 |
$return['icon'] = 'asterisk.png'; |
| 85 |
// self-service |
| 86 |
$return['selfServiceFieldSettings'] = [ |
| 87 |
'syncAsteriskVoicemailPassword' => _('Sync Asterisk password with Unix password'), |
| 88 |
]; |
| 89 |
// self-service: fields that cannot be relabeled |
| 90 |
$return['selfServiceNoRelabelFields'] = ['syncAsteriskVoicemailPassword']; |
| 91 |
// help |
| 92 |
$return['help'] = [ |
| 93 |
'AstContext' => [ |
| 94 |
"Headline" => _("Account context"), 'attr' => 'AstContext', |
| 95 |
"Text" => _("The account context stores information about the dial plan.") |
| 96 |
], |
| 97 |
'AstVoicemailMailbox' => [ |
| 98 |
"Headline" => _("Mailbox"), 'attr' => 'AstVoicemailMailbox', |
| 99 |
"Text" => _("Voicemail mailbox for this account.") |
| 100 |
], |
| 101 |
'AstVoicemailPassword' => [ |
| 102 |
"Headline" => _("Password"), 'attr' => 'AstVoicemailPassword', |
| 103 |
"Text" => _("Password for voicemail mailbox.") |
| 104 |
], |
| 105 |
'AstVoicemailFullname' => [ |
| 106 |
"Headline" => _("Full name"), 'attr' => 'AstVoicemailFullname', |
| 107 |
"Text" => _("Full name for Asterisk voicemail mailbox.") |
| 108 |
], |
| 109 |
'AstVoicemailEmail' => [ |
| 110 |
"Headline" => _("Email address"), 'attr' => 'AstVoicemailEmail', |
| 111 |
"Text" => _("Email address for this voicemail account.") |
| 112 |
], |
| 113 |
'AstVoicemailPager' => [ |
| 114 |
"Headline" => _("Pager"), 'attr' => 'AstVoicemailPager', |
| 115 |
"Text" => _("Pager number for Asterisk voicemail.") |
| 116 |
], |
| 117 |
'AstVoicemailOptions' => [ |
| 118 |
"Headline" => _("Options"), 'attr' => 'AstVoicemailOptions', |
| 119 |
"Text" => _("Options for Asterisk voicemail account (e.g. sendvoicemail=yes).") |
| 120 |
], |
| 121 |
'AstVoicemailContext' => [ |
| 122 |
"Headline" => _("Voicemail context"), 'attr' => 'AstVoicemailContext', |
| 123 |
"Text" => _("Asterisk voicemail context.") |
| 124 |
], |
| 125 |
]; |
| 126 |
// profile options |
| 127 |
$profileContainer = new htmlResponsiveRow(); |
| 128 |
$profileContainer->add(new htmlResponsiveInputField(_('Options'), 'asteriskVoicemail_AstVoicemailOptions', null, 'AstVoicemailOptions')); |
| 129 |
$profileContainer->add(new htmlResponsiveInputField(_('Voicemail context'), 'asteriskVoicemail_AstVoicemailContext', null, 'AstVoicemailContext')); |
| 130 |
$profileContainer->add(new htmlResponsiveInputField(_('Account context'), 'asteriskVoicemail_AstContext', null, 'AstContext')); |
| 131 |
$return['profile_options'] = $profileContainer; |
| 132 |
// profile mappings |
| 133 |
$return['profile_mappings'] = [ |
| 134 |
'asteriskVoicemail_AstContext' => 'AstContext', |
| 135 |
'asteriskVoicemail_AstVoicemailContext' => 'AstVoicemailContext', |
| 136 |
'asteriskVoicemail_AstVoicemailOptions' => 'AstVoicemailOptions' |
| 137 |
]; |
| 138 |
// available PDF fields |
| 139 |
$return['PDF_fields'] = [ |
| 140 |
'AstContext' => _('Account context'), |
| 141 |
'AstVoicemailMailbox' => _('Mailbox'), |
| 142 |
'AstVoicemailFullname' => _('Full name'), |
| 143 |
'AstVoicemailEmail' => _('Email address'), |
| 144 |
'AstVoicemailPager' => _('Pager'), |
| 145 |
'AstVoicemailOptions' => _('Options'), |
| 146 |
'AstVoicemailContext' => _('Voicemail context') |
| 147 |
]; |
| 148 |
// upload dependencies |
| 149 |
$return['upload_preDepends'] = ['posixAccount', 'inetOrgPerson']; |
| 150 |
// upload fields |
| 151 |
$return['upload_columns'] = [ |
| 152 |
[ |
| 153 |
'name' => 'asteriskVoicemail_AstContext', |
| 154 |
'description' => _('Account context'), |
| 155 |
'help' => 'AstContext', |
| 156 |
'example' => 'default', |
| 157 |
'required' => true |
| 158 |
], |
| 159 |
[ |
| 160 |
'name' => 'asteriskVoicemail_AstVoicemailMailbox', |
| 161 |
'description' => _('Mailbox'), |
| 162 |
'help' => 'AstVoicemailMailbox', |
| 163 |
'example' => '12345', |
| 164 |
'required' => true |
| 165 |
], |
| 166 |
[ |
| 167 |
'name' => 'asteriskVoicemail_AstVoicemailPassword', |
| 168 |
'description' => _('Password'), |
| 169 |
'help' => 'AstVoicemailPassword', |
| 170 |
'example' => _('secret'), |
| 171 |
'required' => true |
| 172 |
], |
| 173 |
[ |
| 174 |
'name' => 'asteriskVoicemail_AstVoicemailFullname', |
| 175 |
'description' => _('Full name'), |
| 176 |
'help' => 'AstVoicemailFullname', |
| 177 |
'example' => _('Steve Miller') |
| 178 |
], |
| 179 |
[ |
| 180 |
'name' => 'asteriskVoicemail_AstVoicemailEmail', |
| 181 |
'description' => _('Email address'), |
| 182 |
'help' => 'AstVoicemailEmail', |
| 183 |
'example' => _('[email protected]') |
| 184 |
], |
| 185 |
[ |
| 186 |
'name' => 'asteriskVoicemail_AstVoicemailPager', |
| 187 |
'description' => _('Pager'), |
| 188 |
'help' => 'AstVoicemailPager', |
| 189 |
'example' => _('123-123-1234') |
| 190 |
], |
| 191 |
[ |
| 192 |
'name' => 'asteriskVoicemail_AstVoicemailOptions', |
| 193 |
'description' => _('Options'), |
| 194 |
'help' => 'AstVoicemailOptions', |
| 195 |
'example' => 'sendvoicemail=yes' |
| 196 |
], |
| 197 |
[ |
| 198 |
'name' => 'asteriskVoicemail_AstVoicemailContext', |
| 199 |
'description' => _('Voicemail context'), |
| 200 |
'help' => 'AstVoicemailContext', |
| 201 |
'example' => 'default' |
| 202 |
] |
| 203 |
]; |
| 204 |
return $return; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* {@inheritDoc} |
| 209 |
*/ |
| 210 |
protected function load_Messages(): void { |
| 211 |
//messages for voicemail |
| 212 |
$this->messages['AstVoicemailMailbox'][0] = ['ERROR', _('Please enter a mailbox.')]; |
| 213 |
$this->messages['AstVoicemailMailbox'][1] = ['ERROR', _('The mailbox format is invalid.')]; |
| 214 |
$this->messages['AstVoicemailMailbox'][2] = ['ERROR', _('There is already another user with this mailbox name.')]; |
| 215 |
$this->messages['AstVoicemailMailbox'][3] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailMailbox', _('The mailbox format is invalid.')]; |
| 216 |
|
| 217 |
$this->messages['AstContext'][0] = ['ERROR', _('Please enter the account context.')]; |
| 218 |
$this->messages['AstContext'][1] = ['ERROR', _('The account context is invalid.')]; |
| 219 |
$this->messages['AstContext'][2] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstContext', _('The account context is invalid.')]; |
| 220 |
|
| 221 |
$this->messages['AstVoicemailFullname'][0] = ['ERROR', _('The full name is invalid.')]; |
| 222 |
$this->messages['AstVoicemailFullname'][1] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailFullname', _('The full name is invalid.')]; |
| 223 |
$this->messages['AstVoicemailEmail'][0] = ['ERROR', _('The email address is invalid.')]; |
| 224 |
$this->messages['AstVoicemailEmail'][1] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailEmail', _('The email address is invalid.')]; |
| 225 |
$this->messages['AstVoicemailPager'][0] = ['ERROR', _('The pager number has bad format.')]; |
| 226 |
$this->messages['AstVoicemailPager'][1] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailPager', _('The pager number has bad format.')]; |
| 227 |
$this->messages['AstVoicemailOptions'][0] = ['ERROR', _('The options have bad format.')]; |
| 228 |
$this->messages['AstVoicemailOptions'][1] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailOptions', _('The options have bad format.')]; |
| 229 |
$this->messages['AstVoicemailContext'][0] = ['ERROR', _('The voicemail context name is invalid.')]; |
| 230 |
$this->messages['AstVoicemailContext'][1] = ['ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailContext', _('The voicemail context name is invalid.')]; |
| 231 |
$this->messages['AstVoicemailPassword'][0] = ['INFO', _('Please set the voicemail password with "Set password" before saving.')]; |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* {@inheritDoc} |
| 236 |
*/ |
| 237 |
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void { |
| 238 |
parent::loadAttributesFromAccountCopy($ldapAttributes, array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY)); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* {@inheritDoc} |
| 243 |
*/ |
| 244 |
public function display_html_attributes(): htmlElement|array { |
| 245 |
$return = new htmlResponsiveRow(); |
| 246 |
if (in_array('AsteriskVoiceMail', $this->attributes['objectClass'])) { |
| 247 |
if (!isset($this->attributes['AstVoicemailPassword'])) { |
| 248 |
$message = new htmlStatusMessage($this->messages['AstVoicemailPassword'][0][0], $this->messages['AstVoicemailPassword'][0][1]); |
| 249 |
$return->add($message); |
| 250 |
} |
| 251 |
// mailbox |
| 252 |
$this->addSimpleInputTextField($return, 'AstVoicemailMailbox', _("Mailbox"), true); |
| 253 |
// account context |
| 254 |
$this->addSimpleInputTextField($return, 'AstContext', _("Account context"), true); |
| 255 |
|
| 256 |
$return->addVerticalSpacer('1rem'); |
| 257 |
|
| 258 |
// full name |
| 259 |
$this->addSimpleInputTextField($return, 'AstVoicemailFullname', _("Full name")); |
| 260 |
// email |
| 261 |
$this->addSimpleInputTextField($return, 'AstVoicemailEmail', _("Email address")); |
| 262 |
// pager |
| 263 |
$this->addSimpleInputTextField($return, 'AstVoicemailPager', _("Pager")); |
| 264 |
// options |
| 265 |
$this->addSimpleInputTextField($return, 'AstVoicemailOptions', _("Options")); |
| 266 |
// voicemail context |
| 267 |
$this->addSimpleInputTextField($return, 'AstVoicemailContext', _("Voicemail context")); |
| 268 |
// remove button |
| 269 |
$return->addVerticalSpacer('2rem'); |
| 270 |
$remButton = new htmlButton('remVoicemailObjectClass', _('Remove Asterisk voicemail extension')); |
| 271 |
$remButton->setCSSClasses(['lam-danger']); |
| 272 |
$return->add($remButton, 12, 12, 12, 'text-center'); |
| 273 |
} |
| 274 |
else { |
| 275 |
// add button |
| 276 |
$return->add(new htmlButton('addVoicemailObjectClass', _('Add Asterisk voicemail extension'))); |
| 277 |
} |
| 278 |
return $return; |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* {@inheritDoc} |
| 283 |
*/ |
| 284 |
public function process_attributes(): array { |
| 285 |
if (isset($_POST['addVoicemailObjectClass'])) { |
| 286 |
$this->attributes['objectClass'][] = 'AsteriskVoiceMail'; |
| 287 |
return []; |
| 288 |
} |
| 289 |
// remove extension |
| 290 |
elseif (isset($_POST['remVoicemailObjectClass'])) { |
| 291 |
$this->attributes['objectClass'] = array_delete(['AsteriskVoiceMail'], $this->attributes['objectClass']); |
| 292 |
$attrKeys = array_keys($this->attributes); |
| 293 |
for ($k = 0; $k < count($attrKeys); $k++) { |
| 294 |
if (strpos($attrKeys[$k], 'AstVoicemail') > -1) { |
| 295 |
unset($this->attributes[$attrKeys[$k]]); |
| 296 |
} |
| 297 |
} |
| 298 |
if (isset($this->attributes['AstContext'])) { |
| 299 |
unset($this->attributes['AstContext']); |
| 300 |
} |
| 301 |
return []; |
| 302 |
} |
| 303 |
$errors = []; |
| 304 |
if (!in_array('AsteriskVoiceMail', $this->attributes['objectClass'])) { |
| 305 |
return []; |
| 306 |
} |
| 307 |
$this->attributes['AstVoicemailMailbox'] = []; |
| 308 |
$this->attributes['AstVoicemailFullname'] = []; |
| 309 |
$this->attributes['AstVoicemailEmail'] = []; |
| 310 |
$this->attributes['AstVoicemailPager'] = []; |
| 311 |
$this->attributes['AstVoicemailOptions'] = []; |
| 312 |
$this->attributes['AstVoicemailContext'] = []; |
| 313 |
|
| 314 |
if (isset($_POST['AstContext'])) { |
| 315 |
$this->attributes['AstContext'][0] = $_POST['AstContext']; |
| 316 |
if ($this->attributes['AstContext'][0] == '') { |
| 317 |
$errors[] = $this->messages['AstContext'][0]; |
| 318 |
} |
| 319 |
elseif (!get_preg($this->attributes['AstContext'][0], 'realname')) { |
| 320 |
$errors[] = $this->messages['AstContext'][1]; |
| 321 |
} |
| 322 |
} |
| 323 |
if (isset($_POST['AstVoicemailMailbox'])) { |
| 324 |
$this->attributes['AstVoicemailMailbox'][0] = $_POST['AstVoicemailMailbox']; |
| 325 |
// check if caller ID is empty |
| 326 |
if ($this->attributes['AstVoicemailMailbox'][0] == '') { |
| 327 |
$errors[] = $this->messages['AstVoicemailMailbox'][0]; |
| 328 |
} |
| 329 |
// check format |
| 330 |
elseif (!get_preg($this->attributes['AstVoicemailMailbox'][0], 'username')) { |
| 331 |
$errors[] = $this->messages['AstVoicemailMailbox'][1]; |
| 332 |
} |
| 333 |
// check for duplicate Voicemail ID |
| 334 |
elseif (!isset($this->orig['AstVoicemailMailbox'][0]) || ($this->orig['AstVoicemailMailbox'][0] != $this->attributes['AstVoicemailMailbox'][0])) { |
| 335 |
$entries = searchLDAPByAttribute('AstVoicemailMailbox', $this->attributes['AstVoicemailMailbox'][0], 'AstVoicemailMailbox', ['dn'], ['user']); |
| 336 |
if (count($entries) > 0) { |
| 337 |
$errors[] = $this->messages['AstVoicemailMailbox'][2]; |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
if (isset($_POST['AstVoicemailFullname'])) { |
| 342 |
$this->attributes['AstVoicemailFullname'][0] = $_POST['AstVoicemailFullname']; |
| 343 |
if ($this->attributes['AstVoicemailFullname'][0] != '' && !get_preg($this->attributes['AstVoicemailFullname'][0], 'realname')) { |
| 344 |
$errors[] = $this->messages['AstVoicemailFullname'][0]; |
| 345 |
} |
| 346 |
} |
| 347 |
if (isset($_POST['AstVoicemailEmail'])) { |
| 348 |
$this->attributes['AstVoicemailEmail'][0] = $_POST['AstVoicemailEmail']; |
| 349 |
if ($this->attributes['AstVoicemailEmail'][0] != '' && !get_preg($this->attributes['AstVoicemailEmail'][0], 'email')) { |
| 350 |
$errors[] = $this->messages['AstVoicemailEmail'][0]; |
| 351 |
} |
| 352 |
} |
| 353 |
if (isset($_POST['AstVoicemailPager'])) { |
| 354 |
$this->attributes['AstVoicemailPager'][0] = $_POST['AstVoicemailPager']; |
| 355 |
if ($this->attributes['AstVoicemailPager'][0] != '' && !get_preg($this->attributes['AstVoicemailPager'][0], 'telephone')) { |
| 356 |
$errors[] = $this->messages['AstVoicemailPager'][0]; |
| 357 |
} |
| 358 |
} |
| 359 |
if (isset($_POST['AstVoicemailOptions'])) { |
| 360 |
$this->attributes['AstVoicemailOptions'][0] = $_POST['AstVoicemailOptions']; |
| 361 |
} |
| 362 |
if (isset($_POST['AstVoicemailContext'])) { |
| 363 |
$this->attributes['AstVoicemailContext'][0] = $_POST['AstVoicemailContext']; |
| 364 |
if ($this->attributes['AstVoicemailContext'][0] != '' && !get_preg($this->attributes['AstVoicemailContext'][0], 'realname')) { |
| 365 |
$errors[] = $this->messages['AstVoicemailContext'][0]; |
| 366 |
} |
| 367 |
} |
| 368 |
return $errors; |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* {@inheritDoc} |
| 373 |
*/ |
| 374 |
public function get_pdfEntries(array $pdfKeys, string $typeId): array { |
| 375 |
$return = []; |
| 376 |
$this->addSimplePDFField($return, 'AstVoicemailMailbox', _('Mailbox')); |
| 377 |
$this->addSimplePDFField($return, 'AstContext', _('Account context')); |
| 378 |
$this->addSimplePDFField($return, 'AstVoicemailFullname', _('Full name')); |
| 379 |
$this->addSimplePDFField($return, 'AstVoicemailContext', _('Voicemail context')); |
| 380 |
$this->addSimplePDFField($return, 'AstVoicemailPager', _('Pager')); |
| 381 |
$this->addSimplePDFField($return, 'AstVoicemailEmail', _('Email address')); |
| 382 |
$this->addSimplePDFField($return, 'AstVoicemailOptions', _('Options')); |
| 383 |
return $return; |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* {@inheritDoc} |
| 388 |
*/ |
| 389 |
public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array { |
| 390 |
$messages = []; |
| 391 |
for ($i = 0; $i < count($rawAccounts); $i++) { |
| 392 |
// add object class |
| 393 |
if (!in_array("AsteriskVoiceMail", $partialAccounts[$i]['objectClass'])) { |
| 394 |
$partialAccounts[$i]['objectClass'][] = "AsteriskVoiceMail"; |
| 395 |
} |
| 396 |
|
| 397 |
//add context |
| 398 |
if (empty($rawAccounts[$i][$ids['asteriskVoicemail_AstContext']])) { |
| 399 |
// default value |
| 400 |
$partialAccounts[$i]['AstContext'] = 'default'; |
| 401 |
} |
| 402 |
else { |
| 403 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstContext', 'AstContext', |
| 404 |
'realname', $this->messages['AstContext'][2], $messages); |
| 405 |
} |
| 406 |
|
| 407 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailMailbox', 'AstVoicemailMailbox', |
| 408 |
'realname', $this->messages['AstVoicemailMailbox'][3], $messages); |
| 409 |
|
| 410 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailEmail', 'AstVoicemailEmail', |
| 411 |
'email', $this->messages['AstVoicemailEmail'][1], $messages); |
| 412 |
|
| 413 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailPager', 'AstVoicemailPager', |
| 414 |
'telephone', $this->messages['AstVoicemailPager'][1], $messages); |
| 415 |
|
| 416 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailOptions', 'AstVoicemailOptions'); |
| 417 |
|
| 418 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailFullname', 'AstVoicemailFullname', |
| 419 |
'realname', $this->messages['AstVoicemailFullname'][1], $messages); |
| 420 |
|
| 421 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailContext', 'AstVoicemailContext', |
| 422 |
'realname', $this->messages['AstVoicemailContext'][1], $messages); |
| 423 |
|
| 424 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailPassword', 'AstVoicemailPassword'); |
| 425 |
} |
| 426 |
return $messages; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* {@inheritDoc} |
| 431 |
*/ |
| 432 |
public function module_complete(): bool { |
| 433 |
return (!in_array('AsteriskVoiceMail', $this->attributes['objectClass']) |
| 434 |
|| !empty($this->attributes['AstVoicemailPassword'][0])); |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* {@inheritDoc} |
| 439 |
*/ |
| 440 |
public function save_attributes(): array { |
| 441 |
if (!in_array('AsteriskVoiceMail', $this->attributes['objectClass']) && !in_array('AsteriskVoiceMail', $this->orig['objectClass'])) { |
| 442 |
// skip saving if the extension was not added/modified |
| 443 |
return []; |
| 444 |
} |
| 445 |
return $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig); |
| 446 |
} |
| 447 |
|
| 448 |
/** |
| 449 |
* {@inheritDoc} |
| 450 |
*/ |
| 451 |
public function managesPasswordAttributes(): bool { |
| 452 |
return in_array('AsteriskVoiceMail', $this->attributes['objectClass']); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* {@inheritDoc} |
| 457 |
*/ |
| 458 |
public function supportsForcePasswordChange(): bool { |
| 459 |
return false; |
| 460 |
} |
| 461 |
|
| 462 |
/** |
| 463 |
* {@inheritDoc} |
| 464 |
*/ |
| 465 |
public function passwordChangeRequested(string $password, array $modules, bool $forcePasswordChange): array { |
| 466 |
if (!in_array(static::class, $modules)) { |
| 467 |
return []; |
| 468 |
} |
| 469 |
$this->attributes['AstVoicemailPassword'][0] = $password; |
| 470 |
return []; |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* {@inheritDoc} |
| 475 |
*/ |
| 476 |
public function checkSelfServiceOptions(array $fields, array $attributes, bool $passwordChangeOnly, array $readOnlyFields): array { |
| 477 |
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []]; |
| 478 |
if (!isset($attributes['objectClass']) || !in_array_ignore_case('AsteriskVoiceMail', $attributes['objectClass'])) { |
| 479 |
return $return; |
| 480 |
} |
| 481 |
if (isset($_POST['posixAccount_password']) && ($_POST['posixAccount_password'] != '')) { |
| 482 |
if ($_POST['posixAccount_password'] != $_POST['posixAccount_password2']) { |
| 483 |
return $return; |
| 484 |
} |
| 485 |
elseif (!get_preg($_POST['posixAccount_password'], 'password')) { |
| 486 |
return $return; |
| 487 |
} |
| 488 |
elseif (in_array('syncAsteriskVoicemailPassword', $fields)) { |
| 489 |
// sync password |
| 490 |
$return['mod']['AstVoicemailPassword'][0] = $_POST['posixAccount_password']; |
| 491 |
} |
| 492 |
} |
| 493 |
return $return; |
| 494 |
} |
| 495 |
|
| 496 |
/** |
| 497 |
* @inheritDoc |
| 498 |
*/ |
| 499 |
public function supportsPasswordQuickChangePage(): bool { |
| 500 |
return true; |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* @inheritDoc |
| 505 |
*/ |
| 506 |
public function addPasswordQuickChangeAccountDetails(htmlResponsiveRow $row): void { |
| 507 |
// no details |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* @inheritDoc |
| 512 |
*/ |
| 513 |
public function getPasswordQuickChangeOptions(bool $forcePasswordChangeByDefault): array { |
| 514 |
$options = []; |
| 515 |
if (in_array_ignore_case('AsteriskVoiceMail', $this->attributes['objectClass'])) { |
| 516 |
$options[] = new PasswordQuickChangeOption('syncAsteriskVoiceMail', _('Change Asterisk voicemail password')); |
| 517 |
} |
| 518 |
return $options; |
| 519 |
} |
| 520 |
|
| 521 |
/** |
| 522 |
* @inheritDoc |
| 523 |
*/ |
| 524 |
public function getPasswordQuickChangeChanges(string $password): array { |
| 525 |
$attrs = []; |
| 526 |
if (isset($_POST['syncAsteriskVoiceMail'])) { |
| 527 |
$attrs['AstVoicemailPassword'][0] = $password; |
| 528 |
} |
| 529 |
return $attrs; |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* @inheritDoc |
| 534 |
*/ |
| 535 |
public function getPasswordQuickChangePasswordStrengthUserName(): ?string { |
| 536 |
return null; |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* @inheritDoc |
| 541 |
*/ |
| 542 |
public function getPasswordQuickChangePasswordStrengthAttributes(): array { |
| 543 |
return []; |
| 544 |
} |
| 545 |
|
| 546 |
/** |
| 547 |
* @inheritDoc |
| 548 |
*/ |
| 549 |
public function getPasswordQuickChangeIsPasswordInHistory(string $password): bool { |
| 550 |
return false; |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* @inheritDoc |
| 555 |
*/ |
| 556 |
public function getListAttributeDescriptions(ConfiguredType $type): array { |
| 557 |
return [ |
| 558 |
'astcontext' => _('Account context'), |
| 559 |
'astvoicemailmailbox' => _('Mailbox'), |
| 560 |
'astvoicemailfullname' => _('Full name'), |
| 561 |
'astvoicemailemail' => _('Email address'), |
| 562 |
'astvoicemailpager' => _('Pager'), |
| 563 |
'astvoicemailoptions' => _('Options'), |
| 564 |
'astvoicemailcontext' => _('Voicemail context') |
| 565 |
]; |
| 566 |
} |
| 567 |
|
| 568 |
} |