3 <title
>Tiny Tiny RSS
- Installer
</title
>
4 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
5 <link rel
="stylesheet" type
="text/css" href
="../css/default.css">
6 <style type
="text/css">
7 textarea
{ font
-size
: 12px
; }
10 <body
class="claro ttrss_utility">
14 // could be needed because of existing config.php
15 function define_default($param, $value) {
19 function make_password($length = 8) {
22 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
26 while ($i < $length) {
27 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
29 if (!strstr($password, $char)) {
38 function sanity_check($db_type) {
41 if (version_compare(PHP_VERSION
, '5.4.0', '<')) {
42 array_push($errors, "PHP version 5.4.0 or newer required.");
45 if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
46 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.");
49 if (!function_exists("json_encode")) {
50 array_push($errors, "PHP support for JSON is required, but was not found.");
53 if ($db_type == "mysql" && !function_exists("mysqli_connect")) {
54 array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php.");
57 if ($db_type == "pgsql" && !function_exists("pg_connect")) {
58 array_push($errors, "PHP support for PostgreSQL is required for configured $db_type in config.php");
61 if (!function_exists("mb_strlen")) {
62 array_push($errors, "PHP support for mbstring functions is required but was not found.");
65 if (!function_exists("hash")) {
66 array_push($errors, "PHP support for hash() function is required but was not found.");
69 if (!function_exists("iconv")) {
70 array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
73 if (ini_get("safe_mode")) {
74 array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
77 if (!class_exists("DOMDocument")) {
78 array_push($errors, "PHP support for DOMDocument is required, but was not found.");
84 function print_error($msg) {
85 print "<div class='alert alert-error'>$msg</div>";
88 function print_notice($msg) {
89 print "<div class=\"alert alert-info\">$msg</div>";
92 function db_connect($host, $user, $pass, $db, $type, $port = false) {
93 if ($type == "pgsql") {
95 $string = "dbname=$db user=$user";
98 $string .= " password=$pass";
102 $string .= " host=$host";
106 $string = "$string port=" . $port;
109 $link = pg_connect($string);
113 } else if ($type == "mysql") {
115 return mysqli_connect($host, $user, $pass, $db, $port);
117 return mysqli_connect($host, $user, $pass, $db);
121 function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
122 $DB_PORT, $SELF_URL_PATH) {
124 $data = explode("\n", file_get_contents("../config.php-dist"));
130 foreach ($data as $line) {
131 if (preg_match("/define\('DB_TYPE'/", $line)) {
132 $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
133 } else if (preg_match("/define\('DB_HOST'/", $line)) {
134 $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
135 } else if (preg_match("/define\('DB_USER'/", $line)) {
136 $rv .= "\tdefine('DB_USER', '$DB_USER');\n";
137 } else if (preg_match("/define\('DB_NAME'/", $line)) {
138 $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
139 } else if (preg_match("/define\('DB_PASS'/", $line)) {
140 $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
141 } else if (preg_match("/define\('DB_PORT'/", $line)) {
142 $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
143 } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
144 $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
145 } else if (!$finished) {
149 if (preg_match("/\?\>/", $line)) {
157 function db_query($link, $query, $type, $die_on_error = true) {
158 if ($type == "pgsql") {
159 $result = pg_query($link, $query);
161 $query = htmlspecialchars($query); // just in case
163 die("Query <i>$query</i> failed [$result]: " . ($link ?
pg_last_error($link) : "No connection"));
167 } else if ($type == "mysql") {
169 $result = mysqli_query($link, $query);
172 $query = htmlspecialchars($query);
174 die("Query <i>$query</i> failed: " . ($link ?
mysqli_error($link) : "No connection"));
181 function is_server_https() {
182 return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) ||
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
185 function make_self_url_path() {
186 $url_path = (is_server_https() ?
'https://' : 'http://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH
);
193 <div
class="floatingLogo"><img src
="../images/logo_small.png"></div
>
195 <h1
>Tiny Tiny RSS Installer
</h1
>
197 <div
class='content'>
201 if (file_exists("../config.php")) {
202 require "../config.php";
204 if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
205 print_error("Error: config.php already exists in tt-rss directory; aborting.");
210 @$op = $_REQUEST['op'];
212 @$DB_HOST = strip_tags($_POST['DB_HOST']);
213 @$DB_TYPE = strip_tags($_POST['DB_TYPE']);
214 @$DB_USER = strip_tags($_POST['DB_USER']);
215 @$DB_NAME = strip_tags($_POST['DB_NAME']);
216 @$DB_PASS = strip_tags($_POST['DB_PASS']);
217 @$DB_PORT = strip_tags($_POST['DB_PORT']);
218 @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
220 if (!$SELF_URL_PATH) {
221 $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
225 <form action
="" method
="post">
226 <input type
="hidden" name
="op" value
="testconfig">
228 <h2
>Database settings
</h2
>
231 $issel_pgsql = $DB_TYPE == "pgsql" ?
"selected" : "";
232 $issel_mysql = $DB_TYPE == "mysql" ?
"selected" : "";
236 <label
>Database type
</label
>
237 <select name
="DB_TYPE">
238 <option
<?php
echo $issel_pgsql ?
> value
="pgsql">PostgreSQL
</option
>
239 <option
<?php
echo $issel_mysql ?
> value
="mysql">MySQL
</option
>
244 <label
>Username
</label
>
245 <input
class="input input-text" required name
="DB_USER" size
="20" value
="<?php echo $DB_USER ?>"/>
249 <label
>Password
</label
>
250 <input
class="input input-text" name
="DB_PASS" size
="20" type
="password" value
="<?php echo $DB_PASS ?>"/>
254 <label
>Database name
</label
>
255 <input
class="input input-text" required name
="DB_NAME" size
="20" value
="<?php echo $DB_NAME ?>"/>
259 <label
>Host name
</label
>
260 <input
class="input input-text" name
="DB_HOST" size
="20" value
="<?php echo $DB_HOST ?>"/>
261 <span
class="hint">If needed
</span
>
266 <input
class="input input-text" name
="DB_PORT" type
="number" size
="20" value
="<?php echo $DB_PORT ?>"/>
267 <span
class="hint">Usually
3306 for MySQL
or 5432 for PostgreSQL
</span
>
270 <h2
>Other settings
</h2
>
272 <p
>This should be set to the location your Tiny Tiny RSS will be available on
.</p
>
275 <label
>Tiny Tiny RSS URL
</label
>
276 <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 ?>"/>
280 <p
><input type
="submit" value
="Test configuration"></p
>
284 <?php
if ($op == 'testconfig') { ?
>
286 <h2
>Checking configuration
</h2
>
289 $errors = sanity_check($DB_TYPE);
291 if (count($errors) > 0) {
292 print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
296 foreach ($errors as $error) {
297 print "<li style='color : red'>$error</li>";
307 if (!function_exists("curl_init")) {
308 array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
311 if (function_exists("curl_init") && ini_get("open_basedir")) {
312 array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
315 if (!function_exists("idn_to_ascii")) {
316 array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
319 if (count($notices) > 0) {
320 print_notice("Configuration check succeeded with minor problems:");
324 foreach ($notices as $notice) {
325 print "<li>$notice</li>";
330 print_notice("Configuration check succeeded.");
335 <h2
>Checking database
</h2
>
338 $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
341 print_error("Unable to connect to database using specified parameters.");
345 print_notice("Database test succeeded."); ?
>
347 <h2
>Initialize database
</h2
>
349 <p
>Before you can start using tt
-rss
, database needs to be initialized
. Click on the button below to
do that now
.</p
>
352 $result = @db_query
($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
355 print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization.");
356 $need_confirm = true;
358 $need_confirm = false;
364 <input type
="hidden" name
="op" value
="installschema">
366 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
367 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
368 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
369 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
370 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
371 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
372 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
374 <?php
if ($need_confirm) { ?
>
375 <p
><input onclick
="return confirm('Please read the warning above. Continue?')" type
="submit" value
="Initialize database" style
="color : red"></p
>
377 <p
><input type
="submit" value
="Initialize database" style
="color : red"></p
>
383 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
384 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
385 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
386 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
387 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
388 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
389 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
391 <input type
="hidden" name
="op" value
="skipschema">
392 <p
><input type
="submit" value
="Skip initialization"></p
>
399 } else if ($op == 'installschema' ||
$op == 'skipschema') {
401 $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
404 print_error("Unable to connect to database using specified parameters.");
408 if ($op == 'installschema') {
410 print "<h2>Initializing database...</h2>";
412 $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql")));
414 foreach ($lines as $line) {
415 if (strpos($line, "--") !== 0 && $line) {
416 db_query($link, $line, $DB_TYPE);
420 print_notice("Database initialization completed.");
423 print_notice("Database initialization skipped.");
426 print "<h2>Generated configuration file</h2>";
428 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>";
430 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>"; ?
>
432 <form action
="" method
="post">
433 <input type
="hidden" name
="op" value
="saveconfig">
434 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
435 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
436 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
437 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
438 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
439 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
440 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
441 <?php
print "<textarea cols=\"80\" rows=\"20\">";
442 echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
443 $DB_PORT, $SELF_URL_PATH);
444 print "</textarea>"; ?
>
446 <?php
if (is_writable("..")) { ?
>
447 <p
>We can also
try saving the file automatically now
.</p
>
449 <p
><input type
="submit" value
="Save configuration"></p
>
452 print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
455 print_notice("You can generate the file again by changing the form above.");
457 } else if ($op == "saveconfig") {
459 print "<h2>Saving configuration file to parent directory...</h2>";
461 if (!file_exists("../config.php")) {
463 $fp = fopen("../config.php", "w");
466 $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
467 $DB_USER, $DB_NAME, $DB_PASS,
468 $DB_PORT, $SELF_URL_PATH));
471 print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
474 print_notice("Unable to write into config.php in tt-rss directory.");
479 print_error("Unable to open config.php in tt-rss directory for writing.");
482 print_error("config.php already present in tt-rss directory, refusing to overwrite.");