LDAPAccountManager/lam/lib/modules/inetLocalMailRecipient.inc

395 lines
15 KiB
PHP
Raw Normal View History

2004-12-29 08:50:04 +00:00
<?php
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2019 Roland Gruber
2004-12-29 08:50:04 +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
*/
/**
* Provides mail routing for user accounts.
*
* @package modules
* @author Roland Gruber
*/
/**
* Provides mail routing for users.
*
* @package modules
*/
class inetLocalMailRecipient extends baseModule {
2006-08-13 12:58:19 +00:00
2016-11-12 08:48:34 +00:00
/**
* Creates a new mitKerberos 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() {
2016-11-12 08:48:34 +00:00
return in_array($this->get_scope(), array('user', 'group'));
}
2004-12-29 08:50:04 +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
*
2008-02-03 14:28:28 +00:00
* @see baseModule::get_metaData()
2004-12-29 08:50:04 +00:00
*/
function get_metaData() {
$return = array();
2007-11-19 18:42:03 +00:00
// icon
2007-12-01 12:34:52 +00:00
$return['icon'] = 'mailBig.png';
2004-12-29 08:50:04 +00:00
// alias name
$return["alias"] = _("Mail routing");
// module dependencies
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
// managed object classes
$return['objectClasses'] = array('inetLocalMailRecipient');
2006-05-13 08:55:31 +00:00
// managed attributes
$return['attributes'] = array('mailLocalAddress', 'mailHost', 'mailRoutingAddress');
2004-12-29 08:50:04 +00:00
// help Entries
$return['help'] = array(
2013-10-22 17:41:24 +00:00
'mailRoutingAddress' => array(
2012-02-04 15:56:31 +00:00
"Headline" => _("Routing address"), 'attr' => 'mailRoutingAddress',
2004-12-29 08:50:04 +00:00
"Text" => _("This is the target email address for the user's mails.")
),
'localAdr' => array(
2012-02-04 15:56:31 +00:00
"Headline" => _("Local address"), 'attr' => 'mailLocalAddress',
2004-12-29 08:50:04 +00:00
"Text" => _("This is one of the users public email addresses.")
),
'localAdrList' => array(
2012-02-04 15:56:31 +00:00
"Headline" => _("Local address list"), 'attr' => 'mailLocalAddress',
2004-12-29 08:50:04 +00:00
"Text" => _("This is a comma separated list of the users public email addresses.")
),
2013-10-22 17:41:24 +00:00
'mailHost' => array(
2012-02-04 15:56:31 +00:00
"Headline" => _("Mail server"), 'attr' => 'mailHost',
2004-12-29 08:50:04 +00:00
"Text" => _("This is the mail server for the user.")
));
// profile options
2018-05-19 07:48:12 +00:00
$profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputCheckbox('inetLocalMailRecipient_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12);
$profileContainer->add(new htmlResponsiveInputField(_('Routing address'), 'inetLocalMailRecipient_mailRoutingAddress', null, 'mailRoutingAddress'), 12);
$profileContainer->add(new htmlResponsiveInputField(_('Local address'), 'inetLocalMailRecipient_mailLocalAddress', null, 'localAdr'), 12);
$profileContainer->add(new htmlResponsiveInputField(_('Mail server'), 'inetLocalMailRecipient_host', null, 'mailHost'), 12);
2010-09-18 16:11:43 +00:00
$return['profile_options'] = $profileContainer;
2004-12-29 08:50:04 +00:00
// profile checks
$return['profile_checks']['inetLocalMailRecipient_host'] = array(
'type' => 'ext_preg',
'regex' => 'DNSname',
2013-10-22 17:41:24 +00:00
'error_message' => $this->messages['mailHost'][0]);
2005-01-07 10:55:05 +00:00
// profile mappings
$return['profile_mappings'] = array(
'inetLocalMailRecipient_host' => 'mailHost',
'inetLocalMailRecipient_mailRoutingAddress' => 'mailRoutingAddress',
'inetLocalMailRecipient_mailLocalAddress' => 'mailLocalAddress',
2005-01-07 10:55:05 +00:00
);
2004-12-29 08:50:04 +00:00
// upload fields
$return['upload_columns'] = array(
array(
'name' => 'inetLocalMailRecipient_routingAdr',
'description' => _('Routing address'),
2013-10-22 17:41:24 +00:00
'help' => 'mailRoutingAddress',
2007-06-10 14:51:35 +00:00
'example' => _('smiller@otherdomain.org')
2004-12-29 08:50:04 +00:00
),
array(
'name' => 'inetLocalMailRecipient_localAdr',
'description' => _('Local address list'),
'help' => 'localAdrList',
2007-06-10 14:51:35 +00:00
'example' => _('smiller@yourdomain.org')
2004-12-29 08:50:04 +00:00
),
array(
'name' => 'inetLocalMailRecipient_server',
'description' => _('Mail server'),
2013-10-22 17:41:24 +00:00
'help' => 'mailHost',
2007-06-10 14:51:35 +00:00
'example' => _('mail.yourdomain.org')
2004-12-29 08:50:04 +00:00
)
);
// available PDF fields
$return['PDF_fields'] = array(
2010-04-05 12:38:23 +00:00
'routingAdr' => _('Routing address'),
'localAdr' => _('Local address list'),
'host' => _('Mail server')
2004-12-29 08:50:04 +00:00
);
// self service
$return['selfServiceFieldSettings'] = array(
'mailLocalAddress' => _('Local address (read-only)'),
'mailRoutingAddress' => _('Routing address (read-only)'),
);
2004-12-29 08:50:04 +00:00
return $return;
}
/**
* This function fills the error message array with messages
*/
function load_Messages() {
2013-10-22 17:41:24 +00:00
$this->messages['mailRoutingAddress'][0] = array('ERROR', 'Routing address is invalid!'); // third array value is set dynamically
$this->messages['mailRoutingAddress'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_routingAdr', 'Routing address is invalid!');
2004-12-29 08:50:04 +00:00
$this->messages['localAdr'][0] = array('ERROR', 'Local address is invalid!'); // third array value is set dynamically
$this->messages['localAdr'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_localAdr', 'Local address is invalid!');
2013-10-22 17:41:24 +00:00
$this->messages['mailHost'][0] = array('ERROR', 'Mail server is invalid!'); // third array value is set dynamically
$this->messages['mailHost'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_server', 'Mail server is invalid!');
2004-12-29 08:50:04 +00:00
}
2006-08-13 12:58:19 +00:00
2016-11-12 08:48:34 +00:00
/**
* 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
if (isset($profile['inetLocalMailRecipient_addExt'][0]) && ($profile['inetLocalMailRecipient_addExt'][0] == "true")) {
if (!in_array('inetLocalMailRecipient', $this->attributes['objectClass'])) {
$this->attributes['objectClass'][] = 'inetLocalMailRecipient';
}
}
}
2004-12-29 08:50:04 +00:00
/**
2007-11-03 14:17:19 +00:00
* Returns the HTML meta data for the main account page.
2015-08-15 18:11:54 +00:00
*
2010-09-18 16:11:43 +00:00
* @return htmlElement HTML meta data
2007-11-03 14:17:19 +00:00
*/
2006-08-13 12:58:19 +00:00
function display_html_attributes() {
2010-09-18 16:11:43 +00:00
$return = new htmlTable();
2016-11-12 08:48:34 +00:00
if (in_array('inetLocalMailRecipient', $this->attributes['objectClass'])) {
// mail routing address
$this->addSimpleInputTextField($return, 'mailRoutingAddress', _('Routing address'));
// mail server
$this->addSimpleInputTextField($return, 'mailHost', _('Mail server'));
// list current local addresses
$localAdresses = array();
if (isset($this->attributes['mailLocalAddress'])) $localAdresses = $this->attributes['mailLocalAddress'];
for ($i = 0; $i < sizeof($localAdresses); $i++) {
if ($i == 0) {
$return->addElement(new htmlOutputText(_('Local address')));
}
else {
$return->addElement(new htmlOutputText(''));
}
$return->addElement(new htmlInputField('localAdr' . $i, $localAdresses[$i]));
$return->addElement(new htmlButton('delAdr' . $i, 'del.png', true));
if ($i == 0) {
$return->addElement(new htmlHelpLink('localAdr'));
}
$return->addNewLine();
2013-10-22 17:41:24 +00:00
}
2016-11-12 08:48:34 +00:00
// input box for new local addresses
$return->addElement(new htmlOutputText(_('New local address')));
$return->addElement(new htmlInputField('localAdr', ''));
$return->addElement(new htmlButton('addAdr', 'add.png', true));
$return->addElement(new htmlHelpLink('localAdr'));
$return->addElement(new htmlHiddenInput('adr_number', sizeof($localAdresses)));
$return->addElement(new htmlSpacer(null, '10px'), true);
$deleteButton = new htmlButton('remObjectClass', _('Remove mail routing extension'));
$deleteButton->colspan = 3;
$return->addElement($deleteButton);
}
else {
$return->addElement(new htmlButton('addObjectClass', _('Add mail routing extension')));
2004-12-29 08:50:04 +00:00
}
return $return;
}
/**
* Processes user input of the primary module page.
* It checks if all input values are correct and updates the associated LDAP attributes.
2004-12-29 08:50:04 +00:00
*
* @return array list of info/error messages
2004-12-29 08:50:04 +00:00
*/
2006-08-13 12:58:19 +00:00
function process_attributes() {
2016-11-12 08:48:34 +00:00
if (isset($_POST['addObjectClass'])) {
$this->attributes['objectClass'][] = 'inetLocalMailRecipient';
return array();
}
elseif (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('inetLocalMailRecipient'), $this->attributes['objectClass']);
for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) {
if (isset($this->attributes[$this->meta['attributes'][$i]])) {
unset($this->attributes[$this->meta['attributes'][$i]]);
}
}
return array();
}
if (!in_array('inetLocalMailRecipient', $this->attributes['objectClass'])) {
return array();
}
2006-05-16 15:38:55 +00:00
$errors = array();
$this->getAccountContainer()->replaceWildcardsInPOST(array('localAdr', 'mailRoutingAddress'));
2004-12-29 08:50:04 +00:00
$this->attributes['mailRoutingAddress'] = array();
$this->attributes['mailLocalAddress'] = array();
$this->attributes['mailHost'] = array();
// check routing address
2013-10-22 17:41:24 +00:00
if (isset($_POST['mailRoutingAddress']) && ($_POST['mailRoutingAddress'] != "")) {
2004-12-29 08:50:04 +00:00
// check if address has correct format
2013-10-22 17:41:24 +00:00
if (get_preg($_POST['mailRoutingAddress'], 'email')) {
$this->attributes['mailRoutingAddress'][0] = $_POST['mailRoutingAddress'];
2004-12-29 08:50:04 +00:00
}
else {
2013-10-22 17:41:24 +00:00
$message = $this->messages['mailRoutingAddress'][0];
$message[] = $_POST['mailRoutingAddress'];
2006-08-16 17:42:35 +00:00
$errors[] = $message;
2004-12-29 08:50:04 +00:00
}
}
// check mail server
2013-10-22 17:41:24 +00:00
if (isset($_POST['mailHost']) && ($_POST['mailHost'] != "")) {
2004-12-29 08:50:04 +00:00
// check if address has correct format
2013-10-22 17:41:24 +00:00
if (get_preg($_POST['mailHost'], 'DNSname')) {
$this->attributes['mailHost'][0] = $_POST['mailHost'];
2004-12-29 08:50:04 +00:00
}
else {
2013-10-22 17:41:24 +00:00
$message = $this->messages['mailHost'][0];
$message[] = $_POST['mailHost'];
2006-08-16 17:42:35 +00:00
$errors[] = $message;
2004-12-29 08:50:04 +00:00
}
}
// check old local addresses
2006-08-13 12:58:19 +00:00
if (isset($_POST['adr_number'])) {
for ($i = 0; $i < $_POST['adr_number']; $i++) {
if (isset($_POST['delAdr' . $i])) continue;
if (isset($_POST['localAdr' . $i]) && ($_POST['localAdr' . $i] != "")) {
2004-12-29 08:50:04 +00:00
// check if address has correct format
2006-08-13 12:58:19 +00:00
if (!get_preg($_POST['localAdr' . $i], 'mailLocalAddress')) {
2004-12-29 08:50:04 +00:00
$message = $this->messages['localAdr'][0];
2006-08-13 12:58:19 +00:00
$message[] = $_POST['localAdr' . $i];
2006-08-16 17:42:35 +00:00
$errors[] = $message;
2004-12-29 08:50:04 +00:00
}
2006-08-13 12:58:19 +00:00
$this->attributes['mailLocalAddress'][] = $_POST['localAdr' . $i];
2004-12-29 08:50:04 +00:00
}
}
}
// check new local address
2006-08-13 12:58:19 +00:00
if (isset($_POST['localAdr']) && ($_POST['localAdr'] != "")) {
2004-12-29 08:50:04 +00:00
// check if address has correct format
2006-08-13 12:58:19 +00:00
if (get_preg($_POST['localAdr'], 'mailLocalAddress')) {
// check if new address is not already in database
2016-11-12 08:51:08 +00:00
$data = searchLDAPByAttribute('mailLocalAddress', $_POST['localAdr'], 'inetLocalMailRecipient', array('dn'), array($this->get_scope()));
2010-08-05 20:42:39 +00:00
if (sizeof($data) > 0) {
$errors[] = array('WARN', _('This mail address is already in use:') . " " . $_POST['localAdr'], $data[0]['dn']);
}
2006-08-13 12:58:19 +00:00
$this->attributes['mailLocalAddress'][] = $_POST['localAdr'];
2004-12-29 08:50:04 +00:00
}
else {
$message = $this->messages['localAdr'][0];
2006-08-13 12:58:19 +00:00
$message[] = $_POST['localAdr'];
2006-08-16 17:42:35 +00:00
$errors[] = $message;
2004-12-29 08:50:04 +00:00
}
}
$this->attributes['mailLocalAddress'] = array_unique($this->attributes['mailLocalAddress']);
2006-05-16 15:38:55 +00:00
return $errors;
2004-12-29 08:50:04 +00:00
}
2016-11-12 08:48:34 +00:00
/**
* 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('inetLocalMailRecipient', $this->attributes['objectClass']) && !in_array('inetLocalMailRecipient', $this->orig['objectClass'])) {
// skip saving if the extension was not added/modified
return array();
}
return parent::save_attributes();
}
2004-12-29 08:50:04 +00:00
/**
2017-05-20 09:46:49 +00:00
* {@inheritDoc}
* @see baseModule::build_uploadAccounts()
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) {
2004-12-29 08:50:04 +00:00
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class
if (!in_array("inetLocalMailRecipient", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "inetLocalMailRecipient";
// add local addresses
2015-08-15 18:11:54 +00:00
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetLocalMailRecipient_localAdr', 'mailLocalAddress', 'mailLocalAddress', $this->messages['localAdr'][1], $messages, '/,[ ]*/');
2004-12-29 08:50:04 +00:00
// add routing address
2014-04-13 11:37:32 +00:00
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetLocalMailRecipient_routingAdr', 'mailRoutingAddress',
'email', $this->messages['mailRoutingAddress'][1], $messages);
2004-12-29 08:50:04 +00:00
// add mail server
2014-04-13 11:37:32 +00:00
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetLocalMailRecipient_server', 'mailHost',
'DNSname', $this->messages['mailHost'][1], $messages);
2004-12-29 08:50:04 +00:00
}
return $messages;
}
/**
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) {
2004-12-29 08:50:04 +00:00
$return = array();
2013-05-05 18:37:04 +00:00
$this->addSimplePDFField($return, 'routingAdr', _('Routing address'), 'mailRoutingAddress');
$this->addSimplePDFField($return, 'localAdr', _('Local address list'), 'mailLocalAddress');
$this->addSimplePDFField($return, 'host', _('Mail server'), 'mailHost');
2004-12-29 08:50:04 +00:00
return $return;
}
function getSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
if ($passwordChangeOnly) {
return array(); // no processing as long no LDAP content can be read
}
$return = array();
if (in_array('mailLocalAddress', $fields)) {
$mailLocalAddress = array();
if (isset($attributes['mailLocalAddress'])) {
$mailLocalAddress = $attributes['mailLocalAddress'];
}
array_map('htmlspecialchars', $mailLocalAddress);
$row = new htmlResponsiveRow();
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('mailLocalAddress', _('Local address'))));
$row->addField(new htmlOutputText(implode('<br>', $mailLocalAddress), false));
$return['mailLocalAddress'] = $row;
}
if (in_array('mailRoutingAddress', $fields)) {
$mailRoutingAddress = null;
if (isset($attributes['mailRoutingAddress'][0])) {
$mailRoutingAddress = $attributes['mailRoutingAddress'][0];
}
$row = new htmlResponsiveRow();
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('mailRoutingAddress', _('Routing address'))));
$row->addField(new htmlOutputText($mailRoutingAddress));
$return['mailRoutingAddress'] = $row;
}
return $return;
}
2004-12-29 08:50:04 +00:00
}
?>