The version of vichan running on lainchan.org
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

198 linhas
7.3KB

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