Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2528966
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
19 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/Kolab/CalDAV/Principal/Collection.php b/lib/Kolab/CalDAV/Principal/Collection.php
new file mode 100644
index 0000000..52e0b14
--- /dev/null
+++ b/lib/Kolab/CalDAV/Principal/Collection.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * SabreDAV Principal Collection derived class for the Kolab service.
+ *
+ * @author Thomas Bruederli <bruederli@kolabsys.com>
+ *
+ * Copyright (C) 2014, 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\CalDAV\Principal;
+
+class Collection extends \Sabre\CalDAV\Principal\Collection
+{
+ /**
+ * Returns a child object based on principal information
+ *
+ * @param array $principalInfo
+ * @return User
+ */
+ public function getChildForPrincipal(array $principalInfo)
+ {
+ return new User($this->principalBackend, $principalInfo);
+ }
+}
\ No newline at end of file
diff --git a/lib/Kolab/CalDAV/Principal/User.php b/lib/Kolab/CalDAV/Principal/User.php
new file mode 100644
index 0000000..aa8a247
--- /dev/null
+++ b/lib/Kolab/CalDAV/Principal/User.php
@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * SabreDAV Principal User derived class for the Kolab service.
+ *
+ * @author Thomas Bruederli <bruederli@kolabsys.com>
+ *
+ * Copyright (C) 2014, 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\CalDAV\Principal;
+
+class User extends \Sabre\CalDAV\Principal\User
+{
+ /**
+ * Returns a list of ACE's for this node.
+ *
+ * Adds {DAV:}read for {DAV:}authenticated to enable access to
+ * principal records which are listed as owner of shared folders.
+ *
+ * @return array
+ */
+ public function getACL()
+ {
+ $acl = parent::getACL();
+ $acl[] = array(
+ 'privilege' => '{DAV:}read',
+ 'principal' => '{DAV:}authenticated',
+ 'protected' => true,
+ );
+ return $acl;
+ }
+}
\ No newline at end of file
diff --git a/lib/Kolab/DAVACL/PrincipalBackend.php b/lib/Kolab/DAVACL/PrincipalBackend.php
index bf19c44..908aca3 100644
--- a/lib/Kolab/DAVACL/PrincipalBackend.php
+++ b/lib/Kolab/DAVACL/PrincipalBackend.php
@@ -1,245 +1,255 @@
<?php
/**
* SabreDAV Principals Backend implementation for Kolab.
*
* @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\DAVACL;
use \rcube;
use Sabre\DAV\Exception;
use Sabre\DAV\URLUtil;
use Kolab\DAV\Auth\HTTPBasic;
/**
* Kolab Principal Backend
*/
class PrincipalBackend implements \Sabre\DAVACL\PrincipalBackend\BackendInterface
{
/**
* Sets up the backend.
*/
public function __construct()
{
}
/**
* Returns a pricipal record for the currently authenticated user
*/
public function getCurrentUser()
{
// console(__METHOD__, HTTPBasic::$current_user);
if (HTTPBasic::$current_user) {
$user_email = rcube::get_instance()->get_user_email();
return array(
'uri' => 'principals/' . HTTPBasic::$current_user,
'{DAV:}displayname' => HTTPBasic::$current_user,
'{http://sabredav.org/ns}email-address' => $user_email,
'{http://calendarserver.org/ns/}email-address-set' => $user_email,
);
}
return false;
}
/**
* Returns a list of principals based on a prefix.
*
* This prefix will often contain something like 'principals'. You are only
* expected to return principals that are in this base path.
*
* You are expected to return at least a 'uri' for every user, you can
* return any additional properties if you wish so. Common properties are:
* {DAV:}displayname
* {http://sabredav.org/ns}email-address - This is a custom SabreDAV
* field that's actualy injected in a number of other properties. If
* you have an email address, use this property.
*
* @param string $prefixPath
* @return array
*/
public function getPrincipalsByPrefix($prefixPath)
{
console(__METHOD__, $prefixPath);
$principals = array();
if ($prefixPath == 'principals') {
// TODO: list users from LDAP
// we currently only advertise the authenticated user
if ($user = $this->getCurrentUser()) {
$principals[] = $user;
}
}
return $principals;
}
/**
* Returns a specific principal, specified by it's path.
* The returned structure should be the exact same as from
* getPrincipalsByPrefix.
*
* @param string $path
* @return array
*/
public function getPrincipalByPath($path)
{
// console(__METHOD__, $path);
list($prefix,$name) = explode('/', $path);
if ($prefix == 'principals' && $name == HTTPBasic::$current_user) {
return $this->getCurrentUser();
}
+ else if ($prefix == 'principals' && \rcube_utils::check_email($name, false)) {
+ // TODO: do a user lookup in LDAP
+ list($localname,$domain) = explode('@', $name);
+ return array(
+ 'uri' => $path,
+ '{DAV:}displayname' => $localname,
+ '{http://sabredav.org/ns}email-address' => $name,
+ '{http://calendarserver.org/ns/}email-address-set' => $name,
+ );
+ }
return null;
}
/**
* Returns the list of members for a group-principal
*
* @param string $principal
* @return array
*/
public function getGroupMemberSet($principal)
{
// TODO: for now the group principal has only one member, the user itself
list($prefix, $name) = URLUtil::splitPath($principal);
$principal = $this->getPrincipalByPath($prefix);
if (!$principal) throw new Exception('Principal not found');
return array(
$prefix
);
}
/**
* Returns the list of groups a principal is a member of
*
* @param string $principal
* @return array
*/
public function getGroupMembership($principal)
{
list($prefix,$name) = URLUtil::splitPath($principal);
$group_membership = array();
if ($prefix == 'principals') {
$principal = $this->getPrincipalByPath($principal);
if (!$principal) throw new Exception('Principal not found');
// TODO: implement full calendar delegation (with information from LDAP kolabDelegate)
return array(
// Calendar delegation is not supported by our backend
//'principals/'.$name.'/calendar-proxy-read',
//'principals/'.$name.'/calendar-proxy-write',
// The addressbook groups are not supported in Sabre,
// see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753
//'principals/'.$name.'/addressbook-proxy-read',
//'principals/'.$name.'/addressbook-proxy-write',
);
}
return $group_membership;
}
/**
* Updates the list of group members for a group principal.
*
* The principals should be passed as a list of uri's.
*
* @param string $principal
* @param array $members
* @return void
*/
public function setGroupMemberSet($principal, array $members)
{
throw new Exception('Setting members of the group is not supported yet');
}
function updatePrincipal($path, $mutations)
{
return 0;
}
/**
* This method is used to search for principals matching a set of
* properties.
*
* This search is specifically used by RFC3744's principal-property-search
* REPORT. You should at least allow searching on
* http://sabredav.org/ns}email-address.
*
* The actual search should be a unicode-non-case-sensitive search. The
* keys in searchProperties are the WebDAV property names, while the values
* are the property values to search on.
*
* If multiple properties are being searched on, the search should be
* AND'ed.
*
* This method should simply return an array with full principal uri's.
*
* If somebody attempted to search on a property the backend does not
* support, you should simply return 0 results.
*
* @param string $prefixPath
* @param array $searchProperties
* @return array
*/
function searchPrincipals($prefixPath, array $searchProperties)
{
console(__METHOD__, $prefixPath, $searchProperties);
$email = null;
$results = array();
$current_user = $this->getCurrentUser();
foreach($searchProperties as $property => $value) {
// check search property against the current user
if ($current_user[$property] == $value) {
$results[] = $current_user['uri'];
continue;
}
switch($property) {
case '{http://sabredav.org/ns}email-address':
$email = $value;
break;
case '{DAV:}displayname':
default :
// Unsupported property
return array();
}
}
// we only support search by email
if (!empty($email)) {
// TODO: search via LDAP
}
return array_unique($results);
}
}
diff --git a/public_html/index.php b/public_html/index.php
index c7e55ee..04e7f53 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -1,197 +1,197 @@
<?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-2014, 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->set('Kolab', array(KOLAB_DAV_ROOT . '/lib')); // register iRony namespace(s)
$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 $logger;
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),
+ new \Kolab\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);
// 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 responsible for making sure users don't overwrite each others changes.
$locks_backend = new \Kolab\DAV\Locks\Chwala(\Kolab\DAV\Collection::ROOT_DIRECTORY);
$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());
}
// log exceptions in iRony error log
$server->subscribeEvent('exception', function($e){
if (!($e instanceof \Sabre\DAV\Exception) || $e->getHTTPCode() == 500) {
rcube::raise_error(array(
'code' => 500,
'type' => 'php',
'file' => $e->getFile(),
'line' => $e->getLine(),
'message' => $e->getMessage() . " (error 500)\n" . $e->getTraceAsString(),
), true, false);
}
});
// finally, process the request
$server->exec();
// trigger log
$server->broadcastEvent('exit', array());
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Feb 2, 4:19 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426807
Default Alt Text
(19 KB)
Attached To
Mode
R5 irony
Attached
Detach File
Event Timeline
Log In to Comment