summaryrefslogtreecommitdiff
path: root/plugins/kolab_addressbook/lib/rcube_kolab.php
blob: 44c37a68f48056d73931ab8a795af1d4fce0ea6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

require_once 'Horde/Kolab/Format/XML.php';
require_once 'Horde/Kolab/Storage/List.php';
require_once 'Horde/Auth.php';
require_once 'Horde/Auth/kolab.php';
require_once 'Horde/Perms.php';

/**
 * Glue class to handle access to the Kolab data using the Kolab_* classes
 * from the Horde project.
 *
 * @author Thomas Bruederli
 */
class rcube_kolab
{
    private static $horde_auth;
    
    /**
     * Setup the environment needed by the Kolab_* classes to access Kolab data
     */
    public static function setup()
    {
        global $conf;
        
        // setup already done
        if (self::$horde_auth)
            return;
        
        $rcmail = rcmail::get_instance();
        
        // load ldap credentials from local config
        $conf['kolab'] = $rcmail->config->get('kolab');
        
        $conf['kolab']['ldap']['server'] = 'ldap://' . $_SESSION['imap_host'] . ':389';
        $conf['kolab']['imap']['server'] = $_SESSION['imap_host'];
        $conf['kolab']['imap']['port'] = $_SESSION['imap_port'];
        
        // pass the current IMAP authentication credentials to the Horde auth system
        self::$horde_auth = Auth::singleton('kolab');
        if (self::$horde_auth->authenticate($_SESSION['username'], array('password' => ($pwd = $rcmail->decrypt($_SESSION['password']))), false)) {
            $_SESSION['__auth'] = array(
                'authenticated' => true,
                'userId' => $_SESSION['username'],
                'timestamp' => time(),
                'remote_addr' => $_SERVER['REMOTE_ADDR'],
            );
            Auth::setCredential('password', $pwd);
        }
    }


}