Project

General

Profile

Download (9.91 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
##|-PRIV
44

    
45
require("guiconfig.inc");
46

    
47
if ($_POST['width'])
48
	$width = $_POST['width'];
49
else
50
	$width = "100%";
51

    
52
if ($_POST['height'])
53
	$height = $_POST['height'];
54
else
55
	$height = "200";
56

    
57
// Get configured interface list
58
$ifdescrs = get_configured_interface_with_descr();
59
$ifdescrs["enc0"] = "IPSEC";
60

    
61
if ($_GET['if']) {
62
	$curif = $_GET['if'];
63
	$found = false;
64
	foreach($ifdescrs as $descr => $ifdescr) 
65
		if($descr == $curif) $found = true;
66
	if(!$found) {
67
		Header("Location: status_graph.php");
68
		exit;
69
	}
70
} else {
71
	$curif = "wan";
72
}
73

    
74
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
75

    
76
include("head.inc");
77

    
78
?>
79

    
80
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
81

    
82
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
83
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
84
<script language="javascript" type="text/javascript">
85

    
86
function updateBandwidth(){
87
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
88
    bandwidthAjax(hostinterface);
89
}
90

    
91
function bandwidthAjax(hostinterface) {
92
	uri = "bandwidth_by_ip.php?if=" + hostinterface;
93
	var opt = {
94
	    // Use GET
95
	    method: 'get',
96
	    asynchronous: true,
97
	    // Handle 404
98
	    on404: function(t) {
99
	        alert('Error 404: location "' + t.statusText + '" was not found.');
100
	    },
101
	    // Handle other errors
102
	    onFailure: function(t) {
103
	        alert('Error ' + t.status + ' -- ' + t.statusText);
104
	    },
105
		onSuccess: function(t) {
106
			updateBandwidthHosts(t.responseText);
107
	    }
108
	}
109
	new Ajax.Request(uri, opt);
110
}
111

    
112
function updateBandwidthHosts(data){
113
    var hosts_split = data.split("|");
114
    d = document;
115
    //parse top ten bandwidth abuser hosts
116
    for (var y=0; y<10; y++){
117
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
118
            if (hosts_split[y]) {
119
                hostinfo = hosts_split[y].split(";");
120

    
121
                //update host ip info
122
                var HostIpID = "hostip" + y;
123
                var hostip = d.getElementById(HostIpID);
124
                hostip.innerHTML = hostinfo[0];
125

    
126
                //update bandwidth inbound to host
127
                var hostbandwidthInID = "bandwidthin" + y;
128
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
129
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
130

    
131
                //update bandwidth outbound from host
132
                var hostbandwidthOutID = "bandwidthout" + y;
133
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
134
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
135

    
136
                //make the row appear if hidden
137
                var rowid = "host" + y;
138
                textlink = d.getElementById(rowid);
139
                if (textlink.style.display == "none"){
140
                     //hide rows that contain no data
141
                     Effect.Appear(rowid, {duration:1});
142
                }
143
            }
144
        }
145
        else
146
        {
147
            var rowid = "host" + y;
148
            textlink = d.getElementById(rowid);
149
            if (textlink.style.display != "none"){
150
                //hide rows that contain no data
151
                Effect.Fade(rowid, {duration:2});
152
            }
153
        }
154
    }
155
    
156
    setTimeout('updateBandwidth()', 1000);
157
}
158

    
159

    
160
</script>
161

    
162
<?php include("fbegin.inc"); ?>
163
<?php
164

    
165
/* link the ipsec interface magically */
166
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable'])) 
167
	$ifdescrs['enc0'] = "IPsec";
168

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

    
285
<?php include("fend.inc"); ?>
286

    
287
<script type="text/javascript">
288
window.onload = function(in_event)
289
	{
290
        updateBandwidth();
291
    }
292

    
293
</script>
294
</body>
295
</html>
(162-162/224)