pastebin - collaborative debugging tool
kpaste.net RSS


Untitled
Posted by Anonymous on Mon 18th Jul 2016 00:03
raw | new post
modification of post by Anonymous (view diff)

  1. $json = ($argv[2] == "json" ? true : false)
  2. $output = array();
  3.  
  4. function iptables($args) {
  5.         global $json, $output;
  6.         $descriptorspec = array(1 => array("pipe", "w"), 2 => array("pipe", "w"));
  7.         $process = proc_open("iptables $args", $descriptorspec, $pipes);
  8.         if (is_resource($process)) {
  9.                 $stdout = str_replace("\n", "\r\n", stream_get_contents($pipe[1]));
  10.                 $stderr = str_replace("\n", "\r\n", stream_get_contents($pipe[2]));
  11.                 fclose($pipes[1]);
  12.                 fclose($pipes[2]);
  13.                 $returncode = proc_close($process);
  14.                 if ($json) {
  15.                         $output[] = array(
  16.                                 "command" => "iptables $args",
  17.                                 "returncode" => $returncode,
  18.                                 "stdout" => $stdout,
  19.                                 "stderr" => $stderr;
  20.                 } else {
  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.                 }
  23.         }
  24. }
  25.  
  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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at