Skip to content

Commit 1904a16

Browse files
committed
Détection plus fine de l'interpréteur à utiliser
Evite les erreurs : ``` Erreur sur script::cronUpdate() : strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) #0 /var/www/html/plugins/script/core/class/script.class.php(251): strrpos() #1 /var/www/html/plugins/script/core/class/script.class.php(103): scriptCmd->execute() #2 /var/www/html/plugins/script/core/class/script.class.php(75): scriptCmd->refreshInfo() #3 /var/www/html/plugins/script/core/class/script.class.php(43): script->refreshAllInfo() #4 /var/www/html/core/php/jeeCron.php(78): script::cronUpdate() #5 {main} ```
1 parent baf531f commit 1904a16

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

core/class/script.class.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,33 @@ public function execute($_options = null) {
231231
$first_element = explode(' ', $request)[0];
232232
$from_path = false;
233233
$use_shebang = false;
234-
if (is_readable($first_element)) {
235-
$env_path = explode(PATH_SEPARATOR, getenv('PATH'));
236-
$from_path = in_array(dirname($first_element), $env_path);
237-
if (!$from_path) {
238-
$shebang = file_get_contents($first_element, false, null, 0, 3);
239-
$use_shebang = $shebang == '#!/';
234+
$sys_paths = explode(PATH_SEPARATOR, getenv('PATH'));
235+
foreach ($sys_paths as $path) {
236+
if (is_executable($path . DIRECTORY_SEPARATOR . $first_element)) {
237+
$from_path = true;
238+
break;
240239
}
240+
}
241+
if (!$from_path && is_readable($first_element)) {
242+
$env_path = explode(PATH_SEPARATOR, getenv('PATH'));
243+
$shebang = file_get_contents($first_element, false, null, 0, 3);
244+
$use_shebang = $shebang == '#!/';
241245
if (!is_executable($first_element)) {
242246
$cmd = 'sudo chmod +x ' . $first_element . ' 2>/dev/null;';
243247
}
244-
}
245-
$interpreters = [
246-
'.php' => 'php',
247-
'.py' => 'python',
248-
'.pl' => 'perl',
249-
'.rb' => 'ruby'
250-
];
251-
$extension = substr($first_element, strrpos($first_element, '.', -4));
252-
if (isset($interpreters[$extension]) && !$from_path && !$use_shebang) {
253-
$cmd .= $interpreters[$extension] . ' ';
248+
if (!$use_shebang) {
249+
$interpreters = [
250+
'.php' => 'php',
251+
'.py' => 'python',
252+
'.pl' => 'perl',
253+
'.rb' => 'ruby'
254+
];
255+
$point_pos = strpos($first_element, '.', -4);
256+
$extension = substr($first_element, $point_pos);
257+
if (isset($interpreters[$extension])) {
258+
$cmd .= $interpreters[$extension] . ' ';
259+
}
260+
}
254261
}
255262
$cmd .= $request;
256263
$request_shell = new com_shell($cmd . ' 2>&1');

0 commit comments

Comments
 (0)