2014-01-23 15:11:53 +04:00
|
|
|
<?php
|
2015-02-26 13:37:37 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-02-26 13:37:37 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +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-02-26 13:37:37 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
namespace OCA\DAV\Connector\Sabre;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2018-11-03 00:06:25 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
|
2017-10-13 13:23:00 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
|
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2015-03-11 13:53:31 +03:00
|
|
|
use OCP\ILogger;
|
2020-09-11 12:52:05 +03:00
|
|
|
use Sabre\DAV\Exception\BadRequest;
|
2018-01-03 13:58:55 +03:00
|
|
|
use Sabre\DAV\Exception\Conflict;
|
2017-10-13 13:23:00 +03:00
|
|
|
use Sabre\DAV\Exception\Forbidden;
|
2017-11-27 18:37:11 +03:00
|
|
|
use Sabre\DAV\Exception\InvalidSyncToken;
|
2018-03-24 00:35:31 +03:00
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed;
|
2017-10-13 13:23:00 +03:00
|
|
|
use Sabre\DAV\Exception\NotAuthenticated;
|
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2017-11-27 18:17:01 +03:00
|
|
|
use Sabre\DAV\Exception\NotImplemented;
|
2017-10-13 13:23:00 +03:00
|
|
|
use Sabre\DAV\Exception\PreconditionFailed;
|
2020-07-14 21:46:33 +03:00
|
|
|
use Sabre\DAV\Exception\RequestedRangeNotSatisfiable;
|
2017-08-15 15:46:22 +03:00
|
|
|
use Sabre\DAV\Exception\ServiceUnavailable;
|
2015-03-11 13:53:31 +03:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
|
2016-09-19 13:17:06 +03:00
|
|
|
protected $nonFatalExceptions = [
|
2017-10-13 13:23:00 +03:00
|
|
|
NotAuthenticated::class => true,
|
2016-07-14 23:53:12 +03:00
|
|
|
// If tokenauth can throw this exception (which is basically as
|
|
|
|
// NotAuthenticated. So not fatal.
|
2017-10-13 13:23:00 +03:00
|
|
|
PasswordLoginForbidden::class => true,
|
2017-11-27 18:37:11 +03:00
|
|
|
// basically a NotAuthenticated
|
|
|
|
InvalidSyncToken::class => true,
|
2014-05-05 13:31:25 +04:00
|
|
|
// the sync client uses this to find out whether files exist,
|
|
|
|
// so it is not always an error, log it as debug
|
2017-10-13 13:23:00 +03:00
|
|
|
NotFound::class => true,
|
2020-09-11 12:52:05 +03:00
|
|
|
// the sync client messed up their request
|
|
|
|
// (e.g. propfind for tags with string instead of int)
|
|
|
|
// so it is not always an error, log it as debug
|
|
|
|
BadRequest::class => true,
|
2014-05-05 13:31:25 +04:00
|
|
|
// this one mostly happens when the same file is uploaded at
|
|
|
|
// exactly the same time from two clients, only one client
|
|
|
|
// wins, the second one gets "Precondition failed"
|
2017-10-13 13:23:00 +03:00
|
|
|
PreconditionFailed::class => true,
|
2015-03-25 00:08:11 +03:00
|
|
|
// forbidden can be expected when trying to upload to
|
|
|
|
// read-only folders for example
|
2017-10-13 13:23:00 +03:00
|
|
|
Forbidden::class => true,
|
2016-09-19 13:17:06 +03:00
|
|
|
// Happens when an external storage or federated share is temporarily
|
|
|
|
// not available
|
2017-10-13 13:23:00 +03:00
|
|
|
StorageNotAvailableException::class => true,
|
2017-11-27 18:17:01 +03:00
|
|
|
// happens if some a client uses the wrong method for a given URL
|
|
|
|
// the error message itself is visible on the client side anyways
|
|
|
|
NotImplemented::class => true,
|
2018-01-03 13:58:55 +03:00
|
|
|
// happens when the parent directory is not present (for example when a
|
|
|
|
// move is done to a non-existent directory)
|
|
|
|
Conflict::class => true,
|
2018-03-24 00:35:31 +03:00
|
|
|
// happens when a certain method is not allowed to be called
|
|
|
|
// for example creating a folder that already exists
|
|
|
|
MethodNotAllowed::class => true,
|
2018-11-03 00:06:25 +03:00
|
|
|
// A locked file is perfectly valid and can happen in various cases
|
|
|
|
FileLocked::class => true,
|
2020-07-14 21:46:33 +03:00
|
|
|
// An invalid range is requested
|
|
|
|
RequestedRangeNotSatisfiable::class => true,
|
2016-09-19 13:17:06 +03:00
|
|
|
];
|
2014-05-05 13:31:25 +04:00
|
|
|
|
2015-03-11 13:53:31 +03:00
|
|
|
/** @var string */
|
2014-01-23 15:11:53 +04:00
|
|
|
private $appName;
|
|
|
|
|
2015-03-11 13:53:31 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2014-01-23 15:11:53 +04:00
|
|
|
/**
|
|
|
|
* @param string $loggerAppName app name to use when logging
|
2015-03-11 13:53:31 +03:00
|
|
|
* @param ILogger $logger
|
2014-01-23 15:11:53 +04:00
|
|
|
*/
|
2015-03-11 13:53:31 +03:00
|
|
|
public function __construct($loggerAppName, $logger) {
|
2014-01-23 15:11:53 +04:00
|
|
|
$this->appName = $loggerAppName;
|
2015-03-11 13:53:31 +03:00
|
|
|
$this->logger = $logger;
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This initializes the plugin.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* This function is called by \Sabre\DAV\Server, after
|
2014-01-23 15:11:53 +04:00
|
|
|
* addPlugin is called.
|
|
|
|
*
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\Server $server
|
2014-01-23 15:11:53 +04:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function initialize(\Sabre\DAV\Server $server) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$server->on('exception', [$this, 'logException'], 10);
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log exception
|
|
|
|
*
|
|
|
|
*/
|
2020-04-15 16:28:37 +03:00
|
|
|
public function logException(\Throwable $ex) {
|
2015-03-11 13:53:31 +03:00
|
|
|
$exceptionClass = get_class($ex);
|
2018-04-25 16:22:28 +03:00
|
|
|
$level = ILogger::FATAL;
|
2017-08-15 15:46:22 +03:00
|
|
|
if (isset($this->nonFatalExceptions[$exceptionClass]) ||
|
|
|
|
(
|
|
|
|
$exceptionClass === ServiceUnavailable::class &&
|
|
|
|
$ex->getMessage() === 'System in maintenance mode.'
|
|
|
|
)
|
|
|
|
) {
|
2018-04-25 16:22:28 +03:00
|
|
|
$level = ILogger::DEBUG;
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
2015-03-11 13:53:31 +03:00
|
|
|
|
2017-06-29 12:43:32 +03:00
|
|
|
$this->logger->logException($ex, [
|
|
|
|
'app' => $this->appName,
|
|
|
|
'level' => $level,
|
|
|
|
]);
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
|
|
|
}
|