Commit 708a14bc authored by Ad Schellevis's avatar Ad Schellevis

(legacy) some more refactoring for diag_ping.php

parent 6c0e84cc
...@@ -34,7 +34,7 @@ require_once("interfaces.inc"); ...@@ -34,7 +34,7 @@ require_once("interfaces.inc");
define('MAX_COUNT', 10); define('MAX_COUNT', 10);
define('DEFAULT_COUNT', 3); define('DEFAULT_COUNT', 3);
$cmd_action = false; $cmd_output = false;
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// set form defaults // set form defaults
$pconfig = array(); $pconfig = array();
...@@ -78,7 +78,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -78,7 +78,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$host .= "%{$ifscope}"; $host .= "%{$ifscope}";
} }
} }
// execute ping command and catch both stdout and stderr
$cmd_action = "{$command} {$srcip} -c" . escapeshellarg($pconfig['count']) . " " . escapeshellarg($host); $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"); ?> ...@@ -155,25 +161,14 @@ include("head.inc"); ?>
</div> </div>
</section> </section>
<?php <?php
if ( $cmd_action !== false):?> if ( $cmd_output !== false):?>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="content-box"> <div class="content-box">
<header class="content-box-head container-fluid"> <header class="content-box-head container-fluid">
<h3><?=gettext("Ping output"); ?></h3> <h3><?=gettext("Ping output"); ?></h3>
</header> </header>
<div class="content-box-main col-xs-12"> <div class="content-box-main col-xs-12">
<pre> <pre><?=$cmd_output;?></pre>
<?php
// execute ping command and catch both stdout and stderr
$process = proc_open($cmd_action, array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes);
if (is_resource($process)) {
$result = stream_get_contents($pipes[1]);
$result .= stream_get_contents($pipes[2]);
echo $result;
}
?>
</pre>
</div> </div>
</div> </div>
</section> </section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment