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