| 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 |
2107
|
darkviper
|
*
|
| 22 |
1884
|
Luisehahne
|
* @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 |
2075
|
darkviper
|
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 |
2104
|
darkviper
|
include(__DIR__.'/InstallHelper.php');
|
| 43 |
2075
|
darkviper
|
// register PHPMailer autoloader ---
|
| 44 |
|
|
if (!function_exists('PHPMailerAutoload')) {
|
| 45 |
|
|
require(dirname(__DIR__).'/include/phpmailer/PHPMailerAutoload.php');
|
| 46 |
|
|
}
|
| 47 |
1870
|
Luisehahne
|
|
| 48 |
1896
|
Luisehahne
|
function errorLogs($error_str)
|
| 49 |
|
|
{
|
| 50 |
2107
|
darkviper
|
$log_error = true;
|
| 51 |
|
|
if ( ! function_exists('error_log') ) { $log_error = false; }
|
| 52 |
|
|
$log_file = @ini_get('error_log');
|
| 53 |
|
|
if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) {
|
| 54 |
|
|
$log_error = false;
|
| 55 |
|
|
}
|
| 56 |
|
|
if ( $log_error ) {@error_log($error_str, 0);}
|
| 57 |
1896
|
Luisehahne
|
}
|
| 58 |
1884
|
Luisehahne
|
|
| 59 |
|
|
/**
|
| 60 |
|
|
* Read DB settings from configuration file
|
| 61 |
|
|
* @return string
|
| 62 |
|
|
* @throws RuntimeException
|
| 63 |
2107
|
darkviper
|
*
|
| 64 |
1884
|
Luisehahne
|
*/
|
| 65 |
2107
|
darkviper
|
function _readConfiguration($sRetvalType = 'url') {
|
| 66 |
|
|
// check for valid file request. Becomes more stronger in next version
|
| 67 |
|
|
$x = debug_backtrace();
|
| 68 |
|
|
$bValidRequest = false;
|
| 69 |
|
|
if(sizeof($x) != 0) {
|
| 70 |
|
|
foreach($x as $aStep) {
|
| 71 |
|
|
// define the scripts which can read the configuration
|
| 72 |
|
|
if(preg_match('/(save.php|index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
|
| 73 |
|
|
$bValidRequest = true;
|
| 74 |
|
|
break;
|
| 75 |
|
|
}
|
| 76 |
|
|
}
|
| 77 |
|
|
}else {
|
| 78 |
|
|
$bValidRequest = true;
|
| 79 |
|
|
}
|
| 80 |
|
|
if(!$bValidRequest) {
|
| 81 |
|
|
throw new RuntimeException('illegal function request!');
|
| 82 |
|
|
}
|
| 83 |
|
|
$aRetval = array();
|
| 84 |
|
|
$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
|
| 85 |
|
|
if(is_readable($sSetupFile)) {
|
| 86 |
|
|
$aCfg = parse_ini_file($sSetupFile, true);
|
| 87 |
|
|
foreach($aCfg['Constants'] as $key=>$value) {
|
| 88 |
|
|
switch($key):
|
| 89 |
|
|
case 'DEBUG':
|
| 90 |
|
|
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
| 91 |
|
|
break;
|
| 92 |
|
|
case 'WB_URL':
|
| 93 |
|
|
case 'AppUrl':
|
| 94 |
|
|
$value = trim(str_replace('\\', '/', $value), '/');
|
| 95 |
|
|
if(!defined('WB_URL')) { define('WB_URL', $value); }
|
| 96 |
|
|
break;
|
| 97 |
|
|
case 'ADMIN_DIRECTORY':
|
| 98 |
|
|
case 'AcpDir':
|
| 99 |
|
|
$value = trim(str_replace('\\', '/', $value), '/');
|
| 100 |
|
|
if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
|
| 101 |
|
|
break;
|
| 102 |
|
|
default:
|
| 103 |
|
|
if(!defined($key)) { define($key, $value); }
|
| 104 |
|
|
break;
|
| 105 |
|
|
endswitch;
|
| 106 |
|
|
}
|
| 107 |
|
|
$db = $aCfg['DataBase'];
|
| 108 |
|
|
$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
|
| 109 |
|
|
$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
|
| 110 |
|
|
$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
|
| 111 |
|
|
$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
|
| 112 |
|
|
$db['port'] = isset($db['port']) ? $db['port'] : '3306';
|
| 113 |
|
|
$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
|
| 114 |
|
|
$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
|
| 115 |
|
|
$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
|
| 116 |
|
|
$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
|
| 117 |
|
|
if(!defined('TABLE_PREFIX')) {define('TABLE_PREFIX', $db['table_prefix']);}
|
| 118 |
|
|
if($sRetvalType == 'dsn') {
|
| 119 |
|
|
$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';'
|
| 120 |
|
|
. ($db['port'] != '' ? 'port='.(int)$db['port'].';' : '');
|
| 121 |
|
|
$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
|
| 122 |
|
|
$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']);
|
| 123 |
|
|
}else { // $sRetvalType == 'url'
|
| 124 |
|
|
$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
|
| 125 |
|
|
. $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
|
| 126 |
|
|
. '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
|
| 127 |
|
|
}
|
| 128 |
|
|
unset($db, $aCfg);
|
| 129 |
|
|
return $aRetval;
|
| 130 |
|
|
}
|
| 131 |
|
|
throw new RuntimeException('unable to read setup.ini.php');
|
| 132 |
|
|
}
|
| 133 |
1884
|
Luisehahne
|
|
| 134 |
1470
|
Luisehahne
|
if (true === $debug) {
|
| 135 |
2107
|
darkviper
|
ini_set('display_errors', 1);
|
| 136 |
|
|
error_reporting(E_ALL);
|
| 137 |
1470
|
Luisehahne
|
}
|
| 138 |
|
|
// Start a session
|
| 139 |
|
|
if(!defined('SESSION_STARTED')) {
|
| 140 |
2107
|
darkviper
|
session_name('wb_session_id');
|
| 141 |
|
|
session_start();
|
| 142 |
|
|
define('SESSION_STARTED', true);
|
| 143 |
1470
|
Luisehahne
|
}
|
| 144 |
|
|
// get random-part for session_name()
|
| 145 |
|
|
list($usec,$sec) = explode(' ',microtime());
|
| 146 |
|
|
srand((float)$sec+((float)$usec*100000));
|
| 147 |
|
|
$session_rand = rand(1000,9999);
|
| 148 |
|
|
|
| 149 |
|
|
// Function to set error
|
| 150 |
|
|
function set_error($message, $field_name = '') {
|
| 151 |
2107
|
darkviper
|
global $_POST;
|
| 152 |
|
|
if(isset($message) AND $message != '') {
|
| 153 |
|
|
// Copy values entered into session so user doesn't have to re-enter everything
|
| 154 |
|
|
if(isset($_POST['website_title'])) {
|
| 155 |
|
|
$_SESSION['website_title'] = $_POST['website_title'];
|
| 156 |
|
|
$_SESSION['default_timezone'] = $_POST['default_timezone'];
|
| 157 |
|
|
$_SESSION['default_language'] = $_POST['default_language'];
|
| 158 |
|
|
if(!isset($_POST['operating_system'])) {
|
| 159 |
|
|
$_SESSION['operating_system'] = 'linux';
|
| 160 |
|
|
} else {
|
| 161 |
|
|
$_SESSION['operating_system'] = $_POST['operating_system'];
|
| 162 |
|
|
}
|
| 163 |
|
|
if(!isset($_POST['world_writeable'])) {
|
| 164 |
|
|
$_SESSION['world_writeable'] = false;
|
| 165 |
|
|
} else {
|
| 166 |
|
|
$_SESSION['world_writeable'] = true;
|
| 167 |
|
|
}
|
| 168 |
|
|
$_SESSION['database_host'] = $_POST['database_host'];
|
| 169 |
|
|
$_SESSION['database_username'] = $_POST['database_username'];
|
| 170 |
|
|
$_SESSION['database_password'] = '';
|
| 171 |
|
|
$_SESSION['database_name'] = $_POST['database_name'];
|
| 172 |
|
|
$_SESSION['table_prefix'] = $_POST['table_prefix'];
|
| 173 |
|
|
if(!isset($_POST['install_tables'])) {
|
| 174 |
|
|
$_SESSION['install_tables'] = true;
|
| 175 |
|
|
} else {
|
| 176 |
|
|
$_SESSION['install_tables'] = true;
|
| 177 |
|
|
}
|
| 178 |
|
|
$_SESSION['website_title'] = $_POST['website_title'];
|
| 179 |
|
|
$_SESSION['admin_username'] = $_POST['admin_username'];
|
| 180 |
|
|
$_SESSION['admin_email'] = $_POST['admin_email'];
|
| 181 |
|
|
$_SESSION['admin_password'] = '';
|
| 182 |
|
|
$_SESSION['admin_repassword'] = '';
|
| 183 |
|
|
}
|
| 184 |
|
|
// Set the message
|
| 185 |
|
|
$_SESSION['message'] = $message;
|
| 186 |
|
|
// Set the element(s) to highlight
|
| 187 |
|
|
if($field_name != '') {
|
| 188 |
|
|
$_SESSION['ERROR_FIELD'] = $field_name;
|
| 189 |
|
|
}
|
| 190 |
|
|
// Specify that session support is enabled
|
| 191 |
|
|
$_SESSION['session_support'] = '<font class="good">Enabled</font>';
|
| 192 |
|
|
// Redirect to first page again and exit
|
| 193 |
|
|
header('Location: index.php?sessions_checked=true');
|
| 194 |
|
|
exit();
|
| 195 |
|
|
}
|
| 196 |
1470
|
Luisehahne
|
}
|
| 197 |
1529
|
Luisehahne
|
/* */
|
| 198 |
1470
|
Luisehahne
|
|
| 199 |
|
|
// Function to workout what the default permissions are for files created by the webserver
|
| 200 |
|
|
function default_file_mode($temp_dir) {
|
| 201 |
2107
|
darkviper
|
$v = explode(".",PHP_VERSION);
|
| 202 |
|
|
$v = $v[0].$v[1];
|
| 203 |
|
|
if($v > 41 AND is_writable($temp_dir)) {
|
| 204 |
|
|
$filename = $temp_dir.'/test_permissions.txt';
|
| 205 |
|
|
$handle = fopen($filename, 'w');
|
| 206 |
|
|
fwrite($handle, 'This file is to get the default file permissions');
|
| 207 |
|
|
fclose($handle);
|
| 208 |
|
|
$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
|
| 209 |
|
|
unlink($filename);
|
| 210 |
|
|
} else {
|
| 211 |
|
|
$default_file_mode = '0666';
|
| 212 |
|
|
}
|
| 213 |
|
|
return $default_file_mode;
|
| 214 |
1470
|
Luisehahne
|
}
|
| 215 |
|
|
|
| 216 |
|
|
// Function to workout what the default permissions are for directories created by the webserver
|
| 217 |
|
|
function default_dir_mode($temp_dir) {
|
| 218 |
2107
|
darkviper
|
$v = explode(".",PHP_VERSION);
|
| 219 |
|
|
$v = $v[0].$v[1];
|
| 220 |
|
|
if($v > 41 AND is_writable($temp_dir)) {
|
| 221 |
|
|
$dirname = $temp_dir.'/test_permissions/';
|
| 222 |
|
|
mkdir($dirname);
|
| 223 |
|
|
$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
|
| 224 |
|
|
rmdir($dirname);
|
| 225 |
|
|
} else {
|
| 226 |
|
|
$default_dir_mode = '0777';
|
| 227 |
|
|
}
|
| 228 |
|
|
return $default_dir_mode;
|
| 229 |
1470
|
Luisehahne
|
}
|
| 230 |
|
|
|
| 231 |
|
|
function add_slashes($input) {
|
| 232 |
2107
|
darkviper
|
if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
| 233 |
|
|
return $input;
|
| 234 |
|
|
}
|
| 235 |
|
|
$output = addslashes($input);
|
| 236 |
|
|
return $output;
|
| 237 |
1470
|
Luisehahne
|
}
|
| 238 |
|
|
|
| 239 |
|
|
// Begin check to see if form was even submitted
|
| 240 |
|
|
// Set error if no post vars found
|
| 241 |
|
|
if(!isset($_POST['website_title'])) {
|
| 242 |
2107
|
darkviper
|
set_error('Please fill-in the wesite title below');
|
| 243 |
1470
|
Luisehahne
|
}
|
| 244 |
|
|
// End check to see if form was even submitted
|
| 245 |
|
|
|
| 246 |
|
|
// Begin path and timezone details code
|
| 247 |
|
|
|
| 248 |
|
|
// Check if user has entered the installation url
|
| 249 |
|
|
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
|
| 250 |
2107
|
darkviper
|
set_error('Please enter an absolute URL', 'wb_url');
|
| 251 |
1470
|
Luisehahne
|
} else {
|
| 252 |
2107
|
darkviper
|
$wb_url = $_POST['wb_url'];
|
| 253 |
1470
|
Luisehahne
|
}
|
| 254 |
|
|
// Remove any slashes at the end of the URL
|
| 255 |
1885
|
Luisehahne
|
$wb_url = trim(str_replace('\\', '/', $wb_url), '/').'/';
|
| 256 |
1470
|
Luisehahne
|
// Get the default time zone
|
| 257 |
|
|
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
|
| 258 |
2107
|
darkviper
|
set_error('Please select a valid default timezone', 'default_timezone');
|
| 259 |
1470
|
Luisehahne
|
} else {
|
| 260 |
2107
|
darkviper
|
$default_timezone = $_POST['default_timezone']*60*60;
|
| 261 |
1470
|
Luisehahne
|
}
|
| 262 |
|
|
// End path and timezone details code
|
| 263 |
|
|
|
| 264 |
|
|
// Get the default language
|
| 265 |
2107
|
darkviper
|
$sLanguageDirectory = dirname(__DIR__).'/languages/';
|
| 266 |
|
|
$allowed_languages = InstallHelper::getAvailableLanguages($sLanguageDirectory);
|
| 267 |
|
|
if (
|
| 268 |
|
|
!isset($_POST['default_language']) ||
|
| 269 |
|
|
!array_key_exists($_POST['default_language'], $allowed_languages)
|
| 270 |
|
|
) {
|
| 271 |
|
|
set_error('Please select a valid default backend language','default_language');
|
| 272 |
1470
|
Luisehahne
|
} else {
|
| 273 |
2107
|
darkviper
|
$default_language = $_POST['default_language'];
|
| 274 |
|
|
// make sure the selected language file exists in the language folder
|
| 275 |
|
|
if(!file_exists('../languages/' .$default_language .'.php')) {
|
| 276 |
|
|
set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
|
| 277 |
|
|
}
|
| 278 |
1470
|
Luisehahne
|
}
|
| 279 |
|
|
// End default language details code
|
| 280 |
|
|
|
| 281 |
|
|
// Begin operating system specific code
|
| 282 |
|
|
// Get operating system
|
| 283 |
|
|
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
|
| 284 |
2107
|
darkviper
|
set_error('Please select a valid operating system');
|
| 285 |
1470
|
Luisehahne
|
} else {
|
| 286 |
2107
|
darkviper
|
$operating_system = $_POST['operating_system'];
|
| 287 |
1470
|
Luisehahne
|
}
|
| 288 |
|
|
// Work-out file permissions
|
| 289 |
|
|
if($operating_system == 'windows') {
|
| 290 |
2107
|
darkviper
|
$file_mode = '0777';
|
| 291 |
|
|
$dir_mode = '0666';
|
| 292 |
1470
|
Luisehahne
|
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
|
| 293 |
2107
|
darkviper
|
$file_mode = '0666';
|
| 294 |
|
|
$dir_mode = '0777';
|
| 295 |
1470
|
Luisehahne
|
} else {
|
| 296 |
2107
|
darkviper
|
$file_mode = default_file_mode('../temp');
|
| 297 |
|
|
$dir_mode = default_dir_mode('../temp');
|
| 298 |
1470
|
Luisehahne
|
}
|
| 299 |
|
|
// End operating system specific code
|
| 300 |
|
|
|
| 301 |
|
|
// Begin database details code
|
| 302 |
|
|
// Check if user has entered a database host
|
| 303 |
|
|
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
|
| 304 |
2107
|
darkviper
|
set_error('Please enter a database host name', 'database_host');
|
| 305 |
1470
|
Luisehahne
|
} else {
|
| 306 |
2107
|
darkviper
|
$database_host = $_POST['database_host'];
|
| 307 |
1770
|
Luisehahne
|
}
|
| 308 |
1470
|
Luisehahne
|
// Check if user has entered a database name
|
| 309 |
|
|
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
|
| 310 |
2107
|
darkviper
|
set_error('Please enter a database name', 'database_name');
|
| 311 |
1470
|
Luisehahne
|
} else {
|
| 312 |
2107
|
darkviper
|
// make sure only allowed characters are specified
|
| 313 |
|
|
if(!preg_match('/^[a-z0-9_-]*$/i', $_POST['database_name'])) {
|
| 314 |
|
|
// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
|
| 315 |
|
|
set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
|
| 316 |
|
|
}
|
| 317 |
|
|
$database_name = $_POST['database_name'];
|
| 318 |
1470
|
Luisehahne
|
}
|
| 319 |
|
|
// Get table prefix
|
| 320 |
1770
|
Luisehahne
|
if(!preg_match('/^[a-z0-9_]*$/i', $_POST['table_prefix'])) {
|
| 321 |
2107
|
darkviper
|
// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
|
| 322 |
|
|
set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
|
| 323 |
1470
|
Luisehahne
|
} else {
|
| 324 |
2107
|
darkviper
|
$table_prefix = $_POST['table_prefix'];
|
| 325 |
1470
|
Luisehahne
|
}
|
| 326 |
|
|
|
| 327 |
1770
|
Luisehahne
|
// Check if user has entered a database username
|
| 328 |
|
|
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
|
| 329 |
2107
|
darkviper
|
set_error('Please enter a database username','database_username');
|
| 330 |
1770
|
Luisehahne
|
} else {
|
| 331 |
2107
|
darkviper
|
$database_username = $_POST['database_username'];
|
| 332 |
1770
|
Luisehahne
|
}
|
| 333 |
|
|
// Check if user has entered a database password
|
| 334 |
1884
|
Luisehahne
|
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
|
| 335 |
2107
|
darkviper
|
set_error('Please enter a database password', 'database_password');
|
| 336 |
1770
|
Luisehahne
|
} else {
|
| 337 |
2107
|
darkviper
|
$database_password = $_POST['database_password'];
|
| 338 |
1770
|
Luisehahne
|
}
|
| 339 |
|
|
|
| 340 |
1470
|
Luisehahne
|
// Find out if the user wants to install tables and data
|
| 341 |
1695
|
Luisehahne
|
$install_tables = ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
|
| 342 |
1470
|
Luisehahne
|
// End database details code
|
| 343 |
|
|
|
| 344 |
|
|
// Begin website title code
|
| 345 |
|
|
// Get website title
|
| 346 |
|
|
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
|
| 347 |
2107
|
darkviper
|
set_error('Please enter a website title', 'website_title');
|
| 348 |
1470
|
Luisehahne
|
} else {
|
| 349 |
2107
|
darkviper
|
$website_title = add_slashes($_POST['website_title']);
|
| 350 |
1470
|
Luisehahne
|
}
|
| 351 |
|
|
// End website title code
|
| 352 |
|
|
|
| 353 |
|
|
// Begin admin user details code
|
| 354 |
|
|
// Get admin username
|
| 355 |
|
|
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
|
| 356 |
2107
|
darkviper
|
set_error('Please enter a username for the Administrator account','admin_username');
|
| 357 |
1470
|
Luisehahne
|
} else {
|
| 358 |
2107
|
darkviper
|
$admin_username = $_POST['admin_username'];
|
| 359 |
1470
|
Luisehahne
|
}
|
| 360 |
|
|
// Get admin email and validate it
|
| 361 |
|
|
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
|
| 362 |
2107
|
darkviper
|
set_error('Please enter an email for the Administrator account','admin_email');
|
| 363 |
1470
|
Luisehahne
|
} else {
|
| 364 |
2107
|
darkviper
|
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i', $_POST['admin_email'])) {
|
| 365 |
|
|
$admin_email = $_POST['admin_email'];
|
| 366 |
|
|
} else {
|
| 367 |
|
|
set_error('Please enter a valid email address for the Administrator account','admin_email');
|
| 368 |
|
|
}
|
| 369 |
1470
|
Luisehahne
|
}
|
| 370 |
|
|
// Get the two admin passwords entered, and check that they match
|
| 371 |
|
|
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
|
| 372 |
2107
|
darkviper
|
set_error('Please enter a password for the Administrator account','admin_password');
|
| 373 |
1470
|
Luisehahne
|
} else {
|
| 374 |
2107
|
darkviper
|
$admin_password = $_POST['admin_password'];
|
| 375 |
1470
|
Luisehahne
|
}
|
| 376 |
|
|
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
|
| 377 |
2107
|
darkviper
|
set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
|
| 378 |
1470
|
Luisehahne
|
} else {
|
| 379 |
2107
|
darkviper
|
$admin_repassword = $_POST['admin_repassword'];
|
| 380 |
1470
|
Luisehahne
|
}
|
| 381 |
|
|
if($admin_password != $admin_repassword) {
|
| 382 |
2107
|
darkviper
|
set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
|
| 383 |
1470
|
Luisehahne
|
}
|
| 384 |
2095
|
darkviper
|
if (mb_strlen($admin_password) < 6) {
|
| 385 |
2107
|
darkviper
|
set_error('Sorry, the password must have 6 chars at last','admin_password');
|
| 386 |
2095
|
darkviper
|
}
|
| 387 |
|
|
|
| 388 |
1470
|
Luisehahne
|
// End admin user details code
|
| 389 |
|
|
|
| 390 |
|
|
// Try and write settings to config file
|
| 391 |
2107
|
darkviper
|
$sConfigContent =
|
| 392 |
1884
|
Luisehahne
|
";<?php die('sorry, illegal file access'); ?>#####\n"
|
| 393 |
|
|
.";################################################\n"
|
| 394 |
|
|
."; WebsiteBaker configuration file\n"
|
| 395 |
|
|
."; auto generated ".date('Y-m-d h:i:s A e ')."\n"
|
| 396 |
|
|
.";################################################\n"
|
| 397 |
|
|
."[Constants]\n"
|
| 398 |
1885
|
Luisehahne
|
."DEBUG = false\n"
|
| 399 |
2016
|
darkviper
|
."AppUrl = \"".$wb_url."\"\n"
|
| 400 |
|
|
."AcpDir = \"admin/\"\n"
|
| 401 |
1884
|
Luisehahne
|
.";##########\n"
|
| 402 |
|
|
."[DataBase]\n"
|
| 403 |
|
|
."type = \"mysql\"\n"
|
| 404 |
|
|
."user = \"".$database_username."\"\n"
|
| 405 |
|
|
."pass = \"".$database_password."\"\n"
|
| 406 |
|
|
."host = \"".$database_host."\"\n"
|
| 407 |
|
|
."port = \"3306\"\n"
|
| 408 |
2104
|
darkviper
|
."socket = \"\"\n"
|
| 409 |
1884
|
Luisehahne
|
."name = \"".$database_name."\"\n"
|
| 410 |
|
|
."charset = \"utf8\"\n"
|
| 411 |
|
|
."table_prefix = \"".$table_prefix."\"\n"
|
| 412 |
|
|
.";\n"
|
| 413 |
|
|
.";################################################\n";
|
| 414 |
|
|
$sConfigFile = realpath('../setup.ini.php');
|
| 415 |
|
|
$sConfigName = basename($sConfigFile);
|
| 416 |
1470
|
Luisehahne
|
// Check if the file exists and is writable first.
|
| 417 |
1884
|
Luisehahne
|
if(file_exists($sConfigFile) && is_writable($sConfigFile)) {
|
| 418 |
2107
|
darkviper
|
if(!$handle = fopen($sConfigFile, 'w')) {
|
| 419 |
|
|
set_error("Cannot open the configuration file ($sConfigName)");
|
| 420 |
|
|
} else {
|
| 421 |
|
|
if (fwrite($handle, $sConfigContent) === FALSE) {
|
| 422 |
|
|
set_error("Cannot write to the configuration file ($sConfigName)");
|
| 423 |
|
|
}
|
| 424 |
|
|
// Close file
|
| 425 |
|
|
fclose($handle);
|
| 426 |
|
|
}
|
| 427 |
1470
|
Luisehahne
|
} else {
|
| 428 |
2107
|
darkviper
|
set_error("The configuration file $sConfigName is not writable. Change its permissions so it is, then re-run step 4.");
|
| 429 |
1470
|
Luisehahne
|
}
|
| 430 |
|
|
|
| 431 |
1887
|
Luisehahne
|
//_SetInstallPathConstants();
|
| 432 |
1896
|
Luisehahne
|
if(!defined('WB_INSTALL_PROCESS')){ define('WB_INSTALL_PROCESS', true ); }
|
| 433 |
|
|
if(!defined('WB_URL')){ define('WB_URL', trim( $wb_url,'/' )); }
|
| 434 |
1887
|
Luisehahne
|
if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
|
| 435 |
|
|
if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/admin'); }
|
| 436 |
|
|
if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/admin'); }
|
| 437 |
1896
|
Luisehahne
|
// load db configuration ---
|
| 438 |
|
|
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
|
| 439 |
|
|
$aSqlData = _readConfiguration($sDbConnectType);
|
| 440 |
1884
|
Luisehahne
|
|
| 441 |
|
|
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
|
| 442 |
2107
|
darkviper
|
set_error('It appears the Absolute path that you entered is incorrect');
|
| 443 |
1884
|
Luisehahne
|
}
|
| 444 |
|
|
|
| 445 |
|
|
$database = WbDatabase::getInstance();
|
| 446 |
|
|
try{
|
| 447 |
2107
|
darkviper
|
if($sDbConnectType == 'dsn') {
|
| 448 |
|
|
$bTmp = @$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
|
| 449 |
|
|
}else {
|
| 450 |
|
|
$bTmp = @$database->doConnect($aSqlData[0], TABLE_PREFIX);
|
| 451 |
|
|
}
|
| 452 |
1885
|
Luisehahne
|
} catch (WbDatabaseException $e) {
|
| 453 |
2107
|
darkviper
|
if(!file_put_contents($sConfigFile,"<?php\n")) {
|
| 454 |
|
|
set_error("Cannot write to the configuration file ($sSetupFile)");
|
| 455 |
|
|
}
|
| 456 |
|
|
set_error($e->getMessage());
|
| 457 |
1884
|
Luisehahne
|
}
|
| 458 |
1470
|
Luisehahne
|
|
| 459 |
1884
|
Luisehahne
|
unset($aSqlData);
|
| 460 |
|
|
// write the config.php
|
| 461 |
|
|
$sConfigContent = "<?php\n"
|
| 462 |
|
|
."/* this file is for backward compatibility only */\n"
|
| 463 |
1934
|
darkviper
|
."/* never put any code in this file! */\n"
|
| 464 |
1884
|
Luisehahne
|
."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
|
| 465 |
|
|
$sSetupFile = WB_PATH.'/config.php';
|
| 466 |
|
|
if(!file_put_contents($sSetupFile,$sConfigContent)) {
|
| 467 |
2107
|
darkviper
|
set_error("Cannot write to the configuration file ($sSetupFile)");
|
| 468 |
1884
|
Luisehahne
|
}
|
| 469 |
|
|
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
| 470 |
|
|
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
|
| 471 |
|
|
require_once($sSecMod);
|
| 472 |
2104
|
darkviper
|
require(ADMIN_PATH.'/interface/version.php');
|
| 473 |
|
|
|
| 474 |
|
|
/*****************************
|
| 475 |
|
|
Begin Create Database Tables
|
| 476 |
|
|
*****************************/
|
| 477 |
2110
|
darkviper
|
$oSqlInst = new SqlImport($database, __DIR__.'/sql/install-struct.sql');
|
| 478 |
2107
|
darkviper
|
if ($oSqlInst) {
|
| 479 |
|
|
if (!$oSqlInst->doImport('install')) {
|
| 480 |
|
|
set_error($oSqlInst->getError());
|
| 481 |
2104
|
darkviper
|
}
|
| 482 |
|
|
}
|
| 483 |
2110
|
darkviper
|
$oSqlInst = new SqlImport($database, __DIR__.'/sql/install-data.sql');
|
| 484 |
2107
|
darkviper
|
if ($oSqlInst) {
|
| 485 |
|
|
if (!$oSqlInst->doImport('install')) {
|
| 486 |
|
|
set_error($oSqlInst->getError());
|
| 487 |
2104
|
darkviper
|
}
|
| 488 |
|
|
}
|
| 489 |
2108
|
darkviper
|
unset($oSqlInst);
|
| 490 |
2104
|
darkviper
|
$sql = // additional settings from install input
|
| 491 |
|
|
'REPLACE INTO `'.TABLE_PREFIX.'settings` (`name`, `value`) VALUES '
|
| 492 |
|
|
. '(\'wb_version\', \''.VERSION.'\'), '
|
| 493 |
|
|
. '(\'website_title\', \''.$website_title.'\'), '
|
| 494 |
|
|
. '(\'default_language\', \''.$default_language.'\'), '
|
| 495 |
|
|
. '(\'app_name\', \'wb_'.$session_rand.'\'), '
|
| 496 |
|
|
. '(\'default_timezone\', \''.$default_timezone.'\'), '
|
| 497 |
|
|
. '(\'operating_system\', \''.$operating_system.'\'), '
|
| 498 |
|
|
. '(\'string_file_mode\', \''.$file_mode.'\'), '
|
| 499 |
|
|
. '(\'string_dir_mode\', \''.$dir_mode.'\'), '
|
| 500 |
|
|
. '(\'server_email\', \''.$admin_email.'\'), '
|
| 501 |
|
|
. '(\'wb_revision\', \''.REVISION.'\'), '
|
| 502 |
|
|
. '(\'wb_sp\', \''.SP.'\'), '
|
| 503 |
|
|
. '(\'groups_updated\', \''.time().'\')';
|
| 504 |
|
|
if (! ($database->query($sql))) {
|
| 505 |
|
|
set_error('unable to write \'install presets\' into table \'settings\'');
|
| 506 |
|
|
}
|
| 507 |
|
|
$sql = // add the Admin user
|
| 508 |
|
|
'INSERT INTO `'.TABLE_PREFIX.'users` '
|
| 509 |
|
|
.'SET `user_id`=1, '
|
| 510 |
|
|
. '`group_id`=1, '
|
| 511 |
|
|
. '`groups_id`=\'1\', '
|
| 512 |
|
|
. '`active`=\'1\', '
|
| 513 |
|
|
. '`username`=\''.$admin_username.'\', '
|
| 514 |
|
|
. '`password`=\''.md5($admin_password).'\', '
|
| 515 |
|
|
. '`email`=\''.$admin_email.'\', '
|
| 516 |
|
|
. '`timezone`=\''.$default_timezone.'\', '
|
| 517 |
|
|
. '`language`=\''.$default_language.'\', '
|
| 518 |
|
|
. '`display_name`=\'Administrator\'';
|
| 519 |
|
|
if (! ($database->query($sql))) {
|
| 520 |
|
|
set_error('unable to write Administrator account into table \'users\'');
|
| 521 |
|
|
}
|
| 522 |
|
|
/**********************
|
| 523 |
|
|
END OF TABLES IMPORT
|
| 524 |
|
|
**********************/
|
| 525 |
|
|
// initialize the system
|
| 526 |
|
|
require_once(WB_PATH.'/framework/initialize.php');
|
| 527 |
1884
|
Luisehahne
|
require_once(WB_PATH.'/framework/class.admin.php');
|
| 528 |
2104
|
darkviper
|
/***********************
|
| 529 |
1529
|
Luisehahne
|
// Dummy class to allow modules' install scripts to call $admin->print_error
|
| 530 |
2104
|
darkviper
|
***********************/
|
| 531 |
|
|
class admin_dummy extends admin
|
| 532 |
|
|
{
|
| 533 |
|
|
public $error='';
|
| 534 |
|
|
public function print_error($message, $link = 'index.php', $auto_footer = true)
|
| 535 |
|
|
{
|
| 536 |
|
|
$this->error=$message;
|
| 537 |
|
|
}
|
| 538 |
|
|
}
|
| 539 |
1821
|
Luisehahne
|
// Include WB functions file
|
| 540 |
2107
|
darkviper
|
require_once(WB_PATH.'/framework/functions.php');
|
| 541 |
1821
|
Luisehahne
|
// Re-connect to the database, this time using in-build database class
|
| 542 |
2107
|
darkviper
|
// require_once(WB_PATH.'/framework/class.login.php');
|
| 543 |
|
|
// Include the PclZip class file (thanks to
|
| 544 |
|
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
| 545 |
|
|
// Install add-ons
|
| 546 |
|
|
$admin=new admin_dummy('Start','',false,false);
|
| 547 |
2104
|
darkviper
|
// Load addons and templates into DB
|
| 548 |
|
|
$aScanDirs = array(
|
| 549 |
|
|
'module' => dirname(__DIR__).'/modules/',
|
| 550 |
|
|
'template' => dirname(__DIR__).'/templates/',
|
| 551 |
|
|
'language' => dirname(__DIR__).'/languages/'
|
| 552 |
|
|
);
|
| 553 |
|
|
foreach ($aScanDirs as $sType => $sPath) {
|
| 554 |
|
|
$sCommand = 'load_'.$sType;
|
| 555 |
|
|
if ($sType != 'language') {
|
| 556 |
|
|
foreach (glob($sPath, GLOB_ONLYDIR) as $sMatchingPath) {
|
| 557 |
|
|
if ($sType == 'module') {
|
| 558 |
|
|
$sCommand($sMatchingPath, true);
|
| 559 |
|
|
if ($admin->error) { set_error($admin->error); }
|
| 560 |
|
|
} elseif ($sType == 'template') {
|
| 561 |
|
|
$sCommand($sMatchingPath);
|
| 562 |
|
|
}
|
| 563 |
|
|
}
|
| 564 |
|
|
} else {
|
| 565 |
|
|
foreach (glob(dirname(__DIR__).'/languages/??.php') as $sMatchingPath) {
|
| 566 |
|
|
if (preg_match('/\/[A-Z]{2}\.php$/sU', $sMatchingPath)) {
|
| 567 |
|
|
$sCommand($sMatchingPath);
|
| 568 |
|
|
}
|
| 569 |
|
|
}
|
| 570 |
|
|
}
|
| 571 |
|
|
}
|
| 572 |
1540
|
Luisehahne
|
|
| 573 |
1821
|
Luisehahne
|
// Check if there was a database error
|
| 574 |
2107
|
darkviper
|
if($database->is_error()) {
|
| 575 |
|
|
set_error($database->get_error());
|
| 576 |
|
|
}
|
| 577 |
1470
|
Luisehahne
|
|
| 578 |
2107
|
darkviper
|
if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY )) ) { }
|
| 579 |
|
|
if ( sizeof(createFolderProtectFile( WB_PATH.MEDIA_DIRECTORY.'/home' )) ) { }
|
| 580 |
|
|
if ( sizeof(createFolderProtectFile( WB_PATH.PAGES_DIRECTORY )) ) { }
|
| 581 |
1818
|
Luisehahne
|
|
| 582 |
1684
|
Luisehahne
|
// end of if install_tables
|
| 583 |
|
|
|
| 584 |
1529
|
Luisehahne
|
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
|
| 585 |
|
|
// Setup template object, parse vars to it, then parse it
|
| 586 |
1722
|
Luisehahne
|
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('loginBox.htt'));
|
| 587 |
1529
|
Luisehahne
|
|
| 588 |
1470
|
Luisehahne
|
// Log the user in and go to Website Baker Administration
|
| 589 |
|
|
$thisApp = new Login(
|
| 590 |
2107
|
darkviper
|
array(
|
| 591 |
|
|
"MAX_ATTEMPS" => "50",
|
| 592 |
|
|
"WARNING_URL" => $ThemeUrl."/warning.html",
|
| 593 |
|
|
"USERNAME_FIELDNAME" => 'admin_username',
|
| 594 |
|
|
"PASSWORD_FIELDNAME" => 'admin_password',
|
| 595 |
|
|
"REMEMBER_ME_OPTION" => SMART_LOGIN,
|
| 596 |
|
|
"MIN_USERNAME_LEN" => "2",
|
| 597 |
|
|
"MIN_PASSWORD_LEN" => "3",
|
| 598 |
|
|
"MAX_USERNAME_LEN" => "30",
|
| 599 |
|
|
"MAX_PASSWORD_LEN" => "30",
|
| 600 |
|
|
'LOGIN_URL' => ADMIN_URL."/login/index.php",
|
| 601 |
|
|
'DEFAULT_URL' => ADMIN_URL."/start/index.php",
|
| 602 |
|
|
'TEMPLATE_DIR' => $ThemePath,
|
| 603 |
|
|
'TEMPLATE_FILE' => 'loginBox.htt',
|
| 604 |
|
|
'FRONTEND' => false,
|
| 605 |
|
|
'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
|
| 606 |
|
|
'USERS_TABLE' => TABLE_PREFIX."users",
|
| 607 |
|
|
'GROUPS_TABLE' => TABLE_PREFIX."groups",
|
| 608 |
|
|
)
|
| 609 |
1470
|
Luisehahne
|
);
|