Project

General

Profile

Download (10.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_graph.php
5
	Part of pfSense
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8

    
9
	Originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	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

    
23
	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
/*	
35
	pfSense_MODULE:	routing
36
*/
37

    
38
##|+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
##|*MATCH=bandwidth_by_ip.php*
44
##|-PRIV
45

    
46
require("guiconfig.inc");
47

    
48
if ($_POST['width'])
49
	$width = $_POST['width'];
50
else
51
	$width = "100%";
52

    
53
if ($_POST['height'])
54
	$height = $_POST['height'];
55
else
56
	$height = "200";
57

    
58
// Get configured interface list
59
$ifdescrs = get_configured_interface_with_descr();
60
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

    
72
if ($_GET['if']) {
73
	$curif = $_GET['if'];
74
	$found = false;
75
	foreach($ifdescrs as $descr => $ifdescr) {
76
		if ($descr == $curif) {
77
			$found = true;
78
			break;
79
		}
80
	}
81
	if ($found === false) {
82
		Header("Location: status_graph.php");
83
		exit;
84
	}
85
} else {
86
	if (empty($ifdescrs["wan"])) {
87
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
88
		reset($ifdescrs);
89
		$curif = key($ifdescrs);
90
	}
91
	else {
92
		$curif = "wan";
93
	}
94
}
95
if ($_GET['sort']) {
96
	$cursort = $_GET['sort'];
97
} else {
98
	$cursort = "";
99
}
100

    
101
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
102

    
103
include("head.inc");
104

    
105
?>
106

    
107
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
108

    
109
<script language="javascript" type="text/javascript">
110

    
111
function updateBandwidth(){
112
    var hostinterface = jQuery("#if").val();
113
	var sorting = jQuery("#sort").val();
114
    bandwidthAjax(hostinterface, sorting);
115
}
116

    
117
function bandwidthAjax(hostinterface, sorting) {
118
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting;
119
	var opt = {
120
	    // Use GET
121
	    type: 'get',
122
	    error: function(req) {
123
	        /* XXX: Leave this for debugging purposes: Handle 404
124
	        if(req.status == 404)
125
	            alert('Error 404: location "' + uri + '" was not found.');
126
		*/
127
	        /* Handle other errors
128
	        else
129
	            alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
130
		*/
131
	    },
132
		success: function(data) {
133
			updateBandwidthHosts(data);
134
	    }
135
	}
136
	jQuery.ajax(uri, opt);
137
}
138

    
139
function updateBandwidthHosts(data){
140
    var hosts_split = data.split("|");
141
    d = document;
142
    //parse top ten bandwidth abuser hosts
143
    for (var y=0; y<10; y++){
144
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
145
            if (hosts_split[y]) {
146
                hostinfo = hosts_split[y].split(";");
147

    
148
                //update host ip info
149
                var HostIpID = "hostip" + y;
150
                var hostip = d.getElementById(HostIpID);
151
                hostip.innerHTML = hostinfo[0];
152

    
153
                //update bandwidth inbound to host
154
                var hostbandwidthInID = "bandwidthin" + y;
155
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
156
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
157

    
158
                //update bandwidth outbound from host
159
                var hostbandwidthOutID = "bandwidthout" + y;
160
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
161
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
162

    
163
                //make the row appear if hidden
164
                var rowid = "#host" + y;
165
                if (jQuery(rowid).css('display') == "none"){
166
                     //hide rows that contain no data
167
                     jQuery(rowid).show(1000);
168
                }
169
            }
170
        }
171
        else
172
        {
173
            var rowid = "#host" + y;
174
            if (jQuery(rowid).css('display') != "none"){
175
                //hide rows that contain no data
176
                jQuery(rowid).fadeOut(2000);
177
            }
178
        }
179
    }
180
    
181
    setTimeout('updateBandwidth()', 1000);
182
}
183

    
184

    
185
</script>
186

    
187
<?php include("fbegin.inc"); ?>
188
<?php
189

    
190
/* link the ipsec interface magically */
191
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
192
	$ifdescrs['enc0'] = "IPsec";
193

    
194
?>
195
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
196
<?=gettext("Interface"); ?>:
197
<select id="if" name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
198
<?php
199
foreach ($ifdescrs as $ifn => $ifd) {
200
	echo "<option value=\"$ifn\"";
201
	if ($ifn == $curif) echo " selected";
202
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
203
}
204
?>
205
</select>
206
, Sort by: 
207
<select id="sort" name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
208
	<option value="">Bandwidth In</option>
209
	<option value="out"<?php if ($cursort == "out") echo " selected";?>>Bandwidth Out</option>
210
</select>
211
</form>
212
<p>
213
<div id="niftyOutter">
214
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
215
        <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" />
216
    </div>
217
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
218
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
219
            <tr>
220
                <td class="listtopic" valign="top"><?=gettext("Host IP"); ?></td>
221
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
222
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
223
           </tr>
224
           <tr id="host0" style="display:none">
225
                <td id="hostip0" class="vncell">
226
                </td>
227
                <td id="bandwidthin0" class="listr">
228
                </td>
229
                <td id="bandwidthout0" class="listr">
230
                </td>
231
           </tr>
232
           <tr id="host1" style="display:none">
233
                <td id="hostip1" class="vncell">
234
                </td>
235
                <td id="bandwidthin1" class="listr">
236
                </td>
237
                <td id="bandwidthout1" class="listr">
238
                </td>
239
           </tr>
240
           <tr id="host2" style="display:none">
241
                <td id="hostip2" class="vncell">
242
                </td>
243
                <td id="bandwidthin2" class="listr">
244
                </td>
245
                <td id="bandwidthout2" class="listr">
246
                </td>
247
           </tr>
248
           <tr id="host3" style="display:none">
249
                <td id="hostip3" class="vncell">
250
                </td>
251
                <td id="bandwidthin3" class="listr">
252
                </td>
253
                <td id="bandwidthout3" class="listr">
254
                </td>
255
           </tr>
256
           <tr id="host4" style="display:none">
257
                <td id="hostip4" class="vncell">
258
                </td>
259
                <td id="bandwidthin4" class="listr">
260
                </td>
261
                <td id="bandwidthout4" class="listr">
262
                </td>
263
           </tr>
264
           <tr id="host5" style="display:none">
265
                <td id="hostip5" class="vncell">
266
                </td>
267
                <td id="bandwidthin5" class="listr">
268
                </td>
269
                <td id="bandwidthout5" class="listr">
270
                </td>
271
           </tr>
272
           <tr id="host6" style="display:none">
273
                <td id="hostip6" class="vncell">
274
                </td>
275
                <td id="bandwidthin6" class="listr">
276
                </td>
277
                <td id="bandwidthout6" class="listr">
278
                </td>
279
           </tr>
280
           <tr id="host7" style="display:none">
281
                <td id="hostip7" class="vncell">
282
                </td>
283
                <td id="bandwidthin7" class="listr">
284
                </td>
285
                <td id="bandwidthout7" class="listr">
286
                </td>
287
           </tr>
288
           <tr id="host8" style="display:none">
289
                <td id="hostip8" class="vncell">
290
                </td>
291
                <td id="bandwidthin8" class="listr">
292
                </td>
293
                <td id="bandwidthout8" class="listr">
294
                </td>
295
           </tr>
296
           <tr id="host9" style="display:none">
297
                <td id="hostip9" class="vncell">
298
                </td>
299
                <td id="bandwidthin9" class="listr">
300
                </td>
301
                <td id="bandwidthout9" class="listr">
302
                </td>
303
           </tr>
304
        </table>
305
	</div>
306
	<div style="clear: both;"></div>
307
</div>
308
<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"); ?>.
309

    
310
<?php include("fend.inc"); ?>
311

    
312
<script type="text/javascript">
313
jQuery(document).ready(updateBandwidth);
314
</script>
315
</body>
316
</html>
(181-181/246)