Project

General

Profile

Download (9.63 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
##|+PRIV
36
##|*IDENT=page-status-trafficgraph
37
##|*NAME=Status: Traffic Graph page
38
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
39
##|*MATCH=status_graph.php*
40
##|-PRIV
41

    
42

    
43

    
44
require("guiconfig.inc");
45

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

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

    
56

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

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

    
64
include("head.inc");
65

    
66
?>
67

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

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

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

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

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

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

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

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

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

    
147

    
148
</script>
149

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

    
154
for($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
155
	if(isset($config['interfaces']['opt' . $j]['enable']))
156
		$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
157
}
158
if((isset($config['ipsec']['enable'])) || (isset($config['ipsec']['mobileclients']['enable']))) {
159
	$ifdescrs['ipsec'] = "IPSEC";
160
}
161

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

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

    
281
<?php include("fend.inc"); ?>
282

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

    
289
</script>
290
</body>
291
</html>
(156-156/217)