Project

General

Profile

Download (9.8 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 language="javascript" type="text/javascript">
94

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

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

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

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

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

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

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

    
165

    
166
</script>
167

    
168
<?php include("fbegin.inc"); ?>
169
<?php
170

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

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

    
288
<?php include("fend.inc"); ?>
289

    
290
<script type="text/javascript">
291
window.onload = function(in_event)
292
	{
293
        updateBandwidth();
294
    }
295

    
296
</script>
297
</body>
298
</html>
(182-182/248)