Project

General

Profile

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