[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/admin/check/ -> check_database_inc.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package MantisBT
  19   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  20   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @link http://www.mantisbt.org
  22   *
  23   * @uses check_api.php
  24   * @uses config_api.php
  25   * @uses database_api.php
  26   * @uses utility_api.php
  27   */
  28  
  29  if ( !defined( 'CHECK_DATABASE_INC_ALLOW' ) ) {
  30      return;
  31  }
  32  
  33  /**
  34   * MantisBT Check API
  35   */
  36  require_once ( 'check_api.php' );
  37  require_api( 'config_api.php' );
  38  require_api( 'database_api.php' );
  39  require_api( 'utility_api.php' );
  40  
  41  check_print_section_header_row( 'Database' );
  42  
  43  $t_adodb_version_check_ok = false;
  44  $t_adodb_version_info = 'No version of ADOdb could be found. This is a compulsory dependency of MantisBT.';
  45  if( isset( $ADODB_vers ) ) {
  46      # ADOConnection::Version() is broken as it treats v5.1 the same as v5.10
  47      # Therefore we must extract the correct version ourselves
  48      # Upstream bug report: http://phplens.com/lens/lensforum/msgs.php?id=18320
  49      # This bug has been fixed in ADOdb 5.11 (May 5, 2010) but we still
  50      # need to use the backwards compatible approach to detect ADOdb <5.11.
  51      if( preg_match( '/^[Vv]([0-9\.]+)/', $ADODB_vers, $t_matches ) == 1 ) {
  52          $t_adodb_version_check_ok = version_compare( $t_matches[1], '5.10', '>=' );
  53          $t_adodb_version_info = 'ADOdb version ' . htmlentities( $t_matches[1] ) . ' was found.';
  54      }
  55  }
  56  check_print_test_row(
  57      'Version of <a href="http://en.wikipedia.org/wiki/ADOdb">ADOdb</a> available is at least 5.11',
  58      $t_adodb_version_check_ok,
  59      $t_adodb_version_info
  60  );
  61  
  62  if( !$t_adodb_version_check_ok ) {
  63      return;
  64  }
  65  
  66  $t_database_dsn = config_get_global( 'dsn' );
  67  check_print_info_row(
  68      'Using a custom <a href="http://en.wikipedia.org/wiki/Database_Source_Name">Database Source Name</a> (DSN) for connecting to the database',
  69      $t_database_dsn ? 'Yes' : 'No'
  70  );
  71  
  72  $t_database_type = config_get_global( 'db_type' );
  73  check_print_info_row(
  74      'Database type',
  75      htmlentities( $t_database_type )
  76  );
  77  
  78  check_print_test_row(
  79      'Database type is supported by the version of PHP installed on this server',
  80      db_check_database_support( $t_database_type ),
  81      array( false => 'The current database type is set to ' . htmlentities( $t_database_type ) . '. The version of PHP installed on this server does not have support for this database type.' )
  82  );
  83  
  84  if ( db_is_mssql() ) {
  85  
  86      $t_mssql_textsize = ini_get_number( 'mssql.textsize' );
  87      check_print_info_row(
  88          'php.ini directive: mssql.textsize',
  89          htmlentities( $t_mssql_textsize )
  90      );
  91  
  92      check_print_test_warn_row(
  93          'mssql.textsize php.ini directive is set to -1',
  94          $t_mssql_textsize == -1,
  95          array( false => 'The value of the mssql.textsize directive is currently ' . htmlentities( $t_mssql_textsize ) . '. You should set this value to -1 to prevent large text fields being truncated upon being read from the database.' )
  96      );
  97  
  98      $t_mssql_textlimit = ini_get_number( 'mssql.textlimit' );
  99      check_print_info_row(
 100          'php.ini directive: mssql.textlimit',
 101          htmlentities( $t_mssql_textlimit )
 102      );
 103  
 104      check_print_test_warn_row(
 105          'mssql.textlimit php.ini directive is set to -1',
 106          $t_mssql_textlimit == -1,
 107          array( false => 'The value of the mssql.textlimit directive is currently ' . htmlentities( $t_mssql_textlimit ) . '. You should set this value to -1 to prevent large text fields being truncated upon being read from the database.' )
 108      );
 109  
 110  }
 111  
 112  $t_database_hostname = config_get_global( 'hostname' );
 113  check_print_info_row(
 114      'Database hostname',
 115      htmlentities( $t_database_hostname )
 116  );
 117  
 118  $t_database_username = config_get_global( 'db_username' );
 119  check_print_info_row(
 120      'Database username',
 121      htmlentities( $t_database_username )
 122  );
 123  
 124  $t_database_password = config_get_global( 'db_password' );
 125  
 126  $t_database_name = config_get_global( 'database_name' );
 127  check_print_info_row(
 128      'Database name',
 129      htmlentities( $t_database_name )
 130  );
 131  
 132  db_connect( $t_database_dsn, $t_database_hostname, $t_database_username, $t_database_password, $t_database_name );
 133  check_print_test_row(
 134      'Can open connection to database <em>' . htmlentities( $t_database_name ) . '</em> on host <em>' . htmlentities( $t_database_hostname ) . '</em> with username <em>' . htmlentities( $t_database_username ) . '</em>',
 135      db_is_connected()
 136  );
 137  
 138  if( !db_is_connected() ) {
 139      return;
 140  }
 141  
 142  $t_database_server_info = $g_db->ServerInfo();
 143  check_print_info_row(
 144      'Database server version',
 145      htmlentities( $t_database_server_info['version'] )
 146  );
 147  
 148  if( db_is_mysql() ) {
 149  
 150      check_print_test_row(
 151          'Version of MySQL being used is within the <a href="http://www.mysql.com/about/legal/lifecycle/">MySQL extended lifecycle period</a>',
 152          version_compare( $t_database_server_info['version'], '5.0', '>=' ),
 153          array(
 154              true => 'Extended lifecycle support ends on 2011-12-31 for MySQL 5.0 and on 2013-12-31 for MySQL 5.1.',
 155              false => 'The version of MySQL you are using is ' . htmlentities( $t_database_server_info['version'] ) . '. This version is no longer supported and should not be used as security flaws discovered in this version will not be fixed.'
 156          )
 157      );
 158  
 159      check_print_test_warn_row(
 160          'Version of MySQL being used is within the <a href="http://www.mysql.com/about/legal/lifecycle/">MySQL active lifecycle period</a>',
 161          version_compare( $t_database_server_info['version'], '5.1', '>=' ),
 162          array(
 163              true => 'Active lifecycle support ends on 2010-12-31 for MySQL 5.1.',
 164              false => 'The version of MySQL you are using is ' . htmlentities( $t_database_server_info['version'] ) . '. It is recommended you use a newer version of MySQL still within the active lifecycle period.'
 165          )
 166      );
 167  
 168  }
 169  
 170  if( db_is_pgsql() ) {
 171  
 172      check_print_test_row(
 173          'Version of PostgreSQL being used still has <a href="http://wiki.postgresql.org/wiki/PostgreSQL_Release_Support_Policy">release support</a>',
 174          version_compare( $t_database_server_info['version'], '7.4', '>=' ),
 175          array( false => 'The version of PostgreSQL you are using is '. htmlentities( $t_database_server_info['version'] ). '. This version is no longer supported and should not be used as security flaws discovered in this version will not be fixed.' )
 176      );
 177  
 178  }
 179  
 180  $t_table_prefix = config_get_global( 'db_table_prefix' );
 181  check_print_info_row(
 182      'Prefix added to each MantisBT table name',
 183      htmlentities( $t_table_prefix )
 184  );
 185  
 186  $t_table_suffix = config_get_global( 'db_table_suffix' );
 187  check_print_info_row(
 188      'Suffix added to each MantisBT table name',
 189      htmlentities( $t_table_suffix )
 190  );
 191  
 192  if( db_is_mysql() ) {
 193  
 194      $t_table_prefix_regex_safe = preg_quote( $t_table_prefix, '/' );
 195      $t_table_suffix_regex_safe = preg_quote( $t_table_suffix, '/' );
 196  
 197      $t_result = db_query_bound( 'SHOW TABLE STATUS' );
 198      while( $t_row = db_fetch_array( $t_result ) ) {
 199          if( $t_row['Comment'] !== 'VIEW' &&
 200              preg_match( "/^$t_table_prefix_regex_safe.+?$t_table_suffix_regex_safe\$/", $t_row['Name'] ) ) {
 201              check_print_test_row(
 202                  'Table <em>' . htmlentities( $t_row['Name'] ) . '</em> is using UTF-8 collation',
 203                  substr( $t_row['Collation'], 0, 5 ) === 'utf8_',
 204                  array( false => 'Table ' . htmlentities( $t_row['Name'] ) . ' is using ' . htmlentities( $t_row['Collation'] ) . ' collation where UTF-8 collation is required.' )
 205              );
 206          }
 207      }
 208  
 209      foreach( db_get_table_list() as $t_table ) {
 210          if( preg_match( "/^$t_table_prefix_regex_safe.+?$t_table_suffix_regex_safe\$/", $t_table ) ) {
 211              $t_result = db_query_bound( 'SHOW FULL FIELDS FROM ' . $t_table );
 212              while( $t_row = db_fetch_array( $t_result ) ) {
 213                  if ( $t_row['Collation'] === null ) {
 214                      continue;
 215                  }
 216                  check_print_test_row(
 217                      'Text column <em>' . htmlentities( $t_row['Field'] ) . '</em> of type <em>' . $t_row['Type'] . '</em> on table <em>' . htmlentities( $t_table ) . '</em> is is using UTF-8 collation',
 218                      substr( $t_row['Collation'], 0, 5 ) === 'utf8_',
 219                      array( false => 'Text column ' . htmlentities( $t_row['Field'] ) . ' of type ' . $t_row['Type'] . ' on table ' . htmlentities( $t_table ) . ' is using ' . htmlentities( $t_row['Collation'] ) . ' collation where UTF-8 collation is required.' )
 220                  );
 221              }
 222          }
 223      }
 224  
 225  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7