Project

General

Profile

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