* Copyright (c) 2004-2005 Jonathan Watt * All rights reserved. * * originally part of m0n0wall (http://m0n0.ch/wall) * Copyright (c) 2003-2004 Manuel Kasper . * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $nocsrf = true; require_once("guiconfig.inc"); require_once("pfsense-utils.inc"); require_once("functions.inc"); require_once("/usr/local/www/widgets/include/interface_statistics.inc"); $ifdescrs = get_configured_interface_with_descr(); $ifstats = array( 'inpkts' => gettext('Packets In'), 'outpkts' => gettext('Packets Out'), 'inbytes' => gettext('Bytes In'), 'outbytes' => gettext('Bytes Out'), 'inerrs' => gettext('Errors In'), 'outerrs' => gettext('Errors Out'), 'collisions' => gettext('Collisions'), ); // Compose the table contents and pass it back to the ajax caller if ($_REQUEST && $_REQUEST['ajax']) { $skipinterfaces = explode(",", $user_settings['widgets'][$_REQUEST['widgetkey']]['iffilter']); $skipifstats = explode(",", $user_settings['widgets'][$_REQUEST['widgetkey']]['ifstatsfilter']); $an_interface_is_selected = false; // decide if at least 1 interface is selected for display $an_interface_is_displayed = false; // decide if at least 1 interface is displayed (i.e. not down) $an_ifstat_is_displayed = false; if (isset($user_settings["widgets"][$_REQUEST['widgetkey']]["orientation_type"])) { $orientation_type = $user_settings["widgets"][$_REQUEST['widgetkey']]["orientation_type"]; } else { $orientation_type = "if_columns"; } $ifstats_arr = array(); // Construct an array of only the selected stats items foreach ($ifstats as $key => $name) { if (!in_array($key, $skipifstats)) { $ifstats_arr[$key] = $name; $an_ifstat_is_displayed = true; } } $ifinfo_arr = array(); // Gather the stats info for the required interfaces foreach ($ifdescrs as $ifdescr => $ifname) { if (in_array($ifdescr, $skipinterfaces)) { continue; } $ifinfo = get_interface_info($ifdescr); $an_interface_is_selected = true; if ($ifinfo_arr[$ifdescr]['status'] != "down") { $ifinfo['inbytes'] = format_bytes($ifinfo['inbytes']); $ifinfo['outbytes'] = format_bytes($ifinfo['outbytes']); $ifinfo['name'] = $ifname; $ifinfo_arr[$ifdescr] = $ifinfo; $an_interface_is_displayed = true; } } print(""); print(""); print(""); if ($orientation_type == "if_columns") { // Put interface names as column headings foreach ($ifinfo_arr as $ifdescr => $ifinfo) { print("" . $ifinfo['name'] . ""); } if (!$an_interface_is_selected) { print("" . gettext('All interfaces are hidden.') . ""); } else if (!$an_interface_is_displayed) { print("" . gettext('All selected interfaces are down.') . ""); } } else { // Put stats item names as column headings foreach ($ifstats_arr as $key => $name) { print("" . $name . ""); } if (!$an_ifstat_is_displayed) { print("" . gettext('All statistics are hidden.') . ""); } } print(""); print(""); print(""); if ($orientation_type == "if_columns") { //Construct the table with stats as rows and interfaces as columns foreach ($ifstats_arr as $key => $name) { print(""); print("" . $name . ""); foreach ($ifinfo_arr as $ifdescr => $ifinfo) { print("" . (isset($ifinfo[$key]) ? htmlspecialchars($ifinfo[$key]) : 'n/a') . ""); } print(""); } if (!$an_ifstat_is_displayed) { print("" . gettext('All statistics are hidden.') . ""); } } else { //Construct the table with interfaces as rows and stats as columns foreach ($ifinfo_arr as $ifdescr => $ifinfo) { print(""); print("" . $ifinfo['name'] . ""); foreach ($ifstats_arr as $key => $name) { print("" . (isset($ifinfo[$key]) ? htmlspecialchars($ifinfo[$key]) : 'n/a') . ""); } print(""); } if (!$an_interface_is_selected) { print("" . gettext('All interfaces are hidden.') . ""); } else if (!$an_interface_is_displayed) { print("" . gettext('All selected interfaces are down.') . ""); } } print( ""); exit; } else if ($_POST['widgetkey']) { set_customwidgettitle($user_settings); if (isset($_POST['orientation_type'])) { $user_settings['widgets'][$_POST['widgetkey']]['orientation_type'] = $_POST['orientation_type']; } $validNames = array(); foreach ($ifdescrs as $ifdescr => $ifname) { array_push($validNames, $ifdescr); } if (is_array($_POST['show'])) { $user_settings['widgets'][$_POST['widgetkey']]['iffilter'] = implode(',', array_diff($validNames, $_POST['show'])); } else { $user_settings['widgets'][$_POST['widgetkey']]['iffilter'] = implode(',', $validNames); } $validStats = array(); foreach ($ifstats as $statkey => $statname) { array_push($validStats, $statkey); } if (is_array($_POST['showifstat'])) { $user_settings['widgets'][$_POST['widgetkey']]['ifstatsfilter'] = implode(',', array_diff($validStats, $_POST['showifstat'])); } else { $user_settings['widgets'][$_POST['widgetkey']]['ifstatsfilter'] = implode(',', $validStats); } save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved Interface Statistics Filter via Dashboard.")); header("Location: /index.php"); } $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; $widgetkey_nodash = str_replace("-", "", $widgetkey); ?>