1
|
<?php
|
2
|
/*
|
3
|
$Id$
|
4
|
Copyright 2007 Scott Dale
|
5
|
Part of pfSense widgets (https://www.pfsense.org)
|
6
|
originally based on m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
|
9
|
and Jonathan Watt <jwatt@jwatt.org>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
|
34
|
$nocsrf = true;
|
35
|
|
36
|
require_once("guiconfig.inc");
|
37
|
require_once("pfsense-utils.inc");
|
38
|
require_once("functions.inc");
|
39
|
|
40
|
$first_time = false;
|
41
|
if (!is_array($config["widgets"]["trafficgraphs"])) {
|
42
|
$first_time = true;
|
43
|
$config["widgets"]["trafficgraphs"] = array();
|
44
|
}
|
45
|
$a_config = &$config["widgets"]["trafficgraphs"];
|
46
|
|
47
|
if (!is_array($a_config["shown"])) {
|
48
|
$a_config["shown"] = array();
|
49
|
}
|
50
|
if (!is_array($a_config["shown"]["item"])) {
|
51
|
$a_config["shown"]["item"] = array();
|
52
|
}
|
53
|
|
54
|
$ifdescrs = get_configured_interface_with_descr();
|
55
|
if (isset($config['ipsec']['enable']))
|
56
|
$ifdescrs['enc0'] = "IPsec";
|
57
|
|
58
|
if ($_POST) {
|
59
|
if (isset($_POST["refreshinterval"])) {
|
60
|
$a_config["refreshinterval"] = $_POST["refreshinterval"];
|
61
|
}
|
62
|
if (isset($_POST["scale_type"])) {
|
63
|
$a_config["scale_type"] = $_POST["scale_type"];
|
64
|
}
|
65
|
$a_config["shown"]["item"] = array();
|
66
|
foreach ($ifdescrs as $ifname => $ifdescr) {
|
67
|
$state = $_POST["shown"][$ifname];
|
68
|
if ($state === "show") {
|
69
|
$a_config["shown"]["item"][] = $ifname;
|
70
|
}
|
71
|
}
|
72
|
write_config("Updated traffic graph settings via dashboard.");
|
73
|
header("Location: /");
|
74
|
exit(0);
|
75
|
}
|
76
|
|
77
|
$shown = array();
|
78
|
foreach ($a_config["shown"]["item"] as $if) {
|
79
|
$shown[$if] = true;
|
80
|
}
|
81
|
if ($first_time) {
|
82
|
$keys = array_keys($ifdescrs);
|
83
|
$shown[$keys[0]] = true;
|
84
|
}
|
85
|
|
86
|
if (isset($a_config["refreshinterval"])) {
|
87
|
$refreshinterval = $a_config["refreshinterval"];
|
88
|
} else {
|
89
|
$refreshinterval = 10;
|
90
|
}
|
91
|
|
92
|
if (isset($a_config["scale_type"])) {
|
93
|
$scale_type = $a_config["scale_type"];
|
94
|
} else {
|
95
|
$scale_type = "up";
|
96
|
}
|
97
|
|
98
|
?>
|
99
|
<input type="hidden" id="traffic_graphs-config" name="traffic_graphs-config" value="" />
|
100
|
|
101
|
<?php
|
102
|
//set variables for traffic graph
|
103
|
$width = "100%";
|
104
|
$height = "150";
|
105
|
?>
|
106
|
|
107
|
<div id="traffic_graphs-settings" class="widgetconfigdiv" style="display:none;">
|
108
|
<form action="/widgets/widgets/traffic_graphs.widget.php" method="post" name="iform" id="iform">
|
109
|
<?php foreach ($ifdescrs as $ifname => $ifdescr) { ?>
|
110
|
<input type="hidden" name="shown[<?= $ifname ?>]" value="<?= $shown[$ifname] ? "show" : "hide" ?>" />
|
111
|
<?php } ?>
|
112
|
Default AutoScale:
|
113
|
<?php
|
114
|
$scale_type_up="checked=\"checked\"";
|
115
|
$scale_type_follow="";
|
116
|
if (isset($config["widgets"]["trafficgraphs"]["scale_type"])) {
|
117
|
$selected_radio = $config["widgets"]["trafficgraphs"]["scale_type"];
|
118
|
if ($selected_radio == "up") {
|
119
|
$scale_type_up = "checked=\"checked\"";
|
120
|
}
|
121
|
else if ($selected_radio == "follow") {
|
122
|
$scale_type_follow = "checked=\"checked\"";
|
123
|
}
|
124
|
}
|
125
|
?>
|
126
|
<input name="scale_type_up" class="radio" type="radio" id="scale_type_up" value="up" <?php echo $scale_type_up; ?> onchange="updateGraphDisplays();" /> <span>up</span>
|
127
|
<input name="scale_type_follow" class="radio" type="radio" id="scale_type_follow" value="follow" <?php echo $scale_type_follow; ?> onchange="updateGraphDisplays();" /> <span>follow</span><br /><br />
|
128
|
Refresh Interval:
|
129
|
<select name="refreshinterval" class="formfld" id="refreshinterval" onchange="updateGraphDisplays();">
|
130
|
<?php for ($i = 1; $i <= 10; $i += 1) { ?>
|
131
|
<option value="<?= $i ?>" <?php if ($refreshinterval == $i) echo "selected=\"selected\"";?>><?= $i ?></option>
|
132
|
<?php } ?>
|
133
|
</select> Seconds<br /> <b>Note:</b> changing this setting will increase CPU utilization<br /><br />
|
134
|
<input id="submit_settings" name="submit_settings" type="submit" onclick="return updatePref();" class="formbtn" value="Save Settings" />
|
135
|
</form>
|
136
|
</div>
|
137
|
|
138
|
<script type="text/javascript">
|
139
|
//<![CDATA[
|
140
|
d = document;
|
141
|
selectIntLink = "traffic_graphs-configure";
|
142
|
textlink = d.getElementById(selectIntLink);
|
143
|
textlink.style.display = "inline";
|
144
|
//]]>
|
145
|
</script>
|
146
|
|
147
|
<?php
|
148
|
foreach ($ifdescrs as $ifname => $ifdescr) {
|
149
|
$ifinfo = get_interface_info($ifname);
|
150
|
if ($shown[$ifname]) {
|
151
|
$mingraphbutton = "inline";
|
152
|
$showgraphbutton = "none";
|
153
|
$graphdisplay = "inline";
|
154
|
$interfacevalue = "show";
|
155
|
} else {
|
156
|
$mingraphbutton = "none";
|
157
|
$showgraphbutton = "inline";
|
158
|
$graphdisplay = "none";
|
159
|
$interfacevalue = "hide";
|
160
|
}
|
161
|
if ($ifinfo['status'] != "down") { ?>
|
162
|
<div id="<?=$ifname;?>trafficdiv" style="padding: 5px">
|
163
|
<div id="<?=$ifname;?>topic" class="widgetsubheader">
|
164
|
<div style="float:left;width:49%">
|
165
|
<span onclick="location.href='/status_graph.php?if=<?=$ifname;?>'" style="cursor:pointer">Current <?=$ifdescr;?> Traffic</span>
|
166
|
</div>
|
167
|
<div align="right" style="float:right;width:49%">
|
168
|
<div id="<?=$ifname;?>graphdiv-min" onclick='return trafficminimizeDiv("<?= $ifname ?>", true);'
|
169
|
style="display:<?php echo $mingraphbutton;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_minus.gif" alt="Minimize <?=$ifname;?> traffic graph" /></div>
|
170
|
<div id="<?=$ifname;?>graphdiv-open" onclick='return trafficshowDiv("<?= $ifname ?>", true);'
|
171
|
style="display:<?php echo $showgraphbutton;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_open.gif" alt="Show <?=$ifname;?> traffic graph" /></div>
|
172
|
</div>
|
173
|
<div style="clear:both;"></div>
|
174
|
</div>
|
175
|
<div id="<?=$ifname;?>graphdiv" style="display:<?php echo $graphdisplay;?>">
|
176
|
<object data="graph.php?ifnum=<?=$ifname;?>&ifname=<?=rawurlencode($ifdescr);?>&timeint=<?=$refreshinterval;?>&initdelay=<?=($graphcounter+1) * 2;?>">
|
177
|
<param name="id" value="graph" />
|
178
|
<param name="type" value="image/svg+xml" />
|
179
|
<param name="width" value="<? echo $width; ?>" />
|
180
|
<param name="height" value="<? echo $height; ?>" />
|
181
|
<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
|
182
|
</object>
|
183
|
</div>
|
184
|
</div>
|
185
|
<?php }
|
186
|
}
|
187
|
?>
|