Project

General

Profile

1 552 thorn
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, 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
26 582 thorn
// Start a session
27 552 thorn
if(!defined('SESSION_STARTED')) {
28 582 thorn
	session_name('wb_session_id');
29 552 thorn
	session_start();
30 582 thorn
	define('SESSION_STARTED', true);
31
}
32
// get random-part for session_name()
33
list($usec,$sec) = explode(' ',microtime());
34
srand((float)$sec+((float)$usec*100000));
35
$session_rand = rand(1000,9999);
36 552 thorn
37
// Function to set error
38
function set_error($message) {
39
	global $_POST;
40
	if(isset($message) AND $message != '') {
41
		// Copy values entered into session so user doesn't have to re-enter everything
42
		if(isset($_POST['website_title'])) {
43
			$_SESSION['wb_url'] = $_POST['wb_url'];
44
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
45
			if(!isset($_POST['operating_system'])) {
46
				$_SESSION['operating_system'] = 'linux';
47
			} else {
48
				$_SESSION['operating_system'] = $_POST['operating_system'];
49
			}
50
			if(!isset($_POST['world_writeable'])) {
51
				$_SESSION['world_writeable'] = false;
52
			} else {
53
				$_SESSION['world_writeable'] = true;
54
			}
55
			$_SESSION['database_host'] = $_POST['database_host'];
56
			$_SESSION['database_username'] = $_POST['database_username'];
57
			$_SESSION['database_password'] = $_POST['database_password'];
58
			$_SESSION['database_name'] = $_POST['database_name'];
59
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
60
			if(!isset($_POST['install_tables'])) {
61
				$_SESSION['install_tables'] = false;
62
			} else {
63
				$_SESSION['install_tables'] = true;
64
			}
65
			$_SESSION['website_title'] = $_POST['website_title'];
66
			$_SESSION['admin_username'] = $_POST['admin_username'];
67
			$_SESSION['admin_email'] = $_POST['admin_email'];
68
			$_SESSION['admin_password'] = $_POST['admin_password'];
69
		}
70
		// Set the message
71
		$_SESSION['message'] = $message;
72
		// Specify that session support is enabled
73
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
74
		// Redirect to first page again and exit
75
		header('Location: index.php?sessions_checked=true');
76
		exit();
77
	}
78
}
79
80
// Dummy class to allow modules' install scripts to call $admin->print_error
81
class admin_dummy
82
{
83
	var $error='';
84
	function print_error($message)
85
	{
86
		$this->error=$message;
87
	}
88
}
89
90
// Function to workout what the default permissions are for files created by the webserver
91
function default_file_mode($temp_dir) {
92
	$v = explode(".",PHP_VERSION);
93
	$v = $v[0].$v[1];
94
	if($v > 41 AND is_writable($temp_dir)) {
95
		$filename = $temp_dir.'/test_permissions.txt';
96
		$handle = fopen($filename, 'w');
97
		fwrite($handle, 'This file is to get the default file permissions');
98
		fclose($handle);
99
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
100
		unlink($filename);
101
	} else {
102
		$default_file_mode = '0777';
103
	}
104
	return $default_file_mode;
105
}
106
107
// Function to workout what the default permissions are for directories created by the webserver
108
function default_dir_mode($temp_dir) {
109
	$v = explode(".",PHP_VERSION);
110
	$v = $v[0].$v[1];
111
	if($v > 41 AND is_writable($temp_dir)) {
112
		$dirname = $temp_dir.'/test_permissions/';
113
		mkdir($dirname);
114
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
115
		rmdir($dirname);
116
	} else {
117
		$default_dir_mode = '0777';
118
	}
119
	return $default_dir_mode;
120
}
121
122
function add_slashes($input) {
123
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
124
			return $input;
125
		}
126
		$output = addslashes($input);
127
		return $output;
128
	}
129
130
// Begin check to see if form was even submitted
131
// Set error if no post vars found
132
if(!isset($_POST['website_title'])) {
133
	set_error('Please fill-in the form below');
134
}
135
// End check to see if form was even submitted
136
137
// Begin path and timezone details code
138
139
// Check if user has entered the installation url
140
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
141
	set_error('Please enter an absolute URL');
142
} else {
143
	$wb_url = $_POST['wb_url'];
144
}
145
// Remove any slashes at the end of the URL
146
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
147
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
148
}
149
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
150
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
151
}
152
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
153
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
154
}
155
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
156
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
157
}
158
// Get the default time zone
159
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
160
	set_error('Please select a valid default timezone');
161
} else {
162
	$default_timezone = $_POST['default_timezone']*60*60;
163
}
164
// End path and timezone details code
165
166
// Begin operating system specific code
167
// Get operating system
168
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
169
	set_error('Please select a valid operating system');
170
} else {
171
	$operating_system = $_POST['operating_system'];
172
}
173
// Work-out file permissions
174
if($operating_system == 'windows') {
175
	$file_mode = '0777';
176
	$dir_mode = '0777';
177
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
178
	$file_mode = '0777';
179
	$dir_mode = '0777';
180
} else {
181
	$file_mode = default_file_mode('../temp');
182
	$dir_mode = default_dir_mode('../temp');
183
}
184
// End operating system specific code
185
186
// Begin database details code
187
// Check if user has entered a database host
188
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
189
	set_error('Please enter a database host name');
190
} else {
191
	$database_host = $_POST['database_host'];
192
}
193
// Check if user has entered a database username
194
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
195
	set_error('Please enter a database username');
196
} else {
197
	$database_username = $_POST['database_username'];
198
}
199
// Check if user has entered a database password
200
if(!isset($_POST['database_password'])) {
201
	set_error('Please enter a database password');
202
} else {
203
	$database_password = $_POST['database_password'];
204
}
205
// Check if user has entered a database name
206
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
207
	set_error('Please enter a database name');
208
} else {
209
	$database_name = $_POST['database_name'];
210
}
211
// Get table prefix
212
$table_prefix = $_POST['table_prefix'];
213
// Find out if the user wants to install tables and data
214
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
215
	$install_tables = true;
216
} else {
217
	$install_tables = false;
218
}
219
// End database details code
220
221
// Begin website title code
222
// Get website title
223
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
224
	set_error('Please enter a website title');
225
} else {
226
	$website_title = add_slashes($_POST['website_title']);
227
}
228
// End website title code
229
230
// Begin admin user details code
231
// Get admin username
232
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
233
	set_error('Please enter a username for the Administrator account');
234
} else {
235
	$admin_username = $_POST['admin_username'];
236
}
237
// Get admin email and validate it
238
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
239
	set_error('Please enter an email for the Administrator account');
240
} else {
241
	if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['admin_email'])) {
242
		$admin_email = $_POST['admin_email'];
243
	} else {
244
		set_error('Please enter a valid email address for the Administrator account');
245
	}
246
}
247
// Get the two admin passwords entered, and check that they match
248
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
249
	set_error('Please enter a password for the Administrator account');
250
} else {
251
	$admin_password = $_POST['admin_password'];
252
}
253
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
254
	set_error('Please make sure you re-enter the password for the Administrator account');
255
} else {
256
	$admin_repassword = $_POST['admin_repassword'];
257
}
258
if($admin_password != $admin_repassword) {
259
	set_error('Sorry, the two Administrator account passwords you entered do not match');
260
}
261
// End admin user details code
262
263
// Try and write settings to config file
264
$config_content = "" .
265
"<?php\n".
266
"\n".
267
"define('DB_TYPE', 'mysql');\n".
268
"define('DB_HOST', '$database_host');\n".
269
"define('DB_USERNAME', '$database_username');\n".
270
"define('DB_PASSWORD', '$database_password');\n".
271
"define('DB_NAME', '$database_name');\n".
272
"define('TABLE_PREFIX', '$table_prefix');\n".
273
"\n".
274
"define('WB_PATH', dirname(__FILE__));\n".
275
"define('WB_URL', '$wb_url');\n".
276
"define('ADMIN_PATH', WB_PATH.'/admin');\n".
277
"define('ADMIN_URL', '$wb_url/admin');\n".
278
"\n".
279
"require_once(WB_PATH.'/framework/initialize.php');\n".
280
"\n".
281
"?>";
282
283
$config_filename = '../config.php';
284
285
// Check if the file exists and is writable first.
286
if(file_exists($config_filename) AND is_writable($config_filename)) {
287
	if(!$handle = fopen($config_filename, 'w')) {
288
		set_error("Cannot open the configuration file ($config_filename)");
289
	} else {
290
		if (fwrite($handle, $config_content) === FALSE) {
291
			set_error("Cannot write to the configuration file ($config_filename)");
292
		}
293
		// Close file
294
		fclose($handle);
295
	}
296
} else {
297
	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
298
}
299
300
// Define configuration vars
301
define('DB_TYPE', 'mysql');
302
define('DB_HOST', $database_host);
303
define('DB_USERNAME', $database_username);
304
define('DB_PASSWORD', $database_password);
305
define('DB_NAME', $database_name);
306
define('TABLE_PREFIX', $table_prefix);
307
define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
308
define('WB_URL', $wb_url);
309
define('ADMIN_PATH', WB_PATH.'/admin');
310
define('ADMIN_URL', $wb_url.'/admin');
311
312
// Check if the user has entered a correct path
313
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
314
	set_error('It appears the Absolute path that you entered is incorrect');
315
}
316
317
// Try connecting to database
318
if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
319
	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
320
}
321
322
// Try to create the database
323
mysql_query('CREATE DATABASE '.$database_name);
324
325
// Close the mysql connection
326
mysql_close();
327
328
// Include WB functions file
329
require_once(WB_PATH.'/framework/functions.php');
330
331
// Re-connect to the database, this time using in-build database class
332
require_once(WB_PATH.'/framework/class.login.php');
333
$database=new database();
334
335
// Check if we should install tables
336
if($install_tables == true) {
337
338
	// Remove tables if they exist
339
340
	// Pages table
341
	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
342
	$database->query($pages);
343
	// Sections table
344
	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
345
	$database->query($sections);
346
	// Settings table
347
	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
348
	$database->query($settings);
349
	// Users table
350
	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
351
	$database->query($users);
352
	// Groups table
353
	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
354
	$database->query($groups);
355
	// Search table
356
	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
357
	$database->query($search);
358
	// Addons table
359
	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
360
	$database->query($addons);
361
362
	// Try installing tables
363
364
	// Pages table
365
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
366
	       . ' `parent` INT NOT NULL DEFAULT \'0\','
367
	       . ' `root_parent` INT NOT NULL DEFAULT \'0\','
368
	       . ' `level` INT NOT NULL DEFAULT \'0\','
369
	       . ' `link` TEXT NOT NULL,'
370
	       . ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
371
	       . ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
372
	       . ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
373
	       . ' `description` TEXT NOT NULL ,'
374
	       . ' `keywords` TEXT NOT NULL ,'
375
	       . ' `page_trail` TEXT NOT NULL  ,'
376
	       . ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
377
	       . ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
378
	       . ' `position` INT NOT NULL DEFAULT \'0\','
379
	       . ' `menu` INT NOT NULL DEFAULT \'0\','
380
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
381
	       . ' `searching` INT NOT NULL DEFAULT \'0\','
382
	       . ' `admin_groups` TEXT NOT NULL ,'
383
	       . ' `admin_users` TEXT NOT NULL ,'
384
	       . ' `viewing_groups` TEXT NOT NULL ,'
385
	       . ' `viewing_users` TEXT NOT NULL ,'
386
	       . ' `modified_when` INT NOT NULL DEFAULT \'0\','
387
	       . ' `modified_by` INT NOT NULL  DEFAULT \'0\','
388
	       . ' PRIMARY KEY ( `page_id` ) '
389
	       . ' )';
390
	$database->query($pages);
391
392
	// Sections table
393
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
394
	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
395
	       . ' `position` INT NOT NULL DEFAULT \'0\','
396
	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
397
	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
398
	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
399
	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
400
	       . ' PRIMARY KEY ( `section_id` ) '
401
	       . ' )';
402
	$database->query($pages);
403
404
	require(WB_PATH.'/admin/interface/version.php');
405
406
	// Settings table
407
	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
408
		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
409
		. ' `value` TEXT NOT NULL ,'
410
		. ' PRIMARY KEY ( `setting_id` ) '
411
		. ' )';
412
	$database->query($settings);
413
414
	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
415
	." (name, value) VALUES "
416
	." ('wb_version', '".VERSION."'),"
417
	." ('website_title', '$website_title'),"
418
	." ('website_description', ''),"
419
	." ('website_keywords', ''),"
420
	." ('website_header', ''),"
421
	." ('website_footer', ''),"
422
	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
423
	." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
424
	." ('er_level', ''),"
425
	." ('default_language', 'EN'),"
426 581 thorn
	." ('app_name', 'wb_$session_rand'),"
427 552 thorn
	." ('default_timezone', '$default_timezone'),"
428
	." ('default_date_format', 'M d Y'),"
429
	." ('default_time_format', 'g:i A'),"
430
	." ('home_folders', 'true'),"
431
	." ('default_template', 'round'),"
432
	." ('default_charset', 'utf-8'),"
433
	." ('multiple_menus', 'false'),"
434
	." ('page_level_limit', '4'),"
435
	." ('intro_page', 'false'),"
436
	." ('page_trash', 'disabled'),"
437
	." ('homepage_redirection', 'false'),"
438
	." ('page_languages', 'false'),"
439
	." ('wysiwyg_editor', 'fckeditor'),"
440
	." ('manage_sections', 'true'),"
441
	." ('section_blocks', 'false'),"
442
	." ('smart_login', 'false'),"
443
	." ('captcha_verification', 'true'),"
444
	." ('frontend_login', 'false'),"
445
	." ('frontend_signup', 'false'),"
446
	." ('search', 'public'),"
447
	." ('page_extension', '.php'),"
448
	." ('page_spacer', '-'),"
449
	." ('pages_directory', '/pages'),"
450
	." ('media_directory', '/media'),"
451
	." ('operating_system', '$operating_system'),"
452
	." ('string_file_mode', '$file_mode'),"
453
	." ('string_dir_mode', '$dir_mode'),"
454
	." ('wbmailer_routine', 'phpmail'),"
455 568 doc
	." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
456
	." ('wbmailer_default_sendername', 'WB Mailer'),"
457 552 thorn
	." ('wbmailer_smtp_host', ''),"
458
	." ('wbmailer_smtp_auth', ''),"
459
	." ('wbmailer_smtp_username', ''),"
460
	." ('wbmailer_smtp_password', '')";
461
	$database->query($settings_rows);
462
463
	// Users table
464
	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
465
	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
466
	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
467
	       . ' `active` INT NOT NULL DEFAULT \'0\','
468
	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
469
	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
470
	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
471
	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
472
	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
473
	       . ' `email` TEXT NOT NULL ,'
474
	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
475
	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
476
	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
477
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
478
	       . ' `home_folder` TEXT NOT NULL ,'
479
	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
480
	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
481
	       . ' PRIMARY KEY ( `user_id` ) '
482
	       . ' )';
483
	$database->query($users);
484
485
	// Groups table
486
	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
487
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
488
	        . ' `system_permissions` TEXT NOT NULL ,'
489
	        . ' `module_permissions` TEXT NOT NULL ,'
490
	        . ' `template_permissions` TEXT NOT NULL ,'
491
	        . ' PRIMARY KEY ( `group_id` ) '
492
	        . ' )';
493
	$database->query($groups);
494
495
	// Search settings table
496
	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
497
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
498
	        . ' `value` TEXT NOT NULL ,'
499
	        . ' `extra` TEXT NOT NULL ,'
500
	        . ' PRIMARY KEY ( `search_id` ) '
501
	        . ' )';
502
	$database->query($search);
503
504
	// Addons table
505
	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
506
			.'`addon_id` INT NOT NULL auto_increment ,'
507
			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
508
			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
509
			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
510
			.'`description` TEXT NOT NULL ,'
511
			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
512
			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
513
			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
514
			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
515
			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
516
			.' PRIMARY KEY ( `addon_id` ) '
517
			.' )';
518
	$database->query($addons);
519
520
	// Insert default data
521
522
	// Admin group
523
	$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';
524
	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
525
	$database->query($insert_admin_group);
526
	// Admin user
527
	$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')";
528
	$database->query($insert_admin_user);
529
530
	// Search header
531
	$search_header = addslashes('
532
<h1>[TEXT_SEARCH]</h1>
533
534
<form name="search" action="[WB_URL]/search/index.php" method="get">
535
<table cellpadding="3" cellspacing="0" border="0" width="500">
536
<tr>
537
<td>
538
<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
539
<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
540
</td>
541
<td width="150">
542
<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
543
</td>
544
</tr>
545
<tr>
546
<td colspan="2">
547
<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
548
<label for="match_all">[TEXT_ALL_WORDS]</label>
549
<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
550
<label for="match_any">[TEXT_ANY_WORDS]</label>
551
<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
552
<label for="match_exact">[TEXT_EXACT_MATCH]</label>
553
</td>
554
</tr>
555
</table>
556
557
</form>
558
559
<hr />
560
	');
561
	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
562
	$database->query($insert_search_header);
563
	// Search footer
564
	$search_footer = addslashes('');
565
	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
566
	$database->query($insert_search_footer);
567
	// Search results header
568
	$search_results_header = addslashes(''.
569
'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
570
<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
571
	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
572
	$database->query($insert_search_results_header);
573
	// Search results loop
574
	$search_results_loop = addslashes(''.
575
'<tr style="background-color: #F0F0F0;">
576
<td><a href="[LINK]">[TITLE]</a></td>
577
<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
578
</tr>
579
<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
580
<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
581
582
	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
583
	$database->query($insert_search_results_loop);
584
	// Search results footer
585
	$search_results_footer = addslashes("</table>");
586
	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
587
	$database->query($insert_search_results_footer);
588
	// Search no results
589
	$search_no_results = addslashes('<br />[TEXT_NO_RESULTS]');
590
	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
591
	$database->query($insert_search_no_results);
592
	// Search module-order
593
	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
594
	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
595
	$database->query($insert_search_module_order);
596
	// Search max lines of excerpt
597
	$search_max_excerpt = addslashes('15');
598
	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
599
	$database->query($insert_search_max_excerpt);
600
	// some config-elements
601
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
602
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
603
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
604
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
605
	// Search template
606
	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
607
608
	require_once(WB_PATH.'/framework/initialize.php');
609
610
	// Include the PclZip class file (thanks to
611
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
612
613
	// Install add-ons
614
	if(file_exists(WB_PATH.'/install/modules')) {
615
		// Unpack pre-packaged modules
616
617
	}
618
	if(file_exists(WB_PATH.'/install/templates')) {
619
		// Unpack pre-packaged templates
620
621
	}
622
	if(file_exists(WB_PATH.'/install/languages')) {
623
		// Unpack pre-packaged languages
624
625
	}
626
627
	$admin=new admin_dummy();
628
	// Load addons into DB
629
	$dirs['modules'] = WB_PATH.'/modules/';
630
	$dirs['templates'] = WB_PATH.'/templates/';
631
	$dirs['languages'] = WB_PATH.'/languages/';
632
	foreach($dirs AS $type => $dir) {
633
		if($handle = opendir($dir)) {
634
			while(false !== ($file = readdir($handle))) {
635
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
636
					// Get addon type
637
					if($type == 'modules') {
638
						load_module($dir.'/'.$file, true);
639
						// Pretty ugly hack to let modules run $admin->set_error
640
						// See dummy class definition admin_dummy above
641
						if ($admin->error!='') {
642
							set_error($admin->error);
643
						}
644
					} elseif($type == 'templates') {
645
						load_template($dir.'/'.$file);
646
					} elseif($type == 'languages') {
647
						load_language($dir.'/'.$file);
648
					}
649
				}
650
			}
651
		closedir($handle);
652
		}
653
	}
654
655
	// Check if there was a database error
656
	if($database->is_error()) {
657
		set_error($database->get_error());
658
	}
659
660
}
661
662
// Log the user in and go to Website Baker Administration
663
$thisApp = new Login(
664
							array(
665
									"MAX_ATTEMPS" => "50",
666
									"WARNING_URL" => ADMIN_URL."/login/warning.html",
667
									"USERNAME_FIELDNAME" => 'admin_username',
668
									"PASSWORD_FIELDNAME" => 'admin_password',
669
									"REMEMBER_ME_OPTION" => SMART_LOGIN,
670
									"MIN_USERNAME_LEN" => "2",
671
									"MIN_PASSWORD_LEN" => "2",
672
									"MAX_USERNAME_LEN" => "30",
673
									"MAX_PASSWORD_LEN" => "30",
674
									'LOGIN_URL' => ADMIN_URL."/login/index.php",
675
									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
676
									'TEMPLATE_DIR' => ADMIN_PATH."/login",
677
									'TEMPLATE_FILE' => "template.html",
678
									'FRONTEND' => false,
679
									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
680
									'USERS_TABLE' => TABLE_PREFIX."users",
681
									'GROUPS_TABLE' => TABLE_PREFIX."groups",
682
							)
683
					);
684
?>