Projet

Général

Profil

Télécharger (11,6 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / status_graph.php @ 6f3d2063

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
if ($_GET['filter']) {
101
	$curfilter = $_GET['filter'];
102
} else {
103
	$curfilter = "";
104
}
105
if ($_GET['hostipformat']) {
106
	$curhostipformat = $_GET['hostipformat'];
107
} else {
108
	$curhostipformat = "";
109
}
110

    
111
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
112

    
113
include("head.inc");
114

    
115
?>
116

    
117
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
118
<?php include("fbegin.inc"); ?>
119

    
120
<script type="text/javascript">
121
//<![CDATA[
122
function updateBandwidth(){
123
    var hostinterface = jQuery("#if").val();
124
	var sorting = jQuery("#sort").val();
125
	var filter = jQuery("#filter").val();
126
	var hostipformat = jQuery("#hostipformat").val();
127
    bandwidthAjax(hostinterface, sorting, filter, hostipformat);
128
}
129

    
130
function bandwidthAjax(hostinterface, sorting, filter, hostipformat) {
131
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting + "&filter=" + filter + "&hostipformat=" + hostipformat;
132
	var opt = {
133
	    // Use GET
134
	    type: 'get',
135
	    error: function(req) {
136
	        /* XXX: Leave this for debugging purposes: Handle 404
137
	        if(req.status == 404)
138
	            alert('Error 404: location "' + uri + '" was not found.');
139
		*/
140
	        /* Handle other errors
141
	        else
142
	            alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
143
		*/
144
	    },
145
		success: function(data) {
146
			updateBandwidthHosts(data);
147
	    }
148
	}
149
	jQuery.ajax(uri, opt);
150
}
151

    
152
function updateBandwidthHosts(data){
153
    var hosts_split = data.split("|");
154
    d = document;
155
    //parse top ten bandwidth abuser hosts
156
    for (var y=0; y<10; y++){
157
        if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
158
			hostinfo = hosts_split[y].split(";");
159

    
160
			//update host ip info
161
			var HostIpID = "hostip" + y;
162
			var hostip = d.getElementById(HostIpID);
163
			hostip.innerHTML = hostinfo[0];
164

    
165
			//update bandwidth inbound to host
166
			var hostbandwidthInID = "bandwidthin" + y;
167
			var hostbandwidthin = d.getElementById(hostbandwidthInID);
168
			hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
169

    
170
			//update bandwidth outbound from host
171
			var hostbandwidthOutID = "bandwidthout" + y;
172
			var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
173
			hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
174

    
175
			//make the row appear if hidden
176
			var rowid = "#host" + y;
177
			if (jQuery(rowid).css('display') == "none"){
178
				//hide rows that contain no data
179
				jQuery(rowid).show(1000);
180
			}
181
        }
182
        else
183
        {
184
            var rowid = "#host" + y;
185
            if (jQuery(rowid).css('display') != "none"){
186
                //hide rows that contain no data
187
                jQuery(rowid).fadeOut(2000);
188
            }
189
        }
190
    }
191
    
192
    setTimeout('updateBandwidth()', 1000);
193
}
194
//]]>
195
</script>
196

    
197
<?php
198

    
199
/* link the ipsec interface magically */
200
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
201
	$ifdescrs['enc0'] = "IPsec";
202

    
203
?>
204
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
205
<?=gettext("Interface"); ?>:
206
<select id="if" name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
207
<?php
208
foreach ($ifdescrs as $ifn => $ifd) {
209
	echo "<option value=\"$ifn\"";
210
	if ($ifn == $curif) echo " selected=\"selected\"";
211
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
212
}
213
?>
214
</select>
215
, Sort by: 
216
<select id="sort" name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
217
	<option value="">Bw In</option>
218
	<option value="out"<?php if ($cursort == "out") echo " selected=\"selected\"";?>>Bw Out</option>
219
</select>
220
, Filter: 
221
<select id="filter" name="filter" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
222
	<option value="local"<?php if ($curfilter == "local") echo " selected=\"selected\"";?>>Local</option>
223
	<option value="remote"<?php if ($curfilter == "remote") echo " selected=\"selected\"";?>>Remote</option>
224
	<option value="all"<?php if ($curfilter == "all") echo " selected=\"selected\"";?>>All</option>
225
</select>
226
, Display: 
227
<select id="hostipformat" name="hostipformat" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
228
	<option value="">IP Address</option>
229
	<option value="hostname"<?php if ($curhostipformat == "hostname") echo " selected";?>>Host Name</option>
230
	<option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>>FQDN</option>
231
</select>
232
</form>
233
<p>&nbsp;</p>
234
<div id="niftyOutter">
235
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
236
        <object	data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
237
          <param name="id" value="graph" />
238
          <param name="type" value="image/svg+xml" />
239
          <param name="width" value="<? echo $width; ?>" />
240
          <param name="height" value="<? echo $height; ?>" />
241
          <param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
242
        </object>
243
    </div>
244
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
245
        <table width="100%" border="0" cellspacing="0" cellpadding="0" summary="status">
246
            <tr>
247
                <td class="listtopic" valign="top"><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></td>
248
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
249
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
250
           </tr>
251
           <tr id="host0" style="display:none">
252
                <td id="hostip0" class="vncell">
253
                </td>
254
                <td id="bandwidthin0" class="listr">
255
                </td>
256
                <td id="bandwidthout0" class="listr">
257
                </td>
258
           </tr>
259
           <tr id="host1" style="display:none">
260
                <td id="hostip1" class="vncell">
261
                </td>
262
                <td id="bandwidthin1" class="listr">
263
                </td>
264
                <td id="bandwidthout1" class="listr">
265
                </td>
266
           </tr>
267
           <tr id="host2" style="display:none">
268
                <td id="hostip2" class="vncell">
269
                </td>
270
                <td id="bandwidthin2" class="listr">
271
                </td>
272
                <td id="bandwidthout2" class="listr">
273
                </td>
274
           </tr>
275
           <tr id="host3" style="display:none">
276
                <td id="hostip3" class="vncell">
277
                </td>
278
                <td id="bandwidthin3" class="listr">
279
                </td>
280
                <td id="bandwidthout3" class="listr">
281
                </td>
282
           </tr>
283
           <tr id="host4" style="display:none">
284
                <td id="hostip4" class="vncell">
285
                </td>
286
                <td id="bandwidthin4" class="listr">
287
                </td>
288
                <td id="bandwidthout4" class="listr">
289
                </td>
290
           </tr>
291
           <tr id="host5" style="display:none">
292
                <td id="hostip5" class="vncell">
293
                </td>
294
                <td id="bandwidthin5" class="listr">
295
                </td>
296
                <td id="bandwidthout5" class="listr">
297
                </td>
298
           </tr>
299
           <tr id="host6" style="display:none">
300
                <td id="hostip6" class="vncell">
301
                </td>
302
                <td id="bandwidthin6" class="listr">
303
                </td>
304
                <td id="bandwidthout6" class="listr">
305
                </td>
306
           </tr>
307
           <tr id="host7" style="display:none">
308
                <td id="hostip7" class="vncell">
309
                </td>
310
                <td id="bandwidthin7" class="listr">
311
                </td>
312
                <td id="bandwidthout7" class="listr">
313
                </td>
314
           </tr>
315
           <tr id="host8" style="display:none">
316
                <td id="hostip8" class="vncell">
317
                </td>
318
                <td id="bandwidthin8" class="listr">
319
                </td>
320
                <td id="bandwidthout8" class="listr">
321
                </td>
322
           </tr>
323
           <tr id="host9" style="display:none">
324
                <td id="hostip9" class="vncell">
325
                </td>
326
                <td id="bandwidthin9" class="listr">
327
                </td>
328
                <td id="bandwidthout9" class="listr">
329
                </td>
330
           </tr>
331
        </table>
332
	</div>
333
	<div style="clear: both;"></div>
334
</div>
335
<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"); ?>.</p>
336

    
337
<?php include("fend.inc"); ?>
338

    
339
<script type="text/javascript">
340
//<![CDATA[
341
jQuery(document).ready(updateBandwidth);
342
//]]>
343
</script>
344
</body>
345
</html>
(189-189/255)