b2evolution PHP Cross Reference Blogging Systems

Source: /install/debug.php - 402 lines - 13361 bytes - Summary - Text - Print

Description: This is the bedug tool IF YOU ARE READING THIS IN YOUR WEB BROWSER, IT MEANS THAT PHP IS NOT PROPERLY INSTALLED ON YOUR WEB SERVER. IF YOU DON'T KNOW WHAT THIS MEANS, CONTACT YOUR SERVER ADMINISTRATOR OR YOUR HOSTING COMPANY.

   1  <?php
   2  /**

   3   * This is the bedug 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  /**

  17   * include config and default functions:

  18   */
  19  require_once dirname(__FILE__).'/../conf/_config.php';
  20  
  21  // Make the includes believe they are being called in the right place...

  22  define( 'EVO_MAIN_INIT', true );
  23  
  24  require_once $inc_path.'_core/_class'.floor(PHP_VERSION).'.funcs.php';
  25  require_once $inc_path.'_core/_misc.funcs.php';
  26  
  27  /**

  28   * Load locale related functions

  29   */
  30  require_once $inc_path.'locales/_locale.funcs.php';
  31  
  32  load_class( '_core/model/_log.class.php', 'Log');
  33  $Debuglog = new Log();
  34  load_class( '_core/model/_messages.class.php', 'Messages');
  35  $Messages = new Messages();
  36  
  37  /**

  38   * Load modules.

  39   *

  40   * This initializes table name aliases and is required before trying to connect to the DB.

  41   */
  42  load_class( '_core/model/_module.class.php', 'Module' );
  43  foreach( $modules as $module )
  44  {
  45      require_once $inc_path.$module.'/_'.$module.'.init.php';
  46  }
  47  
  48  load_class( '/_core/model/db/_db.class.php', 'DB' );
  49  load_class( '_core/model/_timer.class.php', 'Timer' );
  50  load_funcs( '_core/_url.funcs.php' );
  51  
  52  require_once dirname(__FILE__).'/_functions_install.php';
  53  
  54  
  55  /**

  56   * Check password

  57   */
  58  function debug_check_password()
  59  {
  60      global $errors, $debug_pwd;
  61  
  62      $password = param( 'password', 'string' );
  63      if( empty( $password ) )
  64      {
  65          $errors[] = T_('Please enter the password');
  66          return false;
  67      }
  68      else if( $password != $debug_pwd )
  69      {
  70          $errors[] = T_('Incorrect password');
  71          return false;
  72      }
  73  
  74      return true;
  75  }
  76  
  77  /**

  78   * Get debug config content

  79   *

  80   * @param boolean TRUE- to close file handle after getting the content

  81   * @return string Debug config

  82   */
  83  function debug_get_config( $close_handle = true )
  84  {
  85      global $errors, $file_overrides_name, $file_section_start, $file_section_end, $file_overrides_handle;
  86  
  87      // Get debug config from file

  88      $file_overrides_handle = @fopen( $file_overrides_name, 'r+' );
  89      $file_overrides_content = '';
  90      if( $file_overrides_handle )
  91      {
  92          while( !feof( $file_overrides_handle ) )
  93          {
  94              $file_overrides_content .= fgets( $file_overrides_handle, 4096 );
  95          }
  96          if( $close_handle )
  97          {
  98              fclose( $file_overrides_handle );
  99          }
 100      }
 101      else
 102      {    // Bad file name or file has not the rights to read/write
 103          $errors[] = T_('Config file cannot be opened');
 104          return false;
 105      }
 106  
 107      return $file_overrides_content;
 108  }
 109  
 110  
 111  $Timer = new Timer('main');
 112  
 113  load_funcs('_core/_param.funcs.php');
 114  
 115  // Let the modules load/register what they need:

 116  modules_call_method( 'init' );
 117  
 118  /**

 119   * @var File name

 120   */
 121  $file_overrides_name = $conf_path.'_overrides_TEST.php';
 122  
 123  // The start and the end of the debug config

 124  $file_section_start = '// @@BEGIN debug.php section';
 125  $file_section_end = '// @@END debug.php section';
 126  
 127  param( 'action', 'string', '' );
 128  
 129  $errors = array();
 130  switch( $action )
 131  {
 132      case 'login':
 133          // Check password

 134          if( !debug_check_password() )
 135          {    // Some errors exist, show the form with password again
 136              $action = 'password_form';
 137              break;
 138          }
 139  
 140          $action = 'config_form';
 141  
 142          $file_overrides_content = debug_get_config();
 143  
 144          // Get only part for editing

 145          $file_overrides_content = substr( $file_overrides_content, strpos( $file_overrides_content, $file_section_start ) + strlen( $file_section_start ) );
 146          $file_overrides_content = substr( $file_overrides_content, 0, strpos( $file_overrides_content, $file_section_end ) );
 147          $file_overrides_content = trim( $file_overrides_content );
 148          break;
 149  
 150      case 'update_config':
 151          // Update debug config

 152          if( !debug_check_password() )
 153          {    // Some errors exist, show the form with password again
 154              $action = 'password_form';
 155              break;
 156          }
 157  
 158          $action = 'config_form';
 159  
 160          $file_overrides_content = param( 'content', 'raw' );
 161          $old_content = debug_get_config( false );
 162  
 163          if( count( $errors ) > 0)
 164          {
 165              if( $file_overrides_handle )
 166              {
 167                  fclose( $file_overrides_handle );
 168              }
 169              break;
 170          }
 171  
 172          if( strpos( $old_content, $file_section_start ) !== false && strpos( $old_content, $file_section_end ) !== false )
 173          { // File contains correct section to edit
 174              $old_content_start = substr( $old_content, 0, strpos( $old_content, $file_section_start ) + strlen( $file_section_start ) );
 175              $old_content_end = substr( $old_content, strpos( $old_content, $file_section_end ) );
 176          }
 177          else
 178          { // Config editable start or end sections don't exist in the file, we should create them
 179              $is_php_tag_opened = strpos( $old_content, '<?' ) !== false;
 180              $is_php_tag_closed = strpos( $old_content, '?>' ) !== false;
 181              if( $is_php_tag_opened && $is_php_tag_closed )
 182              { // File contains the open and close tags
 183                  $old_content_start = substr( $old_content, 0, strpos( $old_content, '?>' ) );
 184                  $old_content_end = substr( $old_content, strpos( $old_content, '?>' ) );
 185              }
 186              elseif( !$is_php_tag_opened && !$is_php_tag_closed )
 187              { // File doesn't contain the open and close php tags, Add this at the file end
 188                  $old_content_start = $old_content.'<?php'."\n";
 189                  $old_content_end = '?>';
 190              }
 191              elseif( !$is_php_tag_closed )
 192              { // File doesn't contain only the close php tag, Insert new config text at the end
 193                  $old_content_start = $old_content;
 194                  $old_content_end = '';
 195              }
 196              $old_content_start = $old_content_start."\n".$file_section_start;
 197              $old_content_end = $file_section_end."\n".$old_content_end;
 198          }
 199  
 200          // Write new content into config

 201          ftruncate( $file_overrides_handle, 0 );
 202          fseek( $file_overrides_handle, 0 );
 203          fwrite( $file_overrides_handle, $old_content_start."\n".$file_overrides_content."\n".$old_content_end );
 204  
 205          fclose( $file_overrides_handle );
 206          $message = T_('Debug config has been changed');
 207          break;
 208  
 209      default:
 210          if( file_exists( $file_overrides_name ) )
 211          {    // Display a form to log in if file already exists
 212              $action = 'password_form';
 213          }
 214          break;
 215  }
 216  
 217  
 218  switch( $action )
 219  {
 220      case 'password_form':
 221          $title = T_('Check password');
 222          break;
 223  
 224      case 'config_form':
 225          $title = T_('Update debug config');
 226          break;
 227  
 228      default:
 229          $title = '';
 230          break;
 231  }
 232  
 233  // Add CSS:

 234  require_css( 'basic_styles.css', 'rsc_url' ); // the REAL basic styles

 235  require_css( 'basic.css', 'rsc_url' ); // Basic styles

 236  require_css( 'evo_distrib_2.css', 'rsc_url' );
 237  
 238  header('Content-Type: text/html; charset='.$io_charset);
 239  header('Cache-Control: no-cache'); // no request to this page should get cached!

 240  ?>
 241  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 242  <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" -->
 243  <head>
 244      <!-- InstanceBeginEditable name="doctitle" -->
 245      <title><?php echo T_('b2evo debug tool').( $title ? ': '.$title : '' ) ?></title>
 246      <!-- InstanceEndEditable -->
 247      <meta name="viewport" content="width = 750" />
 248      <meta name="robots" content="noindex, follow" />
 249      <?php include_headlines() /* Add javascript and css files included by plugins and skin */ ?>
 250      <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
 251      <!-- InstanceParam name="lang" type="text" value="&lt;?php locale_lang() ?&gt;" -->
 252  </head>
 253  
 254  <body>
 255      <!-- InstanceBeginEditable name="BodyHead" --><!-- InstanceEndEditable -->
 256  
 257      <div class="wrapper1">
 258      <div class="wrapper2">
 259          <span class="version_top"><!-- InstanceBeginEditable name="Version" --><?php echo T_('Debug tool') ?><!-- InstanceEndEditable --></span>
 260  
 261          <a href="http://b2evolution.net/" target="_blank"><img src="../rsc/img/distrib/b2evolution-logo.gif" alt="b2evolution" width="237" height="92" /></a>
 262  
 263          <div class="menu_top"><!-- InstanceBeginEditable name="MenuTop" -->
 264              <span class="floatright"><?php echo T_('After install') ?>: <a href="../index.php"><?php echo T_('Blogs') ?></a> &middot;
 265              <a href="../<?php echo $dispatcher ?>"><?php echo T_('Admin') ?></a>
 266              </span>
 267          <?php echo T_('Current installation') ?>:
 268          <a href="index.php?locale=<?php echo $default_locale ?>"><?php echo T_('Install menu') ?></a> &middot;
 269          <a href="phpinfo.php"><?php echo T_('PHP info') ?></a>
 270          <!-- InstanceEndEditable --></div>
 271  
 272          <!-- InstanceBeginEditable name="Main" -->
 273  <?php
 274  
 275  if( count( $errors ) > 0 )
 276  {    // Display errors
 277      echo '<div class="error">';
 278      echo '<ul class="error"><li>'.implode( '</li><li>', $errors ).'</li></ul>';
 279      echo '</div>';
 280  }
 281  
 282  if( !empty( $message ) )
 283  {    // Display errors
 284      echo '<div class="success">';
 285      echo '<ul class="success"><li>'.$message.'</li></ul>';
 286      echo '</div>';
 287  }
 288  
 289  block_open();
 290  echo '<h1>'.T_('Debug tool').'</h1>';
 291  echo '<p>'.sprintf( T_('This tool allows you to configure some debug variables in the file %s'), $file_overrides_name ).'</p>';
 292  
 293  switch( $action )
 294  {
 295      case 'password_form':
 296          /*

 297           * -----------------------------------------------------------------------------------

 298           * Form to log in

 299           * -----------------------------------------------------------------------------------

 300           */
 301          ?>
 302          <form class="fform" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 303              <input type="hidden" name="action" value="login" />
 304  
 305              <fieldset>
 306                  <legend><?php echo T_('Log in to edit the config of debug') ?></legend>
 307                  <?php
 308                      form_text( 'password', '', 16, T_('Password'), T_('Debug password'), 120, '', 'password' );
 309                  ?>
 310                      <div class="input">
 311                          <input type="submit" name="submit" value="<?php echo T_('Log in') ?>" class="search" />
 312                      </div>
 313              </fieldset>
 314  
 315          </form>
 316          <?php
 317          break;
 318  
 319      case 'config_form':
 320          /*

 321           * -----------------------------------------------------------------------------------

 322           * Form to change the debug config

 323           * -----------------------------------------------------------------------------------

 324           */
 325          ?>
 326          <form class="fform" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 327              <input type="hidden" name="action" value="update_config" />
 328              <input type="hidden" name="password" value="<?php echo $password; ?>" />
 329  
 330              <fieldset>
 331                  <legend><?php echo T_('Debug config') ?></legend>
 332                  <?php
 333  
 334                      form_textarea( 'content', $file_overrides_content, 20, T_('Config'), array(
 335                          'cols' => 50,
 336                          'note' => '<br />
 337  A few possible settings:<br /><br />
 338  $minimum_comment_interval = 1;<br />
 339  $debug = 1;<br />
 340  $debug_jslog = 1;<br />
 341  $allow_po_extraction = 1;<br />
 342  $test_install_all_features = true;<br />
 343  $db_config[\'debug_dump_rows\'] = 20;<br />
 344  $db_config[\'debug_explain_joins\'] = false;'
 345                          ) );
 346                  ?>
 347                      <div class="input">
 348                          <input type="submit" name="submit" value="<?php echo T_('Update') ?>" class="search" />
 349                      </div>
 350              </fieldset>
 351  
 352          </form>
 353          <?php
 354          break;
 355  
 356      default:
 357          /*

 358           * -----------------------------------------------------------------------------------

 359           * Default config

 360           * -----------------------------------------------------------------------------------

 361           */
 362  
 363          echo T_( 'To enable this tool, create a file called /conf/_overrides_TEST.php with the following contents:' );
 364          echo '<p>&lt;?php<br />
 365  $debug_pwd = \'set a password here\';<br />
 366  // @@BEGIN debug.php section<br />

 367  // @@END debug.php section<br />

 368  ?&gt;</p>';
 369  
 370          break;
 371  }
 372  
 373  block_close();
 374  ?>
 375  
 376  <!-- InstanceEndEditable -->
 377      </div>
 378  
 379      <div class="body_fade_out">
 380  
 381      <div class="menu_bottom"><!-- InstanceBeginEditable name="MenuBottom" -->
 382              <?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="http://b2evolution.net/man/" target="_blank"><?php echo T_('Manual') ?></a> &bull; <a href="http://forums.b2evolution.net/" target="_blank"><?php echo T_('Forums') ?></a>
 383          <!-- InstanceEndEditable --></div>
 384  
 385      <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>
 386          <!-- InstanceEndEditable --></div>
 387  
 388      </div>
 389      </div>
 390  
 391      <!-- InstanceBeginEditable name="BodyFoot" -->
 392      <?php
 393          // We need to manually call debug_info since there is no shutdown function registered during the install process.

 394          // debug_info( true ); // force output of debug info

 395  
 396          // The following comments get checked in the automatic install script of demo.b2evolution.net:

 397  ?>
 398  <!-- b2evo-install-action:<?php echo $action ?> -->
 399  <!-- b2evo-install-end -->
 400      <!-- InstanceEndEditable -->
 401  </body>
 402  <!-- InstanceEnd --></html>

title

Description

title

Description

title

Description

title

title

Body