PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/emergency.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 289 lines | 158 code | 47 blank | 84 comment | 33 complexity | 75cc3c27539a83fbf7c252ca7a6235f6 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Christian Knerr (cback) - (www.cback.de)
  14. *
  15. */
  16. /**
  17. * <b>emergency.php</b>
  18. * A small emergency console to reset the last functioning Board configuration
  19. * or reset the domain settings. Please remember that <b>this file is not part of
  20. * phpBB</b> so it is really important that you exactly READ the instructions
  21. * before you use the file!
  22. *
  23. * @author Christian Knerr (cback)
  24. * @package ctracker
  25. * @version 5.0.0
  26. * @since 16.08.2006 - 00:20:13
  27. * @copyright (c) 2006 www.cback.de
  28. */
  29. // Warning........: File is not part of phpBB itself!
  30. /*
  31. * Comment out the following code part to use the Emergency Console. If you stop
  32. * working with this file please remember to block this file again!! If not
  33. * everyone could access it and use the functions in here!
  34. *
  35. * If you want access the recovery console just enter the url to that file into your Browser for example:
  36. *
  37. * www.example.com/emergency.php
  38. *
  39. *
  40. * Our suggestion is to remove this file completely from your Board if you don't need it!
  41. */
  42. die("<img src=\"admin/console/console_pic.png\" border=\"0\" alt=\"ECON\" title=\"ECON\"><br /><br /><b>Emergency Console Blocked!</b><br />See more instructions in this file!");
  43. /*
  44. * Define some vars & constants we need
  45. */
  46. define('IN_ICYPHOENIX', true);
  47. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  48. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  49. error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
  50. set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
  51. // The following code (unsetting globals)
  52. // Thanks to Matt Kavanagh and Stefan Esser for providing feedback as well as patch files
  53. // PHP5 with register_long_arrays off?
  54. if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off'))
  55. {
  56. $HTTP_POST_VARS = $_POST;
  57. $HTTP_GET_VARS = $_GET;
  58. $HTTP_SERVER_VARS = $_SERVER;
  59. $HTTP_COOKIE_VARS = $_COOKIE;
  60. $HTTP_ENV_VARS = $_ENV;
  61. $HTTP_POST_FILES = $_FILES;
  62. // _SESSION is the only superglobal which is conditionally set
  63. if (isset($_SESSION))
  64. {
  65. $HTTP_SESSION_VARS = $_SESSION;
  66. }
  67. }
  68. // Protect against GLOBALS tricks
  69. if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_POST_FILES['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS']) || isset($HTTP_COOKIE_VARS['GLOBALS']))
  70. {
  71. die('Hacking attempt');
  72. }
  73. // Protect against HTTP_SESSION_VARS tricks
  74. if (isset($HTTP_SESSION_VARS) && !is_array($HTTP_SESSION_VARS))
  75. {
  76. die('Hacking attempt');
  77. }
  78. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
  79. {
  80. // PHP4+ path
  81. $not_unset = array('HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_SERVER_VARS', 'HTTP_SESSION_VARS', 'HTTP_ENV_VARS', 'HTTP_POST_FILES');
  82. // Not only will array_merge give a warning if a parameter
  83. // is not an array, it will actually fail. So we check if
  84. // HTTP_SESSION_VARS has been initialised.
  85. if (!isset($HTTP_SESSION_VARS) || !is_array($HTTP_SESSION_VARS))
  86. {
  87. $HTTP_SESSION_VARS = array();
  88. }
  89. // Merge all into one extremely huge array; unset
  90. // this later
  91. $input = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);
  92. unset($input['input']);
  93. unset($input['not_unset']);
  94. while (list($var,) = @each($input))
  95. {
  96. if (in_array($var, $not_unset))
  97. {
  98. die('Hacking attempt!');
  99. }
  100. unset(${$var});
  101. }
  102. unset($input);
  103. }
  104. /*
  105. * Include some files we need for the Emergency Console
  106. */
  107. include(IP_ROOT_PATH . 'config.' . PHP_EXT);
  108. include(IP_ROOT_PATH . 'includes/db.' . PHP_EXT);
  109. include(IP_ROOT_PATH . 'includes/template.' . PHP_EXT);
  110. define('PREFIX', $table_prefix);
  111. /*
  112. * DB Connection, Template and Adminclass
  113. */
  114. $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname);
  115. $template = new Template();
  116. /*
  117. * Unset unused vars
  118. */
  119. unset($dbname); // Unset Database Name
  120. unset($dbuser); // Unset Database Username
  121. unset($dbpasswd); // Unset Database Password var
  122. unset($db->password); // Unset Database Password in DB Class
  123. unset($sql); // Unset maybe injected SQL Commands in this var
  124. function phpbb_realpath($path)
  125. {
  126. return (!@function_exists('realpath') || !@realpath(IP_ROOT_PATH . 'includes/functions.' . PHP_EXT)) ? $path : @realpath($path);
  127. }
  128. function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
  129. {
  130. die("<html>\n<body bgcolor=\"#000000\">\n<span style=\"color:#FFFFFF;\">" . $msg_title . "</span>\n<br /><br />\n" . $msg_text . "</body>\n</html>");
  131. }
  132. /*
  133. * The script itself :)
  134. */
  135. $template->set_filenames(array('ct_body' => IP_ROOT_PATH . 'includes/ctracker/admin/console/emergency.tpl'));
  136. /*
  137. * Console Operations
  138. */
  139. $mode = $HTTP_GET_VARS['mode'];
  140. if ($mode == 'restore')
  141. {
  142. // Drop existing Config Table
  143. $sql = 'DROP TABLE IF EXISTS ' . PREFIX . 'config';
  144. $result = $db->sql_query($sql);
  145. // Create Config table
  146. $sql = 'CREATE TABLE ' . PREFIX . 'config (
  147. `config_name` varchar(190) NOT NULL ,
  148. `config_value` text NOT NULL ,
  149. PRIMARY KEY (`config_name`)
  150. )';
  151. $result = $db->sql_query($sql);
  152. // Insert config data
  153. $sql = 'SELECT * FROM ' . PREFIX . 'ctracker_backup';
  154. $result = $db->sql_query($sql);
  155. while ( $row = $db->sql_fetchrow($result) )
  156. {
  157. $sql2 = 'INSERT INTO ' . PREFIX . 'config (`config_name`, `config_value`) VALUES (\'' . $db->sql_escape($row['config_name']) . '\', \'' . $db->sql_escape($row['config_value']) . '\')';
  158. $result2 = $db->sql_query($sql2);
  159. }
  160. // Remove Backup Timestamp
  161. $sql = 'DELETE FROM ' . PREFIX . 'config WHERE config_name = \'ct_last_backup\'';
  162. $result = $db->sql_query($sql);
  163. $template->assign_block_vars('ok', array());
  164. }
  165. else if ( $mode == 'psrt' )
  166. {
  167. $sql = "UPDATE " . PREFIX . "config SET
  168. config_value = '" . $db->sql_escape($HTTP_POST_VARS['cookie_name']) . "'
  169. WHERE config_name = 'cookie_name'";
  170. $result = $db->sql_query($sql);
  171. $sql = "UPDATE " . PREFIX . "config SET
  172. config_value = '" . $db->sql_escape($HTTP_POST_VARS['cookie_path']) . "'
  173. WHERE config_name = 'cookie_path'";
  174. $result = $db->sql_query($sql);
  175. $sql = "UPDATE " . PREFIX . "config SET
  176. config_value = '" . $db->sql_escape($HTTP_POST_VARS['cookie_domain']) . "'
  177. WHERE config_name = 'cookie_domain'";
  178. $result = $db->sql_query($sql);
  179. $sql = "UPDATE " . PREFIX . "config SET
  180. config_value = '" . $db->sql_escape($HTTP_POST_VARS['cookie_secure']) . "'
  181. WHERE config_name = 'cookie_secure'";
  182. $result = $db->sql_query($sql);
  183. $sql = "UPDATE " . PREFIX . "config SET
  184. config_value = '" . $db->sql_escape($HTTP_POST_VARS['server_name']) . "'
  185. WHERE config_name = 'server_name'";
  186. $result = $db->sql_query($sql);
  187. $sql = "UPDATE " . PREFIX . "config SET
  188. config_value = '" . $db->sql_escape($HTTP_POST_VARS['server_port']) . "'
  189. WHERE config_name = 'server_port'";
  190. $result = $db->sql_query($sql);
  191. $sql = "UPDATE " . PREFIX . "config SET
  192. config_value = '" . $db->sql_escape($HTTP_POST_VARS['script_path']) . "'
  193. WHERE config_name = 'script_path'";
  194. $result = $db->sql_query($sql);
  195. $sql = "UPDATE " . PREFIX . "config SET
  196. config_value = '" . $db->sql_escape($HTTP_POST_VARS['session_length']) . "'
  197. WHERE config_name = 'session_length'";
  198. $result = $db->sql_query($sql);
  199. $template->assign_block_vars('ok', array());
  200. }
  201. /*
  202. * Load backup status
  203. */
  204. $save_status = '';
  205. $saved_now = false;
  206. $sql = 'SELECT * FROM ' . PREFIX . 'ctracker_backup WHERE config_name = \'ct_last_backup\'';
  207. $db->sql_return_on_error(true);
  208. $result = $db->sql_query($sql);
  209. $db->sql_return_on_error(false);
  210. if (!$result)
  211. {
  212. $save_status = 'no configuration backup available';
  213. }
  214. else
  215. {
  216. $saved_now = true;
  217. while ($row = $db->sql_fetchrow($result))
  218. {
  219. $backup[$row['config_name']] = $row['config_value'];
  220. }
  221. $save_status = gmdate('d.m.Y - H:i', $backup['ct_last_backup']);
  222. }
  223. /*
  224. * Send some vars to the template
  225. */
  226. $template->assign_vars(array(
  227. 'YEAR' => date(Y),
  228. 'BACKUP' => $save_status,
  229. 'PHP_EXT' => PHP_EXT,
  230. 'RESTORE_OUTPUT' => ($saved_now)? '<a href="emergency.php?mode=restore" style="color:#FDFF00">&raquo; Click here to restore configuration table now! &laquo;</a>': ''
  231. )
  232. );
  233. // Generate the page
  234. $template->pparse('ct_body');
  235. /*
  236. * Disconnect from Database
  237. */
  238. if (!empty($db))
  239. {
  240. $db->sql_close();
  241. }
  242. ?>