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