[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/admin/ -> install.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: install.php,v 1.38.2.1 2007-10-13 22:34:55 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      error_reporting( E_ALL );
  25  
  26      //@@@ put this somewhere
  27      set_time_limit ( 0 ) ;
  28      $g_skip_open_db = true;  # don't open the database in database_api.php
  29      @require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
  30      $g_error_send_page_header = false; # bypass page headers in error handler
  31  
  32      define( 'BAD', 0 );
  33      define( 'GOOD', 1 );
  34      $g_failed = false;
  35  
  36      # -------
  37      # print test result
  38  	function print_test_result( $p_result, $p_hard_fail=true, $p_message='' ) {
  39          global $g_failed;
  40          echo '<td ';
  41          if ( BAD == $p_result ) {
  42              if ( $p_hard_fail ) {
  43                  $g_failed = true;
  44                  echo 'bgcolor="red">BAD';
  45              } else {
  46                  echo 'bgcolor="pink">POSSIBLE PROBLEM';
  47              }
  48              if ( '' != $p_message ) {
  49                  echo '<br />' . $p_message;
  50              }
  51          }
  52  
  53          if ( GOOD == $p_result ) {
  54              echo 'bgcolor="green">GOOD';
  55          }
  56          echo '</td>';
  57      }
  58  
  59      # -------
  60      # print test header and result
  61  	function print_test( $p_test_description, $p_result, $p_hard_fail=true, $p_message='' ) {
  62  
  63          echo "\n<tr><td bgcolor=\"#ffffff\">$p_test_description</td>";
  64          print_test_result( $p_result, $p_hard_fail, $p_message );
  65          echo "</tr>\n";
  66      }
  67  
  68      # --------
  69      # create an SQLArray to insert data
  70  	function InsertData( $p_table, $p_data ) {
  71          $query = "INSERT INTO " . $p_table . $p_data;
  72          return Array( $query );
  73      }
  74  
  75  
  76  
  77      # install_state
  78      #   0 = no checks done
  79      #   1 = server ok, get database information
  80      #   2 = check the database information
  81      #   3 = install the database
  82      #   4 = get additional config file information
  83      #   5 = write the config file
  84      #    6 = post install checks
  85      #    7 = done, link to login or db updater
  86      $t_install_state = gpc_get_int( 'install', 0 );
  87  
  88      # read control variables with defaults
  89      $f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) );
  90      $f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) );
  91      $f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack') );
  92      $f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) );
  93      $f_db_password = gpc_get( 'db_password', config_get( 'db_password', '' ) );
  94      if ( CONFIGURED_PASSWORD == $f_db_password ) {
  95          $f_db_password = config_get( 'db_password' ); 
  96      }
  97      $f_admin_username = gpc_get( 'admin_username', '' );
  98      $f_admin_password = gpc_get( 'admin_password', '');
  99      $f_log_queries = gpc_get_bool( 'log_queries', false );
 100      $f_db_exists = gpc_get_bool( 'db_exists', false );
 101  
 102      $f_db_schema='';    
 103      if ( $f_db_type == 'db2' ) {
 104          # If schema name is supplied, then separate it from database name.
 105          if ( strpos( $f_database_name, '/' ) != false ) {
 106              $f_db2AS400 = $f_database_name;
 107              list( $f_database_name, $f_db_schema ) = split( '/', $f_db2AS400, 2 );
 108          }
 109      }
 110  ?>
 111  <html>
 112  <head>
 113  <title> Mantis Administration - Installation  </title>
 114  <link rel="stylesheet" type="text/css" href="admin.css" />
 115  </head>
 116  <body>
 117  <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
 118      <tr class="top-bar">
 119          <td class="links">
 120              [ <a href="index.php">Back to Administration</a> ]
 121          </td>
 122          <td class="title">
 123          <?php
 124              switch ( $t_install_state ) {
 125                  case 6:
 126                      echo "Post Installation Checks";
 127                      break;
 128                  case 5:
 129                      echo "Install Configuration File";
 130                      break;
 131                  case 4:
 132                      echo "Additional Configuration Information";
 133                      break;
 134                  case 3:
 135                      echo "Install Database";
 136                      break;
 137                  case 2:
 138                      echo "Check and Install Database";
 139                      break;
 140                  case 1:
 141                      echo "Database Parameters";
 142                      break;
 143                  case 0:
 144                  default:
 145                      echo "Pre-Installation Check";
 146                      break;
 147              }
 148          ?>
 149          </td>
 150      </tr>
 151  </table>
 152  <br /><br />
 153  
 154  <form method='POST'>
 155  <?php
 156  if ( 0 == $t_install_state ) {
 157  ?>
 158  <table width="100%" bgcolor="#222222" border="0" cellpadding="10" cellspacing="1">
 159  <tr>
 160      <td bgcolor="#e8e8e8" colspan="2">
 161          <span class="title">Checking Installation...</span>
 162      </td>
 163  </tr>
 164  
 165  <!-- Check PHP Version -->
 166  <tr>
 167      <td bgcolor="#ffffff">
 168          Checking PHP version (your version is <?php echo phpversion(); ?>)
 169      </td>
 170      <?php
 171          if (phpversion() == '4.0.6') {
 172              print_test_result( GOOD );
 173          } else {
 174              if ( function_exists ( 'version_compare' ) ) {
 175                  if ( version_compare ( phpversion() , '4.0.6', '>=' ) ) {
 176                      print_test_result( GOOD );
 177                  } else {
 178                      print_test_result( BAD, true, 'Upgrade to a more recent version of PHP' );
 179                  }
 180              } else {
 181                   print_test_result( BAD, true, 'Upgrade to a more recent version of PHP' );
 182              }
 183          }
 184      ?>
 185  </tr>
 186  
 187  <!-- Check Safe Mode -->
 188  <?php print_test( 'Checking if safe mode is enabled for install script',
 189          ! ini_get ( 'SAFE_MODE' ),
 190          true,
 191          'Disable safe_mode in php.ini before proceeding' ) ?>
 192  
 193  </table>
 194  <?php
 195      if ( false == $g_failed ) {
 196          $t_install_state++;
 197      }
 198  } # end install_state == 0
 199  
 200  # got database information, check and install
 201  if ( 2 == $t_install_state ) {
 202  ?>
 203  
 204  <table width="100%" border="0" cellpadding="10" cellspacing="1">
 205  <!-- Setting config variables -->
 206  <?php print_test( 'Setting Database Hostname', '' !== $f_hostname , true, 'host name is blank' ) ?>
 207  
 208  <!-- Setting config variables -->
 209  <?php print_test( 'Setting Database Type', '' !== $f_db_type , true, 'database type is blank?' ) ?>
 210  
 211  <!-- Checking DB support-->
 212  <tr>
 213      <td bgcolor="#ffffff">
 214          Checking PHP support for database type
 215      </td>
 216      <?php
 217              $t_support = false;
 218              switch ($f_db_type) {
 219                  case 'mysql':
 220                      $t_support = function_exists('mysql_connect');
 221                      break;
 222                  case 'mysqli':
 223                      $t_support = function_exists('mysqli_connect');
 224                      break;
 225                  case 'pgsql':
 226                      $t_support = function_exists('pg_connect');
 227                      break;
 228                  case 'mssql':
 229                      $t_support = function_exists('mssql_connect');
 230                      break;
 231                  case 'oci8':
 232                      $t_support = function_exists('OCILogon');
 233                      break;
 234                  case 'db2':
 235                      $t_support = function_exists( 'db2_connect' );
 236                      break;
 237                  default:
 238                      $t_support = false;
 239              }
 240  
 241              if ( $t_support ) {
 242                  print_test_result( GOOD );
 243              } else {
 244                  print_test_result( BAD, true, 'database is not supported by PHP. Check that it has been compiled into your server.' );
 245              }
 246      ?>
 247  </tr>
 248  
 249  <?php print_test( 'Setting Database Username', '' !== $f_db_username , true, 'database username is blank' ) ?>
 250  <?php print_test( 'Setting Database Password', '' !== $f_db_password , false, 'database password is blank' ) ?>
 251  <?php print_test( 'Setting Database Name', '' !== $f_database_name , true, 'database name is blank' )?>
 252  <?php
 253      if ( $f_db_type == 'db2' ) {
 254          print_test( 'Setting Database Schema', !is_blank( $f_db_schema ), true, 'must have a schema name for AS400 in the form of DBNAME/SCHEMA' );
 255      }
 256  ?>
 257  <tr>
 258      <td bgcolor="#ffffff">
 259          Setting Admin Username
 260      </td>
 261      <?php
 262              if ( '' !== $f_admin_username ) {
 263                  print_test_result( GOOD );
 264              } else {
 265                  print_test_result( BAD, false, 'admin user name is blank, using database user instead' );
 266                  $f_admin_username = $f_db_username;
 267              }
 268      ?>
 269  </tr>
 270  <tr>
 271      <td bgcolor="#ffffff">
 272          Setting Admin Password
 273      </td>
 274      <?php
 275              if ( '' !== $f_admin_password ) {
 276                  print_test_result( GOOD );
 277              } else {
 278                  if (  '' != $f_db_password ) {
 279                      print_test_result( BAD, false, 'admin user password is blank, using database user password instead' );
 280                      $f_admin_password = $f_db_password;
 281                  } else {
 282                      print_test_result( GOOD );
 283                  }
 284              }
 285      ?>
 286  </tr>
 287  
 288  <!-- connect to db -->
 289  <tr>
 290      <td bgcolor="#ffffff">
 291          Attempting to connect to database as admin
 292      </td>
 293      <?php
 294          $g_db = ADONewConnection($f_db_type);
 295          $t_result = @$g_db->Connect($f_hostname, $f_admin_username, $f_admin_password);
 296  
 297          if ( $t_result ) {
 298              print_test_result( GOOD );
 299              # check if db exists for the admin
 300              $t_result = @$g_db->Connect($f_hostname, $f_admin_username, $f_admin_password, $f_database_name);
 301              if ( $t_result ) {
 302                  $f_db_exists = true;
 303              }
 304          } else {
 305              print_test_result( BAD, true, 'Does administrative user have access to the database? ( ' .  db_error_msg() . ' )' );
 306          }
 307  
 308          if ( $f_db_type == 'db2' ) {
 309              $result = &$g_db->execute( 'set schema ' . $f_db_schema );
 310              if ( $result === false ) {
 311                  echo $g_db->errorMsg();
 312              }
 313          }            
 314          
 315      ?>
 316  </tr>
 317  
 318  <!-- display database version -->
 319  <tr>
 320      <td bgcolor="#ffffff">
 321          Checking Database Server Version
 322          <?php
 323              # due to a bug in ADODB, this call prompts warnings, hence the @
 324              $t_version_info = @$g_db->ServerInfo();
 325              echo '<br /> Running ' . $f_db_type . ' version ' . $t_version_info['description'];
 326          ?>
 327      </td>
 328      <?php
 329          $t_warning = '';
 330          $t_error = '';
 331          switch ( $f_db_type ) {
 332              case 'mysql':
 333              case 'mysqli':
 334                  if ( function_exists ( 'version_compare' ) ) {
 335                      if ( version_compare ( $t_version_info['version'] , '4.1.0', '>' ) ) {
 336                          $t_warning = 'Please ensure that your installation supports the new password scheme used in MySQL 4.1.0 and later. See ' .
 337                              '<a href="http://dev.mysql.com/doc/mysql/en/password-hashing.html">http://dev.mysql.com/doc/mysql/en/password-hashing.html</a>.';
 338                      }
 339                  }
 340                  break;
 341              case 'pgsql':
 342              case 'mssql':
 343              case 'db2':
 344              default:
 345                  break;
 346          }
 347              
 348          print_test_result( ( '' == $t_error ) && ( '' == $t_warning ), ( '' != $t_error ), $t_error . ' ' . $t_warning );
 349      ?>
 350  </tr>
 351  <?php
 352      if ( $f_db_exists ) {
 353  ?>
 354  <tr>
 355      <td bgcolor="#ffffff">
 356          Attempting to connect to database as user
 357      </td>
 358      <?php
 359          $g_db = ADONewConnection($f_db_type);
 360          $t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
 361  
 362          if ( $t_result == true ) {
 363              print_test_result( GOOD );
 364          } else {
 365              print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' .  db_error_msg() . ' )' );
 366          }
 367  
 368          if ( $f_db_type == 'db2' ) {
 369              echo "<br />SET SCHEMA " . $f_db_schema;
 370              $result = &$g_db->execute( 'set schema ' . $f_db_schema );
 371              if ( $result === false ) {
 372                  echo $g_db->errorMsg();
 373              }
 374          }        
 375          
 376      ?>
 377  </tr>
 378  
 379  <?php
 380      }
 381      if ( false == $g_failed ) {
 382          $t_install_state++;
 383      } else {
 384          $t_install_state--;    # a check failed, redisplay the questions
 385      }
 386  } # end 2 == $t_install_state
 387  
 388  # system checks have passed, get the database information
 389  if ( 1 == $t_install_state ) {
 390  ?>
 391  
 392  <table width="100%" border="0" cellpadding="10" cellspacing="1">
 393  <tr>
 394      <td bgcolor="#e8e8e8" colspan="2">
 395          <span class="title">Installation Options</span>
 396      </td>
 397  </tr>
 398  
 399  <tr>
 400      <td>
 401          Type of Database
 402      </td>
 403      <td>
 404          <select name="db_type">
 405          <?php
 406              if ( $f_db_type == 'mysql' ) {
 407                  echo '<option value="mysql" selected="selected">MySql (default)</option>';
 408              } else {
 409                  echo '<option value="mysql">MySql (default)</option>';
 410              }
 411  
 412              if ( $f_db_type == 'mysqli' ) {
 413                  echo '<option value="mysqli" selected="selected">MySqli</option>';
 414              } else {
 415                  echo '<option value="mysqli">MySqli</option>';
 416              }
 417  
 418              if ( $f_db_type == 'mssql' ) {
 419                  echo '<option value="mssql" selected="selected">Microsoft SQL Server (experimental)</option>';
 420              } else {
 421                  echo '<option value="mssql">Microsoft SQL Server (experimental)</option>';
 422              }
 423  
 424              if ( $f_db_type == 'pgsql' ) {
 425                  echo '<option value="pgsql" selected="selected">PGSQL (experimental)</option>';
 426              } else {
 427                  echo '<option value="pgsql">PGSQL (experimental)</option>';
 428              }
 429              
 430              if ( $f_db_type == 'oci8' ) {
 431                  echo '<option value="oci8" selected="selected">Oracle - oci8 (Experimental)</option>';
 432              } else {
 433                  echo '<option value="oci8">Oracle - oci8 (Experimental)</option>';
 434              }
 435  
 436              if ( $f_db_type == 'db2' ) {
 437                  echo '<option value="db2" selected="selected">db2/400 (experimental)</option>';
 438              } else {
 439                  echo '<option value="db2">db2/400 (experimental)</option>';
 440              }
 441          ?>
 442          </select>
 443      </td>
 444  </tr>
 445  
 446  <tr>
 447      <td>
 448          Hostname (for Database Server)
 449      </td>
 450      <td>
 451          <input name="hostname" type="textbox" value="<?php echo $f_hostname ?>"></input>
 452      </td>
 453  </tr>
 454  
 455  <tr>
 456      <td>
 457          Username (for Database)
 458      </td>
 459      <td>
 460          <input name="db_username" type="textbox" value="<?php echo $f_db_username ?>"></input>
 461      </td>
 462  </tr>
 463  
 464  <tr>
 465      <td>
 466          Password (for Database)
 467      </td>
 468      <td>
 469          <input name="db_password" type="password" value="<?php echo ( !is_blank( $f_db_password ) ? CONFIGURED_PASSWORD : "" ) ?>"></input>
 470      </td>
 471  </tr>
 472  
 473  <tr>
 474      <td>
 475          Database name (for Database)
 476      </td>
 477      <td>
 478          <input name="database_name" type="textbox" value="<?php echo $f_database_name ?>"></input>
 479      </td>
 480  </tr>
 481  <tr>
 482      <td>
 483          Admin Username (to create Database)
 484      </td>
 485      <td>
 486          <input name="admin_username" type="textbox" value="<?php echo $f_admin_username ?>"></input>
 487      </td>
 488  </tr>
 489  
 490  <tr>
 491      <td>
 492          Admin Password (to create Database)
 493      </td>
 494      <td>
 495          <input name="admin_password" type="password" value="<?php echo $f_admin_password  ?>"></input>
 496      </td>
 497  </tr>
 498  
 499  <tr>
 500      <td>
 501          Print SQL Queries instead of Writing to the Database
 502      </td>
 503      <td>
 504          <input name="log_queries" type="checkbox" value="1" <?php echo ( $f_log_queries ? 'checked="checked"' : '' ) ?>></input>
 505      </td>
 506  </tr>
 507  
 508  <tr>
 509      <td>
 510          Attempt Installation
 511      </td>
 512      <td>
 513          <input name="go" type="submit" value="Install/Upgrade Database"></input>
 514      </td>
 515  </tr>
 516  <input name="install" type="hidden" value="2"></input>
 517  
 518  </table>
 519  <?php
 520  }  # end install_state == 1
 521  
 522  # all checks have passed, install the database
 523  if ( 3 == $t_install_state ) {
 524  ?>
 525  
 526  <table width="100%" border="0" cellpadding="10" cellspacing="1">
 527  <tr>
 528      <td bgcolor="#e8e8e8" colspan="2">
 529          <span class="title">Installing Database</span>
 530      </td>
 531  </tr>
 532  <?php if ( ! $f_log_queries ) { ?>
 533  <tr>
 534      <td bgcolor="#ffffff">
 535          Create database if it does not exist
 536      </td>
 537      <?php
 538          $t_result = @$g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name );
 539  
 540          if ( $f_db_type == 'db2' ) {
 541              $rs = $g_db->Execute("select * from SYSIBM.SCHEMATA WHERE SCHEMA_NAME = '" . $f_db_schema . "' AND SCHEMA_OWNER = '" . $f_db_username . "'" ); 
 542              if ( $rs === false ) {
 543                  echo "<br />false";
 544              }
 545  
 546              if ( $rs->EOF ) {
 547                  $t_result = false;
 548                  echo $g_db->errorMsg();
 549              } else {
 550                  $t_result = &$g_db->execute( 'set schema ' . $f_db_schema );
 551              }
 552          }
 553  
 554          $g_db->Close();
 555  
 556      if ( $t_result == true ) {
 557          print_test_result( GOOD );
 558      } else {
 559          // create db
 560          $g_db = ADONewConnection( $f_db_type );
 561          $t_result = $g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password );
 562  
 563          $dict = NewDataDictionary( $g_db );
 564  
 565          if ( $f_db_type == 'db2' ) {
 566              $rs = &$g_db->Execute("CREATE SCHEMA "   . $f_db_schema  );   
 567  
 568              if ( !$rs ) {
 569                  $t_result = false;
 570                  print_test_result( BAD, true, 'Does administrative user have access to create the database? ( ' .  db_error_msg() . ' )' );
 571                  $t_install_state--;    # db creation failed, allow user to re-enter user/password info
 572              } else {
 573                  print_test_result( GOOD );
 574              }
 575          } else {
 576              $sqlarray = $dict->CreateDatabase( $f_database_name );
 577              $ret = $dict->ExecuteSQLArray( $sqlarray );
 578              if( $ret == 2) {
 579                  print_test_result( GOOD );
 580              } else {
 581                  $t_error = db_error_msg();
 582                  if( strstr( $t_error, 'atabase exists' ) ) {
 583                      print_test_result( BAD, false, 'Database already exists? ( ' .  db_error_msg() . ' )' );
 584                  } else {
 585                      print_test_result( BAD, true, 'Does administrative user have access to create the database? ( ' .  db_error_msg() . ' )' );
 586                      $t_install_state--;    # db creation failed, allow user to re-enter user/password info
 587                  }
 588              }
 589              $g_db->Close();
 590          }
 591      }
 592      ?>
 593  </tr>
 594  <tr>
 595      <td bgcolor="#ffffff">
 596          Attempting to connect to database as user
 597      </td>
 598      <?php
 599          $g_db = ADONewConnection($f_db_type);
 600          $t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
 601  
 602          if ( $f_db_type == 'db2' ) {
 603              $result = &$g_db->execute( 'set schema ' . $f_db_schema );
 604              if ( $result === false ) {
 605                  echo $g_db->errorMsg();
 606              }
 607          }
 608  
 609          if ( $t_result == true ) {
 610              print_test_result( GOOD );
 611          } else {
 612              print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' .  db_error_msg() . ' )' );
 613          }
 614          $g_db->Close();
 615      ?>
 616  </tr>
 617  <?php
 618      }
 619  
 620      # install the tables
 621      if ( false == $g_failed ) {
 622          $g_db_connected = false; # fake out database access routines used by config_get
 623          $GLOBALS['g_db_type'] = $f_db_type; # database_api references this
 624          require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'schema.php' );
 625          $g_db = ADONewConnection( $f_db_type );
 626          $t_result = @$g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name );
 627          if ( ! $f_log_queries ) {
 628              $g_db_connected = true; # fake out database access routines used by config_get
 629          }
 630          $t_last_update = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS );
 631          $lastid = sizeof( $upgrade ) - 1;
 632          $i = $t_last_update + 1;
 633          if ( $f_log_queries ) {
 634              echo '<tr><td bgcolor="#ffffff" col_span="2"> Database Creation Suppressed, SQL Queries follow <pre>';
 635          }
 636  
 637          if ( $f_db_type == 'db2' ) {
 638              $result = &$g_db->execute( 'set schema ' . $f_db_schema );
 639              if ( $result === false ) {
 640                  echo $g_db->errorMsg();
 641              }
 642          }
 643  
 644          while ( ( $i <= $lastid ) && ! $g_failed ) {
 645              if ( ! $f_log_queries ) {
 646                  echo '<tr><td bgcolor="#ffffff">';
 647              }
 648  
 649              $dict = NewDataDictionary($g_db);
 650              $t_sql = true;
 651              $t_target = $upgrade[$i][1][0];
 652              if ( $upgrade[$i][0] == 'InsertData' ) {
 653                  $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] );
 654              } else if ( $upgrade[$i][0] == 'UpdateSQL' ) {
 655                  $sqlarray = array( $upgrade[$i][1] );
 656                  $t_target = $upgrade[$i][1];
 657              } else if ( $upgrade[$i][0] == 'UpdateFunction' ) {
 658                  $sqlarray = array( $upgrade[$i][1] );
 659                  $t_sql = false;
 660                  $t_target = $upgrade[$i][1];
 661              } else {
 662                  $sqlarray = call_user_func_array(Array($dict,$upgrade[$i][0]),$upgrade[$i][1]);
 663              }
 664              if ( $f_log_queries ) {
 665                  foreach ( $sqlarray as $sql ) {
 666                      echo htmlentities( $sql ) . ";\r\n\r\n";
 667                  }
 668              } else {
 669                  echo 'Schema ' . $upgrade[$i][0] . ' ( ' . $t_target . ' )</td>';
 670                  if ($t_sql)
 671                      $ret = $dict->ExecuteSQLArray($sqlarray);
 672                  else 
 673                      $ret = call_user_func( 'install_' . $sqlarray[0] );
 674                  if ( $ret == 2 ) {
 675                      print_test_result( GOOD );
 676                      config_set( 'database_version', $i );
 677                  } else {
 678                      print_test_result( BAD, true, $sqlarray[0] . '<br />' . $g_db->ErrorMsg() );
 679                  }
 680                  echo '</tr>';
 681              }
 682              $i++;
 683          }
 684          if ( $f_log_queries ) {
 685              # add a query to set the database version
 686              echo 'INSERT INTO mantis_config_table ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $lastid . '\', 1, 90, \'database_version\', 20, 0 );' . "\r\n";
 687              echo '</pre></br /><p style="color:red">Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding.</td></tr>';
 688          }
 689  
 690      }
 691      if ( false == $g_failed ) {
 692          $t_install_state++;
 693      } else {
 694          $t_install_state--;
 695      }
 696  
 697  ?>
 698  </table>
 699  <?php
 700  }  # end install_state == 3
 701  
 702  # database installed, get any additional information
 703  if ( 4 == $t_install_state ) {
 704      # @@@ to be written
 705      #  must post data gathered to preserve it
 706  ?>
 707          <input name="hostname" type="hidden" value="<?php echo $f_hostname ?>"></input>
 708          <input name="db_type" type="hidden" value="<?php echo $f_db_type ?>"></input>
 709          <input name="database_name" type="hidden" value="<?php echo $f_database_name ?>"></input>
 710          <input name="db_username" type="hidden" value="<?php echo $f_db_username ?>"></input>
 711          <input name="db_password" type="hidden" value="<?php echo $f_db_password ?>"></input>
 712          <input name="admin_username" type="hidden" value="<?php echo $f_admin_username ?>"></input>
 713          <input name="admin_password" type="hidden" value="<?php echo $f_admin_password ?>"></input>
 714          <input name="log_queries" type="hidden" value="<?php echo ( $f_log_queries ? 1 : 0 ) ?>"></input>
 715          <input name="db_exists" type="hidden" value="<?php echo ( $f_db_exists ? 1 : 0 ) ?>"></input>
 716  <?php
 717      # must post <input name="install" type="hidden" value="5"></input>
 718      # rather than the following line
 719          $t_install_state++;
 720  }  # end install_state == 4
 721  
 722  # all checks have passed, install the database
 723  if ( 5 == $t_install_state ) {
 724          $t_config_filename = $g_absolute_path . 'config_inc.php';
 725          $t_config_exists = file_exists ( $t_config_filename );
 726  ?>
 727  <table width="100%" border="0" cellpadding="10" cellspacing="1">
 728  <tr>
 729      <td bgcolor="#e8e8e8" colspan="2">
 730          <span class="title">Write Configuration File(s)</span>
 731      </td>
 732  </tr>
 733  
 734  <tr>
 735      <td bgcolor="#ffffff">
 736          <?php
 737              if ( !$t_config_exists ) {
 738                  echo 'Creating Configuration File (config_inc.php)<br />';
 739                  echo '<font color="red">(if this file is not created, create it manually with the contents below)</font>';
 740              } else {
 741                  echo 'Updating Configuration File (config_inc.php)<br />';
 742              }
 743           ?>
 744      </td>
 745      <?php
 746          $t_config = '<?php'."\r\n";
 747          $t_config .= "\t\$g_hostname = '$f_hostname';\r\n";
 748          $t_config .= "\t\$g_db_type = '$f_db_type';\r\n";
 749          $t_config .= "\t\$g_database_name = '$f_database_name';\r\n";
 750          $t_config .= "\t\$g_db_username = '$f_db_username';\r\n";
 751          $t_config .= "\t\$g_db_password = '$f_db_password';\r\n";
 752  
 753          if ( $f_db_type == 'db2' ) {
 754              $t_config .= "\t\$g_db_schema = '$f_db_schema';\r\n";
 755          }
 756  
 757          $t_config .= '?>' . "\r\n";
 758          $t_write_failed = true;
 759  
 760          if ( !$t_config_exists ) {
 761              if ( $fd = @fopen( $t_config_filename, 'w' ) ) {
 762                  fwrite( $fd, $t_config );
 763                  fclose( $fd );
 764              }
 765  
 766              if ( file_exists ( $t_config_filename ) ) {
 767                  print_test_result( GOOD );
 768                  $t_write_failed = false;
 769              } else {
 770                  print_test_result( BAD, false, 'cannot write ' . $t_config_filename );
 771              }
 772          } else {
 773              # already exists, see if the information is the same
 774              if ( ( $f_hostname != config_get( 'hostname', '' ) ) ||
 775                      ( $f_db_type != config_get( 'db_type', '' ) ) ||
 776                      ( $f_database_name != config_get( 'database_name', '') ) ||
 777                      ( $f_db_schema != config_get( 'db_schema', '') ) ||
 778                      ( $f_db_username != config_get( 'db_username', '' ) ) ||
 779                      ( $f_db_password != config_get( 'db_password', '' ) ) ) {
 780                  print_test_result( BAD, false, 'file ' . $g_absolute_path . 'config_inc.php' . ' already exists and has different settings' );
 781              } else {
 782                  print_test_result( GOOD, false, 'file not updated' );
 783                  $t_write_failed = false;
 784              }
 785          }
 786      ?>
 787  </tr>
 788  <?php
 789      if ( true == $t_write_failed ) {
 790          echo '<tr><table width="50%" border="0" cellpadding="10" cellspacing="1" align="center">';
 791          echo '<tr><td>Please add the following lines to ' . $g_absolute_path . 'config_inc.php before continuing to the database upgrade check:</td></tr>';
 792          echo '<tr><td><pre>' . htmlentities( $t_config ) . '</pre></td></tr></table></tr>';
 793      }
 794  ?>
 795  
 796  </table>
 797  
 798  <?php
 799      if ( false == $g_failed ) {
 800          $t_install_state++;
 801      }
 802  }  # end install_state == 5
 803  
 804  if ( 6 == $t_install_state ) {
 805  # post install checks
 806  ?>
 807  <table width="100%" bgcolor="#222222" border="0" cellpadding="10" cellspacing="1">
 808  <tr>
 809      <td bgcolor="#e8e8e8" colspan="2">
 810          <span class="title">Checking Installation...</span>
 811      </td>
 812  </tr>
 813  
 814  <!-- Checking register_globals are off -->
 815  <?php print_test( 'Checking for register_globals are off for mantis', ! ini_get_bool( 'register_globals' ), false, 'change php.ini to disable register_globals setting' ) ?>
 816  
 817  <tr>
 818      <td bgcolor="#ffffff">
 819          Attempting to connect to database as user
 820      </td>
 821      <?php
 822          $g_db = ADONewConnection($f_db_type);
 823          $t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
 824  
 825          if ( $t_result == true ) {
 826              print_test_result( GOOD );
 827          } else {
 828              print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' .  db_error_msg() . ' )' );
 829          }
 830  
 831          if ( $f_db_type == 'db2' ) {
 832              $result = &$g_db->execute('set schema ' . $f_db_schema);
 833              if ( $result === false ) {
 834                  echo $g_db->errorMsg();
 835              }
 836          }
 837      ?>
 838  </tr>
 839  <tr>
 840      <td bgcolor="#ffffff">
 841          checking ability to SELECT records
 842      </td>
 843      <?php
 844          $t_mantis_config_table = config_get_global( 'mantis_config_table' );
 845          $t_query = "SELECT COUNT(*) FROM $t_mantis_config_table";
 846          $t_result = @$g_db->Execute( $t_query );
 847  
 848          if ( $t_result != false ) {
 849              print_test_result( GOOD );
 850              
 851          } else {
 852              print_test_result( BAD, true, 'Database user doesn\'t have SELECT access to the database ( ' .  db_error_msg() . ' )' );
 853          }
 854      ?>
 855  </tr>
 856  <tr>
 857      <td bgcolor="#ffffff">
 858          checking ability to INSERT records
 859      </td>
 860      <?php
 861          $t_query = "INSERT INTO $t_mantis_config_table ( value, type, access_reqd, config_id, project_id, user_id ) VALUES ('test', 1, 90, 'database_test', 20, 0 )";
 862          $t_result = @$g_db->Execute( $t_query );
 863  
 864          if ( $t_result != false ) {
 865              print_test_result( GOOD );
 866              
 867          } else {
 868              print_test_result( BAD, true, 'Database user doesn\'t have INSERT access to the database ( ' .  db_error_msg() . ' )' );
 869          }
 870      ?>
 871  </tr>
 872  <tr>
 873      <td bgcolor="#ffffff">
 874          checking ability to UPDATE records
 875      </td>
 876      <?php
 877          $t_query = "UPDATE $t_mantis_config_table SET value='test_update' WHERE config_id='database_test'";
 878          $t_result = @$g_db->Execute( $t_query );
 879  
 880          if ( $t_result != false ) {
 881              print_test_result( GOOD );
 882              
 883          } else {
 884              print_test_result( BAD, true, 'Database user doesn\'t have UPDATE access to the database ( ' .  db_error_msg() . ' )' );
 885          }
 886      ?>
 887  </tr>
 888  <tr>
 889      <td bgcolor="#ffffff">
 890          checking ability to DELETE records
 891      </td>
 892      <?php
 893          $t_query = "DELETE FROM $t_mantis_config_table WHERE config_id='database_test'";
 894          $t_result = @$g_db->Execute( $t_query );
 895  
 896          if ( $t_result != false ) {
 897              print_test_result( GOOD );
 898              
 899          } else {
 900              print_test_result( BAD, true, 'Database user doesn\'t have DELETE access to the database ( ' .  db_error_msg() . ' )' );
 901          }
 902      ?>
 903  </tr>
 904  </table>
 905  <?php
 906      if ( false == $g_failed ) {
 907          $t_install_state++;
 908      }
 909  }  # end install_state == 6
 910  
 911  if ( 7 == $t_install_state ) {
 912  # cleanup and launch upgrade
 913  ?>
 914  <p>Install was successful.</p>
 915  <?php if ( $f_db_exists ) { ?>
 916  <p><a href="../login_page.php">Continue</a> to log into Mantis</p>
 917  <?php } else { ?>
 918  <p>Please log in as the administrator and <a href="../manage_proj_create_page.php">create</a> your first project.
 919  
 920  <?php }
 921  } # end install_state == 7
 922  
 923  
 924  if( $g_failed ) {
 925  ?>
 926  <table width="100%" bgcolor="#222222" border="0" cellpadding="10" cellspacing="1">
 927  <tr>
 928      <td bgcolor="#e8e8e8" colspan="2">
 929          <span class="title">Checks Failed...</span>
 930      </td>
 931  </tr>
 932  <tr>
 933      <td bgcolor="#ffffff">Please correct failed checks</td>
 934      <td bgcolor="#ffffff">
 935          <input name="install" type="hidden" value="<?php echo $t_install_state ?>"></input>
 936          <input name="hostname" type="hidden" value="<?php echo $f_hostname ?>"></input>
 937          <input name="db_type" type="hidden" value="<?php echo $f_db_type ?>"></input>
 938          <input name="database_name" type="hidden" value="<?php echo $f_database_name ?>"></input>
 939          <input name="db_username" type="hidden" value="<?php echo $f_db_username ?>"></input>
 940          <input name="db_password" type="hidden" value="<?php echo $f_db_password ?>"></input>
 941          <input name="admin_username" type="hidden" value="<?php echo $f_admin_username ?>"></input>
 942          <input name="admin_password" type="hidden" value="<?php echo $f_admin_password ?>"></input>
 943          <input name="log_queries" type="hidden" value="<?php echo ( $f_log_queries ? 1 : 0 ) ?>"></input>
 944          <input name="retry" type="submit" value="Retry"></input>
 945          <input name="db_exists" type="hidden" value="<?php echo ( $f_db_exists ? 1 : 0 ) ?>"></input>
 946      </td>
 947  </tr>
 948  </table>
 949  
 950  <?php
 951  }
 952  ?>
 953  
 954  </form>
 955  
 956  </body>
 957  </html>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics