-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.php
368 lines (343 loc) · 17.4 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
###############################################################################
# Gregarius - A PHP based RSS aggregator.
# Copyright (C) 2003 - 2005 Marco Bonetti
#
###############################################################################
# This program is free software and open source software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
# http://www.gnu.org/licenses/gpl.html
#
###############################################################################
# E-mail: mbonetti at gmail dot com
# Web page: http://gregarius.net/
#
###############################################################################
define('GREGARIUS_RELEASE', '0.5.5');
define('GREGARIUS_CODENAME', 'null');
define('DBINIT', dirname(__FILE__) . '/dbinit.php');
// NOTE: This _must_ be a standard version string, see:
// php.net/version_compare
define('REQUIRED_VERSION', '4.3.0');
define('SQL_SERVER_DEFAULT', 'localhost');
define('SQLITE_DEFAULT', '/tmp/gregarius.sqlite');
define('WEB_SERVER_DEFAULT', 'localhost');
define('DATABASE_DEFAULT', 'rss');
define('TYPE_HELP', 'The type of database being used.');
define('SQL_SERVER_HELP', 'The location of the database. If in doubt, leave the default. Default: ' . SQL_SERVER_DEFAULT . '');
define('SQLITE_HELP', 'The path to the database. If in doubt, leave the default. Default: ' . SQLITE_DEFAULT . '');
define('DATABASE_HELP', 'The name of the database. Default: ' . DATABASE_DEFAULT . '');
define('USERNAME_HELP', 'The username to connect to the database. <br/>Make sure this user has INSERT,UPDATE,DELETE,CREATE,ALTER permission to the database!');
define('PASSWORD_HELP', 'The password used to connect to the database.');
define('PREFIX_HELP', 'The string to prefix the tables with. Example: A table called rss_item should have rss as the prefix.');
define('ADMIN_USERNAME_HELP', 'The administrator username to use for database creation.');
define('ADMIN_PASSWORD_HELP', 'The administrator password used to connect to the database. Make sure this user has GRANT privileges!');
define('WEBSERVER_HELP', 'The location of the webserver. If in doubt, leave the default. Default: ' . WEB_SERVER_DEFAULT . '');
global $hasWritePerm;
function install_main() {
$hasXML = function_exists('xml_parser_create');
$hasMySQL = function_exists('mysql_connect');
$hasSQLite = function_exists('sqlite_open');
$hasSocket = function_exists('fsockopen');
// $hasSQLite = true;
// If the server is running safe mode, try writing a temp file.
if(ini_get('safe_mode')) {
define ('TMPINIT', DBINIT . GREGARIUS_CODENAME . "tmp");
$fp = @fopen(TMPINIT, 'w');
if ($fp) {
$hasWritePerm = true;
fclose($fp);
unlink (TMPINIT);
} else {
$hasWritePerm = false;
}
} else { // else, just check to see if it's writable.
$hasWritePerm = is_writable(dirname(__FILE__));
}
if($hasMySQL && $hasSQLite) {
$sql = "MySQL & SQLite";
} else if($hasMySQL) {
$sql = "MySQL";
} else if($hasSQLite) {
$sql = "SQLite";
} else {
$sql = "None!";
}
echo ""
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
. "<head>\n"
. " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
. " <title>Gregarius " . GREGARIUS_RELEASE . " " . GREGARIUS_CODENAME . " Installer</title>\n"
. " <link rel=\"stylesheet\" type=\"text/css\" href=\"themes/default/css/layout.css\" />\n"
. " <link rel=\"stylesheet\" type=\"text/css\" href=\"themes/default/css/look.css\" />\n"
. "<style type=\"text/css\">\n"
. " .install {\n"
. " display: block;\n"
. " text-align: left;\n"
. " }\n"
. " .help {\n"
. " display: none;\n"
. " font-size: 12pt;\n"
. " color: red;\n"
. " }\n"
. " .found {\n"
. " color: green;\n"
. " font-weight: bold;\n"
. " }\n"
. " .not_found {\n"
. " color: red;\n"
. " font-weight: bold;\n"
. " }\n"
. " h2 {\n"
. " margin: 2px;\n"
. " }\n"
. " label { display:block; }\n"
. "</style>\n"
. "<script type=\"text/javascript\">\n"
. "//<![CDATA[\n"
. " function ValidInput(str) {\n"
. " return true;\n"
. " }\n"
. "\n"
. " function ToggleHelp(name) {\n"
. " var i=document.getElementById(name);\n"
. " if('block' == i.style.display) {\n"
. " i.style.display='none';\n"
. " } else {\n"
. " i.style.display='block';\n"
. " }\n"
. " }\n"
. "\n"
. " function ToggleType(rad) {\n"
. " if('mysql' == rad.value) {\n"
. " document.getElementById('database').disabled = false;\n"
. " document.getElementById('username').disabled = false;\n"
. " document.getElementById('password').disabled = false;\n"
. " document.getElementById('admin_username').disabled = false;\n"
. " document.getElementById('admin_password').disabled = false;\n"
. " document.getElementById('prefix').disabled = false;\n"
. " document.getElementById('web_server').disabled = false;\n"
. " document.getElementById('server').value = '" . SQL_SERVER_DEFAULT . "';\n"
. " document.getElementById('server_help').innerHTML = '" . SQL_SERVER_HELP . "';\n"
. " } else if ('sqlite' == rad.value) {\n"
. " document.getElementById('database').disabled = true;\n"
. " document.getElementById('username').disabled = true;\n"
. " document.getElementById('password').disabled = true;\n"
. " document.getElementById('admin_username').disabled = true;\n"
. " document.getElementById('admin_password').disabled = true;\n"
. " document.getElementById('prefix').disabled = true;\n"
. " document.getElementById('web_server').disabled = true;\n"
. " document.getElementById('server').value = '" . SQLITE_DEFAULT . "';\n"
. " document.getElementById('server_help').innerHTML = '" . SQLITE_HELP . "';\n"
. " }\n"
. " }\n"
. "\n"
. " function ValidateData() {\n"
. " var ret = false;\n"
. " if('mysql' == document.getElementById('type').value) {\n"
. " if(document.getElementById('server').value.length < 1) {\n"
. " alert('A server location is required.');\n"
. " document.getElementById('server').focus();\n"
. " } else if(document.getElementById('database').value.length < 1) {\n"
. " alert('A database name is required.');\n"
. " document.getElementById('database').focus();\n"
. " } else if(document.getElementById('username').value.length < 1) {\n"
. " alert('A username is required.');\n"
. " document.getElementById('username').focus();\n"
. " } else if(document.getElementById('password').value.length < 1) {\n"
. " alert('A password is required.');\n"
. " document.getElementById('password').focus();\n"
. " } else {\n"
. " ret = true;\n"
. " }\n"
. " } else if('sqlite' == document.getElementById('type').value) {\n"
. " if(document.getElementById('server').value.length < 1) {\n"
. " alert('A server path is required.');\n"
. " document.getElementById('server').focus();\n"
. " } else {\n"
. " ret = true;\n"
. " }\n"
. " }\n"
. "\n"
. " return ret;\n"
. " }\n"
. "//]]>\n"
. "</script>\n"
. "</head>\n"
. "<body>\n"
. "<div id=\"nav\" class=\"frame\">"
. "<h1>Gregarius Database Setup</h1>\n"
. "<fieldset class=\"install\" style=\"text-align:center\">\n"
. "<legend>Version " . GREGARIUS_RELEASE . " - " . GREGARIUS_CODENAME . "</legend>\n"
. "<p><img src=\"themes/default/media/installer/codename.jpg\" alt=\"".GREGARIUS_CODENAME."\" /></p>\n"
. "</fieldset>\n"
. "</div>"
. "<div id=\"install\" class=\"frame\">\n"
. "<h2>Step 1: Verify Environment</h2>\n"
. "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" onsubmit=\"return ValidateData();\">\n"
. "<fieldset class=\"install\">\n"
. "<legend>Diagnostics</legend>\n"
. "<p>Below are some of the requirements to run Gregarius. If any are not found, please fix them before continuing.</p>\n"
. "<p class=\"" . (version_compare(REQUIRED_VERSION, PHP_VERSION) <= 0 ? "found" : "not_found") . "\"><label>PHP Version: " . phpversion() . "</label></p>\n"
. "<p class=\"" . ($hasSocket ? "found" : "not_found") . "\"><label>Sockets: " . ($hasSocket ? "Found" : "Not Found!") . "</label></p>\n"
. "<p class=\"" . ($hasXML ? "found" : "not_found") . "\"><label>XML: " . ($hasXML ? "Found" : "Not Found!") . "</label></p>\n"
. "<p class=\"" . ($hasMySQL || $hasSQLite ? "found" : "not_found") . "\"><label>Database: " . $sql . "</label></p>\n"
. "</fieldset>\n"
. "<h2>Step 2: Provide Database Settings</h2>\n"
. "<fieldset class=\"install\">\n"
. "<legend>Database Settings</legend>\n"
. "<p>The settings below are for the database Gregarius will keep its data.</p>\n"
. "<p><label for=\"type\">Server Type <a href=\"#\" onclick=\"ToggleHelp('type_help'); return false; \">[?]</a></label>\n"
. "<input type=\"radio\" style=\"display:inline\" name=\"type\" id=\"type\" value=\"mysql\" onchange=\"ToggleType(this); return false;\" " . ($hasMySQL ? "checked=\"checked\"" : "disabled=\"disabled\"") . "/>MySQL"
. "<input type=\"radio\" style=\"display:inline\" name=\"type\" value=\"sqlite\" onchange=\"ToggleType(this); return false;\" " . ($hasSQLite ? ($hasMySQL ? "" : "checked=\"checked\"") : "disabled=\"disabled\"") . "/>SQLite"
. "<span class=\"help\" id=\"type_help\">" . TYPE_HELP . "</span></p>\n"
. "<p><label for=\"server\">Server Location <a href=\"#\" onclick=\"ToggleHelp('server_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"server\" id=\"server\" value=\"" . SQL_SERVER_DEFAULT . "\" />"
. "<span class=\"help\" id=\"server_help\">" . SQL_SERVER_HELP . "</span></p>\n"
. "<p><label for=\"database\">Database Name <a href=\"#\" onclick=\"ToggleHelp('database_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"database\" id=\"database\" value=\"" . DATABASE_DEFAULT . "\" />"
. "<span class=\"help\" id=\"database_help\">" . DATABASE_HELP . "</span></p>\n"
. "<p><label for=\"username\">Database UserName <a href=\"#\" onclick=\"ToggleHelp('username_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"username\" id=\"username\" value=\"\" />"
. "<span class=\"help\" id=\"username_help\">" . USERNAME_HELP . "</span></p>\n"
. "<p><label for=\"password\">Database Password <a href=\"#\" onclick=\"ToggleHelp('password_help'); return false; \">[?]</a></label>\n"
. "<input type=\"password\" name=\"password\" id=\"password\" value=\"\" />"
. "<span class=\"help\" id=\"password_help\">" . PASSWORD_HELP . "</span></p>\n"
. "<p><label for=\"prefix\">Database Table Prefix <a href=\"#\" onclick=\"ToggleHelp('prefix_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"prefix\" id=\"prefix\" value=\"\" />"
. "<span class=\"help\" id=\"prefix_help\">" . PREFIX_HELP . "</span></p>\n"
. "</fieldset>\n"
. "<h2>Step 3: Provide Admin Settings (optional)</h2>\n"
. "<fieldset class=\"install\">\n"
. "<legend>Server Setup</legend>\n"
. "<p>If you would like Gregarius to create the database and user for you, input the correct settings below.</p>\n"
. "<p><label for=\"admin_username\">Admin UserName <a href=\"#\" onclick=\"ToggleHelp('admin_username_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"admin_username\" id=\"admin_username\" value=\"\" />"
. "<span class=\"help\" id=\"admin_username_help\">" . ADMIN_USERNAME_HELP . "</span></p>\n"
. "<p><label for=\"admin_password\">Admin Password <a href=\"#\" onclick=\"ToggleHelp('admin_password_help'); return false; \">[?]</a></label>\n"
. "<input type=\"password\" name=\"admin_password\" id=\"admin_password\" value=\"\" />"
. "<span class=\"help\" id=\"admin_password_help\">" . ADMIN_PASSWORD_HELP . "</span></p>\n"
. "<p><label for=\"web_server\">Web Location <a href=\"#\" onclick=\"ToggleHelp('web_server_help'); return false; \">[?]</a></label>\n"
. "<input type=\"text\" name=\"web_server\" id=\"web_server\" value=\"" . WEB_SERVER_DEFAULT . "\" />"
. "<span class=\"help\" id=\"web_server_help\">" . WEBSERVER_HELP . "</span></p>\n"
. "</fieldset>\n"
. "<h2>Step 4: " . ($hasWritePerm ? "Create database and write dbinit.php" : "Create database and download dbinit.php") . "</h2>\n"
. "<p><input type=\"submit\" name=\"action\" value=\"" . ($hasWritePerm ? "Setup Database" : "Download dbinit.php file") . "\" /></p>\n"
. "<p><input type=\"hidden\" name=\"process\" value=\"1\" /></p>\n"
. "</form>\n"
. "</div>\n"
. "</body>\n"
. "</html>\n";
}
if(file_exists(DBINIT)) {
print("The dbinit.php file already exists in the Gregarius directory! Please remove it if you would like to use this installer.");
} else if(!empty($_POST['process']) && 1 == $_POST['process']) {
if(empty($_POST['server']) ||
empty($_POST['database']) ||
empty($_POST['username']) ||
empty($_POST['password']) ||
empty($_POST['type'])) {
print("Not all required fields have been filled in!");
} else {
// create the database and user
if(!empty($_POST['admin_username'])) {
if("mysql" == $_POST['type']) {
$sql = @mysql_connect($_POST['server'], $_POST['admin_username'], $_POST['admin_password']);
if(!$sql) {
print("Unable to connect to database! Please create manually.");
} else {
mysql_query("CREATE DATABASE " . $_POST['database'] . "", $sql);
mysql_query("GRANT ALL ON " . $_POST['database'] . ".* TO '" . $_POST['username'] . "'@'" . $_POST['web_server'] . "' IDENTIFIED BY '" . $_POST['password'] . "'", $sql);
mysql_close($sql);
}
} else if("sqlite" == $_POST['type']) {
$sql = @sqlite_open($_POST['server'], 0666);
if(!$sql) {
print("Unable to connect to database! Please create manually.");
}
} else {
print("Invalid SQL Type!");
exit();
}
}
$out = "<?php
//
// The type of database server you are using. By default
// Gregarius will look for a MySQL database server. If you
// would like to use an SQLite database, change accordingly
//
define ('DBTYPE','" . $_POST['type'] . "');
//
// The name of your database
//
define ('DBNAME','" . $_POST['database'] . "');
//
// The username to use when connecting to the database. Make sure that
// thus user owns privileges to CREATE database tables on the above
// database!
//
define ('DBUNAME','" . $_POST['username'] . "');
//
// The password to use when connecting to the database
//
define ('DBPASS', '" . $_POST['password'] . "');
//
// If you are using a MySQL database:
// The hostname of your database server. Unless you know
// different this should probably be 'localhost' or '127.0.0.1'
//
// If you are using a SQLite database:
// This constant must contain the full path to your database file,
// for example: '/tmp/gregarius.db'
// Note that the apache process must have write access privileges
// on the given directory!
//
define ('DBSERVER', '" . $_POST['server'] . "');
//
// The table name prefix to use. If you specify anything here,
// say 'gregarius', your database table 'channels' will be referred to
// as 'gregarius_channels'. This is useful to avoid table collisions when
// your hosting provider only grants you one single database and several
// applications rely on that db.
//
// If this is not the case you can safely ignore this option.
//
";
if(empty($_POST['prefix'])) {
$out .= "//define ('DB_TABLE_PREFIX','');";
} else {
$out .= "define('DB_TABLE_PREFIX', '" . $_POST['prefix'] . "');";
}
$out .= "\n?>";
$fp = @fopen(DBINIT, 'w');
if(!$fp) {
// unable to open file for writing
header('Content-type: application/x-httpd-php-source');
header('Content-Disposition: attachment; filename="dbinit.php"');
echo($out);
exit();
} else {
// write the file
fwrite($fp, $out);
fclose($fp);
header('Location: admin/');
exit();
}
}
} else { // dbinit.php does not exist and we are not asked to process
// print out the form
install_main();
}
?>