post.php, mod.php: pass the context to check_login

This commit is contained in:
Zankaria 2024-10-01 22:15:03 +02:00
parent 4197b5a376
commit 8cf497eb93
3 changed files with 23 additions and 18 deletions

View file

@ -850,7 +850,7 @@ function mod_view_thread50(Context $ctx, $boardName, $thread) {
} }
function mod_ip_remove_note(Context $ctx, $ip, $id) { function mod_ip_remove_note(Context $ctx, $ip, $id) {
global $config, $mod; global $config;
if (!hasPermission($config['mod']['remove_notes'])) if (!hasPermission($config['mod']['remove_notes']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
@ -1057,7 +1057,7 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = '') {
mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($ip)), 'mod/view_ip.html', $args, $args['hostname']); mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($ip)), 'mod/view_ip.html', $args, $args['hostname']);
} }
function mod_ban() { function mod_ban(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['ban'])) if (!hasPermission($config['mod']['ban']))
@ -1645,8 +1645,8 @@ function mod_move(Context $ctx, $originBoard, $postID) {
mod_page(_('Move thread'), 'mod/move.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); mod_page(_('Move thread'), 'mod/move.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token));
} }
function mod_merge($originBoard, $postID) { function mod_merge(Context $ctx, $originBoard, $postID) {
global $board, $config, $mod, $pdo; global $board, $config, $pdo;
if (!openBoard($originBoard)) if (!openBoard($originBoard))
error($config['error']['noboard']); error($config['error']['noboard']);

View file

@ -12,7 +12,10 @@ if ($config['debug']) {
require_once 'inc/bans.php'; require_once 'inc/bans.php';
require_once 'inc/mod/pages.php'; require_once 'inc/mod/pages.php';
check_login(true);
$ctx = Vichan\build_context($config);
check_login($ctx, true);
$query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : ''; $query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : '';
@ -148,8 +151,6 @@ foreach ($pages as $key => $callback) {
} }
$pages = $new_pages; $pages = $new_pages;
$ctx = Vichan\build_context($config);
foreach ($pages as $uri => $handler) { foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) { if (preg_match($uri, $query, $matches)) {
$matches[0] = $ctx; // Replace the text captured by the full pattern with a reference to the context. $matches[0] = $ctx; // Replace the text captured by the full pattern with a reference to the context.

View file

@ -3,6 +3,8 @@
* Copyright (c) 2010-2014 Tinyboard Development Group * Copyright (c) 2010-2014 Tinyboard Development Group
*/ */
use Vichan\Context;
require_once 'inc/bootstrap.php'; require_once 'inc/bootstrap.php';
/** /**
@ -529,7 +531,7 @@ function handle_nntpchan()
); );
} }
function handle_delete() function handle_delete(Context $ctx)
{ {
// Delete // Delete
global $config, $board, $mod; global $config, $board, $mod;
@ -537,7 +539,7 @@ function handle_delete()
error($config['error']['bot']); error($config['error']['bot']);
} }
check_login(false); check_login($ctx, false);
$is_mod = !!$mod; $is_mod = !!$mod;
if (isset($_POST['mod']) && $_POST['mod'] && !$mod) { if (isset($_POST['mod']) && $_POST['mod'] && !$mod) {
@ -653,7 +655,7 @@ function handle_delete()
rebuildThemes('post-delete', $board['uri']); rebuildThemes('post-delete', $board['uri']);
} }
function handle_report() function handle_report(Context $ctx)
{ {
global $config, $board; global $config, $board;
if (!isset($_POST['board'], $_POST['reason'])) if (!isset($_POST['board'], $_POST['reason']))
@ -802,7 +804,7 @@ function handle_report()
} }
} }
function handle_post() function handle_post(Context $ctx)
{ {
global $config, $dropped_post, $board, $mod, $pdo; global $config, $dropped_post, $board, $mod, $pdo;
@ -911,7 +913,7 @@ function handle_post()
} }
if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) { if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) {
check_login(false); check_login($ctx, false);
if (!$mod) { if (!$mod) {
// Liar. You're not a mod >:-[ // Liar. You're not a mod >:-[
error($config['error']['notamod']); error($config['error']['notamod']);
@ -1846,7 +1848,7 @@ function handle_post()
} }
} }
function handle_appeal() function handle_appeal(Context $ctx)
{ {
global $config; global $config;
if (!isset($_POST['ban_id'])) { if (!isset($_POST['ban_id'])) {
@ -1899,14 +1901,16 @@ if (isset($_GET['Newsgroups'])) {
} }
} }
$ctx = Vichan\build_context($config);
if (isset($_POST['delete'])) { if (isset($_POST['delete'])) {
handle_delete(); handle_delete($ctx);
} elseif (isset($_POST['report'])) { } elseif (isset($_POST['report'])) {
handle_report(); handle_report($ctx);
} elseif (isset($_POST['post']) || $dropped_post) { } elseif (isset($_POST['post']) || $dropped_post) {
handle_post(); handle_post($ctx);
} elseif (isset($_POST['appeal'])) { } elseif (isset($_POST['appeal'])) {
handle_appeal(); handle_appeal($ctx);
} else { } else {
if (!file_exists($config['has_installed'])) { if (!file_exists($config['has_installed'])) {
header('Location: install.php', true, $config['redirect_http']); header('Location: install.php', true, $config['redirect_http']);