egroupware/admin/inc/class.boldap_mgr.inc.php

389 lines
10 KiB
PHP
Raw Normal View History

<?php
/***************************************************************************\
2005-11-02 11:05:57 +01:00
* EGroupWare - LDAPManager *
* http://www.egroupware.org *
2005-11-02 11:05:57 +01:00
* Written by : Andreas Krause (ak703@users.sourceforge.net *
* based on EmailAdmin by Lars Kneschke [lkneschke@egroupware.org] *
* ------------------------------------------------- *
* 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. *
\***************************************************************************/
2005-11-02 11:05:57 +01:00
/* $Id$ */
class boldap_mgr
{
var $sessionData;
var $LDAPData;
2005-11-26 15:04:40 +01:00
var $SMTPServerType = array(); // holds a list of config options
2005-11-26 15:04:40 +01:00
var $imapClass; // holds the imap/pop3 class
var $smtpClass; // holds the smtp class
var $public_functions = array
(
'getFieldNames' => True,
'getLDAPStorageData' => True,
'getLocals' => True,
'getProfile' => True,
'getProfileList' => True,
'getRcptHosts' => True,
'getSMTPServerTypes' => True
);
function boldap_mgr($_profileID=-1)
{
2005-10-14 19:03:16 +02:00
$this->soldapmgr =& CreateObject('admin.soldap_mgr');
2005-11-26 15:04:40 +01:00
$this->SMTPServerType = array(
'1' => array(
'fieldNames' => array(
'smtpServer',
'smtpPort',
'smtpAuth',
'smtpType'
),
'description' => lang('standard SMTP-Server'),
'classname' => 'defaultsmtp'
),
'2' => array(
'fieldNames' => array(
'smtpServer',
'smtpPort',
'smtpAuth',
'smtpType',
'smtpLDAPServer',
'smtpLDAPAdminDN',
'smtpLDAPAdminPW',
'smtpLDAPBaseDN',
'smtpLDAPUseDefault'
),
'description' => lang('Postfix with LDAP'),
'classname' => 'postfixldap'
)
);
$this->IMAPServerType = array(
'1' => array(
'fieldNames' => array(
'imapServer',
'imapPort',
'imapType',
'imapLoginType',
'imapTLSEncryption',
'imapTLSAuthentication',
'imapoldcclient'
),
'description' => lang('standard POP3 server'),
'protocol' => 'pop3',
'classname' => 'defaultpop'
),
'2' => array(
'fieldNames' => array(
'imapServer',
'imapPort',
'imapType',
'imapLoginType',
'imapTLSEncryption',
'imapTLSAuthentication',
'imapoldcclient'
),
'description' => lang('standard IMAP server'),
'protocol' => 'imap',
'classname' => 'defaultimap'
),
'3' => array(
'fieldNames' => array(
'imapServer',
'imapPort',
'imapType',
'imapLoginType',
'imapTLSEncryption',
'imapTLSAuthentication',
'imapoldcclient',
'imapEnableCyrusAdmin',
'imapAdminUsername',
'imapAdminPW',
'imapEnableSieve',
'imapSieveServer',
'imapSievePort'
),
'description' => lang('Cyrus IMAP Server'),
'protocol' => 'imap',
'classname' => 'cyrusimap'
)
2005-11-26 15:04:40 +01:00
);
$this->restoreSessionData();
2005-11-26 15:04:40 +01:00
if($_profileID >= 0)
{
$this->profileID = $_profileID;
2005-11-26 15:04:40 +01:00
$this->profileData = $this->getProfile($_profileID);
2005-11-26 15:04:40 +01:00
$this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname'];
$this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname'];
}
}
function encodeHeader($_string, $_encoding='q')
{
switch($_encoding)
{
2005-11-26 15:04:40 +01:00
case 'q':
if(!preg_match("/[\x80-\xFF]/",$_string))
{
// nothing to quote, only 7 bit ascii
return $_string;
}
2005-11-26 15:04:40 +01:00
$string = imap_8bit($_string);
$stringParts = explode("=\r\n",$string);
while(list($key,$value) = each($stringParts))
{
2005-11-26 15:04:40 +01:00
if(!empty($retString)) $retString .= ' ';
$value = str_replace(' ','_',$value);
// imap_8bit does not convert '?'
// it does not need, but it should
$value = str_replace("?","=3F",$value);
$retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?=";
}
#exit;
return $retString;
break;
default:
return $_string;
}
}
function getAccountEmailAddress($_accountName, $_profileID)
{
$profileData = $this->getProfile($_profileID);
2005-11-26 15:04:40 +01:00
$smtpClass = $this->SMTPServerType[$profileData['smtpType']]['classname'];
2005-11-02 11:05:57 +01:00
return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData);
}
2005-11-26 15:04:40 +01:00
function getFieldNames($_serverTypeID, $_class)
{
switch($_class)
{
case 'imap':
return $this->IMAPServerType[$_serverTypeID]['fieldNames'];
break;
case 'smtp':
return $this->SMTPServerType[$_serverTypeID]['fieldNames'];
break;
}
}
2005-11-26 15:04:40 +01:00
# function getIMAPClass($_profileID)
# {
# if(!is_object($this->imapClass))
# {
# $profileData = $this->getProfile($_profileID);
2005-10-14 19:03:16 +02:00
# $this->imapClass =& CreateObject('emailadmin.cyrusimap',$profileData);
# }
2005-11-26 15:04:40 +01:00
#
# return $this->imapClass;
# }
2005-11-26 15:04:40 +01:00
function getIMAPServerTypes()
{
foreach($this->IMAPServerType as $key => $value)
{
$retData[$key]['description'] = $value['description'];
$retData[$key]['protocol'] = $value['protocol'];
}
2005-11-26 15:04:40 +01:00
return $retData;
}
2005-11-26 15:04:40 +01:00
function getLDAPStorageData($_serverid)
{
$storageData = $this->soldapmgr->getLDAPStorageData($_serverid);
return $storageData;
}
2005-11-26 15:04:40 +01:00
function getMailboxString($_folderName)
{
if (!empty($this->imapClass))
{
2005-11-26 15:04:40 +01:00
return ExecMethod('emailadmin.'.$this->imapClass.'.getMailboxString',$_folderName,3,$this->profileData);
}
else
{
return false;
}
}
function getProfile($_profileID)
{
$profileData = $this->soldapmgr->getProfileList($_profileID);
$fieldNames = $this->SMTPServerType[$profileData[0]['smtpType']]['fieldNames'];
$fieldNames = array_merge($fieldNames, $this->IMAPServerType[$profileData[0]['imapType']]['fieldNames']);
$fieldNames[] = 'description';
$fieldNames[] = 'defaultDomain';
$fieldNames[] = 'profileID';
$fieldNames[] = 'organisationName';
$fieldNames[] = 'userDefinedAccounts';
2005-11-26 15:04:40 +01:00
return $this->soldapmgr->getProfile($_profileID, $fieldNames);
}
2005-11-26 15:04:40 +01:00
function getProfileList($_profileID='')
{
$profileList = $this->soldapmgr->getProfileList($_profileID);
return $profileList;
}
2005-11-26 15:04:40 +01:00
# function getSMTPClass($_profileID)
# {
# if(!is_object($this->smtpClass))
# {
# $profileData = $this->getProfile($_profileID);
2005-10-14 19:03:16 +02:00
# $this->smtpClass =& CreateObject('emailadmin.postfixldap',$profileData);
# }
2005-11-26 15:04:40 +01:00
#
# return $this->smtpClass;
# }
2005-11-26 15:04:40 +01:00
function getSMTPServerTypes()
{
foreach($this->SMTPServerType as $key => $value)
{
$retData[$key] = $value['description'];
}
2005-11-26 15:04:40 +01:00
return $retData;
}
2005-11-26 15:04:40 +01:00
function getUserData($_accountID, $_usecache)
{
if ($_usecache)
{
$userData = $this->userSessionData[$_accountID];
}
else
{
$userData = $this->soldapmgr->getUserData($_accountID);
$this->userSessionData[$_accountID] = $userData;
$this->saveSessionData();
}
return $userData;
}
function restoreSessionData()
{
2005-10-14 19:03:16 +02:00
$this->sessionData = $GLOBALS['egw']->session->appsession('session_data');
$this->userSessionData = $GLOBALS['egw']->session->appsession('user_session_data');
2005-11-26 15:04:40 +01:00
#while(list($key, $value) = each($this->userSessionData))
#{
# print "++ $key: $value<br>";
#}
#print "restored Session<br>";
}
2005-11-26 15:04:40 +01:00
function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings)
{
if(!isset($_globalSettings['profileID']))
{
$this->soldapmgr->addProfile($_globalSettings, $_smtpSettings, $_imapSettings);
}
else
{
$this->soldapmgr->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings);
}
}
function saveSessionData()
{
2005-10-14 19:03:16 +02:00
$GLOBALS['egw']->session->appsession('session_data','',$this->sessionData);
$GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData);
}
function saveUserData($_accountID, $_formData, $_boAction)
{
2005-11-26 15:04:40 +01:00
$this->userSessionData[$_accountID]['mail'] = $_formData['mail'];
$this->userSessionData[$_accountID]['mailForwardingAddress'] = $_formData['mailForwardingAddress'];
$this->userSessionData[$_accountID]['accountStatus'] = $_formData['accountStatus'];
switch ($_boAction)
{
case 'add_mailAlternateAddress':
if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress']))
{
$count = count($this->userSessionData[$_accountID]['mailAlternateAddress']);
}
else
{
//ACHTUNG!!
$count = 0;
}
2005-11-26 15:04:40 +01:00
$this->userSessionData[$_accountID]['mailAlternateAddress'][$count] =
$_formData['add_mailAlternateAddress'];
2005-11-26 15:04:40 +01:00
$this->saveSessionData();
2005-11-26 15:04:40 +01:00
break;
2005-11-26 15:04:40 +01:00
case 'remove_mailAlternateAddress':
$i=0;
2005-11-26 15:04:40 +01:00
while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress']))
{
#print ".. $key: $value<br>";
if ($key != $_formData['remove_mailAlternateAddress'])
{
$newMailAlternateAddress[$i]=$value;
#print "!! $i: $value<br>";
$i++;
}
}
$this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress;
2005-11-26 15:04:40 +01:00
$this->saveSessionData();
break;
case 'save':
$this->soldapmgr->saveUserData(
2005-11-26 15:04:40 +01:00
$_accountID,
$this->userSessionData[$_accountID]
);
2005-10-14 19:03:16 +02:00
$bofelamimail =& CreateObject('felamimail.bofelamimail');
$bofelamimail->openConnection('','',true);
2005-11-26 15:04:40 +01:00
$bofelamimail->imapSetQuota(
$GLOBALS['egw']->accounts->id2name($_accountID),
$this->userSessionData[$_accountID]['quotaLimit']
);
$bofelamimail->closeConnection();
2005-10-14 19:03:16 +02:00
$GLOBALS['egw']->accounts->cache_invalidate($_accountID);
2005-11-26 15:04:40 +01:00
break;
}
}
function updateAccount($_hookValues)
{
if (!empty($this->imapClass))
{
2005-11-26 15:04:40 +01:00
ExecMethod('emailadmin.'.$this->imapClass.'.updateAccount',$_hookValues,3,$this->profileData);
}
if (!empty($this->smtpClass))
{
2005-11-26 15:04:40 +01:00
ExecMethod('emailadmin.'.$this->smtpClass.'.updateAccount',$_hookValues,3,$this->profileData);
}
}
}
?>