mirror of
https://github.com/friendica/friendica
synced 2025-05-02 17:04:24 +02:00
Replace System::httpExit() by HTTPException throwing
This commit is contained in:
parent
358baa9f62
commit
41f781c52a
39 changed files with 116 additions and 140 deletions
|
@ -153,7 +153,7 @@ abstract class BaseModule extends BaseObject
|
|||
Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
|
||||
Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
|
||||
|
||||
System::httpExit(403);
|
||||
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,6 @@ class Profile
|
|||
|
||||
if (!DBA::isResult($user) && empty($profiledata)) {
|
||||
Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
|
||||
notice(L10n::t('Requested account is not available.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -129,7 +128,6 @@ class Profile
|
|||
|
||||
if (empty($pdata) && empty($profiledata)) {
|
||||
Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
|
||||
notice(L10n::t('Requested profile is not available.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class Attach extends BaseModule
|
|||
{
|
||||
$a = self::getApp();
|
||||
if ($a->argc != 2) {
|
||||
System::httpExit(400); // Bad Request.
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
|
@ -33,19 +33,19 @@ class Attach extends BaseModule
|
|||
// Check for existence
|
||||
$item = MAttach::exists(['id' => $item_id]);
|
||||
if ($item === false) {
|
||||
System::httpExit(404, ['description' => L10n::t('Item was not found.')]);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
|
||||
}
|
||||
|
||||
// Now we'll fetch the item, if we have enough permisson
|
||||
$item = MAttach::getByIdWithPermission($item_id);
|
||||
if ($item === false) {
|
||||
System::httpExit(403, ['description' => L10n::t('Permission denied.')]);
|
||||
throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Permission denied.'));
|
||||
}
|
||||
|
||||
$data = MAttach::getData($item);
|
||||
if (is_null($data)) {
|
||||
Logger::log('NULL data for attachment with id ' . $item['id']);
|
||||
System::httpExit(404, ['description' => L10n::t('Item was not found.')]);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
|
||||
}
|
||||
|
||||
// Use quotes around the filename to prevent a "multiple Content-Disposition"
|
||||
|
|
|
@ -33,7 +33,7 @@ class Feed extends BaseModule
|
|||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc < 2) {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$type = null;
|
||||
|
|
|
@ -20,13 +20,13 @@ class Followers extends BaseModule
|
|||
|
||||
// @TODO: Replace with parameter from router
|
||||
if (empty($a->argv[1])) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
$owner = User::getOwnerDataByNick($a->argv[1]);
|
||||
if (empty($owner)) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$page = defaults($_REQUEST, 'page', null);
|
||||
|
|
|
@ -20,13 +20,13 @@ class Following extends BaseModule
|
|||
|
||||
// @TODO: Replace with parameter from router
|
||||
if (empty($a->argv[1])) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
$owner = User::getOwnerDataByNick($a->argv[1]);
|
||||
if (empty($owner)) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$page = defaults($_REQUEST, 'page', null);
|
||||
|
|
|
@ -137,7 +137,7 @@ class Group extends BaseModule
|
|||
$change = false;
|
||||
|
||||
if (!local_user()) {
|
||||
System::httpExit(403);
|
||||
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
||||
}
|
||||
|
||||
$a = self::getApp();
|
||||
|
@ -276,7 +276,7 @@ class Group extends BaseModule
|
|||
}
|
||||
|
||||
if (!isset($group)) {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$groupeditor = [
|
||||
|
|
|
@ -25,7 +25,7 @@ class Inbox extends BaseModule
|
|||
$postdata = file_get_contents('php://input');
|
||||
|
||||
if (empty($postdata)) {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
if (Config::get('debug', 'ap_inbox_log')) {
|
||||
|
@ -43,7 +43,7 @@ class Inbox extends BaseModule
|
|||
if (!empty($a->argv[1])) {
|
||||
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
|
||||
if (!DBA::isResult($user)) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
$uid = $user['uid'];
|
||||
} else {
|
||||
|
@ -52,6 +52,6 @@ class Inbox extends BaseModule
|
|||
|
||||
ActivityPub\Receiver::processInbox($postdata, $_SERVER, $uid);
|
||||
|
||||
System::httpExit(202);
|
||||
throw new \Friendica\Network\HTTPException\AcceptedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class Install extends BaseModule
|
|||
$a = self::getApp();
|
||||
|
||||
if (!$a->getMode()->isInstall()) {
|
||||
Core\System::httpExit(403);
|
||||
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
||||
}
|
||||
|
||||
// route: install/testrwrite
|
||||
|
@ -59,7 +59,7 @@ class Install extends BaseModule
|
|||
// @TODO: Replace with parameter from router
|
||||
if ($a->getArgumentValue(1, '') == 'testrewrite') {
|
||||
// Status Code 204 means that it worked without content
|
||||
Core\System::httpExit(204);
|
||||
throw new \Friendica\Network\HTTPException\NoContentException();
|
||||
}
|
||||
|
||||
self::$installer = new Core\Installer();
|
||||
|
|
|
@ -18,7 +18,7 @@ class NodeInfo extends BaseModule
|
|||
$config = self::getApp()->getConfig();
|
||||
|
||||
if (!$config->get('system', 'nodeinfo')) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,14 +41,14 @@ class NodeInfo extends BaseModule
|
|||
*
|
||||
* @param App $app
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
private static function printWellKnown(App $app)
|
||||
{
|
||||
$config = $app->getConfig();
|
||||
|
||||
if (!$config->get('system', 'nodeinfo')) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$nodeinfo = [
|
||||
|
|
|
@ -20,7 +20,7 @@ class Objects extends BaseModule
|
|||
$a = self::getApp();
|
||||
|
||||
if (empty($a->argv[1])) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
if (!ActivityPub::isRequest()) {
|
||||
|
@ -38,7 +38,7 @@ class Objects extends BaseModule
|
|||
// @TODO: Replace with parameter from router
|
||||
$item = Item::selectFirst(['id', 'author-link'], ['guid' => $a->argv[1], 'private' => false]);
|
||||
if (!DBA::isResult($item) || !strstr($item['author-link'], System::baseUrl())) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ class Outbox extends BaseModule
|
|||
|
||||
// @TODO: Replace with parameter from router
|
||||
if (empty($a->argv[1])) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$owner = User::getOwnerDataByNick($a->argv[1]);
|
||||
if (empty($owner)) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$page = defaults($_REQUEST, 'page', null);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Photo as MPhoto;
|
||||
|
@ -27,7 +28,7 @@ class Photo extends BaseModule
|
|||
$a = self::getApp();
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc <= 1 || $a->argc > 4) {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
|
||||
|
@ -74,9 +75,7 @@ class Photo extends BaseModule
|
|||
}
|
||||
|
||||
if ($photo === false) {
|
||||
// not using System::httpExit() because we don't want html here.
|
||||
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found" , true, 404);
|
||||
exit();
|
||||
System::httpExit('404', 'Not Found');
|
||||
}
|
||||
|
||||
$cacheable = ($photo["allow_cid"] . $photo["allow_gid"] . $photo["deny_cid"] . $photo["deny_gid"] === "") && (isset($photo["cacheable"]) ? $photo["cacheable"] : true);
|
||||
|
@ -85,7 +84,7 @@ class Photo extends BaseModule
|
|||
|
||||
if (is_null($img) || !$img->isValid()) {
|
||||
Logger::log("Invalid photo with id {$photo["id"]}.");
|
||||
System::httpExit(500, ["description" => "Invalid photo with id {$photo["id"]}."]);
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException(L10n::t('Invalid photo with id %s.', $photo["id"]));
|
||||
}
|
||||
|
||||
// if customsize is set and image is not a gif, resize it
|
||||
|
|
|
@ -38,7 +38,7 @@ class Profile extends BaseModule
|
|||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc < 2) {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
self::$which = filter_var($a->argv[1], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
|
||||
|
|
|
@ -70,7 +70,7 @@ class Proxy extends BaseModule
|
|||
$request = self::getRequestInfo();
|
||||
|
||||
if (empty($request['url'])) {
|
||||
System::httpExit(400, ['title' => L10n::t('Bad Request.')]);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
// Webserver already tried direct cache...
|
||||
|
|
|
@ -13,7 +13,7 @@ class Statistics extends BaseModule
|
|||
$config = self::getApp()->getConfig();
|
||||
|
||||
if (!$config->get("system", "nodeinfo")) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Friendica\Module;
|
|||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Network\Probe;
|
||||
|
||||
/**
|
||||
|
@ -13,22 +12,14 @@ use Friendica\Network\Probe;
|
|||
*/
|
||||
class WebFinger extends BaseModule
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
if (!local_user()) {
|
||||
System::httpExit(
|
||||
403,
|
||||
[
|
||||
'title' => L10n::t('Public access denied.'),
|
||||
'description' => L10n::t('Only logged in users are permitted to perform a probing.'),
|
||||
],
|
||||
);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public static function content()
|
||||
{
|
||||
if (!local_user()) {
|
||||
$e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a probing."));
|
||||
$e->httpdesc = L10n::t("Public access denied.");
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$app = self::getApp();
|
||||
|
||||
$addr = defaults($_GET, 'addr', '');
|
||||
|
|
|
@ -58,7 +58,7 @@ class Xrd extends BaseModule
|
|||
$user = User::getByNickname($name);
|
||||
|
||||
if (empty($user)) {
|
||||
System::httpExit(404);
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$profileURL = $app->getBaseURL() . '/profile/' . $user['nickname'];
|
||||
|
|
|
@ -400,7 +400,7 @@ class Diaspora
|
|||
if ($no_exit) {
|
||||
return false;
|
||||
} else {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ class Diaspora
|
|||
if ($no_exit) {
|
||||
return false;
|
||||
} else {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,7 @@ class Diaspora
|
|||
if ($no_exit) {
|
||||
return false;
|
||||
} else {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ class Diaspora
|
|||
if ($no_exit) {
|
||||
return false;
|
||||
} else {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,7 @@ class Diaspora
|
|||
if ($no_exit) {
|
||||
return false;
|
||||
} else {
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ class Diaspora
|
|||
|
||||
if (!$base) {
|
||||
Logger::log('unable to locate salmon data in xml');
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
|
||||
|
@ -588,7 +588,7 @@ class Diaspora
|
|||
|
||||
if (!$author_link) {
|
||||
Logger::log('Could not retrieve author URI.');
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
// Once we have the author URI, go to the web and try to find their public key
|
||||
// (first this will look it up locally if it is in the fcontact cache)
|
||||
|
@ -599,14 +599,14 @@ class Diaspora
|
|||
|
||||
if (!$key) {
|
||||
Logger::log('Could not retrieve author key.');
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
|
||||
|
||||
if (!$verify) {
|
||||
Logger::log('Message did not verify. Discarding.');
|
||||
System::httpExit(400);
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
Logger::log('Message verified.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue