From c7edec885d84206eb438bd903f37ca0a6b8a1890 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 10 May 2016 10:36:26 +0200 Subject: [PATCH] (interfaces -> traffic graph) trash old svg graph and start using d3 --- .../OPNsense/Core/ACL_Legacy_Page_Map.json | 20 +- src/www/graph.php | 373 ------------------ src/www/legacy_traffic_stats.php | 94 ----- src/www/status_graph.php | 62 ++- 4 files changed, 45 insertions(+), 504 deletions(-) delete mode 100644 src/www/graph.php delete mode 100644 src/www/legacy_traffic_stats.php diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/ACL_Legacy_Page_Map.json b/src/opnsense/mvc/app/models/OPNsense/Core/ACL_Legacy_Page_Map.json index d185f5747..e15cb8e2b 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Core/ACL_Legacy_Page_Map.json +++ b/src/opnsense/mvc/app/models/OPNsense/Core/ACL_Legacy_Page_Map.json @@ -51,9 +51,7 @@ "match": [ "index.php*", "*.widget.php*", - "graph.php*", "widgets/api/get.php*", - "legacy_traffic_stats.php*", "diag_logs_filter_dynamic.php*" ] }, @@ -99,13 +97,6 @@ "diag_halt.php*" ] }, - "page-diagnostics-interfacetraffic": { - "name": "WebCfg - Diagnostics: Interface Traffic page", - "descr": "Allow access to the 'Diagnostics: Interface Traffic' page.", - "match": [ - "graph.php*" - ] - }, "page-diagnostics-limiter-info": { "name": "WebCfg - Diagnostics: Limiter Info", "descr": "Allows access to the 'Diagnostics: Limiter Info' page", @@ -957,9 +948,7 @@ "name": "WebCfg - Status: Traffic Graph page", "descr": "Allow access to the 'Status: Traffic Graph' page.", "match": [ - "status_graph.php*", - "graph.php*", - "legacy_traffic_stats.php*" + "status_graph.php*" ] }, "page-service-upnp": { @@ -1251,13 +1240,6 @@ "vpn_openvpn_server.php*" ] }, - "page-xmlrpcinterfacestats": { - "name": "WebCfg - XMLRPC Interface Stats page", - "descr": "Allow access to the 'XMLRPC Interface Stats' page.", - "match": [ - "legacy_traffic_stats.php*" - ] - }, "page-xmlrpclibrary": { "name": "WebCfg - XMLRPC Library page", "descr": "Allow access to the 'XMLRPC Library' page.", diff --git a/src/www/graph.php b/src/www/graph.php deleted file mode 100644 index 200e6330b..000000000 --- a/src/www/graph.php +++ /dev/null @@ -1,373 +0,0 @@ -, Manuel Kasper - and Jonathan Watt . - 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"); - -header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" ); -header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" ); -header("Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 -header("Cache-Control: post-check=0, pre-check=0", FALSE ); -header("Pragma: no-cache"); // HTTP/1.0 -header("Content-type: image/svg+xml"); - -/********** HTTP GET Based Conf ***********/ -$ifnum=@$_GET["ifnum"]; // BSD / SNMP interface name / number -$ifnum = get_real_interface($ifnum); -$ifname=@$_GET["ifname"]?$_GET["ifname"]:"Interface $ifnum"; //Interface name that will be showed on top right of graph - -/********* Other conf *******/ -if (isset($config["widgets"]["trafficgraphs"]["scale_type"])) - $scale_type = $config["widgets"]["trafficgraphs"]["scale_type"]; -else - $scale_type = "up"; - -$nb_plot=120; //NB plot in graph -if ($_GET["timeint"]) - $time_interval = $_GET["timeint"]; //Refresh time Interval -else - $time_interval = 3; - -if ($_GET["initdelay"]) - $init_delay = $_GET["initdelay"]; //Initial Delay -else - $init_delay = 3; - -//SVG attributes -$attribs['axis']='fill="black" stroke="black"'; -$attribs['in']='fill="#f07712" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"'; -$attribs['out']='fill="#333333" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"'; -$attribs['graph_in']='fill="none" stroke="#f07712" stroke-opacity="0.8"'; -$attribs['graph_out']='fill="none" stroke="#333333" stroke-opacity="0.8"'; -$attribs['legend']='fill="black" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"'; -$attribs['graphname']='fill="#f07712" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="8"'; -$attribs['grid_txt']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"'; -$attribs['grid']='stroke="gray" stroke-opacity="0.5"'; -$attribs['switch_unit']='fill="#f07712" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"'; -$attribs['switch_scale']='fill="#f07712" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"'; -$attribs['error']='fill="blue" font-family="Arial" font-size="4"'; -$attribs['collect_initial']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"'; - -//Error text if we cannot fetch data : depends on which method is used -$error_text = sprintf(gettext('Cannot get data about interface %s'), htmlspecialchars($ifnum)); - -$height=100; //SVG internal height : do not modify -$width=200; //SVG internal width : do not modify - -$fetch_link = "legacy_traffic_stats.php?if=" . htmlspecialchars($ifnum); - -/********* Graph DATA **************/ -print('' . "\n");?> - - - - /> - /> - /> - /> - /> - text-anchor="end"> - text-anchor="end"> - text-anchor="end"> - > - > - > - > - text-anchor="end"> - > - > () - > - > - > - points=" "/> - text-anchor="middle"> - text-anchor="middle">... - - - diff --git a/src/www/legacy_traffic_stats.php b/src/www/legacy_traffic_stats.php deleted file mode 100644 index 6130187d8..000000000 --- a/src/www/legacy_traffic_stats.php +++ /dev/null @@ -1,94 +0,0 @@ - - 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('pfsense-utils.inc'); - -//get interface IP and break up into an array -$real_interface = get_real_interface($_GET['if']); -if (!does_interface_exist($real_interface)) { - echo gettext("Wrong Interface"); - exit; -} elseif (!empty($_GET['act']) && $_GET['act'] == "top") { - // - // find top bandwitdh users - // (parts copied from bandwidth_by_ip.php) - // - - //get interface subnet - $netmask = find_interface_subnet($real_interface); - $intsubnet = gen_subnet(find_interface_ip($real_interface), $netmask) . "/$netmask"; - $cmd_args = ""; - switch (!empty($_GET['filter']) ? $_GET['filter'] : "") { - case "local": - $cmd_args .= " -c " . $intsubnet . " "; - break; - case "remote": - default: - $cmd_args .= " -lc 0.0.0.0/0 "; - break; - } - if (!empty($_GET['sort']) && $_GET['sort'] == "out") { - $cmd_args .= " -T "; - } else { - $cmd_args .= " -R "; - } - - $listedIPs = array(); - $cmd_action = "/usr/local/bin/rate -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); - - $result = array(); - for ($idx = 2 ; $idx < count($listedIPs) ; ++$idx) { - $fields = explode(':', $listedIPs[$idx]); - if (!empty($_GET['hostipformat'])) { - $addrdata = gethostbyaddr($fields[0]); - if ($_GET['hostipformat'] == 'hostname' && $addrdata != $fields[0]){ - $addrdata = explode(".", $addrdata)[0]; - } - } else { - $addrdata = $fields[0]; - } - $result[] = array('host' => $addrdata, 'in' => $fields[1], 'out' => $fields[2]); - } - // return json traffic - echo json_encode($result); -} else { - // collect interface statistics - // original source ifstats.php - $ifinfo = legacy_interface_stats($real_interface); - $temp = gettimeofday(); - $timing = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0; - echo "$timing|" . $ifinfo['bytes received'] . "|" . $ifinfo['bytes transmitted'] . "\n"; -} - - -exit; diff --git a/src/www/status_graph.php b/src/www/status_graph.php index c786e7469..67cf27f0f 100644 --- a/src/www/status_graph.php +++ b/src/www/status_graph.php @@ -29,6 +29,8 @@ */ 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(); @@ -45,7 +47,6 @@ foreach (array('server', 'client') as $mode) { } } - if ($_SERVER['REQUEST_METHOD'] === 'GET') { // load initial form data $pconfig = array(); @@ -59,6 +60,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $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']); + if (does_interface_exist($real_interface)) { + $netmask = find_interface_subnet($real_interface); + $intsubnet = gen_subnet(find_interface_ip($real_interface), $netmask) . "/$netmask"; + $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 -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 { + $addrdata = $fields[0]; + } + $result[] = array('host' => $addrdata, 'in' => $fields[1], 'out' => $fields[2]); + } + } + echo json_encode($result); + } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { header("Location: status_graph.php"); exit; @@ -74,6 +106,9 @@ include("head.inc"); @@ -121,7 +157,7 @@ include("head.inc"); - $ifd):?> @@ -142,7 +178,7 @@ include("head.inc"); - @@ -152,7 +188,7 @@ include("head.inc"); -