From 681197a265f1dd3873780fdcf0b5f1e8fa0150ab Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 20 Jan 2009 00:54:02 +0000 Subject: Web based installer. It's still got some rough edges, but you can now do a complete CLI or web based install. --- installer/check.html.php | 92 ------------- installer/cli.php | 90 +++++++++++++ installer/database_config.php | 14 +- installer/index.php | 4 +- installer/init_var.php | 12 +- installer/install.css | 51 +++++++- installer/install.html.php | 61 ++------- installer/install.sql | 6 +- installer/installer.php | 195 +++++----------------------- installer/pages/about_install.html.php | 18 +++ installer/pages/already_installed.html.php | 4 + installer/pages/db_not_empty.html.php | 5 + installer/pages/environment_errors.html.php | 19 +++ installer/pages/get_db_info.html.php | 78 +++++++++++ installer/pages/missing_db.html.php | 2 + installer/pages/oops.html.php | 9 ++ installer/pages/success.html.php | 22 ++++ installer/web.php | 105 +++++++++++++++ 18 files changed, 462 insertions(+), 325 deletions(-) delete mode 100644 installer/check.html.php create mode 100644 installer/cli.php create mode 100644 installer/pages/about_install.html.php create mode 100644 installer/pages/already_installed.html.php create mode 100644 installer/pages/db_not_empty.html.php create mode 100644 installer/pages/environment_errors.html.php create mode 100644 installer/pages/get_db_info.html.php create mode 100644 installer/pages/missing_db.html.php create mode 100644 installer/pages/oops.html.php create mode 100644 installer/pages/success.html.php create mode 100644 installer/web.php (limited to 'installer') diff --git a/installer/check.html.php b/installer/check.html.php deleted file mode 100644 index 34d0b3cb..00000000 --- a/installer/check.html.php +++ /dev/null @@ -1,92 +0,0 @@ - - - - Gallery3 Installer: System Checks - - - -
-
- - -

System Checks

- -

- As a privacy measure, we do not allow you to run the system - check page after your Gallery has been installed. This - keeps prying eyes from learning about your system. -

- - - - - - - -

- There are some problems with your web hosting environment - that need to be fixed before you can successfully install - Gallery 3. -

- -

- Check again -

- - -

- Good news! We've checked everything we can think of and it - looks like Gallery 3 should work just fine on your system. -

- - -
-
- - diff --git a/installer/cli.php b/installer/cli.php new file mode 100644 index 00000000..bff9c16c --- /dev/null +++ b/installer/cli.php @@ -0,0 +1,90 @@ + " . $message; + print "\n"; + print "For help you can try:\n"; + print " * The Gallery3 FAQ - http://codex.gallery2.org/Gallery3:FAQ\n"; + print " * The Gallery Forums - http://gallery.menalto.com/forum\n"; + print "\n\n** INSTALLATION FAILED **\n"; + exit(1); +} + +function parse_cli_params() { + $config = array("host" => "localhost", + "user" => "root", + "password" => "", + "dbname" => "gallery3", + "prefix" => "", + "type" => function_exists("mysqli_init") ? "mysqli" : "mysql"); + + $argv = $_SERVER["argv"]; + for ($i = 1; $i < count($argv); $i++) { + switch (strtolower($argv[$i])) { + case "-d": + $config["dbname"] = $argv[++$i]; + break; + case "-h": + $config["host"] = $argv[++$i]; + break; + case "-u": + $config["user"] = $argv[++$i]; + break; + case "-p": + $config["password"] = $argv[++$i]; + break; + } + } + + return $config; +} diff --git a/installer/database_config.php b/installer/database_config.php index 3cc452ed..eac55b96 100644 --- a/installer/database_config.php +++ b/installer/database_config.php @@ -1,5 +1,5 @@ - defined("SYSPATH") or die("No direct script access."); + defined("SYSPATH") or die("No direct script access."); /** * @package Database @@ -29,16 +29,16 @@ $config["default"] = array( "benchmark" => false, "persistent" => false, "connection" => array( - "type" => "", - "user" => "", - "pass" => "", - "host" => "", + "type" => "", + "user" => "", + "pass" => "", + "host" => "", "port" => false, "socket" => false, - "database" => "" + "database" => "" ), "character_set" => "utf8", - "table_prefix" => "", + "table_prefix" => "", "object" => true, "cache" => false, "escape" => true diff --git a/installer/index.php b/installer/index.php index 90beb4f9..27faf1b6 100644 --- a/installer/index.php +++ b/installer/index.php @@ -32,12 +32,12 @@ define("SYSPATH", "DEFINED_TO_SOMETHING_SO_THAT_WE_CAN_KEEP_CONSISTENT_PREAMBLES require(DOCROOT . "installer/installer.php"); if (php_sapi_name() == "cli") { - installer::command_line(); + include("cli.php"); } else { if ($_GET["page"] == "check") { include("check.html.php"); } else { - installer::web(); + include("web.php"); } } diff --git a/installer/init_var.php b/installer/init_var.php index 7c5509f5..94dd5c67 100644 --- a/installer/init_var.php +++ b/installer/init_var.php @@ -1,8 +1,8 @@
- -

- Your Gallery3 install is complete. - -

- Welcome to Gallery 3. In order to get started, we need to - know how to talk to your database. You'll need to know: -

    -
  1. Database name
  2. -
  3. Database username
  4. -
  5. Database password
  6. -
  7. Database host
  8. -
- - If you're missing any of this information, please ask your - web host or system administrator for a little help. -

-

- Continue -

- + +
+ -

- Did something go wrong? Run - a system check to make sure - that it's not an issue with your web host. -

-

- Questions or problems? Visit the Gallery Website. -

diff --git a/installer/install.sql b/installer/install.sql index 69ce70bb..1cbcbb56 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -143,7 +143,7 @@ CREATE TABLE `items` ( KEY `type` (`type`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO `items` VALUES (NULL,1232345987,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1232345987,0,NULL,1,1); +INSERT INTO `items` VALUES (NULL,1232411356,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1232411356,0,NULL,1,1); DROP TABLE IF EXISTS `items_tags`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -288,7 +288,7 @@ CREATE TABLE `users` ( 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','iEkC795166ec7ac8c7acced8d31a8421906b',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL); +INSERT INTO `users` VALUES (1,'guest','Guest User','QYV8187262d4349b69c82675f8378185a61c',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL); DROP TABLE IF EXISTS `vars`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -301,4 +301,4 @@ CREATE TABLE `vars` ( UNIQUE KEY `module_name` (`module_name`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=12 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','blocks_dashboard_sidebar','a:4:{i:949042169;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:1377548023;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1576910954;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:201768872;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(9,'core','blocks_dashboard_center','a:4:{i:754436234;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:1128952603;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1021381592;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1986335277;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(10,'core','version','3.0'),(11,'comment','spam_caught','0'); +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','blocks_dashboard_sidebar','a:4:{i:1876961917;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:924956900;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:8006564;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1576448242;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(9,'core','blocks_dashboard_center','a:4:{i:1489461869;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:2076717831;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:706100302;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1064064430;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(10,'core','version','3.0'),(11,'comment','spam_caught','0'); diff --git a/installer/installer.php b/installer/installer.php index 2da3cd02..cf4f41d1 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -18,131 +18,20 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class installer { - static function command_line() { - // Set error handlers - set_error_handler(create_function('$errno, $errstr, $errfile, $errline', - 'throw new ErrorException($errstr, 0, $errno, $errfile, $errline);')); - set_exception_handler(array("installer", "print_exception")); - - if (self::already_installed()) { - print "Gallery 3 is already installed.\n"; - return; - } - - $config = self::parse_cli_params(); - try { - self::setup_database($config); - self::setup_var(); - 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 web() { - if (self::already_installed()) { - $state = "already_installed"; - include("install.html.php"); - return; - } - - switch ($step = $_GET["step"]) { - default: - $step = "welcome"; - break; - - case "get_info": - break; - - case "save_info": - $config = array("host" => $_GET["dbhost"], - "user" => $_GET["dbuser"], - "password" => $_GET["dbpass"], - "dbname" => $_GET["dbname"], - "prefix" => "", - "type" => function_exists("mysqli_init") ? "mysqli" : "mysql"); - try { - self::setup_database($config); - self::setup_var(); - self::install($config); - list ($user, $password) = self::create_admin($config); - } catch (Exception $e) { - $step = "database_failure"; - } - break; - } - - include("install.html.php"); - } - static function already_installed() { return file_exists(VARPATH . "database.php"); } - static function parse_cli_params() { - $config = array("host" => "localhost", - "user" => "root", - "password" => "", - "dbname" => "gallery3", - "prefix" => ""); - - if (function_exists("mysqli_init")) { - $config["type"] = "mysqli"; - } else { - $config["type"] = "mysql"; + static function var_writable() { + if (is_writable(VARPATH)) { + return true; } - $argv = $_SERVER["argv"]; - for ($i = 1; $i < count($argv); $i++) { - switch (strtolower($argv[$i])) { - case "-d": - $config["dbname"] = $argv[++$i]; - break; - case "-h": - $config["host"] = $argv[++$i]; - break; - case "-u": - $config["user"] = $argv[++$i]; - break; - case "-p": - $config["password"] = $argv[++$i]; - break; - } + if (@mkdir(VARPATH)) { + return true; } - return $config; - } - - 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; - } - - if (!mysql_select_db($config["dbname"])) { - if (!(mysql_query("CREATE DATABASE {$config['dbname']}") && - mysql_select_db($config["dbname"]))) { - $errors["Database"] = sprintf( - "Database '%s' is not defined and can't be created", - $config["dbname"]); - } - } - - if (empty($errors) && 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"]); - } - - if ($errors) { - throw new InstallException($errors); - } + return false; } static function setup_var() { @@ -161,36 +50,48 @@ class installer { } } - static function install($config) { - $errors = array(); + static function create_database_config($config) { + $db_config_file = VARPATH . "database.php"; + ob_start(); + extract($config); + include(DOCROOT . "installer/database_config.php"); + $output = ob_get_clean(); + return file_put_contents($db_config_file, $output) !== false; + } + static function unpack_var() { include(DOCROOT . "installer/init_var.php"); + return true; + } - $buf = ""; - foreach (file("installer/install.sql") as $line) { + static function unpack_sql() { + foreach (file(DOCROOT . "installer/install.sql") as $line) { $buf .= $line; if (preg_match("/;$/", $buf)) { if (!mysql_query($buf)) { - throw new InstallException( - array("Database" => "Unable to install database tables. Error details:\n" . - mysql_error())); - break; + return false; } $buf = ""; } } + return true; + } - $db_config_file = VARPATH . "database.php"; - ob_start(); - extract($config); - include("installer/database_config.php"); - $output = ob_get_clean(); + static function connect($config) { + return mysql_connect($config["host"], $config["user"], $config["password"]); + } - if (!file_put_contents($db_config_file, $output) !== false) { - throw new InstallException(array("Config" => "Unable to create " . VARPATH . "database.php")); + static function select_db($config) { + if (mysql_select_db($config["dbname"])) { + return true; } - system("chmod -R 777 " . VARPATH); + return mysql_query("CREATE DATABASE {$config['dbname']}") && + mysql_select_db($config["dbname"]); + } + + static function db_empty($config) { + return mysql_num_rows(mysql_query("SHOW TABLES FROM {$config['dbname']}")) == 0; } static function create_admin($config) { @@ -214,30 +115,4 @@ class installer { return array("admin", $password); } - - static function print_exception($exception) { - print $exception->getMessage() . "\n"; - print $exception->getTraceAsString(); - } - - static function display_errors($errors) { - print "Errors\n"; - foreach ($errors as $title => $error) { - print "$title\n"; - print " $error\n\n"; - } - } -} - -class InstallException extends Exception { - var $errors; - - function __construct($errors) { - parent::__construct(); - $this->errors = $errors; - } - - function errors() { - return $this->errors; - } -} +} \ No newline at end of file diff --git a/installer/pages/about_install.html.php b/installer/pages/about_install.html.php new file mode 100644 index 00000000..6ad2c242 --- /dev/null +++ b/installer/pages/about_install.html.php @@ -0,0 +1,18 @@ +

+ Gallery needs to talk to your MySQL database, so to get started + you'll need to know: +

+
    +
  1. Database name
  2. +
  3. Database username
  4. +
  5. Database password
  6. +
  7. Database host
  8. +
+ +

+ If you're missing any of this information, please ask your + web host or system administrator for a little help. +

+

+ Continue +

diff --git a/installer/pages/already_installed.html.php b/installer/pages/already_installed.html.php new file mode 100644 index 00000000..f8fc5706 --- /dev/null +++ b/installer/pages/already_installed.html.php @@ -0,0 +1,4 @@ +

+ Your Gallery3 install is complete. +

+ diff --git a/installer/pages/db_not_empty.html.php b/installer/pages/db_not_empty.html.php new file mode 100644 index 00000000..754d46c6 --- /dev/null +++ b/installer/pages/db_not_empty.html.php @@ -0,0 +1,5 @@ +

+ The database you provided already has other tables in it. + Continuing with the install might overwrite an existing Gallery + install. Please go back and choose a different database. +

diff --git a/installer/pages/environment_errors.html.php b/installer/pages/environment_errors.html.php new file mode 100644 index 00000000..7c31c1c2 --- /dev/null +++ b/installer/pages/environment_errors.html.php @@ -0,0 +1,19 @@ +

Whoa there!

+ +

+ There are some problems with your web hosting environment + that need to be fixed before you can successfully install + Gallery 3. +

+ + + +

+ Check again +

diff --git a/installer/pages/get_db_info.html.php b/installer/pages/get_db_info.html.php new file mode 100644 index 00000000..3459948e --- /dev/null +++ b/installer/pages/get_db_info.html.php @@ -0,0 +1,78 @@ +

+ Installing Gallery is very easy. We just need to know how to talk + to your MySQL database, and we need a place to store your photos on + your web host. +

+ + +
+ Photo Storage + +

+ We're having trouble creating a place for your photos. Can you + help? Please create a directory called var in your + gallery3 directory, then run chmod 777 var. That + should fix it. +

+ Check again +

+ +

+ We've found a place to store your photos. +

+ +
+ +
+
+ Database +

+ We've provided values that work for most common web hosts. If + you have problems, contact your web host for help. +

+
+ + + + + + + + + + + + + + + + + + + + +
+ Database Name + + +
+ User + + +
+ Password + + +
+ Host + + +
+ + + + (Please fix the photo storage problem before continuing) + +
+
+
diff --git a/installer/pages/missing_db.html.php b/installer/pages/missing_db.html.php new file mode 100644 index 00000000..1f93f08a --- /dev/null +++ b/installer/pages/missing_db.html.php @@ -0,0 +1,2 @@ +

+ < \ No newline at end of file diff --git a/installer/pages/oops.html.php b/installer/pages/oops.html.php new file mode 100644 index 00000000..141a4538 --- /dev/null +++ b/installer/pages/oops.html.php @@ -0,0 +1,9 @@ +

Oops!

+

+ Something unexpected happened and we can't finish your install. + We'll try to provide some details about the specific problem below. +

+

+ +

+ diff --git a/installer/pages/success.html.php b/installer/pages/success.html.php new file mode 100644 index 00000000..fbf5395d --- /dev/null +++ b/installer/pages/success.html.php @@ -0,0 +1,22 @@ +

Success!

+

+ Your Gallery3 install is complete! +

+ + +

Before you start using it...

+

+ We've created an account for you to use: +
+ username: +
+ password: +
+
+ Save this information in a safe place, or change your admin password + right away! +

+ + +

Start using Gallery

+ diff --git a/installer/web.php b/installer/web.php new file mode 100644 index 00000000..ddabcd19 --- /dev/null +++ b/installer/web.php @@ -0,0 +1,105 @@ + $errors)); + } else { + $content = render("pages/get_db_info.html.php"); + } + break; + + case "save_db_info": + $config = array("host" => $_POST["dbhost"], + "user" => $_POST["dbuser"], + "password" => $_POST["dbpass"], + "dbname" => $_POST["dbname"], + "prefix" => "", + "type" => function_exists("mysqli_init") ? "mysqli" : "mysql"); + + if (!installer::connect($config)) { + $content = render("pages/invalid_db_info.html.php"); + } else if (!installer::select_db($config)) { + $content = render("pages/missing_db.html.php"); + } else if (!installer::db_empty($config)) { + $content = render("pages/db_not_empty.html.php"); + } else if (!installer::unpack_var()) { + $content = oops("Unable to create files inside the var directory"); + } else if (!installer::unpack_sql()) { + $content = oops("Failed to create tables in your database:" . mysql_error()); + } else if (!installer::create_database_config($config)) { + $content = oops("Couldn't create var/database.php"); + } else { + list ($user, $password) = installer::create_admin($config); + $content = render("pages/success.html.php", array("user" => $user, "password" => $password)); + } + break; + } +} + +include("install.html.php"); + +function render($page, $args=array()) { + ob_start(); + extract($args); + include($page); + return ob_get_clean(); +} + +function oops($error) { + return render("pages/oops.html.php", array("error" => $error)); +} + +function check_environment() { + if (version_compare(PHP_VERSION, "5.2", "<")) { + $errors[] = "Gallery 3 requires PHP 5.2 or newer, current version: " . PHP_VERSION; + } + + if (!function_exists("mysql_query") && !function_exists("mysqli_init")) { + $errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the the MySQL or the MySQLi extension."; + } + + if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { + $errors[] = "PHP is missing Perl-Compatible Regular Expression support."; + } + + if (!(class_exists("ReflectionClass"))) { + $errors[] = "PHP is missing reflection support"; + } + + if (!(function_exists("filter_list"))) { + $errors[] = "PHP is missing the filter extension"; + } + + if (!(extension_loaded("iconv"))) { + $errors[] = "PHP is missing the iconv extension"; + } + + if (extension_loaded("mbstring") && (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { + $errors[] = "The mbstring extension is overloading PHP's native string functions. Please disable it."; + } + + return $errors; +} -- cgit v1.2.3