From 4236a9a1059411c1d6483f772af30322ce713f0e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 29 Oct 2021 23:21:07 +0000 Subject: [PATCH 1/8] Improved http error handling --- bin/auth_ejabberd.php | 5 ++- bin/console.php | 5 ++- bin/daemon.php | 5 ++- bin/testargs.php | 5 ++- bin/wait-for-connection | 5 ++- bin/worker.php | 5 ++- include/api.php | 2 - src/App/Module.php | 4 +- src/Core/Cache/TraitMemcacheCommand.php | 8 ++-- src/Core/Renderer.php | 18 ++++----- src/Core/System.php | 39 +++++++++++-------- src/Database/Database.php | 4 +- src/Factory/Api/Mastodon/Application.php | 6 +-- src/Module/Admin/Summary.php | 7 ++-- src/Module/Diaspora/Receive.php | 4 +- src/Module/Friendica.php | 1 + src/Module/Photo.php | 4 +- src/Module/Proxy.php | 4 +- src/Module/Special/HTTPException.php | 37 ++++-------------- src/Network/CurlResult.php | 9 ++--- src/Network/HTTPException.php | 8 +--- .../HTTPException/AcceptedException.php | 1 + .../HTTPException/BadGatewayException.php | 4 +- .../HTTPException/BadRequestException.php | 4 +- .../HTTPException/ConflictException.php | 4 +- .../ExpectationFailedException.php | 4 +- .../HTTPException/ForbiddenException.php | 4 +- src/Network/HTTPException/FoundException.php | 30 ++++++++++++++ .../HTTPException/GatewayTimeoutException.php | 4 +- src/Network/HTTPException/GoneException.php | 4 +- .../HTTPException/ImATeapotException.php | 5 ++- .../InternalServerErrorException.php | 4 +- .../HTTPException/LenghtRequiredException.php | 4 +- .../MethodNotAllowedException.php | 4 +- .../HTTPException/MovedPermanently.php | 30 ++++++++++++++ .../HTTPException/NoContentException.php | 1 + .../HTTPException/NonAcceptableException.php | 4 +- .../HTTPException/NotFoundException.php | 4 +- .../HTTPException/NotImplementedException.php | 4 +- .../HTTPException/NotModifiedException.php | 30 ++++++++++++++ src/Network/HTTPException/OKException.php | 1 + .../PreconditionFailedException.php | 4 +- .../ServiceUnavailableException.php | 4 +- .../TemporaryRedirectException.php | 30 ++++++++++++++ .../TooManyRequestsException.php | 4 +- .../HTTPException/UnauthorizedException.php | 4 +- .../UnprocessableEntityException.php | 4 +- .../UnsupportedMediaTypeException.php | 4 +- src/Render/FriendicaSmartyEngine.php | 4 +- src/Util/EMailer/MailBuilder.php | 8 ++-- src/Util/HTTPSignature.php | 2 +- src/Util/Network.php | 4 +- src/Worker/Notifier.php | 2 +- view/theme/frio/style.php | 4 +- view/theme/vier/style.php | 4 +- 55 files changed, 282 insertions(+), 135 deletions(-) create mode 100644 src/Network/HTTPException/FoundException.php create mode 100644 src/Network/HTTPException/MovedPermanently.php create mode 100644 src/Network/HTTPException/NotModifiedException.php create mode 100644 src/Network/HTTPException/TemporaryRedirectException.php diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 88e5d034cb..fd1b40cc84 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -51,9 +51,10 @@ * */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } use Dice\Dice; diff --git a/bin/console.php b/bin/console.php index 35f0b5feef..edfb8cd285 100755 --- a/bin/console.php +++ b/bin/console.php @@ -20,9 +20,10 @@ * */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } use Dice\Dice; diff --git a/bin/daemon.php b/bin/daemon.php index 7d4945fe03..965c495ecd 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -23,9 +23,10 @@ * This script was taken from http://php.net/manual/en/function.pcntl-fork.php */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } use Dice\Dice; diff --git a/bin/testargs.php b/bin/testargs.php index 55197f63a3..05826f2e42 100644 --- a/bin/testargs.php +++ b/bin/testargs.php @@ -26,9 +26,10 @@ * */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) { diff --git a/bin/wait-for-connection b/bin/wait-for-connection index f0fd8cc60f..35560feb2a 100755 --- a/bin/wait-for-connection +++ b/bin/wait-for-connection @@ -24,9 +24,10 @@ * Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}] */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } $timeout = 60; diff --git a/bin/worker.php b/bin/worker.php index 2fe03cb4b2..a39d049632 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -21,9 +21,10 @@ * Starts the background processing */ +use Friendica\Network\HTTPException\ForbiddenException; + if (php_sapi_name() !== 'cli') { - header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); - exit(); + throw new ForbiddenException(); } use Dice\Dice; diff --git a/include/api.php b/include/api.php index 22a6ee4321..fc73ae8500 100644 --- a/include/api.php +++ b/include/api.php @@ -246,8 +246,6 @@ function api_login(App $a) if (!DBA::isResult($record)) { Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); header('WWW-Authenticate: Basic realm="Friendica"'); - //header('HTTP/1.0 401 Unauthorized'); - //die('This api requires login'); throw new UnauthorizedException("This API requires login"); } diff --git a/src/App/Module.php b/src/App/Module.php index f15b1236e8..a5fddb2064 100644 --- a/src/App/Module.php +++ b/src/App/Module.php @@ -29,6 +29,7 @@ use Friendica\Module\Home; use Friendica\Module\HTTPException\MethodNotAllowed; use Friendica\Module\HTTPException\PageNotFound; use Friendica\Network\HTTPException\MethodNotAllowedException; +use Friendica\Network\HTTPException\NoContentException; use Friendica\Network\HTTPException\NotFoundException; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -291,9 +292,8 @@ class Module // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS // @todo Check allowed methods per requested path if ($server['REQUEST_METHOD'] === Router::OPTIONS) { - header('HTTP/1.1 204 No Content'); header('Allow: ' . implode(',', Router::ALLOWED_METHODS)); - exit(); + throw new NoContentException(); } $placeholder = ''; diff --git a/src/Core/Cache/TraitMemcacheCommand.php b/src/Core/Cache/TraitMemcacheCommand.php index abc41ceeae..3eaae2c159 100644 --- a/src/Core/Cache/TraitMemcacheCommand.php +++ b/src/Core/Cache/TraitMemcacheCommand.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Cache; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\ServiceUnavailableException; /** * Trait for Memcache to add a custom version of the @@ -52,7 +52,7 @@ trait TraitMemcacheCommand * * @return array All keys of the memcache instance * - * @throws InternalServerErrorException + * @throws ServiceUnavailableException */ protected function getMemcacheKeys() { @@ -88,13 +88,13 @@ trait TraitMemcacheCommand * * @return string The returned buffer result * - * @throws InternalServerErrorException In case the memcache server isn't available (anymore) + * @throws ServiceUnavailableException In case the memcache server isn't available (anymore) */ protected function sendMemcacheCommand(string $command) { $s = @fsockopen($this->server, $this->port); if (!$s) { - throw new InternalServerErrorException("Cant connect to:" . $this->server . ':' . $this->port); + throw new ServiceUnavailableException("Cant connect to:" . $this->server . ':' . $this->port); } fwrite($s, $command . "\r\n"); diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index ad1717ae83..4eb4084728 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -23,7 +23,7 @@ namespace Friendica\Core; use Exception; use Friendica\DI; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Render\TemplateEngine; /** @@ -69,7 +69,7 @@ class Renderer * @param string $template * @param array $vars * @return string - * @throws InternalServerErrorException + * @throws ServiceUnavailableException */ public static function replaceMacros(string $template, array $vars = []) { @@ -87,7 +87,7 @@ class Renderer $message = is_site_admin() ? $e->getMessage() : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); - throw new InternalServerErrorException($message); + throw new ServiceUnavailableException($message); } DI::profiler()->stopRecording(); @@ -102,7 +102,7 @@ class Renderer * @param string $subDir Subdirectory (Optional) * * @return string template. - * @throws InternalServerErrorException + * @throws ServiceUnavailableException */ public static function getMarkupTemplate($file, $subDir = '') { @@ -116,7 +116,7 @@ class Renderer $message = is_site_admin() ? $e->getMessage() : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); - throw new InternalServerErrorException($message); + throw new ServiceUnavailableException($message); } DI::profiler()->stopRecording(); @@ -128,7 +128,7 @@ class Renderer * Register template engine class * * @param string $class - * @throws InternalServerErrorException + * @throws ServiceUnavailableException */ public static function registerTemplateEngine($class) { @@ -143,7 +143,7 @@ class Renderer $message = is_site_admin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); - throw new InternalServerErrorException($message); + throw new ServiceUnavailableException($message); } } @@ -154,7 +154,7 @@ class Renderer * or default * * @return TemplateEngine Template Engine instance - * @throws InternalServerErrorException + * @throws ServiceUnavailableException */ public static function getTemplateEngine() { @@ -177,7 +177,7 @@ class Renderer $message = is_site_admin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); - throw new InternalServerErrorException($message); + throw new ServiceUnavailableException($message); } /** diff --git a/src/Core/System.php b/src/Core/System.php index c61225e482..15f4ba60aa 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -22,7 +22,10 @@ namespace Friendica\Core; use Friendica\DI; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\BadRequestException; +use Friendica\Network\HTTPException\FoundException; +use Friendica\Network\HTTPException\MovedPermanentlyException; +use Friendica\Network\HTTPException\TemporaryRedirectException; use Friendica\Util\XML; /** @@ -122,7 +125,9 @@ class System */ public static function httpExit($val, $message = '', $content = '') { - Logger::log('http_status_exit ' . $val); + if ($val >= 400) { + Logger::debug('Exit with error', ['code' => $val, 'message' => $message, 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + } header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $message); echo $content; @@ -132,6 +137,9 @@ class System public static function jsonError($httpCode, $data, $content_type = 'application/json') { + if ($httpCode >= 400) { + Logger::debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + } header($_SERVER["SERVER_PROTOCOL"] . ' ' . $httpCode); self::jsonExit($data, $content_type); } @@ -222,28 +230,25 @@ class System * @param string $url The new Location to redirect * @param int $code The redirection code, which is used (Default is 302) * - * @throws InternalServerErrorException If the URL is not fully qualified + * @throws BadRequestException If the URL is not fully qualified */ public static function externalRedirect($url, $code = 302) { if (empty(parse_url($url, PHP_URL_SCHEME))) { - throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead"); - } - - switch ($code) { - case 302: - // this is the default code for a REDIRECT - // We don't need a extra header here - break; - case 301: - header('HTTP/1.1 301 Moved Permanently'); - break; - case 307: - header('HTTP/1.1 307 Temporary Redirect'); - break; + throw new BadRequestException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead"); } header("Location: $url"); + + switch ($code) { + case 302: + throw new FoundException(); + case 301: + throw new MovedPermanentlyException(); + case 307: + throw new TemporaryRedirectException(); + } + exit(); } diff --git a/src/Database/Database.php b/src/Database/Database.php index a654cccc5b..88363cc397 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -23,7 +23,7 @@ namespace Friendica\Database; use Friendica\Core\Config\Cache; use Friendica\Core\System; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Util\DateTimeFormat; use Friendica\Util\Profiler; use mysqli; @@ -520,7 +520,7 @@ class Database $called_from_e = ($called_from['function'] == 'e'); if (!isset($this->connection)) { - throw new InternalServerErrorException('The Connection is empty, although connected is set true.'); + throw new ServiceUnavailableException('The Connection is empty, although connected is set true.'); } switch ($this->driver) { diff --git a/src/Factory/Api/Mastodon/Application.php b/src/Factory/Api/Mastodon/Application.php index f0567f2ebd..a7c0e6fc69 100644 --- a/src/Factory/Api/Mastodon/Application.php +++ b/src/Factory/Api/Mastodon/Application.php @@ -23,7 +23,7 @@ namespace Friendica\Factory\Api\Mastodon; use Friendica\BaseFactory; use Friendica\Database\Database; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\UnprocessableEntityException; use Psr\Log\LoggerInterface; class Application extends BaseFactory @@ -42,13 +42,13 @@ class Application extends BaseFactory * * @return \Friendica\Object\Api\Mastodon\Application * - * @throws InternalServerErrorException + * @throws UnprocessableEntityException */ public function createFromApplicationId(int $id): \Friendica\Object\Api\Mastodon\Application { $application = $this->dba->selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]); if (!$this->dba->isResult($application)) { - throw new InternalServerErrorException(sprintf("ID '%s' not found", $id)); + throw new UnprocessableEntityException(sprintf("ID '%s' not found", $id)); } return new \Friendica\Object\Api\Mastodon\Application( diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 2d081f4077..730cf3719d 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -32,8 +32,7 @@ use Friendica\DI; use Friendica\Factory\ConfigFactory; use Friendica\Model\Register; use Friendica\Module\BaseAdmin; -use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Util\ConfigFileLoader; +use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Util\DateTimeFormat; class Summary extends BaseAdmin @@ -129,7 +128,7 @@ class Summary extends BaseAdmin $stream = $fileSystem->createStream($file); if (!isset($stream)) { - throw new InternalServerErrorException('Stream is null.'); + throw new ServiceUnavailableException('Stream is null.'); } } catch (\Throwable $exception) { @@ -143,7 +142,7 @@ class Summary extends BaseAdmin $stream = $fileSystem->createStream($file); if (!isset($stream)) { - throw new InternalServerErrorException('Stream is null.'); + throw new ServiceUnavailableException('Stream is null.'); } } } catch (\Throwable $exception) { diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 0860dfd67c..dc6fb716b7 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -96,7 +96,9 @@ class Receive extends BaseModule if (Diaspora::dispatch($importer, $msg)) { throw new HTTPException\OKException(); } else { - throw new HTTPException\InternalServerErrorException(); + // We couldn't process the content. + // To avoid the remote system trying again we send the message that we accepted the content. + throw new HTTPException\AcceptedException(); } } diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 95a319a41a..08e463bd40 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -30,6 +30,7 @@ use Friendica\Database\PostUpdate; use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\ImATeapotException; use Friendica\Protocol\ActivityPub; /** diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 0b03f4a799..58a2eeac56 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -33,6 +33,7 @@ use Friendica\Model\Storage\ExternalResource; use Friendica\Model\Storage\SystemResource; use Friendica\Model\User; use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Object\Image; use Friendica\Util\Images; use Friendica\Util\Network; @@ -55,7 +56,6 @@ class Photo extends BaseModule $totalstamp = microtime(true); if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) { - header("HTTP/1.1 304 Not Modified"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) { header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]); @@ -67,7 +67,7 @@ class Photo extends BaseModule header_remove("Expires"); header_remove("Cache-Control"); } - exit; + throw new NotModifiedException(); } Profile::addVisitorCookieForHTTPSigner(); diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 15ef1c4412..86b8a95cbb 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -25,6 +25,7 @@ use Friendica\BaseModule; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\DI; +use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Object\Image; use Friendica\Util\HTTPSignature; use Friendica\Util\Images; @@ -53,7 +54,6 @@ class Proxy extends BaseModule } if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) { - header("HTTP/1.1 304 Not Modified"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) { header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]); @@ -65,7 +65,7 @@ class Proxy extends BaseModule header_remove("Expires"); header_remove("Cache-Control"); } - exit; + throw new NotModifiedException(); } if (empty($request['url'])) { diff --git a/src/Module/Special/HTTPException.php b/src/Module/Special/HTTPException.php index 09e962407a..137b72b36e 100644 --- a/src/Module/Special/HTTPException.php +++ b/src/Module/Special/HTTPException.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Special; +use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\DI; @@ -42,36 +43,10 @@ class HTTPException */ private static function getVars(\Friendica\Network\HTTPException $e) { - $message = $e->getMessage(); - - $titles = [ - 200 => 'OK', - 400 => DI::l10n()->t('Bad Request'), - 401 => DI::l10n()->t('Unauthorized'), - 403 => DI::l10n()->t('Forbidden'), - 404 => DI::l10n()->t('Not Found'), - 500 => DI::l10n()->t('Internal Server Error'), - 503 => DI::l10n()->t('Service Unavailable'), - ]; - $title = ($titles[$e->getCode()] ?? '') ?: 'Error ' . $e->getCode(); - - if (empty($message)) { - // Explanations are taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes - $explanation = [ - 400 => DI::l10n()->t('The server cannot or will not process the request due to an apparent client error.'), - 401 => DI::l10n()->t('Authentication is required and has failed or has not yet been provided.'), - 403 => DI::l10n()->t('The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.'), - 404 => DI::l10n()->t('The requested resource could not be found but may be available in the future.'), - 500 => DI::l10n()->t('An unexpected condition was encountered and no more specific message is suitable.'), - 503 => DI::l10n()->t('The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.'), - ]; - - $message = $explanation[$e->getCode()] ?? ''; - } - + // Explanations are mostly taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes $vars = [ - '$title' => $title, - '$message' => $message, + '$title' => $e->httpdesc ?: 'Error ' . $e->getCode(), + '$message' => $e->getMessage() ?: $e->explanation, '$back' => DI::l10n()->t('Go back'), '$stack_trace' => DI::l10n()->t('Stack trace:'), ]; @@ -113,6 +88,10 @@ class HTTPException { header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->httpdesc); + if ($e->getCode() >= 400) { + Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->httpdesc, 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + } + $tpl = Renderer::getMarkupTemplate('exception.tpl'); return Renderer::replaceMacros($tpl, self::getVars($e)); diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index 8b3b12876a..2326437868 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -22,8 +22,7 @@ namespace Friendica\Network; use Friendica\Core\Logger; -use Friendica\Core\System; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\UnprocessableEntityException; use Friendica\Util\Network; /** @@ -102,7 +101,7 @@ class CurlResult implements IHTTPResult * @param string $url optional URL * * @return IHTTPResult a CURL with error response - * @throws InternalServerErrorException + * @throws UnprocessableEntityException */ public static function createErrorCurl($url = '') { @@ -117,12 +116,12 @@ class CurlResult implements IHTTPResult * @param int $errorNumber the error number or 0 (zero) if no error * @param string $error the error message or '' (the empty string) if no * - * @throws InternalServerErrorException when HTTP code of the CURL response is missing + * @throws UnprocessableEntityException when HTTP code of the CURL response is missing */ public function __construct($url, $result, $info, $errorNumber = 0, $error = '') { if (!array_key_exists('http_code', $info)) { - throw new InternalServerErrorException('CURL response doesn\'t contains a response HTTP code'); + throw new UnprocessableEntityException('CURL response doesn\'t contains a response HTTP code'); } $this->returnCode = $info['http_code']; diff --git a/src/Network/HTTPException.php b/src/Network/HTTPException.php index d6698605d0..1ca6bd36df 100644 --- a/src/Network/HTTPException.php +++ b/src/Network/HTTPException.php @@ -31,15 +31,11 @@ use Exception; */ abstract class HTTPException extends Exception { - public $httpdesc = ''; + public $httpdesc = ''; + public $explanation = ''; public function __construct($message = '', Exception $previous = null) { parent::__construct($message, $this->code, $previous); - - if (empty($this->httpdesc)) { - $classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this))); - $this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname); - } } } diff --git a/src/Network/HTTPException/AcceptedException.php b/src/Network/HTTPException/AcceptedException.php index a52c1a3ea3..e7a8e5a3e0 100644 --- a/src/Network/HTTPException/AcceptedException.php +++ b/src/Network/HTTPException/AcceptedException.php @@ -26,4 +26,5 @@ use Friendica\Network\HTTPException; class AcceptedException extends HTTPException { protected $code = 202; + var $httpdesc = 'Accepted'; } diff --git a/src/Network/HTTPException/BadGatewayException.php b/src/Network/HTTPException/BadGatewayException.php index ceaa3189e4..d2f6c3fbeb 100644 --- a/src/Network/HTTPException/BadGatewayException.php +++ b/src/Network/HTTPException/BadGatewayException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class BadGatewayException extends HTTPException { - protected $code = 502; + protected $code = 502; + var $httpdesc = 'Bad Gateway'; + var $explanation = 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.'; } diff --git a/src/Network/HTTPException/BadRequestException.php b/src/Network/HTTPException/BadRequestException.php index 5b71e5b976..c2fe816afc 100644 --- a/src/Network/HTTPException/BadRequestException.php +++ b/src/Network/HTTPException/BadRequestException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class BadRequestException extends HTTPException { - protected $code = 400; + protected $code = 400; + var $httpdesc = 'Bad Request'; + var $explanation = 'The server cannot or will not process the request due to an apparent client error.'; } diff --git a/src/Network/HTTPException/ConflictException.php b/src/Network/HTTPException/ConflictException.php index f7e2678359..01cfc8dce0 100644 --- a/src/Network/HTTPException/ConflictException.php +++ b/src/Network/HTTPException/ConflictException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class ConflictException extends HTTPException { - protected $code = 409; + protected $code = 409; + var $httpdesc = 'Conflict '; + var $explanation = 'Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.'; } diff --git a/src/Network/HTTPException/ExpectationFailedException.php b/src/Network/HTTPException/ExpectationFailedException.php index 4269fbde51..9ae58bcc81 100644 --- a/src/Network/HTTPException/ExpectationFailedException.php +++ b/src/Network/HTTPException/ExpectationFailedException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class ExpectationFailedException extends HTTPException { - protected $code = 417; + protected $code = 417; + var $httpdesc = 'Expectation Failed'; + var $explanation = 'The server cannot meet the requirements of the Expect request-header field.'; } diff --git a/src/Network/HTTPException/ForbiddenException.php b/src/Network/HTTPException/ForbiddenException.php index c492cb928e..a1dafa9a5b 100644 --- a/src/Network/HTTPException/ForbiddenException.php +++ b/src/Network/HTTPException/ForbiddenException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class ForbiddenException extends HTTPException { - protected $code = 403; + protected $code = 403; + var $httpdesc = 'Forbidden'; + var $explanation = 'The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.'; } diff --git a/src/Network/HTTPException/FoundException.php b/src/Network/HTTPException/FoundException.php new file mode 100644 index 0000000000..c60a5f8c83 --- /dev/null +++ b/src/Network/HTTPException/FoundException.php @@ -0,0 +1,30 @@ +. + * + */ + +namespace Friendica\Network\HTTPException; + +use Friendica\Network\HTTPException; + +class FoundException extends HTTPException +{ + protected $code = 302; + var $httpdesc = 'Found (Moved Temporarily)'; +} diff --git a/src/Network/HTTPException/GatewayTimeoutException.php b/src/Network/HTTPException/GatewayTimeoutException.php index 4aca8fd836..2f674b2dcd 100644 --- a/src/Network/HTTPException/GatewayTimeoutException.php +++ b/src/Network/HTTPException/GatewayTimeoutException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class GatewayTimeoutException extends HTTPException { - protected $code = 504; + protected $code = 504; + var $httpdesc = 'Gateway Timeout'; + var $explanation = 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.'; } diff --git a/src/Network/HTTPException/GoneException.php b/src/Network/HTTPException/GoneException.php index 77f0a5f7a2..73eedcb671 100644 --- a/src/Network/HTTPException/GoneException.php +++ b/src/Network/HTTPException/GoneException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class GoneException extends HTTPException { - protected $code = 410; + protected $code = 410; + var $httpdesc = 'Gone'; + var $explanation = 'Indicates that the resource requested is no longer available and will not be available again.'; } diff --git a/src/Network/HTTPException/ImATeapotException.php b/src/Network/HTTPException/ImATeapotException.php index 689bc36a2e..dcfd72de04 100644 --- a/src/Network/HTTPException/ImATeapotException.php +++ b/src/Network/HTTPException/ImATeapotException.php @@ -25,6 +25,7 @@ use Friendica\Network\HTTPException; class ImATeapotException extends HTTPException { - protected $code = 418; - var $httpdesc = "I'm A Teapot"; + protected $code = 418; + var $httpdesc = "I'm A Teapot"; + var $explanation = 'This is a teapot that is requested to brew coffee.'; } diff --git a/src/Network/HTTPException/InternalServerErrorException.php b/src/Network/HTTPException/InternalServerErrorException.php index 570f8e0fcf..d5df8fdd3a 100644 --- a/src/Network/HTTPException/InternalServerErrorException.php +++ b/src/Network/HTTPException/InternalServerErrorException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class InternalServerErrorException extends HTTPException { - protected $code = 500; + protected $code = 500; + var $httpdesc = 'Internal Server Error'; + var $explanation = 'An unexpected condition was encountered and no more specific message is suitable.'; } diff --git a/src/Network/HTTPException/LenghtRequiredException.php b/src/Network/HTTPException/LenghtRequiredException.php index 3071547122..3818f681ae 100644 --- a/src/Network/HTTPException/LenghtRequiredException.php +++ b/src/Network/HTTPException/LenghtRequiredException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class LenghtRequiredException extends HTTPException { - protected $code = 411; + protected $code = 411; + var $httpdesc = 'Length Required'; + var $explanation = 'The request did not specify the length of its content, which is required by the requested resource.'; } diff --git a/src/Network/HTTPException/MethodNotAllowedException.php b/src/Network/HTTPException/MethodNotAllowedException.php index 6a733a3746..d09c0fe318 100644 --- a/src/Network/HTTPException/MethodNotAllowedException.php +++ b/src/Network/HTTPException/MethodNotAllowedException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class MethodNotAllowedException extends HTTPException { - protected $code = 405; + protected $code = 405; + var $httpdesc = 'Method Not Allowed'; + var $explanation = 'A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.'; } diff --git a/src/Network/HTTPException/MovedPermanently.php b/src/Network/HTTPException/MovedPermanently.php new file mode 100644 index 0000000000..ef78f87bd6 --- /dev/null +++ b/src/Network/HTTPException/MovedPermanently.php @@ -0,0 +1,30 @@ +. + * + */ + +namespace Friendica\Network\HTTPException; + +use Friendica\Network\HTTPException; + +class MovedPermanentlyException extends HTTPException +{ + protected $code = 301; + var $httpdesc = 'Moved Permanently'; +} diff --git a/src/Network/HTTPException/NoContentException.php b/src/Network/HTTPException/NoContentException.php index 78900aff54..90d9d2ae6a 100644 --- a/src/Network/HTTPException/NoContentException.php +++ b/src/Network/HTTPException/NoContentException.php @@ -26,4 +26,5 @@ use Friendica\Network\HTTPException; class NoContentException extends HTTPException { protected $code = 204; + var $httpdesc = 'No Content'; } diff --git a/src/Network/HTTPException/NonAcceptableException.php b/src/Network/HTTPException/NonAcceptableException.php index 1eddc8b288..c9811ddb79 100644 --- a/src/Network/HTTPException/NonAcceptableException.php +++ b/src/Network/HTTPException/NonAcceptableException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class NonAcceptableException extends HTTPException { - protected $code = 406; + protected $code = 406; + var $httpdesc = 'Not Acceptable'; + var $explanation = 'The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.'; } diff --git a/src/Network/HTTPException/NotFoundException.php b/src/Network/HTTPException/NotFoundException.php index a89d8a4e19..9acc32031d 100644 --- a/src/Network/HTTPException/NotFoundException.php +++ b/src/Network/HTTPException/NotFoundException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class NotFoundException extends HTTPException { - protected $code = 404; + protected $code = 404; + var $httpdesc = 'Not Found'; + var $explanation = 'The requested resource could not be found but may be available in the future.'; } diff --git a/src/Network/HTTPException/NotImplementedException.php b/src/Network/HTTPException/NotImplementedException.php index 3a84f6a549..6c2d1e25e6 100644 --- a/src/Network/HTTPException/NotImplementedException.php +++ b/src/Network/HTTPException/NotImplementedException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class NotImplementedException extends HTTPException { - protected $code = 501; + protected $code = 501; + var $httpdesc = 'Not Implemented'; + var $explanation = 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).'; } diff --git a/src/Network/HTTPException/NotModifiedException.php b/src/Network/HTTPException/NotModifiedException.php new file mode 100644 index 0000000000..431b2096a3 --- /dev/null +++ b/src/Network/HTTPException/NotModifiedException.php @@ -0,0 +1,30 @@ +. + * + */ + +namespace Friendica\Network\HTTPException; + +use Friendica\Network\HTTPException; + +class NotModifiedException extends HTTPException +{ + protected $code = 304; + var $httpdesc = 'Not Modified'; +} diff --git a/src/Network/HTTPException/OKException.php b/src/Network/HTTPException/OKException.php index 44dc6c80b8..e4b409ce0f 100644 --- a/src/Network/HTTPException/OKException.php +++ b/src/Network/HTTPException/OKException.php @@ -26,4 +26,5 @@ use Friendica\Network\HTTPException; class OKException extends HTTPException { protected $code = 200; + var $httpdesc = 'OK'; } diff --git a/src/Network/HTTPException/PreconditionFailedException.php b/src/Network/HTTPException/PreconditionFailedException.php index 9baf5a0928..fe4ebcb123 100644 --- a/src/Network/HTTPException/PreconditionFailedException.php +++ b/src/Network/HTTPException/PreconditionFailedException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class PreconditionFailedException extends HTTPException { - protected $code = 412; + protected $code = 412; + var $httpdesc = 'Precondition Failed'; + var $explanation = 'The server does not meet one of the preconditions that the requester put on the request header fields.'; } diff --git a/src/Network/HTTPException/ServiceUnavailableException.php b/src/Network/HTTPException/ServiceUnavailableException.php index 2f9ef8863e..a88390e6a7 100644 --- a/src/Network/HTTPException/ServiceUnavailableException.php +++ b/src/Network/HTTPException/ServiceUnavailableException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class ServiceUnavailableException extends HTTPException { - protected $code = 503; + protected $code = 503; + var $httpdesc = 'Service Unavailable'; + var $explanation = 'The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.'; } diff --git a/src/Network/HTTPException/TemporaryRedirectException.php b/src/Network/HTTPException/TemporaryRedirectException.php new file mode 100644 index 0000000000..cae4be7281 --- /dev/null +++ b/src/Network/HTTPException/TemporaryRedirectException.php @@ -0,0 +1,30 @@ +. + * + */ + +namespace Friendica\Network\HTTPException; + +use Friendica\Network\HTTPException; + +class TemporaryRedirectException extends HTTPException +{ + protected $code = 307; + var $httpdesc = 'Temporary Redirect'; +} diff --git a/src/Network/HTTPException/TooManyRequestsException.php b/src/Network/HTTPException/TooManyRequestsException.php index 567191fc56..c94679af72 100644 --- a/src/Network/HTTPException/TooManyRequestsException.php +++ b/src/Network/HTTPException/TooManyRequestsException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class TooManyRequestsException extends HTTPException { - protected $code = 429; + protected $code = 429; + var $httpdesc = 'Too Many Requests'; + var $explanation = 'The user has sent too many requests in a given amount of time.'; } diff --git a/src/Network/HTTPException/UnauthorizedException.php b/src/Network/HTTPException/UnauthorizedException.php index d7bcb5c740..ad6adfd423 100644 --- a/src/Network/HTTPException/UnauthorizedException.php +++ b/src/Network/HTTPException/UnauthorizedException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class UnauthorizedException extends HTTPException { - protected $code = 401; + protected $code = 401; + var $httpdesc = 'Unauthorized'; + var $explanation = 'Authentication is required and has failed or has not yet been provided.'; } diff --git a/src/Network/HTTPException/UnprocessableEntityException.php b/src/Network/HTTPException/UnprocessableEntityException.php index 41f952941e..29b0d3158e 100644 --- a/src/Network/HTTPException/UnprocessableEntityException.php +++ b/src/Network/HTTPException/UnprocessableEntityException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class UnprocessableEntityException extends HTTPException { - protected $code = 422; + protected $code = 422; + var $httpdesc = 'Unprocessable Entity'; + var $explanation = 'The request was well-formed but was unable to be followed due to semantic errors.'; } diff --git a/src/Network/HTTPException/UnsupportedMediaTypeException.php b/src/Network/HTTPException/UnsupportedMediaTypeException.php index 00c89cebdb..adf008d015 100644 --- a/src/Network/HTTPException/UnsupportedMediaTypeException.php +++ b/src/Network/HTTPException/UnsupportedMediaTypeException.php @@ -25,5 +25,7 @@ use Friendica\Network\HTTPException; class UnsupportedMediaTypeException extends HTTPException { - protected $code = 415; + protected $code = 415; + var $httpdesc = 'Unsupported Media Type'; + var $explanation = 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.'; } diff --git a/src/Render/FriendicaSmartyEngine.php b/src/Render/FriendicaSmartyEngine.php index 8eafd7d94a..c336273c72 100644 --- a/src/Render/FriendicaSmartyEngine.php +++ b/src/Render/FriendicaSmartyEngine.php @@ -23,7 +23,7 @@ namespace Friendica\Render; use Friendica\Core\Hook; use Friendica\DI; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Util\Strings; /** @@ -54,7 +54,7 @@ final class FriendicaSmartyEngine extends TemplateEngine $message = is_site_admin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); - throw new InternalServerErrorException($message); + throw new ServiceUnavailableException($message); } } diff --git a/src/Util/EMailer/MailBuilder.php b/src/Util/EMailer/MailBuilder.php index 56034a6966..1e1a064910 100644 --- a/src/Util/EMailer/MailBuilder.php +++ b/src/Util/EMailer/MailBuilder.php @@ -27,7 +27,7 @@ use Friendica\Core\Config\IConfig; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Model\User; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\UnprocessableEntityException; use Friendica\Object\Email; use Friendica\Object\EMail\IEmail; use Psr\Log\LoggerInterface; @@ -226,7 +226,7 @@ abstract class MailBuilder * * @return IEmail A new generated email * - * @throws InternalServerErrorException + * @throws UnprocessableEntityException * @throws Exception */ public function build(bool $raw = false) @@ -241,11 +241,11 @@ abstract class MailBuilder } if (empty($this->recipientAddress)) { - throw new InternalServerErrorException('Recipient address is missing.'); + throw new UnprocessableEntityException('Recipient address is missing.'); } if (empty($this->senderAddress) || empty($this->senderName)) { - throw new InternalServerErrorException('Sender address or name is missing.'); + throw new UnprocessableEntityException('Sender address or name is missing.'); } $this->senderNoReply = $this->senderNoReply ?? $this->senderAddress; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index f11dbcceb4..663c5a752a 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -476,7 +476,7 @@ class HTTPSignature public static function getSigner($content, $http_headers) { if (empty($http_headers['HTTP_SIGNATURE'])) { - Logger::info('No HTTP_SIGNATURE header'); + Logger::debug('No HTTP_SIGNATURE header'); return false; } diff --git a/src/Util/Network.php b/src/Util/Network.php index 9c7b6a8af8..2631fc75b0 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -25,6 +25,7 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; use Friendica\Model\Contact; +use Friendica\Network\HTTPException\NotModifiedException; class Network { @@ -544,8 +545,7 @@ class Network header('Last-Modified: ' . $last_modified); if ($flag_not_modified) { - header("HTTP/1.1 304 Not Modified"); - exit; + throw new NotModifiedException(); } } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 16baea281d..6d7a7050b1 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -693,7 +693,7 @@ class Notifier private static function notifySelfRemoval($self_user_id, $priority, $created) { $owner = User::getOwnerDataById($self_user_id); - if (!$owner) { + if (empty($self_user_id) || empty($owner)) { return false; } diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index c60fb7a8f4..f68f4c291e 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -20,6 +20,7 @@ */ use Friendica\DI; +use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Util\Strings; require_once 'view/theme/frio/theme.php'; @@ -225,8 +226,7 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MA stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); if (($cached_modified == $modified) && ($cached_etag == $etag)) { - header('HTTP/1.1 304 Not Modified'); - exit(); + throw new NotModifiedException(); } } diff --git a/view/theme/vier/style.php b/view/theme/vier/style.php index a1b492b950..909a27fc6c 100644 --- a/view/theme/vier/style.php +++ b/view/theme/vier/style.php @@ -21,6 +21,7 @@ use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Network\HTTPException\NotModifiedException; $uid = $_REQUEST['puid'] ?? 0; @@ -67,8 +68,7 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MA stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); if (($cached_modified == $modified) && ($cached_etag == $etag)) { - header('HTTP/1.1 304 Not Modified'); - exit(); + throw new NotModifiedException(); } } echo $stylecss; From ec5bd9a756ae2273dbe5915b0b1fd60f0320896a Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 30 Oct 2021 09:13:06 +0000 Subject: [PATCH 2/8] Reverting some parts because wouldn't work --- bin/auth_ejabberd.php | 3 ++- bin/console.php | 3 ++- bin/daemon.php | 3 ++- bin/testargs.php | 3 ++- bin/worker.php | 3 ++- src/Module/Friendica.php | 1 - 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index fd1b40cc84..22087ed017 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -54,7 +54,8 @@ use Friendica\Network\HTTPException\ForbiddenException; if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } use Dice\Dice; diff --git a/bin/console.php b/bin/console.php index edfb8cd285..8305176157 100755 --- a/bin/console.php +++ b/bin/console.php @@ -23,7 +23,8 @@ use Friendica\Network\HTTPException\ForbiddenException; if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } use Dice\Dice; diff --git a/bin/daemon.php b/bin/daemon.php index 965c495ecd..78eb74001d 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -26,7 +26,8 @@ use Friendica\Network\HTTPException\ForbiddenException; if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } use Dice\Dice; diff --git a/bin/testargs.php b/bin/testargs.php index 05826f2e42..dbfd05a130 100644 --- a/bin/testargs.php +++ b/bin/testargs.php @@ -29,7 +29,8 @@ use Friendica\Network\HTTPException\ForbiddenException; if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) { diff --git a/bin/worker.php b/bin/worker.php index a39d049632..ad70bb176a 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -24,7 +24,8 @@ use Friendica\Network\HTTPException\ForbiddenException; if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } use Dice\Dice; diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 08e463bd40..95a319a41a 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -30,7 +30,6 @@ use Friendica\Database\PostUpdate; use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; -use Friendica\Network\HTTPException\ImATeapotException; use Friendica\Protocol\ActivityPub; /** From 57353eb9b02af1da80658fe6a18e6a81e80a9472 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 31 Oct 2021 04:54:24 +0000 Subject: [PATCH 3/8] Changed scope --- include/api.php | 2 +- src/Module/Debug/Probe.php | 4 +--- src/Module/Debug/WebFinger.php | 4 +--- src/Module/Search/Index.php | 4 +--- src/Module/Special/HTTPException.php | 10 +++++----- src/Network/HTTPException.php | 14 ++++++++++++-- src/Network/HTTPException/AcceptedException.php | 4 ++-- src/Network/HTTPException/BadGatewayException.php | 6 +++--- src/Network/HTTPException/BadRequestException.php | 6 +++--- src/Network/HTTPException/ConflictException.php | 6 +++--- .../HTTPException/ExpectationFailedException.php | 6 +++--- src/Network/HTTPException/ForbiddenException.php | 6 +++--- src/Network/HTTPException/FoundException.php | 4 ++-- .../HTTPException/GatewayTimeoutException.php | 6 +++--- src/Network/HTTPException/GoneException.php | 6 +++--- src/Network/HTTPException/ImATeapotException.php | 6 +++--- .../HTTPException/InternalServerErrorException.php | 6 +++--- .../HTTPException/LenghtRequiredException.php | 6 +++--- .../HTTPException/MethodNotAllowedException.php | 6 +++--- src/Network/HTTPException/MovedPermanently.php | 4 ++-- src/Network/HTTPException/NoContentException.php | 4 ++-- .../HTTPException/NonAcceptableException.php | 6 +++--- src/Network/HTTPException/NotFoundException.php | 6 +++--- .../HTTPException/NotImplementedException.php | 6 +++--- src/Network/HTTPException/NotModifiedException.php | 4 ++-- src/Network/HTTPException/OKException.php | 4 ++-- .../HTTPException/PreconditionFailedException.php | 6 +++--- .../HTTPException/ServiceUnavailableException.php | 6 +++--- .../HTTPException/TemporaryRedirectException.php | 4 ++-- .../HTTPException/TooManyRequestsException.php | 6 +++--- .../HTTPException/UnauthorizedException.php | 6 +++--- .../HTTPException/UnprocessableEntityException.php | 6 +++--- .../UnsupportedMediaTypeException.php | 6 +++--- 33 files changed, 95 insertions(+), 91 deletions(-) diff --git a/include/api.php b/include/api.php index fc73ae8500..b6869a2b13 100644 --- a/include/api.php +++ b/include/api.php @@ -371,7 +371,7 @@ function api_call(App $a, App\Arguments $args = null) Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]); throw new NotFoundException(); } catch (HTTPException $e) { - header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}"); + header("HTTP/1.1 {$e->getCode()} {$e->getDescription()}"); return api_error($type, $e, $args); } } diff --git a/src/Module/Debug/Probe.php b/src/Module/Debug/Probe.php index 6c2891c0be..304096b2ec 100644 --- a/src/Module/Debug/Probe.php +++ b/src/Module/Debug/Probe.php @@ -35,9 +35,7 @@ class Probe extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - $e = new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.')); - $e->httpdesc = DI::l10n()->t('Public access denied.'); - throw $e; + throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.')); } $addr = $_GET['addr'] ?? ''; diff --git a/src/Module/Debug/WebFinger.php b/src/Module/Debug/WebFinger.php index ace1c1f9a4..e8a619f0b9 100644 --- a/src/Module/Debug/WebFinger.php +++ b/src/Module/Debug/WebFinger.php @@ -34,9 +34,7 @@ class WebFinger extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - $e = new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.')); - $e->httpdesc = DI::l10n()->t('Public access denied.'); - throw $e; + throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.')); } $addr = $_GET['addr'] ?? ''; diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 7be5058c2b..5220317bf9 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -51,9 +51,7 @@ class Index extends BaseSearch } if (DI::config()->get('system', 'local_search') && !Session::isAuthenticated()) { - $e = new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.')); - $e->httpdesc = DI::l10n()->t('Public access denied.'); - throw $e; + throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.')); } if (DI::config()->get('system', 'permit_crawling') && !Session::isAuthenticated()) { diff --git a/src/Module/Special/HTTPException.php b/src/Module/Special/HTTPException.php index 137b72b36e..8fe4c8ce57 100644 --- a/src/Module/Special/HTTPException.php +++ b/src/Module/Special/HTTPException.php @@ -45,8 +45,8 @@ class HTTPException { // Explanations are mostly taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes $vars = [ - '$title' => $e->httpdesc ?: 'Error ' . $e->getCode(), - '$message' => $e->getMessage() ?: $e->explanation, + '$title' => $e->getDescription() ?: 'Error ' . $e->getCode(), + '$message' => $e->getMessage() ?: $e->getExplanation(), '$back' => DI::l10n()->t('Go back'), '$stack_trace' => DI::l10n()->t('Stack trace:'), ]; @@ -74,7 +74,7 @@ class HTTPException $content = Renderer::replaceMacros($tpl, self::getVars($e)); } - System::httpExit($e->getCode(), $e->httpdesc, $content); + System::httpExit($e->getCode(), $e->getDescription(), $content); } /** @@ -86,10 +86,10 @@ class HTTPException */ public static function content(\Friendica\Network\HTTPException $e) { - header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->httpdesc); + header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription()); if ($e->getCode() >= 400) { - Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->httpdesc, 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->getDescription(), 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); } $tpl = Renderer::getMarkupTemplate('exception.tpl'); diff --git a/src/Network/HTTPException.php b/src/Network/HTTPException.php index 1ca6bd36df..a0cdcdf6af 100644 --- a/src/Network/HTTPException.php +++ b/src/Network/HTTPException.php @@ -31,11 +31,21 @@ use Exception; */ abstract class HTTPException extends Exception { - public $httpdesc = ''; - public $explanation = ''; + protected $httpdesc = ''; + protected $explanation = ''; public function __construct($message = '', Exception $previous = null) { parent::__construct($message, $this->code, $previous); } + + public function getDescription() + { + return $this->httpdesc; + } + + public function getExplanation() + { + return $this->explanation; + } } diff --git a/src/Network/HTTPException/AcceptedException.php b/src/Network/HTTPException/AcceptedException.php index e7a8e5a3e0..3c42802ed7 100644 --- a/src/Network/HTTPException/AcceptedException.php +++ b/src/Network/HTTPException/AcceptedException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class AcceptedException extends HTTPException { - protected $code = 202; - var $httpdesc = 'Accepted'; + protected $code = 202; + protected $httpdesc = 'Accepted'; } diff --git a/src/Network/HTTPException/BadGatewayException.php b/src/Network/HTTPException/BadGatewayException.php index d2f6c3fbeb..c80202a41a 100644 --- a/src/Network/HTTPException/BadGatewayException.php +++ b/src/Network/HTTPException/BadGatewayException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class BadGatewayException extends HTTPException { - protected $code = 502; - var $httpdesc = 'Bad Gateway'; - var $explanation = 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.'; + protected $code = 502; + protected $httpdesc = 'Bad Gateway'; + protected $explanation = 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.'; } diff --git a/src/Network/HTTPException/BadRequestException.php b/src/Network/HTTPException/BadRequestException.php index c2fe816afc..fef39c1c16 100644 --- a/src/Network/HTTPException/BadRequestException.php +++ b/src/Network/HTTPException/BadRequestException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class BadRequestException extends HTTPException { - protected $code = 400; - var $httpdesc = 'Bad Request'; - var $explanation = 'The server cannot or will not process the request due to an apparent client error.'; + protected $code = 400; + protected $httpdesc = 'Bad Request'; + protected $explanation = 'The server cannot or will not process the request due to an apparent client error.'; } diff --git a/src/Network/HTTPException/ConflictException.php b/src/Network/HTTPException/ConflictException.php index 01cfc8dce0..2f7a892e25 100644 --- a/src/Network/HTTPException/ConflictException.php +++ b/src/Network/HTTPException/ConflictException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class ConflictException extends HTTPException { - protected $code = 409; - var $httpdesc = 'Conflict '; - var $explanation = 'Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.'; + protected $code = 409; + protected $httpdesc = 'Conflict '; + protected $explanation = 'Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.'; } diff --git a/src/Network/HTTPException/ExpectationFailedException.php b/src/Network/HTTPException/ExpectationFailedException.php index 9ae58bcc81..5c1bc6ab7f 100644 --- a/src/Network/HTTPException/ExpectationFailedException.php +++ b/src/Network/HTTPException/ExpectationFailedException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class ExpectationFailedException extends HTTPException { - protected $code = 417; - var $httpdesc = 'Expectation Failed'; - var $explanation = 'The server cannot meet the requirements of the Expect request-header field.'; + protected $code = 417; + protected $httpdesc = 'Expectation Failed'; + protected $explanation = 'The server cannot meet the requirements of the Expect request-header field.'; } diff --git a/src/Network/HTTPException/ForbiddenException.php b/src/Network/HTTPException/ForbiddenException.php index a1dafa9a5b..2d65987064 100644 --- a/src/Network/HTTPException/ForbiddenException.php +++ b/src/Network/HTTPException/ForbiddenException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class ForbiddenException extends HTTPException { - protected $code = 403; - var $httpdesc = 'Forbidden'; - var $explanation = 'The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.'; + protected $code = 403; + protected $httpdesc = 'Forbidden'; + protected $explanation = 'The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.'; } diff --git a/src/Network/HTTPException/FoundException.php b/src/Network/HTTPException/FoundException.php index c60a5f8c83..8fcaceb773 100644 --- a/src/Network/HTTPException/FoundException.php +++ b/src/Network/HTTPException/FoundException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class FoundException extends HTTPException { - protected $code = 302; - var $httpdesc = 'Found (Moved Temporarily)'; + protected $code = 302; + protected $httpdesc = 'Found (Moved Temporarily)'; } diff --git a/src/Network/HTTPException/GatewayTimeoutException.php b/src/Network/HTTPException/GatewayTimeoutException.php index 2f674b2dcd..695616f0d7 100644 --- a/src/Network/HTTPException/GatewayTimeoutException.php +++ b/src/Network/HTTPException/GatewayTimeoutException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class GatewayTimeoutException extends HTTPException { - protected $code = 504; - var $httpdesc = 'Gateway Timeout'; - var $explanation = 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.'; + protected $code = 504; + protected $httpdesc = 'Gateway Timeout'; + protected $explanation = 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.'; } diff --git a/src/Network/HTTPException/GoneException.php b/src/Network/HTTPException/GoneException.php index 73eedcb671..400bbc23e4 100644 --- a/src/Network/HTTPException/GoneException.php +++ b/src/Network/HTTPException/GoneException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class GoneException extends HTTPException { - protected $code = 410; - var $httpdesc = 'Gone'; - var $explanation = 'Indicates that the resource requested is no longer available and will not be available again.'; + protected $code = 410; + protected $httpdesc = 'Gone'; + protected $explanation = 'Indicates that the resource requested is no longer available and will not be available again.'; } diff --git a/src/Network/HTTPException/ImATeapotException.php b/src/Network/HTTPException/ImATeapotException.php index dcfd72de04..33f7a641b2 100644 --- a/src/Network/HTTPException/ImATeapotException.php +++ b/src/Network/HTTPException/ImATeapotException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class ImATeapotException extends HTTPException { - protected $code = 418; - var $httpdesc = "I'm A Teapot"; - var $explanation = 'This is a teapot that is requested to brew coffee.'; + protected $code = 418; + protected $httpdesc = "I'm A Teapot"; + protected $explanation = 'This is a teapot that is requested to brew coffee.'; } diff --git a/src/Network/HTTPException/InternalServerErrorException.php b/src/Network/HTTPException/InternalServerErrorException.php index d5df8fdd3a..4638d5c849 100644 --- a/src/Network/HTTPException/InternalServerErrorException.php +++ b/src/Network/HTTPException/InternalServerErrorException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class InternalServerErrorException extends HTTPException { - protected $code = 500; - var $httpdesc = 'Internal Server Error'; - var $explanation = 'An unexpected condition was encountered and no more specific message is suitable.'; + protected $code = 500; + protected $httpdesc = 'Internal Server Error'; + protected $explanation = 'An unexpected condition was encountered and no more specific message is suitable.'; } diff --git a/src/Network/HTTPException/LenghtRequiredException.php b/src/Network/HTTPException/LenghtRequiredException.php index 3818f681ae..dd0c02f8d7 100644 --- a/src/Network/HTTPException/LenghtRequiredException.php +++ b/src/Network/HTTPException/LenghtRequiredException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class LenghtRequiredException extends HTTPException { - protected $code = 411; - var $httpdesc = 'Length Required'; - var $explanation = 'The request did not specify the length of its content, which is required by the requested resource.'; + protected $code = 411; + protected $httpdesc = 'Length Required'; + protected $explanation = 'The request did not specify the length of its content, which is required by the requested resource.'; } diff --git a/src/Network/HTTPException/MethodNotAllowedException.php b/src/Network/HTTPException/MethodNotAllowedException.php index d09c0fe318..03841e5e5f 100644 --- a/src/Network/HTTPException/MethodNotAllowedException.php +++ b/src/Network/HTTPException/MethodNotAllowedException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class MethodNotAllowedException extends HTTPException { - protected $code = 405; - var $httpdesc = 'Method Not Allowed'; - var $explanation = 'A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.'; + protected $code = 405; + protected $httpdesc = 'Method Not Allowed'; + protected $explanation = 'A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.'; } diff --git a/src/Network/HTTPException/MovedPermanently.php b/src/Network/HTTPException/MovedPermanently.php index ef78f87bd6..7ded3847a3 100644 --- a/src/Network/HTTPException/MovedPermanently.php +++ b/src/Network/HTTPException/MovedPermanently.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class MovedPermanentlyException extends HTTPException { - protected $code = 301; - var $httpdesc = 'Moved Permanently'; + protected $code = 301; + protected $httpdesc = 'Moved Permanently'; } diff --git a/src/Network/HTTPException/NoContentException.php b/src/Network/HTTPException/NoContentException.php index 90d9d2ae6a..f652b66211 100644 --- a/src/Network/HTTPException/NoContentException.php +++ b/src/Network/HTTPException/NoContentException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class NoContentException extends HTTPException { - protected $code = 204; - var $httpdesc = 'No Content'; + protected $code = 204; + protected $httpdesc = 'No Content'; } diff --git a/src/Network/HTTPException/NonAcceptableException.php b/src/Network/HTTPException/NonAcceptableException.php index c9811ddb79..3b1c1538af 100644 --- a/src/Network/HTTPException/NonAcceptableException.php +++ b/src/Network/HTTPException/NonAcceptableException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class NonAcceptableException extends HTTPException { - protected $code = 406; - var $httpdesc = 'Not Acceptable'; - var $explanation = 'The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.'; + protected $code = 406; + protected $httpdesc = 'Not Acceptable'; + protected $explanation = 'The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.'; } diff --git a/src/Network/HTTPException/NotFoundException.php b/src/Network/HTTPException/NotFoundException.php index 9acc32031d..33731bd1c1 100644 --- a/src/Network/HTTPException/NotFoundException.php +++ b/src/Network/HTTPException/NotFoundException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class NotFoundException extends HTTPException { - protected $code = 404; - var $httpdesc = 'Not Found'; - var $explanation = 'The requested resource could not be found but may be available in the future.'; + protected $code = 404; + protected $httpdesc = 'Not Found'; + protected $explanation = 'The requested resource could not be found but may be available in the future.'; } diff --git a/src/Network/HTTPException/NotImplementedException.php b/src/Network/HTTPException/NotImplementedException.php index 6c2d1e25e6..94e7af0916 100644 --- a/src/Network/HTTPException/NotImplementedException.php +++ b/src/Network/HTTPException/NotImplementedException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class NotImplementedException extends HTTPException { - protected $code = 501; - var $httpdesc = 'Not Implemented'; - var $explanation = 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).'; + protected $code = 501; + protected $httpdesc = 'Not Implemented'; + protected $explanation = 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).'; } diff --git a/src/Network/HTTPException/NotModifiedException.php b/src/Network/HTTPException/NotModifiedException.php index 431b2096a3..9bdec60f08 100644 --- a/src/Network/HTTPException/NotModifiedException.php +++ b/src/Network/HTTPException/NotModifiedException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class NotModifiedException extends HTTPException { - protected $code = 304; - var $httpdesc = 'Not Modified'; + protected $code = 304; + protected $httpdesc = 'Not Modified'; } diff --git a/src/Network/HTTPException/OKException.php b/src/Network/HTTPException/OKException.php index e4b409ce0f..5daa199a94 100644 --- a/src/Network/HTTPException/OKException.php +++ b/src/Network/HTTPException/OKException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class OKException extends HTTPException { - protected $code = 200; - var $httpdesc = 'OK'; + protected $code = 200; + protected $httpdesc = 'OK'; } diff --git a/src/Network/HTTPException/PreconditionFailedException.php b/src/Network/HTTPException/PreconditionFailedException.php index fe4ebcb123..7a62ca7d56 100644 --- a/src/Network/HTTPException/PreconditionFailedException.php +++ b/src/Network/HTTPException/PreconditionFailedException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class PreconditionFailedException extends HTTPException { - protected $code = 412; - var $httpdesc = 'Precondition Failed'; - var $explanation = 'The server does not meet one of the preconditions that the requester put on the request header fields.'; + protected $code = 412; + protected $httpdesc = 'Precondition Failed'; + protected $explanation = 'The server does not meet one of the preconditions that the requester put on the request header fields.'; } diff --git a/src/Network/HTTPException/ServiceUnavailableException.php b/src/Network/HTTPException/ServiceUnavailableException.php index a88390e6a7..d520a9df0f 100644 --- a/src/Network/HTTPException/ServiceUnavailableException.php +++ b/src/Network/HTTPException/ServiceUnavailableException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class ServiceUnavailableException extends HTTPException { - protected $code = 503; - var $httpdesc = 'Service Unavailable'; - var $explanation = 'The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.'; + protected $code = 503; + protected $httpdesc = 'Service Unavailable'; + protected $explanation = 'The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.'; } diff --git a/src/Network/HTTPException/TemporaryRedirectException.php b/src/Network/HTTPException/TemporaryRedirectException.php index cae4be7281..008e3798ce 100644 --- a/src/Network/HTTPException/TemporaryRedirectException.php +++ b/src/Network/HTTPException/TemporaryRedirectException.php @@ -25,6 +25,6 @@ use Friendica\Network\HTTPException; class TemporaryRedirectException extends HTTPException { - protected $code = 307; - var $httpdesc = 'Temporary Redirect'; + protected $code = 307; + protected $httpdesc = 'Temporary Redirect'; } diff --git a/src/Network/HTTPException/TooManyRequestsException.php b/src/Network/HTTPException/TooManyRequestsException.php index c94679af72..0861aaefc7 100644 --- a/src/Network/HTTPException/TooManyRequestsException.php +++ b/src/Network/HTTPException/TooManyRequestsException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class TooManyRequestsException extends HTTPException { - protected $code = 429; - var $httpdesc = 'Too Many Requests'; - var $explanation = 'The user has sent too many requests in a given amount of time.'; + protected $code = 429; + protected $httpdesc = 'Too Many Requests'; + protected $explanation = 'The user has sent too many requests in a given amount of time.'; } diff --git a/src/Network/HTTPException/UnauthorizedException.php b/src/Network/HTTPException/UnauthorizedException.php index ad6adfd423..4bb2e86285 100644 --- a/src/Network/HTTPException/UnauthorizedException.php +++ b/src/Network/HTTPException/UnauthorizedException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class UnauthorizedException extends HTTPException { - protected $code = 401; - var $httpdesc = 'Unauthorized'; - var $explanation = 'Authentication is required and has failed or has not yet been provided.'; + protected $code = 401; + protected $httpdesc = 'Unauthorized'; + protected $explanation = 'Authentication is required and has failed or has not yet been provided.'; } diff --git a/src/Network/HTTPException/UnprocessableEntityException.php b/src/Network/HTTPException/UnprocessableEntityException.php index 29b0d3158e..9c78b73770 100644 --- a/src/Network/HTTPException/UnprocessableEntityException.php +++ b/src/Network/HTTPException/UnprocessableEntityException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class UnprocessableEntityException extends HTTPException { - protected $code = 422; - var $httpdesc = 'Unprocessable Entity'; - var $explanation = 'The request was well-formed but was unable to be followed due to semantic errors.'; + protected $code = 422; + protected $httpdesc = 'Unprocessable Entity'; + protected $explanation = 'The request was well-formed but was unable to be followed due to semantic errors.'; } diff --git a/src/Network/HTTPException/UnsupportedMediaTypeException.php b/src/Network/HTTPException/UnsupportedMediaTypeException.php index adf008d015..fad8d9f7e7 100644 --- a/src/Network/HTTPException/UnsupportedMediaTypeException.php +++ b/src/Network/HTTPException/UnsupportedMediaTypeException.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; class UnsupportedMediaTypeException extends HTTPException { - protected $code = 415; - var $httpdesc = 'Unsupported Media Type'; - var $explanation = 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.'; + protected $code = 415; + protected $httpdesc = 'Unsupported Media Type'; + protected $explanation = 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.'; } From 2d098b3fc876393bcd07234bf6c0364c05b7c9bd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 31 Oct 2021 05:28:16 +0000 Subject: [PATCH 4/8] Updated messages.po --- view/lang/C/messages.po | 180 ++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 116 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 0cb7b2c78d..0508a99e41 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-27 20:01+0200\n" +"POT-Creation-Date: 2021-10-31 05:26+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,21 +18,21 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" -#: include/api.php:1113 src/Module/BaseApi.php:294 +#: include/api.php:1111 src/Module/BaseApi.php:294 #, php-format msgid "Daily posting limit of %d post reached. The post was rejected." msgid_plural "Daily posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1127 src/Module/BaseApi.php:310 +#: include/api.php:1125 src/Module/BaseApi.php:310 #, php-format msgid "Weekly posting limit of %d post reached. The post was rejected." msgid_plural "Weekly posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1141 src/Module/BaseApi.php:326 +#: include/api.php:1139 src/Module/BaseApi.php:326 #, php-format msgid "Monthly posting limit of %d post reached. The post was rejected." msgstr "" @@ -157,9 +157,8 @@ msgid "calendar" msgstr "" #: mod/display.php:165 mod/photos.php:811 -#: src/Module/Conversation/Community.php:176 src/Module/Debug/Probe.php:39 -#: src/Module/Debug/WebFinger.php:38 src/Module/Directory.php:49 -#: src/Module/Search/Index.php:50 src/Module/Search/Index.php:55 +#: src/Module/Conversation/Community.php:176 src/Module/Directory.php:49 +#: src/Module/Search/Index.php:50 msgid "Public access denied." msgstr "" @@ -180,7 +179,7 @@ msgid "Edit post" msgstr "" #: mod/editpost.php:91 mod/notes.php:56 src/Content/Text/HTML.php:885 -#: src/Module/Admin/Storage.php:143 src/Module/Filer/SaveTag.php:69 +#: src/Module/Admin/Storage.php:142 src/Module/Filer/SaveTag.php:69 msgid "Save" msgstr "" @@ -343,7 +342,7 @@ msgstr "" #: src/Module/Admin/Blocklist/Server.php:80 #: src/Module/Admin/Blocklist/Server.php:99 #: src/Module/Admin/Blocklist/Server.php:100 -#: src/Module/Admin/Item/Delete.php:70 src/Module/Debug/Probe.php:61 +#: src/Module/Admin/Item/Delete.php:70 src/Module/Debug/Probe.php:59 #: src/Module/Install.php:200 src/Module/Install.php:233 #: src/Module/Install.php:238 src/Module/Install.php:257 #: src/Module/Install.php:268 src/Module/Install.php:273 @@ -392,7 +391,7 @@ msgstr "" #: src/Module/Contact/Advanced.php:133 src/Module/Contact/Poke.php:158 #: src/Module/Debug/ActivityPubConversion.php:141 #: src/Module/Debug/Babel.php:313 src/Module/Debug/Localtime.php:64 -#: src/Module/Debug/Probe.php:56 src/Module/Debug/WebFinger.php:53 +#: src/Module/Debug/Probe.php:54 src/Module/Debug/WebFinger.php:51 #: src/Module/Delegation.php:147 src/Module/FriendSuggest.php:128 #: src/Module/Install.php:245 src/Module/Install.php:287 #: src/Module/Install.php:324 src/Module/Invite.php:177 @@ -2091,7 +2090,7 @@ msgstr "" msgid "No system theme config value set." msgstr "" -#: src/App/Module.php:241 +#: src/App/Module.php:242 msgid "You must be logged in to use addons. " msgstr "" @@ -2791,7 +2790,7 @@ msgstr "" msgid "Nothing new here" msgstr "" -#: src/Content/Nav.php:94 src/Module/Special/HTTPException.php:75 +#: src/Content/Nav.php:94 src/Module/Special/HTTPException.php:50 msgid "Go back" msgstr "" @@ -2902,7 +2901,7 @@ msgid "Addon applications, utilities, games" msgstr "" #: src/Content/Nav.php:230 src/Content/Text/HTML.php:891 -#: src/Module/Admin/Logs/View.php:86 src/Module/Search/Index.php:99 +#: src/Module/Admin/Logs/View.php:86 src/Module/Search/Index.php:97 msgid "Search" msgstr "" @@ -4041,7 +4040,6 @@ msgid "Unprocessable Entity" msgstr "" #: src/Factory/Api/Mastodon/Error.php:75 -#: src/Module/Special/HTTPException.php:50 msgid "Unauthorized" msgstr "" @@ -4051,7 +4049,6 @@ msgid "" msgstr "" #: src/Factory/Api/Mastodon/Error.php:95 -#: src/Module/Special/HTTPException.php:53 msgid "Internal Server Error" msgstr "" @@ -4388,7 +4385,7 @@ msgstr "" msgid "Title/Description:" msgstr "" -#: src/Model/Profile.php:988 src/Module/Admin/Summary.php:234 +#: src/Model/Profile.php:988 src/Module/Admin/Summary.php:233 msgid "Summary" msgstr "" @@ -4711,8 +4708,8 @@ msgstr "" #: src/Module/Admin/Blocklist/Server.php:88 src/Module/Admin/Federation.php:159 #: src/Module/Admin/Item/Delete.php:65 src/Module/Admin/Logs/Settings.php:80 #: src/Module/Admin/Logs/View.php:83 src/Module/Admin/Queue.php:72 -#: src/Module/Admin/Site.php:499 src/Module/Admin/Storage.php:139 -#: src/Module/Admin/Summary.php:233 src/Module/Admin/Themes/Details.php:90 +#: src/Module/Admin/Site.php:499 src/Module/Admin/Storage.php:138 +#: src/Module/Admin/Summary.php:232 src/Module/Admin/Themes/Details.php:90 #: src/Module/Admin/Themes/Index.php:111 src/Module/Admin/Tos.php:58 #: src/Module/Admin/Users/Active.php:136 src/Module/Admin/Users/Blocked.php:137 #: src/Module/Admin/Users/Create.php:61 src/Module/Admin/Users/Deleted.php:85 @@ -6264,48 +6261,48 @@ msgstr "" msgid "Storage backend %s error: %s" msgstr "" -#: src/Module/Admin/Storage.php:85 src/Module/Admin/Storage.php:88 +#: src/Module/Admin/Storage.php:84 src/Module/Admin/Storage.php:87 msgid "Invalid storage backend setting value." msgstr "" -#: src/Module/Admin/Storage.php:140 +#: src/Module/Admin/Storage.php:139 msgid "Current Storage Backend" msgstr "" -#: src/Module/Admin/Storage.php:141 +#: src/Module/Admin/Storage.php:140 msgid "Storage Configuration" msgstr "" -#: src/Module/Admin/Storage.php:142 src/Module/BaseAdmin.php:91 +#: src/Module/Admin/Storage.php:141 src/Module/BaseAdmin.php:91 msgid "Storage" msgstr "" -#: src/Module/Admin/Storage.php:144 +#: src/Module/Admin/Storage.php:143 msgid "Save & Use storage backend" msgstr "" -#: src/Module/Admin/Storage.php:145 +#: src/Module/Admin/Storage.php:144 msgid "Use storage backend" msgstr "" -#: src/Module/Admin/Storage.php:146 +#: src/Module/Admin/Storage.php:145 msgid "Save & Reload" msgstr "" -#: src/Module/Admin/Storage.php:147 +#: src/Module/Admin/Storage.php:146 msgid "This backend doesn't have custom settings" msgstr "" -#: src/Module/Admin/Storage.php:150 +#: src/Module/Admin/Storage.php:149 msgid "Database (legacy)" msgstr "" -#: src/Module/Admin/Summary.php:54 +#: src/Module/Admin/Summary.php:53 #, php-format msgid "Template engine (%s) error: %s" msgstr "" -#: src/Module/Admin/Summary.php:58 +#: src/Module/Admin/Summary.php:57 #, php-format msgid "" "Your DB still runs with MyISAM tables. You should change the engine type to " @@ -6316,7 +6313,7 @@ msgid "" "automatic conversion.
" msgstr "" -#: src/Module/Admin/Summary.php:63 +#: src/Module/Admin/Summary.php:62 #, php-format msgid "" "Your DB still runs with InnoDB tables in the Antelope file format. You " @@ -6327,7 +6324,7 @@ msgid "" "installation for an automatic conversion.
" msgstr "" -#: src/Module/Admin/Summary.php:73 +#: src/Module/Admin/Summary.php:72 #, php-format msgid "" "Your table_definition_cache is too low (%d). This can lead to the database " @@ -6335,39 +6332,39 @@ msgid "" "to %d. See here for more information.
" msgstr "" -#: src/Module/Admin/Summary.php:83 +#: src/Module/Admin/Summary.php:82 #, php-format msgid "" "There is a new version of Friendica available for download. Your current " "version is %1$s, upstream version is %2$s" msgstr "" -#: src/Module/Admin/Summary.php:92 +#: src/Module/Admin/Summary.php:91 msgid "" "The database update failed. Please run \"php bin/console.php dbstructure " "update\" from the command line and have a look at the errors that might " "appear." msgstr "" -#: src/Module/Admin/Summary.php:96 +#: src/Module/Admin/Summary.php:95 msgid "" "The last update failed. Please run \"php bin/console.php dbstructure update" "\" from the command line and have a look at the errors that might appear. " "(Some of the errors are possibly inside the logfile.)" msgstr "" -#: src/Module/Admin/Summary.php:101 +#: src/Module/Admin/Summary.php:100 msgid "The worker was never executed. Please check your database structure!" msgstr "" -#: src/Module/Admin/Summary.php:103 +#: src/Module/Admin/Summary.php:102 #, php-format msgid "" "The last worker execution was on %s UTC. This is older than one hour. Please " "check your crontab settings." msgstr "" -#: src/Module/Admin/Summary.php:108 +#: src/Module/Admin/Summary.php:107 #, php-format msgid "" "Friendica's configuration now is stored in config/local.config.php, please " @@ -6376,7 +6373,7 @@ msgid "" "with the transition." msgstr "" -#: src/Module/Admin/Summary.php:112 +#: src/Module/Admin/Summary.php:111 #, php-format msgid "" "Friendica's configuration now is stored in config/local.config.php, please " @@ -6385,7 +6382,7 @@ msgid "" "with the transition." msgstr "" -#: src/Module/Admin/Summary.php:118 +#: src/Module/Admin/Summary.php:117 #, php-format msgid "" "%s is not reachable on your system. This is a severe " @@ -6393,82 +6390,82 @@ msgid "" "href=\"%s\">the installation page for help." msgstr "" -#: src/Module/Admin/Summary.php:136 +#: src/Module/Admin/Summary.php:135 #, php-format msgid "The logfile '%s' is not usable. No logging possible (error: '%s')" msgstr "" -#: src/Module/Admin/Summary.php:150 +#: src/Module/Admin/Summary.php:149 #, php-format msgid "The debug logfile '%s' is not usable. No logging possible (error: '%s')" msgstr "" -#: src/Module/Admin/Summary.php:166 +#: src/Module/Admin/Summary.php:165 #, php-format msgid "" "Friendica's system.basepath was updated from '%s' to '%s'. Please remove the " "system.basepath from your db to avoid differences." msgstr "" -#: src/Module/Admin/Summary.php:174 +#: src/Module/Admin/Summary.php:173 #, php-format msgid "" "Friendica's current system.basepath '%s' is wrong and the config file '%s' " "isn't used." msgstr "" -#: src/Module/Admin/Summary.php:182 +#: src/Module/Admin/Summary.php:181 #, php-format msgid "" "Friendica's current system.basepath '%s' is not equal to the config file " "'%s'. Please fix your configuration." msgstr "" -#: src/Module/Admin/Summary.php:189 +#: src/Module/Admin/Summary.php:188 msgid "Normal Account" msgstr "" -#: src/Module/Admin/Summary.php:190 +#: src/Module/Admin/Summary.php:189 msgid "Automatic Follower Account" msgstr "" -#: src/Module/Admin/Summary.php:191 +#: src/Module/Admin/Summary.php:190 msgid "Public Forum Account" msgstr "" -#: src/Module/Admin/Summary.php:192 +#: src/Module/Admin/Summary.php:191 msgid "Automatic Friend Account" msgstr "" -#: src/Module/Admin/Summary.php:193 +#: src/Module/Admin/Summary.php:192 msgid "Blog Account" msgstr "" -#: src/Module/Admin/Summary.php:194 +#: src/Module/Admin/Summary.php:193 msgid "Private Forum Account" msgstr "" -#: src/Module/Admin/Summary.php:214 +#: src/Module/Admin/Summary.php:213 msgid "Message queues" msgstr "" -#: src/Module/Admin/Summary.php:220 +#: src/Module/Admin/Summary.php:219 msgid "Server Settings" msgstr "" -#: src/Module/Admin/Summary.php:236 +#: src/Module/Admin/Summary.php:235 msgid "Registered users" msgstr "" -#: src/Module/Admin/Summary.php:238 +#: src/Module/Admin/Summary.php:237 msgid "Pending registrations" msgstr "" -#: src/Module/Admin/Summary.php:239 +#: src/Module/Admin/Summary.php:238 msgid "Version" msgstr "" -#: src/Module/Admin/Summary.php:243 +#: src/Module/Admin/Summary.php:242 msgid "Active addons" msgstr "" @@ -7247,7 +7244,7 @@ msgstr "" msgid "Search your contacts" msgstr "" -#: src/Module/Contact.php:779 src/Module/Search/Index.php:194 +#: src/Module/Contact.php:779 src/Module/Search/Index.php:192 #, php-format msgid "Results for: %s" msgstr "" @@ -7526,8 +7523,8 @@ msgstr "" msgid "Hide" msgstr "" -#: src/Module/Conversation/Community.php:137 src/Module/Search/Index.php:139 -#: src/Module/Search/Index.php:181 +#: src/Module/Conversation/Community.php:137 src/Module/Search/Index.php:137 +#: src/Module/Search/Index.php:179 msgid "No results." msgstr "" @@ -7836,23 +7833,23 @@ msgstr "" msgid "Only logged in users are permitted to perform a probing." msgstr "" -#: src/Module/Debug/Probe.php:54 +#: src/Module/Debug/Probe.php:52 msgid "Probe Diagnostic" msgstr "" -#: src/Module/Debug/Probe.php:55 +#: src/Module/Debug/Probe.php:53 msgid "Output" msgstr "" -#: src/Module/Debug/Probe.php:58 +#: src/Module/Debug/Probe.php:56 msgid "Lookup address" msgstr "" -#: src/Module/Debug/WebFinger.php:52 +#: src/Module/Debug/WebFinger.php:50 msgid "Webfinger Diagnostic" msgstr "" -#: src/Module/Debug/WebFinger.php:54 +#: src/Module/Debug/WebFinger.php:52 msgid "Lookup address:" msgstr "" @@ -8793,11 +8790,11 @@ msgstr "" msgid "Only logged in users are permitted to perform a search." msgstr "" -#: src/Module/Search/Index.php:76 +#: src/Module/Search/Index.php:74 msgid "Only one search per minute is permitted for not logged in users." msgstr "" -#: src/Module/Search/Index.php:192 +#: src/Module/Search/Index.php:190 #, php-format msgid "Items tagged with: %s" msgstr "" @@ -9666,60 +9663,11 @@ msgid "" "e.g. Mastodon." msgstr "" -#: src/Module/Special/HTTPException.php:49 -msgid "Bad Request" -msgstr "" - #: src/Module/Special/HTTPException.php:51 -msgid "Forbidden" -msgstr "" - -#: src/Module/Special/HTTPException.php:52 -msgid "Not Found" -msgstr "" - -#: src/Module/Special/HTTPException.php:54 -msgid "Service Unavailable" -msgstr "" - -#: src/Module/Special/HTTPException.php:61 -msgid "" -"The server cannot or will not process the request due to an apparent client " -"error." -msgstr "" - -#: src/Module/Special/HTTPException.php:62 -msgid "Authentication is required and has failed or has not yet been provided." -msgstr "" - -#: src/Module/Special/HTTPException.php:63 -msgid "" -"The request was valid, but the server is refusing action. The user might not " -"have the necessary permissions for a resource, or may need an account." -msgstr "" - -#: src/Module/Special/HTTPException.php:64 -msgid "" -"The requested resource could not be found but may be available in the future." -msgstr "" - -#: src/Module/Special/HTTPException.php:65 -msgid "" -"An unexpected condition was encountered and no more specific message is " -"suitable." -msgstr "" - -#: src/Module/Special/HTTPException.php:66 -msgid "" -"The server is currently unavailable (because it is overloaded or down for " -"maintenance). Please try again later." -msgstr "" - -#: src/Module/Special/HTTPException.php:76 msgid "Stack trace:" msgstr "" -#: src/Module/Special/HTTPException.php:80 +#: src/Module/Special/HTTPException.php:55 #, php-format msgid "Exception thrown in %s:%d" msgstr "" From 3ca1cd334579ff2288067ca6fc0fd7c0a7cb1434 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 31 Oct 2021 05:31:58 +0000 Subject: [PATCH 5/8] Use getter function --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index b6869a2b13..6a00268b04 100644 --- a/include/api.php +++ b/include/api.php @@ -386,11 +386,11 @@ function api_call(App $a, App\Arguments $args = null) */ function api_error($type, $e, App\Arguments $args) { - $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc); + $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->getDescription()); /// @TODO: https://dev.twitter.com/overview/api/response-codes $error = ["error" => $error, - "code" => $e->getCode() . " " . $e->httpdesc, + "code" => $e->getCode() . " " . $e->getDescription(), "request" => $args->getQueryString()]; $return = api_format_data('status', $type, ['status' => $error]); From bfc27d151ffd0b5b686f5c8c30e7e8b168b113fe Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 31 Oct 2021 05:35:40 +0000 Subject: [PATCH 6/8] Fix test --- tests/src/Util/Emailer/MailBuilderTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/Util/Emailer/MailBuilderTest.php b/tests/src/Util/Emailer/MailBuilderTest.php index 83c22d7ec6..af80d1aff9 100644 --- a/tests/src/Util/Emailer/MailBuilderTest.php +++ b/tests/src/Util/Emailer/MailBuilderTest.php @@ -24,7 +24,7 @@ namespace Friendica\Test\src\Util\Emailer; use Friendica\App\BaseURL; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; -use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Network\HTTPException\UnprocessableEntityException; use Friendica\Object\EMail\IEmail; use Friendica\Test\MockedTest; use Friendica\Test\Util\SampleMailBuilder; @@ -133,7 +133,7 @@ class MailBuilderTest extends MockedTest */ public function testBuilderWithEmptyMail() { - $this->expectException(InternalServerErrorException::class); + $this->expectException(UnprocessableEntityException::class); $this->expectExceptionMessage("Recipient address is missing."); $builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger()); @@ -146,7 +146,7 @@ class MailBuilderTest extends MockedTest */ public function testBuilderWithEmptySender() { - $this->expectException(InternalServerErrorException::class); + $this->expectException(UnprocessableEntityException::class); $this->expectExceptionMessage("Sender address or name is missing."); $builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger()); From c3964a87352f6536786525ace5e1a717879d6901 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Nov 2021 21:21:03 +0000 Subject: [PATCH 7/8] Using internal redirect in case of missing scheme --- src/Core/System.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Core/System.php b/src/Core/System.php index 15f4ba60aa..86e562f123 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -22,7 +22,6 @@ namespace Friendica\Core; use Friendica\DI; -use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\FoundException; use Friendica\Network\HTTPException\MovedPermanentlyException; use Friendica\Network\HTTPException\TemporaryRedirectException; @@ -229,13 +228,12 @@ class System * * @param string $url The new Location to redirect * @param int $code The redirection code, which is used (Default is 302) - * - * @throws BadRequestException If the URL is not fully qualified */ public static function externalRedirect($url, $code = 302) { if (empty(parse_url($url, PHP_URL_SCHEME))) { - throw new BadRequestException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead"); + Logger::warning('No fully qualified URL provided', ['url' => $url, 'callstack' => self::callstack(20)]); + DI::baseUrl()->redirect($url); } header("Location: $url"); From 5c82c2d4ee18254ca8e73b80cb2052fe5c39a095 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Nov 2021 02:52:16 +0000 Subject: [PATCH 8/8] Removing unused "use" --- bin/auth_ejabberd.php | 2 -- bin/console.php | 2 -- bin/daemon.php | 2 -- bin/testargs.php | 2 -- bin/wait-for-connection | 5 ++--- bin/worker.php | 2 -- 6 files changed, 2 insertions(+), 13 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 22087ed017..88e5d034cb 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -51,8 +51,6 @@ * */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); exit(); diff --git a/bin/console.php b/bin/console.php index 8305176157..35f0b5feef 100755 --- a/bin/console.php +++ b/bin/console.php @@ -20,8 +20,6 @@ * */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); exit(); diff --git a/bin/daemon.php b/bin/daemon.php index 78eb74001d..7d4945fe03 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -23,8 +23,6 @@ * This script was taken from http://php.net/manual/en/function.pcntl-fork.php */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); exit(); diff --git a/bin/testargs.php b/bin/testargs.php index dbfd05a130..55197f63a3 100644 --- a/bin/testargs.php +++ b/bin/testargs.php @@ -26,8 +26,6 @@ * */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); exit(); diff --git a/bin/wait-for-connection b/bin/wait-for-connection index 35560feb2a..f0fd8cc60f 100755 --- a/bin/wait-for-connection +++ b/bin/wait-for-connection @@ -24,10 +24,9 @@ * Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}] */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { - throw new ForbiddenException(); + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); } $timeout = 60; diff --git a/bin/worker.php b/bin/worker.php index ad70bb176a..2fe03cb4b2 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -21,8 +21,6 @@ * Starts the background processing */ -use Friendica\Network\HTTPException\ForbiddenException; - if (php_sapi_name() !== 'cli') { header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); exit();