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) $found = true;
77
	if(!$found) {
78
		Header("Location: status_graph.php");
79
		exit;
80
	}
81
} else {
82
	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
}
91
if ($_GET['sort']) {
92
	$cursort = $_GET['sort'];
93
} else {
94
	$cursort = "";
95
}
96

    
97
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
98

    
99
include("head.inc");
100

    
101
?>
102

    
103
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
104

    
105
<script language="javascript" type="text/javascript">
106

    
107
function updateBandwidth(){
108
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
109
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
110
    bandwidthAjax(hostinterface, sorting);
111
}
112

    
113
function bandwidthAjax(hostinterface, sorting) {
114
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting;
115
	var opt = {
116
	    // Use GET
117
	    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
	    },
126
		success: function(data) {
127
			updateBandwidthHosts(data);
128
	    }
129
	}
130
	jQuery.ajax(uri, opt);
131
}
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
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
151

    
152
                //update bandwidth outbound from host
153
                var hostbandwidthOutID = "bandwidthout" + y;
154
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
155
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
156

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

    
178

    
179
</script>
180

    
181
<?php include("fbegin.inc"); ?>
182
<?php
183

    
184
/* link the ipsec interface magically */
185
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
186
	$ifdescrs['enc0'] = "IPsec";
187

    
188
?>
189
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
190
<?=gettext("Interface"); ?>:
191
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
192
<?php
193
foreach ($ifdescrs as $ifn => $ifd) {
194
	echo "<option value=\"$ifn\"";
195
	if ($ifn == $curif) echo " selected";
196
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
197
}
198
?>
199
</select>
200
, 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
</form>
206
<p><form method="post" action="status_graph.php">
207
</form>
208
<p>
209
<div id="niftyOutter">
210
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
211
        <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
    </div>
213
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
214
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
215
            <tr>
216
                <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
           </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
	</div>
302
	<div style="clear: both;"></div>
303
</div>
304
<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

    
306
<?php include("fend.inc"); ?>
307

    
308
<script type="text/javascript">
309
window.onload = function(in_event)
310
	{
311
        updateBandwidth();
312
    }
313

    
314
</script>
315
</body>
316
</html>
(184-184/249)