summaryrefslogtreecommitdiffstats
path: root/usr
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2007-11-19 05:38:34 +0000
committerScott Ullrich <sullrich@pfsense.org>2007-11-19 05:38:34 +0000
commit50fa05d1139b44bee2814649c69cac088a053199 (patch)
tree0bc4b9a961efeba3b5a5a0c7db3959dc4d25c866 /usr
parent7aa6eee62183889610780d526749759503fea4da (diff)
downloadpfsense-50fa05d1139b44bee2814649c69cac088a053199.zip
pfsense-50fa05d1139b44bee2814649c69cac088a053199.tar.gz
Add pipe_cmd() function
Diffstat (limited to 'usr')
-rwxr-xr-xusr/local/sbin/pfSsh.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/usr/local/sbin/pfSsh.php b/usr/local/sbin/pfSsh.php
index ac0e118..c78a4c5 100755
--- a/usr/local/sbin/pfSsh.php
+++ b/usr/local/sbin/pfSsh.php
@@ -25,6 +25,26 @@ $shell_cmds = array("alias", "alloc", "bg", "bind", "bindkey", "break",
"uncomplete", "unhash", "unlimit", "unset", "unsetenv", "until", "wait", "where", "which",
"while");
+function pipe_cmd($command, $text_to_pipe) {
+ $descriptorspec = array(
+ 0 => array("pipe", "r"), // stdin
+ 1 => array("pipe", "w"), // stdout
+ 2 => array("pipe", "w")); // stderr ?? instead of a file
+
+ $fd = proc_open("$command", $descriptorspec, $pipes);
+ if (is_resource($fd)) {
+ fwrite($pipes[0], "{$text_to_pipe}");
+ fclose($pipes[0]);
+ while($s= fgets($pipes[1], 1024)) {
+ // read from the pipe
+ $buffer .= $s;
+ }
+ fclose($pipes[1]);
+ fclose($pipes[2]);
+ }
+ return $buffer;
+}
+
if(!function_exists("readline")) {
function readline() {
$fp = fopen('php://stdin', 'r');
@@ -148,6 +168,10 @@ while($shell_active == true) {
}
$command = "";
break;
+ case "!":
+ system("$newcmd");
+ $command = "";
+ break;
}
if($command == "help") {
show_help();
@@ -173,6 +197,7 @@ while($shell_active == true) {
$command = $mlcommand;
}
if($command) {
+ echo $command . "\n";
eval($command);
}
}
OpenPOWER on IntegriCloud