Initial work
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 07:27:02 +0000 (00:27 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 25 Dec 2009 12:44:50 +0000 (05:44 -0700)
15 files changed:
gollem/clipboard.php
gollem/edit.php
gollem/lib/Api.php
gollem/lib/Application.php
gollem/lib/Auth.php
gollem/lib/Gollem.php
gollem/lib/Session.php [deleted file]
gollem/lib/base.load.php [deleted file]
gollem/lib/base.php [deleted file]
gollem/manager.php
gollem/permissions.php
gollem/quota.php
gollem/selectlist.php
gollem/test.php
gollem/view.php

index 3a884aa..060a3ba 100644 (file)
@@ -11,7 +11,8 @@
  * @package Gollem
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new Gollem_Application(array('init' => true));
 
 $dir = Horde_Util::getFormData('dir');
 
index 26ea1e8..9f630ea 100644 (file)
@@ -11,7 +11,8 @@
  * @package Gollem
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new Gollem_Application(array('init' => true));
 
 $actionID = Horde_Util::getFormData('actionID');
 $driver = Horde_Util::getFormData('driver');
index ea0e53d..842bcf7 100644 (file)
@@ -26,11 +26,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function browse($path = '', $properties = array())
     {
-        $GLOBALS['gollem_authentication'] = 'none';
-        require_once dirname(__FILE__) . '/base.php';
-        require GOLLEM_BASE . '/config/backends.php';
-        require GOLLEM_BASE . '/config/credentials.php';
-
         $path = Gollem::stripAPIPath($path);
 
         // Default properties.
@@ -148,14 +143,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function put($path, $content, $content_type)
     {
-        // Gollem does not handle authentication
-        $GLOBALS['gollem_authentication'] = 'none';
-
-        // Include Gollem base libraries
-        require_once dirname(__FILE__) . '/base.php';
-        require GOLLEM_BASE . '/config/backends.php';
-        require GOLLEM_BASE . '/config/credentials.php';
-
         // Clean off the irrelevant portions of the path
         $path = Gollem::stripAPIPath($path);
 
@@ -207,14 +194,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function mkcol($path)
     {
-        // Gollem does not handle authentication
-        $GLOBALS['gollem_authentication'] = 'none';
-
-        // Include Gollem base libraries
-        require_once dirname(__FILE__) . '/base.php';
-        require GOLLEM_BASE . '/config/backends.php';
-        require GOLLEM_BASE . '/config/credentials.php';
-
         // Clean off the irrelevant portions of the path
         $path = Gollem::stripAPIPath($path);
 
@@ -268,14 +247,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function move($path, $dest)
     {
-        // Gollem does not handle authentication
-        $GLOBALS['gollem_authentication'] = 'none';
-
-        // Include Gollem base libraries
-        require_once dirname(__FILE__) . '/base.php';
-        require GOLLEM_BASE . '/config/backends.php';
-        require GOLLEM_BASE . '/config/credentials.php';
-
         // Clean off the irrelevant portions of the path
         $path = Gollem::stripAPIPath($path);
         $dest = Gollem::stripAPIPath($dest);
@@ -342,14 +313,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function path_delete($path)
     {
-        // Gollem does not handle authentication
-        $GLOBALS['gollem_authentication'] = 'none';
-
-        // Include Gollem base libraries
-        require_once dirname(__FILE__) . '/base.php';
-        require GOLLEM_BASE . '/config/backends.php';
-        require GOLLEM_BASE . '/config/credentials.php';
-
         // Clean off the irrelevant portions of the path
         $path = Gollem::stripAPIPath($path);
 
@@ -410,8 +373,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function getViewLink($dir, $file, $backend = '')
     {
-        require_once dirname(__FILE__) . '/base.php';
-
         if (empty($backend)) {
             $backend = Gollem::getPreferredBackend();
         }
@@ -453,7 +414,7 @@ class Gollem_Api extends Horde_Registry_Api
      * @return string  The URL string.
      */
     public function selectlistLink($link_text, $link_style, $formid,
-        $icon = false, $selectid = '')
+                                   $icon = false, $selectid = '')
     {
         $link = Horde::link('#', $link_text, $link_style, '_blank', Horde::popupJs(Horde::applicationUrl('selectlist.php'), array('params' => array('formid' => $formid, 'cacheid' => $selectid), 'height' => 500, 'width' => 300, 'urlencode' => true)) . 'return false;');
         if ($icon) {
@@ -475,14 +436,15 @@ class Gollem_Api extends Horde_Registry_Api
     {
         if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'])) {
             return null;
-        } else {
-            $list = array();
-            foreach ($_SESSION['gollem']['selectlist'][$selectid]['files'] as $val) {
-                list($dir, $filename) = explode('|', $val);
-                $list[] = array($dir => $filename);
-            }
-            return $list;
         }
+
+        $list = array();
+        foreach ($_SESSION['gollem']['selectlist'][$selectid]['files'] as $val) {
+            list($dir, $filename) = explode('|', $val);
+            $list[] = array($dir => $filename);
+        }
+
+        return $list;
     }
 
     /**
@@ -495,8 +457,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function returnFromSelectlist($selectid, $index)
     {
-        require_once dirname(__FILE__) . '/base.php';
-
         if (!isset($_SESSION['gollem']['selectlist'][$selectid]['files'][$index])) {
             return null;
         }
@@ -517,8 +477,6 @@ class Gollem_Api extends Horde_Registry_Api
      */
     public function setSelectlist($selectid = '', $files = array())
     {
-        require_once dirname(__FILE__) . '/base.php';
-
         if (empty($selectid)) {
             $selectid = uniqid(mt_rand(), true);
         }
index 7d0f7b3..02d0565 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/* Determine the base directories. */
+if (!defined('GOLLEM_BASE')) {
+    define('GOLLEM_BASE', dirname(__FILE__) . '/..');
+}
+
+if (!defined('HORDE_BASE')) {
+    /* If Horde does not live directly under the app directory, the HORDE_BASE
+     * constant should be defined in config/horde.local.php. */
+    if (file_exists(GOLLEM_BASE . '/config/horde.local.php')) {
+        include GOLLEM_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', GOLLEM_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ *  Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
 /**
  * Gollem application API.
  *
@@ -20,6 +39,108 @@ class Gollem_Application extends Horde_Registry_Application
     public $version = 'H4 (2.0-git)';
 
     /**
+     * The auth type to use.
+     *
+     * @var string
+     */
+    static public $authType = null;
+
+    /**
+     * Disable compression of pages?
+     *
+     * @var boolean
+     */
+    static public $noCompress = false;
+
+    /**
+     * Constructor.
+
+     * @param array $args  The following entries:
+     * <pre>
+     * 'init' - (boolean|array) If true, perform application init. If an
+     *          array, perform application init and pass the array to init().
+     * </pre>
+     */
+    public function __construct($args = array())
+    {
+        if (!empty($args['init'])) {
+            $this->init(is_array($args['init']) ? $args['init'] : array());
+        }
+    }
+
+    /**
+     * Gollem base initialization.
+     *
+     * Global variables defined:
+     *   $gollem_backends - A link to the current list of available backends
+     *   $gollem_be - A link to the current backend parameters in the session
+     *   $gollem_vfs - A link to the current VFS object for the active backend
+     *
+     * @param array $args  Optional arguments:
+     * <pre>
+     * 'authentication' - (string) The type of authentication to use:
+     *   'horde' - Only use horde authentication
+     *   'none'  - Do not authenticate
+     *   [DEFAULT] - Authenticate to backend; on no auth redirect to
+     *               login screen
+     * 'nocompress' - (boolean) Controls whether the page should be
+     *                compressed.
+     * 'session_control' - (string) Sets special session control limitations:
+     *   'readonly' - Start session readonly
+     *   [DEFAULT] - Start read/write session
+     * </pre>
+     */
+    public function init($args = array())
+    {
+        $args = array_merge(array(
+            'authentication' => null,
+            'nocompress' => false,
+            'session_control' => null
+        ), $args);
+
+        self::$authType = $args['authentication'];
+        self::$noCompress = $args['nocompress'];
+
+        // Registry.
+        $s_ctrl = 0;
+        switch ($args['session_control']) {
+        case 'readonly':
+            $s_ctrl = Horde_Registry::SESSION_READONLY;
+            break;
+        }
+
+        $GLOBALS['registry'] = Horde_Registry::singleton($s_ctrl);
+
+        try {
+            $GLOBALS['registry']->pushApp('gollem', array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => true));
+        } catch (Horde_Exception $e) {
+            Horde_Auth::authenticateFailure('gollem', $e);
+        }
+
+        if (!defined('GOLLEM_TEMPLATES')) {
+            define('GOLLEM_TEMPLATES', $GLOBALS['registry']->get('templates'));
+        }
+
+        // Notification system.
+        $notification = Horde_Notification::singleton();
+        $notification->attach('status');
+
+        // Start compression.
+        if (!self::$noCompress) {
+            Horde::compressOutput();
+        }
+
+        // Set the global $gollem_be variable to the current backend's
+        // parameters.
+        $GLOBALS['gollem_be'] = empty($_SESSION['gollem']['backend_key'])
+            ? null
+            : $_SESSION['gollem']['backends'][$_SESSION['gollem']['backend_key']];
+
+        // Load the backend list.
+        Gollem::loadBackendList();
+    }
+
+    /**
      * Returns a list of available permissions.
      *
      * @return array  An array describing all available permissions.
index 9444be8..595d8df 100644 (file)
@@ -102,4 +102,236 @@ class Gollem_Auth
         }
     }
 
+    /**
+     * Check Gollem authentication and change to the currently active
+     * directory. Redirects to login page on authentication/session failure.
+     *
+     * @param string $mode       The authentication mode we are using.
+     * @param boolean $redirect  Redirect to the logout page if authentication
+     *                           is unsuccessful?
+     *
+     * @return boolean  True on success, false on failure.
+     */
+    static public function checkAuthentication($mode = null, $redirect = true)
+    {
+        $auth_gollem = new Gollem_Auth();
+        $reason = $auth_gollem->authenticate();
+
+        if ($reason !== true) {
+            if ($redirect) {
+                if ($mode = 'selectlist') {
+                    $url = Horde_Util::addParameter($GLOBALS['registry']->get('webroot', 'gollem') . '/login.php', 'selectlist_login', 1, false);
+                } else {
+                    $url = Horde_Auth::addLogoutParameters(self::logoutUrl());
+                }
+                $url = Horde_Util::addParameter($url, 'url', Horde::selfUrl(true, true, true), false);
+                header('Location: ' . $url);
+                exit;
+            } else {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Can we log in without a login screen for the requested backend key?
+     *
+     * @param string $key     The backend key to check. Defaults to
+     *                        self::getPreferredBackend().
+     * @param boolean $force  If true, check the backend key even if there is
+     *                        more than one backend.
+     *
+     * @return boolean  True if autologin possible, false if not.
+     */
+    static public function canAutoLogin($key = null, $force = false)
+    {
+        $auto_server = self::getPreferredBackend();
+        if ($key === null) {
+            $key = $auto_server;
+        }
+
+        return (((count($auto_server) == 1) || $force) &&
+                Horde_Auth::getAuth() &&
+                empty($GLOBALS['gollem_backends'][$key]['loginparams']) &&
+                !empty($GLOBALS['gollem_backends'][$key]['hordeauth']));
+    }
+
+    /**
+     * Take information posted from a login attempt and try setting up
+     * an initial Gollem session. Handle Horde authentication, if
+     * required, and only do enough work to see if the user can log
+     * in. This function should only be called once, when the user first logs
+     * into Gollem.
+     *
+     * Creates the $gollem session variable with the following entries:
+     * 'backend_key' --  The current backend
+     * 'be_list'     --  The cached list of available backends
+     * 'selectlist'  --  Stores file selections from the API call
+     *
+     * Each backend is stored by its name in the 'backends' array.  Each
+     * backend contains the following entries:
+     * 'attributes'  --  See config/backends.php
+     * 'autologin'   --  Whether this backend supports autologin
+     * 'clipboard'   --  The clipboard for the current backend
+     * 'createhome'  --  See config/backends.php
+     * 'dir'         --  The current directory
+     * 'driver'      --  See config/backends.php
+     * 'filter'      --  See config/backends.php
+     * 'home'        --  The user's home directory
+     * 'hordeauth'   --  See config/backends.php
+     * 'hostspec'    --  See config/backends.php
+     * 'label'       --  The label to use
+     * 'name'        --  See config/backends.php
+     * 'params'      --  See config/backends.php
+     * 'preferred'   --  See config/backends.php
+     * 'root'        --  The root directory
+     *
+     * @param string $key   The backend key to initialize.
+     * @param string $user  The username to use for authentication.
+     * @param string $pass  The password to use for authentication.
+     * @param array $args   Any additional parameters the backend needs.
+     *
+     * @return boolean  True on success, false on failure.
+     */
+    function createSession($key, $user = null, $pass = null, $args = array())
+    {
+        global $conf;
+
+        /* Make sure we have a key and that it is valid. */
+        if (empty($key) || (substr($key, 0, 1) == '_')) {
+            return false;
+        }
+
+        /* We might need to override some of the defaults with
+         * environment-wide settings. Do NOT use the global $backends
+         * variable as it may not exist. */
+        require GOLLEM_BASE . '/config/backends.php';
+        if (empty($backends[$key])) {
+            $entry = sprintf('Invalid server key from client [%s]', $_SERVER['REMOTE_ADDR']);
+            Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO);
+            return false;
+        }
+
+        /* Create gollem session object if it doesn't already exist. */
+        if (!isset($_SESSION['gollem'])) {
+            $_SESSION['gollem'] = array();
+            $_SESSION['gollem']['backends'] = array();
+            $_SESSION['gollem']['selectlist'] = array();
+        }
+        $_SESSION['gollem']['backends'][$key] = $backends[$key];
+        $GLOBALS['gollem_be'] = &$_SESSION['gollem']['backends'][$key];
+        $ptr = &$_SESSION['gollem']['backends'][$key];
+        $ptr['params'] = array_merge($ptr['params'], $args);
+
+        /* Set the current backend as active. */
+        $_SESSION['gollem']['backend_key'] = $key;
+
+        /* Set username now. Don't set the current username if the backend
+         * already has a username defined. */
+        if (empty($ptr['params']['username'])) {
+            $ptr['params']['username'] = ($user === null) ? Horde_Auth::getBareAuth() : $user;
+        }
+
+        /* Set password now. The password should always be encrypted within
+         * the session. */
+        if (!empty($ptr['params']['password'])) {
+            $pass = $ptr['params']['password'];
+        }
+        if ($pass === null) {
+            $ptr['params']['password'] = null;
+        } else {
+            $ptr['params']['password'] = Horde_Secret::write(Horde_Secret::getKey('gollem'), $pass);
+        }
+
+        /* Try to authenticate with the given information. */
+        $auth_gollem = new Gollem_Auth();
+        if ($auth_gollem->authenticate(null, null, true) !== true) {
+            unset($_SESSION['gollem']['backends'][$key]);
+            $_SESSION['gollem']['backend_key'] = null;
+            return false;
+        }
+
+        // Make sure we have a 'root' parameter.
+        if (empty($ptr['root'])) {
+            $ptr['root'] = '/';
+        }
+        $ptr['root'] = Horde_Util::realPath($ptr['root']);
+
+        // Make sure we have a 'home' parameter.
+        if (empty($ptr['home'])) {
+            $ptr['home'] = (!empty($ptr['params']['home'])) ? $ptr['params']['home'] : $GLOBALS['gollem_vfs']->getCurrentDirectory();
+            if (empty($ptr['home'])) {
+                $ptr['home'] = $ptr['root'];
+            }
+        }
+
+        // Make sure the home parameter lives under root if it is a relative
+        // directory.
+        if (strpos($ptr['home'], '/') !== 0) {
+            $ptr['home'] = $ptr['root'] . '/' . $ptr['home'];
+        }
+        $ptr['home'] = Horde_Util::realPath($ptr['home']);
+        $ptr['dir'] = $ptr['home'];
+
+        // Verify that home is below root.
+        if (!Gollem::verifyDir($ptr['home'])) {
+            $error_msg = 'Backend Configuration Error: Home directory not below root.';
+            $auth_gollem->gollemSetAuthErrorMsg($error_msg);
+            Horde::logMessage(PEAR::raiseError($error_msg), __FILE__, __LINE__, PEAR_LOG_ERR);
+            unset($_SESSION['gollem']['backends'][$key]);
+            $_SESSION['gollem']['backend_key'] = null;
+            return false;
+        }
+
+        /* Create the home directory if it doesn't already exist. */
+        if (($ptr['home'] != '/') && !empty($ptr['createhome'])) {
+            $pos = strrpos($ptr['home'], '/');
+            $cr_dir = substr($ptr['home'], 0, $pos);
+            $cr_file = substr($ptr['home'], $pos + 1);
+            if (!$GLOBALS['gollem_vfs']->exists($cr_dir, $cr_file)) {
+                $res = Gollem::createFolder($cr_dir, $cr_file);
+                if (is_a($res, 'PEAR_Error')) {
+                    $error_msg = 'Backend Configuration Error: Could not create home directory ' . $ptr['home'] . '.';
+                    $auth_gollem->gollemSetAuthErrorMsg($error_msg);
+                    Horde::logMessage(PEAR::raiseError($error_msg), __FILE__, __LINE__, PEAR_LOG_ERR);
+                    unset($_SESSION['gollem']['backends'][$key]);
+                    $_SESSION['gollem']['backend_key'] = null;
+                    return false;
+                }
+            }
+        }
+
+        /* Does this driver support autologin? */
+        $ptr['autologin'] = Gollem::canAutoLogin(true);
+
+        /* Cache the backend_list in the session. */
+        if (empty($_SESSION['gollem']['be_list'])) {
+            Gollem::loadBackendList();
+            $_SESSION['gollem']['be_list'] = $GLOBALS['gollem_backends'];
+        }
+
+        /* Initialize clipboard. */
+        if (!isset($_SESSION['gollem']['clipboard'])) {
+            $_SESSION['gollem']['clipboard'] = array();
+        }
+
+        /* Call Gollem::changeDir() to make sure the label is set. */
+        Gollem::changeDir();
+
+        return true;
+    }
+
+    /**
+     * Change the currently active backend.
+     *
+     * @param string $key  The ID of the backend to set as active.
+     */
+    function changeBackend($key)
+    {
+        $_SESSION['gollem']['backend_key'] = $key;
+        $GLOBALS['gollem_be'] = &$_SESSION['gollem']['backends'][$key];
+    }
+
 }
index 14272fe..ebe4acd 100644 (file)
@@ -24,62 +24,6 @@ class Gollem
     const SORT_DESCEND = 1;
 
     /**
-     * Check Gollem authentication and change to the currently active
-     * directory. Redirects to login page on authentication/session failure.
-     *
-     * @param string $mode       The authentication mode we are using.
-     * @param boolean $redirect  Redirect to the logout page if authentication
-     *                           is unsuccessful?
-     *
-     * @return boolean  True on success, false on failure.
-     */
-    static public function checkAuthentication($mode = null, $redirect = true)
-    {
-        $auth_gollem = new Gollem_Auth();
-        $reason = $auth_gollem->authenticate();
-
-        if ($reason !== true) {
-            if ($redirect) {
-                if ($mode = 'selectlist') {
-                    $url = Horde_Util::addParameter($GLOBALS['registry']->get('webroot', 'gollem') . '/login.php', 'selectlist_login', 1, false);
-                } else {
-                    $url = Horde_Auth::addLogoutParameters(self::logoutUrl());
-                }
-                $url = Horde_Util::addParameter($url, 'url', Horde::selfUrl(true, true, true), false);
-                header('Location: ' . $url);
-                exit;
-            } else {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Can we log in without a login screen for the requested backend key?
-     *
-     * @param string $key     The backend key to check. Defaults to
-     *                        self::getPreferredBackend().
-     * @param boolean $force  If true, check the backend key even if there is
-     *                        more than one backend.
-     *
-     * @return boolean  True if autologin possible, false if not.
-     */
-    static public function canAutoLogin($key = null, $force = false)
-    {
-        $auto_server = self::getPreferredBackend();
-        if ($key === null) {
-            $key = $auto_server;
-        }
-
-        return (((count($auto_server) == 1) || $force) &&
-                Horde_Auth::getAuth() &&
-                empty($GLOBALS['gollem_backends'][$key]['loginparams']) &&
-                !empty($GLOBALS['gollem_backends'][$key]['hordeauth']));
-    }
-
-    /**
      * Changes the current directory of the Gollem session to the supplied
      * value.
      *
diff --git a/gollem/lib/Session.php b/gollem/lib/Session.php
deleted file mode 100644 (file)
index aff7a04..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-<?php
-/**
- * Functions required to start a Gollem session.
- *
- * Copyright 1999-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @author  Max Kalika <max@horde.org>
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Gollem
- */
-class Gollem_Session {
-
-    /**
-     * Take information posted from a login attempt and try setting up
-     * an initial Gollem session. Handle Horde authentication, if
-     * required, and only do enough work to see if the user can log
-     * in. This function should only be called once, when the user first logs
-     * into Gollem.
-     *
-     * Creates the $gollem session variable with the following entries:
-     * 'backend_key' --  The current backend
-     * 'be_list'     --  The cached list of available backends
-     * 'selectlist'  --  Stores file selections from the API call
-     *
-     * Each backend is stored by its name in the 'backends' array.  Each
-     * backend contains the following entries:
-     * 'attributes'  --  See config/backends.php
-     * 'autologin'   --  Whether this backend supports autologin
-     * 'clipboard'   --  The clipboard for the current backend
-     * 'createhome'  --  See config/backends.php
-     * 'dir'         --  The current directory
-     * 'driver'      --  See config/backends.php
-     * 'filter'      --  See config/backends.php
-     * 'home'        --  The user's home directory
-     * 'hordeauth'   --  See config/backends.php
-     * 'hostspec'    --  See config/backends.php
-     * 'label'       --  The label to use
-     * 'name'        --  See config/backends.php
-     * 'params'      --  See config/backends.php
-     * 'preferred'   --  See config/backends.php
-     * 'root'        --  The root directory
-     *
-     * @param string $key   The backend key to initialize.
-     * @param string $user  The username to use for authentication.
-     * @param string $pass  The password to use for authentication.
-     * @param array $args   Any additional parameters the backend needs.
-     *
-     * @return boolean  True on success, false on failure.
-     */
-    function createSession($key, $user = null, $pass = null, $args = array())
-    {
-        global $conf;
-
-        /* Make sure we have a key and that it is valid. */
-        if (empty($key) || (substr($key, 0, 1) == '_')) {
-            return false;
-        }
-
-        /* We might need to override some of the defaults with
-         * environment-wide settings. Do NOT use the global $backends
-         * variable as it may not exist. */
-        require GOLLEM_BASE . '/config/backends.php';
-        if (empty($backends[$key])) {
-            $entry = sprintf('Invalid server key from client [%s]', $_SERVER['REMOTE_ADDR']);
-            Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO);
-            return false;
-        }
-
-        /* Create gollem session object if it doesn't already exist. */
-        if (!isset($_SESSION['gollem'])) {
-            $_SESSION['gollem'] = array();
-            $_SESSION['gollem']['backends'] = array();
-            $_SESSION['gollem']['selectlist'] = array();
-        }
-        $_SESSION['gollem']['backends'][$key] = $backends[$key];
-        $GLOBALS['gollem_be'] = &$_SESSION['gollem']['backends'][$key];
-        $ptr = &$_SESSION['gollem']['backends'][$key];
-        $ptr['params'] = array_merge($ptr['params'], $args);
-
-        /* Set the current backend as active. */
-        $_SESSION['gollem']['backend_key'] = $key;
-
-        /* Set username now. Don't set the current username if the backend
-         * already has a username defined. */
-        if (empty($ptr['params']['username'])) {
-            $ptr['params']['username'] = ($user === null) ? Horde_Auth::getBareAuth() : $user;
-        }
-
-        /* Set password now. The password should always be encrypted within
-         * the session. */
-        if (!empty($ptr['params']['password'])) {
-            $pass = $ptr['params']['password'];
-        }
-        if ($pass === null) {
-            $ptr['params']['password'] = null;
-        } else {
-            $ptr['params']['password'] = Horde_Secret::write(Horde_Secret::getKey('gollem'), $pass);
-        }
-
-        /* Try to authenticate with the given information. */
-        $auth_gollem = new Gollem_Auth();
-        if ($auth_gollem->authenticate(null, null, true) !== true) {
-            unset($_SESSION['gollem']['backends'][$key]);
-            $_SESSION['gollem']['backend_key'] = null;
-            return false;
-        }
-
-        // Make sure we have a 'root' parameter.
-        if (empty($ptr['root'])) {
-            $ptr['root'] = '/';
-        }
-        $ptr['root'] = Horde_Util::realPath($ptr['root']);
-
-        // Make sure we have a 'home' parameter.
-        if (empty($ptr['home'])) {
-            $ptr['home'] = (!empty($ptr['params']['home'])) ? $ptr['params']['home'] : $GLOBALS['gollem_vfs']->getCurrentDirectory();
-            if (empty($ptr['home'])) {
-                $ptr['home'] = $ptr['root'];
-            }
-        }
-
-        // Make sure the home parameter lives under root if it is a relative
-        // directory.
-        if (strpos($ptr['home'], '/') !== 0) {
-            $ptr['home'] = $ptr['root'] . '/' . $ptr['home'];
-        }
-        $ptr['home'] = Horde_Util::realPath($ptr['home']);
-        $ptr['dir'] = $ptr['home'];
-
-        // Verify that home is below root.
-        if (!Gollem::verifyDir($ptr['home'])) {
-            $error_msg = 'Backend Configuration Error: Home directory not below root.';
-            $auth_gollem->gollemSetAuthErrorMsg($error_msg);
-            Horde::logMessage(PEAR::raiseError($error_msg), __FILE__, __LINE__, PEAR_LOG_ERR);
-            unset($_SESSION['gollem']['backends'][$key]);
-            $_SESSION['gollem']['backend_key'] = null;
-            return false;
-        }
-
-        /* Create the home directory if it doesn't already exist. */
-        if (($ptr['home'] != '/') && !empty($ptr['createhome'])) {
-            $pos = strrpos($ptr['home'], '/');
-            $cr_dir = substr($ptr['home'], 0, $pos);
-            $cr_file = substr($ptr['home'], $pos + 1);
-            if (!$GLOBALS['gollem_vfs']->exists($cr_dir, $cr_file)) {
-                $res = Gollem::createFolder($cr_dir, $cr_file);
-                if (is_a($res, 'PEAR_Error')) {
-                    $error_msg = 'Backend Configuration Error: Could not create home directory ' . $ptr['home'] . '.';
-                    $auth_gollem->gollemSetAuthErrorMsg($error_msg);
-                    Horde::logMessage(PEAR::raiseError($error_msg), __FILE__, __LINE__, PEAR_LOG_ERR);
-                    unset($_SESSION['gollem']['backends'][$key]);
-                    $_SESSION['gollem']['backend_key'] = null;
-                    return false;
-                }
-            }
-        }
-
-        /* Does this driver support autologin? */
-        $ptr['autologin'] = Gollem::canAutoLogin(true);
-
-        /* Cache the backend_list in the session. */
-        if (empty($_SESSION['gollem']['be_list'])) {
-            Gollem::loadBackendList();
-            $_SESSION['gollem']['be_list'] = $GLOBALS['gollem_backends'];
-        }
-
-        /* Initialize clipboard. */
-        if (!isset($_SESSION['gollem']['clipboard'])) {
-            $_SESSION['gollem']['clipboard'] = array();
-        }
-
-        /* Call Gollem::changeDir() to make sure the label is set. */
-        Gollem::changeDir();
-
-        return true;
-    }
-
-    /**
-     * Change the currently active backend.
-     *
-     * @param string $key  The ID of the backend to set as active.
-     */
-    function changeBackend($key)
-    {
-        $_SESSION['gollem']['backend_key'] = $key;
-        $GLOBALS['gollem_be'] = &$_SESSION['gollem']['backends'][$key];
-    }
-
-}
diff --git a/gollem/lib/base.load.php b/gollem/lib/base.load.php
deleted file mode 100644 (file)
index d6fcbe5..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * Script to determine the correct *_BASE values.
- *
- * Copyright 2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Gollem
- */
-
-if (!defined('GOLLEM_BASE')) {
-    define('GOLLEM_BASE', dirname(__FILE__) . '/..');
-}
-
-if (!defined('HORDE_BASE')) {
-    /* If horde does not live directly under the app directory, the HORDE_BASE
-     * constant should be defined in lib/horde.local.php. */
-    if (file_exists(GOLLEM_BASE . '/config/horde.local.php')) {
-        include GOLLEM_BASE . '/config/horde.local.php';
-    } else {
-        define('HORDE_BASE', GOLLEM_BASE . '/..');
-    }
-}
diff --git a/gollem/lib/base.php b/gollem/lib/base.php
deleted file mode 100644 (file)
index b5a4e68..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * Gollem base inclusion file. This file brings in all of the
- * dependencies that every Gollem script will need, and sets up
- * objects that all scripts use.
- *
- * The following variables, defined in the script that calls this one, are
- * used:
- *   $gollem_authentication   - The authentication mode to use.
- *   $gollem_session_control  - Sets special session control limitations.
- *
- * This file creates the following global variables:
- *   $gollem_backends - A link to the current list of available backends
- *   $gollem_be - A link to the current backend parameters in the session
- *   $gollem_vfs - A link to the current VFS object for the active backend
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- */
-
-// Determine BASE directories.
-require_once dirname(__FILE__) . '/base.load.php';
-
-// Load the Horde Framework core, and set up inclusion paths.
-require_once HORDE_BASE . '/lib/core.php';
-
-// Registry.
-if (Horde_Util::nonInputVar('gollem_session_control') == 'readonly') {
-    $registry = Horde_Registry::singleton(Horde_Registry::SESSION_READONLY);
-} else {
-    $registry = Horde_Registry::singleton();
-}
-
-try {
-    $registry->pushApp('gollem', array('check_perms' => (Horde_Util::nonInputVar('gollem_authentication') != 'none'), 'logintasks' => true));
-} catch (Horde_Exception $e) {
-    Horde_Auth::authenticateFailure('gollem', $e);
-}
-$conf = &$GLOBALS['conf'];
-define('GOLLEM_TEMPLATES', $registry->get('templates'));
-
-// Notification system.
-$notification = Horde_Notification::singleton();
-$notification->attach('status');
-
-// Start compression.
-Horde::compressOutput();
-
-// Set the global $gollem_be variable to the current backend's parameters.
-if (empty($_SESSION['gollem']['backend_key'])) {
-    $GLOBALS['gollem_be'] = null;
-} else {
-    $GLOBALS['gollem_be'] = &$_SESSION['gollem']['backends'][$_SESSION['gollem']['backend_key']];
-}
-
-// Load the backend list.
-Gollem::loadBackendList();
index de8986d..8b0de72 100644 (file)
@@ -13,7 +13,8 @@
  * @package Gollem
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new Gollem_Application(array('init' => true));
 
 $actionID = Horde_Util::getFormData('actionID');
 $backkey = $_SESSION['gollem']['backend_key'];
index 8166455..3a9cd12 100644 (file)
@@ -8,7 +8,8 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new Gollem_Application(array('init' => true));
 
 if (!Horde_Auth::isAdmin()) {
     Horde::authenticationFailureRedirect('gollem');
index 00b1afa..12e6732 100644 (file)
@@ -10,7 +10,8 @@
  * @author Michael Slusarz <slusarz@horde.org>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new Gollem_Application(array('init' => true));
 
 /* Is this a popup window? */
 $isPopup = $browser->hasFeature('javascript');
index a0430c9..21915b7 100644 (file)
@@ -8,8 +8,8 @@
  * @author Michael Slusarz <slusarz@horde.org>
  */
 
-$gollem_authentication = 'selectlist';
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new IMP_Application(array('init' => array('authentication' => 'selectlist'));
 
 /* Set directory. */
 if (is_a($result = Gollem::changeDir(), 'PEAR_Error')) {
index 40a6202..371496b 100644 (file)
@@ -11,8 +11,7 @@
  */
 
 /* Include Horde's core.php file. */
-require_once dirname(__FILE__) . '/lib/base.load.php';
-require_once '../lib/core.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
 
 /* We should have loaded the String class, from the Horde_Util
    package, in core.php. If Horde_String:: isn't defined, then we're not
@@ -33,7 +32,6 @@ $horde_test = new Horde_Test();
 
 /* Gollem version. */
 $module = 'Gollem';
-require_once dirname(__FILE__) . '/lib/Application.php';
 $app = new Gollem_Application();
 $module_version = $app->version;
 
index 86aa6c6..a3e0bc4 100644 (file)
@@ -11,8 +11,8 @@
  * @author Chuck Hagenbuch <chuck@horde.org>
  */
 
-$gollem_session_control = 'readonly';
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+new IMP_Application(array('init' => array('session_control' => 'readonly'));
 
 $actionID = Horde_Util::getFormData('actionID');
 $driver = Horde_Util::getFormData('driver');