diff options
Diffstat (limited to 'src/usr/local/www/widgets/widgets/traffic_graphs.widget.php')
-rw-r--r-- | src/usr/local/www/widgets/widgets/traffic_graphs.widget.php | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php b/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php new file mode 100644 index 0000000..c5f6286 --- /dev/null +++ b/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php @@ -0,0 +1,193 @@ +<?php +/* + traffic_graphs.widget.php + Copyright (C) 2013-2015 Electric Sheep Fencing, LP + + Copyright 2007 Scott Dale + Part of pfSense widgets (https://www.pfsense.org) + originally based on m0n0wall (http://m0n0.ch/wall) + + Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net> + and Jonathan Watt <jwatt@jwatt.org>. + 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. +*/ + +$nocsrf = true; + +require_once("guiconfig.inc"); +require_once("pfsense-utils.inc"); +require_once("functions.inc"); + +$first_time = false; +if (!is_array($config["widgets"]["trafficgraphs"])) { + $first_time = true; + $config["widgets"]["trafficgraphs"] = array(); +} +$a_config = &$config["widgets"]["trafficgraphs"]; + +if (!is_array($a_config["shown"])) { + $a_config["shown"] = array(); +} +if (!is_array($a_config["shown"]["item"])) { + $a_config["shown"]["item"] = array(); +} + +$ifdescrs = get_configured_interface_with_descr(); +if (isset($config['ipsec']['enable'])) { + $ifdescrs['enc0'] = "IPsec"; +} + +if ($_POST) { + if (isset($_POST["refreshinterval"])) { + $a_config["refreshinterval"] = $_POST["refreshinterval"]; + } + if (isset($_POST["scale_type"])) { + $a_config["scale_type"] = $_POST["scale_type"]; + } + $a_config["shown"]["item"] = array(); + foreach ($ifdescrs as $ifname => $ifdescr) { + $state = $_POST["shown"][$ifname]; + if ($state === "show") { + $a_config["shown"]["item"][] = $ifname; + } + } + write_config("Updated traffic graph settings via dashboard."); + header("Location: /"); + exit(0); +} + +$shown = array(); +foreach ($a_config["shown"]["item"] as $if) { + $shown[$if] = true; +} +if ($first_time) { + $keys = array_keys($ifdescrs); + $shown[$keys[0]] = true; +} + +if (isset($a_config["refreshinterval"])) { + $refreshinterval = $a_config["refreshinterval"]; +} else { + $refreshinterval = 10; +} + +if (isset($a_config["scale_type"])) { + $scale_type = $a_config["scale_type"]; +} else { + $scale_type = "up"; +} + +?> +<input type="hidden" id="traffic_graphs-config" name="traffic_graphs-config" value="" /> + +<div id="traffic_graphs-settings" class="widgetconfigdiv" style="display:none;"> +<form action="/widgets/widgets/traffic_graphs.widget.php" method="post" name="traffic_graphs_widget_iform" id="traffic_graphs_widget_iform"> + <?php foreach ($ifdescrs as $ifname => $ifdescr) { ?> + <input type="hidden" name="shown[<?= $ifname ?>]" value="<?= $shown[$ifname] ? "show" : "hide" ?>" /> + <?php } ?> + Default AutoScale: + <?php + $scale_type_up="checked=\"checked\""; + $scale_type_follow=""; + if (isset($config["widgets"]["trafficgraphs"]["scale_type"])) { + $selected_radio = $config["widgets"]["trafficgraphs"]["scale_type"]; + if ($selected_radio == "up") { + $scale_type_up = "checked=\"checked\""; + $scale_type_follow=""; + } else if ($selected_radio == "follow") { + $scale_type_up=""; + $scale_type_follow = "checked=\"checked\""; + } + } + ?> + <input name="scale_type" class="radio" type="radio" id="scale_type_up" value="up" <?php echo $scale_type_up; ?> onchange="updateGraphDisplays();" /> <span>up</span> + <input name="scale_type" class="radio" type="radio" id="scale_type_follow" value="follow" <?php echo $scale_type_follow; ?> onchange="updateGraphDisplays();" /> <span>follow</span><br /><br /> + Refresh Interval: + <select name="refreshinterval" class="formfld" id="refreshinterval" onchange="updateGraphDisplays();"> + <?php for ($i = 1; $i <= 10; $i += 1) { ?> + <option value="<?= $i ?>" <?php if ($refreshinterval == $i) echo "selected=\"selected\"";?>><?= $i ?></option> + <?php } ?> + </select> Seconds<br /> <b>Note:</b> changing this setting will increase CPU utilization<br /><br /> + <input id="traffic_graphs_widget_submit" name="traffic_graphs_widget_submit" type="submit" onclick="return updatePref();" class="formbtn" value="Save Settings" /> +</form> +</div> + +<script type="text/javascript"> +//<![CDATA[ + d = document; + selectIntLink = "traffic_graphs-configure"; + textlink = d.getElementById(selectIntLink); + textlink.style.display = "inline"; +//]]> +</script> + +<?php +$graphcounter = 0; +foreach ($ifdescrs as $ifname => $ifdescr) { + $ifinfo = get_interface_info($ifname); + if ($shown[$ifname]) { + $mingraphbutton = "inline"; + $showgraphbutton = "none"; + $graphdisplay = "inline"; + $interfacevalue = "show"; + $graphcounter++; + } else { + $mingraphbutton = "none"; + $showgraphbutton = "inline"; + $graphdisplay = "none"; + $interfacevalue = "hide"; + } + if ($ifinfo['status'] != "down") { ?> + <div id="<?=$ifname;?>trafficdiv" style="padding: 5px"> + <div id="<?=$ifname;?>topic" class="widgetsubheader"> + <div style="float:left;width:49%"> + <span onclick="location.href='/status_graph.php?if=<?=$ifname;?>'" style="cursor:pointer">Current <?=$ifdescr;?> Traffic</span> + </div> + <div align="right" style="float:right;width:49%"> + <div id="<?=$ifname;?>graphdiv-min" onclick='return trafficminimizeDiv("<?= $ifname ?>", true);' + style="display:<?php echo $mingraphbutton;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_minus.gif" alt="Minimize <?=$ifname;?> traffic graph" /></div> + <div id="<?=$ifname;?>graphdiv-open" onclick='return trafficshowDiv("<?= $ifname ?>", "<?= rawurlencode($ifdescr); ?>", "<?= $refreshinterval ?>", true);' + style="display:<?php echo $showgraphbutton;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_open.gif" alt="Show <?=$ifname;?> traffic graph" /></div> + </div> + <div style="clear:both;"></div> + </div> + <div id="<?=$ifname;?>graphdiv" style="display:<?php echo $graphdisplay;?>"> +<?php + // If the graph is already enabled by the config then put the object inside the div now. + // Otherwise the graph object is inserted by trafficshowDiv JS when the user opens it. + if ($graphdisplay == "inline") { +?> + <object data="graph.php?ifnum=<?=$ifname;?>&ifname=<?=rawurlencode($ifdescr);?>&timeint=<?=$refreshinterval;?>&initdelay=<?=$graphcounter * 2;?>" height="100%" width="100%"> + <param name="id" value="graph" /> + <param name="type" value="image/svg+xml" /> + <param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" /> + </object> +<?php + } +?> + </div> + </div> + <?php } +} +?> |