2017-05-30 18:31:05 +00:00
|
|
|
<?php
|
|
|
|
use \LAM\TYPES\TypeManager;
|
|
|
|
/*
|
|
|
|
* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
|
|
|
* Copyright (C) 2017 Lars Althof
|
2019-01-02 20:10:32 +00:00
|
|
|
* 2017 - 2019 Roland Gruber
|
2017-05-30 18:31:05 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Courier mail extension for users.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*
|
|
|
|
* @author Lars Althof
|
|
|
|
* @author Roland Gruber
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Courier mail extension for users.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*
|
|
|
|
* @author Lars Althof
|
|
|
|
* @author Roland Gruber
|
|
|
|
*/
|
|
|
|
class courierMailAccount extends baseModule {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new courierMailAccount 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.
|
|
|
|
*
|
|
|
|
* @return boolean true if module fits
|
|
|
|
*/
|
|
|
|
public function can_manage() {
|
|
|
|
return in_array($this->get_scope(), array(
|
|
|
|
'user'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function get_metaData() {
|
|
|
|
$return = array();
|
|
|
|
// icon
|
|
|
|
$return['icon'] = 'courierMail.png';
|
|
|
|
// alias name
|
|
|
|
$return["alias"] = _("Courier");
|
|
|
|
// module dependencies
|
|
|
|
$return['dependencies'] = array(
|
|
|
|
'depends' => array(
|
|
|
|
'inetOrgPerson'
|
|
|
|
),
|
|
|
|
'conflicts' => array()
|
|
|
|
);
|
|
|
|
// managed object classes
|
|
|
|
$return['objectClasses'] = array(
|
|
|
|
'courierMailAccount'
|
|
|
|
);
|
|
|
|
// managed attributes
|
|
|
|
$return['attributes'] = array(
|
|
|
|
'mailbox', 'mailhost', 'sharedgroup', 'disableimap',
|
|
|
|
'disablepop3', 'disableshared', 'disablewebmail', 'quota'
|
|
|
|
);
|
|
|
|
// help entries
|
|
|
|
$return['help'] = array(
|
|
|
|
'disableimap' => array(
|
|
|
|
"Headline" => _("Disable IMAP access"),
|
|
|
|
"attr" => 'disableimap',
|
|
|
|
"Text" => _("Setting this will disallow the user from logging in using IMAP.")
|
|
|
|
),
|
|
|
|
'disablepop3' => array(
|
|
|
|
"Headline" => _("Disable POP3 access"),
|
|
|
|
"attr" => 'disablepop3',
|
|
|
|
"Text" => _("Setting this will disallow the user from logging in using POP3.")
|
|
|
|
),
|
|
|
|
'disablewebmail' => array(
|
|
|
|
"Headline" => _("Disable webmail access"),
|
|
|
|
"attr" => 'disablewebmail',
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("Setting this will disallow the user from logging in using webmail.")
|
2017-05-30 18:31:05 +00:00
|
|
|
),
|
|
|
|
'disableshared' => array(
|
|
|
|
"Headline" => _("Disable shared folder access"),
|
|
|
|
"attr" => 'disableshared',
|
|
|
|
"Text" => _("Setting this will make shared folders invisible to this user.")
|
|
|
|
),
|
|
|
|
'mailbox' => array(
|
2017-06-06 17:46:20 +00:00
|
|
|
"Headline" => _("Mailbox"),
|
2017-05-30 18:31:05 +00:00
|
|
|
"attr" => 'mailbox',
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("Path to the user's mailbox. Usually relative to the user's home folder.")
|
2017-05-30 18:31:05 +00:00
|
|
|
),
|
|
|
|
'mailhost' => array(
|
2017-06-06 17:46:20 +00:00
|
|
|
"Headline" => _("Mailbox home server"),
|
2017-05-30 18:31:05 +00:00
|
|
|
"attr" => 'mailhost',
|
|
|
|
"Text" => _("Name of the host that stores the user's email. Must be a FQDN.")
|
|
|
|
),
|
|
|
|
'quota' => array(
|
2017-06-06 17:46:20 +00:00
|
|
|
"Headline" => _("Mailbox quota"),
|
2017-05-30 18:31:05 +00:00
|
|
|
"attr" => 'quota',
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("The amount of storage available to the user.")
|
2017-05-30 18:31:05 +00:00
|
|
|
),
|
2017-06-05 09:03:31 +00:00
|
|
|
'quotaUpload' => array(
|
2017-06-06 17:46:20 +00:00
|
|
|
"Headline" => _("Mailbox quota"),
|
2017-06-05 09:03:31 +00:00
|
|
|
"attr" => 'quota',
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("The amount of storage available to the user.") . ' ' . _('Please enter the amount in MB, e.g. 1000 means 1000MB of quota.')
|
2017-06-05 09:03:31 +00:00
|
|
|
),
|
2017-05-30 18:31:05 +00:00
|
|
|
'autoAdd' => array(
|
|
|
|
"Headline" => _("Automatically add this extension"),
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("This will enable the extension automatically if this profile is loaded.")
|
2017-05-30 18:31:05 +00:00
|
|
|
),
|
|
|
|
'homeDirectory' => array(
|
2017-06-06 17:46:20 +00:00
|
|
|
"Headline" => _("Home directory"),
|
2017-05-30 18:31:05 +00:00
|
|
|
"attr" => 'homeDirectory',
|
2017-06-06 17:46:20 +00:00
|
|
|
"Text" => _("The system home directory of the user. In a virtual user setup this is typically '/' for all users.")
|
2017-05-30 18:31:05 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
// profile options
|
2018-05-19 06:15:34 +00:00
|
|
|
$profileContainer = new htmlResponsiveRow();
|
|
|
|
$profileContainer->add(new htmlResponsiveInputCheckbox('courierMailAccount_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12);
|
2017-05-30 18:31:05 +00:00
|
|
|
$return['profile_options'] = $profileContainer;
|
|
|
|
// PDF fields
|
|
|
|
$return['PDF_fields'] = array(
|
2017-06-06 17:46:20 +00:00
|
|
|
'mailbox' => _('Mailbox'),
|
|
|
|
'mailhost' => _('Mailbox home server'),
|
|
|
|
'quota' => _('Mailbox quota'),
|
2017-05-30 18:31:05 +00:00
|
|
|
'disableimap' => _('Disable IMAP access'),
|
|
|
|
'disablepop3' => _('Disable POP3 access'),
|
|
|
|
'disablewebmail' => _('Disable webmail access'),
|
|
|
|
'disableshared' => _('Disable shared folder access')
|
|
|
|
);
|
2017-06-05 09:03:31 +00:00
|
|
|
// upload fields
|
|
|
|
$return['upload_columns'] = array(
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_mailbox',
|
2017-06-06 17:46:20 +00:00
|
|
|
'description' => _('Mailbox'),
|
2017-06-05 09:03:31 +00:00
|
|
|
'help' => 'mailbox',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_mailhost',
|
2017-06-06 17:46:20 +00:00
|
|
|
'description' => _('Mailbox home server'),
|
2017-06-05 09:03:31 +00:00
|
|
|
'help' => 'mailhost',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_quota',
|
2017-06-06 17:46:20 +00:00
|
|
|
'description' => _('Mailbox quota'),
|
2017-06-05 09:03:31 +00:00
|
|
|
'help' => 'quotaUpload',
|
|
|
|
'example' => '1000'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_disableimap',
|
|
|
|
'description' => _('Disable IMAP access'),
|
|
|
|
'help' => 'disableimap',
|
|
|
|
'values' => 'true, false',
|
|
|
|
'default' => 'false',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_disablepop3',
|
|
|
|
'description' => _('Disable POP3 access'),
|
|
|
|
'help' => 'disablepop3',
|
|
|
|
'values' => 'true, false',
|
|
|
|
'default' => 'false',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_disablewebmail',
|
|
|
|
'description' => _('Disable webmail access'),
|
|
|
|
'help' => 'disablewebmail',
|
|
|
|
'values' => 'true, false',
|
|
|
|
'default' => 'false',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'courierMailAccount_disableshared',
|
|
|
|
'description' => _('Disable shared folder access'),
|
|
|
|
'help' => 'disableshared',
|
|
|
|
'values' => 'true, false',
|
|
|
|
'default' => 'false',
|
|
|
|
),
|
|
|
|
);
|
2017-05-30 18:31:05 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function fills the error message array with messages
|
|
|
|
*/
|
|
|
|
public function load_Messages() {
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->messages['mailhost'][0] = array('ERROR', _('The mail host is not valid.')); // third array value is set dynamically
|
2017-06-05 09:03:31 +00:00
|
|
|
$this->messages['mailhost'][1] = array('ERROR', _('Account %s:') . ' courierMailAccount_mailhost', _('The mail host is not valid.'));
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->messages['quota'][0] = array('ERROR', _('The quota must be entered as a floating point number.')); // third array value is set dynamically
|
2017-06-06 17:46:20 +00:00
|
|
|
$this->messages['quota'][1] = array('ERROR', _('Account %s:') . ' courierMailAccount_quota', _('Please enter a number.'));
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->messages['homeDirectory'][0] = array('ERROR', _('Homedirectory contains invalid characters.')); // third array value is set dynamically
|
|
|
|
$this->messages['homeDirectory'][1] = array('ERROR', _('Account %s:') . ' courierMailAccount_homeDirectory', _('Homedirectory contains invalid characters.'));
|
2017-06-05 09:03:31 +00:00
|
|
|
$this->messages['boolean'][0] = array('ERROR', _('Account %s:') . ' courierMailAccount_%s', _('This value can only be "true" or "false".'));
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* @see baseModule::getManagedAttributes()
|
|
|
|
*/
|
|
|
|
public function getManagedAttributes($typeId) {
|
|
|
|
$attrs = parent::getManagedAttributes($typeId);
|
|
|
|
$typeManager = new TypeManager();
|
2017-06-12 15:49:15 +00:00
|
|
|
$type = $typeManager->getConfiguredType($typeId);
|
|
|
|
if ($type == null) {
|
|
|
|
return $attrs;
|
|
|
|
}
|
|
|
|
$modules = $type->getModules();
|
2017-05-30 18:31:05 +00:00
|
|
|
if ($this->isUnixDisabled($modules)) {
|
|
|
|
$attrs[] = 'homeDirectory';
|
|
|
|
}
|
|
|
|
return $attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function display_html_attributes() {
|
|
|
|
$return = new htmlTable();
|
|
|
|
if ($this->isExtensionEnabled()) {
|
|
|
|
if ($this->isUnixDisabled($this->getAccountContainer()->get_type()->getModules())) {
|
|
|
|
// home directory
|
|
|
|
$this->addSimpleInputTextField($return, 'homeDirectory', _('Home directory'), true);
|
|
|
|
}
|
|
|
|
// show current mailBox
|
|
|
|
$this->addSimpleInputTextField($return, 'mailbox', _('Mailbox folder'));
|
|
|
|
// mail host input
|
|
|
|
$this->addSimpleInputTextField($return, 'mailhost', _('Mailbox host'));
|
|
|
|
// quota with selection for unit of measure
|
|
|
|
$unitIndex = 2;
|
|
|
|
$value = 0;
|
|
|
|
if (isset($this->attributes['quota'][0]) && (strlen($this->attributes['quota'][0]) > 0)) {
|
|
|
|
$unitIndex = floor(log(substr($this->attributes['quota'][0], 0, -1), 1000));
|
|
|
|
$value = round((float) (substr($this->attributes['quota'][0], 0, -1)) / pow(1000, $unitIndex), 2);
|
|
|
|
}
|
2017-06-06 17:46:20 +00:00
|
|
|
$return->addElement(new htmlOutputText(_('Mailbox quota')));
|
2017-05-30 18:31:05 +00:00
|
|
|
$tempTable = new htmlTable();
|
|
|
|
$boxInput = new htmlInputField('quotaValue', $value);
|
|
|
|
$boxInput->setFieldSize(5);
|
|
|
|
$boxInput->setFieldMaxLength(5);
|
|
|
|
$tempTable->addElement($boxInput);
|
|
|
|
$units = array(
|
|
|
|
'B', 'kB', 'MB', 'GB',
|
|
|
|
'TB', 'PB', 'EB'
|
|
|
|
);
|
|
|
|
$selected = array(
|
|
|
|
$units[$unitIndex]
|
|
|
|
);
|
2017-06-05 07:42:00 +00:00
|
|
|
$unitSelect = new htmlSelect('quotaUnit', $units, $selected);
|
|
|
|
$unitSelect->setSortElements(false);
|
|
|
|
$tempTable->addElement($unitSelect);
|
2017-05-30 18:31:05 +00:00
|
|
|
$return->addElement($tempTable);
|
|
|
|
$return->addElement(new htmlHelpLink('quota'), true);
|
2017-06-05 07:42:00 +00:00
|
|
|
// check boxes for account access control
|
|
|
|
$disableimap = isset($this->attributes['disableimap'][0]) && ($this->attributes['disableimap'][0] != 0);
|
2017-06-06 17:46:20 +00:00
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('disableimap', $disableimap, _('Disable IMAP access'), 'disableimap'), true);
|
2017-06-05 07:42:00 +00:00
|
|
|
$disablepop3 = isset($this->attributes['disablepop3'][0]) && ($this->attributes['disablepop3'][0] != 0);
|
2017-06-06 17:46:20 +00:00
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('disablepop3', $disablepop3, _('Disable POP3 access'), 'disablepop3'), true);
|
2017-06-05 07:42:00 +00:00
|
|
|
$disablewebmail = isset($this->attributes['disablewebmail'][0]) && ($this->attributes['disablewebmail'][0] != 0);
|
2017-06-06 17:46:20 +00:00
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('disablewebmail', $disablewebmail, _('Disable webmail access'), 'disablewebmail'), true);
|
2017-06-05 07:42:00 +00:00
|
|
|
$disableshared = isset($this->attributes['disableshared'][0]) && ($this->attributes['disableshared'][0] != 0);
|
2017-06-06 17:46:20 +00:00
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('disableshared', $disableshared, _('Disable shared folder access'), 'disableshared'), true);
|
2017-06-05 07:42:00 +00:00
|
|
|
// remove extension
|
2017-05-30 18:31:05 +00:00
|
|
|
$return->addElement(new htmlSpacer(null, '20px'), true);
|
|
|
|
$remButton = new htmlButton('remObjectClass', _('Remove Courier mail extension'));
|
|
|
|
$remButton->colspan = 3;
|
|
|
|
$return->addElement($remButton);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$return->addElement(new htmlButton('addObjectClass', _('Add Courier mail extension')));
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function process_attributes() {
|
|
|
|
// add extension
|
|
|
|
if (isset($_POST['addObjectClass'])) {
|
|
|
|
$this->attributes['objectClass'][] = 'courierMailAccount';
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
// remove extension
|
|
|
|
elseif (isset($_POST['remObjectClass'])) {
|
|
|
|
$this->attributes['objectClass'] = array_delete(array(
|
|
|
|
'courierMailAccount'
|
|
|
|
), $this->attributes['objectClass']);
|
|
|
|
$attrNames = $this->getManagedAttributes($this->getAccountContainer()->get_type()->getId());
|
|
|
|
foreach ($attrNames as $attrName) {
|
|
|
|
if (isset($this->attributes[$attrName])) {
|
|
|
|
unset($this->attributes[$attrName]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
// skip processing if extension is not active
|
|
|
|
if (!$this->isExtensionEnabled()) {
|
|
|
|
return array();
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->getAccountContainer()->replaceWildcardsInPOST(array('homeDirectory', 'mailbox'));
|
2017-05-30 18:31:05 +00:00
|
|
|
$errors = array();
|
|
|
|
// check new mailbox
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->attributes['mailbox'][0] = $_POST['mailbox'];
|
|
|
|
// quota
|
2017-05-30 18:31:05 +00:00
|
|
|
$units = array(
|
|
|
|
'B', 'kB', 'MB',
|
|
|
|
'GB', 'TB', 'PB', 'EB'
|
|
|
|
);
|
|
|
|
// check new quota
|
|
|
|
if (isset($_POST['quotaValue'])) {
|
|
|
|
if (is_numeric($_POST['quotaValue']) && in_array($_POST['quotaUnit'], $units)) {
|
|
|
|
if ($_POST['quotaValue'] > 0) {
|
|
|
|
$power = array_search($_POST['quotaUnit'], $units);
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->attributes['quota'][0] = $_POST['quotaValue'] * pow(1000, $power) . "S";
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
elseif (isset($this->attributes['quota'])) {
|
2017-05-30 18:31:05 +00:00
|
|
|
unset($this->attributes['quota']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-06-05 07:42:00 +00:00
|
|
|
$message = $this->messages['quota'][0];
|
2017-05-30 18:31:05 +00:00
|
|
|
$message[] = $_POST['quotaValue'];
|
|
|
|
$errors[] = $message;
|
|
|
|
}
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
elseif (isset($this->attributes['quota'])) {
|
2017-05-30 18:31:05 +00:00
|
|
|
unset($this->attributes['quota']);
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// mail host
|
|
|
|
if (!empty($_POST['mailhost'])) {
|
|
|
|
// must be a valid host name
|
|
|
|
$this->attributes['mailhost'][0] = $_POST['mailhost'];
|
|
|
|
if (!get_preg($this->attributes['mailhost'][0], 'hostname')) {
|
2017-05-30 18:31:05 +00:00
|
|
|
$message = $this->messages['mailhost'][0];
|
|
|
|
$message[] = $_POST['mailhost'];
|
|
|
|
$errors[] = $message;
|
|
|
|
}
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
elseif (isset($this->attributes['mailhost'])) {
|
2017-05-30 18:31:05 +00:00
|
|
|
unset($this->attributes['mailhost']);
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// disable IMAP
|
2017-05-30 18:31:05 +00:00
|
|
|
$this->attributes['disableimap'][0] = 0;
|
|
|
|
if (isset($_POST['disableimap'])) {
|
|
|
|
$this->attributes['disableimap'][0] = 1;
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// disable POP3
|
2017-05-30 18:31:05 +00:00
|
|
|
$this->attributes['disablepop3'][0] = 0;
|
|
|
|
if (isset($_POST['disablepop3'])) {
|
|
|
|
$this->attributes['disablepop3'][0] = 1;
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// disable Webmail
|
2017-05-30 18:31:05 +00:00
|
|
|
$this->attributes['disablewebmail'][0] = 0;
|
|
|
|
if (isset($_POST['disablewebmail'])) {
|
|
|
|
$this->attributes['disablewebmail'][0] = 1;
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// disable shared folder
|
2017-05-30 18:31:05 +00:00
|
|
|
$this->attributes['disableshared'][0] = 0;
|
|
|
|
if (isset($_POST['disableshared'])) {
|
|
|
|
$this->attributes['disableshared'][0] = 1;
|
|
|
|
}
|
2017-06-05 07:42:00 +00:00
|
|
|
// home directory
|
2017-05-30 18:31:05 +00:00
|
|
|
if ($this->isUnixDisabled($this->getAccountContainer()->get_type()->getModules())) {
|
|
|
|
// check new home directory
|
2017-06-05 07:42:00 +00:00
|
|
|
$this->attributes['homeDirectory'][0] = $_POST['homeDirectory'];
|
|
|
|
// check for valid path
|
|
|
|
if (!get_preg($this->attributes['homeDirectory'][0], 'filePath')) {
|
|
|
|
$message = $this->messages['homeDirectory'][0];
|
|
|
|
$message[] = $this->attributes['homeDirectory'][0];
|
|
|
|
$errors[] = $message;
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function module_ready() {
|
|
|
|
$attrs = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
|
|
|
return isset($attrs['mail'][0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the Courier extension is enabled.
|
|
|
|
*
|
|
|
|
* @return boolean Courier extension is active
|
|
|
|
*/
|
|
|
|
private function isExtensionEnabled() {
|
|
|
|
return in_array('courierMailAccount', $this->attributes['objectClass']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@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->isUnixDisabled($modules)) {
|
|
|
|
$fields['homeDirectory'] = _('Home directory');
|
|
|
|
}
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-06-11 19:04:16 +00:00
|
|
|
public function get_pdfEntries($pdfKeys, $typeId) {
|
2017-05-30 18:31:05 +00:00
|
|
|
$return = array();
|
2017-06-06 17:46:20 +00:00
|
|
|
$this->addSimplePDFField($return, 'mailbox', _('Mailbox'));
|
|
|
|
$this->addSimplePDFField($return, 'mailhost', _('Mailbox home server'));
|
2017-05-30 18:31:05 +00:00
|
|
|
$this->addSimplePDFField($return, 'homeDirectory', _('Home directory'));
|
2017-06-05 07:42:00 +00:00
|
|
|
$disableOptions = array(
|
2017-06-06 17:46:20 +00:00
|
|
|
'disableimap' => _('Disable IMAP access'),
|
|
|
|
'disablepop3' => _('Disable POP3 access'),
|
|
|
|
'disablewebmail' => _('Disable webmail access'),
|
|
|
|
'disableshared' => _('Disable shared folder access')
|
2017-06-05 07:42:00 +00:00
|
|
|
);
|
|
|
|
foreach ($disableOptions as $attrName => $label) {
|
|
|
|
$value = _('No');
|
|
|
|
if (isset($this->attributes[$attrName][0]) && ($this->attributes[$attrName][0] == '1')) {
|
|
|
|
$value = _('Yes');
|
|
|
|
}
|
|
|
|
$this->addPDFKeyValue($return, $attrName, $label, $value);
|
|
|
|
}
|
|
|
|
// quota
|
|
|
|
$unitIndex = 2;
|
|
|
|
$value = 0;
|
|
|
|
if (isset($this->attributes['quota'][0]) && (strlen($this->attributes['quota'][0]) > 0)) {
|
|
|
|
$unitIndex = floor(log(substr($this->attributes['quota'][0], 0, -1), 1000));
|
|
|
|
$value = round((float) (substr($this->attributes['quota'][0], 0, -1)) / pow(1000, $unitIndex), 2);
|
|
|
|
}
|
|
|
|
$units = array(
|
|
|
|
'B', 'kB', 'MB', 'GB',
|
|
|
|
'TB', 'PB', 'EB'
|
|
|
|
);
|
2017-06-06 17:46:20 +00:00
|
|
|
$this->addPDFKeyValue($return, 'quota', _('Mailbox quota'), $value . $units[$unitIndex]);
|
2017-05-30 18:31:05 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2017-06-05 09:03:31 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* @see baseModule::getManagedAttributes()
|
|
|
|
*/
|
|
|
|
function get_uploadColumns($selectedModules, &$type) {
|
|
|
|
$return = parent::get_uploadColumns($selectedModules, $type);
|
|
|
|
// home directory
|
|
|
|
if ($this->isUnixDisabled($selectedModules)) {
|
|
|
|
$return[] = array(
|
|
|
|
'name' => 'courierMailAccount_homeDirectory',
|
|
|
|
'description' => _('Home directory'),
|
|
|
|
'help' => 'homeDirectory',
|
|
|
|
'example' => _('/home/smiller'),
|
2017-09-18 17:47:27 +00:00
|
|
|
'required' => true
|
2017-06-05 09:03:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:31:05 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-06-11 19:04:16 +00:00
|
|
|
public function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) {
|
2017-05-30 18:31:05 +00:00
|
|
|
$messages = array();
|
|
|
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
|
|
|
// add object class
|
2017-06-05 09:03:31 +00:00
|
|
|
if (!in_array("courierMailAccount", $partialAccounts[$i]['objectClass'])) {
|
|
|
|
$partialAccounts[$i]['objectClass'][] = "courierMailAccount";
|
|
|
|
}
|
|
|
|
// home directory
|
|
|
|
if ($this->isUnixDisabled($selectedModules)) {
|
|
|
|
if (!get_preg($rawAccounts[$i][$ids['courierMailAccount_homeDirectory']], 'homeDirectory')) {
|
|
|
|
$message = $this->messages['homeDirectory'][1];
|
|
|
|
$message[] = array($i);
|
|
|
|
$messages[] = $message;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$partialAccounts[$i]['homeDirectory'] = $rawAccounts[$i][$ids['courierMailAccount_homeDirectory']];
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-05 09:03:31 +00:00
|
|
|
// mailbox
|
|
|
|
if (!empty($rawAccounts[$i][$ids['courierMailAccount_mailbox']])) {
|
|
|
|
$partialAccounts[$i]['mailbox'] = $rawAccounts[$i][$ids['courierMailAccount_mailbox']];
|
|
|
|
}
|
2017-05-30 18:31:05 +00:00
|
|
|
// add mailhost
|
2017-06-05 09:03:31 +00:00
|
|
|
if (!empty($rawAccounts[$i][$ids['courierMailAccount_mailhost']])) {
|
2017-05-30 18:31:05 +00:00
|
|
|
if (!get_preg($rawAccounts[$i][$ids['courierMailAccount_mailhost']], 'hostname')) {
|
2017-06-05 09:03:31 +00:00
|
|
|
$message = $this->messages['mailhost'][1];
|
|
|
|
$message[] = array($i);
|
|
|
|
$messages[] = $message;
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
2017-06-05 09:03:31 +00:00
|
|
|
else {
|
|
|
|
$partialAccounts[$i]['mailhost'] = $rawAccounts[$i][$ids['courierMailAccount_mailhost']];
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
2017-06-05 09:03:31 +00:00
|
|
|
}
|
|
|
|
// mail quota
|
|
|
|
if (!empty($rawAccounts[$i][$ids['courierMailAccount_quota']])) {
|
|
|
|
if (is_numeric($rawAccounts[$i][$ids['courierMailAccount_quota']])) {
|
|
|
|
$partialAccounts[$i]['quota'] = ($rawAccounts[$i][$ids['courierMailAccount_quota']] * 1000000) . "S";
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-06-05 09:03:31 +00:00
|
|
|
$message = $this->messages['quota'][1];
|
|
|
|
$message[] = array($i);
|
|
|
|
$messages[] = $message;
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-05 09:03:31 +00:00
|
|
|
// boolean flags
|
|
|
|
$flags = array(
|
|
|
|
'disableimap', 'disablepop3',
|
|
|
|
'disablewebmail', 'disableshared'
|
|
|
|
);
|
|
|
|
$flagValues = array('true', 'false');
|
|
|
|
foreach ($flags as $flag) {
|
|
|
|
$partialAccounts[$i][$flag] = 0;
|
|
|
|
if (!empty($rawAccounts[$i][$ids['courierMailAccount_' . $flag]])) {
|
|
|
|
$flagValue = $rawAccounts[$i][$ids['courierMailAccount_' . $flag]];
|
|
|
|
if (!in_array($flagValue, $flagValues)) {
|
|
|
|
$message = $this->messages['boolean'][0];
|
|
|
|
$message[] = array($i, $flag);
|
|
|
|
$messages[] = $message;
|
|
|
|
}
|
|
|
|
elseif ($flagValue == 'true') {
|
|
|
|
$partialAccounts[$i][$flag] = 1;
|
|
|
|
}
|
|
|
|
}
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public 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['courierMailAccount_addExt'][0])
|
|
|
|
&& ($profile['courierMailAccount_addExt'][0] == "true")
|
|
|
|
&& !in_array('courierMailAccount', $this->attributes['objectClass'])) {
|
|
|
|
$this->attributes['objectClass'][] = 'courierMailAccount';
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if this account is virtual only or also a unix account
|
|
|
|
*
|
|
|
|
* @param string[] modules
|
|
|
|
* @return boolean only virtual account
|
|
|
|
*/
|
|
|
|
private function isUnixDisabled($modules) {
|
2019-01-02 20:10:32 +00:00
|
|
|
return !in_array('posixAccount', $modules);
|
2017-05-30 18:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|