Kolab update

This commit is contained in:
Roland Gruber 2018-07-14 16:23:35 +02:00
parent b58fb827fd
commit b06266c1e6
1 changed files with 25 additions and 148 deletions

View File

@ -33,9 +33,6 @@
*/ */
class kolabSharedFolder extends baseModule { class kolabSharedFolder extends baseModule {
/** cache for mailHost values */
private $mailHostCache = null;
/** list of folder types (label => id) */ /** list of folder types (label => id) */
private $folderTypes = array(); private $folderTypes = array();
@ -48,10 +45,6 @@ class kolabSharedFolder extends baseModule {
// call parent constructor // call parent constructor
parent::__construct($scope); parent::__construct($scope);
$this->folderTypes = array( $this->folderTypes = array(
/*_('Shared address book') => 'addressbook',
_('Shared calendar') => 'calendar',
_('Shared journal') => 'journal',
_('Shared tasks') => 'task',*/
_('Shared mail folder') => 'mail', _('Shared mail folder') => 'mail',
); );
} }
@ -89,21 +82,8 @@ class kolabSharedFolder extends baseModule {
// managed object classes // managed object classes
$return['objectClasses'] = array('kolabSharedFolder', 'mailrecipient'); $return['objectClasses'] = array('kolabSharedFolder', 'mailrecipient');
// managed attributes // managed attributes
$return['attributes'] = array('cn', 'kolabAllowSMTPRecipient', 'kolabAllowSMTPSender', 'kolabDeleteflag', 'acl', $return['attributes'] = array('cn', 'kolabAllowSMTPRecipient', 'kolabAllowSMTPSender', 'acl',
'alias', 'kolabDelegate', 'kolabFolderType', 'kolabTargetFolder', 'mailHost', 'mail'); 'alias', 'kolabDelegate', 'kolabFolderType', 'kolabTargetFolder', 'mail');
// profile options
$profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputField(_('Mail server'), 'kolab_mailHost', null, 'mailHost'), 12);
$return['profile_options'] = $profileContainer;
// profile checks
$return['profile_checks']['kolab_mailHost'] = array(
'type' => 'ext_preg',
'regex' => 'DNSname',
'error_message' => $this->messages['mailHost'][0]);
// profile mappings
$return['profile_mappings'] = array(
'kolab_mailHost' => 'mailHost',
);
// help Entries // help Entries
$return['help'] = array( $return['help'] = array(
'cn' => array( 'cn' => array(
@ -116,20 +96,20 @@ class kolabSharedFolder extends baseModule {
), ),
'kolabAllowSMTPRecipient' => array ( 'kolabAllowSMTPRecipient' => array (
"Headline" => _('Allowed recipients'), 'attr' => '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").') "Text" => _('Describes the allowed or disallowed SMTP recipient addresses for mail sent by this account (e.g. "domain.tld" or "user@domain.tld").')
), ),
'kolabAllowSMTPRecipientList' => array ( 'kolabAllowSMTPRecipientList' => array (
"Headline" => _('Allowed recipients'), 'attr' => '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").') "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.") . ' ' . _("Multiple values are separated by semicolon.")
), ),
'kolabAllowSMTPSender' => array ( 'kolabAllowSMTPSender' => array (
"Headline" => _('Allowed senders'), 'attr' => '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").') "Text" => _('Describes the allowed or disallowed SMTP addresses sending mail to this account (e.g. "domain.tld" or "user@domain.tld").')
), ),
'kolabAllowSMTPSenderList' => array ( 'kolabAllowSMTPSenderList' => array (
"Headline" => _('Allowed senders'), 'attr' => '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").') "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.") . ' ' . _("Multiple values are separated by semicolon.")
), ),
'delegate' => array( 'delegate' => array(
@ -138,7 +118,7 @@ class kolabSharedFolder extends baseModule {
), ),
'delegateList' => array( 'delegateList' => array(
"Headline" => _("Delegates"), 'attr' => 'kolabDelegate', "Headline" => _("Delegates"), 'attr' => 'kolabDelegate',
"Text" => _("This is a comma separated list of delegates.") "Text" => _("This is a semi-colon separated list of delegates.")
), ),
'alias' => array( 'alias' => array(
"Headline" => _("Email alias"), 'attr' => 'alias', "Headline" => _("Email alias"), 'attr' => 'alias',
@ -148,22 +128,14 @@ class kolabSharedFolder extends baseModule {
"Headline" => _("Email alias list"), 'attr' => 'alias', "Headline" => _("Email alias list"), 'attr' => 'alias',
"Text" => _("This is a comma separated list of eMail aliases.") "Text" => _("This is a comma separated list of eMail aliases.")
), ),
'mailHost' => array(
"Headline" => _("Mailbox home server"), 'attr' => 'mailHost',
"Text" => _("The name of the server where the mailbox is located.")
),
'kolabTargetFolder' => array( 'kolabTargetFolder' => array(
"Headline" => _("Target IMAP folder"), 'attr' => 'kolabTargetFolder', "Headline" => _("Target IMAP folder"), 'attr' => 'kolabTargetFolder',
"Text" => _("The folder on the server where the shared folder is located (e.g. user/myfolder@example.com).") "Text" => _("The folder on the server where the shared folder is located (e.g. shared/myfolder@example.com).")
), ),
'kolabFolderType' => array( 'kolabFolderType' => array(
"Headline" => _("Type"), 'attr' => 'kolabFolderType', "Headline" => _("Type"), 'attr' => 'kolabFolderType',
"Text" => _("Specifies the folder type (e.g. shared mail folder).") "Text" => _("Specifies the folder type (e.g. shared mail folder).")
), ),
'deleteFlag' => array(
"Headline" => _("Mark for deletion"), 'attr' => 'kolabDeleteflag',
"Text" => _("This will set a special flag on the account which tells Kolabd to remove it. Use this to cleanly delete Kolab accounts (e.g. this removes mail boxes).")
),
); );
// upload fields // upload fields
$return['upload_columns'] = array( $return['upload_columns'] = array(
@ -181,17 +153,11 @@ class kolabSharedFolder extends baseModule {
'example' => _('user@company.com'), 'example' => _('user@company.com'),
'required' => true 'required' => true
), ),
array(
'name' => 'kolabSharedFolder_mailHost',
'description' => _('Mailbox home server'),
'help' => 'mailHost',
'example' => 'localhost',
),
array( array(
'name' => 'kolabSharedFolder_kolabTargetFolder', 'name' => 'kolabSharedFolder_kolabTargetFolder',
'description' => _('Target IMAP folder'), 'description' => _('Target IMAP folder'),
'help' => 'kolabTargetFolder', 'help' => 'kolabTargetFolder',
'example' => 'user/myfolder@example.com', 'example' => 'shared/myfolder@example.com',
'required' => true 'required' => true
), ),
array( array(
@ -223,7 +189,7 @@ class kolabSharedFolder extends baseModule {
'name' => 'kolabSharedFolder_delegates', 'name' => 'kolabSharedFolder_delegates',
'description' => _('Delegates'), 'description' => _('Delegates'),
'help' => 'delegateList', 'help' => 'delegateList',
'example' => 'user@domain,user2@domain' 'example' => 'uid=user,ou=People,dc=example,dc=com;uid=user2,ou=People,dc=example,dc=com'
), ),
); );
// available PDF fields // available PDF fields
@ -233,7 +199,6 @@ class kolabSharedFolder extends baseModule {
'kolabAllowSMTPSender' => _('Allowed senders'), 'kolabAllowSMTPSender' => _('Allowed senders'),
'aliases' => _('Email aliases'), 'aliases' => _('Email aliases'),
'delegate' => _('Delegates'), 'delegate' => _('Delegates'),
'mailHost' => _('Mailbox home server'),
'mail' => _('Email address'), 'mail' => _('Email address'),
'kolabTargetFolder' => _('Target IMAP folder'), 'kolabTargetFolder' => _('Target IMAP folder'),
'kolabFolderType' => _('Type'), 'kolabFolderType' => _('Type'),
@ -251,9 +216,7 @@ class kolabSharedFolder extends baseModule {
$this->messages['kolabAllowSMTPSender'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_kolabAllowSMTPSender', _('Please enter a valid sender expression.')); $this->messages['kolabAllowSMTPSender'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_kolabAllowSMTPSender', _('Please enter a valid sender expression.'));
$this->messages['alias'][0] = array('ERROR', _('Email alias is invalid!')); // third array value is set dynamically $this->messages['alias'][0] = array('ERROR', _('Email alias is invalid!')); // third array value is set dynamically
$this->messages['alias'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_aliases', _('Email alias list has invalid format!')); $this->messages['alias'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_aliases', _('Email alias list has invalid format!'));
$this->messages['delegate'][0] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_delegates', _('Unknown delegate address: %s')); $this->messages['delegate'][0] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_delegates', _('Unknown delegate: %s'));
$this->messages['mailHost'][0] = array('ERROR', _('Mailbox home server name is invalid!')); // third array value is set dynamically
$this->messages['mailHost'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_mailHost', _('Mailbox home server name is invalid!'));
$this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!')); $this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!'));
$this->messages['mail'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_mail', _('Please enter a valid email address!')); $this->messages['mail'][1] = array('ERROR', _('Account %s:') . ' kolabSharedFolder_mail', _('Please enter a valid email address!'));
$this->messages['cn'][0] = array('ERROR', _('Name'), _('Please enter a name.')); $this->messages['cn'][0] = array('ERROR', _('Name'), _('Please enter a name.'));
@ -267,25 +230,11 @@ class kolabSharedFolder extends baseModule {
*/ */
function display_html_attributes() { function display_html_attributes() {
$container = new htmlTable(); $container = new htmlTable();
// check if account is marked for deletion
if (isset($this->attributes['kolabDeleteflag'])) {
$container->addElement(new htmlOutputText(_('This account is marked for deletion.')));
return $container;
}
$baseContainer = new htmlTable(); $baseContainer = new htmlTable();
// name // name
$this->addSimpleInputTextField($baseContainer, 'cn', _('Name'), true); $this->addSimpleInputTextField($baseContainer, 'cn', _('Name'), true);
// mail // mail
$this->addSimpleInputTextField($baseContainer, 'mail', _('Email address'), true); $this->addSimpleInputTextField($baseContainer, 'mail', _('Email address'), true);
// mailbox server
if (!isset($this->orig['mailHost'][0])) { // value currently not set
$this->addSimpleInputTextField($baseContainer, 'mailHost', _('Mailbox home server'));
}
else { // input is unchangable when set
$baseContainer->addElement(new htmlOutputText(_('Mailbox home server')));
$baseContainer->addElement(new htmlOutputText($this->attributes['mailHost'][0]));
$baseContainer->addElement(new htmlHelpLink('mailHost'), true);
}
// target folder // target folder
$this->addSimpleInputTextField($baseContainer, 'kolabTargetFolder', _('Target IMAP folder'), true); $this->addSimpleInputTextField($baseContainer, 'kolabTargetFolder', _('Target IMAP folder'), true);
// folder type // folder type
@ -310,17 +259,21 @@ class kolabSharedFolder extends baseModule {
$container->addElement(new htmlSubTitle(_('Email aliases')), true); $container->addElement(new htmlSubTitle(_('Email aliases')), true);
$this->addMultiValueInputTextField($container, 'alias', null); $this->addMultiValueInputTextField($container, 'alias', null);
// delegates // delegates
$delegates = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', array('mail'), array('user')); $delegatesData = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', array('dn'), array('user'));
for ($i = 0; $i < sizeof($delegates); $i++) { $delegates = array();
$delegates[$i] = $delegates[$i]['mail'][0]; for ($i = 0; $i < sizeof($delegatesData); $i++) {
$delegates[getAbstractDN($delegatesData[$i]['dn'])] = $delegatesData[$i]['dn'];
} }
sort($delegates); uksort($delegates, 'compareDN');
$container->addElement(new htmlSubTitle(_('Delegates')), true); $container->addElement(new htmlSubTitle(_('Delegates')), true);
$delegatesContainer = new htmlTable(); $delegatesContainer = new htmlTable();
$delegatesContainer->colspan = 3; $delegatesContainer->colspan = 3;
if (isset($this->attributes['kolabDelegate'])) { if (isset($this->attributes['kolabDelegate'])) {
for ($i = 0; $i < sizeof($this->attributes['kolabDelegate']); $i++) { for ($i = 0; $i < sizeof($this->attributes['kolabDelegate']); $i++) {
$delegatesContainer->addElement(new htmlSelect('delegate' . $i, $delegates, array($this->attributes['kolabDelegate'][$i]))); $delegateSelect = new htmlSelect('delegate' . $i, $delegates, array($this->attributes['kolabDelegate'][$i]));
$delegateSelect->setHasDescriptiveElements(true);
$delegateSelect->setSortElements(false);
$delegatesContainer->addElement($delegateSelect);
$delegatesContainer->addElement(new htmlButton('delDelegate' . $i, 'del.png', true)); $delegatesContainer->addElement(new htmlButton('delDelegate' . $i, 'del.png', true));
if ($i == 0) { if ($i == 0) {
$delegatesContainer->addElement(new htmlHelpLink('delegate')); $delegatesContainer->addElement(new htmlHelpLink('delegate'));
@ -335,15 +288,6 @@ class kolabSharedFolder extends baseModule {
$delegatesContainer->addElement(new htmlHelpLink('delegate')); $delegatesContainer->addElement(new htmlHelpLink('delegate'));
} }
$container->addElement($delegatesContainer, true); $container->addElement($delegatesContainer, true);
// delete flag
$this->loadMailHostCache();
if (!$this->getAccountContainer()->isNewAccount && (sizeof($this->mailHostCache) > 0)) {
$deleteContainer = new htmlTable();
$deleteContainer->addElement(new htmlSpacer(null, '20px'), true);
$deleteContainer->addElement(new htmlAccountPageButton(get_class($this), 'deleteFlag', 'open', _('Mark account for deletion')));
$deleteContainer->addElement(new htmlHelpLink('deleteFlag'));
$container->addElement($deleteContainer);
}
return $container; return $container;
} }
@ -365,22 +309,6 @@ class kolabSharedFolder extends baseModule {
if (empty($_POST['mail']) || !get_preg($_POST['mail'], 'email')) { if (empty($_POST['mail']) || !get_preg($_POST['mail'], 'email')) {
$errors[] = $this->messages['mail'][0]; $errors[] = $this->messages['mail'][0];
} }
// mailbox server
if (isset($_POST['mailHost'])) {
if (($_POST['mailHost'] == "") && isset($this->attributes['mailHost'])) {
unset($this->attributes['mailHost']);
}
elseif (!empty($_POST['mailHost'])) {
if (get_preg($_POST['mailHost'], 'DNSname')) {
$this->attributes['mailHost'][0] = $_POST['mailHost'];
}
else {
$message = $this->messages['mailHost'][0];
$message[] = $_POST['mailHost'];
$errors[] = $message;
}
}
}
// target folder // target folder
$this->attributes['kolabTargetFolder'][0] = $_POST['kolabTargetFolder']; $this->attributes['kolabTargetFolder'][0] = $_POST['kolabTargetFolder'];
if (empty($_POST['kolabTargetFolder'])) { if (empty($_POST['kolabTargetFolder'])) {
@ -413,47 +341,16 @@ class kolabSharedFolder extends baseModule {
return $errors; return $errors;
} }
/**
* This function will create the meta HTML code to show a page to mark an account for deletion.
*
* @return htmlElement HTML meta data
*/
function display_html_deleteFlag() {
$return = new htmlTable();
$message = new htmlOutputText(_('Do you really want to mark this account for deletion?'));
$return->addElement($message, true);
$return->addElement(new htmlSpacer(null, '10px'), true);
$serverTable = new htmlTable();
$serverTable->addElement(new htmlTableExtendedSelect('deletionServer', $this->mailHostCache, array(), _('Server'), 'deleteFlag'));
$return->addElement($serverTable, true);
$return->addElement(new htmlSpacer(null, '10px'), true);
$buttonGroup = new htmlGroup();
$buttonGroup->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'confirm', _('Mark account for deletion')));
$buttonGroup->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'cancel', _('Cancel')));
$return->addElement($buttonGroup, true);
return $return;
}
/**
* Write variables into object and do some regex checks
*/
function process_deleteFlag() {
if (isset($_POST['form_subpage_kolabSharedFolder_attributes_confirm'])) {
// set delete flag
$this->attributes['kolabDeleteflag'][0] = $_POST['deletionServer'];
}
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* @see baseModule::build_uploadAccounts() * @see baseModule::build_uploadAccounts()
*/ */
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) { function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules, &$type) {
$messages = array(); $messages = array();
$delegates = searchLDAPByAttribute(null, null, 'inetOrgPerson', array('mail'), array('user')); $delegates = searchLDAPByAttribute(null, null, 'inetOrgPerson', array('dn'), array('user'));
for ($d = 0; $d < sizeof($delegates); $d++) { for ($d = 0; $d < sizeof($delegates); $d++) {
if (isset($delegates[$d]['mail'][0])) { if (isset($delegates[$d]['dn'])) {
$delegates[$d] = $delegates[$d]['mail'][0]; $delegates[$d] = $delegates[$d]['dn'];
} }
} }
for ($i = 0; $i < sizeof($rawAccounts); $i++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
@ -469,9 +366,6 @@ class kolabSharedFolder extends baseModule {
// mail // mail
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabSharedFolder_mail', 'mail', $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabSharedFolder_mail', 'mail',
'email', $this->messages['mail'][1], $messages); 'email', $this->messages['mail'][1], $messages);
// mailbox server
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabSharedFolder_mailHost', 'mailHost',
'DNSname', $this->messages['mailHost'][1], $messages);
// target folder // target folder
$partialAccounts[$i]['kolabTargetFolder'] = $rawAccounts[$i][$ids['kolabSharedFolder_kolabTargetFolder']]; $partialAccounts[$i]['kolabTargetFolder'] = $rawAccounts[$i][$ids['kolabSharedFolder_kolabTargetFolder']];
// folder type // folder type
@ -484,7 +378,7 @@ class kolabSharedFolder extends baseModule {
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabSharedFolder_aliases', 'alias', 'email', $this->messages['alias'][1], $messages, '/,[ ]*/'); $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'kolabSharedFolder_aliases', 'alias', 'email', $this->messages['alias'][1], $messages, '/,[ ]*/');
// add delegates // add delegates
if ($rawAccounts[$i][$ids['kolabSharedFolder_delegates']] != "") { if ($rawAccounts[$i][$ids['kolabSharedFolder_delegates']] != "") {
$newDelegates = explode(',', $rawAccounts[$i][$ids['kolabSharedFolder_delegates']]); $newDelegates = explode(';', $rawAccounts[$i][$ids['kolabSharedFolder_delegates']]);
// check format // check format
for ($d = 0; $d < sizeof($newDelegates); $d++) { for ($d = 0; $d < sizeof($newDelegates); $d++) {
if (in_array($newDelegates[$d], $delegates)) { if (in_array($newDelegates[$d], $delegates)) {
@ -510,12 +404,11 @@ class kolabSharedFolder extends baseModule {
$return = array(); $return = array();
$this->addSimplePDFField($return, 'cn', _('Name')); $this->addSimplePDFField($return, 'cn', _('Name'));
$this->addSimplePDFField($return, 'mail', _('Email address')); $this->addSimplePDFField($return, 'mail', _('Email address'));
$this->addSimplePDFField($return, 'mailHost', _('Mailbox home server'));
$this->addSimplePDFField($return, 'kolabTargetFolder', _('Target IMAP folder')); $this->addSimplePDFField($return, 'kolabTargetFolder', _('Target IMAP folder'));
$this->addSimplePDFField($return, 'kolabAllowSMTPRecipient', _('Allowed recipients')); $this->addSimplePDFField($return, 'kolabAllowSMTPRecipient', _('Allowed recipients'));
$this->addSimplePDFField($return, 'kolabAllowSMTPSender', _('Allowed senders')); $this->addSimplePDFField($return, 'kolabAllowSMTPSender', _('Allowed senders'));
$this->addSimplePDFField($return, 'aliases', _('Email aliases'), 'alias'); $this->addSimplePDFField($return, 'aliases', _('Email aliases'), 'alias');
$this->addSimplePDFField($return, 'delegate', _('Delegates'), 'kolabDelegate'); $this->addSimplePDFField($return, 'delegate', _('Delegates'), 'kolabDelegate', '; ');
if (!empty($this->attributes['kolabFolderType'])) { if (!empty($this->attributes['kolabFolderType'])) {
$type = $this->attributes['kolabFolderType'][0]; $type = $this->attributes['kolabFolderType'][0];
$typeList = array_flip($this->folderTypes); $typeList = array_flip($this->folderTypes);
@ -527,22 +420,6 @@ class kolabSharedFolder extends baseModule {
return $return; return $return;
} }
/**
* Loads the list of mail hosts into the cache.
*/
private function loadMailHostCache() {
if ($this->mailHostCache != null) {
return;
}
$results = searchLDAPByFilter('(mailHost=*)', array('mailHost'), array('user'));
$this->mailHostCache = array();
foreach ($results as $result) {
if (isset($result['mailhost'][0]) && !in_array_ignore_case($result['mailhost'][0], $this->mailHostCache)) {
$this->mailHostCache[] = $result['mailhost'][0];
}
}
}
} }