2015-04-16 16:39:44 -04:00
|
|
|
<?php
|
2024-05-27 11:39:07 -04:00
|
|
|
|
2015-04-16 16:39:44 -04:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-04-16 16:39:44 -04:00
|
|
|
*/
|
2015-08-30 13:13:01 -04:00
|
|
|
namespace OCA\DAV\Connector\Sabre;
|
2015-04-16 16:39:44 -04:00
|
|
|
|
|
|
|
|
use OCP\IConfig;
|
2023-06-23 03:50:46 -04:00
|
|
|
use OCP\IRequest;
|
2023-11-23 04:22:34 -05:00
|
|
|
use Sabre\DAV\Server;
|
2015-04-16 16:39:44 -04:00
|
|
|
use Sabre\DAV\ServerPlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Sabre\HTTP\RequestInterface;
|
2015-04-16 16:39:44 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class BlockLegacyClientPlugin is used to detect old legacy sync clients and
|
2015-04-20 06:53:40 -04:00
|
|
|
* returns a 403 status to those clients
|
2015-04-16 16:39:44 -04:00
|
|
|
*
|
2015-08-30 13:13:01 -04:00
|
|
|
* @package OCA\DAV\Connector\Sabre
|
2015-04-16 16:39:44 -04:00
|
|
|
*/
|
|
|
|
|
class BlockLegacyClientPlugin extends ServerPlugin {
|
2022-05-05 18:01:08 -04:00
|
|
|
protected ?Server $server = null;
|
2022-04-12 08:01:13 -04:00
|
|
|
protected IConfig $config;
|
2015-04-16 16:39:44 -04:00
|
|
|
|
|
|
|
|
public function __construct(IConfig $config) {
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-04-12 08:01:13 -04:00
|
|
|
public function initialize(Server $server) {
|
2015-04-16 16:39:44 -04:00
|
|
|
$this->server = $server;
|
2020-03-09 11:32:04 -04:00
|
|
|
$this->server->on('beforeMethod:*', [$this, 'beforeHandler'], 200);
|
2015-04-16 16:39:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-04-20 06:53:40 -04:00
|
|
|
* Detects all unsupported clients and throws a \Sabre\DAV\Exception\Forbidden
|
|
|
|
|
* exception which will result in a 403 to them.
|
2015-04-16 16:39:44 -04:00
|
|
|
* @param RequestInterface $request
|
2015-04-20 06:53:40 -04:00
|
|
|
* @throws \Sabre\DAV\Exception\Forbidden If the client version is not supported
|
2015-04-16 16:39:44 -04:00
|
|
|
*/
|
|
|
|
|
public function beforeHandler(RequestInterface $request) {
|
|
|
|
|
$userAgent = $request->getHeader('User-Agent');
|
2020-04-10 08:19:56 -04:00
|
|
|
if ($userAgent === null) {
|
2015-04-23 10:33:51 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 05:40:30 -05:00
|
|
|
$minimumSupportedDesktopVersion = $this->config->getSystemValue('minimum.supported.desktop.version', '2.3.0');
|
2023-06-23 03:50:46 -04:00
|
|
|
preg_match(IRequest::USER_AGENT_CLIENT_DESKTOP, $userAgent, $versionMatches);
|
2020-04-10 08:19:56 -04:00
|
|
|
if (isset($versionMatches[1]) &&
|
2015-04-16 16:39:44 -04:00
|
|
|
version_compare($versionMatches[1], $minimumSupportedDesktopVersion) === -1) {
|
2015-04-20 06:53:40 -04:00
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('Unsupported client version.');
|
2015-04-16 16:39:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|