The version of vichan running on lainchan.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

204 строки
7.8KB

  1. <?php
  2. /*
  3. * Copyright (c) 2010-2014 Tinyboard Development Group
  4. */
  5. require_once 'inc/functions.php';
  6. if ($config['debug'])
  7. $parse_start_time = microtime(true);
  8. require_once 'inc/bans.php';
  9. require_once 'inc/mod/pages.php';
  10. check_login(true);
  11. $query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : '';
  12. $pages = array(
  13. '' => ':?/', // redirect to dashboard
  14. '/' => 'dashboard', // dashboard
  15. '/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
  16. '/logout' => 'secure logout', // logout
  17. '/users' => 'users', // manage users
  18. '/users/(\d+)/(promote|demote)' => 'secure user_promote', // prmote/demote user
  19. '/users/(\d+)' => 'secure_POST user', // edit user
  20. '/users/new' => 'secure_POST user_new', // create a new user
  21. '/new_PM/([^/]+)' => 'secure_POST new_pm', // create a new pm
  22. '/PM/(\d+)(/reply)?' => 'pm', // read a pm
  23. '/inbox' => 'inbox', // pm inbox
  24. '/log' => 'log', // modlog
  25. '/log/(\d+)' => 'log', // modlog
  26. '/log:([^/:]+)' => 'user_log', // modlog
  27. '/log:([^/:]+)/(\d+)' => 'user_log', // modlog
  28. '/log:b:([^/]+)' => 'board_log', // modlog
  29. '/log:b:([^/]+)/(\d+)' => 'board_log', // modlog
  30. '/edit_news' => 'secure_POST news', // view news
  31. '/edit_news/(\d+)' => 'secure_POST news', // view news
  32. '/edit_news/delete/(\d+)' => 'secure news_delete', // delete from news
  33. '/edit_pages(?:/?(\%b)?)' => 'secure_POST pages',
  34. '/edit_page/(\d+)' => 'secure_POST edit_page',
  35. '/edit_pages/delete/([a-z0-9]+)' => 'secure delete_page',
  36. '/edit_pages/delete/([a-z0-9]+)/(\%b)' => 'secure delete_page_board',
  37. '/noticeboard' => 'secure_POST noticeboard', // view noticeboard
  38. '/noticeboard/(\d+)' => 'secure_POST noticeboard', // view noticeboard
  39. '/noticeboard/delete/(\d+)' => 'secure noticeboard_delete', // delete from noticeboard
  40. '/edit/(\%b)' => 'secure_POST edit_board', // edit board details
  41. '/new-board' => 'secure_POST new_board', // create a new board
  42. '/rebuild' => 'secure_POST rebuild', // rebuild static files
  43. '/reports' => 'reports', // report queue
  44. '/reports/(\d+)/dismiss(all)?' => 'secure report_dismiss', // dismiss a report
  45. '/IP/([\w.:]+)' => 'secure_POST ip', // view ip address
  46. '/IP/([\w.:]+)/remove_note/(\d+)' => 'secure ip_remove_note', // remove note from ip address
  47. '/ban' => 'secure_POST ban', // new ban
  48. '/bans' => 'secure_POST bans', // ban list
  49. '/bans.json' => 'secure bans_json', // ban list JSON
  50. '/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
  51. '/recent/(\d+)' => 'recent_posts', // view recent posts
  52. '/search' => 'search_redirect', // search
  53. '/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
  54. '/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
  55. '/(\%b)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
  56. '/(\%b)/move/(\d+)' => 'secure_POST move', // move thread
  57. '/(\%b)/move_reply/(\d+)' => 'secure_POST move_reply', // move reply
  58. '/(\%b)/edit(_raw)?/(\d+)' => 'secure_POST edit_post', // edit post
  59. '/(\%b)/delete/(\d+)' => 'secure delete', // delete post
  60. '/(\%b)/deletefile/(\d+)/(\d+)' => 'secure deletefile', // delete file from post
  61. '/(\%b+)/spoiler/(\d+)/(\d+)' => 'secure spoiler_image', // spoiler file
  62. '/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
  63. '/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
  64. '/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
  65. '/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
  66. '/themes' => 'themes_list', // manage themes
  67. '/themes/(\w+)' => 'secure_POST theme_configure', // configure/reconfigure theme
  68. '/themes/(\w+)/rebuild' => 'secure theme_rebuild', // rebuild theme
  69. '/themes/(\w+)/uninstall' => 'secure theme_uninstall', // uninstall theme
  70. '/config' => 'secure_POST config', // config editor
  71. '/config/(\%b)' => 'secure_POST config', // config editor
  72. // these pages aren't listed in the dashboard without $config['debug']
  73. '/debug/antispam' => 'debug_antispam',
  74. '/debug/recent' => 'debug_recent_posts',
  75. '/debug/apc' => 'debug_apc',
  76. '/debug/sql' => 'secure_POST debug_sql',
  77. // This should always be at the end:
  78. '/(\%b)/' => 'view_board',
  79. '/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board',
  80. '/(\%b)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_board',
  81. '/(\%b)/' . preg_quote($config['dir']['res'], '!') .
  82. str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50',
  83. '/(\%b)/' . preg_quote($config['dir']['res'], '!') .
  84. str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
  85. '/(\%b)/' . preg_quote($config['dir']['res'], '!') .
  86. str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
  87. '/(\%b)/' . preg_quote($config['dir']['res'], '!') .
  88. str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread',
  89. );
  90. if (!$mod) {
  91. $pages = array('!^(.+)?$!' => 'login');
  92. } elseif (isset($_GET['status'], $_GET['r'])) {
  93. header('Location: ' . $_GET['r'], true, (int)$_GET['status']);
  94. exit;
  95. }
  96. if (isset($config['mod']['custom_pages'])) {
  97. $pages = array_merge($pages, $config['mod']['custom_pages']);
  98. }
  99. $new_pages = array();
  100. foreach ($pages as $key => $callback) {
  101. if (is_string($callback) && preg_match('/^secure /', $callback))
  102. $key .= '(/(?P<token>[a-f0-9]{8}))?';
  103. $key = str_replace('\%b', '?P<board>' . sprintf(substr($config['board_path'], 0, -1), $config['board_regex']), $key);
  104. $new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!u'] = $callback;
  105. }
  106. $pages = $new_pages;
  107. foreach ($pages as $uri => $handler) {
  108. if (preg_match($uri, $query, $matches)) {
  109. $matches = array_slice($matches, 1);
  110. if (isset($matches['board'])) {
  111. $board_match = $matches['board'];
  112. unset($matches['board']);
  113. $key = array_search($board_match, $matches);
  114. if (preg_match('/^' . sprintf(substr($config['board_path'], 0, -1), '(' . $config['board_regex'] . ')') . '$/u', $matches[$key], $board_match)) {
  115. $matches[$key] = $board_match[1];
  116. }
  117. }
  118. if (is_string($handler) && preg_match('/^secure(_POST)? /', $handler, $m)) {
  119. $secure_post_only = isset($m[1]);
  120. if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
  121. $token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false);
  122. if ($token === false) {
  123. if ($secure_post_only)
  124. error($config['error']['csrf']);
  125. else {
  126. mod_confirm(substr($query, 1));
  127. exit;
  128. }
  129. }
  130. // CSRF-protected page; validate security token
  131. $actual_query = preg_replace('!/([a-f0-9]{8})$!', '', $query);
  132. if ($token != make_secure_link_token(substr($actual_query, 1))) {
  133. error($config['error']['csrf']);
  134. }
  135. }
  136. $handler = preg_replace('/^secure(_POST)? /', '', $handler);
  137. }
  138. if ($config['debug']) {
  139. $debug['mod_page'] = array(
  140. 'req' => $query,
  141. 'match' => $uri,
  142. 'handler' => $handler,
  143. );
  144. $debug['time']['parse_mod_req'] = '~' . round((microtime(true) - $parse_start_time) * 1000, 2) . 'ms';
  145. }
  146. if (is_string($handler)) {
  147. if ($handler[0] == ':') {
  148. header('Location: ' . substr($handler, 1), true, $config['redirect_http']);
  149. } elseif (is_callable("mod_page_$handler")) {
  150. call_user_func_array("mod_page_$handler", $matches);
  151. } elseif (is_callable("mod_$handler")) {
  152. call_user_func_array("mod_$handler", $matches);
  153. } else {
  154. error("Mod page '$handler' not found!");
  155. }
  156. } elseif (is_callable($handler)) {
  157. call_user_func_array($handler, $matches);
  158. } else {
  159. error("Mod page '$handler' not a string, and not callable!");
  160. }
  161. exit;
  162. }
  163. }
  164. error($config['error']['404']);