-
Notifications
You must be signed in to change notification settings - Fork 1
/
p_c.php
167 lines (152 loc) · 5.56 KB
/
p_c.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
<?php
require_once 'mem_f.php';
function MAD_CheckIfSystemInstalled()
{
$path = @dirname(__FILE__);
if (!@empty($path)) {
if (@file_exists($path . '/conf/INSTALLED')) {
return false;
} else {
return true;
}
}
return false;
}
function MAD_checkSystemInitialRequirements(&$aErrors){
$isSystemOK = true;
$return = true;
$aRequiredFunctions = array(
'dirname',
'empty',
'file_exists',
'ini_set',
'parse_ini_file',
'version_compare'
);
// Prepare error strings, in the simplest possible way
$errorString1 = 'The built in PHP function "';
$errorString2 = '" is in the "disable_functions" list in your "php.ini" file.';
// Need "function_exists" to be able to test for functions required
// for testing what is in the "disabled_functions" list
if (!function_exists('function_exists')) {
$aErrors[] = $errorString1 . 'function_exists' . $errorString2;
// Cannot detect any more errors, as function_exists is
// needed to detect the required functions!
return -1;
}
// Test for existence of "parse_url" and "strpos", which are
// special cases required for the display of the error message
// in the event of anything failing in this test!
if (!function_exists('parse_url')) {
$aErrors[] = $errorString1 . 'parse_url' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -2;
}
}
if (!function_exists('strpos')) {
$aErrors[] = $errorString1 . 'strpos' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -2;
}
}
// Test for existence of "array_intersect", "explode", "ini_get"
// and "trim", which are all required as part of the code to test
// which functions are in the "disabled_functions" list below...
if (!function_exists('array_intersect')) {
$aErrors[] = $errorString1 . 'array_intersect' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('explode')) {
$aErrors[] = $errorString1 . 'explode' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('ini_get')) {
$aErrors[] = $errorString1 . 'ini_get' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('trim')) {
$aErrors[] = $errorString1 . 'trim' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
// Test the disabled functons list with required functions list
// defined above in $aRequiredFunctions
$aDisabledFunctions = explode(',', ini_get('disable_functions'));
foreach ($aDisabledFunctions as $key => $value) {
$aDisabledFunctions[$key] = trim($value);
}
$aNeededFunctions = array_intersect($aDisabledFunctions, $aRequiredFunctions);
if (count($aNeededFunctions) > 0) {
$isSystemOK = false;
foreach ($aNeededFunctions as $functionName) {
$aErrors[] = $errorString1 . $functionName . $errorString2;
}
}
// Check PHP version, as use of PHP < 5.1.4 will result in parse errors
$errorMessage = "PHP version 5.1.4, or greater, was not detected.";
if (function_exists('version_compare')) {
$result = version_compare(phpversion(), '5.1.4', '<');
if ($result) {
$aErrors[] = $errorMessage;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
}
// Check minimum memory requirements are okay (24MB)
$minimumRequiredMemory = MAD_getMinimumRequiredMemory();
$phpMemoryLimit = MAD_getMemoryLimitSizeInBytes();
if ($phpMemoryLimit > 0 && $phpMemoryLimit < $minimumRequiredMemory) {
// The memory limit is too low, but can it be increased?
$memoryCanBeSet = MAD_checkMemoryCanBeSet();
if (!$memoryCanBeSet) {
$minimumRequiredMemoryInMB = $minimumRequiredMemory / 1048576;
$errorMessage = 'The PHP "memory_limit" value is set to less than the required minimum of ' .
$minimumRequiredMemoryInMB . 'MB, but because the built in PHP function "ini_set" ' .
'has been disabled, the memory limit cannot be automatically increased.';
$aErrors[] = $errorMessage;
$isSystemOK = false;
if ($return === true) {
$return = -4;
}
}
}
// Check magic_quotes_runtime and try to unset it
$GLOBALS['original_get_magic_quotes_runtime'] = MAD_getMagicQuotesRuntime();
if ($GLOBALS['original_get_magic_quotes_runtime']) {
ini_set('magic_quotes_runtime', 0);
if (MAD_getMagicQuotesRuntime()) {
// try deprecated set_magic_quotes_runtime
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime(0);
}
}
// check magic_quotes_runtime again, stop if still is set
if (MAD_getMagicQuotesRuntime()) {
$aErrors[] = 'The PHP magic_quotes_runtime option is ON, and cannot be automatically turned off.';
$isSystemOK = false;
if ($return === true) {
$return = -5;
}
}
}
if (!$isSystemOK) {
return $return;
}
return true;
}
?>