diff --git a/public/git-pull.php b/public/git-pull.php index fe137e3c6..e4789c86f 100644 --- a/public/git-pull.php +++ b/public/git-pull.php @@ -32,6 +32,7 @@ echo "Disabled Functions: " . (ini_get('disable_functions') ?: '(none)') . "\n"; echo "shell_exec status: " . (function_exists('shell_exec') ? 'Enabled' : 'Disabled') . "\n"; echo "exec status: " . (function_exists('exec') ? 'Enabled' : 'Disabled') . "\n"; echo "system status: " . (function_exists('system') ? 'Enabled' : 'Disabled') . "\n"; +echo "proc_open status: " . (function_exists('proc_open') ? 'Enabled' : 'Disabled') . "\n"; echo "-----------------------------------------\n\n"; // Move to the root directory (one level up from public) @@ -41,12 +42,36 @@ if ($rootPath) { } echo "Working Directory: " . getcwd() . "\n\n"; -// Helper function to execute and print command output +// Helper function to execute commands with proc_open or standard fallbacks function execute($cmd) { echo "$ {$cmd}\n"; $output = ''; - if (function_exists('shell_exec')) { + + if (function_exists('proc_open')) { + $descriptorspec = [ + 0 => ["pipe", "r"], // stdin + 1 => ["pipe", "w"], // stdout + 2 => ["pipe", "w"] // stderr + ]; + + $process = proc_open($cmd, $descriptorspec, $pipes); + + if (is_resource($process)) { + fclose($pipes[0]); + + $stdout = stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $stderr = stream_get_contents($pipes[2]); + fclose($pipes[2]); + + proc_close($process); + $output = $stdout . $stderr; + } else { + $output = "Error: Failed to open process using proc_open."; + } + } elseif (function_exists('shell_exec')) { $output = shell_exec($cmd); } elseif (function_exists('exec')) { $outputLines = []; @@ -57,7 +82,7 @@ function execute($cmd) { system($cmd); $output = ob_get_clean(); } else { - echo "Error: No command execution functions (shell_exec, exec, system) are enabled on this hosting server.\n"; + echo "Error: No command execution functions (proc_open, shell_exec, exec, system) are enabled on this hosting server.\n"; echo "-----------------------------------------\n"; return; }