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: 1934 $
30
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/install/save.php $
31
 * @lastmodified $Date: 2013-07-22 09:54:06 +0200 (Mon, 22 Jul 2013) $
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(dirname(__FILE__)).'/framework/globalExceptionHandler.php'); 
40
include(dirname(dirname(__FILE__)).'/framework/WbAutoloader.php');
41
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m'));
42

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

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

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

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

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

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

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

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

    
241
// Begin path and timezone details code
242

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
474
	require(ADMIN_PATH.'/interface/version.php');
475

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

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

    
562
// Admin user
563
	$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, '');";
564
	if(!$database->query($insert_admin_user)) { set_error($database->get_error()); }
565

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

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

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

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

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

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

    
627
// end of if install_tables
628

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

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