From d0c6dd29d19da4de9966cd9985d467fe1cfab556 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 26 Mar 2013 22:38:05 +0400 Subject: [PATCH] add experimental easy installer --- include/db.php | 2 +- include/sanity_check.php | 4 + index.php | 4 + install/index.php | 352 +++++++++++++++++++++++++++++++++++++++ prefs.php | 10 ++ utility.css | 9 +- 6 files changed, 374 insertions(+), 7 deletions(-) create mode 100644 install/index.php diff --git a/include/db.php b/include/db.php index 0479df6a..a70a1d87 100644 --- a/include/db.php +++ b/include/db.php @@ -15,7 +15,7 @@ function db_connect($host, $user, $pass, $db) { $string .= " host=$host"; } - if (defined('DB_PORT')) { + if (defined('DB_PORT') && DB_PORT) { $string = "$string port=" . DB_PORT; } diff --git a/include/sanity_check.php b/include/sanity_check.php index 0373196b..f428550f 100644 --- a/include/sanity_check.php +++ b/include/sanity_check.php @@ -12,6 +12,10 @@ require_once "sanity_config.php"; + if (file_exists("install") && !file_exists("config.php")) { + array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); + } + if (strpos(PLUGINS, "auth_") === FALSE) { array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); } diff --git a/index.php b/index.php index c6698793..757be908 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,8 @@ Fatal Error: You forgot to copy config.php-dist to config.php and edit it.\n"; diff --git a/install/index.php b/install/index.php new file mode 100644 index 00000000..21dd0d8c --- /dev/null +++ b/install/index.php @@ -0,0 +1,352 @@ + + + Tiny Tiny RSS - Installer + + + + + + + $msg"; + } + + function print_notice($msg) { + print "
+ $msg
"; + } + + function db_connect($host, $user, $pass, $db, $type) { + if ($type == "pgsql") { + + $string = "dbname=$db user=$user"; + + if ($pass) { + $string .= " password=$pass"; + } + + if ($host) { + $string .= " host=$host"; + } + + if (defined('DB_PORT')) { + $string = "$string port=" . DB_PORT; + } + + $link = pg_connect($string); + + return $link; + + } else if ($type == "mysql") { + $link = mysql_connect($host, $user, $pass); + if ($link) { + $result = mysql_select_db($db, $link); + return $link; + } + } + } + + function db_query($link, $query, $type, $die_on_error = true) { + if ($type == "pgsql") { + $result = pg_query($link, $query); + if (!$result) { + $query = htmlspecialchars($query); // just in case + if ($die_on_error) { + die("Query $query failed [$result]: " . ($link ? pg_last_error($link) : "No connection")); + } + } + return $result; + } else if ($type == "mysql") { + $result = mysql_query($query, $link); + if (!$result) { + $query = htmlspecialchars($query); + if ($die_on_error) { + die("Query $query failed: " . ($link ? mysql_error($link) : "No connection")); + } + } + return $result; + } + } + +?> + + + +

Tiny Tiny RSS Installer

+ + + +

Database settings

+ +
+ + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +

+ +
+ + + +

Checking configuration

+ + 0) { + print "

Some configuration tests failed. Please correct them before continuing.

"; + + print ""; + + exit; + } + + ?> + +

Checking database

+ + + +

Initialize database

+ +

Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.

+ + + +
+
+ + + + + + + + + + +

+ +

+ +
+ +
+
+ + + + + + + + +

+
+ +
+ + Initializing database..."; + + $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); + + foreach ($lines as $line) { + if (strpos($line, "--") !== 0 && $line) { + db_query($link, $line, $DB_TYPE); + } + } + + print_notice("Database initialization completed."); + + } else { + print_notice("Database initialization skipped."); + } + + print "

Generated configuration file

"; + + print "

Copy following text and save as config.php in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.

"; + + print ""; + + print "

You can generate the file again by changing the form above.

"; + } + ?> + + + + diff --git a/prefs.php b/prefs.php index 32496875..5b4ac176 100644 --- a/prefs.php +++ b/prefs.php @@ -1,7 +1,17 @@ Fatal Error: You forgot to copy + config.php-dist to config.php and edit it.\n"; + exit; + } + require_once "sessions.php"; require_once "functions.php"; require_once "sanity_check.php"; diff --git a/utility.css b/utility.css index b520a49b..27054dfe 100644 --- a/utility.css +++ b/utility.css @@ -70,17 +70,14 @@ div.error { h1 { color : #88b0f0; font-size : 16pt; -/* border-width : 0px 0px 1px 0px; - border-color : black; - border-style : solid; */ } h2 { color : #88b0f0; font-size : 14pt; -/* border-width : 0px 0px 1px 0px; - border-color : black; - border-style : solid; */ + border-width : 0px 0px 1px 0px; + border-color : #f0f0f0; + border-style : solid; } div.rss h1 { -- 2.39.5