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: 2104 $
30
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/install/save.php $
31
 * @lastmodified $Date: 2014-11-20 21:24:59 +0100 (Thu, 20 Nov 2014) $
32
 * @since        File available since 2012-04-01
33
 * @description  xyz
34
 */
35

    
36
$debug = true;
37
if(!defined('DEBUG')) { define('DEBUG', true); }
38

    
39
include(dirname(__DIR__).'/framework/globalExceptionHandler.php');
40
include(dirname(__DIR__).'/framework/WbAutoloader.php');
41
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m', 'templates'=>'t', 'include'=>'i'));
42
include(__DIR__.'/InstallHelper.php');
43
// register PHPMailer autoloader ---
44
if (!function_exists('PHPMailerAutoload')) {
45
    require(dirname(__DIR__).'/include/phpmailer/PHPMailerAutoload.php');
46
}
47

    
48
function errorLogs($error_str)
49
{
50
	$log_error = true;
51
	if ( ! function_exists('error_log') ) { $log_error = false; }
52
	$log_file = @ini_get('error_log');
53
	if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) {
54
		$log_error = false;
55
	}
56
	if ( $log_error ) {@error_log($error_str, 0);}
57
}
58

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

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

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

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

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

    
231
function add_slashes($input) {
232
	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
233
		return $input;
234
	}
235
	$output = addslashes($input);
236
	return $output;
237
}
238

    
239
// Begin check to see if form was even submitted
240
// Set error if no post vars found
241
if(!isset($_POST['website_title'])) {
242
	set_error('Please fill-in the wesite title below');
243
}
244
// End check to see if form was even submitted
245

    
246
// Begin path and timezone details code
247

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

    
264
// Get the default language
265
$sLanguageDirectory = dirname(__DIR__).'languages/';
266
$allowed_languages = array_keys(InstallHelper::getAvailableLanguages($sLanguageDirectory));
267
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
268
	set_error('Please select a valid default backend language','default_language');
269
} else {
270
	$default_language = $_POST['default_language'];
271
	// make sure the selected language file exists in the language folder
272
	if(!file_exists('../languages/' .$default_language .'.php')) {
273
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
274
	}
275
}
276
// End default language details code
277

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

    
298
// Begin database details code
299
// Check if user has entered a database host
300
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
301
	set_error('Please enter a database host name', 'database_host');
302
} else {
303
	$database_host = $_POST['database_host'];
304
 }
305
// Check if user has entered a database name
306
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
307
	set_error('Please enter a database name', 'database_name');
308
} else {
309
	// make sure only allowed characters are specified
310
	if(!preg_match('/^[a-z0-9_-]*$/i', $_POST['database_name'])) {
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 database name.', 'database_name');
313
	}
314
	$database_name = $_POST['database_name'];
315
}
316
// Get table prefix
317
if(!preg_match('/^[a-z0-9_]*$/i', $_POST['table_prefix'])) {
318
	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
319
	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
320
} else {
321
	$table_prefix = $_POST['table_prefix'];
322
}
323

    
324
// Check if user has entered a database username
325
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
326
	set_error('Please enter a database username','database_username');
327
} else {
328
	$database_username = $_POST['database_username'];
329
}
330
// Check if user has entered a database password
331
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
332
	set_error('Please enter a database password', 'database_password');
333
} else {
334
	$database_password = $_POST['database_password'];
335
}
336

    
337
// Find out if the user wants to install tables and data
338
$install_tables = ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
339
// End database details code
340

    
341
// Begin website title code
342
// Get website title
343
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
344
	set_error('Please enter a website title', 'website_title');
345
} else {
346
	$website_title = add_slashes($_POST['website_title']);
347
}
348
// End website title code
349

    
350
// Begin admin user details code
351
// Get admin username
352
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
353
	set_error('Please enter a username for the Administrator account','admin_username');
354
} else {
355
	$admin_username = $_POST['admin_username'];
356
}
357
// Get admin email and validate it
358
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
359
	set_error('Please enter an email for the Administrator account','admin_email');
360
} else {
361
	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i', $_POST['admin_email'])) {
362
		$admin_email = $_POST['admin_email'];
363
	} else {
364
		set_error('Please enter a valid email address for the Administrator account','admin_email');
365
	}
366
}
367
// Get the two admin passwords entered, and check that they match
368
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
369
	set_error('Please enter a password for the Administrator account','admin_password');
370
} else {
371
	$admin_password = $_POST['admin_password'];
372
}
373
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
374
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
375
} else {
376
	$admin_repassword = $_POST['admin_repassword'];
377
}
378
if($admin_password != $admin_repassword) {
379
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
380
}
381
if (mb_strlen($admin_password) < 6) {
382
	set_error('Sorry, the password must have 6 chars at last','admin_password');
383
}
384

    
385
// End admin user details code
386

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

    
428
//_SetInstallPathConstants();
429
if(!defined('WB_INSTALL_PROCESS')){ define('WB_INSTALL_PROCESS', true ); }
430
if(!defined('WB_URL')){ define('WB_URL', trim( $wb_url,'/' )); }
431
if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
432
if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/admin'); }
433
if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/admin'); }
434
// load db configuration ---
435
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
436
$aSqlData = _readConfiguration($sDbConnectType);
437

    
438
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
439
	set_error('It appears the Absolute path that you entered is incorrect');
440
}
441

    
442
$database = WbDatabase::getInstance();
443
try{
444
	if($sDbConnectType == 'dsn') {
445
		$bTmp = @$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
446
	}else {
447
		$bTmp = @$database->doConnect($aSqlData[0], TABLE_PREFIX);
448
	}
449
} catch (WbDatabaseException $e) {
450
	if(!file_put_contents($sConfigFile,"<?php\n")) {
451
		set_error("Cannot write to the configuration file ($sSetupFile)");
452
	}
453
	set_error($e->getMessage()); 
454
}
455

    
456
unset($aSqlData);
457
// write the config.php
458
$sConfigContent = "<?php\n"
459
    ."/* this file is for backward compatibility only */\n"
460
    ."/* never put any code in this file! */\n"
461
    ."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
462
$sSetupFile = WB_PATH.'/config.php';
463
if(!file_put_contents($sSetupFile,$sConfigContent)) {
464
	set_error("Cannot write to the configuration file ($sSetupFile)");
465
}
466
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
467
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
468
require_once($sSecMod);
469
require(ADMIN_PATH.'/interface/version.php');
470

    
471
/*****************************
472
Begin Create Database Tables
473
*****************************/
474
if (is_readable(__DIR__.'/sql/install-struct.sql')) {
475
    if (! $database->SqlImport(__DIR__.'/sql/install-struct.sql', TABLE_PREFIX, false)) {
476
        set_error('unable to import install-struct.sql');
477
    }
478
}
479
if (is_readable(__DIR__.'/sql/install-data.sql')) {
480
    if (! $database->SqlImport(__DIR__.'/sql/install-data.sql', TABLE_PREFIX)) {
481
        set_error('unable to import install-data.sql');
482
    }
483
}
484
$sql = // additional settings from install input
485
       'REPLACE INTO `'.TABLE_PREFIX.'settings` (`name`, `value`) VALUES '
486
     .        '(\'wb_version\', \''.VERSION.'\'), '
487
     .        '(\'website_title\', \''.$website_title.'\'), '
488
     .        '(\'default_language\', \''.$default_language.'\'), '
489
     .        '(\'app_name\', \'wb_'.$session_rand.'\'), '
490
     .        '(\'default_timezone\', \''.$default_timezone.'\'), '
491
     .        '(\'operating_system\', \''.$operating_system.'\'), '
492
     .        '(\'string_file_mode\', \''.$file_mode.'\'), '
493
     .        '(\'string_dir_mode\', \''.$dir_mode.'\'), '
494
     .        '(\'server_email\', \''.$admin_email.'\'), '
495
     .        '(\'wb_revision\', \''.REVISION.'\'), '
496
     .        '(\'wb_sp\', \''.SP.'\'), '
497
     .        '(\'groups_updated\', \''.time().'\')';
498
if (! ($database->query($sql))) {
499
    set_error('unable to write \'install presets\' into table \'settings\'');
500
}
501
$sql = // add the Admin user
502
     'INSERT INTO `'.TABLE_PREFIX.'users` '
503
    .'SET `user_id`=1, '
504
    .    '`group_id`=1, '
505
    .    '`groups_id`=\'1\', '
506
    .    '`active`=\'1\', '
507
    .    '`username`=\''.$admin_username.'\', '
508
    .    '`password`=\''.md5($admin_password).'\', '
509
    .    '`email`=\''.$admin_email.'\', '
510
    .    '`timezone`=\''.$default_timezone.'\', '
511
    .    '`language`=\''.$default_language.'\', '
512
    .    '`display_name`=\'Administrator\'';
513
if (! ($database->query($sql))) {
514
    set_error('unable to write Administrator account into table \'users\'');
515
}
516
/**********************
517
END OF TABLES IMPORT
518
**********************/
519
// initialize the system
520
require_once(WB_PATH.'/framework/initialize.php');
521
require_once(WB_PATH.'/framework/class.admin.php');
522
/***********************
523
// Dummy class to allow modules' install scripts to call $admin->print_error
524
***********************/
525
class admin_dummy extends admin
526
{
527
    public $error='';
528
    public function print_error($message, $link = 'index.php', $auto_footer = true)
529
    {
530
        $this->error=$message;
531
    }
532
}
533
// Include WB functions file
534
	require_once(WB_PATH.'/framework/functions.php');
535
// Re-connect to the database, this time using in-build database class
536
//	require_once(WB_PATH.'/framework/class.login.php');
537
	// Include the PclZip class file (thanks to
538
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
539
	// Install add-ons
540
	$admin=new admin_dummy('Start','',false,false);
541
// Load addons and templates into DB
542
    $aScanDirs = array(
543
        'module'   => dirname(__DIR__).'/modules/',
544
        'template' => dirname(__DIR__).'/templates/',
545
        'language' => dirname(__DIR__).'/languages/'
546
    );
547
    foreach ($aScanDirs as $sType => $sPath) {
548
        $sCommand = 'load_'.$sType;
549
        if ($sType != 'language') {
550
            foreach (glob($sPath, GLOB_ONLYDIR) as $sMatchingPath) {
551
                if ($sType == 'module') {
552
                    $sCommand($sMatchingPath, true);
553
                    if ($admin->error) { set_error($admin->error); }
554
                } elseif ($sType == 'template') {
555
                    $sCommand($sMatchingPath);
556
                }
557
            }
558
        } else {
559
            foreach (glob(dirname(__DIR__).'/languages/??.php') as $sMatchingPath) {
560
                if (preg_match('/\/[A-Z]{2}\.php$/sU', $sMatchingPath)) {
561
                    $sCommand($sMatchingPath);
562
                }
563
            }
564
        }
565
    }
566

    
567
// Check if there was a database error
568
	if($database->is_error()) {
569
		set_error($database->get_error());
570
	}
571

    
572
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY )) ) {  }
573
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY.'/home' )) ) {  }
574
	if ( sizeof(createFolderProtectFile( WB_PATH.PAGES_DIRECTORY )) ) {  }
575

    
576
// end of if install_tables
577

    
578
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
579
// Setup template object, parse vars to it, then parse it
580
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('loginBox.htt'));
581

    
582
// Log the user in and go to Website Baker Administration
583
$thisApp = new Login(
584
	array(
585
			"MAX_ATTEMPS" => "50",
586
			"WARNING_URL" => $ThemeUrl."/warning.html",
587
			"USERNAME_FIELDNAME" => 'admin_username',
588
			"PASSWORD_FIELDNAME" => 'admin_password',
589
			"REMEMBER_ME_OPTION" => SMART_LOGIN,
590
			"MIN_USERNAME_LEN" => "2",
591
			"MIN_PASSWORD_LEN" => "3",
592
			"MAX_USERNAME_LEN" => "30",
593
			"MAX_PASSWORD_LEN" => "30",
594
			'LOGIN_URL' => ADMIN_URL."/login/index.php",
595
			'DEFAULT_URL' => ADMIN_URL."/start/index.php",
596
			'TEMPLATE_DIR' => $ThemePath,
597
			'TEMPLATE_FILE' => 'loginBox.htt',
598
			'FRONTEND' => false,
599
			'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
600
			'USERS_TABLE' => TABLE_PREFIX."users",
601
			'GROUPS_TABLE' => TABLE_PREFIX."groups",
602
	)
603
);
(5-5/6)