X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=install%2Findex.php;h=764283ab8dfdf8f019d8d07544d3ea39e43ad604;hb=e52034b4bcce994312ce2af31be0a46a70172691;hp=b0696ca6d155cdbd161b5f4ff8027b8e8ad419bb;hpb=884d16505e2c4502ec4438a7e987855683a2d75d;p=tt-rss.git diff --git a/install/index.php b/install/index.php old mode 100644 new mode 100755 index b0696ca6..764283ab --- a/install/index.php +++ b/install/index.php @@ -2,23 +2,44 @@ Tiny Tiny RSS - Installer - + - + - $msg"; + print "
$msg
"; } function print_notice($msg) { - print "
- $msg
"; + print "
$msg
"; } - function db_connect($host, $user, $pass, $db, $type) { - if ($type == "pgsql") { + function pdo_connect($host, $user, $pass, $db, $type, $port = false) { - $string = "dbname=$db user=$user"; + $db_port = $port ? ';port=' . $port : ''; + $db_host = $host ? ';host=' . $host : ''; - if ($pass) { - $string .= " password=$pass"; - } + try { + $pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port, + $user, + $pass); - if ($host) { - $string .= " host=$host"; - } + return $pdo; + } catch (Exception $e) { + print "
" . $e->getMessage() . "
"; + return null; + } + } - if (defined('DB_PORT')) { - $string = "$string port=" . DB_PORT; + function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, + $DB_PORT, $SELF_URL_PATH) { + + $data = explode("\n", file_get_contents("../config.php-dist")); + + $rv = ""; + + $finished = false; + + foreach ($data as $line) { + if (preg_match("/define\('DB_TYPE'/", $line)) { + $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n"; + } else if (preg_match("/define\('DB_HOST'/", $line)) { + $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n"; + } else if (preg_match("/define\('DB_USER'/", $line)) { + $rv .= "\tdefine('DB_USER', '$DB_USER');\n"; + } else if (preg_match("/define\('DB_NAME'/", $line)) { + $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n"; + } else if (preg_match("/define\('DB_PASS'/", $line)) { + $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n"; + } else if (preg_match("/define\('DB_PORT'/", $line)) { + $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n"; + } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) { + $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n"; + } else if (!$finished) { + $rv .= "$line\n"; } - $link = pg_connect($string); - - return $link; - - } else if ($type == "mysql") { - $link = mysql_connect($host, $user, $pass); - if ($link) { - $result = mysql_select_db($db, $link); - if ($result) return $link; + if (preg_match("/\?\>/", $line)) { + $finished = true; } } + + return $rv; } - 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; - } + function is_server_https() { + return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'); + } + + function make_self_url_path() { + $url_path = (is_server_https() ? 'https://' : 'http://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); + + return $url_path; } ?> @@ -138,11 +157,12 @@
-

Database settings

-
+

Database settings

+ - +
- +
- +
- + + If needed
- + + Usually 3306 for MySQL or 5432 for PostgreSQL +
+ +

Other settings

+ +

This should be set to the location your Tiny Tiny RSS will be available on.

+ +
+ +
+

@@ -226,16 +262,50 @@ exit; } - ?> + $notices = array(); + + if (!function_exists("curl_init")) { + array_push($notices, "It is highly recommended to enable support for CURL in PHP."); + } + + if (function_exists("curl_init") && ini_get("open_basedir")) { + array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information."); + } + + if (!function_exists("idn_to_ascii")) { + array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names."); + } + + if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { + array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working."); + } - + if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) { + array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working."); + } + + if (count($notices) > 0) { + print_notice("Configuration check succeeded with minor problems:"); + + print ""; + } else { + print_notice("Configuration check succeeded."); + } + + ?>

Checking database

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

query("SELECT true FROM ttrss_feeds"); - if ($result) { - print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization."); + if ($res && $res->fetch()) { + print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data will be lost."); $need_confirm = true; } else { $need_confirm = false; @@ -267,6 +337,7 @@ +

@@ -283,6 +354,7 @@ +

@@ -294,9 +366,9 @@ } else if ($op == 'installschema' || $op == 'skipschema') { - $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE); + $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT); - if (!$link) { + if (!$pdo) { print_error("Unable to connect to database using specified parameters."); exit; } @@ -305,11 +377,17 @@ print "

Initializing database...

"; - $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); + $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); + $res = $pdo->query($line); + + if (!$res) { + print_notice("Query: $line"); + print_error("Error: " . implode(", ", $this->pdo->errorInfo())); + } } } @@ -321,33 +399,62 @@ 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 ""; ?> + + +

We can also try saving the file automatically now.

+ +

+ + "; + print_notice("You can generate the file again by changing the form above."); + + } else if ($op == "saveconfig") { + + print "

Saving configuration file to parent directory...

"; - print "

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

"; + if (!file_exists("../config.php")) { + + $fp = fopen("../config.php", "w"); + + if ($fp) { + $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST, + $DB_USER, $DB_NAME, $DB_PASS, + $DB_PORT, $SELF_URL_PATH)); + + if ($written > 0) { + print_notice("Successfully saved config.php. You can try loading tt-rss now."); + + } else { + print_notice("Unable to write into config.php in tt-rss directory."); + } + + fclose($fp); + } else { + print_error("Unable to open config.php in tt-rss directory for writing."); + } + } else { + print_error("config.php already present in tt-rss directory, refusing to overwrite."); + } } ?>