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