Merge pull request #816 from Zankaria/fix-dir-config

Assorted php fixes
This commit is contained in:
Lorenzo Yario 2024-10-02 08:32:52 -07:00 committed by GitHub
commit f421e25e63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 59 additions and 60 deletions

View File

@ -1429,14 +1429,10 @@
$config['dir'] = [ $config['dir'] = [
'img' => 'src/', 'img' => 'src/',
'thumb' => 'thumb/', 'thumb' => 'thumb/',
'res' => 'res/' 'res' => 'res/',
];
// For load balancing, having a seperate server (and domain/subdomain) for serving static content is // For load balancing, having a seperate server (and domain/subdomain) for serving static content is
// possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'. // possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'.
// $config['dir']['static'] = 'http://static.example.org/'; // $config['dir']['static'] = 'http://static.example.org/';
$config['dir'] = [
// Where to store the .html templates. This folder and the template files must exist. // Where to store the .html templates. This folder and the template files must exist.
'template' => getcwd() . '/templates', 'template' => getcwd() . '/templates',
// Location of vichan "themes". // Location of vichan "themes".
@ -1563,50 +1559,6 @@
'lock_ip' => true, 'lock_ip' => true,
// The page that is first shown when a moderator logs in. Defaults to the dashboard (?/). // The page that is first shown when a moderator logs in. Defaults to the dashboard (?/).
'default' => '/', 'default' => '/',
'link_delete' => '[D]',
'link_ban' => '[B]',
'link_bandelete' => '[&D]',
'link_deletefile' => '[F]',
'link_spoilerimage' => '[S]',
'link_deletebyip' => '[D+]',
'link_deletebyip_global' => '[D++]',
'link_sticky' => '[Sticky]',
'link_desticky' => '[-Sticky]',
'link_lock' => '[Lock]',
'link_unlock' => '[-Lock]',
'link_bumplock' => '[Sage]',
'link_bumpunlock' => '[-Sage]',
'link_editpost' => '[Edit]',
'link_move' => '[Move]',
'link_cycle' => '[Cycle]',
'link_uncycle' => '[-Cycle]'
];
// Moderator capcodes.
$config['capcode'] = ' <span class="capcode">## %s</span>';
// "## Custom" becomes lightgreen, italic and bold:
//$config['custom_capcode']['Custom'] ='<span class="capcode" style="color:lightgreen;font-style:italic;font-weight:bold"> ## %s</span>';
// "## Mod" makes everything purple, including the name and tripcode:
//$config['custom_capcode']['Mod'] = array(
// '<span class="capcode" style="color:purple"> ## %s</span>',
// 'color:purple', // Change name style; optional
// 'color:purple' // Change tripcode style; optional
//);
// "## Admin" makes everything red and bold, including the name and tripcode:
//$config['custom_capcode']['Admin'] = array(
// '<span class="capcode" style="color:red;font-weight:bold"> ## %s</span>',
// 'color:red;font-weight:bold', // Change name style; optional
// 'color:red;font-weight:bold' // Change tripcode style; optional
//);
// Enable the moving of single replies
$config['move_replies'] = false;
$config['mod'] = [
// Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x). // Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x).
'dns_lookup' => true, 'dns_lookup' => true,
// How many recent posts, per board, to show in ?/IP/x.x.x.x. // How many recent posts, per board, to show in ?/IP/x.x.x.x.
@ -1657,9 +1609,50 @@
'dismiss_reports_on_lock' => true, 'dismiss_reports_on_lock' => true,
// Replace ?/config with a simple text editor for editing inc/instance-config.php. // Replace ?/config with a simple text editor for editing inc/instance-config.php.
'config_editor_php' => false 'config_editor_php' => false,
'link_delete' => '[D]',
'link_ban' => '[B]',
'link_bandelete' => '[&amp;D]',
'link_deletefile' => '[F]',
'link_spoilerimage' => '[S]',
'link_deletebyip' => '[D+]',
'link_deletebyip_global' => '[D++]',
'link_sticky' => '[Sticky]',
'link_desticky' => '[-Sticky]',
'link_lock' => '[Lock]',
'link_unlock' => '[-Lock]',
'link_bumplock' => '[Sage]',
'link_bumpunlock' => '[-Sage]',
'link_editpost' => '[Edit]',
'link_move' => '[Move]',
'link_cycle' => '[Cycle]',
'link_uncycle' => '[-Cycle]'
]; ];
// Moderator capcodes.
$config['capcode'] = ' <span class="capcode">## %s</span>';
// "## Custom" becomes lightgreen, italic and bold:
//$config['custom_capcode']['Custom'] ='<span class="capcode" style="color:lightgreen;font-style:italic;font-weight:bold"> ## %s</span>';
// "## Mod" makes everything purple, including the name and tripcode:
//$config['custom_capcode']['Mod'] = array(
// '<span class="capcode" style="color:purple"> ## %s</span>',
// 'color:purple', // Change name style; optional
// 'color:purple' // Change tripcode style; optional
//);
// "## Admin" makes everything red and bold, including the name and tripcode:
//$config['custom_capcode']['Admin'] = array(
// '<span class="capcode" style="color:red;font-weight:bold"> ## %s</span>',
// 'color:red;font-weight:bold', // Change name style; optional
// 'color:red;font-weight:bold' // Change tripcode style; optional
//);
// Enable the moving of single replies
$config['move_replies'] = false;
/* /*
* ==================== * ====================
* Mod permissions * Mod permissions

View File

@ -4,6 +4,7 @@
* Copyright (c) 2010-2013 Tinyboard Development Group * Copyright (c) 2010-2013 Tinyboard Development Group
*/ */
use Vichan\Context;
use Vichan\Functions\Net; use Vichan\Functions\Net;
defined('TINYBOARD') or exit; defined('TINYBOARD') or exit;
@ -232,7 +233,7 @@ function make_secure_link_token(string $uri): string {
return substr(sha1($config['cookies']['salt'] . '-' . $uri . '-' . $mod['id']), 0, 8); return substr(sha1($config['cookies']['salt'] . '-' . $uri . '-' . $mod['id']), 0, 8);
} }
function check_login(bool $prompt = false): void { function check_login(Context $ctx, bool $prompt = false): void {
global $config, $mod; global $config, $mod;
$is_https = Net\is_connection_secure($config['cookies']['secure_login_only'] === 1); $is_https = Net\is_connection_secure($config['cookies']['secure_login_only'] === 1);
@ -246,7 +247,9 @@ function check_login(bool $prompt = false): void {
if (count($cookie) != 3) { if (count($cookie) != 3) {
// Malformed cookies // Malformed cookies
destroyCookies(); destroyCookies();
if ($prompt) mod_login(); if ($prompt) {
mod_login($ctx);
}
exit; exit;
} }
@ -259,7 +262,9 @@ function check_login(bool $prompt = false): void {
if ($cookie[1] !== mkhash($cookie[0], $user['password'], $cookie[2])) { if ($cookie[1] !== mkhash($cookie[0], $user['password'], $cookie[2])) {
// Malformed cookies // Malformed cookies
destroyCookies(); destroyCookies();
if ($prompt) mod_login(); if ($prompt) {
mod_login($ctx);
}
exit; exit;
} }

View File

@ -11,7 +11,10 @@ if ($config['debug']) {
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']) : '';
@ -136,8 +139,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

@ -694,7 +694,7 @@ if (isset($_POST['delete'])) {
if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) { if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) {
check_login(false); check_login($context, 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']);