Skip to content

Commit 2744282

Browse files
committed
v 0.122.0
Diagnostic : - Check max execution time - Test if htaccess behave correctly.
1 parent d7e1c6e commit 2744282

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

tools/diagnostic/inc/40-wordpress.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,50 @@ function wputools_diagnostic_check_domain_is_preproduction($domainName) {
161161
}
162162
$is_test_extension = $host_extension && in_array($host_extension, $ignored_extensions);
163163

164+
/* ----------------------------------------------------------
165+
Htaccess
166+
---------------------------------------------------------- */
167+
168+
$temp_dir_name = 'wputools_temp_dir_' . uniqid();
169+
$wputools_temp_dir = wp_upload_dir()['basedir'] . '/' . $temp_dir_name;
170+
$wputools_temp_url = wp_upload_dir()['baseurl'] . '/' . $temp_dir_name;
171+
mkdir($wputools_temp_dir, 0755, true);
172+
if (!is_dir($wputools_temp_dir)) {
173+
$wputools_errors[] = sprintf('The temporary directory %s could not be created', $wputools_temp_dir);
174+
} else {
175+
/* Create temp files */
176+
$temp_files = array(
177+
'.htaccess',
178+
'test.txt'
179+
);
180+
181+
foreach ($temp_files as $temp_file) {
182+
file_put_contents($wputools_temp_dir . '/' . $temp_file, 'deny from all');
183+
}
184+
185+
/* Test if the temporary directory is correctly blocked */
186+
$response = wp_remote_get($wputools_temp_url . '/test.txt');
187+
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 403) {
188+
$wputools_errors[] = 'The temporary directory test did not return a 403 error as expected.';
189+
}
190+
191+
/* Clean up the temporary directory */
192+
foreach ($temp_files as $temp_file) {
193+
unlink($wputools_temp_dir . '/' . $temp_file);
194+
}
195+
196+
/* Test if the temporary directory does not show an Apache index */
197+
$response = wp_remote_get($wputools_temp_url . '/');
198+
if (!is_wp_error($response)) {
199+
$body = wp_remote_retrieve_body($response);
200+
if (strpos($body, '<title>Index of') !== false) {
201+
$wputools_errors[] = 'The temporary directory is publicly accessible and shows an Apache index.';
202+
}
203+
}
204+
205+
rmdir($wputools_temp_dir);
206+
}
207+
164208
/* ----------------------------------------------------------
165209
Mail
166210
---------------------------------------------------------- */
@@ -286,6 +330,17 @@ function wputools_diagnostic_check_domain_is_preproduction($domainName) {
286330
}
287331
}
288332

333+
/* ----------------------------------------------------------
334+
Check execution time
335+
---------------------------------------------------------- */
336+
337+
if (!$wputools_is_cli) {
338+
$execution_time = ini_get('max_execution_time');
339+
if ($execution_time < 5 || $execution_time > 120) {
340+
$wputools_errors[] = sprintf('WordPress : max_execution_time should be set roughly to 30 seconds. Current value is %s seconds.', $execution_time);
341+
}
342+
}
343+
289344
/* ----------------------------------------------------------
290345
Check for enabled auto file modification
291346
---------------------------------------------------------- */

wputools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
WPUTools(){
44

5-
local _WPUTOOLS_VERSION='0.121.0';
5+
local _WPUTOOLS_VERSION='0.122.0';
66
local _PHP_VERSIONS=(7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5 9.0)
77
local _PHP_VERSIONS_OBSOLETES=(7.0 7.1 7.2 7.3 7.4 8.0)
88
local _PHP_VERSIONS_ADVANCED=(8.3 8.4 8.5 9.0)

0 commit comments

Comments
 (0)