Project

General

Profile

Download (10.4 KB) Statistics
| Branch: | Tag: | Revision:
1 9573d170 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	status_graph.php
5 6ad24605 Scott Ullrich
	Part of pfSense
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8 9573d170 Scott Ullrich
9 6ad24605 Scott Ullrich
	Originally part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 9573d170 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 9573d170 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 9573d170 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 9573d170 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 1d333258 Scott Ullrich
/*	
35
	pfSense_MODULE:	routing
36
*/
37 5b237745 Scott Ullrich
38 6b07c15a Matthew Grooms
##|+PRIV
39
##|*IDENT=page-status-trafficgraph
40
##|*NAME=Status: Traffic Graph page
41
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
42
##|*MATCH=status_graph.php*
43 8e95a671 jim-p
##|*MATCH=bandwidth_by_ip.php*
44 6b07c15a Matthew Grooms
##|-PRIV
45
46 5b237745 Scott Ullrich
require("guiconfig.inc");
47
48 9573d170 Scott Ullrich
if ($_POST['width'])
49
	$width = $_POST['width'];
50
else
51 f0a3b883 Scott Ullrich
	$width = "100%";
52 9573d170 Scott Ullrich
53 dd521ae8 Scott Ullrich
if ($_POST['height'])
54 9573d170 Scott Ullrich
	$height = $_POST['height'];
55
else
56 f0a3b883 Scott Ullrich
	$height = "200";
57 9573d170 Scott Ullrich
58 94556105 Scott Ullrich
// Get configured interface list
59 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
60 9f5d14ce jim-p
if (isset($config['ipsec']['enable']))
61
	$ifdescrs['enc0'] = "IPsec";
62
foreach (array('server', 'client') as $mode) {
63
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
64
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
65
			if (!isset($setting['disable'])) {
66
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
67
			}
68
		}
69
	}
70
}
71 43a0ac8a Scott Ullrich
72 50b2f6ab Scott Ullrich
if ($_GET['if']) {
73 5b237745 Scott Ullrich
	$curif = $_GET['if'];
74 50b2f6ab Scott Ullrich
	$found = false;
75
	foreach($ifdescrs as $descr => $ifdescr) 
76
		if($descr == $curif) $found = true;
77
	if(!$found) {
78
		Header("Location: status_graph.php");
79
		exit;
80
	}
81
} else {
82 76165eac Phil Davis
	if (empty($ifdescrs["wan"])) {
83
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
84
		reset($ifdescrs);
85
		$curif = key($ifdescrs);
86
	}
87
	else {
88
		$curif = "wan";
89
	}
90 50b2f6ab Scott Ullrich
}
91 893fb622 Michele Di Maria
if ($_GET['sort']) {
92
	$cursort = $_GET['sort'];
93
} else {
94
	$cursort = "";
95
}
96 769cdf3b Bill Marquette
97 d0033721 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
98 f0a3b883 Scott Ullrich
99 4df96eff Scott Ullrich
include("head.inc");
100
101 5b237745 Scott Ullrich
?>
102
103
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
104 f0a3b883 Scott Ullrich
105
<script language="javascript" type="text/javascript">
106
107
function updateBandwidth(){
108 50b2f6ab Scott Ullrich
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
109 893fb622 Michele Di Maria
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
110
    bandwidthAjax(hostinterface, sorting);
111 f0a3b883 Scott Ullrich
}
112
113 893fb622 Michele Di Maria
function bandwidthAjax(hostinterface, sorting) {
114
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting;
115 f0a3b883 Scott Ullrich
	var opt = {
116
	    // Use GET
117 e03ef9a0 Vinicius Coque
	    type: 'get',
118
	    error: function(req) {
119
	        // Handle 404
120
	        if(req.status == 404)
121
	            alert('Error 404: location "' + uri + '" was not found.');
122
	        // Handle other errors
123
	        else
124
	            alert('Error ' + req.status + ' -- ' + req.statusText);
125 f0a3b883 Scott Ullrich
	    },
126 e03ef9a0 Vinicius Coque
		success: function(data) {
127
			updateBandwidthHosts(data);
128 f0a3b883 Scott Ullrich
	    }
129
	}
130 e03ef9a0 Vinicius Coque
	jQuery.ajax(uri, opt);
131 f0a3b883 Scott Ullrich
}
132
133
function updateBandwidthHosts(data){
134
    var hosts_split = data.split("|");
135
    d = document;
136
    //parse top ten bandwidth abuser hosts
137
    for (var y=0; y<10; y++){
138
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
139
            if (hosts_split[y]) {
140
                hostinfo = hosts_split[y].split(";");
141
142
                //update host ip info
143
                var HostIpID = "hostip" + y;
144
                var hostip = d.getElementById(HostIpID);
145
                hostip.innerHTML = hostinfo[0];
146
147
                //update bandwidth inbound to host
148
                var hostbandwidthInID = "bandwidthin" + y;
149
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
150 e774e3b3 Ermal
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
151 f0a3b883 Scott Ullrich
152
                //update bandwidth outbound from host
153
                var hostbandwidthOutID = "bandwidthout" + y;
154
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
155 e774e3b3 Ermal
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
156 f0a3b883 Scott Ullrich
157
                //make the row appear if hidden
158 e03ef9a0 Vinicius Coque
                var rowid = "#host" + y;
159 7f8f5d01 Phil Davis
                if (jQuery(rowid).css('display') == "none"){
160 f0a3b883 Scott Ullrich
                     //hide rows that contain no data
161 e03ef9a0 Vinicius Coque
                     jQuery(rowid).show(1000);
162 f0a3b883 Scott Ullrich
                }
163
            }
164
        }
165
        else
166
        {
167 e03ef9a0 Vinicius Coque
            var rowid = "#host" + y;
168 7f8f5d01 Phil Davis
            if (jQuery(rowid).css('display') != "none"){
169 f0a3b883 Scott Ullrich
                //hide rows that contain no data
170 e03ef9a0 Vinicius Coque
                jQuery(rowid).fadeOut(2000);
171 f0a3b883 Scott Ullrich
            }
172
        }
173
    }
174
    
175 e6dd418d sullrich
    setTimeout('updateBandwidth()', 1000);
176 f0a3b883 Scott Ullrich
}
177
178
179
</script>
180
181 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
182
<?php
183 9573d170 Scott Ullrich
184 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
185 c6dfd289 jim-p
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
186 872ce0dd Ermal Luçi
	$ifdescrs['enc0'] = "IPsec";
187 c1abd446 Seth Mos
188 5b237745 Scott Ullrich
?>
189 60f9e276 Bill Marquette
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
190 59bb015e Carlos Eduardo Ramos
<?=gettext("Interface"); ?>:
191 b5c78501 Seth Mos
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
192 5b237745 Scott Ullrich
<?php
193
foreach ($ifdescrs as $ifn => $ifd) {
194
	echo "<option value=\"$ifn\"";
195
	if ($ifn == $curif) echo " selected";
196 82bf9411 Scott Ullrich
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
197 5b237745 Scott Ullrich
}
198
?>
199
</select>
200 893fb622 Michele Di Maria
, Sort by: 
201
<select name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
202
	<option value="">Bandwidth In</option>
203
	<option value="out"<?php if ($cursort == "out") echo " selected";?>>Bandwidth Out</option>
204
</select>
205 5b237745 Scott Ullrich
</form>
206 570cdbcf Bill Marquette
<p><form method="post" action="status_graph.php">
207 8ab3e9ed Erik Kristensen
</form>
208 da07227e Scott Ullrich
<p>
209 e57c91a2 Renato Botelho
<div id="niftyOutter">
210
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
211 c58715af Erik Fonnesbeck
        <embed src="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" type="image/svg+xml" width="<?=$width;?>" height="<?=$height;?>" pluginspage="http://www.adobe.com/svg/viewer/install/auto" />
212 f0a3b883 Scott Ullrich
    </div>
213 e57c91a2 Renato Botelho
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
214 f0a3b883 Scott Ullrich
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
215
            <tr>
216 d0033721 Carlos Eduardo Ramos
                <td class="listtopic" valign="top"><?=gettext("Host IP"); ?></td>
217
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
218
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
219 f0a3b883 Scott Ullrich
           </tr>
220
           <tr id="host0" style="display:none">
221
                <td id="hostip0" class="vncell">
222
                </td>
223
                <td id="bandwidthin0" class="listr">
224
                </td>
225
                <td id="bandwidthout0" class="listr">
226
                </td>
227
           </tr>
228
           <tr id="host1" style="display:none">
229
                <td id="hostip1" class="vncell">
230
                </td>
231
                <td id="bandwidthin1" class="listr">
232
                </td>
233
                <td id="bandwidthout1" class="listr">
234
                </td>
235
           </tr>
236
           <tr id="host2" style="display:none">
237
                <td id="hostip2" class="vncell">
238
                </td>
239
                <td id="bandwidthin2" class="listr">
240
                </td>
241
                <td id="bandwidthout2" class="listr">
242
                </td>
243
           </tr>
244
           <tr id="host3" style="display:none">
245
                <td id="hostip3" class="vncell">
246
                </td>
247
                <td id="bandwidthin3" class="listr">
248
                </td>
249
                <td id="bandwidthout3" class="listr">
250
                </td>
251
           </tr>
252
           <tr id="host4" style="display:none">
253
                <td id="hostip4" class="vncell">
254
                </td>
255
                <td id="bandwidthin4" class="listr">
256
                </td>
257
                <td id="bandwidthout4" class="listr">
258
                </td>
259
           </tr>
260
           <tr id="host5" style="display:none">
261
                <td id="hostip5" class="vncell">
262
                </td>
263
                <td id="bandwidthin5" class="listr">
264
                </td>
265
                <td id="bandwidthout5" class="listr">
266
                </td>
267
           </tr>
268
           <tr id="host6" style="display:none">
269
                <td id="hostip6" class="vncell">
270
                </td>
271
                <td id="bandwidthin6" class="listr">
272
                </td>
273
                <td id="bandwidthout6" class="listr">
274
                </td>
275
           </tr>
276
           <tr id="host7" style="display:none">
277
                <td id="hostip7" class="vncell">
278
                </td>
279
                <td id="bandwidthin7" class="listr">
280
                </td>
281
                <td id="bandwidthout7" class="listr">
282
                </td>
283
           </tr>
284
           <tr id="host8" style="display:none">
285
                <td id="hostip8" class="vncell">
286
                </td>
287
                <td id="bandwidthin8" class="listr">
288
                </td>
289
                <td id="bandwidthout8" class="listr">
290
                </td>
291
           </tr>
292
           <tr id="host9" style="display:none">
293
                <td id="hostip9" class="vncell">
294
                </td>
295
                <td id="bandwidthin9" class="listr">
296
                </td>
297
                <td id="bandwidthout9" class="listr">
298
                </td>
299
           </tr>
300
        </table>
301 e57c91a2 Renato Botelho
	</div>
302
	<div style="clear: both;"></div>
303 8ab3e9ed Erik Kristensen
</div>
304 e5fee340 Scott Ullrich
<p><span class="red"><strong><?=gettext("Note"); ?>:</strong></span> <?=gettext("the"); ?> <a href="http://www.adobe.com/svg/viewer/install/" target="_blank"><?=gettext("Adobe SVG Viewer"); ?></a>, <?=gettext("Firefox 1.5 or later or other browser supporting SVG is required to view the graph"); ?>.
305 8ab3e9ed Erik Kristensen
306 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
307 f0a3b883 Scott Ullrich
308
<script type="text/javascript">
309
window.onload = function(in_event)
310
	{
311
        updateBandwidth();
312
    }
313
314
</script>
315 5b237745 Scott Ullrich
</body>
316
</html>