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 = "<?php echo htmlspecialchars($curif); ?>";
113
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
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
	        // Handle 404
124
	        if(req.status == 404)
125
	            alert('Error 404: location "' + uri + '" was not found.');
126
	        // Handle other errors
127
	        else
128
	            alert('Error ' + req.status + ' -- ' + req.statusText);
129
	    },
130
		success: function(data) {
131
			updateBandwidthHosts(data);
132
	    }
133
	}
134
	jQuery.ajax(uri, opt);
135
}
136

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

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

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

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

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

    
182

    
183
</script>
184

    
185
<?php include("fbegin.inc"); ?>
186
<?php
187

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

    
192
?>
193
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
194
<?=gettext("Interface"); ?>:
195
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
196
<?php
197
foreach ($ifdescrs as $ifn => $ifd) {
198
	echo "<option value=\"$ifn\"";
199
	if ($ifn == $curif) echo " selected";
200
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
201
}
202
?>
203
</select>
204
, Sort by: 
205
<select name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
206
	<option value="">Bandwidth In</option>
207
	<option value="out"<?php if ($cursort == "out") echo " selected";?>>Bandwidth Out</option>
208
</select>
209
</form>
210
<p><form method="post" action="status_graph.php">
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
window.onload = function(in_event)
314
	{
315
        updateBandwidth();
316
    }
317

    
318
</script>
319
</body>
320
</html>
(181-181/246)