1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
status_interfaces.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
require("guiconfig.inc");
|
33
|
|
34
|
function get_interface_info($ifdescr) {
|
35
|
|
36
|
global $config, $g;
|
37
|
|
38
|
$ifinfo = array();
|
39
|
|
40
|
/* find out interface name */
|
41
|
if ($ifdescr == "wan")
|
42
|
$ifinfo['if'] = get_real_wan_interface();
|
43
|
else
|
44
|
$ifinfo['if'] = $config['interfaces'][$ifdescr]['if'];
|
45
|
|
46
|
/* run netstat to determine link info */
|
47
|
unset($linkinfo);
|
48
|
exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
|
49
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
50
|
if (preg_match("/\*$/", $linkinfo[0])) {
|
51
|
$ifinfo['status'] = "down";
|
52
|
} else {
|
53
|
$ifinfo['status'] = "up";
|
54
|
}
|
55
|
|
56
|
if (($ifinfo['if'] != $g['pppoe_interface']) && (!strstr($ifinfo['if'],'tun'))) {
|
57
|
$ifinfo['macaddr'] = $linkinfo[3];
|
58
|
$ifinfo['inpkts'] = $linkinfo[4];
|
59
|
$ifinfo['inerrs'] = $linkinfo[5];
|
60
|
$ifinfo['inbytes'] = $linkinfo[6];
|
61
|
$ifinfo['outpkts'] = $linkinfo[7];
|
62
|
$ifinfo['outerrs'] = $linkinfo[8];
|
63
|
$ifinfo['outbytes'] = $linkinfo[9];
|
64
|
$ifinfo['collisions'] = $linkinfo[10];
|
65
|
} else {
|
66
|
$ifinfo['inpkts'] = $linkinfo[3];
|
67
|
$ifinfo['inbytes'] = $linkinfo[5];
|
68
|
$ifinfo['outpkts'] = $linkinfo[6];
|
69
|
$ifinfo['outbytes'] = $linkinfo[8];
|
70
|
}
|
71
|
|
72
|
if ($ifinfo['status'] == "up") {
|
73
|
/* run netstat to determine inet info */
|
74
|
unset($inetinfo);
|
75
|
exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f inet", $inetinfo);
|
76
|
$inetinfo = preg_split("/\s+/", $inetinfo[1]);
|
77
|
|
78
|
$ifinfo['ipaddr'] = $inetinfo[3];
|
79
|
|
80
|
if ($ifdescr == "wan") {
|
81
|
/* run netstat to determine the default gateway */
|
82
|
unset($netstatrninfo);
|
83
|
exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
|
84
|
|
85
|
foreach ($netstatrninfo as $nsr) {
|
86
|
if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
|
87
|
$ifinfo['gateway'] = $matches[1];
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
|
92
|
/* try to determine netmask and media with ifconfig */
|
93
|
unset($ifconfiginfo);
|
94
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
95
|
|
96
|
foreach ($ifconfiginfo as $ici) {
|
97
|
if (preg_match("/netmask (\S+)/", $ici, $matches) && !$ifinfo['subnet']) {
|
98
|
if (preg_match("/^0x/", $matches[1])) {
|
99
|
$ifinfo['subnet'] = long2ip(hexdec($matches[1]));
|
100
|
}
|
101
|
}
|
102
|
if (!isset($config['interfaces'][$ifdescr]['wireless'])) {
|
103
|
/* don't list media/speed for wireless cards, as it always
|
104
|
displays 2 Mbps even though clients can connect at 11 Mbps */
|
105
|
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
|
106
|
$ifinfo['media'] = $matches[1];
|
107
|
} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
|
108
|
$ifinfo['media'] = $matches[1];
|
109
|
}
|
110
|
}
|
111
|
if (preg_match("/status: (.*)$/", $ici, $matches)) {
|
112
|
if ($matches[1] != "active")
|
113
|
$ifinfo['status'] = $matches[1];
|
114
|
}
|
115
|
if (preg_match("/channel (\S*)/", $ici, $matches)) {
|
116
|
$ifinfo['channel'] = $matches[1];
|
117
|
}
|
118
|
if (preg_match("/ssid (\S*)/", $ici, $matches)) {
|
119
|
$ifinfo['ssid'] = $matches[1];
|
120
|
}
|
121
|
}
|
122
|
|
123
|
/* PPPoE only: get media from underlying ethernet interface */
|
124
|
if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pppoe")) {
|
125
|
unset($ifconfiginfo);
|
126
|
exec("/sbin/ifconfig " . $config['interfaces']['wan']['if'], $ifconfiginfo);
|
127
|
|
128
|
foreach ($ifconfiginfo as $ici) {
|
129
|
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
|
130
|
$ifinfo['media'] = $matches[1];
|
131
|
} else if (preg_match("/ether (.*)/", $ici, $matches)) {
|
132
|
$ifinfo['macaddr'] = $matches[1];
|
133
|
}
|
134
|
}
|
135
|
|
136
|
/* get pppoe link status for dial on demand */
|
137
|
unset($ifconfiginfo);
|
138
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
139
|
|
140
|
$ifinfo['pppoelink'] = "up";
|
141
|
|
142
|
foreach ($ifconfiginfo as $ici) {
|
143
|
if (strpos($ici, 'LINK0') !== false)
|
144
|
$ifinfo['pppoelink'] = "down";
|
145
|
}
|
146
|
}
|
147
|
|
148
|
/* get ppptp link status for dial on demand */
|
149
|
if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
|
150
|
|
151
|
unset($ifconfiginfo);
|
152
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
153
|
|
154
|
$ifinfo['pptplink'] = "up";
|
155
|
|
156
|
foreach ($ifconfiginfo as $ici) {
|
157
|
if (strpos($ici, 'LINK0') !== false)
|
158
|
$ifinfo['pptplink'] = "down";
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
return $ifinfo;
|
164
|
}
|
165
|
|
166
|
?>
|
167
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
168
|
<html>
|
169
|
<head>
|
170
|
<title><?=gentitle("Status: Interfaces");?></title>
|
171
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
172
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
173
|
</head>
|
174
|
|
175
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
176
|
<?php include("fbegin.inc"); ?>
|
177
|
<p class="pgtitle">Status: Interfaces</p>
|
178
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
179
|
<?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
|
180
|
|
181
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
|
182
|
$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
183
|
}
|
184
|
|
185
|
foreach ($ifdescrs as $ifdescr => $ifname):
|
186
|
$ifinfo = get_interface_info($ifdescr);
|
187
|
?>
|
188
|
<?php if ($i): ?>
|
189
|
<tr>
|
190
|
<td colspan="8" class="list" height="12"></td>
|
191
|
</tr>
|
192
|
<?php endif; ?>
|
193
|
<tr>
|
194
|
<td colspan="2" class="listtopic">
|
195
|
<?=htmlspecialchars($ifname);?>
|
196
|
interface</td>
|
197
|
</tr>
|
198
|
<tr>
|
199
|
<td width="22%" class="listhdrr">Status</td>
|
200
|
<td width="78%" class="listr">
|
201
|
<?=htmlspecialchars($ifinfo['status']);?>
|
202
|
</td>
|
203
|
</tr><?php if ($ifinfo['pppoelink']): ?>
|
204
|
<tr>
|
205
|
<td width="22%" class="listhdrr">PPPoE</td>
|
206
|
<td width="78%" class="listr">
|
207
|
<?=htmlspecialchars($ifinfo['pppoelink']);?>
|
208
|
</td>
|
209
|
</tr><?php endif; if ($ifinfo['pptplink']): ?>
|
210
|
<tr>
|
211
|
<td width="22%" class="listhdrr">PPTP</td>
|
212
|
<td width="78%" class="listr">
|
213
|
<?=htmlspecialchars($ifinfo['pptplink']);?>
|
214
|
</td>
|
215
|
</tr><?php endif; if ($ifinfo['macaddr']): ?>
|
216
|
<tr>
|
217
|
<td width="22%" class="listhdrr">MAC address</td>
|
218
|
<td width="78%" class="listr">
|
219
|
<?=htmlspecialchars($ifinfo['macaddr']);?>
|
220
|
</td>
|
221
|
</tr><?php endif; if ($ifinfo['status'] != "down"): ?>
|
222
|
<?php if ($ifinfo['ipaddr']): ?>
|
223
|
<tr>
|
224
|
<td width="22%" class="listhdrr">IP address</td>
|
225
|
<td width="78%" class="listr">
|
226
|
<?=htmlspecialchars($ifinfo['ipaddr']);?>
|
227
|
</td>
|
228
|
</tr><?php endif; ?><?php if ($ifinfo['subnet']): ?>
|
229
|
<tr>
|
230
|
<td width="22%" class="listhdrr">Subnet mask</td>
|
231
|
<td width="78%" class="listr">
|
232
|
<?=htmlspecialchars($ifinfo['subnet']);?>
|
233
|
</td>
|
234
|
</tr><?php endif; ?><?php if ($ifinfo['gateway']): ?>
|
235
|
<tr>
|
236
|
<td width="22%" class="listhdrr">Gateway</td>
|
237
|
<td width="78%" class="listr">
|
238
|
<?=htmlspecialchars($ifinfo['gateway']);?>
|
239
|
</td>
|
240
|
</tr><?php endif; ?><?php if ($ifinfo['media']): ?>
|
241
|
<tr>
|
242
|
<td width="22%" class="listhdrr">Media</td>
|
243
|
<td width="78%" class="listr">
|
244
|
<?=htmlspecialchars($ifinfo['media']);?>
|
245
|
</td>
|
246
|
</tr><?php endif; ?><?php if ($ifinfo['channel']): ?>
|
247
|
<tr>
|
248
|
<td width="22%" class="listhdrr">Channel</td>
|
249
|
<td width="78%" class="listr">
|
250
|
<?=htmlspecialchars($ifinfo['channel']);?>
|
251
|
</td>
|
252
|
</tr><?php endif; ?><?php if ($ifinfo['ssid']): ?>
|
253
|
<tr>
|
254
|
<td width="22%" class="listhdrr">SSID</td>
|
255
|
<td width="78%" class="listr">
|
256
|
<?=htmlspecialchars($ifinfo['ssid']);?>
|
257
|
</td>
|
258
|
</tr><?php endif; ?>
|
259
|
<tr>
|
260
|
<td width="22%" class="listhdrr">In/out packets</td>
|
261
|
<td width="78%" class="listr">
|
262
|
<?=htmlspecialchars($ifinfo['inpkts'] . "/" . $ifinfo['outpkts'] . " (" .
|
263
|
format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");?>
|
264
|
</td>
|
265
|
</tr><?php if (isset($ifinfo['inerrs'])): ?>
|
266
|
<tr>
|
267
|
<td width="22%" class="listhdrr">In/out errors</td>
|
268
|
<td width="78%" class="listr">
|
269
|
<?=htmlspecialchars($ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);?>
|
270
|
</td>
|
271
|
</tr><?php endif; ?><?php if (isset($ifinfo['collisions'])): ?>
|
272
|
<tr>
|
273
|
<td width="22%" class="listhdrr">Collisions</td>
|
274
|
<td width="78%" class="listr">
|
275
|
<?=htmlspecialchars($ifinfo['collisions']);?>
|
276
|
</td>
|
277
|
</tr><?php endif; ?>
|
278
|
<?php endif; ?>
|
279
|
<?php $i++; endforeach; ?>
|
280
|
</table>
|
281
|
<?php include("fend.inc"); ?>
|
282
|
</body>
|
283
|
</html>
|