core/source/main.php
2025-09-22 23:17:08 +02:00

104 lines
2.8 KiB
PHP

<?php
/*
davina — Calendar data CalDAV conditioner
Copyright (C) 2025 Fenris <fenris@folksprak.org>
This program 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see
<https://www.gnu.org/licenses/>.
*/
namespace davina;
define("DIR_LOGIC", "logic");
require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/base.php');
require_once(DIR_LOGIC . '/conf.php');
require_once(DIR_LOGIC . '/model.php');
require_once(DIR_LOGIC . '/sources/_factory.php');
require_once(DIR_LOGIC . '/auths/_factory.php');
require_once(DIR_LOGIC . '/overwrites/principal_backend.php');
require_once(DIR_LOGIC . '/overwrites/auth_backend.php');
require_once(DIR_LOGIC . '/overwrites/caldav_backend.php');
function main(
) : void
{
\davina\conf\load('conf.dvn.json');
\davina\set_parameters([]);
\date_default_timezone_set(\davina\conf\get()['settings']['timezone']);
/**
* @todo realm names irgendwie wandeln, statt direkt als keys zu verwenden?
*/
$realms = [];
foreach (\davina\conf\get()['realms'] as $realm_raw)
{
$realms[$realm_raw['name']] = new \davina\model\struct_realm(
$realm_raw['name'],
\davina\auths\make(
$realm_raw['auth']['kind'],
$realm_raw['auth']['data']
),
\davina\sources\make(
$realm_raw['source']['kind'],
$realm_raw['source']['data']
)
);
}
$principal_backend = new \davina\overwrites\class_principle_backend($realms);
$server = new \Sabre\DAV\Server(
[
new \Sabre\CalDAV\Principal\Collection(
$principal_backend
),
new \Sabre\CalDAV\CalendarRoot(
$principal_backend,
new \davina\overwrites\class_caldav_backend($realms)
),
]
);
// $server->setBaseUri('/');
$server->addPlugin(
new \Sabre\DAV\Auth\Plugin(
new \davina\overwrites\class_auth_backend(
$realms
)
)
);
/**
* this somehow breaks authentication, but seems to be required for calendar discovery
*/
// $server->addPlugin(new \Sabre\DAVACL\Plugin());
$server->addPlugin(new \Sabre\CalDAV\Plugin());
$server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
$server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\DAV\Sharing\Plugin());
$server->addPlugin(new \Sabre\CalDAV\SharingPlugin());
/**
* not required
*/
// $server->addPlugin(new \Sabre\DAV\Browser\Plugin());
$server->start();
}
main();
?>