diff options
Diffstat (limited to 'installer')
| -rw-r--r-- | installer/cli.php | 121 | ||||
| -rw-r--r-- | installer/database_config.php | 46 | ||||
| -rw-r--r-- | installer/index.php | 40 | ||||
| -rwxr-xr-x | installer/init_var.php | 12 | ||||
| -rw-r--r-- | installer/install.css | 92 | ||||
| -rw-r--r-- | installer/install.sql | 433 | ||||
| -rw-r--r-- | installer/installer.php | 270 | ||||
| -rw-r--r-- | installer/views/already_installed.html.php | 5 | ||||
| -rw-r--r-- | installer/views/db_not_empty.html.php | 8 | ||||
| -rw-r--r-- | installer/views/environment_errors.html.php | 20 | ||||
| -rw-r--r-- | installer/views/get_db_info.html.php | 89 | ||||
| -rw-r--r-- | installer/views/install.html.php | 24 | ||||
| -rw-r--r-- | installer/views/invalid_db_info.html.php | 6 | ||||
| -rw-r--r-- | installer/views/invalid_db_version.html.php | 5 | ||||
| -rw-r--r-- | installer/views/missing_db.html.php | 13 | ||||
| -rw-r--r-- | installer/views/oops.html.php | 10 | ||||
| -rw-r--r-- | installer/views/success.html.php | 23 | ||||
| -rw-r--r-- | installer/web.php | 94 |
18 files changed, 1311 insertions, 0 deletions
diff --git a/installer/cli.php b/installer/cli.php new file mode 100644 index 0000000..b31405f --- /dev/null +++ b/installer/cli.php @@ -0,0 +1,121 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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. + */ +/** + * Command line parameters: + * -h Database host (default: localhost) + * -u Database user (default: root) + * -p Database user password (default: ) + * -d Database name (default: gallery3) + * -x Table prefix (default: ) + */ +if (installer::already_installed()) { + print "Gallery 3 is already installed.\n"; + return; +} + +$errors = installer::check_environment(); +if ($errors) { + oops(implode($errors, "\n")); +} + +$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 (is_string($count = installer::db_empty($config)) || !$count) { + if (is_string($count)) { + oops($count); + } else { + oops("Database {$config['dbname']} already has Gallery 3 tables in it. \n" . + " Please remove the Gallery 3 tables, change your prefix,\n" . + " or specify an empty database.\n"); + } +} else if (!installer::unpack_var()) { + oops("Unable to create files inside the 'var' directory"); +} else if (!installer::unpack_sql($config)) { + oops("Failed to create database tables\n" . mysql_error()); +} else if (!installer::create_database_config($config)) { + oops("Couldn't create var/database.php"); +} else { + system("chmod -R 777 " . VARPATH); + try { + 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"; + + installer::create_private_key($config); + exit(0); + } catch (Exception $e) { + oops($e->getMessage()); + } +} + +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 Gallery 3 FAQ - http://codex.galleryproject.org/Gallery3:FAQ\n"; + print " * The Gallery Forums - http://galleryproject.org/forum\n"; + print "\n\n** INSTALLATION FAILED **\n"; + exit(1); +} + +function parse_cli_params() { + $config = array("host" => "localhost", + "user" => "root", + "password" => "", + "dbname" => "gallery3", + "prefix" => "", + "g3_password" => "", + "type" => function_exists("mysqli_set_charset") ? "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": + list ($config["host"], $config["port"]) = explode(":", $argv[++$i]); + break; + case "-u": + $config["user"] = $argv[++$i]; + break; + case "-p": + $config["password"] = $argv[++$i]; + break; + case "-x": + $config["prefix"] = $argv[++$i]; + break; + case "-g3p": + $config["g3_password"] = $argv[++$i]; + break; + } + } + + return $config; +} diff --git a/installer/database_config.php b/installer/database_config.php new file mode 100644 index 0000000..fb7dd11 --- /dev/null +++ b/installer/database_config.php @@ -0,0 +1,46 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?php print "<?php" ?> defined("SYSPATH") or die("No direct script access."); + +/** + * @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' => '<?php print $type ?>', + 'user' => '<?php print $user ?>', + 'pass' => '<?php print $password ?>', + 'host' => '<?php print $host ?>', + 'port' => <?php if (!empty($port)): ?>'<?php print $port ?>' <?php else: ?>false<?php endif ?>, + 'socket' => false, + 'database' => '<?php print $dbname ?>', + 'params' => null, + ), + 'character_set' => 'utf8', + 'table_prefix' => '<?php print $prefix ?>', + 'object' => true, + 'cache' => false, + 'escape' => true +);
\ No newline at end of file diff --git a/installer/index.php b/installer/index.php new file mode 100644 index 0000000..651edc9 --- /dev/null +++ b/installer/index.php @@ -0,0 +1,40 @@ +<?php +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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. + */ +define("DOCROOT", dirname(dirname(__FILE__)) . "/"); +define("VARPATH", DOCROOT . "var/"); +define("SYSPATH", "DEFINED_TO_SOMETHING_SO_THAT_WE_CAN_KEEP_CONSISTENT_PREAMBLES_IN_THE_INSTALLER"); + +if (version_compare(PHP_VERSION, "5.2.3", "<")) { + print "Gallery 3 requires PHP 5.2.3 or newer.\n"; + exit; +} + +// Turn off session.use_trans_sid -- that feature attempts to inject session ids +// into generated URLs and forms, but it doesn't interoperate will with Gallery's +// Ajax code. +ini_set("session.use_trans_sid", false); + +require(DOCROOT . "installer/installer.php"); +if (PHP_SAPI == "cli") { + include("cli.php"); +} else { + include("web.php"); +} + diff --git a/installer/init_var.php b/installer/init_var.php new file mode 100755 index 0000000..353665a --- /dev/null +++ b/installer/init_var.php @@ -0,0 +1,12 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?php +!file_exists(VARPATH . "albums") && mkdir(VARPATH . "albums"); +!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs"); +!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules"); +!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes"); +!file_exists(VARPATH . "thumbs") && mkdir(VARPATH . "thumbs"); +!file_exists(VARPATH . "tmp") && mkdir(VARPATH . "tmp"); +!file_exists(VARPATH . "uploads") && mkdir(VARPATH . "uploads"); +file_put_contents(VARPATH . "logs/.htaccess", base64_decode("RGlyZWN0b3J5SW5kZXggLmh0YWNjZXNzClNldEhhbmRsZXIgR2FsbGVyeV9TZWN1cml0eV9Eb19Ob3RfUmVtb3ZlCk9wdGlvbnMgTm9uZQo8SWZNb2R1bGUgbW9kX3Jld3JpdGUuYz4KUmV3cml0ZUVuZ2luZSBvZmYKPC9JZk1vZHVsZT4KT3JkZXIgYWxsb3csZGVueQpEZW55IGZyb20gYWxsCg==")); +file_put_contents(VARPATH . "tmp/.htaccess", base64_decode("RGlyZWN0b3J5SW5kZXggLmh0YWNjZXNzClNldEhhbmRsZXIgR2FsbGVyeV9TZWN1cml0eV9Eb19Ob3RfUmVtb3ZlCk9wdGlvbnMgTm9uZQo8SWZNb2R1bGUgbW9kX3Jld3JpdGUuYz4KUmV3cml0ZUVuZ2luZSBvZmYKPC9JZk1vZHVsZT4KT3JkZXIgYWxsb3csZGVueQpEZW55IGZyb20gYWxsCg==")); +file_put_contents(VARPATH . "uploads/.htaccess", base64_decode("RGlyZWN0b3J5SW5kZXggLmh0YWNjZXNzClNldEhhbmRsZXIgR2FsbGVyeV9TZWN1cml0eV9Eb19Ob3RfUmVtb3ZlCk9wdGlvbnMgTm9uZQo8SWZNb2R1bGUgbW9kX3Jld3JpdGUuYz4KUmV3cml0ZUVuZ2luZSBvZmYKPC9JZk1vZHVsZT4KT3JkZXIgYWxsb3csZGVueQpEZW55IGZyb20gYWxsCg==")); diff --git a/installer/install.css b/installer/install.css new file mode 100644 index 0000000..e132b80 --- /dev/null +++ b/installer/install.css @@ -0,0 +1,92 @@ +h1, h2, h3 { + margin-bottom: .1em; +} + +body { + background: #eee; + font-family: Trebuchet MS, Verdana; + font-size: 1.1em; +} + +em { + font-style: italic; +} + +div#outer { + width: 650px; + background: white; + border: 1px solid #999; + margin: 0 auto; + padding: -10px; +} + +div#inner { + padding: 0 1em 0 1em; + margin: 0px; +} + +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; + border: 1px solid #ccc; + padding: 8px; +} + +fieldset legend { + font-weight: bold; + margin: 8px; + padding: 2px; +} + +table#db_info { + padding-left: 2em; +} + +table td { + padding-right: 1em; +} + +code { + background: #eee; + border: 1px solid #bbb; + padding: 2px; + display: block; + width: 200px; + margin: 4px 4px 4px 20px; +} + +code.location { + display: block; + margin: 4px; + padding: 4px; + width: auto; +} + +span.subtext { + font-size: .7em; + color: #999; +} + diff --git a/installer/install.sql b/installer/install.sql new file mode 100644 index 0000000..f4938f6 --- /dev/null +++ b/installer/install.sql @@ -0,0 +1,433 @@ +DROP TABLE IF EXISTS {access_caches}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {access_caches} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `item_id` int(9) DEFAULT NULL, + `view_full_1` binary(1) NOT NULL DEFAULT '0', + `edit_1` binary(1) NOT NULL DEFAULT '0', + `add_1` binary(1) NOT NULL DEFAULT '0', + `view_full_2` binary(1) NOT NULL DEFAULT '0', + `edit_2` binary(1) NOT NULL DEFAULT '0', + `add_2` binary(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `item_id` (`item_id`) +) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {access_caches} VALUES (1,1,'1','0','0','1','0','0'); +DROP TABLE IF EXISTS {access_intents}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {access_intents} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `item_id` int(9) DEFAULT NULL, + `view_1` binary(1) DEFAULT NULL, + `view_full_1` binary(1) DEFAULT NULL, + `edit_1` binary(1) DEFAULT NULL, + `add_1` binary(1) DEFAULT NULL, + `view_2` binary(1) DEFAULT NULL, + `view_full_2` binary(1) DEFAULT NULL, + `edit_2` binary(1) DEFAULT NULL, + `add_2` binary(1) DEFAULT NULL, + PRIMARY KEY (`id`) +) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {access_intents} VALUES (1,1,'1','1','0','0','1','1','0','0'); +DROP TABLE IF EXISTS {caches}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {caches} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL, + `tags` varchar(255) DEFAULT NULL, + `expiration` int(9) NOT NULL, + `cache` longblob, + PRIMARY KEY (`id`), + UNIQUE KEY `key` (`key`), + KEY `tags` (`tags`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {comments}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {comments} ( + `author_id` int(9) DEFAULT NULL, + `created` int(9) NOT NULL, + `guest_email` varchar(128) DEFAULT NULL, + `guest_name` varchar(128) DEFAULT NULL, + `guest_url` varchar(255) DEFAULT NULL, + `id` int(9) NOT NULL AUTO_INCREMENT, + `item_id` int(9) NOT NULL, + `server_http_accept_charset` varchar(64) DEFAULT NULL, + `server_http_accept_encoding` varchar(64) DEFAULT NULL, + `server_http_accept_language` varchar(64) DEFAULT NULL, + `server_http_accept` varchar(128) DEFAULT NULL, + `server_http_connection` varchar(64) DEFAULT NULL, + `server_http_host` varchar(64) DEFAULT NULL, + `server_http_referer` varchar(255) DEFAULT NULL, + `server_http_user_agent` varchar(128) DEFAULT NULL, + `server_query_string` varchar(64) DEFAULT NULL, + `server_remote_addr` varchar(40) DEFAULT NULL, + `server_remote_host` varchar(255) DEFAULT NULL, + `server_remote_port` varchar(16) DEFAULT NULL, + `state` varchar(15) DEFAULT 'unpublished', + `text` text, + `updated` int(9) NOT NULL, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {failed_auths}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {failed_auths} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `count` int(9) NOT NULL, + `name` varchar(255) NOT NULL, + `time` int(9) NOT NULL, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {graphics_rules}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {graphics_rules} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `active` tinyint(1) DEFAULT '0', + `args` varchar(255) DEFAULT NULL, + `module_name` varchar(64) NOT NULL, + `operation` varchar(64) NOT NULL, + `priority` int(9) NOT NULL, + `target` varchar(32) NOT NULL, + PRIMARY KEY (`id`) +) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'thumb'); +INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:640;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'resize'); +DROP TABLE IF EXISTS {groups}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {groups} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `name` char(64) DEFAULT NULL, + `special` tinyint(1) DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {groups} VALUES (1,'Everybody',1); +INSERT INTO {groups} VALUES (2,'Registered Users',1); +DROP TABLE IF EXISTS {groups_users}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {groups_users} ( + `group_id` int(9) NOT NULL, + `user_id` int(9) NOT NULL, + PRIMARY KEY (`group_id`,`user_id`), + UNIQUE KEY `user_id` (`user_id`,`group_id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {groups_users} VALUES (1,1); +INSERT INTO {groups_users} VALUES (1,2); +INSERT INTO {groups_users} VALUES (2,2); +DROP TABLE IF EXISTS {incoming_translations}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {incoming_translations} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `key` char(32) NOT NULL, + `locale` char(10) NOT NULL, + `message` text NOT NULL, + `revision` int(9) DEFAULT NULL, + `translation` text, + PRIMARY KEY (`id`), + UNIQUE KEY `key` (`key`,`locale`), + KEY `locale_key` (`locale`,`key`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {items}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {items} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `album_cover_item_id` int(9) DEFAULT NULL, + `captured` int(9) DEFAULT NULL, + `created` int(9) DEFAULT NULL, + `description` text, + `height` int(9) DEFAULT NULL, + `left_ptr` int(9) NOT NULL, + `level` int(9) NOT NULL, + `mime_type` varchar(64) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `owner_id` int(9) DEFAULT NULL, + `parent_id` int(9) NOT NULL, + `rand_key` decimal(11,10) DEFAULT NULL, + `relative_path_cache` varchar(255) DEFAULT NULL, + `relative_url_cache` varchar(255) DEFAULT NULL, + `resize_dirty` tinyint(1) DEFAULT '1', + `resize_height` int(9) DEFAULT NULL, + `resize_width` int(9) DEFAULT NULL, + `right_ptr` int(9) NOT NULL, + `slug` varchar(255) DEFAULT NULL, + `sort_column` varchar(64) DEFAULT NULL, + `sort_order` char(4) DEFAULT 'ASC', + `thumb_dirty` tinyint(1) DEFAULT '1', + `thumb_height` int(9) DEFAULT NULL, + `thumb_width` int(9) DEFAULT NULL, + `title` varchar(255) DEFAULT NULL, + `type` varchar(32) NOT NULL, + `updated` int(9) DEFAULT NULL, + `view_count` int(9) DEFAULT '0', + `weight` int(9) NOT NULL DEFAULT '0', + `width` int(9) DEFAULT NULL, + `view_1` binary(1) DEFAULT '0', + `view_2` binary(1) DEFAULT '0', + PRIMARY KEY (`id`), + KEY `parent_id` (`parent_id`), + KEY `type` (`type`), + KEY `random` (`rand_key`), + KEY `weight` (`weight`), + KEY `left_ptr` (`left_ptr`), + KEY `relative_path_cache` (`relative_path_cache`) +) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,2,0,NULL,'','',1,NULL,NULL,2,NULL,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1'); +DROP TABLE IF EXISTS {items_tags}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {items_tags} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `item_id` int(9) NOT NULL, + `tag_id` int(9) NOT NULL, + PRIMARY KEY (`id`), + KEY `tag_id` (`tag_id`,`id`), + KEY `item_id` (`item_id`,`id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {logs}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {logs} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `category` varchar(64) DEFAULT NULL, + `html` varchar(255) DEFAULT NULL, + `message` text, + `referer` varchar(255) DEFAULT NULL, + `severity` int(9) DEFAULT '0', + `timestamp` int(9) DEFAULT '0', + `url` varchar(255) DEFAULT NULL, + `user_id` int(9) DEFAULT '0', + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {messages}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {messages} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `key` varchar(255) DEFAULT NULL, + `severity` varchar(32) DEFAULT NULL, + `value` text, + PRIMARY KEY (`id`), + UNIQUE KEY `key` (`key`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {modules}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {modules} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `active` tinyint(1) DEFAULT '0', + `name` varchar(64) DEFAULT NULL, + `version` int(9) DEFAULT NULL, + `weight` int(9) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`), + KEY `weight` (`weight`) +) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {modules} VALUES (1,1,'gallery',57,1); +INSERT INTO {modules} VALUES (2,1,'user',4,2); +INSERT INTO {modules} VALUES (3,1,'comment',7,3); +INSERT INTO {modules} VALUES (4,1,'organize',4,4); +INSERT INTO {modules} VALUES (5,1,'info',2,5); +INSERT INTO {modules} VALUES (6,1,'rss',1,6); +INSERT INTO {modules} VALUES (7,1,'search',1,7); +INSERT INTO {modules} VALUES (8,1,'slideshow',2,8); +INSERT INTO {modules} VALUES (9,1,'tag',3,9); +DROP TABLE IF EXISTS {outgoing_translations}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {outgoing_translations} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `base_revision` int(9) DEFAULT NULL, + `key` char(32) NOT NULL, + `locale` char(10) NOT NULL, + `message` text NOT NULL, + `translation` text, + PRIMARY KEY (`id`), + UNIQUE KEY `key` (`key`,`locale`), + KEY `locale_key` (`locale`,`key`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {permissions}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {permissions} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `display_name` varchar(64) DEFAULT NULL, + `name` varchar(64) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {permissions} VALUES (1,'View','view'); +INSERT INTO {permissions} VALUES (2,'View full size','view_full'); +INSERT INTO {permissions} VALUES (3,'Edit','edit'); +INSERT INTO {permissions} VALUES (4,'Add','add'); +DROP TABLE IF EXISTS {search_records}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {search_records} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `item_id` int(9) DEFAULT NULL, + `dirty` tinyint(1) DEFAULT '1', + `data` longtext, + PRIMARY KEY (`id`), + KEY `item_id` (`item_id`), + FULLTEXT KEY `data` (`data`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {search_records} VALUES (1,1,0,' Gallery'); +DROP TABLE IF EXISTS {sessions}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {sessions} ( + `session_id` varchar(127) NOT NULL, + `data` text NOT NULL, + `last_activity` int(10) unsigned NOT NULL, + PRIMARY KEY (`session_id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {tags}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {tags} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `name` varchar(128) NOT NULL, + `count` int(10) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {tasks}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {tasks} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `callback` varchar(128) DEFAULT NULL, + `context` text NOT NULL, + `done` tinyint(1) DEFAULT '0', + `name` varchar(128) DEFAULT NULL, + `owner_id` int(9) DEFAULT NULL, + `percent_complete` int(9) DEFAULT '0', + `state` varchar(32) DEFAULT NULL, + `status` varchar(255) DEFAULT NULL, + `updated` int(9) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `owner_id` (`owner_id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS {themes}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 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`) +) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {themes} VALUES (1,'wind',1); +INSERT INTO {themes} VALUES (2,'admin_wind',1); +DROP TABLE IF EXISTS {users}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 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', + `hash` char(32) DEFAULT NULL, + `url` varchar(255) DEFAULT NULL, + `locale` char(10) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`), + UNIQUE KEY `hash` (`hash`) +) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {users} VALUES (1,'guest','Guest User','',0,0,NULL,0,1,NULL,NULL,NULL); +INSERT INTO {users} VALUES (2,'admin','Gallery Administrator','',0,0,'unknown@unknown.com',1,0,NULL,NULL,NULL); +DROP TABLE IF EXISTS {vars}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 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`) +) AUTO_INCREMENT=47 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind'); +INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind'); +INSERT INTO {vars} VALUES (NULL,'gallery','page_size','9'); +INSERT INTO {vars} VALUES (NULL,'gallery','thumb_size','200'); +INSERT INTO {vars} VALUES (NULL,'gallery','resize_size','640'); +INSERT INTO {vars} VALUES (NULL,'gallery','default_locale','en_US'); +INSERT INTO {vars} VALUES (NULL,'gallery','image_quality','75'); +INSERT INTO {vars} VALUES (NULL,'gallery','image_sharpen','15'); +INSERT INTO {vars} VALUES (NULL,'gallery','upgrade_checker_auto_enabled','1'); +INSERT INTO {vars} VALUES (NULL,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'); +INSERT INTO {vars} VALUES (NULL,'gallery','blocks_dashboard_center','a:4:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:15:\"upgrade_checker\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:9;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}}'); +INSERT INTO {vars} VALUES (NULL,'gallery','choose_default_tookit','1'); +INSERT INTO {vars} VALUES (NULL,'gallery','date_format','Y-M-d'); +INSERT INTO {vars} VALUES (NULL,'gallery','date_time_format','Y-M-d H:i:s'); +INSERT INTO {vars} VALUES (NULL,'gallery','time_format','H:i:s'); +INSERT INTO {vars} VALUES (NULL,'gallery','show_credits','1'); +INSERT INTO {vars} VALUES (NULL,'gallery','credits','Powered by <a href=\"%url\">%gallery_version</a>'); +INSERT INTO {vars} VALUES (NULL,'gallery','simultaneous_upload_limit','5'); +INSERT INTO {vars} VALUES (NULL,'gallery','admin_area_timeout','5400'); +INSERT INTO {vars} VALUES (NULL,'gallery','maintenance_mode','0'); +INSERT INTO {vars} VALUES (NULL,'gallery','visible_title_length','15'); +INSERT INTO {vars} VALUES (NULL,'gallery','favicon_url','lib/images/favicon.ico'); +INSERT INTO {vars} VALUES (NULL,'gallery','apple_touch_icon_url','lib/images/apple-touch-icon.png'); +INSERT INTO {vars} VALUES (NULL,'gallery','email_from','unknown@unknown.com'); +INSERT INTO {vars} VALUES (NULL,'gallery','email_reply_to','unknown@unknown.com'); +INSERT INTO {vars} VALUES (NULL,'gallery','email_line_length','70'); +INSERT INTO {vars} VALUES (NULL,'gallery','email_header_separator','s:1:\"\n\";'); +INSERT INTO {vars} VALUES (NULL,'gallery','show_user_profiles_to','registered_users'); +INSERT INTO {vars} VALUES (NULL,'gallery','extra_binary_paths','/usr/local/bin:/opt/local/bin:/opt/bin'); +INSERT INTO {vars} VALUES (NULL,'gallery','timezone',NULL); +INSERT INTO {vars} VALUES (NULL,'gallery','lock_timeout','1'); +INSERT INTO {vars} VALUES (NULL,'gallery','movie_extract_frame_time','3'); +INSERT INTO {vars} VALUES (NULL,'gallery','movie_allow_uploads','autodetect'); +INSERT INTO {vars} VALUES (NULL,'gallery','blocks_site_sidebar','a:4:{i:10;a:2:{i:0;s:7:\"gallery\";i:1;s:8:\"language\";}i:11;a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}i:12;a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}i:13;a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}'); +INSERT INTO {vars} VALUES (NULL,'gallery','identity_provider','user'); +INSERT INTO {vars} VALUES (NULL,'user','minimum_password_length','5'); +INSERT INTO {vars} VALUES (NULL,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (NULL,'comment','access_permissions','everybody'); +INSERT INTO {vars} VALUES (NULL,'comment','rss_visible','all'); +INSERT INTO {vars} VALUES (NULL,'info','show_title','1'); +INSERT INTO {vars} VALUES (NULL,'info','show_description','1'); +INSERT INTO {vars} VALUES (NULL,'info','show_owner','1'); +INSERT INTO {vars} VALUES (NULL,'info','show_name','1'); +INSERT INTO {vars} VALUES (NULL,'info','show_captured','1'); +INSERT INTO {vars} VALUES (NULL,'slideshow','max_scale','0'); +INSERT INTO {vars} VALUES (NULL,'tag','tag_cloud_size','30'); diff --git a/installer/installer.php b/installer/installer.php new file mode 100644 index 0000000..434d8e5 --- /dev/null +++ b/installer/installer.php @@ -0,0 +1,270 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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. + */ + +class installer { + static $mysqli; + + static function already_installed() { + return file_exists(VARPATH . "database.php"); + } + + static function var_writable() { + if (is_writable(VARPATH)) { + return true; + } + + if (@mkdir(VARPATH)) { + return true; + } + + return false; + } + + 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() { + if (!file_exists(VARPATH)) { + mkdir(VARPATH); + chmod(VARPATH, 0777); + } + + include(DOCROOT . "installer/init_var.php"); + return true; + } + + static function unpack_sql($config) { + $prefix = $config["prefix"]; + $buf = null; + foreach (file(DOCROOT . "installer/install.sql") as $line) { + $buf .= trim($line); + if (preg_match("/;$/", $buf)) { + if (!mysql_query(self::prepend_prefix($prefix, $buf))) { + return false; + } + $buf = ""; + } + } + return true; + } + + static function connect($config) { + // We know that we have either mysql or mysqli. By default we use mysql functions, so if + // they're not defined then do the simplest thing which will work: remap them to their mysqli + // counterparts. + if (!function_exists("mysql_query")) { + function mysql_connect($host, $user, $pass) { + list ($host, $port) = explode(":", $host . ":"); + installer::$mysqli = new mysqli($host, $user, $pass, $port); + // http://php.net/manual/en/mysqli.connect.php says to use mysqli_connect_error() instead of + // $mysqli->connect_error because of bugs before PHP 5.2.9 + $error = mysqli_connect_error(); + return empty($error); + } + function mysql_query($query) { + return installer::$mysqli->query($query); + } + function mysql_num_rows($result) { + return $result->num_rows; + } + function mysql_error() { + return installer::$mysqli->error; + } + function mysql_select_db($db) { + return installer::$mysqli->select_db($db); + } + } + + $host = empty($config["port"]) ? $config['host'] : "{$config['host']}:{$config['port']}"; + return @mysql_connect($host, $config["user"], $config["password"]); + } + + static function select_db($config) { + if (mysql_select_db($config["dbname"])) { + return true; + } + + return mysql_query("CREATE DATABASE `{$config['dbname']}`") && + mysql_select_db($config["dbname"]); + } + + static function verify_mysql_version($config) { + return version_compare(installer::mysql_version($config), "5.0.0", ">="); + } + + static function mysql_version($config) { + $result = mysql_query("SHOW VARIABLES WHERE variable_name = \"version\""); + $row = mysql_fetch_object($result); + return $row->Value; + } + + static function db_empty($config) { + $query = "SHOW TABLES LIKE '{$config['prefix']}items'"; + $results = mysql_query($query); + if ($results === false) { + $msg = mysql_error(); + return $msg; + } + return mysql_num_rows($results) === 0; + } + + static function create_admin($config) { + $salt = ""; + for ($i = 0; $i < 4; $i++) { + $char = mt_rand(48, 109); + $char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0; + $salt .= chr($char); + } + if (!$password = $config["g3_password"]) { + $password = substr(md5(time() . mt_rand()), 0, 6); + } + // Escape backslash in preparation for our UPDATE statement. + $hashed_password = str_replace("\\", "\\\\", $salt . md5($salt . $password)); + $sql = self::prepend_prefix($config["prefix"], + "UPDATE {users} SET `password` = '$hashed_password' WHERE `id` = 2"); + if (mysql_query($sql)) { + } else { + throw new Exception(mysql_error()); + } + + return array("admin", $password); + } + + static function create_admin_session($config) { + $session_id = md5(time() . mt_rand()); + $user_agent = $_SERVER["HTTP_USER_AGENT"]; + $user_agent_len = strlen($user_agent); + $now = time(); + $data = "session_id|s:32:\"$session_id\""; + $data .= ";user_agent|s:{$user_agent_len}:\"$user_agent\""; + $data .= ";user|i:2"; + $data .= ";after_install|i:1"; + $data .= ";last_activity|i:$now"; + $data = base64_encode($data); + $sql = "INSERT INTO {sessions}(`session_id`, `last_activity`, `data`) " . + "VALUES('$session_id', $now, '$data')"; + $sql = self::prepend_prefix($config["prefix"], $sql); + if (mysql_query($sql)) { + setcookie("g3sid", $session_id, 0, "/", "", false, false); + } else { + throw new Exception(mysql_error()); + } + } + + static function create_private_key($config) { + $key = md5(uniqid(mt_rand(), true)) . md5(uniqid(mt_rand(), true)); + $sql = self::prepend_prefix($config["prefix"], + "INSERT INTO {vars} VALUES(NULL, 'gallery', 'private_key', '$key')"); + if (mysql_query($sql)) { + } else { + throw new Exception(mysql_error()); + } + } + + static function prepend_prefix($prefix, $sql) { + return preg_replace("#{([a-zA-Z0-9_]+)}#", "`{$prefix}$1`", $sql); + } + + static function check_environment() { + if (!function_exists("mysql_query") && !function_exists("mysqli_set_charset")) { + $errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the <a href=\"http://php.net/mysql\">MySQL</a> or the <a href=\"http://php.net/mysqli\">MySQLi</a> extension."; + } + + if (!preg_match("/^.$/u", "ñ")) { + $errors[] = "PHP is missing <a href=\"http://php.net/pcre\">Perl-Compatible Regular Expression</a> with UTF-8 support."; + } else if (!preg_match("/^\pL$/u", "ñ")) { + $errors[] = "PHP is missing <a href=\"http://php.net/pcre\">Perl-Compatible Regular Expression</a> with Unicode support."; + } + + if (!(function_exists("spl_autoload_register"))) { + $errors[] = "PHP is missing <a href=\"http://php.net/spl\">Standard PHP Library (SPL)</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("xml"))) { + $errors[] = "PHP is missing the <a href=\"http://php.net/xml\">XML Parser extension</a>"; + } + + if (!(extension_loaded("simplexml"))) { + $errors[] = "PHP is missing the <a href=\"http://php.net/simplexml\">SimpleXML extension</a>"; + } + + if (!extension_loaded("mbstring")) { + $errors[] = "PHP is missing the <a href=\"http://php.net/mbstring\">mbstring extension</a>"; + } else if (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."; + } + + if (!function_exists("json_encode")) { + $errors[] = "PHP is missing the <a href=\"http://php.net/manual/en/book.json.php\">JavaScript Object Notation (JSON) extension</a>. Please install it."; + } + + if (!ini_get("short_open_tag")) { + $errors[] = "Gallery requires <a href=\"http://php.net/manual/en/ini.core.php\">short_open_tag</a> to be on. Please enable it in your php.ini."; + } + + if (!function_exists("ctype_alpha")) { + $errors[] = "Gallery requires the <a href=\"http://php.net/manual/en/book.ctype.php\">PHP Ctype</a> extension. Please install it."; + } + + if (self::ini_get_bool("safe_mode")) { + $errors[] = "Gallery cannot function when PHP is in <a href=\"http://php.net/manual/en/features.safe-mode.php\">Safe Mode</a>. Please disable safe mode."; + } + + return @$errors; + } + + /** + * Convert any possible boolean ini value to true/false. + * On = on = 1 = true + * Off = off = 0 = false + */ + static function ini_get_bool($varname) { + $value = ini_get($varname); + + if (!strcasecmp("on", $value) || $value == 1 || $value === true) { + return true; + } + + if (!strcasecmp("off", $value) || $value == 0 || $value === false) { + return false; + } + + return false; + } + +} diff --git a/installer/views/already_installed.html.php b/installer/views/already_installed.html.php new file mode 100644 index 0000000..f6ac1bf --- /dev/null +++ b/installer/views/already_installed.html.php @@ -0,0 +1,5 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<p class="success"> + Your Gallery 3 install is complete. +</p> + diff --git a/installer/views/db_not_empty.html.php b/installer/views/db_not_empty.html.php new file mode 100644 index 0000000..bc45458 --- /dev/null +++ b/installer/views/db_not_empty.html.php @@ -0,0 +1,8 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Uh oh! </h1> +<p class="error"> + The database you provided already has Gallery 3 tables in it. + Continuing with the install would overwrite your existing install. + Please either use a different database, delete the old tables, + or choose a different table prefix. +</p> diff --git a/installer/views/environment_errors.html.php b/installer/views/environment_errors.html.php new file mode 100644 index 0000000..318be61 --- /dev/null +++ b/installer/views/environment_errors.html.php @@ -0,0 +1,20 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<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/views/get_db_info.html.php b/installer/views/get_db_info.html.php new file mode 100644 index 0000000..c9f57e1 --- /dev/null +++ b/installer/views/get_db_info.html.php @@ -0,0 +1,89 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Let's get going! </h1> +<p> + Installing Gallery is easy. We just need a place to put your photos + and info about your MySQL database. +</p> + + +<fieldset class="<?= installer::var_writable() ? 'success' : 'error' ?>"> + <legend>Photo Storage</legend> + <?php if (!installer::var_writable()): ?> + <p> + We're having trouble creating a place for your photos. Can you + help? We need you to create a directory called <em>var</em> in + your gallery3 directory. This sample code works for most users. + Run it in the gallery3 directory: + <code> + mkdir var<br> + chmod 777 var + </code> + <a href="index.php">Check again</a> + </p> + <?php else: ?> + <p> + We've found a place to store your photos: + <code class="location"> <?= htmlspecialchars(VARPATH, ENT_QUOTES, 'UTF-8', true) ?> </code> + </p> + <?php endif ?> +</fieldset> + +<?php if (installer::var_writable()): ?> +<form method="post" action="index.php?step=save_db_info"> + <fieldset> + <legend>Database</legend> + <p> + Gallery 3 needs a MySQL database. The values provided work for + most setups, so if you're confused try clicking <i>continue</i>. + </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> + Table prefix <span class="subtext">(optional)</span> + </td> + <td> + <input name="prefix" value=""/> + </td> + </tr> + <tr> + <td colspan="2"> + <input type="submit" value="Continue"/> + </td> + </tr> + </table> + </fieldset> +</form> +<?php endif ?> diff --git a/installer/views/install.html.php b/installer/views/install.html.php new file mode 100644 index 0000000..7a30561 --- /dev/null +++ b/installer/views/install.html.php @@ -0,0 +1,24 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<html> + <head> + <title>Gallery 3 Installer</title> + <link rel="stylesheet" type="text/css" href="install.css"/> + </head> + <body> + <div id="outer"> + <img src="../modules/gallery/images/gallery.png" /> + <div id="inner"> + <?php print $content ?> + </div> + <div id="footer"> + <p> + <i>Did something go wrong? Try + the <a href="http://codex.galleryproject.org/Gallery3:FAQ">FAQ</a> + or ask in + the <a href="http://galleryproject.org/forum">Gallery + forums</a>.</i> + </p> + </div> + </div> + </body> +</html> diff --git a/installer/views/invalid_db_info.html.php b/installer/views/invalid_db_info.html.php new file mode 100644 index 0000000..242a28a --- /dev/null +++ b/installer/views/invalid_db_info.html.php @@ -0,0 +1,6 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Uh oh! </h1> +<p class="error"> + We were unable to connect to your MySQL server with the username and + password that you provided. Please go back and try again! +</p> diff --git a/installer/views/invalid_db_version.html.php b/installer/views/invalid_db_version.html.php new file mode 100644 index 0000000..5b021ba --- /dev/null +++ b/installer/views/invalid_db_version.html.php @@ -0,0 +1,5 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Uh oh! </h1> +<p class="error"> + Gallery requires at least MySQL version 5.0.0. You're using version <?= installer::mysql_version($config) ?> +</p> diff --git a/installer/views/missing_db.html.php b/installer/views/missing_db.html.php new file mode 100644 index 0000000..fa42fde --- /dev/null +++ b/installer/views/missing_db.html.php @@ -0,0 +1,13 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Can't find that database! </h1> +<p class="error"> + We were able to connect to your MySQL server, yay! But the database + name you gave us doesn't exist and we don't have permissions to + create it for you. Please create the database manually, then go + back and try again. +</p> + +<p> + If you're having trouble creating the database, please contact your + web host or system administrator for assistance. +</p> diff --git a/installer/views/oops.html.php b/installer/views/oops.html.php new file mode 100644 index 0000000..9c6b165 --- /dev/null +++ b/installer/views/oops.html.php @@ -0,0 +1,10 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<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/views/success.html.php b/installer/views/success.html.php new file mode 100644 index 0000000..e9ee981 --- /dev/null +++ b/installer/views/success.html.php @@ -0,0 +1,23 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h1> Success! </h1> +<p class="success"> + Your Gallery 3 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 0000000..5fa8541 --- /dev/null +++ b/installer/web.php @@ -0,0 +1,94 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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("success.html.php"); +} else { + switch (@$_GET["step"]) { + default: + case "welcome": + $errors = installer::check_environment(); + if ($errors) { + $content = render("environment_errors.html.php", array("errors" => $errors)); + } else { + $content = render("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" => $_POST["prefix"], + "type" => function_exists("mysqli_set_charset") ? "mysqli" : "mysql"); + list ($config["host"], $config["port"]) = explode(":", $config["host"] . ":"); + foreach ($config as $k => $v) { + if ($k == "password") { + $config[$k] = str_replace(array("'", "\\"), array("\\'", "\\\\"), $v); + } else { + $config[$k] = strtr($v, "'`\\", "___"); + } + } + + if (!installer::connect($config)) { + $content = render("invalid_db_info.html.php"); + } else if (!installer::verify_mysql_version($config)) { + $content = render("invalid_db_version.html.php"); + } else if (!installer::select_db($config)) { + $content = render("missing_db.html.php"); + } else if (is_string($count = installer::db_empty($config)) || !$count) { + if (is_string($count)) { + $content = oops($count); + } else { + $content = render("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($config)) { + $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 { + try { + list ($user, $password) = installer::create_admin($config); + installer::create_admin_session($config); + $content = render("success.html.php", array("user" => $user, "password" => $password)); + + installer::create_private_key($config); + } catch (Exception $e) { + $content = oops($e->getMessage()); + } + } + break; + } +} + +include("views/install.html.php"); + +function render($view, $args=array()) { + ob_start(); + extract($args); + include(DOCROOT . "installer/views/" . $view); + return ob_get_clean(); +} + +function oops($error) { + return render("oops.html.php", array("error" => $error)); +} |
