# HG changeset patch # User Dan # Date 1200553413 18000 # Node ID fdaf9070566c78d38a6aef41eace6e07cbab9e83 # Parent 87e08a6e4fec6b7ba8205968c7022298fbbc36b2 More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases. diff -r 87e08a6e4fec -r fdaf9070566c includes/http.php --- a/includes/http.php Wed Jan 16 13:55:49 2008 -0500 +++ b/includes/http.php Thu Jan 17 02:03:33 2008 -0500 @@ -324,24 +324,11 @@ function _sock_open(&$connection) { - if ( $this->debug ) - { - echo '
' . __CLASS__ . ': Sending request
Request parameters:
'; - echo "Headers:
$headers"; - echo "
Cookies: $cookies
"; - echo "GET URI: " . htmlspecialchars($get) . "
"; - echo "POST DATA: " . htmlspecialchars($post) . "
"; - } - // Open connection $connection = fsockopen($this->host, $this->port); if ( !$connection ) die(__CLASS__ . '::' . __METHOD__ . ': Could not make connection'); - if ( $this->debug ) - echo 'Connection opened. Writing main request to socket. Raw socket data follows.
'; - // 1 = socket open $this->state = 1; } @@ -355,6 +342,20 @@ { $newline = "\r\n"; + if ( $this->debug ) + echo 'Connection opened. Writing main request to socket. Raw socket data follows.
'; + + if ( $this->debug ) + { + echo ''; + echo '' . __CLASS__ . ': Sending request
Request parameters:
'; + echo "Headers:
$headers"; + echo "Cookies: $cookies
"; + echo "GET URI: " . htmlspecialchars($this->uri . $get) . "
"; + echo "POST DATA: " . htmlspecialchars($post) . "
"; + } + echo ""; + $this->_fputs($connection, "{$this->method} {$this->uri}{$get} HTTP/1.1{$newline}"); $this->_fputs($connection, "Host: {$this->host}{$newline}"); $this->_fputs($connection, $headers); @@ -393,7 +394,7 @@ if ( $this->debug ) { echo 'Response fetched. Closing connection. Response text follows.
'; - echo htmlspecialchars($buffer); + echo htmlspecialchars($this->response); echo '
'; } diff -r 87e08a6e4fec -r fdaf9070566c includes/template.php --- a/includes/template.php Wed Jan 16 13:55:49 2008 -0500 +++ b/includes/template.php Thu Jan 17 02:03:33 2008 -0500 @@ -306,7 +306,7 @@ $tb .= $button->run(); } // Edit button - if($session->get_permissions('read') && ($paths->namespace != 'Special' && $paths->namespace != 'Admin') && ( $session->get_permissions('edit_page') && ( ( $paths->page_protected && $session->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) ) + if($session->get_permissions('read') && ($paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->namespace != 'Anonymous') && ( $session->get_permissions('edit_page') && ( ( $paths->page_protected && $session->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) ) { $button->assign_vars(array( 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"', @@ -317,7 +317,7 @@ $tb .= $button->run(); // View source button } - else if($session->get_permissions('view_source') && ( !$session->get_permissions('edit_page') || !$session->get_permissions('even_when_protected') && $paths->page_protected ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin') + else if($session->get_permissions('view_source') && ( !$session->get_permissions('edit_page') || !$session->get_permissions('even_when_protected') && $paths->page_protected ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->namespace != 'Anonymous') { $button->assign_vars(array( 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"', @@ -1942,9 +1942,9 @@ $tpl_strings = Array( 'PAGE_NAME'=>$this_page, 'PAGE_URLNAME'=>'Null', - 'SITE_NAME'=>$lang->get('meta_site_name'), + 'SITE_NAME'=> ( defined('IN_ENANO_INSTALL') ) ? $lang->get('meta_site_name') : 'Critical error', 'USERNAME'=>'admin', - 'SITE_DESC'=>$lang->get('meta_site_desc'), + 'SITE_DESC'=>( defined('IN_ENANO_INSTALL') ) ? $lang->get('meta_site_desc') : 'This site is experiencing a problem and cannot load.', 'TOOLBAR'=>$tb, 'SCRIPTPATH'=>scriptPath, 'CONTENTPATH'=>contentPath, @@ -1953,7 +1953,7 @@ 'ADMIN_SID_AMP_HTML'=>'', 'ADDITIONAL_HEADERS'=>$this->additional_headers, 'SIDEBAR_EXTRA'=>'', - 'COPYRIGHT'=>$lang->get('meta_enano_copyright'), + 'COPYRIGHT'=>( defined('IN_ENANO_INSTALL') ) ? $lang->get('meta_enano_copyright') : ( defined('ENANO_CONFIG_FETCHED') ? getConfig('copyright_notice') : '' ), 'TOOLBAR_EXTRAS'=>'', 'REQUEST_URI'=>( isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '' ).$_SERVER['REQUEST_URI'], 'STYLE_LINK'=>$slink, diff -r 87e08a6e4fec -r fdaf9070566c install/includes/common.php --- a/install/includes/common.php Wed Jan 16 13:55:49 2008 -0500 +++ b/install/includes/common.php Thu Jan 17 02:03:33 2008 -0500 @@ -113,6 +113,7 @@ { $languages[$meta['lang_code']] = array( 'name' => $meta['lang_name_native'], + 'name_eng' => $meta['lang_name_english'], 'dir' => $dh ); } diff -r 87e08a6e4fec -r fdaf9070566c install/includes/payload.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install/includes/payload.php Thu Jan 17 02:03:33 2008 -0500 @@ -0,0 +1,312 @@ +sql_query('SELECT config_value FROM ' . table_prefix . 'config WHERE config_name=\'install_aes_key\';'); + if ( !$q ) + $db->_die(); + if ( $db->numrows() < 1 ) + return false; + list($aes_key) = $db->fetchrow_num(); + $aes_key = $aes->hextostring($aes_key); + + $pass = $aes->decrypt($_POST['crypt_data'], $aes_key, ENC_HEX); + if ( !$pass ) + return false; + + return $pass; // Will be true if the password isn't crapped +} + +function stg_make_private_key() +{ + global $db; + static $site_key = false; + + if ( $site_key ) + return $site_key; + + // Is there already a key cached in the database? + $q = $db->sql_query('SELECT config_value FROM ' . table_prefix . 'config WHERE config_name=\'site_aes_key\';'); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() > 0 ) + { + list($site_key) = $db->fetchrow_num(); + $db->free_result(); + return $site_key; + } + + $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); + // This will use /dev/urandom if possible + $site_key = $aes->gen_readymade_key(); + + // Stash it in the database, don't check for errors though because we can always regenerate it + $db->sql_query('INSERT INTO ' . table_prefix . 'config ( config_name, config_value ) VALUES ( \'site_aes_key\', \'' . $site_key . '\' );'); + + return $site_key; +} + +function stg_load_schema() +{ + global $db, $dbdriver, $installer_version; + static $sql_parser = false; + + if ( is_object($sql_parser) ) + return $sql_parser->parse(); + + $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); + + $site_key = stg_make_private_key(); + $site_key = $aes->hextostring($site_key); + $admin_pass_clean = stg_password_decode(); + $admin_pass = $aes->encrypt($admin_pass_clean, $site_key, ENC_HEX); + + unset($admin_pass_clean); // Security + + try + { + $sql_parser = new SQL_Parser( ENANO_ROOT . "/install/schemas/{$dbdriver}_stage2.sql" ); + } + catch ( Exception $e ) + { + echo "$e"; + return false; + } + + $vars = array( + 'TABLE_PREFIX' => $_POST['table_prefix'], + 'SITE_NAME' => $db->escape($_POST['site_name']), + 'SITE_DESC' => $db->escape($_POST['site_desc']), + 'COPYRIGHT' => $db->escape($_POST['copyright']), + // FIXME: update form + 'WIKI_MODE' => ( isset($_POST['wiki_mode']) ? '1' : '0' ), + 'ENABLE_CACHE' => ( is_writable( ENANO_ROOT . '/cache/' ) ? '1' : '0' ), + 'VERSION' => $installer_version['version'], + 'ADMIN_USER' => $db->escape($_POST['username']), + 'ADMIN_PASS' => $admin_pass, + 'ADMIN_EMAIL' => $db->escape($_POST['email']), + 'REAL_NAME' => '', // This has always been stubbed. + 'ADMIN_EMBED_PHP' => strval(AUTH_DISALLOW), + 'UNIX_TIME' => strval(time()) + ); + + $sql_parser->assign_vars($vars); + return $sql_parser->parse(); +} + +function stg_deliver_payload() +{ + global $db; + $schema = stg_load_schema(); + foreach ( $schema as $sql ) + { + if ( !$db->sql_query($sql) ) + { + echo $db->get_error(); + return false; + } + } + return true; +} + +function stg_write_config() +{ + global $dbhost, $dbuser, $dbpasswd, $dbname, $dbdriver; + $db_data = array( + 'host' => str_replace("'", "\\'", $dbhost), + 'user' => str_replace("'", "\\'", $dbuser), + 'pass' => str_replace("'", "\\'", $dbpasswd), + 'name' => str_replace("'", "\\'", $dbname), + 'tp' => table_prefix, + 'drv' => $dbdriver + ); + + // Retrieves the existing key + $site_key = stg_make_private_key(); + + // Determine contentPath + switch ( @$_POST['url_scheme'] ) + { + case 'standard': + default: + $sp_append = 'index.php?title='; + break; + case 'shortened': + $sp_append = 'index.php/'; + break; + case 'rewrite': + $sp_append = '/'; + break; + } + + $scriptpath = scriptPath; + $contentpath = $scriptpath . $sp_append; + + $config_file = <<import( ENANO_ROOT . "/language/{$lang_info['dir']}/user.json" ); + $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/tools.json" ); + $lang_local->import( ENANO_ROOT . "/language/{$lang_info['dir']}/admin.json" ); + + return true; +} diff -r 87e08a6e4fec -r fdaf9070566c install/includes/payloads/common.php --- a/install/includes/payloads/common.php Wed Jan 16 13:55:49 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -sql_query('SELECT config_value FROM ' . table_prefix . 'config WHERE config_name=\'install_aes_key\';'); - if ( !$q ) - $db->_die(); - if ( $db->numrows() < 1 ) - return false; - list($aes_key) = $db->fetchrow_num(); - $aes_key = $aes->hextostring($aes_key); - - $pass = $aes->decrypt($_POST['crypt_data'], $aes_key, ENC_HEX); - if ( !$pass ) - return false; - - return $pass; // Will be true if the password isn't crapped -} - -function stg_make_private_key() -{ - global $db; - static $site_key = false; - - if ( $site_key ) - return $site_key; - - // Is there already a key cached in the database? - $q = $db->sql_query('SELECT config_value FROM ' . table_prefix . 'config WHERE config_name=\'site_aes_key\';'); - if ( !$q ) - $db->_die(); - - if ( $db->numrows() > 0 ) - { - list($site_key) = $db->fetchrow_num(); - $db->free_result(); - return $site_key; - } - - $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); - // This will use /dev/urandom if possible - $site_key = $aes->gen_readymade_key(); - - // Stash it in the database, don't check for errors though because we can always regenerate it - $db->sql_query('INSERT INTO ' . table_prefix . 'config ( config_name, config_value ) VALUES ( \'site_aes_key\', \'' . $site_key . '\' );'); - - return $site_key; -} - -function stg_load_schema() -{ - global $db, $dbdriver, $installer_version; - static $sql_parser = false; - - if ( is_object($sql_parser) ) - return $sql_parser->parse(); - - $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); - - $site_key = stg_make_private_key(); - $site_key = $aes->hextostring($site_key); - $admin_pass_clean = stg_password_decode(); - $admin_pass = $aes->encrypt($admin_pass_clean, $site_key, ENC_HEX); - - unset($admin_pass_clean); // Security - - try - { - $sql_parser = new SQL_Parser( ENANO_ROOT . "/install/schemas/{$dbdriver}_stage2.sql" ); - } - catch ( Exception $e ) - { - echo " $e"; - return false; - } - - $vars = array( - 'TABLE_PREFIX' => $_POST['table_prefix'], - 'SITE_NAME' => $db->escape($_POST['site_name']), - 'SITE_DESC' => $db->escape($_POST['site_desc']), - 'COPYRIGHT' => $db->escape($_POST['copyright']), - // FIXME: update form - 'WIKI_MODE' => ( isset($_POST['wiki_mode']) ? '1' : '0' ), - 'ENABLE_CACHE' => ( is_writable( ENANO_ROOT . '/cache/' ) ? '1' : '0' ), - 'VERSION' => $installer_version['version'], - 'ADMIN_USER' => $db->escape($_POST['username']), - 'ADMIN_PASS' => $admin_pass, - 'ADMIN_EMAIL' => $db->escape($_POST['email']), - 'REAL_NAME' => '', // This has always been stubbed. - 'ADMIN_EMBED_PHP' => strval(AUTH_DISALLOW), - 'UNIX_TIME' => strval(time()) - ); - - $sql_parser->assign_vars($vars); - return $sql_parser->parse(); -} - -function stg_deliver_payload() -{ - global $db; - $schema = stg_load_schema(); - foreach ( $schema as $sql ) - { - if ( !$db->sql_query($sql) ) - { - echo $db->get_error(); - return false; - } - } - return true; -} - diff -r 87e08a6e4fec -r fdaf9070566c install/includes/payloads/mysql.php --- a/install/includes/payloads/mysql.php Wed Jan 16 13:55:49 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -get('install_stg_writeconfig_title'), 'stg_write_config', $lang->get('install_stg_writeconfig_body')); + +// Now that the config is written, shutdown our primitive API and startup the full Enano API +$db->close(); + +@define('ENANO_ALLOW_LOAD_NOLANG', 1); +require(ENANO_ROOT . '/includes/common.php'); + +if ( is_object($db) && is_object($session) ) +{ + run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_sim_good', '...', false); +} +else +{ + run_installer_stage('startapi', $lang->get('install_stg_startapi_title'), 'stg_sim_bad', $lang->get('install_stg_startapi_body'), false); +} + +// Import languages +run_installer_stage('importlang', $lang->get('install_stg_importlang_title'), 'stg_language_setup', $lang->get('install_stg_importlang_body')); close_install_table(); diff -r 87e08a6e4fec -r fdaf9070566c install/schemas/mysql_stage2.sql --- a/install/schemas/mysql_stage2.sql Wed Jan 16 13:55:49 2008 -0500 +++ b/install/schemas/mysql_stage2.sql Thu Jan 17 02:03:33 2008 -0500 @@ -277,8 +277,6 @@ PRIMARY KEY ( string_id ) ); -DELETE FROM {{TABLE_PREFIX}}config; - INSERT INTO {{TABLE_PREFIX}}config(config_name, config_value) VALUES ('site_name', '{{SITE_NAME}}'), ('main_page', 'Main_Page'), diff -r 87e08a6e4fec -r fdaf9070566c install/schemas/postgresql_stage2.sql --- a/install/schemas/postgresql_stage2.sql Wed Jan 16 13:55:49 2008 -0500 +++ b/install/schemas/postgresql_stage2.sql Thu Jan 17 02:03:33 2008 -0500 @@ -271,8 +271,6 @@ string_content text NOT NULL ); -DELETE FROM {{TABLE_PREFIX}}config; - INSERT INTO {{TABLE_PREFIX}}config(config_name, config_value) VALUES ('site_name', '{{SITE_NAME}}'), ('main_page', 'Main_Page'),