Project

General

Profile

Download (9.54 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

    
58
if ($_GET['if'])
59
	$curif = $_GET['if'];
60
else
61
	$curif = "wan";
62

    
63
$pgtitle = array("Status","Traffic Graph");
64

    
65
include("head.inc");
66

    
67
?>
68

    
69
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
70

    
71
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
72
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
73
<script language="javascript" type="text/javascript">
74

    
75
function updateBandwidth(){
76
    var hostinterface = "<?php echo $curif; ?>";
77
    bandwidthAjax(hostinterface);
78
}
79

    
80
function bandwidthAjax(hostinterface) {
81
	uri = "bandwidth_by_ip.php?if=" + hostinterface;
82
	var opt = {
83
	    // Use GET
84
	    method: 'get',
85
	    asynchronous: true,
86
	    // Handle 404
87
	    on404: function(t) {
88
	        alert('Error 404: location "' + t.statusText + '" was not found.');
89
	    },
90
	    // Handle other errors
91
	    onFailure: function(t) {
92
	        alert('Error ' + t.status + ' -- ' + t.statusText);
93
	    },
94
		onSuccess: function(t) {
95
			updateBandwidthHosts(t.responseText);
96
	    }
97
	}
98
	new Ajax.Request(uri, opt);
99
}
100

    
101
function updateBandwidthHosts(data){
102
    var hosts_split = data.split("|");
103
    d = document;
104
    //parse top ten bandwidth abuser hosts
105
    for (var y=0; y<10; y++){
106
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
107
            if (hosts_split[y]) {
108
                hostinfo = hosts_split[y].split(";");
109

    
110
                //update host ip info
111
                var HostIpID = "hostip" + y;
112
                var hostip = d.getElementById(HostIpID);
113
                hostip.innerHTML = hostinfo[0];
114

    
115
                //update bandwidth inbound to host
116
                var hostbandwidthInID = "bandwidthin" + y;
117
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
118
                hostbandwidthin.innerHTML = hostinfo[1] + " Bytes/sec";
119

    
120
                //update bandwidth outbound from host
121
                var hostbandwidthOutID = "bandwidthout" + y;
122
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
123
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bytes/sec";
124

    
125
                //make the row appear if hidden
126
                var rowid = "host" + y;
127
                textlink = d.getElementById(rowid);
128
                if (textlink.style.display == "none"){
129
                     //hide rows that contain no data
130
                     Effect.Appear(rowid, {duration:1});
131
                }
132
            }
133
        }
134
        else
135
        {
136
            var rowid = "host" + y;
137
            textlink = d.getElementById(rowid);
138
            if (textlink.style.display != "none"){
139
                //hide rows that contain no data
140
                Effect.Fade(rowid, {duration:2});
141
            }
142
        }
143
    }
144
    
145
    setTimeout('updateBandwidth()', 3000);
146
}
147

    
148

    
149
</script>
150

    
151
<?php include("fbegin.inc"); ?>
152
<?php
153
$ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
154

    
155
for($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
156
	if(isset($config['interfaces']['opt' . $j]['enable']))
157
		$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
158
}
159

    
160
/* link the ipsec interface magically */
161
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable'])) 
162
	$ifdescrs['enc0'] = "IPsec";
163

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

    
279
<?php include("fend.inc"); ?>
280

    
281
<script type="text/javascript">
282
window.onload = function(in_event)
283
	{
284
        updateBandwidth();
285
    }
286

    
287
</script>
288
</body>
289
</html>
(155-155/217)