[Svn] r4247 - in trunk/plugins: . kolab_addressbook kolab_core

trac at roundcube.net trac at roundcube.net
Mon Nov 22 11:18:46 CET 2010


Author: thomasb
Date: 2010-11-22 04:18:46 -0600 (Mon, 22 Nov 2010)
New Revision: 4247

Added:
   trunk/plugins/kolab_core/
   trunk/plugins/kolab_core/config.inc.php.dist
   trunk/plugins/kolab_core/kolab_core.php
   trunk/plugins/kolab_core/rcube_kolab.php
Removed:
   trunk/plugins/kolab_addressbook/config.inc.php.dist
Modified:
   trunk/plugins/kolab_addressbook/kolab_addressbook.php
Log:
Move core Kolab functions to a separate plugin to be used by others too

Deleted: trunk/plugins/kolab_addressbook/config.inc.php.dist
===================================================================
--- trunk/plugins/kolab_addressbook/config.inc.php.dist	2010-11-22 10:10:42 UTC (rev 4246)
+++ trunk/plugins/kolab_addressbook/config.inc.php.dist	2010-11-22 10:18:46 UTC (rev 4247)
@@ -1,8 +0,0 @@
-<?php
-
-// Sample configuration for Kolab LDAP binding used by Kolab_Storage
-$rcmail_config['kolab']['ldap']['basedn'] = 'dc=kolabserver,dc=local';
-$rcmail_config['kolab']['ldap']['phpdn'] = 'cn=nobody,cn=internal,dc=kolabserver,dc=local';
-$rcmail_config['kolab']['ldap']['phppw'] = '<ldap-pwd-goes-here>';
-
-?>

Modified: trunk/plugins/kolab_addressbook/kolab_addressbook.php
===================================================================
--- trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-22 10:10:42 UTC (rev 4246)
+++ trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-22 10:18:46 UTC (rev 4247)
@@ -6,10 +6,7 @@
  * Kolab address book
  * 
  * Sample plugin to add a new address book source with data from Kolab storage
- *
  * This is work-in-progress for the Roundcube+Kolab integration.
- * The library part is to be moved into a separate PEAR package or plugin
- * that this and other Kolab-related plugins will depend on.
  *
  * @author Thomas Bruederli <roundcube at gmail.com>
  * 
@@ -24,17 +21,14 @@
      */
     public function init()
     {
-        // load local config
-        $this->load_config();
+        // load required plugin
+        $this->require_plugin('kolab_core');
         
+        // register hooks
         $this->add_hook('addressbooks_list', array($this, 'address_sources'));
         $this->add_hook('addressbook_get', array($this, 'get_address_book'));
         $this->add_hook('contact_form', array($this, 'contact_form'));
-
-        // extend include path to load bundled Horde classes
-        $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path');
-        set_include_path($include_path);
-
+        
         // extend list of address sources to be used for autocompletion
         $rcmail = rcmail::get_instance();
         if ($rcmail->action == 'autocomplete' || $rcmail->action == 'group-expand') {

Added: trunk/plugins/kolab_core/config.inc.php.dist
===================================================================
--- trunk/plugins/kolab_core/config.inc.php.dist	                        (rev 0)
+++ trunk/plugins/kolab_core/config.inc.php.dist	2010-11-22 10:18:46 UTC (rev 4247)
@@ -0,0 +1,8 @@
+<?php
+
+// Sample configuration for Kolab LDAP binding used by Kolab_Storage
+$rcmail_config['kolab']['ldap']['basedn'] = 'dc=kolabserver,dc=local';
+$rcmail_config['kolab']['ldap']['phpdn'] = 'cn=nobody,cn=internal,dc=kolabserver,dc=local';
+$rcmail_config['kolab']['ldap']['phppw'] = '<ldap-pwd-goes-here>';
+
+?>

Added: trunk/plugins/kolab_core/kolab_core.php
===================================================================
--- trunk/plugins/kolab_core/kolab_core.php	                        (rev 0)
+++ trunk/plugins/kolab_core/kolab_core.php	2010-11-22 10:18:46 UTC (rev 4247)
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Kolab core library
+ * 
+ * Plugin to setup a basic environment for interaction with a Kolab server.
+ * Other Kolab-related plugins will depend on it and can use the static API rcube_core
+ *
+ * This is work-in-progress for the Roundcube+Kolab integration.
+ *
+ * @author Thomas Bruederli <roundcube at gmail.com>
+ * 
+ */
+class kolab_core extends rcube_plugin
+{
+    /**
+     * Required startup method of a Roundcube plugin
+     */
+    public function init()
+    {
+        // load local config
+        $this->load_config();
+        
+        // extend include path to load bundled Horde classes
+        $include_path = $this->home . PATH_SEPARATOR . ini_get('include_path');
+        set_include_path($include_path);
+    }
+    
+}
+


Property changes on: trunk/plugins/kolab_core/kolab_core.php
___________________________________________________________________
Added: svn:keywords
   + Id Date Author Revision
Added: svn:eol-style
   + native

Copied: trunk/plugins/kolab_core/rcube_kolab.php (from rev 4244, trunk/plugins/kolab_addressbook/lib/rcube_kolab.php)
===================================================================
--- trunk/plugins/kolab_core/rcube_kolab.php	                        (rev 0)
+++ trunk/plugins/kolab_core/rcube_kolab.php	2010-11-22 10:18:46 UTC (rev 4247)
@@ -0,0 +1,109 @@
+<?php
+
+require_once 'Horde/Kolab/Storage/List.php';
+require_once 'Horde/Kolab/Format.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);
+        }
+    }
+    
+    
+    /**
+     * Get instance of a Kolab (XML) format object
+     *
+     * @param string Data type (contact,event,task,note)
+     * @return object Horde_Kolab_Format_XML The format object
+     */
+    public static function get_format($type)
+    {
+      self::setup();
+      return Horde_Kolab_Format::factory('XML', $type);
+    }
+
+    /**
+     * Get a list of storage folders for the given data type
+     *
+     * @param string Data type to list folders for (contact,event,task,note)
+     * @return array List of Kolab_Folder objects
+     */
+    public static function get_folders($type)
+    {
+        self::setup();
+        $kolab = Kolab_List::singleton();
+        return $kolab->getByType($type);
+    }
+
+    /**
+     * Get storage object for read/write access to the Kolab backend
+     *
+     * @param string IMAP folder to access
+     * @param string Object type to deal with (leave empty for auto-detection using annotations)
+     * @return object Kolab_Data The data storage object
+     */
+    public static function get_storage($folder, $data_type = null)
+    {
+        self::setup();
+        $kolab = Kolab_List::singleton();
+        return $kolab->getFolder($folder)->getData($data_type);
+    }
+
+    /**
+     * Cleanup session data when done
+     */
+    public static function shutdown()
+    {
+        if (isset($_SESSION['__auth'])) {
+            // unset auth data from session. no need to store it persistantly
+            unset($_SESSION['__auth']);
+            
+            // FIXME: remove strange numeric entries
+            foreach ($_SESSION as $key => $val) {
+                if (!$val && is_numeric($key))
+                    unset($_SESSION[$key]);
+            }
+        }
+    }
+}

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list