core/source/main.php

104 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2025-09-09 12:07:53 +02:00
<?php
2025-09-22 23:17:08 +02:00
/*
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/>.
*/
2025-09-09 12:07:53 +02:00
2025-09-16 12:05:35 +02:00
namespace davina;
2025-09-09 12:07:53 +02:00
2025-09-16 12:48:45 +02:00
define("DIR_LOGIC", "logic");
2025-09-09 12:07:53 +02:00
require_once('vendor/autoload.php');
2025-09-16 12:48:45 +02:00
require_once(DIR_LOGIC . '/base.php');
2025-09-22 23:17:08 +02:00
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');
2025-09-16 12:48:45 +02:00
require_once(DIR_LOGIC . '/overwrites/principal_backend.php');
2025-09-21 18:49:03 +02:00
require_once(DIR_LOGIC . '/overwrites/auth_backend.php');
2025-09-16 12:48:45 +02:00
require_once(DIR_LOGIC . '/overwrites/caldav_backend.php');
2025-09-09 12:07:53 +02:00
function main(
) : void
{
2025-09-22 20:08:05 +02:00
\davina\conf\load('conf.dvn.json');
2025-09-09 12:07:53 +02:00
2025-09-16 12:05:35 +02:00
\davina\set_parameters([]);
2025-09-10 15:03:44 +02:00
2025-09-21 18:49:03 +02:00
\date_default_timezone_set(\davina\conf\get()['settings']['timezone']);
2025-09-09 12:07:53 +02:00
2025-09-21 13:27:37 +02:00
/**
2025-09-22 23:17:08 +02:00
* @todo realm names irgendwie wandeln, statt direkt als keys zu verwenden?
2025-09-21 13:27:37 +02:00
*/
2025-09-21 18:49:03 +02:00
$realms = [];
foreach (\davina\conf\get()['realms'] as $realm_raw)
2025-09-21 13:27:37 +02:00
{
2025-09-21 18:49:03 +02:00
$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']
)
2025-09-21 13:27:37 +02:00
);
}
2025-09-09 12:07:53 +02:00
2025-09-21 18:49:03 +02:00
$principal_backend = new \davina\overwrites\class_principle_backend($realms);
2025-09-09 12:07:53 +02:00
$server = new \Sabre\DAV\Server(
[
2025-09-21 13:27:37 +02:00
new \Sabre\CalDAV\Principal\Collection(
$principal_backend
),
new \Sabre\CalDAV\CalendarRoot(
$principal_backend,
2025-09-21 18:49:03 +02:00
new \davina\overwrites\class_caldav_backend($realms)
2025-09-21 13:27:37 +02:00
),
2025-09-09 12:07:53 +02:00
]
);
// $server->setBaseUri('/');
$server->addPlugin(
new \Sabre\DAV\Auth\Plugin(
2025-09-21 18:49:03 +02:00
new \davina\overwrites\class_auth_backend(
$realms
2025-09-09 12:07:53 +02:00
)
)
);
/**
2025-09-09 19:43:23 +02:00
* this somehow breaks authentication, but seems to be required for calendar discovery
2025-09-09 12:07:53 +02:00
*/
2025-09-10 15:03:44 +02:00
// $server->addPlugin(new \Sabre\DAVACL\Plugin());
2025-09-09 12:07:53 +02:00
$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
*/
2025-09-21 18:49:03 +02:00
// $server->addPlugin(new \Sabre\DAV\Browser\Plugin());
2025-09-10 15:03:44 +02:00
2025-09-09 12:07:53 +02:00
$server->start();
}
main();
?>