Project

General

Profile

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