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