2005-01-04 20:18:02 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
2006-03-03 17:30:35 +00:00
|
|
|
Copyright (C) 2004 - 2006 Roland Gruber
|
2005-01-04 20:18:02 +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 NIS mail alias management.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
* @author Roland Gruber
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides NIS mail alias management.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*/
|
|
|
|
class nisMailAlias extends baseModule {
|
2006-08-13 12:58:19 +00:00
|
|
|
|
2005-01-04 20:18:02 +00:00
|
|
|
/**
|
|
|
|
* Returns meta data that is interpreted by parent class
|
|
|
|
*
|
|
|
|
* @return array array with meta data
|
|
|
|
*/
|
|
|
|
function get_metaData() {
|
|
|
|
$return = array();
|
2007-11-19 18:42:03 +00:00
|
|
|
// icon
|
|
|
|
$return['icon'] = 'mailAlias.png';
|
2005-01-04 20:18:02 +00:00
|
|
|
// manages host accounts
|
2006-01-01 16:30:05 +00:00
|
|
|
$return["account_types"] = array("mailAlias");
|
2005-01-04 20:18:02 +00:00
|
|
|
// base module
|
|
|
|
$return["is_base"] = true;
|
|
|
|
// LDAP filter
|
|
|
|
$return["ldap_filter"] = array('or' => "(objectClass=nisMailAlias)");
|
|
|
|
// alias name
|
|
|
|
$return["alias"] = _("Mail aliases");
|
2005-08-26 08:53:16 +00:00
|
|
|
// RDN attribute
|
|
|
|
$return["RDN"] = array("cn" => "normal");
|
2005-01-04 20:18:02 +00:00
|
|
|
// module dependencies
|
2005-01-10 10:41:38 +00:00
|
|
|
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
|
2006-04-05 15:48:27 +00:00
|
|
|
// managed object classes
|
|
|
|
$return['objectClasses'] = array('nisMailAlias');
|
2006-05-13 08:55:31 +00:00
|
|
|
// managed attributes
|
|
|
|
$return['attributes'] = array('cn', 'rfc822MailMember');
|
2005-01-04 20:18:02 +00:00
|
|
|
// help Entries
|
|
|
|
$return['help'] = array(
|
|
|
|
'alias' => array(
|
|
|
|
"Headline" => _("Alias name"),
|
|
|
|
"Text" => _("Mails to this name are forwarded to the recipients.")
|
|
|
|
),
|
|
|
|
'recipient' => array(
|
|
|
|
"Headline" => _("Recipient"),
|
|
|
|
"Text" => _("This is one recipient for this alias.")
|
|
|
|
),
|
|
|
|
'recipientList' => array(
|
|
|
|
"Headline" => _("Recipient list"),
|
|
|
|
"Text" => _("This is a comma separated list of recipients.")
|
|
|
|
));
|
|
|
|
// upload fields
|
|
|
|
$return['upload_columns'] = array(
|
|
|
|
array(
|
|
|
|
'name' => 'nisMailAlias_alias',
|
|
|
|
'description' => _('Alias name'),
|
|
|
|
'help' => 'alias',
|
|
|
|
'example' => 'root',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'nisMailAlias_recipients',
|
|
|
|
'description' => _('Recipient list'),
|
|
|
|
'help' => 'recipientList',
|
|
|
|
'example' => _('smiller')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
// available PDF fields
|
|
|
|
$return['PDF_fields'] = array(
|
|
|
|
'alias', 'recipients'
|
|
|
|
);
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function fills the error message array with messages
|
|
|
|
*/
|
|
|
|
function load_Messages() {
|
|
|
|
$this->messages['alias'][0] = array('ERROR', 'Alias is empty or invalid!'); // third array value is set dynamically
|
|
|
|
$this->messages['alias'][1] = array('ERROR', _('Account %s:') . ' nisMailAlias_alias', 'Alias is empty or invalid!');
|
|
|
|
$this->messages['recipient'][0] = array('ERROR', 'Recipient is invalid!'); // third array value is set dynamically
|
|
|
|
$this->messages['recipient'][1] = array('ERROR', _('Account %s:') . ' nisMailAlias_recipient', 'Recipient is invalid!');
|
|
|
|
}
|
2006-08-13 12:58:19 +00:00
|
|
|
|
2005-01-04 20:18:02 +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
|
|
|
|
*/
|
|
|
|
function save_attributes() {
|
2005-08-26 08:53:16 +00:00
|
|
|
// skip saving if account is based on another structural object class
|
2007-10-03 18:02:10 +00:00
|
|
|
if (!$this->getAccountContainer()->isNewAccount && !in_array('nisMailAlias', $this->getAccountContainer()->attributes_orig['objectClass'])) {
|
2005-08-26 08:53:16 +00:00
|
|
|
return array();
|
|
|
|
}
|
2006-02-01 19:10:51 +00:00
|
|
|
return parent::save_attributes();
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-03 14:17:19 +00:00
|
|
|
* Returns the HTML meta data for the main account page.
|
|
|
|
*
|
|
|
|
* @return array HTML meta data
|
|
|
|
*/
|
2006-08-13 12:58:19 +00:00
|
|
|
function display_html_attributes() {
|
2005-01-04 20:18:02 +00:00
|
|
|
$return = array();
|
|
|
|
// alias name
|
|
|
|
$return[] = array(
|
|
|
|
0 => array('kind' => 'text', 'text' => _('Alias name')),
|
|
|
|
1 => array('kind' => 'input', 'name' => 'cn', 'type' => 'text', 'size' => '20', 'value' => $this->attributes['cn'][0]),
|
|
|
|
2 => array('kind' => 'help', 'value' => 'alias'));
|
|
|
|
// list current recipients
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['rfc822MailMember']); $i++) {
|
|
|
|
$return[] = array(
|
|
|
|
0 => array('kind' => 'text', 'text' => _('Recipient')),
|
|
|
|
1 => array('kind' => 'input', 'name' => 'rfc822MailMember' . $i, 'type' => 'text', 'size' => '17', 'value' => $this->attributes['rfc822MailMember'][$i]),
|
|
|
|
2 => array('kind' => 'input', 'type' => 'submit', 'name' => 'delRec' . $i, 'value' => _("Remove")),
|
|
|
|
3 => array('kind' => 'help', 'value' => 'recipient'));
|
|
|
|
}
|
|
|
|
// input box for new recipient
|
|
|
|
$return[] = array(
|
|
|
|
0 => array('kind' => 'text', 'text' => _('New recipient')),
|
|
|
|
1 => array('kind' => 'input', 'name' => 'rfc822MailMember', 'type' => 'text', 'size' => '17', 'value' => ''),
|
|
|
|
2 => array('kind' => 'input', 'type' => 'submit', 'name' => 'addRec', 'value' => _("Add")),
|
|
|
|
3 => array('kind' => 'help', 'value' => 'recipient'),
|
|
|
|
4 => array('kind' => 'input', 'type' => 'hidden', 'value' => sizeof($this->attributes['rfc822MailMember']), 'name' => 'rec_number'));
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-09-07 12:58:34 +00:00
|
|
|
* Processes user input of the primary module page.
|
|
|
|
* It checks if all input values are correct and updates the associated LDAP attributes.
|
2005-01-04 20:18:02 +00:00
|
|
|
*
|
2005-09-07 12:58:34 +00:00
|
|
|
* @return array list of info/error messages
|
2005-01-04 20:18:02 +00:00
|
|
|
*/
|
2006-08-13 12:58:19 +00:00
|
|
|
function process_attributes() {
|
2006-05-16 15:38:55 +00:00
|
|
|
$errors = array();
|
2005-01-04 20:18:02 +00:00
|
|
|
$this->attributes['cn'] = array();
|
|
|
|
$this->attributes['rfc822MailMember'] = array();
|
|
|
|
// check alias name
|
2006-08-13 12:58:19 +00:00
|
|
|
if (isset($_POST['cn']) && ($_POST['cn'] != "") && get_preg($_POST['cn'], 'nis_alias')) {
|
|
|
|
$this->attributes['cn'][] = $_POST['cn'];
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = $this->messages['alias'][0];
|
2006-08-13 12:58:19 +00:00
|
|
|
$message[] = $_POST['cn'];
|
2006-08-16 17:42:35 +00:00
|
|
|
$errors[] = $message;
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
// check old recipients
|
2006-08-13 12:58:19 +00:00
|
|
|
if (isset($_POST['rec_number'])) {
|
|
|
|
for ($i = 0; $i < $_POST['rec_number']; $i++) {
|
|
|
|
if (isset($_POST['delRec' . $i])) continue;
|
|
|
|
if (isset($_POST['rfc822MailMember' . $i]) && ($_POST['rfc822MailMember' . $i] != "")) {
|
2005-01-04 20:18:02 +00:00
|
|
|
// check if address has correct format
|
2006-08-13 12:58:19 +00:00
|
|
|
if (!get_preg($_POST['rfc822MailMember' . $i], 'nis_recipient')) {
|
2005-01-04 20:18:02 +00:00
|
|
|
$message = $this->messages['recipient'][0];
|
2006-08-13 12:58:19 +00:00
|
|
|
$message[] = $_POST['rfc822MailMember' . $i];
|
2006-08-16 17:42:35 +00:00
|
|
|
$errors[] = $message;
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
2006-08-13 12:58:19 +00:00
|
|
|
$this->attributes['rfc822MailMember'][] = $_POST['rfc822MailMember' . $i];
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check new recipient
|
2006-08-13 12:58:19 +00:00
|
|
|
if (isset($_POST['rfc822MailMember']) && ($_POST['rfc822MailMember'] != "")) {
|
2005-01-04 20:18:02 +00:00
|
|
|
// check if address has correct format
|
2006-08-13 12:58:19 +00:00
|
|
|
if (get_preg($_POST['rfc822MailMember'], 'nis_recipient')) {
|
|
|
|
$this->attributes['rfc822MailMember'][] = $_POST['rfc822MailMember'];
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = $this->messages['recipient'][0];
|
2006-08-13 12:58:19 +00:00
|
|
|
$message[] = $_POST['rfc822MailMember'];
|
2006-08-16 17:42:35 +00:00
|
|
|
$errors[] = $message;
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->attributes['rfc822MailMember'] = array_unique($this->attributes['rfc822MailMember']);
|
2006-05-16 15:38:55 +00:00
|
|
|
return $errors;
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 08:53:16 +00:00
|
|
|
/**
|
|
|
|
* Controls if the module button the account page is visible and activated.
|
|
|
|
*
|
|
|
|
* @return string status ("enabled", "disabled", "hidden")
|
|
|
|
*/
|
|
|
|
function getButtonStatus() {
|
2007-10-03 18:02:10 +00:00
|
|
|
if (!$this->getAccountContainer()->isNewAccount) {
|
2005-08-26 08:53:16 +00:00
|
|
|
// check if account is based on our object class
|
2007-10-03 18:02:10 +00:00
|
|
|
$objectClasses = $this->getAccountContainer()->attributes_orig['objectClass'];
|
2005-08-26 08:53:16 +00:00
|
|
|
if (is_array($objectClasses) && !in_array('nisMailAlias', $objectClasses)) {
|
|
|
|
return "disabled";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "enabled";
|
|
|
|
}
|
|
|
|
|
2005-01-04 20:18:02 +00:00
|
|
|
/**
|
|
|
|
* In this function the LDAP account is built up.
|
|
|
|
*
|
|
|
|
* @param array $rawAccounts list of hash arrays (name => value) from user input
|
|
|
|
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
|
|
|
|
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
|
|
|
|
* @return array list of error messages if any
|
|
|
|
*/
|
|
|
|
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
|
|
|
|
$messages = array();
|
|
|
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
|
|
|
// add object class
|
|
|
|
if (!in_array("nisMailAlias", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "nisMailAlias";
|
|
|
|
// add alias name
|
|
|
|
// check format
|
|
|
|
if (get_preg($rawAccounts[$i][$ids['nisMailAlias_alias']], 'nis_alias')) {
|
2007-11-01 14:57:01 +00:00
|
|
|
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['nisMailAlias_alias']];
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$errMsg = $this->messages['alias'][1];
|
|
|
|
array_push($errMsg, array($i));
|
|
|
|
$messages[] = $errMsg;
|
|
|
|
}
|
|
|
|
// add recipients
|
|
|
|
if ($rawAccounts[$i][$ids['nisMailAlias_recipients']] != "") {
|
|
|
|
$aliases = explode(',', $rawAccounts[$i][$ids['nisMailAlias_recipients']]);
|
|
|
|
// check format
|
|
|
|
for ($a = 0; $a < sizeof($aliases); $a++) {
|
|
|
|
if (get_preg($aliases[$a], 'nis_recipient')) {
|
|
|
|
$partialAccounts[$i]['rfc822MailMember'][] = $aliases[$a];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$errMsg = $this->messages['recipient'][1];
|
|
|
|
array_push($errMsg, array($i));
|
|
|
|
$messages[] = $errMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-09 18:05:32 +00:00
|
|
|
* Returns the PDF entries for this module.
|
2006-08-13 12:58:19 +00:00
|
|
|
*
|
2005-10-09 18:05:32 +00:00
|
|
|
* @return array list of possible PDF entries
|
2005-01-04 20:18:02 +00:00
|
|
|
*/
|
|
|
|
function get_pdfEntries() {
|
|
|
|
$return = array();
|
|
|
|
if (isset($this->attributes['cn'][0])) {
|
2005-06-12 19:41:49 +00:00
|
|
|
$return['nisMailAlias_alias'][0] = '<block><key>' . _('Alias name') . '</key><value>' . $this->attributes['cn'][0] . '</value></block>';
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
if (sizeof($this->attributes['rfc822MailMember']) > 0) {
|
2005-06-12 19:41:49 +00:00
|
|
|
$return['nisMailAlias_recipients'][0] = '<block><key>' . _('Recipient list') . '</key><value>' . implode(', ', $this->attributes['rfc822MailMember']) . '</value></block>';
|
2005-01-04 20:18:02 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|