]>
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 | ||
12 | <? | |
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 | ||
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)."); | |
22 | } | |
23 | ||
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."); | |
26 | } | |
27 | ||
28 | if (!function_exists("json_encode")) { | |
29 | array_push($errors, "PHP support for JSON is required, but was not found."); | |
30 | } | |
31 | ||
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."); | |
34 | } | |
35 | ||
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"); | |
38 | } | |
39 | ||
40 | if (!function_exists("mb_strlen")) { | |
41 | array_push($errors, "PHP support for mbstring functions is required but was not found."); | |
42 | } | |
43 | ||
44 | if (!function_exists("hash")) { | |
45 | array_push($errors, "PHP support for hash() function is required but was not found."); | |
46 | } | |
47 | ||
48 | if (!function_exists("ctype_lower")) { | |
49 | array_push($errors, "PHP support for ctype functions are required by HTMLPurifier."); | |
50 | } | |
51 | ||
52 | if (!function_exists("iconv")) { | |
53 | array_push($errors, "PHP support for iconv is required to handle multiple charsets."); | |
54 | } | |
55 | ||
56 | /* if (ini_get("safe_mode")) { | |
57 | array_push($errors, "PHP safe mode setting is not supported."); | |
58 | } */ | |
59 | ||
60 | if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED) && !function_exists("curl_init")) { | |
61 | array_push($errors, "PHP support for CURL is required for PubSubHubbub."); | |
62 | } | |
63 | ||
64 | if (!class_exists("DOMDocument")) { | |
65 | array_push($errors, "PHP support for DOMDocument is required, but was not found."); | |
66 | } | |
67 | ||
68 | return $errors; | |
69 | } | |
70 | ||
71 | function print_error($msg) { | |
72 | print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>"; | |
73 | } | |
74 | ||
75 | function print_notice($msg) { | |
76 | print "<div class=\"notice\"> | |
77 | <img src=\"../images/sign_info.svg\">$msg</div>"; | |
78 | } | |
79 | ||
80 | function db_connect($host, $user, $pass, $db, $type) { | |
81 | if ($type == "pgsql") { | |
82 | ||
83 | $string = "dbname=$db user=$user"; | |
84 | ||
85 | if ($pass) { | |
86 | $string .= " password=$pass"; | |
87 | } | |
88 | ||
89 | if ($host) { | |
90 | $string .= " host=$host"; | |
91 | } | |
92 | ||
93 | if (defined('DB_PORT')) { | |
94 | $string = "$string port=" . DB_PORT; | |
95 | } | |
96 | ||
97 | $link = pg_connect($string); | |
98 | ||
99 | return $link; | |
100 | ||
101 | } else if ($type == "mysql") { | |
102 | $link = mysql_connect($host, $user, $pass); | |
103 | if ($link) { | |
104 | $result = mysql_select_db($db, $link); | |
884d1650 | 105 | if ($result) return $link; |
d0c6dd29 AD |
106 | } |
107 | } | |
108 | } | |
109 | ||
110 | function db_query($link, $query, $type, $die_on_error = true) { | |
111 | if ($type == "pgsql") { | |
112 | $result = pg_query($link, $query); | |
113 | if (!$result) { | |
114 | $query = htmlspecialchars($query); // just in case | |
115 | if ($die_on_error) { | |
116 | die("Query <i>$query</i> failed [$result]: " . ($link ? pg_last_error($link) : "No connection")); | |
117 | } | |
118 | } | |
119 | return $result; | |
120 | } else if ($type == "mysql") { | |
121 | $result = mysql_query($query, $link); | |
122 | if (!$result) { | |
123 | $query = htmlspecialchars($query); | |
124 | if ($die_on_error) { | |
125 | die("Query <i>$query</i> failed: " . ($link ? mysql_error($link) : "No connection")); | |
126 | } | |
127 | } | |
128 | return $result; | |
129 | } | |
130 | } | |
131 | ||
132 | ?> | |
133 | ||
884d1650 | 134 | <div class="floatingLogo"><img src="../images/logo_small.png"></div> |
d0c6dd29 AD |
135 | |
136 | <h1>Tiny Tiny RSS Installer</h1> | |
137 | ||
884d1650 AD |
138 | <div class='content'> |
139 | ||
d0c6dd29 AD |
140 | <?php |
141 | if (file_exists("../config.php")) { | |
142 | require "../config.php"; | |
143 | ||
144 | if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) { | |
145 | print_error("Error: config.php already exists; aborting."); | |
146 | exit; | |
147 | } | |
148 | } | |
149 | ||
150 | @$op = $_REQUEST['op']; | |
151 | ||
152 | @$DB_HOST = strip_tags($_POST['DB_HOST']); | |
153 | @$DB_TYPE = strip_tags($_POST['DB_TYPE']); | |
154 | @$DB_USER = strip_tags($_POST['DB_USER']); | |
155 | @$DB_NAME = strip_tags($_POST['DB_NAME']); | |
156 | @$DB_PASS = strip_tags($_POST['DB_PASS']); | |
157 | @$DB_PORT = strip_tags($_POST['DB_PORT']); | |
158 | ||
159 | ?> | |
160 | ||
161 | <h2>Database settings</h2> | |
162 | ||
163 | <form action="" method="post"> | |
164 | <input type="hidden" name="op" value="testconfig"> | |
165 | ||
166 | <?php | |
167 | $issel_pgsql = $DB_TYPE == "pgsql" ? "selected" : ""; | |
168 | $issel_mysql = $DB_TYPE == "mysql" ? "selected" : ""; | |
169 | ?> | |
170 | ||
171 | <fieldset> | |
172 | <label>Database type</label> | |
173 | <select name="DB_TYPE"> | |
174 | <option <?php echo $issel_pgsql ?> value="pgsql">PostgreSQL</option> | |
175 | <option <?php echo $issel_mysql ?> value="mysql">MySQL</option> | |
176 | </select> | |
177 | </fieldset> | |
178 | ||
179 | <fieldset> | |
180 | <label>Username</label> | |
181 | <input required name="DB_USER" size="20" value="<?php echo $DB_USER ?>"/> | |
182 | </fieldset> | |
183 | ||
184 | <fieldset> | |
185 | <label>Password</label> | |
186 | <input required name="DB_PASS" size="20" type="password" value="<?php echo $DB_PASS ?>"/> | |
187 | </fieldset> | |
188 | ||
189 | <fieldset> | |
190 | <label>Database name</label> | |
191 | <input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/> | |
192 | </fieldset> | |
193 | ||
194 | <fieldset> | |
195 | <label>Host name</label> | |
196 | <input name="DB_HOST" placeholder="if needed" size="20" value="<?php echo $DB_HOST ?>"/> | |
197 | </fieldset> | |
198 | ||
199 | <fieldset> | |
200 | <label>Port</label> | |
201 | <input name="DB_PORT" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/> | |
202 | </fieldset> | |
203 | ||
204 | <p><input type="submit" value="Test configuration"></p> | |
205 | ||
206 | </form> | |
207 | ||
208 | <?php if ($op == 'testconfig') { ?> | |
209 | ||
210 | <h2>Checking configuration</h2> | |
211 | ||
212 | <?php | |
213 | $errors = sanity_check($DB_TYPE); | |
214 | ||
215 | if (count($errors) > 0) { | |
216 | print "<p>Some configuration tests failed. Please correct them before continuing.</p>"; | |
217 | ||
218 | print "<ul>"; | |
219 | ||
220 | foreach ($errors as $error) { | |
221 | print "<li style='color : red'>$error</li>"; | |
222 | } | |
223 | ||
224 | print "</ul>"; | |
225 | ||
226 | exit; | |
227 | } | |
228 | ||
229 | ?> | |
230 | ||
884d1650 AD |
231 | <?php print_notice("Configuration check succeeded."); ?> |
232 | ||
d0c6dd29 AD |
233 | <h2>Checking database</h2> |
234 | ||
235 | <?php | |
236 | $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE); | |
237 | ||
238 | if (!$link) { | |
239 | print_error("Unable to connect to database using specified parameters."); | |
240 | exit; | |
241 | } | |
242 | ||
243 | print_notice("Database test succeeded."); ?> | |
244 | ||
245 | <h2>Initialize database</h2> | |
246 | ||
247 | <p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p> | |
248 | ||
249 | <?php | |
250 | $result = db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false); | |
251 | ||
252 | if ($result) { | |
253 | print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization."); | |
254 | $need_confirm = true; | |
255 | } else { | |
256 | $need_confirm = false; | |
257 | } | |
258 | ?> | |
259 | ||
260 | <table><tr><td> | |
261 | <form method="post"> | |
262 | <input type="hidden" name="op" value="installschema"> | |
263 | ||
264 | <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/> | |
265 | <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/> | |
266 | <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/> | |
267 | <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/> | |
268 | <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/> | |
269 | <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/> | |
270 | ||
271 | <?php if ($need_confirm) { ?> | |
272 | <p><input onclick="return confirm('Please read the warning above. Continue?')" type="submit" value="Initialize database" style="color : red"></p> | |
273 | <?php } else { ?> | |
274 | <p><input type="submit" value="Initialize database" style="color : red"></p> | |
275 | <?php } ?> | |
276 | </form> | |
277 | ||
278 | </td><td> | |
279 | <form method="post"> | |
280 | <input type="hidden" name="DB_USER" value="<?php echo $DB_USER ?>"/> | |
281 | <input type="hidden" name="DB_PASS" value="<?php echo $DB_PASS ?>"/> | |
282 | <input type="hidden" name="DB_NAME" value="<?php echo $DB_NAME ?>"/> | |
283 | <input type="hidden" name="DB_HOST" value="<?php echo $DB_HOST ?>"/> | |
284 | <input type="hidden" name="DB_PORT" value="<?php echo $DB_PORT ?>"/> | |
285 | <input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/> | |
286 | ||
287 | <input type="hidden" name="op" value="skipschema"> | |
288 | <p><input type="submit" value="Skip initialization"></p> | |
289 | </form> | |
290 | ||
291 | </td></tr></table> | |
292 | ||
293 | <?php | |
294 | ||
295 | } else if ($op == 'installschema' || $op == 'skipschema') { | |
296 | ||
297 | $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE); | |
298 | ||
299 | if (!$link) { | |
300 | print_error("Unable to connect to database using specified parameters."); | |
301 | exit; | |
302 | } | |
303 | ||
304 | if ($op == 'installschema') { | |
305 | ||
306 | print "<h2>Initializing database...</h2>"; | |
307 | ||
308 | $lines = explode(";", preg_replace("/[\r\n]/", "", file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); | |
309 | ||
310 | foreach ($lines as $line) { | |
311 | if (strpos($line, "--") !== 0 && $line) { | |
312 | db_query($link, $line, $DB_TYPE); | |
313 | } | |
314 | } | |
315 | ||
316 | print_notice("Database initialization completed."); | |
317 | ||
318 | } else { | |
319 | print_notice("Database initialization skipped."); | |
320 | } | |
321 | ||
322 | print "<h2>Generated configuration file</h2>"; | |
323 | ||
324 | 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>"; | |
325 | ||
326 | print "<textarea cols=\"80\" rows=\"20\" name=\"config\">"; | |
327 | $data = explode("\n", file_get_contents("../config.php-dist")); | |
328 | ||
329 | foreach ($data as $line) { | |
330 | if (preg_match("/define\('DB_TYPE'/", $line)) { | |
260501fd | 331 | echo "\tdefine('DB_TYPE', '$DB_TYPE');\n"; |
d0c6dd29 | 332 | } else if (preg_match("/define\('DB_HOST'/", $line)) { |
260501fd | 333 | echo "\tdefine('DB_HOST', '$DB_HOST');\n"; |
d0c6dd29 | 334 | } else if (preg_match("/define\('DB_USER'/", $line)) { |
260501fd | 335 | echo "\tdefine('DB_USER', '$DB_USER');\n"; |
d0c6dd29 | 336 | } else if (preg_match("/define\('DB_NAME'/", $line)) { |
260501fd | 337 | echo "\tdefine('DB_NAME', '$DB_NAME');\n"; |
d0c6dd29 | 338 | } else if (preg_match("/define\('DB_PASS'/", $line)) { |
260501fd | 339 | echo "\tdefine('DB_PASS', '$DB_PASS');\n"; |
d0c6dd29 | 340 | } else if (preg_match("/define\('DB_PORT'/", $line)) { |
260501fd | 341 | echo "\tdefine('DB_PORT', '$DB_PORT');\n"; |
d0c6dd29 AD |
342 | |
343 | } else { | |
344 | print "$line\n"; | |
345 | } | |
346 | } | |
347 | ||
348 | print "</textarea>"; | |
349 | ||
350 | print "<p>You can generate the file again by changing the form above.</p>"; | |
351 | } | |
352 | ?> | |
353 | ||
884d1650 | 354 | </div> |
d0c6dd29 AD |
355 | |
356 | </body> | |
357 | </html> |