From 31f5909642baebac705ae3aa661367d1fd271b51 Mon Sep 17 00:00:00 2001 From: Spine Date: Tue, 18 Mar 2025 05:50:23 +0000 Subject: [PATCH] refactor error messages and add response code --- app/Collector.php | 2 +- app/Debug.php | 2 +- app/Error.php | 28 ++++ app/Error400.php | 19 +++ app/Error403.php | 32 ++++ app/Error404.php | 19 +++ app/Error429.php | 19 +++ app/Error500.php | 19 +++ app/Manager/Comment.php | 4 +- app/Search/Torrent.php | 3 +- classes/sphinxql.class.php | 7 +- gazelle.php | 55 +++---- lib/util.php | 33 ++-- .../20250322000000_admin_privileges.php | 151 ++++++++++++++++++ misc/phpstan-baseline.neon | 40 ----- sections/ajax/index.php | 4 +- sections/ajax/loadavg.php | 13 +- sections/ajax/logchecker.php | 2 +- sections/ajax/post_edit.php | 2 +- sections/ajax/requests.php | 4 +- sections/ajax/torrent_tag_remove.php | 4 +- sections/apply/admin.php | 2 +- sections/apply/edit.php | 4 +- sections/apply/view.php | 4 +- sections/artist/add_alias.php | 14 +- sections/artist/add_similar.php | 4 +- sections/artist/artist.php | 2 +- sections/artist/change_artistid.php | 10 +- sections/artist/delete.php | 4 +- sections/artist/delete_alias.php | 10 +- sections/artist/delete_similar.php | 4 +- sections/artist/download.php | 8 +- sections/artist/edit.php | 6 +- sections/artist/edit_handle.php | 10 +- sections/artist/edit_request.php | 2 +- sections/artist/edit_request_handle.php | 2 +- sections/artist/history.php | 2 +- sections/artist/index.php | 4 +- sections/artist/notify.php | 4 +- sections/artist/notify_remove.php | 4 +- sections/artist/rename.php | 18 ++- sections/artist/vote_similar.php | 4 +- sections/better/better.php | 4 +- sections/better/transcode.php | 4 +- sections/blog/dead_thread.php | 6 +- sections/blog/delete_blog.php | 4 +- sections/blog/edit_blog_handle.php | 8 +- sections/blog/new_blog_handle.php | 6 +- sections/bonus/bprates.php | 4 +- sections/bonus/history.php | 4 +- sections/bonus/index.php | 4 +- sections/bonus/invite.php | 4 +- sections/bonus/purchase.php | 8 +- sections/bonus/title.php | 8 +- sections/bonus/token_other.php | 10 +- sections/bonus/tokens.php | 6 +- sections/bookmarks/artists.php | 4 +- sections/bookmarks/edit_torrents.php | 4 +- sections/bookmarks/index.php | 6 +- sections/bookmarks/torrents.php | 4 +- sections/collages/add_artist.php | 18 ++- sections/collages/add_torrent.php | 20 +-- sections/collages/all_comments.php | 2 +- sections/collages/browse.php | 6 +- sections/collages/collage.php | 2 +- sections/collages/delete.php | 4 +- sections/collages/delete_handle.php | 6 +- sections/collages/download.php | 8 +- sections/collages/edit.php | 6 +- sections/collages/edit_handle.php | 12 +- sections/collages/manage.php | 6 +- sections/collages/manage_artists.php | 8 +- sections/collages/manage_artists_handle.php | 10 +- sections/collages/manage_handle.php | 12 +- sections/collages/new.php | 2 +- sections/collages/new_handle.php | 4 +- sections/collages/recover.php | 4 +- sections/comments/comments.php | 6 +- sections/comments/delete_handle.php | 4 +- sections/comments/edit_handle.php | 10 +- sections/comments/get.php | 2 +- sections/comments/jump.php | 2 +- sections/comments/post_handle.php | 6 +- sections/comments/warn.php | 4 +- sections/contest/admin.php | 2 +- sections/enable/index.php | 2 +- sections/error/403.php | 9 -- sections/error/404.php | 12 -- sections/error/413.php | 7 - sections/error/504.php | 7 - sections/error/index.php | 61 ------- sections/forums/add_poll_option.php | 6 +- sections/forums/catchup.php | 2 +- sections/forums/change_vote.php | 6 +- sections/forums/delete.php | 6 +- sections/forums/delete_poll_option.php | 8 +- sections/forums/do_warn.php | 16 +- sections/forums/edit_handle.php | 12 +- sections/forums/forum.php | 4 +- sections/forums/get_post.php | 4 +- sections/forums/index.php | 2 +- sections/forums/new_thread.php | 4 +- sections/forums/new_thread_handle.php | 12 +- sections/forums/poll_mod.php | 4 +- sections/forums/poll_vote.php | 6 +- sections/forums/reply_handle.php | 8 +- sections/forums/search.php | 10 +- sections/forums/sticky_post.php | 4 +- sections/forums/thread.php | 8 +- sections/forums/thread_handle.php | 18 +-- sections/forums/thread_notes_handle.php | 6 +- sections/forums/warn.php | 6 +- sections/friends/add.php | 6 +- sections/friends/comment.php | 4 +- sections/friends/remove.php | 2 +- sections/inbox/compose.php | 6 +- sections/inbox/compose_handle.php | 8 +- sections/inbox/conversation.php | 2 +- sections/inbox/edit_handle.php | 4 +- sections/inbox/forward.php | 10 +- sections/inbox/get_post.php | 4 +- sections/inbox/massdelete_handle.php | 2 +- sections/index/index.php | 2 +- sections/logchecker/test_handle.php | 4 +- sections/logchecker/upload_handle.php | 8 +- sections/random/index.php | 2 +- sections/recovery/admin.php | 4 +- sections/recovery/browse.php | 2 +- sections/recovery/pair.php | 2 +- sections/recovery/view.php | 4 +- sections/report_auto/reports.php | 10 +- sections/reports/compose.php | 26 +-- sections/reports/compose_handle.php | 6 +- sections/reports/report.php | 26 +-- sections/reports/report_handle.php | 8 +- sections/reports/reports.php | 2 +- sections/reports/resolve_handle.php | 4 +- sections/reports/stats.php | 2 +- sections/reportsv2/ajax_claim.php | 2 +- sections/reportsv2/ajax_new_report.php | 2 +- sections/reportsv2/ajax_switch.php | 2 +- sections/reportsv2/ajax_unclaim.php | 2 +- sections/reportsv2/ajax_update_comment.php | 2 +- sections/reportsv2/report_handle.php | 34 ++-- sections/reportsv2/reports.php | 2 +- sections/reportsv2/search.php | 4 +- sections/reportsv2/static.php | 2 +- sections/reportsv2/views.php | 2 +- sections/requests/bounty_handle.php | 8 +- sections/requests/delete_handle.php | 4 +- sections/requests/edit.php | 4 +- sections/requests/edit_bounty.php | 4 +- sections/requests/edit_handle.php | 6 +- sections/requests/fill_handle.php | 2 +- sections/requests/index.php | 2 +- sections/requests/interim.php | 8 +- sections/requests/new.php | 2 +- sections/requests/new_handle.php | 4 +- sections/requests/request.php | 2 +- sections/requests/requests.php | 12 +- sections/requests/unfill_handle.php | 4 +- sections/requests/vote_handle.php | 2 +- sections/staffblog/index.php | 8 +- sections/staffpm/ajax_delete_response.php | 2 +- sections/staffpm/ajax_edit_response.php | 2 +- sections/staffpm/ajax_get_response.php | 2 +- sections/staffpm/assign.php | 10 +- sections/staffpm/common_responses.php | 2 +- sections/staffpm/get_post.php | 4 +- sections/staffpm/scoreboard.php | 2 +- sections/staffpm/staff_inbox.php | 2 +- sections/staffpm/unresolve.php | 4 +- sections/staffpm/viewconv.php | 4 +- sections/staffpm/viewconv_handle.php | 10 +- sections/tools/data/bonus_stats.php | 2 +- sections/tools/data/economic_stats.php | 2 +- sections/tools/data/invite_pool.php | 2 +- sections/tools/data/platform_usage.php | 2 +- sections/tools/data/ratio_watch.php | 2 +- sections/tools/data/registration_log.php | 2 +- sections/tools/data/site_info.php | 2 +- sections/tools/data/special_users.php | 2 +- sections/tools/data/torrent_stats.php | 2 +- sections/tools/data/user_flow.php | 2 +- sections/tools/data/user_info.php | 4 +- sections/tools/development/analysis.php | 2 +- sections/tools/development/analysis_list.php | 2 +- sections/tools/development/clear_cache.php | 4 +- sections/tools/development/db_sandbox.php | 2 +- sections/tools/development/mysql.php | 4 +- sections/tools/development/notification.php | 2 +- sections/tools/development/periodic_alter.php | 8 +- .../tools/development/periodic_detail.php | 4 +- sections/tools/development/periodic_edit.php | 2 +- sections/tools/development/periodic_run.php | 4 +- sections/tools/development/periodic_stats.php | 2 +- sections/tools/development/periodic_view.php | 4 +- sections/tools/development/pg.php | 2 +- sections/tools/development/process_info.php | 2 +- .../tools/development/referral_sandbox.php | 2 +- sections/tools/development/service_stats.php | 2 +- sections/tools/development/site_options.php | 4 +- sections/tools/finances/donation_log.php | 2 +- sections/tools/finances/donor_rewards.php | 2 +- sections/tools/finances/payment_alter.php | 4 +- sections/tools/finances/payment_list.php | 2 +- sections/tools/index.php | 2 +- .../managers/ajax_take_enable_request.php | 2 +- sections/tools/managers/asn_search.php | 2 +- sections/tools/managers/bans.php | 6 +- sections/tools/managers/bonus_points.php | 4 +- sections/tools/managers/categories_alter.php | 10 +- sections/tools/managers/categories_list.php | 2 +- sections/tools/managers/change_log.php | 2 +- sections/tools/managers/create_user.php | 10 +- sections/tools/managers/custom_pm.php | 4 +- sections/tools/managers/db_key.php | 2 +- sections/tools/managers/dnu_alter.php | 4 +- sections/tools/managers/dnu_list.php | 2 +- sections/tools/managers/dupe_ip.php | 2 +- sections/tools/managers/email_blacklist.php | 2 +- .../tools/managers/email_blacklist_alter.php | 10 +- sections/tools/managers/email_search.php | 2 +- sections/tools/managers/enable_requests.php | 4 +- sections/tools/managers/featured_album.php | 12 +- sections/tools/managers/forum_alter.php | 12 +- sections/tools/managers/forum_list.php | 2 +- .../managers/forum_transitions_alter.php | 12 +- .../tools/managers/forum_transitions_list.php | 9 +- .../tools/managers/global_notification.php | 2 +- sections/tools/managers/invite_source.php | 2 +- .../tools/managers/invite_source_config.php | 2 +- sections/tools/managers/ip_search.php | 2 +- sections/tools/managers/login_watch.php | 2 +- sections/tools/managers/manipulate_tree.php | 8 +- sections/tools/managers/mass_pm.php | 2 +- sections/tools/managers/navigation_alter.php | 10 +- sections/tools/managers/navigation_list.php | 2 +- sections/tools/managers/news.php | 10 +- sections/tools/managers/ocelot.php | 2 +- sections/tools/managers/ocelot_info.php | 6 +- sections/tools/managers/privilege_matrix.php | 2 +- sections/tools/managers/quick_ban.php | 4 +- sections/tools/managers/rate_limit.php | 6 +- sections/tools/managers/reaper.php | 2 +- sections/tools/managers/referral_accounts.php | 2 +- sections/tools/managers/referral_alter.php | 8 +- sections/tools/managers/referral_users.php | 4 +- sections/tools/managers/ssl_host.php | 2 +- .../tools/managers/staff_groups_alter.php | 6 +- sections/tools/managers/staff_groups_list.php | 2 +- sections/tools/managers/stylesheets_list.php | 2 +- sections/tools/managers/tags.php | 2 +- sections/tools/managers/tags_aliases.php | 2 +- sections/tools/managers/tags_official.php | 4 +- sections/tools/managers/take_mass_pm.php | 4 +- sections/tools/managers/tokens.php | 6 +- sections/tools/managers/tor_node.php | 2 +- .../tools/managers/torrent_report_edit.php | 4 +- .../tools/managers/torrent_report_view.php | 2 +- sections/tools/managers/userclass_alter.php | 10 +- sections/tools/managers/userclass_edit.php | 2 +- sections/tools/managers/userclass_list.php | 2 +- sections/tools/managers/whitelist_alter.php | 8 +- sections/tools/managers/whitelist_list.php | 2 +- sections/tools/tools.php | 2 +- sections/top10/history.php | 4 +- sections/torrents/add_alias.php | 4 +- sections/torrents/add_cover_art.php | 10 +- sections/torrents/collector.php | 14 +- sections/torrents/delete.php | 28 ++-- sections/torrents/delete_alias.php | 8 +- sections/torrents/delete_handle.php | 16 +- sections/torrents/details.php | 2 +- sections/torrents/downloadlist.php | 4 +- sections/torrents/edit.php | 4 +- sections/torrents/edit_category_handle.php | 16 +- sections/torrents/edit_group.php | 5 +- sections/torrents/edit_group_handle.php | 16 +- sections/torrents/edit_handle.php | 18 ++- sections/torrents/edit_log.php | 6 +- sections/torrents/edit_log_handle.php | 6 +- sections/torrents/edit_request.php | 2 +- sections/torrents/edit_request_handle.php | 2 +- sections/torrents/grouplog.php | 2 +- sections/torrents/history.php | 2 +- sections/torrents/log_ajax.php | 2 +- sections/torrents/manage_artists.php | 8 +- sections/torrents/masspm.php | 4 +- sections/torrents/masspm_handle.php | 6 +- sections/torrents/merge.php | 10 +- sections/torrents/new_group_handle.php | 6 +- sections/torrents/new_groupid.php | 8 +- sections/torrents/nonwikiedit.php | 5 +- sections/torrents/notify.php | 4 +- sections/torrents/notify_actions.php | 10 +- sections/torrents/peerlist.php | 2 +- sections/torrents/redownload.php | 12 +- sections/torrents/regen.php | 4 +- sections/torrents/remove_log.php | 4 +- sections/torrents/remove_logs.php | 4 +- sections/torrents/rename.php | 6 +- sections/torrents/rescore_log.php | 4 +- sections/torrents/reseed.php | 16 +- sections/torrents/snatchlist.php | 4 +- sections/torrents/user.php | 22 +-- sections/torrents/vote_tag.php | 2 +- sections/upload/index.php | 4 +- sections/upload/parse_html.php | 5 +- sections/user/2fa/complete.php | 8 +- sections/user/2fa/index.php | 8 +- sections/user/2fa/remove.php | 6 +- sections/user/advancedsearch.php | 2 +- sections/user/audit-edit-handle.php | 10 +- sections/user/audit-edit.php | 10 +- sections/user/audit.php | 4 +- sections/user/delete_invite.php | 4 +- sections/user/edit.php | 4 +- sections/user/edit_handle.php | 20 +-- sections/user/index.php | 6 +- sections/user/invite.php | 4 +- sections/user/invite_handle.php | 10 +- sections/user/invitetree.php | 4 +- sections/user/moderate_handle.php | 14 +- sections/user/notify_edit.php | 2 +- sections/user/notify_handle.php | 4 +- sections/user/permissions.php | 4 +- sections/user/push_handle.php | 4 +- sections/user/search.php | 12 +- sections/user/seedbox_edit.php | 18 +-- sections/user/seedbox_view.php | 8 +- sections/user/sessions.php | 4 +- sections/user/token.php | 2 +- sections/user/user.php | 10 +- sections/user/user_stats.php | 6 +- sections/user/userlink_handle.php | 10 +- sections/user/vote_history.php | 4 +- sections/userhistory/announce_key_history.php | 4 +- sections/userhistory/catchup_collages.php | 2 +- sections/userhistory/collage_subscribe.php | 2 +- sections/userhistory/comments_subscribe.php | 2 +- sections/userhistory/email_history.php | 4 +- sections/userhistory/ip_history.php | 4 +- sections/userhistory/ip_tracker_history.php | 4 +- sections/userhistory/password_history.php | 4 +- sections/userhistory/post_history.php | 4 +- sections/userhistory/quote_notifications.php | 2 +- sections/userhistory/subscribed_collages.php | 2 +- sections/userhistory/subscriptions.php | 2 +- sections/userhistory/thread_subscribe.php | 6 +- sections/userhistory/token_history.php | 8 +- sections/userhistory/topic_history.php | 4 +- sections/view/index.php | 6 +- sections/wiki/add_alias.php | 6 +- sections/wiki/article.php | 2 +- sections/wiki/compare.php | 6 +- sections/wiki/create_handle.php | 8 +- sections/wiki/delete.php | 8 +- sections/wiki/delete_alias.php | 4 +- sections/wiki/delete_handle.php | 4 +- sections/wiki/edit.php | 4 +- sections/wiki/edit_handle.php | 10 +- sections/wiki/revisions.php | 4 +- templates/error.twig | 13 +- tests/cypress/e2e/1-simple/basic.cy.js | 7 +- tests/phpunit/ErrorTest.php | 52 ++++++ 366 files changed, 1368 insertions(+), 1118 deletions(-) create mode 100644 app/Error.php create mode 100644 app/Error400.php create mode 100644 app/Error403.php create mode 100644 app/Error404.php create mode 100644 app/Error429.php create mode 100644 app/Error500.php create mode 100644 misc/phinx/migrations/20250322000000_admin_privileges.php delete mode 100644 sections/error/403.php delete mode 100644 sections/error/404.php delete mode 100644 sections/error/413.php delete mode 100644 sections/error/504.php delete mode 100644 sections/error/index.php create mode 100644 tests/phpunit/ErrorTest.php diff --git a/app/Collector.php b/app/Collector.php index a971d9378..b3f319854 100644 --- a/app/Collector.php +++ b/app/Collector.php @@ -117,7 +117,7 @@ abstract class Collector extends Base { '44' => $sql .= "t.Format = 'AAC' AND t.Encoding = 'q5.5'", '45' => $sql .= "t.Format = 'AAC' AND t.Encoding = 'q5'", '46' => $sql .= "t.Format = 'AAC' AND t.Encoding = '192'", - default => error('Unknown collector selector'), + default => Error400::error('Unknown collector selector'), }; $sql .= " THEN $Priority "; } diff --git a/app/Debug.php b/app/Debug.php index 6e7c51664..b80f6bb4c 100644 --- a/app/Debug.php +++ b/app/Debug.php @@ -146,7 +146,7 @@ class Debug { ); } - public function saveError(\Exception $e): int { + public function saveError(\Error|\Exception $e): int { return $this->saveCase( $e->getMessage() . "\n" . str_replace(SERVER_ROOT . '/', '', $e->getTraceAsString()) diff --git a/app/Error.php b/app/Error.php new file mode 100644 index 000000000..7fe0e9db3 --- /dev/null +++ b/app/Error.php @@ -0,0 +1,28 @@ +render('error.twig', [ + 'code' => static::errorCode(), + 'label' => static::errorLabel(), + 'description' => static::errorDescription(), + 'message' => $message, + ]); + } + + abstract public static function errorCode(): int; + + abstract public static function errorLabel(): string; + + abstract public static function errorDescription(): string; +} diff --git a/app/Error400.php b/app/Error400.php new file mode 100644 index 000000000..23c3525cc --- /dev/null +++ b/app/Error400.php @@ -0,0 +1,19 @@ +viewer()->label(); + $ipaddr = static::$requestContext->viewer()->ipaddr(); + $geoip = new Util\GeoIP(new Util\Curl()); + Util\Irc::sendMessage( + IRC_CHAN_STATUS, + "$who ($ipaddr [{$geoip->countryISO($ipaddr)}]) on {$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']}" + . (!empty($_SERVER['HTTP_REFERER']) ? " from {$_SERVER['HTTP_REFERER']}" : '') + . (!empty($message) ? " message '$message'" : '') + ); + parent::error($message); + } + + public static function errorCode(): int { + return 403; + } + + public static function errorLabel(): string { + return 'Forbidden'; + } + + public static function errorDescription(): string { + return "You cannot view something you are not allowed to view."; + } +} diff --git a/app/Error404.php b/app/Error404.php new file mode 100644 index 000000000..1b6a84f16 --- /dev/null +++ b/app/Error404.php @@ -0,0 +1,19 @@ + \Gazelle\Comment\Collage::class, 'requests' => \Gazelle\Comment\Request::class, 'torrents' => \Gazelle\Comment\Torrent::class, - default => error("no comments for " . display_str($page)), + default => Error400::error("no comments for " . html_escape($page)), }; } diff --git a/app/Search/Torrent.php b/app/Search/Torrent.php index 4d1d0604d..4e2bd19b2 100644 --- a/app/Search/Torrent.php +++ b/app/Search/Torrent.php @@ -4,6 +4,7 @@ namespace Gazelle\Search; use Gazelle\Enum\LeechType; +use Gazelle\Error500; class Torrent { final protected const TAGS_ANY = 0; @@ -199,7 +200,7 @@ class Torrent { $ErrMsg, 86_400, ); - error('-1'); + Error500::error(); } $this->Page = $searchMany ? $Page : min($Page, SPHINX_MAX_MATCHES / $PageSize); /** @phpstan-ignore-line sphinx must die */ diff --git a/classes/sphinxql.class.php b/classes/sphinxql.class.php index 117d5ecb2..6a4ff1995 100644 --- a/classes/sphinxql.class.php +++ b/classes/sphinxql.class.php @@ -1,11 +1,6 @@ ' . display_str($error) . ''; die(); } else { - error('-1'); + Gazelle\Error500::error($message); } } } diff --git a/gazelle.php b/gazelle.php index 5361826d2..9fc1b23a6 100644 --- a/gazelle.php +++ b/gazelle.php @@ -1,6 +1,8 @@ logoutEverywhere(); $forceLogout(); } - $session = new Gazelle\User\Session($Viewer); + $session = new User\Session($Viewer); if (!$session->valid($SessionID)) { $Viewer->logout($SessionID); $forceLogout(); @@ -139,16 +141,16 @@ if ($Viewer) { // To proxify images (or not), or e.g. not render the name of a thread // for a user who may lack the privileges to see it in the first place. \Text::setViewer($Viewer); - \Gazelle\Util\Twig::setViewer($Viewer); + Util\Twig::setViewer($Viewer); $context->setViewer($Viewer); } unset($forceLogout); $Debug->mark('load page'); -if (DEBUG_MODE || ($Viewer && $Viewer->permitted('site_debug'))) { - $Twig->addExtension(new Twig\Extension\DebugExtension()); +if (DEBUG_MODE || $Viewer?->permitted('site_debug')) { + $Twig->addExtension(new \Twig\Extension\DebugExtension()); } -Gazelle\Base::setRequestContext($context); +Base::setRequestContext($context); // for sections/tools/development/process_info.php $Cache->cache_value('php_' . getmypid(), [ @@ -181,30 +183,25 @@ header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0'); header('Pragma: no-cache'); $file = realpath(__DIR__ . "/sections/{$module}/index.php"); -if (!$file || !preg_match('/^[a-z][a-z0-9_]+$/', $module)) { - error($Viewer ? 403 : 404); +if ($file === false) { + Error400::error(); } try { include_once $file; -} catch (Gazelle\DB\MysqlException $e) { - Gazelle\DB::DB()->rollback(); // if there was an ongoing transaction, abort it - if (DEBUG_MODE || (isset($Viewer) && $Viewer->permitted('site_debug'))) { - echo $Twig->render('error-db.twig', [ - 'message' => $e->getMessage(), - 'trace' => str_replace(SERVER_ROOT . '/', '', $e->getTraceAsString()), - ]); - } else { - $id = $Debug->saveError($e); - error("That is not supposed to happen, please create a thread in the Bugs forum explaining what you were doing and referencing Error ID $id"); +} catch (\Error | \Exception $e) { + // if there was an ongoing transaction, abort it + if ($e::class === DB\MysqlException::class) { + DB::DB()->rollback(); + } + $id = $Debug->saveError($e); + $message = DEBUG_MODE || $Viewer?->permitted('site_debug') + ? ($e->getMessage() . " (case $id)") + : "That is not supposed to happen, you can a thread in the Bugs forum explaining what you were doing and referencing Error ID $id"; + Error500::error($message); +} finally { + $Debug->mark('send to user'); + if (!is_null($Viewer)) { + $Debug->profile($Viewer, $module); } -} catch (\Exception $e) { - $Debug->saveError($e); -} - -// 5. Finish up - -$Debug->mark('send to user'); -if (!is_null($Viewer)) { - $Debug->profile($Viewer, $module); } diff --git a/lib/util.php b/lib/util.php index 6fe562b27..876b8bec1 100644 --- a/lib/util.php +++ b/lib/util.php @@ -343,7 +343,7 @@ function authKey(): string { * Make sure $_GET['auth'] is the same as the user's authorization key * Should be used for any user action that relies solely on GET. */ -function authorize(bool $Ajax = false): void { +function authorize(bool $ajax = false): void { global $Viewer; foreach (['auth', 'authkey'] as $auth) { if (isset($_REQUEST[$auth]) && $Viewer->auth() === $_REQUEST[$auth]) { @@ -354,7 +354,13 @@ function authorize(bool $Ajax = false): void { "{$Viewer->username()} authorize failed on {$_SERVER['REQUEST_URI']}" . (!empty($_SERVER['HTTP_REFERER']) ? " coming from " . $_SERVER['HTTP_REFERER'] : "") ); - error('Invalid authorization key. Go back, refresh, and try again.', $Ajax); + if ($ajax) { + json_die('Invalid authorization key. Go back, refresh, and try again.'); + } else { + Gazelle\Error400::error( + 'Invalid authorization key. Go back, refresh, and try again.' + ); + } } function parse_user_agent(string $useragent): array { @@ -411,25 +417,6 @@ function parse_user_agent(string $useragent): array { return $browserUserAgent; } -/** - * Display a critical error and kills the page. - * - * $Error Error type. Automatically supported: - * 403, 404, 0 (invalid input), -1 (invalid request) - * If you use your own string for Error, it becomes the error description. - * $NoHTML If true, the header/footer won't be shown, just the description. - * $Log If true, the user is given a link to search $Log in the site log. - */ -// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -function error(int|string $Error, bool $NoHTML = false, bool $Log = false): never { - global $Debug, $Viewer, $Twig; - include_once __DIR__ . '/../sections/error/index.php'; - if (isset($Viewer)) { - $Debug->profile($Viewer, $Viewer->requestContext()->module()); - } - exit; -} - // phpcs:enable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed /** @@ -460,11 +447,11 @@ function json_error(int|string $code): never { exit; } -function json_or_error(mixed $JsonError, mixed $Error = null, bool $NoHTML = false): never { +function json_or_error(mixed $JsonError, mixed $Error = null): never { if (defined('AJAX')) { json_error($JsonError); } else { - error($Error ?? $JsonError, $NoHTML); + Gazelle\Error400::error($Error ?? $JsonError); } } diff --git a/misc/phinx/migrations/20250322000000_admin_privileges.php b/misc/phinx/migrations/20250322000000_admin_privileges.php new file mode 100644 index 000000000..f73410898 --- /dev/null +++ b/misc/phinx/migrations/20250322000000_admin_privileges.php @@ -0,0 +1,151 @@ +getQueryBuilder('update') /** @phpstan-ignore-line need more magic */ + ->update('permissions') + ->set('`Values`', + serialize([ + 'admin_add_log' => 1, + 'admin_advanced_user_search' => 1, + 'admin_audit_edit' => 1, + 'admin_audit_view' => 1, + 'admin_bp_history' => 1, + 'admin_clear_cache' => 1, + 'admin_create_users' => 1, + 'admin_dnu' => 1, + 'admin_donor_log' => 1, + 'admin_fl_history' => 1, + 'admin_freeleech' => 1, + 'admin_global_notification' => 1, + 'admin_login_watch' => 1, + 'admin_manage_applicants' => 1, + 'admin_manage_blog' => 1, + 'admin_manage_contest' => 1, + 'admin_manage_fls' => 1, + 'admin_manage_forums' => 1, + 'admin_manage_invite_source' => 1, + 'admin_manage_ipbans' => 1, + 'admin_manage_navigation' => 1, + 'admin_manage_news' => 1, + 'admin_manage_payments' => 1, + 'admin_manage_permissions' => 1, + 'admin_manage_polls' => 1, + 'admin_manage_referrals' => 1, + 'admin_manage_stylesheets' => 1, + 'admin_manage_user_fls' => 1, + 'admin_manage_wiki' => 1, + 'admin_periodic_task_manage' => 1, + 'admin_periodic_task_view' => 1, + 'admin_rate_limit_manage' => 1, + 'admin_rate_limit_view' => 1, + 'admin_recovery' => 1, + 'admin_reports' => 1, + 'admin_schedule' => 1, + 'admin_site_debug' => 1, + 'admin_staffpm_stats' => 1, + 'admin_tracker' => 1, + 'admin_view_notifications' => 1, + 'admin_view_payments' => 1, + 'admin_view_referrals' => 1, + 'admin_whitelist' => 1, + 'artist_edit_vanityhouse' => 1, + 'can_use_tor' => 1, + 'edit_unknowns' => 1, + 'forums_polls_create' => 1, + 'forums_polls_moderate' => 1, + 'site_admin_forums' => 1, + 'site_admin_requests' => 1, + 'site_advanced_search' => 1, + 'site_advanced_top10' => 1, + 'site_album_votes' => 1, + 'site_analysis' => 1, + 'site_archive_ajax' => 1, + 'site_can_invite_always' => 1, + 'site_collages_create' => 1, + 'site_collages_delete' => 1, + 'site_collages_manage' => 1, + 'site_collages_personal' => 1, + 'site_collages_recover' => 1, + 'site_collages_renamepersonal' => 1, + 'site_collages_subscribe' => 1, + 'site_database_specifics' => 1, + 'site_debug' => 1, + 'site_delete_artist' => 1, + 'site_delete_tag' => 1, + 'site_disable_ip_history' => 1, + 'site_edit_lineage' => 1, + 'site_edit_requests' => 1, + 'site_edit_wiki' => 1, + 'site_forum_autosub' => 1, + 'site_forum_post_delete' => 1, + 'site_make_bookmarks' => 1, + 'site_moderate_forums' => 1, + 'site_moderate_requests' => 1, + 'site_search_many' => 1, + 'site_send_unlimited_invites' => 1, + 'site_submit_requests' => 1, + 'site_tag_aliases_read' => 1, + 'site_top10' => 1, + 'site_torrents_notify' => 1, + 'site_unlimit_ajax' => 1, + 'site_upload' => 1, + 'site_user_stats' => 1, + 'site_view_flow' => 1, + 'site_view_full_log' => 1, + 'site_view_torrent_snatchlist' => 1, + 'site_vote' => 1, + 'torrents_add_artist' => 1, + 'torrents_delete' => 1, + 'torrents_delete_fast' => 1, + 'torrents_edit' => 1, + 'torrents_edit_vanityhouse' => 1, + 'torrents_freeleech' => 1, + 'users_auto_reports' => 1, + 'users_delete_users' => 1, + 'users_disable_any' => 1, + 'users_disable_posts' => 1, + 'users_disable_users' => 1, + 'users_edit_avatars' => 1, + 'users_edit_invites' => 1, + 'users_edit_own_ratio' => 1, + 'users_edit_password' => 1, + 'users_edit_profiles' => 1, + 'users_edit_ratio' => 1, + 'users_edit_reset_keys' => 1, + 'users_edit_titles' => 1, + 'users_edit_usernames' => 1, + 'users_give_donor' => 1, + 'users_invite_notes' => 1, + 'users_linked_users' => 1, + 'users_logout' => 1, + 'users_make_invisible' => 1, + 'users_mod' => 1, + 'users_override_paranoia' => 1, + 'users_promote_below' => 1, + 'users_promote_to' => 1, + 'users_reset_own_keys' => 1, + 'users_view_email' => 1, + 'users_view_friends' => 1, + 'users_view_invites' => 1, + 'users_view_ips' => 1, + 'users_view_keys' => 1, + 'users_view_seedleech' => 1, + 'users_view_uploaded' => 1, + 'users_warn' => 1, + 'view_last_seen' => 1, + 'zip_downloader' => 1, + ]) + ) + ->where(['Level' => 1000]) + ->execute(); + } + + public function down(): void { + // no-op + } +} diff --git a/misc/phpstan-baseline.neon b/misc/phpstan-baseline.neon index 6df44e32f..2094026af 100644 --- a/misc/phpstan-baseline.neon +++ b/misc/phpstan-baseline.neon @@ -230,46 +230,6 @@ parameters: count: 1 path: ../sections/better/better.php - - - message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#" - count: 1 - path: ../sections/error/404.php - - - - message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#" - count: 1 - path: ../sections/error/413.php - - - - message: "#^Function Gazelle\\\\notify invoked with 2 parameters, 3 required\\.$#" - count: 1 - path: ../sections/error/504.php - - - - message: "#^Function Gazelle\\\\notify\\(\\) has no return type specified\\.$#" - count: 1 - path: ../sections/error/index.php - - - - message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Channel with no type specified\\.$#" - count: 1 - path: ../sections/error/index.php - - - - message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Message with no type specified\\.$#" - count: 1 - path: ../sections/error/index.php - - - - message: "#^Function Gazelle\\\\notify\\(\\) has parameter \\$Viewer with no type specified\\.$#" - count: 1 - path: ../sections/error/index.php - - - - message: "#^Variable \\$Error might not be defined\\.$#" - count: 1 - path: ../sections/error/index.php - - message: "#^Variable \\$info might not be defined\\.$#" count: 1 diff --git a/sections/ajax/index.php b/sections/ajax/index.php index 45e25a63a..68814bc4b 100644 --- a/sections/ajax/index.php +++ b/sections/ajax/index.php @@ -67,10 +67,10 @@ if (!$Action || !isset($Viewer)) { } $UserID = $Viewer->id(); -if (!empty($_SERVER['CONTENT_TYPE']) && str_starts_with($_SERVER['CONTENT_TYPE'], 'application/json')) { +if (str_starts_with($_SERVER['CONTENT_TYPE'] ?? '', 'application/json')) { $input = file_get_contents('php://input'); if ($input === false) { - error("json decode failure"); + json_error("json decode failure"); } $_POST = json_decode($input, true); } diff --git a/sections/ajax/loadavg.php b/sections/ajax/loadavg.php index dbd8c112b..3aa535f14 100644 --- a/sections/ajax/loadavg.php +++ b/sections/ajax/loadavg.php @@ -6,12 +6,7 @@ namespace Gazelle; authorize(true); -print - json_encode( - [ - 'status' => 'success', - 'response' => [ - 'loadAverage' => sys_getloadavg() - ] - ] - ); +print json_encode([ + 'status' => 'success', + 'response' => ['loadAverage' => sys_getloadavg()] +]); diff --git a/sections/ajax/logchecker.php b/sections/ajax/logchecker.php index b19172a75..2e25cf430 100644 --- a/sections/ajax/logchecker.php +++ b/sections/ajax/logchecker.php @@ -11,7 +11,7 @@ if (isset($_FILES['log']) && is_uploaded_file($_FILES['log']['tmp_name'])) { $fileTmp = tempnam(TMPDIR, 'log_'); if ($fileTmp === false) { // This will only happen if the directory that TMPDIR points to disappears - error('Failed to persist the log file.'); + json_error('Failed to persist the log file.'); } file_put_contents($fileTmp, $_POST["pastelog"]); $file = [ diff --git a/sections/ajax/post_edit.php b/sections/ajax/post_edit.php index 2a5ef1102..b72ba8764 100644 --- a/sections/ajax/post_edit.php +++ b/sections/ajax/post_edit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_admin_forums')) { - error(403); + Error403::error(); } $postId = (int)($_GET['postid'] ?? 0); diff --git a/sections/ajax/requests.php b/sections/ajax/requests.php index b45e412e9..c5fa66da5 100644 --- a/sections/ajax/requests.php +++ b/sections/ajax/requests.php @@ -58,7 +58,7 @@ switch ($type) { case 'bookmarks': $Title = 'Your bookmarked requests'; if (is_null($user)) { - error("No user id given"); + json_die("No user id given"); } $search->setBookmarker($user); $BookmarkView = true; @@ -99,7 +99,7 @@ if (isset($_GET['requestor'])) { if ($requestor) { $search->setRequestor($requestor); } else { - error(404); + json_die('requestor not found'); } } diff --git a/sections/ajax/torrent_tag_remove.php b/sections/ajax/torrent_tag_remove.php index d6b4d077f..4212c5f0e 100644 --- a/sections/ajax/torrent_tag_remove.php +++ b/sections/ajax/torrent_tag_remove.php @@ -8,7 +8,7 @@ namespace Gazelle; authorize(); if ($Viewer->disableTagging() || !$Viewer->permitted('site_delete_tag')) { - error(403); + Error403::error(); } $tagMan = new Manager\Tag(); $tgMan = new Manager\TGroup(); @@ -16,7 +16,7 @@ $tgMan = new Manager\TGroup(); $tag = $tagMan->findById((int)$_GET['tagid']); $tgroup = $tgMan->findById((int)$_GET['groupid']); if (is_null($tgroup) || is_null($tag)) { - error(404); + Error404::error(); } $tagName = $tag->name(); diff --git a/sections/apply/admin.php b/sections/apply/admin.php index bbbdf2155..bd7d707c5 100644 --- a/sections/apply/admin.php +++ b/sections/apply/admin.php @@ -13,7 +13,7 @@ if ($Viewer->permitted('admin_manage_applicants')) { /** @var \Gazelle\User $Viewer phpstan is dense */ if (!array_filter($appRoleMan->publishedList(), fn($r) => $r->isStaffViewer($Viewer))) { // a user is being naughty - error(403); + Error403::error(); } // Staff who can see specific roles cannot see the admin page header('Location: apply.php?action=view'); diff --git a/sections/apply/edit.php b/sections/apply/edit.php index fef1e8b3e..6b1e1a388 100644 --- a/sections/apply/edit.php +++ b/sections/apply/edit.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_applicants')) { - error(403); + Error403::error(); } $role = (new Manager\ApplicantRole())->findById((int)($_GET['id'] ?? 0)); if (is_null($role)) { - error(404); + Error404::error(); } if (isset($_POST['auth'])) { diff --git a/sections/apply/view.php b/sections/apply/view.php index f0f7b9982..a68627440 100644 --- a/sections/apply/view.php +++ b/sections/apply/view.php @@ -10,10 +10,10 @@ $appMan = new Manager\Applicant(); if (isset($_REQUEST['id'])) { $app = $appMan->findById((int)$_GET['id']); if (is_null($app)) { - error(404); + Error404::error(); } if (!$app->isViewable($Viewer)) { - error(403); + Error403::error(); } if (!empty($_POST['note_reply'])) { diff --git a/sections/artist/add_alias.php b/sections/artist/add_alias.php index fc04dbbbd..3bef5e1f4 100644 --- a/sections/artist/add_alias.php +++ b/sections/artist/add_alias.php @@ -7,28 +7,28 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } authorize(); $redirectId = (int)$_POST['redirect']; $newName = Artist::sanitize($_POST['name']); if (empty($newName)) { - error('The specified name is empty.'); + Error400::error('The specified name is empty.'); } $artMan = new Manager\Artist(); $artist = $artMan->findById((int)$_POST['artistid']); if (is_null($artist)) { - error(404); + Error404::error(); } elseif ($artist->isLocked() && !$Viewer->permitted('users_mod')) { - error('This artist is locked.'); + Error400::error('This artist is locked.'); } $otherArtist = $artMan->findByName($newName); if ($otherArtist) { if ($otherArtist->id() === $artist->id()) { - error("This artist already has the specified alias."); + Error400::error("This artist already has the specified alias."); } echo $Twig->render('artist/error-alias.twig', [ 'alias' => $newName, @@ -41,10 +41,10 @@ $redirArtist = null; if ($redirectId) { $redirArtist = $artMan->findByAliasId($redirectId); if (is_null($redirArtist)) { - error("No alias found for desired redirect."); + Error400::error("No alias found for desired redirect."); } if ($artist->id() !== $redirArtist->id()) { - error("Cannot redirect to the alias of a different artist."); + Error400::error("Cannot redirect to the alias of a different artist."); } } diff --git a/sections/artist/add_similar.php b/sections/artist/add_similar.php index bf49461ca..9ba42a14a 100644 --- a/sections/artist/add_similar.php +++ b/sections/artist/add_similar.php @@ -15,7 +15,7 @@ if (is_null($artist)) { if (defined('AJAX')) { json_die('failure', 'no such artist'); } else { - error(404); + Error404::error('no such artist'); } } $other = $artistMan->findByName(trim($_POST['artistname'] ?? '')); @@ -25,7 +25,7 @@ if (is_null($other)) { if (defined('AJAX')) { json_die('failure', 'no such similar artist name'); } else { - error('Unknown similar artist name.'); + Error404::error('Unknown similar artist name.'); } } } diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 10dd8fea8..34ce3d5f2 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -14,7 +14,7 @@ $artist = $revisionId ? $artistMan->findByIdAndRevision((int)($_GET['id'] ?? 0), $revisionId) : $artistMan->findById((int)($_GET['id'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } $artist->loadArtistRole(); $artistId = $artist->id(); diff --git a/sections/artist/change_artistid.php b/sections/artist/change_artistid.php index f54f9d2cd..e5ee4cba1 100644 --- a/sections/artist/change_artistid.php +++ b/sections/artist/change_artistid.php @@ -7,28 +7,28 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } authorize(); $artMan = new Manager\Artist(); $artist = $artMan->findById((int)($_POST['artistid'] ?? 0)); if (is_null($artist)) { - error('Please select a valid artist to change.'); + Error400::error('Please select a valid artist to change.'); } elseif ($artist->isLocked() && !$Viewer->permitted('users_mod')) { - error('This artist is locked.'); + Error400::error('This artist is locked.'); } $new = $artMan->findById((int)($_POST['newartistid'] ?? 0)); if (is_null($new)) { $new = $artMan->findByName($_POST['newartistname'] ?? ''); if (is_null($new)) { - error('Please enter a valid artist ID number or a valid artist name.'); + Error404::error('Please enter a valid artist ID number or a valid artist name.'); } } if ($artist->id() == $new->id()) { - error('You cannot merge an artist with itself.'); + Error400::error('You cannot merge an artist with itself.'); } $redirect = (bool)$_POST['redirect']; diff --git a/sections/artist/delete.php b/sections/artist/delete.php index ac9087dea..e9333df3d 100644 --- a/sections/artist/delete.php +++ b/sections/artist/delete.php @@ -7,13 +7,13 @@ declare(strict_types=1); namespace Gazelle; if (!($Viewer->permitted('site_delete_artist') && $Viewer->permitted('torrents_delete'))) { - error(403); + Error403::error(); } authorize(); $artist = (new Manager\Artist())->findById((int)($_GET['artistid'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } $tgMan = new Manager\TGroup(); diff --git a/sections/artist/delete_alias.php b/sections/artist/delete_alias.php index 2e7c126b8..86f49ae65 100644 --- a/sections/artist/delete_alias.php +++ b/sections/artist/delete_alias.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } authorize(); @@ -15,16 +15,16 @@ $artMan = new Manager\Artist(); $aliasId = (int)$_GET['aliasid']; $artist = $artMan->findByAliasId($aliasId); if (is_null($artist)) { - error(404); + Error404::error(); } elseif ($artist->isLocked() && !$Viewer->permitted('users_mod')) { - error('This artist is locked.'); + Error400::error('This artist is locked.'); } if ($artist->primaryAliasId() === $aliasId) { - error("You cannot delete the primary alias."); + Error400::error("You cannot delete the primary alias."); } if (!empty($artist->aliasInfo()[$aliasId]['alias'])) { - error("This alias has redirecting aliases attached."); + Error400::error("This alias has redirecting aliases attached."); } $tgroupList = $artMan->tgroupList($aliasId, new Manager\TGroup()); diff --git a/sections/artist/delete_similar.php b/sections/artist/delete_similar.php index 05a2aef95..d936670c6 100644 --- a/sections/artist/delete_similar.php +++ b/sections/artist/delete_similar.php @@ -8,14 +8,14 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_delete_tag')) { - error(403); + Error403::error(); } $artistMan = new Manager\Artist(); $artist = $artistMan->findById((int)($_GET['artistid'] ?? 0)); $similar = $artistMan->findById((int)($_GET['similarid'] ?? 0)); if (is_null($artist) || is_null($similar)) { - error(404); + Error404::error(); } $artist->similar()->removeSimilar($similar, $Viewer); diff --git a/sections/artist/download.php b/sections/artist/download.php index 4b28a1e7c..84b59a4b9 100644 --- a/sections/artist/download.php +++ b/sections/artist/download.php @@ -6,19 +6,19 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('zip_downloader')) { - error(403); + Error403::error(); } if (!isset($_REQUEST['preference']) || count($_REQUEST['list']) === 0) { - error('No artist collector preference specified'); + Error400::error('No artist collector preference specified'); } $artist = (new Manager\Artist())->findById((int)($_REQUEST['artistid'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } $collector = new Collector\Artist($Viewer, new Manager\Torrent(), $artist, (int)$_REQUEST['preference']); if (!$collector->prepare($_REQUEST['list'])) { - error("Nothing to gather, choose some encodings and media!"); + Error400::error("Nothing to gather, choose some encodings and media!"); } $Viewer->modifyOption('Collector', [implode(':', $_REQUEST['list']), $_REQUEST['preference']]); diff --git a/sections/artist/edit.php b/sections/artist/edit.php index 9fc6414b4..9c40b2ba7 100644 --- a/sections/artist/edit.php +++ b/sections/artist/edit.php @@ -7,13 +7,15 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $artist = (new Manager\Artist())->findById((int)$_GET['artistid']); if (is_null($artist)) { $id = html_escape($_GET['artistid']); // might not be a number - error("Cannot find an artist with the ID $id: See the site log."); + Error400::error( + "Cannot find an artist with the ID $id: See the site log." + ); } echo $Twig->render('artist/edit.twig', [ diff --git a/sections/artist/edit_handle.php b/sections/artist/edit_handle.php index 406120521..89f20d9fd 100644 --- a/sections/artist/edit_handle.php +++ b/sections/artist/edit_handle.php @@ -6,21 +6,21 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_edit_wiki')) { - error(403); + Error403::error(); } authorize(); $artist = (new Manager\Artist())->findById((int)$_POST['artistid']); if (is_null($artist)) { - error(404); + Error404::error(); } if (($_GET['action'] ?? '') === 'revert') { // if we're reverting to a previous revision authorize(); $revisionId = (int)$_GET['revisionid']; if (!$revisionId) { - error('No revision given to revert'); + Error400::error('No revision given to revert'); } $artist->revertRevision($revisionId, $Viewer); header("Location: " . $artist->location()); @@ -36,11 +36,11 @@ $image = trim($_POST['image']); if ($image != $artist->image()) { if (!empty($image)) { if (!preg_match(IMAGE_REGEXP, $image)) { - error(display_str($image) . " does not look like a valid image url"); + Error400::error(html_escape($image) . " does not look like a valid image url"); } $banned = (new Util\ImageProxy($Viewer))->badHost($image); if ($banned) { - error("Please rehost images from $banned elsewhere."); + Error400::error("Please rehost images from $banned elsewhere."); } } $artist->setField('image', $image); diff --git a/sections/artist/edit_request.php b/sections/artist/edit_request.php index fa4b036a2..06d658308 100644 --- a/sections/artist/edit_request.php +++ b/sections/artist/edit_request.php @@ -8,7 +8,7 @@ namespace Gazelle; $artist = (new Manager\Artist())->findById((int)($_GET['artistid'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } echo $Twig->render('artist/request-edit.twig', [ diff --git a/sections/artist/edit_request_handle.php b/sections/artist/edit_request_handle.php index 0e43ccd4a..073b22552 100644 --- a/sections/artist/edit_request_handle.php +++ b/sections/artist/edit_request_handle.php @@ -8,7 +8,7 @@ namespace Gazelle; $artist = (new Manager\Artist())->findById((int)($_POST['artistid'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } authorize(); diff --git a/sections/artist/history.php b/sections/artist/history.php index f30f6f2c0..b77e457e6 100644 --- a/sections/artist/history.php +++ b/sections/artist/history.php @@ -8,7 +8,7 @@ namespace Gazelle; $artistMan = new Manager\Artist(); $artist = $artistMan->findById((int)$_GET['artistid']); if (is_null($artist)) { - error(404); + Error404::error(); } echo $Twig->render('revision.twig', ['object' => $artist]); diff --git a/sections/artist/index.php b/sections/artist/index.php index fc13d89d1..cc12be5dd 100644 --- a/sections/artist/index.php +++ b/sections/artist/index.php @@ -14,7 +14,7 @@ if (!empty($_POST['action'])) { 'rename' => include_once 'rename.php', 'edit' => include_once 'edit_handle.php', 'takeeditrequest' => include_once 'edit_request_handle.php', - default => error('Missing artist POST action'), + default => Error400::error('Missing artist POST action'), }; } elseif (!empty($_GET['action'])) { match ($_GET['action']) { @@ -30,7 +30,7 @@ if (!empty($_POST['action'])) { 'notifyremove' => include_once 'notify_remove.php', 'revert' => include_once 'edit_handle.php', 'vote_similar' => include_once 'vote_similar.php', - default => error('Missing artist action'), + default => Error400::error('Missing artist action'), }; } else { if (!empty($_GET['id'])) { diff --git a/sections/artist/notify.php b/sections/artist/notify.php index aef6776d8..9cac48fe4 100644 --- a/sections/artist/notify.php +++ b/sections/artist/notify.php @@ -6,13 +6,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_torrents_notify')) { - error(403); + Error403::error(); } authorize(); $artist = (new Manager\Artist())->findById((int)$_GET['artistid']); if (is_null($artist)) { - error(404); + Error404::error(); } $Viewer->addArtistNotification($artist); diff --git a/sections/artist/notify_remove.php b/sections/artist/notify_remove.php index fc139b94f..df50bc660 100644 --- a/sections/artist/notify_remove.php +++ b/sections/artist/notify_remove.php @@ -6,13 +6,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_torrents_notify')) { - error(403); + Error403::error(); } authorize(); $artist = (new Manager\Artist())->findById((int)$_GET['artistid']); if (is_null($artist)) { - error(404); + Error404::error(); } $Viewer->removeArtistNotification($artist); diff --git a/sections/artist/rename.php b/sections/artist/rename.php index 9021919f4..9e3f0683a 100644 --- a/sections/artist/rename.php +++ b/sections/artist/rename.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } authorize(); @@ -14,25 +14,27 @@ authorize(); $artistMan = new Manager\Artist(); $artist = $artistMan->findById((int)($_POST['artistid'] ?? 0)); if (is_null($artist) || empty($_POST['aliasid'])) { - error(404); + Error404::error(); } elseif ($artist->isLocked() && !$Viewer->permitted('users_mod')) { - error('This artist is locked.'); + Error400::error('This artist is locked.'); } $aliasId = (int)$_POST['aliasid']; $newName = Artist::sanitize($_POST['name']); if (empty($newName)) { - error('No new name given.'); + Error400::error('No new name given.'); } elseif (!isset($artist->aliasList()[$aliasId])) { - error('Could not find existing alias ID'); + Error400::error('Could not find existing alias ID'); } elseif ($artist->aliasList()[$aliasId]['name'] === $newName) { - error('The new name is identical to the old name."'); + Error400::error('The new name is identical to the old name."'); } $oldName = $artist->aliasList()[$aliasId]['name']; $otherArtist = $artistMan->findByName($newName); if (!is_null($otherArtist) && $otherArtist->id() !== $artist->id()) { - error("An artist with this alias already exists: {$otherArtist->name()} ({$otherArtist->id()})"); + Error400::error( + "An artist with this alias already exists: {$otherArtist->name()} ({$otherArtist->id()})" + ); } $result = $artist->renameAlias( @@ -44,7 +46,7 @@ $result = $artist->renameAlias( ); if (is_null($result)) { - error("The specified name is already in use."); + Error::error("The specified name is already in use."); } header("Location: artist.php?artistid={$artist->id()}&action=edit"); diff --git a/sections/artist/vote_similar.php b/sections/artist/vote_similar.php index 94425693a..515b2c5a8 100644 --- a/sections/artist/vote_similar.php +++ b/sections/artist/vote_similar.php @@ -7,14 +7,14 @@ namespace Gazelle; $way = trim($_GET['way']); if (!in_array($way, ['up', 'down'])) { - error('Missing artist vote decision'); + Error::error('Missing artist vote decision'); } $artistMan = new Manager\Artist(); $artist = $artistMan->findById((int)($_GET['artistid'] ?? 0)); $similar = $artistMan->findById((int)($_GET['similarid'] ?? 0)); if (is_null($artist) || is_null($similar)) { - error("One of the artists was not found"); + Error::error("One of the artists was not found"); } $artist->similar()->voteSimilar($Viewer, $similar, $way === 'up'); diff --git a/sections/better/better.php b/sections/better/better.php index 7f1ccadbd..1a319fae2 100644 --- a/sections/better/better.php +++ b/sections/better/better.php @@ -10,7 +10,7 @@ $userMan = new Manager\User(); if (isset($_GET['userid']) && $Viewer->permitted('users_override_paranoia')) { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } else { $user = $Viewer; @@ -34,7 +34,7 @@ $better = match ($type) { 'single' => new Better\SingleSeeded($user, $filter, (new Manager\Torrent())->setViewer($Viewer)), 'files', 'folders', 'lineage', 'tags', 'trumpable' => (new Better\Bad($user, $filter, new Manager\Torrent()))->setBadType($type), - default => error(404), + default => Error404::error(), }; if (isset($_GET['remove']) && $better instanceof Better\Bad && $Viewer->permitted('admin_reports')) { diff --git a/sections/better/transcode.php b/sections/better/transcode.php index 781ab0552..1993c94cc 100644 --- a/sections/better/transcode.php +++ b/sections/better/transcode.php @@ -20,11 +20,11 @@ if (!isset($_GET['userid'])) { $user = $Viewer; } else { if (!$Viewer->permitted('users_override_paranoia')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/blog/dead_thread.php b/sections/blog/dead_thread.php index 2e4f1bec4..eb7d03b4e 100644 --- a/sections/blog/dead_thread.php +++ b/sections/blog/dead_thread.php @@ -6,13 +6,15 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_blog')) { - error(403); + Error403::error(); } authorize(); $blog = (new Manager\Blog())->findById((int)($_GET['id'] ?? 0)); if (is_null($blog)) { - error('Please provide the ID of a blog post from which to remove the thread link.'); + Error404::error( + 'Please provide the ID of a blog post from which to remove the thread link.' + ); } $blog->removeThread(); diff --git a/sections/blog/delete_blog.php b/sections/blog/delete_blog.php index 6c17125ce..a67c87375 100644 --- a/sections/blog/delete_blog.php +++ b/sections/blog/delete_blog.php @@ -6,14 +6,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_blog')) { - error(403); + Error403::error(); } authorize(); $blogMan = new Manager\Blog(); $blog = $blogMan->findById((int)($_GET['id'] ?? 0)); if (is_null($blog)) { - error('You must provide an ID of a blog to delete'); + Error404::error('You must provide an ID of a blog to delete'); } $blog->remove(); $blogMan->flush(); diff --git a/sections/blog/edit_blog_handle.php b/sections/blog/edit_blog_handle.php index 24812b83c..b9d6189e9 100644 --- a/sections/blog/edit_blog_handle.php +++ b/sections/blog/edit_blog_handle.php @@ -6,23 +6,23 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_blog')) { - error(403); + Error403::error(); } authorize(); $body = trim($_POST['body']); if (empty($body)) { - error('The body of the blog article must not be empty'); + Error400::error('The body of the blog article must not be empty'); } $title = trim($_POST['title']); if (empty($title)) { - error('The title of the blog article must not be empty'); + Error400::error('The title of the blog article must not be empty'); } $blog = (new Manager\Blog())->findById((int)($_POST['blogid'] ?? 0)); if (is_null($blog)) { - error(404); + Error404::error(); } $manager = new Manager\ForumThread(); diff --git a/sections/blog/new_blog_handle.php b/sections/blog/new_blog_handle.php index 6a2a93399..1cf6cfa21 100644 --- a/sections/blog/new_blog_handle.php +++ b/sections/blog/new_blog_handle.php @@ -8,18 +8,18 @@ namespace Gazelle; use Gazelle\Enum\NotificationType; if (!$Viewer->permitted('admin_manage_blog')) { - error(403); + Error403::error(); } authorize(); $body = trim($_POST['body']); if (empty($body)) { - error('The body of the blog article must not be empty'); + Error400::error('The body of the blog article must not be empty'); } $title = trim($_POST['title']); if (empty($title)) { - error('The title of the blog article must not be empty'); + Error400::error('The title of the blog article must not be empty'); } $thread = match ((int)($_POST['thread'] ?? -1)) { diff --git a/sections/bonus/bprates.php b/sections/bonus/bprates.php index e52b1c6c3..70e625638 100644 --- a/sections/bonus/bprates.php +++ b/sections/bonus/bprates.php @@ -28,11 +28,11 @@ if (empty($_GET['userid'])) { $ownProfile = true; } else { if (!$Viewer->permitted('admin_bp_history')) { - error(403); + Error403::error(); } $user = $userMan->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $ownProfile = false; } diff --git a/sections/bonus/history.php b/sections/bonus/history.php index 70eedcc73..0411a87d7 100644 --- a/sections/bonus/history.php +++ b/sections/bonus/history.php @@ -10,11 +10,11 @@ if (!isset($_GET['userid'])) { $user = $Viewer; } else { if (!$Viewer->permitted('admin_bp_history')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/bonus/index.php b/sections/bonus/index.php index ddf0ef45c..b4e721dec 100644 --- a/sections/bonus/index.php +++ b/sections/bonus/index.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableBonusPoints()) { - error('Your bonus points have been deactivated.'); + Error403::error('Your bonus points have been deactivated.'); } const DEFAULT_PAGE = 'store.php'; @@ -24,7 +24,7 @@ switch ($_GET['action'] ?? '') { } $Price = $viewerBonus->effectivePrice($Label); if ($Price > $Viewer->bonusPointsTotal()) { - error('You cannot afford this item.'); + Error400::error('You cannot afford this item.'); } include_once match ($Label) { 'invite' => 'invite.php', diff --git a/sections/bonus/invite.php b/sections/bonus/invite.php index 8105d4ced..741c87268 100644 --- a/sections/bonus/invite.php +++ b/sections/bonus/invite.php @@ -7,6 +7,8 @@ namespace Gazelle; authorize(); if (!(new User\Bonus($Viewer))->purchaseInvite()) { - error("You cannot purchase an invite (either you don't have the privilege or you don't have enough bonus points)."); + Error400::error( + "You cannot purchase an invite (either you don't have the privilege or you don't have enough bonus points)." + ); } header('Location: bonus.php?complete=invite'); diff --git a/sections/bonus/purchase.php b/sections/bonus/purchase.php index 6bcfed37c..f9e711233 100644 --- a/sections/bonus/purchase.php +++ b/sections/bonus/purchase.php @@ -12,19 +12,19 @@ $bonus = new User\Bonus($Viewer); if ($label === 'collage-1') { if (!$bonus->purchaseCollage($label)) { - error('Could not purchase a personal collage slot due to lack of funds.'); + Error400::error('Could not purchase a personal collage slot due to lack of funds.'); } header("Location: bonus.php?complete=$label"); } elseif ($label === 'seedbox') { if (!$bonus->unlockSeedbox()) { - error('Could not unlock the seedbox viewer. Either you have already unlocked it, or you lack the required bonus points.'); + Error400::error('Could not unlock the seedbox viewer. Either you have already unlocked it, or you lack the required bonus points.'); } header("Location: bonus.php?complete=$label"); } elseif ($label === 'file-count') { if (!$bonus->purchaseFeatureFilecount()) { - error('Could not purchase the file count feature. Either you have already own it, or you lack the required bonus points.'); + Error400::error('Could not purchase the file count feature. Either you have already own it, or you lack the required bonus points.'); } header("Location: bonus.php?complete=$label"); } else { - error(403); + Error403::error(); } diff --git a/sections/bonus/title.php b/sections/bonus/title.php index c3468c746..bdbd6a14b 100644 --- a/sections/bonus/title.php +++ b/sections/bonus/title.php @@ -30,17 +30,19 @@ if ($Label === 'title-bb-y') { } elseif ($Label === 'title-bb-n') { $BBCode = 'false'; } else { - error(403); + Error403::error(); } if (isset($_POST['confirm'])) { authorize(); if (!isset($_POST['title'])) { - error(403); + Error403::error(); } $viewerBonus = new \Gazelle\User\Bonus($Viewer); if (!$viewerBonus->purchaseTitle($Label, $_POST['title'])) { - error('This title is too long, you must reduce the length (or you do not have enough bonus points).'); + Error400::error( + 'This title is too long, you must reduce the length (or you do not have enough bonus points).' + ); } header('Location: bonus.php?complete=' . urlencode($Label)); exit; diff --git a/sections/bonus/token_other.php b/sections/bonus/token_other.php index a565f2f89..e1e8c6e3f 100644 --- a/sections/bonus/token_other.php +++ b/sections/bonus/token_other.php @@ -15,17 +15,19 @@ namespace Gazelle; if (isset($_POST['confirm'])) { authorize(); if (empty($_POST['user'])) { - error('You have to enter a username to give tokens to.'); + Error404::error('You have to enter a username to give tokens to.'); } $user = (new Manager\User())->findByUsername(urldecode($_POST['user'])); if (is_null($user)) { - error('Nobody with that name found at ' . SITE_NAME . '. Try a user search and give them tokens from their profile page.'); + Error404::error( + 'Nobody with that name found. Try a user search and give them tokens from their profile page.' + ); } elseif ($user->id() == $Viewer->id()) { - error('You cannot gift yourself tokens, they are cheaper to buy directly.'); + Error400::error('You cannot gift yourself tokens, they are cheaper to buy directly.'); } $viewerBonus = new \Gazelle\User\Bonus($Viewer); if (!$viewerBonus->purchaseTokenOther($user, $Label, $_POST['message'] ?? '')) { - error('Purchase for other not concluded. Either you lacked funds or they have chosen to decline FL tokens.'); + Error400::error('Purchase for other not concluded. Either you lacked funds or they have chosen to decline FL tokens.'); } header('Location: bonus.php?complete=' . urlencode($Label)); } diff --git a/sections/bonus/tokens.php b/sections/bonus/tokens.php index 76e8056db..5479b1465 100644 --- a/sections/bonus/tokens.php +++ b/sections/bonus/tokens.php @@ -12,12 +12,14 @@ namespace Gazelle; authorize(); if (!preg_match('/^token-[1-4]$/', $Label, $match)) { - error(403); + Error403::error(); } $viewerBonus = new \Gazelle\User\Bonus($Viewer); if (!$viewerBonus->purchaseToken($Label)) { - error("You aren't able to buy those tokens. Do you have enough bonus points?"); + Error400::error( + "You aren't able to buy those tokens. Do you have enough bonus points?" + ); } header('Location: bonus.php?complete=' . urlencode($Label)); diff --git a/sections/bookmarks/artists.php b/sections/bookmarks/artists.php index 3ba673fea..2653ae872 100644 --- a/sections/bookmarks/artists.php +++ b/sections/bookmarks/artists.php @@ -12,10 +12,10 @@ if (!isset($_GET['userid'])) { } else { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() != $Viewer->id() && !$Viewer->permitted('users_override_paranoia')) { - error(403); + Error403::error(); } } diff --git a/sections/bookmarks/edit_torrents.php b/sections/bookmarks/edit_torrents.php index 490d69941..db9a00a25 100644 --- a/sections/bookmarks/edit_torrents.php +++ b/sections/bookmarks/edit_torrents.php @@ -10,11 +10,11 @@ if (empty($_GET['userid'])) { $user = $Viewer; } else { if (!$Viewer->permitted('users_override_paranoia')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/bookmarks/index.php b/sections/bookmarks/index.php index bfa4abbd7..5cb478e97 100644 --- a/sections/bookmarks/index.php +++ b/sections/bookmarks/index.php @@ -24,7 +24,7 @@ switch ($_REQUEST['action'] ?? 'view') { case 'edit': match ($_REQUEST['type'] ?? '') { 'torrents' => include_once 'edit_torrents.php', - default => error(404), + default => Error404::error(), }; break; @@ -45,10 +45,10 @@ switch ($_REQUEST['action'] ?? 'view') { include_once __DIR__ . '/../requests/requests.php'; break; default: - error(404); + Error404::error(); } break; default: - error(404); + Error404::error(); } diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index af6cff029..2102a69ad 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -19,11 +19,11 @@ if (empty($_GET['userid'])) { $ownProfile = true; } else { if (!$Viewer->permitted('users_override_paranoia')) { - error(403); + Error403::error(); } $user = $userMan->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $ownProfile = ($user->id() === $Viewer->id()); } diff --git a/sections/collages/add_artist.php b/sections/collages/add_artist.php index aef12a389..8abc58127 100644 --- a/sections/collages/add_artist.php +++ b/sections/collages/add_artist.php @@ -8,7 +8,7 @@ namespace Gazelle; authorize(); if (!in_array($_POST['action'], ['add_artist', 'add_artist_batch'])) { - error(403); + Error403::error(); } $collageMan = new Manager\Collage(); @@ -29,18 +29,18 @@ if (is_null($collage) && isset($_POST['collage_ref'])) { $collage = $collageMan->findById((int)$_POST['collageid']); } if (is_null($collage)) { - error(404); + Error404::error(); } if (!$Viewer->permitted('site_collages_delete')) { if ($collage->isLocked()) { - error('This collage is locked'); + Error400::error('This collage is locked'); } if ($collage->isPersonal() && !$collage->isOwner($Viewer)) { - error("You cannot edit someone else's personal collage."); + Error400::error("You cannot edit someone else's personal collage."); } if ($collage->maxGroups() > 0 && $collage->numEntries() >= $collage->maxGroups()) { - error('This collage already holds its maximum allowed number of entries.'); + Error400::error('This collage already holds its maximum allowed number of entries.'); } } @@ -74,7 +74,7 @@ foreach ($URL as $u) { ? $artistMan->findById((int)$match['id']) : null; if (is_null($artist)) { - error("The artist " . htmlspecialchars($u) . " does not exist."); + Error400::error("The artist " . htmlspecialchars($u) . " does not exist."); } $list[] = $artist; } @@ -84,13 +84,15 @@ if (!$Viewer->permitted('site_collages_delete')) { $maxGroupsPerUser = $collage->maxGroupsPerUser(); if ($maxGroupsPerUser > 0) { if ($collage->contributionTotal($Viewer) + count($list) > $maxGroupsPerUser) { - error("You may add no more than $maxGroupsPerUser entries to this collage."); + Error400::error( + "You may add no more than $maxGroupsPerUser entries to this collage." + ); } } $maxGroups = $collage->maxGroups(); if ($maxGroups > 0 && ($collage->numEntries() + count($list) > $maxGroups)) { - error("This collage can hold only $maxGroups entries."); + Error400::error("This collage can hold only $maxGroups entries."); } } diff --git a/sections/collages/add_torrent.php b/sections/collages/add_torrent.php index b0ff0f4cc..7b8394af6 100644 --- a/sections/collages/add_torrent.php +++ b/sections/collages/add_torrent.php @@ -8,10 +8,10 @@ namespace Gazelle; authorize(); if (!in_array($_REQUEST['action'], ['add_torrent', 'add_torrent_batch'])) { - error(403); + Error403::error(); } if (!$Viewer->permitted('site_collages_manage') && !$Viewer->activePersonalCollages()) { - error(403); + Error403::error(); } $collageMan = new Manager\Collage(); @@ -27,18 +27,18 @@ if (isset($_POST['collage_combo']) && (int)$_POST['collage_combo']) { $collage = $collageMan->findById((int)$_POST['collageid']); // From collage page } if (!$collage) { - error(404); + Error404::error(); } if (!$Viewer->permitted('site_collages_delete')) { if ($collage->isLocked()) { - error('This collage is locked'); + Error400::error('This collage is locked'); } if ($collage->isPersonal() && !$collage->isOwner($Viewer)) { - error('You cannot edit someone else\'s personal collage.'); + Error400::error('You cannot edit someone else\'s personal collage.'); } if ($collage->maxGroups() > 0 && $collage->numEntries() >= $collage->maxGroups()) { - error('This collage already holds its maximum allowed number of entries.'); + Error400::error('This collage already holds its maximum allowed number of entries.'); } } @@ -70,7 +70,7 @@ foreach ($URL as $u) { preg_match(TGROUP_REGEXP, $u, $match); $tgroup = $tgroupMan->findById((int)($match['id'] ?? 0)); if (is_null($tgroup)) { - error("The torrent " . htmlspecialchars($u) . " does not exist."); + Error400::error("The torrent " . htmlspecialchars($u) . " does not exist."); } $list[] = $tgroup; } @@ -80,14 +80,16 @@ if (!$Viewer->permitted('site_collages_delete')) { if ($maxGroupsPerUser > 0) { if ($collage->contributionTotal($Viewer) + count($list) > $maxGroupsPerUser) { $entry = $maxGroupsPerUser === 1 ? 'entry' : 'entries'; - error("You may add no more than $maxGroupsPerUser $entry to this collage."); + Error400::error( + "You may add no more than $maxGroupsPerUser $entry to this collage." + ); } } $maxGroups = $collage->maxGroups(); if ($maxGroups > 0 && ($collage->numEntries() + count($list) > $maxGroups)) { $entry = $maxGroupsPerUser === 1 ? 'entry' : 'entries'; - error("This collage can hold only $maxGroups $entry."); + Error400::error("This collage can hold only $maxGroups $entry."); } } diff --git a/sections/collages/all_comments.php b/sections/collages/all_comments.php index 4812ab1f1..56301f2c2 100644 --- a/sections/collages/all_comments.php +++ b/sections/collages/all_comments.php @@ -8,7 +8,7 @@ namespace Gazelle; $collage = (new Manager\Collage())->findById((int)($_GET['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } $commentPage = new Comment\Collage($collage->id(), (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0)); diff --git a/sections/collages/browse.php b/sections/collages/browse.php index 16f658b74..8f510f5b1 100644 --- a/sections/collages/browse.php +++ b/sections/collages/browse.php @@ -40,16 +40,16 @@ if (($_GET['action'] ?? '') === 'mine') { if (!empty($_GET['userid'])) { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } if (empty($_GET['contrib'])) { if (!$user->propertyVisible($Viewer, 'collages')) { - error(403); + Error403::error(); } $search->setUser($user); } else { if (!$user->propertyVisible($Viewer, 'collagecontribs')) { - error(403); + Error403::error(); } $search->setContributor($user); } diff --git a/sections/collages/collage.php b/sections/collages/collage.php index 689b11de2..410e66d32 100644 --- a/sections/collages/collage.php +++ b/sections/collages/collage.php @@ -7,7 +7,7 @@ namespace Gazelle; $collageMan = new Manager\Collage(); $Collage = $collageMan->findById((int)($_GET['id'] ?? 0)); if (is_null($Collage)) { - error(404); + Error404::error(); } if ($Collage->isDeleted()) { diff --git a/sections/collages/delete.php b/sections/collages/delete.php index a5a2af23f..99601389b 100644 --- a/sections/collages/delete.php +++ b/sections/collages/delete.php @@ -8,10 +8,10 @@ namespace Gazelle; $collage = (new Manager\Collage())->findById((int)($_GET['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } if ($collage->isDeleted() && !$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } echo $Twig->render('collage/delete.twig', [ diff --git a/sections/collages/delete_handle.php b/sections/collages/delete_handle.php index b8b43380b..e4edb49a3 100644 --- a/sections/collages/delete_handle.php +++ b/sections/collages/delete_handle.php @@ -9,15 +9,15 @@ authorize(); $reason = trim($_POST['reason']); if (!$reason) { - error('You must enter a reason!'); + Error400::error('You must enter a reason!'); } $collage = (new Manager\Collage())->findById((int)$_POST['collageid']); if (is_null($collage)) { - error(404); + Error404::error(); } if (!$Viewer->permitted('site_collages_delete') && !$collage->isOwner($Viewer)) { - error(403); + Error403::error(); } $collageId = $collage->id(); diff --git a/sections/collages/download.php b/sections/collages/download.php index 652169b9a..c9d233a66 100644 --- a/sections/collages/download.php +++ b/sections/collages/download.php @@ -6,21 +6,21 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('zip_downloader')) { - error(403); + Error403::error(); } if (!isset($_REQUEST['preference']) || count($_REQUEST['list']) === 0) { - error('No collage collector preference specified'); + Error400::error('No collage collector preference specified'); } $collage = (new Manager\Collage())->findById((int)($_REQUEST['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } $collector = new Collector\Collage($Viewer, new Manager\Torrent(), $collage, (int)$_REQUEST['preference']); if (!$collector->prepare($_REQUEST['list'])) { - error("Nothing to gather, choose some encodings and media!"); + Error400::error("Nothing to gather, choose some encodings and media!"); } $Viewer->modifyOption('Collector', [implode(':', $_REQUEST['list']), $_REQUEST['preference']]); diff --git a/sections/collages/edit.php b/sections/collages/edit.php index 42dc3c94d..e0b901cb8 100644 --- a/sections/collages/edit.php +++ b/sections/collages/edit.php @@ -7,15 +7,15 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_edit_wiki')) { - error(403); + Error403::error(); } $collage = (new Manager\Collage())->findById((int)($_GET['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } if ($collage->isPersonal() && !$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } $torMan = new Manager\Torrent(); diff --git a/sections/collages/edit_handle.php b/sections/collages/edit_handle.php index 966e568f8..58d49e1a3 100644 --- a/sections/collages/edit_handle.php +++ b/sections/collages/edit_handle.php @@ -9,7 +9,7 @@ use Gazelle\Enum\LeechType; use Gazelle\Enum\LeechReason; if (!$Viewer->permitted('site_edit_wiki')) { - error(403); + Error403::error(); } authorize(); @@ -17,15 +17,15 @@ authorize(); $collageMan = new Manager\Collage(); $collage = $collageMan->findById((int)($_POST['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } if (!$collage->isPersonal()) { if (!$Viewer->permitted('site_collages_manage')) { - error(403); + Error403::error(); } } elseif (!$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { // only owner or mod+ can edit personal collages - error(403); + Error403::error(); } if (isset($_POST['name'])) { @@ -43,7 +43,7 @@ if (isset($_POST['name'])) { } if ($collage->isOwner($Viewer)) { if (!$Viewer->permitted('site_collages_renamepersonal') && !stristr($name, $Viewer->username())) { - error("Your personal collage's title must include your username."); + Error400::error("Your personal collage's title must include your username."); } } } @@ -81,7 +81,7 @@ if ( if (isset($_POST['category']) && isset(COLLAGE[$_POST['category']]) && (int)$_POST['category'] !== $collage->categoryId()) { if ($collage->isPersonal() && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } $collage->setField('CategoryID', (int)$_POST['category']); } diff --git a/sections/collages/manage.php b/sections/collages/manage.php index c32036214..11db26161 100644 --- a/sections/collages/manage.php +++ b/sections/collages/manage.php @@ -7,15 +7,15 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_manage')) { - error(403); + Error403::error(); } $collage = (new Manager\Collage())->findById((int)($_GET['collageid'] ?? $_GET['id'] ?? 0)); if (is_null($collage) || $collage->isArtist()) { - error(404); + Error404::error(); } if ($collage->isPersonal() && !$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } echo $Twig->render('collage/manage-tgroup.twig', [ diff --git a/sections/collages/manage_artists.php b/sections/collages/manage_artists.php index 4c3c43853..4df148125 100644 --- a/sections/collages/manage_artists.php +++ b/sections/collages/manage_artists.php @@ -7,17 +7,17 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_create')) { - error(403); + Error403::error(); } $collage = (new Manager\Collage())->findById((int)$_GET['collageid']); if (is_null($collage)) { - error(404); + Error404::error(); } if ($collage->isPersonal() && !$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } if (!$collage->isArtist()) { - error(404); + Error404::error(); } echo $Twig->render('collage/manage-artists.twig', [ diff --git a/sections/collages/manage_artists_handle.php b/sections/collages/manage_artists_handle.php index 1f6429fb5..96b6f588e 100644 --- a/sections/collages/manage_artists_handle.php +++ b/sections/collages/manage_artists_handle.php @@ -6,21 +6,21 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_create')) { - error(403); + Error403::error(); } authorize(); $artist = (new Manager\Artist())->findById((int)($_POST['artistid'] ?? 0)); if (is_null($artist)) { - error(404); + Error404::error(); } $collage = (new Manager\Collage())->findById((int)$_POST['collageid']); if (is_null($collage)) { - error(404); + Error404::error(); } if (!$collage->isArtist()) { - error(403); + Error403::error(); } if (isset($_POST['drag_drop_collage_sort_order'])) { @@ -30,7 +30,7 @@ if (isset($_POST['drag_drop_collage_sort_order'])) { } else { $sequence = (int)$_POST['sort']; if (!$sequence) { - error(404); + Error404::error(); } $collage->updateSequenceEntry($artist, $sequence); } diff --git a/sections/collages/manage_handle.php b/sections/collages/manage_handle.php index e44d0e8b0..72653f0c5 100644 --- a/sections/collages/manage_handle.php +++ b/sections/collages/manage_handle.php @@ -6,17 +6,17 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_manage')) { - error(403); + Error403::error(); } authorize(); $collage = (new Manager\Collage())->findById((int)($_POST['collageid'])); if (is_null($collage)) { - error("Cannot find the requested collage"); + Error404::error("Cannot find the requested collage"); } if ($collage->isPersonal() && !$collage->isOwner($Viewer) && !$Viewer->permitted('site_collages_delete')) { - error(403); + Error403::error(); } if (isset($_POST['drag_drop_collage_sort_order'])) { @@ -24,11 +24,13 @@ if (isset($_POST['drag_drop_collage_sort_order'])) { } elseif (isset($_POST['groupid'])) { $tgroup = (new Manager\TGroup())->findById((int)($_POST['groupid'] ?? 0)); if (is_null($tgroup)) { - error("Cannot find torrent group"); + Error404::error("Cannot find torrent group"); } if (isset($_POST['sort'])) { $collage->updateSequenceEntry($tgroup, (int)$_POST['sort']); - } elseif ($_POST['submit'] === 'Remove') { + } + + if ($_POST['submit'] === 'Remove') { $userId = $collage->entryUserId($tgroup); if ($collage->removeEntry($tgroup)) { $collage->logger()->general( diff --git a/sections/collages/new.php b/sections/collages/new.php index e573ce82e..b2d2eccdc 100644 --- a/sections/collages/new.php +++ b/sections/collages/new.php @@ -9,7 +9,7 @@ namespace Gazelle; use Gazelle\Enum\CollageType; if (!$Viewer->permitted('site_collages_create') && !$Viewer->canCreatePersonalCollage()) { - error(403); + Error403::error(); } // the variables below are instantiated via new_handle.php in the event of an error diff --git a/sections/collages/new_handle.php b/sections/collages/new_handle.php index fc37c8b4d..805971163 100644 --- a/sections/collages/new_handle.php +++ b/sections/collages/new_handle.php @@ -8,13 +8,13 @@ namespace Gazelle; use Gazelle\Enum\CollageType; if (!$Viewer->permitted('site_collages_create') && !$Viewer->canCreatePersonalCollage()) { - error(403); + Error403::error(); } authorize(); if (!isset($_POST['category'])) { - error(403); + Error403::error(); } $categoryId = (int)$_POST['category']; $collageMan = new Manager\Collage(); diff --git a/sections/collages/recover.php b/sections/collages/recover.php index 2d1187d04..b7cf38283 100644 --- a/sections/collages/recover.php +++ b/sections/collages/recover.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_recover')) { - error(403); + Error403::error(); } $_POST['id'] = (int)($_POST['id'] ?? 0); @@ -25,7 +25,7 @@ if (!empty($_POST['id']) || $_POST['name'] !== '') { $collage = $collageMan->recoverByName($_POST['name']); } if (!$collage) { - error('Collage is completely deleted'); + Error404::error('Collage is completely deleted'); } else { $collageId = $collage->flush()->id(); $collage->logger()->general("Collage $collageId was recovered by " . $Viewer->username()); diff --git a/sections/comments/comments.php b/sections/comments/comments.php index b25385745..f66b69cfd 100644 --- a/sections/comments/comments.php +++ b/sections/comments/comments.php @@ -28,10 +28,10 @@ if (!isset($_GET['id'])) { } else { $User = $userMan->findById((int)($_GET['id'] ?? 0)); if (is_null($User)) { - error(404); + Error404::error(); } if (!$User->propertyVisible($Viewer, 'torrentcomments')) { - error(403); + Error403::error(); } } $UserID = $User->id(); @@ -177,7 +177,7 @@ switch ($Action) { } break; default: - error('What are you trying to comment on?'); + Error400::error('What are you trying to comment on?'); } $Join[] = "INNER JOIN comments C ON (C.Page = ? AND C.PageID = $idField)"; diff --git a/sections/comments/delete_handle.php b/sections/comments/delete_handle.php index ec2851a5f..ce8f83a5c 100644 --- a/sections/comments/delete_handle.php +++ b/sections/comments/delete_handle.php @@ -6,12 +6,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } authorize(); $comment = (new Manager\Comment())->findById((int)($_REQUEST['postid'] ?? 0)); if (is_null($comment)) { - error(404); + Error404::error(); } $comment->remove(); diff --git a/sections/comments/edit_handle.php b/sections/comments/edit_handle.php index 6413fbdd7..7ecc4c162 100644 --- a/sections/comments/edit_handle.php +++ b/sections/comments/edit_handle.php @@ -6,25 +6,25 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disablePosting()) { - error('Your posting privileges have been removed.'); + Error403::error('Your posting privileges have been removed.'); } authorize(); $body = trim($_POST['body'] ?? ''); if (!strlen($body)) { - error(404); + Error404::error(); } $comment = (new Manager\Comment())->findById((int)($_REQUEST['postid'] ?? 0)); if (is_null($comment)) { - error(404); + Error404::error(); } if ($comment->userId() != $Viewer->id() && !$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById($comment->userId()); if (is_null($user)) { - error(404); + Error404::error(); } $comment->setField('Body', $body)->setField('EditedUserID', $Viewer->id())->modify(); diff --git a/sections/comments/get.php b/sections/comments/get.php index 62e56cbc9..7be7f51b2 100644 --- a/sections/comments/get.php +++ b/sections/comments/get.php @@ -6,7 +6,7 @@ namespace Gazelle; $body = (new Manager\Comment())->findBodyById((int)($_GET['postid'] ?? 0)); if (is_null($body)) { - error(404); + Error404::error(); } header('Content-type: text/plain'); diff --git a/sections/comments/jump.php b/sections/comments/jump.php index 8b1ef93bd..68659ded2 100644 --- a/sections/comments/jump.php +++ b/sections/comments/jump.php @@ -6,6 +6,6 @@ namespace Gazelle; $comment = (new Manager\Comment())->findById((int)($_REQUEST['postid'] ?? 0)); if (is_null($comment)) { - error(404); + Error404::error(); } header('Location: ' . $comment->location()); diff --git a/sections/comments/post_handle.php b/sections/comments/post_handle.php index b6edd1a15..f51b5440e 100644 --- a/sections/comments/post_handle.php +++ b/sections/comments/post_handle.php @@ -6,18 +6,18 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disablePosting()) { - error('Your posting privileges have been removed.'); + Error403::error('Your posting privileges have been removed.'); } authorize(); $page = $_REQUEST['page'] ?? null; if (!in_array($page, ['artist', 'collages', 'requests', 'torrents'])) { - error(403); + Error403::error(); } $pageId = (int)($_REQUEST['pageid'] ?? 0); if (!$pageId) { - error(404); + Error404::error(); } $commentMan = new Manager\Comment(); diff --git a/sections/comments/warn.php b/sections/comments/warn.php index 172edcfd2..fb5fa1517 100644 --- a/sections/comments/warn.php +++ b/sections/comments/warn.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_warn')) { - error(403); + Error403::error(); } $comment = (new Manager\Comment())->findById((int)($_POST['postid'] ?? 0)); if (is_null($comment)) { - error(404); + Error404::error(); } echo $Twig->render('comment/warn.twig', [ diff --git a/sections/contest/admin.php b/sections/contest/admin.php index 5d66544ff..173e06852 100644 --- a/sections/contest/admin.php +++ b/sections/contest/admin.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_contest')) { - error(403); + Error403::error(); } $contestMan = new Manager\Contest(); diff --git a/sections/enable/index.php b/sections/enable/index.php index 5e926ec9e..9d36cf93e 100644 --- a/sections/enable/index.php +++ b/sections/enable/index.php @@ -16,7 +16,7 @@ if (!isset($_GET['token'])) { $enabler = (new Manager\AutoEnable())->findByToken($_GET['token']); if (is_null($enabler)) { - error('invalid enable token'); + Error400::error('invalid enable token'); } echo $Twig->render('enable/processed.twig', [ diff --git a/sections/error/403.php b/sections/error/403.php deleted file mode 100644 index 47a22064f..000000000 --- a/sections/error/403.php +++ /dev/null @@ -1,9 +0,0 @@ - -

Error: 403

Forbidden. diff --git a/sections/error/404.php b/sections/error/404.php deleted file mode 100644 index ce23f87ef..000000000 --- a/sections/error/404.php +++ /dev/null @@ -1,12 +0,0 @@ - -

Error: 404

Not Found. - -

Error: 413

Request is too large. diff --git a/sections/error/504.php b/sections/error/504.php deleted file mode 100644 index 239cc871c..000000000 --- a/sections/error/504.php +++ /dev/null @@ -1,7 +0,0 @@ - -

Error: 504

Gateway timeout. diff --git a/sections/error/index.php b/sections/error/index.php deleted file mode 100644 index be945cc22..000000000 --- a/sections/error/index.php +++ /dev/null @@ -1,61 +0,0 @@ -requestContext()->remoteAddr(); - Irc::sendMessage($Channel, - $Message . " error by " - . ($Viewer - ? $Viewer->publicLocation() . " (" . $Viewer->username() . ")" - : $ipaddr - ) - . " (" . (new \Gazelle\Util\GeoIP(new \Gazelle\Util\Curl()))->countryISO($ipaddr) . ")" - . " accessing " . SITE_URL . $_SERVER['REQUEST_URI'] . ' (' . $_SERVER['REQUEST_METHOD'] . ')' - . (!empty($_SERVER['HTTP_REFERER']) ? " from " . $_SERVER['HTTP_REFERER'] : '') - ); -} - -switch ($Error) { - case '403': - $Title = "Error 403"; - $Description = "You tried to go to a page that you don't have enough permission to view."; - notify($Viewer, IRC_CHAN_STATUS, 403); - break; - case '404': - $Title = "Error 404"; - $Description = "You tried to go to a page that doesn't exist."; - break; - case '429': - $Title = "Error 429"; - $Description = "You tried to do something too frequently."; - break; - default: - if (empty($Error)) { - $Title = "Unexpected Error"; - $Description = "You have encountered an unexpected error."; - } else { - $Title = 'Error'; - $Description = $Error; - } -} - -if (isset($Log) && $Log) { - $Description .= ' Search Log'; -} - -if (empty($NoHTML) && isset($Error) && $Error != -1) { - echo $Twig->render('error.twig', [ - 'title' => $Title, - 'description' => $Description, - ]); -} else { - echo $Description; -} diff --git a/sections/forums/add_poll_option.php b/sections/forums/add_poll_option.php index 7c8f8d5f9..8dd9ab0b3 100644 --- a/sections/forums/add_poll_option.php +++ b/sections/forums/add_poll_option.php @@ -6,16 +6,16 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } authorize(); $poll = (new Manager\ForumPoll())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($poll)) { - error(404); + Error404::error(); } if (!$poll->hasRevealVotes()) { - error(403); + Error403::error(); } $poll->addAnswer(trim($_POST['new_option'])); diff --git a/sections/forums/catchup.php b/sections/forums/catchup.php index 859736ffe..a5c8c39a6 100644 --- a/sections/forums/catchup.php +++ b/sections/forums/catchup.php @@ -15,7 +15,7 @@ if (($_GET['forumid'] ?? '') == 'all') { $forum = (new Manager\Forum())->findById((int)($_GET['forumid'] ?? 0)); if (is_null($forum)) { - error(404); + Error404::error(); } $forum->userCatchup($Viewer); diff --git a/sections/forums/change_vote.php b/sections/forums/change_vote.php index b240f2c11..606ce1e4c 100644 --- a/sections/forums/change_vote.php +++ b/sections/forums/change_vote.php @@ -9,15 +9,15 @@ authorize(); $poll = (new Manager\ForumPoll())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($poll)) { - error(404); + Error404::error(); } if (!$Viewer->permitted('site_moderate_forums') && !$poll->hasRevealVotes()) { - error(403); + Error403::error(); } $vote = (int)$_GET['vote']; if (!$vote) { - error(404); + Error404::error(); } $poll->modifyVote($Viewer, $vote); diff --git a/sections/forums/delete.php b/sections/forums/delete.php index f7e1173bb..2d897521b 100644 --- a/sections/forums/delete.php +++ b/sections/forums/delete.php @@ -6,15 +6,15 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_forum_post_delete')) { - error(403); + Error403::error(); } authorize(); $post = (new Manager\ForumPost())->findById((int)($_GET['postid'] ?? 0)); if (is_null($post)) { - error(404); + Error404::error(); } if (!$post->remove()) { - error(404); + Error404::error(); } diff --git a/sections/forums/delete_poll_option.php b/sections/forums/delete_poll_option.php index e5f6c1189..fb321cb65 100644 --- a/sections/forums/delete_poll_option.php +++ b/sections/forums/delete_poll_option.php @@ -8,20 +8,20 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } $poll = (new Manager\ForumPoll())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($poll)) { - error(404); + Error404::error(); } if (!$poll->hasRevealVotes()) { - error(403); + Error403::error(); } $vote = (int)$_GET['vote']; if (!$vote) { - error(404); + Error404::error(); } $poll->removeAnswer($vote); diff --git a/sections/forums/do_warn.php b/sections/forums/do_warn.php index af4338e4c..b17bc4df2 100644 --- a/sections/forums/do_warn.php +++ b/sections/forums/do_warn.php @@ -11,34 +11,36 @@ function handleWarningRequest(\Gazelle\Manager\ForumPost|\Gazelle\Manager\Commen global $Viewer; if (!$Viewer->permitted('users_warn')) { - error(403); + Error403::error(); } authorize(); $postId = (int)($_POST['postid'] ?? 0); $post = $manager->findById($postId); if (is_null($post)) { - error(404); + Error404::error(); } $userMan = new \Gazelle\Manager\User(); $user = $userMan->findById($post->userId()); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->classLevel() >= $Viewer->classLevel()) { - error(403); + Error403::error(); } $body = trim($_POST['body'] ?? ''); if (empty($body)) { - error("Post body cannot be left empty (you can leave a reason for others to see)"); + Error400::error( + "Post body cannot be left empty (you can leave a reason for others to see)" + ); } if (empty($_POST['reason'])) { - error("Reason for warning not provided"); + Error400::error("Reason for warning not provided"); } if (!isset($_POST['length']) || !strlen($_POST['length'])) { - error("Length of warning not provided"); + Error400::error("Length of warning not provided"); } $weeks = (int)$_POST['length']; diff --git a/sections/forums/edit_handle.php b/sections/forums/edit_handle.php index 9a195a21a..4e4f82fe5 100644 --- a/sections/forums/edit_handle.php +++ b/sections/forums/edit_handle.php @@ -6,30 +6,30 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disablePosting()) { - error("Your posting privileges have been removed."); + Error403::error("Your posting privileges have been removed."); } authorize(); $post = (new Manager\ForumPost())->findById((int)($_POST['post'] ?? 0)); if (!$post) { - error(display_str("No forum post #{$_POST['post']} found")); + Error404::error(display_str("No forum post #{$_POST['post']} found")); } $thread = $post->thread(); if (!$Viewer->writeAccess($thread->forum())) { - error("You lack the permission to edit this post."); + Error403::error("You lack the permission to edit this post."); } if ($thread->isLocked() && !$Viewer->permitted('site_moderate_forums')) { - error("You cannot edit a post in a locked thread."); + Error403::error("You cannot edit a post in a locked thread."); } if ($Viewer->id() != $post->userId()) { if (!$Viewer->permitted('site_moderate_forums')) { - error("You cannot edit someone else's post"); + Error403::error("You cannot edit someone else's post"); } if ($_POST['pm'] ?? 0) { $user = (new Manager\User())->findById($post->userId()); if (is_null($user)) { - error('Author of post not found'); + Error404::error('Author of post not found'); } $user->inbox()->createSystem( "Your post #{$post->id()} has been edited", diff --git a/sections/forums/forum.php b/sections/forums/forum.php index b61cbe721..990ec192e 100644 --- a/sections/forums/forum.php +++ b/sections/forums/forum.php @@ -17,11 +17,11 @@ Things to expect in $_GET: $forum = (new Manager\Forum())->findById((int)$_GET['forumid']); if (!$forum) { - error(404); + Error404::error(); } $forumId = $forum->id(); if (!$Viewer->readAccess($forum)) { - error(403); + Error403::error(); } $paginator = new Util\Paginator(TOPICS_PER_PAGE, (int)($_GET['page'] ?? 1)); diff --git a/sections/forums/get_post.php b/sections/forums/get_post.php index e8020daad..7126bbcc0 100644 --- a/sections/forums/get_post.php +++ b/sections/forums/get_post.php @@ -7,10 +7,10 @@ namespace Gazelle; $post = (new Manager\ForumPost())->findById((int)($_GET['post'] ?? 0)); if (is_null($post)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($post->thread()->forum())) { - error(403); + Error403::error(); } header('Content-type: text/plain'); echo $post->body(); diff --git a/sections/forums/index.php b/sections/forums/index.php index 5ad68747b..247823b5d 100644 --- a/sections/forums/index.php +++ b/sections/forums/index.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableForums()) { - error(403); + Error403::error(); } require_once match ($_REQUEST['action'] ?? '') { diff --git a/sections/forums/new_thread.php b/sections/forums/new_thread.php index f08f1cf2e..86763633c 100644 --- a/sections/forums/new_thread.php +++ b/sections/forums/new_thread.php @@ -8,10 +8,10 @@ namespace Gazelle; $forum = (new Manager\Forum())->findById((int)($_GET['forumid'] ?? 0)); if (!$forum) { - error(404); + Error404::error(); } if (!$Viewer->writeAccess($forum) || !$Viewer->createAccess($forum)) { - error(403); + Error403::error(); } echo $Twig->render('forum/new-thread.twig', [ diff --git a/sections/forums/new_thread_handle.php b/sections/forums/new_thread_handle.php index b84eefc01..21198080c 100644 --- a/sections/forums/new_thread_handle.php +++ b/sections/forums/new_thread_handle.php @@ -18,19 +18,19 @@ use Gazelle\Util\Irc; */ if ($Viewer->disablePosting()) { - error('Your posting privileges have been removed.'); + Error403::error('Your posting privileges have been removed.'); } authorize(); if (!isset($_POST['forum'])) { - error('Forum ID not specified'); + Error400::error('Forum ID not specified'); } $forum = (new Manager\Forum())->findById((int)$_POST['forum']); if (is_null($forum)) { - error(404); + Error404::error(); } if (!$Viewer->writeAccess($forum) || !$Viewer->createAccess($forum)) { - error(403); + Error403::error(); } // If you're not sending anything, go back @@ -57,10 +57,10 @@ if (empty($_POST['question']) || empty($_POST['answers']) || !$Viewer->permitted } if (count($answerList) < 2) { - error('You cannot create a poll with only one answer.'); + Error400::error('You cannot create a poll with only one answer.'); } if (count($answerList) > 25) { - error('You cannot create a poll with more than 25 answers.'); + Error400::error('You cannot create a poll with more than 25 answers.'); } } diff --git a/sections/forums/poll_mod.php b/sections/forums/poll_mod.php index 1ed40c61d..cde07a783 100644 --- a/sections/forums/poll_mod.php +++ b/sections/forums/poll_mod.php @@ -6,13 +6,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('forums_polls_moderate')) { - error(403); + Error403::error(); } authorize(); $poll = (new Manager\ForumPoll())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($poll)) { - error('Cannot find a poll for that thread'); + Error404::error('Cannot find a poll for that thread'); } if (isset($_POST['ck-feat']) && isset($_POST['feature'])) { $poll->setField('Featured', $poll->isFeatured() ? null : date('Y-m-d H:i:s')); diff --git a/sections/forums/poll_vote.php b/sections/forums/poll_vote.php index e5dc6522e..007b466c3 100644 --- a/sections/forums/poll_vote.php +++ b/sections/forums/poll_vote.php @@ -9,10 +9,10 @@ namespace Gazelle; $poll = (new Manager\ForumPoll())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($poll)) { - error(404); + Error404::error(); } if ($poll->isClosed()) { - error(403); + Error403::error(); } $vote = $poll->vote(); @@ -35,7 +35,7 @@ if (!isset($_POST['vote']) || !is_number($_POST['vote'])) { authorize(); $response = (int)$_POST['vote']; if (!$poll->addVote($Viewer, $response)) { - error('Cannot add your vote to the poll'); + Error400::error('Cannot add your vote to the poll'); } $vote = $poll->vote(); // need to refresh the results to take the vote into account diff --git a/sections/forums/reply_handle.php b/sections/forums/reply_handle.php index 01d2f15c3..538ca02e1 100644 --- a/sections/forums/reply_handle.php +++ b/sections/forums/reply_handle.php @@ -6,18 +6,18 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disablePosting()) { - error('Your posting privileges have been removed.'); + Error403::error('Your posting privileges have been removed.'); } authorize(); $thread = (new Manager\ForumThread())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($thread)) { - error(404); + Error404::error(); } $forum = $thread->forum(); if (!$Viewer->readAccess($forum) || !$Viewer->writeAccess($forum) || $thread->isLocked() && !$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } // If you're not sending anything, go back @@ -30,7 +30,7 @@ if ($body === '') { if ($thread->lastAuthorId() == $Viewer->id() && isset($_POST['merge'])) { $post = (new Manager\ForumPost())->findById($thread->lastPostId()); if (is_null($post)) { - error("cannot find post #{$thread->lastPostId()} in thread {$thread->id()}"); + Error404::error("cannot find post #{$thread->lastPostId()} in thread {$thread->id()}"); } $thread->mergePost($post, $Viewer, $body); } else { diff --git a/sections/forums/search.php b/sections/forums/search.php index bf16e4353..35c1df8d3 100644 --- a/sections/forums/search.php +++ b/sections/forums/search.php @@ -21,7 +21,7 @@ if (!$ThreadID) { $Title = $search->threadTitle($ThreadID); if (is_null($Title)) { // naughty naughty - error(403); + Error403::error(); } $search->setSearchType('body'); $Title = " › $Title"; @@ -36,14 +36,14 @@ if (!empty($userSearch)) { $threadCreatedBefore = $_GET['thread_created_before'] ?? ''; if (!empty($threadCreatedBefore)) { if (!Time::isValidDate($threadCreatedBefore)) { - error("Incorrect topic created before date"); + Error400::error("Incorrect topic created before date"); } $search->setThreadCreatedBefore($threadCreatedBefore); } $threadCreatedAfter = $_GET['thread_created_after'] ?? ''; if (!empty($threadCreatedAfter)) { if (!Time::isValidDate($threadCreatedAfter)) { - error("Incorrect topic created after date"); + Error400::error("Incorrect topic created after date"); } $search->setThreadCreatedAfter($threadCreatedAfter); } @@ -52,14 +52,14 @@ if ($search->isBodySearch()) { $postCreatedBefore = $_GET['post_created_before'] ?? ''; if (!empty($postCreatedBefore)) { if (!Time::isValidDate($postCreatedBefore)) { - error("Incorrect post created before date"); + Error400::error("Incorrect post created before date"); } $search->setPostCreatedBefore($postCreatedBefore); } $postCreatedAfter = $_GET['post_created_after'] ?? ''; if (!empty($postCreatedAfter)) { if (!Time::isValidDate($postCreatedAfter)) { - error("Incorrect post created after date"); + Error400::error("Incorrect post created after date"); } $search->setPostCreatedAfter($postCreatedAfter); } diff --git a/sections/forums/sticky_post.php b/sections/forums/sticky_post.php index dfbb2b3b5..052147e90 100644 --- a/sections/forums/sticky_post.php +++ b/sections/forums/sticky_post.php @@ -6,13 +6,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } authorize(); $post = (new Manager\ForumPost())->findById((int)($_GET['postid'] ?? 0)); if (is_null($post)) { - error(404); + Error404::error(); } $post->pin($Viewer, empty($_GET['remove'])); diff --git a/sections/forums/thread.php b/sections/forums/thread.php index 600792a3d..3105fe69f 100644 --- a/sections/forums/thread.php +++ b/sections/forums/thread.php @@ -15,7 +15,7 @@ $forumMan = new Manager\Forum(); if (isset($_GET['postid'])) { $post = (new Manager\ForumPost())->findById((int)$_GET['postid']); if (is_null($post)) { - error(404); + Error404::error(); } if (!isset($_GET['threadid'])) { header("Location: {$post->location()}"); @@ -26,16 +26,16 @@ if (isset($_GET['postid'])) { $post = null; $thread = (new Manager\ForumThread())->findById((int)$_GET['threadid']); if (is_null($thread)) { - error(404); + Error404::error(); } } else { - error(404); + Error404::error(); } $threadId = $thread->id(); $forum = $thread->forum(); if (!$Viewer->readAccess($forum)) { - error(403); + Error403::error(); } //Escape strings for later display diff --git a/sections/forums/thread_handle.php b/sections/forums/thread_handle.php index 00b7db6e4..324941eb0 100644 --- a/sections/forums/thread_handle.php +++ b/sections/forums/thread_handle.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums') && empty($_POST['transition'])) { - error(403); + Error403::error(); } authorize(); @@ -14,17 +14,17 @@ $forumMan = new Manager\Forum(); $thread = (new Manager\ForumThread())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($thread)) { - error(404); + Error404::error(); } $forum = $thread->forum(); if (!$Viewer->writeAccess($forum)) { - error(403); + Error403::error(); } if (isset($_POST['delete'])) { if (!$Viewer->permitted('site_admin_forums')) { - error(403); + Error403::error(); } $thread->remove(); header('Location: ' . $forum->location()); @@ -35,13 +35,13 @@ $newForum = null; if (isset($_POST['forumid'])) { $newForum = $forumMan->findById((int)$_POST['forumid']); if (is_null($newForum) && !isset($_POST['transition'])) { - error(404); + Error404::error(); } } $newTitle = trim($_POST['title'] ?? ''); if (!isset($_POST['transition']) && $newTitle === '') { - error("Title cannot be empty"); + Error400::error("Title cannot be empty"); } // Variables for database input @@ -53,17 +53,17 @@ $newRank = (int)($_POST['ranking'] ?? 0); if (!$newPinned && $newRank > 0) { $newRank = 0; } elseif ($newRank < 0) { - error('Ranking cannot be a negative value'); + Error400::error('Ranking cannot be a negative value'); } if (isset($_POST['transition'])) { $transId = (int)$_POST['transition']; if ($transId < 1) { - error('No forum transition ID specified'); + Error400::error('No forum transition ID specified'); } $transitions = (new Manager\ForumTransition())->threadTransitionList($Viewer, $thread); if (!isset($transitions[$transId])) { - error('Forum transition not found'); + Error404::error("Forum transition $transId not found"); } $transition = $transitions[$transId]; $newForum = $forumMan->findById($transition->destinationId()); diff --git a/sections/forums/thread_notes_handle.php b/sections/forums/thread_notes_handle.php index 73ce5cf2f..8a995089c 100644 --- a/sections/forums/thread_notes_handle.php +++ b/sections/forums/thread_notes_handle.php @@ -6,17 +6,17 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } authorize(); $thread = (new Manager\ForumThread())->findById((int)($_POST['threadid'] ?? 0)); if (is_null($thread)) { - error(404); + Error404::error(); } $body = trim($_POST['body'] ?? ''); if (!strlen($body)) { - error("Thread note cannot be empty"); + Error400::error("Thread note cannot be empty"); } $thread->addThreadNote($Viewer, $body); diff --git a/sections/forums/warn.php b/sections/forums/warn.php index 7914d783d..aafa68b67 100644 --- a/sections/forums/warn.php +++ b/sections/forums/warn.php @@ -7,17 +7,17 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_warn')) { - error(403); + Error403::error(); } authorize(); $post = (new Manager\ForumPost())->findById((int)($_POST['postid'] ?? 0)); if (is_null($post)) { - error(404); + Error404::error(); } $user = (new Manager\User())->findById((int)($_POST['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } echo $Twig->render('forum/warn.twig', [ diff --git a/sections/friends/add.php b/sections/friends/add.php index bac739ac5..d9c8cdef7 100644 --- a/sections/friends/add.php +++ b/sections/friends/add.php @@ -9,15 +9,15 @@ authorize(); $friend = (new Manager\User())->findById((int)($_GET['friendid'] ?? 0)); if (!$friend) { - error("no such user found"); + Error404::error("no such user found"); } if ($friend->id() === $Viewer->id()) { - error("you cannot add yourself as a friend"); + Error400::error("you cannot add yourself as a friend"); } if (!(new User\Friend($Viewer))->add($friend)) { - error("you are already friends with {$friend->username()}"); + Error400::error("you are already friends with {$friend->username()}"); } header('Location: friends.php'); diff --git a/sections/friends/comment.php b/sections/friends/comment.php index 8ec354e0c..1516d2618 100644 --- a/sections/friends/comment.php +++ b/sections/friends/comment.php @@ -9,12 +9,12 @@ authorize(); $friend = (new Manager\User())->findById((int)($_POST['friendid'] ?? 0)); if (!$friend) { - error("no such user found"); + Error404::error("no such user found"); } $viewerFriend = new User\Friend($Viewer); if (!$viewerFriend->isFriend($friend)) { - error("you are not friends with {$friend->username()}"); + Error400::error("you are not friends with {$friend->username()}"); } $viewerFriend->addComment($friend, trim($_POST['comment'])); diff --git a/sections/friends/remove.php b/sections/friends/remove.php index cdc160cbe..df0046d05 100644 --- a/sections/friends/remove.php +++ b/sections/friends/remove.php @@ -9,7 +9,7 @@ authorize(); $friend = (new Manager\User())->findById((int)($_POST['friendid'] ?? 0)); if (!$friend) { - error("no such user found"); + Error404::error("no such user found"); } (new User\Friend($Viewer))->remove($friend); diff --git a/sections/inbox/compose.php b/sections/inbox/compose.php index 70beeac99..ed8cf2269 100644 --- a/sections/inbox/compose.php +++ b/sections/inbox/compose.php @@ -8,13 +8,13 @@ namespace Gazelle; $recipient = (new Manager\User())->findById((int)$_GET['toid']); if (is_null($recipient)) { - error(404); + Error404::error(); } if ($Viewer->disablePm() && !$recipient->isStaff()) { - error(403); + Error403::error(); } if ($recipient->id() == $Viewer->id()) { - error('You cannot start a conversation with yourself!'); + Error400::error('You cannot start a conversation with yourself!'); } echo $Twig->render('inbox/compose.twig', [ diff --git a/sections/inbox/compose_handle.php b/sections/inbox/compose_handle.php index a89e4a6b5..ed1deaa2f 100644 --- a/sections/inbox/compose_handle.php +++ b/sections/inbox/compose_handle.php @@ -9,15 +9,15 @@ authorize(); $recipient = (new Manager\User())->findById((int)$_POST['toid']); if (is_null($recipient)) { - error(404); + Error404::error(); } if ($Viewer->option('DisablePM') && !$recipient->isStaffPMReader()) { - error(403); + Error403::error(); } $body = trim($_POST['body'] ?? ''); if ($body === '') { - error('You cannot send a message without a body.'); + Error400::error('You cannot send a message without a body.'); } $userMan = new Manager\User(); @@ -28,7 +28,7 @@ if ($pm) { } else { $subject = trim($_POST['subject']); if (empty($subject)) { - error('You cannot send a message without a subject.'); + Error400::error('You cannot send a message without a subject.'); } $pm = $recipient->inbox()->create($Viewer, $subject, $body); } diff --git a/sections/inbox/conversation.php b/sections/inbox/conversation.php index 14aca4ef2..9f6124aba 100644 --- a/sections/inbox/conversation.php +++ b/sections/inbox/conversation.php @@ -8,7 +8,7 @@ namespace Gazelle; $pm = (new Manager\PM($Viewer))->findById((int)($_GET['id'] ?? 0)); if (is_null($pm)) { - error(404); + Error404::error(); } $pm->markRead(); diff --git a/sections/inbox/edit_handle.php b/sections/inbox/edit_handle.php index 69de6b1da..e87777fee 100644 --- a/sections/inbox/edit_handle.php +++ b/sections/inbox/edit_handle.php @@ -9,10 +9,10 @@ authorize(); $pm = (new Manager\PM($Viewer))->findById((int)$_POST['convid']); if (is_null($pm)) { - error(404); + Error404::error(); } if (!$pm->isReadable()) { - error(403); + Error403::error(); } if (isset($_POST['delete'])) { diff --git a/sections/inbox/forward.php b/sections/inbox/forward.php index ed703e1e3..1d97e13f6 100644 --- a/sections/inbox/forward.php +++ b/sections/inbox/forward.php @@ -9,18 +9,20 @@ authorize(); $pm = (new Manager\PM($Viewer))->findById((int)$_POST['convid']); if (is_null($pm)) { - error('Sorry, there is no trace of that conversation in your folder'); + Error404::error('Sorry, there is no trace of that conversation in your folder'); } $recipient = (new Manager\User())->findById((int)$_POST['receiverid']); if (is_null($recipient)) { - error('Sorry, there is no-one here by that name'); + Error404::error('Sorry, there is no-one here by that name'); } if (!$Viewer->permitted('users_mod') && !$recipient->isStaffPMReader()) { - error(403); + Error403::error(); } if (in_array($recipient->id(), $pm->recipientList())) { - error($recipient->username() . " already has this conversation in their inbox."); + Error400::error( + "{$recipient->username()} already has this conversation in their inbox." + ); } $pm->setForwardedTo($recipient->id()); diff --git a/sections/inbox/get_post.php b/sections/inbox/get_post.php index 5bf49a9b3..4bf9fd9cd 100644 --- a/sections/inbox/get_post.php +++ b/sections/inbox/get_post.php @@ -8,12 +8,12 @@ namespace Gazelle; $postId = (int)($_GET['post'] ?? 0); $pm = (new Manager\PM($Viewer))->findByPostId($postId); if (is_null($pm)) { - error(403); + Error403::error(); } $body = $pm->postBody($postId); if (is_null($body)) { - error(404); + Error404::error(); } // This gets sent to the browser, which echoes it wherever diff --git a/sections/inbox/massdelete_handle.php b/sections/inbox/massdelete_handle.php index 86168eea6..b2cb8a9da 100644 --- a/sections/inbox/massdelete_handle.php +++ b/sections/inbox/massdelete_handle.php @@ -17,7 +17,7 @@ if (empty($messageIds)) { } else { $action = 'delete'; } - error("You forgot to select any messages to $action."); + Error400::error("You forgot to select any messages to $action."); } $inbox = $Viewer->inbox(); diff --git a/sections/index/index.php b/sections/index/index.php index 3e2439fe5..2a30834ff 100644 --- a/sections/index/index.php +++ b/sections/index/index.php @@ -13,7 +13,7 @@ if (!isset($Viewer)) { } else { match ($_REQUEST['action']) { 'poll' => include __DIR__ . '/../forums/poll_vote.php', - default => error('Unknown action requested'), + default => Error400::error('Unknown action requested'), }; } } diff --git a/sections/logchecker/test_handle.php b/sections/logchecker/test_handle.php index b55f6d912..3065fa6c0 100644 --- a/sections/logchecker/test_handle.php +++ b/sections/logchecker/test_handle.php @@ -12,7 +12,7 @@ if (isset($_FILES['log']) && is_uploaded_file($_FILES['log']['tmp_name'])) { $fileTmp = tempnam(TMPDIR, 'log_'); if ($fileTmp === false) { // This will only happen if the directory that TMPDIR points to disappears - error('Failed to persist the log file.'); + Error404::error('Failed to persist the log file.'); } file_put_contents($fileTmp, $_POST["pastelog"]); $file = [ @@ -21,7 +21,7 @@ if (isset($_FILES['log']) && is_uploaded_file($_FILES['log']['tmp_name'])) { ]; $isPaste = true; } else { - error('No log file uploaded or file is empty.'); + Error400::error('No log file uploaded or file is empty.'); } $logfile = new \Gazelle\Logfile($file['tmp_name'], $file['name']); if (isset($fileTmp)) { diff --git a/sections/logchecker/upload_handle.php b/sections/logchecker/upload_handle.php index 6bb62ff48..42ae03141 100644 --- a/sections/logchecker/upload_handle.php +++ b/sections/logchecker/upload_handle.php @@ -12,20 +12,20 @@ ini_set('upload_max_filesize', 1_000_000); $torrent = (new Manager\Torrent())->findById((int)$_POST['torrentid']); if (is_null($torrent)) { - error('No torrent is selected.'); + Error404::error('No torrent is selected.'); } if ($torrent->media() !== 'CD') { - error('Media of torrent precludes adding a log.'); + Error400::error('Media of torrent precludes adding a log.'); } if ($torrent->uploaderId() != $Viewer->id() && !$Viewer->permitted('admin_add_log')) { - error('Not your upload.'); + Error403::error('Not your upload.'); } $action = in_array($_POST['from_action'], ['upload', 'update']) ? $_POST['from_action'] : 'upload'; $logfileSummary = new LogfileSummary($_FILES['logfiles']); if (!$logfileSummary->total()) { - error("No logfiles uploaded."); + Error400::error("No logfiles uploaded."); } else { $ripFiler = new File\RipLog(); $htmlFiler = new File\RipLogHTML(); diff --git a/sections/random/index.php b/sections/random/index.php index 55070fc2e..6aba56704 100644 --- a/sections/random/index.php +++ b/sections/random/index.php @@ -10,7 +10,7 @@ $object = match ($_REQUEST['action'] ?? '') { default => (new Manager\TGroup())->findRandom(), }; if (is_null($object)) { - error(404); /* only likely to happen on a brand new installation */ + Error404::error(); /* only likely to happen on a brand new installation */ } header("Location: " . $object->location()); diff --git a/sections/recovery/admin.php b/sections/recovery/admin.php index bb13e63a3..d986949a3 100644 --- a/sections/recovery/admin.php +++ b/sections/recovery/admin.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_recovery')) { - error(403); + Error403::error(); } $recovery = new Manager\Recovery(); @@ -28,7 +28,7 @@ if (isset($_GET['task'])) { $message = sprintf('Request %d was unclaimed', $id); break; default: - error(403); + Error403::error(); } } } else { diff --git a/sections/recovery/browse.php b/sections/recovery/browse.php index 59a766c26..a3597aeac 100644 --- a/sections/recovery/browse.php +++ b/sections/recovery/browse.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_recovery')) { - error(403); + Error403::error(); } $recovery = new Manager\Recovery(); diff --git a/sections/recovery/pair.php b/sections/recovery/pair.php index 447ef9a6e..e1f408f65 100644 --- a/sections/recovery/pair.php +++ b/sections/recovery/pair.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_recovery')) { - error(403); + Error403::error(); } $prev = false; diff --git a/sections/recovery/view.php b/sections/recovery/view.php index 7d1fa1d42..cb684b5aa 100644 --- a/sections/recovery/view.php +++ b/sections/recovery/view.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_recovery')) { - error(403); + Error403::error(); } $recovery = new Manager\Recovery(); @@ -17,7 +17,7 @@ if (isset($_GET['id']) && (int)$_GET['id'] > 0) { } elseif (isset($_GET['action']) && $_GET['action'] == 'search') { $search = true; } else { - error(404); + Error404::error(); } $terms = []; diff --git a/sections/report_auto/reports.php b/sections/report_auto/reports.php index 466f8ee11..be47030e7 100644 --- a/sections/report_auto/reports.php +++ b/sections/report_auto/reports.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_auto_reports')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); @@ -22,13 +22,13 @@ if (isset($_GET['id'])) { } elseif ($isOld) { $search->setState(Enum\ReportAutoState::closed); } else { - error(404); + Error404::error(); } if (isset($_GET['owner'])) { $owner = $userMan->findById((int)$_GET['owner']); if (is_null($owner)) { - error("no such owner"); + Error404::error("no such owner"); } $search->setOwner($owner); } @@ -36,7 +36,7 @@ if (isset($_GET['owner'])) { if (isset($_GET['userid'])) { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error("no such user"); + Error404::error("no such user"); } $search->setUser($user); } @@ -45,7 +45,7 @@ $type = null; if (isset($_GET['type'])) { $type = $ratMan->findById((int)$_GET['type']); if (is_null($type)) { - error("no such report type"); + Error404::error("no such report type"); } $search->setType($type); } diff --git a/sections/reports/compose.php b/sections/reports/compose.php index 24b1a0ae6..5faac9372 100644 --- a/sections/reports/compose.php +++ b/sections/reports/compose.php @@ -7,14 +7,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_forums')) { - error(403); + Error403::error(); } $reportId = (int)($_GET['reportid'] ?? 0); $id = (int)($_GET['thingid'] ?? 0); $type = $_GET['type'] ?? null; if (!$reportId || !$id || is_null($type)) { - error(403); + Error403::error(); } require_once 'array.php'; @@ -25,10 +25,10 @@ $user = null; if (!isset($Return)) { $user = (new Manager\User())->findById((int)($_GET['toid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() === $Viewer->id()) { - error("You cannot start a conversation with yourself!"); + Error400::error("You cannot start a conversation with yourself!"); } } @@ -36,7 +36,7 @@ switch ($type) { case 'user': $reported = (new Manager\User())->findById($id); if (is_null($reported)) { - error(404); + Error404::error(); } $report = new Report\User($reportId, $reported); break; @@ -45,7 +45,7 @@ switch ($type) { case 'request_update': $request = (new Manager\Request())->findById($id); if (is_null($request)) { - error(404); + Error404::error(); } $report = new Report\Request($reportId, $request); break; @@ -53,7 +53,7 @@ switch ($type) { case 'collage': $collage = (new Manager\Collage())->findById($id); if (is_null($collage)) { - error(404); + Error404::error(); } $report = new Report\Collage($reportId, $collage); break; @@ -61,10 +61,10 @@ switch ($type) { case 'thread': $thread = (new Manager\ForumThread())->findById($id); if (is_null($thread)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($thread->forum())) { - error(403); + Error403::error(); } $report = new Report\ForumThread($reportId, $thread); break; @@ -72,10 +72,10 @@ switch ($type) { case 'post': $post = (new Manager\ForumPost())->findById($id); if (is_null($post)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($post->thread()->forum())) { - error(403); + Error403::error(); } $report = new Report\ForumPost($reportId, $post); break; @@ -83,13 +83,13 @@ switch ($type) { case 'comment': $comment = (new Manager\Comment())->findById($id); if (is_null($comment)) { - error(404); + Error404::error(); } $report = (new Report\Comment($reportId, $comment))->setContext($reportType['title']); break; default: - error('Incorrect type'); + Error400::error('Incorrect type'); } echo $Twig->render('report/compose-reply.twig', [ diff --git a/sections/reports/compose_handle.php b/sections/reports/compose_handle.php index 049430f83..b7f4b3bfc 100644 --- a/sections/reports/compose_handle.php +++ b/sections/reports/compose_handle.php @@ -10,16 +10,16 @@ authorize(); $userMan = new Manager\User(); $recipient = $userMan->findById((int)($_POST['toid'] ?? 0)); if (is_null($recipient)) { - error("No such recipient!"); + Error404::error("No such recipient!"); } $subject = trim($_POST['subject']); if (empty($subject)) { - error("You can't send a message without a subject."); + Error400::error("You can't send a message without a subject."); } $body = trim($_POST['body'] ?? ''); if ($body === '') { - error("You can't send a message without a body!"); + Error400::error("You can't send a message without a body!"); } $recipient->inbox()->create($Viewer, $subject, $body); diff --git a/sections/reports/report.php b/sections/reports/report.php index 99abbe95f..0fe27c7f1 100644 --- a/sections/reports/report.php +++ b/sections/reports/report.php @@ -8,12 +8,12 @@ namespace Gazelle; $id = (int)$_GET['id']; if (!$id) { - error(404); + Error404::error(); } require_once 'array.php'; if (!isset($Types[$_GET['type'] ?? ''])) { - error(403); + Error403::error(); } $type = $_GET['type']; $reportType = $Types[$type]; @@ -22,7 +22,7 @@ switch ($type) { case 'user': $user = (new Manager\User())->findById($id); if (is_null($user)) { - error(404); + Error404::error(); } $report = new Report\User($id, $user); break; @@ -30,7 +30,7 @@ switch ($type) { case 'request': $request = (new Manager\Request())->findById($id); if (is_null($request)) { - error(404); + Error404::error(); } $report = new Report\Request($id, $request); break; @@ -38,10 +38,10 @@ switch ($type) { case 'request_update': $request = (new Manager\Request())->findById($id); if (is_null($request)) { - error(404); + Error404::error(); } if ($request->isFilled() || $request->categoryName() != 'Music' || $request->year() != 0) { - error(403); + Error403::error(); } $report = (new Report\Request($id, $request))->isUpdate(true); break; @@ -49,7 +49,7 @@ switch ($type) { case 'collage': $collage = (new Manager\Collage())->findById($id); if (is_null($collage)) { - error(404); + Error404::error(); } $report = new Report\Collage($id, $collage); break; @@ -57,10 +57,10 @@ switch ($type) { case 'thread': $thread = (new Manager\ForumThread())->findById($id); if (is_null($thread)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($thread->forum())) { - error(403); + Error403::error(); } $report = new Report\ForumThread($id, $thread); break; @@ -68,10 +68,10 @@ switch ($type) { case 'post': $post = (new Manager\ForumPost())->findById($id); if (is_null($post)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($post->thread()->forum())) { - error(403); + Error403::error(); } $report = new Report\ForumPost($id, $post); break; @@ -79,12 +79,12 @@ switch ($type) { case 'comment': $comment = (new Manager\Comment())->findById($id); if (is_null($comment)) { - error(404); + Error404::error(); } $report = (new Report\Comment($id, $comment))->setContext($reportType['title']); break; default: - error('Unknown report target'); + Error400::error('Unknown report target'); } echo $Twig->render('report/create.twig', [ diff --git a/sections/reports/report_handle.php b/sections/reports/report_handle.php index 61d882c8f..a67e80807 100644 --- a/sections/reports/report_handle.php +++ b/sections/reports/report_handle.php @@ -11,13 +11,13 @@ authorize(); $subjectId = (int)$_POST['id']; if (!$subjectId || empty($_POST['type']) || ($_POST['type'] !== 'request_update' && empty($_POST['reason']))) { - error(404); + Error404::error(); } require_once 'array.php'; /** @var array $Types */ if (!array_key_exists($_POST['type'], $Types)) { - error(403); + Error403::error(); } $subjectType = (string)$_POST['type']; @@ -26,7 +26,7 @@ if ($subjectType !== 'request_update') { } else { $year = trim($_POST['year']); if (empty($year) || !is_number($year)) { - error('Year must be specified.'); + Error400::error('Year must be specified.'); } $reason = "[b]Year[/b]: {$year}.\n\n"; // If the release type is somehow invalid, return "Not given"; otherwise, return the release type. @@ -46,7 +46,7 @@ $location = match ($subjectType) { default => null, // definitely a problem }; if (is_null($location)) { - error("Cannot generate a link to the reported item"); + Error400::error("Cannot generate a link to the reported item '$subjectType'"); } $report = (new Manager\Report(new Manager\User()))->create($Viewer, $subjectId, $subjectType, $reason); diff --git a/sections/reports/reports.php b/sections/reports/reports.php index f6c731a65..9c739a8ce 100644 --- a/sections/reports/reports.php +++ b/sections/reports/reports.php @@ -9,7 +9,7 @@ namespace Gazelle; use Gazelle\Enum\SearchReportOrder; if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) { - error(403); + Error403::error(); } require_once 'array.php'; diff --git a/sections/reports/resolve_handle.php b/sections/reports/resolve_handle.php index cf75777c9..436095e92 100644 --- a/sections/reports/resolve_handle.php +++ b/sections/reports/resolve_handle.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) { - error(403); + Error403::error(); } authorize(); @@ -15,7 +15,7 @@ if (is_null($report)) { json_error('no report id'); } if (!$Viewer->permitted('admin_reports') && !in_array($report->subjectType(), ['comment', 'post', 'thread'])) { - error('forbidden ' . $report->subjectType()); + Error403::error('forbidden ' . $report->subjectType()); } $report->resolve($Viewer); diff --git a/sections/reports/stats.php b/sections/reports/stats.php index 576dd2358..caadde83b 100644 --- a/sections/reports/stats.php +++ b/sections/reports/stats.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) { - error(403); + Error403::error(); } echo $Twig->render('report/stats.twig', [ diff --git a/sections/reportsv2/ajax_claim.php b/sections/reportsv2/ajax_claim.php index 408f636cc..84e3dcd4a 100644 --- a/sections/reportsv2/ajax_claim.php +++ b/sections/reportsv2/ajax_claim.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } echo (new Manager\Torrent\Report(new Manager\Torrent())) diff --git a/sections/reportsv2/ajax_new_report.php b/sections/reportsv2/ajax_new_report.php index f669a8bb4..ad3d5ec00 100644 --- a/sections/reportsv2/ajax_new_report.php +++ b/sections/reportsv2/ajax_new_report.php @@ -15,7 +15,7 @@ namespace Gazelle; */ if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } $torMan = new Manager\Torrent(); diff --git a/sections/reportsv2/ajax_switch.php b/sections/reportsv2/ajax_switch.php index 899fb3c11..80b855fa3 100644 --- a/sections/reportsv2/ajax_switch.php +++ b/sections/reportsv2/ajax_switch.php @@ -17,7 +17,7 @@ namespace Gazelle; */ if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } authorize(); diff --git a/sections/reportsv2/ajax_unclaim.php b/sections/reportsv2/ajax_unclaim.php index 3d761114d..dc8d9f84a 100644 --- a/sections/reportsv2/ajax_unclaim.php +++ b/sections/reportsv2/ajax_unclaim.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } (new Manager\Torrent\Report(new Manager\Torrent())) diff --git a/sections/reportsv2/ajax_update_comment.php b/sections/reportsv2/ajax_update_comment.php index 56dad5603..8f9af25ce 100644 --- a/sections/reportsv2/ajax_update_comment.php +++ b/sections/reportsv2/ajax_update_comment.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } authorize(); diff --git a/sections/reportsv2/report_handle.php b/sections/reportsv2/report_handle.php index fb16733cb..dfe70d147 100644 --- a/sections/reportsv2/report_handle.php +++ b/sections/reportsv2/report_handle.php @@ -22,23 +22,25 @@ authorize(); $torMan = new Manager\Torrent(); $torrent = $torMan->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $reportMan = new Manager\Torrent\Report($torMan); if ($reportMan->existsRecent($torrent->id(), $Viewer->id())) { - error("Slow down, you're moving too fast!"); + Error429::error("Slow down, you're moving too fast!"); } $reportType = (new Manager\Torrent\ReportType())->findByType($_POST['type'] ?? ''); if (is_null($reportType)) { - error("bad report type"); + Error400::error("bad report type"); } if ($reportType->needImage() === 'required') { $field = 'image'; if (empty($_POST[$field])) { - error("You are missing a required field ($field) for a {$reportType->name()} report."); + Error400::error( + "You are missing a required field ($field) for a {$reportType->name()} report." + ); } } @@ -47,15 +49,19 @@ if ($reportType->needSitelink() !== 'none') { $sitelink = trim($_POST['sitelink'] ?? ''); if ($sitelink === '') { if ($reportType->needSitelink() === 'required') { - error("You must supply a permalink [PL] in your report"); + Error400::error("You must supply a permalink [PL] in your report"); } } else { if (!preg_match_all(TORRENT_REGEXP, $sitelink, $match)) { - error("The permalink was incorrect. Please copy the torrent permalink URL, which is labelled as [PL] and is found next to the [DL] buttons."); + Error400::error( + "The permalink was incorrect. Please copy the torrent permalink URL, which is labelled as [PL] and is found next to the [DL] buttons." + ); } $all = $match['id']; if (in_array($torrent->id(), $all)) { - error("The extra permalinks you gave included the link to the torrent you're reporting!"); + Error400::error( + "The extra permalinks you gave included the link to the torrent you're reporting!" + ); } $ExtraIDs = implode(' ', $all); } @@ -65,10 +71,10 @@ $Links = ''; if ($reportType->needLink() !== 'none') { $link = trim($_POST['link'] ?? ''); if ($link === '' && $reportType->needLink() === 'required') { - error("You must supply one or more links in your report"); + Error400::error("You must supply one or more links in your report"); } elseif ($link != '') { if (!preg_match_all(URL_REGEXP, $link, $match)) { - error("The extra links you provided weren't links..."); + Error400::error("The extra links you provided weren't links..."); } $Links = implode(' ', $match[1]); } @@ -79,11 +85,11 @@ if ($reportType->needImage() !== 'none') { $image = trim($_POST['image'] ?? ''); if ($image === '') { if ($reportType->needImage() === 'required') { - error("You must supply one or more images in your report"); + Error400::error("You must supply one or more images in your report"); } } else { if (!preg_match_all(IMAGE_REGEXP, $image, $match)) { - error("The extra image links you provided weren't links to images..."); + Error400::error("The extra image links you provided weren't links to images..."); } $Images = implode(' ', $match[1]); } @@ -98,14 +104,16 @@ if ($reportType->needTrack() !== 'none') { ? '' : implode(' ', array_filter(array_map('intval', $split), fn ($n) => $n > 0)); if ($reportType->needTrack() === 'required' && $trackList === '') { - error('Tracks should be given in a space-separated list of numbers with no other characters, or "all".'); + Error400::error( + 'Tracks should be given in a space-separated list of numbers with no other characters, or "all".' + ); } } } $reason = trim($_POST['extra']); if (empty($reason)) { - error("As useful as blank reports are, could you be a tiny bit more helpful? (Leave a comment)"); + Error400::error("Please supply a reason to help resolve this report."); } $report = $reportMan->create( diff --git a/sections/reportsv2/reports.php b/sections/reportsv2/reports.php index c98048b99..70ddd0681 100644 --- a/sections/reportsv2/reports.php +++ b/sections/reportsv2/reports.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } echo $Twig->render('reportsv2/outline.twig', [ diff --git a/sections/reportsv2/search.php b/sections/reportsv2/search.php index 01ce5ee14..f2d8bb48e 100644 --- a/sections/reportsv2/search.php +++ b/sections/reportsv2/search.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); @@ -29,7 +29,7 @@ foreach (['reporter', 'handler', 'uploader'] as $role) { if (isset($_GET[$role]) && preg_match('/(@?[\w.-]+)/', $_GET[$role], $match)) { $user = $userMan->find($match[1]); if (is_null($user)) { - error("No such $role: {$_GET[$role]} (numeric id or @username expected)."); + Error404::error("No such $role: {$_GET[$role]} (numeric id or @username expected)."); } $filter[$role] = $user; } diff --git a/sections/reportsv2/static.php b/sections/reportsv2/static.php index 84413c514..a14fc97f9 100644 --- a/sections/reportsv2/static.php +++ b/sections/reportsv2/static.php @@ -19,7 +19,7 @@ namespace Gazelle; */ if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } $torMan = new Manager\Torrent(); diff --git a/sections/reportsv2/views.php b/sections/reportsv2/views.php index 0e8d4b515..a851d1766 100644 --- a/sections/reportsv2/views.php +++ b/sections/reportsv2/views.php @@ -13,7 +13,7 @@ namespace Gazelle; * All the different views are self explanatory by their names. */ if (!$Viewer->permitted('admin_reports')) { - error(403); + Error403::error(); } $reportMan = new Manager\Torrent\Report(new Manager\Torrent()); diff --git a/sections/requests/bounty_handle.php b/sections/requests/bounty_handle.php index 92622be07..6a8822685 100644 --- a/sections/requests/bounty_handle.php +++ b/sections/requests/bounty_handle.php @@ -8,12 +8,12 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_admin_requests')) { - error(403); + Error403::error(); } $request = (new Manager\Request())->findById((int)$_POST['id']); if (is_null($request)) { - error(404); + Error404::error(); } $action = []; @@ -34,11 +34,11 @@ foreach ($_POST as $k => $v) { continue; } if (!in_array($v, ['refund', 'remove'])) { - error('Unknown bounty action'); + Error400::error('Unknown bounty action'); } $action[(int)$match[2]] = $v; } else { - error('Unknown bounty edit requested'); + Error400::error('Unknown bounty edit requested'); } } } diff --git a/sections/requests/delete_handle.php b/sections/requests/delete_handle.php index 585296525..76d53a025 100644 --- a/sections/requests/delete_handle.php +++ b/sections/requests/delete_handle.php @@ -9,10 +9,10 @@ authorize(); $request = (new Manager\Request())->findById((int)$_POST['id']); if (is_null($request)) { - error(404); + Error404::error(); } if ($Viewer->id() != $request->userId() && !$Viewer->permitted('site_moderate_requests')) { - error(403); + Error403::error(); } $reason = trim($_POST['reason']); diff --git a/sections/requests/edit.php b/sections/requests/edit.php index b7deb23d1..a3a1bec8e 100644 --- a/sections/requests/edit.php +++ b/sections/requests/edit.php @@ -8,10 +8,10 @@ namespace Gazelle; $request = (new Manager\Request())->findById((int)($_GET['id'] ?? 0)); if (is_null($request)) { - error(404); + Error404::error(); } if (!$request->canEdit($Viewer)) { - error(403); + Error403::error("You do not have the necessary privileges to edit requests."); } $requestId = $request->id(); $ownRequest = $request->userId() == $Viewer->id(); diff --git a/sections/requests/edit_bounty.php b/sections/requests/edit_bounty.php index 277d77144..4188318c6 100644 --- a/sections/requests/edit_bounty.php +++ b/sections/requests/edit_bounty.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_admin_requests')) { - error(403); + Error403::error(); } $request = (new Manager\Request())->findById((int)$_GET['id']); if (is_null($request)) { - error(404); + Error404::error(); } echo $Twig->render('request/edit-bounty.twig', [ diff --git a/sections/requests/edit_handle.php b/sections/requests/edit_handle.php index 239aa7be4..89c4bbfd8 100644 --- a/sections/requests/edit_handle.php +++ b/sections/requests/edit_handle.php @@ -10,11 +10,11 @@ authorize(); $requestMan = new Manager\Request(); $request = $requestMan->findById((int)($_POST['requestid'] ?? 0)); if (is_null($request)) { - error(404); + Error404::error(); } if (!$request->canEdit($Viewer)) { - error(403); + Error403::error(); } if (!isset($_POST['type'])) { @@ -24,7 +24,7 @@ if (!isset($_POST['type'])) { $categoryName = $_POST['type']; $categoryId = array_search($categoryName, CATEGORY); if ($categoryId === false) { - error('The upload category is corrupt'); + Error400::error('The upload category is corrupt'); } $categoryId++; // array offset to id if ($categoryId != $request->categoryId()) { diff --git a/sections/requests/fill_handle.php b/sections/requests/fill_handle.php index e1df4ccf2..17b4519ff 100644 --- a/sections/requests/fill_handle.php +++ b/sections/requests/fill_handle.php @@ -22,7 +22,7 @@ if (!defined('AJAX')) { $request = (new Manager\Request())->findById((int)$_REQUEST['requestid']); if (is_null($request)) { - error(404); + Error404::error(); } $error = []; diff --git a/sections/requests/index.php b/sections/requests/index.php index 658a298a5..ea686f822 100644 --- a/sections/requests/index.php +++ b/sections/requests/index.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableRequests()) { - error('Your request privileges have been removed.'); + Error403::error('Your request privileges have been removed.'); } require_once match ($_REQUEST['action'] ?? null) { diff --git a/sections/requests/interim.php b/sections/requests/interim.php index 00eb14916..f5750e152 100644 --- a/sections/requests/interim.php +++ b/sections/requests/interim.php @@ -8,23 +8,23 @@ namespace Gazelle; $request = (new Manager\Request())->findById((int)$_GET['id']); if (is_null($request)) { - error(404); + Error404::error(); } $action = $_GET['action'] ?? ''; switch ($action) { case 'delete': if ($Viewer->id() != $request->userId() && !$Viewer->permitted('site_moderate_requests')) { - error(403); + Error403::error(); } break; case 'unfill': if (!in_array($Viewer->id(), [$request->userId(), $request->fillerId()]) && !$Viewer->permitted('site_moderate_requests')) { - error(403); + Error403::error(); } break; default: - error('Unknown request action specified'); + Error400::error('Unknown request action specified'); } echo $Twig->render('request/interim.twig', [ diff --git a/sections/requests/new.php b/sections/requests/new.php index 060d611ef..be3a76376 100644 --- a/sections/requests/new.php +++ b/sections/requests/new.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->uploadedSize() < 250 * 1024 * 1024 || !$Viewer->permitted('site_submit_requests')) { - error('You have not enough upload to make a request.'); + Error400::error('You have not enough upload to make a request.'); } // We may be able to prepare some things based on whence we came diff --git a/sections/requests/new_handle.php b/sections/requests/new_handle.php index cef9848cb..8c4591c50 100644 --- a/sections/requests/new_handle.php +++ b/sections/requests/new_handle.php @@ -8,13 +8,13 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_submit_requests') || $Viewer->uploadedSize() < 250 * 1024 * 1024) { - error(403); + Error403::error(); } $categoryName = $_POST['type'] ?? ''; $categoryId = array_search($categoryName, CATEGORY); if ($categoryId === false) { - error('request category corrupt'); + Error400::error('request category corrupt'); } $categoryId += 1; diff --git a/sections/requests/request.php b/sections/requests/request.php index 1ebd03db0..4f0adf0b3 100644 --- a/sections/requests/request.php +++ b/sections/requests/request.php @@ -8,7 +8,7 @@ namespace Gazelle; $request = (new Manager\Request())->findById((int)($_GET['id'] ?? 0)); if (is_null($request)) { - error(404); + Error404::error(); } $commentPage = new Comment\Request($request->id(), (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0)); diff --git a/sections/requests/requests.php b/sections/requests/requests.php index b44c76dc9..b68462a05 100644 --- a/sections/requests/requests.php +++ b/sections/requests/requests.php @@ -12,7 +12,7 @@ if (!isset($_GET['userid'])) { } else { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } @@ -34,24 +34,24 @@ if (empty($_GET['type'])) { break; case 'created': if (!$user->propertyVisible($Viewer, 'requestsvoted_list')) { - error(403); + Error403::error(); } $search->setCreator($user); break; case 'voted': if (!$user->propertyVisible($Viewer, 'requestsvoted_list')) { - error(403); + Error403::error(); } $search->setVoter($user); break; case 'filled': if (!$user->propertyVisible($Viewer, 'requestsfilled_list')) { - error(403); + Error403::error(); } $search->setFiller($user); break; default: - error(404); + Error404::error(); } } @@ -89,7 +89,7 @@ if (isset($_GET['requestor'])) { if ($requestor) { $search->setRequestor($requestor); } else { - error(404); + Error404::error(); } } diff --git a/sections/requests/unfill_handle.php b/sections/requests/unfill_handle.php index 7906352ce..3556ecf70 100644 --- a/sections/requests/unfill_handle.php +++ b/sections/requests/unfill_handle.php @@ -9,7 +9,7 @@ authorize(); $request = (new Manager\Request())->findById((int)$_REQUEST['id']); if (is_null($request)) { - error(404); + Error404::error(); } if ( $request->fillerId() === 0 @@ -18,7 +18,7 @@ if ( && !$Viewer->permitted('site_moderate_requests') ) ) { - error(403); + Error403::error(); } $request->unfill($Viewer, trim($_POST['reason']), new Manager\Torrent()); diff --git a/sections/requests/vote_handle.php b/sections/requests/vote_handle.php index 3f6f2eb03..b29eddc9f 100644 --- a/sections/requests/vote_handle.php +++ b/sections/requests/vote_handle.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_vote')) { - error(403); + Error403::error(); } authorize(); diff --git a/sections/staffblog/index.php b/sections/staffblog/index.php index 28580395b..c6845bd67 100644 --- a/sections/staffblog/index.php +++ b/sections/staffblog/index.php @@ -9,7 +9,7 @@ namespace Gazelle; use Gazelle\Util\Irc; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $blogMan = new Manager\StaffBlog(); @@ -33,11 +33,11 @@ if ($Viewer->permitted('admin_manage_blog')) { authorize(); $title = trim($_POST['title'] ?? ''); if (empty($title)) { - error("Please enter a title."); + Error400::error("Please enter a title."); } $body = trim($_POST['body'] ?? ''); if (empty($body)) { - error("Please enter a body."); + Error400::error("Please enter a body."); } if ($_REQUEST['action'] == 'takenewblog') { $blog = $blogMan->create($Viewer, $title, $body); @@ -51,7 +51,7 @@ if ($Viewer->permitted('admin_manage_blog')) { exit; default: - error(403); + Error403::error(); } } } diff --git a/sections/staffpm/ajax_delete_response.php b/sections/staffpm/ajax_delete_response.php index d6cc7b0d6..0140d9a53 100644 --- a/sections/staffpm/ajax_delete_response.php +++ b/sections/staffpm/ajax_delete_response.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->isStaffPMReader()) { - error(403); + Error403::error(); } authorize(); diff --git a/sections/staffpm/ajax_edit_response.php b/sections/staffpm/ajax_edit_response.php index 937b3c563..f27c6c104 100644 --- a/sections/staffpm/ajax_edit_response.php +++ b/sections/staffpm/ajax_edit_response.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->isStaffPMReader()) { - error(403); + Error403::error(); } $name = trim($_POST['name']); diff --git a/sections/staffpm/ajax_get_response.php b/sections/staffpm/ajax_get_response.php index 41e23238c..fb51ad13b 100644 --- a/sections/staffpm/ajax_get_response.php +++ b/sections/staffpm/ajax_get_response.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->isStaffPMReader()) { - error(403); + Error403::error(); } $answer = (new Manager\StaffPM())->commonAnswer((int)($_GET['id'] ?? 0)); diff --git a/sections/staffpm/assign.php b/sections/staffpm/assign.php index 483b6f0d1..3016a9eb9 100644 --- a/sections/staffpm/assign.php +++ b/sections/staffpm/assign.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->isStaffPMReader()) { - error(403); + Error403::error(); } $staffPm = (new Manager\StaffPM())->findById((int)($_REQUEST['convid'] ?? 0)); @@ -18,16 +18,16 @@ if (is_null($staffPm)) { if (isset($_GET['convid'])) { if ($Viewer->isFLS() && $staffPm->classLevel() > 0) { // FLS trying to assign non-FLS conversation - error(403); + Error403::error(); } if (empty($_GET['to'])) { - error(404); + Error404::error(); } $classList = (new Manager\User())->classList(); match ($_GET['to']) { 'forum' => $staffPm->assignClass($classList[FORUM_MOD]['Level'], $Viewer), 'staff' => $staffPm->assignClass($classList[MOD]['Level'], $Viewer), - default => error(404), + default => Error404::error(), }; header('Location: staffpm.php'); exit; @@ -45,7 +45,7 @@ if ($Viewer->privilege()->effectiveClassLevel() < $staffPm->classLevel() && $Vie } else { $assignee = (new Manager\User())->findById($NewLevel); if (is_null($assignee)) { - error(404); + Error404::error(); } $staffPm->assign($assignee, $Viewer); } diff --git a/sections/staffpm/common_responses.php b/sections/staffpm/common_responses.php index 46d84e76d..8dc7020ca 100644 --- a/sections/staffpm/common_responses.php +++ b/sections/staffpm/common_responses.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->isStaffPMReader()) { - error(403); + Error403::error(); } echo $Twig->render('staffpm/common-response.twig', [ diff --git a/sections/staffpm/get_post.php b/sections/staffpm/get_post.php index 2805d7bf9..e138ea2e9 100644 --- a/sections/staffpm/get_post.php +++ b/sections/staffpm/get_post.php @@ -8,10 +8,10 @@ namespace Gazelle; $postId = (int)($_GET['post'] ?? 0); $pm = (new Manager\StaffPM())->findByPostId($postId); if (is_null($pm)) { - error(404); + Error404::error(); } if (!$pm->visible($Viewer)) { - error(403); + Error403::error(); } header('Content-Type: application/json; charset=utf-8'); diff --git a/sections/staffpm/scoreboard.php b/sections/staffpm/scoreboard.php index a604c36ed..154b85464 100644 --- a/sections/staffpm/scoreboard.php +++ b/sections/staffpm/scoreboard.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_staffpm_stats')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); diff --git a/sections/staffpm/staff_inbox.php b/sections/staffpm/staff_inbox.php index 8e653a18e..3277d5907 100644 --- a/sections/staffpm/staff_inbox.php +++ b/sections/staffpm/staff_inbox.php @@ -41,7 +41,7 @@ if ($Viewer->isStaff()) { $view = $_GET['view'] ?? ''; if (!isset($viewMap[$view])) { - error('Unknown staff inbox view parameter'); + Error400::error('Unknown staff inbox view parameter'); } if (isset($_GET['id'])) { diff --git a/sections/staffpm/unresolve.php b/sections/staffpm/unresolve.php index 09c83dc51..2407089f4 100644 --- a/sections/staffpm/unresolve.php +++ b/sections/staffpm/unresolve.php @@ -7,10 +7,10 @@ namespace Gazelle; $spm = (new Manager\StaffPM())->findById((int)($_GET['id'] ?? 0)); if (is_null($spm)) { - error(404); + Error404::error(); } if (!$spm->visible($Viewer)) { - error(403); + Error403::error(); } $spm->unresolve($Viewer); diff --git a/sections/staffpm/viewconv.php b/sections/staffpm/viewconv.php index 7b5263a1a..6a461fbbd 100644 --- a/sections/staffpm/viewconv.php +++ b/sections/staffpm/viewconv.php @@ -9,10 +9,10 @@ namespace Gazelle; $manager = new Manager\StaffPM(); $staffPM = $manager->findById((int)($_GET['id'] ?? 0)); if (is_null($staffPM)) { - error(404); + Error404::error(); } if (!$staffPM->visible($Viewer)) { - error(403); + Error403::error(); } if ($staffPM->userId() === $Viewer->id() && $staffPM->isUnread()) { // User is viewing their own unread conversation, set it to read diff --git a/sections/staffpm/viewconv_handle.php b/sections/staffpm/viewconv_handle.php index c76967ed8..1090c90b5 100644 --- a/sections/staffpm/viewconv_handle.php +++ b/sections/staffpm/viewconv_handle.php @@ -11,7 +11,7 @@ $resolve = isset($_POST['resolve']); $message = trim($_POST['quickpost'] ?? ''); if (empty($message) && !$resolve) { - error("You must write something in your message"); + Error400::error("You must write something in your message"); } if (isset($_POST['convid'])) { @@ -21,22 +21,22 @@ if (isset($_POST['convid'])) { exit; } if (!$spm->visible($Viewer)) { - error(403); + Error403::error(); } } elseif (isset($_POST['subject'])) { // New staff PM conversation if (!isset($_POST['level'])) { - error("Unclear on the recipient"); + Error400::error("Unclear on the recipient"); } $subject = trim($_POST['subject']); if (empty($subject)) { - error("You must provide a subject for your message"); + Error400::error("You must provide a subject for your message"); } $manager->create($Viewer, (int)$_POST['level'], $subject, $message); header('Location: staffpm.php'); exit; } else { - error(0); + Error400::error(); } if ($message) { diff --git a/sections/tools/data/bonus_stats.php b/sections/tools/data/bonus_stats.php index 1c77c4715..991758a45 100644 --- a/sections/tools/data/bonus_stats.php +++ b/sections/tools/data/bonus_stats.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_bp_history')) { - error(403); + Error403::error(); } $bonus = new Stats\Bonus(); diff --git a/sections/tools/data/economic_stats.php b/sections/tools/data/economic_stats.php index 24fa2aee7..9af3c802e 100644 --- a/sections/tools/data/economic_stats.php +++ b/sections/tools/data/economic_stats.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_flow')) { - error(403); + Error403::error(); } echo $Twig->render('admin/economy.twig', [ diff --git a/sections/tools/data/invite_pool.php b/sections/tools/data/invite_pool.php index 27f2747ea..987a2f187 100644 --- a/sections/tools/data/invite_pool.php +++ b/sections/tools/data/invite_pool.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_invites')) { - error(403); + Error403::error(); } $inviteMan = new Manager\Invite(); diff --git a/sections/tools/data/platform_usage.php b/sections/tools/data/platform_usage.php index de22b6e60..ef053e59f 100644 --- a/sections/tools/data/platform_usage.php +++ b/sections/tools/data/platform_usage.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_debug')) { - error(403); + Error403::error(); } $stats = new Stats\Users(); diff --git a/sections/tools/data/ratio_watch.php b/sections/tools/data/ratio_watch.php index 4b5862fdc..63668fe38 100644 --- a/sections/tools/data/ratio_watch.php +++ b/sections/tools/data/ratio_watch.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_flow')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); diff --git a/sections/tools/data/registration_log.php b/sections/tools/data/registration_log.php index 620a753f1..d97024532 100644 --- a/sections/tools/data/registration_log.php +++ b/sections/tools/data/registration_log.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('users_view_ips', 'users_view_email')) { - error(403); + Error403::error(); } $registration = new Manager\Registration(); diff --git a/sections/tools/data/site_info.php b/sections/tools/data/site_info.php index cf8c5b762..11e47465f 100644 --- a/sections/tools/data/site_info.php +++ b/sections/tools/data/site_info.php @@ -8,7 +8,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } function uid(int $id): string { diff --git a/sections/tools/data/special_users.php b/sections/tools/data/special_users.php index 05ea863b6..fa3a4e514 100644 --- a/sections/tools/data/special_users.php +++ b/sections/tools/data/special_users.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } echo $Twig->render('admin/user-custom-permission.twig', [ diff --git a/sections/tools/data/torrent_stats.php b/sections/tools/data/torrent_stats.php index 2a7d61063..3a816878c 100644 --- a/sections/tools/data/torrent_stats.php +++ b/sections/tools/data/torrent_stats.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_flow')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); diff --git a/sections/tools/data/user_flow.php b/sections/tools/data/user_flow.php index 7a8f51682..a8152f7f4 100644 --- a/sections/tools/data/user_flow.php +++ b/sections/tools/data/user_flow.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_flow')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); diff --git a/sections/tools/data/user_info.php b/sections/tools/data/user_info.php index 5146de9fc..2c0b41c0a 100644 --- a/sections/tools/data/user_info.php +++ b/sections/tools/data/user_info.php @@ -7,14 +7,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); $user = $userMan->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $column = $_GET['col'] ?? 'first'; diff --git a/sections/tools/development/analysis.php b/sections/tools/development/analysis.php index 2df8396b7..377d43de0 100644 --- a/sections/tools/development/analysis.php +++ b/sections/tools/development/analysis.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_analysis')) { - error(403); + Error403::error(); } $errorLog = new Manager\ErrorLog(); diff --git a/sections/tools/development/analysis_list.php b/sections/tools/development/analysis_list.php index f86bd44cc..2c3781615 100644 --- a/sections/tools/development/analysis_list.php +++ b/sections/tools/development/analysis_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_analysis')) { - error(403); + Error403::error(); } $errMan = new Manager\ErrorLog(); diff --git a/sections/tools/development/clear_cache.php b/sections/tools/development/clear_cache.php index 08e1f2c70..6623555d5 100644 --- a/sections/tools/development/clear_cache.php +++ b/sections/tools/development/clear_cache.php @@ -8,7 +8,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_clear_cache')) { - error(403); + Error403::error(); } $result = []; @@ -33,7 +33,7 @@ if (!empty($_REQUEST['key'])) { foreach ($Keys as $Key) { foreach (CACHE_PERMISSION as $name => $permission) { if (str_contains($Key, $name) && !$Viewer->permitted($permission)) { - error(403); + Error403::error(); } } $result[$Key] = $Cache->get_value($Key); diff --git a/sections/tools/development/db_sandbox.php b/sections/tools/development/db_sandbox.php index 2d49f2bd2..b09cf51b2 100644 --- a/sections/tools/development/db_sandbox.php +++ b/sections/tools/development/db_sandbox.php @@ -10,7 +10,7 @@ use Gazelle\Enum\SourceDB; use Gazelle\Util\Text; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } $src = ($_REQUEST['src'] ?? SourceDB::mysql->value) == SourceDB::mysql->value diff --git a/sections/tools/development/mysql.php b/sections/tools/development/mysql.php index f6c6d3542..557f4b6fe 100644 --- a/sections/tools/development/mysql.php +++ b/sections/tools/development/mysql.php @@ -11,7 +11,7 @@ use Gazelle\Enum\MysqlInfoOrderBy; use Gazelle\Enum\MysqlTableMode; if (!$Viewer->permitted('site_database_specifics')) { - error(403); + Error403::error(); } // View table definition @@ -20,7 +20,7 @@ if (!empty($_GET['table']) && preg_match('/([\w-]+)/', $_GET['table'], $match)) $tableName = $match[1]; $siteInfo = new SiteInfo(); if (!$siteInfo->tableExists($tableName)) { - error("No such table"); + Error404::error("No such table"); } echo $Twig->render('admin/mysql-table.twig', [ 'definition' => $db->row('SHOW CREATE TABLE ' . $tableName)[1], diff --git a/sections/tools/development/notification.php b/sections/tools/development/notification.php index e85a6aa04..ec3e62bed 100644 --- a/sections/tools/development/notification.php +++ b/sections/tools/development/notification.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_view_notifications')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)($_POST['torrentid'] ?? 0)); diff --git a/sections/tools/development/periodic_alter.php b/sections/tools/development/periodic_alter.php index 32004d0ba..17bd43cdb 100644 --- a/sections/tools/development/periodic_alter.php +++ b/sections/tools/development/periodic_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_periodic_task_manage')) { - error(403); + Error403::error(); } authorize(); @@ -16,7 +16,7 @@ $scheduler = new TaskScheduler(); if ($p['submit'] == 'Delete') { if (!is_number($p['id']) || $p['id'] == '') { - error('Unknown or missing task id for delete'); + Error400::error('Unknown or missing task id for delete'); } $scheduler->deleteTask($p['id']); @@ -44,12 +44,12 @@ if ($p['submit'] == 'Delete') { isset($p['enabled']), isset($p['sane']), isset($p['debug'])); } elseif ($p['submit'] == 'Edit') { if (!is_number($p['id']) || $p['id'] == '') { - error('Unknown or missing task id for edit'); + Error400::error('Unknown or missing task id for edit'); } $task = $scheduler->getTask($p['id']); if ($task == null) { - error('Task not found'); + Error404::error('Task not found'); } $scheduler->updateTask(intval($p['id']), $p['name'], $p['classname'], $p['description'], diff --git a/sections/tools/development/periodic_detail.php b/sections/tools/development/periodic_detail.php index dd3560632..0955b5591 100644 --- a/sections/tools/development/periodic_detail.php +++ b/sections/tools/development/periodic_detail.php @@ -7,13 +7,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_periodic_task_view')) { - error(403); + Error403::error(); } $scheduler = new TaskScheduler(); $id = (int)($_GET['id'] ?? 0); if (!$scheduler->getTask($id)) { - error(404); + Error404::error(); } $header = new Util\SortableTableHeader('launchtime', [ diff --git a/sections/tools/development/periodic_edit.php b/sections/tools/development/periodic_edit.php index 16b566cc4..958fa5daf 100644 --- a/sections/tools/development/periodic_edit.php +++ b/sections/tools/development/periodic_edit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_periodic_task_manage')) { - error(403); + Error403::error(); } echo $Twig->render('admin/scheduler/edit.twig', [ diff --git a/sections/tools/development/periodic_run.php b/sections/tools/development/periodic_run.php index 4d617f38c..133e34784 100644 --- a/sections/tools/development/periodic_run.php +++ b/sections/tools/development/periodic_run.php @@ -7,14 +7,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_schedule')) { - error(403); + Error403::error(); } authorize(); $taskId = (int)($_REQUEST['id'] ?? 0); if (!$taskId) { - error("Task not found"); + Error400::error("Task not found"); } $scheduler = new TaskScheduler(); diff --git a/sections/tools/development/periodic_stats.php b/sections/tools/development/periodic_stats.php index b55e147b1..057f87265 100644 --- a/sections/tools/development/periodic_stats.php +++ b/sections/tools/development/periodic_stats.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_periodic_task_view')) { - error(403); + Error403::error(); } $stats = (new TaskScheduler())->getRuntimeStats(); diff --git a/sections/tools/development/periodic_view.php b/sections/tools/development/periodic_view.php index 3d6d29c16..79570be1d 100644 --- a/sections/tools/development/periodic_view.php +++ b/sections/tools/development/periodic_view.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_periodic_task_view')) { - error(403); + Error403::error(); } $scheduler = new TaskScheduler(); @@ -15,7 +15,7 @@ $taskId = (int)($_REQUEST['id'] ?? 0); if ($taskId && $_REQUEST['mode'] === 'run_now') { if (!$Viewer->permitted('admin_schedule')) { - error(403); + Error403::error(); } authorize(); $scheduler->runNow($taskId); diff --git a/sections/tools/development/pg.php b/sections/tools/development/pg.php index 8f2a23b09..0d32c5475 100644 --- a/sections/tools/development/pg.php +++ b/sections/tools/development/pg.php @@ -10,7 +10,7 @@ use Gazelle\Enum\PgInfoOrderBy; use Gazelle\Enum\Direction; if (!$Viewer->permitted('site_database_specifics')) { - error(403); + Error403::error(); } $info = new DB\PgInfo( diff --git a/sections/tools/development/process_info.php b/sections/tools/development/process_info.php index ce2d2cdaf..07be3270a 100644 --- a/sections/tools/development/process_info.php +++ b/sections/tools/development/process_info.php @@ -8,7 +8,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } $proc = []; diff --git a/sections/tools/development/referral_sandbox.php b/sections/tools/development/referral_sandbox.php index 0884329de..8651abacd 100644 --- a/sections/tools/development/referral_sandbox.php +++ b/sections/tools/development/referral_sandbox.php @@ -8,7 +8,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_referrals')) { - error(403); + Error403::error(); } $referralManager = new Manager\Referral(); diff --git a/sections/tools/development/service_stats.php b/sections/tools/development/service_stats.php index b953c4a76..e96b6f9f5 100644 --- a/sections/tools/development/service_stats.php +++ b/sections/tools/development/service_stats.php @@ -8,7 +8,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_debug')) { - error(403); + Error403::error(); } $inspectDb = new DB(); diff --git a/sections/tools/development/site_options.php b/sections/tools/development/site_options.php index ac84ac795..db09d187d 100644 --- a/sections/tools/development/site_options.php +++ b/sections/tools/development/site_options.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_manage_permissions', 'users_mod')) { - error(403); + Error403::error(); } $siteOption = new Manager\SiteOption(); @@ -29,7 +29,7 @@ if ($Viewer->permitted('admin_manage_permissions') && isset($_POST['submit'])) { ['comment', true, 'string', 'You must specify a comment for the option.'], ]); if (!$Val->validate($_POST)) { - error($Val->errorMessage()); + Error400::error($Val->errorMessage()); } if ($_POST['submit'] == 'Edit') { diff --git a/sections/tools/finances/donation_log.php b/sections/tools/finances/donation_log.php index 4f28e5201..32c42933f 100644 --- a/sections/tools/finances/donation_log.php +++ b/sections/tools/finances/donation_log.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_donor_log')) { - error(403); + Error403::error(); } $search = new Search\Donation(); diff --git a/sections/tools/finances/donor_rewards.php b/sections/tools/finances/donor_rewards.php index 8b0d4426b..47cb3aeee 100644 --- a/sections/tools/finances/donor_rewards.php +++ b/sections/tools/finances/donor_rewards.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $manager = new Manager\Donation(); diff --git a/sections/tools/finances/payment_alter.php b/sections/tools/finances/payment_alter.php index 8fdb33067..47a7d9632 100644 --- a/sections/tools/finances/payment_alter.php +++ b/sections/tools/finances/payment_alter.php @@ -6,14 +6,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_payments')) { - error(403); + Error403::error(); } $Payment = new Manager\Payment(); if ($_POST['submit'] == 'Delete') { if (!is_number($_POST['id']) || $_POST['id'] == '') { - error('Unknown payment id for delete'); + Error400::error('Unknown payment id for delete'); } $Payment->remove($_POST['id']); } else { diff --git a/sections/tools/finances/payment_list.php b/sections/tools/finances/payment_list.php index 522251d22..47c46a61d 100644 --- a/sections/tools/finances/payment_list.php +++ b/sections/tools/finances/payment_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_view_payments')) { - error(403); + Error403::error(); } echo $Twig->render('admin/payment.twig', [ diff --git a/sections/tools/index.php b/sections/tools/index.php index 0c50e6ec3..c3d745bb3 100644 --- a/sections/tools/index.php +++ b/sections/tools/index.php @@ -281,7 +281,7 @@ switch ($_REQUEST['action'] ?? '') { break; case 'bbcode_sandbox': if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } echo $Twig->render('admin/sandbox/bbcode.twig'); break; diff --git a/sections/tools/managers/ajax_take_enable_request.php b/sections/tools/managers/ajax_take_enable_request.php index 8719c7b32..c860f4582 100644 --- a/sections/tools/managers/ajax_take_enable_request.php +++ b/sections/tools/managers/ajax_take_enable_request.php @@ -35,7 +35,7 @@ switch ($_GET['type'] ?? '') { if ($enableRequest?->isDiscarded()) { $enableRequest->unresolve($Viewer); } else { - error(404); + json_error(404); } break; diff --git a/sections/tools/managers/asn_search.php b/sections/tools/managers/asn_search.php index d4c50e908..f37b171e5 100644 --- a/sections/tools/managers/asn_search.php +++ b/sections/tools/managers/asn_search.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $name = false; diff --git a/sections/tools/managers/bans.php b/sections/tools/managers/bans.php index bdac038d5..9d8c5c80c 100644 --- a/sections/tools/managers/bans.php +++ b/sections/tools/managers/bans.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_ipbans')) { - error(403); + Error403::error(); } $IPv4Man = new Manager\IPv4(); @@ -17,7 +17,7 @@ if (isset($_POST['submit'])) { $id = (int)($_POST['id'] ?? 0); if ($_POST['submit'] == 'Delete') { //Delete if (!$id) { - error('Unknown id for ip ban removal'); + Error400::error('Unknown id for ip ban removal'); } $IPv4Man->removeBan($id); } else { //Edit & Create, Shared Validation @@ -28,7 +28,7 @@ if (isset($_POST['submit'])) { ['notes', true,'string','You must include the reason for the ban.'], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($id) { $IPv4Man->modifyBan($Viewer, $id, $_POST['start'], $_POST['end'], trim($_POST['notes'])); diff --git a/sections/tools/managers/bonus_points.php b/sections/tools/managers/bonus_points.php index 018e3f467..fcd22c593 100644 --- a/sections/tools/managers/bonus_points.php +++ b/sections/tools/managers/bonus_points.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $message = ""; @@ -19,7 +19,7 @@ if (isset($_REQUEST['add_points'])) { $since = trim($_POST['since_date'] ?? date("Y-m-d", strtotime("-120 day", time()))); if ($active < 0 || $upload < 0 || $seed < 0) { - error('Please enter a positive number of points.'); + Error400::error('Please enter a positive number of points.'); } $bonusMan = new Manager\Bonus(); diff --git a/sections/tools/managers/categories_alter.php b/sections/tools/managers/categories_alter.php index 24a2306d5..d8b3e5218 100644 --- a/sections/tools/managers/categories_alter.php +++ b/sections/tools/managers/categories_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_forums')) { - error(403); + Error403::error(); } authorize(); @@ -16,10 +16,10 @@ $manager = new Manager\ForumCategory(); if ($_POST['submit'] == 'Delete') { $forumCategory = $manager->findById((int)($_POST['id'] ?? 0)); if (is_null($forumCategory)) { - error(404); + Error404::error(); } if (!$forumCategory->remove()) { - error('You must move all forums out of a category before deleting it.'); + Error400::error('You must move all forums out of a category before deleting it.'); } } else { // Edit & Create @@ -29,7 +29,7 @@ if ($_POST['submit'] == 'Delete') { ['sort', true, 'number', 'Sequence must be set'], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($_POST['submit'] == 'Create') { @@ -37,7 +37,7 @@ if ($_POST['submit'] == 'Delete') { } else { $forumCategory = $manager->findById((int)($_POST['id'] ?? 0)); if (is_null($forumCategory)) { - error(404); + Error404::error(); } $forumCategory ->setField('Sort', (int)$_POST['sort']) diff --git a/sections/tools/managers/categories_list.php b/sections/tools/managers/categories_list.php index c50a1383c..92f9bd482 100644 --- a/sections/tools/managers/categories_list.php +++ b/sections/tools/managers/categories_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_forums')) { - error(403); + Error403::error(); } echo $Twig->render('admin/forum-category.twig', [ diff --git a/sections/tools/managers/change_log.php b/sections/tools/managers/change_log.php index e04e482fc..4a38ce363 100644 --- a/sections/tools/managers/change_log.php +++ b/sections/tools/managers/change_log.php @@ -22,7 +22,7 @@ if ($Viewer->permitted('users_mod') && isset($_POST['perform'])) { } break; default: - error(403); + Error403::error(); } } diff --git a/sections/tools/managers/create_user.php b/sections/tools/managers/create_user.php index 2989c337f..ca637bb9b 100644 --- a/sections/tools/managers/create_user.php +++ b/sections/tools/managers/create_user.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_create_users')) { - error(403); + Error403::error(); } if (isset($_POST['Username'])) { @@ -19,11 +19,11 @@ if (isset($_POST['Username'])) { $password = $_POST['Password']; if (empty($username)) { - error('Please supply a username'); + Error400::error('Please supply a username'); } elseif (empty($email)) { - error('Please supply an email address'); + Error400::error('Please supply an email address'); } elseif (empty($password)) { - error('Please supply a password'); + Error400::error('Please supply a password'); } $creator = new UserCreator(); @@ -34,7 +34,7 @@ if (isset($_POST['Username'])) { ->addNote('Created by ' . $Viewer->username() . ' via admin toolbox') ->create(); } catch (Exception\UserCreatorException $e) { - error(match ($e->getMessage()) { + Error400::error(match ($e->getMessage()) { 'username-invalid' => 'Specified username is forbidden', default => 'Unable to create user', }); diff --git a/sections/tools/managers/custom_pm.php b/sections/tools/managers/custom_pm.php index b1f9eb22b..011550907 100644 --- a/sections/tools/managers/custom_pm.php +++ b/sections/tools/managers/custom_pm.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } $delivered = false; @@ -37,7 +37,7 @@ if (isset($_POST['query'])) { } break; default: - error("Bad database source, try again"); + Error400::error("Bad database source, try again"); } if (!$error && !$result && $_POST['query']) { $error = "Query returned 0 rows"; diff --git a/sections/tools/managers/db_key.php b/sections/tools/managers/db_key.php index 7d4c66203..4c26ebad2 100644 --- a/sections/tools/managers/db_key.php +++ b/sections/tools/managers/db_key.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } if (isset($_POST['dbkey'])) { diff --git a/sections/tools/managers/dnu_alter.php b/sections/tools/managers/dnu_alter.php index c44e319a2..0c9ec81f6 100644 --- a/sections/tools/managers/dnu_alter.php +++ b/sections/tools/managers/dnu_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_dnu')) { - error(403); + Error403::error(); } authorize(); @@ -30,7 +30,7 @@ if ($_POST['submit'] == 'Delete') { $Val->setField('name', true, 'string', 'The name must be set, have a length of between 5 and 100 characters.', ['range' => [5, 100]]); $Val->setField('description', false, 'string', 'The description has a maximum length of 255 characters.', ['maxlength' => 255]); if (!$Val->validate($_POST)) { - error($Val->errorMessage()); + Error400::error($Val->errorMessage()); } if ($_POST['submit'] == 'Edit') { diff --git a/sections/tools/managers/dnu_list.php b/sections/tools/managers/dnu_list.php index 50781813a..da825d1e0 100644 --- a/sections/tools/managers/dnu_list.php +++ b/sections/tools/managers/dnu_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_dnu')) { - error(403); + Error403::error(); } echo $Twig->render('admin/dnu.twig', [ diff --git a/sections/tools/managers/dupe_ip.php b/sections/tools/managers/dupe_ip.php index 9a59caaaa..620e44650 100644 --- a/sections/tools/managers/dupe_ip.php +++ b/sections/tools/managers/dupe_ip.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $manager = new Manager\DuplicateIP(); diff --git a/sections/tools/managers/email_blacklist.php b/sections/tools/managers/email_blacklist.php index 3212144bb..694857cd8 100644 --- a/sections/tools/managers/email_blacklist.php +++ b/sections/tools/managers/email_blacklist.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_email')) { - error(403); + Error403::error(); } diff --git a/sections/tools/managers/email_blacklist_alter.php b/sections/tools/managers/email_blacklist_alter.php index f437487d4..10b710ee1 100644 --- a/sections/tools/managers/email_blacklist_alter.php +++ b/sections/tools/managers/email_blacklist_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_email')) { - error(403); + Error403::error(); } authorize(); @@ -14,14 +14,14 @@ $emailBlacklist = new Manager\EmailBlacklist(); if ($_POST['submit'] === 'Delete') { // Delete if (!$emailBlacklist->remove((int)$_POST['id'])) { - error('Unknown id for email blacklist removal'); + Error400::error('Unknown id for email blacklist removal'); } } else { // Edit & Create, Shared Validation $validator = new Util\Validator(); $validator->setField('email', true, 'string', 'The email must be set', ['minlength' => 6]); $validator->setField('comment', false, 'string', 'The description has a max length of 255 characters', ['maxlength' => 255]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } $comment = trim($_POST['comment'] ?? ''); @@ -36,7 +36,7 @@ if ($_POST['submit'] === 'Delete') { // Delete user : $Viewer, ) ) { - error('Unable to edit email blacklist entry'); + Error400::error('Unable to edit email blacklist entry'); } } else { if ( @@ -46,7 +46,7 @@ if ($_POST['submit'] === 'Delete') { // Delete user : $Viewer, ) ) { - error('Unable to create email blacklist entry'); + Error400::error('Unable to create email blacklist entry'); } } } diff --git a/sections/tools/managers/email_search.php b/sections/tools/managers/email_search.php index 3b9353e68..c1ceb68a1 100644 --- a/sections/tools/managers/email_search.php +++ b/sections/tools/managers/email_search.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_email')) { - error(403); + Error403::error(); } $found = 0; diff --git a/sections/tools/managers/enable_requests.php b/sections/tools/managers/enable_requests.php index 6e36aee02..d3cf4ce61 100644 --- a/sections/tools/managers/enable_requests.php +++ b/sections/tools/managers/enable_requests.php @@ -7,11 +7,11 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } if (!FEATURE_EMAIL_REENABLE) { - error("Email reenabling is currently switched off"); + Error403::error("Email reenabling is currently switched off"); } $showChecked = $_GET['show_checked'] ?? false; diff --git a/sections/tools/managers/featured_album.php b/sections/tools/managers/featured_album.php index 7b58f3604..933b3a26b 100644 --- a/sections/tools/managers/featured_album.php +++ b/sections/tools/managers/featured_album.php @@ -11,7 +11,7 @@ use Gazelle\Enum\LeechType; use Gazelle\Enum\LeechReason; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $tgMan = new Manager\TGroup(); @@ -23,7 +23,7 @@ if (isset($_GET['unfeature'])) { match ($_GET['unfeature']) { 'aotm' => $manager->findByType(FeaturedAlbumType::AlbumOfTheMonth)?->unfeature(), 'showcase' => $manager->findByType(FeaturedAlbumType::Showcase)?->unfeature(), - default => error(403), + default => Error403::error(), }; header('Location: tools.php?action=featured_album'); exit; @@ -44,21 +44,21 @@ if (isset($_POST['groupid'])) { $tgroup = $tgMan->findById((int)$match[1]); } if (is_null($tgroup)) { - error('You did not enter a valid group ID'); + Error400::error('You did not enter a valid group ID'); } if (empty($_POST['body'])) { - error('You did not provide any text for the feature'); + Error400::error('You did not provide any text for the feature'); } $title = trim($_POST['title'] ?? ''); if (empty($title)) { - error('You did not provide a title for the front page announcement'); + Error400::error('You did not provide a title for the front page announcement'); } if ($leechType === LeechType::Normal || !isset($_POST['neutral'])) { $threshold = 0; } else { if (!$size || !in_array($unit, ['k', 'm', 'g'])) { - error('Invalid size or units for freeleech'); + Error400::error('Invalid size or units for freeleech'); } $threshold = get_bytes("$size$unit"); } diff --git a/sections/tools/managers/forum_alter.php b/sections/tools/managers/forum_alter.php index abb717677..15260f60a 100644 --- a/sections/tools/managers/forum_alter.php +++ b/sections/tools/managers/forum_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_forums')) { - error(403); + Error403::error(); } authorize(); @@ -14,7 +14,7 @@ authorize(); $forumMan = new Manager\Forum(); $forum = $forumMan->findById((int)($_POST['id'] ?? 0)); if (is_null($forum) && in_array($_POST['submit'], ['Edit', 'Delete'])) { - error('Unknown forum alter action'); + Error400::error('Unknown forum alter action'); } if ($_POST['submit'] == 'Delete') { $forum->remove(); @@ -23,7 +23,7 @@ if ($_POST['submit'] == 'Delete') { $minWrite = (int)$_POST['minclasswrite']; $minCreate = (int)$_POST['minclasscreate']; if ($Viewer->classLevel() < min($minRead, $minWrite, $minCreate)) { - error(403); + Error403::error(); } $validator = new Util\Validator(); @@ -37,7 +37,7 @@ if ($_POST['submit'] == 'Delete') { ['minclasscreate', true, 'number', 'MinClassCreate must be set'], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($_POST['submit'] == 'Create') { @@ -56,11 +56,11 @@ if ($_POST['submit'] == 'Delete') { } elseif ($_POST['submit'] == 'Edit') { $minClassRead = $forum->minClassRead(); if (!$minClassRead || $minClassRead > $Viewer->classLevel()) { - error(403); + Error403::error(); } $forum->modifyForum($_POST); } else { - error(403); + Error403::error(); } } header("Location: tools.php?action=forum"); diff --git a/sections/tools/managers/forum_list.php b/sections/tools/managers/forum_list.php index 73c426f90..d43efd79d 100644 --- a/sections/tools/managers/forum_list.php +++ b/sections/tools/managers/forum_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_forums')) { - error(403); + Error403::error(); } echo $Twig->render('admin/forum-management.twig', [ diff --git a/sections/tools/managers/forum_transitions_alter.php b/sections/tools/managers/forum_transitions_alter.php index 3e7a04a3b..15e9562da 100644 --- a/sections/tools/managers/forum_transitions_alter.php +++ b/sections/tools/managers/forum_transitions_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_forums')) { - error(403); + Error403::error(); } authorize(); @@ -15,7 +15,7 @@ $transition = $manager->findById((int)($_POST['id'] ?? 0)); if ($_POST['submit'] === 'Delete') { if (is_null($transition)) { - error(404); + Error404::error(); } $transition->remove(); } else { @@ -29,17 +29,17 @@ if ($_POST['submit'] === 'Delete') { $_POST = array_map('trim', $_POST); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } $forumMan = new Manager\Forum(); $source = $forumMan->findById((int)$_POST['source']); if (is_null($source)) { - error("no such source forum id: " . (int)$_POST['source']); + Error404::error("no such source forum id: " . (int)$_POST['source']); } $target = $forumMan->findById((int)$_POST['destination']); if (is_null($target)) { - error("no such target forum id: " . (int)$_POST['source']); + Error404::error("no such target forum id: " . (int)$_POST['source']); } if ($_POST['submit'] === 'Create') { @@ -54,7 +54,7 @@ if ($_POST['submit'] === 'Delete') { ); } elseif ($_POST['submit'] === 'Edit') { if (is_null($transition)) { - error(404); + Error404::error(); } $transition ->setField('source', $source->id()) diff --git a/sections/tools/managers/forum_transitions_list.php b/sections/tools/managers/forum_transitions_list.php index 4b78ff8ed..4fb02859d 100644 --- a/sections/tools/managers/forum_transitions_list.php +++ b/sections/tools/managers/forum_transitions_list.php @@ -1,14 +1,13 @@ permitted('admin_manage_forums')) { - error(403); + Error403::error(); } if (!isset($_REQUEST['userid'])) { @@ -16,7 +15,7 @@ if (!isset($_REQUEST['userid'])) { } else { $user = (new Manager\User())->find((int)$_REQUEST['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/tools/managers/global_notification.php b/sections/tools/managers/global_notification.php index b1441a188..da217bc07 100644 --- a/sections/tools/managers/global_notification.php +++ b/sections/tools/managers/global_notification.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_global_notification')) { - error(403); + Error403::error(); } $global = new Notification\GlobalNotification(); diff --git a/sections/tools/managers/invite_source.php b/sections/tools/managers/invite_source.php index c0e3c3cae..691fd1c97 100644 --- a/sections/tools/managers/invite_source.php +++ b/sections/tools/managers/invite_source.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_invite_source')) { - error(403); + Error403::error(); } $user = (new Manager\User())->find(trim($_POST['user'] ?? '')); diff --git a/sections/tools/managers/invite_source_config.php b/sections/tools/managers/invite_source_config.php index ce2fb5472..9368d8de8 100644 --- a/sections/tools/managers/invite_source_config.php +++ b/sections/tools/managers/invite_source_config.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_invite_source')) { - error(403); + Error403::error(); } $manager = new Manager\InviteSource(); diff --git a/sections/tools/managers/ip_search.php b/sections/tools/managers/ip_search.php index c85dbf97c..3e2b75297 100644 --- a/sections/tools/managers/ip_search.php +++ b/sections/tools/managers/ip_search.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $column = (int)($_POST['column'] ?? 3); diff --git a/sections/tools/managers/login_watch.php b/sections/tools/managers/login_watch.php index 6ee7ce300..750a22dcf 100644 --- a/sections/tools/managers/login_watch.php +++ b/sections/tools/managers/login_watch.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_login_watch', 'admin_manage_ipbans')) { - error(403); + Error403::error(); } if ($_POST) { diff --git a/sections/tools/managers/manipulate_tree.php b/sections/tools/managers/manipulate_tree.php index 55c588300..2d664eabb 100644 --- a/sections/tools/managers/manipulate_tree.php +++ b/sections/tools/managers/manipulate_tree.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('users_view_invites', 'users_disable_users', 'users_edit_invites', 'users_disable_any')) { - error(403); + Error403::error(); } $doComment = false; @@ -22,16 +22,16 @@ if (isset($_POST['id'])) { $doDisable = $action === 'disable'; $doInvites = $action === 'invites'; if (!($comment || $doDisable || $doInvites)) { - error("No maniplation action specified"); + Error400::error("No maniplation action specified"); } if (!$_POST['comment']) { - error('Please enter a comment to add to the users affected.'); + Error400::error('Please enter a comment to add to the users affected.'); } $userMan = new Manager\User(); $id = trim($_POST['id']); $user = $userMan->find($id); if (is_null($user)) { - error((int)$id + Error404::error((int)$id ? "No such user '{$_POST['id']}'" : "No such user '{$_POST['id']}', did you mean '@{$_POST['id']}'?" ); diff --git a/sections/tools/managers/mass_pm.php b/sections/tools/managers/mass_pm.php index 6d5277cf9..b2044fac9 100644 --- a/sections/tools/managers/mass_pm.php +++ b/sections/tools/managers/mass_pm.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted("admin_global_notification")) { - error(404); + Error404::error(); } echo $Twig->render('admin/mass-pm.twig', [ diff --git a/sections/tools/managers/navigation_alter.php b/sections/tools/managers/navigation_alter.php index c14d56490..1e16dafd3 100644 --- a/sections/tools/managers/navigation_alter.php +++ b/sections/tools/managers/navigation_alter.php @@ -8,7 +8,7 @@ namespace Gazelle; use Gazelle\Util\Arrays; if (!$Viewer->permitted('admin_manage_navigation')) { - error(403); + Error403::error(); } authorize(); @@ -19,7 +19,7 @@ if ($_POST['submit'] == 'Delete') { $id = (int)($_POST['id'] ?? 0); $control = $manager->findById($id); if (is_null($control)) { - error(404); + Error404::error(); } $control->remove(); } else { @@ -34,7 +34,7 @@ if ($_POST['submit'] == 'Delete') { ['default', true, 'checkbox', ''], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($_POST['submit'] == 'Create') { @@ -51,7 +51,7 @@ if ($_POST['submit'] == 'Delete') { $id = (int)($_POST['id'] ?? 0); $control = $manager->findById($id); if (is_null($control)) { - error(404); + Error404::error(); } $control->setField('tag', trim($_POST['tag'])) ->setField('target', trim($_POST['target'])) @@ -62,7 +62,7 @@ if ($_POST['submit'] == 'Delete') { ->setField('initial', $_POST['default'] == 'on') ->modify(); } else { - error('Unknown forum navigation action specified'); + Error400::error('Unknown forum navigation action specified'); } } diff --git a/sections/tools/managers/navigation_list.php b/sections/tools/managers/navigation_list.php index e17593e3e..d639aa2e7 100644 --- a/sections/tools/managers/navigation_list.php +++ b/sections/tools/managers/navigation_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_navigation')) { - error(403); + Error403::error(); } echo $Twig->render('admin/user-navigation.twig', [ diff --git a/sections/tools/managers/news.php b/sections/tools/managers/news.php index d7865f4d9..ab98f36a1 100644 --- a/sections/tools/managers/news.php +++ b/sections/tools/managers/news.php @@ -10,7 +10,7 @@ use Gazelle\Manager\Notification; use Gazelle\Enum\NotificationType; if (!$Viewer->permitted('admin_manage_news')) { - error(403); + Error403::error(); } $newsMan = new Manager\News(); @@ -39,7 +39,7 @@ switch ($_REQUEST['action']) { authorize(); $id = (int)$_REQUEST['id']; if (!$id) { - error('Unknown id for handle news item edit'); + Error400::error('Unknown id for handle news item edit'); } $newsMan->modify($id, $_POST['title'], $_POST['body']); header('Location: index.php'); @@ -48,7 +48,7 @@ switch ($_REQUEST['action']) { case 'editnews': $id = (int)$_REQUEST['id']; if (!$id) { - error('Unknown id for news item edit'); + Error400::error('Unknown id for news item edit'); } [$title, $body] = $newsMan->fetch($id); break; @@ -56,7 +56,7 @@ switch ($_REQUEST['action']) { case 'deletenews': $id = (int)$_REQUEST['id']; if (!$id) { - error('Unknown id for news item delete'); + Error400::error('Unknown id for news item delete'); } $newsMan->remove($id); header('Location: index.php'); @@ -67,7 +67,7 @@ switch ($_REQUEST['action']) { break; default: - error('Unknown news action'); + Error400::error('Unknown news action'); } echo $Twig->render('admin/news.twig', [ 'body' => new Util\Textarea('body', $body), diff --git a/sections/tools/managers/ocelot.php b/sections/tools/managers/ocelot.php index 7ad24b8df..e931abd58 100644 --- a/sections/tools/managers/ocelot.php +++ b/sections/tools/managers/ocelot.php @@ -14,7 +14,7 @@ if ( && isset($_GET['tokens']) ) ) { - error(403); + Error403::error(); } (new Tracker())->expireFreeleechTokens($_GET['tokens']); diff --git a/sections/tools/managers/ocelot_info.php b/sections/tools/managers/ocelot_info.php index 6dd4c5e60..4795ca31d 100644 --- a/sections/tools/managers/ocelot_info.php +++ b/sections/tools/managers/ocelot_info.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $tracker = new Tracker(); @@ -57,7 +57,7 @@ if (isset($_POST['interval'])) { $interval = (int)$_POST['interval']; if ($interval != $info['announce interval']['value']) { if ($interval < 600) { - error("Cowardly refusing to lower the announce interval below five minutes"); + Error400::error("Cowardly refusing to lower the announce interval below five minutes"); } $tracker->modifyAnnounceInterval($interval); $dirty = true; @@ -69,7 +69,7 @@ if (isset($_POST['jitter'])) { $jitter = (int)$_POST['jitter']; if ($jitter != $info['announce jitter']['value']) { if ($jitter < 0 || $jitter >= 3600) { - error("Cowardly refusing to set the jitter to an absurd value"); + Error400::error("Cowardly refusing to set the jitter to an absurd value"); } $tracker->modifyAnnounceJitter($jitter); $dirty = true; diff --git a/sections/tools/managers/privilege_matrix.php b/sections/tools/managers/privilege_matrix.php index 87a0b5062..ae1cd1271 100644 --- a/sections/tools/managers/privilege_matrix.php +++ b/sections/tools/managers/privilege_matrix.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_site_debug')) { - error(403); + Error403::error(); } echo $Twig->render('admin/privilege-matrix.twig', [ diff --git a/sections/tools/managers/quick_ban.php b/sections/tools/managers/quick_ban.php index 5c32ca2f2..eacdf37c7 100644 --- a/sections/tools/managers/quick_ban.php +++ b/sections/tools/managers/quick_ban.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_ipbans')) { - error(403); + Error403::error(); } if (isset($_GET['perform'])) { @@ -16,6 +16,6 @@ if (isset($_GET['perform'])) { } elseif ($_GET['perform'] == 'create') { $IPv4Man->createBan($Viewer, $_GET['ip'], $_GET['ip'], trim($_GET['notes'])); } else { - error(403); + Error403::error(); } } diff --git a/sections/tools/managers/rate_limit.php b/sections/tools/managers/rate_limit.php index 7070f196f..2e9906ed8 100644 --- a/sections/tools/managers/rate_limit.php +++ b/sections/tools/managers/rate_limit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_rate_limit_view', 'admin_rate_limit_manage')) { - error(403); + Error403::error(); } $limiter = new Manager\UserclassRateLimit(); @@ -24,11 +24,11 @@ if ($_POST) { ['overshoot', true, 'number', 'overshoot must be set', ['minlength' => 1]], ]); if (!$val->validate($_POST)) { - error($val->errorMessage()); + Error400::error($val->errorMessage()); } $limiter->save($_POST['class'], $_POST['factor'], $_POST['overshoot']); } else { - error(403); + Error403::error(); } } diff --git a/sections/tools/managers/reaper.php b/sections/tools/managers/reaper.php index 2b315ac3f..e1af2a9d4 100644 --- a/sections/tools/managers/reaper.php +++ b/sections/tools/managers/reaper.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_flow')) { - error(403); + Error403::error(); } $affected = false; diff --git a/sections/tools/managers/referral_accounts.php b/sections/tools/managers/referral_accounts.php index 020b99e25..567f87b8f 100644 --- a/sections/tools/managers/referral_accounts.php +++ b/sections/tools/managers/referral_accounts.php @@ -25,7 +25,7 @@ function type_list(array $Types, int $Selected = 0): string { /** @phpstan-var \Gazelle\User $Viewer */ if (!$Viewer->permitted('admin_manage_referrals')) { - error(403); + Error403::error(); } $ReferralManager = new Manager\Referral(); diff --git a/sections/tools/managers/referral_alter.php b/sections/tools/managers/referral_alter.php index bb0e603b2..d3d8debf8 100644 --- a/sections/tools/managers/referral_alter.php +++ b/sections/tools/managers/referral_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_referrals')) { - error(403); + Error403::error(); } authorize(); @@ -16,7 +16,7 @@ $ReferralManager = new Manager\Referral(); if ($_POST['submit'] == 'Delete') { $id = (int)$_POST['id']; if (!$id) { - error('No referral id for delete'); + Error400::error('No referral id for delete'); } $ReferralManager->deleteAccount($id); } else { @@ -29,7 +29,7 @@ if ($_POST['submit'] == 'Delete') { ['active', true, 'checkbox', ''], ]); if (!$Val->validate($_POST)) { - error($Val->errorMessage()); + Error400::error($Val->errorMessage()); } if (!str_ends_with($_POST['url'], '/')) { @@ -42,7 +42,7 @@ if ($_POST['submit'] == 'Delete') { } elseif ($_POST['submit'] === 'Edit') { $id = (int)$_POST['id']; if (!$ReferralManager->getAccount($id)) { - error('No referral id for edit'); + Error400::error('No referral id for edit'); } $ReferralManager->updateAccount($_POST['id'], $_POST['site'], $_POST['url'], $_POST['user'], diff --git a/sections/tools/managers/referral_users.php b/sections/tools/managers/referral_users.php index 6a597eaa4..2730c3cc1 100644 --- a/sections/tools/managers/referral_users.php +++ b/sections/tools/managers/referral_users.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_view_referrals')) { - error(403); + Error403::error(); } $ReferralManager = new Manager\Referral(); @@ -15,7 +15,7 @@ $ReferralManager = new Manager\Referral(); if (isset($_POST['id'])) { authorize(); if (!$Viewer->permitted('admin_manage_referrals')) { - error(403); + Error403::error(); } $ReferralManager->deleteUserReferral($_POST['id']); } diff --git a/sections/tools/managers/ssl_host.php b/sections/tools/managers/ssl_host.php index 5e00edadb..8da1967fa 100644 --- a/sections/tools/managers/ssl_host.php +++ b/sections/tools/managers/ssl_host.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $ssl = new Manager\SSLHost(); diff --git a/sections/tools/managers/staff_groups_alter.php b/sections/tools/managers/staff_groups_alter.php index 954ce3445..7bf558560 100644 --- a/sections/tools/managers/staff_groups_alter.php +++ b/sections/tools/managers/staff_groups_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } authorize(); @@ -15,7 +15,7 @@ $staffGroup = $manager->findById((int)($_POST['id'] ?? 0)); if ($_POST['submit'] == 'Delete') { if (is_null($staffGroup)) { - error('Staff Group not found for delete'); + Error404::error('Staff Group not found for delete'); } $staffGroup->remove(); } else { @@ -25,7 +25,7 @@ if ($_POST['submit'] == 'Delete') { ['name', true, 'string', 'Name must be set, and has a max length of 50 characters', ['maxlength' => 50]], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($_POST['submit'] == 'Edit') { diff --git a/sections/tools/managers/staff_groups_list.php b/sections/tools/managers/staff_groups_list.php index 37056ba45..0b70fec14 100644 --- a/sections/tools/managers/staff_groups_list.php +++ b/sections/tools/managers/staff_groups_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } echo $Twig->render('admin/staff-group.twig', [ diff --git a/sections/tools/managers/stylesheets_list.php b/sections/tools/managers/stylesheets_list.php index da6fe1374..710897b20 100644 --- a/sections/tools/managers/stylesheets_list.php +++ b/sections/tools/managers/stylesheets_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_stylesheets')) { - error(403); + Error403::error(); } $heading = new Util\SortableTableHeader('id', [ diff --git a/sections/tools/managers/tags.php b/sections/tools/managers/tags.php index 959148579..7180fcd73 100644 --- a/sections/tools/managers/tags.php +++ b/sections/tools/managers/tags.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $validator = new Util\Validator(); diff --git a/sections/tools/managers/tags_aliases.php b/sections/tools/managers/tags_aliases.php index a191c45cd..fb7d9e8b9 100644 --- a/sections/tools/managers/tags_aliases.php +++ b/sections/tools/managers/tags_aliases.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!($Viewer->permittedAny('users_mod', 'site_tag_aliases_read'))) { - error(403); + Error403::error(); } $isAdmin = $Viewer->permitted('users_mod'); diff --git a/sections/tools/managers/tags_official.php b/sections/tools/managers/tags_official.php index 9997d92d0..433e22931 100644 --- a/sections/tools/managers/tags_official.php +++ b/sections/tools/managers/tags_official.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $tagMan = new Manager\Tag(); @@ -19,7 +19,7 @@ if ($_POST['oldtags'] ?? null) { foreach ($_POST['oldtags'] as $tagId) { $tag = $tagMan->findById($tagId); if (is_null($tag)) { - error(403); + Error403::error(); } $unofficialId[] = $tag->id(); $unofficialName[] = $tag->name(); diff --git a/sections/tools/managers/take_mass_pm.php b/sections/tools/managers/take_mass_pm.php index 5ff699dd2..e9afa7b81 100644 --- a/sections/tools/managers/take_mass_pm.php +++ b/sections/tools/managers/take_mass_pm.php @@ -6,13 +6,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted("admin_global_notification")) { - error(403); + Error403::error(); } authorize(); if (!is_number($_POST['class_id']) || empty($_POST['subject']) || empty($_POST['body'])) { - error("Error in message form"); + Error400::error("Error in message form"); } set_time_limit(0); diff --git a/sections/tools/managers/tokens.php b/sections/tools/managers/tokens.php index 1c0111817..665fd0df9 100644 --- a/sections/tools/managers/tokens.php +++ b/sections/tools/managers/tokens.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); @@ -17,13 +17,13 @@ $flCleared = false; if (isset($_POST['addtokens'])) { authorize(); if ($amount < 1) { - error('Please enter a valid number of tokens.'); + Error400::error('Please enter a valid number of tokens.'); } $flAdded = $userMan->addMassTokens($amount, isset($_POST['allowleechdisabled'])); } elseif (isset($_POST['cleartokens'])) { authorize(); if ($amount < 0) { - error('Please enter a valid number of tokens.'); + Error400::error('Please enter a valid number of tokens.'); } $flCleared = $userMan->clearMassTokens($amount, isset($_POST['allowleechdisabled']), isset($_POST['onlydrop'])); } diff --git a/sections/tools/managers/tor_node.php b/sections/tools/managers/tor_node.php index 2b0e7a3ce..b72b8aaee 100644 --- a/sections/tools/managers/tor_node.php +++ b/sections/tools/managers/tor_node.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $tor = new Manager\Tor(); diff --git a/sections/tools/managers/torrent_report_edit.php b/sections/tools/managers/torrent_report_edit.php index 9e47cd923..b807663ee 100644 --- a/sections/tools/managers/torrent_report_edit.php +++ b/sections/tools/managers/torrent_report_edit.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $config = (new Manager\Torrent\ReportType())->findById((int)($_GET['id'] ?? 0)); if (is_null($config)) { - error(404); + Error404::error(); } if (isset($_POST['submit'])) { diff --git a/sections/tools/managers/torrent_report_view.php b/sections/tools/managers/torrent_report_view.php index ae3d5788e..49bad741f 100644 --- a/sections/tools/managers/torrent_report_view.php +++ b/sections/tools/managers/torrent_report_view.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } echo $Twig->render('admin/torrent-report-view.twig', [ diff --git a/sections/tools/managers/userclass_alter.php b/sections/tools/managers/userclass_alter.php index 33e544239..1a61850b4 100644 --- a/sections/tools/managers/userclass_alter.php +++ b/sections/tools/managers/userclass_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } $privMan = new Manager\Privilege(); @@ -15,7 +15,7 @@ $privilege = $privMan->findById((int)($_REQUEST['removeid'] ?? 0)); if ($privilege) { authorize(); if ($privilege->userTotal() > 0) { - error('You cannot delete a class with users.'); + Error400::error('You cannot delete a class with users.'); } $privilege->remove(); header("Location: tools.php?action=userclass"); @@ -34,7 +34,7 @@ if (isset($_REQUEST['submit'])) { ['level', true, 'number', 'You did not enter a valid level for this permission set.'], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($edit) { @@ -44,12 +44,12 @@ if (isset($_REQUEST['submit'])) { exit; } if (empty($_REQUEST['secondary']) == $privilege->isSecondary() && $privilege->userTotal() > 0) { - error("You can't toggle secondary when there are users"); + Error400::error("You can't toggle secondary when there are users"); } $check = $privMan->findByLevel((int)$_REQUEST['level']); if ($check && $privilege->id() != $check->id()) { - error('There is already a permission class with that level.'); + Error400::error('There is already a permission class with that level.'); } } diff --git a/sections/tools/managers/userclass_edit.php b/sections/tools/managers/userclass_edit.php index 4396b2464..09d2b3032 100644 --- a/sections/tools/managers/userclass_edit.php +++ b/sections/tools/managers/userclass_edit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } $privMan = new Manager\Privilege(); diff --git a/sections/tools/managers/userclass_list.php b/sections/tools/managers/userclass_list.php index 8d3f6bdb8..c904d2c1a 100644 --- a/sections/tools/managers/userclass_list.php +++ b/sections/tools/managers/userclass_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } if (isset($_REQUEST['id']) && $_REQUEST['id'] === 'new') { diff --git a/sections/tools/managers/whitelist_alter.php b/sections/tools/managers/whitelist_alter.php index 596ae9e57..703ea7869 100644 --- a/sections/tools/managers/whitelist_alter.php +++ b/sections/tools/managers/whitelist_alter.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_whitelist')) { - error(403); + Error403::error(); } authorize(); @@ -19,14 +19,14 @@ $submitAction = $_POST['submit'] ?? null; if ($submitAction === 'Delete') { $clientId = (int)$_POST['id']; if (!$clientId) { - error('Whitelist client id not found for delete'); + Error404::error('Whitelist client id not found for delete'); } $tracker->removeWhitelist($whitelist->peerId($clientId)); $whitelist->remove($clientId); } else { // Edit or Create if (empty($_POST['client']) || empty($_POST['peer_id'])) { - error('Whitelist client id not found for create/edit'); + Error404::error('Whitelist client id not found for create/edit'); } $peer = trim($_POST['peer_id']); $vstring = trim($_POST['client']); @@ -37,7 +37,7 @@ if ($submitAction === 'Delete') { } else { $clientId = (int)($_POST['id'] ?? 0); if (!$clientId) { - error('Whitelist client id not found for edit'); + Error404::error('Whitelist client id not found for edit'); } $tracker->modifyWhitelist(old: $whitelist->modify($clientId, $peer, $vstring), new: $peer); } diff --git a/sections/tools/managers/whitelist_list.php b/sections/tools/managers/whitelist_list.php index 3ba87b784..797a93e06 100644 --- a/sections/tools/managers/whitelist_list.php +++ b/sections/tools/managers/whitelist_list.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_whitelist')) { - error(403); + Error403::error(); } echo $Twig->render('admin/client-whitelist.twig', [ diff --git a/sections/tools/tools.php b/sections/tools/tools.php index 6635d9d80..24b844127 100644 --- a/sections/tools/tools.php +++ b/sections/tools/tools.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } /** @var \Gazelle\User $Viewer phpstan is dense */ diff --git a/sections/top10/history.php b/sections/top10/history.php index a6dcf8b42..aba86b46c 100644 --- a/sections/top10/history.php +++ b/sections/top10/history.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(404); + Error404::error(); } $isByDay = trim($_GET['datetype'] ?? 'day') == 'day'; @@ -19,7 +19,7 @@ if (empty($_GET['date'])) { } else { $date = trim($_GET['date']); if (!Util\Time::validDate($date . ' 00:00:00')) { - error('That does not look like a date'); + Error400::error('That does not look like a date'); } $list = (new Manager\Torrent())->topTenHistoryList($date, $isByDay); } diff --git a/sections/torrents/add_alias.php b/sections/torrents/add_alias.php index 119b68574..9bb0dab96 100644 --- a/sections/torrents/add_alias.php +++ b/sections/torrents/add_alias.php @@ -10,7 +10,7 @@ authorize(); $tgMan = new Manager\TGroup(); $tgroup = $tgMan->findById((int)$_POST['groupid']); if (is_null($tgroup)) { - error(404); + Error404::error(); } $count = $tgroup->addArtists( @@ -20,7 +20,7 @@ $count = $tgroup->addArtists( ); if ($count < 1) { - error("artist already added"); + Error400::error("artist already added"); } header('Location: ' . redirectUrl($tgroup->location())); diff --git a/sections/torrents/add_cover_art.php b/sections/torrents/add_cover_art.php index 0de5982cc..7afac2450 100644 --- a/sections/torrents/add_cover_art.php +++ b/sections/torrents/add_cover_art.php @@ -6,19 +6,19 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_edit_wiki')) { - error(403); + Error403::error(); } authorize(); $summaryList = $_POST['summary'] ?? []; $imageList = $_POST['image'] ?? []; if (count($imageList) != count($summaryList)) { - error('Missing an image or a summary'); + Error400::error('Missing an image or a summary'); } $tgroup = (new Manager\TGroup())->findById((int)($_POST['groupid'] ?? 0)); if (is_null($tgroup)) { - error(404); + Error404::error(); } $imgProxy = new Util\ImageProxy($Viewer); @@ -26,11 +26,11 @@ $imgProxy = new Util\ImageProxy($Viewer); foreach ($imageList as $n => $image) { $image = trim($image); if (!preg_match(IMAGE_REGEXP, $image)) { - error(display_str($image) . " does not look like a valid image url"); + Error400::error(html_escape($image) . " does not look like a valid image url"); } $banned = $imgProxy->badHost($image); if ($banned) { - error("Please rehost images from $banned elsewhere."); + Error400::error("Please rehost images from $banned elsewhere."); } $tgroup->addCoverArt($image, trim($summaryList[$n])); } diff --git a/sections/torrents/collector.php b/sections/torrents/collector.php index 7ba9766ea..e42a7c0d2 100644 --- a/sections/torrents/collector.php +++ b/sections/torrents/collector.php @@ -6,18 +6,18 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('zip_downloader')) { - error(403); + Error403::error(); } if (empty($_GET['title'])) { - error('Collector type not specified'); + Error400::error('Collector type not specified'); } $title = trim($_GET['title']); switch ($title) { case 'better': if ($Viewer->hashHmac('collector', $_GET['ids']) !== ($_GET['sig'] ?? '')) { - error('Better signature mismatch'); + Error400::error('Better signature mismatch'); } $ids = array_filter(explode(',', $_GET['ids'] ?? '0'), fn($id) => (int)$id > 0); break; @@ -25,7 +25,7 @@ switch ($title) { authorize(); $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $ids = (new User\Seedbox($user)) ->setSource($_GET['s'] ?? '') @@ -35,17 +35,17 @@ switch ($title) { $title = "$title-" . $user->username(); break; default: - error('Unknown collector type'); + Error400::error('Unknown collector type'); } if (!$ids) { - error('No groups found to collect'); + Error400::error('No groups found to collect'); } $collector = new Collector\TList($Viewer, new Manager\Torrent(), $title, 0); $collector->setList($ids); if (!$collector->prepare([])) { - error("Nothing to gather, choose some encodings and media!"); + Error403::error("Nothing to gather, choose some encodings and media!"); } $collector->emitZip(Util\Zip::make($title)); diff --git a/sections/torrents/delete.php b/sections/torrents/delete.php index 35d6ffb79..f4a4894a0 100644 --- a/sections/torrents/delete.php +++ b/sections/torrents/delete.php @@ -14,28 +14,38 @@ $reportTypeMan = new Manager\Torrent\ReportType(); $torrent = $torMan->findById((int)($_GET['torrentid'] ?? 0)); if (is_null($torrent)) { - error('This torrent has already been deleted.'); + Error400::error('This torrent has already been deleted.'); } if ($torrent->hasUploadLock()) { - error('Torrent cannot be deleted because the upload process is not completed yet. Please try again later.'); + Error400::error( + 'Torrent cannot be deleted because the upload process is not completed yet. Please try again later.' + ); } if ($Viewer->id() != $torrent->uploaderId() && !$Viewer->permitted('torrents_delete')) { - error(403); + Error403::error(); } if ($Viewer->torrentRecentRemoveCount(USER_TORRENT_DELETE_HOURS) >= USER_TORRENT_DELETE_MAX && !$Viewer->permitted('torrents_delete_fast')) { - error('You have recently deleted ' . USER_TORRENT_DELETE_MAX - . ' torrents. Please contact a staff member if you need to delete more.'); + Error400::error( + 'You have recently deleted ' . USER_TORRENT_DELETE_MAX + . ' torrents. Please contact a staff member if you need to delete more.' + ); } -if (Time::timeAgo($torrent->created()) > 3600 * 24 * 7 && !$Viewer->permitted('torrents_delete')) { // Should this be torrents_delete or torrents_delete_fast? - error('You can no longer delete this torrent as it has been uploaded for over a week. If you now think there is a problem, please report the torrent instead.'); +if (Time::timeAgo($torrent->created()) > 3600 * 24 * 7 && !$Viewer->permitted('torrents_delete')) { + // Should this be torrents_delete or torrents_delete_fast? + Error400::error( + 'You can no longer delete this torrent as it has been uploaded for over a week. If you now think there is a problem, please report the torrent instead.' + ); } -if ($torrent->snatchTotal() >= 5 && !$Viewer->permitted('torrents_delete')) { // Should this be torrents_delete or torrents_delete_fast? - error('You can no longer delete this torrent as it has been snatched by 5 or more users. If you believe there is a problem with this torrent, please report it instead.'); +if ($torrent->snatchTotal() >= 5 && !$Viewer->permitted('torrents_delete')) { + // Should this be torrents_delete or torrents_delete_fast? + Error400::error( + 'You can no longer delete this torrent as it has been snatched by 5 or more users. If you believe there is a problem with this torrent, please report it instead.' + ); } echo $Twig->render('torrent/remove.twig', [ diff --git a/sections/torrents/delete_alias.php b/sections/torrents/delete_alias.php index c814906f0..99ade751e 100644 --- a/sections/torrents/delete_alias.php +++ b/sections/torrents/delete_alias.php @@ -7,21 +7,21 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $role = (int)$_GET['importance']; if (!$role) { - error('No role specified to delete'); + Error400::error('No role specified to delete'); } $tgMan = new Manager\TGroup(); $tgroup = $tgMan->findById((int)$_GET['groupid']); if (is_null($tgroup)) { - error(404); + Error404::error(); } $artist = (new Manager\Artist())->findByAliasId((int)$_GET['aliasid']); if (is_null($artist)) { - error(404); + Error404::error(); } // save data in case removeArtist() deletes the artist diff --git a/sections/torrents/delete_handle.php b/sections/torrents/delete_handle.php index 2e4a54e08..88464a65a 100644 --- a/sections/torrents/delete_handle.php +++ b/sections/torrents/delete_handle.php @@ -10,20 +10,24 @@ authorize(); $torrent = (new Manager\Torrent())->setViewer($Viewer)->findById((int)$_POST['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $torrentId = $torrent->id(); $uploader = $torrent->uploader(); if ($Viewer->id() != $uploader->id() && !$Viewer->permitted('torrents_delete')) { - error(403); + Error403::error(); } if ($Viewer->torrentRecentRemoveCount(USER_TORRENT_DELETE_HOURS) >= USER_TORRENT_DELETE_MAX && !$Viewer->permitted('torrents_delete_fast')) { - error('You have recently deleted ' . USER_TORRENT_DELETE_MAX - . ' torrents. Please contact a staff member if you need to delete more.'); + Error400::error( + 'You have recently deleted ' . USER_TORRENT_DELETE_MAX + . ' torrents. Please contact a staff member if you need to delete more.' + ); } if ($torrent->hasUploadLock()) { - error('Torrent cannot be deleted because the upload process is not completed yet. Please try again later.'); + Error400::error( + 'Torrent cannot be deleted because the upload process is not completed yet. Please try again later.' + ); } $fullName = $torrent->fullName(); @@ -34,7 +38,7 @@ $reason = implode(' ', array_map('trim', [$_POST['reason'], $_POST['extra']])) [$success, $message] = $torrent->remove($Viewer, $reason); if (!$success) { - error($message); + Error400::error($message); } (new Manager\User())->sendRemovalPm( diff --git a/sections/torrents/details.php b/sections/torrents/details.php index 641068a0b..2cbfc3178 100644 --- a/sections/torrents/details.php +++ b/sections/torrents/details.php @@ -16,7 +16,7 @@ header('Access-Control-Allow-Origin: *'); $tgMan = (new Manager\TGroup())->setViewer($Viewer); $tgroup = $tgMan->findById((int)($_GET['id'] ?? 0)); if (is_null($tgroup)) { - error(404); + Error404::error(); } $tgroupId = $tgroup->id(); $RevisionID = (int)($_GET['revisionid'] ?? 0); diff --git a/sections/torrents/downloadlist.php b/sections/torrents/downloadlist.php index 68c50f22e..7ee721699 100644 --- a/sections/torrents/downloadlist.php +++ b/sections/torrents/downloadlist.php @@ -7,11 +7,11 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_torrent_snatchlist')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1)); diff --git a/sections/torrents/edit.php b/sections/torrents/edit.php index 0d04f6eea..841d886c2 100644 --- a/sections/torrents/edit.php +++ b/sections/torrents/edit.php @@ -10,11 +10,11 @@ namespace Gazelle; $torrent = (new Manager\Torrent())->findById((int)($_GET['id'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } if (($Viewer->id() != $torrent->uploaderId() && !$Viewer->permitted('torrents_edit')) || $Viewer->disableWiki()) { - error(403); + Error403::error(); } $tgroup = $torrent->group(); diff --git a/sections/torrents/edit_category_handle.php b/sections/torrents/edit_category_handle.php index 5898a189c..6bd0141e0 100644 --- a/sections/torrents/edit_category_handle.php +++ b/sections/torrents/edit_category_handle.php @@ -6,33 +6,33 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } authorize(); $torrent = (new Manager\Torrent())->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error('Torrent does not exist!'); + Error404::error('Torrent does not exist!'); } $tgMan = new Manager\TGroup(); $old = $tgMan->findById((int)($_POST['oldgroupid'] ?? 0)); if (is_null($old)) { - error('The source torrent group does not exist!'); + Error404::error('The source torrent group does not exist!'); } $title = trim($_POST['title'] ?? ''); if ($title === '') { - error('Title cannot be blank'); + Error400::error('Title cannot be blank'); } $newCategoryId = (int)($_POST['newcategoryid'] ?? 0); $newName = (new Manager\Category())->findNameById($newCategoryId); if (!$newName) { - error('Bad category'); + Error400::error('Bad category'); } elseif ($newName === $old->categoryName()) { - error("Cannot change category to same category ({$newName})"); + Error400::error("Cannot change category to same category ({$newName})"); } $new = $tgMan->changeCategory( @@ -46,8 +46,8 @@ $new = $tgMan->changeCategory( artistMan: new Manager\Artist(), user: $Viewer, ); - if (is_null($new)) { - error("Unable to change category to $newName"); + Error400::error("Unable to change category to $newName"); } + header('Location: ' . $new->location()); diff --git a/sections/torrents/edit_group.php b/sections/torrents/edit_group.php index b11168839..7e167db94 100644 --- a/sections/torrents/edit_group.php +++ b/sections/torrents/edit_group.php @@ -6,9 +6,12 @@ declare(strict_types=1); namespace Gazelle; +if (!$Viewer->permitted('site_edit_wiki')) { + Error403::error(); +} $tgroup = (new Manager\TGroup())->findById((int)($_GET['id'] ?? 0)); if (is_null($tgroup)) { - error(404); + Error404::error(); } $torMan = new Manager\Torrent(); diff --git a/sections/torrents/edit_group_handle.php b/sections/torrents/edit_group_handle.php index 868e2834d..4dd877ed5 100644 --- a/sections/torrents/edit_group_handle.php +++ b/sections/torrents/edit_group_handle.php @@ -9,14 +9,14 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_edit_wiki')) { - error(403); + Error403::error(); } if (!$Viewer->permitted('torrents_edit_vanityhouse') && isset($_POST['vanity_house'])) { - error(403); + Error403::error(); } $tgroup = (new Manager\TGroup())->findById((int)$_REQUEST['groupid']); if (is_null($tgroup)) { - error(404); + Error404::error(); } $logInfo = []; @@ -24,7 +24,7 @@ if (($_GET['action'] ?? '') == 'revert') { // we're reverting to a previous revision $revisionId = (int)$_GET['revisionid']; if (!$revisionId) { - error('No revision specified to revert'); + Error400::error('No revision specified to revert'); } if (empty($_GET['confirm'])) { echo $Twig->render('tgroup/confirm-revert.twig', [ @@ -36,7 +36,7 @@ if (($_GET['action'] ?? '') == 'revert') { } $revert = $tgroup->revertRevision($Viewer->id(), $revisionId); if (is_null($revert)) { - error(404); + Error404::error(); } [$Body, $Image] = $revert; } else { @@ -46,7 +46,7 @@ if (($_GET['action'] ?? '') == 'revert') { $rt = new ReleaseType(); $newReleaseTypeName = $rt->findNameById($ReleaseType); if (!$newReleaseTypeName) { - error(403); + Error400::error(); } if ($ReleaseType != $tgroup->releaseType()) { $tgroup->setField('ReleaseType', $ReleaseType); @@ -69,11 +69,11 @@ if (($_GET['action'] ?? '') == 'revert') { } else { $Image = $_POST['image']; if (!preg_match(IMAGE_REGEXP, $Image)) { - error(display_str($Image) . " does not look like a valid image url"); + Error400::error(html_escape($Image) . " does not look like a valid image url"); } $banned = (new Util\ImageProxy($Viewer))->badHost($Image); if ($banned) { - error("Please rehost images from $banned elsewhere."); + Error400::error("Please rehost images from $banned elsewhere."); } } diff --git a/sections/torrents/edit_handle.php b/sections/torrents/edit_handle.php index b1af115b1..d6dddaa06 100644 --- a/sections/torrents/edit_handle.php +++ b/sections/torrents/edit_handle.php @@ -16,7 +16,7 @@ authorize(); $torMan = new Manager\Torrent(); $torrent = $torMan->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $Remastered = $torrent->isRemastered(); $RemasterYear = $torrent->remasterYear(); @@ -24,7 +24,7 @@ $TorrentID = $torrent->id(); $UserID = $torrent->uploaderId(); if ($Viewer->id() != $UserID && !$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } //******************************************************************************// @@ -69,11 +69,11 @@ foreach (TorrentFlag::cases() as $flag) { if (!$Viewer->permitted('edit_unknowns')) { if ($Remastered && !$RemasterYear) { - error("You must supply a remaster year for a remastered release"); + Error400::error("You must supply a remaster year for a remastered release"); } if ($Properties['UnknownRelease'] && !($Remastered && !$RemasterYear)) { /** @phpstan-ignore-line *//* wtf is this logic */ if ($Viewer->id() != $UserID) { - error("You cannot set a release to be Unknown"); + Error400::error("You cannot set a release to be Unknown"); } } if ($Viewer->id() !== $UserID && $Properties['Remastered'] && !$Properties['RemasterYear']) { @@ -86,10 +86,12 @@ $Validate->setField('type', true, 'number', 'Not a valid category.', ['range' => switch (CATEGORY[(int)($_POST['type'] ?? 0) - 1]) { case 'Music': if ($Properties['Remastered'] && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] == 'CD') { - error('You have selected a year for an album that predates the medium you say it was created on.'); + Error400::error( + 'You have selected a year for an album that predates the medium you say it was created on.' + ); } if ($Properties['RemasterTitle'] == 'Original Release') { - error('"Original Release" is not a valid remaster title.'); + Error400::error('"Original Release" is not a valid remaster title.'); } $Validate->setFields([ @@ -156,7 +158,7 @@ if (!$Err && isset($Properties['Image'])) { /** @phpstan-ignore-line */ } if ($Err) { - error($Err); + Error400::error($Err); } $propertyMap = [ @@ -176,7 +178,7 @@ $change = []; foreach ($propertyMap as $field => $method) { if (!method_exists($torrent, $method)) { $Debug->saveCase("bad method $method in torrent edit id={$torrent->id()}"); - error('Cannot proceed with torrent edit'); + Error400::error('Cannot proceed with torrent edit'); } $value = $torrent->$method(); if (isset($Properties[$field])) { diff --git a/sections/torrents/edit_log.php b/sections/torrents/edit_log.php index 6851ac26a..d79593c1a 100644 --- a/sections/torrents/edit_log.php +++ b/sections/torrents/edit_log.php @@ -7,16 +7,16 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)($_GET['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $tlog = (new Manager\TorrentLog(new File\RipLog(), new File\RipLogHTML()))->findById($torrent, (int)($_GET['logid'] ?? 0)); if (is_null($tlog)) { - error(404); + Error404::error(); } echo $Twig->render('torrent/edit-log.twig', [ diff --git a/sections/torrents/edit_log_handle.php b/sections/torrents/edit_log_handle.php index 959c64bb8..ec3c75ae9 100644 --- a/sections/torrents/edit_log_handle.php +++ b/sections/torrents/edit_log_handle.php @@ -6,16 +6,16 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $LogID = (int)($_POST['logid'] ?? 0); if (!$LogID) { - error(404); + Error404::error(); } $torrent = (new Manager\Torrent())->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $adjusted = false; diff --git a/sections/torrents/edit_request.php b/sections/torrents/edit_request.php index 0f7d4f624..5a000f96c 100644 --- a/sections/torrents/edit_request.php +++ b/sections/torrents/edit_request.php @@ -8,7 +8,7 @@ namespace Gazelle; $tgroup = (new Manager\TGroup())->findById((int)($_GET['id'] ?? 0)); if (!$tgroup) { - error(404); + Error404::error(); } echo $Twig->render('torrent/edit-request.twig', [ diff --git a/sections/torrents/edit_request_handle.php b/sections/torrents/edit_request_handle.php index 8134c1195..918f29dad 100644 --- a/sections/torrents/edit_request_handle.php +++ b/sections/torrents/edit_request_handle.php @@ -8,7 +8,7 @@ namespace Gazelle; $tgroup = (new Manager\TGroup())->findById((int)($_POST['id'] ?? 0)); if (!$tgroup) { - error(404); + Error404::error(); } authorize(); diff --git a/sections/torrents/grouplog.php b/sections/torrents/grouplog.php index 1d90e4348..ed8f63bc4 100644 --- a/sections/torrents/grouplog.php +++ b/sections/torrents/grouplog.php @@ -9,7 +9,7 @@ $tgroupId = (int)($_GET['id'] ?? 0); if (!$tgroupId) { // we may not have a torrent group because it has already been merged elsewhere // so the best we can hope for is something that looks like a positive integer - error(404); + Error404::error(); } $tgroup = (new Manager\TGroup())->findById($tgroupId); diff --git a/sections/torrents/history.php b/sections/torrents/history.php index 92195771f..af6f67867 100644 --- a/sections/torrents/history.php +++ b/sections/torrents/history.php @@ -7,7 +7,7 @@ namespace Gazelle; $group = (new Manager\TGroup())->findById((int)($_GET['id'] ?? 0)); if (is_null($group)) { - error(404); + Error404::error(); } echo $Twig->render('revision.twig', ['object' => $group]); diff --git a/sections/torrents/log_ajax.php b/sections/torrents/log_ajax.php index 8e26395f5..5fca163cc 100644 --- a/sections/torrents/log_ajax.php +++ b/sections/torrents/log_ajax.php @@ -12,7 +12,7 @@ if (is_null($torrent)) { $torrent = $torMan->findDeletedById((int)$_GET['torrentid']); } if (is_null($torrent)) { - error(404); + Error404::error(); } echo $Twig->render('torrent/riplog.twig', [ diff --git a/sections/torrents/manage_artists.php b/sections/torrents/manage_artists.php index 4dc6f8489..4bd459d7a 100644 --- a/sections/torrents/manage_artists.php +++ b/sections/torrents/manage_artists.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } authorize(); @@ -19,12 +19,12 @@ foreach (explode(',', $_POST['artists'] ?? '') as $roleAliasId) { } } if (!$roleAliasList) { - error('No artists to manage'); + Error400::error('No artists to manage'); } $tgroup = (new Manager\TGroup())->findById((int)($_POST['groupid'] ?? 0)); if (is_null($tgroup)) { - error(404); + Error404::error(); } if (($_POST['manager_action'] ?? '') == 'delete') { @@ -32,7 +32,7 @@ if (($_POST['manager_action'] ?? '') == 'delete') { } else { $newRole = (int)($_POST['importance'] ?? 0); if ($newRole === 0 || !isset(ARTIST_TYPE[$newRole])) { - error('Unknown new artist role'); + Error400::error('Unknown new artist role'); } $tgroup->artistRole()->modifyList($roleAliasList, $newRole, $Viewer); } diff --git a/sections/torrents/masspm.php b/sections/torrents/masspm.php index bb4c3c15a..5886f5f9c 100644 --- a/sections/torrents/masspm.php +++ b/sections/torrents/masspm.php @@ -7,11 +7,11 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_moderate_requests')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } echo $Twig->render('torrent/masspm.twig', [ diff --git a/sections/torrents/masspm_handle.php b/sections/torrents/masspm_handle.php index aab91e49e..76490420f 100644 --- a/sections/torrents/masspm_handle.php +++ b/sections/torrents/masspm_handle.php @@ -8,11 +8,11 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('site_moderate_requests')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_POST['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $subject = trim($_POST['subject']); @@ -24,7 +24,7 @@ $validator->setFields([ ['message', false, 'string', 'Invalid message.', ['maxlength' => 10000]], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } (new Manager\User())->sendSnatchPm($Viewer, $torrent, $subject, $message); diff --git a/sections/torrents/merge.php b/sections/torrents/merge.php index 3698f53e9..1873e67f5 100644 --- a/sections/torrents/merge.php +++ b/sections/torrents/merge.php @@ -7,23 +7,23 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $tgMan = new Manager\TGroup(); $old = $tgMan->findById((int)($_POST['groupid'] ?? 0)); if (is_null($old)) { - error(404); + Error404::error(); } $new = $tgMan->findById((int)($_POST['targetgroupid'] ?? 0)); if (is_null($new)) { - error('Target group does not exist.'); + Error400::error('Target group does not exist.'); } if ($new->id() === $old->id()) { - error('Old group ID is the same as new group ID!'); + Error400::error('Old group ID is the same as new group ID!'); } if ($old->categoryName() !== 'Music') { - error('Only music groups can be merged.'); + Error400::error('Only music groups can be merged.'); } // Everything is legit, ask for confirmation diff --git a/sections/torrents/new_group_handle.php b/sections/torrents/new_group_handle.php index 3d19aa910..66b6f8612 100644 --- a/sections/torrents/new_group_handle.php +++ b/sections/torrents/new_group_handle.php @@ -14,19 +14,19 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $artistName = trim($_POST['artist']); $title = trim($_POST['title']); $year = (int)$_POST['year']; if (!$year || empty($title) || empty($artistName)) { - error('Missing parameters to set up new group'); + Error400::error('Missing parameters to set up new group'); } $torrent = (new Manager\Torrent())->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error('Torrent does not exist!'); + Error400::error('Torrent does not exist!'); } // double check diff --git a/sections/torrents/new_groupid.php b/sections/torrents/new_groupid.php index e2d38998a..6c15f79c8 100644 --- a/sections/torrents/new_groupid.php +++ b/sections/torrents/new_groupid.php @@ -9,21 +9,21 @@ namespace Gazelle; /* Move a torrent from one group to another */ if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)($_POST['torrentid'] ?? 0)); if (is_null($torrent)) { - error('Torrent does not exist!'); + Error404::error('Torrent does not exist!'); } $tgMan = new Manager\TGroup(); $new = $tgMan->findById((int)($_POST['groupid'] ?? 0)); if (is_null($new)) { - error('The destination torrent group does not exist!'); + Error404::error('The destination torrent group does not exist!'); } if ($new->categoryName() !== 'Music') { - error('Destination torrent group must be in the "Music" category.'); + Error400::error('Destination torrent group must be in the "Music" category.'); } if ($torrent->groupId() === $new->id()) { diff --git a/sections/torrents/nonwikiedit.php b/sections/torrents/nonwikiedit.php index ddcd2b627..06024ba4b 100644 --- a/sections/torrents/nonwikiedit.php +++ b/sections/torrents/nonwikiedit.php @@ -13,11 +13,10 @@ authorize(); $tgMan = new Manager\TGroup(); $tgroup = $tgMan->findById((int)($_POST['groupid'])); if (is_null($tgroup)) { - error(404); + Error404::error(); } - if (!$tgroup->canEdit($Viewer)) { - error(403); + Error403::error(); } $log = []; diff --git a/sections/torrents/notify.php b/sections/torrents/notify.php index 1efddeaa1..bbbb19063 100644 --- a/sections/torrents/notify.php +++ b/sections/torrents/notify.php @@ -11,13 +11,13 @@ namespace Gazelle; use Gazelle\Util\SortableTableHeader; if (!$Viewer->permitted('site_torrents_notify')) { - error(403); + Error403::error(); } if ($Viewer->permitted('users_mod') && (int)($_GET['userid'] ?? 0)) { $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } else { $user = $Viewer; diff --git a/sections/torrents/notify_actions.php b/sections/torrents/notify_actions.php index f4c820621..fbaa054f8 100644 --- a/sections/torrents/notify_actions.php +++ b/sections/torrents/notify_actions.php @@ -17,7 +17,7 @@ switch ($_GET['action']) { case 'notify_catchup_filter': $filterId = (int)$_GET['filterid']; if (!$filterId) { - error('Notification filter not found for catch up'); + Error404::error('Notification filter not found for catch up'); } $notifier->catchupFilter($filterId); header('Location: torrents.php?action=notify'); @@ -31,7 +31,7 @@ switch ($_GET['action']) { case 'notify_clear_filter': $filterId = (int)$_GET['filterid']; if (!$filterId) { - error('Notification filter not found for clear'); + Error404::error('Notification filter not found for clear'); } $notifier->clearFilter($filterId); header('Location: torrents.php?action=notify'); @@ -40,7 +40,7 @@ switch ($_GET['action']) { case 'notify_clear_item': $torrentId = (int)$_GET['torrentid']; if (!$torrentId) { - error('Torrent id not found for clear'); + Error404::error('Torrent id not found for clear'); } $notifier->clearTorrentList([$torrentId]); break; @@ -50,10 +50,10 @@ switch ($_GET['action']) { fn($n) => (int)$n, explode(',', $_GET['torrentids'] ?? '') )); if (!$cleared) { - error('Unable to clear marked torrents'); + Error400::error('Unable to clear marked torrents'); } break; default: - error('Unknown notification action'); + Error400::error('Unknown notification action'); } diff --git a/sections/torrents/peerlist.php b/sections/torrents/peerlist.php index eccb61c11..f6def9bf3 100644 --- a/sections/torrents/peerlist.php +++ b/sections/torrents/peerlist.php @@ -8,7 +8,7 @@ namespace Gazelle; $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1)); diff --git a/sections/torrents/redownload.php b/sections/torrents/redownload.php index ecb9cefd9..edeb973eb 100644 --- a/sections/torrents/redownload.php +++ b/sections/torrents/redownload.php @@ -8,32 +8,32 @@ namespace Gazelle; use Gazelle\Enum\UserTorrentSearch; if (!$Viewer->permitted('zip_downloader')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() != $Viewer->id() && !$Viewer->isStaff()) { - error(403); + Error403::error(); } switch ($_GET['type']) { case 'seeding': if (!$user->propertyVisible($Viewer, 'seeding')) { - error(403); + Error403::error(); } $userTorrent = new Search\UserTorrent($user, UserTorrentSearch::seeding); break; case 'snatches': if (!$user->propertyVisible($Viewer, 'snatched')) { - error(403); + Error403::error(); } $userTorrent = new Search\UserTorrent($user, UserTorrentSearch::snatched); break; default: if (!$user->propertyVisible($Viewer, 'uploads')) { - error(403); + Error403::error(); } $userTorrent = new Search\UserTorrent($user, UserTorrentSearch::uploaded); break; diff --git a/sections/torrents/regen.php b/sections/torrents/regen.php index a2410a824..39103b99f 100644 --- a/sections/torrents/regen.php +++ b/sections/torrents/regen.php @@ -6,12 +6,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)($_REQUEST['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $torrent->regenerateFilelist( new File\Torrent(), diff --git a/sections/torrents/remove_log.php b/sections/torrents/remove_log.php index adfa39d35..571841e65 100644 --- a/sections/torrents/remove_log.php +++ b/sections/torrents/remove_log.php @@ -7,13 +7,13 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); $logId = (int)$_GET['logid']; if (is_null($torrent) || !$logId) { - error(404); + Error404::error(); } (new File\RipLog())->remove([$torrent->id(), $logId]); diff --git a/sections/torrents/remove_logs.php b/sections/torrents/remove_logs.php index f9d531dbe..7b172cfe5 100644 --- a/sections/torrents/remove_logs.php +++ b/sections/torrents/remove_logs.php @@ -7,12 +7,12 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('torrents_delete')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)($_GET['torrentid'] ?? 0)); if (is_null($torrent)) { - error(404); + Error404::error(); } $torrent->removeAllLogs( diff --git a/sections/torrents/rename.php b/sections/torrents/rename.php index 7bc098ea5..cd4c04f1e 100644 --- a/sections/torrents/rename.php +++ b/sections/torrents/rename.php @@ -8,18 +8,18 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('torrents_edit')) { - error(403); + Error403::error(); } $name = trim($_POST['name'] ?? ''); if (empty($name)) { - error('Torrent groups must have a name'); + Error400::error('Torrent groups must have a name'); } $tgMan = new \Gazelle\Manager\TGroup(); $tgroup = $tgMan->findById((int)($_POST['groupid'] ?? 0)); if (is_null($tgroup)) { - error(404); + Error404::error(); } $tgroup->rename($name); diff --git a/sections/torrents/rescore_log.php b/sections/torrents/rescore_log.php index 664f378fb..bb1c40a33 100644 --- a/sections/torrents/rescore_log.php +++ b/sections/torrents/rescore_log.php @@ -8,13 +8,13 @@ namespace Gazelle; use OrpheusNET\Logchecker\Logchecker; if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); $logId = (int)$_GET['logid']; if (is_null($torrent) || !$logId) { - error(404); + Error404::error(); } $logpath = (new File\RipLog())->path([$torrent->id(), $logId]); diff --git a/sections/torrents/reseed.php b/sections/torrents/reseed.php index 8da8e45ea..d4f854f23 100644 --- a/sections/torrents/reseed.php +++ b/sections/torrents/reseed.php @@ -8,14 +8,22 @@ namespace Gazelle; $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } if (!$Viewer->permitted('users_mod')) { match (true) { - is_null($torrent->lastActiveDate()) && !is_null($torrent->lastReseedRequestDate()) => error('There was already a re-seed request for this torrent within the past ' . RESEED_NEVER_ACTIVE_TORRENT . ' days.'), - !is_null($torrent->lastReseedRequestDate()) => error('There was already a re-seed request for this torrent within the past ' . RESEED_TORRENT . ' days.'), - default => false, + is_null($torrent->lastActiveDate()) && !is_null($torrent->lastReseedRequestDate()) + => Error400::error( + 'There was already a re-seed request for this torrent within the past ' + . RESEED_NEVER_ACTIVE_TORRENT . ' days.' + ), + !is_null($torrent->lastReseedRequestDate()) + => Error400::error( + 'There was already a re-seed request for this torrent within the past ' + . RESEED_TORRENT . ' days.' + ), + default => false, }; } diff --git a/sections/torrents/snatchlist.php b/sections/torrents/snatchlist.php index 28d7cb1d6..56bf31dbf 100644 --- a/sections/torrents/snatchlist.php +++ b/sections/torrents/snatchlist.php @@ -7,11 +7,11 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_view_torrent_snatchlist')) { - error(403); + Error403::error(); } $torrent = (new Manager\Torrent())->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1)); diff --git a/sections/torrents/user.php b/sections/torrents/user.php index 352867927..af2788ba5 100644 --- a/sections/torrents/user.php +++ b/sections/torrents/user.php @@ -19,7 +19,7 @@ if ($_GET['userid'] == 'me') { } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $userId = $user->id(); @@ -172,7 +172,7 @@ if (!empty($_GET['tags'])) { switch ($_GET['type']) { case 'snatched': if (!$user->propertyVisible($Viewer, 'snatched')) { - error(403); + Error403::error(); } $join = "INNER JOIN xbt_snatched AS xs ON (xs.fid = t.ID)"; $time = 'xs.tstamp'; @@ -180,7 +180,7 @@ switch ($_GET['type']) { break; case 'snatched-unseeded': if (!$user->propertyVisible($Viewer, 'snatched')) { - error(403); + Error403::error(); } $join = "INNER JOIN xbt_snatched AS xs ON (xs.fid = t.ID) LEFT JOIN xbt_files_users AS xfu USING (uid, fid)"; @@ -190,7 +190,7 @@ switch ($_GET['type']) { break; case 'seeding': if (!$user->propertyVisible($Viewer, 'seeding')) { - error(403); + Error403::error(); } $join = "INNER JOIN xbt_files_users AS xfu ON (xfu.fid = t.ID)"; $cond[] = 'xfu.active = 1 AND xfu.Remaining = 0'; @@ -199,7 +199,7 @@ switch ($_GET['type']) { break; case 'leeching': if (!$user->propertyVisible($Viewer, 'leeching')) { - error(403); + Error403::error(); } $join = "INNER JOIN xbt_files_users AS xfu ON (xfu.fid = t.ID)"; $cond[] = 'xfu.active = 1 AND xfu.Remaining > 0'; @@ -208,7 +208,7 @@ switch ($_GET['type']) { break; case 'uploaded': if ((empty($_GET['filter']) || $_GET['filter'] !== 'perfectflac') && !$user->propertyVisible($Viewer, 'uploads')) { - error(403); + Error403::error(); } $join = ""; $time = 'unix_timestamp(t.created)'; @@ -216,7 +216,7 @@ switch ($_GET['type']) { break; case 'uploaded-unseeded': if ((empty($_GET['filter']) || $_GET['filter'] !== 'perfectflac') && !$user->propertyVisible($Viewer, 'uploads')) { - error(403); + Error403::error(); } $join = "LEFT JOIN xbt_files_users AS xfu ON (xfu.fid = t.ID AND xfu.uid = t.UserID)"; $cond[] = 'xfu.fid IS NULL'; @@ -225,20 +225,20 @@ switch ($_GET['type']) { break; case 'downloaded': if (!($userId === $Viewer->id() || $Viewer->permitted('site_view_torrent_snatchlist'))) { - error(403); + Error403::error(); } $join = "INNER JOIN users_downloads AS ud ON (ud.TorrentID = t.ID)"; $time = 'unix_timestamp(ud.Time)'; $userField = 'ud.UserID'; break; default: - error(404); + Error404::error(); } if (!empty($_GET['filter'])) { if ($_GET['filter'] === 'perfectflac') { if (!$user->propertyVisible($Viewer, 'perfectflacs')) { - error(403); + Error403::error(); } $cond[] = "t.Format = ?"; $args[] = 'FLAC'; @@ -250,7 +250,7 @@ if (!empty($_GET['filter'])) { } } elseif ($_GET['filter'] === 'uniquegroup') { if (!$user->propertyVisible($Viewer, 'uniquegroups')) { - error(403); + Error403::error(); } $groupBy = 'tg.ID'; } diff --git a/sections/torrents/vote_tag.php b/sections/torrents/vote_tag.php index 5f96153e3..c7d9e5789 100644 --- a/sections/torrents/vote_tag.php +++ b/sections/torrents/vote_tag.php @@ -11,7 +11,7 @@ $tag = (new Manager\Tag())->findById((int)$_GET['tagid']); $way = $_GET['way']; if (is_null($tgroup) || is_null($tag) || !in_array($way, ['up', 'down'])) { - error(404); + Error404::error(); } if (!$tag->hasVoteTGroup($tgroup, $Viewer)) { $tag->voteTGroup($tgroup, $Viewer, $way); diff --git a/sections/upload/index.php b/sections/upload/index.php index 1c22bbd7d..16d22d6c8 100644 --- a/sections/upload/index.php +++ b/sections/upload/index.php @@ -6,10 +6,10 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_upload')) { - error("Your userclass does not allow you to upload."); + Error403::error("Your userclass does not allow you to upload."); } if ($Viewer->disableUpload()) { - error('Your upload privileges have been revoked.'); + Error403::error('Your upload privileges have been revoked.'); } if (isset($_GET['action']) && $_GET['action'] == 'parse_html') { diff --git a/sections/upload/parse_html.php b/sections/upload/parse_html.php index 5d01cb8b4..24926aed1 100644 --- a/sections/upload/parse_html.php +++ b/sections/upload/parse_html.php @@ -5,9 +5,10 @@ declare(strict_types=1); namespace Gazelle; if (!$_POST['html'] || empty($_POST['html'])) { - error(-1); + Error400::error(); } -header('Content-type: text/plain'); + // we can assume that everything sent to this endpoint is legacy gazelle html-escaped bbcode // hence we run html_unescape() on the result +header('Content-type: text/plain'); echo html_unescape(Util\Text::parseHtml($_POST['html'])); diff --git a/sections/user/2fa/complete.php b/sections/user/2fa/complete.php index 739ca41e2..596b169c2 100644 --- a/sections/user/2fa/complete.php +++ b/sections/user/2fa/complete.php @@ -8,22 +8,22 @@ namespace Gazelle; $user = (new Manager\User())->findById((int)($_REQUEST['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->MFA()->enabled()) { - error($Viewer->permitted('users_edit_password') ? '2FA is already configured' : 404); + Error400::error('MFA is already configured'); } if (session_status() === PHP_SESSION_NONE) { session_start(['read_and_close' => true]); } if (empty($_SESSION['private_key'])) { - error(404); + Error404::error(); } $recoveryKeys = $user->MFA()->create(new Manager\UserToken(), $_SESSION['private_key'], $Viewer); if (!$recoveryKeys) { - error('failed to create 2FA'); + Error400::error('failed to create MFA'); } if (session_status() === PHP_SESSION_NONE) { diff --git a/sections/user/2fa/index.php b/sections/user/2fa/index.php index d71405406..52c4e416a 100644 --- a/sections/user/2fa/index.php +++ b/sections/user/2fa/index.php @@ -7,16 +7,16 @@ namespace Gazelle; $user = (new Manager\User())->findById((int)($_REQUEST['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() != $Viewer->id() && !$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } switch ($_GET['do'] ?? '') { case 'configure': if ($user->MFA()->enabled()) { - error($Viewer->permitted('users_edit_password') ? '2FA is already configured' : 404); + Error400::error('MFA is already configured'); } include_once 'configure.php'; break; @@ -30,5 +30,5 @@ switch ($_GET['do'] ?? '') { break; default: - error(404); + Error404::error(); } diff --git a/sections/user/2fa/remove.php b/sections/user/2fa/remove.php index 83e0aaa25..474acb0c8 100644 --- a/sections/user/2fa/remove.php +++ b/sections/user/2fa/remove.php @@ -8,16 +8,16 @@ namespace Gazelle; // Remove 2FA. Users have to enter their password, moderators skip this step. $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } if (!$user->MFA()->enabled()) { - error($Viewer->permitted('users_edit_password') ? 'No 2FA configured' : 404); + Error400::error('No MFA configured'); } $userId = $user->id(); if (!$Viewer->permitted('users_edit_password')) { if ($userId !== $Viewer->id()) { - error(403); + Error403::error(); } elseif (empty($_POST['password'])) { include_once 'confirm.php'; exit; diff --git a/sections/user/advancedsearch.php b/sections/user/advancedsearch.php index f91a2e055..faa10f75e 100644 --- a/sections/user/advancedsearch.php +++ b/sections/user/advancedsearch.php @@ -179,7 +179,7 @@ if (empty($_GET)) { ['way', false, 'inarray', 'Invalid way', $WayVals], ]); if (!$validator->validate($_GET)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } $m = new SQLMatcher($matchMode); diff --git a/sections/user/audit-edit-handle.php b/sections/user/audit-edit-handle.php index 555768624..7e3e0286a 100644 --- a/sections/user/audit-edit-handle.php +++ b/sections/user/audit-edit-handle.php @@ -4,15 +4,17 @@ declare(strict_types=1); +namespace Gazelle; + if (!$Viewer->permitted('admin_audit_edit')) { - error(403); + Error403::error(); } authorize(); -$userMan = new Gazelle\Manager\User(); +$userMan = new Manager\User(); $user = $userMan->findById((int)($_REQUEST['id'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $idList = $_REQUEST['id_list'] ?? ''; @@ -21,7 +23,7 @@ if (!$idList) { exit; } if ($Viewer->hashHmac('audit', $idList) !== $_REQUEST['sig']) { - error('bad signature'); + Error400::error('bad signature'); } $user->auditTrail()->modifyEventList( array_map('intval', explode(',', $idList)), diff --git a/sections/user/audit-edit.php b/sections/user/audit-edit.php index 78f975be4..f59abdef5 100644 --- a/sections/user/audit-edit.php +++ b/sections/user/audit-edit.php @@ -4,13 +4,15 @@ declare(strict_types=1); +namespace Gazelle; + if (!$Viewer->permitted('admin_audit_view')) { - error(403); + Error403::error(); } -$userMan = new Gazelle\Manager\User(); +$userMan = new Manager\User(); $user = $userMan->findById((int)($_REQUEST['id'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $idList = array_map('intval', $_REQUEST['idlist'] ?? []); @@ -25,7 +27,7 @@ echo $Twig->render('user/audit-edit.twig', [ ',', array_map(fn ($e) => $e['id_user_audit_trail'], $eventList), ), - 'note' => new Gazelle\Util\Textarea( + 'note' => new Util\Textarea( 'note', implode( "\n\n", diff --git a/sections/user/audit.php b/sections/user/audit.php index 2d412ff52..2ae94f2a5 100644 --- a/sections/user/audit.php +++ b/sections/user/audit.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('admin_audit_edit', 'admin_audit_view')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); $user = $userMan->findById((int)($_GET['id'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $user->auditTrail()->migrate($userMan); diff --git a/sections/user/delete_invite.php b/sections/user/delete_invite.php index 40fb31e8b..7b61b2bd1 100644 --- a/sections/user/delete_invite.php +++ b/sections/user/delete_invite.php @@ -10,10 +10,10 @@ authorize(); $inviteKey = trim($_GET['invite'] ?? ''); $user = (new Manager\Invite())->findUserByKey($inviteKey, new Manager\User()); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() != $Viewer->id()) { - error(403); + Error403::error(); } $user->invite()->revoke($inviteKey); diff --git a/sections/user/edit.php b/sections/user/edit.php index 9772c7628..80c0a3b21 100644 --- a/sections/user/edit.php +++ b/sections/user/edit.php @@ -10,11 +10,11 @@ $userMan = new Manager\User(); $user = $userMan->findById(($_REQUEST['id'] ?? '') === 'me' ? $Viewer->id() : (int)($_REQUEST['id'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } $UserID = $user->id(); if ($UserID != $Viewer->id() && !$Viewer->permitted('users_edit_profiles')) { - error(403); + Error403::error(); } $donor = new User\Donor($user); diff --git a/sections/user/edit_handle.php b/sections/user/edit_handle.php index 2b75f6334..142051cf1 100644 --- a/sections/user/edit_handle.php +++ b/sections/user/edit_handle.php @@ -19,12 +19,12 @@ if (!isset($_REQUEST['id'])) { } else { $user = $userMan->findById((int)$_REQUEST['id']); if (is_null($user)) { - error(404); + Error404::error(); } $ownProfile = ($user->id() === $Viewer->id()); if (!$ownProfile && !$Viewer->permitted('users_edit_profiles')) { $irc::sendMessage(IRC_CHAN_MOD, "User {$Viewer->label()} tried to edit {$user->publicLocation()}"); - error(403); + Error403::error(); } } @@ -44,7 +44,7 @@ $validator->setFields([ ['new_pass_2', true, "compare", "Your passwords do not match.", ['comparefield' => 'new_pass_1']], ]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } // Begin building $Paranoia @@ -125,7 +125,7 @@ $newEmail = false; $emailClean = trim($_POST['email']); if ($user->email() != $emailClean) { if (!$Viewer->permitted('users_edit_profiles') && !$user->validatePassword($_POST['password'])) { - error('You must enter your current password when changing your email address.'); + Error400::error('You must enter your current password when changing your email address.'); } if ($ownProfile && !Util\PasswordCheck::checkPasswordStrength($_POST['password'], $user)) { // same corner case as with changing passwords, see comment there @@ -144,11 +144,11 @@ if ($user->email() != $emailClean) { $avatar = trim($_POST['avatar']); if ($avatar != $user->avatar()) { if ($ownProfile && $user->disableAvatar()) { - error('Your avatar privileges have been revoked.'); + Error403::error('Your avatar privileges have been revoked.'); } $len = strlen($avatar); if ($len > 255) { - error('Your avatar link is too long ($len characters, maximum allowed is 255).'); + Error400::error('Your avatar link is too long ($len characters, maximum allowed is 255).'); } $user->setField('Avatar', $avatar); } @@ -156,7 +156,7 @@ if ($avatar != $user->avatar()) { $ResetPassword = false; if (!empty($_POST['password']) && !empty($_POST['new_pass_1']) && !empty($_POST['new_pass_2'])) { if (!$user->validatePassword($_POST['password'])) { - error('You did not enter the correct password.'); + Error400::error('You did not enter the correct password.'); } elseif (!Util\PasswordCheck::checkPasswordStrength($_POST['password'], $user)) { // This is a corner case: the user already has an active session and is trying to change their password. // They would not have been able to log in with this password and since it is weak it might as well be @@ -168,12 +168,12 @@ if (!empty($_POST['password']) && !empty($_POST['new_pass_1']) && !empty($_POST[ exit; } else { if (!Util\PasswordCheck::checkPasswordStrength($_POST['new_pass_1'], $user)) { - error(Util\PasswordCheck::ERROR_MSG); + Error400::error(Util\PasswordCheck::ERROR_MSG); } if ($_POST['password'] == $_POST['new_pass_1']) { - error('Your new password cannot be the same as your old password.'); + Error400::error('Your new password cannot be the same as your old password.'); } elseif ($_POST['new_pass_1'] !== $_POST['new_pass_2']) { - error('You did not enter the same password twice.'); + Error400::error('You did not enter the same password twice.'); } $user->updatePassword($_POST['new_pass_1'], true); $ResetPassword = true; diff --git a/sections/user/index.php b/sections/user/index.php index d331e7a90..dac38f865 100644 --- a/sections/user/index.php +++ b/sections/user/index.php @@ -13,10 +13,10 @@ switch ($_REQUEST['action'] ?? '') { include_once 'audit.php'; break; case 'audit-edit': - require_once('audit-edit.php'); + include_once 'audit-edit.php'; break; case 'audit-edit-handle': - require_once('audit-edit-handle.php'); + include_once 'audit-edit-handle.php'; break; case 'dupes': include_once 'userlink_handle.php'; @@ -92,7 +92,7 @@ switch ($_REQUEST['action'] ?? '') { break; case 'clearcache': if (!$Viewer->permittedAny('admin_clear_cache', 'users_override_paranoia')) { - error(403); + Error403::error(); } (new Manager\User())->findById((int)$_REQUEST['id'])?->flush(); include_once 'user.php'; diff --git a/sections/user/invite.php b/sections/user/invite.php index 9c7e46366..200565286 100644 --- a/sections/user/invite.php +++ b/sections/user/invite.php @@ -12,13 +12,13 @@ if (!isset($_GET['id'])) { } else { $user = $userMan->findById((int)$_GET['id']); if (is_null($user)) { - error(404); + Error404::error(); } } $userId = $user->id(); $ownProfile = $user->id() == $Viewer->id(); if (!$Viewer->permitted('users_view_invites') && !$ownProfile) { - error(403); + Error403::error(); } $inviteSourceMan = $Viewer->permitted('users_view_invites') || $Viewer->isRecruiter() diff --git a/sections/user/invite_handle.php b/sections/user/invite_handle.php index 0460de174..dcea0ff86 100644 --- a/sections/user/invite_handle.php +++ b/sections/user/invite_handle.php @@ -9,21 +9,21 @@ namespace Gazelle; authorize(); if (!isset($_POST['agreement'])) { - error("You must agree to the conditions for sending invitations."); + Error400::error("You must agree to the conditions for sending invitations."); } // Can the site allow an invite to be spent? if (!(new Stats\Users())->newUsersAllowed($Viewer) || !$Viewer->canInvite()) { - error(403); + Error403::error(); } $email = trim($_POST['email'] ?? ''); if (!preg_match(EMAIL_REGEXP, $email)) { - error('Invalid email.'); + Error400::error('Invalid email.'); } $manager = new Manager\Invite(); if ($manager->emailExists($Viewer, $email)) { - error('You already have a pending invite to that address!'); + Error403::error('You already have a pending invite to that address!'); } $notes = ''; @@ -62,7 +62,7 @@ $invite = $manager->create( ); if (!$invite) { - error(403); + Error403::error(); } (new \Gazelle\Util\Mail())->send($email, 'You have been invited to ' . SITE_NAME, diff --git a/sections/user/invitetree.php b/sections/user/invitetree.php index d4f58817b..2a34a6754 100644 --- a/sections/user/invitetree.php +++ b/sections/user/invitetree.php @@ -11,11 +11,11 @@ if (!isset($_GET['userid'])) { $user = $Viewer; } else { if (!$Viewer->permitted('users_view_invites')) { - error(403); + Error403::error(); } $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/user/moderate_handle.php b/sections/user/moderate_handle.php index d8df2b970..ba483f82f 100644 --- a/sections/user/moderate_handle.php +++ b/sections/user/moderate_handle.php @@ -28,7 +28,7 @@ function revoked(bool $state): string { } if (!$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); @@ -38,7 +38,9 @@ if (is_null($user)) { exit; } if ($_POST['checkpoint'] != $user->checkpoint()) { - error("Somebody else has moderated this user since you loaded it. Please go back and refresh the page."); + Error400::error( + "Somebody else has moderated this user since you loaded it. Please go back and refresh the page." + ); } $userId = $user->id(); @@ -101,7 +103,7 @@ $cur['RestrictedForums'] = $user->privilege()->forbiddenUserForums(); if ($mergeStatsFrom && ($downloaded != $user->downloadedSize() || $uploaded != $user->uploadedSize())) { // Too make make-work code to deal with this unlikely eventuality - error("Do not transfer buffer and edit upload/download in the same operation."); + Error400::error("Do not transfer buffer and edit upload/download in the same operation."); } $tracker = new Tracker(); @@ -253,11 +255,11 @@ if ($Viewer->permitted('users_edit_usernames')) { $username = trim($_POST['Username']); if ($username !== $user->username()) { if (in_array($username, ['0', '1'])) { - error('You cannot set a username of "0" or "1".'); + Error400::error('You cannot set a username of "0" or "1".'); } elseif (strtolower($username) !== strtolower($user->username())) { $found = $userMan->findByUsername($username); if ($found) { - error("Username already in use by $username"); + Error400::error("Username already in use by $username"); } } $user->setField('Username', $username); @@ -268,7 +270,7 @@ if ($Viewer->permitted('users_edit_usernames')) { if ($title != $user->title() && $Viewer->permitted('users_edit_titles')) { // Using the unescaped value for the test to avoid confusion if (mb_strlen($_POST['Title']) > 1024) { - error("Custom titles have a maximum length of 1,024 characters."); + Error400::error("Custom titles have a maximum length of 1,024 characters."); } else { $user->setField('Title', $title); $editSummary[] = "title changed to [code]{$title}[/code]"; diff --git a/sections/user/notify_edit.php b/sections/user/notify_edit.php index 51e467066..48fcd2841 100644 --- a/sections/user/notify_edit.php +++ b/sections/user/notify_edit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_torrents_notify')) { - error(403); + Error403::error(); } echo $Twig->render('user/edit-notification-filter.twig', [ diff --git a/sections/user/notify_handle.php b/sections/user/notify_handle.php index 93d42c552..a0a3e4dfa 100644 --- a/sections/user/notify_handle.php +++ b/sections/user/notify_handle.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_torrents_notify')) { - error(403); + Error403::error(); } authorize(); @@ -44,7 +44,7 @@ if (!$filter->isConfigured()) { $error = 'You must add at least one criterion to filter by'; } if ($error) { - error($error); + Error400::error($error); } if ($filterId) { diff --git a/sections/user/permissions.php b/sections/user/permissions.php index 480cda638..10f79d145 100644 --- a/sections/user/permissions.php +++ b/sections/user/permissions.php @@ -7,13 +7,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_permissions')) { - error(403); + Error403::error(); } $userMan = new Manager\User(); $user = $userMan->findById((int)($_REQUEST['userid'])); if (is_null($user)) { - error(404); + Error404::error(); } if (isset($_POST['action'])) { diff --git a/sections/user/push_handle.php b/sections/user/push_handle.php index 065e335ff..ca052584c 100644 --- a/sections/user/push_handle.php +++ b/sections/user/push_handle.php @@ -7,10 +7,10 @@ namespace Gazelle; $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(403); + Error403::error(); } if (!$Viewer->permitted('users_mod') && $user->id() != $Viewer->id()) { - error(403); + Error403::error(); } authorize(); diff --git a/sections/user/search.php b/sections/user/search.php index 0c0f83b1c..403dc6c38 100644 --- a/sections/user/search.php +++ b/sections/user/search.php @@ -1,7 +1,11 @@ findByUsername($_GET['search'] ?? $_GET['username'] ?? ''); -if (!is_null($user)) { - header('Location: ' . $user->location()); +declare(strict_types=1); + +namespace Gazelle; + +$user = (new Manager\User())->findByUsername($_GET['search'] ?? $_GET['username'] ?? ''); +if (is_null($user)) { + Error404::error("There is no-one here with that name."); } -error("There is no-one here with that name."); +header('Location: ' . $user->location()); diff --git a/sections/user/seedbox_edit.php b/sections/user/seedbox_edit.php index 58976f70f..f9c7dd8a4 100644 --- a/sections/user/seedbox_edit.php +++ b/sections/user/seedbox_edit.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->hasAttr('feature-seedbox') && !$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } if (!isset($_POST['action'])) { @@ -18,10 +18,10 @@ if (!isset($_POST['action'])) { } $user = (new Manager\User())->findById($userId); if (!$user) { - error(404); + Error404::error(); } if ($Viewer->id() != $userId && !$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $seedbox = new User\Seedbox($user); @@ -35,18 +35,18 @@ if (isset($_POST['mode'])) { $sigList = array_key_filter_and_map('sig-', $_POST); $uaList = array_key_filter_and_map('ua-', $_POST); if (count($idList) != count($ipList)) { - error("id/ip mismatch"); + Error400::error("id/ip mismatch"); } elseif (count($idList) != count($nameList)) { - error("id/name mismatch"); + Error400::error("id/name mismatch"); } elseif (count($idList) != count($sigList)) { - error("id/sig mismatch"); + Error400::error("id/sig mismatch"); } elseif (count($idList) != count($uaList)) { - error("id/ua mismatch"); + Error400::error("id/ua mismatch"); } $update = []; foreach (array_keys($idList) as $i) { if ($sigList[$i] != signature("{$ipList[$i]}/{$uaList[$i]}}", SEEDBOX_SALT)) { - error("ip/ua signature failed"); + Error400::error("ip/ua signature failed"); } $update[] = [ 'id' => $idList[$i], @@ -62,7 +62,7 @@ if (isset($_POST['mode'])) { $seedbox->removeNames($remove); break; default: - error(403); + Error403::error(); } } diff --git a/sections/user/seedbox_view.php b/sections/user/seedbox_view.php index ea01a1a72..275b0f6e3 100644 --- a/sections/user/seedbox_view.php +++ b/sections/user/seedbox_view.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->hasAttr('feature-seedbox') && !$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } if (!isset($_POST['action'])) { @@ -18,10 +18,10 @@ if (!isset($_POST['action'])) { } $user = (new Manager\User())->findById($userId); if (!$user) { - error(404); + Error404::error(); } if ($Viewer->id() != $userId && !$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $union = trim($_REQUEST['view'] ?? 'union') === 'union'; @@ -31,7 +31,7 @@ $target = ($_REQUEST['target'] ?? null); $seedbox = new User\Seedbox($user); if (isset($_POST['action']) || isset($_REQUEST['viewby'])) { if (is_null($source) || is_null($target) || $source === $target) { - error("Invalid comparison between two seedbox instances"); + Error400::error("Invalid comparison between two seedbox instances"); } $seedbox->setSource($source) ->setTarget($target) diff --git a/sections/user/sessions.php b/sections/user/sessions.php index a9bf22da2..1fee1e893 100644 --- a/sections/user/sessions.php +++ b/sections/user/sessions.php @@ -11,11 +11,11 @@ if (!isset($_GET['id'])) { } else { $userId = (int)$_GET['id']; if ($userId !== $Viewer->id() && !$Viewer->permittedAny('users_logout', 'users_view_ips')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById($userId); if (is_null($user)) { - error(404); + Error404::error(); } } diff --git a/sections/user/token.php b/sections/user/token.php index 73871d407..73f1c7a2d 100644 --- a/sections/user/token.php +++ b/sections/user/token.php @@ -17,7 +17,7 @@ $tokenName = ''; $_GET['do'] ??= ''; if (!empty($_GET['do']) && $userId !== $Viewer->id() && !$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } if ($_GET['do'] === 'revoke') { diff --git a/sections/user/user.php b/sections/user/user.php index 77f44a5b1..c990551f6 100644 --- a/sections/user/user.php +++ b/sections/user/user.php @@ -39,18 +39,20 @@ if (!empty($_POST)) { authorize(); foreach (['action', 'flsubmit', 'fltype'] as $arg) { if (!isset($_POST[$arg])) { - error(403); + Error403::error(); } } if ($_POST['action'] !== 'fltoken' || $_POST['flsubmit'] !== 'Send') { - error(403); + Error403::error(); } if (!preg_match('/^fl-(other-[1-4])$/', $_POST['fltype'], $match)) { - error(403); + Error403::error(); } $FL_OTHER_tokens = $viewerBonus->purchaseTokenOther($user, $match[1], $_POST['message'] ?? ''); if (!$FL_OTHER_tokens) { - error('Purchase of tokens not concluded. Either you lacked funds or they have chosen to decline FL tokens.'); + Error400::error( + 'Purchase of tokens not concluded. Either you lacked funds or they have chosen to decline FL tokens.' + ); } } diff --git a/sections/user/user_stats.php b/sections/user/user_stats.php index dd6dd087e..2a5244b80 100644 --- a/sections/user/user_stats.php +++ b/sections/user/user_stats.php @@ -9,16 +9,16 @@ namespace Gazelle; $userMan = new Manager\User(); if (!isset($_GET['userid'])) { if (!$Viewer->permitted('site_user_stats')) { - error(403); + Error403::error(); } $user = $Viewer; } else { $user = $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() != $Viewer->id() && !$Viewer->permitted('users_mod')) { - error(403); + Error403::error(); } } diff --git a/sections/user/userlink_handle.php b/sections/user/userlink_handle.php index 0df4aeabe..0e186ed69 100644 --- a/sections/user/userlink_handle.php +++ b/sections/user/userlink_handle.php @@ -6,14 +6,14 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_linked_users')) { - error(403); + Error403::error(); } authorize(); $userMan = new Manager\User(); $source = $userMan->findById((int)$_REQUEST['userid']); if (is_null($source)) { - error(404); + Error404::error(); } $userLink = new User\UserLink($source); @@ -29,9 +29,9 @@ switch ($_REQUEST['dupeaction'] ?? '') { $username = trim($_REQUEST['target']); $target = $userMan->find($username); if (is_null($target)) { - error("User '" . display_str($username) . "' not found."); + Error400::error("User '" . display_str($username) . "' not found."); } elseif ($source->id() === $target->id()) { - error("Cannot link a user to themselves"); + Error400::error("Cannot link a user to themselves"); } $userLink->dupe($target, $Viewer, $updateNote); } @@ -42,7 +42,7 @@ switch ($_REQUEST['dupeaction'] ?? '') { break; default: - error(403); + Error403::error(); } header("Location: {$source->location()}"); diff --git a/sections/user/vote_history.php b/sections/user/vote_history.php index c176c5cd4..48515bd90 100644 --- a/sections/user/vote_history.php +++ b/sections/user/vote_history.php @@ -10,11 +10,11 @@ use Gazelle\User\Vote; $user = (new Manager\User())->findById((int)$_GET['id']); if (is_null($user)) { - error(404); + Error404::error(); } $ownProfile = $user->id() === $Viewer->id(); if (!$Viewer->permitted('view-release-votes') && !$ownProfile) { - error(403); + Error403::error(); } if (isset($_GET['up'])) { diff --git a/sections/userhistory/announce_key_history.php b/sections/userhistory/announce_key_history.php index 39d44933e..289e8d47d 100644 --- a/sections/userhistory/announce_key_history.php +++ b/sections/userhistory/announce_key_history.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_keys')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); if (is_null($user)) { - error(404); + Error404::error(); } echo $Twig->render('admin/announcekey-history.twig', [ diff --git a/sections/userhistory/catchup_collages.php b/sections/userhistory/catchup_collages.php index cd51b70de..7c4889869 100644 --- a/sections/userhistory/catchup_collages.php +++ b/sections/userhistory/catchup_collages.php @@ -13,7 +13,7 @@ if (!isset($_REQUEST['collageid'])) { } else { $collage = (new Manager\Collage())->findById((int)$_REQUEST['collageid']); if (is_null($collage)) { - error(404); + Error404::error(); } $notifier->clearCollage($collage); } diff --git a/sections/userhistory/collage_subscribe.php b/sections/userhistory/collage_subscribe.php index 0512ff8a1..6217918da 100644 --- a/sections/userhistory/collage_subscribe.php +++ b/sections/userhistory/collage_subscribe.php @@ -9,6 +9,6 @@ authorize(); $collage = (new Manager\Collage())->findById((int)($_GET['collageid'] ?? 0)); if (is_null($collage)) { - error(404); + Error404::error(); } $collage->toggleSubscription($Viewer); diff --git a/sections/userhistory/comments_subscribe.php b/sections/userhistory/comments_subscribe.php index f7d171c72..497024e4c 100644 --- a/sections/userhistory/comments_subscribe.php +++ b/sections/userhistory/comments_subscribe.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!in_array($_GET['page'], ['artist', 'collages', 'requests', 'torrents']) || !(int)($_GET['pageid'] ?? 0)) { - error('Unknown comments subscription target'); + Error400::error('Unknown comments subscription target'); } authorize(); diff --git a/sections/userhistory/email_history.php b/sections/userhistory/email_history.php index a54ac430c..edefd8d42 100644 --- a/sections/userhistory/email_history.php +++ b/sections/userhistory/email_history.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_email')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } echo $Twig->render('user/email-history.twig', [ diff --git a/sections/userhistory/ip_history.php b/sections/userhistory/ip_history.php index 25131ee4e..a5904fb5a 100644 --- a/sections/userhistory/ip_history.php +++ b/sections/userhistory/ip_history.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_ips')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } $ipMan = new Manager\IPv4(); if (trim($_GET['ip'] ?? '') !== '') { diff --git a/sections/userhistory/ip_tracker_history.php b/sections/userhistory/ip_tracker_history.php index 54ebe032b..2cf78e0d1 100644 --- a/sections/userhistory/ip_tracker_history.php +++ b/sections/userhistory/ip_tracker_history.php @@ -7,13 +7,13 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permittedAny('users_mod', 'users_view_ips')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)($_GET['userid'] ?? 0)); $ipaddr = $_GET['ip'] ?? null; if (is_null($user) && !preg_match(IP_REGEXP, $ipaddr)) { - error(403); + Error403::error(); } $snatchInfo = new SnatchInfo(); diff --git a/sections/userhistory/password_history.php b/sections/userhistory/password_history.php index e3896392c..2f5b96d89 100644 --- a/sections/userhistory/password_history.php +++ b/sections/userhistory/password_history.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('users_view_keys')) { - error(403); + Error403::error(); } $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } echo $Twig->render('user/password-history.twig', [ diff --git a/sections/userhistory/post_history.php b/sections/userhistory/post_history.php index 6c3ed10b4..01f087ed2 100644 --- a/sections/userhistory/post_history.php +++ b/sections/userhistory/post_history.php @@ -7,13 +7,13 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableForums()) { - error(403); + Error403::error(); } $userMan = new Manager\User(); $user = empty($_GET['userid']) ? $Viewer : $userMan->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } $ownProfile = $user->id() === $Viewer->id(); diff --git a/sections/userhistory/quote_notifications.php b/sections/userhistory/quote_notifications.php index 3c8907d48..fcb436143 100644 --- a/sections/userhistory/quote_notifications.php +++ b/sections/userhistory/quote_notifications.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableForums()) { - error(403); + Error403::error(); } $userQuote = new User\Quote($Viewer); diff --git a/sections/userhistory/subscribed_collages.php b/sections/userhistory/subscribed_collages.php index 185297bc9..868368a8a 100644 --- a/sections/userhistory/subscribed_collages.php +++ b/sections/userhistory/subscribed_collages.php @@ -9,7 +9,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('site_collages_subscribe')) { - error(403); + Error403::error(); } $viewAll = (bool)($_GET['showall'] ?? 0); diff --git a/sections/userhistory/subscriptions.php b/sections/userhistory/subscriptions.php index 0761162cf..c84a1b587 100644 --- a/sections/userhistory/subscriptions.php +++ b/sections/userhistory/subscriptions.php @@ -75,7 +75,7 @@ foreach ($Results as &$result) { } break; default: - error('Unknown comment history target'); + Error400::error('Unknown comment history target'); } if (!empty($result['LastReadBody'])) { $result['avatar'] = $avatarFilter->render(['user' => new User($result['LastReadUserID']), 'viewer' => $Viewer]); diff --git a/sections/userhistory/thread_subscribe.php b/sections/userhistory/thread_subscribe.php index af4667b63..e84dfcd6a 100644 --- a/sections/userhistory/thread_subscribe.php +++ b/sections/userhistory/thread_subscribe.php @@ -6,16 +6,16 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableForums()) { - error(403); + Error403::error(); } authorize(); $thread = (new Manager\ForumThread())->findById((int)($_GET['threadid'] ?? 0)); if (is_null($thread)) { - error(404); + Error404::error(); } if (!$Viewer->readAccess($thread->forum())) { - error(403); + Error403::error(); } json_print('success', (new User\Subscription($Viewer))->subscribe($thread)); diff --git a/sections/userhistory/token_history.php b/sections/userhistory/token_history.php index 6c1c9e3d1..7af2b7fb5 100644 --- a/sections/userhistory/token_history.php +++ b/sections/userhistory/token_history.php @@ -11,10 +11,10 @@ if (!isset($_GET['userid'])) { } else { $user = (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } if ($user->id() !== $Viewer->id() && !$Viewer->permitted('admin_fl_history')) { - error(403); + Error403::error(); } } @@ -23,11 +23,11 @@ $torMan->setViewer($Viewer); if ($_GET['expire'] ?? 0) { if (!$Viewer->permitted('admin_fl_history')) { - error(403); + Error403::error(); } $torrent = $torMan->findById((int)$_GET['torrentid']); if (is_null($torrent)) { - error(404); + Error404::error(); } $torrent->expireToken($user); header("Location: userhistory.php?action=token_history&userid=" . $user->id()); diff --git a/sections/userhistory/topic_history.php b/sections/userhistory/topic_history.php index 1ae45bf79..a5f30022f 100644 --- a/sections/userhistory/topic_history.php +++ b/sections/userhistory/topic_history.php @@ -7,12 +7,12 @@ declare(strict_types=1); namespace Gazelle; if ($Viewer->disableForums()) { - error(403); + Error403::error(); } $user = empty($_GET['userid']) ? $Viewer : (new Manager\User())->findById((int)$_GET['userid']); if (is_null($user)) { - error(404); + Error404::error(); } $forumSearch = new Search\Forum($user); if ($Viewer->id() != $user->id()) { diff --git a/sections/view/index.php b/sections/view/index.php index 772fa46c1..e1c3da8d4 100644 --- a/sections/view/index.php +++ b/sections/view/index.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Gazelle; if (!array_key_exists('type', $_GET) && !array_key_exists('id', $_GET)) { - error(404); + Error404::error(); } switch ($_GET['type']) { @@ -16,9 +16,9 @@ switch ($_GET['type']) { $file = new \Gazelle\File\RipLog(); echo $file->get([$m[1], $m[2]]); } else { - error(404); + Error404::error(); } break; default: - error(404); + Error404::error(); } diff --git a/sections/wiki/add_alias.php b/sections/wiki/add_alias.php index a88f2a363..ede19b775 100644 --- a/sections/wiki/add_alias.php +++ b/sections/wiki/add_alias.php @@ -9,16 +9,16 @@ authorize(); $article = (new Manager\Wiki())->findById((int)$_POST['article']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->editable($Viewer)) { - error(403); + Error403::error(); } try { $article->addAlias(trim($_POST['alias']), $Viewer); } catch (DB\MysqlDuplicateKeyException) { - error('The alias you attempted to add is already assigned to an article.'); + Error400::error('The alias you attempted to add is already assigned to an article.'); } header('Location: ' . $article->location()); diff --git a/sections/wiki/article.php b/sections/wiki/article.php index 895c0d030..04265e816 100644 --- a/sections/wiki/article.php +++ b/sections/wiki/article.php @@ -27,7 +27,7 @@ if (!$article) { } if (!$article->readable($Viewer)) { - error(403); + Error403::error(); } $classList = (new Manager\User())->classLevelList(); diff --git a/sections/wiki/compare.php b/sections/wiki/compare.php index 88f73fb1e..acdced840 100644 --- a/sections/wiki/compare.php +++ b/sections/wiki/compare.php @@ -68,16 +68,16 @@ function diff(string $OldText, string $NewText): array { $old = (int)($_GET['old'] ?? 0); $new = (int)($_GET['new'] ?? 0); if ($old >= $new) { - error("Selected older revision is more recent than selected newer revision."); + Error400::error("Selected older revision is more recent than selected newer revision."); } $wikiMan = new Manager\Wiki(); $article = $wikiMan->findById((int)$_GET['id']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->readable($Viewer)) { - error(403); + Error403::error(); } View::show_header("Compare Article Revisions $old versus $new"); diff --git a/sections/wiki/create_handle.php b/sections/wiki/create_handle.php index 7f2729403..2003174e9 100644 --- a/sections/wiki/create_handle.php +++ b/sections/wiki/create_handle.php @@ -10,22 +10,22 @@ authorize(); $validator = new Util\Validator(); $validator->setField('title', true, 'string', 'The title must be between 3 and 100 characters', ['range' => [3, 100]]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } $wikiMan = new Manager\Wiki(); $title = trim($_POST['title']); $article = $wikiMan->findByTitle($title); if ($article) { - error('An article with that name already exists here' + Error400::error( + 'An article with that name already exists here' ); } [$minRead, $minEdit, $error] = $wikiMan->configureAccess( $Viewer, (int)$_POST['minclassread'], (int)$_POST['minclassedit'] ); if ($error) { - error($error); + Error400::error($error); } $article = $wikiMan->create($title, $_POST['body'], $minRead, $minEdit, $Viewer); diff --git a/sections/wiki/delete.php b/sections/wiki/delete.php index 35870f81b..94fb96211 100644 --- a/sections/wiki/delete.php +++ b/sections/wiki/delete.php @@ -8,18 +8,18 @@ namespace Gazelle; authorize(); if (!$Viewer->permitted('admin_manage_wiki')) { - error(403); + Error403::error(); } $article = (new Manager\Wiki())->findById((int)$_GET['id']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->editable($Viewer)) { - error(403); + Error403::error(); } if ($article->id() == INDEX_WIKI_PAGE_ID) { - error('You cannot delete the main wiki article.'); + Error403::error('You cannot delete the main wiki article.'); } $article->logger()->general( diff --git a/sections/wiki/delete_alias.php b/sections/wiki/delete_alias.php index f0701a9b4..34ea997c2 100644 --- a/sections/wiki/delete_alias.php +++ b/sections/wiki/delete_alias.php @@ -10,11 +10,11 @@ authorize(); $alias = $_GET['alias'] ?? ''; $article = (new Manager\Wiki())->findByAlias($alias); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->editable($Viewer)) { - error(403); + Error403::error(); } $article->removeAlias($alias); diff --git a/sections/wiki/delete_handle.php b/sections/wiki/delete_handle.php index e2b12601f..0468a139b 100644 --- a/sections/wiki/delete_handle.php +++ b/sections/wiki/delete_handle.php @@ -6,7 +6,7 @@ declare(strict_types=1); namespace Gazelle; if (!$Viewer->permitted('admin_manage_wiki')) { - error(403); + Error403::error(); } authorize(); @@ -14,7 +14,7 @@ authorize(); $wikiMan = new Manager\Wiki(); $article = $wikiMan->findById((int)$_POST['id']); if (is_null($article)) { - error(404); + Error404::error(); } $id = $article->id(); diff --git a/sections/wiki/edit.php b/sections/wiki/edit.php index 127f7e484..d83dc3b0b 100644 --- a/sections/wiki/edit.php +++ b/sections/wiki/edit.php @@ -8,11 +8,11 @@ namespace Gazelle; $article = (new Manager\Wiki())->findById((int)$_GET['id']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->editable($Viewer)) { - error('You do not have access to edit this article.'); + Error403::error('You do not have access to edit this article.'); } echo $Twig->render('wiki/create.twig', [ diff --git a/sections/wiki/edit_handle.php b/sections/wiki/edit_handle.php index 88d78a143..8489894fc 100644 --- a/sections/wiki/edit_handle.php +++ b/sections/wiki/edit_handle.php @@ -10,21 +10,21 @@ authorize(); $wikiMan = new Manager\Wiki(); $article = $wikiMan->findById((int)$_POST['id']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->editable($Viewer)) { - error(403); + Error403::error(); } $validator = new Util\Validator(); $validator->setField('title', true, 'string', 'The title must be between 3 and 100 characters', ['range' => [3, 100]]); if (!$validator->validate($_POST)) { - error($validator->errorMessage()); + Error400::error($validator->errorMessage()); } if ($article->revision() != (int)($_POST['revision'] ?? 0)) { - error('This article has already been modified from its original version.'); + Error400::error('This article has already been modified from its original version.'); } [$minRead, $minEdit, $error] = $wikiMan->configureAccess( @@ -33,7 +33,7 @@ if ($article->revision() != (int)($_POST['revision'] ?? 0)) { (int)($_POST['minclassedit'] ?? $article->minClassEdit()), ); if ($error) { - error($error); + Error400::error($error); } $article->setField('Body', trim($_POST['body'])) diff --git a/sections/wiki/revisions.php b/sections/wiki/revisions.php index e0f992012..2aedd8a47 100644 --- a/sections/wiki/revisions.php +++ b/sections/wiki/revisions.php @@ -9,10 +9,10 @@ namespace Gazelle; $wikiMan = new Manager\Wiki(); $article = $wikiMan->findById((int)$_GET['id']); if (is_null($article)) { - error(404); + Error404::error(); } if (!$article->readable($Viewer)) { - error(403); + Error403::error(); } echo $Twig->render('wiki/revision-list.twig', [ diff --git a/templates/error.twig b/templates/error.twig index cb8465612..1c8af6d07 100644 --- a/templates/error.twig +++ b/templates/error.twig @@ -1,9 +1,10 @@ -{{ header(title) }} +{{ header("Error " ~ code) }}
- -

{{ title }}

- -

{{ description }}

- +

Error {{ code }}

+

{{ description }}

+{% if message %} +

Additional details: {{ message }}

+{% endif %} +
{{ footer() }} diff --git a/tests/cypress/e2e/1-simple/basic.cy.js b/tests/cypress/e2e/1-simple/basic.cy.js index 9c7662ed2..7019e6eb4 100644 --- a/tests/cypress/e2e/1-simple/basic.cy.js +++ b/tests/cypress/e2e/1-simple/basic.cy.js @@ -1,6 +1,6 @@ -describe('page loads as admin', () => { - let date = new Date(); +/* global beforeEach, cy, describe, it */ +describe('page loads as admin', () => { [ "/", "/artist.php", @@ -27,9 +27,9 @@ describe('page loads as admin', () => { "/stats.php", "/tools.php", "/tools.php?action=analysis_list", + "/tools.php?action=privilege-edit&id=15", "/top10.php", "/torrents.php", - "/torrents.php?action=advanced&artistname=doesnotexist", "/user.php", "/user.php?id=1", "/user.php?action=edit&id=1", @@ -38,7 +38,6 @@ describe('page loads as admin', () => { "/user.php?action=search&search=aaa", "/userhistory.php?action=subscriptions", "/userhistory.php?action=posts", - "/view.php", "/wiki.php", ].forEach((url) => { beforeEach(() => { diff --git a/tests/phpunit/ErrorTest.php b/tests/phpunit/ErrorTest.php new file mode 100644 index 000000000..dcac1d882 --- /dev/null +++ b/tests/phpunit/ErrorTest.php @@ -0,0 +1,52 @@ +user = Helper::makeUser('error.' . randomString(6), 'error'); + Base::staticRequestContext()->setViewer($this->user); + global $SessionID; + $SessionID = 'phpunit'; + } + + public function tearDown(): void { + $this->user->remove(); + } + + public function testOutputError400(): void { + $this->expectOutputRegex("#Error 400 ⠶ " . SITE_NAME . "#"); + echo Error400::payload(''); + } + + public function testOutputErrorDetails(): void { + $detail = randomString(); + $this->expectOutputRegex("#

Additional details: $detail

#"); + echo Error400::payload($detail); + } + + public function testOutputError403(): void { + $this->expectOutputRegex("#Error 403 ⠶ " . SITE_NAME . "#"); + echo Error403::payload(''); + } + + public function testOutputError404(): void { + $this->expectOutputRegex("#Error 404 ⠶ " . SITE_NAME . "#"); + echo Error404::payload(''); + } + + public function testOutputError429(): void { + $this->expectOutputRegex("#Error 429 ⠶ " . SITE_NAME . "#"); + echo Error429::payload(''); + } + + public function testOutputError500(): void { + $this->expectOutputRegex("#Error 500 ⠶ " . SITE_NAME . "#"); + echo Error500::payload(''); + } +}