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