Difference between
modified post af266a5 by Anonymous on Mon 18th Jul 2016 00:03
original post 9ef by Anonymous on Mon 18th Jul 2016 00:00
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | $json = ($argv[2] == "json" ? true : false) | |
| 2 | 2 | $output = array(); | |
| 3 | 3 | ||
| 4 | 4 | function iptables($args) { | |
| 5 | 5 | global $json, $output; | |
| 6 | 6 | $descriptorspec = array(1 => array("pipe", "w"), 2 => array("pipe", "w")); | |
| 7 | 7 | $process = proc_open("iptables $args", $descriptorspec, $pipes); | |
| 8 | 8 | if (is_resource($process)) { | |
| 9 | 9 | $stdout = str_replace("\n", "\r\n", stream_get_contents($pipe[1])); | |
| 10 | 10 | $stderr = str_replace("\n", "\r\n", stream_get_contents($pipe[2])); | |
| 11 | 11 | fclose($pipes[1]); | |
| 12 | 12 | fclose($pipes[2]); | |
| 13 | 13 | $returncode = proc_close($process); | |
| 14 | 14 | if ($json) { | |
| 15 | 15 | $output[] = array( | |
| 16 | 16 | "command" => "iptables $args", | |
| 17 | 17 | "returncode" => $returncode, | |
| 18 | 18 | "stdout" => $stdout, | |
| 19 | 19 | "stderr" => $stderr; | |
| 20 | 20 | } else { | |
| 21 | 21 | printf("%s\r\n\tReturn Code: %d\r\n\tOutput:\r\n\t\t%s\r\nErrors:\r\n\t\t%s\r\n\r\n", "iptables $args", $returncode, $stdout, $stderr; | |
| 22 | 22 | } | |
| 23 | 23 | } | |
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | - | echo json_encode($output); | |
| 26 | + | if ($json) echo json_encode($output); |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
kpaste.net RSS