2015-04-16 23:39:44 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @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,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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\HTTP\RequestInterface;
|
|
|
|
use Sabre\DAV\ServerPlugin;
|
2015-04-20 13:53:40 +03:00
|
|
|
use Sabre\DAV\Exception;
|
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;
|
|
|
|
$this->server->on('beforeMethod', [$this, 'beforeHandler'], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-16 23:39:44 +03:00
|
|
|
$minimumSupportedDesktopVersion = $this->config->getSystemValue('minimum.supported.desktop.version', '1.7.0');
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|