1 |
1349
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
1864
|
darkviper
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
4 |
1349
|
Luisehahne
|
*
|
5 |
1864
|
darkviper
|
* 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 |
1349
|
Luisehahne
|
*
|
10 |
1864
|
darkviper
|
* 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 |
1349
|
Luisehahne
|
*/
|
18 |
|
|
|
19 |
1617
|
darkviper
|
/**
|
20 |
1864
|
darkviper
|
* initialize.php
|
21 |
|
|
*
|
22 |
|
|
* @category Core
|
23 |
|
|
* @package Core_Environment
|
24 |
|
|
* @author Werner v.d.Decken <wkl@isteam.de>
|
25 |
|
|
* @copyright Werner v.d.Decken <wkl@isteam.de>
|
26 |
|
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
27 |
|
|
* @version 0.0.1
|
28 |
|
|
* @revision $Revision$
|
29 |
|
|
* @link $HeadURL$
|
30 |
|
|
* @lastmodified $Date$
|
31 |
|
|
* @since File replaced since 05.02.2013
|
32 |
|
|
* @description set the basic environment to run WebsiteBaker
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
/* *** define some helper functions *** */
|
36 |
|
|
/**
|
37 |
1617
|
darkviper
|
* sanitize $_SERVER['HTTP_REFERER']
|
38 |
|
|
* @param string $sWbUrl qualified startup URL of current application
|
39 |
|
|
*/
|
40 |
2121
|
darkviper
|
function initSanitizeHttpReferer($sWbUrl) {
|
41 |
|
|
$sTmpReferer = '';
|
42 |
|
|
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
|
43 |
|
|
define('ORG_REFERER', ($_SERVER['HTTP_REFERER'] ?: ''));
|
44 |
|
|
$sTmpReferer = $_SERVER['HTTP_REFERER'];
|
45 |
|
|
$aRefUrl = parse_url($_SERVER['HTTP_REFERER']);
|
46 |
|
|
if ($aRefUrl !== false) {
|
47 |
|
|
$aRefUrl['host'] = isset($aRefUrl['host']) ? $aRefUrl['host'] : '';
|
48 |
|
|
$aRefUrl['path'] = isset($aRefUrl['path']) ? $aRefUrl['path'] : '';
|
49 |
|
|
$aRefUrl['fragment'] = isset($aRefUrl['fragment']) ? '#'.$aRefUrl['fragment'] : '';
|
50 |
|
|
$aWbUrl = parse_url($sWbUrl);
|
51 |
|
|
if ($aWbUrl !== false) {
|
52 |
|
|
$aWbUrl['host'] = isset($aWbUrl['host']) ? $aWbUrl['host'] : '';
|
53 |
|
|
$aWbUrl['path'] = isset($aWbUrl['path']) ? $aWbUrl['path'] : '';
|
54 |
|
|
if (strpos($aRefUrl['host'].$aRefUrl['path'],
|
55 |
|
|
$aWbUrl['host'].$aWbUrl['path']) !== false) {
|
56 |
|
|
$aRefUrl['path'] = preg_replace('#^'.$aWbUrl['path'].'#i', '', $aRefUrl['path']);
|
57 |
|
|
$sTmpReferer = $sWbUrl.$aRefUrl['path'].$aRefUrl['fragment'];
|
58 |
|
|
}
|
59 |
|
|
unset($aWbUrl);
|
60 |
|
|
}
|
61 |
|
|
unset($aRefUrl);
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
$_SERVER['HTTP_REFERER'] = $sTmpReferer;
|
65 |
|
|
}
|
66 |
1864
|
darkviper
|
/**
|
67 |
|
|
* Set constants for system/install values
|
68 |
|
|
* @throws RuntimeException
|
69 |
|
|
*/
|
70 |
2121
|
darkviper
|
function initSetInstallPathConstants() {
|
71 |
|
|
if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
|
72 |
|
|
if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
|
73 |
|
|
if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
|
74 |
|
|
throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
|
75 |
|
|
}
|
76 |
|
|
if(!defined('WB_PATH')){ define('WB_PATH', dirname(__DIR__)); }
|
77 |
|
|
if(!defined('ADMIN_URL')){ define('ADMIN_URL', rtrim(WB_URL, '/\\').'/'.ADMIN_DIRECTORY); }
|
78 |
|
|
if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
|
79 |
|
|
if(!defined('WB_REL')){
|
80 |
|
|
$x1 = parse_url(WB_URL);
|
81 |
|
|
define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
|
82 |
|
|
}
|
83 |
|
|
if(!defined('ADMIN_REL')){ define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY); }
|
84 |
|
|
if(!defined('DOCUMENT_ROOT')) {
|
85 |
|
|
define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
|
86 |
|
|
$_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
|
87 |
|
|
}
|
88 |
|
|
if(!defined('TMP_PATH')){ define('TMP_PATH', WB_PATH.'/temp'); }
|
89 |
|
|
}
|
90 |
1864
|
darkviper
|
/**
|
91 |
2015
|
darkviper
|
* checkValidCaller
|
92 |
|
|
* @param array $aCaller list of allowed scripts
|
93 |
|
|
* @return true || Exception
|
94 |
1864
|
darkviper
|
* @throws RuntimeException
|
95 |
2015
|
darkviper
|
* @description test if acctual file is called from one of the given list
|
96 |
1864
|
darkviper
|
*/
|
97 |
2121
|
darkviper
|
function initCheckValidCaller(array $aCaller)
|
98 |
|
|
{
|
99 |
2060
|
darkviper
|
return true;
|
100 |
2121
|
darkviper
|
$x = debug_backtrace();
|
101 |
|
|
if(sizeof($x) == 0) {
|
102 |
|
|
return true;
|
103 |
|
|
}
|
104 |
|
|
$sPattern = '/('.str_replace('#', '|', preg_quote(implode('#', $aCaller), '/')).')$/si';
|
105 |
|
|
foreach($x as $aStep) {
|
106 |
|
|
// define the scripts which can read the configuration
|
107 |
|
|
if(preg_match($sPattern, $aStep['file'])) {
|
108 |
|
|
return true;
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
throw new RuntimeException('illegal file request!');
|
112 |
|
|
}
|
113 |
2015
|
darkviper
|
/**
|
114 |
|
|
* Read DB settings from configuration file
|
115 |
|
|
* @return array
|
116 |
|
|
* @throws RuntimeException
|
117 |
2124
|
darkviper
|
*
|
118 |
2015
|
darkviper
|
*/
|
119 |
2121
|
darkviper
|
function initReadSetupFile()
|
120 |
|
|
{
|
121 |
|
|
// check for valid file request. Becomes more stronger in next version
|
122 |
|
|
initCheckValidCaller(array('save.php','index.php','config.php','upgrade-script.php'));
|
123 |
|
|
$aCfg = array();
|
124 |
2124
|
darkviper
|
$sSetupFile = dirname(__DIR__).'/setup.ini.php';
|
125 |
2121
|
darkviper
|
if(is_readable($sSetupFile)) {
|
126 |
|
|
$aCfg = parse_ini_file($sSetupFile, true);
|
127 |
|
|
if (!isset($aCfg['Constants']) || !isset($aCfg['DataBase'])) {
|
128 |
|
|
throw new InvalidArgumentException('configuration missmatch in setup.ini.php');
|
129 |
|
|
}
|
130 |
|
|
foreach($aCfg['Constants'] as $key=>$value) {
|
131 |
|
|
switch($key):
|
132 |
|
|
case 'DEBUG':
|
133 |
|
|
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
134 |
|
|
if(!defined('DEBUG')) { define('DEBUG', $value); }
|
135 |
|
|
break;
|
136 |
|
|
case 'WB_URL': // << case is set deprecated
|
137 |
|
|
case 'AppUrl':
|
138 |
|
|
$value = trim(str_replace('\\', '/', $value), '/');
|
139 |
|
|
if(!defined('WB_URL')) { define('WB_URL', $value); }
|
140 |
|
|
break;
|
141 |
|
|
case 'ADMIN_DIRECTORY': // << case is set deprecated
|
142 |
|
|
case 'AcpDir':
|
143 |
|
|
$value = trim(str_replace('\\', '/', $value), '/');
|
144 |
|
|
if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
|
145 |
|
|
break;
|
146 |
|
|
default:
|
147 |
|
|
if(!defined($key)) { define($key, $value); }
|
148 |
|
|
break;
|
149 |
|
|
endswitch;
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
return $aCfg;
|
153 |
|
|
// throw new RuntimeException('unable to read setup.ini.php');
|
154 |
|
|
}
|
155 |
|
|
/**
|
156 |
2015
|
darkviper
|
* GetDbConnectData
|
157 |
|
|
* @param array $aCfg
|
158 |
|
|
* @param string $sDbConnectType can be 'url' or 'dsn'
|
159 |
|
|
* @return array
|
160 |
|
|
*
|
161 |
|
|
*/
|
162 |
2121
|
darkviper
|
function initGetDbConnectData(array $aCfg, $sDbConnectType = 'url')
|
163 |
|
|
{
|
164 |
|
|
if(defined('DB_TYPE'))
|
165 |
|
|
{
|
166 |
|
|
// import constants for compatibility reasons
|
167 |
|
|
$db = array();
|
168 |
|
|
if(defined('DB_TYPE')) { $db['type'] = DB_TYPE; }
|
169 |
|
|
if(defined('DB_USERNAME')) { $db['user'] = DB_USERNAME; }
|
170 |
|
|
if(defined('DB_PASSWORD')) { $db['pass'] = DB_PASSWORD; }
|
171 |
|
|
if(defined('DB_HOST')) { $db['host'] = DB_HOST; }
|
172 |
|
|
if(defined('DB_PORT')) { $db['port'] = DB_PORT; }
|
173 |
|
|
if(defined('DB_NAME')) { $db['name'] = DB_NAME; }
|
174 |
|
|
if(defined('DB_CHARSET')) { $db['charset'] = DB_CHARSET; }
|
175 |
|
|
if(defined('TABLE_PREFIX')) { $db['table_prefix'] = TABLE_PREFIX; }
|
176 |
|
|
$aCfg['DataBase'] = $db;
|
177 |
|
|
}
|
178 |
|
|
// sanitize values
|
179 |
|
|
$db = $aCfg['DataBase'];
|
180 |
|
|
$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
|
181 |
|
|
$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
|
182 |
|
|
$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
|
183 |
|
|
$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
|
184 |
|
|
$db['port'] = isset($db['port']) ? $db['port'] : '3306';
|
185 |
|
|
$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
|
186 |
|
|
$db['socket'] = isset($db['socket']) ? $db['socket'] : '';
|
187 |
|
|
$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
|
188 |
|
|
$db['charset'] = isset($db['charset']) ? trim($db['charset']) : 'utf8';
|
189 |
|
|
$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
|
190 |
2085
|
darkviper
|
if (isset($db['options']) && is_array($db['options'])) {
|
191 |
|
|
foreach ($db['options'] as $key=>$value) {
|
192 |
|
|
$aRetval['options'][constant($key)] = $value;
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
2121
|
darkviper
|
if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $db['table_prefix']); }
|
196 |
|
|
if($sDbConnectType == 'dsn') {
|
197 |
|
|
// build dsn to connect
|
198 |
2085
|
darkviper
|
$aRetval['dsn'] = $db['type'].':dbname='.$db['name'].';host='.$db['host']
|
199 |
2121
|
darkviper
|
. ($db['port'] != '' ? ';port='.(int)$db['port'] : '');
|
200 |
2085
|
darkviper
|
if ($db['charset'] == 'utf8') {
|
201 |
|
|
$aRetval['dsn'] .= ';charset=UTF8';
|
202 |
|
|
$aRetval['options'][constant('PDO::MYSQL_ATTR_INIT_COMMAND')] = 'SET NAMES \'UTF8\'';
|
203 |
|
|
}
|
204 |
|
|
$aRetval['options'] = '';
|
205 |
|
|
$aRetval['user'] = $db['user'];
|
206 |
|
|
$aRetval['password'] = $db['pass'];
|
207 |
|
|
$aRetval['addons'] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
|
208 |
2121
|
darkviper
|
}else {
|
209 |
|
|
// build url to connect
|
210 |
2085
|
darkviper
|
$aRetval['url'] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
|
211 |
2121
|
darkviper
|
. $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
|
212 |
|
|
. '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
|
213 |
|
|
}
|
214 |
|
|
return $aRetval;
|
215 |
|
|
}
|
216 |
2015
|
darkviper
|
|
217 |
2129
|
darkviper
|
function WbErrorHandler($iErrorCode, $sErrorText, $sErrorFile, $iErrorLine)
|
218 |
|
|
{
|
219 |
|
|
if (!(error_reporting() & $iErrorCode)) {
|
220 |
|
|
return false;
|
221 |
|
|
}
|
222 |
|
|
$bRetval = false;
|
223 |
|
|
$aErrors = array(
|
224 |
|
|
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
|
225 |
|
|
E_USER_NOTICE => 'E_USER_NOTICE',
|
226 |
|
|
E_USER_WARNING => 'E_USER_WARNING',
|
227 |
|
|
E_DEPRECATED => 'E_DEPRECATED',
|
228 |
|
|
E_NOTICE => 'E_NOTICE',
|
229 |
|
|
E_WARNING => 'E_WARNING',
|
230 |
|
|
E_CORE_WARNING => 'E_CORE_WARNING',
|
231 |
|
|
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
|
232 |
|
|
E_STRICT => 'E_STRICT',
|
233 |
|
|
);
|
234 |
|
|
if (array_key_exists($iErrorCode, $aErrors)) {
|
235 |
|
|
$sErrorType = $aErrors[$iErrorCode];
|
236 |
|
|
$bRetval = true;
|
237 |
|
|
}
|
238 |
|
|
$aBt= debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
239 |
2133
|
darkviper
|
$x = sizeof($aBt) -1;
|
240 |
|
|
$x = $x < 2 ? $x : 2;
|
241 |
2129
|
darkviper
|
$sEntry = date('c').' '.'['.$sErrorType.'] '.str_replace(dirname(__DIR__), '', $sErrorFile).':['.$iErrorLine.'] '
|
242 |
2133
|
darkviper
|
. ' from '.str_replace(dirname(__DIR__), '', $aBt[$x]['file']).':['.$aBt[$x]['line'].'] '
|
243 |
|
|
. (@$aBt[$x]['class'] ? $aBt[$x]['class'].$aBt[$x]['type'] : '').$aBt[$x]['function'].' '
|
244 |
2129
|
darkviper
|
. '"'.$sErrorText.'"'.PHP_EOL;
|
245 |
2133
|
darkviper
|
file_put_contents(dirname(__DIR__).'/var/log/error.log', $sEntry, FILE_APPEND);
|
246 |
2129
|
darkviper
|
return $bRetval;
|
247 |
|
|
}
|
248 |
1864
|
darkviper
|
/* ***************************************************************************************
|
249 |
|
|
* Start initialization *
|
250 |
|
|
****************************************************************************************/
|
251 |
2129
|
darkviper
|
// activate errorhandler
|
252 |
|
|
set_error_handler('WbErrorHandler');
|
253 |
2124
|
darkviper
|
// reset global output buffering
|
254 |
|
|
while (ob_get_level()) { ob_end_clean(); }
|
255 |
2121
|
darkviper
|
// test for existing and active old config.php
|
256 |
|
|
if (defined('TABLE_PREFIX')) { /** TODO */ }
|
257 |
2124
|
darkviper
|
// set system defaults
|
258 |
|
|
date_default_timezone_set('UTC');
|
259 |
|
|
|
260 |
|
|
// initialize debug evaluation values ---
|
261 |
2121
|
darkviper
|
$starttime = array_sum(explode(" ",microtime()));
|
262 |
|
|
$iPhpDeclaredClasses = sizeof(get_declared_classes());
|
263 |
|
|
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
|
264 |
|
|
// calculate maximum timestamp
|
265 |
|
|
if (!defined('MAX_TIMESTAMP')) { define('MAX_TIMESTAMP', pow(2, 31)-1); } // 2038-01-19 04:14:07
|
266 |
|
|
// PHP less then 5.4.0 is prohibited ---
|
267 |
|
|
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
|
268 |
|
|
$sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.4.0!!<br />'
|
269 |
|
|
. 'Please change your PHP-Version to any kind from 5.4.0 and up!<br />'
|
270 |
|
|
. 'If you have problems to solve that, ask your hosting provider for it.<br />'
|
271 |
|
|
. 'The very best solution is the use of PHP-5.5 and up</p>';
|
272 |
|
|
die($sMsg);
|
273 |
|
|
}
|
274 |
|
|
if (! defined('SYSTEM_RUN')) { define('SYSTEM_RUN', true); }
|
275 |
2015
|
darkviper
|
// load configuration ---
|
276 |
2121
|
darkviper
|
$aCfg = initReadSetupFile();
|
277 |
2129
|
darkviper
|
|
278 |
1865
|
darkviper
|
// sanitize $_SERVER['HTTP_REFERER'] ---
|
279 |
2121
|
darkviper
|
initSetInstallPathConstants();
|
280 |
|
|
initSanitizeHttpReferer(WB_URL);
|
281 |
1864
|
darkviper
|
// register WB basic autoloader ---
|
282 |
2124
|
darkviper
|
$sTmp = __DIR__.'/WbAutoloader.php';
|
283 |
2121
|
darkviper
|
if(!class_exists('WbAutoloader')){
|
284 |
|
|
include($sTmp);
|
285 |
|
|
}
|
286 |
2124
|
darkviper
|
WbAutoloader::doRegister( array(
|
287 |
|
|
'a' => trim(str_replace('\\', '/',ADMIN_DIRECTORY), '/'),
|
288 |
|
|
'm' => 'modules',
|
289 |
|
|
't' => 'templates',
|
290 |
|
|
'i' => 'include',
|
291 |
|
|
'v' => 'vendor'
|
292 |
|
|
));
|
293 |
|
|
// WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m', 'templates'=>'t', 'include'=>'i'));
|
294 |
2015
|
darkviper
|
// instantiate and initialize adaptor for temporary registry replacement ---
|
295 |
2064
|
darkviper
|
$oReg = WbAdaptor::getInstance();
|
296 |
2121
|
darkviper
|
$oReg->getWbConstants();
|
297 |
1864
|
darkviper
|
// register TWIG autoloader ---
|
298 |
2124
|
darkviper
|
$sTmp = dirname(__DIR__).'/include/Sensio/Twig/lib/Twig/Autoloader.php';
|
299 |
2121
|
darkviper
|
if(!class_exists('Twig_Autoloader') && is_readable($sTmp)) {
|
300 |
|
|
include($sTmp);
|
301 |
2124
|
darkviper
|
Twig_Autoloader::register();
|
302 |
2121
|
darkviper
|
}
|
303 |
2064
|
darkviper
|
// register PHPMailer autoloader ---
|
304 |
2124
|
darkviper
|
$sTmp = dirname(__DIR__).'include/phpmailer/PHPMailerAutoload.php';
|
305 |
2121
|
darkviper
|
if (!function_exists('PHPMailerAutoload') && is_readable($sTmp)) {
|
306 |
|
|
require($sTmp);
|
307 |
2064
|
darkviper
|
}
|
308 |
1864
|
darkviper
|
// aktivate exceptionhandler ---
|
309 |
2121
|
darkviper
|
if(!function_exists('globalExceptionHandler')) {
|
310 |
2124
|
darkviper
|
include(__DIR__.'/globalExceptionHandler.php');
|
311 |
2121
|
darkviper
|
}
|
312 |
2133
|
darkviper
|
// check logfiles and compress it if needed
|
313 |
|
|
$oLogRotate = new LogRotation($oReg);
|
314 |
|
|
$oLogRotate->execute();
|
315 |
|
|
unset($oLogRotate);
|
316 |
1864
|
darkviper
|
// ---------------------------
|
317 |
2015
|
darkviper
|
// get Database connection data from configuration
|
318 |
2121
|
darkviper
|
$aSqlData = initGetDbConnectData($aCfg, $sDbConnectType);
|
319 |
1864
|
darkviper
|
// Create global database instance ---
|
320 |
2121
|
darkviper
|
$oDb = $database = WbDatabase::getInstance();
|
321 |
|
|
if($sDbConnectType == 'dsn') {
|
322 |
|
|
$bTmp = $oDb->doConnect($aSqlData['dsn'], $aSqlData['user'], $aSqlData['password'], null, $aSqlData['addons']);
|
323 |
|
|
}else {
|
324 |
|
|
$bTmp = $oDb->doConnect($aSqlData['url']);
|
325 |
|
|
}
|
326 |
2015
|
darkviper
|
// remove critical data from memory
|
327 |
2121
|
darkviper
|
unset($aSqlData, $aCfg);
|
328 |
2015
|
darkviper
|
|
329 |
2121
|
darkviper
|
if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $oDb->TablePrefix); }
|
330 |
2015
|
darkviper
|
|
331 |
1864
|
darkviper
|
// load global settings from database and define global consts from ---
|
332 |
2121
|
darkviper
|
$sql = 'SELECT `name`, `value` FROM `'.$oDb->TablePrefix.'settings`';
|
333 |
|
|
if(($oSettings = $oDb->doQuery($sql))) {
|
334 |
2130
|
darkviper
|
if (($aRecords = $oSettings->fetchAll(MYSQLI_ASSOC))) {
|
335 |
|
|
for ($i = 0, $iNum = sizeof($aRecords); $i < $iNum; $i++) {
|
336 |
2129
|
darkviper
|
//sanitize true/false values
|
337 |
2130
|
darkviper
|
$aRecords[$i]['value'] = ($aRecords[$i]['value'] == 'true'
|
338 |
2129
|
darkviper
|
? true
|
339 |
2130
|
darkviper
|
: ($aRecords[$i]['value'] == 'false'
|
340 |
2129
|
darkviper
|
? false
|
341 |
2130
|
darkviper
|
: $aRecords[$i]['value'])
|
342 |
2129
|
darkviper
|
);
|
343 |
2130
|
darkviper
|
$sSettingName = strtoupper($aRecords[$i]['name']);
|
344 |
2129
|
darkviper
|
switch($sSettingName):
|
345 |
|
|
case 'STRING_FILE_MODE':
|
346 |
2130
|
darkviper
|
$iTmp = ((intval(octdec($aRecords[$i]['value'])) & ~0111)|0600);
|
347 |
2129
|
darkviper
|
if(!defined('OCTAL_FILE_MODE')) { define('OCTAL_FILE_MODE', $iTmp); } // deprecated
|
348 |
2133
|
darkviper
|
if(!defined('FILE_MODE_OCTAL')) { define('FILE_MODE_OCTAL', $iTmp); } // deprecated
|
349 |
2129
|
darkviper
|
if(!defined('STRING_FILE_MODE')) { define('STRING_FILE_MODE', sprintf('0%03o', $iTmp)); } // deprecated
|
350 |
2133
|
darkviper
|
if(!defined('FILE_MODE')) { define('FILE_MODE', $iTmp); }
|
351 |
2129
|
darkviper
|
if(!defined('FILE_MODE_STRING')) { define('FILE_MODE_STRING', sprintf('0%03o', $iTmp)); }
|
352 |
|
|
break;
|
353 |
|
|
case 'STRING_DIR_MODE':
|
354 |
2130
|
darkviper
|
$iTmp = (intval(octdec($aRecords[$i]['value'])) |0711);
|
355 |
2129
|
darkviper
|
if(!defined('OCTAL_DIR_MODE')) { define('OCTAL_DIR_MODE', $iTmp); } // deprecated
|
356 |
2133
|
darkviper
|
if(!defined('DIR_MODE_OCTAL')) { define('DIR_MODE_OCTAL', $iTmp); } // deprecated
|
357 |
2129
|
darkviper
|
if(!defined('STRING_DIR_MODE')) { define('STRING_DIR_MODE', sprintf('0%03o', $iTmp)); } // deprecated
|
358 |
2133
|
darkviper
|
if(!defined('DIR_MODE')) { define('DIR_MODE', $iTmp); }
|
359 |
2129
|
darkviper
|
if(!defined('DIR_MODE_STRING')) { define('DIR_MODE_STRING', sprintf('0%03o', $iTmp)); }
|
360 |
|
|
break;
|
361 |
|
|
case 'PAGES_DIRECTORY':
|
362 |
|
|
// sanitize pages_directory
|
363 |
2130
|
darkviper
|
$sTmp = trim($aRecords[$i]['value'], '/');
|
364 |
2129
|
darkviper
|
$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
|
365 |
|
|
if(!defined('PAGES_DIRECTORY')) { define('PAGES_DIRECTORY', $sTmp); }
|
366 |
|
|
break;
|
367 |
|
|
default: // make global const from setting
|
368 |
2130
|
darkviper
|
if(!defined($sSettingName)) { define($sSettingName, $aRecords[$i]['value']); }
|
369 |
2129
|
darkviper
|
break;
|
370 |
|
|
endswitch;
|
371 |
|
|
}
|
372 |
2130
|
darkviper
|
unset($aRecords);
|
373 |
2129
|
darkviper
|
} else {
|
374 |
|
|
throw new AppException('no settings found');
|
375 |
2121
|
darkviper
|
}
|
376 |
2129
|
darkviper
|
} else {
|
377 |
|
|
throw new AppException($oDb->getError());
|
378 |
|
|
}
|
379 |
|
|
$oReg->getWbConstants();
|
380 |
1872
|
Luisehahne
|
// set error-reporting from loaded settings ---
|
381 |
2129
|
darkviper
|
$iErrorLevel = intval(ER_LEVEL);
|
382 |
|
|
if ($iErrorLevel >= 0 && $iErrorLevel <= E_ALL) {
|
383 |
|
|
error_reporting($iErrorLevel);
|
384 |
|
|
} else {
|
385 |
|
|
// on invalid value in ER_LEVEL activate E_ALL
|
386 |
|
|
error_reporting(E_ALL);
|
387 |
2121
|
darkviper
|
}
|
388 |
2129
|
darkviper
|
// activate display_errors
|
389 |
|
|
if( intval(ini_get ( 'display_errors' )) == 0 ) {
|
390 |
|
|
ini_set('display_errors', 1);
|
391 |
|
|
}
|
392 |
1872
|
Luisehahne
|
// Start a session ---
|
393 |
2121
|
darkviper
|
if(!defined('SESSION_STARTED')) {
|
394 |
|
|
session_name(APP_NAME.'_session_id');
|
395 |
|
|
@session_start();
|
396 |
|
|
define('SESSION_STARTED', true);
|
397 |
|
|
}
|
398 |
1963
|
darkviper
|
// get/set server timezone ---
|
399 |
2121
|
darkviper
|
if(!defined('SERVER_TIMEZONE')) { define('SERVER_TIMEZONE', "UTC"); }
|
400 |
|
|
if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
|
401 |
|
|
$sTmp = (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] != '') ? $_SERVER['HTTP_DNT'] : '0';
|
402 |
|
|
if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', ($sTmp[0] == '1')); }
|
403 |
1864
|
darkviper
|
// get/set users timezone ---
|
404 |
2121
|
darkviper
|
if(!defined('TIMEZONE')) { define('TIMEZONE', (isset($_SESSION['TIMEZONE']) ? $_SESSION['TIMEZONE'] : DEFAULT_TIMEZONE)); }
|
405 |
|
|
if(!defined('DATE_FORMAT')) { define('DATE_FORMAT', (isset($_SESSION['DATE_FORMAT']) ? $_SESSION['DATE_FORMAT'] : DEFAULT_DATE_FORMAT)); }
|
406 |
|
|
if(!defined('TIME_FORMAT')) { define('TIME_FORMAT', (isset($_SESSION['TIME_FORMAT']) ? $_SESSION['TIME_FORMAT'] : DEFAULT_TIME_FORMAT)); }
|
407 |
2124
|
darkviper
|
// set Theme directory ---
|
408 |
2121
|
darkviper
|
if(!defined('THEME_URL')) { define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME); }
|
409 |
|
|
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME); }
|
410 |
|
|
if(!defined('THEME_REL')) { define('THEME_REL', WB_REL.'/templates/'.DEFAULT_THEME); }
|
411 |
1864
|
darkviper
|
// extended wb editor settings
|
412 |
2121
|
darkviper
|
if(!defined('EDIT_ONE_SECTION')) { define('EDIT_ONE_SECTION', false); }
|
413 |
|
|
if(!defined('EDITOR_WIDTH')) { define('EDITOR_WIDTH', 0); }
|
414 |
1864
|
darkviper
|
// define form security class and preload it ---
|
415 |
2121
|
darkviper
|
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
416 |
|
|
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
|
417 |
|
|
require_once($sSecMod);
|
418 |
1864
|
darkviper
|
// *** begin deprecated part *************************************************************
|
419 |
|
|
// load settings for use in Captch and ASP module
|
420 |
2121
|
darkviper
|
if (!defined('WB_INSTALL_PROCESS') && !defined('ENABLED_CAPTCHA')) {
|
421 |
2129
|
darkviper
|
$sql = 'SELECT * FROM `'.$oDb->TablePrefix.'mod_captcha_control`';
|
422 |
2121
|
darkviper
|
// request settings from database
|
423 |
2129
|
darkviper
|
if(($oSettings = $oDb->doQuery($sql))) {
|
424 |
|
|
if(($aSetting = $oSettings->fetchAssoc())) {
|
425 |
2121
|
darkviper
|
define('ENABLED_CAPTCHA', ($aSetting['enabled_captcha'] == '1'));
|
426 |
|
|
define('ENABLED_ASP', ($aSetting['enabled_asp'] == '1'));
|
427 |
|
|
define('CAPTCHA_TYPE', $aSetting['captcha_type']);
|
428 |
|
|
define('ASP_SESSION_MIN_AGE', (int)$aSetting['asp_session_min_age']);
|
429 |
|
|
define('ASP_VIEW_MIN_AGE', (int)$aSetting['asp_view_min_age']);
|
430 |
|
|
define('ASP_INPUT_MIN_AGE', (int)$aSetting['asp_input_min_age']);
|
431 |
|
|
}
|
432 |
|
|
}
|
433 |
|
|
}
|
434 |
|
|
if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started'])) {
|
435 |
|
|
$_SESSION['session_started'] = time();
|
436 |
|
|
}
|
437 |
1864
|
darkviper
|
// *** end of deprecated part ************************************************************
|
438 |
|
|
// get user language ---
|
439 |
2060
|
darkviper
|
$sRequestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
440 |
|
|
// check if get/post value is available
|
441 |
|
|
$sTempLanguage = (isset(${$sRequestMethod}['lang']) ? ${$sRequestMethod}['lang'] : '');
|
442 |
|
|
// validate language code
|
443 |
|
|
if (preg_match('/^[a-z]{2}$/si', $sTempLanguage)) {
|
444 |
|
|
// if there's valid get/post
|
445 |
|
|
define('LANGUAGE', strtoupper($sTempLanguage));
|
446 |
|
|
} else {
|
447 |
|
|
if (!defined('LANGUAGE')) {
|
448 |
|
|
if(isset($_SESSION['LANGUAGE']) && $_SESSION['LANGUAGE']) {
|
449 |
|
|
// if there's valid session value
|
450 |
|
|
define('LANGUAGE', $_SESSION['LANGUAGE']);
|
451 |
|
|
} else {
|
452 |
|
|
// otherwise set to default
|
453 |
|
|
define('LANGUAGE', DEFAULT_LANGUAGE);
|
454 |
|
|
}
|
455 |
|
|
}
|
456 |
|
|
}
|
457 |
|
|
$_SESSION['LANGUAGE'] = LANGUAGE;
|
458 |
1864
|
darkviper
|
// activate translations / load language definitions
|
459 |
2124
|
darkviper
|
/** begin of deprecated part || will be replaced by class Translate **/
|
460 |
1864
|
darkviper
|
// Load Language file
|
461 |
2121
|
darkviper
|
if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
|
462 |
|
|
$sMsg = 'Error loading language file '.LANGUAGE.', please check configuration';
|
463 |
|
|
throw new AppException($sMsg);
|
464 |
|
|
} else {
|
465 |
|
|
// include language file
|
466 |
|
|
require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
|
467 |
|
|
}
|
468 |
1864
|
darkviper
|
/** end of deprecated part **/
|
469 |
|
|
// instantiate and initialize adaptor for temporary registry replacement ---
|
470 |
2121
|
darkviper
|
$oReg->getWbConstants();
|
471 |
1864
|
darkviper
|
// load and activate new global translation table
|
472 |
2121
|
darkviper
|
$oTrans = Translate::getInstance();
|
473 |
2124
|
darkviper
|
/* initializise Translate old style *************************************************** */
|
474 |
2133
|
darkviper
|
|
475 |
2121
|
darkviper
|
$oTrans->initialize(
|
476 |
|
|
'en',
|
477 |
|
|
(defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''),
|
478 |
|
|
(defined('LANGUAGE') ? LANGUAGE : ''),
|
479 |
|
|
'WbOldStyle',
|
480 |
|
|
// (Translate::CACHE_DISABLED|Translate::KEEP_MISSING),
|
481 |
|
|
(DEBUG ? Translate::CACHE_DISABLED|Translate::KEEP_MISSING : 0)
|
482 |
|
|
);
|
483 |
2133
|
darkviper
|
|
484 |
2124
|
darkviper
|
/* initializise Translate new style *************************************************** */
|
485 |
2121
|
darkviper
|
/*
|
486 |
|
|
$oTrans->initialize(
|
487 |
2133
|
darkviper
|
new TranslateAdaptorWbOldStyle($oReg),
|
488 |
2121
|
darkviper
|
'en',
|
489 |
|
|
(defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''),
|
490 |
|
|
(defined('LANGUAGE') ? LANGUAGE : ''),
|
491 |
|
|
(DEBUG ? Translate::CACHE_DISABLED|Translate::KEEP_MISSING : 0),
|
492 |
|
|
$oReg->DirModeOctal,
|
493 |
|
|
$oReg->TempPath
|
494 |
|
|
);
|
495 |
2133
|
darkviper
|
*/
|
496 |
2121
|
darkviper
|
/* ****** */
|
497 |
|
|
$oReg->setDatabase(WbDatabase::getInstance());
|
498 |
|
|
$oReg->setTranslate(Translate::getInstance());
|
499 |
|
|
if(!class_exists('PasswordHash', false)) { include(WB_PATH.'/include/phpass/PasswordHash.php'); }
|
500 |
|
|
$oPass = Password::getInstance(new PasswordHash(Password::CRYPT_LOOPS_DEFAULT, Password::HASH_TYPE_AUTO));
|
501 |
|
|
if(defined('PASSWORD_CRYPT_LOOPS')) { $oPass->setIteration(PASSWORD_CRYPT_LOOPS); }
|
502 |
|
|
if(defined('PASSWORD_HASH_TYPES')) { $oPass->setHashType(PASSWORD_HASH_TYPES); }
|
503 |
|
|
/* *** END OF FILE ******************************************************************** */
|