install/includes/stages/database_post.php
changeset 857 f3a5a276208c
parent 801 eb8b23f11744
child 1081 745200a9cc2a
equal deleted inserted replaced
856:0b7ff06aad13 857:f3a5a276208c
    20 // Start up the DBAL
    20 // Start up the DBAL
    21 require( ENANO_ROOT . '/includes/dbal.php' );
    21 require( ENANO_ROOT . '/includes/dbal.php' );
    22 require( ENANO_ROOT . '/includes/sql_parse.php' );
    22 require( ENANO_ROOT . '/includes/sql_parse.php' );
    23 $dbal = new $driver();
    23 $dbal = new $driver();
    24 $db_host =& $_POST['db_host'];
    24 $db_host =& $_POST['db_host'];
       
    25 $db_port =& $_POST['db_port'];
    25 $db_user =& $_POST['db_user'];
    26 $db_user =& $_POST['db_user'];
    26 $db_pass =& $_POST['db_pass'];
    27 $db_pass =& $_POST['db_pass'];
    27 $db_name =& $_POST['db_name'];
    28 $db_name =& $_POST['db_name'];
    28 $db_prefix =& $_POST['table_prefix'];
    29 $db_prefix =& $_POST['table_prefix'];
    29 $db_root_user =& $_POST['db_root_user'];
    30 $db_root_user =& $_POST['db_root_user'];
    34   $ui->show_header();
    35   $ui->show_header();
    35   echo '<p>That table prefix isn\'t going to work.</p>';
    36   echo '<p>That table prefix isn\'t going to work.</p>';
    36   return true;
    37   return true;
    37 }
    38 }
    38 
    39 
    39 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name);
    40 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port);
    40 
    41 
    41 // If connection failed, we have the root login, AND we're on MySQL, try to force our way in
    42 // If connection failed, we have the root login, AND we're on MySQL, try to force our way in
    42 if ( !$result && !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) && $driver == 'mysql' )
    43 if ( !$result && !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) && $driver == 'mysql' )
    43 {
    44 {
    44   // Allow a jump / breakout
    45   // Allow a jump / breakout
    45   switch ( 'foo' ) { case 'foo':
    46   switch ( 'foo' ) { case 'foo':
    46       
    47       
    47     // Try to connect to the DB as root
    48     // Try to connect to the DB as root
    48     $result_root = $dbal->connect(true, $db_host, $db_root_user, $db_root_pass, 'mysql');
    49     $result_root = $dbal->connect(true, $db_host, $db_root_user, $db_root_pass, 'mysql', $db_port);
    49     if ( !$result_root )
    50     if ( !$result_root )
    50       break;
    51       break;
    51     
    52     
    52     $q = $dbal->sql_query('CREATE DATABASE IF NOT EXISTS `' . $dbal->escape($db_name) . '`;');
    53     $q = $dbal->sql_query('CREATE DATABASE IF NOT EXISTS `' . $dbal->escape($db_name) . '`;');
    53     if ( !$q )
    54     if ( !$q )
    66     
    67     
    67     if ( !$q )
    68     if ( !$q )
    68       break;
    69       break;
    69     
    70     
    70     $dbal->close();
    71     $dbal->close();
    71     $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name);
    72     $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port);
    72       
    73       
    73     break;
    74     break;
    74   }
    75   }
    75 }
    76 }
    76 
    77 
   110   if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) )
   111   if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) )
   111   {
   112   {
   112     echo '<p>That table prefix isn\'t going to work.</p>';
   113     echo '<p>That table prefix isn\'t going to work.</p>';
   113     return true;
   114     return true;
   114   }
   115   }
       
   116   if ( !preg_match('/^[0-9]*$/', $db_port) )
       
   117   {
       
   118     echo '<p>That port isn\'t going to work.</p>';
       
   119     return true;
       
   120   }
   115   fwrite($ch, "<?php
   121   fwrite($ch, "<?php
   116 // Enano temporary configuration file, will be OVERWRITTEN after installation.
   122 // Enano temporary configuration file, will be OVERWRITTEN after installation.
   117 
   123 
   118 \$dbdriver = '$driver';
   124 \$dbdriver = '$driver';
   119 \$dbhost = '$db_host';
   125 \$dbhost = '$db_host';
       
   126 \$dbport = $db_port;
   120 \$dbname = '$db_name';
   127 \$dbname = '$db_name';
   121 \$dbuser = '$db_user';
   128 \$dbuser = '$db_user';
   122 \$dbpasswd = '$db_pass';
   129 \$dbpasswd = '$db_pass';
   123 @define('table_prefix', '$db_prefix');
   130 @define('table_prefix', '$db_prefix');
   124 
   131