From 1d271b4c55ae04fee314c28a798b88ceb6572d1a Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 5 Mar 2009 16:02:49 +0100 Subject: [PATCH] Fix passing HTTP auth for remote calendars through Kronolith::listEvents(). Use higher timout value for remote calendars if retrieving events through ajax, since events are being updated asynchronously. --- kronolith/ajax.php | 3 +++ kronolith/lib/Driver.php | 11 ++++++++++ kronolith/lib/Kronolith.php | 53 +++++++++++++++++++++++++++------------------ 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index 078d2d322..d50c95640 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -59,6 +59,9 @@ case 'ListEvents': $cal = Util::getFormData('cal'); list($driver, $calendar) = explode('|', $cal); $kronolith_driver = Kronolith::getDriver($driver, $calendar); + if ($driver == 'Ical') { + $kronolith_driver->setParam('timeout', 15); + } $events = $kronolith_driver->listEvents($start, $end, true, false, true); if (is_a($events, 'PEAR_Error')) { $notification->push($events, 'horde.error'); diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index a00e8a05e..21bae88d5 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -65,6 +65,17 @@ class Kronolith_Driver return isset($this->_params[$param]) ? $this->_params[$param] : null; } + /** + * Sets a configuration for this driver. + * + * @param string $param A parameter name. + * @param mixed $value The parameter value. + */ + public function setParam($param, $value) + { + $this->_params[$param] = $value; + } + public function open($calendar) { $this->_calendar = $calendar; diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 3c4506b40..0ccc83d14 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -610,6 +610,9 @@ class Kronolith $driver = Kronolith::getDriver('Ical'); foreach ($GLOBALS['display_remote_calendars'] as $url) { $driver->open($url); + foreach (Kronolith::getRemoteParams($url) as $param => $value) { + $driver->setParam($param, $value); + } $events = $driver->listEvents($startDate, $endDate, true); if (!is_a($events, 'PEAR_Error')) { Kronolith::mergeEvents($results, $events); @@ -1943,27 +1946,7 @@ class Kronolith if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) { $params['proxy'] = $GLOBALS['conf']['http']['proxy']; } - - /* Check for HTTP authentication credentials */ - $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - foreach ($cals as $cal) { - if ($cal['url'] == $calendar) { - $user = isset($cal['user']) ? $cal['user'] : ''; - $password = isset($cal['password']) ? $cal['password'] : ''; - $key = Auth::getCredential('password'); - if ($key && $user) { - require_once 'Horde/Secret.php'; - $user = Secret::read($key, base64_decode($user)); - $password = Secret::read($key, base64_decode($password)); - } - if (!empty($user)) { - $params['user'] = $user; - $params['password'] = $password; - } - break; - } - } - + $params = Kronolith::getRemoteParams($calendar); break; case 'Horde': @@ -1986,6 +1969,34 @@ class Kronolith } /** + * Check for HTTP authentication credentials + */ + public static function getRemoteParams($calendar) + { + if (empty($calendar)) { + return array(); + } + + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + foreach ($cals as $cal) { + if ($cal['url'] == $calendar) { + $user = isset($cal['user']) ? $cal['user'] : ''; + $password = isset($cal['password']) ? $cal['password'] : ''; + $key = Auth::getCredential('password'); + if ($key && $user) { + $user = Horde_Secret::read($key, base64_decode($user)); + $password = Horde_Secret::read($key, base64_decode($password)); + } + if (!empty($user)) { + return array('user' => $user, 'password' => $password); + } + } + } + + return array(); + } + + /** * Get a named Kronolith_View_* object and load it with the * appropriate date parameters. * -- 2.11.0