support also windowsUser
This commit is contained in:
parent
bf1e8081f7
commit
2a6ea95e60
|
@ -4,7 +4,7 @@ $Id$
|
|||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2010 - 2011 Pavel Pozdniak
|
||||
2010 - 2014 Roland Gruber
|
||||
2010 - 2015 Roland Gruber
|
||||
|
||||
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
|
||||
|
@ -41,6 +41,11 @@ class imapAccess extends baseModule {
|
|||
/** quota limit from profile */
|
||||
private $profileQuotaLimit = null;
|
||||
|
||||
/** user name */
|
||||
private $user;
|
||||
/** email address */
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* Returns true if this module can manage accounts of the current type, otherwise false.
|
||||
*
|
||||
|
@ -62,7 +67,7 @@ class imapAccess extends baseModule {
|
|||
// alias name
|
||||
$return["alias"] = _("Mailbox");
|
||||
// module dependencies
|
||||
$return['dependencies'] = array('depends' => array('inetOrgPerson'), 'conflicts' => array());
|
||||
$return['dependencies'] = array('depends' => array(array('inetOrgPerson', 'windowsUser')), 'conflicts' => array());
|
||||
// managed object classes
|
||||
$return['objectClasses'] = array();
|
||||
// managed attributes
|
||||
|
@ -141,7 +146,7 @@ class imapAccess extends baseModule {
|
|||
$mailDomainsInput->setRequired(true);
|
||||
$configContainer->addElement($mailDomainsInput, true);
|
||||
$configContainer->addElement(new htmlTableExtendedInputField(_('Prefix for mailboxes'), 'ImapAccess_ImapUserPrefix', '', 'ImapUserPrefix'), true);
|
||||
$configUserName = new htmlTableExtendedSelect('ImapAccess_UserNameAttribute', array('mail', 'uid'), array('mail'), _("User name attribute"), 'ImapUserNameAttr');
|
||||
$configUserName = new htmlTableExtendedSelect('ImapAccess_UserNameAttribute', array('mail', 'uid', 'userPrincipalName'), array('mail'), _("User name attribute"), 'ImapUserNameAttr');
|
||||
$configContainer->addElement($configUserName, true);
|
||||
$configPathSeparator = new htmlTableExtendedSelect('ImapAccess_pathSeparator', array('.', '/'), array('.'), _("Path separator"), 'pathSeparator');
|
||||
$configContainer->addElement($configPathSeparator, true);
|
||||
|
@ -188,6 +193,48 @@ class imapAccess extends baseModule {
|
|||
$this->messages['managemailbox'][8] = array('ERROR', _('Wrong quota format. Quota must be numeric.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts user name and email address from inetOrgPerson/posixAccount/windowsUser modules.
|
||||
*
|
||||
* @return htmlStatusMessage message if any
|
||||
*/
|
||||
private function extractUserAndEmail() {
|
||||
$this->email = '';
|
||||
if ($this->getAccountContainer()->getAccountModule('inetOrgPerson') != null) {
|
||||
$attrs = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
||||
$this->email = $attrs['mail'][0];
|
||||
}
|
||||
else {
|
||||
$attrs = $this->getAccountContainer()->getAccountModule('windowsUser')->getAttributes();
|
||||
$this->email = $attrs['mail'][0];
|
||||
}
|
||||
$this->user = '';
|
||||
// extract user name from email address
|
||||
if (empty($this->moduleSettings['ImapAccess_UserNameAttribute'][0]) || $this->moduleSettings['ImapAccess_UserNameAttribute'][0] == 'mail') {
|
||||
$email_parts = explode('@', $this->email, 2);
|
||||
$this->user = array_shift($email_parts);
|
||||
}
|
||||
elseif ($this->moduleSettings['ImapAccess_UserNameAttribute'][0] == 'userPrincipalName') {
|
||||
$parts = explode('@', $attrs['userPrincipalName'][0], 2);
|
||||
$this->user = array_shift($parts);
|
||||
}
|
||||
// extract user name from Unix user name (might be in inetOrgPerson/windowUser or posixAccount module)
|
||||
else {
|
||||
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
|
||||
$attrsUnix = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
|
||||
$this->user = !empty($attrsUnix['uid'][0]) ? $attrsUnix['uid'][0] : '';
|
||||
}
|
||||
else {
|
||||
$this->user = !empty($attrs['uid'][0]) ? $attrs['uid'][0] : '';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->email)) {
|
||||
$modName = ($this->getAccountContainer()->getAccountModule('inetOrgPerson') != null) ? 'inetOrgPerson' : 'windowUser';
|
||||
return new htmlStatusMessage('INFO', _("Please enter an email address on this page: %s"), '', array($this->getAccountContainer()->getAccountModule($modName)->get_alias()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML meta data for the main account page.
|
||||
*
|
||||
|
@ -198,39 +245,21 @@ class imapAccess extends baseModule {
|
|||
if (!checkIfWriteAccessIsAllowed($this->get_scope())) {
|
||||
return $return;
|
||||
}
|
||||
$prefix = $this->getMailboxPrefix();
|
||||
|
||||
$email = '';
|
||||
$attrsPersonal = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
||||
$email = $attrsPersonal['mail'][0];
|
||||
|
||||
if ($email == '') {
|
||||
$return->addElement(new htmlStatusMessage('INFO', _("Please enter an email address on this page: %s"), '', array($this->getAccountContainer()->getAccountModule('inetOrgPerson')->get_alias())));
|
||||
$msg = $this->extractUserAndEmail();
|
||||
if ($msg != null) {
|
||||
$return->addElement($msg);
|
||||
return $return;
|
||||
}
|
||||
$email_domain = substr(strstr($email, '@'), 1);
|
||||
// extract user name from email address
|
||||
if (!isset($this->moduleSettings['ImapAccess_UserNameAttribute'][0]) || $this->moduleSettings['ImapAccess_UserNameAttribute'][0] == 'mail') {
|
||||
$email_parts = explode('@', $email, 2);
|
||||
$email_username = array_shift($email_parts);
|
||||
}
|
||||
// extract user name from Unix user name (might be in inetOrgPerson or posixAccount module)
|
||||
else {
|
||||
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
|
||||
$attrsUnix = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
|
||||
$email_username = $attrsUnix['uid'][0];
|
||||
}
|
||||
else {
|
||||
$email_username = $attrsPersonal['uid'][0];
|
||||
}
|
||||
}
|
||||
$prefix = $this->getMailboxPrefix();
|
||||
|
||||
$email_domain = substr(strstr($this->email, '@'), 1);
|
||||
$imap_admin_password = $this->getAdminPassword(); // check for password for fall back mechanism
|
||||
if (!isset($_SESSION['imapAdmPass']) && !isset($imap_admin_password)) {
|
||||
return $this->display_html_password();
|
||||
}
|
||||
|
||||
$return->addElement(new htmlOutputText(_('Email address')));
|
||||
$return->addElement(new htmlOutputText($email), true);
|
||||
$return->addElement(new htmlOutputText($this->email), true);
|
||||
|
||||
$imap_server_address = $this->getServerAddress();
|
||||
$imap_admin_user = $this->getAdminUser();
|
||||
|
@ -241,14 +270,14 @@ class imapAccess extends baseModule {
|
|||
}
|
||||
|
||||
$return->addElement(new htmlOutputText(_('Mailbox')));
|
||||
$return->addElement(new htmlOutputText($prefix . $this->getSep() . $email_username));
|
||||
$return->addElement(new htmlOutputText($prefix . $this->getSep() . $this->user));
|
||||
$return->addElement(new htmlHelpLink('MailAddress'), true);
|
||||
$return->addElement(new htmlSpacer(null, '10px'), true);
|
||||
|
||||
$is_mailbox_exist = false; //default is false
|
||||
$list = imap_list($mbox, "{" . $imap_server_address . "}", $prefix . $this->getSep() . $email_username);
|
||||
$list = imap_list($mbox, "{" . $imap_server_address . "}", $prefix . $this->getSep() . $this->user);
|
||||
if (is_array($list) && sizeof($list) == 1) {
|
||||
$this->renderQuotasForMailbox($return, $mbox, $prefix . $this->getSep() . $email_username);
|
||||
$this->renderQuotasForMailbox($return, $mbox, $prefix . $this->getSep() . $this->user);
|
||||
$mailboxMessage = new htmlOutputText(_("Mailbox already exists on IMAP server."));
|
||||
$mailboxMessage->colspan = 3;
|
||||
$return->addElement($mailboxMessage, true);
|
||||
|
@ -361,35 +390,19 @@ class imapAccess extends baseModule {
|
|||
$mbox = @imap_open("{" . $imap_server_address . "}", $imap_admin_user, $imap_admin_password, OP_HALFOPEN, 1);
|
||||
}
|
||||
if ($mbox) {
|
||||
$attrsPersonal = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
||||
$email = $attrsPersonal['mail'][0];
|
||||
$email_domain = substr(strstr($email, '@'), 1);
|
||||
// extract user name from email address
|
||||
if (!isset($this->moduleSettings['ImapAccess_UserNameAttribute'][0]) || $this->moduleSettings['ImapAccess_UserNameAttribute'][0] == 'mail') {
|
||||
$email_parts = explode('@', $email, 2);
|
||||
$email_username = array_shift($email_parts);
|
||||
}
|
||||
// extract user name from Unix user name (might be in inetOrgPerson or posixAccount module)
|
||||
else {
|
||||
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
|
||||
$attrsUnix = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
|
||||
$email_username = $attrsUnix['uid'][0];
|
||||
}
|
||||
else {
|
||||
$email_username = $attrsPersonal['uid'][0];
|
||||
}
|
||||
}
|
||||
$this->extractUserAndEmail();
|
||||
$email_domain = substr(strstr($this->email, '@'), 1);
|
||||
|
||||
if (isset($_POST['deleteMailbox'])) {
|
||||
if ($this->isWrongDomain($email_domain)) {
|
||||
$errors[] = $this->messages['managemailbox'][4];
|
||||
}
|
||||
else {
|
||||
if (!imap_setacl($mbox, $prefix . $this->getSep() . $email_username, $imap_admin_user, "c")) {
|
||||
if (!imap_setacl($mbox, $prefix . $this->getSep() . $this->user, $imap_admin_user, "c")) {
|
||||
$errors[] = $this->messages['managemailbox'][0];
|
||||
}
|
||||
|
||||
$delete_mailbox_arg = "{" . $imap_server_address . "}" . $prefix . $this->getSep() . $email_username;
|
||||
$delete_mailbox_arg = "{" . $imap_server_address . "}" . $prefix . $this->getSep() . $this->user;
|
||||
if (!@imap_deletemailbox($mbox, $delete_mailbox_arg)) {
|
||||
$errors[] = $this->messages['managemailbox'][1];
|
||||
}
|
||||
|
@ -401,9 +414,9 @@ class imapAccess extends baseModule {
|
|||
$errors[] = $this->messages['managemailbox'][4];
|
||||
}
|
||||
else {
|
||||
$create_mailbox_arg = "{" . $imap_server_address . "}" . $prefix . $this->getSep() . $email_username;
|
||||
$create_mailbox_arg = "{" . $imap_server_address . "}" . $prefix . $this->getSep() . $this->user;
|
||||
if (imap_createmailbox($mbox, imap_utf7_encode($create_mailbox_arg))) {
|
||||
$list = imap_list($mbox, "{" . $imap_server_address . "}", $prefix . $this->getSep() . $email_username);
|
||||
$list = imap_list($mbox, "{" . $imap_server_address . "}", $prefix . $this->getSep() . $this->user);
|
||||
if (is_array($list) && sizeof($list) == 1) {
|
||||
|
||||
}
|
||||
|
@ -430,7 +443,7 @@ class imapAccess extends baseModule {
|
|||
}*/
|
||||
}
|
||||
elseif (isset($_POST['ImapUserQuotaLimit']) && ($_POST['ImapUserQuotaLimit'] != '') && get_preg($_POST['ImapUserQuotaLimit'], 'digit')){
|
||||
if (!imap_set_quota($mbox, $prefix . $this->getSep() . $email_username, $_POST['ImapUserQuotaLimit'])) {
|
||||
if (!imap_set_quota($mbox, $prefix . $this->getSep() . $this->user, $_POST['ImapUserQuotaLimit'])) {
|
||||
$message = $this->messages['managemailbox'][7];
|
||||
$message[] = imap_last_error();
|
||||
$errors[] = $message;
|
||||
|
|
Loading…
Reference in New Issue