# HG changeset patch # User Dan # Date 1200630523 18000 # Node ID 9d7225c0db6d964b38b00c41e62135ec4397eb43 # Parent 8978cb3541caa7cc6563304863ee2144e09db64c Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization. diff -r 8978cb3541ca -r 9d7225c0db6d includes/common.php --- a/includes/common.php Thu Jan 17 19:49:14 2008 -0500 +++ b/includes/common.php Thu Jan 17 23:28:43 2008 -0500 @@ -259,36 +259,6 @@ setConfig('default_language', $row['lang_id']); } -// Our list of tables included in Enano -$system_table_list = Array( - table_prefix.'categories', - table_prefix.'comments', - table_prefix.'config', - table_prefix.'logs', - table_prefix.'page_text', - table_prefix.'session_keys', - table_prefix.'pages', - table_prefix.'users', - table_prefix.'users_extra', - table_prefix.'themes', - table_prefix.'buddies', - table_prefix.'banlist', - table_prefix.'files', - table_prefix.'privmsgs', - table_prefix.'sidebar', - table_prefix.'hits', - table_prefix.'groups', - table_prefix.'group_members', - table_prefix.'acl', - table_prefix.'page_groups', - table_prefix.'page_group_members', - table_prefix.'tags', - table_prefix.'language', - table_prefix.'language_strings', - table_prefix.'lockout', - table_prefix.'search_index' - ); - // Load plugin manager $plugins = new pluginLoader(); diff -r 8978cb3541ca -r 9d7225c0db6d includes/constants.php --- a/includes/constants.php Thu Jan 17 19:49:14 2008 -0500 +++ b/includes/constants.php Thu Jan 17 23:28:43 2008 -0500 @@ -141,6 +141,44 @@ // significantly increase encryption strength either. define('AES_BLOCKSIZE', 128); +// Our list of tables included in Enano +$system_table_list = Array( + 'categories', + 'comments', + 'config', + 'logs', + 'page_text', + 'session_keys', + 'pages', + 'users', + 'users_extra', + 'themes', + 'buddies', + 'banlist', + 'files', + 'privmsgs', + 'sidebar', + 'hits', + 'groups', + 'group_members', + 'acl', + 'page_groups', + 'page_group_members', + 'tags', + 'language', + 'language_strings', + 'lockout', + 'search_index' + ); + +if ( defined('table_prefix') ) +{ + foreach ( $system_table_list as $i => $_ ) + { + $system_table_list[$i] = table_prefix . $system_table_list[$i]; + } +} + /* * MIMETYPES * diff -r 8978cb3541ca -r 9d7225c0db6d includes/dbal.php --- a/includes/dbal.php Thu Jan 17 19:49:14 2008 -0500 +++ b/includes/dbal.php Thu Jan 17 23:28:43 2008 -0500 @@ -199,7 +199,11 @@ $q = $this->sql_query('USE `'.$dbname.'`;'); if ( !$q ) + { + if ( $manual_credentials ) + return false; $this->_die('The database could not be selected.'); + } // We're in! $this->disable_errorhandler(); diff -r 8978cb3541ca -r 9d7225c0db6d includes/payload.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/payload.php Thu Jan 17 23:28:43 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 8978cb3541ca -r 9d7225c0db6d install/includes/libenanoinstall.php --- a/install/includes/libenanoinstall.php Thu Jan 17 19:49:14 2008 -0500 +++ b/install/includes/libenanoinstall.php Thu Jan 17 23:28:43 2008 -0500 @@ -99,15 +99,18 @@ $key = htmlspecialchars($key); $post_data .= " \n"; } - echo '
- ' . $post_data . ' - -

' . $lang->get('meta_msg_err_stagefailed_title') . '

-

' . $failure_explanation . '

- ' . ( !empty($mysql_error) ? "

" . $lang->get('meta_msg_err_stagefailed_mysqlerror') . " $mysql_error

" : '' ) . ' -

' . $lang->get('meta_msg_err_stagefailed_body') . '

-

-
'; + if ( $stage_id == 'renameconfig' ) + echo '

' . $failure_explanation . '

'; + else + echo '
+ ' . $post_data . ' + +

' . $lang->get('meta_msg_err_stagefailed_title') . '

+

' . $failure_explanation . '

+ ' . ( !empty($mysql_error) ? "

" . $lang->get('meta_msg_err_stagefailed_mysqlerror') . " $mysql_error

" : '' ) . ' +

' . $lang->get('meta_msg_err_stagefailed_body') . '

+

+
'; global $ui; $ui->show_footer(); exit; diff -r 8978cb3541ca -r 9d7225c0db6d install/includes/payload.php --- a/install/includes/payload.php Thu Jan 17 19:49:14 2008 -0500 +++ b/install/includes/payload.php Thu Jan 17 23:28:43 2008 -0500 @@ -339,3 +339,76 @@ return true; } +function stg_aes_cleanup() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + $q = $db->sql_query('DELETE FROM ' . table_prefix . 'config WHERE config_name = \'install_aes_key\' OR config_name = \'site_aes_key\';'); + if ( !$q ) + $db->_die(); + return true; +} + +function _stg_rename_config_revert() +{ + if ( file_exists('./config.php') ) + { + @rename('./config.php', './config.new.php'); + } + + $handle = @fopen('./config.php.new', 'w'); + if ( !$handle ) + return false; + $contents = ''; + fwrite($handle, $contents); + fclose($handle); + return true; +} + +function stg_build_index() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + if ( $paths->rebuild_search_index() ) + return true; + return false; +} + +function stg_rename_config() +{ + if ( !@rename(ENANO_ROOT . '/config.new.php', ENANO_ROOT . '/config.php') ) + { + echo '

Can\'t rename config.php

'; + _stg_rename_config_revert(); + return false; + } + + if ( filesize(ENANO_ROOT . '/.htaccess.new') > 1 ) + { + // rename/possibly concatenate .htaccess.new + $htaccess_base = ''; + if ( file_exists(ENANO_ROOT . '/.htaccess') ) + $htaccess_base .= @file_get_contents(ENANO_ROOT . '/.htaccess'); + if ( strlen($htaccess_base) > 0 && !preg_match("/\n$/", $htaccess_base) ) + $htaccess_base .= "\n\n"; + $htaccess_base .= @file_get_contents(ENANO_ROOT . '/.htaccess.new'); + if ( file_exists(ENANO_ROOT . '/.htaccess') ) + { + $hh = @fopen(ENANO_ROOT . '/.htaccess', 'w'); + if ( !$hh ) + return false; + fwrite($hh, $htaccess_base); + fclose($hh); + @unlink(ENANO_ROOT . '/.htaccess.new'); + return true; + } + else + { + return @rename(ENANO_ROOT . '/.htaccess.new', ENANO_ROOT . '/.htaccess'); + } + } + else + { + @unlink(ENANO_ROOT . '/.htaccess.new'); + } + return true; +} + diff -r 8978cb3541ca -r 9d7225c0db6d install/includes/stages/database_post.php --- a/install/includes/stages/database_post.php Thu Jan 17 19:49:14 2008 -0500 +++ b/install/includes/stages/database_post.php Thu Jan 17 23:28:43 2008 -0500 @@ -26,14 +26,68 @@ $db_pass =& $_POST['db_pass']; $db_name =& $_POST['db_name']; $db_prefix =& $_POST['table_prefix']; +$db_root_user =& $_POST['db_root_user']; +$db_root_pass =& $_POST['db_root_pass']; + +if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) ) +{ + $ui->show_header(); + echo '

That table prefix isn\'t going to work.

'; + return true; +} $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name); +// If connection failed, we have the root login, AND we're on MySQL, try to force our way in +if ( !$result && !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) && $driver == 'mysql' ) +{ + // Allow a jump / breakout + switch ( 'foo' ) { case 'foo': + + // Try to connect to the DB as root + $result_root = $dbal->connect(true, $db_host, $db_root_user, $db_root_pass, 'mysql'); + if ( !$result_root ) + break; + + $q = $dbal->sql_query('CREATE DATABASE IF NOT EXISTS `' . $dbal->escape($db_name) . '`;'); + if ( !$q ) + break; + + if ( $db_host == 'localhost' || $db_host == '127.0.0.1' ) + { + $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'localhost\'' . "\n" . + ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); + } + else + { + $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'%\'' . "\n" . + ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); + } + + if ( !$q ) + break; + + $dbal->close(); + $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name); + + break; + } +} + $ui->show_header(); if ( $result ) { - // We're good, write out a config file + // We're good, do table drop if requested + if ( isset($_POST['drop_tables']) ) + { + global $system_table_list; + foreach ( $system_table_list as $table ) + { + $dbal->sql_query("DROP TABLE {$db_prefix}$table"); + } + } + // Write out a config file $ch = @fopen( ENANO_ROOT . '/config.new.php', 'w' ); if ( !$ch ) { diff -r 8978cb3541ca -r 9d7225c0db6d install/includes/stages/finish.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install/includes/stages/finish.php Thu Jan 17 23:28:43 2008 -0500 @@ -0,0 +1,76 @@ +show_header(); + echo '

Installation error

+

ERROR: That database driver is not supported.

'; + return true; +} + +$db = new $dbdriver(); +$db->connect(); + +$ui->show_header(); +flush(); + +?> +

Performing final installation steps

+

Enano is cleaning up and performing some final installation tasks. Please wait...

+ +get('install_stg_buildindex_title'), 'stg_build_index', $lang->get('install_stg_buildindex_body')); +run_installer_stage('renameconfig', $lang->get('install_stg_rename_title'), 'stg_rename_config', $lang->get('install_stg_rename_body', array('mainpage_link' => scriptPath . '/index.php'))); + +close_install_table(); + +?> +

Congratulations! You've finished installing Enano.

+

Enano has finished setting up on your server. Now you can go to your new + website and start creating content!

+get('finish_body'); + echo '

' . $lang->get('finish_link_mainpage', array('mainpage_link' => scriptPath . '/index.php')) . '

'; +?> +close(); + diff -r 8978cb3541ca -r 9d7225c0db6d install/includes/stages/install.php --- a/install/includes/stages/install.php Thu Jan 17 19:49:14 2008 -0500 +++ b/install/includes/stages/install.php Thu Jan 17 23:28:43 2008 -0500 @@ -112,5 +112,14 @@ close_install_table(); +?> +
+ +
+ +
+
+close(); diff -r 8978cb3541ca -r 9d7225c0db6d install/install.php --- a/install/install.php Thu Jan 17 19:49:14 2008 -0500 +++ b/install/install.php Thu Jan 17 23:28:43 2008 -0500 @@ -19,6 +19,7 @@ define('ENANO_DANGEROUS', 1); require_once('includes/common.php'); +@ini_set('display_errors', 'on'); $stages = array('language', 'license', 'sysreqs', 'database', 'website', 'login', 'confirm', 'install', 'finish'); $stage_ids = array(); @@ -268,6 +269,9 @@ case 'install': require( ENANO_ROOT . '/install/includes/stages/install.php' ); break; + case 'finish': + require( ENANO_ROOT . '/install/includes/stages/finish.php' ); + break; } $ui->show_footer(); diff -r 8978cb3541ca -r 9d7225c0db6d language/english/install.json --- a/language/english/install.json Thu Jan 17 19:49:14 2008 -0500 +++ b/language/english/install.json Thu Jan 17 23:28:43 2008 -0500 @@ -273,7 +273,13 @@ stg_writeconfig_title: 'Write configuration files', stg_writeconfig_body: 'Enano was unable to write the configuration file with your site\'s database credentials. This is almost always because your configuration file does not have the correct permissions. On Windows servers, you may see this message even if the check on the System Requirements page passed. Temporarily running IIS as the Administrator user may help.', stg_rename_title: 'Rename configuration files', - stg_rename_body: 'Enano couldn\'t rename the configuration files to their correct production names. Please CHMOD the folder where your Enano files are to 777 and click the retry button below, or perform the following rename operations and then finish the installation.', + stg_rename_body: 'Enano couldn\'t rename the configuration files to their correct production names. Please perform the following rename operations and then follow the instructions to finish the installation below. + + %this.finish_body% + %this.finish_link_mainpage%', stg_startapi_title: 'Start the Enano API', stg_startapi_body: 'The Enano API could not be started. This is an error that should never occur; please contact the Enano team for support.', stg_importlang_title: 'Import default language', @@ -292,8 +298,7 @@ modetitle: 'Finish', modetitle_long: 'Complete installation', msg_congratulations: 'Congratulations!', - body: '

You have finished installing Enano on this server.

-

Now what?

+ body: '

Wait... Now what?

Click the link below to see the main page for your website. Where to go from here: