PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/blogs/install/debug.php

https://github.com/blueyed/b2evolution
PHP | 408 lines | 278 code | 67 blank | 63 comment | 19 complexity | a18bfdf84929df716c9c04551cf15019 MD5 | raw file
  1. <?php
  2. /**
  3. * This is the debug tool
  4. *
  5. * IF YOU ARE READING THIS IN YOUR WEB BROWSER, IT MEANS THAT PHP IS NOT PROPERLY INSTALLED
  6. * ON YOUR WEB SERVER. IF YOU DON'T KNOW WHAT THIS MEANS, CONTACT YOUR SERVER ADMINISTRATOR
  7. * OR YOUR HOSTING COMPANY.
  8. *
  9. * b2evolution - {@link http://b2evolution.net/}
  10. * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  11. * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
  12. *
  13. * @package install
  14. */
  15. /**
  16. * include config and default functions:
  17. */
  18. require_once dirname(__FILE__).'/../conf/_config.php';
  19. // Make the includes believe they are being called in the right place...
  20. define( 'EVO_MAIN_INIT', true );
  21. if( ! $config_is_done )
  22. { // Base config is not done yet, try to guess some values needed for correct display:
  23. $rsc_url = '../rsc/';
  24. }
  25. require_once $inc_path.'_core/_class'.floor(PHP_VERSION).'.funcs.php';
  26. require_once $inc_path.'_core/_misc.funcs.php';
  27. /**
  28. * Load locale related functions
  29. */
  30. require_once $inc_path.'locales/_locale.funcs.php';
  31. load_class( '_core/model/_log.class.php', 'Log');
  32. $Debuglog = new Log();
  33. load_class( '_core/model/_messages.class.php', 'Messages');
  34. $Messages = new Messages();
  35. /**
  36. * Load modules.
  37. *
  38. * This initializes table name aliases and is required before trying to connect to the DB.
  39. */
  40. load_class( '_core/model/_module.class.php', 'Module' );
  41. foreach( $modules as $module )
  42. {
  43. require_once $inc_path.$module.'/_'.$module.'.init.php';
  44. }
  45. load_class( '/_core/model/db/_db.class.php', 'DB' );
  46. load_class( '_core/model/_timer.class.php', 'Timer' );
  47. load_funcs( '_core/_url.funcs.php' );
  48. require_once dirname(__FILE__).'/_functions_install.php';
  49. /**
  50. * Check password
  51. */
  52. function debug_check_password()
  53. {
  54. global $errors, $debug_pwd;
  55. $password = param( 'password', 'string' );
  56. if( empty( $password ) )
  57. {
  58. $errors[] = T_('Please enter the password');
  59. return false;
  60. }
  61. else if( $password != $debug_pwd )
  62. {
  63. $errors[] = T_('Incorrect password');
  64. return false;
  65. }
  66. return true;
  67. }
  68. /**
  69. * Get debug config content
  70. *
  71. * @param boolean TRUE- to close file handle after getting the content
  72. * @return string Debug config
  73. */
  74. function debug_get_config( $close_handle = true )
  75. {
  76. global $errors, $file_overrides_name, $file_section_start, $file_section_end, $file_overrides_handle;
  77. // Get debug config from file
  78. $file_overrides_handle = @fopen( $file_overrides_name, 'r+' );
  79. $file_overrides_content = '';
  80. if( $file_overrides_handle )
  81. {
  82. while( !feof( $file_overrides_handle ) )
  83. {
  84. $file_overrides_content .= fgets( $file_overrides_handle, 4096 );
  85. }
  86. if( $close_handle )
  87. {
  88. fclose( $file_overrides_handle );
  89. }
  90. }
  91. else
  92. { // Bad file name or file has not the rights to read/write
  93. $errors[] = T_('Config file cannot be opened');
  94. return false;
  95. }
  96. return $file_overrides_content;
  97. }
  98. $Timer = new Timer('main');
  99. load_funcs('_core/_param.funcs.php');
  100. // Let the modules load/register what they need:
  101. modules_call_method( 'init' );
  102. /**
  103. * @var File name
  104. */
  105. $file_overrides_name = $conf_path.'_overrides_TEST.php';
  106. // The start and the end of the debug config
  107. $file_section_start = '// @@BEGIN debug.php section';
  108. $file_section_end = '// @@END debug.php section';
  109. param( 'action', 'string', '' );
  110. $errors = array();
  111. switch( $action )
  112. {
  113. case 'login':
  114. // Check password
  115. if( !debug_check_password() )
  116. { // Some errors exist, show the form with password again
  117. $action = 'password_form';
  118. break;
  119. }
  120. $action = 'config_form';
  121. $file_overrides_content = debug_get_config();
  122. // Get only part for editing
  123. $file_overrides_content = substr( $file_overrides_content, strpos( $file_overrides_content, $file_section_start ) + strlen( $file_section_start ) );
  124. $file_overrides_content = substr( $file_overrides_content, 0, strpos( $file_overrides_content, $file_section_end ) );
  125. $file_overrides_content = trim( $file_overrides_content );
  126. break;
  127. case 'update_config':
  128. // Update debug config
  129. if( !debug_check_password() )
  130. { // Some errors exist, show the form with password again
  131. $action = 'password_form';
  132. break;
  133. }
  134. $action = 'config_form';
  135. $file_overrides_content = param( 'content', 'raw' );
  136. $old_content = debug_get_config( false );
  137. if( count( $errors ) > 0)
  138. {
  139. if( $file_overrides_handle )
  140. {
  141. fclose( $file_overrides_handle );
  142. }
  143. break;
  144. }
  145. if( strpos( $old_content, $file_section_start ) !== false && strpos( $old_content, $file_section_end ) !== false )
  146. { // File contains correct section to edit
  147. $old_content_start = substr( $old_content, 0, strpos( $old_content, $file_section_start ) + strlen( $file_section_start ) );
  148. $old_content_end = substr( $old_content, strpos( $old_content, $file_section_end ) );
  149. }
  150. else
  151. { // Config editable start or end sections don't exist in the file, we should create them
  152. $is_php_tag_opened = strpos( $old_content, '<?' ) !== false;
  153. $is_php_tag_closed = strpos( $old_content, '?>' ) !== false;
  154. if( $is_php_tag_opened && $is_php_tag_closed )
  155. { // File contains the open and close tags
  156. $old_content_start = substr( $old_content, 0, strpos( $old_content, '?>' ) );
  157. $old_content_end = substr( $old_content, strpos( $old_content, '?>' ) );
  158. }
  159. elseif( !$is_php_tag_opened && !$is_php_tag_closed )
  160. { // File doesn't contain the open and close php tags, Add this at the file end
  161. $old_content_start = $old_content.'<?php'."\n";
  162. $old_content_end = '?>';
  163. }
  164. elseif( !$is_php_tag_closed )
  165. { // File doesn't contain only the close php tag, Insert new config text at the end
  166. $old_content_start = $old_content;
  167. $old_content_end = '';
  168. }
  169. $old_content_start = $old_content_start."\n".$file_section_start;
  170. $old_content_end = $file_section_end."\n".$old_content_end;
  171. }
  172. // Write new content into config
  173. ftruncate( $file_overrides_handle, 0 );
  174. fseek( $file_overrides_handle, 0 );
  175. fwrite( $file_overrides_handle, $old_content_start."\n".$file_overrides_content."\n".$old_content_end );
  176. fclose( $file_overrides_handle );
  177. $message = T_('Debug config has been changed');
  178. break;
  179. default:
  180. if( file_exists( $file_overrides_name ) )
  181. { // Display a form to log in if file already exists
  182. $action = 'password_form';
  183. }
  184. break;
  185. }
  186. switch( $action )
  187. {
  188. case 'password_form':
  189. $title = T_('Check password');
  190. break;
  191. case 'config_form':
  192. $title = T_('Update debug config');
  193. break;
  194. default:
  195. $title = '';
  196. break;
  197. }
  198. // Add CSS:
  199. require_css( 'basic_styles.css', 'rsc_url' ); // the REAL basic styles
  200. require_css( 'basic.css', 'rsc_url' ); // Basic styles
  201. require_css( 'evo_distrib_2.css', 'rsc_url' );
  202. header('Content-Type: text/html; charset='.$io_charset);
  203. header('Cache-Control: no-cache'); // no request to this page should get cached!
  204. ?>
  205. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  206. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php locale_lang() ?>" lang="<?php locale_lang() ?>"><!-- InstanceBegin template="/Templates/evo_distrib_2.dwt" codeOutsideHTMLIsLocked="false" -->
  207. <head>
  208. <!-- InstanceBeginEditable name="doctitle" -->
  209. <title><?php echo T_('b2evo debug tool').( $title ? ': '.$title : '' ) ?></title>
  210. <!-- InstanceEndEditable -->
  211. <meta name="viewport" content="width = 750" />
  212. <meta name="robots" content="noindex, follow" />
  213. <?php include_headlines() /* Add javascript and css files included by plugins and skin */ ?>
  214. <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  215. <!-- InstanceParam name="lang" type="text" value="&lt;?php locale_lang() ?&gt;" -->
  216. </head>
  217. <body>
  218. <!-- InstanceBeginEditable name="BodyHead" --><!-- InstanceEndEditable -->
  219. <div class="wrapper1">
  220. <div class="wrapper2">
  221. <span class="version_top"><!-- InstanceBeginEditable name="Version" --><?php echo T_('Debug tool') ?><!-- InstanceEndEditable --></span>
  222. <a href="http://b2evolution.net/" target="_blank"><img src="../rsc/img/distrib/b2evolution-logo.gif" alt="b2evolution" width="237" height="92" /></a>
  223. <div class="menu_top"><!-- InstanceBeginEditable name="MenuTop" -->
  224. <span class="floatright"><?php echo T_('After install') ?>: <a href="../index.php"><?php echo T_('Blogs') ?></a> &middot;
  225. <a href="../<?php echo $dispatcher ?>"><?php echo T_('Admin') ?></a>
  226. </span>
  227. <?php echo T_('Current installation') ?>:
  228. <a href="index.php?locale=<?php echo $default_locale ?>"><?php echo T_('Install menu') ?></a> &middot;
  229. <a href="phpinfo.php"><?php echo T_('PHP info') ?></a>
  230. <!-- InstanceEndEditable --></div>
  231. <!-- InstanceBeginEditable name="Main" -->
  232. <?php
  233. if( count( $errors ) > 0 )
  234. { // Display errors
  235. echo '<div class="error">';
  236. echo '<ul class="error"><li>'.implode( '</li><li>', $errors ).'</li></ul>';
  237. echo '</div>';
  238. }
  239. if( !empty( $message ) )
  240. { // Display errors
  241. echo '<div class="success">';
  242. echo '<ul class="success"><li>'.$message.'</li></ul>';
  243. echo '</div>';
  244. }
  245. block_open();
  246. echo '<h1>'.T_('Debug tool').'</h1>';
  247. echo '<p>'.sprintf( T_('This tool allows you to configure some debug variables in the file %s'), $file_overrides_name ).'</p>';
  248. switch( $action )
  249. {
  250. case 'password_form':
  251. /*
  252. * -----------------------------------------------------------------------------------
  253. * Form to log in
  254. * -----------------------------------------------------------------------------------
  255. */
  256. ?>
  257. <form class="fform" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  258. <input type="hidden" name="action" value="login" />
  259. <fieldset>
  260. <legend><?php echo T_('Log in to edit the config of debug') ?></legend>
  261. <?php
  262. form_text( 'password', '', 16, T_('Password'), T_('Debug password'), 120, '', 'password' );
  263. ?>
  264. <div class="input">
  265. <input type="submit" name="submit" value="<?php echo T_('Log in') ?>" class="search" />
  266. </div>
  267. </fieldset>
  268. </form>
  269. <?php
  270. break;
  271. case 'config_form':
  272. /*
  273. * -----------------------------------------------------------------------------------
  274. * Form to change the debug config
  275. * -----------------------------------------------------------------------------------
  276. */
  277. ?>
  278. <form class="fform" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  279. <input type="hidden" name="action" value="update_config" />
  280. <input type="hidden" name="password" value="<?php echo $password; ?>" />
  281. <fieldset>
  282. <legend><?php echo T_('Debug config') ?></legend>
  283. <?php
  284. form_textarea( 'content', $file_overrides_content, 20, T_('Config'), array(
  285. 'cols' => 50,
  286. 'note' => '<br />
  287. A few possible settings:<br /><br />
  288. $minimum_comment_interval = 1;<br />
  289. $debug = 1;<br />
  290. $debug_jslog = 1;<br />
  291. $allow_po_extraction = 1;<br />
  292. $test_install_all_features = true;<br />
  293. $db_config[\'debug_dump_rows\'] = 20;<br />
  294. $db_config[\'debug_explain_joins\'] = false;<br />
  295. $display_errors_on_production = false;'
  296. ) );
  297. ?>
  298. <div class="input">
  299. <input type="submit" name="submit" value="<?php echo T_('Save Changes!') ?>" class="search" />
  300. </div>
  301. </fieldset>
  302. </form>
  303. <?php
  304. break;
  305. default:
  306. /*
  307. * -----------------------------------------------------------------------------------
  308. * Default config
  309. * -----------------------------------------------------------------------------------
  310. */
  311. echo T_( 'To enable this tool, create a file called /conf/_overrides_TEST.php with the following contents:' );
  312. echo '<p>&lt;?php<br />
  313. $debug_pwd = \'set a password here\';<br />
  314. // @@BEGIN debug.php section<br />
  315. // @@END debug.php section<br />
  316. ?&gt;</p>';
  317. break;
  318. }
  319. block_close();
  320. ?>
  321. <!-- InstanceEndEditable -->
  322. </div>
  323. <div class="body_fade_out">
  324. <div class="menu_bottom"><!-- InstanceBeginEditable name="MenuBottom" -->
  325. <?php echo T_('Online resources') ?>: <a href="http://b2evolution.net/" target="_blank"><?php echo T_('Official website') ?></a> &bull; <a href="http://b2evolution.net/about/recommended-hosting-lamp-best-choices.php" target="_blank"><?php echo T_('Find a host') ?></a> &bull; <a href="<?php echo get_manual_url( NULL ); ?>" target="_blank"><?php echo T_('Manual') ?></a> &bull; <a href="http://forums.b2evolution.net/" target="_blank"><?php echo T_('Forums') ?></a>
  326. <!-- InstanceEndEditable --></div>
  327. <div class="copyright"><!-- InstanceBeginEditable name="CopyrightTail" -->Copyright &copy; 2003-2014 by Fran&ccedil;ois Planque &amp; others &middot; <a href="http://b2evolution.net/about/license.html" target="_blank">GNU GPL license</a> &middot; <a href="http://b2evolution.net/contact/" target="_blank">Contact</a>
  328. <!-- InstanceEndEditable --></div>
  329. </div>
  330. </div>
  331. <!-- InstanceBeginEditable name="BodyFoot" -->
  332. <?php
  333. // We need to manually call debug_info since there is no shutdown function registered during the install process.
  334. // debug_info( true ); // force output of debug info
  335. // The following comments get checked in the automatic install script of demo.b2evolution.net:
  336. ?>
  337. <!-- b2evo-install-action:<?php echo $action ?> -->
  338. <!-- b2evo-install-end -->
  339. <!-- InstanceEndEditable -->
  340. </body>
  341. <!-- InstanceEnd --></html>