LDAPAccountManager/lam/lib/modules/kolabGroup.inc

408 lines
14 KiB
PHP
Raw Normal View History

2013-08-29 16:44:58 +00:00
<?php
2017-05-01 18:02:44 +00:00
use LAM\TYPES\TypeManager;
2013-08-29 16:44:58 +00:00
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2019-01-02 20:10:32 +00:00
Copyright (C) 2013 - 2019 Roland Gruber
2013-08-29 16:44:58 +00:00
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 group accounts.
*
* @package modules
* @author Roland Gruber
*/
/**
* Manages Kolab group accounts.
*
* @package modules
*/
class kolabGroup extends baseModule {
2015-08-15 18:11:54 +00:00
2013-08-29 16:44:58 +00:00
/** cache for mail attribute */
private $mailCache = null;
2015-08-15 18:11:54 +00:00
2013-08-29 16:44:58 +00:00
/**
* Creates a new kolabGroup object.
*
* @param string $scope account type (user, group, host)
*/
function __construct($scope) {
// call parent constructor
parent::__construct($scope);
$this->autoAddObjectClasses = false;
}
/**
* Returns true if this module can manage accounts of the current type, otherwise false.
2015-08-15 18:11:54 +00:00
*
* @return boolean true if module fits
*/
public function can_manage() {
return in_array($this->get_scope(), array('group'));
}
2013-08-29 16:44:58 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @return array array with meta data
2015-08-15 18:11:54 +00:00
*
2013-08-29 16:44:58 +00:00
* @see baseModule::get_metaData()
*/
function get_metaData() {
$return = array();
// icon
$return['icon'] = 'kolab.png';
// alias name
$return["alias"] = _("Kolab");
// module dependencies
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
// managed object classes
$return['objectClasses'] = array('kolabGroupOfUniqueNames');
// managed attributes
2018-07-14 14:59:35 +00:00
$return['attributes'] = array('kolabAllowSMTPRecipient', 'kolabAllowSMTPSender');
2013-08-29 16:44:58 +00:00
// help Entries
$return['help'] = array(
'mail' => array(
"Headline" => _("Email address"), 'attr' => 'mail',
"Text" => _("The list's email address.")
),
'mailList' => array(
"Headline" => _("Email address"), 'attr' => 'mail',
"Text" => _("The list's email address.") . ' ' . _("Multiple values are separated by semicolon.")
),
'kolabAllowSMTPRecipient' => array (
2013-12-01 10:02:20 +00:00
"Headline" => _('Allowed recipients'), 'attr' => 'kolabAllowSMTPRecipient',
2018-09-04 17:55:05 +00:00
"Text" => _('Describes the allowed or disallowed SMTP recipient addresses for mail sent by this account (e.g. "domain.tld" or "-user@domain.tld").')
2013-08-29 16:44:58 +00:00
),
'kolabAllowSMTPRecipientList' => array (
2013-12-01 10:02:20 +00:00
"Headline" => _('Allowed recipients'), 'attr' => 'kolabAllowSMTPRecipient',
2018-09-04 17:55:05 +00:00
"Text" => _('Describes the allowed or disallowed SMTP recipient addresses for mail sent by this account (e.g. "domain.tld" or "-user@domain.tld").')
2013-08-29 16:44:58 +00:00
. ' ' . _("Multiple values are separated by semicolon.")
),
'kolabAllowSMTPSender' => array (
"Headline" => _('Allowed senders'), 'attr' => 'kolabAllowSMTPSender',
2018-09-04 17:55:05 +00:00
"Text" => _('Describes the allowed or disallowed SMTP addresses sending mail to this account (e.g. "domain.tld" or "-user@domain.tld").')
2013-08-29 16:44:58 +00:00
),
'kolabAllowSMTPSenderList' => array (
"Headline" => _('Allowed senders'), 'attr' => 'kolabAllowSMTPSender',
2018-09-04 17:55:05 +00:00
"Text" => _('Describes the allowed or disallowed SMTP addresses sending mail to this account (e.g. "domain.tld" or "-user@domain.tld").')
2013-08-29 16:44:58 +00:00
. ' ' . _("Multiple values are separated by semicolon.")
),
'autoAdd' => array(
"Headline" => _("Automatically add this extension"),
"Text" => _("This will enable the extension automatically if this profile is loaded.")
),
2013-11-02 15:06:03 +00:00
'addExtension' => array(
"Headline" => _("Add Kolab extension"),
"Text" => _("Adds this Kolab extension.")
),
2013-08-29 16:44:58 +00:00
);
// profile options
2018-05-19 07:48:12 +00:00
$profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputCheckbox('kolabGroup_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12);
2013-08-29 16:44:58 +00:00
$return['profile_options'] = $profileContainer;
// upload fields
$return['upload_columns'] = array(
2013-11-02 15:06:03 +00:00
array(
'name' => 'kolabGroup_addExtension',
'description' => _('Add Kolab extension'),
'help' => 'addExtension',
'example' => 'false',
'default' => 'false',
'values' => 'true, false'
),
2013-08-29 16:44:58 +00:00
array(
'name' => 'kolabGroup_kolabAllowSMTPRecipient',
2013-12-01 10:02:20 +00:00
'description' => _('Allowed recipients'),
2013-08-29 16:44:58 +00:00
'help' => 'kolabAllowSMTPRecipientList',
'example' => '.com; -.net',
),
array(
'name' => 'kolabGroup_kolabAllowSMTPSender',
'description' => _('Allowed senders'),
'help' => 'kolabAllowSMTPSenderList',
'example' => '.com; -.net',
),
);
// available PDF fields
$return['PDF_fields'] = array(
2013-12-01 10:02:20 +00:00
'kolabAllowSMTPRecipient' => _('Allowed recipients'),
2013-08-29 16:44:58 +00:00
'kolabAllowSMTPSender' => _('Allowed senders'),
);
return $return;
}
/**
* This function fills the $messages variable with output messages from this module.
*/
function load_Messages() {
$this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!'));
$this->messages['mail'][1] = array('ERROR', _('Account %s:') . ' kolabGroup_mail', _('Please enter a valid email address!'));
$this->messages['mail'][2] = array('ERROR', _('Email address'), _('Email address already exists.'));
$this->messages['mail'][3] = array('ERROR', _('Account %s:') . ' kolabGroup_mail', _('Email address already exists.'));
2013-12-07 16:49:23 +00:00
$this->messages['kolabAllowSMTPRecipient'][0] = array('ERROR', _('Allowed recipients'), _('Please enter a valid recipient expression.'));
$this->messages['kolabAllowSMTPRecipient'][1] = array('ERROR', _('Account %s:') . ' kolabGroup_kolabAllowSMTPRecipient', _('Please enter a valid recipient expression.'));
2013-08-29 16:44:58 +00:00
$this->messages['kolabAllowSMTPSender'][0] = array('ERROR', _('Allowed senders'), _('Please enter a valid sender expression.'));
$this->messages['kolabAllowSMTPSender'][1] = array('ERROR', _('Account %s:') . ' kolabGroup_kolabAllowSMTPSender', _('Please enter a valid sender expression.'));
}
/**
* Returns the HTML meta data for the main account page.
2015-08-15 18:11:54 +00:00
*
2013-08-29 16:44:58 +00:00
* @return htmlElement HTML meta data
*/
function display_html_attributes() {
$container = new htmlTable();
if (isset($this->attributes['objectClass']) && in_array('kolabGroupOfUniqueNames', $this->attributes['objectClass'])) {
// mail
2017-05-01 18:02:44 +00:00
if ($this->manageMail($this->getAccountContainer()->get_type()->getModules())) {
2013-08-29 16:44:58 +00:00
$this->addSimpleInputTextField($container, 'mail', _('Email address'), true);
}
2013-12-01 10:02:20 +00:00
// allowed recipients
$this->addMultiValueInputTextField($container, 'kolabAllowSMTPRecipient', _('Allowed recipients'));
2013-08-29 16:44:58 +00:00
// allowed senders
$this->addMultiValueInputTextField($container, 'kolabAllowSMTPSender', _('Allowed senders'));
}
else {
// add button
$container->addElement(new htmlButton('addObjectClass', _('Add Kolab extension')));
}
return $container;
}
/**
* 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 = array();
if (isset($_POST['addObjectClass'])) {
$this->attributes['objectClass'][] = 'kolabGroupOfUniqueNames';
return $errors;
}
if (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('kolabGroupOfUniqueNames'), $this->attributes['objectClass']);
$attrs = $this->meta['attributes'];
foreach ($attrs as $name) {
if (isset($this->attributes[$name])) {
unset($this->attributes[$name]);
}
}
return $errors;
}
// skip processing if object class is not set
if (!isset($this->attributes['objectClass']) || !in_array('kolabGroupOfUniqueNames', $this->attributes['objectClass'])) {
return $errors;
}
// mail
2017-05-01 18:02:44 +00:00
if ($this->manageMail($this->getAccountContainer()->get_type()->getModules())) {
2013-08-29 16:44:58 +00:00
if (!empty($_POST['mail'])) {
$this->attributes['mail'][0] = $_POST['mail'];
// check format
if (!get_preg($_POST['mail'], 'email')) {
$errors[] = $this->messages['mail'][0];
}
// check if unique
if ($this->getAccountContainer()->isNewAccount || (!empty($this->orig['mail'][0]) && ($this->orig['mail'][0] != $this->attributes['mail'][0]))) {
$this->loadMailCache();
if (in_array_ignore_case($_POST['mail'], $this->mailCache)) {
$errors[] = $this->messages['mail'][2];
}
}
}
elseif (isset($this->attributes['mail'])) {
unset($this->attributes['mail']);
}
}
2013-12-01 10:02:20 +00:00
// allowed recipients
2013-08-29 16:44:58 +00:00
$this->processMultiValueInputTextField('kolabAllowSMTPRecipient', $errors, 'kolabEmailPrefix');
// allowed senders
$this->processMultiValueInputTextField('kolabAllowSMTPSender', $errors, 'kolabEmailPrefix');
return $errors;
}
/**
* 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('kolabGroupOfUniqueNames', $this->attributes['objectClass']) && !in_array('kolabGroupOfUniqueNames', $this->orig['objectClass'])) {
// skip saving if the extension was not added/modified
return array();
}
return parent::save_attributes();
}
/**
* 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);
// add extension
2019-01-02 20:10:32 +00:00
if (isset($profile['kolabGroup_addExt'][0])
&& ($profile['kolabGroup_addExt'][0] == "true")
&& !in_array('kolabGroupOfUniqueNames', $this->attributes['objectClass'])) {
$this->attributes['objectClass'][] = 'kolabGroupOfUniqueNames';
2013-08-29 16:44:58 +00:00
}
}
2015-08-15 18:11:54 +00:00
2017-05-01 18:02:44 +00:00
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
2017-05-20 08:55:26 +00:00
function get_uploadColumns($selectedModules, &$type) {
$return = parent::get_uploadColumns($selectedModules, $type);
2017-05-01 18:02:44 +00:00
if ($this->manageMail($selectedModules)) {
$return[] = array(
'name' => 'kolabGroup_mail',
'description' => _('Email address'),
'help' => 'mailList',
'example' => 'list@company.com',
'required' => true,
'unique' => true,
);
}
return $return;
}
2013-08-29 16:44:58 +00:00
/**
2017-05-20 09:46:49 +00:00
* {@inheritDoc}
* @see baseModule::build_uploadAccounts()
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) {
2013-08-29 16:44:58 +00:00
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
2013-11-02 15:06:03 +00:00
// check if extension should be added
if (isset($rawAccounts[$i][$ids['kolabGroup_addExtension']]) && ($rawAccounts[$i][$ids['kolabGroup_addExtension']] != 'true')) {
continue;
}
2013-08-29 16:44:58 +00:00
// add object classes
if (!in_array('kolabGroupOfUniqueNames', $partialAccounts[$i]['objectClass'])) {
$partialAccounts[$i]['objectClass'][] = 'kolabGroupOfUniqueNames';
}
// mail
2017-05-01 18:02:44 +00:00
if ($this->manageMail($selectedModules) && !empty($rawAccounts[$i][$ids['kolabGroup_mail']])) {
2013-08-29 16:44:58 +00:00
if (get_preg($rawAccounts[$i][$ids['kolabGroup_mail']], 'email')) {
$this->loadMailCache();
if (!in_array_ignore_case(trim($rawAccounts[$i][$ids['kolabGroup_mail']]), $this->mailCache)) {
$partialAccounts[$i]['mail'] = trim($rawAccounts[$i][$ids['kolabGroup_mail']]);
}
else {
$errMsg = $this->messages['mail'][3];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
}
else {
$errMsg = $this->messages['mail'][1];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
}
// allowed recipients
2015-08-15 18:11:54 +00:00
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabGroup_kolabAllowSMTPRecipient', 'kolabAllowSMTPRecipient', 'kolabEmailPrefix', $this->messages['kolabAllowSMTPRecipient'][1], $messages, '/;[ ]*/');
2013-08-29 16:44:58 +00:00
// allowed senders
2015-08-15 18:11:54 +00:00
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabGroup_kolabAllowSMTPSender', 'kolabAllowSMTPSender', 'kolabEmailPrefix', $this->messages['kolabAllowSMTPSender'][1], $messages, '/;[ ]*/');
2013-08-29 16:44:58 +00:00
}
return $messages;
}
2015-08-15 18:11:54 +00:00
2017-05-01 18:02:44 +00:00
/**
* {@inheritDoc}
* @see baseModule::get_pdfFields()
*/
public function get_pdfFields($typeId) {
$fields = parent::get_pdfFields($typeId);
$typeManager = new TypeManager();
$modules = $typeManager->getConfiguredType($typeId)->getModules();
if ($this->manageMail($modules)) {
$fields['mail'] = _('Email address');
}
return $fields;
}
2013-08-29 16:44:58 +00:00
/**
2017-02-19 08:14:11 +00:00
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
2015-01-07 17:16:35 +00:00
*/
2017-04-01 07:57:03 +00:00
function get_pdfEntries($pdfKeys, $typeId) {
2013-08-29 16:44:58 +00:00
$return = array();
$this->addSimplePDFField($return, 'mail', _('Email address'));
2013-12-01 10:02:20 +00:00
$this->addSimplePDFField($return, 'kolabAllowSMTPRecipient', _('Allowed recipients'));
2013-08-29 16:44:58 +00:00
$this->addSimplePDFField($return, 'kolabAllowSMTPSender', _('Allowed senders'));
return $return;
}
2015-08-15 18:11:54 +00:00
2013-08-29 16:44:58 +00:00
/**
* Returns if the mail attribute should be managed.
2015-08-15 18:11:54 +00:00
*
2017-05-01 18:02:44 +00:00
* @param string[] $modules account modules
2013-08-29 16:44:58 +00:00
* @return boolean manage mail attribute
*/
2017-05-01 18:02:44 +00:00
private function manageMail($modules) {
2019-01-02 20:10:32 +00:00
return !in_array('qmailGroup', $modules);
2013-08-29 16:44:58 +00:00
}
/**
* Loads the list of email addresses into the cache.
*/
private function loadMailCache() {
if ($this->mailCache != null) {
return;
}
$results = searchLDAPByFilter('(mail=*)', array('mail'), array($this->get_scope()));
$this->mailCache = array();
foreach ($results as $result) {
if (isset($result['mail'][0])) {
$this->mailCache[] = $result['mail'][0];
}
}
}
2015-08-15 18:11:54 +00:00
2017-05-01 18:02:44 +00:00
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
public function getManagedAttributes($typeId) {
$attrs = parent::getManagedAttributes($typeId);
$typeManager = new TypeManager();
if ($this->manageMail($typeManager->getConfiguredType($typeId)->getModules())) {
$attrs[] = 'mail';
}
return $attrs;
}
2013-08-29 16:44:58 +00:00
}
?>