]>
Commit | Line | Data |
---|---|---|
d0c6dd29 AD |
1 | <html> |
2 | <head> | |
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; } | |
8 | </style> | |
9 | </head> | |
10 | <body> | |
11 | ||
1fcb6baa | 12 | <?php |
044cff2d AD |
13 | function make_password($length = 8) { |
14 | ||
15 | $password = ""; | |
16 | $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^"; | |
17 | ||
18 | $i = 0; | |
19 | ||
20 | while ($i < $length) { | |
21 | $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
22 | ||
23 | if (!strstr($password, $char)) { | |
24 | $password .= $char; | |
25 | $i++; | |
26 | } | |
27 | } | |
28 | return $password; | |
29 | } | |
30 | ||
31 | ||
d0c6dd29 AD |
32 | function sanity_check($db_type) { |
33 | $errors = array(); | |
34 | ||
35 | if (version_compare(PHP_VERSION, '5.3.0', '<')) { | |
36 | array_push($errors, "PHP version 5.3.0 or newer required."); | |
37 | } | |
38 | ||
d0c6dd29 AD |
39 | if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
40 | 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."); | |
41 | } | |
42 | ||
43 | if (!function_exists("json_encode")) { | |
44 | array_push($errors, "PHP support for JSON is required, but was not found."); | |
45 | } | |
46 | ||
ae35bb87 | 47 | if ($db_type == "mysql" && !function_exists("mysql_connect") && !function_exists("mysqli_connect")) { |
d0c6dd29 AD |
48 | array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php."); |
49 | } | |
50 | ||
51 | if ($db_type == "pgsql" && !function_exists("pg_connect")) { | |
52 | array_push($errors, "PHP support for PostgreSQL is required for configured $db_type in config.php"); | |
53 | } | |
54 | ||
55 | if (!function_exists("mb_strlen")) { | |
56 | array_push($errors, "PHP support for mbstring functions is required but was not found."); | |
57 | } | |
58 | ||
59 | if (!function_exists("hash")) { | |
60 | array_push($errors, "PHP support for hash() function is required but was not found."); | |
61 | } | |
62 | ||
63 | if (!function_exists("ctype_lower")) { | |
64 | array_push($errors, "PHP support for ctype functions are required by HTMLPurifier."); | |
65 | } | |
66 | ||
67 | if (!function_exists("iconv")) { | |
68 | array_push($errors, "PHP support for iconv is required to handle multiple charsets."); | |
69 | } | |
70 | ||
71 | /* if (ini_get("safe_mode")) { | |
72 | array_push($errors, "PHP safe mode setting is not supported."); | |
73 | } */ | |
74 | ||
d0c6dd29 AD |
75 | if (!class_exists("DOMDocument")) { |
76 | array_push($errors, "PHP support for DOMDocument is required, but was not found."); | |
77 | } | |
78 | ||
79 | return $errors; | |
80 | } | |
81 | ||
82 | function print_error($msg) { | |
3c200461 AD |
83 | print "<div class='error'><span><img src='../images/sign_excl.svg'></span> |
84 | <span>$msg</span></div>"; | |
d0c6dd29 AD |
85 | } |
86 | ||
87 | function print_notice($msg) { | |
88 | print "<div class=\"notice\"> | |
3c200461 | 89 | <span><img src=\"../images/sign_info.svg\"></span><span>$msg</span></div>"; |
d0c6dd29 AD |
90 | } |
91 | ||
bbffc43e | 92 | function db_connect($host, $user, $pass, $db, $type, $port) { |
d0c6dd29 AD |
93 | if ($type == "pgsql") { |
94 | ||
95 | $string = "dbname=$db user=$user"; | |
96 | ||
97 | if ($pass) { | |
98 | $string .= " password=$pass"; | |
99 | } | |
100 | ||
101 | if ($host) { | |
102 | $string .= " host=$host"; | |
103 | } | |
104 | ||
bbffc43e AD |
105 | if ($port) { |
106 | $string = "$string port=" . $port; | |
d0c6dd29 AD |
107 | } |
108 | ||
109 | $link = pg_connect($string); | |
110 | ||
111 | return $link; | |
112 | ||
113 | } else if ($type == "mysql") { | |
bbffc43e AD |
114 | if (function_exists("mysqli_connect")) { |
115 | return mysqli_connect($host, $user, $pass, $db, $port); | |
116 | ||
117 | } else { | |
118 | $link = mysql_connect($host, $user, $pass); | |
119 | if ($link) { | |
120 | $result = mysql_select_db($db, $link); | |
121 | if ($result) return $link; | |
122 | } | |
d0c6dd29 AD |
123 | } |
124 | } | |
125 | } | |
126 | ||
b4cec374 AD |
127 | function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, |
128 | $DB_PORT, $SELF_URL_PATH) { | |
129 | ||
130 | $data = explode("\n", file_get_contents("../config.php-dist")); | |
131 | ||
132 | $rv = ""; | |
133 | ||
c93f98e1 AD |
134 | $finished = false; |
135 | ||
044cff2d AD |
136 | if (function_exists("mcrypt_decrypt")) { |
137 | $crypt_key = make_password(24); | |
138 | } else { | |
139 | $crypt_key = ""; | |
140 | } | |
141 | ||
b4cec374 AD |
142 | foreach ($data as $line) { |
143 | if (preg_match("/define\('DB_TYPE'/", $line)) { | |
144 | $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n"; | |
145 | } else if (preg_match("/define\('DB_HOST'/", $line)) { | |
146 | $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n"; | |
147 | } else if (preg_match("/define\('DB_USER'/", $line)) { | |
148 | $rv .= "\tdefine('DB_USER', '$DB_USER');\n"; | |
149 | } else if (preg_match("/define\('DB_NAME'/", $line)) { | |
150 | $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n"; | |
151 | } else if (preg_match("/define\('DB_PASS'/", $line)) { | |
152 | $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n"; | |
153 | } else if (preg_match("/define\('DB_PORT'/", $line)) { | |
154 | $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n"; | |
155 | } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) { | |
156 | $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n"; | |
044cff2d AD |
157 | } else if (preg_match("/define\('FEED_CRYPT_KEY'/", $line)) { |
158 | $rv .= "\tdefine('FEED_CRYPT_KEY', '$crypt_key');\n"; | |
c93f98e1 | 159 | } else if (!$finished) { |
b4cec374 AD |
160 | $rv .= "$line\n"; |
161 | } | |
c93f98e1 AD |
162 | |
163 | if (preg_match("/\?\>/", $line)) { | |
164 | $finished = true; | |
165 | } | |
b4cec374 AD |
166 | } |
167 | ||
168 | return $rv; | |
169 | } | |
170 | ||
d0c6dd29 AD |
171 | function db_query($link, $query, $type, $die_on_error = true) { |
172 | if ($type == "pgsql") { | |
173 | $result = pg_query($link, $query); | |
174 | if (!$result) { | |
175 | $query = htmlspecialchars($query); // just in case | |
176 | if ($die_on_error) { | |
177 | die("Query <i>$query</i> failed [$result]: " . ($link ? pg_last_error($link) : "No connection")); | |
178 | } | |
179 | } | |
180 | return $result; | |
181 | } else if ($type == "mysql") { | |
bbffc43e AD |
182 | |
183 | if (function_exists("mysqli_connect")) { | |
184 | $result = mysqli_query($link, $query); | |
185 | } else { | |
186 | $result = mysql_query($query, $link); | |
187 | } | |
d0c6dd29 AD |
188 | if (!$result) { |
189 | $query = htmlspecialchars($query); | |
190 | if ($die_on_error) { | |
191 | die("Query <i>$query</i> failed: " . ($link ? mysql_error($link) : "No connection")); | |
192 | } | |
193 | } | |
194 | return $result; | |
195 | } | |
196 | } | |
197 | ||
056c537b AD |
198 | function make_self_url_path() { |
199 | $url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); | |
200 | ||
201 | return $url_path; | |
202 | } | |
203 | ||
d0c6dd29 AD |
204 | ?> |
205 | ||
884d1650 | 206 | <div class="floatingLogo"><img src="../images/logo_small.png"></div> |
d0c6dd29 AD |
207 | |
208 | <h1>Tiny Tiny RSS Installer</h1> | |
209 | ||
884d1650 AD |
210 | <div class='content'> |
211 | ||
d0c6dd29 | 212 | <?php |
056c537b | 213 | |
d0c6dd29 AD |
214 | if (file_exists("../config.php")) { |
215 | require "../config.php"; | |
216 | ||
217 | if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) { | |
b4cec374 | 218 | print_error("Error: config.php already exists in tt-rss directory; aborting."); |
d0c6dd29 AD |
219 | exit; |
220 | } | |
221 | } | |
222 | ||
223 | @$op = $_REQUEST['op']; | |
224 | ||
225 | @$DB_HOST = strip_tags($_POST['DB_HOST']); | |
226 | @$DB_TYPE = strip_tags($_POST['DB_TYPE']); | |
227 | @$DB_USER = strip_tags($_POST['DB_USER']); | |
228 | @$DB_NAME = strip_tags($_POST['DB_NAME']); | |
229 | @$DB_PASS = strip_tags($_POST['DB_PASS']); | |
230 | @$DB_PORT = strip_tags($_POST['DB_PORT']); | |
056c537b | 231 | @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']); |
d0c6dd29 | 232 | |
056c537b AD |
233 | if (!$SELF_URL_PATH) { |
234 | $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path()); | |
235 | } | |
d0c6dd29 AD |
236 | ?> |
237 | ||
d0c6dd29 AD |
238 | <form action="" method="post"> |
239 | <input type="hidden" name="op" value="testconfig"> | |
240 | ||
056c537b AD |
241 | <h2>Database settings</h2> |
242 | ||
d0c6dd29 AD |
243 | <?php |
244 | $issel_pgsql = $DB_TYPE == "pgsql" ? "selected" : ""; | |
245 | $issel_mysql = $DB_TYPE == "mysql" ? "selected" : ""; | |
246 | ?> | |
247 | ||
248 | <fieldset> | |
249 | <label>Database type</label> | |
250 | <select name="DB_TYPE"> | |
251 | <option <?php echo $issel_pgsql ?> value="pgsql">PostgreSQL</option> | |
252 | <option <?php echo $issel_mysql ?> value="mysql">MySQL</option> | |
253 | </select> | |
254 | </fieldset> | |
255 | ||
256 | <fieldset> | |
257 | <label>Username</label> | |
258 | <input required name="DB_USER" size="20" value="<?php echo $DB_USER ?>"/> | |
259 | </fieldset> | |
260 | ||
261 | <fieldset> | |
262 | <label>Password</label> | |
263 | <input required name="DB_PASS" size="20" type="password" value="<?php echo $DB_PASS ?>"/> | |
264 | </fieldset> | |
265 | ||
266 | <fieldset> | |
267 | <label>Database name</label> | |
bbffc43e | 268 | <input required name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/> |
d0c6dd29 AD |
269 | </fieldset> |
270 | ||
271 | <fieldset> | |
272 | <label>Host name</label> | |
bbffc43e AD |
273 | <input name="DB_HOST" size="20" value="<?php echo $DB_HOST ?>"/> |
274 | <span class="hint">If needed</span> | |
d0c6dd29 AD |
275 | </fieldset> |
276 | ||
277 | <fieldset> | |
278 | <label>Port</label> | |
bbffc43e AD |
279 | <input name="DB_PORT" type="number" size="20" value="<?php echo $DB_PORT ?>"/> |
280 | <span class="hint">Usually 3306 for MySQL or 5432 for PostgreSQL</span> | |
d0c6dd29 AD |
281 | </fieldset> |
282 | ||
056c537b AD |
283 | <h2>Other settings</h2> |
284 | ||
285 | <p>This should be set to the location your Tiny Tiny RSS will be available on.</p> | |
286 | ||
287 | <fieldset> | |
288 | <label>Tiny Tiny RSS URL</label> | |
00df2b5f | 289 | <input type="url" name="SELF_URL_PATH" placeholder="<?php echo $SELF_URL_PATH; ?>" size="60" value="<?php echo $SELF_URL_PATH ?>"/> |
056c537b AD |
290 | </fieldset> |
291 | ||
292 | ||
d0c6dd29 AD |
293 | <p><input type="submit" value="Test configuration"></p> |
294 | ||
295 | </form> | |
296 | ||
297 | <?php if ($op == 'testconfig') { ?> | |
298 | ||
299 | <h2>Checking configuration</h2> | |
300 | ||
301 | <?php | |
302 | $errors = sanity_check($DB_TYPE); | |
303 | ||
304 | if (count($errors) > 0) { | |
305 | print "<p>Some configuration tests failed. Please correct them before continuing.</p>"; | |
306 | ||
307 | print "<ul>"; | |
308 | ||
309 | foreach ($errors as $error) { | |
310 | print "<li style='color : red'>$error</li>"; | |
311 | } | |
312 | ||
313 | print "</ul>"; | |
314 | ||
315 | exit; | |
316 | } | |
317 | ||
a55857db AD |
318 | $notices = array(); |
319 | ||
320 | if (!function_exists("curl_init")) { | |
321 | array_push($notices, "It is highly recommended to enable support for CURL in PHP."); | |
322 | } | |
323 | ||
324 | if (count($notices) > 0) { | |
325 | print_notice("Configuration check succeeded with minor problems:"); | |
326 | ||
327 | print "<ul>"; | |
d0c6dd29 | 328 | |
a55857db AD |
329 | foreach ($notices as $notice) { |
330 | print "<li>$notice</li>"; | |
331 | } | |
332 | ||
333 | print "</ul>"; | |
334 | } else { | |
335 | print_notice("Configuration check succeeded."); | |
336 | } | |
337 | ||
338 | ?> | |
884d1650 | 339 | |
d0c6dd29 AD |
340 | <h2>Checking database</h2> |
341 | ||
342 | <?php | |
bbffc43e | 343 | $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT); |
d0c6dd29 AD |
344 | |
345 | if (!$link) { | |
346 | print_error("Unable to connect to database using specified parameters."); | |
347 | exit; | |
348 | } | |
349 | ||
350 | print_notice("Database test succeeded."); ?> | |
351 | ||
352 | <h2>Initialize database</h2> | |
353 | ||
354 | <p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p> | |
355 | ||
356 | <?php | |
357 | $result = db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false); | |
358 | ||
359 | if ($result) { | |
360 | print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization."); | |
361 | $need_confirm = true; | |
362 | } else { | |
363 | $need_confirm = false; | |
364 | } | |
365 | ?> | |
366 | ||
367 | <table><tr><td> | |
368 | <form method="post"> | |
369 | <input type="hidden" name="op" value="installschema"> | |
370 | ||
371 | <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/> | |
372 | <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/> | |
373 | <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/> | |
374 | <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/> | |
375 | <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/> | |
376 | <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/> | |
056c537b | 377 | <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/> |
d0c6dd29 AD |
378 | |
379 | <?php if ($need_confirm) { ?> | |
380 | <p><input onclick="return confirm('Please read the warning above. Continue?')" type="submit" value="Initialize database" style="color : red"></p> | |
381 | <?php } else { ?> | |
382 | <p><input type="submit" value="Initialize database" style="color : red"></p> | |
383 | <?php } ?> | |
384 | </form> | |
385 | ||
386 | </td><td> | |
387 | <form method="post"> | |
388 | <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/> | |
389 | <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/> | |
390 | <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/> | |
391 | <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/> | |
392 | <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/> | |
393 | <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/> | |
056c537b | 394 | <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/> |
d0c6dd29 AD |
395 | |
396 | <input type="hidden" name="op" value="skipschema"> | |
397 | <p><input type="submit" value="Skip initialization"></p> | |
398 | </form> | |
399 | ||
400 | </td></tr></table> | |
401 | ||
402 | <?php | |
403 | ||
404 | } else if ($op == 'installschema' || $op == 'skipschema') { | |
405 | ||
406 | $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE); | |
407 | ||
408 | if (!$link) { | |
409 | print_error("Unable to connect to database using specified parameters."); | |
410 | exit; | |
411 | } | |
412 | ||
413 | if ($op == 'installschema') { | |
414 | ||
415 | print "<h2>Initializing database...</h2>"; | |
416 | ||
417 | $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); | |
418 | ||
419 | foreach ($lines as $line) { | |
420 | if (strpos($line, "--") !== 0 && $line) { | |
421 | db_query($link, $line, $DB_TYPE); | |
422 | } | |
423 | } | |
424 | ||
425 | print_notice("Database initialization completed."); | |
426 | ||
427 | } else { | |
428 | print_notice("Database initialization skipped."); | |
429 | } | |
430 | ||
431 | print "<h2>Generated configuration file</h2>"; | |
432 | ||
b4cec374 AD |
433 | 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>"; |
434 | ||
435 | 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>"; ?> | |
436 | ||
437 | <form action="" method="post"> | |
438 | <input type="hidden" name="op" value="saveconfig"> | |
439 | <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/> | |
440 | <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/> | |
441 | <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/> | |
442 | <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/> | |
443 | <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/> | |
444 | <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/> | |
445 | <input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/> | |
446 | <?php print "<textarea cols=\"80\" rows=\"20\">"; | |
447 | echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, | |
448 | $DB_PORT, $SELF_URL_PATH); | |
449 | print "</textarea>"; ?> | |
450 | ||
451 | <?php if (is_writable("..")) { ?> | |
452 | <p>We can also try saving the file automatically now.</p> | |
453 | ||
454 | <p><input type="submit" value="Save configuration"></p> | |
455 | </form> | |
456 | <?php } else { | |
457 | print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically."); | |
d0c6dd29 AD |
458 | } |
459 | ||
b4cec374 AD |
460 | print_notice("You can generate the file again by changing the form above."); |
461 | ||
462 | } else if ($op == "saveconfig") { | |
463 | ||
464 | print "<h2>Saving configuration file to parent directory...</h2>"; | |
465 | ||
466 | if (!file_exists("../config.php")) { | |
467 | ||
468 | $fp = fopen("../config.php", "w"); | |
469 | ||
470 | if ($fp) { | |
471 | $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST, | |
472 | $DB_USER, $DB_NAME, $DB_PASS, | |
473 | $DB_PORT, $SELF_URL_PATH)); | |
d0c6dd29 | 474 | |
b4cec374 AD |
475 | if ($written > 0) { |
476 | print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>."); | |
477 | ||
478 | } else { | |
479 | print_notice("Unable to write into config.php in tt-rss directory."); | |
480 | } | |
481 | ||
482 | fclose($fp); | |
483 | } else { | |
484 | print_error("Unable to open config.php in tt-rss directory for writing."); | |
485 | } | |
486 | } else { | |
487 | print_error("config.php already present in tt-rss directory, refusing to overwrite."); | |
488 | } | |
d0c6dd29 AD |
489 | } |
490 | ?> | |
491 | ||
884d1650 | 492 | </div> |
d0c6dd29 AD |
493 | |
494 | </body> | |
495 | </html> |