Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F256657
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
26 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/config/dav.inc.php.sample b/config/dav.inc.php.sample
index 623f7b4..0c22f32 100644
--- a/config/dav.inc.php.sample
+++ b/config/dav.inc.php.sample
@@ -1,48 +1,52 @@
<?php
/*
+-------------------------------------------------------------------------+
| Configuration for the Kolab DAV server |
| |
| Copyright (C) 2013, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as |
| published by the Free Software Foundation, either version 3 of the |
| License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License|
| along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
+-------------------------------------------------------------------------+
*/
$config = array();
// Log DAV requests to <log_dir>/davdebug
$config['base_uri'] = null;
// User agent string written to kolab storage MIME messages
$config['useragent'] = 'Kolab DAV Server libkolab/' . RCUBE_VERSION;
// Roundcube plugins. Not all are supported here.
$config['kolabdav_plugins'] = array('kolab_auth');
// Type of Auth cache. Supported values: 'db', 'apc' and 'memcache'.
// Note: This is only for username canonification map.
$config['kolabdav_auth_cache'] = 'apc';
// lifetime of the Auth cache, possible units: s, m, h, d, w
$config['kolabdav_auth_cache_ttl'] = '1h';
// enable debug console showing the internal function calls triggered
// by http requests. This will write log to /var/log/iRony/console
$config['kolabdav_console'] = false;
// enable per-user debugging if /var/log/iRony/<username>/ folder exists
$config['kolabdav_user_debug'] = false;
+
+// enable logging of full HTTP payload
+// (bitmask of these values: 2 = HTTP Requests, 4 = HTTP Responses)
+$config['kolabdav_http_log'] = 0;
diff --git a/lib/Kolab/Utils/DAVLogger.php b/lib/Kolab/Utils/DAVLogger.php
index 982d87e..311fc8a 100644
--- a/lib/Kolab/Utils/DAVLogger.php
+++ b/lib/Kolab/Utils/DAVLogger.php
@@ -1,86 +1,191 @@
<?php
/**
* Utility class logging DAV requests
*
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Kolab\Utils;
+use \rcube;
use Sabre\DAV;
+use Kolab\DAV\Auth\HTTPBasic;
/**
* Utility class to log debug information about processed DAV requests
*/
class DAVLogger extends DAV\ServerPlugin
{
+ const CONSOLE = 1;
+ const HTTP_REQUEST = 2;
+ const HTTP_RESPONSE = 4;
+
+ private $rcube;
private $server;
private $method;
+ private $loglevel;
+
+
+ /**
+ * Default constructor
+ */
+ public function __construct($level = 1)
+ {
+ $this->rcube = rcube::get_instance();
+ $this->loglevel = $level;
+ }
/**
* This initializes the plugin.
* This method should set up the required event subscriptions.
*
* @param Server $server
*/
- public function initialize(DAV\Server $server)
- {
- $this->server = $server;
+ public function initialize(DAV\Server $server)
+ {
+ $this->server = $server;
- $server->subscribeEvent('beforeMethod', array($this, '_beforeMethod'));
- $server->subscribeEvent('exception', array($this, '_exception'));
- $server->subscribeEvent('exit', array($this, '_exit'));
+ $server->subscribeEvent('beforeMethod', array($this, '_beforeMethod'), 15);
+ $server->subscribeEvent('exception', array($this, '_exception'));
+ $server->subscribeEvent('exit', array($this, '_exit'));
+
+ // replace $server->httpResponse with a derived class that can do logging
+ $server->httpResponse = new HTTPResponse();
}
- /**
- * Handler for 'beforeMethod' events
- */
- public function _beforeMethod($method, $uri)
- {
- $this->method = $method;
+ /**
+ * Handler for 'beforeMethod' events
+ */
+ public function _beforeMethod($method, $uri)
+ {
+ $this->method = $method;
- // log to console
- console($method . ' ' . $uri);
- }
+ // turn on per-user http logging if the destination file exists
+ if ($this->loglevel < 2 && $this->rcube->config->get('kolabdav_user_debug', false)
+ && ($log_dir = $this->user_log_dir()) && file_exists($log_dir . '/httpraw')) {
+ $this->loglevel |= (self::HTTP_REQUEST | self::HTTP_RESPONSE);
+ }
- /**
- * Handler for 'exception' events
- */
- public function _exception($e)
- {
- // log to console
- console(get_class($e) . ' (EXCEPTION)', $e->getMessage() /*, $e->getTraceAsString()*/);
- }
+ // log full HTTP request data
+ if ($this->loglevel & self::HTTP_REQUEST) {
+ $request = $this->server->httpRequest;
+ $content_type = $request->getHeader('CONTENT_TYPE');
+ if (strpos($content_type, 'text/') === 0) {
+ $http_body = $request->getBody(true);
- /**
- * Handler for 'exit' events
- */
- public function _exit()
- {
- $time = microtime(true) - KOLAB_DAV_START;
+ // Hack for reading php:://input because that stream can only be read once.
+ // This is why we re-populate the request body with the existing data.
+ $request->setBody($http_body);
+ }
+ else if (!empty($content_type)) {
+ $http_body = '[binary data]';
+ }
- if (function_exists('memory_get_usage'))
- $mem = round(memory_get_usage() / 1024) . 'K';
- if (function_exists('memory_get_peak_usage'))
- $mem .= '/' . round(memory_get_peak_usage() / 1024) . 'K';
+ // catch all headers
+ $http_headers = array();
+ foreach (apache_request_headers() as $hdr => $value) {
+ $http_headers[$hdr] = "$hdr: $value";
+ }
- console(sprintf("/%s: %0.4f sec; %s", $this->method, $time, $mem));
- }
+ $this->write_log('httpraw', $request->getMethod() . ' ' . $request->getUri() . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\n" .
+ join("\n", $http_headers) . "\n\n" . $http_body);
+ }
+
+ // log to console
+ if ($this->loglevel & self::CONSOLE) {
+ $this->write_log('console', $method . ' ' . $uri);
+ }
+ }
+
+ /**
+ * Handler for 'exception' events
+ */
+ public function _exception($e)
+ {
+ // log to console
+ $this->console(get_class($e) . ' (EXCEPTION)', $e->getMessage() /*, $e->getTraceAsString()*/);
+ }
+
+ /**
+ * Handler for 'exit' events
+ */
+ public function _exit()
+ {
+ if ($this->loglevel & self::CONSOLE) {
+ $time = microtime(true) - KOLAB_DAV_START;
+
+ if (function_exists('memory_get_usage'))
+ $mem = round(memory_get_usage() / 1024) . 'K';
+ if (function_exists('memory_get_peak_usage'))
+ $mem .= '/' . round(memory_get_peak_usage() / 1024) . 'K';
+
+ $this->write_log('console', sprintf("/%s: %0.4f sec; %s", $this->method, $time, $mem));
+ }
+
+ // log full HTTP reponse
+ if ($this->loglevel & self::HTTP_RESPONSE) {
+ $this->write_log('httpraw', "RESPONSE: " . $this->server->httpResponse->dump());
+ }
+ }
+
+ /**
+ * Wrapper for rcube::cosole() to write per-user logs
+ */
+ public function console(/* ... */)
+ {
+ if ($this->loglevel & self::CONSOLE) {
+ $msg = array();
+ foreach (func_get_args() as $arg) {
+ $msg[] = !is_string($arg) ? var_export($arg, true) : $arg;
+ }
+
+ $this->write_log('console', join(";\n", $msg));
+ }
+ }
+
+ /**
+ * Wrapper for rcube::write_log() that can write per-user logs
+ */
+ public function write_log($filename, $msg)
+ {
+ // dump data per user
+ if ($this->rcube->config->get('kolabdav_user_debug', false)) {
+ if ($this->user_log_dir()) {
+ $filename = HTTPBasic::$current_user . '/' . $filename;
+ }
+ else {
+ return; // don't log
+ }
+ }
+
+ rcube::write_log($filename, $msg);
+ }
+
+ /**
+ * Get the per-user log directory
+ */
+ private function user_log_dir()
+ {
+ $log_dir = $this->rcube->config->get('log_dir', RCUBE_INSTALL_PATH . 'logs');
+ $user_log_dir = $log_dir . '/' . HTTPBasic::$current_user;
+
+ return HTTPBasic::$current_user && is_writable($user_log_dir) ? $user_log_dir : false;
+ }
}
\ No newline at end of file
diff --git a/lib/Kolab/Utils/HTTPResponse.php b/lib/Kolab/Utils/HTTPResponse.php
new file mode 100644
index 0000000..4f4e72d
--- /dev/null
+++ b/lib/Kolab/Utils/HTTPResponse.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Utility class representing a HTTP response with logging capabilities
+ *
+ * @author Thomas Bruederli <bruederli@kolabsys.com>
+ *
+ * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Kolab\Utils;
+
+/**
+ * This class represents a HTTP response.
+ */
+class HTTPResponse extends \Sabre\HTTP\Response
+{
+ private $status;
+ private $body = '';
+ private $headers = array();
+
+ /**
+ * Sends an HTTP status header to the client.
+ *
+ * @param int $code HTTP status code
+ * @return bool
+ */
+ public function sendStatus($code)
+ {
+ $this->status = $this->getStatusMessage($code, $this->defaultHttpVersion);
+ return parent::sendStatus($code);
+ }
+
+ /**
+ * Sets an HTTP header for the response
+ *
+ * @param string $name
+ * @param string $value
+ * @param bool $replace
+ * @return bool
+ */
+ public function setHeader($name, $value, $replace = true) {
+ $this->headers[$name] = $value;
+ return parent::setHeader($name, $value, $replace);
+ }
+
+ /**
+ * Sends the entire response body
+ *
+ * This method can accept either an open filestream, or a string.
+ *
+ * @param mixed $body
+ * @return void
+ */
+ public function sendBody($body)
+ {
+ if (is_resource($body)) {
+ fpassthru($body);
+ $this->body = '[binary data]';
+ }
+ else {
+ echo $body;
+ $this->body .= $body;
+ }
+ }
+
+ /**
+ * Dump the response data for logging
+ */
+ public function dump()
+ {
+ $result_headers = '';
+ foreach ($this->headers as $hdr => $value) {
+ $result_headers .= "\n$hdr: " . $value;
+ }
+
+ return $this->status . $result_headers . "\n\n" . $this->body;
+ }
+}
\ No newline at end of file
diff --git a/public_html/debug.php b/public_html/debug.php
deleted file mode 100644
index 10fcea8..0000000
--- a/public_html/debug.php
+++ /dev/null
@@ -1,173 +0,0 @@
-<?php
-
-/**
- * Kolab WebDAV/CalDAV/CardDAV Debug Pipe
- *
- * @author Thomas Bruederli <bruederli@kolabsys.com>
- *
- * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define some environment variables used throughout the app and libraries
-define('KOLAB_DAV_ROOT', realpath('../'));
-define('KOLAB_DAV_START', microtime(true));
-
-define('RCUBE_INSTALL_PATH', KOLAB_DAV_ROOT . '/');
-define('RCUBE_CONFIG_DIR', KOLAB_DAV_ROOT . '/config/');
-
-ini_set('error_reporting', E_ALL &~ E_NOTICE &~ E_STRICT);
-
-require_once KOLAB_DAV_ROOT . '/vendor/autoload.php';
-require_once KOLAB_DAV_ROOT . '/lib/Roundcube/bootstrap.php';
-
-// Roundcube framework initialization
-$rcube = rcube::get_instance();
-$rcube->config->load_from_file(RCUBE_CONFIG_DIR . 'dav.inc.php');
-
-$base_uri = $rcube->config->get('base_uri', slashify(substr(dirname($_SERVER['SCRIPT_FILENAME']), strlen($_SERVER['DOCUMENT_ROOT']))));
-
-// quick & dirty request debugging
-$http_headers = array();
-foreach (apache_request_headers() as $hdr => $value) {
- if ($hdr == 'Destination')
- $value = str_replace($base_uri, $base_uri . 'index.php/', $value);
- $http_headers[$hdr] = "$hdr: $value";
-}
-// read HTTP request body
-$in = fopen('php://input', 'r');
-$http_body = stream_get_contents($in);
-fclose($in);
-
-$rcube->write_log('davdebug', $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\n" .
- join("\n", $http_headers) . "\n\n" . $http_body);
-
-// fix URIs in request body
-$http_body = preg_replace("!(<\w+:href[^>]*>$base_uri)!i", '\\1index.php/', $http_body);
-$http_headers['Content-Length'] = "Content-Length: " . strlen($http_body);
-
-// forward the full request to index.php
-$rel_url = substr($_SERVER['REQUEST_URI'], strlen($base_uri));
-$host = $_SERVER['HTTP_HOST'];
-$port = 80;
-$path = $base_uri . 'index.php/' . $rel_url;
-
-// remove Host: header
-unset($http_headers['Host']);
-$response_headers = array();
-
-// re-send using curl
-$ch = curl_init();
-curl_setopt($ch, CURLOPT_URL, "http://$host:$port$path");
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
-curl_setopt($ch, CURLOPT_POSTFIELDS, $http_body);
-curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($http_headers));
-curl_setopt($ch, CURLOPT_HEADER, 0);
-curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) use (&$response_headers){
- list($key, $val) = explode(": ", rtrim($header), 2);
- if (!empty($val)) $response_headers[$key] = $val;
- return strlen($header);
-});
-
-$result = str_replace('index.php/', '', curl_exec($ch));
-$info = curl_getinfo($ch);
-
-// send recieved HTTP status code
-$result_headers = $_SERVER['SERVER_PROTOCOL'] . " " . $info['http_code'] . " " . http_response_phrase($info['http_code']);
-header($result_headers, true);
-
-// forward response headers
-unset($response_headers['Transfer-Encoding']);
-foreach ($response_headers as $hdr => $value) {
- $value = str_replace('index.php/', '', $value);
- $result_headers .= "\n$hdr: " . $value;
- header("$hdr: " . $value, true);
-}
-
-// log response
-$rcube->write_log('davdebug', "RESPONSE:\n" . $result_headers . "\n\n" . (strpos($info['content_type'], 'image/') === false ? $result : ''));
-
-// send response body back to client
-echo $result;
-
-
-/**
- * Derived from HTTP_Request2_Response::getDefaultReasonPhrase()
- */
-function http_response_phrase($code)
-{
- static $phrases = array(
-
- // 1xx: Informational - Request received, continuing process
- 100 => 'Continue',
- 101 => 'Switching Protocols',
-
- // 2xx: Success - The action was successfully received, understood and
- // accepted
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
- 207 => 'Multi-Status',
-
- // 3xx: Redirection - Further action must be taken in order to complete
- // the request
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found', // 1.1
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
-
- // 4xx: Client Error - The request contains bad syntax or cannot be
- // fulfilled
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
-
- // 5xx: Server Error - The server failed to fulfill an apparently
- // valid request
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported',
- 509 => 'Bandwidth Limit Exceeded',
- );
-
- return $phrases[$code];
-}
-
diff --git a/public_html/index.php b/public_html/index.php
index a87b403..89631d4 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -1,196 +1,188 @@
<?php
/**
* iRony, the Kolab WebDAV/CalDAV/CardDAV Server
*
* This is the public API to provide *DAV-based access to the Kolab Groupware backend
*
* @version 0.3-dev
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// define some environment variables used throughout the app and libraries
define('KOLAB_DAV_ROOT', realpath('../'));
define('KOLAB_DAV_VERSION', '0.3-dev');
define('KOLAB_DAV_START', microtime(true));
define('RCUBE_INSTALL_PATH', KOLAB_DAV_ROOT . '/');
define('RCUBE_CONFIG_DIR', KOLAB_DAV_ROOT . '/config/');
define('RCUBE_PLUGINS_DIR', KOLAB_DAV_ROOT . '/lib/plugins/');
// suppress error notices
ini_set('error_reporting', E_ALL &~ E_NOTICE &~ E_STRICT);
/**
* Mapping PHP errors to exceptions.
*
* While this is not strictly needed, it makes a lot of sense to do so. If an
* E_NOTICE or anything appears in your code, this allows SabreDAV to intercept
* the issue and send a proper response back to the client (HTTP/1.1 500).
*/
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
//set_error_handler("exception_error_handler");
// use composer's autoloader for dependencies
$loader = require_once(KOLAB_DAV_ROOT . '/vendor/autoload.php');
$loader->setUseIncludePath(true); // enable include_path to load PEAR classes from their default location
// load the Roundcube framework with its autoloader
require_once KOLAB_DAV_ROOT . '/lib/Roundcube/bootstrap.php';
// Roundcube framework initialization
$rcube = rcube::get_instance(rcube::INIT_WITH_DB | rcube::INIT_WITH_PLUGINS);
$rcube->config->load_from_file(RCUBE_CONFIG_DIR . 'dav.inc.php');
// Load plugins
$plugins = (array)$rcube->config->get('kolabdav_plugins', array('kolab_auth'));
$required = array('libkolab', 'libcalendaring');
$rcube->plugins->init($rcube);
$rcube->plugins->load_plugins($plugins, $required);
+// enable logger
+if ($rcube->config->get('kolabdav_console') || $rcube->config->get('kolabdav_user_debug')) {
+ $logger = new \Kolab\Utils\DAVLogger((\Kolab\Utils\DAVLogger::CONSOLE | $rcube->config->get('kolabdav_http_log', 0)));
+}
// convenience function, you know it well :-)
function console()
{
- global $rcube;
+ global $rcube, $logger;
// write to global console log
if ($rcube->config->get('kolabdav_console', false)) {
call_user_func_array(array('rcube', 'console'), func_get_args());
}
-
- // dump console data per user
- if ($rcube->config->get('kolabdav_user_debug', false)) {
- $uname = \Kolab\DAV\Auth\HTTPBasic::$current_user;
- $log_dir = $rcube->config->get('log_dir', RCUBE_INSTALL_PATH . 'logs');
-
- if ($uname && $log_dir && is_writable($log_dir . '/' . $uname)) {
- $msg = array();
- foreach (func_get_args() as $arg) {
- $msg[] = !is_string($arg) ? var_export($arg, true) : $arg;
- }
-
- rcube::write_log($uname . '/console', join(";\n", $msg));
- }
+ else if ($logger) {
+ call_user_func_array(array($logger, 'console'), func_get_args());
}
}
// Make sure this setting is turned on and reflects the root url of the *DAV server.
$base_uri = $rcube->config->get('base_uri', slashify(substr(dirname($_SERVER['SCRIPT_FILENAME']), strlen($_SERVER['DOCUMENT_ROOT']))));
// add filename to base URI when called without mod_rewrite (e.g. /dav/index.php/calendar)
if (strpos($_SERVER['REQUEST_URI'], 'index.php'))
$base_uri .= 'index.php/';
// create the various backend instances
$auth_backend = new \Kolab\DAV\Auth\HTTPBasic();
$principal_backend = new \Kolab\DAVACL\PrincipalBackend();
$services = array();
foreach (array('CALDAV','CARDDAV','WEBDAV') as $skey) {
if (getenv($skey))
$services[$skey] = 1;
}
// no config means *all* services
if (empty($services))
$services = array('CALDAV' => 1, 'CARDDAV' => 1, 'WEBDAV' => 1);
// add chwala directories to include path for autoloading
if ($services['WEBDAV']) {
$include_path = ini_get('include_path') . PATH_SEPARATOR;
$include_path .= KOLAB_DAV_ROOT . '/lib/FileAPI' . PATH_SEPARATOR;
$include_path .= KOLAB_DAV_ROOT . '/lib/FileAPI/kolab' . PATH_SEPARATOR;
$include_path .= KOLAB_DAV_ROOT . '/lib/FileAPI/ext';
set_include_path($include_path);
}
// Build the directory tree
// This is an array which contains the 'top-level' directories in the WebDAV server.
if ($services['CALDAV'] || $services['CARDDAV']) {
$nodes = array(
new \Sabre\CalDAV\Principal\Collection($principal_backend),
);
if ($services['CALDAV']) {
$caldav_backend = new \Kolab\CalDAV\CalendarBackend();
$caldav_backend->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$nodes[] = new \Kolab\CalDAV\CalendarRootNode($principal_backend, $caldav_backend);
}
if ($services['CARDDAV']) {
$carddav_backend = new \Kolab\CardDAV\ContactsBackend();
$carddav_backend->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$nodes[] = new \Kolab\CardDAV\AddressBookRoot($principal_backend, $carddav_backend);
}
if ($services['WEBDAV']) {
$nodes[] = new \Kolab\DAV\Collection(\Kolab\DAV\Collection::ROOT_DIRECTORY);
}
}
// register WebDAV service as root
else if ($services['WEBDAV']) {
$nodes = new \Kolab\DAV\Collection('');
}
// the object tree needs in turn to be passed to the server class
$server = new \Sabre\DAV\Server($nodes);
$server->setBaseUri($base_uri);
-// enable logger
-if ($rcube->config->get('kolabdav_console') || $rcube->config->get('kolabdav_user_debug')) {
- $server->addPlugin(new \Kolab\Utils\DAVLogger());
+// connect logger
+if (is_object($logger)) {
+ $server->addPlugin($logger);
}
// register some plugins
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($auth_backend, 'KolabDAV'));
$server->addPlugin(new \Sabre\DAVACL\Plugin());
if ($services['CALDAV']) {
$caldav_plugin = new \Kolab\CalDAV\Plugin();
$caldav_plugin->setIMipHandler(new \Kolab\CalDAV\IMip());
$server->addPlugin($caldav_plugin);
}
if ($services['CARDDAV']) {
$server->addPlugin(new \Kolab\CardDAV\Plugin());
}
if ($services['WEBDAV']) {
// the lock manager is reponsible for making sure users don't overwrite each others changes.
// TODO: replace this with a class that manages locks in the Kolab backend
$locks_backend = new \Kolab\DAV\Locks\File(KOLAB_DAV_ROOT . '/temp');
$server->addPlugin(new \Sabre\DAV\Locks\Plugin($locks_backend));
// intercept some of the garbage files operation systems tend to generate when mounting a WebDAV share
$server->addPlugin(new \Kolab\DAV\TempFilesPlugin(KOLAB_DAV_ROOT . '/temp'));
}
// HTML UI for browser-based access (recommended only for development)
if (getenv('DAVBROWSER')) {
$server->addPlugin(new \Sabre\DAV\Browser\Plugin());
}
// finally, process the request
$server->exec();
// trigger log
$server->broadcastEvent('exit', array());
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jun 9, 1:23 AM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
196730
Default Alt Text
(26 KB)
Attached To
Mode
R5 irony
Attached
Detach File
Event Timeline
Log In to Comment