1
|
<?php
|
2
|
|
3
|
// $Id: save.php 1035 2009-07-06 22:34:35Z Ruebenwurzel $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
$debug = true;
|
26
|
|
27
|
if (true === $debug) {
|
28
|
ini_set('display_errors', 1);
|
29
|
error_reporting(E_ALL);
|
30
|
}
|
31
|
// Start a session
|
32
|
if(!defined('SESSION_STARTED')) {
|
33
|
session_name('wb_session_id');
|
34
|
session_start();
|
35
|
define('SESSION_STARTED', true);
|
36
|
}
|
37
|
// get random-part for session_name()
|
38
|
list($usec,$sec) = explode(' ',microtime());
|
39
|
srand((float)$sec+((float)$usec*100000));
|
40
|
$session_rand = rand(1000,9999);
|
41
|
|
42
|
// Function to set error
|
43
|
function set_error($message, $field_name = '') {
|
44
|
global $_POST;
|
45
|
if(isset($message) AND $message != '') {
|
46
|
// Copy values entered into session so user doesn't have to re-enter everything
|
47
|
if(isset($_POST['website_title'])) {
|
48
|
$_SESSION['wb_url'] = $_POST['wb_url'];
|
49
|
$_SESSION['default_timezone'] = $_POST['default_timezone'];
|
50
|
$_SESSION['default_language'] = $_POST['default_language'];
|
51
|
if(!isset($_POST['operating_system'])) {
|
52
|
$_SESSION['operating_system'] = 'linux';
|
53
|
} else {
|
54
|
$_SESSION['operating_system'] = $_POST['operating_system'];
|
55
|
}
|
56
|
if(!isset($_POST['world_writeable'])) {
|
57
|
$_SESSION['world_writeable'] = false;
|
58
|
} else {
|
59
|
$_SESSION['world_writeable'] = true;
|
60
|
}
|
61
|
$_SESSION['database_host'] = $_POST['database_host'];
|
62
|
$_SESSION['database_username'] = $_POST['database_username'];
|
63
|
$_SESSION['database_password'] = $_POST['database_password'];
|
64
|
$_SESSION['database_name'] = $_POST['database_name'];
|
65
|
$_SESSION['table_prefix'] = $_POST['table_prefix'];
|
66
|
if(!isset($_POST['install_tables'])) {
|
67
|
$_SESSION['install_tables'] = false;
|
68
|
} else {
|
69
|
$_SESSION['install_tables'] = true;
|
70
|
}
|
71
|
$_SESSION['website_title'] = $_POST['website_title'];
|
72
|
$_SESSION['admin_username'] = $_POST['admin_username'];
|
73
|
$_SESSION['admin_email'] = $_POST['admin_email'];
|
74
|
$_SESSION['admin_password'] = $_POST['admin_password'];
|
75
|
$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
|
76
|
}
|
77
|
// Set the message
|
78
|
$_SESSION['message'] = $message;
|
79
|
// Set the element(s) to highlight
|
80
|
if($field_name != '') {
|
81
|
$_SESSION['ERROR_FIELD'] = $field_name;
|
82
|
}
|
83
|
// Specify that session support is enabled
|
84
|
$_SESSION['session_support'] = '<font class="good">Enabled</font>';
|
85
|
// Redirect to first page again and exit
|
86
|
header('Location: index.php?sessions_checked=true');
|
87
|
exit();
|
88
|
}
|
89
|
}
|
90
|
|
91
|
// Dummy class to allow modules' install scripts to call $admin->print_error
|
92
|
class admin_dummy
|
93
|
{
|
94
|
var $error='';
|
95
|
function print_error($message)
|
96
|
{
|
97
|
$this->error=$message;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
// Function to workout what the default permissions are for files created by the webserver
|
102
|
function default_file_mode($temp_dir) {
|
103
|
$v = explode(".",PHP_VERSION);
|
104
|
$v = $v[0].$v[1];
|
105
|
if($v > 41 AND is_writable($temp_dir)) {
|
106
|
$filename = $temp_dir.'/test_permissions.txt';
|
107
|
$handle = fopen($filename, 'w');
|
108
|
fwrite($handle, 'This file is to get the default file permissions');
|
109
|
fclose($handle);
|
110
|
$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
|
111
|
unlink($filename);
|
112
|
} else {
|
113
|
$default_file_mode = '0777';
|
114
|
}
|
115
|
return $default_file_mode;
|
116
|
}
|
117
|
|
118
|
// Function to workout what the default permissions are for directories created by the webserver
|
119
|
function default_dir_mode($temp_dir) {
|
120
|
$v = explode(".",PHP_VERSION);
|
121
|
$v = $v[0].$v[1];
|
122
|
if($v > 41 AND is_writable($temp_dir)) {
|
123
|
$dirname = $temp_dir.'/test_permissions/';
|
124
|
mkdir($dirname);
|
125
|
$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
|
126
|
rmdir($dirname);
|
127
|
} else {
|
128
|
$default_dir_mode = '0777';
|
129
|
}
|
130
|
return $default_dir_mode;
|
131
|
}
|
132
|
|
133
|
function add_slashes($input) {
|
134
|
if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
135
|
return $input;
|
136
|
}
|
137
|
$output = addslashes($input);
|
138
|
return $output;
|
139
|
}
|
140
|
|
141
|
// Begin check to see if form was even submitted
|
142
|
// Set error if no post vars found
|
143
|
if(!isset($_POST['website_title'])) {
|
144
|
set_error('Please fill-in the form below');
|
145
|
}
|
146
|
// End check to see if form was even submitted
|
147
|
|
148
|
// Begin path and timezone details code
|
149
|
|
150
|
// Check if user has entered the installation url
|
151
|
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
|
152
|
set_error('Please enter an absolute URL', 'wb_url');
|
153
|
} else {
|
154
|
$wb_url = $_POST['wb_url'];
|
155
|
}
|
156
|
// Remove any slashes at the end of the URL
|
157
|
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
|
158
|
$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
|
159
|
}
|
160
|
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
|
161
|
$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
|
162
|
}
|
163
|
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
|
164
|
$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
|
165
|
}
|
166
|
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
|
167
|
$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
|
168
|
}
|
169
|
// Get the default time zone
|
170
|
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
|
171
|
set_error('Please select a valid default timezone', 'default_timezone');
|
172
|
} else {
|
173
|
$default_timezone = $_POST['default_timezone']*60*60;
|
174
|
}
|
175
|
// End path and timezone details code
|
176
|
|
177
|
// Get the default language
|
178
|
$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE', 'TR');
|
179
|
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
|
180
|
set_error('Please select a valid default backend language','default_language');
|
181
|
} else {
|
182
|
$default_language = $_POST['default_language'];
|
183
|
// make sure the selected language file exists in the language folder
|
184
|
if(!file_exists('../languages/' .$default_language .'.php')) {
|
185
|
set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
|
186
|
}
|
187
|
}
|
188
|
// End default language details code
|
189
|
|
190
|
// Begin operating system specific code
|
191
|
// Get operating system
|
192
|
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
|
193
|
set_error('Please select a valid operating system');
|
194
|
} else {
|
195
|
$operating_system = $_POST['operating_system'];
|
196
|
}
|
197
|
// Work-out file permissions
|
198
|
if($operating_system == 'windows') {
|
199
|
$file_mode = '0777';
|
200
|
$dir_mode = '0777';
|
201
|
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
|
202
|
$file_mode = '0777';
|
203
|
$dir_mode = '0777';
|
204
|
} else {
|
205
|
$file_mode = default_file_mode('../temp');
|
206
|
$dir_mode = default_dir_mode('../temp');
|
207
|
}
|
208
|
// End operating system specific code
|
209
|
|
210
|
// Begin database details code
|
211
|
// Check if user has entered a database host
|
212
|
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
|
213
|
set_error('Please enter a database host name', 'database_host');
|
214
|
} else {
|
215
|
$database_host = $_POST['database_host'];
|
216
|
}
|
217
|
// Check if user has entered a database username
|
218
|
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
|
219
|
set_error('Please enter a database username','database_username');
|
220
|
} else {
|
221
|
$database_username = $_POST['database_username'];
|
222
|
}
|
223
|
// Check if user has entered a database password
|
224
|
if(!isset($_POST['database_password'])) {
|
225
|
set_error('Please enter a database password', 'database_password');
|
226
|
} else {
|
227
|
$database_password = $_POST['database_password'];
|
228
|
}
|
229
|
// Check if user has entered a database name
|
230
|
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
|
231
|
set_error('Please enter a database name', 'database_name');
|
232
|
} else {
|
233
|
// make sure only allowed characters are specified
|
234
|
if(preg_match('/[^a-z0-9_-]+/i', $_POST['database_name'])) {
|
235
|
// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
|
236
|
set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
|
237
|
}
|
238
|
$database_name = $_POST['database_name'];
|
239
|
}
|
240
|
// Get table prefix
|
241
|
if(preg_match('/[^a-z0-9_]+/i', $_POST['table_prefix'])) {
|
242
|
// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
|
243
|
set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
|
244
|
} else {
|
245
|
$table_prefix = $_POST['table_prefix'];
|
246
|
}
|
247
|
|
248
|
// Find out if the user wants to install tables and data
|
249
|
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
|
250
|
$install_tables = true;
|
251
|
} else {
|
252
|
$install_tables = false;
|
253
|
}
|
254
|
// End database details code
|
255
|
|
256
|
// Begin website title code
|
257
|
// Get website title
|
258
|
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
|
259
|
set_error('Please enter a website title', 'website_title');
|
260
|
} else {
|
261
|
$website_title = add_slashes($_POST['website_title']);
|
262
|
}
|
263
|
// End website title code
|
264
|
|
265
|
// Begin admin user details code
|
266
|
// Get admin username
|
267
|
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
|
268
|
set_error('Please enter a username for the Administrator account','admin_username');
|
269
|
} else {
|
270
|
$admin_username = $_POST['admin_username'];
|
271
|
}
|
272
|
// Get admin email and validate it
|
273
|
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
|
274
|
set_error('Please enter an email for the Administrator account','admin_email');
|
275
|
} else {
|
276
|
if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['admin_email'])) {
|
277
|
$admin_email = $_POST['admin_email'];
|
278
|
} else {
|
279
|
set_error('Please enter a valid email address for the Administrator account','admin_email');
|
280
|
}
|
281
|
}
|
282
|
// Get the two admin passwords entered, and check that they match
|
283
|
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
|
284
|
set_error('Please enter a password for the Administrator account','admin_password');
|
285
|
} else {
|
286
|
$admin_password = $_POST['admin_password'];
|
287
|
}
|
288
|
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
|
289
|
set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
|
290
|
} else {
|
291
|
$admin_repassword = $_POST['admin_repassword'];
|
292
|
}
|
293
|
if($admin_password != $admin_repassword) {
|
294
|
set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
|
295
|
}
|
296
|
// End admin user details code
|
297
|
|
298
|
// Try and write settings to config file
|
299
|
$config_content = "" .
|
300
|
"<?php\n".
|
301
|
"\n".
|
302
|
"define('DB_TYPE', 'mysql');\n".
|
303
|
"define('DB_HOST', '$database_host');\n".
|
304
|
"define('DB_USERNAME', '$database_username');\n".
|
305
|
"define('DB_PASSWORD', '$database_password');\n".
|
306
|
"define('DB_NAME', '$database_name');\n".
|
307
|
"define('TABLE_PREFIX', '$table_prefix');\n".
|
308
|
"\n".
|
309
|
"define('WB_PATH', dirname(__FILE__));\n".
|
310
|
"define('WB_URL', '$wb_url');\n".
|
311
|
"define('ADMIN_PATH', WB_PATH.'/admin');\n".
|
312
|
"define('ADMIN_URL', '$wb_url/admin');\n".
|
313
|
"\n".
|
314
|
"require_once(WB_PATH.'/framework/initialize.php');\n".
|
315
|
"\n".
|
316
|
"?>";
|
317
|
|
318
|
$config_filename = '../config.php';
|
319
|
|
320
|
// Check if the file exists and is writable first.
|
321
|
if(file_exists($config_filename) AND is_writable($config_filename)) {
|
322
|
if(!$handle = fopen($config_filename, 'w')) {
|
323
|
set_error("Cannot open the configuration file ($config_filename)");
|
324
|
} else {
|
325
|
if (fwrite($handle, $config_content) === FALSE) {
|
326
|
set_error("Cannot write to the configuration file ($config_filename)");
|
327
|
}
|
328
|
// Close file
|
329
|
fclose($handle);
|
330
|
}
|
331
|
} else {
|
332
|
set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
|
333
|
}
|
334
|
|
335
|
// Define configuration vars
|
336
|
define('DB_TYPE', 'mysql');
|
337
|
define('DB_HOST', $database_host);
|
338
|
define('DB_USERNAME', $database_username);
|
339
|
define('DB_PASSWORD', $database_password);
|
340
|
define('DB_NAME', $database_name);
|
341
|
define('TABLE_PREFIX', $table_prefix);
|
342
|
define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
|
343
|
define('WB_URL', $wb_url);
|
344
|
define('ADMIN_PATH', WB_PATH.'/admin');
|
345
|
define('ADMIN_URL', $wb_url.'/admin');
|
346
|
|
347
|
// Check if the user has entered a correct path
|
348
|
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
|
349
|
set_error('It appears the Absolute path that you entered is incorrect');
|
350
|
}
|
351
|
|
352
|
// Try connecting to database
|
353
|
if(!@mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
|
354
|
set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
|
355
|
}
|
356
|
|
357
|
// Try to create the database
|
358
|
mysql_query('CREATE DATABASE `'.$database_name.'`');
|
359
|
|
360
|
// Close the mysql connection
|
361
|
mysql_close();
|
362
|
|
363
|
// Include WB functions file
|
364
|
require_once(WB_PATH.'/framework/functions.php');
|
365
|
|
366
|
// Re-connect to the database, this time using in-build database class
|
367
|
require_once(WB_PATH.'/framework/class.login.php');
|
368
|
$database=new database();
|
369
|
|
370
|
// Check if we should install tables
|
371
|
if($install_tables == true) {
|
372
|
if (!defined('WB_INSTALL_PROCESS')) define ('WB_INSTALL_PROCESS', true);
|
373
|
// Remove tables if they exist
|
374
|
|
375
|
// Pages table
|
376
|
$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
|
377
|
$database->query($pages);
|
378
|
// Sections table
|
379
|
$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
|
380
|
$database->query($sections);
|
381
|
// Settings table
|
382
|
$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
|
383
|
$database->query($settings);
|
384
|
// Users table
|
385
|
$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
|
386
|
$database->query($users);
|
387
|
// Groups table
|
388
|
$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
|
389
|
$database->query($groups);
|
390
|
// Search table
|
391
|
$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
|
392
|
$database->query($search);
|
393
|
// Addons table
|
394
|
$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
|
395
|
$database->query($addons);
|
396
|
|
397
|
// Try installing tables
|
398
|
|
399
|
// Pages table
|
400
|
$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
|
401
|
. ' `parent` INT NOT NULL DEFAULT \'0\','
|
402
|
. ' `root_parent` INT NOT NULL DEFAULT \'0\','
|
403
|
. ' `level` INT NOT NULL DEFAULT \'0\','
|
404
|
. ' `link` TEXT NOT NULL,'
|
405
|
. ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
|
406
|
. ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
407
|
. ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
408
|
. ' `description` TEXT NOT NULL ,'
|
409
|
. ' `keywords` TEXT NOT NULL ,'
|
410
|
. ' `page_trail` TEXT NOT NULL ,'
|
411
|
. ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
412
|
. ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
413
|
. ' `position` INT NOT NULL DEFAULT \'0\','
|
414
|
. ' `menu` INT NOT NULL DEFAULT \'0\','
|
415
|
. ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
|
416
|
. ' `searching` INT NOT NULL DEFAULT \'0\','
|
417
|
. ' `admin_groups` TEXT NOT NULL ,'
|
418
|
. ' `admin_users` TEXT NOT NULL ,'
|
419
|
. ' `viewing_groups` TEXT NOT NULL ,'
|
420
|
. ' `viewing_users` TEXT NOT NULL ,'
|
421
|
. ' `modified_when` INT NOT NULL DEFAULT \'0\','
|
422
|
. ' `modified_by` INT NOT NULL DEFAULT \'0\','
|
423
|
. ' PRIMARY KEY ( `page_id` ) '
|
424
|
. ' )';
|
425
|
$database->query($pages);
|
426
|
|
427
|
// Sections table
|
428
|
$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
|
429
|
. ' `page_id` INT NOT NULL DEFAULT \'0\','
|
430
|
. ' `position` INT NOT NULL DEFAULT \'0\','
|
431
|
. ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
432
|
. ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
433
|
. ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
|
434
|
. ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
|
435
|
. ' PRIMARY KEY ( `section_id` ) '
|
436
|
. ' )';
|
437
|
$database->query($pages);
|
438
|
|
439
|
require(ADMIN_PATH.'/interface/version.php');
|
440
|
|
441
|
// Settings table
|
442
|
$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
|
443
|
. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
444
|
. ' `value` TEXT NOT NULL ,'
|
445
|
. ' PRIMARY KEY ( `setting_id` ) '
|
446
|
. ' )';
|
447
|
$database->query($settings);
|
448
|
|
449
|
$settings_rows= "INSERT INTO `".TABLE_PREFIX."settings` "
|
450
|
." (name, value) VALUES "
|
451
|
." ('wb_version', '".VERSION."'),"
|
452
|
." ('website_title', '$website_title'),"
|
453
|
." ('website_description', ''),"
|
454
|
." ('website_keywords', ''),"
|
455
|
." ('website_header', ''),"
|
456
|
." ('website_footer', ''),"
|
457
|
." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
|
458
|
." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
|
459
|
." ('er_level', ''),"
|
460
|
." ('default_language', '$default_language'),"
|
461
|
." ('app_name', 'wb_$session_rand'),"
|
462
|
." ('sec_anchor', 'wb_'),"
|
463
|
." ('default_timezone', '$default_timezone'),"
|
464
|
." ('default_date_format', 'M d Y'),"
|
465
|
." ('default_time_format', 'g:i A'),"
|
466
|
." ('redirect_timer', '1500'),"
|
467
|
." ('home_folders', 'true'),"
|
468
|
." ('default_template', 'round'),"
|
469
|
." ('default_theme', 'wb_theme'),"
|
470
|
." ('default_charset', 'utf-8'),"
|
471
|
." ('multiple_menus', 'false'),"
|
472
|
." ('page_level_limit', '4'),"
|
473
|
." ('intro_page', 'false'),"
|
474
|
." ('page_trash', 'disabled'),"
|
475
|
." ('homepage_redirection', 'false'),"
|
476
|
." ('page_languages', 'false'),"
|
477
|
." ('wysiwyg_editor', 'fckeditor'),"
|
478
|
." ('manage_sections', 'true'),"
|
479
|
." ('section_blocks', 'false'),"
|
480
|
." ('smart_login', 'false'),"
|
481
|
." ('frontend_login', 'false'),"
|
482
|
." ('frontend_signup', 'false'),"
|
483
|
." ('search', 'public'),"
|
484
|
." ('page_extension', '.php'),"
|
485
|
." ('page_spacer', '-'),"
|
486
|
." ('pages_directory', '/pages'),"
|
487
|
." ('media_directory', '/media'),"
|
488
|
." ('operating_system', '$operating_system'),"
|
489
|
." ('string_file_mode', '$file_mode'),"
|
490
|
." ('string_dir_mode', '$dir_mode'),"
|
491
|
." ('wbmailer_routine', 'phpmail'),"
|
492
|
." ('server_email', 'admin@yourdomain.com')," // avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
|
493
|
." ('wbmailer_default_sendername', 'WB Mailer'),"
|
494
|
." ('wbmailer_smtp_host', ''),"
|
495
|
." ('wbmailer_smtp_auth', ''),"
|
496
|
." ('wbmailer_smtp_username', ''),"
|
497
|
." ('wbmailer_smtp_password', ''),"
|
498
|
." ('mediasettings', '')";
|
499
|
$database->query($settings_rows);
|
500
|
|
501
|
// Users table
|
502
|
$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
|
503
|
. ' `group_id` INT NOT NULL DEFAULT \'0\','
|
504
|
. ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
|
505
|
. ' `active` INT NOT NULL DEFAULT \'0\','
|
506
|
. ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
507
|
. ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
508
|
. ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
|
509
|
. ' `last_reset` INT NOT NULL DEFAULT \'0\','
|
510
|
. ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
511
|
. ' `email` TEXT NOT NULL ,'
|
512
|
. ' `timezone` INT NOT NULL DEFAULT \'0\','
|
513
|
. ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
514
|
. ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
515
|
. ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'' .$default_language .'\' ,'
|
516
|
. ' `home_folder` TEXT NOT NULL ,'
|
517
|
. ' `login_when` INT NOT NULL DEFAULT \'0\','
|
518
|
. ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
|
519
|
. ' PRIMARY KEY ( `user_id` ) '
|
520
|
. ' )';
|
521
|
$database->query($users);
|
522
|
|
523
|
// Groups table
|
524
|
$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
|
525
|
. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
526
|
. ' `system_permissions` TEXT NOT NULL ,'
|
527
|
. ' `module_permissions` TEXT NOT NULL ,'
|
528
|
. ' `template_permissions` TEXT NOT NULL ,'
|
529
|
. ' PRIMARY KEY ( `group_id` ) '
|
530
|
. ' )';
|
531
|
$database->query($groups);
|
532
|
|
533
|
// Search settings table
|
534
|
$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
|
535
|
. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
536
|
. ' `value` TEXT NOT NULL ,'
|
537
|
. ' `extra` TEXT NOT NULL ,'
|
538
|
. ' PRIMARY KEY ( `search_id` ) '
|
539
|
. ' )';
|
540
|
$database->query($search);
|
541
|
|
542
|
// Addons table
|
543
|
$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
|
544
|
.'`addon_id` INT NOT NULL auto_increment ,'
|
545
|
.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
546
|
.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
547
|
.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
548
|
.'`description` TEXT NOT NULL ,'
|
549
|
.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
550
|
.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
551
|
.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
552
|
.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
553
|
.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
|
554
|
.' PRIMARY KEY ( `addon_id` ) '
|
555
|
.' )';
|
556
|
$database->query($addons);
|
557
|
|
558
|
// Insert default data
|
559
|
|
560
|
// Admin group
|
561
|
$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
|
562
|
$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
|
563
|
$database->query($insert_admin_group);
|
564
|
// Admin user
|
565
|
$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,groups_id,active,username,password,email,display_name) VALUES ('1','1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
|
566
|
$database->query($insert_admin_user);
|
567
|
|
568
|
// Search header
|
569
|
$search_header = addslashes('
|
570
|
<h1>[TEXT_SEARCH]</h1>
|
571
|
|
572
|
<form name="search" action="[WB_URL]/search/index.php" method="get">
|
573
|
<table cellpadding="3" cellspacing="0" border="0" width="500">
|
574
|
<tr>
|
575
|
<td>
|
576
|
<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
|
577
|
<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
|
578
|
</td>
|
579
|
<td width="150">
|
580
|
<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
|
581
|
</td>
|
582
|
</tr>
|
583
|
<tr>
|
584
|
<td colspan="2">
|
585
|
<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
|
586
|
<label for="match_all">[TEXT_ALL_WORDS]</label>
|
587
|
<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
|
588
|
<label for="match_any">[TEXT_ANY_WORDS]</label>
|
589
|
<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
|
590
|
<label for="match_exact">[TEXT_EXACT_MATCH]</label>
|
591
|
</td>
|
592
|
</tr>
|
593
|
</table>
|
594
|
|
595
|
</form>
|
596
|
|
597
|
<hr />
|
598
|
');
|
599
|
$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
|
600
|
$database->query($insert_search_header);
|
601
|
// Search footer
|
602
|
$search_footer = addslashes('');
|
603
|
$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
|
604
|
$database->query($insert_search_footer);
|
605
|
// Search results header
|
606
|
$search_results_header = addslashes(''.
|
607
|
'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
|
608
|
<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
|
609
|
$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
|
610
|
$database->query($insert_search_results_header);
|
611
|
// Search results loop
|
612
|
$search_results_loop = addslashes(''.
|
613
|
'<tr style="background-color: #F0F0F0;">
|
614
|
<td><a href="[LINK]">[TITLE]</a></td>
|
615
|
<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
|
616
|
</tr>
|
617
|
<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
|
618
|
<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
|
619
|
|
620
|
$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
|
621
|
$database->query($insert_search_results_loop);
|
622
|
// Search results footer
|
623
|
$search_results_footer = addslashes("</table>");
|
624
|
$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
|
625
|
$database->query($insert_search_results_footer);
|
626
|
// Search no results
|
627
|
$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
|
628
|
$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
|
629
|
$database->query($insert_search_no_results);
|
630
|
// Search module-order
|
631
|
$search_module_order = addslashes('faqbaker,manual,wysiwyg');
|
632
|
$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
|
633
|
$database->query($insert_search_module_order);
|
634
|
// Search max lines of excerpt
|
635
|
$search_max_excerpt = addslashes('15');
|
636
|
$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
|
637
|
$database->query($insert_search_max_excerpt);
|
638
|
// max time to search per module
|
639
|
$search_time_limit = addslashes('0');
|
640
|
$insert_search_time_limit = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'time_limit', '$search_time_limit', '')";
|
641
|
$database->query($insert_search_time_limit);
|
642
|
// some config-elements
|
643
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
|
644
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
|
645
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
|
646
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
|
647
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_flush', 'false', '')");
|
648
|
// Search template
|
649
|
$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
|
650
|
|
651
|
require_once(WB_PATH.'/framework/initialize.php');
|
652
|
|
653
|
// Include the PclZip class file (thanks to
|
654
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
655
|
|
656
|
// Install add-ons
|
657
|
if(file_exists(WB_PATH.'/install/modules')) {
|
658
|
// Unpack pre-packaged modules
|
659
|
|
660
|
}
|
661
|
if(file_exists(WB_PATH.'/install/templates')) {
|
662
|
// Unpack pre-packaged templates
|
663
|
|
664
|
}
|
665
|
if(file_exists(WB_PATH.'/install/languages')) {
|
666
|
// Unpack pre-packaged languages
|
667
|
|
668
|
}
|
669
|
|
670
|
$admin=new admin_dummy();
|
671
|
// Load addons into DB
|
672
|
$dirs['modules'] = WB_PATH.'/modules/';
|
673
|
$dirs['templates'] = WB_PATH.'/templates/';
|
674
|
$dirs['languages'] = WB_PATH.'/languages/';
|
675
|
foreach($dirs AS $type => $dir) {
|
676
|
if($handle = opendir($dir)) {
|
677
|
while(false !== ($file = readdir($handle))) {
|
678
|
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
|
679
|
// Get addon type
|
680
|
if($type == 'modules') {
|
681
|
load_module($dir.'/'.$file, true);
|
682
|
// Pretty ugly hack to let modules run $admin->set_error
|
683
|
// See dummy class definition admin_dummy above
|
684
|
if ($admin->error!='') {
|
685
|
set_error($admin->error);
|
686
|
}
|
687
|
} elseif($type == 'templates') {
|
688
|
load_template($dir.'/'.$file);
|
689
|
} elseif($type == 'languages') {
|
690
|
load_language($dir.'/'.$file);
|
691
|
}
|
692
|
}
|
693
|
}
|
694
|
closedir($handle);
|
695
|
}
|
696
|
}
|
697
|
|
698
|
// Check if there was a database error
|
699
|
if($database->is_error()) {
|
700
|
set_error($database->get_error());
|
701
|
}
|
702
|
|
703
|
// end of if install_tables
|
704
|
} else {
|
705
|
/**
|
706
|
* DB - Exists
|
707
|
* Tables also?
|
708
|
*
|
709
|
*/
|
710
|
$requested_tables = array("pages","sections","settings","users","groups","search","addons");
|
711
|
for($i=0;$i<count($requested_tables);$i++) $requested_tables[$i] = $table_prefix.$requested_tables[$i];
|
712
|
|
713
|
$result = mysql_list_tables( DB_NAME );
|
714
|
$all_tables = array();
|
715
|
for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i);
|
716
|
|
717
|
$missing_tables = array();
|
718
|
foreach($requested_tables as $temp_table) {
|
719
|
if (!in_array($temp_table, $all_tables)) {
|
720
|
$missing_tables[] = $temp_table;
|
721
|
}
|
722
|
}
|
723
|
|
724
|
/**
|
725
|
* If one or more needed tables are missing, so
|
726
|
* we can't go on and have to display an error
|
727
|
*/
|
728
|
if ( count($missing_tables) > 0 ) {
|
729
|
$error_message = "One or more tables are missing in the selected database <b><font color='#990000'>".DB_NAME."</font></b>.<br />";
|
730
|
$error_message .= "Please install the missing tables or choose 'install tables' as recommend.<br />";
|
731
|
$error_message .= "Missing tables are: <b>".implode(", ", $missing_tables)."</b>";
|
732
|
|
733
|
set_error( $error_message );
|
734
|
}
|
735
|
|
736
|
/**
|
737
|
* Try to get some default settings ...
|
738
|
*/
|
739
|
$vars = array(
|
740
|
'DEFAULT_THEME' => "wb_theme",
|
741
|
'THEME_URL' => WB_URL."/templates/wb_theme",
|
742
|
'THEME_PATH' => WB_PATH."/templates/wb_theme",
|
743
|
'LANGUAGE' => $_POST['default_language'],
|
744
|
'SERVER_EMAIL' => "admin@yourdomain.com",
|
745
|
'SMART_LOGIN' => false
|
746
|
);
|
747
|
foreach($vars as $k => $v) if (!defined($k)) define($k, $v);
|
748
|
|
749
|
if (!isset($MESSAGE)) include (WB_PATH."/languages/".LANGUAGE.".php");
|
750
|
|
751
|
/**
|
752
|
* The important part ...
|
753
|
* Is there an valid user?
|
754
|
*/
|
755
|
$result = $database->query("SELECT * from ".$table_prefix."users where username='".$_POST['admin_username']."'");
|
756
|
if ( $database->is_error() ) {
|
757
|
set_error ($database->get_error() );
|
758
|
}
|
759
|
if ($result->numRows() == 0) {
|
760
|
/**
|
761
|
* No matches found ... user properly unknown
|
762
|
*/
|
763
|
set_error ("Unkown user. Please use a valid username.");
|
764
|
} else {
|
765
|
|
766
|
$data = $result->fetchRow();
|
767
|
/**
|
768
|
* Does the password match
|
769
|
*/
|
770
|
if ( md5($_POST['admin_password']) != $data['password']) {
|
771
|
set_error ("Password didn't match");
|
772
|
}
|
773
|
}
|
774
|
}
|
775
|
// Log the user in and go to Website Baker Administration
|
776
|
$thisApp = new Login(
|
777
|
array(
|
778
|
"MAX_ATTEMPS" => "50",
|
779
|
"WARNING_URL" => ADMIN_URL."/login/warning.html",
|
780
|
"USERNAME_FIELDNAME" => 'admin_username',
|
781
|
"PASSWORD_FIELDNAME" => 'admin_password',
|
782
|
"REMEMBER_ME_OPTION" => SMART_LOGIN,
|
783
|
"MIN_USERNAME_LEN" => "2",
|
784
|
"MIN_PASSWORD_LEN" => "2",
|
785
|
"MAX_USERNAME_LEN" => "30",
|
786
|
"MAX_PASSWORD_LEN" => "30",
|
787
|
'LOGIN_URL' => ADMIN_URL."/login/index.php",
|
788
|
'DEFAULT_URL' => ADMIN_URL."/start/index.php",
|
789
|
'TEMPLATE_DIR' => ADMIN_PATH."/login",
|
790
|
'TEMPLATE_FILE' => "template.html",
|
791
|
'FRONTEND' => false,
|
792
|
'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
|
793
|
'USERS_TABLE' => TABLE_PREFIX."users",
|
794
|
'GROUPS_TABLE' => TABLE_PREFIX."groups",
|
795
|
)
|
796
|
);
|
797
|
?>
|