Add cmpShellEsc

This commit is contained in:
cmp167
2023-08-23 21:00:54 +12:00
parent b08e3df595
commit 8301ee83d3

View File

@@ -249,8 +249,7 @@
return $a; return $a;
} }
function cmpShellEscStr($str) {
function cmpShellEscArr($cmaRaw) {
$ttr = array( $ttr = array(
"\t" => "\\\t", "\$" => "\\\$", "\t" => "\\\t", "\$" => "\\\$",
"\\" => "\\\\", "\"" => "\\\"", "\\" => "\\\\", "\"" => "\\\"",
@@ -265,24 +264,29 @@
"?" => "\\?" , "!" => "\\!" "?" => "\\?" , "!" => "\\!"
); );
if(@$str[0] == "asis")
return @$str[1];
return strtr($str, $ttr);
}
function cmpShellEscArr($cmaRaw) {
$cmaEsc = array(); $cmaEsc = array();
for($i = 0; $i < count($cmaRaw); $i++) { for($i = 0; $i < count($cmaRaw); $i++) {
if(@$cmaRaw[$i][0] == "asis") { $cmaEsc[] = $this->cmpShellEscStr($cmaRaw[$i]);
$cmaEsc[] = $cmaRaw[$i][1];
continue;
}
$cmaEsc[] = strtr($cmaRaw[$i], $ttr);
} }
return $cmaEsc; return $cmaEsc;
} }
function cmpShellEscStr($cmaRaw) { function cmpShellEsc($cmaRaw) {
$cmaEsc = $this->cmpShellEscArr($cmaRaw); if(is_array($cmaRaw)) {
$cmaEsc = $this->cmpShellEscArr($cmaRaw);
return join(" ", $cmaEsc);
}
return join(" ", $cmaEsc); return $this->cmpShellEscStr($cmaRaw);
} }
function cmpSysExec($cmaRaw, $opt = []) { function cmpSysExec($cmaRaw, $opt = []) {
@@ -333,8 +337,23 @@
fclose($ppsAll[0]); fclose($ppsAll[0]);
} }
$out = stream_get_contents($ppsAll[1], 1048576); if(@$opt["stdOutRead"]) {
$err = stream_get_contents($ppsAll[2], 1048576); $this->d("Read loop");
while(!feof($ppsAll[1])) {
$out = stream_get_contents($ppsAll[1], 1048576);
// $err = stream_get_contents($ppsAll[2], 1048576);
($opt["stdOutRead" ]["call"]) (
$out,
$opt["stdOutRead"]
);
}
}
else {
$out = stream_get_contents($ppsAll[1], 1048576);
$err = stream_get_contents($ppsAll[2], 1048576);
}
fclose($ppsAll[1]); fclose($ppsAll[1]);
fclose($ppsAll[2]); fclose($ppsAll[2]);