diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-20 00:54:02 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-20 00:54:02 +0000 |
commit | 681197a265f1dd3873780fdcf0b5f1e8fa0150ab (patch) | |
tree | fe8aafe29cf5f3d6d5a285c330147c9e3f3668c0 | |
parent | d51955c8efa78d7f0a0ca8c138c2eebaf5ecb975 (diff) |
Web based installer. It's still got some rough edges, but you can now
do a complete CLI or web based install.
-rw-r--r-- | core/controllers/welcome.php | 3 | ||||
-rw-r--r-- | core/images/gallery2.png | bin | 0 -> 22178 bytes | |||
-rw-r--r-- | installer/check.html.php | 92 | ||||
-rw-r--r-- | installer/cli.php | 90 | ||||
-rw-r--r-- | installer/database_config.php | 14 | ||||
-rw-r--r-- | installer/index.php | 4 | ||||
-rw-r--r-- | installer/init_var.php | 12 | ||||
-rw-r--r-- | installer/install.css | 51 | ||||
-rw-r--r-- | installer/install.html.php | 61 | ||||
-rw-r--r-- | installer/install.sql | 6 | ||||
-rw-r--r-- | installer/installer.php | 195 | ||||
-rw-r--r-- | installer/pages/about_install.html.php | 18 | ||||
-rw-r--r-- | installer/pages/already_installed.html.php | 4 | ||||
-rw-r--r-- | installer/pages/db_not_empty.html.php | 5 | ||||
-rw-r--r-- | installer/pages/environment_errors.html.php | 19 | ||||
-rw-r--r-- | installer/pages/get_db_info.html.php | 78 | ||||
-rw-r--r-- | installer/pages/missing_db.html.php | 2 | ||||
-rw-r--r-- | installer/pages/oops.html.php | 9 | ||||
-rw-r--r-- | installer/pages/success.html.php | 22 | ||||
-rw-r--r-- | installer/web.php | 105 |
20 files changed, 464 insertions, 326 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index e009452f..6130f0ed 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -541,7 +541,8 @@ class Welcome_Controller extends Template_Controller { } if ($file->isDir()) { - fwrite($fd, "mkdir(\"var/" . substr($name, strlen(VARPATH)) . "\");\n"); + $path = "VARPATH . \"" . substr($name, strlen(VARPATH)) . "\""; + fwrite($fd, "!file_exists($path) && mkdir($path);\n"); } else { // @todo: serialize non-directories print "Unknown file: $name"; diff --git a/core/images/gallery2.png b/core/images/gallery2.png Binary files differnew file mode 100644 index 00000000..ca8e0e95 --- /dev/null +++ b/core/images/gallery2.png 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 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<html> - <head> - <title>Gallery3 Installer: System Checks</title> - <link rel="stylesheet" type="text/css" href="install.css"/> - </head> - <body> - <div id="outer"> - <div id="inner"> - <img width="300" height="178" src="../core/images/gallery2.png"/> - - <h1> System Checks </h1> - <?php if (installer::already_installed()): ?> - <p> - 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. - </p> - <?php else: ?> - - <?php ob_start() ?> - <ul class="errors"> - <?php if (version_compare(PHP_VERSION, "5.2", "<")): ?> - <li> - Gallery 3 requires PHP 5.2 or newer, current version: <?= PHP_VERSION ?> - </li> - <?php $fail++; endif ?> - - <?php if (!function_exists("mysql_query") && !function_exists("mysqli_init")): ?> - <li> - Gallery 3 requires a MySQL database, but PHP doesn't have either the - the <a href="http://php.net/mysql">MySQL</a> - or the <a href="http://php.net/mysqli">MySQLi</a> extension. - </li> - <?php $fail++; endif ?> - - <?php if (!@preg_match("/^.$/u", utf8_encode("\xF1"))): ?> - <li> - PHP is missing <a href="http://php.net/pcre">Perl-Compatible Regular Expression</a> support. - </li> - <?php $fail++; endif ?> - - <?php if (!(class_exists("ReflectionClass"))): ?> - <li> - PHP is missing <a href="http://php.net/reflection">reflection</a> support - </li> - <?php $fail++; endif ?> - - <?php if (!(function_exists("filter_list"))): ?> - <li> - PHP is missing the <a href="http://php.net/filter">filter extension</a> - </li> - <?php $fail++; endif ?> - - <?php if (!(extension_loaded("iconv"))): ?> - <li> - PHP is missing the <a href="http://php.net/iconv">iconv extension</a> - </li> - <?php $fail++; endif ?> - - <?php if (extension_loaded("mbstring") && (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)): ?> - <li> - The <a href="http://php.net/mbstring">mbstring - extension</a> is overloading PHP's native string - functions. Please disable it. - </li> - <?php endif ?> - </ul> - <?php $errors = ob_get_clean() ?> - - <?php if (!empty($fail)): ?> - <p> - There are some problems with your web hosting environment - that need to be fixed before you can successfully install - Gallery 3. - </p> - <?php echo $errors ?> - <p> - <a href="check.php">Check again</a> - </p> - - <?php else: ?> - <p> - Good news! We've checked everything we can think of and it - looks like Gallery 3 should work just fine on your system. - </p> - <? endif ?> - <? endif /* already_installed check */?> - </div> - </div> - </body> -</html> 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 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +if (installer::already_installed()) { + print "Gallery 3 is already installed.\n"; + return; +} + +$config = parse_cli_params(); +if (!installer::connect($config)) { + oops("Unable to connect to the database.\n" . mysql_error() . "\n"); +} else if (!installer::select_db($config)) { + oops("Database {$config['dbname']} doesn't exist and can't be created. " . + "Please create the database by hand."); +} else if (!installer::db_empty($config)) { + oops("Database {$config['dbname']} already has tables in it. " . + "Please specify an empty database.\n"); +} else if (!installer::unpack_var()) { + oops("Unable to create files inside the 'var' directory"); +} else if (!installer::unpack_sql()) { + oops("Failed to create database tables\n" . mysql_error()); +} else if (!installer::create_database_config($config)) { + oops("Couldn't create var/database.php"); +} else { + list ($user, $password) = installer::create_admin($config); + print "Your Gallery has been successfully installed!\n"; + print "We've created an account for you to use:\n"; + print " username: $user\n"; + print " password: $password\n"; + print "\n"; + exit(0); +} + +function oops($message) { + print "Oops! Something went wrong during the installation:\n\n"; + + print "==> " . $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 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<?= "<?php" ?> defined("SYSPATH") or die("No direct script access."); +<?php print "<?php" ?> defined("SYSPATH") or die("No direct script access."); /** * @package Database @@ -29,16 +29,16 @@ $config["default"] = array( "benchmark" => false, "persistent" => false, "connection" => array( - "type" => "<?= $type ?>", - "user" => "<?= $user ?>", - "pass" => "<?= $password ?>", - "host" => "<?= $host ?>", + "type" => "<?php print $type ?>", + "user" => "<?php print $user ?>", + "pass" => "<?php print $password ?>", + "host" => "<?php print $host ?>", "port" => false, "socket" => false, - "database" => "<?= $dbname ?>" + "database" => "<?php print $dbname ?>" ), "character_set" => "utf8", - "table_prefix" => "<?= $prefix ?>", + "table_prefix" => "<?php print $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 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <?php -mkdir("var/albums"); -mkdir("var/resizes"); -mkdir("var/thumbs"); -mkdir("var/logs"); -mkdir("var/uploads"); -mkdir("var/modules"); +!file_exists(VARPATH . "albums") && mkdir(VARPATH . "albums"); +!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes"); +!file_exists(VARPATH . "thumbs") && mkdir(VARPATH . "thumbs"); +!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs"); +!file_exists(VARPATH . "uploads") && mkdir(VARPATH . "uploads"); +!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules"); diff --git a/installer/install.css b/installer/install.css index 36f7f321..eda3e14a 100644 --- a/installer/install.css +++ b/installer/install.css @@ -1,6 +1,11 @@ +h1, h2, h3 { + margin-bottom: .1em; +} + body { background: #eee; font-family: Trebuchet MS; + font-size: 1.1em; } div#outer { @@ -16,6 +21,48 @@ div#inner { margin: 0px; } -h1, h2, h3 { - margin-bottom: .1em; +div#footer { + border-top: 1px solid #ccc; + margin: 1em; +} + +.error { + border: 1px solid red; + background: #fcc; + padding: 4px; +} + +.success { + border: 1px solid green; + background: #cfc; + padding: 4px; +} + +p { + margin: 0px; + padding: 0px; +} + +fieldset { + border: 0px; + padding-left: 0px; + margin-top: 1em; +} + +fieldset legend { + font-weight: bold; + padding-left: 0px; +} + +table#db_info { + padding-left: 2em; +} + +table td { + padding-right: 1em; +} + +code { + background: #eee; + padding: 2px; } diff --git a/installer/install.html.php b/installer/install.html.php index 04870b7a..6d6b7e69 100644 --- a/installer/install.html.php +++ b/installer/install.html.php @@ -8,62 +8,17 @@ <div id="outer"> <img src="http://www.gallery2.org/gallery2.png"/> <div id="inner"> - <?php if ($step == "already_installed"): ?> - <p> - Your Gallery3 install is complete. - <?php elseif ($step == "welcome"): ?> - <p> - Welcome to Gallery 3. In order to get started, we need to - know how to talk to your database. You'll need to know: - <ol> - <li> Database name </li> - <li> Database username </li> - <li> Database password </li> - <li> Database host </li> - </ol> - - If you're missing any of this information, please ask your - web host or system administrator for a little help. - </p> - <p> - <a href="index.php?step=get_info">Continue</a> - </p> - <?php elseif ($step == "get_info"): ?> + <?php print $content ?> + </div> + <div id="footer"> <p> - Enter your database connnection information here. We've - provided common values that work for most people. If you - have problems, contact your web host for help. + <i>Did something go wrong? Try + the <a href="http://codex.gallery2.org/Gallery3:FAQ">FAQ</a> + or ask in + the <a href="http://gallery.menalto.com/forum">Gallery + forums</a>.</i> </p> - <form method="get" action="index.php"> - <fieldset> - <ul> - <li> - Database Name: <input name="dbname" value="gallery3"/> - </li> - <li> - User: <input name="dbuser" value="root"/> - </li> - <li> - Password: <input name="dbpass" value=""/> - </li> - <li> - Host: <input name="dbhost" value="localhost"/> - </li> - </ul> - <input type="hidden" name="step" value="save_info"/> - <input type="submit" value="Continue"/x> - </fieldset> - </form> - <?php endif ?> </div> - <p> - Did something go wrong? Run - a <a href="index.php?page=check">system check</a> to make sure - that it's not an issue with your web host. - </p> - <p> - Questions or problems? Visit the <a href="http://gallery.menalto.com">Gallery Website</a>. - </p> </div> </body> </html> 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 @@ +<p> + Gallery needs to talk to your MySQL database, so to get started + you'll need to know: +</p> +<ol> + <li> Database name </li> + <li> Database username </li> + <li> Database password </li> + <li> Database host </li> +</ol> + +<p> + If you're missing any of this information, please ask your + web host or system administrator for a little help. +</p> +<p> + <a href="index.php?step=get_db_info">Continue</a> +</p> 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 @@ +<p class="success"> + Your Gallery3 install is complete. +</p> + 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 @@ +<p class="error"> + 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. +</p> 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 @@ +<h1> Whoa there! </h1> + +<p class="error"> + There are some problems with your web hosting environment + that need to be fixed before you can successfully install + Gallery 3. +</p> + +<ul> + <?php foreach ($errors as $error): ?> + <li> + <?php print $error ?> + </li> + <?php endforeach ?> +</ul> + +<p> + <a href="index.php">Check again</a> +</p> 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 @@ +<p> + 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. +</p> + + +<fieldset> + <legend>Photo Storage</legend> + <?php if (!installer::var_writable()): ?> + <p class="error"> + We're having trouble creating a place for your photos. Can you + help? Please create a directory called <code>var</code> in your + gallery3 directory, then run <code>chmod 777 var</code>. That + should fix it. + <br/><br/> + <a href="index.php">Check again</a> + </p> + <?php else: ?> + <p class="success"> + We've found a place to store your photos. + </p> + <?php endif ?> +</fieldset> + +<form method="post" action="index.php?step=save_db_info"> + <fieldset> + <legend>Database</legend> + <p> + We've provided values that work for most common web hosts. If + you have problems, contact your web host for help. + </p> + <br/> + <table id="db_info"> + <tr> + <td> + Database Name + </td> + <td> + <input name="dbname" value="gallery3"/> + </td> + </tr> + <tr> + <td> + User + </td> + <td> + <input name="dbuser" value="root"/> + </td> + </tr> + <tr> + <td> + Password + </td> + <td> + <input name="dbpass" value=""/> + </td> + </tr> + <tr> + <td> + Host + </td> + <td> + <input name="dbhost" value="localhost"/> + </td> + </tr> + <tr> + <td colspan="2"> + <?php if (installer::var_writable()): ?> + <input type="submit" value="Continue"/> + <?php else: ?> + <i class="error">(Please fix the photo storage problem before continuing)</i> + <?php endif ?> + </td> + </tr> + </table> + </fieldset> +</form> 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 @@ +<p> + <
\ 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 @@ +<h1> Oops! </h1> +<p> + Something unexpected happened and we can't finish your install. + We'll try to provide some details about the specific problem below. +</p> +<p class="error"> + <?php print $error ?> +</p> + 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 @@ +<h1> Success! </h1> +<p class="success"> + Your Gallery3 install is complete! +</p> + +<?php if (!empty($user)): ?> +<h2> Before you start using it... </h2> +<p> + We've created an account for you to use: + <br/> + username: <b><?php print $user ?></b> + <br/> + password: <b><?php print $password ?></b> + <br/> + <br/> + Save this information in a safe place, or change your admin password + right away! +</p> +<?php endif ?> + +<h2> <a href="..">Start using Gallery</a> </h2> + 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 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +if (installer::already_installed()) { + $content = render("pages/success.html.php"); +} else { + switch ($_GET["step"]) { + default: + case "welcome": + $errors = check_environment(); + if ($errors) { + $content = render("pages/environment_errors.html.php", array("errors" => $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 <code>var</code> 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 <a href=\"http://php.net/mysql\">MySQL</a> or the <a href=\"http://php.net/mysqli\">MySQLi</a> extension."; + } + + if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { + $errors[] = "PHP is missing <a href=\"http://php.net/pcre\">Perl-Compatible Regular Expression</a> support."; + } + + if (!(class_exists("ReflectionClass"))) { + $errors[] = "PHP is missing <a href=\"http://php.net/reflection\">reflection</a> support"; + } + + if (!(function_exists("filter_list"))) { + $errors[] = "PHP is missing the <a href=\"http://php.net/filter\">filter extension</a>"; + } + + if (!(extension_loaded("iconv"))) { + $errors[] = "PHP is missing the <a href=\"http://php.net/iconv\">iconv extension</a>"; + } + + if (extension_loaded("mbstring") && (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { + $errors[] = "The <a href=\"http://php.net/mbstring\">mbstring extension</a> is overloading PHP's native string functions. Please disable it."; + } + + return $errors; +} |