diff options
author | jim-p <jimp@pfsense.org> | 2016-12-28 13:51:08 -0500 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2016-12-28 13:51:08 -0500 |
commit | a4867a30cb184fd63b2025015c3ef67d52977633 (patch) | |
tree | 4b739c923eb23104360accad9b905ec3698a066f /src/etc/inc/gwlb.inc | |
parent | 337822a39bfd89c011cfda4092a6e5e409a7dbcf (diff) | |
download | pfsense-a4867a30cb184fd63b2025015c3ef67d52977633.zip pfsense-a4867a30cb184fd63b2025015c3ef67d52977633.tar.gz |
Add a function to format and return plain text output showing the gateway status, for use by a shell script and status.php. Ticket #7046
Diffstat (limited to 'src/etc/inc/gwlb.inc')
-rw-r--r-- | src/etc/inc/gwlb.inc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc index ab4d53f..b240c12 100644 --- a/src/etc/inc/gwlb.inc +++ b/src/etc/inc/gwlb.inc @@ -470,6 +470,49 @@ function return_gateways_status($byname = false) { return($status); } +function return_gateways_status_text($byname = false, $brief = false) { + $gwstat = return_gateways_status($byname); + $output = ""; + $widths = array(); + $col_sep = 2; + if ($brief) { + $collist = array('status' => "Status"); + } else { + $collist = array('monitorip' => "Monitor", + 'srcip' => "Source", + 'delay' => "Delay", + 'stddev' => "StdDev", + 'loss' => "Loss", + 'status' => "Status"); + } + foreach ($gwstat as $gw) { + foreach ($gw as $gwdidx => $gwdata) { + if (strlen($gwdata) > $widths[$gwdidx]) { + $widths[$gwdidx] = strlen($gwdata); + } + } + } + + $output .= str_pad("Name", $widths['name'] + $col_sep, " ", STR_PAD_RIGHT); + foreach ($collist as $hdrcol => $hdrdesc) { + if (strlen($hdrdesc) > $widths[$hdrcol]) { + $widths[$hdrcol] = strlen($hdrdesc); + } + $output .= str_pad($hdrdesc, $widths[$hdrcol] + $col_sep, " ", (substr($hdrcol, -2, 2) == "ip") ? STR_PAD_RIGHT : STR_PAD_LEFT); + } + $output .= "\n"; + + foreach ($gwstat as $idx => $gw) { + $output .= str_pad($gw['name'], $widths['name'] + $col_sep, " ", STR_PAD_RIGHT); + foreach (array_keys($collist) as $col) { + $output .= str_pad($gw[$col], $widths[$col] + $col_sep, " ", (substr($col, -2, 2) == "ip") ? STR_PAD_RIGHT : STR_PAD_LEFT); + } + $output .= "\n"; + } + + return $output; +} + /* Return all configured gateways on the system */ function return_gateways_array($disabled = false, $localhost = false, $inactive = false) { global $config, $g; |