From 708a14bc1d7ed4d2ca0a5e940f71f593ae98832c Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 6 Jan 2016 17:47:58 +0100 Subject: [PATCH] (legacy) some more refactoring for diag_ping.php --- src/www/diag_ping.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/www/diag_ping.php b/src/www/diag_ping.php index 605d41d00..4e8a904e6 100644 --- a/src/www/diag_ping.php +++ b/src/www/diag_ping.php @@ -34,7 +34,7 @@ require_once("interfaces.inc"); define('MAX_COUNT', 10); define('DEFAULT_COUNT', 3); -$cmd_action = false; +$cmd_output = false; if ($_SERVER['REQUEST_METHOD'] === 'GET') { // set form defaults $pconfig = array(); @@ -78,7 +78,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $host .= "%{$ifscope}"; } } + // execute ping command and catch both stdout and stderr $cmd_action = "{$command} {$srcip} -c" . escapeshellarg($pconfig['count']) . " " . escapeshellarg($host); + $process = proc_open($cmd_action, array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes); + if (is_resource($process)) { + $cmd_output = stream_get_contents($pipes[1]); + $cmd_output .= stream_get_contents($pipes[2]); + } } } @@ -155,25 +161,14 @@ include("head.inc"); ?> + if ( $cmd_output !== false):?>

-
-
-
-            
+