This repository was archived by the owner on Jul 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathPartKeeprRequirements.php
More file actions
213 lines (189 loc) · 6.95 KB
/
Copy pathPartKeeprRequirements.php
File metadata and controls
213 lines (189 loc) · 6.95 KB
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
<?php
class PartKeeprRequirements extends SymfonyRequirements
{
/**
* Constructor that initializes the requirements.
*/
public function __construct()
{
parent::__construct();
$this->addRequirement(
ini_get('allow_url_fopen') || function_exists('curl_init'),
sprintf('No way to remotely load files detected'),
sprintf('Either set <strong>allow_url_fopen=true</strong> or install the cURL extension')
);
$this->addRequirement(
function_exists('imagecreate'),
sprintf('GD library not found'),
sprintf('Install the GD library extension')
);
$this->addRequirement(
function_exists('imagettftext'),
sprintf('GD library has no FreeType support'),
sprintf('Install the FreeType extension and make sure GD extension can use it')
);
$this->addRequirement(
function_exists('ldap_connect'),
sprintf('LDAP library not found'),
sprintf('Install the LDAP library extension')
);
$this->addRequirement(
function_exists('curl_init'),
sprintf('CURL library not found'),
sprintf('Install the CURL library extension')
);
$this->addPhpIniRequirement(
'memory_limit',
$this->getBytesIniSetting('memory_limit') > 128000000,
false,
'Memory Limit too small',
sprintf(
'The php.ini memory_limit directive must be set to 128MB or higher. Your limit is set to %s',
ini_get('memory_limit')
)
);
$this->checkWritable(realpath(dirname(__FILE__).'/../data/'));
$this->checkWritable(realpath(dirname(__FILE__).'/../app/'));
$this->checkWritable(realpath(dirname(__FILE__).'/../web/'));
$this->addRecommendation(
function_exists('apc_fetch'),
sprintf('PHP APCu cache not found'),
sprintf('For best performance install the PHP APCu cache')
);
$this->addPhpIniRecommendation(
'max_execution_time',
ini_get('max_execution_time') > 30,
true,
sprintf('Maximum Execution Time might be too low'),
sprintf(
'Your maximum execution time is set to %d seconds, which might be too low for low-end systems. If you encounter problems, please increase the value.',
ini_get('max_execution_time')
)
);
$this->addRequirement(
function_exists('mb_convert_case'),
sprintf('The PHP function mb_convert_case does not exist.'),
sprintf('Please compile PHP with the mbstring functions in case you are using Gentoo, or install php-mbstring on RedHat, Fedora or CentOS.')
);
$this->addRequirement(
function_exists('bcscale'),
sprintf('BCMath library not found'),
sprintf('Install the BCMath library extension')
);
if (ini_get('opcache.enable')) {
if (version_compare(phpversion(), '7.0', '<')) {
$this->addPhpIniRequirement(
'opcache.save_comments',
1,
false,
'opcache.save_comments must be on',
sprintf('The php.ini opcache.save_comments directive must be set to 1.')
);
$this->addPhpIniRequirement(
'opcache.load_comments',
1,
false,
'opcache.load_comments must be on',
sprintf('The php.ini opcache.load_comments directive must be set to 1.')
);
}
}
}
/**
* Checks if a path is writable. If not, generates a requirement.
*
* @param $path string The path to check
*/
protected function checkWritable($path)
{
try {
$this->isWritableRecursive($path);
} catch (\Exception $e) {
$this->addRequirement(
false,
sprintf(
'Directory %s and all subfolders/files must be writable.<br/><br/>If you already set the subfolders and files writable, you might have SELinux installed. Read <a href="https://wiki.partkeepr.org/wiki/SELinux" target="_blank">the PartKeepr SELinux Wiki Article</a> for further information.<br/>',
$path
),
$e->getMessage()
);
}
}
/**
* Returns a php.ini setting with parsed byte values.
*
* Example: If you specify memory_limit=64M, this method will return 67108864 bytes.
*
* @param $setting string The php.ini setting
*
* @return int The byts
*/
protected function getBytesIniSetting($setting)
{
return (int) $this->returnBytes(ini_get($setting));
}
/**
* Parses a value with g,m or k modifiers and returns the effective bytes.
*
* @param $val string The value to parse
*
* @return int|string The bytes
*/
protected function returnBytes($val)
{
$val = trim($val);
$last = strtolower($val[strlen($val) - 1]);
$vali = (int) substr($val, 0, -1);
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$vali *= 1073741824;
break;
case 'm':
$vali *= 1048576;
break;
case 'k':
$vali *= 1024;
break;
default:
$vali = (int) $val;
}
return $vali;
}
/**
* Checks if the given directory and all contained files within it is writable by the current user.
*
* @param string $dir The directory to check
*
* @throws \Exception If the directory is not writable
*
* @return bool True if the path is writable
*/
protected function isWritableRecursive($dir)
{
if (!is_writable($dir)) {
throw new \Exception($dir.' is not writable.');
}
$folder = opendir($dir);
while ($file = readdir($folder)) {
if ($file != '.' && $file != '..') {
if (!is_writable($dir.'/'.$file)) {
closedir($folder);
throw new \Exception($dir.'/'.$file.' is not writable.');
} else {
// Skip hidden directories
if ((is_dir($dir.'/'.$file)) && ($file[0] == '.')) {
continue;
}
if (is_dir($dir.'/'.$file)) {
if (!$this->isWritableRecursive($dir.'/'.$file)) {
closedir($folder);
throw new \Exception($dir.'/'.$file.' is not writable.');
}
}
}
}
}
return true;
}
}