diff options
author | jim-p <jimp@pfsense.org> | 2016-12-28 13:51:08 -0500 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2017-02-10 12:42:17 -0500 |
commit | 5ab3fb16e8f42dbf981266e0b786537a7029688a (patch) | |
tree | fa7309f969e0e80d27b15cf4ea8916253880895d /src | |
parent | 4cdd0103a05a806c6b48f4b3c6501d487fcb6e62 (diff) | |
download | pfsense-5ab3fb16e8f42dbf981266e0b786537a7029688a.zip pfsense-5ab3fb16e8f42dbf981266e0b786537a7029688a.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')
-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 743fe58..6421170 100644 --- a/src/etc/inc/gwlb.inc +++ b/src/etc/inc/gwlb.inc @@ -506,6 +506,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; |