* Copyright (C) 2003-2004 Manuel Kasper * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once('interfaces.inc'); require_once("/usr/local/www/widgets/api/plugins/traffic.inc"); // Get configured interface list $ifdescrs = get_configured_interface_with_descr(); $interfaces = legacy_config_get_interfaces(array('virtual' => false)); $hostlist = array(); if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) { $ifdescrs['enc0'] = "IPsec"; } foreach (array('server', 'client') as $mode) { if (isset($config['openvpn']["openvpn-{$mode}"])) { foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) { if (!isset($setting['disable'])) { $ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']); } } } } //Create array of hostnames from DHCP foreach ($interfaces as $ifname => $ifarr) { foreach (array('dhcpd', 'dhcpdv6') as $dhcp) { if (isset($config[$dhcp][$ifname]['staticmap'])) { foreach($config[$dhcp][$ifname]['staticmap'] as $entry) { if (!empty($entry['hostname'])) { $hostlist[$entry['ipaddr']] = htmlentities($entry['hostname']); } } } } } if ($_SERVER['REQUEST_METHOD'] === 'GET') { // load initial form data $pconfig = array(); $pconfig['if'] = array_keys($ifdescrs)[0]; foreach($ifdescrs as $descr => $ifdescr) { if ($descr == $_GET['if']) { $pconfig['if'] = $descr; break; } } $pconfig['sort'] = !empty($_GET['sort']) ? $_GET['sort'] : ""; $pconfig['filter'] = !empty($_GET['filter']) ? $_GET['filter'] : ""; $pconfig['hostipformat'] = !empty($_GET['hostipformat']) ? $_GET['hostipformat'] : ""; $pconfig['act'] = !empty($_GET['act']) ? $_GET['act'] : ""; if ($pconfig['act'] == "traffic") { // traffic graph data echo json_encode(traffic_api()); exit; } elseif ($pconfig['act'] == 'top') { // top data $result = array(); $real_interface = get_real_interface($pconfig['if']); $intsubnet = find_interface_network($real_interface); if (is_subnetv4($intsubnet)) { $cmd_args = $pconfig['filter'] == "local" ? " -c " . $intsubnet . " " : " -lc 0.0.0.0/0 "; $cmd_args .= $pconfig['sort'] == "out" ? " -T " : " -R "; $cmd_action = "/usr/local/bin/rate -v -i {$real_interface} -nlq 1 -Aba 20 {$cmd_args} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'"; exec($cmd_action, $listedIPs); for ($idx = 2 ; $idx < count($listedIPs) ; ++$idx) { $fields = explode(':', $listedIPs[$idx]); if (!empty($pconfig['hostipformat'])) { $addrdata = gethostbyaddr($fields[0]); if ($pconfig['hostipformat'] == 'hostname' && $addrdata != $fields[0]){ $addrdata = explode(".", $addrdata)[0]; } else if ($pconfig['hostipformat'] == 'hostname' && array_key_exists($fields[0], $hostlist)) { $addrdata = $hostlist[$fields[0]]; } } else { $addrdata = $fields[0]; } $result[] = array('host' => $addrdata, 'in' => $fields[1], 'out' => $fields[2]); } } echo json_encode($result); exit; } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { header(url_safe('Location: /status_graph.php')); exit; } legacy_html_escape_form_data($pconfig); include("head.inc"); ?>