1
|
<?php
|
2
|
/*
|
3
|
$Id: interface_statistics.widget.php
|
4
|
Copyright 2007 Scott Dale
|
5
|
Part of pfSense widgets (https://www.pfsense.org)
|
6
|
originally based on m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
|
9
|
and Jonathan Watt <jwatt@jwatt.org>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
|
34
|
$nocsrf = true;
|
35
|
|
36
|
require_once("guiconfig.inc");
|
37
|
require_once("pfsense-utils.inc");
|
38
|
require_once("functions.inc");
|
39
|
require_once("/usr/local/www/widgets/include/interface_statistics.inc");
|
40
|
|
41
|
$ifdescrs = get_configured_interface_with_descr();
|
42
|
|
43
|
$array_in_packets = array();
|
44
|
$array_out_packets = array();
|
45
|
$array_in_bytes = array();
|
46
|
$array_out_bytes = array();
|
47
|
$array_in_errors = array();
|
48
|
$array_out_errors = array();
|
49
|
$array_collisions = array();
|
50
|
$array_interrupt = array();
|
51
|
$interfacecounter = 0;
|
52
|
|
53
|
//build data arrays
|
54
|
foreach ($ifdescrs as $ifdescr => $ifname){
|
55
|
$ifinfo = get_interface_info($ifdescr);
|
56
|
$interfacecounter++;
|
57
|
if ($ifinfo['status'] != "down"){
|
58
|
$array_in_packets[] = $ifinfo['inpkts'];
|
59
|
$array_out_packets[] = $ifinfo['outpkts'];
|
60
|
$array_in_bytes[] = format_bytes($ifinfo['inbytes']);
|
61
|
$array_out_bytes[] = format_bytes($ifinfo['outbytes']);
|
62
|
if (isset($ifinfo['inerrs'])){
|
63
|
$array_in_errors[] = $ifinfo['inerrs'];
|
64
|
$array_out_errors[] = $ifinfo['outerrs'];
|
65
|
}
|
66
|
else{
|
67
|
$array_in_errors[] = "n/a";
|
68
|
$array_out_errors[] = "n/a";
|
69
|
}
|
70
|
if (isset($ifinfo['collisions']))
|
71
|
$array_collisions[] = htmlspecialchars($ifinfo['collisions']);
|
72
|
else
|
73
|
$array_collisions[] = "n/a";
|
74
|
}
|
75
|
|
76
|
|
77
|
}//end for
|
78
|
|
79
|
|
80
|
|
81
|
|
82
|
?>
|
83
|
<div id="int_labels" style="float:left;width:32%">
|
84
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="interfaces statistics">
|
85
|
<tr><td class="widgetsubheader" style="height:25px"> </td></tr>
|
86
|
<tr>
|
87
|
<td class="vncellt" style="height:25px">Packets In</td>
|
88
|
</tr>
|
89
|
<tr>
|
90
|
<td class="vncellt" style="height:25px">Packets Out</td>
|
91
|
</tr>
|
92
|
<tr>
|
93
|
<td class="vncellt" style="height:25px">Bytes In</td>
|
94
|
</tr>
|
95
|
<tr>
|
96
|
<td class="vncellt" style="height:25px">Bytes Out</td>
|
97
|
</tr>
|
98
|
<tr>
|
99
|
<td class="vncellt" style="height:25px">Errors In</td>
|
100
|
</tr>
|
101
|
<tr>
|
102
|
<td class="vncellt" style="height:25px">Errors Out</td>
|
103
|
</tr>
|
104
|
<tr>
|
105
|
<td class="vncellt" style="height:25px">Collisions</td>
|
106
|
</tr>
|
107
|
</table>
|
108
|
</div>
|
109
|
<div id="interfacestats" style="float:right;overflow: auto; width:68%">
|
110
|
|
111
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="the stats">
|
112
|
<tr>
|
113
|
<?php
|
114
|
$interface_names = array();
|
115
|
foreach ($ifdescrs as $ifdescr => $ifname):
|
116
|
$ifinfo = get_interface_info($ifdescr);
|
117
|
if ($ifinfo['status'] != "down"){ ?>
|
118
|
<td class="widgetsubheader nowrap" style="height:25px">
|
119
|
<?=htmlspecialchars($ifname);?>
|
120
|
</td>
|
121
|
<?php
|
122
|
//build array of interface names
|
123
|
$interface_names[] = $ifname;
|
124
|
}
|
125
|
endforeach; ?>
|
126
|
</tr>
|
127
|
|
128
|
<tr>
|
129
|
<?php
|
130
|
$counter = 1;
|
131
|
foreach ($array_in_packets as $data): ?>
|
132
|
<td class="listr nowrap" id="stat<?php echo $counter?>" style="height:25px">
|
133
|
<?=htmlspecialchars($data);?>
|
134
|
</td>
|
135
|
<?php
|
136
|
$counter = $counter + 7;
|
137
|
endforeach; ?>
|
138
|
</tr>
|
139
|
|
140
|
<tr>
|
141
|
<?php
|
142
|
$counter = 2;
|
143
|
foreach ($array_out_packets as $data): ?>
|
144
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
145
|
<?=htmlspecialchars($data);?>
|
146
|
</td>
|
147
|
<?php
|
148
|
$counter = $counter + 7;
|
149
|
endforeach; ?>
|
150
|
</tr>
|
151
|
|
152
|
<tr>
|
153
|
<?php
|
154
|
$counter = 3;
|
155
|
foreach ($array_in_bytes as $data): ?>
|
156
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
157
|
<?=htmlspecialchars($data);?>
|
158
|
</td>
|
159
|
<?php
|
160
|
$counter = $counter + 7;
|
161
|
endforeach; ?>
|
162
|
</tr>
|
163
|
|
164
|
<tr>
|
165
|
<?php
|
166
|
$counter = 4;
|
167
|
foreach ($array_out_bytes as $data): ?>
|
168
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
169
|
<?=htmlspecialchars($data);?>
|
170
|
</td>
|
171
|
<?php
|
172
|
$counter = $counter + 7;
|
173
|
endforeach; ?>
|
174
|
</tr>
|
175
|
|
176
|
<tr>
|
177
|
<?php
|
178
|
$counter = 5;
|
179
|
foreach ($array_in_errors as $data): ?>
|
180
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
181
|
<?=htmlspecialchars($data);?>
|
182
|
</td>
|
183
|
<?php
|
184
|
$counter = $counter + 7;
|
185
|
endforeach; ?>
|
186
|
</tr>
|
187
|
|
188
|
<tr>
|
189
|
<?php
|
190
|
$counter = 6;
|
191
|
foreach ($array_out_errors as $data): ?>
|
192
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
193
|
<?=htmlspecialchars($data);?>
|
194
|
</td>
|
195
|
<?php
|
196
|
$counter = $counter + 7;
|
197
|
endforeach; ?>
|
198
|
</tr>
|
199
|
|
200
|
<tr>
|
201
|
<?php
|
202
|
$counter = 7;
|
203
|
foreach ($array_collisions as $data): ?>
|
204
|
<td class="listr nowrap" id="stat<?php echo $counter;?>" style="height:25px">
|
205
|
<?=htmlspecialchars($data);?>
|
206
|
</td>
|
207
|
<?php
|
208
|
$counter = $counter + 7;
|
209
|
endforeach; ?>
|
210
|
</tr>
|
211
|
</table>
|
212
|
</div>
|