install/includes/payload.php
changeset 353 2398420f48e7
parent 350 dd7cbc97f681
parent 352 9d7225c0db6d
child 359 e0787bb6285b
equal deleted inserted replaced
350:dd7cbc97f681 353:2398420f48e7
    87   return $site_key;
    87   return $site_key;
    88 }
    88 }
    89 
    89 
    90 function stg_load_schema()
    90 function stg_load_schema()
    91 {
    91 {
    92   global $db, $dbdriver, $installer_version;
    92   global $db, $dbdriver, $installer_version, $lang_id, $languages;
    93   static $sql_parser = false;
    93   static $sql_parser = false;
    94   
    94   
    95   if ( is_object($sql_parser) )
    95   if ( is_object($sql_parser) )
    96     return $sql_parser->parse();
    96     return $sql_parser->parse();
    97   
    97   
   111   catch ( Exception $e )
   111   catch ( Exception $e )
   112   {
   112   {
   113     echo "<pre>$e</pre>";
   113     echo "<pre>$e</pre>";
   114     return false;
   114     return false;
   115   }
   115   }
       
   116   
       
   117   $wkt = ENANO_ROOT . "/language/{$languages[$lang_id]['dir']}/install/mainpage-default.wkt";
       
   118   if ( !file_exists( $wkt ) )
       
   119   {
       
   120     echo '<div class="error-box">Error: could not locate wikitext for main page (' . $wkt . ')</div>';
       
   121     return false;
       
   122   }
       
   123   $wkt = @file_get_contents($wkt);
       
   124   if ( empty($wkt) )
       
   125     return false;
       
   126   
       
   127   $wkt = $db->escape($wkt);
   116   
   128   
   117   $vars = array(
   129   $vars = array(
   118       'TABLE_PREFIX'         => $_POST['table_prefix'],
   130       'TABLE_PREFIX'         => $_POST['table_prefix'],
   119       'SITE_NAME'            => $db->escape($_POST['site_name']),
   131       'SITE_NAME'            => $db->escape($_POST['site_name']),
   120       'SITE_DESC'            => $db->escape($_POST['site_desc']),
   132       'SITE_DESC'            => $db->escape($_POST['site_desc']),
   126       'ADMIN_USER'           => $db->escape($_POST['username']),
   138       'ADMIN_USER'           => $db->escape($_POST['username']),
   127       'ADMIN_PASS'           => $admin_pass,
   139       'ADMIN_PASS'           => $admin_pass,
   128       'ADMIN_EMAIL'          => $db->escape($_POST['email']),
   140       'ADMIN_EMAIL'          => $db->escape($_POST['email']),
   129       'REAL_NAME'            => '', // This has always been stubbed.
   141       'REAL_NAME'            => '', // This has always been stubbed.
   130       'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
   142       'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
   131       'UNIX_TIME'            => strval(time())
   143       'UNIX_TIME'            => strval(time()),
       
   144       'MAIN_PAGE_CONTENT'    => $wkt
   132     );
   145     );
   133   
   146   
   134   $sql_parser->assign_vars($vars);
   147   $sql_parser->assign_vars($vars);
   135   return $sql_parser->parse();
   148   return $sql_parser->parse();
   136 }
   149 }
   308   $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/tools.json" );
   321   $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/tools.json" );
   309   $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/admin.json" );
   322   $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/admin.json" );
   310   
   323   
   311   return true;
   324   return true;
   312 }
   325 }
       
   326 
       
   327 function stg_init_logs()
       
   328 {
       
   329   global $db, $session, $paths, $template, $plugins; // Common objects
       
   330   global $installer_version;
       
   331   
       
   332   $q = $db->sql_query('INSERT INTO ' . table_prefix . 'logs(log_type,action,time_id,date_string,author,page_text,edit_summary) VALUES(\'security\', \'install_enano\', ' . time() . ', \'' . enano_date('d M Y h:i a') . '\', \'' . $db->escape($_POST['admin_user']) . '\', \'' . $db->escape(enano_version()) . '\', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\');');
       
   333   if ( !$q )
       
   334   {
       
   335     echo '<p><tt>MySQL return: ' . $db->sql_error() . '</tt></p>';
       
   336     return false;
       
   337   }
       
   338   
       
   339   return true;
       
   340 }
       
   341 
       
   342 function stg_aes_cleanup()
       
   343 {
       
   344   global $db, $session, $paths, $template, $plugins; // Common objects
       
   345   $q = $db->sql_query('DELETE FROM ' . table_prefix . 'config WHERE config_name = \'install_aes_key\' OR config_name = \'site_aes_key\';');
       
   346   if ( !$q )
       
   347     $db->_die();
       
   348   return true;
       
   349 }
       
   350 
       
   351 function _stg_rename_config_revert()
       
   352 {
       
   353   if ( file_exists('./config.php') )
       
   354   {
       
   355     @rename('./config.php', './config.new.php');
       
   356   }
       
   357   
       
   358   $handle = @fopen('./config.php.new', 'w');
       
   359   if ( !$handle )
       
   360     return false;
       
   361   $contents = '<?php $cryptkey = \'' . _INSTRESUME_AES_KEYBACKUP . '\'; ?>';
       
   362   fwrite($handle, $contents);
       
   363   fclose($handle);
       
   364   return true;
       
   365 }
       
   366 
       
   367 function stg_build_index()
       
   368 {
       
   369   global $db, $session, $paths, $template, $plugins; // Common objects
       
   370   if ( $paths->rebuild_search_index() )
       
   371     return true;
       
   372   return false;
       
   373 }
       
   374 
       
   375 function stg_rename_config()
       
   376 {
       
   377   if ( !@rename(ENANO_ROOT . '/config.new.php', ENANO_ROOT . '/config.php') )
       
   378   {
       
   379     echo '<p>Can\'t rename config.php</p>';
       
   380     _stg_rename_config_revert();
       
   381     return false;
       
   382   }
       
   383   
       
   384   if ( filesize(ENANO_ROOT . '/.htaccess.new') > 1 )
       
   385   {
       
   386     // rename/possibly concatenate .htaccess.new
       
   387     $htaccess_base = '';
       
   388     if ( file_exists(ENANO_ROOT . '/.htaccess') )
       
   389       $htaccess_base .= @file_get_contents(ENANO_ROOT . '/.htaccess');
       
   390     if ( strlen($htaccess_base) > 0 && !preg_match("/\n$/", $htaccess_base) )
       
   391       $htaccess_base .= "\n\n";
       
   392     $htaccess_base .= @file_get_contents(ENANO_ROOT . '/.htaccess.new');
       
   393     if ( file_exists(ENANO_ROOT . '/.htaccess') )
       
   394     {
       
   395       $hh = @fopen(ENANO_ROOT . '/.htaccess', 'w');
       
   396       if ( !$hh )
       
   397         return false;
       
   398       fwrite($hh, $htaccess_base);
       
   399       fclose($hh);
       
   400       @unlink(ENANO_ROOT . '/.htaccess.new');
       
   401       return true;
       
   402     }
       
   403     else
       
   404     {
       
   405       return @rename(ENANO_ROOT . '/.htaccess.new', ENANO_ROOT . '/.htaccess');
       
   406     }
       
   407   }
       
   408   else
       
   409   {
       
   410     @unlink(ENANO_ROOT . '/.htaccess.new');
       
   411   }
       
   412   return true;
       
   413 }
       
   414