<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/utility.css">
+ <link rel="stylesheet" type="text/css" href="../css/dijit.css">
<style type="text/css">
textarea { font-size : 12px; }
</style>
</head>
<body>
-<?
+<?php
+
+ // could be needed because of existing config.php
+ function define_default($param, $value) {
+ //
+ }
+
+ function make_password($length = 8) {
+
+ $password = "";
+ $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
+
+ $i = 0;
+
+ 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();
array_push($errors, "PHP version 5.3.0 or newer required.");
}
- 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 (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
}
array_push($errors, "PHP support for JSON is required, but was not found.");
}
- if ($db_type == "mysql" && !function_exists("mysql_connect")) {
+ if ($db_type == "mysql" && !function_exists("mysql_connect") && !function_exists("mysqli_connect")) {
array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php.");
}
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 (!class_exists("DOMDocument")) {
array_push($errors, "PHP support for DOMDocument is required, but was not found.");
}
}
function print_error($msg) {
- print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>";
+ print "<div class='error'><span><img src='../images/alert.png'></span>
+ <span>$msg</span></div>";
}
function print_notice($msg) {
print "<div class=\"notice\">
- <img src=\"../images/sign_info.svg\">$msg</div>";
+ <span><img src=\"../images/information.png\"></span><span>$msg</span></div>";
}
- function db_connect($host, $user, $pass, $db, $type) {
+ function db_connect($host, $user, $pass, $db, $type, $port = false) {
if ($type == "pgsql") {
$string = "dbname=$db user=$user";
$string .= " host=$host";
}
- if (defined('DB_PORT')) {
- $string = "$string port=" . DB_PORT;
+ if ($port) {
+ $string = "$string port=" . $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;
+ if (function_exists("mysqli_connect")) {
+ if ($port)
+ return mysqli_connect($host, $user, $pass, $db, $port);
+ else
+ return mysqli_connect($host, $user, $pass, $db);
+
+ } else {
+ $link = mysql_connect($host, $user, $pass);
+ if ($link) {
+ $result = mysql_select_db($db, $link);
+ if ($result) return $link;
+ }
+ }
+ }
+ }
+
+ 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;
+
+ if (function_exists("mcrypt_decrypt")) {
+ $crypt_key = make_password(24);
+ } else {
+ $crypt_key = "";
+ }
+
+ 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 (preg_match("/define\('FEED_CRYPT_KEY'/", $line)) {
+ $rv .= "\tdefine('FEED_CRYPT_KEY', '$crypt_key');\n";
+ } else if (!$finished) {
+ $rv .= "$line\n";
+ }
+
+ if (preg_match("/\?\>/", $line)) {
+ $finished = true;
}
}
+
+ return $rv;
}
function db_query($link, $query, $type, $die_on_error = true) {
}
return $result;
} else if ($type == "mysql") {
- $result = mysql_query($query, $link);
+
+ if (function_exists("mysqli_connect")) {
+ $result = mysqli_query($link, $query);
+ } else {
+ $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"));
+ die("Query <i>$query</i> failed: " . ($link ? function_exists("mysqli_connect") ? mysqli_error($link) : mysql_error($link) : "No connection"));
}
}
return $result;
}
}
+ function make_self_url_path() {
+ $url_path = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+
+ return $url_path;
+ }
+
?>
-<div class="floatingLogo"><img src="../images/logo_wide.png"></div>
+<div class="floatingLogo"><img src="../images/logo_small.png"></div>
<h1>Tiny Tiny RSS Installer</h1>
+<div class='content'>
+
<?php
+
if (file_exists("../config.php")) {
require "../config.php";
if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
- print_error("Error: config.php already exists; aborting.");
+ print_error("Error: config.php already exists in tt-rss directory; aborting.");
exit;
}
}
@$DB_NAME = strip_tags($_POST['DB_NAME']);
@$DB_PASS = strip_tags($_POST['DB_PASS']);
@$DB_PORT = strip_tags($_POST['DB_PORT']);
+ @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
+ if (!$SELF_URL_PATH) {
+ $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
+ }
?>
-<h2>Database settings</h2>
-
<form action="" method="post">
<input type="hidden" name="op" value="testconfig">
+<h2>Database settings</h2>
+
<?php
$issel_pgsql = $DB_TYPE == "pgsql" ? "selected" : "";
$issel_mysql = $DB_TYPE == "mysql" ? "selected" : "";
<fieldset>
<label>Database name</label>
- <input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
+ <input 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 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" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/>
+ <input 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>
+
+<p>This should be set to the location your Tiny Tiny RSS will be available on.</p>
+
+<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 ?>"/>
+</fieldset>
+
+
<p><input type="submit" value="Test configuration"></p>
</form>
exit;
}
+ $notices = array();
+
+ if (!function_exists("curl_init")) {
+ array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
+ }
+
+ 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);
+ $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
if (!$link) {
print_error("Unable to connect to database using specified parameters.");
<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);
+ $result = @db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
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.");
<input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/>
<input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/>
<input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/>
+ <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/>
<?php if ($need_confirm) { ?>
<p><input onclick="return confirm('Please read the warning above. Continue?')" type="submit" value="Initialize database" style="color : red"></p>
<input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/>
<input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/>
<input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/>
+ <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/>
<input type="hidden" name="op" value="skipschema">
<p><input type="submit" value="Skip initialization"></p>
} else if ($op == 'installschema' || $op == 'skipschema') {
- $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
+ $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
if (!$link) {
print_error("Unable to connect to database using specified parameters.");
print "<h2>Generated configuration file</h2>";
- print "<p>Copy following text and save as <b>config.php</b> 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.</p>";
-
- print "<textarea cols=\"80\" rows=\"20\" name=\"config\">";
- $data = explode("\n", file_get_contents("../config.php-dist"));
-
- foreach ($data as $line) {
- if (preg_match("/define\('DB_TYPE'/", $line)) {
- echo "\tdefine('DB_TYPE', '$DB_TYPE')\n";
- } else if (preg_match("/define\('DB_HOST'/", $line)) {
- echo "\tdefine('DB_HOST', '$DB_HOST')\n";
- } else if (preg_match("/define\('DB_USER'/", $line)) {
- echo "\tdefine('DB_USER', '$DB_USER')\n";
- } else if (preg_match("/define\('DB_NAME'/", $line)) {
- echo "\tdefine('DB_NAME', '$DB_NAME')\n";
- } else if (preg_match("/define\('DB_PASS'/", $line)) {
- echo "\tdefine('DB_PASS', '$DB_PASS')\n";
- } else if (preg_match("/define\('DB_PORT'/", $line)) {
- echo "\tdefine('DB_PORT', '$DB_PORT')\n";
+ print "<p>Copy following text and save as <code>config.php</code> 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.</p>";
- } else {
- print "$line\n";
- }
+ print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?>
+
+ <form action="" method="post">
+ <input type="hidden" name="op" value="saveconfig">
+ <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/>
+ <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/>
+ <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/>
+ <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/>
+ <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/>
+ <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/>
+ <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/>
+ <?php print "<textarea cols=\"80\" rows=\"20\">";
+ echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
+ $DB_PORT, $SELF_URL_PATH);
+ print "</textarea>"; ?>
+
+ <?php if (is_writable("..")) { ?>
+ <p>We can also try saving the file automatically now.</p>
+
+ <p><input type="submit" value="Save configuration"></p>
+ </form>
+ <?php } else {
+ print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
}
- print "</textarea>";
+ print_notice("You can generate the file again by changing the form above.");
+
+ } else if ($op == "saveconfig") {
+
+ print "<h2>Saving configuration file to parent directory...</h2>";
- print "<p>You can generate the file again by changing the form above.</p>";
+ 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 <a href=\"..\">loading tt-rss now</a>.");
+
+ } 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.");
+ }
}
?>
+</div>
</body>
</html>