[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/inc/ -> class.boldap_mgr.inc.php (source)

   1  <?php
   2      /***************************************************************************\
   3      * EGroupWare - LDAPManager                                                  *
   4      * http://www.egroupware.org                                                 *
   5      * Written by : Andreas Krause (ak703@users.sourceforge.net                  *
   6      * based on EmailAdmin by Lars Kneschke [lkneschke@egroupware.org]           *
   7      * -------------------------------------------------                         *
   8      * This program is free software; you can redistribute it and/or modify it   *
   9      * under the terms of the GNU General Public License as published by the     *
  10      * Free Software Foundation; either version 2 of the License, or (at your    *
  11      * option) any later version.                                                *
  12      \***************************************************************************/
  13  
  14      /* $Id: class.boldap_mgr.inc.php 20295 2006-02-15 12:31:25Z  $ */
  15  
  16      class boldap_mgr
  17      {
  18          var $sessionData;
  19          var $LDAPData;
  20  
  21          var $SMTPServerType = array();        // holds a list of config options
  22  
  23          var $imapClass;                // holds the imap/pop3 class
  24          var $smtpClass;                // holds the smtp class
  25  
  26          var $public_functions = array
  27          (
  28              'getFieldNames'        => True,
  29              'getLDAPStorageData'    => True,
  30              'getLocals'        => True,
  31              'getProfile'        => True,
  32              'getProfileList'    => True,
  33              'getRcptHosts'        => True,
  34              'getSMTPServerTypes'    => True
  35          );
  36  
  37  		function boldap_mgr($_profileID=-1)
  38          {
  39              $this->soldapmgr =& CreateObject('admin.soldap_mgr');
  40  
  41              $this->SMTPServerType = array(
  42                  '1'     => array(
  43                      'fieldNames'    => array(
  44                          'smtpServer',
  45                          'smtpPort',
  46                          'smtpAuth',
  47                          'smtpType'
  48                      ),
  49                      'description'    => lang('standard SMTP-Server'),
  50                      'classname'    => 'defaultsmtp'
  51                  ),
  52                  '2'     => array(
  53                      'fieldNames'    => array(
  54                          'smtpServer',
  55                          'smtpPort',
  56                          'smtpAuth',
  57                          'smtpType',
  58                          'smtpLDAPServer',
  59                          'smtpLDAPAdminDN',
  60                          'smtpLDAPAdminPW',
  61                          'smtpLDAPBaseDN',
  62                          'smtpLDAPUseDefault'
  63                      ),
  64                      'description'    => lang('Postfix with LDAP'),
  65                      'classname'    => 'postfixldap'
  66                  )
  67              );
  68  
  69              $this->IMAPServerType = array(
  70                  '1'     => array(
  71                      'fieldNames'    => array(
  72                          'imapServer',
  73                          'imapPort',
  74                          'imapType',
  75                          'imapLoginType',
  76                          'imapTLSEncryption',
  77                          'imapTLSAuthentication',
  78                          'imapoldcclient'
  79                      ),
  80                      'description'    => lang('standard POP3 server'),
  81                      'protocol'    => 'pop3',
  82                      'classname'    => 'defaultpop'
  83                  ),
  84                  '2'     => array(
  85                      'fieldNames'    => array(
  86                          'imapServer',
  87                          'imapPort',
  88                          'imapType',
  89                          'imapLoginType',
  90                          'imapTLSEncryption',
  91                          'imapTLSAuthentication',
  92                          'imapoldcclient'
  93                      ),
  94                      'description'    => lang('standard IMAP server'),
  95                      'protocol'    => 'imap',
  96                      'classname'    => 'defaultimap'
  97                  ),
  98                  '3'     => array(
  99                      'fieldNames'    => array(
 100                          'imapServer',
 101                          'imapPort',
 102                          'imapType',
 103                          'imapLoginType',
 104                          'imapTLSEncryption',
 105                          'imapTLSAuthentication',
 106                          'imapoldcclient',
 107                          'imapEnableCyrusAdmin',
 108                          'imapAdminUsername',
 109                          'imapAdminPW',
 110                          'imapEnableSieve',
 111                          'imapSieveServer',
 112                          'imapSievePort'
 113                      ),
 114                      'description'    => lang('Cyrus IMAP Server'),
 115                      'protocol'    => 'imap',
 116                      'classname'    => 'cyrusimap'
 117                  )
 118              );
 119  
 120              $this->restoreSessionData();
 121  
 122              if($_profileID >= 0)
 123              {
 124                  $this->profileID    = $_profileID;
 125  
 126                  $this->profileData    = $this->getProfile($_profileID);
 127  
 128                  $this->imapClass    = $this->IMAPServerType[$this->profileData['imapType']]['classname'];
 129                  $this->smtpClass    = $this->SMTPServerType[$this->profileData['smtpType']]['classname'];
 130              }
 131          }
 132  
 133  		function encodeHeader($_string, $_encoding='q')
 134          {
 135              switch($_encoding)
 136              {
 137                  case 'q':
 138                      if(!preg_match("/[\x80-\xFF]/",$_string))
 139                      {
 140                          // nothing to quote, only 7 bit ascii
 141                          return $_string;
 142                      }
 143  
 144                      $string = imap_8bit($_string);
 145                      $stringParts = explode("=\r\n",$string);
 146                      while(list($key,$value) = each($stringParts))
 147                      {
 148                          if(!empty($retString)) $retString .= ' ';
 149                          $value = str_replace(' ','_',$value);
 150                          // imap_8bit does not convert '?'
 151                          // it does not need, but it should
 152                          $value = str_replace("?","=3F",$value);
 153                          $retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?=";
 154                      }
 155                      #exit;
 156                      return $retString;
 157                      break;
 158                  default:
 159                      return $_string;
 160              }
 161          }
 162  
 163  		function getAccountEmailAddress($_accountName, $_profileID)
 164          {
 165              $profileData    = $this->getProfile($_profileID);
 166  
 167              $smtpClass    = $this->SMTPServerType[$profileData['smtpType']]['classname'];
 168  
 169              return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData);
 170          }
 171  
 172  		function getFieldNames($_serverTypeID, $_class)
 173          {
 174              switch($_class)
 175              {
 176                  case 'imap':
 177                      return $this->IMAPServerType[$_serverTypeID]['fieldNames'];
 178                      break;
 179                  case 'smtp':
 180                      return $this->SMTPServerType[$_serverTypeID]['fieldNames'];
 181                      break;
 182              }
 183          }
 184  
 185  #        function getIMAPClass($_profileID)
 186  #        {
 187  #            if(!is_object($this->imapClass))
 188  #            {
 189  #                $profileData        = $this->getProfile($_profileID);
 190  #                $this->imapClass    =& CreateObject('emailadmin.cyrusimap',$profileData);
 191  #            }
 192  #
 193  #            return $this->imapClass;
 194  #        }
 195  
 196  		function getIMAPServerTypes()
 197          {
 198              foreach($this->IMAPServerType as $key => $value)
 199              {
 200                  $retData[$key]['description']    = $value['description'];
 201                  $retData[$key]['protocol']    = $value['protocol'];
 202              }
 203  
 204              return $retData;
 205          }
 206  
 207  		function getLDAPStorageData($_serverid)
 208          {
 209              $storageData = $this->soldapmgr->getLDAPStorageData($_serverid);
 210              return $storageData;
 211          }
 212  
 213  		function getMailboxString($_folderName)
 214          {
 215              if (!empty($this->imapClass))
 216              {
 217                  return ExecMethod('emailadmin.'.$this->imapClass.'.getMailboxString',$_folderName,3,$this->profileData);
 218              }
 219              else
 220              {
 221                  return false;
 222              }
 223          }
 224  
 225  		function getProfile($_profileID)
 226          {
 227              $profileData = $this->soldapmgr->getProfileList($_profileID);
 228              $fieldNames = $this->SMTPServerType[$profileData[0]['smtpType']]['fieldNames'];
 229              $fieldNames = array_merge($fieldNames, $this->IMAPServerType[$profileData[0]['imapType']]['fieldNames']);
 230              $fieldNames[] = 'description';
 231              $fieldNames[] = 'defaultDomain';
 232              $fieldNames[] = 'profileID';
 233              $fieldNames[] = 'organisationName';
 234              $fieldNames[] = 'userDefinedAccounts';
 235  
 236              return $this->soldapmgr->getProfile($_profileID, $fieldNames);
 237          }
 238  
 239  		function getProfileList($_profileID='')
 240          {
 241              $profileList = $this->soldapmgr->getProfileList($_profileID);
 242              return $profileList;
 243          }
 244  
 245  #        function getSMTPClass($_profileID)
 246  #        {
 247  #            if(!is_object($this->smtpClass))
 248  #            {
 249  #                $profileData        = $this->getProfile($_profileID);
 250  #                $this->smtpClass    =& CreateObject('emailadmin.postfixldap',$profileData);
 251  #            }
 252  #
 253  #            return $this->smtpClass;
 254  #        }
 255  
 256  		function getSMTPServerTypes()
 257          {
 258              foreach($this->SMTPServerType as $key => $value)
 259              {
 260                  $retData[$key] = $value['description'];
 261              }
 262  
 263              return $retData;
 264          }
 265  
 266  		function getUserData($_accountID, $_usecache)
 267          {
 268              if ($_usecache)
 269              {
 270                  $userData = $this->userSessionData[$_accountID];
 271              }
 272              else
 273              {
 274                  $userData = $this->soldapmgr->getUserData($_accountID);
 275                  $this->userSessionData[$_accountID] = $userData;
 276                  $this->saveSessionData();
 277              }
 278              return $userData;
 279          }
 280  
 281  		function restoreSessionData()
 282          {
 283              $this->sessionData = $GLOBALS['egw']->session->appsession('session_data');
 284              $this->userSessionData = $GLOBALS['egw']->session->appsession('user_session_data');
 285  
 286              #while(list($key, $value) = each($this->userSessionData))
 287              #{
 288              #    print "++ $key: $value<br>";
 289              #}
 290              #print "restored Session<br>";
 291          }
 292  
 293  		function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings)
 294          {
 295              if(!isset($_globalSettings['profileID']))
 296              {
 297                  $this->soldapmgr->addProfile($_globalSettings, $_smtpSettings, $_imapSettings);
 298              }
 299              else
 300              {
 301                  $this->soldapmgr->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings);
 302              }
 303          }
 304  
 305  		function saveSessionData()
 306          {
 307              $GLOBALS['egw']->session->appsession('session_data','',$this->sessionData);
 308              $GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData);
 309          }
 310  
 311  		function saveUserData($_accountID, $_formData, $_boAction)
 312          {
 313              $this->userSessionData[$_accountID]['mail']                     = $_formData['mail'];
 314              $this->userSessionData[$_accountID]['mailForwardingAddress'] = $_formData['mailForwardingAddress'];
 315              $this->userSessionData[$_accountID]['accountStatus']         = $_formData['accountStatus'];
 316  
 317              switch ($_boAction)
 318              {
 319                  case 'add_mailAlternateAddress':
 320  
 321                      if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress']))
 322                      {
 323                          $count = count($this->userSessionData[$_accountID]['mailAlternateAddress']);
 324                      }
 325                      else
 326                      {
 327  //ACHTUNG!!
 328                          $count = 0;
 329                      }
 330  
 331                      $this->userSessionData[$_accountID]['mailAlternateAddress'][$count] =
 332                          $_formData['add_mailAlternateAddress'];
 333  
 334                      $this->saveSessionData();
 335  
 336                      break;
 337  
 338                  case 'remove_mailAlternateAddress':
 339                      $i=0;
 340  
 341                      while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress']))
 342                      {
 343                          #print ".. $key: $value<br>";
 344                          if ($key != $_formData['remove_mailAlternateAddress'])
 345                          {
 346                              $newMailAlternateAddress[$i]=$value;
 347                              #print "!! $i: $value<br>";
 348                              $i++;
 349                          }
 350                      }
 351                      $this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress;
 352  
 353                      $this->saveSessionData();
 354  
 355                      break;
 356  
 357                  case 'save':
 358                      $this->soldapmgr->saveUserData(
 359                          $_accountID,
 360                          $this->userSessionData[$_accountID]
 361                      );
 362                      $bofelamimail =& CreateObject('felamimail.bofelamimail');
 363                      $bofelamimail->openConnection('','',true);
 364                      $bofelamimail->imapSetQuota(
 365                          $GLOBALS['egw']->accounts->id2name($_accountID),
 366                          $this->userSessionData[$_accountID]['quotaLimit']
 367                      );
 368                      $bofelamimail->closeConnection();
 369                      $GLOBALS['egw']->accounts->cache_invalidate($_accountID);
 370  
 371                      break;
 372              }
 373          }
 374  
 375  		function updateAccount($_hookValues)
 376          {
 377              if (!empty($this->imapClass))
 378              {
 379                  ExecMethod('emailadmin.'.$this->imapClass.'.updateAccount',$_hookValues,3,$this->profileData);
 380              }
 381  
 382              if (!empty($this->smtpClass))
 383              {
 384                  ExecMethod('emailadmin.'.$this->smtpClass.'.updateAccount',$_hookValues,3,$this->profileData);
 385              }
 386          }
 387      }
 388  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7