install.php
changeset 326 ab66d6d1f1f4
parent 304 e2cb5f1432c8
parent 322 5f1cd51bf1be
child 330 c94af5b5c40f
equal deleted inserted replaced
314:474f8be55943 326:ab66d6d1f1f4
    43   define('contentPath', $sp);
    43   define('contentPath', $sp);
    44 }
    44 }
    45 global $_starttime, $this_page, $sideinfo;
    45 global $_starttime, $this_page, $sideinfo;
    46 $_starttime = microtime(true);
    46 $_starttime = microtime(true);
    47 
    47 
       
    48 global $db;
       
    49 
    48 // Determine directory (special case for development servers)
    50 // Determine directory (special case for development servers)
    49 if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') )
    51 if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') )
    50 {
    52 {
    51   $filename = str_replace('/repo/', '/', __FILE__);
    53   $filename = str_replace('/repo/', '/', __FILE__);
    52 }
    54 }
   183 // INSTALLER STAGES
   185 // INSTALLER STAGES
   184 //
   186 //
   185 
   187 
   186 function stg_mysql_connect($act_get = false)
   188 function stg_mysql_connect($act_get = false)
   187 {
   189 {
       
   190   global $db;
       
   191   $db = new mysql();
       
   192   
   188   static $conn = false;
   193   static $conn = false;
   189   if ( $act_get )
   194   if ( $act_get )
   190     return $conn;
   195     return $conn;
   191   
   196   
   192   $db_user =& $_POST['db_user'];
   197   $db_user =& $_POST['db_user'];
   307     {
   312     {
   308       // really failed this time; bail out
   313       // really failed this time; bail out
   309       return false;
   314       return false;
   310     }
   315     }
   311   }
   316   }
       
   317   // initialize DBAL
       
   318   $db->connect(true, $_POST['db_host'], $db_user, $db_pass, $db_name);
   312   // connected and database exists
   319   // connected and database exists
   313   return true;
   320   return true;
   314 }
   321 }
   315 
   322 
       
   323 function stg_pgsql_connect($act_get = false)
       
   324 {
       
   325   global $db;
       
   326   $db = new postgresql();
       
   327   
       
   328   static $conn = false;
       
   329   if ( $act_get )
       
   330     return $conn;
       
   331   
       
   332   $db_user =& $_POST['db_user'];
       
   333   $db_pass =& $_POST['db_pass'];
       
   334   $db_name =& $_POST['db_name'];
       
   335   
       
   336   if ( !preg_match('/^[a-z0-9_-]+$/', $db_name) )
       
   337   {
       
   338     $db_name = htmlspecialchars($db_name);
       
   339     die("<p>SECURITY: malformed database name \"$db_name\"</p>");
       
   340   }
       
   341   
       
   342   // First, try to connect using the normal credentials
       
   343   $conn = @pg_connect("host={$_POST['db_host']} port=5432 user={$_POST['db_user']} password={$_POST['db_pass']}");
       
   344   if ( !$conn )
       
   345   {
       
   346     // Connection failed. Do we have the root username and password?
       
   347     if ( !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) )
       
   348     {
       
   349       $conn_root = @pg_connect("host={$_POST['db_host']} port=5432 user={$_POST['db_root_user']} password={$_POST['db_root_pass']}");
       
   350       if ( !$conn_root )
       
   351       {
       
   352         // Couldn't connect using either set of credentials. Bail out.
       
   353         return false;
       
   354       }
       
   355       unset($db_user, $db_pass);
       
   356       $db_user = pg_escape_string($_POST['db_user']);
       
   357       $db_pass = pg_escape_string($_POST['db_pass']);
       
   358       // Create the user account
       
   359       $q = @pg_query("CREATE ROLE '$db_user' WITH NOSUPERUSER UNENCRYPTED PASSWORD '$db_pass';", $conn_root);
       
   360       if ( !$q )
       
   361       {
       
   362         return false;
       
   363       }
       
   364       pg_close($conn_root);
       
   365       $conn = @pg_connect("host={$_POST['db_host']} port=5432 user={$_POST['db_user']} password={$_POST['db_pass']}");
       
   366       if ( !$conn )
       
   367       {
       
   368         // This should honestly never happen.
       
   369         return false;
       
   370       }
       
   371     }
       
   372   }
       
   373   if ( !$q )
       
   374   {
       
   375     // access denied to the database; try the whole root schenanegan again
       
   376     if ( !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) )
       
   377     {
       
   378       $conn_root = @pg_connect("host={$_POST['db_host']} port=5432 user={$_POST['db_root_user']} password={$_POST['db_root_pass']}");
       
   379       if ( !$conn_root )
       
   380       {
       
   381         // Couldn't connect as root; bail out
       
   382         return false;
       
   383       }
       
   384       unset($db_user, $db_pass);
       
   385       $db_user = pg_escape_string($_POST['db_user']);
       
   386       $db_pass = pg_escape_string($_POST['db_pass']);
       
   387       // create the database, if it doesn't exist
       
   388       $q = @mysql_query("CREATE DATABASE $db_name WITH OWNER $db_user;", $conn_root);
       
   389       if ( !$q )
       
   390       {
       
   391         // this really should never fail, so don't give any tolerance to it
       
   392         return false;
       
   393       }
       
   394       // Setting the owner to $db_user should grant all the rights we need
       
   395       pg_close($conn_root);
       
   396       // grant tables have hopefully been flushed, kill and reconnect our regular user connection
       
   397       pg_close($conn);
       
   398       $conn = @pg_connect("host={$_POST['db_host']} port=5432 user={$_POST['db_user']} password={$_POST['db_pass']}");
       
   399       if ( !$conn )
       
   400       {
       
   401         return false;
       
   402       }
       
   403     }
       
   404     else
       
   405     {
       
   406       return false;
       
   407     }
       
   408     // try again
       
   409     $q = @mysql_query("USE `$db_name`;", $conn);
       
   410     if ( !$q )
       
   411     {
       
   412       // really failed this time; bail out
       
   413       return false;
       
   414     }
       
   415   }
       
   416   // initialize DBAL
       
   417   $db->connect(true, $_POST['db_host'], $db_user, $db_pass, $db_name);
       
   418   // connected and database exists
       
   419   return true;
       
   420 }
       
   421 
   316 function stg_drop_tables()
   422 function stg_drop_tables()
   317 {
   423 {
   318   $conn = stg_mysql_connect(true);
   424   global $db;
   319   if ( !$conn )
       
   320     return false;
       
   321   // Our list of tables included in Enano
   425   // Our list of tables included in Enano
   322   $tables = Array( 'categories', 'comments', 'config', 'logs', 'page_text', 'session_keys', 'pages', 'users', 'users_extra', 'themes', 'buddies', 'banlist', 'files', 'privmsgs', 'sidebar', 'hits', 'search_index', 'groups', 'group_members', 'acl', 'tags', 'page_groups', 'page_group_members' );
   426   $tables = Array( 'categories', 'comments', 'config', 'logs', 'page_text', 'session_keys', 'pages', 'users', 'users_extra', 'themes', 'buddies', 'banlist', 'files', 'privmsgs', 'sidebar', 'hits', 'search_index', 'groups', 'group_members', 'acl', 'tags', 'page_groups', 'page_group_members' );
   323   
   427   
   324   // Drop each table individually; if it fails, it probably means we're trying to drop a
   428   // Drop each table individually; if it fails, it probably means we're trying to drop a
   325   // table that didn't exist in the Enano version we're deleting the database for.
   429   // table that didn't exist in the Enano version we're deleting the database for.
   326   foreach ( $tables as $table )
   430   foreach ( $tables as $table )
   327   {
   431   {
   328     // Remember that table_prefix is sanitized.
   432     // Remember that table_prefix is sanitized.
   329     $table = "{$_POST['table_prefix']}$table";
   433     $table = "{$_POST['table_prefix']}$table";
   330     @mysql_query("DROP TABLE $table;", $conn);
   434     $db->sql_query("DROP TABLE $table;", $conn);
   331   }
   435   }
   332   return true;
   436   return true;
   333 }
   437 }
   334 
   438 
   335 function stg_decrypt_admin_pass($act_get = false)
   439 function stg_decrypt_admin_pass($act_get = false)
   377 {
   481 {
   378   static $schema;
   482   static $schema;
   379   if ( $act_get )
   483   if ( $act_get )
   380     return $schema;
   484     return $schema;
   381   
   485   
       
   486   global $db;
       
   487   
   382   $admin_pass = stg_decrypt_admin_pass(true);
   488   $admin_pass = stg_decrypt_admin_pass(true);
   383   $key = stg_generate_aes_key(true);
   489   $key = stg_generate_aes_key(true);
   384   $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
   490   $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
   385   $key = $aes->hextostring($key);
   491   $key = $aes->hextostring($key);
   386   $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   492   $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   387   
   493   
   388   $cacheonoff = is_writable(ENANO_ROOT.'/cache/') ? '1' : '0';
   494   $cacheonoff = is_writable(ENANO_ROOT.'/cache/') ? '1' : '0';
   389   
   495   
   390   $admin_user = $_POST['admin_user'];
   496   $admin_user = $_POST['admin_user'];
   391   $admin_user = str_replace('_', ' ', $admin_user);
   497   $admin_user = str_replace('_', ' ', $admin_user);
   392   $admin_user = mysql_real_escape_string($admin_user);
   498   $admin_user = $db->escape($admin_user);
   393   
   499   
   394   $schema = file_get_contents('schema.sql');
   500   switch ( $_POST['db_driver'] )
   395   $schema = str_replace('{{SITE_NAME}}',    mysql_real_escape_string($_POST['sitename']   ), $schema);
   501   {
   396   $schema = str_replace('{{SITE_DESC}}',    mysql_real_escape_string($_POST['sitedesc']   ), $schema);
   502     case 'mysql':
   397   $schema = str_replace('{{COPYRIGHT}}',    mysql_real_escape_string($_POST['copyright']  ), $schema);
   503       $schema_file = 'schema.sql';
       
   504       break;
       
   505     case 'postgresql':
       
   506       $schema_file = 'schema-pg.sql';
       
   507       break;
       
   508   }
       
   509   
       
   510   if ( !isset($schema_file) )
       
   511     die('insanity');
       
   512   
       
   513   $schema = file_get_contents($schema_file);
       
   514   $schema = str_replace('{{SITE_NAME}}',    $db->escape($_POST['sitename']   ), $schema);
       
   515   $schema = str_replace('{{SITE_DESC}}',    $db->escape($_POST['sitedesc']   ), $schema);
       
   516   $schema = str_replace('{{COPYRIGHT}}',    $db->escape($_POST['copyright']  ), $schema);
   398   $schema = str_replace('{{ADMIN_USER}}',   $admin_user                                    , $schema);
   517   $schema = str_replace('{{ADMIN_USER}}',   $admin_user                                    , $schema);
   399   $schema = str_replace('{{ADMIN_PASS}}',   mysql_real_escape_string($admin_pass          ), $schema);
   518   $schema = str_replace('{{ADMIN_PASS}}',   $db->escape($admin_pass          ), $schema);
   400   $schema = str_replace('{{ADMIN_EMAIL}}',  mysql_real_escape_string($_POST['admin_email']), $schema);
   519   $schema = str_replace('{{ADMIN_EMAIL}}',  $db->escape($_POST['admin_email']), $schema);
   401   $schema = str_replace('{{ENABLE_CACHE}}', mysql_real_escape_string($cacheonoff          ), $schema);
   520   $schema = str_replace('{{ENABLE_CACHE}}', $db->escape($cacheonoff          ), $schema);
   402   $schema = str_replace('{{REAL_NAME}}',    '',                                              $schema);
   521   $schema = str_replace('{{REAL_NAME}}',    '',                                              $schema);
   403   $schema = str_replace('{{TABLE_PREFIX}}', $_POST['table_prefix'],                          $schema);
   522   $schema = str_replace('{{TABLE_PREFIX}}', $_POST['table_prefix'],                          $schema);
   404   $schema = str_replace('{{VERSION}}',      ENANO_VERSION,                                   $schema);
   523   $schema = str_replace('{{VERSION}}',      ENANO_VERSION,                                   $schema);
   405   $schema = str_replace('{{ADMIN_EMBED_PHP}}', $_POST['admin_embed_php'],                    $schema);
   524   $schema = str_replace('{{ADMIN_EMBED_PHP}}', $_POST['admin_embed_php'],                    $schema);
   406   // Not anymore!! :-D
   525   // Not anymore!! :-D
   816     $v = mysql_get_server_info();
   935     $v = mysql_get_server_info();
   817     if(version_compare($v, '4.1.17', '<')) die('vers'.$v);
   936     if(version_compare($v, '4.1.17', '<')) die('vers'.$v);
   818     mysql_close($conn);
   937     mysql_close($conn);
   819     die('good');
   938     die('good');
   820     break;
   939     break;
       
   940   case 'pgsql_test':
       
   941     error_reporting(0);
       
   942     $dbhost     = rawurldecode($_POST['host']);
       
   943     $dbname     = rawurldecode($_POST['name']);
       
   944     $dbuser     = rawurldecode($_POST['user']);
       
   945     $dbpass     = rawurldecode($_POST['pass']);
       
   946     $dbrootuser = rawurldecode($_POST['root_user']);
       
   947     $dbrootpass = rawurldecode($_POST['root_pass']);
       
   948     if($dbrootuser != '')
       
   949     {
       
   950       $conn = @pg_connect("host=$dbhost port=5432 user=$dbuser password=$dbpass dbname=$dbname");
       
   951       if(!$conn)
       
   952       {
       
   953         $e = pg_last_error();
       
   954         if(strstr($e, "Lost connection"))
       
   955           die('host'.$e);
       
   956         else
       
   957           die('root'.$e);
       
   958       }
       
   959       $rsp = 'good';
       
   960       $q = mysql_query('USE `' . mysql_real_escape_string($dbname) . '`;', $conn);
       
   961       if(!$q)
       
   962       {
       
   963         $e = mysql_error();
       
   964         if(strstr($e, 'Unknown database'))
       
   965         {
       
   966           $rsp .= '_creating_db';
       
   967         }
       
   968       }
       
   969       mysql_close($conn);
       
   970       $conn = mysql_connect($dbhost, $dbuser, $dbpass);
       
   971       if(!$conn)
       
   972       {
       
   973         $e = mysql_error();
       
   974         if(strstr($e, "Lost connection"))
       
   975           die('host'.$e);
       
   976         else
       
   977           $rsp .= '_creating_user';
       
   978       }
       
   979       mysql_close($conn);
       
   980       die($rsp);
       
   981     }
       
   982     else
       
   983     {
       
   984       $conn = mysql_connect($dbhost, $dbuser, $dbpass);
       
   985       if(!$conn)
       
   986       {
       
   987         $e = mysql_error();
       
   988         if(strstr($e, "Lost connection"))
       
   989           die('host'.$e);
       
   990         else
       
   991           die('auth'.$e);
       
   992       }
       
   993       $q = mysql_query('USE `' . mysql_real_escape_string($dbname) . '`;', $conn);
       
   994       if(!$q)
       
   995       {
       
   996         $e = mysql_error();
       
   997         if(strstr($e, 'Unknown database'))
       
   998         {
       
   999           die('name'.$e);
       
  1000         }
       
  1001         else
       
  1002         {
       
  1003           die('perm'.$e);
       
  1004         }
       
  1005       }
       
  1006     }
       
  1007     $v = mysql_get_server_info();
       
  1008     if(version_compare($v, '4.1.17', '<')) die('vers'.$v);
       
  1009     mysql_close($conn);
       
  1010     die('good');
       
  1011     break;  
   821   case 'pophelp':
  1012   case 'pophelp':
   822     $topic = ( isset($_GET['topic']) ) ? $_GET['topic'] : 'invalid';
  1013     $topic = ( isset($_GET['topic']) ) ? $_GET['topic'] : 'invalid';
   823     switch($topic)
  1014     switch($topic)
   824     {
  1015     {
   825       case 'admin_embed_php':
  1016       case 'admin_embed_php':
   890 
  1081 
   891 $modestrings = Array(
  1082 $modestrings = Array(
   892               'welcome' => $lang->get('welcome_modetitle'),
  1083               'welcome' => $lang->get('welcome_modetitle'),
   893               'license' => $lang->get('license_modetitle'),
  1084               'license' => $lang->get('license_modetitle'),
   894               'sysreqs' => $lang->get('sysreqs_modetitle'),
  1085               'sysreqs' => $lang->get('sysreqs_modetitle'),
   895               'database'=> $lang->get('database_modetitle'),
  1086               'database' => $lang->get('database_modetitle'),
   896               'website' => $lang->get('website_modetitle'),
  1087               'database_mysql'=> $lang->get('database_mysql_modetitle'),
       
  1088               'database_pgsql'=> $lang->get('database_pgsql_modetitle'),
       
  1089               'website' => $lang->get('website_modetitle'), 
   897               'login'   => $lang->get('login_modetitle'),
  1090               'login'   => $lang->get('login_modetitle'),
   898               'confirm' => $lang->get('confirm_modetitle'),
  1091               'confirm' => $lang->get('confirm_modetitle'),
   899               'install' => $lang->get('install_modetitle'),
  1092               'install' => $lang->get('install_modetitle'),
   900               'finish'  => $lang->get('finish_modetitle'),
  1093               'finish'  => $lang->get('finish_modetitle'),
   901               '_hiddenstages' => '...', // all stages below this line are hidden
  1094               '_hiddenstages' => '...', // all stages below this line are hidden
  1025     <table border="0" cellspacing="0" cellpadding="0">
  1218     <table border="0" cellspacing="0" cellpadding="0">
  1026     <?php
  1219     <?php
  1027     run_test('return version_compare(\'4.3.0\', PHP_VERSION, \'<\');', $lang->get('sysreqs_req_php'), $lang->get('sysreqs_req_desc_php') );
  1220     run_test('return version_compare(\'4.3.0\', PHP_VERSION, \'<\');', $lang->get('sysreqs_req_php'), $lang->get('sysreqs_req_desc_php') );
  1028     run_test('return version_compare(\'5.2.0\', PHP_VERSION, \'<\');', $lang->get('sysreqs_req_php5'), $lang->get('sysreqs_req_desc_php5'), true);
  1221     run_test('return version_compare(\'5.2.0\', PHP_VERSION, \'<\');', $lang->get('sysreqs_req_php5'), $lang->get('sysreqs_req_desc_php5'), true);
  1029     run_test('return function_exists(\'mysql_connect\');', $lang->get('sysreqs_req_mysql'), $lang->get('sysreqs_req_desc_mysql') );
  1222     run_test('return function_exists(\'mysql_connect\');', $lang->get('sysreqs_req_mysql'), $lang->get('sysreqs_req_desc_mysql') );
       
  1223     run_test('return function_exists(\'pg_connect\');', 'PostgreSQL extension for PHP', 'It seems that your PHP installation does not have the PostgreSQL extension enabled. Because of this, you won\'t be able to use the PostgreSQL database driver. This is OK in the majority of cases. If you want to use PostgreSQL support, you\'ll need to either compile the PHP extension for Postgres or install the extension with your distribution\'s package manager. Windows administrators will need enable php_pgsql.dll in their php.ini.', true);
  1030     run_test('return @ini_get(\'file_uploads\');', $lang->get('sysreqs_req_uploads'), $lang->get('sysreqs_req_desc_uploads') );
  1224     run_test('return @ini_get(\'file_uploads\');', $lang->get('sysreqs_req_uploads'), $lang->get('sysreqs_req_desc_uploads') );
  1031     run_test('return is_apache();', $lang->get('sysreqs_req_apache'), $lang->get('sysreqs_req_desc_apache'), true);
  1225     run_test('return is_apache();', $lang->get('sysreqs_req_apache'), $lang->get('sysreqs_req_desc_apache'), true);
  1032     run_test('return is_writable(ENANO_ROOT.\'/config.new.php\');', $lang->get('sysreqs_req_config'), $lang->get('sysreqs_req_desc_config') );
  1226     run_test('return is_writable(ENANO_ROOT.\'/config.new.php\');', $lang->get('sysreqs_req_config'), $lang->get('sysreqs_req_desc_config') );
  1033     run_test('return file_exists(\'/usr/bin/convert\');', $lang->get('sysreqs_req_magick'), $lang->get('sysreqs_req_desc_magick'), true);
  1227     run_test('return file_exists(\'/usr/bin/convert\');', $lang->get('sysreqs_req_magick'), $lang->get('sysreqs_req_desc_magick'), true);
  1034     run_test('return is_writable(ENANO_ROOT.\'/cache/\');', $lang->get('sysreqs_req_cachewriteable'), $lang->get('sysreqs_req_desc_cachewriteable'), true);
  1228     run_test('return is_writable(ENANO_ROOT.\'/cache/\');', $lang->get('sysreqs_req_cachewriteable'), $lang->get('sysreqs_req_desc_cachewriteable'), true);
  1035     run_test('return is_writable(ENANO_ROOT.\'/files/\');', $lang->get('sysreqs_req_fileswriteable'), $lang->get('sysreqs_req_desc_fileswriteable'), true);
  1229     run_test('return is_writable(ENANO_ROOT.\'/files/\');', $lang->get('sysreqs_req_fileswriteable'), $lang->get('sysreqs_req_desc_fileswriteable'), true);
       
  1230     if ( !function_exists('mysql_connect') && !function_exists('pg_connect') )
       
  1231     {
       
  1232       run_test('return false;', 'No database drivers are available.', 'You need to have at least one database driver working to install Enano. See the warnings on MySQL and PostgreSQL above for more information on installing these database drivers.', false);
       
  1233     }
  1036     echo '</table>';
  1234     echo '</table>';
  1037     if(!$failed)
  1235     if(!$failed)
  1038     {
  1236     {
  1039       ?>
  1237       ?>
  1040       
  1238       
  1080     }
  1278     }
  1081     ?>
  1279     ?>
  1082     <?php
  1280     <?php
  1083     break;
  1281     break;
  1084   case "database":
  1282   case "database":
       
  1283     echo '<h3>Choose a database driver</h3>';
       
  1284     echo '<p>The next step is to choose the database driver that Enano will use. In most cases this is MySQL, but there are certain
       
  1285              advantages to PostgreSQL, which is made available only experimentally.</p>';
       
  1286     if ( @file_exists('/etc/enano-is-virt-appliance') )
       
  1287     {
       
  1288       echo '<p><b>You\'re using the Enano virtual appliance.</b><br />Unless you configured the appliance manually, PostgreSQL support is not available. In 99% of cases you\'ll want to click MySQL below.</p>';
       
  1289     }
       
  1290     
       
  1291     $mysql_disable_reason = '';
       
  1292     $pgsql_disable_reason = '';
       
  1293     $mysql_disable = '';
       
  1294     $pgsql_disable = '';
       
  1295     if ( !function_exists('mysql_connect') )
       
  1296     {
       
  1297       $mysql_disable = ' disabled="disabled"';
       
  1298       $mysql_disable_reason = 'You don\'t have the MySQL PHP extension installed.';
       
  1299     }
       
  1300     if ( !function_exists('pg_connect') )
       
  1301     {
       
  1302       $pgsql_disable = ' disabled="disabled"';
       
  1303       $pgsql_disable_reason = 'You don\'t have the PostgreSQL PHP extensnion installed.';
       
  1304     }
       
  1305     if ( function_exists('pg_connect') && version_compare(PHP_VERSION, '5.0.0', '<') )
       
  1306     {
       
  1307       $pgsql_disable = ' disabled="disabled"';
       
  1308       $pgsql_disable_reason = 'You need to have at least PHP 5 to use the PostgreSQL database driver.';
       
  1309     }
       
  1310     
       
  1311     echo '<form action="install.php" method="get">';
       
  1312     ?>
       
  1313     <table border="0" cellspacing="5">
       
  1314       <tr>
       
  1315         <td>
       
  1316           <input type="image" name="mode" value="database_mysql" src="images/about-powered-mysql.png"<?php echo $mysql_disable; ?>/>
       
  1317         </td>
       
  1318         <td<?php if ( $mysql_disable ) echo ' style="opacity: 0.5; filter: alpha(opacity=50);"'; ?>>
       
  1319           <b>MySQL</b><br />
       
  1320           Click this button to use MySQL as the database backend for your site. Most web hosts support MySQL, and if you have
       
  1321           administrative access to your MySQL server, you can create a new database and user during this installation process if you
       
  1322           haven't done so already.
       
  1323           <?php
       
  1324           if ( $mysql_disable )
       
  1325           {
       
  1326             echo "<br /><br /><b>$mysql_disable_reason</b>";
       
  1327           }
       
  1328           ?>
       
  1329         </td>
       
  1330       </tr>
       
  1331       <tr>
       
  1332         <td>
       
  1333           <input type="image" name="mode" value="database_pgsql" src="images/about-powered-pgsql.png"<?php echo $pgsql_disable; ?> />
       
  1334         </td>
       
  1335         <td<?php if ( $pgsql_disable ) echo ' style="opacity: 0.5; filter: alpha(opacity=50);"'; ?>>
       
  1336           <b>PostgreSQL</b><br />
       
  1337           Click this button to use PostgreSQL as the database backend for your site. While not as widely supported, PostgreSQL has more
       
  1338           liberal licensing conditions and when properly configured is faster than MySQL. Some plugins may not work with the PostgreSQL
       
  1339           driver.
       
  1340           <?php
       
  1341           if ( $pgsql_disable )
       
  1342           {
       
  1343             echo "<br /><br /><b>$pgsql_disable_reason</b>";
       
  1344           }
       
  1345           ?>
       
  1346         </td>
       
  1347       </tr>
       
  1348     </table>
       
  1349     <?php
       
  1350     echo '</form>';
       
  1351     break;
       
  1352   case "database_mysql":
  1085     ?>
  1353     ?>
  1086     <script type="text/javascript">
  1354     <script type="text/javascript">
  1087       function ajaxGet(uri, f) {
  1355       function ajaxGet(uri, f) {
  1088         if (window.XMLHttpRequest) {
  1356         if (window.XMLHttpRequest) {
  1089           ajax = new XMLHttpRequest();
  1357           ajax = new XMLHttpRequest();
  1285               ' . $lang->get('database_vm_login_info', array( 'host' => 'localhost', 'user' => 'enano', 'pass' => 'clurichaun', 'name' => 'enano_www1' )) . '
  1553               ' . $lang->get('database_vm_login_info', array( 'host' => 'localhost', 'user' => 'enano', 'pass' => 'clurichaun', 'name' => 'enano_www1' )) . '
  1286             </p>';
  1554             </p>';
  1287     }
  1555     }
  1288     ?>
  1556     ?>
  1289     <form name="dbinfo" action="install.php?mode=website" method="post">
  1557     <form name="dbinfo" action="install.php?mode=website" method="post">
       
  1558       <input type="hidden" name="db_driver" value="mysql" />
  1290       <table border="0">
  1559       <table border="0">
  1291         <tr>
  1560         <tr>
  1292           <td colspan="3" style="text-align: center">
  1561           <td colspan="3" style="text-align: center">
  1293             <h3><?php echo $lang->get('database_table_title'); ?></h3>
  1562             <h3><?php echo $lang->get('database_table_title'); ?></h3>
  1294           </td>
  1563           </td>
  1412               </p>
  1681               </p>
  1413             </td>
  1682             </td>
  1414           </tr>
  1683           </tr>
  1415         </table>
  1684         </table>
  1416       </div>
  1685       </div>
       
  1686         } else {
       
  1687           if (window.ActiveXObject) {           
       
  1688             ajax = new ActiveXObject("Microsoft.XMLHTTP");
       
  1689           } else {
       
  1690             alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
  1691             return;
       
  1692           }
       
  1693         }
       
  1694         ajax.onreadystatechange = f;
       
  1695         ajax.open('GET', uri, true);
       
  1696         ajax.send(null);
       
  1697       }
       
  1698       
       
  1699       function ajaxPost(uri, parms, f) {
       
  1700         if (window.XMLHttpRequest) {
       
  1701           ajax = new XMLHttpRequest();
       
  1702         } else {
       
  1703           if (window.ActiveXObject) {           
       
  1704             ajax = new ActiveXObject("Microsoft.XMLHTTP");
       
  1705           } else {
       
  1706             alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
  1707             return;
       
  1708           }
       
  1709         }
       
  1710         ajax.onreadystatechange = f;
       
  1711         ajax.open('POST', uri, true);
       
  1712         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
       
  1713         ajax.setRequestHeader("Content-length", parms.length);
       
  1714         ajax.setRequestHeader("Connection", "close");
       
  1715         ajax.send(parms);
       
  1716       }
       
  1717       function ajaxTestConnection()
       
  1718       {
       
  1719         v = verify();
       
  1720         if(!v)
       
  1721         {
       
  1722           alert('One or more of the form fields is incorrect. Please correct any information in the form that has an "X" next to it.');
       
  1723           return false;
       
  1724         }
       
  1725         var frm = document.forms.dbinfo;
       
  1726         db_host      = escape(frm.db_host.value.replace('+', '%2B'));
       
  1727         db_name      = escape(frm.db_name.value.replace('+', '%2B'));
       
  1728         db_user      = escape(frm.db_user.value.replace('+', '%2B'));
       
  1729         db_pass      = escape(frm.db_pass.value.replace('+', '%2B'));
       
  1730         db_root_user = escape(frm.db_root_user.value.replace('+', '%2B'));
       
  1731         db_root_pass = escape(frm.db_root_pass.value.replace('+', '%2B'));
       
  1732         
       
  1733         parms = 'host='+db_host+'&name='+db_name+'&user='+db_user+'&pass='+db_pass+'&root_user='+db_root_user+'&root_pass='+db_root_pass;
       
  1734         ajaxPost('<?php echo scriptPath; ?>/install.php?mode=pgsql_test', parms, function() {
       
  1735             if(ajax.readyState==4)
       
  1736             {
       
  1737               s = ajax.responseText.substr(0, 4);
       
  1738               t = ajax.responseText.substr(4, ajax.responseText.length);
       
  1739               if(s.substr(0, 4)=='good')
       
  1740               {
       
  1741                 document.getElementById('s_db_host').src='images/good.gif';
       
  1742                 document.getElementById('s_db_name').src='images/good.gif';
       
  1743                 document.getElementById('s_db_auth').src='images/good.gif';
       
  1744                 document.getElementById('s_db_root').src='images/good.gif';
       
  1745                 if(t.match(/_creating_db/)) document.getElementById('e_db_name').innerHTML = '<b>Warning:<\/b> The database you specified does not exist. It will be created during installation.';
       
  1746                 if(t.match(/_creating_user/)) document.getElementById('e_db_auth').innerHTML = '<b>Warning:<\/b> The specified regular user does not exist or the password is incorrect. The user will be created during installation. If the user already exists, the password will be reset.';
       
  1747                 document.getElementById('s_mysql_version').src='images/good.gif';
       
  1748                 document.getElementById('e_mysql_version').innerHTML = 'Your version of PostgreSQL meets Enano requirements.';
       
  1749               }
       
  1750               else
       
  1751               {
       
  1752                 switch(s)
       
  1753                 {
       
  1754                 case 'host':
       
  1755                   document.getElementById('s_db_host').src='images/bad.gif';
       
  1756                   document.getElementById('s_db_name').src='images/unknown.gif';
       
  1757                   document.getElementById('s_db_auth').src='images/unknown.gif';
       
  1758                   document.getElementById('s_db_root').src='images/unknown.gif';
       
  1759                   document.getElementById('e_db_host').innerHTML = '<b>Error:<\/b> The database server "'+document.forms.dbinfo.db_host.value+'" couldn\'t be contacted.<br \/>'+t;
       
  1760                   document.getElementById('e_mysql_version').innerHTML = 'The MySQL version that your server is running could not be determined.';
       
  1761                   break;
       
  1762                 case 'auth':
       
  1763                   document.getElementById('s_db_host').src='images/good.gif';
       
  1764                   document.getElementById('s_db_name').src='images/unknown.gif';
       
  1765                   document.getElementById('s_db_auth').src='images/bad.gif';
       
  1766                   document.getElementById('s_db_root').src='images/unknown.gif';
       
  1767                   document.getElementById('e_db_auth').innerHTML = '<b>Error:<\/b> Access to MySQL under the specified credentials was denied.<br \/>'+t;
       
  1768                   document.getElementById('e_mysql_version').innerHTML = 'The MySQL version that your server is running could not be determined.';
       
  1769                   break;
       
  1770                 case 'perm':
       
  1771                   document.getElementById('s_db_host').src='images/good.gif';
       
  1772                   document.getElementById('s_db_name').src='images/bad.gif';
       
  1773                   document.getElementById('s_db_auth').src='images/good.gif';
       
  1774                   document.getElementById('s_db_root').src='images/unknown.gif';
       
  1775                   document.getElementById('e_db_name').innerHTML = '<b>Error:<\/b> Access to the specified database using those login credentials was denied.<br \/>'+t;
       
  1776                   document.getElementById('e_mysql_version').innerHTML = 'The MySQL version that your server is running could not be determined.';
       
  1777                   break;
       
  1778                 case 'name':
       
  1779                   document.getElementById('s_db_host').src='images/good.gif';
       
  1780                   document.getElementById('s_db_name').src='images/bad.gif';
       
  1781                   document.getElementById('s_db_auth').src='images/good.gif';
       
  1782                   document.getElementById('s_db_root').src='images/unknown.gif';
       
  1783                   document.getElementById('e_db_name').innerHTML = '<b>Error:<\/b> The specified database does not exist<br \/>'+t;
       
  1784                   document.getElementById('e_mysql_version').innerHTML = 'The MySQL version that your server is running could not be determined.';
       
  1785                   break;
       
  1786                 case 'root':
       
  1787                   document.getElementById('s_db_host').src='images/good.gif';
       
  1788                   document.getElementById('s_db_name').src='images/unknown.gif';
       
  1789                   document.getElementById('s_db_auth').src='images/unknown.gif';
       
  1790                   document.getElementById('s_db_root').src='images/bad.gif';
       
  1791                   document.getElementById('e_db_root').innerHTML = '<b>Error:<\/b> Access to MySQL under the specified credentials was denied.<br \/>'+t;
       
  1792                   document.getElementById('e_mysql_version').innerHTML = 'The MySQL version that your server is running could not be determined.';
       
  1793                   break;
       
  1794                 case 'vers':
       
  1795                   document.getElementById('s_db_host').src='images/good.gif';
       
  1796                   document.getElementById('s_db_name').src='images/good.gif';
       
  1797                   document.getElementById('s_db_auth').src='images/good.gif';
       
  1798                   document.getElementById('s_db_root').src='images/good.gif';
       
  1799                   if(t.match(/_creating_db/)) document.getElementById('e_db_name').innerHTML = '<b>Warning:<\/b> The database you specified does not exist. It will be created during installation.';
       
  1800                   if(t.match(/_creating_user/)) document.getElementById('e_db_auth').innerHTML = '<b>Warning:<\/b> The specified regular user does not exist or the password is incorrect. The user will be created during installation. If the user already exists, the password will be reset.';
       
  1801                   
       
  1802                   document.getElementById('e_mysql_version').innerHTML = '<b>Error:<\/b> Your version of MySQL ('+t+') is older than 4.1.17. Enano will still work, but there is a known bug with the comment system and MySQL 4.1.11 that involves some comments not being displayed, due to an issue with the PHP function mysql_fetch_row().';
       
  1803                   document.getElementById('s_mysql_version').src='images/bad.gif';
       
  1804                 default:
       
  1805                   alert(t);
       
  1806                   break;
       
  1807                 }
       
  1808               }
       
  1809             }
       
  1810           });
       
  1811       }
       
  1812       function verify()
       
  1813       {
       
  1814         document.getElementById('e_db_host').innerHTML = '';
       
  1815         document.getElementById('e_db_auth').innerHTML = '';
       
  1816         document.getElementById('e_db_name').innerHTML = '';
       
  1817         document.getElementById('e_db_root').innerHTML = '';
       
  1818         var frm = document.forms.dbinfo;
       
  1819         ret = true;
       
  1820         if(frm.db_host.value != '')
       
  1821         {
       
  1822           document.getElementById('s_db_host').src='images/unknown.gif';
       
  1823         }
       
  1824         else
       
  1825         {
       
  1826           document.getElementById('s_db_host').src='images/bad.gif';
       
  1827           ret = false;
       
  1828         }
       
  1829         if(frm.db_name.value.match(/^([a-z0-9_-]+)$/g))
       
  1830         {
       
  1831           document.getElementById('s_db_name').src='images/unknown.gif';
       
  1832         }
       
  1833         else
       
  1834         {
       
  1835           document.getElementById('s_db_name').src='images/bad.gif';
       
  1836           ret = false;
       
  1837         }
       
  1838         if(frm.db_user.value != '')
       
  1839         {
       
  1840           document.getElementById('s_db_auth').src='images/unknown.gif';
       
  1841         }
       
  1842         else
       
  1843         {
       
  1844           document.getElementById('s_db_auth').src='images/bad.gif';
       
  1845           ret = false;
       
  1846         }
       
  1847         if(frm.table_prefix.value.match(/^([a-z0-9_]*)$/g))
       
  1848         {
       
  1849           document.getElementById('s_table_prefix').src='images/good.gif';
       
  1850         }
       
  1851         else
       
  1852         {
       
  1853           document.getElementById('s_table_prefix').src='images/bad.gif';
       
  1854           ret = false;
       
  1855         }
       
  1856         if(frm.db_root_user.value == '')
       
  1857         {
       
  1858           document.getElementById('s_db_root').src='images/good.gif';
       
  1859         }
       
  1860         else if(frm.db_root_user.value != '' && frm.db_root_pass.value == '')
       
  1861         {
       
  1862           document.getElementById('s_db_root').src='images/bad.gif';
       
  1863           ret = false;
       
  1864         }
       
  1865         else
       
  1866         {
       
  1867           document.getElementById('s_db_root').src='images/unknown.gif';
       
  1868         }
       
  1869         if(ret) frm._cont.disabled = false;
       
  1870         else    frm._cont.disabled = true;
       
  1871         return ret;
       
  1872       }
       
  1873       window.onload = verify;
       
  1874     </script>
       
  1875     <p>Now we need some information that will allow Enano to contact your database server. Enano uses PostgreSQL as a data storage backend,
       
  1876        and we need to have access to a PostgreSQL server in order to continue.</p>
       
  1877     <p>If you do not have access to a PostgreSQL server, and you are using your own server, you can download PostgreSQL for free from
       
  1878        <a href="http://www.postgresql.org/">PostgreSQL.org</a>.</p>
       
  1879     <form name="dbinfo" action="install.php?mode=website" method="post">
       
  1880       <input type="hidden" name="db_driver" value="postgresql" />
       
  1881       <table border="0">
       
  1882         <tr><td colspan="3" style="text-align: center"><h3>Database information</h3></td></tr>
       
  1883         <tr><td><b>Database hostname</b><br />This is the hostname (or sometimes the IP address) of your Postgres server. In many cases, this is "localhost".<br /><span style="color: #993300" id="e_db_host"></span></td><td><input onkeyup="verify();" name="db_host" size="30" type="text" /></td><td><img id="s_db_host" alt="Good/bad icon" src="images/bad.gif" /></td></tr>
       
  1884         <tr><td><b>Database name</b><br />The name of the actual database. If you don't already have a database, you can create one here, if you have the username and password of a PostgreSQL superuser.<br /><span style="color: #993300" id="e_db_name"></span></td><td><input onkeyup="verify();" name="db_name" size="30" type="text" /></td><td><img id="s_db_name" alt="Good/bad icon" src="images/bad.gif" /></td></tr>
       
  1885         <tr><td rowspan="2"><b>Database login</b><br />These fields should be the username and password for a role that has permission to create and alter tables, select data, insert data, update data, and delete data. You may or may not choose to allow dropping tables.<br /><span style="color: #993300" id="e_db_auth"></span></td><td><input onkeyup="verify();" name="db_user" size="30" type="text" /></td><td rowspan="2"><img id="s_db_auth" alt="Good/bad icon" src="images/bad.gif" /></td></tr>
       
  1886         <tr><td><input name="db_pass" size="30" type="password" /></td></tr>
       
  1887         <tr><td colspan="3" style="text-align: center"><h3>Optional information</h3></td></tr>
       
  1888         <tr><td><b>Table prefix</b><br />The value that you enter here will be added to the beginning of the name of each Enano table. You may use lowercase letters (a-z), numbers (0-9), and underscores (_).</td><td><input onkeyup="verify();" name="table_prefix" size="30" type="text" /></td><td><img id="s_table_prefix" alt="Good/bad icon" src="images/good.gif" /></td></tr>
       
  1889         <tr><td rowspan="2"><b>Database administrative login</b><br />If the Postgres database or role that you entered above does not exist yet, you can create them here, assuming that you have the login information for a PostgreSQL superuser. Leave these fields blank unless you need to use them.<br /><span style="color: #993300" id="e_db_root"></span></td><td><input onkeyup="verify();" name="db_root_user" size="30" type="text" /></td><td rowspan="2"><img id="s_db_root" alt="Good/bad icon" src="images/good.gif" /></td></tr>
       
  1890         <tr><td><input onkeyup="verify();" name="db_root_pass" size="30" type="password" /></td></tr>
       
  1891         <tr><td><b>PostgreSQL version</b></td><td id="e_mysql_version">PostgreSQL version information will<br />be checked when you click "Test<br />Connection". You need to have at<br />least PostgreSQL 8.2.0 to install Enano.</td><td><img id="s_mysql_version" alt="Good/bad icon" src="images/unknown.gif" /></td></tr>
       
  1892         <tr><td><b>Delete existing tables?</b><br />If this option is checked, all the tables that will be used by Enano will be dropped (deleted) before the schema is executed. Do NOT use this option unless specifically instructed to.</td><td><input type="checkbox" name="drop_tables" id="dtcheck" />  <label for="dtcheck">Drop existing tables</label></td></tr>
       
  1893         <tr><td colspan="3" style="text-align: center"><input type="button" value="Test connection" onclick="ajaxTestConnection();" /></td></tr>
       
  1894       </table>
       
  1895       <div class="pagenav">
       
  1896        <table border="0">
       
  1897        <tr>
       
  1898        <td><input type="submit" value="Continue" onclick="return verify();" name="_cont" /></td><td><p><span style="font-weight: bold;">Before clicking continue:</span><br />&bull; Check your PostgreSQL connection using the "Test Connection" button.<br />&bull; Be aware that your database information will be transmitted unencrypted several times.</p></td>
       
  1899        </tr>
       
  1900        </table>
       
  1901      </div>
  1417     </form>
  1902     </form>
  1418     <?php
  1903     <?php
  1419     break;
  1904     break;
  1420   case "website":
  1905   case "website":
  1421     if ( !isset($_POST['_cont']) )
  1906     if ( !isset($_POST['_cont']) )
  1818   case "install":
  2303   case "install":
  1819     if(!isset($_POST['db_host']) ||
  2304     if(!isset($_POST['db_host']) ||
  1820        !isset($_POST['db_name']) ||
  2305        !isset($_POST['db_name']) ||
  1821        !isset($_POST['db_user']) ||
  2306        !isset($_POST['db_user']) ||
  1822        !isset($_POST['db_pass']) ||
  2307        !isset($_POST['db_pass']) ||
       
  2308        !isset($_POST['db_driver']) ||
  1823        !isset($_POST['sitename']) ||
  2309        !isset($_POST['sitename']) ||
  1824        !isset($_POST['sitedesc']) ||
  2310        !isset($_POST['sitedesc']) ||
  1825        !isset($_POST['copyright']) ||
  2311        !isset($_POST['copyright']) ||
  1826        !isset($_POST['admin_user']) ||
  2312        !isset($_POST['admin_user']) ||
  1827        !isset($_POST['admin_pass']) ||
  2313        !isset($_POST['admin_pass']) ||
  1828        !isset($_POST['admin_embed_php']) || ( isset($_POST['admin_embed_php']) && !in_array($_POST['admin_embed_php'], array('2', '4')) ) ||
  2314        !isset($_POST['admin_embed_php']) || ( isset($_POST['admin_embed_php']) && !in_array($_POST['admin_embed_php'], array('2', '4')) ) ||
  1829        !isset($_POST['urlscheme'])
  2315        !isset($_POST['urlscheme'])
  1830        )
  2316        )
  1831     {
  2317     {
  1832       echo 'The installer has detected that one or more required form values is not set. Please <a href="install.php?mode=license">restart the installation</a>.';
  2318       echo 'The installer has detected that one or more required form values is not set. Please <a href="install.php?mode=license">restart the installation</a>.';
       
  2319       $template->footer();
       
  2320       exit;
       
  2321     }
       
  2322     if ( !in_array($_POST['db_driver'], array('mysql', 'postgresql')) )
       
  2323     {
       
  2324       echo 'Invalid database driver.';
  1833       $template->footer();
  2325       $template->footer();
  1834       exit;
  2326       exit;
  1835     }
  2327     }
  1836     switch($_POST['urlscheme'])
  2328     switch($_POST['urlscheme'])
  1837     {
  2329     {