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
if ($_GET['sort']) {
85
	$cursort = $_GET['sort'];
86
} else {
87
	$cursort = "";
88
}
89

    
90
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
91

    
92
include("head.inc");
93

    
94
?>
95

    
96
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
97

    
98
<script language="javascript" type="text/javascript">
99

    
100
function updateBandwidth(){
101
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
102
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
103
    bandwidthAjax(hostinterface, sorting);
104
}
105

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

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

    
135
                //update host ip info
136
                var HostIpID = "hostip" + y;
137
                var hostip = d.getElementById(HostIpID);
138
                hostip.innerHTML = hostinfo[0];
139

    
140
                //update bandwidth inbound to host
141
                var hostbandwidthInID = "bandwidthin" + y;
142
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
143
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
144

    
145
                //update bandwidth outbound from host
146
                var hostbandwidthOutID = "bandwidthout" + y;
147
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
148
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
149

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

    
171

    
172
</script>
173

    
174
<?php include("fbegin.inc"); ?>
175
<?php
176

    
177
/* link the ipsec interface magically */
178
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
179
	$ifdescrs['enc0'] = "IPsec";
180

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

    
299
<?php include("fend.inc"); ?>
300

    
301
<script type="text/javascript">
302
window.onload = function(in_event)
303
	{
304
        updateBandwidth();
305
    }
306

    
307
</script>
308
</body>
309
</html>
(183-183/249)