|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Bootstrap phpMyFAQ |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5.4 |
|
6
|
|
|
* |
|
7
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
|
8
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
|
9
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
|
10
|
|
|
* |
|
11
|
|
|
* @category phpMyFAQ |
|
12
|
|
|
* @package Configuration |
|
13
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
14
|
|
|
* @copyright 2012-2014 phpMyFAQ Team |
|
15
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
|
16
|
|
|
* @link http://www.phpmyfaq.de |
|
17
|
|
|
* @since 2012-03-07 |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use Symfony\Component\ClassLoader\UniversalClassLoader; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
22
|
|
|
|
|
23
|
|
|
// |
|
24
|
|
|
// Debug mode: |
|
25
|
|
|
// - false debug mode disabled |
|
26
|
|
|
// - true debug mode enabled |
|
27
|
|
|
// |
|
28
|
|
|
define('DEBUG', true); |
|
29
|
|
|
if (DEBUG) { |
|
30
|
|
|
ini_set('display_errors', 1); |
|
31
|
|
|
ini_set('display_startup_errors', 1); |
|
32
|
|
|
error_reporting(E_ALL | E_STRICT); |
|
33
|
|
|
} else { |
|
34
|
|
|
error_reporting(0); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
|
38
|
|
|
exit(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!defined('PMF_ROOT_DIR')) { |
|
42
|
|
|
/** |
|
43
|
|
|
* The root directory |
|
44
|
|
|
*/ |
|
45
|
|
|
define('PMF_ROOT_DIR', dirname(__DIR__)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The include directory |
|
50
|
|
|
*/ |
|
51
|
|
|
define('PMF_INCLUDE_DIR', __DIR__); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The directory where the translations reside |
|
55
|
|
|
*/ |
|
56
|
|
|
define('PMF_LANGUAGE_DIR', dirname(__DIR__) . '/lang'); |
|
57
|
|
|
|
|
58
|
|
|
// |
|
59
|
|
|
// Setting up PSR-0 autoloader for Symfony Components |
|
60
|
|
|
// |
|
61
|
|
|
require PMF_INCLUDE_DIR . '/libs/Symfony/Component/ClassLoader/UniversalClassLoader.php'; |
|
62
|
|
|
|
|
63
|
|
|
$loader = new UniversalClassLoader(); |
|
64
|
|
|
$loader->registerNamespace('PMF', PMF_INCLUDE_DIR); |
|
65
|
|
|
$loader->registerNamespace('Symfony', PMF_INCLUDE_DIR . '/libs'); |
|
66
|
|
|
$loader->registerPrefix('PMF_', PMF_INCLUDE_DIR); |
|
67
|
|
|
$loader->registerPrefix('Twig_', PMF_INCLUDE_DIR . '/libs'); |
|
68
|
|
|
$loader->register(); |
|
69
|
|
|
|
|
70
|
|
|
// |
|
71
|
|
|
// Fix the PHP include path if PMF is running under a "strange" PHP configuration |
|
72
|
|
|
// |
|
73
|
|
|
$foundCurrPath = false; |
|
74
|
|
|
$includePaths = explode(PATH_SEPARATOR, ini_get('include_path')); |
|
75
|
|
|
$i = 0; |
|
76
|
|
|
while ((!$foundCurrPath) && ($i < count($includePaths))) { |
|
77
|
|
|
if ('.' == $includePaths[$i]) { |
|
78
|
|
|
$foundCurrPath = true; |
|
79
|
|
|
} |
|
80
|
|
|
$i++; |
|
81
|
|
|
} |
|
82
|
|
|
if (!$foundCurrPath) { |
|
83
|
|
|
ini_set('include_path', '.' . PATH_SEPARATOR . ini_get('include_path')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
// |
|
87
|
|
|
// Tweak some PHP configuration values |
|
88
|
|
|
// Warning: be sure the server has enough memory and stack for PHP |
|
89
|
|
|
// |
|
90
|
|
|
ini_set('pcre.backtrack_limit', 100000000); |
|
91
|
|
|
ini_set('pcre.recursion_limit', 100000000); |
|
92
|
|
|
|
|
93
|
|
|
// |
|
94
|
|
|
// Check if multisite/multisite.php exist for Multisite support |
|
95
|
|
|
// |
|
96
|
|
|
if (file_exists(__DIR__ . '/../multisite/multisite.php') && 'cli' !== PHP_SAPI) { |
|
97
|
|
|
require __DIR__ . '/../multisite/multisite.php'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
// |
|
101
|
|
|
// Read configuration and constants |
|
102
|
|
|
// |
|
103
|
|
|
if (! defined('PMF_MULTI_INSTANCE_CONFIG_DIR')) { |
|
104
|
|
|
// Single instance configuration |
|
105
|
|
|
define('PMF_CONFIG_DIR', dirname(__DIR__) . '/config'); |
|
106
|
|
|
} else { |
|
107
|
|
|
// Multi instance configuration |
|
108
|
|
|
define('PMF_CONFIG_DIR', PMF_MULTI_INSTANCE_CONFIG_DIR); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// |
|
112
|
|
|
// Check if config/database.php exist -> if not, redirect to installer |
|
113
|
|
|
// |
|
114
|
|
|
|
|
115
|
|
|
if (!file_exists(PMF_CONFIG_DIR . '/database.php') && !file_exists(PMF_ROOT_DIR . '/inc/data.php')) { |
|
116
|
|
|
RedirectResponse::create('setup/index.php')->send(); |
|
117
|
|
|
exit(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (file_exists(PMF_ROOT_DIR . '/inc/data.php')) { |
|
121
|
|
|
require PMF_ROOT_DIR . '/inc/data.php'; |
|
122
|
|
|
} else { |
|
123
|
|
|
require PMF_CONFIG_DIR . '/database.php'; |
|
124
|
|
|
} |
|
125
|
|
|
require PMF_CONFIG_DIR . '/constants.php'; |
|
126
|
|
|
|
|
127
|
|
|
// |
|
128
|
|
|
// Set the error handler to our pmf_error_handler() function |
|
129
|
|
|
// |
|
130
|
|
|
set_error_handler('pmf_error_handler'); |
|
131
|
|
|
|
|
132
|
|
|
// |
|
133
|
|
|
// Create a database connection |
|
134
|
|
|
// |
|
135
|
|
|
try { |
|
136
|
|
|
PMF_Db::setTablePrefix($DB['prefix']); |
|
137
|
|
|
$db = PMF_Db::factory($DB['type']); |
|
138
|
|
|
$db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']); |
|
139
|
|
|
} catch (PMF_Exception $e) { |
|
140
|
|
|
PMF_Db::errorPage($e->getMessage()); |
|
141
|
|
|
exit(-1); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
// |
|
145
|
|
|
// Fetch the configuration and add the database connection |
|
146
|
|
|
// |
|
147
|
|
|
$faqConfig = new PMF_Configuration($db); |
|
148
|
|
|
$faqConfig->getAll(); |
|
149
|
|
|
|
|
150
|
|
|
// |
|
151
|
|
|
// We always need a valid session! |
|
152
|
|
|
// |
|
153
|
|
|
ini_set('session.use_only_cookies', 1); // Avoid any PHP version to move sessions on URLs |
|
154
|
|
|
ini_set('session.auto_start', 0); // Prevent error to use session_start() if it's active in php.ini |
|
155
|
|
|
ini_set('session.use_trans_sid', 0); |
|
156
|
|
|
ini_set('url_rewriter.tags', ''); |
|
157
|
|
|
|
|
158
|
|
|
// |
|
159
|
|
|
// Start the PHP session |
|
160
|
|
|
// |
|
161
|
|
|
PMF_Init::cleanRequest(); |
|
162
|
|
|
session_start(); |
|
163
|
|
|
|
|
164
|
|
|
// |
|
165
|
|
|
// Connect to LDAP server, when LDAP support is enabled |
|
166
|
|
|
// |
|
167
|
|
|
if ($faqConfig->get('security.ldapSupport') && file_exists(PMF_CONFIG_DIR . '/ldap.php') && extension_loaded('ldap')) { |
|
168
|
|
|
require PMF_CONFIG_DIR . '/constants_ldap.php'; |
|
169
|
|
|
require PMF_CONFIG_DIR . '/ldap.php'; |
|
170
|
|
|
$faqConfig->setLdapConfig($PMF_LDAP); |
|
171
|
|
|
} else { |
|
172
|
|
|
$ldap = null; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
// |
|
176
|
|
|
// Build attachments path |
|
177
|
|
|
// |
|
178
|
|
|
$confAttachmentsPath = trim($faqConfig->get('records.attachmentsPath')); |
|
179
|
|
|
if ('/' == $confAttachmentsPath[0] || preg_match('%^[a-z]:(\\\\|/)%i', $confAttachmentsPath)) { |
|
180
|
|
|
// If we're here, some windows or unix style absolute path was detected. |
|
181
|
|
|
define('PMF_ATTACHMENTS_DIR', $confAttachmentsPath); |
|
182
|
|
|
} else { |
|
183
|
|
|
// otherwise build the absolute path |
|
184
|
|
|
$tmp = dirname(__DIR__) . DIRECTORY_SEPARATOR . $confAttachmentsPath; |
|
185
|
|
|
|
|
186
|
|
|
// Check that nobody is traversing |
|
187
|
|
|
if (0 === strpos((string)$tmp, dirname(__DIR__))) { |
|
188
|
|
|
define('PMF_ATTACHMENTS_DIR', $tmp); |
|
189
|
|
|
} else { |
|
190
|
|
|
define('PMF_ATTACHMENTS_DIR', false); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
// |
|
195
|
|
|
// Fix if phpMyFAQ is running behind a proxy server |
|
196
|
|
|
// |
|
197
|
|
View Code Duplication |
if (! isset($_SERVER['HTTP_HOST'])) { |
|
198
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) { |
|
199
|
|
|
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_SERVER']; |
|
200
|
|
|
} else { |
|
201
|
|
|
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
202
|
|
|
}; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
// |
|
206
|
|
|
// Fix undefined server variables in Windows IIS & CGI mode |
|
207
|
|
|
// |
|
208
|
|
|
if (! isset($_SERVER['SCRIPT_NAME'])) { |
|
209
|
|
|
if(isset($_SERVER['SCRIPT_FILENAME'])) { |
|
210
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME']; |
|
211
|
|
|
} elseif(isset($_SERVER['PATH_TRANSLATED'])) { |
|
212
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['PATH_TRANSLATED']; |
|
213
|
|
|
} elseif(isset($_SERVER['PATH_INFO'])) { |
|
214
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['PATH_INFO']; |
|
215
|
|
|
} elseif(isset($_SERVER['SCRIPT_URL'])) { |
|
216
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_URL']; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
// |
|
221
|
|
|
// phpMyFAQ exception log |
|
222
|
|
|
// |
|
223
|
|
|
$pmfExeptions = []; |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* phpMyFAQ custom error handler function, also to prevent the disclosure of |
|
227
|
|
|
* potential sensitive data. |
|
228
|
|
|
* |
|
229
|
|
|
* @access public |
|
230
|
|
|
* @param int $level The level of the error raised. |
|
231
|
|
|
* @param string $message The error message. |
|
232
|
|
|
* @param string $filename The filename that the error was raised in. |
|
233
|
|
|
* @param int $line The line number the error was raised at. |
|
234
|
|
|
* @param mixed $context It optionally contains an array of every variable |
|
235
|
|
|
* that existed in the scope the error was triggered in. |
|
236
|
|
|
* |
|
237
|
|
|
* @return bool |
|
238
|
|
|
*/ |
|
239
|
|
|
function pmf_error_handler($level, $message, $filename, $line, $context) |
|
240
|
|
|
{ |
|
241
|
|
|
// Sanity check |
|
242
|
|
|
// Note: when DEBUG mode is true we want to track any error! |
|
243
|
|
|
if ( |
|
244
|
|
|
// 1. the @ operator sets the PHP's error_reporting() value to 0 |
|
245
|
|
|
(!DEBUG && (0 == error_reporting())) |
|
246
|
|
|
// 2. Honor the value of PHP's error_reporting() function |
|
247
|
|
|
|| (!DEBUG && (0 == ($level & error_reporting()))) |
|
248
|
|
|
) { |
|
249
|
|
|
// Do nothing |
|
250
|
|
|
return true; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
// Cleanup potential sensitive data |
|
254
|
|
|
$filename = (DEBUG ? $filename : basename($filename)); |
|
255
|
|
|
|
|
256
|
|
|
$errorTypes = array( |
|
257
|
|
|
E_ERROR => 'error', |
|
258
|
|
|
E_WARNING => 'warning', |
|
259
|
|
|
E_PARSE => 'parse error', |
|
260
|
|
|
E_NOTICE => 'notice', |
|
261
|
|
|
E_CORE_ERROR => 'code error', |
|
262
|
|
|
E_CORE_WARNING => 'core warning', |
|
263
|
|
|
E_COMPILE_ERROR => 'compile error', |
|
264
|
|
|
E_COMPILE_WARNING => 'compile warning', |
|
265
|
|
|
E_USER_ERROR => 'user error', |
|
266
|
|
|
E_USER_WARNING => 'user warning', |
|
267
|
|
|
E_USER_NOTICE => 'user notice', |
|
268
|
|
|
E_STRICT => 'strict warning', |
|
269
|
|
|
E_RECOVERABLE_ERROR => 'recoverable error', |
|
270
|
|
|
E_DEPRECATED => 'deprecated warning', |
|
271
|
|
|
E_USER_DEPRECATED => 'user deprecated warning', |
|
272
|
|
|
); |
|
273
|
|
|
$errorType = 'unknown error'; |
|
274
|
|
|
if (isset($errorTypes[$level])) { |
|
275
|
|
|
$errorType = $errorTypes[$level]; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
// Custom error message |
|
279
|
|
|
$errorMessage = sprintf( |
|
280
|
|
|
'<br><strong>phpMyFAQ %s</strong> [%s]: %s in <strong>%s</strong> on line <strong>%d</strong><br>', |
|
281
|
|
|
$errorType, |
|
282
|
|
|
$level, |
|
283
|
|
|
$message, |
|
284
|
|
|
$filename, |
|
285
|
|
|
$line |
|
286
|
|
|
); |
|
287
|
|
|
|
|
288
|
|
|
if (ini_get('display_errors')) { |
|
289
|
|
|
print $errorMessage; |
|
290
|
|
|
} |
|
291
|
|
|
if (ini_get('log_errors')) { |
|
292
|
|
|
error_log(sprintf('phpMyFAQ %s: %s in %s on line %d', |
|
293
|
|
|
$errorType, |
|
294
|
|
|
$message, |
|
295
|
|
|
$filename, |
|
296
|
|
|
$line) |
|
297
|
|
|
); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
switch ($level) { |
|
301
|
|
|
// Blocking errors |
|
302
|
|
|
case E_ERROR: |
|
303
|
|
|
case E_PARSE: |
|
304
|
|
|
case E_CORE_ERROR: |
|
305
|
|
|
case E_COMPILE_ERROR: |
|
306
|
|
|
case E_USER_ERROR: |
|
307
|
|
|
// Prevent processing any more PHP scripts |
|
308
|
|
|
exit(); |
|
309
|
|
|
break; |
|
310
|
|
|
// Not blocking errors |
|
311
|
|
|
default: |
|
312
|
|
|
break; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
return true; |
|
316
|
|
|
} |
|
317
|
|
|
|