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