Project

General

Profile

1 1470 Luisehahne
<?php
2
/**
3 1884 Luisehahne
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 1470 Luisehahne
 *
5 1884 Luisehahne
 * 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 1470 Luisehahne
 *
10 1884 Luisehahne
 * 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 1470 Luisehahne
 */
18
19 1884 Luisehahne
/**
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$
30
 * @link         $HeadURL$
31
 * @lastmodified $Date$
32
 * @since        File available since 2012-04-01
33
 * @description  xyz
34
 */
35
36 1470 Luisehahne
$debug = true;
37
38 1870 Luisehahne
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 1884 Luisehahne
/**
43
 * Set constants for system/install values
44
 * @throws RuntimeException
45
 */
46
	function _SetInstallPathConstants() {
47
		if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
48
		if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
49
		if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
50
			throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
51
		}
52
		if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
53
		if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
54
		if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
55
		if(!defined('WB_REL')){
56
			$x1 = parse_url(WB_URL);
57
			define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
58
		}
59
		define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY);
60
		if(!defined('DOCUMENT_ROOT')) {
61
62
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
63
		}
64
		define('TMP_PATH', WB_PATH.'/temp');
65
	}
66
67
/**
68
 * Read DB settings from configuration file
69
 * @return string
70
 * @throws RuntimeException
71
 *
72
 */
73
	function _readConfiguration($sRetvalType = 'url') {
74
		// check for valid file request. Becomes more stronger in next version
75
		$x = debug_backtrace();
76
		$bValidRequest = false;
77
		if(sizeof($x) != 0) {
78
			foreach($x as $aStep) {
79
				// define the scripts which can read the configuration
80
				if(preg_match('/(save.php|index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
81
					$bValidRequest = true;
82
					break;
83
				}
84
			}
85
		}else {
86
			$bValidRequest = true;
87
		}
88
		if(!$bValidRequest) {
89
			throw new RuntimeException('illegal function request!');
90
		}
91
		$aRetval = array();
92
		$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
93
		if(is_readable($sSetupFile)) {
94
			$aCfg = parse_ini_file($sSetupFile, true);
95
			foreach($aCfg['Constants'] as $key=>$value) {
96 1885 Luisehahne
				switch($key):
97
					case 'DEBUG':
98
						$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
99
						break;
100
					case 'WB_URL':
101
					case 'AppUrl':
102
						$value = trim(str_replace('\\', '/', $value), '/');
103
						if(!defined('WB_URL')) { define('WB_URL', $value); }
104
						break;
105
					case 'ADMIN_DIRECTORY':
106
					case 'AcpDir':
107
						$value = trim(str_replace('\\', '/', $value), '/');
108
						if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
109
						break;
110
					default:
111
						if(!defined($key)) { define($key, $value); }
112
						break;
113
				endswitch;
114 1884 Luisehahne
			}
115
			$db = $aCfg['DataBase'];
116
			$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
117
			$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
118
			$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
119
			$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
120
			$db['port'] = isset($db['port']) ? $db['port'] : '3306';
121
			$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
122
			$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
123
			$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
124
			$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
125
			define('TABLE_PREFIX', $db['table_prefix']);
126
			if($sRetvalType == 'dsn') {
127
				$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';'
128
				            . ($db['port'] != '' ? 'port='.(int)$db['port'].';' : '');
129
				$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
130
				$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']);
131
			}else { // $sRetvalType == 'url'
132
				$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
133 1885 Luisehahne
				            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
134
				            . '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
135 1884 Luisehahne
			}
136
			unset($db, $aCfg);
137
			return $aRetval;
138
		}
139
		throw new RuntimeException('unable to read setup.ini.php');
140
	}
141
142 1470 Luisehahne
if (true === $debug) {
143
	ini_set('display_errors', 1);
144
	error_reporting(E_ALL);
145
}
146
// Start a session
147
if(!defined('SESSION_STARTED')) {
148
	session_name('wb_session_id');
149
	session_start();
150
	define('SESSION_STARTED', true);
151
}
152
// get random-part for session_name()
153
list($usec,$sec) = explode(' ',microtime());
154
srand((float)$sec+((float)$usec*100000));
155
$session_rand = rand(1000,9999);
156
157
// Function to set error
158
function set_error($message, $field_name = '') {
159
	global $_POST;
160
	if(isset($message) AND $message != '') {
161
		// Copy values entered into session so user doesn't have to re-enter everything
162
		if(isset($_POST['website_title'])) {
163 1737 Luisehahne
			$_SESSION['website_title'] = $_POST['website_title'];
164 1470 Luisehahne
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
165
			$_SESSION['default_language'] = $_POST['default_language'];
166
			if(!isset($_POST['operating_system'])) {
167
				$_SESSION['operating_system'] = 'linux';
168
			} else {
169
				$_SESSION['operating_system'] = $_POST['operating_system'];
170
			}
171
			if(!isset($_POST['world_writeable'])) {
172
				$_SESSION['world_writeable'] = false;
173
			} else {
174
				$_SESSION['world_writeable'] = true;
175
			}
176
			$_SESSION['database_host'] = $_POST['database_host'];
177
			$_SESSION['database_username'] = $_POST['database_username'];
178 1737 Luisehahne
			$_SESSION['database_password'] = '';
179 1470 Luisehahne
			$_SESSION['database_name'] = $_POST['database_name'];
180
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
181
			if(!isset($_POST['install_tables'])) {
182 1737 Luisehahne
				$_SESSION['install_tables'] = true;
183 1470 Luisehahne
			} else {
184
				$_SESSION['install_tables'] = true;
185
			}
186
			$_SESSION['website_title'] = $_POST['website_title'];
187
			$_SESSION['admin_username'] = $_POST['admin_username'];
188
			$_SESSION['admin_email'] = $_POST['admin_email'];
189 1737 Luisehahne
			$_SESSION['admin_password'] = '';
190
			$_SESSION['admin_repassword'] = '';
191 1470 Luisehahne
		}
192
		// Set the message
193
		$_SESSION['message'] = $message;
194
		// Set the element(s) to highlight
195
		if($field_name != '') {
196
			$_SESSION['ERROR_FIELD'] = $field_name;
197
		}
198
		// Specify that session support is enabled
199
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
200
		// Redirect to first page again and exit
201
		header('Location: index.php?sessions_checked=true');
202
		exit();
203
	}
204
}
205 1529 Luisehahne
/* */
206 1470 Luisehahne
207
// Function to workout what the default permissions are for files created by the webserver
208
function default_file_mode($temp_dir) {
209
	$v = explode(".",PHP_VERSION);
210
	$v = $v[0].$v[1];
211
	if($v > 41 AND is_writable($temp_dir)) {
212
		$filename = $temp_dir.'/test_permissions.txt';
213
		$handle = fopen($filename, 'w');
214
		fwrite($handle, 'This file is to get the default file permissions');
215
		fclose($handle);
216
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
217
		unlink($filename);
218
	} else {
219 1870 Luisehahne
		$default_file_mode = '0666';
220 1470 Luisehahne
	}
221
	return $default_file_mode;
222
}
223
224
// Function to workout what the default permissions are for directories created by the webserver
225
function default_dir_mode($temp_dir) {
226
	$v = explode(".",PHP_VERSION);
227
	$v = $v[0].$v[1];
228
	if($v > 41 AND is_writable($temp_dir)) {
229
		$dirname = $temp_dir.'/test_permissions/';
230
		mkdir($dirname);
231
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
232
		rmdir($dirname);
233
	} else {
234
		$default_dir_mode = '0777';
235
	}
236
	return $default_dir_mode;
237
}
238
239
function add_slashes($input) {
240
	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
241
		return $input;
242
	}
243
	$output = addslashes($input);
244
	return $output;
245
}
246
247
// Begin check to see if form was even submitted
248
// Set error if no post vars found
249
if(!isset($_POST['website_title'])) {
250 1725 Luisehahne
	set_error('Please fill-in the wesite title below');
251 1470 Luisehahne
}
252
// End check to see if form was even submitted
253
254
// Begin path and timezone details code
255
256
// Check if user has entered the installation url
257
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
258
	set_error('Please enter an absolute URL', 'wb_url');
259
} else {
260
	$wb_url = $_POST['wb_url'];
261
}
262
// Remove any slashes at the end of the URL
263 1885 Luisehahne
$wb_url = trim(str_replace('\\', '/', $wb_url), '/').'/';
264 1470 Luisehahne
// Get the default time zone
265
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
266
	set_error('Please select a valid default timezone', 'default_timezone');
267
} else {
268
	$default_timezone = $_POST['default_timezone']*60*60;
269
}
270
// End path and timezone details code
271
272
// Get the default language
273
$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');
274
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
275
	set_error('Please select a valid default backend language','default_language');
276
} else {
277
	$default_language = $_POST['default_language'];
278
	// make sure the selected language file exists in the language folder
279
	if(!file_exists('../languages/' .$default_language .'.php')) {
280
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
281
	}
282
}
283
// End default language details code
284
285
// Begin operating system specific code
286
// Get operating system
287
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
288
	set_error('Please select a valid operating system');
289
} else {
290
	$operating_system = $_POST['operating_system'];
291
}
292
// Work-out file permissions
293
if($operating_system == 'windows') {
294
	$file_mode = '0777';
295
	$dir_mode = '0777';
296
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
297
	$file_mode = '0777';
298
	$dir_mode = '0777';
299
} else {
300
	$file_mode = default_file_mode('../temp');
301
	$dir_mode = default_dir_mode('../temp');
302
}
303
// End operating system specific code
304
305
// Begin database details code
306
// Check if user has entered a database host
307
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
308
	set_error('Please enter a database host name', 'database_host');
309
} else {
310
	$database_host = $_POST['database_host'];
311 1770 Luisehahne
 }
312 1470 Luisehahne
// Check if user has entered a database name
313
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
314
	set_error('Please enter a database name', 'database_name');
315
} else {
316
	// make sure only allowed characters are specified
317 1770 Luisehahne
	if(!preg_match('/^[a-z0-9_-]*$/i', $_POST['database_name'])) {
318 1470 Luisehahne
		// 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 database name.', 'database_name');
320
	}
321
	$database_name = $_POST['database_name'];
322
}
323
// Get table prefix
324 1770 Luisehahne
if(!preg_match('/^[a-z0-9_]*$/i', $_POST['table_prefix'])) {
325 1470 Luisehahne
	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
326
	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
327
} else {
328
	$table_prefix = $_POST['table_prefix'];
329
}
330
331 1770 Luisehahne
// Check if user has entered a database username
332
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
333
	set_error('Please enter a database username','database_username');
334
} else {
335
	$database_username = $_POST['database_username'];
336
}
337
// Check if user has entered a database password
338 1884 Luisehahne
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
339 1770 Luisehahne
	set_error('Please enter a database password', 'database_password');
340
} else {
341
	$database_password = $_POST['database_password'];
342
}
343
344 1470 Luisehahne
// Find out if the user wants to install tables and data
345 1695 Luisehahne
$install_tables = ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
346 1470 Luisehahne
// End database details code
347
348
// Begin website title code
349
// Get website title
350
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
351
	set_error('Please enter a website title', 'website_title');
352
} else {
353
	$website_title = add_slashes($_POST['website_title']);
354
}
355
// End website title code
356
357
// Begin admin user details code
358
// Get admin username
359
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
360
	set_error('Please enter a username for the Administrator account','admin_username');
361
} else {
362
	$admin_username = $_POST['admin_username'];
363
}
364
// Get admin email and validate it
365
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
366
	set_error('Please enter an email for the Administrator account','admin_email');
367
} else {
368
	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
369
		$admin_email = $_POST['admin_email'];
370
	} else {
371
		set_error('Please enter a valid email address for the Administrator account','admin_email');
372
	}
373
}
374
// Get the two admin passwords entered, and check that they match
375
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
376
	set_error('Please enter a password for the Administrator account','admin_password');
377
} else {
378
	$admin_password = $_POST['admin_password'];
379
}
380
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
381
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
382
} else {
383
	$admin_repassword = $_POST['admin_repassword'];
384
}
385
if($admin_password != $admin_repassword) {
386
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
387
}
388
// End admin user details code
389
390
// Try and write settings to config file
391 1884 Luisehahne
$sConfigContent =
392
 ";<?php die('sorry, illegal file access'); ?>#####\n"
393
.";################################################\n"
394
."; WebsiteBaker configuration file\n"
395
."; auto generated ".date('Y-m-d h:i:s A e ')."\n"
396
.";################################################\n"
397
."[Constants]\n"
398 1885 Luisehahne
."DEBUG   = false\n"
399
."AppUrl  = ".$wb_url."\n"
400
."AcpDir  = admin/\n"
401 1884 Luisehahne
.";##########\n"
402
."[DataBase]\n"
403
."type    = \"mysql\"\n"
404
."user    = \"".$database_username."\"\n"
405
."pass    = \"".$database_password."\"\n"
406
."host    = \"".$database_host."\"\n"
407
."port    = \"3306\"\n"
408
."name    = \"".$database_name."\"\n"
409
."charset = \"utf8\"\n"
410
."table_prefix = \"".$table_prefix."\"\n"
411
.";\n"
412
.";################################################\n";
413
$sConfigFile = realpath('../setup.ini.php');
414
$sConfigName = basename($sConfigFile);
415 1470 Luisehahne
// Check if the file exists and is writable first.
416 1884 Luisehahne
if(file_exists($sConfigFile) && is_writable($sConfigFile)) {
417
	if(!$handle = fopen($sConfigFile, 'w')) {
418
		set_error("Cannot open the configuration file ($sConfigName)");
419 1470 Luisehahne
	} else {
420 1884 Luisehahne
		if (fwrite($handle, $sConfigContent) === FALSE) {
421
			set_error("Cannot write to the configuration file ($sConfigName)");
422 1470 Luisehahne
		}
423
		// Close file
424
		fclose($handle);
425
	}
426
} else {
427 1884 Luisehahne
	set_error("The configuration file $sConfigName is not writable. Change its permissions so it is, then re-run step 4.");
428 1470 Luisehahne
}
429
430 1884 Luisehahne
// load db configuration ---
431
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
432
$aSqlData = _readConfiguration($sDbConnectType);
433 1470 Luisehahne
434 1884 Luisehahne
_SetInstallPathConstants();
435
436
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
437
	set_error('It appears the Absolute path that you entered is incorrect');
438
}
439
440
$database = WbDatabase::getInstance();
441
try{
442
	if($sDbConnectType == 'dsn') {
443
		$bTmp = @$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
444
	}else {
445
		$bTmp = @$database->doConnect($aSqlData[0], TABLE_PREFIX);
446 1870 Luisehahne
	}
447 1885 Luisehahne
} catch (WbDatabaseException $e) {
448 1884 Luisehahne
	if(!file_put_contents($sConfigFile,"<?php\n")) {
449
		set_error("Cannot write to the configuration file ($sSetupFile)");
450
	}
451
	set_error($e->getMessage());
452
}
453 1470 Luisehahne
454 1884 Luisehahne
unset($aSqlData);
455
// write the config.php
456
$sConfigContent = "<?php\n"
457
    ."/* this file is for backward compatibility only */\n"
458
    ."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
459
$sSetupFile = WB_PATH.'/config.php';
460
if(!file_put_contents($sSetupFile,$sConfigContent)) {
461
	set_error("Cannot write to the configuration file ($sSetupFile)");
462
}
463
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
464
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
465
require_once($sSecMod);
466
require_once(WB_PATH.'/framework/class.admin.php');
467 1470 Luisehahne
468 1529 Luisehahne
// Dummy class to allow modules' install scripts to call $admin->print_error
469 1686 darkviper
	class admin_dummy extends admin
470 1529 Luisehahne
	{
471 1686 darkviper
		var $error='';
472
		function print_error($message, $link = 'index.php', $auto_footer = true)
473
		{
474
			$this->error=$message;
475
		}
476 1529 Luisehahne
	}
477 1470 Luisehahne
478 1822 Luisehahne
//  core tables only structure
479 1870 Luisehahne
	$sSqlFileName = dirname(__FILE__).'/sql/websitebaker.sql';
480
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
481 1684 Luisehahne
482 1470 Luisehahne
	require(ADMIN_PATH.'/interface/version.php');
483 1684 Luisehahne
484 1470 Luisehahne
	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
485 1818 Luisehahne
	." (setting_id, name, value) VALUES "
486
	." ( 1, 'wb_version', '".VERSION."'),"
487
	." ( 2, 'website_title', '$website_title'),"
488
	." ( 3, 'website_description', ''),"
489
	." ( 4, 'website_keywords', ''),"
490
	." ( 5, 'website_header', ''),"
491
	." ( 6, 'website_footer', ''),"
492
	." ( 7, 'wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
493
	." ( 8, 'rename_files_on_upload', 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt'),"
494
	." ( 9, 'er_level', '0'),"
495
	." (10, 'default_language', '$default_language'),"
496
	." (11, 'app_name', 'wb_$session_rand'),"
497
	." (12, 'sec_anchor', 'section_'),"
498
	." (13, 'default_timezone', '$default_timezone'),"
499 1842 Luisehahne
	." (14, 'default_date_format', 'Y-m-d'),"
500 1818 Luisehahne
	." (15, 'default_time_format', 'h:i A'),"
501
	." (16, 'redirect_timer', '1500'),"
502
	." (17, 'home_folders', 'true'),"
503
	." (18, 'warn_page_leave', '1'),"
504
	." (19, 'default_template', 'round'),"
505
	." (20, 'default_theme', 'wb_theme'),"
506
	." (21, 'default_charset', 'utf-8'),"
507
	." (22, 'multiple_menus', 'true'),"
508
	." (23, 'page_level_limit', '6'),"
509
	." (24, 'intro_page', 'false'),"
510
	." (25, 'page_trash', 'inline'),"
511
	." (26, 'homepage_redirection', 'false'),"
512
	." (27, 'page_languages', 'true'),"
513
	." (28, 'wysiwyg_editor', 'fckeditor'),"
514
	." (29, 'manage_sections', 'true'),"
515
	." (30, 'section_blocks', 'false'),"
516
	." (31, 'smart_login', 'false'),"
517
	." (32, 'frontend_login', 'false'),"
518
	." (33, 'frontend_signup', 'false'),"
519
	." (34, 'search', 'public'),"
520
	." (35, 'page_extension', '.php'),"
521
	." (36, 'page_spacer', '-'),"
522
	." (37, 'pages_directory', '/pages'),"
523
	." (38, 'rename_files_on_upload', 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt'),"
524
	." (39, 'media_directory', '/media'),"
525
	." (40, 'operating_system', '$operating_system'),"
526
	." (41, 'string_file_mode', '$file_mode'),"
527
	." (42, 'string_dir_mode', '$dir_mode'),"
528
	." (43, 'wbmailer_routine', 'phpmail'),"
529
	." (44, 'server_email', '$admin_email'),"
530
	." (45, 'wbmailer_default_sendername', 'WebsiteBaker Mailer'),"
531
	." (46, 'wbmailer_smtp_host', ''),"
532
	." (47, 'wbmailer_smtp_auth', ''),"
533
	." (48, 'wbmailer_smtp_username', ''),"
534
	." (49, 'wbmailer_smtp_password', ''),"
535
	." (50, 'fingerprint_with_ip_octets', '2'),"
536
	." (51, 'secure_form_module', ''),"
537
	." (52, 'mediasettings', ''),"
538
	." (53, 'wb_revision', '".REVISION."'),"
539
 	." (54, 'wb_sp', '".SP."'),"
540
	." (55, 'page_icon_dir', '/templates/*/title_images'),"
541
	." (56, 'dev_infos', 'false'),"
542
	." (57, 'groups_updated', '".time()."'),"
543 1844 Luisehahne
	." (58, 'wbmail_signature', ''),"
544 1818 Luisehahne
	." (59, 'confirmed_registration', '1'),"
545 1849 Luisehahne
	." (60, 'page_extendet', 'true'),"
546 1818 Luisehahne
	." (62, 'system_locked', '0')";
547 1821 Luisehahne
	if(!$database->query($settings_rows)) { set_error($database->get_error()); }
548 1684 Luisehahne
549 1822 Luisehahne
	// Admin group
550
	$full_system_permissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
551
	$full_system_permissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
552
	$full_system_permissions .= 'modules,modules_advanced,modules_install,modules_uninstall,modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,pages_modify,pages_settings,pages_view,';
553
	$full_system_permissions .= 'preferences,preferences_view,settings,settings_advanced,settings_basic,settings_view,templates,templates_install,templates_uninstall,templates_view,users,users_add,users_delete,users_modify,users_view';
554
	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
555
	if(!$database->query($insert_admin_group)) { set_error($database->get_error()); }
556
557 1821 Luisehahne
// Admin user
558 1870 Luisehahne
	$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, '');";
559 1821 Luisehahne
	if(!$database->query($insert_admin_user)) { set_error($database->get_error()); }
560 1684 Luisehahne
561 1822 Luisehahne
// Search layout default data
562 1870 Luisehahne
	$sSqlFileName = dirname(__FILE__).'/sql/wb_search_data.sql';
563
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
564 1684 Luisehahne
565 1870 Luisehahne
	require_once(WB_PATH.'/framework/initialize.php');
566 1821 Luisehahne
// Include WB functions file
567
	require_once(WB_PATH.'/framework/functions.php');
568
// Re-connect to the database, this time using in-build database class
569
	require_once(WB_PATH.'/framework/class.login.php');
570 1470 Luisehahne
	// Include the PclZip class file (thanks to
571
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
572
	// Install add-ons
573
	if(file_exists(WB_PATH.'/install/modules')) {
574
		// Unpack pre-packaged modules
575
	}
576
	if(file_exists(WB_PATH.'/install/templates')) {
577
		// Unpack pre-packaged templates
578
	}
579
	if(file_exists(WB_PATH.'/install/languages')) {
580
		// Unpack pre-packaged languages
581
	}
582 1734 Luisehahne
583 1529 Luisehahne
	$admin=new admin_dummy('Start','',false,false);
584 1470 Luisehahne
	// Load addons into DB
585
	$dirs['modules'] = WB_PATH.'/modules/';
586
	$dirs['templates'] = WB_PATH.'/templates/';
587
	$dirs['languages'] = WB_PATH.'/languages/';
588 1540 Luisehahne
589 1470 Luisehahne
	foreach($dirs AS $type => $dir) {
590 1686 darkviper
		if(($handle = opendir($dir))) {
591 1470 Luisehahne
			while(false !== ($file = readdir($handle))) {
592
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
593
					// Get addon type
594
					if($type == 'modules') {
595
						load_module($dir.'/'.$file, true);
596
						// Pretty ugly hack to let modules run $admin->set_error
597
						// See dummy class definition admin_dummy above
598
						if ($admin->error!='') {
599
							set_error($admin->error);
600
						}
601
					} elseif($type == 'templates') {
602
						load_template($dir.'/'.$file);
603
					} elseif($type == 'languages') {
604
						load_language($dir.'/'.$file);
605
					}
606
				}
607
			}
608 1686 darkviper
			closedir($handle);
609 1470 Luisehahne
		}
610
	}
611 1684 Luisehahne
612 1821 Luisehahne
// Check if there was a database error
613 1470 Luisehahne
	if($database->is_error()) {
614
		set_error($database->get_error());
615
	}
616
617 1870 Luisehahne
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY )) ) {  }
618
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY.'/home' )) ) {  }
619
	if ( sizeof(createFolderProtectFile( WB_PATH.PAGES_DIRECTORY )) ) {  }
620 1818 Luisehahne
621 1684 Luisehahne
// end of if install_tables
622
623 1529 Luisehahne
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
624
// Setup template object, parse vars to it, then parse it
625 1722 Luisehahne
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('loginBox.htt'));
626 1529 Luisehahne
627 1470 Luisehahne
// Log the user in and go to Website Baker Administration
628
$thisApp = new Login(
629 1821 Luisehahne
	array(
630
			"MAX_ATTEMPS" => "50",
631
			"WARNING_URL" => $ThemeUrl."/warning.html",
632
			"USERNAME_FIELDNAME" => 'admin_username',
633
			"PASSWORD_FIELDNAME" => 'admin_password',
634
			"REMEMBER_ME_OPTION" => SMART_LOGIN,
635
			"MIN_USERNAME_LEN" => "2",
636
			"MIN_PASSWORD_LEN" => "3",
637
			"MAX_USERNAME_LEN" => "30",
638
			"MAX_PASSWORD_LEN" => "30",
639
			'LOGIN_URL' => ADMIN_URL."/login/index.php",
640
			'DEFAULT_URL' => ADMIN_URL."/start/index.php",
641
			'TEMPLATE_DIR' => $ThemePath,
642
			'TEMPLATE_FILE' => 'loginBox.htt',
643
			'FRONTEND' => false,
644
			'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
645
			'USERS_TABLE' => TABLE_PREFIX."users",
646
			'GROUPS_TABLE' => TABLE_PREFIX."groups",
647
	)
648 1470 Luisehahne
);