|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class for checking system requirements. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5.5 |
|
7
|
|
|
* |
|
8
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
|
9
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
|
10
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
|
11
|
|
|
* |
|
12
|
|
|
* @category phpMyFAQ |
|
13
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
14
|
|
|
* @copyright 2010-2016 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 2010-01-13 |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* PMF_System. |
|
22
|
|
|
* |
|
23
|
|
|
* @category phpMyFAQ |
|
24
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
25
|
|
|
* @copyright 2010-2016 phpMyFAQ Team |
|
26
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
|
27
|
|
|
* @link http://www.phpmyfaq.de |
|
28
|
|
|
* @since 2010-01-13 |
|
29
|
|
|
*/ |
|
30
|
|
|
class PMF_System |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Major version. |
|
34
|
|
|
*/ |
|
35
|
|
|
const VERSION_MAJOR = 2; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Minor version. |
|
39
|
|
|
*/ |
|
40
|
|
|
const VERSION_MINOR = 9; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Patchlevel. |
|
44
|
|
|
*/ |
|
45
|
|
|
const VERSION_PATCHLEVEL = 0; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Pre-release version. |
|
49
|
|
|
*/ |
|
50
|
|
|
const VERSION_PRERELEASE = 'RC2'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* API version. |
|
54
|
|
|
*/ |
|
55
|
|
|
const VERSION_API = '1.1'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Minimum required PHP version. |
|
59
|
|
|
*/ |
|
60
|
|
|
const VERSION_MINIMUM_PHP = '5.5.0'; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Array of required PHP extensions. |
|
64
|
|
|
* |
|
65
|
|
|
* @var array |
|
66
|
|
|
*/ |
|
67
|
|
|
private $requiredExtensions = [ |
|
68
|
|
|
'curl', |
|
69
|
|
|
'gd', |
|
70
|
|
|
'json', |
|
71
|
|
|
'xmlwriter', |
|
72
|
|
|
'filter', |
|
73
|
|
|
'zip', |
|
74
|
|
|
'fileinfo' |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Array of missing PHP extensions. |
|
79
|
|
|
* |
|
80
|
|
|
* @var array |
|
81
|
|
|
*/ |
|
82
|
|
|
private $missingExtensions = []; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Supported databases for phpMyFAQ. |
|
86
|
|
|
* |
|
87
|
|
|
* @var array |
|
88
|
|
|
*/ |
|
89
|
|
|
private $supportedDatabases = [ |
|
90
|
|
|
'mysqli' => [ self::VERSION_MINIMUM_PHP, 'MySQL 5.x / Percona Server 5.x / MariaDB 5.x and later' ], |
|
91
|
|
|
'pgsql' => [ self::VERSION_MINIMUM_PHP, 'PostgreSQL 9.x' ], |
|
92
|
|
|
'sqlite3' => [ self::VERSION_MINIMUM_PHP, 'SQLite 3' ], |
|
93
|
|
|
'mssql' => [ self::VERSION_MINIMUM_PHP, 'MS SQL Server 2012 and later (deprecated)' ], |
|
94
|
|
|
'sqlsrv' => [ self::VERSION_MINIMUM_PHP, 'MS SQL Server 2012 Driver for PHP'] |
|
95
|
|
|
]; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Database handle. |
|
99
|
|
|
* |
|
100
|
|
|
* @var PMF_DB_Driver |
|
101
|
|
|
*/ |
|
102
|
|
|
private $database = null; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Sets the database handler. |
|
106
|
|
|
* |
|
107
|
|
|
* @param PMF_DB_Driver $database |
|
108
|
|
|
* |
|
109
|
|
|
* @return PMF_System |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setDatabase(PMF_DB_Driver $database) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->database = $database; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Returns the current version of phpMyFAQ for installation and |
|
120
|
|
|
* version in the database. |
|
121
|
|
|
* |
|
122
|
|
|
* Releases will be numbered with the follow format: |
|
123
|
|
|
* <major>.<minor>.<patch>[-<prerelease>] |
|
124
|
|
|
* |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public static function getVersion() |
|
128
|
|
|
{ |
|
129
|
|
|
if (null !== self::VERSION_PRERELEASE) { |
|
130
|
|
|
return sprintf( |
|
131
|
|
|
'%d.%d.%d-%s', |
|
132
|
|
|
self::VERSION_MAJOR, |
|
133
|
|
|
self::VERSION_MINOR, |
|
134
|
|
|
self::VERSION_PATCHLEVEL, |
|
135
|
|
|
self::VERSION_PRERELEASE |
|
136
|
|
|
); |
|
137
|
|
|
} else { |
|
138
|
|
|
return sprintf( |
|
139
|
|
|
'%d.%d.%d', |
|
140
|
|
|
self::VERSION_MAJOR, |
|
141
|
|
|
self::VERSION_MINOR, |
|
142
|
|
|
self::VERSION_PATCHLEVEL |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns all available templates as array. |
|
149
|
|
|
* |
|
150
|
|
|
* @return array |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getAvailableTemplates() |
|
153
|
|
|
{ |
|
154
|
|
|
$templates = []; |
|
155
|
|
|
|
|
156
|
|
|
foreach (new DirectoryIterator(PMF_ROOT_DIR.'/assets/template') as $item) { |
|
157
|
|
|
$basename = $item->getBasename(); |
|
158
|
|
|
if (!$item->isDot() && $item->isDir()) { |
|
159
|
|
|
$templates[$basename] = (PMF_Template::getTplSetName() === $basename ? true : false); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
return $templates; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Returns the current API version of phpMyFAQ for installation and |
|
168
|
|
|
* version in the database. |
|
169
|
|
|
* |
|
170
|
|
|
* @return int |
|
171
|
|
|
*/ |
|
172
|
|
|
public static function getApiVersion() |
|
173
|
|
|
{ |
|
174
|
|
|
return self::VERSION_API; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Returns the supported databases. |
|
179
|
|
|
* |
|
180
|
|
|
* @return array |
|
181
|
|
|
*/ |
|
182
|
|
|
public function getSupportedDatabases() |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->supportedDatabases; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Returns the locally supported databases. |
|
189
|
|
|
* |
|
190
|
|
|
* @param bool $html |
|
191
|
|
|
* |
|
192
|
|
|
* @return array |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getSupportedSafeDatabases($html = false) |
|
195
|
|
|
{ |
|
196
|
|
|
$retVal = []; |
|
197
|
|
|
foreach ($this->getSupportedDatabases() as $extension => $database) { |
|
198
|
|
|
if (extension_loaded($extension) && version_compare(PHP_VERSION, $database[0]) >= 0) { |
|
199
|
|
|
if ($html) { |
|
200
|
|
|
$retVal[] = sprintf('<option value="%s">%s</option>', $extension, $database[1]); |
|
201
|
|
|
} else { |
|
202
|
|
|
$retVal[$extension] = $database; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return $retVal; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Checks if the system URI is running with http or https. |
|
212
|
|
|
* |
|
213
|
|
|
* @param PMF_Configuration $faqConfig |
|
214
|
|
|
* |
|
215
|
|
|
* @return mixed |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getSystemUri(PMF_Configuration $faqConfig) |
|
218
|
|
|
{ |
|
219
|
|
|
$mainUrl = $faqConfig->getDefaultUrl(); |
|
220
|
|
|
|
|
221
|
|
|
if (isset($_ENV['REQUEST_SCHEME']) && 'https' === $_ENV['REQUEST_SCHEME']) { |
|
222
|
|
|
if (false === strpos($mainUrl, 'https')) { |
|
223
|
|
|
$mainUrl = str_replace('http://', 'https://', $mainUrl); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
if ('/' !== substr($mainUrl, -1)) { |
|
228
|
|
|
$mainUrl .= '/'; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
return $mainUrl; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Checks for installed database extensions, if the first supported |
|
236
|
|
|
* extension is enabled, return true. |
|
237
|
|
|
* |
|
238
|
|
|
* @return bool |
|
239
|
|
|
*/ |
|
240
|
|
|
public function checkDatabase() |
|
241
|
|
|
{ |
|
242
|
|
|
foreach ($this->supportedDatabases as $extension => $database) { |
|
243
|
|
|
if (extension_loaded($extension)) { |
|
244
|
|
|
return true; |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
return false; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Checks for required PHP extensions. |
|
253
|
|
|
* |
|
254
|
|
|
* @return bool |
|
255
|
|
|
*/ |
|
256
|
|
|
public function checkRequiredExtensions() |
|
257
|
|
|
{ |
|
258
|
|
|
foreach ($this->requiredExtensions as $extension) { |
|
259
|
|
|
if (!extension_loaded($extension)) { |
|
260
|
|
|
$this->missingExtensions[] = $extension; |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
if (count($this->missingExtensions) > 0) { |
|
265
|
|
|
return false; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
return true; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Checks for an installed phpMyFAQ version. |
|
273
|
|
|
* |
|
274
|
|
|
* inc/data.php -> phpMyFAQ 2.0 and 2.5 |
|
275
|
|
|
* config/database.php -> phpMyFAQ 2.6 and later |
|
276
|
|
|
* |
|
277
|
|
|
* @return bool |
|
278
|
|
|
*/ |
|
279
|
|
|
public function checkphpMyFAQInstallation() |
|
280
|
|
|
{ |
|
281
|
|
|
if (is_file(PMF_ROOT_DIR.'/inc/data.php') || is_file(PMF_ROOT_DIR.'/config/database.php')) { |
|
282
|
|
|
return false; |
|
283
|
|
|
} else { |
|
284
|
|
|
return true; |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* Returns all missing extensions. |
|
290
|
|
|
* |
|
291
|
|
|
* @return array |
|
292
|
|
|
*/ |
|
293
|
|
|
public function getMissingExtensions() |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->missingExtensions; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Returns true or false on SQLite3. |
|
300
|
|
|
* |
|
301
|
|
|
* @static |
|
302
|
|
|
* |
|
303
|
|
|
* @param string $dbType |
|
304
|
|
|
* |
|
305
|
|
|
* @return bool |
|
306
|
|
|
*/ |
|
307
|
|
|
public static function isSqlite($dbType) |
|
308
|
|
|
{ |
|
309
|
|
|
return ('sqlite3' === $dbType) ? true : false; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* Creates a JSON object with all .php files of phpMyFAQ with their sha1 hashes. |
|
314
|
|
|
* |
|
315
|
|
|
* @return string |
|
316
|
|
|
*/ |
|
317
|
|
|
public function createHashes() |
|
318
|
|
|
{ |
|
319
|
|
|
$created = new DateTime(); |
|
320
|
|
|
|
|
321
|
|
|
$files = new RecursiveIteratorIterator( |
|
322
|
|
|
new RecursiveDirectoryIterator(PMF_ROOT_DIR), |
|
323
|
|
|
RecursiveIteratorIterator::SELF_FIRST |
|
324
|
|
|
); |
|
325
|
|
|
|
|
326
|
|
|
$hashes = array( |
|
327
|
|
|
'created' => $created->format('Y-m-d H:i:sP'), |
|
328
|
|
|
); |
|
329
|
|
|
$blacklist = array( |
|
330
|
|
|
'/config/constants.php' => false, |
|
331
|
|
|
'/config/constants_ldap.php' => false, |
|
332
|
|
|
'/config/database.php' => false, |
|
333
|
|
|
'/config/ldap.php' => false, |
|
334
|
|
|
); |
|
335
|
|
|
$current = ''; |
|
336
|
|
|
|
|
337
|
|
|
try { |
|
338
|
|
|
foreach ($files as $file) { |
|
339
|
|
|
if ('php' === pathinfo($file->getFilename(), PATHINFO_EXTENSION) && |
|
340
|
|
|
!preg_match('#/tests/#', $file->getPath()) |
|
341
|
|
|
) { |
|
342
|
|
|
$current = str_replace(PMF_ROOT_DIR, '', $file->getPathname()); |
|
343
|
|
|
|
|
344
|
|
|
if (isset($blacklist[$current])) { |
|
345
|
|
|
continue; |
|
346
|
|
|
} |
|
347
|
|
|
$hashes[$current] = sha1(file_get_contents($file->getPathname())); |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
} catch (UnexpectedValueException $e) { |
|
351
|
|
|
$hashes[$current.' failed'] = $e->getMessage(); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return json_encode($hashes); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
// |
|
358
|
|
|
// Methods to clean a phpMyFAQ installation |
|
359
|
|
|
// |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* Drops all given tables |
|
363
|
|
|
* @param array $queries |
|
364
|
|
|
*/ |
|
365
|
|
|
public function dropTables(Array $queries) |
|
366
|
|
|
{ |
|
367
|
|
|
if ($this->database instanceof PMF_DB_Driver) { |
|
368
|
|
|
foreach ($queries as $query) { |
|
369
|
|
|
$this->database->query($query); |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Removes the database.php and the ldap.php if an installation failed. |
|
376
|
|
|
*/ |
|
377
|
|
|
public function cleanInstallation() |
|
378
|
|
|
{ |
|
379
|
|
|
// Remove './config/database.php' file: no need of prompt anything to the user |
|
380
|
|
|
if (file_exists(PMF_ROOT_DIR.'/config/database.php')) { |
|
381
|
|
|
@unlink(PMF_ROOT_DIR.'/config/database.php'); |
|
382
|
|
|
} |
|
383
|
|
|
// Remove './config/ldap.php' file: no need of prompt anything to the user |
|
384
|
|
|
if (file_exists(PMF_ROOT_DIR.'/config/ldap.php')) { |
|
385
|
|
|
@unlink(PMF_ROOT_DIR.'/config/ldap.php'); |
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Print out the HTML5 Footer. |
|
391
|
|
|
* |
|
392
|
|
|
* @param bool $onePageBack |
|
393
|
|
|
*/ |
|
394
|
|
|
public static function renderFooter($onePageBack = false) |
|
395
|
|
|
{ |
|
396
|
|
|
if (true === $onePageBack) { |
|
397
|
|
|
printf( |
|
398
|
|
|
'<p><a href="javascript:history.back();">%s</a></p>', |
|
399
|
|
|
'Back to the setup page' |
|
400
|
|
|
); |
|
401
|
|
|
} |
|
402
|
|
|
printf( |
|
403
|
|
|
'</div></section><footer class="footer"><div class="container"><p class="pull-right">%s</p><div></footer></body></html>', |
|
404
|
|
|
COPYRIGHT |
|
405
|
|
|
); |
|
406
|
|
|
exit(-1); |
|
407
|
|
|
} |
|
408
|
|
|
} |
|
409
|
|
|
|