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