<head>
<title>Tiny Tiny RSS - Installer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link rel="stylesheet" type="text/css" href="../utility.css">
+ <link rel="stylesheet" type="text/css" href="../css/default.css">
<style type="text/css">
textarea { font-size : 12px; }
</style>
</head>
-<body>
+<body class="claro ttrss_utility">
-<?
- function sanity_check($db_type) {
- $errors = array();
+<?php
+
+ // could be needed because of existing config.php
+ function define_default($param, $value) {
+ //
+ }
+
+ function make_password($length = 8) {
+
+ $password = "";
+ $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
+
+ $i = 0;
- if (version_compare(PHP_VERSION, '5.3.0', '<')) {
- array_push($errors, "PHP version 5.3.0 or newer required.");
+ while ($i < $length) {
+ $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
+
+ if (!strstr($password, $char)) {
+ $password .= $char;
+ $i++;
+ }
}
+ return $password;
+ }
+
+
+ function sanity_check($db_type) {
+ $errors = array();
- if (ini_get("open_basedir")) {
- array_push($errors, "PHP configuration option open_basedir is not supported. Please disable this in PHP settings file (php.ini).");
+ if (version_compare(PHP_VERSION, '5.6.0', '<')) {
+ array_push($errors, "PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . ".");
}
if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
array_push($errors, "PHP support for JSON is required, but was not found.");
}
- if ($db_type == "mysql" && !function_exists("mysql_connect")) {
- array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php.");
- }
-
- if ($db_type == "pgsql" && !function_exists("pg_connect")) {
- array_push($errors, "PHP support for PostgreSQL is required for configured $db_type in config.php");
+ if (!class_exists("PDO")) {
+ array_push($errors, "PHP support for PDO is required but was not found.");
}
if (!function_exists("mb_strlen")) {
array_push($errors, "PHP support for hash() function is required but was not found.");
}
- if (!function_exists("ctype_lower")) {
- array_push($errors, "PHP support for ctype functions are required by HTMLPurifier.");
- }
-
if (!function_exists("iconv")) {
array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
}
- /* if (ini_get("safe_mode")) {
- array_push($errors, "PHP safe mode setting is not supported.");
- } */
-
- if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED) && !function_exists("curl_init")) {
- array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
+ if (ini_get("safe_mode")) {
+ array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
}
if (!class_exists("DOMDocument")) {
}
function print_error($msg) {
- print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>";
+ print "<div class='alert alert-error'>$msg</div>";
}
function print_notice($msg) {
- print "<div class=\"notice\">
- <img src=\"../images/sign_info.svg\">$msg</div>";
+ print "<div class=\"alert alert-info\">$msg</div>";
}
- 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";
- }
+ function pdo_connect($host, $user, $pass, $db, $type, $port = false) {
- if (defined('DB_PORT')) {
- $string = "$string port=" . DB_PORT;
- }
+ $db_port = $port ? ';port=' . $port : '';
+ $db_host = $host ? ';host=' . $host : '';
- $link = pg_connect($string);
+ try {
+ $pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port,
+ $user,
+ $pass);
- return $link;
-
- } else if ($type == "mysql") {
- $link = mysql_connect($host, $user, $pass);
- if ($link) {
- $result = mysql_select_db($db, $link);
- if ($result) return $link;
- }
- }
+ return $pdo;
+ } catch (Exception $e) {
+ print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>";
+ return null;
+ }
}
function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
$rv = "";
+ $finished = false;
+
foreach ($data as $line) {
if (preg_match("/define\('DB_TYPE'/", $line)) {
$rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
$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 {
+ } else if (!$finished) {
$rv .= "$line\n";
}
+
+ 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 <i>$query</i> 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 <i>$query</i> 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 = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+ $url_path = (is_server_https() ? 'https://' : 'http://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
return $url_path;
}
<fieldset>
<label>Username</label>
- <input required name="DB_USER" size="20" value="<?php echo $DB_USER ?>"/>
+ <input class="input input-text" required name="DB_USER" size="20" value="<?php echo $DB_USER ?>"/>
</fieldset>
<fieldset>
<label>Password</label>
- <input required name="DB_PASS" size="20" type="password" value="<?php echo $DB_PASS ?>"/>
+ <input class="input input-text" name="DB_PASS" size="20" type="password" value="<?php echo $DB_PASS ?>"/>
</fieldset>
<fieldset>
<label>Database name</label>
- <input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
+ <input class="input input-text" required name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
</fieldset>
<fieldset>
<label>Host name</label>
- <input name="DB_HOST" placeholder="if needed" size="20" value="<?php echo $DB_HOST ?>"/>
+ <input class="input input-text" name="DB_HOST" size="20" value="<?php echo $DB_HOST ?>"/>
+ <span class="hint">If needed</span>
</fieldset>
<fieldset>
<label>Port</label>
- <input name="DB_PORT" type="number" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/>
+ <input class="input input-text" name="DB_PORT" type="number" size="20" value="<?php echo $DB_PORT ?>"/>
+ <span class="hint">Usually 3306 for MySQL or 5432 for PostgreSQL</span>
</fieldset>
<h2>Other settings</h2>
<fieldset>
<label>Tiny Tiny RSS URL</label>
- <input type="url" name="SELF_URL_PATH" placeholder="<?php echo $SELF_URL_PATH; ?>" size="60" value="<?php echo $SELF_URL_PATH ?>"/>
+ <input class="input input-text" type="url" name="SELF_URL_PATH" placeholder="<?php echo $SELF_URL_PATH; ?>" size="60" value="<?php echo $SELF_URL_PATH ?>"/>
</fieldset>
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.");
+ }
- <?php print_notice("Configuration check succeeded."); ?>
+ 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 "<ul>";
+
+ foreach ($notices as $notice) {
+ print "<li>$notice</li>";
+ }
+
+ print "</ul>";
+ } else {
+ print_notice("Configuration check succeeded.");
+ }
+
+ ?>
<h2>Checking database</h2>
<?php
- $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;
}
<p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p>
<?php
- $result = db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
+ $res = $pdo->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;
} 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;
}
print "<h2>Initializing database...</h2>";
- $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()));
+ }
}
}