pastebin - collaborative debugging tool
kpaste.net RSS

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

    
11
$json = ($argv[2] == "json" ? true : false)
22
$output = array();
33
44
function iptables($args) {
55
	global $json, $output;
66
	$descriptorspec = array(1 => array("pipe", "w"), 2 => array("pipe", "w"));
77
	$process = proc_open("iptables $args", $descriptorspec, $pipes);
88
	if (is_resource($process)) {
99
		$stdout = str_replace("\n", "\r\n", stream_get_contents($pipe[1]));
1010
		$stderr = str_replace("\n", "\r\n", stream_get_contents($pipe[2]));
1111
		fclose($pipes[1]);
1212
		fclose($pipes[2]);
1313
		$returncode = proc_close($process);
1414
		if ($json) {
1515
			$output[] = array(
1616
				"command" => "iptables $args",
1717
				"returncode" => $returncode,
1818
				"stdout" => $stdout,
1919
				"stderr" => $stderr;
2020
		} else {
2121
			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;
2222
		}
2323
	}
2424
}
2525
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.

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