-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_bin_test.php
148 lines (130 loc) · 4.01 KB
/
php_bin_test.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
<?php
try {
// to prevent it that the output is compressed, resulting in invalid string
ini_set('zlib.output_compression', 'Off');
} catch (\Exception $e) {
// just ignore it
}
$valid = true;
if (!version_compare(PHP_VERSION, '8.0.2', '>=')) {
echo "ERROR: PHP CLI 8.0.2 or higher is required - ";
$valid = false;
}
//if (!empty(ini_get('open_basedir'))) {
// echo "ERROR: Please disable the <strong>open_basedir</strong> setting to continue.<br />";
// $valid = false;
//}
if (!function_exists('mysqli_connect')) {
echo "ERROR: Mysqli Extension is required - ";
$valid = false;
}
if (!extension_loaded('openssl')) {
echo "ERROR: OpenSSL PHP Extension is required - ";
$valid = false;
}
if (!extension_loaded('mbstring')) {
echo "ERROR: Mbstring PHP Extension is required - ";
$valid = false;
}
if (!extension_loaded('pdo')) {
echo "ERROR: PDO PHP extension is required - ";
$valid = false;
}
if (!extension_loaded('tokenizer')) {
echo "ERROR: Tokenizer PHP Extension is required - ";
$valid = false;
}
if (!class_exists('ZipArchive', false)) {
echo "ERROR: PHP Zip Archive is required - ";
$valid = false;
}
if (!extension_loaded('imap')) {
echo "ERROR: PHP IMAP Extension is required - ";
$valid = false;
}
/*** not required for PHP CLI
if (!(extension_loaded('gd') && function_exists('gd_info'))) {
echo "ERROR: PHP GD Library is required - ";
$valid = false;
}
***/
/*** not required for PHP CLI
if (!extension_loaded('fileinfo')) {
echo "ERROR: PHP Fileinfo extension is required - ";
$valid = false;
}
***/
if (!extension_loaded('curl')) {
echo "ERROR: PHP CURL extension is required - ";
$valid = false;
}
if (!extension_loaded('xml')) {
echo "ERROR: PHP XML extension is required - ";
$valid = false;
}
if (!class_exists('SQLite3')) {
echo "ERROR: PHP SQLite3 extension is required - ";
$valid = false;
}
/*
// proc_close() check =========
$proc_close_enabled = true;
try {
$disabled = explode(',', ini_get('disable_functions'));
$proc_close_enabled = !in_array('proc_close', $disabled);
} catch (\Exception $ex) {
$proc_close_enabled = false;
}
if (!$proc_close_enabled) {
echo "ERROR: <strong>proc_close()</strong> must be enabled.<br />";
$valid = false;
}
*/
// =============================
// escapeshellarg() check =========
$escapeshellarg_enabled = true;
try {
$disabled = explode(',', ini_get('disable_functions'));
$escapeshellarg_enabled = !in_array('escapeshellarg', $disabled);
} catch (\Exception $ex) {
$escapeshellarg_enabled = false;
}
if (!$escapeshellarg_enabled) {
echo "ERROR: <strong>escapeshellarg()</strong> must be enabled.<br />";
$valid = false;
}
// check directory permission
// $dirs = [ 'storage/app', 'storage/framework', 'storage/logs', 'bootstrap/cache' ];
// foreach ($dirs as $dir) {
// $basepath = pathinfo(__FILE__)['dirname'];
// $path = "$basepath/$dir";
// file_put_contents('/tmp/emo', $path);
// if (!(file_exists($path) && is_dir($path) && is_writable($path))) {
// echo "ERROR: The directory [{$dir}] must be writable by the web server.<br />";
// $valid = false;
// }
// }
$dirs = ['storage/app', 'storage/framework', 'storage/logs', 'bootstrap/cache'];
foreach ($dirs as $dir) {
$basepath = pathinfo(__FILE__)['dirname'];
$path = "$basepath/$dir";
// Define the path to the 'tmp' directory
$tempDir = "$basepath/tmp";
// Ensure the 'tmp' directory exists
if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true); // Create the 'tmp' directory if it doesn't exist
}
// Define the temp file path
$tempPath = "$tempDir/emo";
// Write the path to a valid temporary location
file_put_contents($tempPath, $path);
// Check if directory is writable
if (!(file_exists($path) && is_dir($path) && is_writable($path))) {
echo "ERROR: The directory [{$dir}] must be writable by the web server.<br />";
$valid = false;
}
}
// just finish
if ($valid) {
echo "ok";
}