Projet

Général

Profil

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

univnautes / usr / local / www / status_graph.php @ 929dfb4c

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
##|*MATCH=graph.php*
45
##|*MATCH=ifstats.php*
46
##|-PRIV
47

    
48
require("guiconfig.inc");
49

    
50
if ($_POST['width'])
51
	$width = $_POST['width'];
52
else
53
	$width = "100%";
54

    
55
if ($_POST['height'])
56
	$height = $_POST['height'];
57
else
58
	$height = "200";
59

    
60
// Get configured interface list
61
$ifdescrs = get_configured_interface_with_descr();
62
if (isset($config['ipsec']['enable']))
63
	$ifdescrs['enc0'] = "IPsec";
64
foreach (array('server', 'client') as $mode) {
65
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
66
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
67
			if (!isset($setting['disable'])) {
68
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
69
			}
70
		}
71
	}
72
}
73

    
74
if ($_GET['if']) {
75
	$curif = $_GET['if'];
76
	$found = false;
77
	foreach($ifdescrs as $descr => $ifdescr) {
78
		if ($descr == $curif) {
79
			$found = true;
80
			break;
81
		}
82
	}
83
	if ($found === false) {
84
		Header("Location: status_graph.php");
85
		exit;
86
	}
87
} else {
88
	if (empty($ifdescrs["wan"])) {
89
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
90
		reset($ifdescrs);
91
		$curif = key($ifdescrs);
92
	}
93
	else {
94
		$curif = "wan";
95
	}
96
}
97
if ($_GET['sort']) {
98
	$cursort = $_GET['sort'];
99
} else {
100
	$cursort = "";
101
}
102
if ($_GET['filter']) {
103
	$curfilter = $_GET['filter'];
104
} else {
105
	$curfilter = "";
106
}
107
if ($_GET['hostipformat']) {
108
	$curhostipformat = $_GET['hostipformat'];
109
} else {
110
	$curhostipformat = "";
111
}
112

    
113
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
114

    
115
include("head.inc");
116

    
117
?>
118

    
119
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
120

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

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

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

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

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

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

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

    
196
//]]>
197
</script>
198

    
199
<?php include("fbegin.inc"); ?>
200
<?php
201

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

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

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

    
340
<script type="text/javascript">
341
jQuery(document).ready(updateBandwidth);
342
</script>
343
</body>
344
</html>
(181-181/246)