Project

General

Profile

Download (10.2 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
	$curif = "wan";
83
}
84

    
85
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
86

    
87
include("head.inc");
88

    
89
?>
90

    
91
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
92

    
93
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
94
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
95
<script language="javascript" type="text/javascript">
96

    
97
function updateBandwidth(){
98
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
99
    bandwidthAjax(hostinterface);
100
}
101

    
102
function bandwidthAjax(hostinterface) {
103
	uri = "bandwidth_by_ip.php?if=" + hostinterface;
104
	var opt = {
105
	    // Use GET
106
	    type: 'get',
107
	    error: function(req) {
108
	        // Handle 404
109
	        if(req.status == 404)
110
	            alert('Error 404: location "' + uri + '" was not found.');
111
	        // Handle other errors
112
	        else
113
	            alert('Error ' + req.status + ' -- ' + req.statusText);
114
	    },
115
		success: function(data) {
116
			updateBandwidthHosts(data);
117
	    }
118
	}
119
	jQuery.ajax(uri, opt);
120
}
121

    
122
function updateBandwidthHosts(data){
123
    var hosts_split = data.split("|");
124
    d = document;
125
    //parse top ten bandwidth abuser hosts
126
    for (var y=0; y<10; y++){
127
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
128
            if (hosts_split[y]) {
129
                hostinfo = hosts_split[y].split(";");
130

    
131
                //update host ip info
132
                var HostIpID = "hostip" + y;
133
                var hostip = d.getElementById(HostIpID);
134
                hostip.innerHTML = hostinfo[0];
135

    
136
                //update bandwidth inbound to host
137
                var hostbandwidthInID = "bandwidthin" + y;
138
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
139
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
140

    
141
                //update bandwidth outbound from host
142
                var hostbandwidthOutID = "bandwidthout" + y;
143
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
144
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
145

    
146
                //make the row appear if hidden
147
                var rowid = "#host" + y;
148
                if (jQuery(rowid).css('dislay') == "none"){
149
                     //hide rows that contain no data
150
                     jQuery(rowid).show(1000);
151
                }
152
            }
153
        }
154
        else
155
        {
156
            var rowid = "#host" + y;
157
            if (jQuery(rowid).css('dislay') != "none"){
158
                //hide rows that contain no data
159
                jQuery(rowid).fadeOut(2000);
160
            }
161
        }
162
    }
163
    
164
    setTimeout('updateBandwidth()', 1000);
165
}
166

    
167

    
168
</script>
169

    
170
<?php include("fbegin.inc"); ?>
171
<?php
172

    
173
/* link the ipsec interface magically */
174
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
175
	$ifdescrs['enc0'] = "IPsec";
176

    
177
?>
178
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
179
<?=gettext("Interface"); ?>:
180
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
181
<?php
182
foreach ($ifdescrs as $ifn => $ifd) {
183
	echo "<option value=\"$ifn\"";
184
	if ($ifn == $curif) echo " selected";
185
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
186
}
187
?>
188
</select>
189
</form>
190
<p><form method="post" action="status_graph.php">
191
</form>
192
<p>
193
<div id="niftyOutter">
194
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
195
        <object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" type="image/svg+xml" width="<?=$width;?>" height="<?=$height;?>">
196
            <param name="src" value="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" />
197
            <?=gettext("Your browser does not support the type SVG! You need to either use Firefox or download the Adobe SVG plugin"); ?>.
198
        </object>
199
    </div>
200
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
201
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
202
            <tr>
203
                <td class="listtopic" valign="top"><?=gettext("Host IP"); ?></td>
204
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
205
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
206
           </tr>
207
           <tr id="host0" style="display:none">
208
                <td id="hostip0" class="vncell">
209
                </td>
210
                <td id="bandwidthin0" class="listr">
211
                </td>
212
                <td id="bandwidthout0" class="listr">
213
                </td>
214
           </tr>
215
           <tr id="host1" style="display:none">
216
                <td id="hostip1" class="vncell">
217
                </td>
218
                <td id="bandwidthin1" class="listr">
219
                </td>
220
                <td id="bandwidthout1" class="listr">
221
                </td>
222
           </tr>
223
           <tr id="host2" style="display:none">
224
                <td id="hostip2" class="vncell">
225
                </td>
226
                <td id="bandwidthin2" class="listr">
227
                </td>
228
                <td id="bandwidthout2" class="listr">
229
                </td>
230
           </tr>
231
           <tr id="host3" style="display:none">
232
                <td id="hostip3" class="vncell">
233
                </td>
234
                <td id="bandwidthin3" class="listr">
235
                </td>
236
                <td id="bandwidthout3" class="listr">
237
                </td>
238
           </tr>
239
           <tr id="host4" style="display:none">
240
                <td id="hostip4" class="vncell">
241
                </td>
242
                <td id="bandwidthin4" class="listr">
243
                </td>
244
                <td id="bandwidthout4" class="listr">
245
                </td>
246
           </tr>
247
           <tr id="host5" style="display:none">
248
                <td id="hostip5" class="vncell">
249
                </td>
250
                <td id="bandwidthin5" class="listr">
251
                </td>
252
                <td id="bandwidthout5" class="listr">
253
                </td>
254
           </tr>
255
           <tr id="host6" style="display:none">
256
                <td id="hostip6" class="vncell">
257
                </td>
258
                <td id="bandwidthin6" class="listr">
259
                </td>
260
                <td id="bandwidthout6" class="listr">
261
                </td>
262
           </tr>
263
           <tr id="host7" style="display:none">
264
                <td id="hostip7" class="vncell">
265
                </td>
266
                <td id="bandwidthin7" class="listr">
267
                </td>
268
                <td id="bandwidthout7" class="listr">
269
                </td>
270
           </tr>
271
           <tr id="host8" style="display:none">
272
                <td id="hostip8" class="vncell">
273
                </td>
274
                <td id="bandwidthin8" class="listr">
275
                </td>
276
                <td id="bandwidthout8" class="listr">
277
                </td>
278
           </tr>
279
           <tr id="host9" style="display:none">
280
                <td id="hostip9" class="vncell">
281
                </td>
282
                <td id="bandwidthin9" class="listr">
283
                </td>
284
                <td id="bandwidthout9" class="listr">
285
                </td>
286
           </tr>
287
        </table>
288
	</div>
289
	<div style="clear: both;"></div>
290
</div>
291
<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"); ?>.
292

    
293
<?php include("fend.inc"); ?>
294

    
295
<script type="text/javascript">
296
window.onload = function(in_event)
297
	{
298
        updateBandwidth();
299
    }
300

    
301
</script>
302
</body>
303
</html>
(174-174/238)