From 626db846052d79c8c154cc6f97f0ad4171bf1e13 Mon Sep 17 00:00:00 2001 From: Stephen Beaver Date: Wed, 18 Nov 2015 13:15:07 -0500 Subject: Fixed #5475 --- .../local/www/widgets/widgets/gateways.widget.php | 250 ++++++++++++--------- 1 file changed, 145 insertions(+), 105 deletions(-) (limited to 'src/usr/local') diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php index 7d306a9..46cb105 100644 --- a/src/usr/local/www/widgets/widgets/gateways.widget.php +++ b/src/usr/local/www/widgets/widgets/gateways.widget.php @@ -64,6 +64,122 @@ require_once("pfsense-utils.inc"); require_once("functions.inc"); require_once("/usr/local/www/widgets/include/gateways.inc"); +$a_gateways = return_gateways_array(); +$gateways_status = array(); +$gateways_status = return_gateways_status(true); + +// Compose the table contents and pass it back to the ajax caller +if($_REQUEST && $_REQUEST['ajax']) { + global $a_gateways, $gateways_status; + + print("\n"); + print( "\n"); + print( "" . gettext("Name") . "\n"); + print( "RTT\n"); + print( "" . gettext("Loss") . "\n"); + print( "" . gettext("Status") . "\n"); + print( "\n"); + print("\n"); + print("\n"); + + foreach ($a_gateways as $gname => $gateway) { + print("\n"); + print( "\n"); + + $if_gw = ''; + if (is_ipaddr($gateway['gateway'])) + $if_gw = $gateway['gateway']; + else { + if($gateway['ipprotocol'] == "inet") + $if_gw = get_interface_gateway($gateway['friendlyiface']); + if($gateway['ipprotocol'] == "inet6") + $if_gw = get_interface_gateway_v6($gateway['friendlyiface']); + } + + print(htmlspecialchars($gateway['name']) . "
"); + + print('
'); + + $monitor_address = ""; + $monitor_address_disp = ""; + if ($display_type == "monitor_ip" || $display_type == "both_ip") { + $monitor_address = $gateway['monitor']; + if ($monitor_address != "" && $display_type == "both_ip") { + $monitor_address_disp = " (" . $monitor_address . ")"; + } else { + $monitor_address_disp = $monitor_address; + } + } + + $if_gw = ''; + // If the user asked to display Gateway IP or both IPs, or asked for just monitor IP but the monitor IP is blank + // then find the gateway IP (which is also the monitor IP if the monitor IP was not explicitly set). + if ($display_type == "gw_ip" || $display_type == "both_ip" || ($display_type == "monitor_ip" && $monitor_address == "")) { + if (is_ipaddr($gateway['gateway'])) { + $if_gw = htmlspecialchars($gateway['gateway']); + } else { + if ($gateway['ipprotocol'] == "inet") { + $if_gw = htmlspecialchars(get_interface_gateway($gateway['friendlyiface'])); + } + if ($gateway['ipprotocol'] == "inet6") { + $if_gw = htmlspecialchars(get_interface_gateway_v6($gateway['friendlyiface'])); + } + } + if ($if_gw == "") { + $if_gw = "~"; + } + } + + if ($monitor_address == $if_gw) { + $monitor_address_disp = ""; + } + + print($if_gw . $monitor_address_disp); + unset ($if_gw); + unset ($monitor_address); + unset ($monitor_address_disp); + $counter++; + + print( ""); + print( "
\n"); + print( "\n"); + + if ($gateways_status[$gname]) { + if (stristr($gateways_status[$gname]['status'], "force_down")) { + $online = "Offline (forced)"; + $bgcolor = "#F08080"; // lightcoral + } elseif (stristr($gateways_status[$gname]['status'], "down")) { + $online = "Offline"; + $bgcolor = "#F08080"; // lightcoral + } elseif (stristr($gateways_status[$gname]['status'], "loss")) { + $online = "Packetloss"; + $bgcolor = "#F0E68C"; // khaki + } elseif (stristr($gateways_status[$gname]['status'], "delay")) { + $online = "Latency"; + $bgcolor = "#F0E68C"; // khaki + } elseif ($gateways_status[$gname]['status'] == "none") { + $online = "Online"; + $bgcolor = "#90EE90"; // lightgreen + } elseif ($gateways_status[$gname]['status'] == "") { + $online = "Pending"; + $bgcolor = "#D3D3D3"; // lightgray + } + } else { + $online = gettext("Unknown"); + $bgcolor = "#ADD8E6"; // lightblue + } + + print( "" . ($gateways_status[$gname] ? htmlspecialchars($gateways_status[$gname]['delay']) : gettext("Pending")) . "\n"); + print( "" . ($gateways_status[$gname] ? htmlspecialchars($gateways_status[$gname]['loss']) : gettext("Pending")) . "\n"); + print('' . $online . "\n"); + print("\n"); + } + + print("\n"); + + exit; +} + if ($_POST) { if (!is_array($config["widgets"]["gateways_widget"])) { $config["widgets"]["gateways_widget"] = array(); @@ -81,118 +197,42 @@ if (isset($config["widgets"]["gateways_widget"]["display_type"])) { } else { $display_type = "gw_ip"; } - -$a_gateways = return_gateways_array(); -$gateways_status = array(); -$gateways_status = return_gateways_status(true); - ?> - - - - - - - $gateway): ?> - - - - - - - - - +
Name - RTT - Loss - Status -
- -
- -
- - -
-
+
+ +