2025-09-21 18:49:03 +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-21 18:49:03 +02:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
);
|
2025-09-22 01:00:27 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$data = $realm->source->read();
|
|
|
|
|
return ($data !== null);
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $throwable)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-09-21 18:49:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|