install.php
changeset 271 f088805540ae
parent 266 917dcc6c4ceb
parent 270 5bcdee999015
child 278 53ba55d33abb
equal deleted inserted replaced
266:917dcc6c4ceb 271:f088805540ae
   103       $resumed = true;
   103       $resumed = true;
   104     }
   104     }
   105   }
   105   }
   106   if ( !$resumed && $allow_skip )
   106   if ( !$resumed && $allow_skip )
   107   {
   107   {
   108     echo_stage_success($stage_id, "[dbg: skipped] $stage_name");
   108     echo_stage_success($stage_id, $stage_name);
   109     return false;
   109     return false;
   110   }
   110   }
   111   if ( !function_exists($function) )
   111   if ( !function_exists($function) )
   112     die('libenanoinstall: CRITICAL: function "' . $function . '" for ' . $stage_id . ' doesn\'t exist');
   112     die('libenanoinstall: CRITICAL: function "' . $function . '" for ' . $stage_id . ' doesn\'t exist');
   113   $result = @call_user_func($function, false, $already_run);
   113   $result = @call_user_func($function, false, $already_run);
   140 {
   140 {
   141   global $neutral_color;
   141   global $neutral_color;
   142   $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
   142   $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
   143   echo '<tr><td style="width: 500px; background-color: #' . "{$neutral_color}{$neutral_color}FF{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Done" src="images/good.gif" /></td></tr>' . "\n";
   143   echo '<tr><td style="width: 500px; background-color: #' . "{$neutral_color}{$neutral_color}FF{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Done" src="images/good.gif" /></td></tr>' . "\n";
   144   ob_flush();
   144   ob_flush();
   145   flush();
       
   146 }
   145 }
   147 
   146 
   148 function echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack)
   147 function echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack)
   149 {
   148 {
   150   global $neutral_color;
   149   global $neutral_color;
   151   global $lang;
   150   global $lang;
   152   
   151   
   153   $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
   152   $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
   154   echo '<tr><td style="width: 500px; background-color: #' . "FF{$neutral_color}{$neutral_color}{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Failed" src="images/bad.gif" /></td></tr>' . "\n";
   153   echo '<tr><td style="width: 500px; background-color: #' . "FF{$neutral_color}{$neutral_color}{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Failed" src="images/bad.gif" /></td></tr>' . "\n";
   155   ob_flush();
   154   ob_flush();
   156   flush();
       
   157   close_install_table();
   155   close_install_table();
   158   $post_data = '';
   156   $post_data = '';
   159   $mysql_error = mysql_error();
   157   $mysql_error = mysql_error();
   160   foreach ( $_POST as $key => $value )
   158   foreach ( $_POST as $key => $value )
   161   {
   159   {
       
   160     // FIXME: These should really also be sanitized for double quotes
   162     $value = htmlspecialchars($value);
   161     $value = htmlspecialchars($value);
   163     $key = htmlspecialchars($key);
   162     $key = htmlspecialchars($key);
   164     $post_data .= "          <input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";
   163     $post_data .= "          <input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";
   165   }
   164   }
   166   echo '<form action="install.php?mode=install&amp;stage=' . $stage_id . '" method="post">
   165   echo '<form action="install.php?mode=install&amp;stage=' . $stage_id . '" method="post">
   386   $key = $aes->hextostring($key);
   385   $key = $aes->hextostring($key);
   387   $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   386   $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   388   
   387   
   389   $cacheonoff = is_writable(ENANO_ROOT.'/cache/') ? '1' : '0';
   388   $cacheonoff = is_writable(ENANO_ROOT.'/cache/') ? '1' : '0';
   390   
   389   
       
   390   $admin_user = $_POST['admin_user'];
       
   391   $admin_user = str_replace('_', ' ', $admin_user);
       
   392   $admin_user = mysql_real_escape_string($admin_user);
       
   393   
   391   $schema = file_get_contents('schema.sql');
   394   $schema = file_get_contents('schema.sql');
   392   $schema = str_replace('{{SITE_NAME}}',    mysql_real_escape_string($_POST['sitename']   ), $schema);
   395   $schema = str_replace('{{SITE_NAME}}',    mysql_real_escape_string($_POST['sitename']   ), $schema);
   393   $schema = str_replace('{{SITE_DESC}}',    mysql_real_escape_string($_POST['sitedesc']   ), $schema);
   396   $schema = str_replace('{{SITE_DESC}}',    mysql_real_escape_string($_POST['sitedesc']   ), $schema);
   394   $schema = str_replace('{{COPYRIGHT}}',    mysql_real_escape_string($_POST['copyright']  ), $schema);
   397   $schema = str_replace('{{COPYRIGHT}}',    mysql_real_escape_string($_POST['copyright']  ), $schema);
   395   $schema = str_replace('{{ADMIN_USER}}',   mysql_real_escape_string($_POST['admin_user'] ), $schema);
   398   $schema = str_replace('{{ADMIN_USER}}',   $admin_user                                    , $schema);
   396   $schema = str_replace('{{ADMIN_PASS}}',   mysql_real_escape_string($admin_pass          ), $schema);
   399   $schema = str_replace('{{ADMIN_PASS}}',   mysql_real_escape_string($admin_pass          ), $schema);
   397   $schema = str_replace('{{ADMIN_EMAIL}}',  mysql_real_escape_string($_POST['admin_email']), $schema);
   400   $schema = str_replace('{{ADMIN_EMAIL}}',  mysql_real_escape_string($_POST['admin_email']), $schema);
   398   $schema = str_replace('{{ENABLE_CACHE}}', mysql_real_escape_string($cacheonoff          ), $schema);
   401   $schema = str_replace('{{ENABLE_CACHE}}', mysql_real_escape_string($cacheonoff          ), $schema);
   399   $schema = str_replace('{{REAL_NAME}}',    '',                                              $schema);
   402   $schema = str_replace('{{REAL_NAME}}',    '',                                              $schema);
   400   $schema = str_replace('{{TABLE_PREFIX}}', $_POST['table_prefix'],                          $schema);
   403   $schema = str_replace('{{TABLE_PREFIX}}', $_POST['table_prefix'],                          $schema);
   460     $key = stg_generate_aes_key(true);
   463     $key = stg_generate_aes_key(true);
   461     $aes = new AESCrypt(AES_BITS, AES_BLOCKSIZE);
   464     $aes = new AESCrypt(AES_BITS, AES_BLOCKSIZE);
   462     $key = $aes->hextostring($key);
   465     $key = $aes->hextostring($key);
   463     $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   466     $admin_pass = $aes->encrypt($admin_pass, $key, ENC_HEX);
   464     $admin_user = mysql_real_escape_string($_POST['admin_user']);
   467     $admin_user = mysql_real_escape_string($_POST['admin_user']);
       
   468     $admin_user = str_replace('_', ' ', $admin_user);
   465     
   469     
   466     $q = @mysql_query("UPDATE {$_POST['table_prefix']}users SET password='$admin_pass' WHERE username='$admin_user';");
   470     $q = @mysql_query("UPDATE {$_POST['table_prefix']}users SET password='$admin_pass' WHERE username='$admin_user';");
   467     if ( !$q )
   471     if ( !$q )
   468     {
   472     {
   469       echo '<p><tt>MySQL return: ' . mysql_error() . '</tt></p>';
   473       echo '<p><tt>MySQL return: ' . mysql_error() . '</tt></p>';
  1824     
  1828     
  1825     if ( !preg_match('/^[a-z0-9_-]*$/', $_POST['table_prefix']) )
  1829     if ( !preg_match('/^[a-z0-9_-]*$/', $_POST['table_prefix']) )
  1826       err('Hacking attempt was detected in table_prefix.');
  1830       err('Hacking attempt was detected in table_prefix.');
  1827     
  1831     
  1828       start_install_table();
  1832       start_install_table();
  1829       // The stages connect, decrypt, genkey, and parse are preprocessing and don't do any actual data modification.
  1833       
  1830       // Thus, they need to be run on each retry, e.g. never skipped.
  1834       // Are we just trying to auto-rename the config files? If so, skip everything else
  1831       run_installer_stage('connect', $lang->get('install_stg_connect_title'), 'stg_mysql_connect', $lang->get('install_stg_connect_body'), false);
  1835       if ( !isset($_GET['stage']) || ( isset($_GET['stage']) && $_GET['stage'] != 'renameconfig' ) )
  1832       if ( isset($_POST['drop_tables']) )
  1836       {
  1833       {
  1837       
  1834         // Are we supposed to drop any existing tables? If so, do it now
  1838         // The stages connect, decrypt, genkey, and parse are preprocessing and don't do any actual data modification.
  1835         run_installer_stage('drop', $lang->get('install_stg_drop_title'), 'stg_drop_tables', 'This step never returns failure');
  1839         // Thus, they need to be run on each retry, e.g. never skipped.
  1836       }
  1840         run_installer_stage('connect', $lang->get('install_stg_connect_title'), 'stg_mysql_connect', $lang->get('install_stg_connect_body'), false);
  1837       run_installer_stage('decrypt', $lang->get('install_stg_decrypt_title'), 'stg_decrypt_admin_pass', $lang->get('install_stg_decrypt_body'), false);
  1841         if ( isset($_POST['drop_tables']) )
  1838       run_installer_stage('genkey', $lang->get('install_stg_genkey_title', array( 'aes_bits' => AES_BITS )), 'stg_generate_aes_key', $lang->get('install_stg_genkey_body'), false);
  1842         {
  1839       run_installer_stage('parse', $lang->get('install_stg_parse_title'), 'stg_parse_schema', $lang->get('install_stg_parse_body'), false);
  1843           // Are we supposed to drop any existing tables? If so, do it now
  1840       run_installer_stage('sql', $lang->get('install_stg_sql_title'), 'stg_install', $lang->get('install_stg_sql_body'), false);
  1844           run_installer_stage('drop', $lang->get('install_stg_drop_title'), 'stg_drop_tables', 'This step never returns failure');
  1841       run_installer_stage('writeconfig', $lang->get('install_stg_writeconfig_title'), 'stg_write_config', $lang->get('install_stg_writeconfig_body'));
  1845         }
       
  1846         run_installer_stage('decrypt', $lang->get('install_stg_decrypt_title'), 'stg_decrypt_admin_pass', $lang->get('install_stg_decrypt_body'), false);
       
  1847         run_installer_stage('genkey', $lang->get('install_stg_genkey_title', array( 'aes_bits' => AES_BITS )), 'stg_generate_aes_key', $lang->get('install_stg_genkey_body'), false);
       
  1848         run_installer_stage('parse', $lang->get('install_stg_parse_title'), 'stg_parse_schema', $lang->get('install_stg_parse_body'), false);
       
  1849         run_installer_stage('sql', $lang->get('install_stg_sql_title'), 'stg_install', $lang->get('install_stg_sql_body'), false);
       
  1850         run_installer_stage('writeconfig', $lang->get('install_stg_writeconfig_title'), 'stg_write_config', $lang->get('install_stg_writeconfig_body'));
       
  1851         
       
  1852         // Mainstream installation complete - Enano should be usable now
       
  1853         // The stage of starting the API is special because it has to be called out of function context.
       
  1854         // To alleviate this, we have two functions, one that returns success and one that returns failure
       
  1855         // If the Enano API load is successful, the success function is called to report the action to the user
       
  1856         // If unsuccessful, the failure report is sent
       
  1857         
       
  1858         $template_bak = $template;
       
  1859         
       
  1860         $_GET['title'] = 'Main_Page';
       
  1861         require('includes/common.php');
       
  1862         
       
  1863         if ( is_object($db) && is_object($session) )
       
  1864         {
       
  1865           run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_start_api_success', '...', false);
       
  1866         }
       
  1867         else
       
  1868         {
       
  1869           run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_start_api_failure', $lang->get('install_stg_startapi_body'), false);
       
  1870         }
       
  1871         
       
  1872         // We need to be logged in (with admin rights) before logs can be flushed
       
  1873         $admin_password = stg_decrypt_admin_pass(true);
       
  1874         $session->login_without_crypto($_POST['admin_user'], $admin_password, false);
       
  1875         
       
  1876         // Now that login cookies are set, initialize the session manager and ACLs
       
  1877         $session->start();
       
  1878         $paths->init();
       
  1879         
       
  1880         run_installer_stage('importlang', $lang->get('install_stg_importlang_title'), 'stg_import_language', $lang->get('install_stg_importlang_body'));
       
  1881         run_installer_stage('initlogs', $lang->get('install_stg_initlogs_title'), 'stg_init_logs', $lang->get('install_stg_initlogs_body'));
       
  1882         
       
  1883         /*
       
  1884          * HACKERS:
       
  1885          * If you're making a custom distribution of Enano, put all your custom plugin-related code here.
       
  1886          * You have access to the full Enano API as well as being logged in with complete admin rights.
       
  1887          * Don't do anything horrendously fancy here, unless you add a new stage (or more than one) and
       
  1888          * have the progress printed out properly.
       
  1889          */
       
  1890         
       
  1891       } // check for stage == renameconfig
       
  1892       else
       
  1893       {
       
  1894         // If we did skip the main installer routine, set $template_bak to make the reversal later work properly
       
  1895         $template_bak = $template;
       
  1896       }
       
  1897 
       
  1898       // Final step is to rename the config file
       
  1899       // In early revisions of 1.0.2, this step was performed prior to the initialization of the Enano API. It was decided to move
       
  1900       // this stage to the end because it will fail more often than any other stage, thus making alternate routes imperative. If this
       
  1901       // stage fails, then no big deal, we'll just have the user rename the files manually and then let them see the pretty success message.
  1842       run_installer_stage('renameconfig', $lang->get('install_stg_rename_title'), 'stg_rename_config', $lang->get('install_stg_rename_body'));
  1902       run_installer_stage('renameconfig', $lang->get('install_stg_rename_title'), 'stg_rename_config', $lang->get('install_stg_rename_body'));
  1843       
  1903       
  1844       // Mainstream installation complete - Enano should be usable now
       
  1845       // The stage of starting the API is special because it has to be called out of function context.
       
  1846       // To alleviate this, we have two functions, one that returns success and one that returns failure
       
  1847       // If the Enano API init is successful, the success function is called to report the action to the user
       
  1848       // If unsuccessful, the failure report is sent
       
  1849       
       
  1850       $template_bak = $template;
       
  1851       
       
  1852       $_GET['title'] = 'Main_Page';
       
  1853       require('includes/common.php');
       
  1854       
       
  1855       if ( is_object($db) && is_object($session) )
       
  1856       {
       
  1857         run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_start_api_success', '...', false);
       
  1858       }
       
  1859       else
       
  1860       {
       
  1861         run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_start_api_failure', $lang->get('install_stg_startapi_body'), false);
       
  1862       }
       
  1863       
       
  1864       // We need to be logged in (with admin rights) before logs can be flushed
       
  1865       $admin_password = stg_decrypt_admin_pass(true);
       
  1866       $session->login_without_crypto($_POST['admin_user'], $admin_password, false);
       
  1867       
       
  1868       // Now that login cookies are set, initialize the session manager and ACLs
       
  1869       $session->start();
       
  1870       $paths->init();
       
  1871       
       
  1872       run_installer_stage('importlang', $lang->get('install_stg_importlang_title'), 'stg_import_language', $lang->get('install_stg_importlang_body'));
       
  1873       
       
  1874       run_installer_stage('initlogs', $lang->get('install_stg_initlogs_title'), 'stg_init_logs', $lang->get('install_stg_initlogs_body'));
       
  1875       close_install_table();
  1904       close_install_table();
  1876       
  1905       
  1877       unset($template);
  1906       unset($template);
  1878       $template =& $template_bak;
  1907       $template =& $template_bak;
  1879     
  1908