From 4fce9b63aee89c04ea0d833992e72ab75585f630 Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Fri, 2 Aug 2013 20:52:58 -0400
Subject: Major config.php cleanup and a few minor misc fixes.
---
mod.php | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'mod.php')
diff --git a/mod.php b/mod.php
index cd4d17d4..ee05c349 100644
--- a/mod.php
+++ b/mod.php
@@ -109,7 +109,7 @@ $new_pages = array();
foreach ($pages as $key => $callback) {
if (is_string($callback) && preg_match('/^secure /', $callback))
$key .= '(/(?P[a-f0-9]{8}))?';
- $key = str_replace('\%b', $config['board_regex'], $key);
+ $key = str_replace('\%b', '?P' . sprintf(substr($config['board_path'], 0, -1), $config['board_regex']), $key);
$new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!u'] = $callback;
}
$pages = $new_pages;
@@ -118,6 +118,15 @@ foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) {
$matches = array_slice($matches, 1);
+ if (isset($matches['board'])) {
+ $board_match = $matches['board'];
+ unset($matches['board']);
+ $key = array_search($board_match, $matches);
+ if (preg_match('/^' . sprintf(substr($config['board_path'], 0, -1), '(' . $config['board_regex'] . ')') . '$/u', $matches[$key], $board_match)) {
+ $matches[$key] = $board_match[1];
+ }
+ }
+
if (is_string($handler) && preg_match('/^secure(_POST)? /', $handler, $m)) {
$secure_post_only = isset($m[1]);
if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
--
cgit v1.3
From 056a6001aceddcf707974577d3566b1a166f01ec Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Sat, 3 Aug 2013 02:01:52 -0400
Subject: Erorr handling update
---
inc/database.php | 12 ++++++------
inc/display.php | 6 +++++-
inc/functions.php | 25 +++++++++++++------------
mod.php | 2 +-
4 files changed, 25 insertions(+), 20 deletions(-)
(limited to 'mod.php')
diff --git a/inc/database.php b/inc/database.php
index 95dfc775..24959d0c 100644
--- a/inc/database.php
+++ b/inc/database.php
@@ -121,14 +121,14 @@ function query($query) {
return $pdo->query($query);
}
-function db_error($PDOStatement=null) {
- global $pdo;
+function db_error($PDOStatement = null) {
+ global $pdo, $db_error;
if (isset($PDOStatement)) {
- $err = $PDOStatement->errorInfo();
- return $err[2];
+ $db_error = $PDOStatement->errorInfo();
+ return $db_error[2];
}
- $err = $pdo->errorInfo();
- return $err[2];
+ $db_error = $pdo->errorInfo();
+ return $db_error[2];
}
diff --git a/inc/display.php b/inc/display.php
index 4972d563..dddb6559 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -58,7 +58,7 @@ function createBoardlist($mod=false) {
}
function error($message, $priority = true, $debug_stuff = false) {
- global $board, $mod, $config;
+ global $board, $mod, $config, $db_error;
if ($config['syslog'] && $priority !== false) {
// Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant.
@@ -70,6 +70,10 @@ function error($message, $priority = true, $debug_stuff = false) {
die('Error: ' . $message . "\n");
}
+ if ($config['debug'] && isset($db_error)) {
+ $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error);
+ }
+
die(Element('page.html', array(
'config' => $config,
'title' => _('Error'),
diff --git a/inc/functions.php b/inc/functions.php
index b6bdd809..6c903663 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -155,19 +155,9 @@ function loadConfig() {
}
if ($config['verbose_errors']) {
- set_error_handler(function($errno, $errstr, $errfile, $errline) {
- if (error_reporting() == 0)
- return false; // Looks like this warning was suppressed by the @ operator.
- error(utf8tohtml($errstr), true, array(
- 'file' => $errfile,
- 'line' => $errline,
- 'errno' => $errno,
- 'error' => $errstr,
- 'backtrace' => array_slice(debug_backtrace(), 1)
- ));
- });
+ set_error_handler('verbose_error_handler');
error_reporting(E_ALL);
- ini_set('display_errors', true);
+ ini_set('display_errors', false);
ini_set('html_errors', false);
}
@@ -244,6 +234,17 @@ function _syslog($priority, $message) {
}
}
+function verbose_error_handler($errno, $errstr, $errfile, $errline) {
+ if (error_reporting() == 0)
+ return false; // Looks like this warning was suppressed by the @ operator.
+ error(utf8tohtml($errstr), true, array(
+ 'file' => $errfile . ':' . $errline,
+ 'errno' => $errno,
+ 'error' => $errstr,
+ 'backtrace' => array_slice(debug_backtrace(), 1)
+ ));
+}
+
function create_antibot($board, $thread = null) {
require_once dirname(__FILE__) . '/anti-bot.php';
diff --git a/mod.php b/mod.php
index ee05c349..bdc89b87 100644
--- a/mod.php
+++ b/mod.php
@@ -23,7 +23,7 @@ $query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) :
$pages = array(
'' => ':?/', // redirect to dashboard
'/' => 'dashboard', // dashboard
- '/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
+ '/confir(m/(.+)' => 'confirm', // confirm action (if javascript didn't work)
'/logout' => 'logout', // logout
'/users' => 'users', // manage users
--
cgit v1.3
From 68403f613e441894f22aa9087e3e535d2712511f Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Sat, 3 Aug 2013 02:03:44 -0400
Subject: Didn't mean to commit that
---
mod.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'mod.php')
diff --git a/mod.php b/mod.php
index bdc89b87..ee05c349 100644
--- a/mod.php
+++ b/mod.php
@@ -23,7 +23,7 @@ $query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) :
$pages = array(
'' => ':?/', // redirect to dashboard
'/' => 'dashboard', // dashboard
- '/confir(m/(.+)' => 'confirm', // confirm action (if javascript didn't work)
+ '/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
'/logout' => 'logout', // logout
'/users' => 'users', // manage users
--
cgit v1.3
From 424de7561dcd1476c64f42f86af2a42fa2c39814 Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Sat, 3 Aug 2013 06:26:17 -0400
Subject: Web config editor: board configs
---
inc/mod/pages.php | 50 ++++++++++++++++--------
mod.php | 73 ++++++++++++++++++------------------
templates/mod/config-editor-php.html | 44 +++++++++++++++-------
templates/mod/config-editor.html | 23 ++++++++++--
4 files changed, 122 insertions(+), 68 deletions(-)
(limited to 'mod.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 13520871..38bdac8b 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -1941,30 +1941,43 @@ function mod_report_dismiss($id, $all = false) {
}
-function mod_config() {
- global $config, $mod;
+function mod_config($board_config = false) {
+ global $config, $mod, $board;
+
+ if ($board_config && !openBoard($board_config))
+ error($config['error']['noboard']);
- if (!hasPermission($config['mod']['edit_config']))
+ if (!hasPermission($config['mod']['edit_config'], $board_config))
error($config['error']['noaccess']);
+ $config_file = $board_config ? $board['dir'] . 'config.php' : 'inc/instance-config.php';
+
if ($config['mod']['config_editor_php']) {
- $readonly = !is_writable('inc/instance-config.php');
+ $readonly = !(is_file($config_file) ? is_writable($config_file) : is_writable(dirname($config_file)));
if (!$readonly && isset($_POST['code'])) {
$code = $_POST['code'];
- file_put_contents('inc/instance-config.php', $code);
+ file_put_contents($config_file, $code);
header('Location: ?/config', true, $config['redirect_http']);
return;
}
- $instance_config = file_get_contents('inc/instance-config.php');
+ $instance_config = @file_get_contents($config_file);
+ if ($instance_config === false) {
+ $instance_config = " $instance_config, 'readonly' => $readonly));
+ mod_page(_('Config editor'), 'mod/config-editor-php.html', array(
+ 'php' => $instance_config,
+ 'readonly' => $readonly,
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'file' => $config_file
+ ));
return;
}
-
require_once 'inc/mod/config-editor.php';
$conf = config_vars();
@@ -2012,7 +2025,7 @@ function mod_config() {
$config_append .= ' = ';
- if ($var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
+ if (@$var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
$perm_array = array(
JANITOR => 'JANITOR',
MOD => 'MOD',
@@ -2029,8 +2042,9 @@ function mod_config() {
if (!empty($config_append)) {
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
-
- if (!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) {
+ if (!is_file($config_file))
+ $config_append = "Tinyboard could not write to inc/instance-config.php with the ammended configuration, probably due to a permissions error.
- You may proceed with these changes manually by copying and pasting the following code to the end of inc/instance-config.php:
+ Tinyboard could not write to ' . $config_file . ' with the ammended configuration, probably due to a permissions error.
+ You may proceed with these changes manually by copying and pasting the following code to the end of ' . $config_file . ':
';
echo Element('page.html', $page);
@@ -2048,12 +2062,18 @@ function mod_config() {
}
}
- header('Location: ?/', true, $config['redirect_http']);
+ header('Location: ?/config', true, $config['redirect_http']);
exit;
}
- mod_page(_('Config editor'), 'mod/config-editor.html', array('conf' => $conf));
+ mod_page(_('Config editor') . ($board_config ? ': ' . sprintf($config['board_abbreviation'], $board_config) : ''),
+ 'mod/config-editor.html', array(
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'conf' => $conf,
+ 'file' => $config_file
+ ));
}
function mod_themes_list() {
diff --git a/mod.php b/mod.php
index ee05c349..742eeefb 100644
--- a/mod.php
+++ b/mod.php
@@ -21,64 +21,65 @@ if (get_magic_quotes_gpc()) {
$query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) : '';
$pages = array(
- '' => ':?/', // redirect to dashboard
- '/' => 'dashboard', // dashboard
+ '' => ':?/', // redirect to dashboard
+ '/' => 'dashboard', // dashboard
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
- '/logout' => 'logout', // logout
+ '/logout' => 'logout', // logout
- '/users' => 'users', // manage users
- '/users/(\d+)' => 'user', // edit user
- '/users/(\d+)/(promote|demote)' => 'user_promote', // prmote/demote user
+ '/users' => 'users', // manage users
+ '/users/(\d+)' => 'user', // edit user
+ '/users/(\d+)/(promote|demote)' => 'user_promote', // prmote/demote user
'/users/new' => 'user_new', // create a new user
'/new_PM/([^/]+)' => 'new_pm', // create a new pm
- '/PM/(\d+)(/reply)?' => 'pm', // read a pm
- '/inbox' => 'inbox', // pm inbox
+ '/PM/(\d+)(/reply)?' => 'pm', // read a pm
+ '/inbox' => 'inbox', // pm inbox
'/noticeboard' => 'noticeboard', // view noticeboard
- '/noticeboard/(\d+)' => 'noticeboard', // view noticeboard
- '/noticeboard/delete/(\d+)' => 'noticeboard_delete',// delete from noticeboard
- '/log' => 'log', // modlog
- '/log/(\d+)' => 'log', // modlog
+ '/noticeboard/(\d+)' => 'noticeboard', // view noticeboard
+ '/noticeboard/delete/(\d+)' => 'noticeboard_delete', // delete from noticeboard
+ '/log' => 'log', // modlog
+ '/log/(\d+)' => 'log', // modlog
'/log:([^/]+)' => 'user_log', // modlog
- '/log:([^/]+)/(\d+)' => 'user_log', // modlog
- '/news' => 'news', // view news
- '/news/(\d+)' => 'news', // view news
- '/news/delete/(\d+)' => 'news_delete', // delete from news
+ '/log:([^/]+)/(\d+)' => 'user_log', // modlog
+ '/news' => 'news', // view news
+ '/news/(\d+)' => 'news', // view news
+ '/news/delete/(\d+)' => 'news_delete', // delete from news
'/edit/(\%b)' => 'edit_board', // edit board details
'/new-board' => 'new_board', // create a new board
- '/rebuild' => 'rebuild', // rebuild static files
- '/reports' => 'reports', // report queue
- '/reports/(\d+)/dismiss(all)?' => 'report_dismiss', // dismiss a report
+ '/rebuild' => 'rebuild', // rebuild static files
+ '/reports' => 'reports', // report queue
+ '/reports/(\d+)/dismiss(all)?' => 'report_dismiss', // dismiss a report
- '/IP/([\w.:]+)' => 'ip', // view ip address
+ '/IP/([\w.:]+)' => 'ip', // view ip address
'/IP/([\w.:]+)/remove_note/(\d+)' => 'ip_remove_note', // remove note from ip address
- '/bans' => 'bans', // ban list
- '/bans/(\d+)' => 'bans', // ban list
+ '/bans' => 'bans', // ban list
+ '/bans/(\d+)' => 'bans', // ban list
- '/search' => 'search_redirect', // search
+ '/search' => 'search_redirect', // search
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
- '/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
+ '/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
// CSRF-protected moderator actions
- '/ban' => 'secure_POST ban', // new ban
- '/(\%b)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
- '/(\%b)/move/(\d+)' => 'secure_POST move', // move thread
+ '/ban' => 'secure_POST ban', // new ban
+ '/(\%b)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
+ '/(\%b)/move/(\d+)' => 'secure_POST move', // move thread
'/(\%b)/edit(_raw)?/(\d+)' => 'secure_POST edit_post', // edit post
- '/(\%b)/delete/(\d+)' => 'secure delete', // delete post
- '/(\%b)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
+ '/(\%b)/delete/(\d+)' => 'secure delete', // delete post
+ '/(\%b)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
'/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
- '/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
- '/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
- '/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
+ '/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
+ '/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
+ '/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
- '/themes' => 'themes_list', // manage themes
+ '/themes' => 'themes_list', // manage themes
'/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme
- '/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme
- '/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
+ '/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme
+ '/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
- '/config' => 'config', // config editor
+ '/config' => 'config', // config editor
+ '/config/(\%b)' => 'config', // config editor
// these pages aren't listed in the dashboard without $config['debug']
'/debug/antispam' => 'debug_antispam',
diff --git a/templates/mod/config-editor-php.html b/templates/mod/config-editor-php.html
index 54c398e4..4f76b5dd 100644
--- a/templates/mod/config-editor-php.html
+++ b/templates/mod/config-editor-php.html
@@ -1,17 +1,35 @@
-{% if readonly %}
- Tinyboard does not have the required permissions to edit inc/instance-config.php. To make changes, you will need to change the file's permissions first or manually edit the code.
-{% endif %}
-
-
-{% if not readonly %}