-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystemcheck.php
591 lines (547 loc) · 20.1 KB
/
systemcheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
<?php
/**
* kitFramework SystemCheck
*
* @author Team phpManufaktur <[email protected]>
* @link https://kit2.phpmanufaktur.de
* @copyright 2013 Ralf Hertsch <[email protected]>
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
ini_set('display_errors', 1);
error_reporting(E_ALL);
class SystemCheck
{
protected static $detected_PHP_VERSION = null;
protected static $required_PHP_VERSION = null;
protected static $CMS_TYPE = null;
protected static $CMS_VERSION = null;
protected static $detected_MYSQL_VERSION = null;
protected static $required_MYSQL_VERSION = null;
protected static $detected_CURL = null;
protected static $required_CURL = null;
protected static $detected_ZIPArchive = null;
protected static $required_ZIPArchive = null;
protected static $cms_config_path = null;
protected static $innoDB_available = null;
protected static $required_innoDB = null;
protected static $PDO_MySQL_enabled = null;
protected static $required_PDO_MySQL = null;
protected static $magic_quotes_gpc = null;
protected static $required_magic_quotes_gpc = null;
protected static $supported_cms_types = array(
'WebsiteBaker',
'LEPTON CMS',
'BlackCat CMS'
);
/**
* Constructor
*/
public function __construct()
{
date_default_timezone_set('Europe/Berlin');
self::setCMSpath();
}
/**
* Set the path of the parent CMS
*/
protected static function setCMSpath()
{
// we assume that the SystemCheck is placed at / or at /kit2
if (file_exists(realpath(dirname(__FILE__).'/../config.php'))) {
self::$cms_config_path = realpath(dirname(__FILE__).'/../config.php');
}
elseif (file_exists(realpath(dirname(__FILE__).'/config.php'))) {
self::$cms_config_path = realpath(dirname(__FILE__).'/config.php');
}
else {
self::$cms_config_path = null;
}
}
/**
* Set the required PHP version
*
* @param string $php_version i.e. '5.3.2'
*/
public function setRequriredPHPVersion($php_version)
{
self::$required_PHP_VERSION = $php_version;
}
/**
* Set the required Magic Quotes settings
*
* @param unknown $magic_quotes
*/
public function setRequiredMagicQuotesGPC($magic_quotes)
{
self::$required_magic_quotes_gpc = $magic_quotes;
}
/**
* Set the required MySQL version
*
* @param string $mysql_version i.e. '5.0.0'
*/
public function setRequiredMySQLVersion($mysql_version)
{
self::$required_MYSQL_VERSION = $mysql_version;
}
/**
* Determine wether PDO is needed or not
*
* @param boolean $required
*/
public function setRequiredPDOmySQL($required)
{
self::$required_PDO_MySQL = (bool) $required;
}
/**
* Determine wether InnoDB is needed or not
*
* @param boolean $required
*/
public function setRequiredInnoDB($required)
{
self::$required_innoDB = (bool) $required;
}
/**
* Determine wether cURL is needed or not
*
* @param boolean $required
*/
public function setRequiredCURL($required)
{
self::$required_CURL = (bool) $required;
}
/**
* Determine wether the ZIPArchive is needed or not
*
* @param boolean $required
*/
public function setRequriredZIPArchive($required)
{
self::$required_ZIPArchive = (bool) $required;
}
/**
* Return the operating system: WINDOWS or LINUX
*
* @return string
*/
protected function getOperatingSystem()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : 'LINUX';
}
/**
* Try to get informations about the parent CMS
*
* @return Ambigous <string, multitype:NULL >
*/
protected function getCMSinformation()
{
$result = array(
'Type' => '- no information available -',
'Version' => '- no information available -',
'Supported' => 'No',
'css' => 'fail'
);
if (file_exists(self::$cms_config_path)) {
include_once self::$cms_config_path;
if (defined('DB_HOST')) {
// establish MySQL connection
if ((false !== ($db_handle = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD))) &&
@mysql_select_db(DB_NAME, $db_handle)) {
// select the CMS settings
$SQL = "SELECT * FROM `".TABLE_PREFIX."settings`";
if (false !== ($query = @mysql_query($SQL))) {
// reset CMS type and version
self::$CMS_TYPE = null;
self::$CMS_VERSION = null;
while (false !== ($row = mysql_fetch_assoc($query))) {
if ($row['name'] == 'wb_version') {
self::$CMS_TYPE = 'WebsiteBaker';
self::$CMS_VERSION = $row['value'];
break;
}
if ($row['name'] == 'lepton_version') {
self::$CMS_TYPE = 'LEPTON CMS';
self::$CMS_VERSION = $row['value'];
break;
}
if ($row['name'] == 'cat_version') {
self::$CMS_TYPE = 'BlackCat CMS';
self::$CMS_VERSION = $row['value'];
break;
}
}
@mysql_free_result($query);
if (!is_null(self::$CMS_TYPE)) {
$result = array(
'Type' => self::$CMS_TYPE,
'Version' => self::$CMS_VERSION,
'Supported' => $this->isCMSsupported() ? 'Yes' : 'No',
'css' => $this->isCMSsupported() ? 'checked' : 'fail'
);
}
}
// get information about InnoDB
$SQL = "SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB'";
if (false !== ($query = @mysql_query($SQL))) {
if (false !== ($row = mysql_fetch_assoc($query))) {
if (isset($row['SUPPORT']) && ($row['SUPPORT'] != 'NO')) {
self::$innoDB_available = true;
}
else {
self::$innoDB_available = false;
}
}
}
// close the db handle
@mysql_close($db_handle);
}
}
}
return $result;
}
/**
* Check if the CMS is supported
*
* @return boolean
*/
protected function isCMSsupported()
{
if (in_array(self::$CMS_TYPE, self::$supported_cms_types)) {
if (self::$CMS_TYPE == 'WebsiteBaker') {
// support WB 2.8.x and above
if (version_compare(self::$CMS_VERSION, '2.8.0', '>=')) {
return true;
}
}
else {
// no restrictions for other CMS versions
return true;
}
}
return false;
}
/**
* Get InnoDB information
*
* @return array
*/
protected function getInnoDBinformation()
{
if (is_null(self::$innoDB_available)) {
return array(
'required' => self::$required_innoDB ? 'Yes' : 'No',
'available' => '- no information available -',
'css' => 'fail'
);
}
else {
return array(
'required' => self::$required_innoDB ? 'Yes' : 'No',
'available' => self::$innoDB_available ? 'Yes' : 'No',
'css' => (self::$required_innoDB && !self::$innoDB_available) ? 'fail' : 'checked'
);
}
}
/**
* Return a valid version string for the MySQL client version,
* using mysqli_get_client_version()
*
* @return string
*/
protected function getMySQLversion()
{
// for version 4.1.6 return 40106;
$mysqlVersion = mysqli_get_client_version();
//create mysql version string to check it
$mainVersion = (int)($mysqlVersion/10000);
$a = $mysqlVersion - ($mainVersion*10000);
$minorVersion = (int)($a/100);
$subVersion = $a - ($minorVersion*100);
return $mainVersion.'.'.$minorVersion.'.'.$subVersion;
}
/**
* Return an array with information about MySQL
*
* @return multitype:mixed NULL
*/
protected function getMySQLinformation()
{
self::$detected_MYSQL_VERSION = $this->getMySQLversion();
if (is_null(self::$required_MYSQL_VERSION)) {
self::$required_MYSQL_VERSION = self::$detected_MYSQL_VERSION;
}
return array(
'installed' => self::$detected_MYSQL_VERSION,
'required' => self::$required_MYSQL_VERSION,
'checked' => (int) version_compare(self::$detected_MYSQL_VERSION, self::$required_MYSQL_VERSION, '>='),
'css' => version_compare(self::$detected_MYSQL_VERSION, self::$required_MYSQL_VERSION, '>=') ? 'checked' : 'fail'
);
}
/**
* Return an array with information about PHP
*
* @return multitype:number NULL
*/
protected function getPHPinformation()
{
if (is_null(self::$required_PHP_VERSION)) {
self::$required_PHP_VERSION = PHP_VERSION;
}
self::$detected_PHP_VERSION = PHP_VERSION;
return array(
'installed' => self::$detected_PHP_VERSION,
'required' => self::$required_PHP_VERSION,
'checked' => (int) version_compare(self::$detected_PHP_VERSION, self::$required_PHP_VERSION, '>='),
'css' => version_compare(self::$detected_PHP_VERSION, self::$required_PHP_VERSION, '>=') ? 'checked' : 'fail'
);
}
/**
* Return an array with information about cURL
*
* @return array
*/
protected function isCURLinstalled()
{
self::$detected_CURL = function_exists('curl_init');
if (is_null(self::$required_CURL)) {
self::$required_CURL = self::$detected_CURL;
}
return array(
'installed' => (int) self::$detected_CURL,
'required' => (int) self::$required_CURL,
'checked' => (self::$required_CURL && !self::$detected_CURL) ? 0 : 1,
'css' => (self::$required_CURL && !self::$detected_CURL) ? 'fail' : 'checked'
);
}
/**
* Return an array with information about PDO_MYSQL
*
* @return array
*/
protected function isPDOmySQLenabled()
{
self::$PDO_MySQL_enabled = extension_loaded('pdo_mysql');
if (is_null(self::$required_PDO_MySQL)) {
self::$required_PDO_MySQL = self::$PDO_MySQL_enabled;
}
return array(
'installed' => (int) self::$PDO_MySQL_enabled,
'required' => (int) self::$required_PDO_MySQL,
'checked' => (self::$required_PDO_MySQL && !self::$PDO_MySQL_enabled) ? 0 : 1,
'css' => (self::$required_PDO_MySQL && !self::$PDO_MySQL_enabled) ? 'fail' : 'checked'
);
}
/**
* Return an array with information about the Magic Quotes settings
*
* @return array
*/
protected function isMagicQuotesGPC()
{
self::$magic_quotes_gpc = filter_var(ini_get('magic_quotes_gpc'), FILTER_VALIDATE_BOOLEAN);
if (is_null(self::$required_magic_quotes_gpc)) {
self::$required_magic_quotes_gpc = self::$magic_quotes_gpc;
}
return array(
'installed' => self::$magic_quotes_gpc ? 'on' : 'off',
'required' => self::$required_magic_quotes_gpc ? 'on' : 'off',
'checked' => (self::$required_magic_quotes_gpc && self::$magic_quotes_gpc) ? 0 : 1,
'css' => (self::$required_magic_quotes_gpc === self::$magic_quotes_gpc) ? 'checked' : 'fail'
);
}
/**
* Return an array with information about the ZipArchive
*
* @return multitype:number
*/
protected function isZIParchiveInstalled()
{
self::$detected_ZIPArchive = class_exists('ZipArchive');
if (is_null(self::$required_ZIPArchive)) {
self::$required_ZIPArchive = self::$detected_ZIPArchive;
}
return array(
'installed' => (int) self::$detected_ZIPArchive,
'required' => (int) self::$required_ZIPArchive,
'checked' => (self::$required_ZIPArchive && !self::$detected_ZIPArchive) ? 0 : 1,
'css' => (self::$required_ZIPArchive && !self::$detected_ZIPArchive) ? 'fail' : 'checked'
);
}
protected static function promptResult($result)
{
$curl_required = $result['cURL']['required'] ? 'Yes' : 'No';
$curl_installed = $result['cURL']['installed'] ? 'Yes' : 'No';
$zip_required = $result['ZIPArchive']['required'] ? 'Yes' : 'No';
$zip_installed = $result['ZIPArchive']['installed'] ? 'Yes' : 'No';
$pdo_mysql_required = $result['PDOmySQL']['required'] ? 'Yes' : 'No';
$pdo_mysql_enabled = $result['PDOmySQL']['installed'] ? 'Yes' : 'No';
echo <<<EOD
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>SystemCheck for the kitFramework</title>
<style type="text/css" media="screen">
body {
margin: 0;
padding: 0 0 0 50px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 13px;
color: #363636;
background-color: #fff;
}
a {
text-decoration: none;
}
a:link,
a:visited {
color: #da251d;
background-color: transparent;
text-decoration: none;
}
a:hover,
a:active {
color: #da251d;
background-color: transparent;
text-decoration: underline;
}
fieldset {
clear: both;
margin: 10px 0;
padding: 10px;
width: 600px;
}
legend {
font-size: 11px;
}
.label {
clear: both;
float: left;
width: 180px;
margin: 0;
padding: 0;
}
.value {
float: left;
width: 300px;
margin: 0;
padding: 0;
}
.checked {
color: #006400;
background-color: transparent;
font-weight: normal;
}
.fail {
color: #da251d;
background-color: transparent;
font-weight: bold;
}
</style>
</head>
<body>
<h1>kitFramework SystemCheck</h2>
<p>© 2014 <a href="https://phpmanufaktur.de">phpManufaktur</a> by <a href="mailto:[email protected]">Ralf Hertsch</a></p>
<fieldset>
<legend>CMS</legend>
<div class="label">CMS Type</div>
<div class="value">{$result['CMS']['Type']}</div>
<div class="label">CMS Version</div>
<div class="value">{$result['CMS']['Version']}</div>
<div class="label">kitFramework compatible</div>
<div class="value {$result['CMS']['css']}">{$result['CMS']['Supported']}</div>
</fieldset>
<fieldset>
<legend>Operating System</legend>
<div class="label">Operating System</div>
<div class="value">{$result['OPERATING_SYSTEM']}</div>
</fieldset>
<fieldset>
<legend>PHP Version</legend>
<div class="label">Required</div>
<div class="value">{$result['PHP_VERSION']['required']}</div>
<div class="label">Installed</div>
<div class="value {$result['PHP_VERSION']['css']}">{$result['PHP_VERSION']['installed']}</div>
</fieldset>
<fieldset>
<legend>Magic Quotes</legend>
<div class="label">Required</div>
<div class="value">{$result['MagicQuotesGPC']['required']}</div>
<div class="label">php.ini setting</div>
<div class="value {$result['MagicQuotesGPC']['css']}">{$result['MagicQuotesGPC']['installed']}</div>
</fieldset>
<fieldset>
<legend>MySQL Version</legend>
<div class="label">Required</div>
<div class="value">{$result['MySQL']['required']}</div>
<div class="label">Installed</div>
<div class="value {$result['MySQL']['css']}">{$result['MySQL']['installed']}</div>
</fieldset>
<fieldset>
<legend>PDO MySQL Extension</legend>
<div class="label">Required</div>
<div class="value">{$pdo_mysql_required}</div>
<div class="label">Available</div>
<div class="value {$result['PDOmySQL']['css']}">{$pdo_mysql_enabled}</div>
</fieldset>
<fieldset>
<legend>MySQL InnoDB Engine</legend>
<div class="label">Required</div>
<div class="value">{$result['InnoDB']['required']}</div>
<div class="label">Available</div>
<div class="value {$result['InnoDB']['css']}">{$result['InnoDB']['available']}</div>
</fieldset>
<fieldset>
<legend>cURL</legend>
<div class="label">Required</div>
<div class="value">{$curl_required}</div>
<div class="label">Installed</div>
<div class="value {$result['cURL']['css']}">{$curl_installed}</div>
</fieldset>
<fieldset>
<legend>ZipArchive</legend>
<div class="label">Required</div>
<div class="value">{$zip_required}</div>
<div class="label">Installed</div>
<div class="value {$result['ZIPArchive']['css']}">{$zip_installed}</div>
</fieldset>
<div class="info">
<p>To get a <a href="?action=phpinfo">detailed PHP information</a> you can use the parameter <code>systemcheck.php?action=phpinfo</code>.</p>
<p>Visit the <a href="https://kit2.phpmanufaktur.de">kitFramework Project</a> and the <a href="https://github.com/phpManufaktur/kitFramework/wiki">kitFramework WIKI</a> to get more information.</p>
<p>Please feel free to contact the <a href="https://support.phpmanufaktur.de">phpManufaktur Support Group</a> to receive assistance.</p>
</div>
</body>
</html>
EOD;
}
public function exec($prompt_result=true)
{
$result = array(
'CMS' => $this->getCMSinformation(),
'OPERATING_SYSTEM' => $this->getOperatingSystem(),
'PHP_VERSION' => $this->getPHPinformation(),
'MySQL' => $this->getMySQLinformation(),
'InnoDB' => $this->getInnoDBinformation(),
'cURL' => $this->isCURLinstalled(),
'ZIPArchive' => $this->isZIParchiveInstalled(),
'PDOmySQL' => $this->isPDOmySQLenabled(),
'MagicQuotesGPC' => $this->isMagicQuotesGPC()
);
return ($prompt_result) ? self::promptResult($result) : $result;
}
}
if (isset($_GET['action']) && ($_GET['action'] === strtolower('phpinfo'))) {
phpinfo();
exit();
}
// check the system for the kitFramework
$info = new SystemCheck();
$info->setRequriredPHPVersion('5.3.3');
$info->setRequiredMySQLVersion('5.0.3');
$info->setRequiredCURL(true);
$info->setRequriredZIPArchive(true);
$info->setRequiredInnoDB(true);
$info->setRequiredPDOmySQL(true);
$info->setRequiredMagicQuotesGPC(false);
$info->exec();