Projet

Général

Profil

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

univnautes / usr / local / www / status_graph.php @ 0fab7eb1

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

    
119
<script type="text/javascript">
120

    
121
function updateBandwidth(){
122
    var hostinterface = jQuery("#if").val();
123
	var sorting = jQuery("#sort").val();
124
	var filter = jQuery("#filter").val();
125
	var hostipformat = jQuery("#hostipformat").val();
126
    bandwidthAjax(hostinterface, sorting, filter, hostipformat);
127
}
128

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

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

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

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

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

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

    
194

    
195
</script>
196

    
197
<?php include("fbegin.inc"); ?>
198
<?php
199

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

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

    
332
<?php include("fend.inc"); ?>
333

    
334
<script type="text/javascript">
335
jQuery(document).ready(updateBandwidth);
336
</script>
337
</body>
338
</html>
(188-188/254)