Compare commits
No commits in common. "93abd2dfd8cfe30aabe8b04212a0398fb2af2160" and "64c887275a424f6153e6c1181bcd0df252f461a2" have entirely different histories.
93abd2dfd8
...
64c887275a
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\auths;
|
|
||||||
|
|
||||||
require_once(DIR_LOGIC . '/auths/_interface.php');
|
|
||||||
require_once(DIR_LOGIC . '/auths/pass_through.php');
|
|
||||||
require_once(DIR_LOGIC . '/auths/static.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
function make(
|
|
||||||
string $kind,
|
|
||||||
$data
|
|
||||||
) : \davina\auths\interface_auth
|
|
||||||
{
|
|
||||||
switch ($kind)
|
|
||||||
{
|
|
||||||
case 'pass_through':
|
|
||||||
{
|
|
||||||
return (new \davina\auths\class_auth_pass_through(
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'static':
|
|
||||||
{
|
|
||||||
return (new \davina\auths\class_auth_static(
|
|
||||||
$data['password']
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw (new \Exception(\sprintf('unhandled auth kind: %s', $kind)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\auths;
|
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
interface interface_auth
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $credentials {
|
|
||||||
* record<
|
|
||||||
* username:(null|string),
|
|
||||||
* password:string
|
|
||||||
* >
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
function check(
|
|
||||||
array $credentials
|
|
||||||
) : bool
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $credentials {
|
|
||||||
* record<
|
|
||||||
* username:(null|string),
|
|
||||||
* password:string
|
|
||||||
* >
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
function determine_parameters(
|
|
||||||
array $credentials
|
|
||||||
) : array
|
|
||||||
;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\auths;
|
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
class class_auth_pass_through implements interface_auth
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [implementation]
|
|
||||||
*/
|
|
||||||
function check(
|
|
||||||
array $credentials
|
|
||||||
) : bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [implementation]
|
|
||||||
*/
|
|
||||||
function determine_parameters(
|
|
||||||
array $credentials
|
|
||||||
) : array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'auth_username' => $credentials['username'],
|
|
||||||
'auth_password' => $credentials['password'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\auths;
|
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
class class_auth_static implements interface_auth
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private string $password;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
string $password
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->password = $password;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [implementation]
|
|
||||||
*/
|
|
||||||
function check(
|
|
||||||
array $credentials
|
|
||||||
) : bool
|
|
||||||
{
|
|
||||||
return ($credentials['password'] === $this->password);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [implementation]
|
|
||||||
*/
|
|
||||||
function determine_parameters(
|
|
||||||
array $credentials
|
|
||||||
) : array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
159
source/conf.php
159
source/conf.php
|
|
@ -2,26 +2,58 @@
|
||||||
|
|
||||||
namespace davina\conf;
|
namespace davina\conf;
|
||||||
|
|
||||||
require_once(DIR_LOGIC . '/helpers/list.php');
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class struct_auth
|
||||||
|
{
|
||||||
|
public string $kind;
|
||||||
|
public $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class struct_source_data_ics_feed
|
||||||
|
{
|
||||||
|
public string $url;
|
||||||
|
public bool $combined;
|
||||||
|
public int $lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class struct_source
|
||||||
|
{
|
||||||
|
public string $kind;
|
||||||
|
public $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class struct_settings
|
||||||
|
{
|
||||||
|
public string $timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class struct_root
|
||||||
|
{
|
||||||
|
public struct_auth $auth;
|
||||||
|
public struct_source $source;
|
||||||
|
public struct_settings $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
class _state
|
class _state
|
||||||
{
|
{
|
||||||
public static $data = null;
|
public static ?struct_root $data = null;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
function validate_realm_name(
|
|
||||||
string $realm_name
|
|
||||||
) : string
|
|
||||||
{
|
|
||||||
$matchs = null;
|
|
||||||
$result = preg_match('/^[0-9a-zA-Z]+$/', $realm_name, $matches);
|
|
||||||
return ($result === 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,86 +69,37 @@ function load(
|
||||||
),
|
),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
_state::$data = [
|
{
|
||||||
/**
|
$data = new struct_root();
|
||||||
* @todo check for name duplicates
|
// auth
|
||||||
*/
|
{
|
||||||
'realms' => \davina\helpers\list_\map(
|
$auth = new struct_auth();
|
||||||
$data_raw['realms'],
|
$auth->kind = (($data_raw['auth'] ?? [])['kind'] ?? 'none');
|
||||||
function ($realm_raw) {
|
$auth->data = (($data_raw['auth'] ?? [])['data'] ?? null);
|
||||||
if (! validate_realm_name($realm_raw['name']))
|
$data->auth = $auth;
|
||||||
{
|
}
|
||||||
throw (new \Exception(\sprintf('invalid realm name: "%s"', $realm_raw['name'])));
|
// source
|
||||||
}
|
{
|
||||||
else
|
$source = new struct_source();
|
||||||
{
|
$source->kind = $data_raw['source']['kind'];
|
||||||
return [
|
$source->data = ($data_raw['source']['data'] ?? null);
|
||||||
'name' => $realm_raw['name'],
|
$data->source = $source;
|
||||||
'auth' => (function ($auth_raw) use ($realm_raw) {
|
}
|
||||||
switch ($auth_raw['kind'])
|
// settings
|
||||||
{
|
{
|
||||||
case 'pass_through':
|
$settings = new struct_settings();
|
||||||
{
|
$settings->timezone = (($data_raw['settings'] ?? [])['timezone'] ?? 'UTC');
|
||||||
return [
|
$data->settings = $settings;
|
||||||
'kind' => 'pass_through',
|
}
|
||||||
'data' => null
|
_state::$data = $data;
|
||||||
];
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'static':
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'kind' => 'static',
|
|
||||||
'data' => [
|
|
||||||
'username' => ($auth_raw['data']['username'] ?? $realm_raw['name']),
|
|
||||||
'password' => ($auth_raw['data']['password'] ?? $realm_raw['name']),
|
|
||||||
]
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw (new \Exception(\sprintf('invalid auth kind: %s', $auth_raw['kind'])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}) ($realm_raw['auth']),
|
|
||||||
'source' => (function ($source_raw) {
|
|
||||||
switch ($source_raw['kind'])
|
|
||||||
{
|
|
||||||
case 'ics_feed':
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'kind' => 'ics_feed',
|
|
||||||
'data' => [
|
|
||||||
'url' => $source_raw['data']['url'],
|
|
||||||
'lifetime' => ($source_raw['data']['lifetime'] ?? (60 * 15)),
|
|
||||||
'conflate' => ($source_raw['data']['conflate'] ?? true),
|
|
||||||
]
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw (new \Exception(\sprintf('invalid source kind: %s', $source_raw['kind'])));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}) ($realm_raw['source']),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'settings' => [
|
|
||||||
'timezone' => (($data_raw['settings'] ?? [])['timezone'] ?? 'UTC'),
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
function get(
|
function get(
|
||||||
)
|
) : struct_root
|
||||||
{
|
{
|
||||||
if (_state::$data === null)
|
if (_state::$data === null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\helpers\list_;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
function map(
|
|
||||||
array $list,
|
|
||||||
\Closure $function
|
|
||||||
) : array
|
|
||||||
{
|
|
||||||
return \array_map(
|
|
||||||
$function,
|
|
||||||
$list
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
function filter(
|
|
||||||
array $list,
|
|
||||||
\Closure $predicate
|
|
||||||
) : array
|
|
||||||
{
|
|
||||||
return \array_values(
|
|
||||||
\array_filter(
|
|
||||||
$list,
|
|
||||||
$predicate
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
@ -13,18 +13,7 @@ function coin(
|
||||||
$result = $template;
|
$result = $template;
|
||||||
foreach ($arguments as $key => $value)
|
foreach ($arguments as $key => $value)
|
||||||
{
|
{
|
||||||
if ($value === null)
|
$result = \str_replace(\sprintf('{{%s}}', $key), $value, $result);
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$result = \str_replace(
|
|
||||||
\sprintf('{{%s}}', $key),
|
|
||||||
$value,
|
|
||||||
$result
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,9 @@ define("DIR_LOGIC", "logic");
|
||||||
require_once('vendor/autoload.php');
|
require_once('vendor/autoload.php');
|
||||||
require_once(DIR_LOGIC . '/base.php');
|
require_once(DIR_LOGIC . '/base.php');
|
||||||
require_once(DIR_LOGIC . '/overwrites/principal_backend.php');
|
require_once(DIR_LOGIC . '/overwrites/principal_backend.php');
|
||||||
require_once(DIR_LOGIC . '/overwrites/auth_backend.php');
|
require_once(DIR_LOGIC . '/overwrites/auths/_factory.php');
|
||||||
require_once(DIR_LOGIC . '/overwrites/caldav_backend.php');
|
require_once(DIR_LOGIC . '/overwrites/caldav_backend.php');
|
||||||
require_once(DIR_LOGIC . '/sources/_factory.php');
|
require_once(DIR_LOGIC . '/sources/_factory.php');
|
||||||
require_once(DIR_LOGIC . '/auths/_factory.php');
|
|
||||||
require_once(DIR_LOGIC . '/model.php');
|
|
||||||
require_once(DIR_LOGIC . '/conf.php');
|
require_once(DIR_LOGIC . '/conf.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,38 +20,21 @@ function main(
|
||||||
|
|
||||||
\davina\set_parameters([]);
|
\davina\set_parameters([]);
|
||||||
|
|
||||||
\date_default_timezone_set(\davina\conf\get()['settings']['timezone']);
|
\date_default_timezone_set(\davina\conf\get()->settings->timezone);
|
||||||
|
|
||||||
/**
|
$source = \davina\sources\make(
|
||||||
* @todo nicht einfach die realm names als keys verwenden …
|
[
|
||||||
*/
|
'kind' => \davina\conf\get()->source->kind,
|
||||||
$realms = [];
|
'data' => \davina\conf\get()->source->data,
|
||||||
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);
|
$principal_backend = new \davina\overwrites\class_principle_backend();
|
||||||
|
|
||||||
$server = new \Sabre\DAV\Server(
|
$server = new \Sabre\DAV\Server(
|
||||||
[
|
[
|
||||||
new \Sabre\CalDAV\Principal\Collection(
|
new \Sabre\CalDAV\Principal\Collection($principal_backend),
|
||||||
$principal_backend
|
new \Sabre\CalDAV\CalendarRoot($principal_backend, new \davina\overwrites\class_caldav_backend($source)),
|
||||||
),
|
|
||||||
new \Sabre\CalDAV\CalendarRoot(
|
|
||||||
$principal_backend,
|
|
||||||
new \davina\overwrites\class_caldav_backend($realms)
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -61,8 +42,12 @@ function main(
|
||||||
|
|
||||||
$server->addPlugin(
|
$server->addPlugin(
|
||||||
new \Sabre\DAV\Auth\Plugin(
|
new \Sabre\DAV\Auth\Plugin(
|
||||||
new \davina\overwrites\class_auth_backend(
|
\davina\overwrites\make_auth_backend(
|
||||||
$realms
|
$source,
|
||||||
|
[
|
||||||
|
'kind' => \davina\conf\get()->auth->kind,
|
||||||
|
'data' => \davina\conf\get()->auth->data,
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -79,7 +64,7 @@ function main(
|
||||||
/**
|
/**
|
||||||
* not required
|
* not required
|
||||||
*/
|
*/
|
||||||
// $server->addPlugin(new \Sabre\DAV\Browser\Plugin());
|
$server->addPlugin(new \Sabre\DAV\Browser\Plugin());
|
||||||
|
|
||||||
$server->start();
|
$server->start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,40 +116,4 @@ function calendar_from_raw(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
class struct_realm
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public string $name;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public \davina\auths\interface_auth $auth;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public \davina\sources\interface_source $source;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
string $name,
|
|
||||||
\davina\auths\interface_auth $auth,
|
|
||||||
\davina\sources\interface_source $source
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->auth = $auth;
|
|
||||||
$this->source = $source;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace davina\overwrites;
|
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
|
||||||
require_once(DIR_LOGIC . '/base.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
class class_auth_backend
|
|
||||||
extends \Sabre\DAV\Auth\Backend\AbstractBasic
|
|
||||||
implements \Sabre\DAV\Auth\Backend\BackendInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array {list<\davina\sources\interface_source>}
|
|
||||||
*/
|
|
||||||
private array $realms;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
array $realms
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// parent::__construct();
|
|
||||||
$this->realms = $realms;
|
|
||||||
$this->setRealm('davina');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
protected function validateUserPass(
|
|
||||||
/*string */$identifier,
|
|
||||||
/*string */$password
|
|
||||||
)/* : bool*/
|
|
||||||
{
|
|
||||||
$parts = \explode('-', $identifier, 2);
|
|
||||||
$realm_name = $parts[0];
|
|
||||||
$credentials = [
|
|
||||||
'username' => (
|
|
||||||
(\count($parts) >= 2)
|
|
||||||
?
|
|
||||||
$parts[1]
|
|
||||||
:
|
|
||||||
null
|
|
||||||
),
|
|
||||||
'password' => $password,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (! \array_key_exists($realm_name, $this->realms))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$realm = $this->realms[$realm_name];
|
|
||||||
if (! $realm->auth->check($credentials))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @todo check for security
|
|
||||||
*/
|
|
||||||
\davina\set_parameters(
|
|
||||||
\array_merge(
|
|
||||||
$realm->auth->determine_parameters($credentials),
|
|
||||||
[
|
|
||||||
'realm_name' => $realm_name,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$data = $realm->source->read();
|
|
||||||
return ($data !== null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
37
source/overwrites/auths/_factory.php
Normal file
37
source/overwrites/auths/_factory.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace davina\overwrites;
|
||||||
|
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
require_once(DIR_LOGIC . '/sources/_interface.php');
|
||||||
|
require_once(DIR_LOGIC . '/overwrites/auths/none.php');
|
||||||
|
require_once(DIR_LOGIC . '/overwrites/auths/basic.php');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make_auth_backend(
|
||||||
|
\davina\sources\interface_source $source,
|
||||||
|
array $descriptor
|
||||||
|
) : \Sabre\DAV\Auth\Backend\BackendInterface
|
||||||
|
{
|
||||||
|
switch ($descriptor['kind'])
|
||||||
|
{
|
||||||
|
case 'none':
|
||||||
|
{
|
||||||
|
return (new \davina\overwrites\class_auth_backend_none());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'basic':
|
||||||
|
{
|
||||||
|
return (new \davina\overwrites\class_auth_backend_basic($source));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw (new \Exception(\sprintf('unhandled auth backend kind: %s', $descriptor['kind'])));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
55
source/overwrites/auths/basic.php
Normal file
55
source/overwrites/auths/basic.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace davina\overwrites;
|
||||||
|
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
require_once(DIR_LOGIC . '/base.php');
|
||||||
|
require_once(DIR_LOGIC . '/sources/_interface.php');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class class_auth_backend_basic
|
||||||
|
extends \Sabre\DAV\Auth\Backend\AbstractBasic
|
||||||
|
implements \Sabre\DAV\Auth\Backend\BackendInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
private \davina\sources\interface_source $source;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
\davina\sources\interface_source $source
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// parent::__construct();
|
||||||
|
$this->source = $source;
|
||||||
|
$this->setRealm('davina');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
protected function validateUserPass(
|
||||||
|
/*string */$username,
|
||||||
|
/*string */$password
|
||||||
|
)/* : bool*/
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'username' => $username,
|
||||||
|
'password' => $password,
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* @todo check for security
|
||||||
|
*/
|
||||||
|
\davina\set_parameters($parameters);
|
||||||
|
$data = $this->source->get(/*$parameters*/[]);
|
||||||
|
return ($data !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
39
source/overwrites/auths/none.php
Normal file
39
source/overwrites/auths/none.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace davina\overwrites;
|
||||||
|
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
require_once(DIR_LOGIC . '/sources/_interface.php');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class class_auth_backend_none
|
||||||
|
implements \Sabre\DAV\Auth\Backend\BackendInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo other principal uri?
|
||||||
|
*/
|
||||||
|
public function check(
|
||||||
|
\Sabre\HTTP\RequestInterface $request,
|
||||||
|
\Sabre\HTTP\ResponseInterface $response
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return [true, 'principals/dummy'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function challenge(
|
||||||
|
\Sabre\HTTP\RequestInterface $request,
|
||||||
|
\Sabre\HTTP\ResponseInterface $response
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -4,9 +4,9 @@ namespace davina\overwrites;
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
require_once('vendor/autoload.php');
|
||||||
require_once(DIR_LOGIC . '/helpers/call.php');
|
require_once(DIR_LOGIC . '/helpers/call.php');
|
||||||
require_once(DIR_LOGIC . '/helpers/list.php');
|
|
||||||
require_once(DIR_LOGIC . '/helpers/ics.php');
|
require_once(DIR_LOGIC . '/helpers/ics.php');
|
||||||
require_once(DIR_LOGIC . '/model.php');
|
require_once(DIR_LOGIC . '/model.php');
|
||||||
|
require_once(DIR_LOGIC . '/sources/_interface.php');
|
||||||
require_once(DIR_LOGIC . '/conf.php');
|
require_once(DIR_LOGIC . '/conf.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,27 +19,52 @@ class class_caldav_backend
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array {map<string, \davina\model\struct_realm>}
|
|
||||||
*/
|
*/
|
||||||
private array $realms;
|
private \davina\sources\interface_source $source;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private ?string $selected_realm_name;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
array $realms
|
\davina\sources\interface_source $source
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// parent::__construct();
|
// parent::__construct();
|
||||||
$this->realms = $realms;
|
$this->source = $source;
|
||||||
$this->selected_realm_name = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
private function hash_tag(
|
||||||
|
string $tag
|
||||||
|
) : string
|
||||||
|
{
|
||||||
|
return \hash('sha256', $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
private function encode_tag(
|
||||||
|
string $tag
|
||||||
|
) : string
|
||||||
|
{
|
||||||
|
return \davina\helpers\call\convey(
|
||||||
|
$tag,
|
||||||
|
[
|
||||||
|
fn($x) => \strtolower($x),
|
||||||
|
fn($x) => \preg_replace('/ä/', 'ae', $x),
|
||||||
|
fn($x) => \preg_replace('/ö/', 'oe', $x),
|
||||||
|
fn($x) => \preg_replace('/ü/', 'ue', $x),
|
||||||
|
fn($x) => \preg_replace('/ß/', 'sz', $x),
|
||||||
|
fn($x) => \preg_replace('/\-/', '', $x),
|
||||||
|
fn($x) => \preg_replace('/ /', '-', $x),
|
||||||
|
fn($x) => \preg_replace('/[^a-zA-Z0-9_\-]/s', '_', $x),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo outsource
|
* @todo outsource
|
||||||
|
|
@ -98,118 +123,6 @@ class class_caldav_backend
|
||||||
}
|
}
|
||||||
return $vcalendar;
|
return $vcalendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private function encode_tag(
|
|
||||||
?string $tag
|
|
||||||
) : ?string
|
|
||||||
{
|
|
||||||
if ($tag === null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return \davina\helpers\call\convey(
|
|
||||||
$tag,
|
|
||||||
[
|
|
||||||
fn($x) => \strtolower($x),
|
|
||||||
fn($x) => \preg_replace('/ä/', 'ae', $x),
|
|
||||||
fn($x) => \preg_replace('/ö/', 'oe', $x),
|
|
||||||
fn($x) => \preg_replace('/ü/', 'ue', $x),
|
|
||||||
fn($x) => \preg_replace('/ß/', 'sz', $x),
|
|
||||||
fn($x) => \preg_replace('/\-/', '', $x),
|
|
||||||
fn($x) => \preg_replace('/ /', '-', $x),
|
|
||||||
fn($x) => \preg_replace('/[^a-zA-Z0-9_\-]/s', '_', $x),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $parameters {
|
|
||||||
* record<
|
|
||||||
* realm_name:string,
|
|
||||||
* calendar_name:(null|string),
|
|
||||||
* >
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
private function encode_calendar_identifier(
|
|
||||||
array $parameters
|
|
||||||
) : string
|
|
||||||
{
|
|
||||||
$str = $parameters['realm_name'];
|
|
||||||
if ($parameters['calendar_name'] === null)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$str .= \sprintf(
|
|
||||||
'-%s',
|
|
||||||
$parameters['calendar_name']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array {
|
|
||||||
* record<
|
|
||||||
* realm_name:string,
|
|
||||||
* calendar_name:(null|string),
|
|
||||||
* >
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
private function decode_calendar_identifier(
|
|
||||||
string $str
|
|
||||||
) : array
|
|
||||||
{
|
|
||||||
$parts = \explode('-', $str, 2);
|
|
||||||
return [
|
|
||||||
'realm_name' => $parts[0],
|
|
||||||
'calendar_name' => (
|
|
||||||
(count($parts) < 2)
|
|
||||||
?
|
|
||||||
null
|
|
||||||
:
|
|
||||||
$parts[1]
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private function get_source(
|
|
||||||
string $realm_name
|
|
||||||
) : \davina\sources\interface_source
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
($this->selected_realm_name === null)
|
|
||||||
||
|
|
||||||
($this->selected_realm_name === $realm_name)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->selected_realm_name = $realm_name;
|
|
||||||
if (! \array_key_exists($realm_name, $this->realms))
|
|
||||||
{
|
|
||||||
throw (new \Exception(\sprintf('no such realm: %s', $realm_name)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $this->realms[$realm_name]->source;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw (new \Exception('may not change source'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -219,11 +132,7 @@ class class_caldav_backend
|
||||||
$principalUri
|
$principalUri
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// $source = $this->source;
|
$calendar = $this->source->get([]);
|
||||||
// $realm_name = \explode('/', $principalUri)[1];
|
|
||||||
$realm_name = \davina\get_parameters()['realm_name'];
|
|
||||||
$source = $this->get_source($realm_name);
|
|
||||||
$calendar = $source->read();
|
|
||||||
$tags = [];
|
$tags = [];
|
||||||
foreach ($calendar->events as $event)
|
foreach ($calendar->events as $event)
|
||||||
{
|
{
|
||||||
|
|
@ -232,42 +141,18 @@ class class_caldav_backend
|
||||||
$tags[$tag] = null;
|
$tags[$tag] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return \davina\helpers\call\convey(
|
$result = \array_map(
|
||||||
$tags,
|
fn($tag) => [
|
||||||
[
|
'id' => $this->hash_tag($tag),
|
||||||
fn($x) => (
|
'uri' => $this->encode_tag($tag),
|
||||||
(\count($x) <= 0)
|
'principaluri' => $principalUri,
|
||||||
?
|
'{DAV:}displayname' => $tag,
|
||||||
[null]
|
\sprintf('{%s}supported-calendar-component-set', \Sabre\CalDAV\Plugin::NS_CALDAV) => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
|
||||||
:
|
|
||||||
\array_keys($x)
|
|
||||||
),
|
|
||||||
fn($x) => \davina\helpers\list_\map(
|
|
||||||
$x,
|
|
||||||
fn($tag) => [
|
|
||||||
'id' => $this->encode_calendar_identifier(
|
|
||||||
[
|
|
||||||
'realm_name' => $realm_name,
|
|
||||||
'calendar_name' => $this->encode_tag($tag),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
// 'uri' => $this->encode_tag($tag),
|
|
||||||
'uri' => $this->encode_calendar_identifier(
|
|
||||||
[
|
|
||||||
'realm_name' => $realm_name,
|
|
||||||
'calendar_name' => $this->encode_tag($tag),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
'principaluri' => $principalUri,
|
|
||||||
'{DAV:}displayname' => ($tag ?? $realm_name),
|
|
||||||
\sprintf(
|
|
||||||
'{%s}supported-calendar-component-set',
|
|
||||||
\Sabre\CalDAV\Plugin::NS_CALDAV
|
|
||||||
) => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
|
\array_keys($tags)
|
||||||
);
|
);
|
||||||
|
// \error_log(\json_encode($result, \JSON_PRETTY_PRINT));
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -302,46 +187,34 @@ class class_caldav_backend
|
||||||
$calendarId
|
$calendarId
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$calendar_identifier = $this->decode_calendar_identifier($calendarId);
|
$tag = $calendarId;
|
||||||
// $realm_name = $calendar_identifier['realm_name'];
|
$calendar = $this->source->get([]);
|
||||||
$realm_name = \davina\get_parameters()['realm_name'];
|
$result = \array_map(
|
||||||
$source = $this->get_source($realm_name);
|
fn($event) => [
|
||||||
$tag = $calendar_identifier['calendar_name'];
|
'calendarid' => $calendarId,
|
||||||
$calendar = $source->read();
|
'id' => $event->id,
|
||||||
|
// 'uri' => \sprintf('%s.ics', $entry['id']),
|
||||||
return \davina\helpers\call\convey(
|
'uri' => $event->id,
|
||||||
$calendar->events,
|
'lastmodified' => \time(),
|
||||||
[
|
// 'etag' => null,
|
||||||
fn($x) => \davina\helpers\list_\filter(
|
// 'size' => null,
|
||||||
$x,
|
'component' => 'vevent',
|
||||||
fn($event) => (
|
'{DAV:}displayname' => $event->title,
|
||||||
(\count($event->tags) <= 0)
|
],
|
||||||
||
|
\array_values(
|
||||||
\in_array(
|
\array_filter(
|
||||||
$tag,
|
$calendar->events,
|
||||||
\davina\helpers\list_\map(
|
fn($event) => \in_array(
|
||||||
$event->tags,
|
$tag,
|
||||||
fn($x) => $this->encode_tag($x)
|
\array_map(
|
||||||
)
|
fn($x) => $this->hash_tag($x),
|
||||||
|
$event->tags
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
fn($x) => \davina\helpers\list_\map(
|
)
|
||||||
$x,
|
|
||||||
fn($event) => [
|
|
||||||
'calendarid' => $calendarId,
|
|
||||||
'id' => $event->id,
|
|
||||||
// 'uri' => \sprintf('%s.ics', $entry['id']),
|
|
||||||
'uri' => $event->id,
|
|
||||||
'lastmodified' => \time(),
|
|
||||||
// 'etag' => null,
|
|
||||||
// 'size' => null,
|
|
||||||
'component' => 'vevent',
|
|
||||||
'{DAV:}displayname' => $event->title,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -354,16 +227,12 @@ class class_caldav_backend
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$id = $objectUri;
|
$id = $objectUri;
|
||||||
$calendar_identifier = $this->decode_calendar_identifier($calendarId);
|
$calendar = $this->source->get([]);
|
||||||
// $realm_name = $calendar_identifier['realm_name'];
|
$events = \array_values(
|
||||||
$realm_name = \davina\get_parameters()['realm_name'];
|
\array_filter(
|
||||||
$source = $this->get_source($realm_name);
|
$calendar->events,
|
||||||
$tag = $calendar_identifier['calendar_name'];
|
fn($event) => ($event->id === $id)
|
||||||
$calendar = $source->read();
|
)
|
||||||
|
|
||||||
$events = \davina\helpers\list_\filter(
|
|
||||||
$calendar->events,
|
|
||||||
fn($event) => ($event->id === $id)
|
|
||||||
);
|
);
|
||||||
if (\count($events) < 1)
|
if (\count($events) < 1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace davina\overwrites;
|
namespace davina\overwrites;
|
||||||
|
|
||||||
require_once('vendor/autoload.php');
|
require_once('vendor/autoload.php');
|
||||||
require_once(DIR_LOGIC . '/helpers/list.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -13,33 +12,17 @@ class class_principle_backend
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array {map<string, \davina\model\struct_realm>}
|
|
||||||
*/
|
*/
|
||||||
private array $realms;
|
public function getPrincipalsByPrefix($prefixPath)
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
array $realms
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->realms = $realms;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function getPrincipalsByPrefix(
|
|
||||||
$prefixPath
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
throw (new \Exception('not implemented: getPrincipalsByPrefix'));
|
||||||
|
/*
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'uri' => 'principals/-',
|
'uri' => 'principals/dummy',
|
||||||
'{DAV:}displayname' => 'default',
|
]
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,6 +32,7 @@ class class_principle_backend
|
||||||
$path
|
$path
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
// throw (new \Exception('not implemented: getPrincipalByPath'));
|
||||||
$parts = \explode('/', $path);
|
$parts = \explode('/', $path);
|
||||||
$username = $parts[1];
|
$username = $parts[1];
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,30 @@
|
||||||
|
|
||||||
namespace davina\sources;
|
namespace davina\sources;
|
||||||
|
|
||||||
require_once(DIR_LOGIC . '/sources/_interface.php');
|
|
||||||
require_once(DIR_LOGIC . '/sources/ics_feed.php');
|
require_once(DIR_LOGIC . '/sources/ics_feed.php');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array $descriptor {
|
||||||
|
* record<
|
||||||
|
* kind:string,
|
||||||
|
* data:any
|
||||||
|
* >
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
function make(
|
function make(
|
||||||
string $kind,
|
array $descriptor
|
||||||
$data
|
|
||||||
) : interface_source
|
) : interface_source
|
||||||
{
|
{
|
||||||
switch ($kind)
|
switch ($descriptor['kind'])
|
||||||
{
|
{
|
||||||
case 'ics_feed':
|
case 'ics_feed':
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
new class_source_ics_feed(
|
new class_source_ics_feed(
|
||||||
$data['url'],
|
$descriptor['data']['url'],
|
||||||
$data['lifetime'],
|
($descriptor['data']['lifetime'] ?? (60 * 15)),
|
||||||
$data['conflate']
|
($descriptor['data']['combine'] ?? false)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +35,7 @@ function make(
|
||||||
new \Exception(
|
new \Exception(
|
||||||
\sprintf(
|
\sprintf(
|
||||||
'unhandled source kind: %s',
|
'unhandled source kind: %s',
|
||||||
$kind
|
$descriptor['kind']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -40,4 +44,4 @@ function make(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,15 @@ interface interface_source
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array $parameters {
|
||||||
|
* record<
|
||||||
|
* username:(null|string),
|
||||||
|
* password:(null|string),
|
||||||
|
* >
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
public function read(
|
public function get(
|
||||||
|
array $parameters
|
||||||
) : \davina\model\struct_calendar
|
) : \davina\model\struct_calendar
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ require_once(DIR_LOGIC . '/helpers/cache.php');
|
||||||
require_once(DIR_LOGIC . '/helpers/pit.php');
|
require_once(DIR_LOGIC . '/helpers/pit.php');
|
||||||
require_once(DIR_LOGIC . '/helpers/ics.php');
|
require_once(DIR_LOGIC . '/helpers/ics.php');
|
||||||
require_once(DIR_LOGIC . '/base.php');
|
require_once(DIR_LOGIC . '/base.php');
|
||||||
require_once(DIR_LOGIC . '/sources/_interface.php');
|
|
||||||
require_once(DIR_LOGIC . '/model.php');
|
require_once(DIR_LOGIC . '/model.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -29,7 +28,7 @@ class class_source_ics_feed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
private bool $conflate;
|
private bool $combine;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,12 +36,12 @@ class class_source_ics_feed
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $url_template,
|
string $url_template,
|
||||||
?int $lifetime,
|
?int $lifetime,
|
||||||
bool $conflate
|
bool $combine
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->url_template = $url_template;
|
$this->url_template = $url_template;
|
||||||
$this->lifetime = $lifetime;
|
$this->lifetime = $lifetime;
|
||||||
$this->conflate = $conflate;
|
$this->combine = $combine;
|
||||||
$this->cache_file = \davina\helpers\call\convey(
|
$this->cache_file = \davina\helpers\call\convey(
|
||||||
new \davina\helpers\cache\class_cache_file('data'),
|
new \davina\helpers\cache\class_cache_file('data'),
|
||||||
[
|
[
|
||||||
|
|
@ -69,10 +68,7 @@ class class_source_ics_feed
|
||||||
{
|
{
|
||||||
return \davina\helpers\string_\coin(
|
return \davina\helpers\string_\coin(
|
||||||
$this->url_template,
|
$this->url_template,
|
||||||
[
|
$parameters
|
||||||
'username' => ($parameters['auth_username'] ?? null),
|
|
||||||
'password' => ($parameters['auth_password'] ?? null),
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,8 +76,7 @@ class class_source_ics_feed
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
private function vcalendar_to_calendar(
|
private function vcalendar_to_calendar(
|
||||||
\davina\helpers\ics\struct_vcalendar $vcalendar,
|
\davina\helpers\ics\struct_vcalendar $vcalendar
|
||||||
?string $realm_name
|
|
||||||
) : \davina\model\struct_calendar
|
) : \davina\model\struct_calendar
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
|
|
@ -92,10 +87,8 @@ class class_source_ics_feed
|
||||||
$vevent->uid,
|
$vevent->uid,
|
||||||
// title
|
// title
|
||||||
(
|
(
|
||||||
(! $this->conflate)
|
$this->combine
|
||||||
?
|
?
|
||||||
$vevent->summary
|
|
||||||
:
|
|
||||||
\sprintf(
|
\sprintf(
|
||||||
'%s%s',
|
'%s%s',
|
||||||
$vevent->summary,
|
$vevent->summary,
|
||||||
|
|
@ -107,6 +100,8 @@ class class_source_ics_feed
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
:
|
||||||
|
$vevent->summary
|
||||||
),
|
),
|
||||||
// begin
|
// begin
|
||||||
\davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value),
|
\davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value),
|
||||||
|
|
@ -124,11 +119,11 @@ class class_source_ics_feed
|
||||||
$vevent->description,
|
$vevent->description,
|
||||||
// 'tags
|
// 'tags
|
||||||
(
|
(
|
||||||
(! $this->conflate)
|
$this->combine
|
||||||
?
|
?
|
||||||
$vevent->categories
|
['combined']
|
||||||
:
|
:
|
||||||
[]
|
$vevent->categories
|
||||||
)
|
)
|
||||||
)),
|
)),
|
||||||
$vcalendar->events
|
$vcalendar->events
|
||||||
|
|
@ -141,8 +136,7 @@ class class_source_ics_feed
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
private function retrieve(
|
private function retrieve(
|
||||||
string $url,
|
string $url
|
||||||
?string $realm_name
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$client = new \Sabre\HTTP\Client();
|
$client = new \Sabre\HTTP\Client();
|
||||||
|
|
@ -160,7 +154,7 @@ class class_source_ics_feed
|
||||||
{
|
{
|
||||||
$ics = $response->getBody();
|
$ics = $response->getBody();
|
||||||
$vcalendar = \davina\helpers\ics\vcalendar_decode($ics);
|
$vcalendar = \davina\helpers\ics\vcalendar_decode($ics);
|
||||||
$calendar = $this->vcalendar_to_calendar($vcalendar, $realm_name);
|
$calendar = $this->vcalendar_to_calendar($vcalendar);
|
||||||
$calendar_raw = \davina\model\calendar_to_raw($calendar);
|
$calendar_raw = \davina\model\calendar_to_raw($calendar);
|
||||||
return $calendar_raw;
|
return $calendar_raw;
|
||||||
break;
|
break;
|
||||||
|
|
@ -184,19 +178,14 @@ class class_source_ics_feed
|
||||||
/**
|
/**
|
||||||
* [implementation]
|
* [implementation]
|
||||||
*/
|
*/
|
||||||
public function read(
|
public function get(
|
||||||
|
array $parameters
|
||||||
) : \davina\model\struct_calendar
|
) : \davina\model\struct_calendar
|
||||||
{
|
{
|
||||||
$parameters = \davina\get_parameters();
|
$url = $this->url(\davina\get_parameters());
|
||||||
$url = $this->url($parameters);
|
$key = $url;
|
||||||
$key = \sprintf(
|
|
||||||
'%s:%u',
|
|
||||||
$url,
|
|
||||||
$this->conflate
|
|
||||||
);
|
|
||||||
$f1 = fn() => $this->retrieve(
|
$f1 = fn() => $this->retrieve(
|
||||||
$url,
|
$url
|
||||||
$parameters['realm_name']
|
|
||||||
);
|
);
|
||||||
$f2 = fn() => \davina\helpers\cache\get(
|
$f2 = fn() => \davina\helpers\cache\get(
|
||||||
$this->cache_file,
|
$this->cache_file,
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ def main():
|
||||||
"--links",
|
"--links",
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"--exclude='conf.json'",
|
"--exclude='conf.json'",
|
||||||
"--exclude='data'",
|
|
||||||
("%s/" % args.build_directory),
|
("%s/" % args.build_directory),
|
||||||
(
|
(
|
||||||
("%s" % args.target_directory)
|
("%s" % args.target_directory)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue