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
="../utility.css">
6 <style type
="text/css">
7 textarea
{ font
-size
: 12px
; }
13 function sanity_check($db_type) {
16 if (version_compare(PHP_VERSION
, '5.3.0', '<')) {
17 array_push($errors, "PHP version 5.3.0 or newer required.");
20 if (ini_get("open_basedir")) {
21 array_push($errors, "PHP configuration option open_basedir is not supported. Please disable this in PHP settings file (php.ini).");
24 if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
25 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.");
28 if (!function_exists("json_encode")) {
29 array_push($errors, "PHP support for JSON is required, but was not found.");
32 if ($db_type == "mysql" && !function_exists("mysql_connect")) {
33 array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php.");
36 if ($db_type == "pgsql" && !function_exists("pg_connect")) {
37 array_push($errors, "PHP support for PostgreSQL is required for configured $db_type in config.php");
40 if (!function_exists("mb_strlen")) {
41 array_push($errors, "PHP support for mbstring functions is required but was not found.");
44 if (!function_exists("hash")) {
45 array_push($errors, "PHP support for hash() function is required but was not found.");
48 if (!function_exists("ctype_lower")) {
49 array_push($errors, "PHP support for ctype functions are required by HTMLPurifier.");
52 if (!function_exists("iconv")) {
53 array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
56 /* if (ini_get("safe_mode")) {
57 array_push($errors, "PHP safe mode setting is not supported.");
60 if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED
) && !function_exists("curl_init")) {
61 array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
64 if (!class_exists("DOMDocument")) {
65 array_push($errors, "PHP support for DOMDocument is required, but was not found.");
71 function print_error($msg) {
72 print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>";
75 function print_notice($msg) {
76 print "<div class=\"notice\">
77 <img src=\"../images/sign_info.svg\">$msg</div>";
80 function db_connect($host, $user, $pass, $db, $type) {
81 if ($type == "pgsql") {
83 $string = "dbname=$db user=$user";
86 $string .= " password=$pass";
90 $string .= " host=$host";
93 if (defined('DB_PORT')) {
94 $string = "$string port=" . DB_PORT
;
97 $link = pg_connect($string);
101 } else if ($type == "mysql") {
102 $link = mysql_connect($host, $user, $pass);
104 $result = mysql_select_db($db, $link);
110 function db_query($link, $query, $type, $die_on_error = true) {
111 if ($type == "pgsql") {
112 $result = pg_query($link, $query);
114 $query = htmlspecialchars($query); // just in case
116 die("Query <i>$query</i> failed [$result]: " . ($link ?
pg_last_error($link) : "No connection"));
120 } else if ($type == "mysql") {
121 $result = mysql_query($query, $link);
123 $query = htmlspecialchars($query);
125 die("Query <i>$query</i> failed: " . ($link ?
mysql_error($link) : "No connection"));
134 <div
class="floatingLogo"><img src
="../images/logo_wide.png"></div
>
136 <h1
>Tiny Tiny RSS Installer
</h1
>
139 if (file_exists("../config.php")) {
140 require "../config.php";
142 if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
143 print_error("Error: config.php already exists; aborting.");
148 @$op = $_REQUEST['op'];
150 @$DB_HOST = strip_tags($_POST['DB_HOST']);
151 @$DB_TYPE = strip_tags($_POST['DB_TYPE']);
152 @$DB_USER = strip_tags($_POST['DB_USER']);
153 @$DB_NAME = strip_tags($_POST['DB_NAME']);
154 @$DB_PASS = strip_tags($_POST['DB_PASS']);
155 @$DB_PORT = strip_tags($_POST['DB_PORT']);
159 <h2
>Database settings
</h2
>
161 <form action
="" method
="post">
162 <input type
="hidden" name
="op" value
="testconfig">
165 $issel_pgsql = $DB_TYPE == "pgsql" ?
"selected" : "";
166 $issel_mysql = $DB_TYPE == "mysql" ?
"selected" : "";
170 <label
>Database type
</label
>
171 <select name
="DB_TYPE">
172 <option
<?php
echo $issel_pgsql ?
> value
="pgsql">PostgreSQL
</option
>
173 <option
<?php
echo $issel_mysql ?
> value
="mysql">MySQL
</option
>
178 <label
>Username
</label
>
179 <input required name
="DB_USER" size
="20" value
="<?php echo $DB_USER ?>"/>
183 <label
>Password
</label
>
184 <input required name
="DB_PASS" size
="20" type
="password" value
="<?php echo $DB_PASS ?>"/>
188 <label
>Database name
</label
>
189 <input name
="DB_NAME" size
="20" value
="<?php echo $DB_NAME ?>"/>
193 <label
>Host name
</label
>
194 <input name
="DB_HOST" placeholder
="if needed" size
="20" value
="<?php echo $DB_HOST ?>"/>
199 <input name
="DB_PORT" placeholder
="if needed, PgSQL only" size
="20" value
="<?php echo $DB_PORT ?>"/>
202 <p
><input type
="submit" value
="Test configuration"></p
>
206 <?php
if ($op == 'testconfig') { ?
>
208 <h2
>Checking configuration
</h2
>
211 $errors = sanity_check($DB_TYPE);
213 if (count($errors) > 0) {
214 print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
218 foreach ($errors as $error) {
219 print "<li style='color : red'>$error</li>";
229 <h2
>Checking database
</h2
>
232 $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
235 print_error("Unable to connect to database using specified parameters.");
239 print_notice("Database test succeeded."); ?
>
241 <h2
>Initialize database
</h2
>
243 <p
>Before you can start using tt
-rss
, database needs to be initialized
. Click on the button below to
do that now
.</p
>
246 $result = db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
249 print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization.");
250 $need_confirm = true;
252 $need_confirm = false;
258 <input type
="hidden" name
="op" value
="installschema">
260 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
261 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
262 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
263 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
264 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
265 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
267 <?php
if ($need_confirm) { ?
>
268 <p
><input onclick
="return confirm('Please read the warning above. Continue?')" type
="submit" value
="Initialize database" style
="color : red"></p
>
270 <p
><input type
="submit" value
="Initialize database" style
="color : red"></p
>
276 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
277 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
278 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
279 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
280 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
281 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
283 <input type
="hidden" name
="op" value
="skipschema">
284 <p
><input type
="submit" value
="Skip initialization"></p
>
291 } else if ($op == 'installschema' ||
$op == 'skipschema') {
293 $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
296 print_error("Unable to connect to database using specified parameters.");
300 if ($op == 'installschema') {
302 print "<h2>Initializing database...</h2>";
304 $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql")));
306 foreach ($lines as $line) {
307 if (strpos($line, "--") !== 0 && $line) {
308 db_query($link, $line, $DB_TYPE);
312 print_notice("Database initialization completed.");
315 print_notice("Database initialization skipped.");
318 print "<h2>Generated configuration file</h2>";
320 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>";
322 print "<textarea cols=\"80\" rows=\"20\" name=\"config\">";
323 $data = explode("\n", file_get_contents("../config.php-dist"));
325 foreach ($data as $line) {
326 if (preg_match("/define\('DB_TYPE'/", $line)) {
327 echo "\tdefine('DB_TYPE', '$DB_TYPE');\n";
328 } else if (preg_match("/define\('DB_HOST'/", $line)) {
329 echo "\tdefine('DB_HOST', '$DB_HOST');\n";
330 } else if (preg_match("/define\('DB_USER'/", $line)) {
331 echo "\tdefine('DB_USER', '$DB_USER');\n";
332 } else if (preg_match("/define\('DB_NAME'/", $line)) {
333 echo "\tdefine('DB_NAME', '$DB_NAME');\n";
334 } else if (preg_match("/define\('DB_PASS'/", $line)) {
335 echo "\tdefine('DB_PASS', '$DB_PASS');\n";
336 } else if (preg_match("/define\('DB_PORT'/", $line)) {
337 echo "\tdefine('DB_PORT', '$DB_PORT');\n";
346 print "<p>You can generate the file again by changing the form above.</p>";