-
Notifications
You must be signed in to change notification settings - Fork 18
/
probe.php
615 lines (521 loc) · 20.4 KB
/
probe.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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?php
/**
* ActiveCollab Probe
*
* Copyright (c) 2012 A51 d.o.o.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
if (!empty($_GET) && array_key_exists('phpinfo', $_GET)) {
phpinfo();
die();
}
// -- Please provide valid database connection parameters ------------------------------
const DB_HOST = ''; // Address of your MySQL server (usually localhost)
const DB_USER = ''; // Username that is used to connect to the server
const DB_PASS = ''; // User's password
const DB_NAME = ''; // Name of the database you are connecting to
// -- No need to change anything below this line --------------------------------------
const PROBE_VERSION = '7.3';
const PROBE_FOR = 'ActiveCollab 7.3 and newer';
const STATUS_OK = 'ok';
const STATUS_WARNING = 'warning';
const STATUS_ERROR = 'error';
class TestResult
{
private $message;
private $status;
private $details;
function __construct($message, $status = STATUS_OK, $details = '')
{
$this->message = $message;
$this->status = $status;
$this->details = $details;
}
public function render()
{
$html = '<li class="' . $this->status . '"><span class="status">' . $this->status . '</span> — ' . $this->message;
if ($this->details) {
$html .= ' <span class="details">' . $this->details . '</span>';
}
$html .= '</li>';
print $html;
}
}
?>
<html>
<head>
<title>ActiveCollab environment test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font: 1em "Lucida Grande", verdana, arial, helvetica, sans-serif;
text-align: center;
background: white;
color: #333;
}
h1, h2 {
margin: 16px 0;
}
h1 {
text-align: center;
}
a {
color: #333;
border-bottom: 1px solid #ccc;
text-decoration: none;
}
a:hover {
color: black;
border-color: black;
}
p {
margin: 8px 0;
}
ul {
margin: 8px 0;
padding: 0 0 0 33px;
list-style: square;
}
dl {
margin: 8px 0;
color: #999;
font-size: 80%;
}
dt, dd {
padding: 3px;
}
dt {
float: left;
width: 100px;
}
dd {
padding-left: 100px;
border-bottom: 1px solid #e8e8e8;
}
#wrapper {
margin: 100px auto 16px auto;
padding: 9px 25px 25px 25px;
border: 10px solid #ccc;
width: 600px;
text-align: left;
}
.ok span.status, .warning span.status, .error span.status {
font-weight: bolder;
}
.ok span.status {
color: green;
}
.warning span.status {
color: orange;
}
.error span.status {
color: red;
}
span.details {
font-weight: normal;
font-size: 12px;
color: #999;
display: block;
padding: 5px;
}
#verdict {
margin: 20px 0;
padding: 20px;
text-align: center;
font-size: 160%;
color: white;
border-radius: 15px;
}
#verdict.all_ok {
background: green;
}
#verdict.not_ok {
background: #BC0000;
}
</style>
</head>
<body>
<div id="wrapper">
<h1>probe.php</h1>
<p style="padding: 16px 0; text-align: center; color: #666;">This simple utility will help you check if your server environment can run ActiveCollab. Grab the latest version on <a href="https://github.com/activecollab/activecollab-probe" target="_blank">GitHub</a>.</p>
<dl>
<dt>Probe Version:</dt>
<dd><?php echo PROBE_VERSION ?></dd>
<dt>Testing For:</dt>
<dd><?php echo PROBE_FOR ?></dd>
</dl>
<h2>1. Environment test</h2>
<ul>
<?php
// ---------------------------------------------------
// Validators
// ---------------------------------------------------
/**
* Validate PHP platform
*
* @param array $results
* @return bool
*/
function validate_php(&$results)
{
if (version_compare(PHP_VERSION, '8.0', '<')) {
$results[] = new TestResult('Minimum PHP version required in order to run ActiveCollab is PHP 8.0. Your PHP version: ' . PHP_VERSION . ' (<a href="probe.php?phpinfo" target="_blank">show info</a>)', STATUS_ERROR);
return false;
} else {
$results[] = new TestResult('Your PHP version is ' . PHP_VERSION . ' (<a href="probe.php?phpinfo" target="_blank">show info</a>)', STATUS_OK);
return true;
}
}
/**
* Validate memory limit
*
* @param array $results
* @return bool
*/
function validate_memory_limit(&$results)
{
$memory_limit = php_config_value_to_bytes(ini_get('memory_limit'));
$formatted_memory_limit = $memory_limit === -1 ? 'unlimited' : format_file_size($memory_limit);
if ($memory_limit === -1 || $memory_limit >= 67108864) {
$results[] = new TestResult('Your memory limit is: ' . $formatted_memory_limit, STATUS_OK);
return true;
} else {
$results[] = new TestResult('Your memory is too low to complete the installation. Minimal value is 64MB, and you have it set to ' . $formatted_memory_limit, STATUS_ERROR);
return false;
}
}
/**
* Validate PHP extensions
*
* @param array $results
* @return bool
*/
function validate_extensions(&$results)
{
$ok = true;
$required_extensions = [
'mysqli',
'pcre',
'tokenizer',
'ctype',
'session',
'json',
'xml',
'dom',
'phar',
'openssl',
'gd',
'mbstring',
'curl',
'zlib',
'fileinfo',
];
foreach ($required_extensions as $required_extension) {
if (extension_loaded($required_extension)) {
$results[] = new TestResult("Required extension <span style=\"color: orange\">$required_extension</span> found", STATUS_OK);
} else {
$results[] = new TestResult("Extension <span style=\"color: orange\">$required_extension</span> is required in order to run ActiveCollab", STATUS_ERROR);
$ok = false;
}
}
// Check for eAccelerator
if (extension_loaded('eAccelerator') && ini_get('eaccelerator.enable')) {
$results[] = new TestResult("eAccelerator opcode cache enabled. <span class=\"details\">eAccelerator opcode cache causes ActiveCollab to crash. <a href=\"https://eaccelerator.net/wiki/Settings\">Disable it</a> for folder where ActiveCollab is installed, or use APC instead: <a href=\"http://www.php.net/apc\">http://www.php.net/apc</a>.</span>", STATUS_ERROR);
$ok = false;
}
// Check for XCache
if (extension_loaded('XCache') && ini_get('xcache.cacher')) {
$results[] = new TestResult("XCache opcode cache enabled. <span class=\"details\">XCache opcode cache causes ActiveCollab to crash. <a href=\"http://xcache.lighttpd.net/wiki/XcacheIni\">Disable it</a> for folder where ActiveCollab is installed, or use APC instead: <a href=\"http://www.php.net/apc\">http://www.php.net/apc</a>.</span>", STATUS_ERROR);
$ok = false;
}
$recommended_extensions = [
'iconv' => 'Iconv is used for character set conversion. Without it, system is a bit slower when converting different character set. Please refer to <a href="http://www.php.net/manual/en/iconv.installation.php">this</a> page for installation instructions',
'imap' => 'IMAP is used to connect to POP3 and IMAP servers. Without it, Incoming Mail module will not work. Please refer to <a href="http://www.php.net/manual/en/imap.installation.php">this</a> page for installation instructions',
];
foreach ($recommended_extensions as $recommended_extension => $recommended_extension_desc) {
if (extension_loaded($recommended_extension)) {
$results[] = new TestResult(
"Recommended extension <span style=\"color: orange\">$recommended_extension</span> found",
STATUS_OK
);
} else {
$results[] = new TestResult(
"Extension <span style=\"color: orange\">$recommended_extension</span> was not found",
STATUS_WARNING,
$recommended_extension_desc
);
}
}
return $ok;
}
/**
* Convert filesize value from php.ini to bytes
*
* Convert PHP config value (2M, 8M, 200K...) to bytes. This function was taken from PHP documentation. $val is string
* value that need to be converted
*
* @param string $val
* @return integer
*/
function php_config_value_to_bytes($val)
{
$val = trim($val);
if (ctype_digit($val)) {
$last = '';
} else {
$last = strtolower(substr($val, strlen($val) - 1));
$val = substr($val, 0, strlen($val) - 1);
}
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return (integer) $val;
}
/**
* Format filesize
*
* @param string $value
* @return string
*/
function format_file_size($value)
{
$data = [
'TB' => 1099511627776,
'GB' => 1073741824,
'MB' => 1048576,
'kb' => 1024,
];
// commented because of integer overflow on 32bit sistems
// http://php.net/manual/en/language.types.integer.php#language.types.integer.overflow
// $value = (integer) $value;
foreach ($data as $unit => $bytes) {
$in_unit = $value / $bytes;
if ($in_unit > 0.9) {
return trim(trim(number_format($in_unit, 2), '0'), '.') . $unit;
}
}
return $value . 'b';
}
/**
* @param mysqli $link
* @return string
*/
function get_mysql_version($link)
{
if ($result = $link->query("SELECT VERSION() AS 'version'")) {
while ($row = $result->fetch_assoc()) {
return $row['version'];
}
}
return $link->get_server_info();
}
function validate_mysql_version($version, $min_mysql_version, $min_mariadb_version)
{
if (strpos(strtolower($version), 'mariadb') !== false) {
return [
'MariaDB',
$min_mariadb_version,
strpos($version, $min_mariadb_version) !== false || version_compare($version, $min_mariadb_version) >= 0,
];
} else {
return [
'MySQL',
$min_mysql_version,
version_compare($version, $min_mysql_version) >= 0,
];
}
}
/**
* @param mysqli $link
* @return bool
*/
function check_is_database_empty($link)
{
if ($result = $link->query('SHOW TABLES')) {
return $result->num_rows < 1;
}
return true;
}
/**
* Return true if MySQL supports InnoDB storage engine
*
* @param mysqli $link
* @return bool
*/
function check_have_inno(mysqli $link)
{
if ($result = $link->query('SHOW ENGINES')) {
while ($engine = $result->fetch_assoc()) {
if (strtolower($engine['Engine']) == 'innodb' && in_array(strtolower($engine['Support']), ['yes', 'default'])) {
return true;
}
}
}
return false;
}
/**
* @param mysqli $link
* @return bool
*/
function check_have_utf8mb4($link)
{
if ($result = $link->query("SHOW CHARACTER SET LIKE 'utf8mb4'")) {
while ($charset = $result->fetch_assoc()) {
if (strtolower($charset['Charset']) == 'utf8mb4') {
return true;
}
}
}
return false;
}
/**
* @param mysqli $link
* @return bool
*/
function check_thread_stack($link)
{
if ($result = $link->query("SELECT @@thread_stack AS 'thread_stack'")) {
while ($row = $result->fetch_assoc()) {
return (int) $row['thread_stack'] >= 262144; // 256kb
}
}
return false;
}
// ---------------------------------------------------
// Do the magic
// ---------------------------------------------------
$results = [];
$php_ok = validate_php($results);
$memory_ok = validate_memory_limit($results);
$extensions_ok = validate_extensions($results);
foreach ($results as $result) {
$result->render();
}
?>
</ul>
<h2>2. Database test</h2>
<?php if (DB_HOST && DB_USER && DB_NAME) { ?>
<ul>
<?php
$mysql_ok = true;
$results = [];
$link = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($link instanceof mysqli) {
$results[] = new TestResult('Connected to database as ' . DB_USER . '@' . DB_HOST);
$mysql_version = get_mysql_version($link);
list ($mysql_server, $min_mysql_server_version, $mysql_version_ok) = validate_mysql_version(
$mysql_version,
'5.7.8',
'10.2.7'
);
if ($mysql_version_ok) {
$results[] = new TestResult("{$mysql_server} version is {$mysql_version}");
if (check_is_database_empty($link)) {
$results[] = new TestResult('Database is empty');
} else {
$results[] = new TestResult(
'Database is not empty',
STATUS_WARNING,
'Empty database is required if your installing a fresh copy of ActiveCollab. Database not being empty is OK if you are upgrading'
);
}
if (check_have_inno($link)) {
$results[] = new TestResult('InnoDB support is enabled');
} else {
$results[] = new TestResult('No InnoDB support', STATUS_ERROR);
$mysql_ok = false;
}
if (check_have_utf8mb4($link)) {
$results[] = new TestResult('UTF8MB4 support available');
} else {
$results[] = new TestResult('UTF8MB4 support not available', STATUS_ERROR);
$mysql_ok = false;
}
if (check_thread_stack($link)) {
$results[] = new TestResult("{$mysql_server} thread stack is 256kb");
} else {
$results[] = new TestResult("{$mysql_server} thread stack should be 256kb", STATUS_ERROR);
$mysql_ok = false;
}
} else {
$results[] = new TestResult("{$mysql_server} {$min_mysql_server_version} or later is required. Your {$mysql_server} version is {$mysql_version}", STATUS_ERROR);
$mysql_ok = false;
}
} else {
$results[] = new TestResult('Failed to connect to database. MySQL said: ' . mysqli_connect_error(), STATUS_ERROR);
$mysql_ok = false;
}
// ---------------------------------------------------
// Validators
// ---------------------------------------------------
foreach ($results as $result) {
$result->render();
}
?>
</ul>
<?php } else { ?>
<p>Database test is <strong style="color: red">turned off</strong>. To turn it On, please open probe.php in your favorite text
editor and set DB_XXXX connection parameters in database section at the beginning of the file:</p>
<ul>
<li><span style="color: orange">DB_HOST</span> — Address of your MySQL server (usually localhost)</li>
<li><span style="color: orange">DB_USER</span> — Username that is used to connect to the server</li>
<li><span style="color: orange">DB_PASS</span> — User's password</li>
<li><span style="color: orange">DB_NAME</span> — Name of the database you are connecting to</li>
</ul>
<p>Once these settings are set, probe.php will check if your database meets the system requirements.</p>
<?php $mysql_ok = null; ?>
<?php } ?>
<?php if ($mysql_ok !== null) { ?>
<?php if ($php_ok && $memory_ok && $extensions_ok && $mysql_ok) { ?>
<p id="verdict" class="all_ok">OK, this system can run ActiveCollab</p>
<?php } else { ?>
<p id="verdict" class="not_ok">This system does not meet ActiveCollab system requirements</p>
<h2>Legend</h2>
<div id="legend">
<ul>
<li class="ok"><span>ok</span> — All OK</li>
<li class="warning"><span>warning</span> — Not a deal breaker, but it's recommended to have
this installed for some features to work
</li>
<li class="error"><span>error</span> — ActiveCollab require this feature and can't work
without it
</li>
</ul>
</div>
<?php } ?>
<?php } ?>
</div>
<?php
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('GMT');
}
?>
<p id="footer">©2007‐<?php echo date('Y') ?>. <a href="https://activecollab.com">ActiveCollab, Inc</a>.</p>
</body>
</html>