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 1931 darkviper
if(!defined('DEBUG')) { define('DEBUG', true); }
38 1470 Luisehahne
39 1870 Luisehahne
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 1896 Luisehahne
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 1884 Luisehahne
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 1885 Luisehahne
				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 1884 Luisehahne
			}
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 1887 Luisehahne
			if(!defined('TABLE_PREFIX')) {define('TABLE_PREFIX', $db['table_prefix']);}
113 1884 Luisehahne
			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 1885 Luisehahne
				            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
121
				            . '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
122 1884 Luisehahne
			}
123
			unset($db, $aCfg);
124
			return $aRetval;
125
		}
126
		throw new RuntimeException('unable to read setup.ini.php');
127
	}
128
129 1470 Luisehahne
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 1737 Luisehahne
			$_SESSION['website_title'] = $_POST['website_title'];
151 1470 Luisehahne
			$_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 1737 Luisehahne
			$_SESSION['database_password'] = '';
166 1470 Luisehahne
			$_SESSION['database_name'] = $_POST['database_name'];
167
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
168
			if(!isset($_POST['install_tables'])) {
169 1737 Luisehahne
				$_SESSION['install_tables'] = true;
170 1470 Luisehahne
			} 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 1737 Luisehahne
			$_SESSION['admin_password'] = '';
177
			$_SESSION['admin_repassword'] = '';
178 1470 Luisehahne
		}
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 1529 Luisehahne
/* */
193 1470 Luisehahne
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 1870 Luisehahne
		$default_file_mode = '0666';
207 1470 Luisehahne
	}
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 1725 Luisehahne
	set_error('Please fill-in the wesite title below');
238 1470 Luisehahne
}
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 1885 Luisehahne
$wb_url = trim(str_replace('\\', '/', $wb_url), '/').'/';
251 1470 Luisehahne
// 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 2016 darkviper
	$dir_mode = '0666';
283 1470 Luisehahne
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
284 2016 darkviper
	$file_mode = '0666';
285 1470 Luisehahne
	$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 1770 Luisehahne
 }
299 1470 Luisehahne
// 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 1770 Luisehahne
	if(!preg_match('/^[a-z0-9_-]*$/i', $_POST['database_name'])) {
305 1470 Luisehahne
		// 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 1770 Luisehahne
if(!preg_match('/^[a-z0-9_]*$/i', $_POST['table_prefix'])) {
312 1470 Luisehahne
	// 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 1770 Luisehahne
// 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 1884 Luisehahne
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
326 1770 Luisehahne
	set_error('Please enter a database password', 'database_password');
327
} else {
328
	$database_password = $_POST['database_password'];
329
}
330
331 1470 Luisehahne
// Find out if the user wants to install tables and data
332 1695 Luisehahne
$install_tables = ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
333 1470 Luisehahne
// 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 1884 Luisehahne
$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 1885 Luisehahne
."DEBUG   = false\n"
386 2016 darkviper
."AppUrl  = \"".$wb_url."\"\n"
387
."AcpDir  = \"admin/\"\n"
388 1884 Luisehahne
.";##########\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 1470 Luisehahne
// Check if the file exists and is writable first.
403 1884 Luisehahne
if(file_exists($sConfigFile) && is_writable($sConfigFile)) {
404
	if(!$handle = fopen($sConfigFile, 'w')) {
405
		set_error("Cannot open the configuration file ($sConfigName)");
406 1470 Luisehahne
	} else {
407 1884 Luisehahne
		if (fwrite($handle, $sConfigContent) === FALSE) {
408
			set_error("Cannot write to the configuration file ($sConfigName)");
409 1470 Luisehahne
		}
410
		// Close file
411
		fclose($handle);
412
	}
413
} else {
414 1884 Luisehahne
	set_error("The configuration file $sConfigName is not writable. Change its permissions so it is, then re-run step 4.");
415 1470 Luisehahne
}
416
417 1887 Luisehahne
//_SetInstallPathConstants();
418 1896 Luisehahne
if(!defined('WB_INSTALL_PROCESS')){ define('WB_INSTALL_PROCESS', true ); }
419
if(!defined('WB_URL')){ define('WB_URL', trim( $wb_url,'/' )); }
420 1887 Luisehahne
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 1896 Luisehahne
// load db configuration ---
424
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
425
$aSqlData = _readConfiguration($sDbConnectType);
426 1884 Luisehahne
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 1870 Luisehahne
	}
438 1885 Luisehahne
} catch (WbDatabaseException $e) {
439 1884 Luisehahne
	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 1470 Luisehahne
445 1884 Luisehahne
unset($aSqlData);
446
// write the config.php
447
$sConfigContent = "<?php\n"
448
    ."/* this file is for backward compatibility only */\n"
449 1934 darkviper
    ."/* never put any code in this file! */\n"
450 1884 Luisehahne
    ."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 1470 Luisehahne
460 1529 Luisehahne
// Dummy class to allow modules' install scripts to call $admin->print_error
461 1686 darkviper
	class admin_dummy extends admin
462 1529 Luisehahne
	{
463 1686 darkviper
		var $error='';
464
		function print_error($message, $link = 'index.php', $auto_footer = true)
465
		{
466
			$this->error=$message;
467
		}
468 1529 Luisehahne
	}
469 1470 Luisehahne
470 1822 Luisehahne
//  core tables only structure
471 1870 Luisehahne
	$sSqlFileName = dirname(__FILE__).'/sql/websitebaker.sql';
472
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
473 1684 Luisehahne
474 1470 Luisehahne
	require(ADMIN_PATH.'/interface/version.php');
475 1684 Luisehahne
476 1930 darkviper
	$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 1963 darkviper
	     . '(\'server_timezone\', \'UTC\'), '
489 1930 darkviper
	     . '(\'default_timezone\', \''.$default_timezone.'\'), '
490
	     . '(\'default_date_format\', \'Y-m-d\'), '
491
	     . '(\'default_time_format\', \'h:i A\'), '
492
	     . '(\'redirect_timer\', \'1500\'), '
493 2030 Luisehahne
	     . '(\'home_folders\', \'false\'), '
494 1930 darkviper
	     . '(\'warn_page_leave\', \'1\'), '
495
	     . '(\'default_template\', \'round\'), '
496
	     . '(\'default_theme\', \'wb_theme\'), '
497
	     . '(\'default_charset\', \'utf-8\'), '
498
	     . '(\'multiple_menus\', \'true\'), '
499
	     . '(\'page_level_limit\', \'6\'), '
500
	     . '(\'intro_page\', \'false\'), '
501
	     . '(\'page_trash\', \'inline\'), '
502
	     . '(\'homepage_redirection\', \'false\'), '
503 2030 Luisehahne
	     . '(\'page_languages\', \'false\'), '
504 1930 darkviper
	     . '(\'wysiwyg_editor\', \'fckeditor\'), '
505
	     . '(\'manage_sections\', \'true\'), '
506
	     . '(\'section_blocks\', \'false\'), '
507
	     . '(\'smart_login\', \'false\'), '
508
	     . '(\'frontend_login\', \'false\'), '
509
	     . '(\'frontend_signup\', \'false\'), '
510
	     . '(\'search\', \'public\'), '
511
	     . '(\'page_extension\', \'.php\'), '
512
	     . '(\'page_spacer\', \'-\'), '
513
	     . '(\'pages_directory\', \'/pages\'), '
514
	     . '(\'rename_files_on_upload\', \'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js,txt\'), '
515
	     . '(\'media_directory\', \'/media\'), '
516
	     . '(\'operating_system\', \''.$operating_system.'\'), '
517
	     . '(\'string_file_mode\', \''.$file_mode.'\'), '
518
	     . '(\'string_dir_mode\', \''.$dir_mode.'\'), '
519
	     . '(\'wbmailer_routine\', \'phpmail\'), '
520
	     . '(\'server_email\', \''.$admin_email.'\'), '
521
	     . '(\'wbmailer_default_sendername\', \'WebsiteBaker Mailer\'), '
522
	     . '(\'wbmailer_smtp_host\', \'\'), '
523
	     . '(\'wbmailer_smtp_auth\', \'\'), '
524
	     . '(\'wbmailer_smtp_username\', \'\'), '
525
	     . '(\'wbmailer_smtp_password\', \'\'), '
526
	     . '(\'fingerprint_with_ip_octets\', \'2\'), '
527
	     . '(\'secure_form_module\', \'\'), '
528
	     . '(\'mediasettings\', \'\'), '
529
	     . '(\'wb_revision\', \''.REVISION.'\'), '
530
 	     . '(\'wb_sp\', \''.SP.'\'), '
531
	     . '(\'page_icon_dir\', \'/templates/*/title_images\'), '
532
	     . '(\'dev_infos\', \'false\'), '
533
	     . '(\'groups_updated\', \''.time().'\'), '
534
	     . '(\'wbmail_signature\', \'\'), '
535
	     . '(\'confirmed_registration\', \'1\'), '
536
	     . '(\'page_extendet\', \'true\'), '
537
	     . '(\'system_locked\', \'0\'), '
538
	     . '(\'password_crypt_loops\', \'12\'), '
539
	     . '(\'password_hash_type\', \'false\'), '
540
	     . '(\'password_length\', \'10\'), '
541
		 . '(\'password_use_types\', \''.(int)0xFFFF.'\') '
542
	     . '';
543 1931 darkviper
	if(!$database->query($sql)) { set_error($database->get_error()); }
544 1684 Luisehahne
545 1822 Luisehahne
	// Admin group
546 1930 darkviper
	$full_system_permissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,'
547
	                          . 'groups_modify,groups_view,languages,languages_install,languages_uninstall,'
548
	                          . 'languages_view,media,media_create,media_delete,media_rename,media_upload,'
549
	                          . 'media_view,modules,modules_advanced,modules_install,modules_uninstall,'
550
	                          . 'modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,'
551
	                          . 'pages_modify,pages_settings,pages_view,preferences,preferences_view,'
552
	                          . 'settings,settings_advanced,settings_basic,settings_view,templates,'
553
	                          . 'templates_install,templates_uninstall,templates_view,users,users_add,'
554
	                          . 'users_delete,users_modify,users_view';
555
	$sql = 'INSERT INTO `'.TABLE_PREFIX.'groups` '
556
	     . 'SET `group_id` =1,'
557
	     .     '`name`=\'Administrators\','
558
		 .     '`system_permissions`=\''.$full_system_permissions.'\','
559
		 .     '`module_permissions`=\'\','
560
		 .     '`template_permissions`=\'\'';
561
	if(!$database->query($sql)) { set_error($database->get_error()); }
562 1822 Luisehahne
563 1821 Luisehahne
// Admin user
564 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, '');";
565 1821 Luisehahne
	if(!$database->query($insert_admin_user)) { set_error($database->get_error()); }
566 1684 Luisehahne
567 1822 Luisehahne
// Search layout default data
568 1870 Luisehahne
	$sSqlFileName = dirname(__FILE__).'/sql/wb_search_data.sql';
569
	if(!$database->SqlImport($sSqlFileName,TABLE_PREFIX, false)) { set_error($database->get_error()); }
570 1684 Luisehahne
571 1870 Luisehahne
	require_once(WB_PATH.'/framework/initialize.php');
572 1887 Luisehahne
//
573 1821 Luisehahne
// Include WB functions file
574
	require_once(WB_PATH.'/framework/functions.php');
575
// Re-connect to the database, this time using in-build database class
576
	require_once(WB_PATH.'/framework/class.login.php');
577 1470 Luisehahne
	// Include the PclZip class file (thanks to
578
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
579
	// Install add-ons
580
	if(file_exists(WB_PATH.'/install/modules')) {
581
		// Unpack pre-packaged modules
582
	}
583
	if(file_exists(WB_PATH.'/install/templates')) {
584
		// Unpack pre-packaged templates
585
	}
586
	if(file_exists(WB_PATH.'/install/languages')) {
587
		// Unpack pre-packaged languages
588
	}
589 1734 Luisehahne
590 1529 Luisehahne
	$admin=new admin_dummy('Start','',false,false);
591 1470 Luisehahne
	// Load addons into DB
592
	$dirs['modules'] = WB_PATH.'/modules/';
593
	$dirs['templates'] = WB_PATH.'/templates/';
594
	$dirs['languages'] = WB_PATH.'/languages/';
595 1540 Luisehahne
596 1470 Luisehahne
	foreach($dirs AS $type => $dir) {
597 1686 darkviper
		if(($handle = opendir($dir))) {
598 1470 Luisehahne
			while(false !== ($file = readdir($handle))) {
599
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
600
					// Get addon type
601
					if($type == 'modules') {
602
						load_module($dir.'/'.$file, true);
603
						// Pretty ugly hack to let modules run $admin->set_error
604
						// See dummy class definition admin_dummy above
605
						if ($admin->error!='') {
606
							set_error($admin->error);
607
						}
608
					} elseif($type == 'templates') {
609
						load_template($dir.'/'.$file);
610
					} elseif($type == 'languages') {
611
						load_language($dir.'/'.$file);
612
					}
613
				}
614
			}
615 1686 darkviper
			closedir($handle);
616 1470 Luisehahne
		}
617
	}
618 1684 Luisehahne
619 1821 Luisehahne
// Check if there was a database error
620 1470 Luisehahne
	if($database->is_error()) {
621
		set_error($database->get_error());
622
	}
623
624 1870 Luisehahne
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY )) ) {  }
625
	if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY.'/home' )) ) {  }
626
	if ( sizeof(createFolderProtectFile( WB_PATH.PAGES_DIRECTORY )) ) {  }
627 1818 Luisehahne
628 1684 Luisehahne
// end of if install_tables
629
630 1529 Luisehahne
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
631
// Setup template object, parse vars to it, then parse it
632 1722 Luisehahne
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('loginBox.htt'));
633 1529 Luisehahne
634 1470 Luisehahne
// Log the user in and go to Website Baker Administration
635
$thisApp = new Login(
636 1821 Luisehahne
	array(
637
			"MAX_ATTEMPS" => "50",
638
			"WARNING_URL" => $ThemeUrl."/warning.html",
639
			"USERNAME_FIELDNAME" => 'admin_username',
640
			"PASSWORD_FIELDNAME" => 'admin_password',
641
			"REMEMBER_ME_OPTION" => SMART_LOGIN,
642
			"MIN_USERNAME_LEN" => "2",
643
			"MIN_PASSWORD_LEN" => "3",
644
			"MAX_USERNAME_LEN" => "30",
645
			"MAX_PASSWORD_LEN" => "30",
646
			'LOGIN_URL' => ADMIN_URL."/login/index.php",
647
			'DEFAULT_URL' => ADMIN_URL."/start/index.php",
648
			'TEMPLATE_DIR' => $ThemePath,
649
			'TEMPLATE_FILE' => 'loginBox.htt',
650
			'FRONTEND' => false,
651
			'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
652
			'USERS_TABLE' => TABLE_PREFIX."users",
653
			'GROUPS_TABLE' => TABLE_PREFIX."groups",
654
	)
655 1470 Luisehahne
);