forked from revive-adserver/revive-adserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-check.php
347 lines (327 loc) · 11 KB
/
pre-check.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
<?php
/*
+---------------------------------------------------------------------------+
| Revive Adserver |
| http://www.revive-adserver.com |
| |
| Copyright: See the COPYRIGHT.txt file. |
| License: GPLv2 or later, see the LICENSE.txt file. |
+---------------------------------------------------------------------------+
*/
/**
* @package OpenX
* @author Łukasz Wikierski <[email protected]>
*
* A pre-initialisation file to check if system settings allow OpenX
* to be run or not.
*/
require_once 'memory.php';
/**
* A function to check system settings and display detected problems
*/
function OX_initialSystemCheck(){
$errorUrl = 'http://www.openx.org/help/2.8/pre-init-error/';
$installed = OX_checkSystemInstalled();
$aErrors = array();
$erorCode = OX_checkSystemInitialRequirements($aErrors);
if ($erorCode !== true) {
$imageRelativePath = "./www/admin/precheck/";
// Do functions strpos & parse_url exist? If so, try to
// guess the proper relative path...
if ($erorCode != -2) {
// Checking if URL include www or admin in path
if (strpos($_SERVER['REQUEST_URI'], '/www/admin/') !== false) {
$imageRelativePath = "./precheck/";
} else if (strpos($_SERVER['REQUEST_URI'], '/www/') !== false) {
$imageRelativePath = "./admin/precheck/";
}
}
// We always trying show images in CSS
$bodyBackground = "url('{$imageRelativePath}body_piksel.gif') repeat-x";
$liBackground = "background: url('{$imageRelativePath}list_element.gif') no-repeat;";
$openXLogo = "background: url('{$imageRelativePath}openx_logo.gif') no-repeat;";
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<title>php Error page</title>
<style type="text/css">
body {
margin: 0;
background: #fff '. $bodyBackground .';
font-family: Arial, Helvetica, sans-serif;
font: 12px Arial;
color: #747474;
}
h1 {
width:80%;
font: 26px Arial;
color:#000;
}
h2 {
width:80%;
font:12px Arial;
color:#747474;
margin-top:20px;
}
.error_container {
margin-top: 80px;
margin-left: 93px;
}
.error_list {
width: 80%;
padding-left: 33px;
padding-top: 15px;
padding-bottom:15px;
line-height:18px;
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
}
ul {
list-style-type: none;
list-style-position: outside;
padding:0px;
padding-top:10px;
margin:0px;
margin-left:15px;
}
li {
'.$liBackground.'
padding-left:10px;
}
.help_link:active, .help_link:link, .help_link:visited {
color: #0767a8;
text-decoration:none;
}
.help_link:hover {
color: #0767a8;
text-decoration:underline;
}
.logo_image {
'.$openXLogo.'
width: 173px;
height: 60px;
}
</style>
</head>
<body>
<div class="logo_image"> </div>
<div class="error_container">
';
if ($installed) {
$message .= "
<h1>Sorry, but OpenX cannot currently run on your machine</h1>
";
} else {
$message .= "
<h1>Sorry, but the OpenX installer system cannot currently be started</h1>
";
}
$message .= '
<div class="error_list">
Detected problem';
if (count($aErrors) > 1) {
$message .= "s";
}
$message .= ":
<ul>
";
echo $message;
foreach ($aErrors as $errorMessage) {
echo "<li>{$errorMessage}</li>";
}
$message = '
</ul>
</div>
<h2>Please see our <a href="'.$errorUrl.'" class="help_link" >documentation</a> for help
with the above error';
if (count($aErrors) > 1) {
$message .= "s";
}
$message .= ".
</h2>
</div>
</body>
</html>
";
echo $message;
// Terminate execution
exit;
}
}
/**
* Check (roughly) to see if the system is installed without
* any of the usual code to check this, as running in pre-init
* mode.
*
* @return bool True if the system seems to be installed, false
* otherwise.
*/
function OX_checkSystemInstalled()
{
$path = @dirname(__FILE__);
if (!@empty($path)) {
if (@file_exists($path . '/var/UPGRADE')) {
return false;
} else {
return true;
}
}
return false;
}
/**
* Check for situation when installing or using software is eithe
* imposible, or results in unformated error output, due to system
* configuration.
*
* @param &$aErrors Array of error mesages. All errors that it is possible to
* detect will be set, regardless of the function return value.
* @return bool|int True on system check OK, negative int value on detected problems.
* -1 => The "function_exists" built-in function doesn't exist
* -2 => At least one of the "strpos" or "parse_url" built-in
* functions don't exist
* -3 => One of the other required built-in functions was
* detected as being disabled
* -4 => The amount of memory required was too low
*
*/
function OX_checkSystemInitialRequirements(&$aErrors){
// Variables for tracking if the test has passed or not,
// and if not, what value to return
$isSystemOK = true;
$return = true;
// The general list of built in PHP functions that are required to
// run OpenX, apart from the functions:
//
// - "function_exists"
// - "array_intersect"
// - "explode"
// - "ini_get"
// - "trim"
// - "parse_url"
// - "strpos"
//
// These other functions are tested separately, as they are
// required to test for the existence of the functions in the
// array below!
$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 = OX_getMinimumRequiredMemory();
$phpMemoryLimit = OX_getMemoryLimitSizeInBytes();
if ($phpMemoryLimit > 0 && $phpMemoryLimit < $minimumRequiredMemory) {
// The memory limit is too low, but can it be increased?
$memoryCanBeSet = OX_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;
}
}
}
if (!$isSystemOK) {
return $return;
}
return true;
}
OX_initialSystemCheck();
?>