2015-04-16 23:39:44 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-04-16 23:39:44 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-04-16 23:39:44 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
namespace OCA\DAV\Connector\Sabre;
|
2015-04-16 23:39:44 +03:00
|
|
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
use Sabre\DAV\ServerPlugin;
|
2019-11-22 22:52:10 +03:00
|
|
|
use Sabre\HTTP\RequestInterface;
|
2015-04-16 23:39:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BlockLegacyClientPlugin is used to detect old legacy sync clients and
|
2015-04-20 13:53:40 +03:00
|
|
|
* returns a 403 status to those clients
|
2015-04-16 23:39:44 +03:00
|
|
|
*
|
2015-08-30 20:13:01 +03:00
|
|
|
* @package OCA\DAV\Connector\Sabre
|
2015-04-16 23:39:44 +03:00
|
|
|
*/
|
|
|
|
class BlockLegacyClientPlugin extends ServerPlugin {
|
2015-04-20 13:53:40 +03:00
|
|
|
/** @var \Sabre\DAV\Server */
|
2015-04-16 23:39:44 +03:00
|
|
|
protected $server;
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IConfig $config
|
|
|
|
*/
|
|
|
|
public function __construct(IConfig $config) {
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-23 17:33:51 +03:00
|
|
|
* @param \Sabre\DAV\Server $server
|
2015-04-16 23:39:44 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-04-20 13:53:40 +03:00
|
|
|
public function initialize(\Sabre\DAV\Server $server) {
|
2015-04-16 23:39:44 +03:00
|
|
|
$this->server = $server;
|
2020-03-09 18:32:04 +03:00
|
|
|
$this->server->on('beforeMethod:*', [$this, 'beforeHandler'], 200);
|
2015-04-16 23:39:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-20 13:53:40 +03:00
|
|
|
* Detects all unsupported clients and throws a \Sabre\DAV\Exception\Forbidden
|
|
|
|
* exception which will result in a 403 to them.
|
2015-04-16 23:39:44 +03:00
|
|
|
* @param RequestInterface $request
|
2015-04-20 13:53:40 +03:00
|
|
|
* @throws \Sabre\DAV\Exception\Forbidden If the client version is not supported
|
2015-04-16 23:39:44 +03:00
|
|
|
*/
|
|
|
|
public function beforeHandler(RequestInterface $request) {
|
|
|
|
$userAgent = $request->getHeader('User-Agent');
|
2015-04-23 17:33:51 +03:00
|
|
|
if($userAgent === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:29:19 +03:00
|
|
|
$minimumSupportedDesktopVersion = $this->config->getSystemValue('minimum.supported.desktop.version', '2.0.0');
|
2015-04-16 23:39:44 +03:00
|
|
|
|
|
|
|
// Match on the mirall version which is in scheme "Mozilla/5.0 (%1) mirall/%2" or
|
|
|
|
// "mirall/%1" for older releases
|
|
|
|
preg_match("/(?:mirall\\/)([\d.]+)/i", $userAgent, $versionMatches);
|
|
|
|
if(isset($versionMatches[1]) &&
|
|
|
|
version_compare($versionMatches[1], $minimumSupportedDesktopVersion) === -1) {
|
2015-04-20 13:53:40 +03:00
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('Unsupported client version.');
|
2015-04-16 23:39:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|