Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * save.php
21
 * 
22
 * @category     Core
23
 * @package      Core_Environment
24
 * @subpackage   Installer
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.2
29
 * @revision     $Revision: 1930 $
30
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/install/save.php $
31
 * @lastmodified $Date: 2013-07-09 13:01:09 +0200 (Tue, 09 Jul 2013) $
32
 * @since        File available since 2012-04-01
33
 * @description  xyz
34
 */
35

    
36
$debug = true;
37

    
38
include(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php'); 
39
include(dirname(dirname(__FILE__)).'/framework/WbAutoloader.php');
40
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m'));
41

    
42
function errorLogs($error_str)
43
{
44
	$log_error = true;
45
	if ( ! function_exists('error_log') ) { $log_error = false; }
46
	$log_file = @ini_get('error_log');
47
	if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) {
48
		$log_error = false;
49
	}
50
	if ( $log_error ) {@error_log($error_str, 0);}
51
}
52

    
53
/**
54
 * Read DB settings from configuration file
55
 * @return string
56
 * @throws RuntimeException
57
 * 
58
 */
59
	function _readConfiguration($sRetvalType = 'url') {
60
		// check for valid file request. Becomes more stronger in next version
61
		$x = debug_backtrace();
62
		$bValidRequest = false;
63
		if(sizeof($x) != 0) {
64
			foreach($x as $aStep) {
65
				// define the scripts which can read the configuration
66
				if(preg_match('/(save.php|index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
67
					$bValidRequest = true;
68
					break;
69
				}
70
			}
71
		}else {
72
			$bValidRequest = true;
73
		}
74
		if(!$bValidRequest) {
75
			throw new RuntimeException('illegal function request!'); 
76
		}
77
		$aRetval = array();
78
		$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
79
		if(is_readable($sSetupFile)) {
80
			$aCfg = parse_ini_file($sSetupFile, true);
81
			foreach($aCfg['Constants'] as $key=>$value) {
82
				switch($key):
83
					case 'DEBUG':
84
						$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
85
						break;
86
					case 'WB_URL':
87
					case 'AppUrl':
88
						$value = trim(str_replace('\\', '/', $value), '/'); 
89
						if(!defined('WB_URL')) { define('WB_URL', $value); }
90
						break;
91
					case 'ADMIN_DIRECTORY':
92
					case 'AcpDir':
93
						$value = trim(str_replace('\\', '/', $value), '/'); 
94
						if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
95
						break;
96
					default:
97
						if(!defined($key)) { define($key, $value); }
98
						break;
99
				endswitch;
100
			}
101
			$db = $aCfg['DataBase'];
102
			$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
103
			$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
104
			$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
105
			$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
106
			$db['port'] = isset($db['port']) ? $db['port'] : '3306';
107
			$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
108
			$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
109
			$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
110
			$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
111
			if(!defined('TABLE_PREFIX')) {define('TABLE_PREFIX', $db['table_prefix']);}
112
			if($sRetvalType == 'dsn') {
113
				$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';'
114
				            . ($db['port'] != '' ? 'port='.(int)$db['port'].';' : '');
115
				$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
116
				$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']);
117
			}else { // $sRetvalType == 'url'
118
				$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
119
				            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
120
				            . '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
121
			}
122
			unset($db, $aCfg);
123
			return $aRetval;
124
		}
125
		throw new RuntimeException('unable to read setup.ini.php');
126
	}
127

    
128
if (true === $debug) {
129
	ini_set('display_errors', 1);
130
	error_reporting(E_ALL);
131
}
132
// Start a session
133
if(!defined('SESSION_STARTED')) {
134
	session_name('wb_session_id');
135
	session_start();
136
	define('SESSION_STARTED', true);
137
}
138
// get random-part for session_name()
139
list($usec,$sec) = explode(' ',microtime());
140
srand((float)$sec+((float)$usec*100000));
141
$session_rand = rand(1000,9999);
142

    
143
// Function to set error
144
function set_error($message, $field_name = '') {
145
	global $_POST;
146
	if(isset($message) AND $message != '') {
147
		// Copy values entered into session so user doesn't have to re-enter everything
148
		if(isset($_POST['website_title'])) {
149
			$_SESSION['website_title'] = $_POST['website_title'];
150
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
151
			$_SESSION['default_language'] = $_POST['default_language'];
152
			if(!isset($_POST['operating_system'])) {
153
				$_SESSION['operating_system'] = 'linux';
154
			} else {
155
				$_SESSION['operating_system'] = $_POST['operating_system'];
156
			}
157
			if(!isset($_POST['world_writeable'])) {
158
				$_SESSION['world_writeable'] = false;
159
			} else {
160
				$_SESSION['world_writeable'] = true;
161
			}
162
			$_SESSION['database_host'] = $_POST['database_host'];
163
			$_SESSION['database_username'] = $_POST['database_username'];
164
			$_SESSION['database_password'] = '';
165
			$_SESSION['database_name'] = $_POST['database_name'];
166
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
167
			if(!isset($_POST['install_tables'])) {
168
				$_SESSION['install_tables'] = true;
169
			} else {
170
				$_SESSION['install_tables'] = true;
171
			}
172
			$_SESSION['website_title'] = $_POST['website_title'];
173
			$_SESSION['admin_username'] = $_POST['admin_username'];
174
			$_SESSION['admin_email'] = $_POST['admin_email'];
175
			$_SESSION['admin_password'] = '';
176
			$_SESSION['admin_repassword'] = '';
177
		}
178
		// Set the message
179
		$_SESSION['message'] = $message;
180
		// Set the element(s) to highlight
181
		if($field_name != '') {
182
			$_SESSION['ERROR_FIELD'] = $field_name;
183
		}
184
		// Specify that session support is enabled
185
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
186
		// Redirect to first page again and exit
187
		header('Location: index.php?sessions_checked=true');
188
		exit();
189
	}
190
}
191
/* */
192

    
193
// Function to workout what the default permissions are for files created by the webserver
194
function default_file_mode($temp_dir) {
195
	$v = explode(".",PHP_VERSION);
196
	$v = $v[0].$v[1];
197
	if($v > 41 AND is_writable($temp_dir)) {
198
		$filename = $temp_dir.'/test_permissions.txt';
199
		$handle = fopen($filename, 'w');
200
		fwrite($handle, 'This file is to get the default file permissions');
201
		fclose($handle);
202
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
203
		unlink($filename);
204
	} else {
205
		$default_file_mode = '0666';
206
	}
207
	return $default_file_mode;
208
}
209

    
210
// Function to workout what the default permissions are for directories created by the webserver
211
function default_dir_mode($temp_dir) {
212
	$v = explode(".",PHP_VERSION);
213
	$v = $v[0].$v[1];
214
	if($v > 41 AND is_writable($temp_dir)) {
215
		$dirname = $temp_dir.'/test_permissions/';
216
		mkdir($dirname);
217
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
218
		rmdir($dirname);
219
	} else {
220
		$default_dir_mode = '0777';
221
	}
222
	return $default_dir_mode;
223
}
224

    
225
function add_slashes($input) {
226
	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
227
		return $input;
228
	}
229
	$output = addslashes($input);
230
	return $output;
231
}
232

    
233
// Begin check to see if form was even submitted
234
// Set error if no post vars found
235
if(!isset($_POST['website_title'])) {
236
	set_error('Please fill-in the wesite title below');
237
}
238
// End check to see if form was even submitted
239

    
240
// Begin path and timezone details code
241

    
242
// Check if user has entered the installation url
243
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
244
	set_error('Please enter an absolute URL', 'wb_url');
245
} else {
246
	$wb_url = $_POST['wb_url'];
247
}
248
// Remove any slashes at the end of the URL
249
$wb_url = trim(str_replace('\\', '/', $wb_url), '/').'/';
250
// Get the default time zone
251
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
252
	set_error('Please select a valid default timezone', 'default_timezone');
253
} else {
254
	$default_timezone = $_POST['default_timezone']*60*60;
255
}
256
// End path and timezone details code
257

    
258
// Get the default language
259
$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');
260
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
261
	set_error('Please select a valid default backend language','default_language');
262
} else {
263
	$default_language = $_POST['default_language'];
264
	// make sure the selected language file exists in the language folder
265
	if(!file_exists('../languages/' .$default_language .'.php')) {
266
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
267
	}
268
}
269
// End default language details code
270

    
271
// Begin operating system specific code
272
// Get operating system
273
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
274
	set_error('Please select a valid operating system');
275
} else {
276
	$operating_system = $_POST['operating_system'];
277
}
278
// Work-out file permissions
279
if($operating_system == 'windows') {
280
	$file_mode = '0777';
281
	$dir_mode = '0777';
282
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
283
	$file_mode = '0777';
284
	$dir_mode = '0777';
285
} else {
286
	$file_mode = default_file_mode('../temp');
287
	$dir_mode = default_dir_mode('../temp');
288
}
289
// End operating system specific code
290

    
291
// Begin database details code
292
// Check if user has entered a database host
293
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
294
	set_error('Please enter a database host name', 'database_host');
295
} else {
296
	$database_host = $_POST['database_host'];
297
 }
298
// Check if user has entered a database name
299
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
300
	set_error('Please enter a database name', 'database_name');
301
} else {
302
	// make sure only allowed characters are specified
303
	if(!preg_match('/^[a-z0-9_-]*$/i', $_POST['database_name'])) {
304
		// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
305
		set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
306
	}
307
	$database_name = $_POST['database_name'];
308
}
309
// Get table prefix
310
if(!preg_match('/^[a-z0-9_]*$/i', $_POST['table_prefix'])) {
311
	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
312
	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
313
} else {
314
	$table_prefix = $_POST['table_prefix'];
315
}
316

    
317
// Check if user has entered a database username
318
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
319
	set_error('Please enter a database username','database_username');
320
} else {
321
	$database_username = $_POST['database_username'];
322
}
323
// Check if user has entered a database password
324
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
325
	set_error('Please enter a database password', 'database_password');
326
} else {
327
	$database_password = $_POST['database_password'];
328
}
329

    
330
// Find out if the user wants to install tables and data
331
$install_tables = ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
332
// End database details code
333

    
334
// Begin website title code
335
// Get website title
336
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
337
	set_error('Please enter a website title', 'website_title');
338
} else {
339
	$website_title = add_slashes($_POST['website_title']);
340
}
341
// End website title code
342

    
343
// Begin admin user details code
344
// Get admin username
345
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
346
	set_error('Please enter a username for the Administrator account','admin_username');
347
} else {
348
	$admin_username = $_POST['admin_username'];
349
}
350
// Get admin email and validate it
351
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
352
	set_error('Please enter an email for the Administrator account','admin_email');
353
} else {
354
	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
355
		$admin_email = $_POST['admin_email'];
356
	} else {
357
		set_error('Please enter a valid email address for the Administrator account','admin_email');
358
	}
359
}
360
// Get the two admin passwords entered, and check that they match
361
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
362
	set_error('Please enter a password for the Administrator account','admin_password');
363
} else {
364
	$admin_password = $_POST['admin_password'];
365
}
366
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
367
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
368
} else {
369
	$admin_repassword = $_POST['admin_repassword'];
370
}
371
if($admin_password != $admin_repassword) {
372
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
373
}
374
// End admin user details code
375

    
376
// Try and write settings to config file
377
$sConfigContent = 
378
 ";<?php die('sorry, illegal file access'); ?>#####\n"
379
.";################################################\n"
380
."; WebsiteBaker configuration file\n"
381
."; auto generated ".date('Y-m-d h:i:s A e ')."\n"
382
.";################################################\n"
383
."[Constants]\n"
384
."DEBUG   = false\n"
385
."AppUrl  = ".$wb_url."\n"
386
."AcpDir  = admin/\n"
387
.";##########\n"
388
."[DataBase]\n"
389
."type    = \"mysql\"\n"
390
."user    = \"".$database_username."\"\n"
391
."pass    = \"".$database_password."\"\n"
392
."host    = \"".$database_host."\"\n"
393
."port    = \"3306\"\n"
394
."name    = \"".$database_name."\"\n"
395
."charset = \"utf8\"\n"
396
."table_prefix = \"".$table_prefix."\"\n"
397
.";\n"
398
.";################################################\n";
399
$sConfigFile = realpath('../setup.ini.php');
400
$sConfigName = basename($sConfigFile);
401
// Check if the file exists and is writable first.
402
if(file_exists($sConfigFile) && is_writable($sConfigFile)) {
403
	if(!$handle = fopen($sConfigFile, 'w')) {
404
		set_error("Cannot open the configuration file ($sConfigName)");
405
	} else {
406
		if (fwrite($handle, $sConfigContent) === FALSE) {
407
			set_error("Cannot write to the configuration file ($sConfigName)");
408
		}
409
		// Close file
410
		fclose($handle);
411
	}
412
} else {
413
	set_error("The configuration file $sConfigName is not writable. Change its permissions so it is, then re-run step 4.");
414
}
415

    
416
//_SetInstallPathConstants();
417
if(!defined('WB_INSTALL_PROCESS')){ define('WB_INSTALL_PROCESS', true ); }
418
if(!defined('WB_URL')){ define('WB_URL', trim( $wb_url,'/' )); }
419
if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
420
if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/admin'); }
421
if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/admin'); }
422
// load db configuration ---
423
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
424
$aSqlData = _readConfiguration($sDbConnectType);
425

    
426
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
427
	set_error('It appears the Absolute path that you entered is incorrect');
428
}
429

    
430
$database = WbDatabase::getInstance();
431
try{
432
	if($sDbConnectType == 'dsn') {
433
		$bTmp = @$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
434
	}else {
435
		$bTmp = @$database->doConnect($aSqlData[0], TABLE_PREFIX);
436
	}
437
} catch (WbDatabaseException $e) {
438
	if(!file_put_contents($sConfigFile,"<?php\n")) {
439
		set_error("Cannot write to the configuration file ($sSetupFile)");
440
	}
441
	set_error($e->getMessage()); 
442
}
443

    
444
unset($aSqlData);
445
// write the config.php
446
$sConfigContent = "<?php\n"
447
    ."/* this file is for backward compatibility only */\n"
448
    ."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
449
$sSetupFile = WB_PATH.'/config.php';
450
if(!file_put_contents($sSetupFile,$sConfigContent)) {
451
	set_error("Cannot write to the configuration file ($sSetupFile)");
452
}
453
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
454
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
455
require_once($sSecMod);
456
require_once(WB_PATH.'/framework/class.admin.php');
457

    
458
// Dummy class to allow modules' install scripts to call $admin->print_error
459
	class admin_dummy extends admin
460
	{
461
		var $error='';
462
		function print_error($message, $link = 'index.php', $auto_footer = true)
463
		{
464
			$this->error=$message;
465
		}
466
	}
467

    
468
//  core tables only structure
469
	$sSqlFileName = dirname(__FILE__).'/sql/websitebaker.sql';
470
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
471

    
472
	require(ADMIN_PATH.'/interface/version.php');
473

    
474
	$sql = 'INSERT INTO `'.TABLE_PREFIX.'settings` (`name`, `value`) VALUES '
475
	     . '(\'wb_version\', \''.VERSION.'\'), '
476
	     . '(\'website_title\', \''.$website_title.'\'), '
477
	     . '(\'website_description\', \'\'), '
478
	     . '(\'website_keywords\', \'\'), '
479
	     . '(\'website_header\', \'\'), '
480
	     . '(\'website_footer\', \'\'), '
481
	     . '(\'wysiwyg_style\', \'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;\'), '
482
	     . '(\'rename_files_on_upload\', \'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt\'), '
483
	     . '(\'er_level\', \'0\'), '
484
	     . '(\'default_language\', \''.$default_language.'\'), '
485
	     . '(\'app_name\', \'wb_'.$session_rand.'\'), '
486
	     . '(\'sec_anchor\', \'Sec\'), '
487
	     . '(\'default_timezone\', \''.$default_timezone.'\'), '
488
	     . '(\'default_date_format\', \'Y-m-d\'), '
489
	     . '(\'default_time_format\', \'h:i A\'), '
490
	     . '(\'redirect_timer\', \'1500\'), '
491
	     . '(\'home_folders\', \'true\'), '
492
	     . '(\'warn_page_leave\', \'1\'), '
493
	     . '(\'default_template\', \'round\'), '
494
	     . '(\'default_theme\', \'wb_theme\'), '
495
	     . '(\'default_charset\', \'utf-8\'), '
496
	     . '(\'multiple_menus\', \'true\'), '
497
	     . '(\'page_level_limit\', \'6\'), '
498
	     . '(\'intro_page\', \'false\'), '
499
	     . '(\'page_trash\', \'inline\'), '
500
	     . '(\'homepage_redirection\', \'false\'), '
501
	     . '(\'page_languages\', \'true\'), '
502
	     . '(\'wysiwyg_editor\', \'fckeditor\'), '
503
	     . '(\'manage_sections\', \'true\'), '
504
	     . '(\'section_blocks\', \'false\'), '
505
	     . '(\'smart_login\', \'false\'), '
506
	     . '(\'frontend_login\', \'false\'), '
507
	     . '(\'frontend_signup\', \'false\'), '
508
	     . '(\'search\', \'public\'), '
509
	     . '(\'page_extension\', \'.php\'), '
510
	     . '(\'page_spacer\', \'-\'), '
511
	     . '(\'pages_directory\', \'/pages\'), '
512
	     . '(\'rename_files_on_upload\', \'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt\'), '
513
	     . '(\'media_directory\', \'/media\'), '
514
	     . '(\'operating_system\', \''.$operating_system.'\'), '
515
	     . '(\'string_file_mode\', \''.$file_mode.'\'), '
516
	     . '(\'string_dir_mode\', \''.$dir_mode.'\'), '
517
	     . '(\'wbmailer_routine\', \'phpmail\'), '
518
	     . '(\'server_email\', \''.$admin_email.'\'), '
519
	     . '(\'wbmailer_default_sendername\', \'WebsiteBaker Mailer\'), '
520
	     . '(\'wbmailer_smtp_host\', \'\'), '
521
	     . '(\'wbmailer_smtp_auth\', \'\'), '
522
	     . '(\'wbmailer_smtp_username\', \'\'), '
523
	     . '(\'wbmailer_smtp_password\', \'\'), '
524
	     . '(\'fingerprint_with_ip_octets\', \'2\'), '
525
	     . '(\'secure_form_module\', \'\'), '
526
	     . '(\'mediasettings\', \'\'), '
527
	     . '(\'wb_revision\', \''.REVISION.'\'), '
528
 	     . '(\'wb_sp\', \''.SP.'\'), '
529
	     . '(\'page_icon_dir\', \'/templates/*/title_images\'), '
530
	     . '(\'dev_infos\', \'false\'), '
531
	     . '(\'groups_updated\', \''.time().'\'), '
532
	     . '(\'wbmail_signature\', \'\'), '
533
	     . '(\'confirmed_registration\', \'1\'), '
534
	     . '(\'page_extendet\', \'true\'), '
535
	     . '(\'system_locked\', \'0\'), '
536
	     . '(\'password_crypt_loops\', \'12\'), '
537
	     . '(\'password_hash_type\', \'false\'), '
538
	     . '(\'password_length\', \'10\'), '
539
		 . '(\'password_use_types\', \''.(int)0xFFFF.'\') '
540
	     . '';
541
	if(!$database->query($settings_rows)) { set_error($database->get_error()); }
542

    
543
	// Admin group
544
	$full_system_permissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,'
545
	                          . 'groups_modify,groups_view,languages,languages_install,languages_uninstall,'
546
	                          . 'languages_view,media,media_create,media_delete,media_rename,media_upload,'
547
	                          . 'media_view,modules,modules_advanced,modules_install,modules_uninstall,'
548
	                          . 'modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,'
549
	                          . 'pages_modify,pages_settings,pages_view,preferences,preferences_view,'
550
	                          . 'settings,settings_advanced,settings_basic,settings_view,templates,'
551
	                          . 'templates_install,templates_uninstall,templates_view,users,users_add,'
552
	                          . 'users_delete,users_modify,users_view';
553
	$sql = 'INSERT INTO `'.TABLE_PREFIX.'groups` '
554
	     . 'SET `group_id` =1,'
555
	     .     '`name`=\'Administrators\','
556
		 .     '`system_permissions`=\''.$full_system_permissions.'\','
557
		 .     '`module_permissions`=\'\','
558
		 .     '`template_permissions`=\'\'';
559
	if(!$database->query($sql)) { set_error($database->get_error()); }
560

    
561
// Admin user
562
	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` VALUES (1, 1, '1', 1, '$admin_username', '".md5($admin_password)."', '', 0, '', 0, 'Administrator', '$admin_email', $default_timezone, '', '', '$default_language', '', 0, '');";
563
	if(!$database->query($insert_admin_user)) { set_error($database->get_error()); }
564

    
565
// Search layout default data
566
	$sSqlFileName = dirname(__FILE__).'/sql/wb_search_data.sql';
567
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
568

    
569
	require_once(WB_PATH.'/framework/initialize.php');
570
// 
571
// Include WB functions file
572
	require_once(WB_PATH.'/framework/functions.php');
573
// Re-connect to the database, this time using in-build database class
574
	require_once(WB_PATH.'/framework/class.login.php');
575
	// Include the PclZip class file (thanks to
576
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
577
	// Install add-ons
578
	if(file_exists(WB_PATH.'/install/modules')) {
579
		// Unpack pre-packaged modules
580
	}
581
	if(file_exists(WB_PATH.'/install/templates')) {
582
		// Unpack pre-packaged templates
583
	}
584
	if(file_exists(WB_PATH.'/install/languages')) {
585
		// Unpack pre-packaged languages
586
	}
587

    
588
	$admin=new admin_dummy('Start','',false,false);
589
	// Load addons into DB
590
	$dirs['modules'] = WB_PATH.'/modules/';
591
	$dirs['templates'] = WB_PATH.'/templates/';
592
	$dirs['languages'] = WB_PATH.'/languages/';
593

    
594
	foreach($dirs AS $type => $dir) {
595
		if(($handle = opendir($dir))) {
596
			while(false !== ($file = readdir($handle))) {
597
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
598
					// Get addon type
599
					if($type == 'modules') {
600
						load_module($dir.'/'.$file, true);
601
						// Pretty ugly hack to let modules run $admin->set_error
602
						// See dummy class definition admin_dummy above
603
						if ($admin->error!='') {
604
							set_error($admin->error);
605
						}
606
					} elseif($type == 'templates') {
607
						load_template($dir.'/'.$file);
608
					} elseif($type == 'languages') {
609
						load_language($dir.'/'.$file);
610
					}
611
				}
612
			}
613
			closedir($handle);
614
		}
615
	}
616

    
617
// Check if there was a database error
618
	if($database->is_error()) {
619
		set_error($database->get_error());
620
	}
621

    
622
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY )) ) {  }
623
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY.'/home' )) ) {  }
624
	if ( sizeof(createFolderProtectFile( WB_PATH.PAGES_DIRECTORY )) ) {  }
625

    
626
// end of if install_tables
627

    
628
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
629
// Setup template object, parse vars to it, then parse it
630
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('loginBox.htt'));
631

    
632
// Log the user in and go to Website Baker Administration
633
$thisApp = new Login(
634
	array(
635
			"MAX_ATTEMPS" => "50",
636
			"WARNING_URL" => $ThemeUrl."/warning.html",
637
			"USERNAME_FIELDNAME" => 'admin_username',
638
			"PASSWORD_FIELDNAME" => 'admin_password',
639
			"REMEMBER_ME_OPTION" => SMART_LOGIN,
640
			"MIN_USERNAME_LEN" => "2",
641
			"MIN_PASSWORD_LEN" => "3",
642
			"MAX_USERNAME_LEN" => "30",
643
			"MAX_PASSWORD_LEN" => "30",
644
			'LOGIN_URL' => ADMIN_URL."/login/index.php",
645
			'DEFAULT_URL' => ADMIN_URL."/start/index.php",
646
			'TEMPLATE_DIR' => $ThemePath,
647
			'TEMPLATE_FILE' => 'loginBox.htt',
648
			'FRONTEND' => false,
649
			'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
650
			'USERS_TABLE' => TABLE_PREFIX."users",
651
			'GROUPS_TABLE' => TABLE_PREFIX."groups",
652
	)
653
);
(4-4/5)