diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-05-30 14:24:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 14:24:22 +0200 |
commit | 258bb03cf59558351bcf47f089fd560de2d82399 (patch) | |
tree | aa59ba898bf410cf8a30e8a8418926536a4537a6 /lib/private/legacy | |
parent | 1395a5360274a6c6c0b4084d22da53466998c954 (diff) | |
parent | 31b0a44cf65b6625636ea0fa15fb1a1122b525e1 (diff) | |
download | nextcloud-server-258bb03cf59558351bcf47f089fd560de2d82399.tar.gz nextcloud-server-258bb03cf59558351bcf47f089fd560de2d82399.zip |
Merge branch 'master' into refactor/OC-Server-getSecureRandom
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
Diffstat (limited to 'lib/private/legacy')
-rw-r--r-- | lib/private/legacy/OC_API.php | 35 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 98 | ||||
-rw-r--r-- | lib/private/legacy/OC_Defaults.php | 54 | ||||
-rw-r--r-- | lib/private/legacy/OC_EventSource.php | 134 | ||||
-rw-r--r-- | lib/private/legacy/OC_FileChunking.php | 31 | ||||
-rw-r--r-- | lib/private/legacy/OC_Files.php | 63 | ||||
-rw-r--r-- | lib/private/legacy/OC_Helper.php | 55 | ||||
-rw-r--r-- | lib/private/legacy/OC_Hook.php | 31 | ||||
-rw-r--r-- | lib/private/legacy/OC_Image.php | 155 | ||||
-rw-r--r-- | lib/private/legacy/OC_JSON.php | 49 | ||||
-rw-r--r-- | lib/private/legacy/OC_Response.php | 30 | ||||
-rw-r--r-- | lib/private/legacy/OC_Template.php | 116 | ||||
-rw-r--r-- | lib/private/legacy/OC_User.php | 72 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 97 | ||||
-rw-r--r-- | lib/private/legacy/template/functions.php | 37 |
15 files changed, 263 insertions, 794 deletions
diff --git a/lib/private/legacy/OC_API.php b/lib/private/legacy/OC_API.php index 275e02986c4..bb2376d4ea0 100644 --- a/lib/private/legacy/OC_API.php +++ b/lib/private/legacy/OC_API.php @@ -1,32 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Tom Needham <tom@owncloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ use OCP\API; use OCP\AppFramework\Http; @@ -130,7 +107,7 @@ class OC_API { protected static function isV2(\OCP\IRequest $request) { $script = $request->getScriptName(); - return substr($script, -11) === '/ocs/v2.php'; + return str_ends_with($script, '/ocs/v2.php'); } /** @@ -171,7 +148,7 @@ class OC_API { ], ]; if ($format == 'json') { - return OC_JSON::encode($response); + return json_encode($response, JSON_HEX_TAG); } $writer = new XMLWriter(); diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ac449a62a4f..c9d1f86cb0e 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -1,69 +1,24 @@ <?php declare(strict_types=1); - /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Borjan Tchakaloff <borjan@tchakaloff.fr> - * @author Brice Maron <brice@bmaron.net> - * @author Christopher Schäpers <kondou@ts.unde.re> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Rudolf <github.com@daniel-rudolf.de> - * @author Frank Karlitschek <frank@karlitschek.de> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Jakob Sack <mail@jakobsack.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Haertl <jus@bitgrid.net> - * @author Julius Härtl <jus@bitgrid.net> - * @author Kamil Domanski <kdomanski@kdemail.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Markus Goetz <markus@woboq.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author RealRancor <Fisch.666@gmx.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Sam Tuke <mail@samtuke.com> - * @author Sebastian Wessalowski <sebastian@wessalowski.org> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - -use OCP\App\Events\AppUpdateEvent; -use OCP\App\IAppManager; -use OCP\App\ManagerEvent; -use OCP\Authentication\IAlternativeLogin; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; -use OC\AppFramework\Bootstrap\Coordinator; use OC\App\DependencyAnalyzer; use OC\App\Platform; +use OC\AppFramework\Bootstrap\Coordinator; use OC\DB\MigrationService; use OC\Installer; use OC\Repair; use OC\Repair\Events\RepairErrorEvent; +use OCP\App\Events\AppUpdateEvent; +use OCP\App\IAppManager; +use OCP\App\ManagerEvent; +use OCP\Authentication\IAlternativeLogin; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IAppConfig; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; @@ -117,6 +72,8 @@ class OC_App { * exists. * * if $types is set to non-empty array, only apps of those types will be loaded + * + * @deprecated 29.0.0 use IAppManager::loadApps instead */ public static function loadApps(array $types = []): bool { if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { @@ -252,7 +209,7 @@ class OC_App { * This function set an app as enabled in appconfig. */ public function enable(string $appId, - array $groups = []) { + array $groups = []) { // Check if app is already downloaded /** @var Installer $installer */ $installer = \OCP\Server::get(Installer::class); @@ -282,17 +239,15 @@ class OC_App { /** * Get the path where to install apps - * - * @return string|false */ - public static function getInstallPath() { + public static function getInstallPath(): string|null { foreach (OC::$APPSROOTS as $dir) { if (isset($dir['writable']) && $dir['writable'] === true) { return $dir['path']; } } - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR); + \OCP\Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']); return null; } @@ -354,7 +309,7 @@ class OC_App { * @param string $appId * @param bool $refreshAppPath should be set to true only during install/upgrade * @return string|false - * @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath() + * @deprecated 11.0.0 use \OCP\Server::get(IAppManager)->getAppPath() */ public static function getAppPath(string $appId, bool $refreshAppPath = false) { if ($appId === null || trim($appId) === '') { @@ -391,7 +346,7 @@ class OC_App { public static function getAppVersionByPath(string $path): string { $infoFile = $path . '/appinfo/info.xml'; $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); - return isset($appData['version']) ? $appData['version'] : ''; + return $appData['version'] ?? ''; } /** @@ -517,7 +472,7 @@ class OC_App { foreach (OC::$APPSROOTS as $apps_dir) { if (!is_readable($apps_dir['path'])) { - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); + \OCP\Server::get(LoggerInterface::class)->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']); continue; } $dh = opendir($apps_dir['path']); @@ -565,15 +520,15 @@ class OC_App { $supportedApps = $this->getSupportedApps(); foreach ($installedApps as $app) { - if (array_search($app, $blacklist) === false) { + if (!in_array($app, $blacklist)) { $info = $appManager->getAppInfo($app, false, $langCode); if (!is_array($info)) { - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); + \OCP\Server::get(LoggerInterface::class)->error('Could not read app info file for app "' . $app . '"', ['app' => 'core']); continue; } if (!isset($info['name'])) { - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); + \OCP\Server::get(LoggerInterface::class)->error('App id "' . $app . '" has no name in appinfo', ['app' => 'core']); continue; } @@ -731,8 +686,9 @@ class OC_App { static $versions; if (!$versions) { - $appConfig = \OC::$server->getAppConfig(); - $versions = $appConfig->getValues(false, 'installed_version'); + /** @var IAppConfig $appConfig */ + $appConfig = \OCP\Server::get(IAppConfig::class); + $versions = $appConfig->searchValues('installed_version'); } return $versions; } @@ -824,7 +780,7 @@ class OC_App { $dispatcher = \OC::$server->get(IEventDispatcher::class); // load the steps - $r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class)); + $r = \OCP\Server::get(Repair::class); foreach ($steps as $step) { try { $r->addStep($step); @@ -870,11 +826,11 @@ class OC_App { } return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); } else { - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); + \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ', user not logged in', ['app' => 'core']); return false; } } else { - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); + \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ' not enabled', ['app' => 'core']); return false; } } diff --git a/lib/private/legacy/OC_Defaults.php b/lib/private/legacy/OC_Defaults.php index ce89a642741..54640a892c9 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -1,40 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Haertl <jus@bitgrid.net> - * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Markus Staab <markus.staab@redaxo.de> - * @author Michael Weimann <mail@michael-weimann.eu> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Pascal de Bruijn <pmjdebruijn@pcode.nl> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author scolebrook <scolebrook@mac.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Volkan Gezer <volkangezer@gmail.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ class OC_Defaults { @@ -52,6 +21,7 @@ class OC_Defaults { private $defaultDocBaseUrl; private $defaultDocVersion; private $defaultSlogan; + private $defaultColorBackground; private $defaultColorPrimary; private $defaultTextColorPrimary; private $defaultProductName; @@ -70,7 +40,8 @@ class OC_Defaults { $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/'); $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links - $this->defaultColorPrimary = '#0082c9'; + $this->defaultColorBackground = '#00679e'; + $this->defaultColorPrimary = '#00679e'; $this->defaultTextColorPrimary = '#ffffff'; $this->defaultProductName = 'Nextcloud'; @@ -300,6 +271,17 @@ class OC_Defaults { } /** + * Returns primary color + * @return string + */ + public function getColorBackground() { + if ($this->themeExist('getColorBackground')) { + return $this->theme->getColorBackground(); + } + return $this->defaultColorBackground; + } + + /** * @return array scss variables to overwrite */ public function getScssVariables() { diff --git a/lib/private/legacy/OC_EventSource.php b/lib/private/legacy/OC_EventSource.php deleted file mode 100644 index cd72ba1f2d5..00000000000 --- a/lib/private/legacy/OC_EventSource.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -use OCP\IRequest; - -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christian Oliff <christianoliff@yahoo.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Felix Moeller <mail@felixmoeller.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @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/> - * - */ -class OC_EventSource implements \OCP\IEventSource { - /** - * @var bool - */ - private $fallback; - - /** - * @var int - */ - private $fallBackId = 0; - - /** - * @var bool - */ - private $started = false; - - private IRequest $request; - - public function __construct(IRequest $request) { - $this->request = $request; - } - - protected function init() { - if ($this->started) { - return; - } - $this->started = true; - - // prevent php output buffering, caching and nginx buffering - OC_Util::obEnd(); - header('Cache-Control: no-cache'); - header('X-Accel-Buffering: no'); - $this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true'; - if ($this->fallback) { - $this->fallBackId = (int)$_GET['fallback_id']; - /** - * FIXME: The default content-security-policy of ownCloud forbids inline - * JavaScript for security reasons. IE starting on Windows 10 will - * however also obey the CSP which will break the event source fallback. - * - * As a workaround thus we set a custom policy which allows the execution - * of inline JavaScript. - * - * @link https://github.com/owncloud/core/issues/14286 - */ - header("Content-Security-Policy: default-src 'none'; script-src 'unsafe-inline'"); - header("Content-Type: text/html"); - echo str_repeat('<span></span>' . PHP_EOL, 10); //dummy data to keep IE happy - } else { - header("Content-Type: text/event-stream"); - } - if (!$this->request->passesStrictCookieCheck()) { - header('Location: '.\OC::$WEBROOT); - exit(); - } - if (!$this->request->passesCSRFCheck()) { - $this->send('error', 'Possible CSRF attack. Connection will be closed.'); - $this->close(); - exit(); - } - flush(); - } - - /** - * send a message to the client - * - * @param string $type - * @param mixed $data - * - * @throws \BadMethodCallException - * if only one parameter is given, a typeless message will be send with that parameter as data - * @suppress PhanDeprecatedFunction - */ - public function send($type, $data = null) { - if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) { - throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')'); - } - $this->init(); - if (is_null($data)) { - $data = $type; - $type = null; - } - if ($this->fallback) { - $response = '<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack(' - . $this->fallBackId . ',"' . $type . '",' . OC_JSON::encode($data) . ')</script>' . PHP_EOL; - echo $response; - } else { - if ($type) { - echo 'event: ' . $type . PHP_EOL; - } - echo 'data: ' . OC_JSON::encode($data) . PHP_EOL; - } - echo PHP_EOL; - flush(); - } - - /** - * close the connection of the event source - */ - public function close() { - $this->send('__internal__', 'close'); //server side closing can be an issue, let the client do it - } -} diff --git a/lib/private/legacy/OC_FileChunking.php b/lib/private/legacy/OC_FileChunking.php index 58bdd0af3d0..7600d810657 100644 --- a/lib/private/legacy/OC_FileChunking.php +++ b/lib/private/legacy/OC_FileChunking.php @@ -1,32 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Felix Moeller <mail@felixmoeller.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ class OC_FileChunking { protected $info; diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index 7bc1fab94b6..76d61a98558 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -1,52 +1,18 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Calviño Sánchez <danxuliu@gmail.com> - * @author Frank Karlitschek <frank@karlitschek.de> - * @author Jakob Sack <mail@jakobsack.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Ko- <k.stoffelen@cs.ru.nl> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Nicolai Ehemann <en@enlightened.de> - * @author Piotr Filiciak <piotr@filiciak.pl> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thibaut GRIDEL <tgridel@free.fr> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Valdnet <47037905+Valdnet@users.noreply.github.com> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\View; use OC\Streamer; -use OCP\Lock\ILockingProvider; -use OCP\Files\Events\BeforeZipCreatedEvent; -use OCP\Files\Events\BeforeDirectFileDownloadEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\BeforeDirectFileDownloadEvent; +use OCP\Files\Events\BeforeZipCreatedEvent; +use OCP\Files\IRootFolder; +use OCP\Lock\ILockingProvider; /** * Class for file server access @@ -76,7 +42,6 @@ class OC_Files { private static function sendHeaders($filename, $name, array $rangeArray): void { OC_Response::setContentDispositionHeader($name, 'attachment'); header('Content-Transfer-Encoding: binary', true); - header('Pragma: public');// enable caching in IE header('Expires: 0'); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $fileSize = \OC\Files\Filesystem::filesize($filename); @@ -87,7 +52,7 @@ class OC_Files { header('Accept-Ranges: bytes', true); if (count($rangeArray) > 1) { $type = 'multipart/byteranges; boundary='.self::getBoundary(); - // no Content-Length header here + // no Content-Length header here } else { header(sprintf('Content-Range: bytes %d-%d/%d', $rangeArray[0]['from'], $rangeArray[0]['to'], $fileSize), true); OC_Response::setContentLengthHeader($rangeArray[0]['to'] - $rangeArray[0]['from'] + 1); @@ -104,7 +69,7 @@ class OC_Files { * return the content of a file or return a zip file containing multiple files * * @param string $dir - * @param string $files ; separated list of files to download + * @param string|array $files ; separated list of files to download * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header */ public static function get($dir, $files, $params = null) { @@ -188,7 +153,7 @@ class OC_Files { foreach ($files as $file) { $file = $dir . '/' . $file; if (\OC\Files\Filesystem::is_file($file)) { - $userFolder = \OC::$server->getRootFolder()->get(\OC\Files\Filesystem::getRoot()); + $userFolder = \OC::$server->get(IRootFolder::class)->get(\OC\Files\Filesystem::getRoot()); $file = $userFolder->get($file); if ($file instanceof \OC\Files\Node\File) { try { @@ -230,6 +195,10 @@ class OC_Files { OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('lib'); \OC_Template::printErrorPage($l->t('Cannot download file'), $ex->getMessage(), 200); + } catch (\OCP\Files\ConnectionLostException $ex) { + self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); + OC::$server->getLogger()->logException($ex, ['level' => \OCP\ILogger::DEBUG]); + \OC_Template::printErrorPage('Connection lost', $ex->getMessage(), 200); } catch (\Exception $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); @@ -304,7 +273,7 @@ class OC_Files { $file = null; try { - $userFolder = \OC::$server->getRootFolder()->get(\OC\Files\Filesystem::getRoot()); + $userFolder = \OC::$server->get(IRootFolder::class)->get(\OC\Files\Filesystem::getRoot()); $file = $userFolder->get($filename); if (!$file instanceof \OC\Files\Node\File || !$file->isReadable()) { http_response_code(403); diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index cf39d045ae9..0c913709111 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -1,53 +1,15 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Ardinis <Ardinis@users.noreply.github.com> - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Felix Moeller <mail@felixmoeller.de> - * @author J0WI <J0WI@users.noreply.github.com> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Olivier Paroz <github@oparoz.com> - * @author Pellaeon Lin <nfsmwlin@gmail.com> - * @author RealRancor <fisch.666@gmx.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Simon Könnecke <simonkoennecke@gmail.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\Filesystem; use OCP\Files\Mount\IMountPoint; -use OCP\ICacheFactory; use OCP\IBinaryFinder; +use OCP\ICacheFactory; use OCP\IUser; use OCP\Util; use Psr\Log\LoggerInterface; @@ -138,7 +100,7 @@ class OC_Helper { $bytes = (float)$str; - if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { + if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && isset($bytes_array[$matches[1]])) { $bytes *= $bytes_array[$matches[1]]; } else { return false; @@ -596,6 +558,11 @@ class OC_Helper { 'mountPoint' => trim($mountPoint, '/'), ]; + if ($ownerId && $path === '/') { + // If path is root, store this as last known quota usage for this user + \OCP\Server::get(\OCP\IConfig::class)->setUserValue($ownerId, 'files', 'lastSeenQuotaUsage', (string)$relative); + } + $memcache->set($cacheKey, $info, 5 * 60); return $info; diff --git a/lib/private/legacy/OC_Hook.php b/lib/private/legacy/OC_Hook.php index a7a0f755673..2f6686f9126 100644 --- a/lib/private/legacy/OC_Hook.php +++ b/lib/private/legacy/OC_Hook.php @@ -1,32 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Sam Tuke <mail@samtuke.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ class OC_Hook { public static $thrownExceptions = []; diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php index aac0c496734..cc6968839d4 100644 --- a/lib/private/legacy/OC_Image.php +++ b/lib/private/legacy/OC_Image.php @@ -1,47 +1,10 @@ <?php declare(strict_types=1); - /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bartek Przybylski <bart.p.pl@gmail.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Byron Marohn <combustible@live.com> - * @author Côme Chilliet <come.chilliet@nextcloud.com> - * @author Christopher Schäpers <kondou@ts.unde.re> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author J0WI <J0WI@users.noreply.github.com> - * @author j-ed <juergen@eisfair.org> - * @author Joas Schilling <coding@schilljs.com> - * @author Johannes Willnecker <johannes@willnecker.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Olivier Paroz <github@oparoz.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Samuel CHEMLA <chemla.samuel@gmail.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ use OCP\IImage; @@ -55,7 +18,10 @@ class OC_Image implements \OCP\IImage { // Default quality for jpeg images protected const DEFAULT_JPEG_QUALITY = 80; - /** @var false|resource|\GdImage */ + // Default quality for webp images + protected const DEFAULT_WEBP_QUALITY = 80; + + /** @var false|\GdImage */ protected $resource = false; // tmp resource. /** @var int */ protected $imageType = IMAGETYPE_PNG; // Default to png if file type isn't evident. @@ -63,25 +29,25 @@ class OC_Image implements \OCP\IImage { protected $mimeType = 'image/png'; // Default to png /** @var null|string */ protected $filePath = null; - /** @var finfo */ - private $fileInfo; + /** @var ?finfo */ + private $fileInfo = null; /** @var \OCP\ILogger */ private $logger; /** @var \OCP\IConfig */ private $config; - /** @var array */ - private $exif; + /** @var ?array */ + private $exif = null; /** * Constructor. * - * @param resource|string|\GdImage $imageRef The path to a local file, a base64 encoded string or a resource created by - * an imagecreate* function. + * @param mixed $imageRef Deprecated, should be null + * @psalm-assert null $imageRef * @param \OCP\ILogger $logger * @param \OCP\IConfig $config * @throws \InvalidArgumentException in case the $imageRef parameter is not null */ - public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\IConfig $config = null) { + public function __construct($imageRef = null, ?\OCP\ILogger $logger = null, ?\OCP\IConfig $config = null) { $this->logger = $logger; if ($logger === null) { $this->logger = \OC::$server->getLogger(); @@ -103,11 +69,11 @@ class OC_Image implements \OCP\IImage { /** * Determine whether the object contains an image resource. * + * @psalm-assert-if-true \GdImage $this->resource * @return bool */ public function valid(): bool { - if ((is_resource($this->resource) && get_resource_type($this->resource) === 'gd') || - (is_object($this->resource) && get_class($this->resource) === \GdImage::class)) { + if (is_object($this->resource) && get_class($this->resource) === \GdImage::class) { return true; } @@ -130,10 +96,7 @@ class OC_Image implements \OCP\IImage { */ public function width(): int { if ($this->valid()) { - $width = imagesx($this->resource); - if ($width !== false) { - return $width; - } + return imagesx($this->resource); } return -1; } @@ -145,10 +108,7 @@ class OC_Image implements \OCP\IImage { */ public function height(): int { if ($this->valid()) { - $height = imagesy($this->resource); - if ($height !== false) { - return $height; - } + return imagesy($this->resource); } return -1; } @@ -207,7 +167,7 @@ class OC_Image implements \OCP\IImage { * @param string $mimeType * @return bool */ - public function show(string $mimeType = null): bool { + public function show(?string $mimeType = null): bool { if ($mimeType === null) { $mimeType = $this->mimeType(); } @@ -283,6 +243,9 @@ class OC_Image implements \OCP\IImage { case 'image/x-ms-bmp': $imageType = IMAGETYPE_BMP; break; + case 'image/webp': + $imageType = IMAGETYPE_WEBP; + break; default: throw new Exception('\OC_Image::_output(): "' . $mimeType . '" is not supported when forcing a specific output format'); } @@ -293,8 +256,7 @@ class OC_Image implements \OCP\IImage { $retVal = imagegif($this->resource, $filePath); break; case IMAGETYPE_JPEG: - /** @psalm-suppress InvalidScalarArgument */ - imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1)); + imageinterlace($this->resource, true); $retVal = imagejpeg($this->resource, $filePath, $this->getJpegQuality()); break; case IMAGETYPE_PNG: @@ -314,6 +276,9 @@ class OC_Image implements \OCP\IImage { case IMAGETYPE_BMP: $retVal = imagebmp($this->resource, $filePath); break; + case IMAGETYPE_WEBP: + $retVal = imagewebp($this->resource, null, $this->getWebpQuality()); + break; default: $retVal = imagepng($this->resource, $filePath); } @@ -328,25 +293,14 @@ class OC_Image implements \OCP\IImage { } /** - * @param resource|\GdImage $resource - * @throws \InvalidArgumentException in case the supplied resource does not have the type "gd" + * @param \GdImage $resource */ - public function setResource($resource) { - // For PHP<8 - if (is_resource($resource) && get_resource_type($resource) === 'gd') { - $this->resource = $resource; - return; - } - // PHP 8 has real objects for GD stuff - if (is_object($resource) && get_class($resource) === \GdImage::class) { - $this->resource = $resource; - return; - } - throw new \InvalidArgumentException('Supplied resource is not of type "gd".'); + public function setResource(\GdImage $resource): void { + $this->resource = $resource; } /** - * @return false|resource|\GdImage Returns the image resource if any + * @return false|\GdImage Returns the image resource if any */ public function resource() { return $this->resource; @@ -364,6 +318,7 @@ class OC_Image implements \OCP\IImage { case 'image/png': case 'image/jpeg': case 'image/gif': + case 'image/webp': return $this->mimeType; default: return 'image/png'; @@ -383,14 +338,16 @@ class OC_Image implements \OCP\IImage { $res = imagepng($this->resource); break; case "image/jpeg": - /** @psalm-suppress InvalidScalarArgument */ - imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1)); + imageinterlace($this->resource, true); $quality = $this->getJpegQuality(); $res = imagejpeg($this->resource, null, $quality); break; case "image/gif": $res = imagegif($this->resource); break; + case "image/webp": + $res = imagewebp($this->resource, null, $this->getWebpQuality()); + break; default: $res = imagepng($this->resource); $this->logger->info('OC_Image->data. Could not guess mime-type, defaulting to png', ['app' => 'core']); @@ -405,7 +362,7 @@ class OC_Image implements \OCP\IImage { /** * @return string - base64 encoded, which is suitable for embedding in a VCard. */ - public function __toString() { + public function __toString(): string { return base64_encode($this->data()); } @@ -422,6 +379,18 @@ class OC_Image implements \OCP\IImage { } /** + * @return int + */ + protected function getWebpQuality(): int { + $quality = $this->config->getAppValue('preview', 'webp_quality', (string) self::DEFAULT_WEBP_QUALITY); + // TODO: remove when getAppValue is type safe + if ($quality === null) { + $quality = self::DEFAULT_WEBP_QUALITY; + } + return min(100, max(10, (int) $quality)); + } + + /** * (I'm open for suggestions on better method name ;) * Get the orientation based on EXIF data. * @@ -558,7 +527,7 @@ class OC_Image implements \OCP\IImage { * It is the responsibility of the caller to position the pointer at the correct place and to close the handle again. * * @param resource $handle - * @return resource|\GdImage|false An image resource or false on error + * @return \GdImage|false An image resource or false on error */ public function loadFromFileHandle($handle) { $contents = stream_get_contents($handle); @@ -637,7 +606,7 @@ class OC_Image implements \OCP\IImage { * Loads an image from a local file. * * @param bool|string $imagePath The path to a local file. - * @return bool|resource|\GdImage An image resource or false on error + * @return bool|\GdImage An image resource or false on error */ public function loadFromFile($imagePath = false) { // exif_imagetype throws "read error!" if file is less than 12 byte @@ -775,7 +744,7 @@ class OC_Image implements \OCP\IImage { * Loads an image from a string of data. * * @param string $str A string of image data as read from a file. - * @return bool|resource|\GdImage An image resource or false on error + * @return bool|\GdImage An image resource or false on error */ public function loadFromData(string $str) { if (!$this->checkImageDataSize($str)) { @@ -801,7 +770,7 @@ class OC_Image implements \OCP\IImage { * Loads an image from a base64 encoded string. * * @param string $str A string base64 encoded string of image data. - * @return bool|resource|\GdImage An image resource or false on error + * @return bool|\GdImage An image resource or false on error */ public function loadFromBase64(string $str) { $data = base64_decode($str); @@ -842,7 +811,7 @@ class OC_Image implements \OCP\IImage { /** * @param $maxSize - * @return resource|bool|\GdImage + * @return bool|\GdImage */ private function resizeNew(int $maxSize) { if (!$this->valid()) { @@ -883,7 +852,7 @@ class OC_Image implements \OCP\IImage { /** * @param int $width * @param int $height - * @return resource|bool|\GdImage + * @return bool|\GdImage */ public function preciseResizeNew(int $width, int $height) { if (!($width > 0) || !($height > 0)) { @@ -959,13 +928,13 @@ class OC_Image implements \OCP\IImage { // preserve transparency if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) { - imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127) ?: null); imagealphablending($process, false); imagesavealpha($process, true); } - imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); - if ($process === false) { + $result = imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); + if ($result === false) { $this->logger->debug('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, ['app' => 'core']); return false; } @@ -1001,7 +970,7 @@ class OC_Image implements \OCP\IImage { * @param int $y Vertical position * @param int $w Width * @param int $h Height - * @return resource|\GdImage|false + * @return \GdImage|false */ public function cropNew(int $x, int $y, int $w, int $h) { if (!$this->valid()) { @@ -1016,13 +985,13 @@ class OC_Image implements \OCP\IImage { // preserve transparency if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) { - imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127) ?: null); imagealphablending($process, false); imagesavealpha($process, true); } - imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h); - if ($process === false) { + $result = imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h); + if ($result === false) { $this->logger->debug(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, ['app' => 'core']); return false; } @@ -1141,7 +1110,7 @@ if (!function_exists('exif_imagetype')) { * * @link https://www.php.net/manual/en/function.exif-imagetype.php#80383 * @param string $fileName - * @return string|boolean + * @return int|false */ function exif_imagetype(string $fileName) { if (($info = getimagesize($fileName)) !== false) { diff --git a/lib/private/legacy/OC_JSON.php b/lib/private/legacy/OC_JSON.php index b9cfb8210e0..a9682e2cce7 100644 --- a/lib/private/legacy/OC_JSON.php +++ b/lib/private/legacy/OC_JSON.php @@ -1,32 +1,13 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ + +use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; + class OC_JSON { /** * Check if the app is enabled, send json error msg if not @@ -48,7 +29,7 @@ class OC_JSON { * @suppress PhanDeprecatedFunction */ public static function checkLoggedIn() { - $twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager(); + $twoFactorAuthManger = \OC::$server->get(TwoFactorAuthManager::class); if (!\OC::$server->getUserSession()->isLoggedIn() || $twoFactorAuthManger->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { $l = \OC::$server->getL10N('lib'); @@ -114,22 +95,10 @@ class OC_JSON { } /** - * Convert OC_L10N_String to string, for use in json encodings - */ - protected static function to_string(&$value) { - if ($value instanceof \OC\L10N\L10NString) { - $value = (string)$value; - } - } - - /** * Encode JSON * @deprecated Use a AppFramework JSONResponse instead */ - public static function encode($data) { - if (is_array($data)) { - array_walk_recursive($data, ['OC_JSON', 'to_string']); - } + private static function encode($data) { return json_encode($data, JSON_HEX_TAG); } } diff --git a/lib/private/legacy/OC_Response.php b/lib/private/legacy/OC_Response.php index 9440feae3cd..8c8890c74c4 100644 --- a/lib/private/legacy/OC_Response.php +++ b/lib/private/legacy/OC_Response.php @@ -1,31 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andreas Fischer <bantu@owncloud.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author J0WI <J0WI@users.noreply.github.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ class OC_Response { /** diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 974f26fa381..5caa733b115 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -1,44 +1,14 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Brice Maron <brice@bmaron.net> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Frank Karlitschek <frank@karlitschek.de> - * @author Individual IT Services <info@individual-it.net> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Marin Treselj <marin@pixelipo.com> - * @author Michael Letzgus <www@chronos.michael-letzgus.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ use OC\TemplateLayout; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\TemplateResponse; +use OCP\EventDispatcher\IEventDispatcher; require_once __DIR__.'/template/functions.php'; @@ -249,20 +219,44 @@ class OC_Template extends \OC\Template\Base { // If the hint is the same as the message there is no need to display it twice. $hint = ''; } + $errors = [['error' => $error_msg, 'hint' => $hint]]; http_response_code($statusCode); try { - $content = new \OC_Template('', 'error', 'error', false); - $errors = [['error' => $error_msg, 'hint' => $hint]]; - $content->assign('errors', $errors); - $content->printPage(); - } catch (\Exception $e) { + // Try rendering themed html error page + $response = new TemplateResponse( + '', + 'error', + ['errors' => $errors], + TemplateResponse::RENDER_AS_ERROR, + $statusCode, + ); + $event = new BeforeTemplateRenderedEvent(false, $response); + \OC::$server->get(IEventDispatcher::class)->dispatchTyped($event); + print($response->render()); + } catch (\Throwable $e1) { $logger = \OC::$server->getLogger(); - $logger->error("$error_msg $hint", ['app' => 'core']); - $logger->logException($e, ['app' => 'core']); + $logger->logException($e1, [ + 'app' => 'core', + 'message' => 'Rendering themed error page failed. Falling back to unthemed error page.' + ]); - header('Content-Type: text/plain; charset=utf-8'); - print("$error_msg $hint"); + try { + // Try rendering unthemed html error page + $content = new \OC_Template('', 'error', 'error', false); + $content->assign('errors', $errors); + $content->printPage(); + } catch (\Exception $e2) { + // If nothing else works, fall back to plain text error page + $logger->error("$error_msg $hint", ['app' => 'core']); + $logger->logException($e2, [ + 'app' => 'core', + 'message' => 'Rendering unthemed error page failed. Falling back to plain text error page.' + ]); + + header('Content-Type: text/plain; charset=utf-8'); + print("$error_msg $hint"); + } } die(); } @@ -275,8 +269,11 @@ class OC_Template extends \OC\Template\Base { * @suppress PhanAccessMethodInternal */ public static function printExceptionErrorPage($exception, $statusCode = 503) { + $debug = false; http_response_code($statusCode); try { + $debug = \OC::$server->getSystemConfig()->getValue('debug', false); + $serverLogsDocumentation = \OC::$server->getSystemConfig()->getValue('documentation_url.server_logs', ''); $request = \OC::$server->getRequest(); $content = new \OC_Template('', 'exception', 'error', false); $content->assign('errorClass', get_class($exception)); @@ -285,7 +282,8 @@ class OC_Template extends \OC\Template\Base { $content->assign('file', $exception->getFile()); $content->assign('line', $exception->getLine()); $content->assign('exception', $exception); - $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); + $content->assign('debugMode', $debug); + $content->assign('serverLogsDocumentation', $serverLogsDocumentation); $content->assign('remoteAddr', $request->getRemoteAddress()); $content->assign('requestID', $request->getId()); $content->printPage(); @@ -296,22 +294,28 @@ class OC_Template extends \OC\Template\Base { $logger->logException($e, ['app' => 'core']); } catch (Throwable $e) { // no way to log it properly - but to avoid a white page of death we send some output - header('Content-Type: text/plain; charset=utf-8'); - print("Internal Server Error\n\n"); - print("The server encountered an internal error and was unable to complete your request.\n"); - print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); - print("More details can be found in the server log.\n"); + self::printPlainErrorPage($e, $debug); // and then throw it again to log it at least to the web server error log throw $e; } - header('Content-Type: text/plain; charset=utf-8'); - print("Internal Server Error\n\n"); - print("The server encountered an internal error and was unable to complete your request.\n"); - print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); - print("More details can be found in the server log.\n"); + self::printPlainErrorPage($e, $debug); } die(); } + + private static function printPlainErrorPage(\Throwable $exception, bool $debug = false) { + header('Content-Type: text/plain; charset=utf-8'); + print("Internal Server Error\n\n"); + print("The server encountered an internal error and was unable to complete your request.\n"); + print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); + print("More details can be found in the server log.\n"); + + if ($debug) { + print("\n"); + print($exception->getMessage() . ' ' . $exception->getFile() . ' at ' . $exception->getLine() . "\n"); + print($exception->getTraceAsString()); + } + } } diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index caa4f5dca65..e7708525c76 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -1,47 +1,20 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Aldo "xoen" Giambelluca <xoen@xoen.org> - * @author Andreas Fischer <bantu@owncloud.com> - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Bartek Przybylski <bart.p.pl@gmail.com> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author shkdee <louis.traynard@m4x.org> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - use OC\User\LoginException; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; +use OCP\IGroupManager; +use OCP\ISession; +use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use OCP\User\Events\BeforeUserLoggedInEvent; use OCP\User\Events\UserLoggedInEvent; +use Psr\Log\LoggerInterface; /** * This class provides wrapper methods for user management. Multiple backends are @@ -84,7 +57,7 @@ class OC_User { \OC::$server->getUserManager()->registerBackend($backend); } else { // You'll never know what happens - if (null === $backend or !is_string($backend)) { + if ($backend === null or !is_string($backend)) { $backend = 'database'; } @@ -93,7 +66,7 @@ class OC_User { case 'database': case 'mysql': case 'sqlite': - \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG); + Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']); self::$_usedBackends[$backend] = new \OC\User\Database(); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); break; @@ -102,7 +75,7 @@ class OC_User { \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); break; default: - \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG); + Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']); $className = 'OC_USER_' . strtoupper($backend); self::$_usedBackends[$backend] = new $className(); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); @@ -138,7 +111,7 @@ class OC_User { $class = $config['class']; $arguments = $config['arguments']; if (class_exists($class)) { - if (array_search($i, self::$_setupedBackends) === false) { + if (!in_array($i, self::$_setupedBackends)) { // make a reflection object $reflectionObj = new ReflectionClass($class); @@ -147,10 +120,10 @@ class OC_User { self::useBackend($backend); self::$_setupedBackends[] = $i; } else { - \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG); + Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']); } } else { - \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR); + Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']); } } } @@ -178,7 +151,7 @@ class OC_User { $dispatcher = \OC::$server->get(IEventDispatcher::class); if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) { - $message = \OC::$server->getL10N('lib')->t('User disabled'); + $message = \OC::$server->getL10N('lib')->t('Account disabled'); throw new LoginException($message); } $userSession->setLoginName($uid); @@ -303,7 +276,7 @@ class OC_User { } $user = \OC::$server->getUserSession()->getUser(); - if ($user instanceof \OCP\IUser) { + if ($user instanceof IUser) { $backend = $user->getBackend(); if ($backend instanceof \OCP\User\Backend\ICustomLogout) { return $backend->getLogoutUrl(); @@ -323,12 +296,9 @@ class OC_User { * @return bool */ public static function isAdminUser($uid) { - $group = \OC::$server->getGroupManager()->get('admin'); - $user = \OC::$server->getUserManager()->get($uid); - if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) { - return true; - } - return false; + $user = Server::get(IUserManager::class)->get($uid); + $isAdmin = $user && Server::get(IGroupManager::class)->isAdmin($user->getUID()); + return $isAdmin && self::$incognitoMode === false; } @@ -338,7 +308,7 @@ class OC_User { * @return string|false uid or false */ public static function getUser() { - $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null; + $uid = Server::get(ISession::class)?->get('user_id'); if (!is_null($uid) && self::$incognitoMode === false) { return $uid; } else { diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index a0575c4bef3..d81589ea8e6 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -1,70 +1,12 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Birk Borkason <daniel.niccoli@gmail.com> - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Brice Maron <brice@bmaron.net> - * @author Christopher Schäpers <kondou@ts.unde.re> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Clark Tomlinson <fallen013@gmail.com> - * @author cmeh <cmeh@users.noreply.github.com> - * @author Eric Masseran <rico.masseran@gmail.com> - * @author Felix Epp <work@felixepp.de> - * @author Florin Peter <github@florin-peter.de> - * @author Frank Karlitschek <frank@karlitschek.de> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author helix84 <helix84@centrum.sk> - * @author Ilja Neumann <ineumann@owncloud.com> - * @author Individual IT Services <info@individual-it.net> - * @author Jakob Sack <mail@jakobsack.de> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Kawohl <john@owncloud.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Markus Goetz <markus@woboq.com> - * @author Martin Mattel <martin.mattel@diemattels.at> - * @author Marvin Thomas Rabe <mrabe@marvinrabe.de> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author rakekniven <mark.ziegler@rakekniven.de> - * @author Robert Dailey <rcdailey@gmail.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Sebastian Wessalowski <sebastian@wessalowski.org> - * @author Stefan Rado <owncloud@sradonia.net> - * @author Stefan Weil <sw@weilnetz.de> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * @author Valdnet <47037905+Valdnet@users.noreply.github.com> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @author Vincent Petry <vincent@nextcloud.com> - * @author Volkan Gezer <volkangezer@gmail.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - use bantu\IniGetWrapper\IniGetWrapper; +use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; use OC\Files\SetupManager; use OCP\Files\Template\ITemplateManager; use OCP\IConfig; @@ -326,9 +268,10 @@ class OC_Util { return; } + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); require OC::$SERVERROOT . '/version.php'; /** @var int $timestamp */ - self::$versionCache['OC_Version_Timestamp'] = \OC::$VERSION_MTIME; + self::$versionCache['OC_Version_Timestamp'] = $timestamp; /** @var string $OC_Version */ self::$versionCache['OC_Version'] = $OC_Version; /** @var string $OC_VersionString */ @@ -513,15 +456,7 @@ class OC_Util { } $webServerRestart = false; - $setup = new \OC\Setup( - $config, - \OC::$server->get(IniGetWrapper::class), - \OC::$server->getL10N('lib'), - \OC::$server->get(\OCP\Defaults::class), - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(ISecureRandom::class), - \OC::$server->get(\OC\Installer::class) - ); + $setup = \OCP\Server::get(\OC\Setup::class); $urlGenerator = \OC::$server->getURLGenerator(); @@ -740,8 +675,8 @@ class OC_Util { if ($perms[2] !== '0') { $l = \OC::$server->getL10N('lib'); return [[ - 'error' => $l->t('Your data directory is readable by other users.'), - 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), + 'error' => $l->t('Your data directory is readable by other people.'), + 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other people.'), ]]; } } @@ -793,7 +728,7 @@ class OC_Util { exit(); } // Redirect to 2FA challenge selection if 2FA challenge was not solved yet - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { + if (\OC::$server->get(TwoFactorAuthManager::class)->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); exit(); } @@ -977,11 +912,11 @@ class OC_Util { */ private static function isNonUTF8Locale() { if (function_exists('escapeshellcmd')) { - return '' === escapeshellcmd('§'); + return escapeshellcmd('§') === ''; } elseif (function_exists('escapeshellarg')) { - return '\'\'' === escapeshellarg('§'); + return escapeshellarg('§') === '\'\''; } else { - return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0)); + return preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0)) === 0; } } @@ -1120,8 +1055,8 @@ class OC_Util { return false; } - foreach (str_split($trimmed) as $char) { - if (str_contains(\OCP\Constants::FILENAME_INVALID_CHARS, $char)) { + foreach (\OCP\Util::getForbiddenFileNameChars() as $char) { + if (str_contains($trimmed, $char)) { return false; } } diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php index bcc0906dcdf..84ada2aa6d8 100644 --- a/lib/private/legacy/template/functions.php +++ b/lib/private/legacy/template/functions.php @@ -1,39 +1,12 @@ <?php -use OCP\Util; - /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Michael Letzgus <www@chronos.michael-letzgus.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ +use OCP\Util; + function p($string) { print(\OCP\Util::sanitizeHTML($string)); } |