2010-12-01 05:53:11 -05:00
|
|
|
<?php
|
2012-04-11 12:49:22 -04:00
|
|
|
|
|
|
|
/*
|
2013-01-20 05:23:46 -05:00
|
|
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
2012-04-11 12:49:22 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
require 'inc/functions.php';
|
2012-04-12 12:11:41 -04:00
|
|
|
require 'inc/mod/pages.php';
|
2013-01-29 12:45:38 -05:00
|
|
|
require 'inc/mod/auth.php';
|
2012-04-11 12:49:22 -04:00
|
|
|
|
2013-08-29 18:39:11 -04:00
|
|
|
if ($config['debug'])
|
|
|
|
$parse_start_time = microtime(true);
|
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
// Fix for magic quotes
|
2012-04-11 12:49:22 -04:00
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
function strip_array($var) {
|
2012-04-12 07:56:01 -04:00
|
|
|
return is_array($var) ? array_map('strip_array', $var) : stripslashes($var);
|
2012-04-11 12:49:22 -04:00
|
|
|
}
|
2010-12-01 05:53:11 -05:00
|
|
|
|
2012-04-11 12:49:22 -04:00
|
|
|
$_GET = strip_array($_GET);
|
|
|
|
$_POST = strip_array($_POST);
|
|
|
|
}
|
|
|
|
|
2013-08-04 22:49:38 -04:00
|
|
|
$query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : '';
|
2012-04-11 12:49:22 -04:00
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
$pages = array(
|
2013-08-03 21:04:45 -04:00
|
|
|
'' => ':?/', // redirect to dashboard
|
|
|
|
'/' => 'dashboard', // dashboard
|
2013-08-03 02:03:44 -04:00
|
|
|
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
|
2013-08-03 21:04:45 -04:00
|
|
|
'/logout' => 'logout', // logout
|
2012-04-16 02:40:24 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/users' => 'users', // manage users
|
|
|
|
'/users/(\d+)' => 'user', // edit user
|
|
|
|
'/users/(\d+)/(promote|demote)' => 'user_promote', // prmote/demote user
|
2012-05-05 22:44:37 -04:00
|
|
|
'/users/new' => 'user_new', // create a new user
|
|
|
|
'/new_PM/([^/]+)' => 'new_pm', // create a new pm
|
2013-08-03 21:04:45 -04:00
|
|
|
'/PM/(\d+)(/reply)?' => 'pm', // read a pm
|
|
|
|
'/inbox' => 'inbox', // pm inbox
|
2012-04-12 20:41:30 -04:00
|
|
|
|
2012-05-05 22:44:37 -04:00
|
|
|
'/noticeboard' => 'noticeboard', // view noticeboard
|
2013-08-03 21:04:45 -04:00
|
|
|
'/noticeboard/(\d+)' => 'noticeboard', // view noticeboard
|
|
|
|
'/noticeboard/delete/(\d+)' => 'noticeboard_delete', // delete from noticeboard
|
|
|
|
'/log' => 'log', // modlog
|
|
|
|
'/log/(\d+)' => 'log', // modlog
|
2012-08-27 08:13:47 -04:00
|
|
|
'/log:([^/]+)' => 'user_log', // modlog
|
2013-08-03 21:04:45 -04:00
|
|
|
'/log:([^/]+)/(\d+)' => 'user_log', // modlog
|
|
|
|
'/news' => 'news', // view news
|
|
|
|
'/news/(\d+)' => 'news', // view news
|
|
|
|
'/news/delete/(\d+)' => 'news_delete', // delete from news
|
2012-05-05 11:33:10 -04:00
|
|
|
|
2013-07-31 02:08:55 -04:00
|
|
|
'/edit/(\%b)' => 'edit_board', // edit board details
|
2012-05-05 22:44:37 -04:00
|
|
|
'/new-board' => 'new_board', // create a new board
|
2012-05-05 11:33:10 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/rebuild' => 'rebuild', // rebuild static files
|
|
|
|
'/reports' => 'reports', // report queue
|
|
|
|
'/reports/(\d+)/dismiss(all)?' => 'report_dismiss', // dismiss a report
|
2012-04-14 08:28:21 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/IP/([\w.:]+)' => 'ip', // view ip address
|
2012-05-05 22:44:37 -04:00
|
|
|
'/IP/([\w.:]+)/remove_note/(\d+)' => 'ip_remove_note', // remove note from ip address
|
2013-08-03 21:04:45 -04:00
|
|
|
'/bans' => 'bans', // ban list
|
|
|
|
'/bans/(\d+)' => 'bans', // ban list
|
2013-09-20 22:51:23 -04:00
|
|
|
'/ban-appeals' => 'ban_appeals', // view ban appeals
|
2013-07-20 07:50:33 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/search' => 'search_redirect', // search
|
2013-07-20 12:05:42 -04:00
|
|
|
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
2013-08-03 21:04:45 -04:00
|
|
|
'/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
|
2012-08-27 01:19:05 -04:00
|
|
|
|
|
|
|
// CSRF-protected moderator actions
|
2013-08-03 21:04:45 -04:00
|
|
|
'/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
|
2013-08-03 06:26:17 -04:00
|
|
|
'/(\%b)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
|
2013-08-08 15:50:11 -04:00
|
|
|
'/(\%b+)/spoiler/(\d+)' => 'secure spoiler_image', // spoiler file
|
2013-08-03 21:04:45 -04:00
|
|
|
'/(\%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
|
2012-04-16 06:11:10 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/themes' => 'themes_list', // manage themes
|
2012-08-12 10:18:13 -04:00
|
|
|
'/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme
|
2013-08-03 21:04:45 -04:00
|
|
|
'/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme
|
|
|
|
'/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
|
2012-08-12 10:18:13 -04:00
|
|
|
|
2013-08-03 21:04:45 -04:00
|
|
|
'/config' => 'config', // config editor
|
2013-08-03 06:26:17 -04:00
|
|
|
'/config/(\%b)' => 'config', // config editor
|
2012-05-20 06:20:50 -04:00
|
|
|
|
2012-04-16 06:11:10 -04:00
|
|
|
// these pages aren't listed in the dashboard without $config['debug']
|
2012-05-05 22:44:37 -04:00
|
|
|
'/debug/antispam' => 'debug_antispam',
|
2013-01-25 06:18:03 -05:00
|
|
|
'/debug/recent' => 'debug_recent_posts',
|
2013-01-25 07:57:51 -05:00
|
|
|
'/debug/sql' => 'secure_POST debug_sql',
|
2012-04-11 12:49:22 -04:00
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
// This should always be at the end:
|
2013-07-31 02:08:55 -04:00
|
|
|
'/(\%b)/' => 'view_board',
|
|
|
|
'/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board',
|
|
|
|
'/(\%b)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_board',
|
|
|
|
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
|
2012-05-05 22:44:37 -04:00
|
|
|
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
|
2012-04-12 12:11:41 -04:00
|
|
|
);
|
|
|
|
|
2012-05-05 11:33:10 -04:00
|
|
|
|
|
|
|
if (!$mod) {
|
2013-01-29 06:11:33 -05:00
|
|
|
$pages = array('!^(.+)?$!' => 'login');
|
2012-05-05 11:33:10 -04:00
|
|
|
} elseif (isset($_GET['status'], $_GET['r'])) {
|
2012-05-05 22:29:54 -04:00
|
|
|
header('Location: ' . $_GET['r'], true, (int)$_GET['status']);
|
2012-05-05 22:44:37 -04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['mod']['custom_pages'])) {
|
2012-05-05 11:33:10 -04:00
|
|
|
$pages = array_merge($pages, $config['mod']['custom_pages']);
|
|
|
|
}
|
2012-04-12 12:11:41 -04:00
|
|
|
|
2012-05-05 22:44:37 -04:00
|
|
|
$new_pages = array();
|
|
|
|
foreach ($pages as $key => $callback) {
|
2013-07-15 08:17:49 -04:00
|
|
|
if (is_string($callback) && preg_match('/^secure /', $callback))
|
2012-08-27 01:19:05 -04:00
|
|
|
$key .= '(/(?P<token>[a-f0-9]{8}))?';
|
2013-08-02 20:52:58 -04:00
|
|
|
$key = str_replace('\%b', '?P<board>' . sprintf(substr($config['board_path'], 0, -1), $config['board_regex']), $key);
|
2013-07-31 02:08:55 -04:00
|
|
|
$new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!u'] = $callback;
|
2012-05-05 22:44:37 -04:00
|
|
|
}
|
|
|
|
$pages = $new_pages;
|
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
foreach ($pages as $uri => $handler) {
|
|
|
|
if (preg_match($uri, $query, $matches)) {
|
|
|
|
$matches = array_slice($matches, 1);
|
|
|
|
|
2013-08-02 20:52:58 -04:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 08:17:49 -04:00
|
|
|
if (is_string($handler) && preg_match('/^secure(_POST)? /', $handler, $m)) {
|
2012-08-27 01:19:05 -04:00
|
|
|
$secure_post_only = isset($m[1]);
|
|
|
|
if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
$token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false);
|
|
|
|
|
|
|
|
if ($token === false) {
|
|
|
|
if ($secure_post_only)
|
|
|
|
error($config['error']['csrf']);
|
|
|
|
else {
|
|
|
|
mod_confirm(substr($query, 1));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSRF-protected page; validate security token
|
|
|
|
$actual_query = preg_replace('!/([a-f0-9]{8})$!', '', $query);
|
|
|
|
if ($token != make_secure_link_token(substr($actual_query, 1))) {
|
|
|
|
error($config['error']['csrf']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$handler = preg_replace('/^secure(_POST)? /', '', $handler);
|
|
|
|
}
|
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
if ($config['debug']) {
|
|
|
|
$debug['mod_page'] = array(
|
|
|
|
'req' => $query,
|
|
|
|
'match' => $uri,
|
2013-08-29 18:39:11 -04:00
|
|
|
'handler' => $handler,
|
2012-04-11 12:49:22 -04:00
|
|
|
);
|
2013-08-29 18:39:11 -04:00
|
|
|
$debug['time']['parse_mod_req'] = '~' . round((microtime(true) - $parse_start_time) * 1000, 2) . 'ms';
|
2012-04-11 12:49:22 -04:00
|
|
|
}
|
|
|
|
|
2012-05-05 11:33:10 -04:00
|
|
|
if (is_string($handler)) {
|
|
|
|
if ($handler[0] == ':') {
|
|
|
|
header('Location: ' . substr($handler, 1), true, $config['redirect_http']);
|
|
|
|
} elseif (is_callable("mod_page_$handler")) {
|
|
|
|
call_user_func_array("mod_page_$handler", $matches);
|
|
|
|
} elseif (is_callable("mod_$handler")) {
|
|
|
|
call_user_func_array("mod_$handler", $matches);
|
|
|
|
} else {
|
|
|
|
error("Mod page '$handler' not found!");
|
|
|
|
}
|
|
|
|
} elseif (is_callable($handler)) {
|
|
|
|
call_user_func_array($handler, $matches);
|
2012-04-11 12:49:22 -04:00
|
|
|
} else {
|
2012-05-05 11:33:10 -04:00
|
|
|
error("Mod page '$handler' not a string, and not callable!");
|
2012-04-11 12:49:22 -04:00
|
|
|
}
|
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
exit;
|
2010-12-01 05:53:11 -05:00
|
|
|
}
|
2012-04-11 12:49:22 -04:00
|
|
|
}
|
2011-11-16 02:53:37 -05:00
|
|
|
|
2012-04-12 12:11:41 -04:00
|
|
|
error($config['error']['404']);
|
|
|
|
|