1 2 3 4 5 6 7 8 9 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
|
<?php
use LAM\PDF\PDFTable;
use LAM\PDF\PDFTableCell;
use LAM\PDF\PDFTableRow;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2024 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Manages Kolab user accounts.
*
* @package modules
* @author Roland Gruber
*/
/**
* Manages Kolab user accounts.
*
* @package modules
*/
class kolabUser extends baseModule {
/** list of invitation policies */
private $invitationPolicies;
/**
* Creates a new kolabUser object.
*
* @param string $scope account type (user, group, host)
*/
function __construct($scope) {
// call parent constructor
parent::__construct($scope);
// list of invitation policies
$this->invitationPolicies = [
'ACT_ALWAYS_ACCEPT' => _('Always accept'),
'ACT_ALWAYS_REJECT' => _('Always reject'),
'ACT_MANUAL' => _('Manual'),
'ACT_REJECT_IF_CONFLICTS' => _('Reject if conflicts'),
'ACT_MANUAL_IF_CONFLICTS' => _('Manual if conflicts')
];
$this->autoAddObjectClasses = false;
}
/**
* Returns true if this module can manage accounts of the current type, otherwise false.
*
* @return boolean true if module fits
*/
public function can_manage() {
return $this->get_scope() === 'user';
}
/**
* Returns meta data that is interpreted by parent class
*
* @return array array with meta data
*
* @see baseModule::get_metaData()
*/
function get_metaData() {
$return = [];
// icon
$return['icon'] = 'kolab.png';
// alias name
$return["alias"] = _("Kolab");
// module dependencies
$return['dependencies'] = ['depends' => ['inetOrgPerson'], 'conflicts' => []];
// LDAP filter
$return["ldap_filter"] = ['or' => "(objectClass=kolabInetOrgPerson)"];
// managed object classes
$return['objectClasses'] = ['kolabInetOrgPerson', 'mailrecipient'];
// managed attributes
$return['attributes'] = ['alias', 'kolabDelegate', 'kolabInvitationPolicy',
'kolabAllowSMTPRecipient', 'kolabAllowSMTPSender', 'mailQuota'];
// profile options
$profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputField(_('Mailbox quota'), 'kolab_mailQuota', null, 'mailQuota'));
$return['profile_options'] = $profileContainer;
// profile checks
$return['profile_checks']['kolab_mailQuota'] = [
'type' => 'ext_preg',
'regex' => 'digit',
'error_message' => $this->messages['mailQuota'][0]];
// self service field settings
$return['selfServiceFieldSettings'] = [
'kolabDelegate' => _('Delegates'),
'kolabInvitationPolicy' => _('Invitation policy')
];
// possible self service read-only fields
$return['selfServiceReadOnlyFields'] = ['kolabDelegate', 'kolabInvitationPolicy'];
// help Entries
$return['help'] = [
'invPol' => [
"Headline" => _("Invitation policy"), 'attr' => 'kolabInvitationPolicy',
"Text" => _("For automatic invitation handling.")
],
'invPolList' => [
"Headline" => _("Invitation policy list"), 'attr' => 'kolabInvitationPolicy',
"Text" => _("This is a comma separated list of invitation policies.")
],
'delegate' => [
"Headline" => _("Delegates"), 'attr' => 'kolabDelegate',
"Text" => _("A user may define who is allowed to act on behalf of herself. This property is checked when using the Kolab smtp daemon (Postfix) to send emails.")
],
'delegateList' => [
"Headline" => _("Delegates"), 'attr' => 'kolabDelegate',
"Text" => _("This is a semi-colon separated list of delegates.")
],
'alias' => [
"Headline" => _("Email alias"), 'attr' => 'alias',
"Text" => _("Email alias for this account.")
],
'aliasList' => [
"Headline" => _("Email alias list"), 'attr' => 'alias',
"Text" => _("This is a comma separated list of eMail aliases.")
],
'kolabAllowSMTPRecipient' => [
"Headline" => _('Allowed recipients'), 'attr' => 'kolabAllowSMTPRecipient',
"Text" => _('Describes the allowed or disallowed SMTP recipient addresses for mail sent by this account (e.g. "domain.tld" or "-user@domain.tld").')
],
'kolabAllowSMTPRecipientList' => [
"Headline" => _('Allowed recipients'), 'attr' => 'kolabAllowSMTPRecipient',
"Text" => _('Describes the allowed or disallowed SMTP recipient addresses for mail sent by this account (e.g. "domain.tld" or "-user@domain.tld").')
. ' ' . _("Multiple values are separated by semicolon.")
],
'kolabAllowSMTPSender' => [
"Headline" => _('Allowed senders'), 'attr' => 'kolabAllowSMTPSender',
"Text" => _('Describes the allowed or disallowed SMTP addresses sending mail to this account (e.g. "domain.tld" or "-user@domain.tld").')
],
'kolabAllowSMTPSenderList' => [
"Headline" => _('Allowed senders'), 'attr' => 'kolabAllowSMTPSender',
"Text" => _('Describes the allowed or disallowed SMTP addresses sending mail to this account (e.g. "domain.tld" or "-user@domain.tld").')
. ' ' . _("Multiple values are separated by semicolon.")
],
'mailQuota' => [
"Headline" => _('Mailbox quota'), 'attr' => 'mailQuota',
"Text" => _('The maximum mailbox size in MB.')
],
];
// upload fields
$return['upload_columns'] = [
[
'name' => 'kolabUser_invPol',
'description' => _('Invitation policy'),
'help' => 'invPolList',
'example' => 'user@domain:ACT_ALWAYS_ACCEPT,user2@domain:ACT_MANUAL'
],
[
'name' => 'kolabUser_mailQuota',
'description' => _('Mailbox quota'),
'help' => 'mailQuota',
'example' => '2000',
],
[
'name' => 'kolabUser_aliases',
'description' => _('Email aliases'),
'help' => 'aliasList',
'example' => 'user@domain,user2@domain'
],
[
'name' => 'kolabUser_delegates',
'description' => _('Delegates'),
'help' => 'delegateList',
'example' => 'uid=user,ou=People,dc=example,dc=com;uid=user2,ou=People,dc=example,dc=com'
],
[
'name' => 'kolabUser_kolabAllowSMTPRecipient',
'description' => _('Allowed recipients'),
'help' => 'kolabAllowSMTPRecipientList',
'example' => '.com; -.net',
],
[
'name' => 'kolabUser_kolabAllowSMTPSender',
'description' => _('Allowed senders'),
'help' => 'kolabAllowSMTPSenderList',
'example' => '.com; -.net',
],
];
// available PDF fields
$return['PDF_fields'] = [
'invPol' => _('Invitation policy'),
'mailQuota' => _('Mailbox quota'),
'aliases' => _('Email aliases'),
'delegate' => _('Delegates'),
'kolabAllowSMTPRecipient' => _('Allowed recipients'),
'kolabAllowSMTPSender' => _('Allowed senders'),
];
return $return;
}
/**
* This function fills the error message array with messages
*/
function load_Messages() {
$this->messages['invPol'][0] = ['ERROR', _('Target of invitation policy is invalid!')]; // third array value is set dynamically
$this->messages['invPol'][1] = ['ERROR', _('Account %s:') . ' kolabUser_invPol', _('Policy list has invalid format!')];
$this->messages['alias'][0] = ['ERROR', _('Email alias is invalid!')]; // third array value is set dynamically
$this->messages['alias'][1] = ['ERROR', _('Account %s:') . ' kolabUser_aliases', _('Email alias list has invalid format!')];
$this->messages['delegate'][0] = ['ERROR', _('Account %s:') . ' kolabUser_delegates', _('Unknown delegate address: %s')];
$this->messages['kolabAllowSMTPRecipient'][0] = ['ERROR', _('Allowed recipients'), _('Please enter a valid recipient expression.')];
$this->messages['kolabAllowSMTPRecipient'][1] = ['ERROR', _('Account %s:') . ' kolabUser_kolabAllowSMTPRecipient', _('Please enter a valid recipient expression.')];
$this->messages['kolabAllowSMTPSender'][0] = ['ERROR', _('Allowed senders'), _('Please enter a valid sender expression.')];
$this->messages['kolabAllowSMTPSender'][1] = ['ERROR', _('Account %s:') . ' kolabUser_kolabAllowSMTPSender', _('Please enter a valid sender expression.')];
$this->messages['mailQuota'][0] = ['ERROR', _('Mailbox quota'), _('Please enter a number.')];
$this->messages['mailQuota'][1] = ['ERROR', _('Account %s:') . ' kolabUser_mailQuota', _('Please enter a number.')];
}
/**
* Returns the HTML meta data for the main account page.
*
* @return htmlElement HTML meta data
*/
function display_html_attributes() {
$return = new htmlResponsiveRow();
if (isset($this->attributes['objectClass']) && in_array('kolabInetOrgPerson', $this->attributes['objectClass'])) {
$attrsI = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
if ($this->getAccountContainer()->isNewAccount) {
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
$attrsP = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
if (!isset($attrsP['userpassword'][0]) || ($attrsP['userpassword'][0] == '')) {
$message = new htmlStatusMessage('ERROR', _("Please enter a user password."));
$return->add($message);
}
}
elseif (!isset($attrsI['userpassword'][0]) || ($attrsI['userpassword'][0] == '')) {
$message = new htmlStatusMessage('ERROR', _("Please enter a user password."));
$return->add($message);
}
}
if (!isset($attrsI['mail'][0])) {
$message = new htmlStatusMessage('ERROR', _("Please enter an email address on this page: %s"), '', [$this->getAccountContainer()->getAccountModule('inetOrgPerson')->get_alias()]);
$return->add($message);
}
// mailbox quota
$mailQuota = '';
if (!empty($this->attributes['mailQuota'][0])) {
$mailQuota = $this->attributes['mailQuota'][0] / 1024;
}
$mailQuotaField = new htmlResponsiveInputField(_('Mailbox quota'), 'mailQuota', $mailQuota, 'mailQuota');
$mailQuotaField->setMinimumAndMaximumNumber();
$return->add($mailQuotaField);
// invitation policies
$return->add(new htmlSubTitle(_('Invitation policy')));
$invitationContainer = new htmlTable();
// default invitation policy
$defaultInvPol = $this->invitationPolicies['ACT_MANUAL'];
if (isset($this->attributes['kolabInvitationPolicy'])) {
for ($i = 0; $i < sizeof($this->attributes['kolabInvitationPolicy']); $i++) {
$parts = explode(":", $this->attributes['kolabInvitationPolicy'][$i]);
if (sizeof($parts) == 1) {
$defaultInvPol = $this->invitationPolicies[$this->attributes['kolabInvitationPolicy'][$i]];
unset($this->attributes['kolabInvitationPolicy'][$i]);
$this->attributes['kolabInvitationPolicy'] = array_values($this->attributes['kolabInvitationPolicy']);
break;
}
}
}
$invitationContainer->addElement(new htmlOutputText(_('Anyone')));
$invitationContainer->addElement(new htmlSelect('defaultInvPol', array_values($this->invitationPolicies), [$defaultInvPol]));
$invitationContainer->addElement(new htmlHelpLink('invPol'), true);
// other invitation policies
if (isset($this->attributes['kolabInvitationPolicy'])) {
for ($i = 0; $i < sizeof($this->attributes['kolabInvitationPolicy']); $i++) {
$parts = explode(":", $this->attributes['kolabInvitationPolicy'][$i]);
if (sizeof($parts) == 2) {
$invitationContainer->addElement(new htmlInputField('invPol1' . $i, $parts[0]));
$invitationContainer->addElement(new htmlSelect('invPol2' . $i, array_values($this->invitationPolicies), [$this->invitationPolicies[$parts[1]]]));
$invitationContainer->addElement(new htmlButton('delInvPol' . $i, 'del.svg', true));
$invitationContainer->addElement(new htmlHelpLink('invPol'), true);
}
}
}
// input box for new invitation policy
$invitationContainer->addElement(new htmlInputField('invPol1', ''));
$invitationContainer->addElement(new htmlSelect('invPol2', array_values($this->invitationPolicies)));
$invitationContainer->addElement(new htmlButton('addInvPol', 'add.svg', true));
$invitationContainer->addElement(new htmlHelpLink('invPol'), true);
$return->add($invitationContainer);
// mail aliases
$return->add(new htmlSubTitle(_('Email aliases')));
$this->addMultiValueInputTextField($return, 'alias', null);
// delegates
$delegatesData = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', ['dn'], ['user']);
$delegates = [];
for ($i = 0; $i < sizeof($delegatesData); $i++) {
$delegates[getAbstractDN($delegatesData[$i]['dn'])] = $delegatesData[$i]['dn'];
}
uksort($delegates, 'compareDN');
$return->add(new htmlSubTitle(_('Delegates')));
$delegatesContainer = new htmlTable();
if (isset($this->attributes['kolabDelegate'])) {
for ($i = 0; $i < sizeof($this->attributes['kolabDelegate']); $i++) {
$delegateSelect = new htmlSelect('delegate' . $i, $delegates, [$this->attributes['kolabDelegate'][$i]]);
$delegateSelect->setSortElements(false);
$delegateSelect->setHasDescriptiveElements(true);
$delegatesContainer->addElement($delegateSelect);
$delegatesContainer->addElement(new htmlButton('delDelegate' . $i, 'del.svg', true));
if ($i == 0) {
$delegatesContainer->addElement(new htmlHelpLink('delegate'));
}
$delegatesContainer->addNewLine();
}
}
// input box for new delegate
$delegatesSelectNew = new htmlSelect('delegate', $delegates);
$delegatesSelectNew->setHasDescriptiveElements(true);
$delegatesContainer->addElement($delegatesSelectNew);
$delegatesContainer->addElement(new htmlButton('addDelegate', 'add.svg', true));
if (empty($this->attributes['kolabDelegate'])) {
$delegatesContainer->addElement(new htmlHelpLink('delegate'));
}
$return->add($delegatesContainer);
$return->add(new htmlSubTitle(_('Options')));
// allowed recipients
$this->addMultiValueInputTextField($return, 'kolabAllowSMTPRecipient', _('Allowed recipients'));
// allowed senders
$this->addMultiValueInputTextField($return, 'kolabAllowSMTPSender', _('Allowed senders'));
}
else {
$return->add(new htmlButton('addObjectClass', _('Add Kolab extension')));
}
return $return;
}
/**
* Processes user input of the primary module page.
* It checks if all input values are correct and updates the associated LDAP attributes.
*
* @return array list of info/error messages
*/
function process_attributes() {
$errors = [];
if (isset($_POST['addObjectClass'])) {
$this->attributes['objectClass'][] = 'kolabInetOrgPerson';
$this->attributes['objectClass'][] = 'mailrecipient';
}
else {
if (isset($_POST['form_subpage_kolabUser_deleteUser_open'])) {
return [];
}
$this->attributes['kolabInvitationPolicy'] = [];
// check old invitation policies
$policies = array_flip($this->invitationPolicies);
$targets = [];
$i = 0;
while (isset($_POST['invPol1' . $i])) {
if (isset($_POST['delInvPol' . $i])) {
$i++;
continue;
}
if (isset($_POST['invPol2' . $i]) && ($_POST['invPol1' . $i] != "") && !in_array($_POST['invPol1' . $i], $targets)) {
$targets[] = $_POST['invPol1' . $i];
// check invitation policy
if (!get_preg($_POST['invPol1' . $i], 'email')) {
$message = $this->messages['invPol'][0];
$message[] = $_POST['invPol1' . $i];
$errors[] = $message;
}
else {
$this->attributes['kolabInvitationPolicy'][] = $_POST['invPol1' . $i] . ':' . $policies[$_POST['invPol2' . $i]];
}
}
$i++;
}
// check new invitation policy
if (isset($_POST['invPol1']) && ($_POST['invPol1'] != "") && !in_array($_POST['invPol1'], $targets)) {
// check new invitation policy
if (!get_preg($_POST['invPol1'], 'email')) {
$message = $this->messages['invPol'][0];
$message[] = $_POST['invPol1'];
$errors[] = $message;
}
else {
$this->attributes['kolabInvitationPolicy'][] = $_POST['invPol1'] . ':' . $policies[$_POST['invPol2']];
}
}
// default invitation policy
if (isset($_POST['defaultInvPol']) && ($_POST['defaultInvPol'] != "")) {
$this->attributes['kolabInvitationPolicy'][] = $policies[$_POST['defaultInvPol']];
}
// mail aliases
$this->processMultiValueInputTextField('alias', $errors, 'email');
// check old delegates
$this->attributes['kolabDelegate'] = [];
$i = 0;
while (isset($_POST['delegate' . $i])) {
if (isset($_POST['delDelegate' . $i])) {
$i++;
continue;
}
$this->attributes['kolabDelegate'][] = $_POST['delegate' . $i];
$i++;
}
// check new delegate
if (isset($_POST['addDelegate']) && ($_POST['delegate'] != "")) {
$this->attributes['kolabDelegate'][] = $_POST['delegate'];
}
$this->attributes['kolabDelegate'] = array_unique($this->attributes['kolabDelegate']);
// allowed recipients
$this->processMultiValueInputTextField('kolabAllowSMTPRecipient', $errors, 'kolabEmailPrefix');
// allowed senders
$this->processMultiValueInputTextField('kolabAllowSMTPSender', $errors, 'kolabEmailPrefix');
// mailbox quota
if (!empty($_POST['mailQuota']) && !get_preg($_POST['mailQuota'], 'digit')) {
$errors[] = $this->messages['mailQuota'][0];
}
else {
$mailQuota = [];
if (!empty($_POST['mailQuota'])) {
$mailQuota = [$_POST['mailQuota'] * 1024];
}
$this->attributes['mailQuota'] = $mailQuota;
}
}
return $errors;
}
/**
* @inheritDoc
*/
function module_complete() {
if (isset($this->attributes['objectClass']) && in_array('kolabInetOrgPerson', $this->attributes['objectClass'])) {
$attrsI = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
if (!$attrsI['mail'][0]) {
return false;
}
if ($this->getAccountContainer()->isNewAccount) {
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
$attrsP = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
if (!$attrsP['userpassword'][0]) {
return false;
}
}
elseif (!$attrsI['userpassword'][0]) {
return false;
}
}
}
return true;
}
/**
* Returns a list of modifications which have to be made to the LDAP account.
*
* @return array list of modifications
* <br>This function returns an array with 3 entries:
* <br>array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... )
* <br>DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid)
* <br>"add" are attributes which have to be added to LDAP entry
* <br>"remove" are attributes which have to be removed from LDAP entry
* <br>"modify" are attributes which have to been modified in LDAP entry
* <br>"info" are values with informational value (e.g. to be used later by pre/postModify actions)
*/
function save_attributes() {
if (!in_array('kolabInetOrgPerson', $this->attributes['objectClass']) && !in_array('kolabInetOrgPerson', $this->orig['objectClass'])) {
// skip saving if the extension was not added/modified
return [];
}
return $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig);
}
/**
* Loads the values of an account profile into internal variables.
*
* @param array $profile hash array with profile values (identifier => value)
*/
function load_profile($profile) {
// profile mappings in meta data
parent::load_profile($profile);
// mailbox quota
if (!empty($profile['kolab_mailQuota'][0])) {
$this->attributes['mailQuota'][0] = $profile['kolab_mailQuota'][0] * 1024;
}
}
/**
* {@inheritDoc}
* @see baseModule::build_uploadAccounts()
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) {
$messages = [];
$delegates = searchLDAPByAttribute(null, null, 'inetOrgPerson', ['mail'], ['user']);
for ($d = 0; $d < sizeof($delegates); $d++) {
if (isset($delegates[$d]['dn'])) {
$delegates[$d] = $delegates[$d]['dn'];
}
}
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class
if (!in_array("kolabInetOrgPerson", $partialAccounts[$i]['objectClass'])) {
$partialAccounts[$i]['objectClass'][] = "kolabInetOrgPerson";
}
if (!in_array("mailrecipient", $partialAccounts[$i]['objectClass'])) {
$partialAccounts[$i]['objectClass'][] = "mailrecipient";
}
// mailbox quota
if (!empty($rawAccounts[$i][$ids['kolabUser_mailQuota']])) {
if (get_preg($rawAccounts[$i][$ids['kolabUser_mailQuota']], 'digit')) {
$partialAccounts[$i]['mailQuota'] = $rawAccounts[$i][$ids['kolabUser_mailQuota']] * 1024;
}
else {
$errMsg = $this->messages['mailQuota'][1];
$errMsg[] = [$i];
$messages[] = $errMsg;
}
}
// add invitation policies
if ($rawAccounts[$i][$ids['kolabUser_invPol']] != "") {
$pols = explode(',', $rawAccounts[$i][$ids['kolabUser_invPol']]);
// check format
$policies = array_keys($this->invitationPolicies);
$defaultFound = false;
for ($p = 0; $p < sizeof($pols); $p++) {
$parts = explode(":", $pols[$p]);
// default policy
if (sizeof($parts) == 1) {
if (!$defaultFound && get_preg($parts[0], 'email')) {
$partialAccounts[$i]['kolabInvitationPolicy'][] = $parts[0];
}
else {
$errMsg = $this->messages['invPol'][1];
$errMsg[] = [$i];
$messages[] = $errMsg;
}
$defaultFound = true;
}
// additional policies
elseif (sizeof($parts) == 2) {
if (get_preg($parts[0], 'email') && in_array($parts[1], $policies)) {
$partialAccounts[$i]['kolabInvitationPolicy'][] = $pols[$p];
}
else {
$errMsg = $this->messages['invPol'][1];
$errMsg[] = [$i];
$messages[] = $errMsg;
}
}
// invalid format
else {
$errMsg = $this->messages['invPol'][1];
$errMsg[] = [$i];
$messages[] = $errMsg;
}
}
}
// add mail aliases
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabUser_aliases', 'alias', 'email', $this->messages['alias'][1], $messages, '/,[ ]*/');
// add delegates
if ($rawAccounts[$i][$ids['kolabUser_delegates']] != "") {
$newDelegates = explode(';', $rawAccounts[$i][$ids['kolabUser_delegates']]);
// check format
for ($d = 0; $d < sizeof($newDelegates); $d++) {
if (in_array($newDelegates[$d], $delegates)) {
$partialAccounts[$i]['kolabDelegate'][] = $newDelegates[$d];
}
// invalid format
else {
$errMsg = $this->messages['delegate'][0];
$errMsg[] = [$i, $newDelegates[$d]];
$messages[] = $errMsg;
}
}
}
// allowed recipients
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabUser_kolabAllowSMTPRecipient', 'kolabAllowSMTPRecipient', 'kolabEmailPrefix', $this->messages['kolabAllowSMTPRecipient'][1], $messages, '/;[ ]*/');
// allowed senders
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabUser_kolabAllowSMTPSender', 'kolabAllowSMTPSender', 'kolabEmailPrefix', $this->messages['kolabAllowSMTPSender'][1], $messages, '/;[ ]*/');
}
return $messages;
}
/**
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys, $typeId) {
$return = [];
// invitation policies
if (isset($this->attributes['kolabInvitationPolicy'][0])) {
// find default policy
$default = "";
for ($i = 0; $i < sizeof($this->attributes['kolabInvitationPolicy']); $i++) {
if (!strpos($this->attributes['kolabInvitationPolicy'][$i], ":")) {
$default = $this->attributes['kolabInvitationPolicy'][$i];
break;
}
}
$pdfTable = new PDFTable(_('Invitation policy'));
$pdfRow = new PDFTableRow();
$pdfRow->cells[] = new PDFTableCell(_('Anyone') . ": " . $this->invitationPolicies[$default]);
$pdfTable->rows[] = $pdfRow;
for ($i = 0; $i < sizeof($this->attributes['kolabInvitationPolicy']); $i++) {
$parts = explode(':', $this->attributes['kolabInvitationPolicy'][$i]);
if (sizeof($parts) == 2) {
$pdfRow = new PDFTableRow();
$pdfRow->cells[] = new PDFTableCell($parts[0] . ": " . $this->invitationPolicies[$parts[1]]);
$pdfTable->rows[] = $pdfRow;
}
}
$this->addPDFTable($return, 'invPol', $pdfTable);
}
$this->addSimplePDFField($return, 'aliases', _('Email aliases'), 'alias');
$this->addSimplePDFField($return, 'delegate', _('Delegates'), 'kolabDelegate', '; ');
$this->addSimplePDFField($return, 'kolabAllowSMTPRecipient', _('Allowed recipients'));
$this->addSimplePDFField($return, 'kolabAllowSMTPSender', _('Allowed senders'));
$mailQuota = '';
if (!empty($this->attributes['mailQuota'][0])) {
$mailQuota = ($this->attributes['mailQuota'][0] / 1024) . 'MB';
}
$this->addPDFKeyValue($return, 'mailQuota', _('Mailbox quota'), $mailQuota);
return $return;
}
/**
* Returns the meta HTML code for each input field.
* format: array(<field1> => array(<META HTML>), ...)
* It is not possible to display help links.
*
* @param array $fields list of active fields
* @param array $attributes attributes of LDAP account
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array list of meta HTML elements (field name => htmlResponsiveRow)
*/
function getSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
if ($passwordChangeOnly) {
return []; // no Kolab fields as long no LDAP content can be read
}
if (!in_array('kolabInetOrgPerson', $attributes['objectClass'])) {
return [];
}
$return = [];
// delegates
if (in_array('kolabDelegate', $fields)) {
$delegates = [];
$sr = @ldap_search($_SESSION['ldapHandle']->getServer(), $this->selfServiceSettings->LDAPSuffix, '(&(objectClass=inetOrgPerson)(mail=*))', ['dn'], 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$result = ldap_get_entries($_SESSION['ldapHandle']->getServer(), $sr);
cleanLDAPResult($result);
for ($i = 0; $i < sizeof($result); $i++) {
$delegates[getAbstractDN($result[$i]['dn'])] = $result[$i]['dn'];
}
}
$kolabDelegate = [];
if (isset($attributes['kolabDelegate'])) {
$kolabDelegate = $attributes['kolabDelegate'];
// do not show existing delegation candidates in selection list
for ($i = 0; $i < sizeof($kolabDelegate); $i++) {
$key = array_search($kolabDelegate[$i], $delegates);
if ($key !== false) {
unset($delegates[$key]);
}
}
}
uksort($delegates, 'compareDN');
$_SESSION['kolabUser_kolabDelegate'] = $kolabDelegate;
$delegateContainer = new htmlTable();
for ($i = 0; $i < sizeof($kolabDelegate); $i++) {
$delegateContainer->addElement(new htmlOutputText($kolabDelegate[$i]));
if (!in_array('kolabDelegate', $readOnlyFields)) {
$delegateGroup = new htmlGroup();
$delCheckbox = new htmlInputCheckbox('delDelegate_' . $i, false);
$delCheckbox->setAccessibilityLabel(_('Delete'));
$delegateGroup->addElement($delCheckbox);
$delegateGroup->addElement(new htmlOutputText(_('Delete')));
$delegateContainer->addElement(new htmlDiv(null, $delegateGroup, ['nowrap']));
}
$delegateContainer->addNewLine();
}
if (!in_array('kolabDelegate', $readOnlyFields)) {
$delegateSelect = new htmlSelect('new_delegate_value', $delegates);
$delegateSelect->setSortElements(false);
$delegateSelect->setHasDescriptiveElements(true);
$delegateContainer->addElement($delegateSelect);
$delegateAddGroup = new htmlGroup();
$addCheckbox = new htmlInputCheckbox('new_delegate', false);
$addCheckbox->setAccessibilityLabel(_("Add"));
$delegateAddGroup->addElement($addCheckbox);
$delegateAddGroup->addElement(new htmlOutputText(_("Add")));
$delegateContainer->addElement(new htmlDiv(null, $delegateAddGroup, ['nowrap']));
}
$delegateLabel = new htmlOutputText($this->getSelfServiceLabel('kolabDelegate', _('Delegates')));
$row = new htmlResponsiveRow();
$row->addLabel($delegateLabel);
$row->addField($delegateContainer);
$return['kolabDelegate'] = $row;
}
// invitation policies
if (in_array('kolabInvitationPolicy', $fields)) {
$invitationContainer = new htmlTable();
// default invitation policy
$defaultInvPol = $this->invitationPolicies['ACT_MANUAL'];
if (!empty($attributes['kolabInvitationPolicy'])) {
for ($i = 0; $i < sizeof($attributes['kolabInvitationPolicy']); $i++) {
$parts = explode(":", $attributes['kolabInvitationPolicy'][$i]);
if (sizeof($parts) == 1) {
$defaultInvPol = $this->invitationPolicies[$attributes['kolabInvitationPolicy'][$i]];
unset($attributes['kolabInvitationPolicy'][$i]);
$attributes['kolabInvitationPolicy'] = array_values($attributes['kolabInvitationPolicy']);
break;
}
}
}
$invitationContainer->addElement(new htmlOutputText(_('Anyone')));
if (!in_array('kolabInvitationPolicy', $readOnlyFields)) {
$invitationContainer->addElement(new htmlSelect('defaultInvPol', array_values($this->invitationPolicies), [$defaultInvPol]), true);
}
else {
$invitationContainer->addElement(new htmlOutputText($defaultInvPol), true);
}
// other invitation policies
if (!empty($attributes['kolabInvitationPolicy'])) {
for ($i = 0; $i < sizeof($attributes['kolabInvitationPolicy']); $i++) {
$parts = explode(":", $attributes['kolabInvitationPolicy'][$i]);
if (sizeof($parts) == 2) {
if (!in_array('kolabDelegate', $readOnlyFields)) {
$newPolicyInput = new htmlInputField('invPol1' . $i, $parts[0]);
$newPolicyInput->setAccessibilityLabel(_('Invitation policy'));
$invitationContainer->addElement($newPolicyInput);
$invitationContainer->addElement(new htmlSelect('invPol2' . $i, array_values($this->invitationPolicies), [$this->invitationPolicies[$parts[1]]]));
$invPolGroup = new htmlGroup();
$delCheckbox = new htmlInputCheckbox('delInvPol' . $i, false);
$delCheckbox->setAccessibilityLabel(_("Remove"));
$invPolGroup->addElement($delCheckbox);
$invPolGroup->addElement(new htmlOutputText(_("Remove")));
$invitationContainer->addElement(new htmlDiv(null, $invPolGroup, ['nowrap']), true);
}
else {
$invitationContainer->addElement(new htmlOutputText($parts[0]));
$invitationContainer->addElement(new htmlOutputText($this->invitationPolicies[$parts[1]]), true);
}
}
}
}
// input box for new invitation policy
if (!in_array('kolabDelegate', $readOnlyFields)) {
$policyInput = new htmlInputField('invPol1', '');
$policyInput->setAccessibilityLabel(_('Invitation policy'));
$invitationContainer->addElement($policyInput);
$invitationContainer->addElement(new htmlSelect('invPol2', array_values($this->invitationPolicies)));
$invPolAddGroup = new htmlGroup();
$addPolicyCheckbox = new htmlInputCheckbox('addInvPol', false);
$addPolicyCheckbox->setAccessibilityLabel(_("Add"));
$invPolAddGroup->addElement($addPolicyCheckbox);
$invPolAddGroup->addElement(new htmlOutputText(_("Add")));
$invitationContainer->addElement(new htmlDiv(null, $invPolAddGroup, ['nowrap']), true);
}
$invitationLabel = new htmlOutputText($this->getSelfServiceLabel('kolabInvitationPolicy', _('Invitation policy')));
$row = new htmlResponsiveRow();
$row->addLabel($invitationLabel);
$row->addField($invitationContainer);
$return['kolabInvitationPolicy'] = $row;
}
return $return;
}
/**
* Checks if all input values are correct and returns the LDAP attributes which should be changed.
* <br>Return values:
* <br>messages: array of parameters to create status messages
* <br>add: array of attributes to add
* <br>del: array of attributes to remove
* <br>mod: array of attributes to modify
* <br>info: array of values with informational value (e.g. to be used later by pre/postModify actions)
*
* Calling this method does not require the existence of an enclosing {@link accountContainer}.
*
* @param string $fields input fields
* @param array $attributes LDAP attributes
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array messages and attributes (array('messages' => [], 'add' => array('mail' => array('test@test.com')), 'del' => [], 'mod' => [], 'info' => []))
*/
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
if ($passwordChangeOnly) {
return $return; // skip processing if only a password change is done
}
if (!in_array_ignore_case('kolabInetOrgPerson', $attributes['objectClass'])) {
return $return;
}
$attributeNames = []; // list of attributes which should be checked for modification
$attributesNew = $attributes;
// delegates
if (in_array('kolabDelegate', $fields) && !in_array('kolabDelegate', $readOnlyFields)) {
$attributeNames[] = 'kolabDelegate';
// new delegation
if (isset($_POST['new_delegate']) && ($_POST['new_delegate'] == 'on')) {
$attributesNew['kolabDelegate'][] = $_POST['new_delegate_value'];
}
// check for deleted delegations
$postKeys = array_keys($_POST);
for ($i = 0; $i < sizeof($postKeys); $i++) {
if (str_contains($postKeys[$i], 'delDelegate_')) {
$sKey = substr($postKeys[$i], strlen('delDelegate_'));
$key = array_search($_SESSION['kolabUser_kolabDelegate'][$sKey], $attributesNew['kolabDelegate']);
if ($key !== false) {
unset($attributesNew['kolabDelegate'][$key]);
$attributesNew['kolabDelegate'] = array_values($attributesNew['kolabDelegate']);
}
}
}
}
// invitation policies
if (in_array('kolabInvitationPolicy', $fields) && !in_array('kolabInvitationPolicy', $readOnlyFields)) {
$attributeNames[] = 'kolabInvitationPolicy';
$policies = array_flip($this->invitationPolicies);
$attributesNew['kolabInvitationPolicy'] = [];
// check old invitation policies
$targets = [];
$i = 0;
while (isset($_POST['invPol1' . $i])) {
if (isset($_POST['delInvPol' . $i])) {
$i++;
continue;
}
if (isset($_POST['invPol2' . $i]) && ($_POST['invPol1' . $i] != "") && !in_array($_POST['invPol1' . $i], $targets)) {
$targets[] = $_POST['invPol1' . $i];
// check invitation policy
if (!get_preg($_POST['invPol1' . $i], 'email')) {
$message = $this->messages['invPol'][0];
$message[] = $_POST['invPol1' . $i];
$return['messages'][] = $message;
}
else {
$attributesNew['kolabInvitationPolicy'][] = $_POST['invPol1' . $i] . ':' . $policies[$_POST['invPol2' . $i]];
}
}
$i++;
}
// check new invitation policy
if (isset($_POST['invPol1']) && ($_POST['invPol1'] != "") && !in_array($_POST['invPol1'], $targets)) {
// check new invitation policy
if (!get_preg($_POST['invPol1'], 'email')) {
$message = $this->messages['invPol'][0];
$message[] = $_POST['invPol1'];
$return['messages'][] = $message;
}
else {
$attributesNew['kolabInvitationPolicy'][] = $_POST['invPol1'] . ':' . $policies[$_POST['invPol2']];
}
}
// default invitation policy
if (isset($_POST['defaultInvPol']) && ($_POST['defaultInvPol'] != "")) {
$attributesNew['kolabInvitationPolicy'][] = $policies[$_POST['defaultInvPol']];
}
}
// find differences
for ($i = 0; $i < sizeof($attributeNames); $i++) {
$attrName = $attributeNames[$i];
if (isset($attributes[$attrName]) && !isset($attributesNew[$attrName])) {
$return['del'][$attrName] = $attributes[$attrName];
}
elseif (!isset($attributes[$attrName]) && isset($attributesNew[$attrName])) {
$return['add'][$attrName] = $attributesNew[$attrName];
}
else {
if (isset($attributes[$attrName])) {
for ($a = 0; $a < sizeof($attributes[$attrName]); $a++) {
if (!in_array($attributes[$attrName][$a], $attributesNew[$attrName])) {
$return['mod'][$attrName] = $attributesNew[$attrName];
break;
}
}
}
if (isset($attributesNew[$attrName])) {
for ($a = 0; $a < sizeof($attributesNew[$attrName]); $a++) {
if (!in_array($attributesNew[$attrName][$a], $attributes[$attrName])) {
$return['mod'][$attrName] = $attributesNew[$attrName];
break;
}
}
}
}
}
return $return;
}
}
|