From 46d010e89d280d391935648f1f713fc784042050 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 19 Jan 2009 03:31:13 +0000 Subject: Simplification pass over the installer: - Flattened the directory structure - Greatly simplified structure in installer; it now only reports environmental checks that fail. Simplified code that prints exceptions. Use only mysql calls for the installer, but select mysqli automatically if it's available. Drop the response file; that's easily replicated with flag support - Create a random password for the admin user - Delete unused controllers - Invert the form of the database config template to be mostly non-PHP with just a few PHP calls --- installer/controllers/installer.php | 80 ------ installer/data/init_var.php | 13 - installer/data/install.sql | 271 ------------------ installer/database_config.php | 45 +++ installer/index.php | 67 +---- installer/init_var.php | 13 + installer/install.sql | 271 ++++++++++++++++++ installer/installer.php | 531 +++++++++--------------------------- installer/views/database.php.php | 44 --- installer/views/installer.html.php | 49 ---- installer/views/installer.txt.php | 51 ---- 11 files changed, 472 insertions(+), 963 deletions(-) delete mode 100644 installer/controllers/installer.php delete mode 100644 installer/data/init_var.php delete mode 100644 installer/data/install.sql create mode 100644 installer/database_config.php create mode 100644 installer/init_var.php create mode 100644 installer/install.sql delete mode 100644 installer/views/database.php.php delete mode 100644 installer/views/installer.html.php delete mode 100644 installer/views/installer.txt.php (limited to 'installer') diff --git a/installer/controllers/installer.php b/installer/controllers/installer.php deleted file mode 100644 index 9c9491b7..00000000 --- a/installer/controllers/installer.php +++ /dev/null @@ -1,80 +0,0 @@ -template->syscheck = new View("install.html"); - $this->template->syscheck->errors = $this->_get_config_errors(); - $this->template->syscheck->modules = array(); - } - - private function _get_config_errors() { - $errors = array(); - if (!file_exists(VARPATH)) { - $error = new stdClass(); - $error->message = "Missing: " . VARPATH; - $error->instructions[] = "mkdir " . VARPATH; - $error->instructions[] = "chmod 777 " . VARPATH; - $errors[] = $error; - } else if (!is_writable(VARPATH)) { - $error = new stdClass(); - $error->message = "Not writable: " . VARPATH; - $error->instructions[] = "chmod 777 " . VARPATH; - $errors[] = $error; - } - - $db_php = VARPATH . "database.php"; - if (!file_exists($db_php)) { - $error = new stdClass(); - $error->message = "Missing: $db_php
Run the following commands..."; - $error->instructions[] = "cp " . DOCROOT . "kohana/config/database.php $db_php"; - $error->instructions[] = "chmod 644 $db_php"; - $error->message2 = "...then edit this file and enter your database configuration settings."; - $errors[] = $error; - } else if (!is_readable($db_php)) { - $error = new stdClass(); - $error->message = "Not readable: $db_php"; - $error->instructions[] = "chmod 644 $db_php"; - $error->message2 = "Then edit this file and enter your database configuration settings."; - $errors[] = $error; - } else { - $old_handler = set_error_handler(array("Welcome_Controller", "_error_handler")); - try { - Database::instance()->connect(); - } catch (Exception $e) { - $error = new stdClass(); - $error->message = "Database error: {$e->getMessage()}"; - $db_name = Kohana::config("database.default.connection.database"); - if (strchr($error->message, "Unknown database")) { - $error->instructions[] = "mysqladmin -uroot create $db_name"; - } else { - $error->instructions = array(); - $error->message2 = "Check " . VARPATH . "database.php"; - } - $errors[] = $error; - } - set_error_handler($old_handler); - } - - return $errors; - } - -} \ No newline at end of file diff --git a/installer/data/init_var.php b/installer/data/init_var.php deleted file mode 100644 index 42d50c0a..00000000 --- a/installer/data/init_var.php +++ /dev/null @@ -1,13 +0,0 @@ -API Key','3'); -DROP TABLE IF EXISTS `modules`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `modules` ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, - `version` int(9) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `modules` VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'akismet',1); -DROP TABLE IF EXISTS `permissions`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `permissions` ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, - `display_name` varchar(64) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `permissions` VALUES (1,'view','View'),(2,'view_full','View Full Size'),(3,'edit','Edit'); -DROP TABLE IF EXISTS `sessions`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `sessions` ( - `session_id` varchar(127) NOT NULL, - `last_activity` int(10) unsigned NOT NULL, - `data` text NOT NULL, - PRIMARY KEY (`session_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `sessions` VALUES ('7d414ede0f86afc6079a90e424b51c41',1232179528,'c2Vzc2lvbl9pZHxzOjMyOiI3ZDQxNGVkZTBmODZhZmM2MDc5YTkwZTQyNGI1MWM0MSI7dG90YWxfaGl0c3xpOjc0O19rZl9mbGFzaF98YTowOnt9dXNlcl9hZ2VudHxzOjkwOiJNb3ppbGxhLzUuMCAoV2luZG93czsgVTsgV2luZG93cyBOVCA1LjE7IGVuLVVTOyBydjoxLjkuMC41KSBHZWNrby8yMDA4MTIwMTIyIEZpcmVmb3gvMy4wLjUiO2lwX2FkZHJlc3N8czoxMzoiMjQuNjkuMjExLjEzNSI7bGFzdF9hY3Rpdml0eXxpOjEyMzIxNzk1MjE7dXNlcnxPOjEwOiJVc2VyX01vZGVsIjo2OntzOjE0OiIAKgBvYmplY3RfbmFtZSI7czo0OiJ1c2VyIjtzOjk6IgAqAG9iamVjdCI7YToxMDp7czoyOiJpZCI7aToyO3M6NDoibmFtZSI7czo1OiJhZG1pbiI7czo5OiJmdWxsX25hbWUiO3M6MjE6IkdhbGxlcnkgQWRtaW5pc3RyYXRvciI7czo4OiJwYXNzd29yZCI7czozNjoiU1VdNjMzMjY3NDhiNTAyNmI0ZDdiNWQ1YzhjODNhMjY2NzQzIjtzOjExOiJsb2dpbl9jb3VudCI7aToxO3M6MTA6Imxhc3RfbG9naW4iO2k6MTIzMjE3MjM1MTtzOjU6ImVtYWlsIjtOO3M6N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idXJsIjtOO31zOjEwOiIAKgBjaGFuZ2VkIjthOjA6e31zOjk6IgAqAGxvYWRlZCI7YjoxO3M6ODoiACoAc2F2ZWQiO2I6MTtzOjEwOiIAKgBzb3J0aW5nIjthOjE6e3M6MjoiaWQiO3M6MzoiYXNjIjt9fWdyb3VwX2lkc3xhOjE6e2k6MDtpOjE7fWNzcmZ8czozMjoiYzlhZDY2YmFjMzRhYjk5Y2NmOTRiMGEwMjhkNWI3ZWQiOw=='); -DROP TABLE IF EXISTS `tasks`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `tasks` ( - `callback` varchar(128) default NULL, - `context` text NOT NULL, - `done` tinyint(1) default '0', - `id` int(9) NOT NULL auto_increment, - `updated` int(9) default NULL, - `name` varchar(128) default NULL, - `percent_complete` int(9) default '0', - `state` varchar(32) default NULL, - `status` varchar(255) default NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -DROP TABLE IF EXISTS `themes`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `themes` ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, - `version` int(9) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `themes` VALUES (1,'default',1),(2,'admin_default',1); -DROP TABLE IF EXISTS `users`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `users` ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(32) NOT NULL, - `full_name` varchar(255) NOT NULL, - `password` varchar(64) NOT NULL, - `login_count` int(10) unsigned NOT NULL default '0', - `last_login` int(10) unsigned NOT NULL default '0', - `email` varchar(64) default NULL, - `admin` tinyint(1) default '0', - `guest` tinyint(1) default '0', - `url` varchar(255) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `users` VALUES (1,'guest','Guest User','mP`hf6bf25b90e2765ffe2e65737b142dba5',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','SU]63326748b5026b4d7b5d5c8c83a266743',1,1232172351,NULL,1,0,NULL); -DROP TABLE IF EXISTS `vars`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `vars` ( - `id` int(9) NOT NULL auto_increment, - `module_name` varchar(64) NOT NULL, - `name` varchar(64) NOT NULL, - `value` text, - PRIMARY KEY (`id`), - UNIQUE KEY `module_name` (`module_name`,`name`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -SET character_set_client = @saved_cs_client; -INSERT INTO `vars` VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','dashboard_blocks','a:2:{s:7:\"sidebar\";a:3:{i:1897057832;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:863091211;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1286303073;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}s:4:\"main\";a:4:{i:1969666309;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:353682022;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1636721943;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:458629768;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}}'),(9,'core','version','3.0'),(10,'comment','spam_caught','0'); diff --git a/installer/database_config.php b/installer/database_config.php new file mode 100644 index 00000000..78492eba --- /dev/null +++ b/installer/database_config.php @@ -0,0 +1,45 @@ + + defined('SYSPATH') OR die('No direct access allowed.'); + +/** + * @package Database + * + * Database connection settings, defined as arrays, or "groups". If no group + * name is used when loading the database library, the group named "default" + * will be used. + * + * Each group can be connected to independently, and multiple groups can be + * connected at once. + * + * Group Options: + * benchmark - Enable or disable database benchmarking + * persistent - Enable or disable a persistent connection + * connection - Array of connection specific parameters; alternatively, + * you can use a DSN though it is not as fast and certain + * characters could create problems (like an '@' character + * in a password): + * 'connection' => 'mysql://dbuser:secret@localhost/kohana' + * character_set - Database character set + * table_prefix - Database table prefix + * object - Enable or disable object results + * cache - Enable or disable query caching + * escape - Enable automatic query builder escaping + */ +$config["default"] = array( + "benchmark" => false, + "persistent" => false, + "connection" => array( + "type" => "", + "user" => "", + "pass" => "", + "host" => "", + "port" => false, + "socket" => false, + "database" => "" + ), + "character_set" => "utf8", + "table_prefix" => "", + "object" => true, + "cache" => false, + "escape" => true +); \ No newline at end of file diff --git a/installer/index.php b/installer/index.php index 7999a76a..b0a4d417 100644 --- a/installer/index.php +++ b/installer/index.php @@ -26,66 +26,13 @@ * -d Database name (default: gallery3) * -t Table prefix (default: ) * -m Modules to install (default: core, user) - * -f Response file (default: not used) - * The response file is a php file that contains the following syntax; - * $config[key] = value; - * Where key is one of "host", "user", "password", "dbname", "prefix". Values specified - * on the command line will override values contained in this file */ +define("DOCROOT", dirname(dirname(__FILE__)) . "/"); +define("VARPATH", DOCROOT . "var/"); -define("DOCROOT", dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); - -// Define application and system paths -define('APPPATH', DOCROOT . 'core' . DIRECTORY_SEPARATOR); -define('MODPATH', DOCROOT . 'modules' . DIRECTORY_SEPARATOR); -define('THEMEPATH', DOCROOT . 'themes' . DIRECTORY_SEPARATOR); -define('SYSPATH', DOCROOT . 'kohana' . DIRECTORY_SEPARATOR); - -define('VARPATH', DOCROOT . 'var' . DIRECTORY_SEPARATOR); -define('TEST_MODE', 0); -define('EXT', ".php"); - -include DOCROOT . "installer/installer.php"; - -if (PHP_SAPI == "cli") { - installer::command_line(); - exit; -} - -if (file_exists(VARPATH . "installed")) { - header("Location: ../index.php/albums/1"); - exit; -} - -set_error_handler(create_function('$errno, $errstr, $errfile, $errline', - 'throw new ErrorException($errstr, 0, $errno, $errfile, $errline);')); - -// Set exception handler -set_exception_handler(array("installer", "print_exception")); - -// @todo Log the results of failed call -if (!installer::environment_check()) { - installer::display_requirements(); - die; -} - -installer::parse_cli_parms($argv); - -$config_valid = true; - -try { - $config_valid = installer::check_database_authorization(); -} catch (Exception $e) { - installer::print_exception($e); - die("Specifed User does not have sufficient authority to install Gallery3\n"); -} - -$config_valid &= installer::check_docroot_writable(); - -installer::display_requirements(!$config_valid); - -if ($config_valid) { - print installer::install(); -} - +// Define this to get the preamable to pass +// @todo: change all preambles to key off of VARPATH instead +define("SYSPATH", "anything"); +require(DOCROOT . "installer/installer.php"); +installer::command_line(); diff --git a/installer/init_var.php b/installer/init_var.php new file mode 100644 index 00000000..42d50c0a --- /dev/null +++ b/installer/init_var.php @@ -0,0 +1,13 @@ +API Key','3'); +DROP TABLE IF EXISTS `modules`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `modules` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) default NULL, + `version` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `modules` VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'akismet',1); +DROP TABLE IF EXISTS `permissions`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `permissions` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) default NULL, + `display_name` varchar(64) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `permissions` VALUES (1,'view','View'),(2,'view_full','View Full Size'),(3,'edit','Edit'); +DROP TABLE IF EXISTS `sessions`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `sessions` ( + `session_id` varchar(127) NOT NULL, + `last_activity` int(10) unsigned NOT NULL, + `data` text NOT NULL, + PRIMARY KEY (`session_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `sessions` VALUES ('7d414ede0f86afc6079a90e424b51c41',1232179528,'c2Vzc2lvbl9pZHxzOjMyOiI3ZDQxNGVkZTBmODZhZmM2MDc5YTkwZTQyNGI1MWM0MSI7dG90YWxfaGl0c3xpOjc0O19rZl9mbGFzaF98YTowOnt9dXNlcl9hZ2VudHxzOjkwOiJNb3ppbGxhLzUuMCAoV2luZG93czsgVTsgV2luZG93cyBOVCA1LjE7IGVuLVVTOyBydjoxLjkuMC41KSBHZWNrby8yMDA4MTIwMTIyIEZpcmVmb3gvMy4wLjUiO2lwX2FkZHJlc3N8czoxMzoiMjQuNjkuMjExLjEzNSI7bGFzdF9hY3Rpdml0eXxpOjEyMzIxNzk1MjE7dXNlcnxPOjEwOiJVc2VyX01vZGVsIjo2OntzOjE0OiIAKgBvYmplY3RfbmFtZSI7czo0OiJ1c2VyIjtzOjk6IgAqAG9iamVjdCI7YToxMDp7czoyOiJpZCI7aToyO3M6NDoibmFtZSI7czo1OiJhZG1pbiI7czo5OiJmdWxsX25hbWUiO3M6MjE6IkdhbGxlcnkgQWRtaW5pc3RyYXRvciI7czo4OiJwYXNzd29yZCI7czozNjoiU1VdNjMzMjY3NDhiNTAyNmI0ZDdiNWQ1YzhjODNhMjY2NzQzIjtzOjExOiJsb2dpbl9jb3VudCI7aToxO3M6MTA6Imxhc3RfbG9naW4iO2k6MTIzMjE3MjM1MTtzOjU6ImVtYWlsIjtOO3M6NToiYWRtaW4iO2k6MTtzOjU6Imd1ZXN0IjtpO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jA6e31zOjk6IgAqAGxvYWRlZCI7YjoxO3M6ODoiACoAc2F2ZWQiO2I6MTtzOjEwOiIAKgBzb3J0aW5nIjthOjE6e3M6MjoiaWQiO3M6MzoiYXNjIjt9fWdyb3VwX2lkc3xhOjE6e2k6MDtpOjE7fWNzcmZ8czozMjoiYzlhZDY2YmFjMzRhYjk5Y2NmOTRiMGEwMjhkNWI3ZWQiOw=='); +DROP TABLE IF EXISTS `tasks`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `tasks` ( + `callback` varchar(128) default NULL, + `context` text NOT NULL, + `done` tinyint(1) default '0', + `id` int(9) NOT NULL auto_increment, + `updated` int(9) default NULL, + `name` varchar(128) default NULL, + `percent_complete` int(9) default '0', + `state` varchar(32) default NULL, + `status` varchar(255) default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +DROP TABLE IF EXISTS `themes`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `themes` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) default NULL, + `version` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `themes` VALUES (1,'default',1),(2,'admin_default',1); +DROP TABLE IF EXISTS `users`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `users` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(32) NOT NULL, + `full_name` varchar(255) NOT NULL, + `password` varchar(64) NOT NULL, + `login_count` int(10) unsigned NOT NULL default '0', + `last_login` int(10) unsigned NOT NULL default '0', + `email` varchar(64) default NULL, + `admin` tinyint(1) default '0', + `guest` tinyint(1) default '0', + `url` varchar(255) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `users` VALUES (1,'guest','Guest User','mP`hf6bf25b90e2765ffe2e65737b142dba5',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','SU]63326748b5026b4d7b5d5c8c83a266743',1,1232172351,NULL,1,0,NULL); +DROP TABLE IF EXISTS `vars`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `vars` ( + `id` int(9) NOT NULL auto_increment, + `module_name` varchar(64) NOT NULL, + `name` varchar(64) NOT NULL, + `value` text, + PRIMARY KEY (`id`), + UNIQUE KEY `module_name` (`module_name`,`name`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `vars` VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','dashboard_blocks','a:2:{s:7:\"sidebar\";a:3:{i:1897057832;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:863091211;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1286303073;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}s:4:\"main\";a:4:{i:1969666309;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:353682022;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1636721943;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:458629768;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}}'),(9,'core','version','3.0'),(10,'comment','spam_caught','0'); diff --git a/installer/installer.php b/installer/installer.php index 986c7794..5266ec3b 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -18,496 +18,237 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class installer { - private static $messages = array(); - private static $config = array(); - private static $database = null; - private static $config_errors = false; - static function command_line() { - // remove the script name from the arguments - array_shift($_SERVER["argv"]); - - //$_SERVER["HTTP_USER_AGENT"] = phpversion(); - //date_default_timezone_set('America/Los_Angeles'); - + // Set error handlers set_error_handler(create_function('$errno, $errstr, $errfile, $errline', 'throw new ErrorException($errstr, 0, $errno, $errfile, $errline);')); - - // Set exception handler set_exception_handler(array("installer", "print_exception")); - // @todo Log the results of failed call - if (!installer::environment_check()) { - self::display_requirements(); - die; - } - - self::parse_cli_parms($_SERVER["argv"]); - - $config_valid = true; - + $config = self::parse_cli_params(); try { - $config_valid = self::check_database_authorization(); - } catch (Exception $e) { - self::print_exception($e); - die("Specifed User does not have sufficient authority to install Gallery3\n"); - } - - $config_valid &= self::check_docroot_writable(); - - self::display_requirements(!$config_valid); - - if ($config_valid) { - print self::install(); + self::environment_check(); + self::setup_database($config); + self::setup_varpath(); + self::install($config); + list ($user, $password) = self::create_admin($config); + print "Successfully installed your Gallery 3!\n"; + print "Log in with:\n username: admin\n password: $password\n"; + } catch (InstallException $e) { + self::display_errors($e->errors()); } } static function environment_check() { - $failed = false; - $section = array("header" => "Environment Test", - "description" => "The following tests have been run to determine if " . - "Gallery3 will work in your environment. If any of the tests have " . - "failed, consult the documention on http://gallery.menalto.com for " . - "more information on how to correct the problem.", - "msgs" => array()); + $errors = array(); if (version_compare(PHP_VERSION, "5.2", "<")) { - $section["msgs"]["PHP Version"] = array("error" => true, - "text" => sprintf("Gallery3 requires PHP 5.2 or newer, current version: %s.", PHP_VERSION)); - $failed = true; - } else { - $section["msgs"]["PHP Version"] = array("error" => false, - "text" => PHP_VERSION); - } - - - if (!(is_dir(SYSPATH) AND is_file(SYSPATH.'core/Bootstrap'.EXT))) { - $section["msgs"]["Kohana Directory"] = array("error" => true, - "text" => "The configured Kohana directory does not exist or does not contain the required files."); - } else { - $section["msgs"]["Kohana Directory"] = array("error" => false, - "text" => SYSPATH); - } - - if (!(is_dir(APPPATH) AND is_file(APPPATH.'config/config'.EXT))) { - $section["msgs"]["Application Directory"] = array("error" => true, - "text" => "The configured Gallery3 application directory does not exist or does not contain the required files."); - $failed = true; - } else { - $section["msgs"]["Application Directory"] = array("error" => false, - "text" => APPPATH); - } - - if (!(is_dir(MODPATH))) { - $section["msgs"]["Modules Directory"] = array("error" => true, - "text" => "The configured Gallery3 modules directory does not exist or does not contain the required files."); - $failed = true; - } else { - $section["msgs"]["Modules Directory"] = array("error" => false, - "text" => MODPATH); - } - - if (!(is_dir(THEMEPATH))) { - $section["msgs"]["Theme Directory"] = array("error" => true, - "text" => "The configured Gallery3 themes directory does not exist or does not contain the required files."); - $failed = true; - } else { - $section["msgs"]["Themes Directory"] = array("error" => false, - "text" => THEMEPATH); + $errors["PHP Version"] = sprintf( + "Gallery3 requires PHP 5.2 or newer, current version: %s.", PHP_VERSION); } if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { - $section["msgs"]["PCRE UTF-8"] = array("error" => true, - "text" => "Perl-Compatible Regular Expressions has not been compiled with UTF-8 support.", - "html" => "PCRE has not been compiled with UTF-8 support."); - $failed = true; - } else if (!@preg_match("/^\pL$/u", utf8_encode("\xF1"))) { - $section["msgs"]["PCRE UTF-8"] = array("error" => true, - "text" => "Perl-Compatible Regular Expressions has not been compiled with Unicode support.", - "html" => "PCRE has not been compiled with Unicode property support."); - $failed = true; - } else { - $section["msgs"]["PCRE UTF-8"] = array("error" => false, - "text" => "Pass"); + $errors["PCRE UTF-8"] = + "PHP is missing Perl-Compatible Regular Expression support (http://php.net/pcre)"; } if (!(class_exists("ReflectionClass"))) { - $section["msgs"]["Reflection Enabled"] = array("error" => true, - "text" => "PHP relection is either not loaded or not compiled in.", - "html" => "PHP relection is either not loaded or not compiled in."); - $failed = true; - } else { - $section["msgs"]["Reflection Enabled"] = array("error" => false, - "text" => "Pass"); + $errors["PHP Reflection"] = "PHP is missing Reflection support (http://php.net/reflection)"; } if (!(function_exists("filter_list"))) { - $section["msgs"]["Filters Enabled"] = array("error" => true, - "text" => "The filter extension is either not loaded or not compiled in.", - "html" => "The filter extension is either not loaded or not compiled in."); - $failed = true; - } else { - $section["msgs"]["Filters Enabled"] = array("error" => false, - "text" => "Pass"); + $errors["Filters"] = "PHP is missing the filter extension (http://php.net/filter)"; } if (!(extension_loaded("iconv"))) { - $section["msgs"]["Iconv Loaded"] = array("error" => true, - "text" => "The iconv extension is not loaded.", - "html" => "The iconv extension is not loaded."); - $failed = true; - } else { - $section["msgs"]["Iconv Enabled"] = array("error" => false, - "text" => "Pass"); + $errors["iconv"] = "PHP is missing the iconv extension (http://php.net/iconv)"; } if (extension_loaded("mbstring") && (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { - $section["msgs"]["Mbstring Overloaded"] = array("error" => true, - "text" => "The mbstring extension is overloading PHP's native string functions.", - "html" => "The mbstring extension is overloading PHP's native string functions."); - $failed = true; - } else { - $section["msgs"]["MbString Overloaded"] = array("error" => false, - "text" => "Pass"); + $errors["Multibyte Strings"] = + "The mbstring extension is overloading PHP's native string functions " . + "(http://php.net/mbstring)"; } if (!(isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["PHP_SELF"]))) { - $section["msgs"]["URI Determination"] = array("error" => true, - "text" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available.", - "html" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available."); - $failed = true; - } else { - $section["msgs"]["URI Determination"] = array("error" => false, - "text" => "Pass"); + $errors["URL Detection"] = + "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available"; } $short_tags = ini_get("short_open_tag"); if (empty($short_tags)) { - $section["msgs"]["Short Tags"] = array("error" => true, - "text" => "Gallery3 requires that PHP short tags be enabled.", - "html" => "Gallery3 requires that PHP short tags be enabled"); - $failed = true; - } else { - $section["msgs"]["Short Tags"] = array("error" => false, - "text" => "Pass"); + $errors["Short Tags"] = + "PHP short tag support is disabled. (http://php.net/manual/en/ini.core.php)"; } - self::$messages[] = $section; - return !$failed; + if ($errors) { + throw new InstallException($errors); + } } - static function display_requirements($errors=false) { - self::$config_errors = $errors; - if (PHP_SAPI == 'cli') { - print self::_render("installer/views/installer.txt"); + static function parse_cli_params() { + $config = array("host" => "localhost", + "user" => "root", + "password" => "", + "dbname" => "gallery3", + "prefix" => ""); + + if (function_exists("mysqli")) { + $config["type"] = "mysqli"; } else { - print self::_render("installer/views/installer.html"); + $config["type"] = "mysql"; } - } - static function parse_cli_parms($argv) { - $section = array("header" => "Installation Parameters", - "description" => "The following parameters will be used to install and " . - "configure your Gallery3 installation.", - "msgs" => array()); - $arguments = array(); - for ($i=0; $i < count($argv); $i++) { + $argv = $_SERVER["argv"]; + for ($i = 1; $i < count($argv); $i++) { switch (strtolower($argv[$i])) { case "-d": - $arguments["dbname"] = $argv[++$i]; + $config["dbname"] = $argv[++$i]; break; case "-h": - $arguments["host"] = $argv[++$i]; + $config["host"] = $argv[++$i]; break; case "-u": - $arguments["user"] = $argv[++$i]; + $config["user"] = $argv[++$i]; break; case "-p": - $arguments["password"] = $argv[++$i]; + $config["password"] = $argv[++$i]; break; case "-t": - $arguments["prefix"] = $argv[++$i]; - break; - case "-f": - $arguments["file"] = $argv[++$i]; - break; - case "-i": - $arguments["type"] = $argv[++$i]; - break; - case "-m": - $arguments["modules"] = $argv[++$i]; + $config["prefix"] = $argv[++$i]; break; } } - $config = array("host" => "localhost", "user" => "root", "password" => "", - "modules" => array("core" => 1, "user" => 1), "type" => "mysqli", - "dbname" => "gallery3", "prefix" => ""); - - if (!empty($arguments["file"])) { - if (file_exists($arguments["file"])) { - $save_modules = $config["modules"]; - include $arguments["file"]; - if (!is_array($config["modules"])) { - $modules = explode(",", $config["modules"]); - $config["modules"] = array_merge($save_modules, array_fill_keys($modules, 1)); - } - } - unset($arguments["file"]); - } - - if (!empty($arguments["modules"])) { - $modules = explode(",", $arguments["modules"]); + return $config; + } - $config["modules"] = array_merge($config["modules"], array_fill_keys($modules, 1)); - unset($arguments["modules"]); + static function setup_database($config) { + $errors = array(); + if (!mysql_connect($config["host"], $config["user"], $config["password"])) { + $errors["Database"] = + "Unable to connect to your database with the credentials provided. Error details:\n" . + mysql_error(); + return; } - foreach (array_keys($config["modules"]) as $module) { - unset($config["modules"][$module]); - $config["modules"][trim($module)] = 1; + if (!mysql_select_db($config["dbname"]) && !mysql_create_db($config["dbname"])) { + $errors["Database"] = sprintf( + "Database '%s' is not defined and can't be created", + $config["dbname"]); } - self::$config = array_merge($config, $arguments); + if (mysql_num_rows(mysql_query("SHOW TABLES FROM {$config['dbname']}"))) { + $errors["Database"] = sprintf( + "Database '%s' exists and has tables in it, continuing may overwrite an existing install", + $config["dbname"]); + } - foreach (self::$config as $key => $value) { - if ($key == "modules") { - $value = implode(", ", array_keys($value)); - } - $section["msgs"][$key] = array("text" => $value, "error" => false); + if ($errors) { + throw new InstallException($errors); } - self::$messages[] = $section; } - static function check_database_authorization() { - $section = array("header" => "Database Configuration", - "description" => "Gallery3 requires the following database configuration.", - "msgs" => array()); - if (!mysql_connect(self::$config["host"], self::$config["user"], self::$config["password"])) { - throw new Exception(mysql_error()); + static function setup_varpath() { + $errors = array(); + if (is_writable(VARPATH)) { + return; } - /* - * If we got this far, then the user/password combination is valid and we can now - * a little more information for the individual that is running the script. We can also - * connect to the database and ask for more information - */ - - $db_config_valid = true; - if (!mysql_select_db(self::$config["dbname"]) && !mysql_create_db(self::$config["dbname"])) { - $db_config_valid = false; - $section["msgs"]["Database"] = array( - "text" => "Database '$dbname' is not defined and can't be created", - "error" => true); + if (is_writable(dirname(VARPATH)) && !mkdir(VARPATH)) { + $errors["Filesystem"] = + sprintf("The %s directory doesn't exist and can't be created", VARPATH); } - if (mysql_num_rows(mysql_query("SHOW TABLES FROM " . self::$config["dbname"]))) { - $db_config_valid = false; - $section["msgs"]["Database Empty"] = array("text" => "Database '$dbname' is not empty", - "error" => true); + if ($errors) { + throw new InstallException($errors); } - - self::$messages[] = $section; - return $db_config_valid; } - static function check_docroot_writable() { - $section = array("header" => "File System Access", - "description" => "The requires the following file system configuration.", - "msgs" => array()); - if (is_writable(DOCROOT)) { - $writable = true; - $section["msgs"]["Permissions"] = - array("text" => "The installation directory '" . DOCROOT . "' is writable.", - "error" => false); - } else { - $writable = false; - $section["msgs"]["Permissions"] = - array("text" => "The current user is unable to write to '" . DOCROOT . "'.", - "error" => true); - } - self::$messages[] = $section; - return $writable; - } + static function install($config) { + $errors = array(); - static function install() { - ob_start(); - $step = 0; - $modules[] = array(); - try { - include(DOCROOT . "installer/data/init_var.php"); - - $db_config_file = realpath("var") . "/database.php"; - $data = array("type" => strtolower(self::$config["type"]), - "user" => self::$config["user"], - "password" => self::$config["password"], - "host" => self::$config["host"], - "database" => self::$config["dbname"], - "prefix" => self::$config["prefix"]); - - $config = self::_render("installer/views/database.php", $data); - if (file_put_contents($db_config_file, $config) !== false) { - print "'var/database.php' created\n"; - } else { - throw new Exception("'var/database.php' was not created"); - } + include(DOCROOT . "installer/init_var.php"); - $buf = ""; - foreach (file("installer/data/install.sql") as $line) { - $buf .= $line; - if (preg_match("/;$/", $buf)) { - mysql_query($buf); - $buf = ""; - } - } + $db_config_file = VARPATH . "database.php"; + $output = self::_render("installer/database_config.php", $config); - if (file_put_contents("var/installed", "installed")) { - print "Gallery3 installed\n"; - } else { - throw new Exception("Unable to write 'var/installed'"); - } - } catch (Exception $e) { - self::print_exception($e); + if (!file_put_contents($db_config_file, $output) !== false) { + $errors["Config"] = "Unable to create " . VARPATH . "database.php"; } - $return = ob_get_contents(); - ob_clean(); - return $return; - } - static function print_exception($exception) { - // Beautify backtrace - try { - $trace = self::_backtrace($exception); - } catch(Exception $e) { - print_r($e); + $buf = ""; + foreach (file("installer/install.sql") as $line) { + $buf .= $line; + if (preg_match("/;$/", $buf)) { + if (!mysql_query($buf)) { + $errors["Database"] = "Unable to install database tables. Error details:\n" . + mysql_error(); + break; + } + $buf = ""; + } } - $type = get_class($exception); - $message = $exception->getMessage(); - $file = $exception->getFile(); - $line = $exception->getLine(); + system("chmod -R 777 " . VARPATH); - print "$type Occurred: $message \nin {$file}[$line]\n$trace"; - // Turn off error reporting - error_reporting(0); + if ($errors) { + throw new InstallException($errors); + } } - /** - * Install a module. - */ - private static function _module_install($module_name) { - $installer_class = "{$module_name}_installer"; - print "$installer_class install (initial)\n"; - if ($module_name != "core") { - require_once(DOCROOT . "modules/${module_name}/helpers/{$installer_class}.php"); + static function create_admin($config) { + $errors = array(); + $salt = ""; + for ($i = 0; $i < 4; $i++) { + $char = mt_rand(48, 109); + $char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0; + $salt .= chr($char); + } + $password = substr(md5(time() * rand()), 0, 6); + $hashed_password = $salt . md5($salt . $password); + if (mysql_query("UPDATE `users` SET `password` = '$hashed_password' WHERE `id` = 2")) { } else { - require_once(DOCROOT . "core/helpers/core_installer.php"); + $errors["Database"] = "Unable to set admin password. Error details:\n" . mysql_error(); } - $core_config = Kohana::config_load("core"); - $kohana_modules = $core_config["modules"]; - $kohana_modules[] = MODPATH . $module_name; - Kohana::config_set("core.modules", $kohana_modules); - - - call_user_func(array($installer_class, "install")); + if ($errors) { + throw new InstallException($errors); + } - //if (method_exists($installer_class, "install")) { - // call_user_func_array(array($installer_class, "install"), array()); - //} - print "Installed module $module_name\n"; + return array("admin", $password); } - private static function _render($view, $data=null) { - if ($view == '') - return; - - // Buffering on + private static function _render($view, $data) { + extract($data); ob_start(); - - try { - // Views are straight HTML pages with embedded PHP, so importing them - // this way insures that $this can be accessed as if the user was in - // the controller, which gives the easiest access to libraries in views - include realpath($view . EXT); - } catch (Exception $e) { - // Display the exception using its internal __toString method - echo $e; - } - - // Fetch the output and close the buffer + include($view); return ob_get_clean(); } - /** - * Displays nice backtrace information. - * @see http://php.net/debug_backtrace - * - * @param array backtrace generated by an exception or debug_backtrace - * @return string - */ - private static function _backtrace($exception) { - $trace = $exception->getTrace(); - if ( ! is_array($trace)) { - return; - } - - // Final output - $output = array(); - $cli = PHP_SAPI == "cli"; + static function print_exception($exception) { + print $exception->getMessage() . "\n"; + print $exception->getTraceAsString(); + } - $args = array(); - // Remove the first entry of debug_backtrace(), it is the exception_handler call - if ($exception instanceof ErrorException) { - $last = array_shift($trace); - $args = !empty($last["args"]) ? $last["args"] : $args; + static function display_errors($errors) { + print "Errors\n"; + foreach ($errors as $title => $error) { + print "$title\n"; + print " $error\n\n"; } + } +} - foreach ($trace as $entry) { - $temp = $cli ? "" : "
  • "; - - if (isset($entry["file"])) { - $format = $cli ? "%s[%s]" : "%s [%s]:"; - $temp .= sprintf($format, preg_replace("!^".preg_quote(DOCROOT)."!", "", - $entry["file"]), $entry["line"]); - } - - $temp .= $cli ? "\n\t" : "
    ";
    -
    -      if (isset($entry["class"])) {
    -        // Add class and call type
    -        $temp .= $entry["class"].$entry["type"];
    -      }
    -
    -      // Add function
    -      $temp .= $entry["function"]."(";
    -
    -      // Add function args
    -      if (isset($entry["args"]) AND is_array($entry["args"])) {
    -        // Separator starts as nothing
    -        $sep = "";
    -
    -        while ($arg = array_shift($args)) {
    -          if (is_string($arg) AND is_file($arg)) {
    -            // Remove docroot from filename
    -            $arg = preg_replace("!^".preg_quote(DOCROOT)."!", "", $arg);
    -          }
    -
    -          $temp .= $sep . ($cli ? print_r($arg, TRUE) : html::specialchars(print_r($arg, TRUE)));
    -
    -          // Change separator to a comma
    -          $sep = ", ";
    -        }
    -        $args = $entry["args"];
    -      }
    -
    -      $temp .= ")" . ($cli ? "\n" : "
  • "); +class InstallException extends Exception { + var $errors; - $output[] = $temp; - } + function __construct($errors) { + parent::__construct(); + $this->errors = $errors; + } - $output = implode("\n", $output); - return $cli ? $output : "
      " . $output . "
    "; + function errors() { + return $this->errors; } -} \ No newline at end of file +} diff --git a/installer/views/database.php.php b/installer/views/database.php.php deleted file mode 100644 index 42268422..00000000 --- a/installer/views/database.php.php +++ /dev/null @@ -1,44 +0,0 @@ - 'mysql://dbuser:secret@localhost/kohana'\n"; -print " * character_set - Database character set\n"; -print " * table_prefix - Database table prefix\n"; -print " * object - Enable or disable object results\n"; -print " * cache - Enable or disable query caching\n"; -print " * escape - Enable automatic query builder escaping\n"; -print " */\n"; -print "\$config['default'] = array(\n"; -print " 'benchmark' => FALSE,\n"; -print " 'persistent' => FALSE,\n"; -print " 'connection' => array(\n"; -print " 'type' => '{$data['type']}',\n"; -print " 'user' => '{$data['user']}',\n"; -print " 'pass' => '{$data['password']}',\n"; -print " 'host' => '{$data['host']}',\n"; -print " 'port' => FALSE,\n"; -print " 'socket' => FALSE,\n"; -print " 'database' => '{$data['database']}'\n"; -print " ),\n"; -print " 'character_set' => 'utf8',\n"; -print " 'table_prefix' => '{$data['prefix']}',\n"; -print " 'object' => TRUE,\n"; -print " 'cache' => FALSE,\n"; -print " 'escape' => TRUE\n"; -print ");\n"; diff --git a/installer/views/installer.html.php b/installer/views/installer.html.php deleted file mode 100644 index 43692846..00000000 --- a/installer/views/installer.html.php +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - Gallery3 Requirements Verification - - - - - - -

    - -

    - -
    - - - $msg): ?> - - - - - - -
    "> - -
    -
    - - - \ No newline at end of file diff --git a/installer/views/installer.txt.php b/installer/views/installer.txt.php deleted file mode 100644 index 986b9297..00000000 --- a/installer/views/installer.txt.php +++ /dev/null @@ -1,51 +0,0 @@ - - $msg) { - print_msg($header, $msg["text"], $msg["error"]); - } -} - -echo "+", str_repeat("-", 98), "+\n"; - -if (self::$config_errors) { - printf("| %-96.96s |\n", magenta_start() . - "Please fix the identified issues before attempting the install" . color_end()); - echo "+", str_repeat("-", 98), "+\n"; -} -flush(); \ No newline at end of file -- cgit v1.2.3