Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a new unified DAV endpoint #440

Merged
merged 2 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions Core/Frameworks/Baikal/Core/Server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
#################################################################
# Copyright notice
#
# (c) 2013 Jérôme Schneider <mail@jeromeschneider.fr>
# All rights reserved
#
# http://baikal-server.com
#
# This script is part of the Baïkal Server project. The Baïkal
# Server project is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# The GNU General Public License can be found at
# http://www.gnu.org/copyleft/gpl.html.
#
# This script 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 General Public License for more details.
#
# This copyright notice MUST APPEAR in all copies of the script!
#################################################################

namespace Baikal\Core;

use PDO;

/**
* The Baikal Server
*
* This class sets up the underlying Sabre\DAV\Server object.
*
* @copyright Copyright (C) Jérôme Schneider <mail@jeromeschneider.fr>
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ GPLv2
*/
class Server {

/**
* Is CalDAV enabled?
*
* @var bool
*/
protected $enableCalDAV;

/**
* is CardDAV enabled?
*
* @var bool
*/
protected $enableCardDAV;

/**
* "Basic" or "Digest"
*
* @var string
*/
protected $authType;

/**
* HTTP authentication realm
*
* @var string
*/
protected $authRealm;

/**
* Reference to Database object
*
* @var PDO
*/
protected $pdo;

/**
* baseUri for the sabre/dav server
*
* @var string
*/
protected $baseUri;

/**
* The sabre/dav Server object
*
* @var \Sabre\DAV\Server
*/
protected $server;


/**
* Creates the server object.
*
* @param bool $enableCalDAV
* @param bool $enableCardDAV
* @param string $authType
* @param string $authRealm
* @param PDO $pdo
* @param string $baseUri
*/
function __construct($enableCalDAV, $enableCardDAV, $authType, $authRealm, PDO $pdo, $baseUri) {

$this->enableCalDAV = $enableCalDAV;
$this->enableCardDAV = $enableCardDAV;
$this->authType = $authType;
$this->authRealm = $authRealm;
$this->pdo = $pdo;
$this->baseUri = $baseUri;

$this->initServer();

}

/**
* Starts processing
*
* @return void
*/
function start() {

$this->server->exec();

}

/**
* Initializes the server object
*
* @return void
*/
protected function initServer() {

if ($this->authType === 'Basic') {
$authBackend = new \Baikal\Core\PDOBasicAuth($this->pdo, $this->authRealm);
} else {
$authBackend = new \Sabre\DAV\Auth\Backend\PDO($this->pdo, $this->authRealm);
}
$principalBackend = new \Sabre\DAVACL\PrincipalBackend\PDO($this->pdo);

$nodes = [
new \Sabre\CalDAV\Principal\Collection($principalBackend)
];
if ($this->enableCalDAV) {
$calendarBackend = new \Sabre\CalDAV\Backend\PDO($this->pdo);
$nodes[] = new \Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend);
}
if ($this->enableCardDAV) {
$carddavBackend = new \Sabre\CardDAV\Backend\PDO($GLOBALS["DB"]->getPDO());
$nodes[] = new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend);
}

$this->server = new \Sabre\DAV\Server($nodes);
$this->server->setBaseUri($this->baseUri);

$this->server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $this->authRealm));
$this->server->addPlugin(new \Sabre\DAVACL\Plugin());
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());

if ($this->enableCalDAV) {
$this->server->addPlugin(new \Sabre\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
}
if ($this->enableCardDAV) {
$this->server->addPlugin(new \Sabre\CardDAV\Plugin());
$this->server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
}

}

}
20 changes: 19 additions & 1 deletion Core/Frameworks/Baikal/Model/Config/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class System extends \Baikal\Model\Config {
"type" => "litteral",
"comment" => 'Should begin and end with a "/"',
),
"BAIKAL_DAV_BASEURI" => array(
"type" => "litteral",
"comment" => 'Should begin and end with a "/"',
),
"PROJECT_SQLITE_FILE" => array(
"type" => "litteral",
"comment" => "Define path to Baïkal Database SQLite file",
Expand Down Expand Up @@ -85,6 +89,7 @@ class System extends \Baikal\Model\Config {
"BAIKAL_AUTH_REALM" => "BaikalDAV",
"BAIKAL_CARD_BASEURI" => 'PROJECT_BASEURI . "card.php/"',
"BAIKAL_CAL_BASEURI" => 'PROJECT_BASEURI . "cal.php/"',
"BAIKAL_DAV_BASEURI" => 'PROJECT_BASEURI . "dav.php/"',
"PROJECT_SQLITE_FILE" => 'PROJECT_PATH_SPECIFIC . "db/db.sqlite"',
"PROJECT_DB_MYSQL" => FALSE,
"PROJECT_DB_MYSQL_HOST" => "",
Expand Down Expand Up @@ -119,6 +124,16 @@ public function formMorphologyForThisModelInstance() {
"content" => "If Baïkal is hosted in a subfolder, this path should reflect it.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>"
)
)));
$oMorpho->add(new \Formal\Element\Text(array(
"prop" => "BAIKAL_DAV_BASEURI",
"label" => "CalDAV/CardDAV base URI",
"validation" => "required",
"help" => "The absolute web path to dav.php",
"popover" => array(
"title" => "DAV base URI",
"content" => "If Baïkal is hosted in a subfolder, this path should reflect it.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>"
)
)));

$oMorpho->add(new \Formal\Element\Text(array(
"prop" => "BAIKAL_AUTH_REALM",
Expand Down Expand Up @@ -213,6 +228,9 @@ protected static function getDefaultConfig() {
# Should begin and end with a "/"
define("BAIKAL_CAL_BASEURI", PROJECT_BASEURI . "cal.php/");

# Should begin and end with a "/"
define("BAIKAL_DAV_BASEURI", PROJECT_BASEURI . "dav.php/");

# Define path to Baïkal Database SQLite file
define("PROJECT_SQLITE_FILE", PROJECT_PATH_SPECIFIC . "db/db.sqlite");

Expand Down Expand Up @@ -241,4 +259,4 @@ protected static function getDefaultConfig() {
$sCode = trim($sCode);
return $sCode;
}
}
}
87 changes: 0 additions & 87 deletions Core/Frameworks/Baikal/WWWRoot/card.php

This file was deleted.

1 change: 0 additions & 1 deletion html/cal.php

This file was deleted.

65 changes: 65 additions & 0 deletions html/cal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2013 Jérôme Schneider <mail@jeromeschneider.fr>
* All rights reserved
*
* http://baikal-server.com
*
* This script is part of the Baïkal Server project. The Baïkal
* Server project is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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 General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

ini_set("session.cookie_httponly", 1);
ini_set("display_errors", 0);
ini_set("log_errors", 1);

define("BAIKAL_CONTEXT", TRUE);
define("PROJECT_CONTEXT_BASEURI", "/");

if(file_exists(getcwd() . "/Core")) {
# Flat FTP mode
define("PROJECT_PATH_ROOT", getcwd() . "/"); #./
} else {
# Dedicated server mode
define("PROJECT_PATH_ROOT", dirname(getcwd()) . "/"); #../
}

if(!file_exists(PROJECT_PATH_ROOT . 'vendor/')) {
die('<h1>Incomplete installation</h1><p>Ba&iuml;kal dependencies have not been installed. Please, execute "<strong>composer install</strong>" in the folder where you installed Ba&iuml;kal.');
}

require PROJECT_PATH_ROOT . 'vendor/autoload.php';

# Bootstraping Flake
\Flake\Framework::bootstrap();
# Bootstrapping Baïkal
\Baikal\Framework::bootstrap();

if(!defined("BAIKAL_CAL_ENABLED") || BAIKAL_CAL_ENABLED !== TRUE) {
throw new ErrorException("Baikal CalDAV is disabled.", 0, 255, __FILE__, __LINE__);
}

$server = new \Baikal\Core\Server(
BAIKAL_CAL_ENABLED,
BAIKAL_CARD_ENABLED,
BAIKAL_DAV_AUTH_TYPE,
BAIKAL_AUTH_REALM,
$GLOBALS['DB']->getPDO(),
BAIKAL_CAL_BASEURI
);
$server->start();
1 change: 0 additions & 1 deletion html/card.php

This file was deleted.

Loading