1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
status_interfaces.php
|
6
|
part of pfSense
|
7
|
Copyright (C) 2005 Scott Ullrich <sullrich@gmail.com>.
|
8
|
All rights reserved.
|
9
|
|
10
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
11
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
12
|
All rights reserved.
|
13
|
|
14
|
Redistribution and use in source and binary forms, with or without
|
15
|
modification, are permitted provided that the following conditions are met:
|
16
|
|
17
|
1. Redistributions of source code must retain the above copyright notice,
|
18
|
this list of conditions and the following disclaimer.
|
19
|
|
20
|
2. Redistributions in binary form must reproduce the above copyright
|
21
|
notice, this list of conditions and the following disclaimer in the
|
22
|
documentation and/or other materials provided with the distribution.
|
23
|
|
24
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
25
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
26
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
27
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
28
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
POSSIBILITY OF SUCH DAMAGE.
|
34
|
*/
|
35
|
|
36
|
require_once("guiconfig.inc");
|
37
|
|
38
|
$wancfg = &$config['interfaces']['wan'];
|
39
|
|
40
|
if ($_POST) {
|
41
|
$interface = $_POST['interface'];
|
42
|
$ifcfg = &$config['interfaces'][$interface];
|
43
|
if ($_POST['submit'] == "Disconnect" || $_POST['submit'] == "Release") {
|
44
|
if ($ifcfg['ipaddr'] == "dhcp")
|
45
|
interfaces_dhcp_down($interface);
|
46
|
else if ($ifcfg['ipaddr'] == "pppoe")
|
47
|
interfaces_wan_pppoe_down(); // FIXME: when we support multi-pppoe
|
48
|
else if ($ifcfg['ipaddr'] == "pptp")
|
49
|
interfaces_wan_pptp_down(); // FIXME: when we support multi-pptp
|
50
|
} else if ($_POST['submit'] == "Connect" || $_POST['submit'] == "Renew") {
|
51
|
if ($ifcfg['ipaddr'] == "dhcp")
|
52
|
interfaces_dhcp_up($interface);
|
53
|
else if ($ifcfg['ipaddr'] == "pppoe")
|
54
|
interfaces_wan_pppoe_up(); // FIXME: when we support multi-pppoe
|
55
|
else if ($ifcfg['ipaddr'] == "pptp")
|
56
|
interfaces_wan_pptp_up(); // FIXME: when we support multi-pptp
|
57
|
} else {
|
58
|
header("Location: index.php");
|
59
|
exit;
|
60
|
}
|
61
|
}
|
62
|
|
63
|
function get_interface_info($ifdescr) {
|
64
|
|
65
|
global $config;
|
66
|
|
67
|
$ifinfo = array();
|
68
|
|
69
|
/* find out interface name */
|
70
|
$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
|
71
|
if ($ifdescr == "wan")
|
72
|
$ifinfo['if'] = get_real_wan_interface();
|
73
|
else
|
74
|
$ifinfo['if'] = $ifinfo['hwif'];
|
75
|
|
76
|
/* run netstat to determine link info */
|
77
|
unset($linkinfo);
|
78
|
exec("/usr/bin/netstat -I " . $ifinfo['hwif'] . " -nWb -f link", $linkinfo);
|
79
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
80
|
if (preg_match("/\*$/", $linkinfo[0])) {
|
81
|
$ifinfo['status'] = "down";
|
82
|
} else {
|
83
|
$ifinfo['status'] = "up";
|
84
|
}
|
85
|
|
86
|
if (!strstr($ifinfo['if'],'tun')) {
|
87
|
$ifinfo['macaddr'] = $linkinfo[3];
|
88
|
$ifinfo['inpkts'] = $linkinfo[4];
|
89
|
$ifinfo['inerrs'] = $linkinfo[5];
|
90
|
$ifinfo['inbytes'] = $linkinfo[6];
|
91
|
$ifinfo['outpkts'] = $linkinfo[7];
|
92
|
$ifinfo['outerrs'] = $linkinfo[8];
|
93
|
$ifinfo['outbytes'] = $linkinfo[9];
|
94
|
$ifinfo['collisions'] = $linkinfo[10];
|
95
|
} else {
|
96
|
$ifinfo['inpkts'] = $linkinfo[3];
|
97
|
$ifinfo['inbytes'] = $linkinfo[5];
|
98
|
$ifinfo['outpkts'] = $linkinfo[6];
|
99
|
$ifinfo['outbytes'] = $linkinfo[8];
|
100
|
}
|
101
|
|
102
|
/* DHCP? -> see if dhclient is up */
|
103
|
if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "dhcp")) {
|
104
|
/* see if dhclient is up */
|
105
|
if (is_dhcp_running("wan") == true)
|
106
|
$ifinfo['dhcplink'] = "up";
|
107
|
else
|
108
|
$ifinfo['dhcplink'] = "down";
|
109
|
}
|
110
|
/* loop through optional interfaces looking to see if they are dhcp */
|
111
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
|
112
|
$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
113
|
if (($ifdescr == "opt{$j}") && ($config['interfaces']['opt' . $j]['ipaddr'] == "dhcp")) {
|
114
|
/* see if dhclient is up */
|
115
|
if (is_dhcp_running("opt{$j}") == true)
|
116
|
$ifinfo['dhcplink'] = "up";
|
117
|
else
|
118
|
$ifinfo['dhcplink'] = "down";
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/* PPPoE interface? -> get status from virtual interface */
|
123
|
if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pppoe")) {
|
124
|
unset($linkinfo);
|
125
|
exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
|
126
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
127
|
if (preg_match("/\*$/", $linkinfo[0])) {
|
128
|
$ifinfo['pppoelink'] = "down";
|
129
|
} else {
|
130
|
/* get PPPoE link status for dial on demand */
|
131
|
unset($ifconfiginfo);
|
132
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
133
|
|
134
|
$ifinfo['pppoelink'] = "up";
|
135
|
|
136
|
foreach ($ifconfiginfo as $ici) {
|
137
|
if (strpos($ici, 'LINK0') !== false)
|
138
|
$ifinfo['pppoelink'] = "down";
|
139
|
}
|
140
|
}
|
141
|
}
|
142
|
|
143
|
/* PPTP interface? -> get status from virtual interface */
|
144
|
if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
|
145
|
unset($linkinfo);
|
146
|
exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
|
147
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
148
|
if (preg_match("/\*$/", $linkinfo[0])) {
|
149
|
$ifinfo['pptplink'] = "down";
|
150
|
} else {
|
151
|
/* get PPTP link status for dial on demand */
|
152
|
unset($ifconfiginfo);
|
153
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
154
|
|
155
|
$ifinfo['pptplink'] = "up";
|
156
|
|
157
|
foreach ($ifconfiginfo as $ici) {
|
158
|
if (strpos($ici, 'LINK0') !== false)
|
159
|
$ifinfo['pptplink'] = "down";
|
160
|
}
|
161
|
}
|
162
|
}
|
163
|
|
164
|
if ($ifinfo['status'] == "up") {
|
165
|
/* try to determine media with ifconfig */
|
166
|
unset($ifconfiginfo);
|
167
|
exec("/sbin/ifconfig " . $ifinfo['hwif'], $ifconfiginfo);
|
168
|
|
169
|
foreach ($ifconfiginfo as $ici) {
|
170
|
if (!isset($config['interfaces'][$ifdescr]['wireless'])) {
|
171
|
/* don't list media/speed for wireless cards, as it always
|
172
|
displays 2 Mbps even though clients can connect at 11 Mbps */
|
173
|
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
|
174
|
$ifinfo['media'] = $matches[1];
|
175
|
} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
|
176
|
$ifinfo['media'] = $matches[1];
|
177
|
}
|
178
|
}
|
179
|
if (preg_match("/status: (.*)$/", $ici, $matches)) {
|
180
|
if ($matches[1] != "active")
|
181
|
$ifinfo['status'] = $matches[1];
|
182
|
}
|
183
|
if (preg_match("/channel (\S*)/", $ici, $matches)) {
|
184
|
$ifinfo['channel'] = $matches[1];
|
185
|
}
|
186
|
if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
|
187
|
if ($matches[1][0] == '"')
|
188
|
$ifinfo['ssid'] = substr($matches[1], 1, -1);
|
189
|
else
|
190
|
$ifinfo['ssid'] = $matches[1];
|
191
|
}
|
192
|
}
|
193
|
|
194
|
if ($ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
|
195
|
/* try to determine IP address and netmask with ifconfig */
|
196
|
unset($ifconfiginfo);
|
197
|
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
|
198
|
|
199
|
foreach ($ifconfiginfo as $ici) {
|
200
|
if (preg_match("/inet (\S+)/", $ici, $matches)) {
|
201
|
$ifinfo['ipaddr'] = $matches[1];
|
202
|
}
|
203
|
if (preg_match("/netmask (\S+)/", $ici, $matches)) {
|
204
|
if (preg_match("/^0x/", $matches[1]))
|
205
|
$ifinfo['subnet'] = long2ip(hexdec($matches[1]));
|
206
|
}
|
207
|
}
|
208
|
|
209
|
if ($ifdescr == "wan") {
|
210
|
/* run netstat to determine the default gateway */
|
211
|
unset($netstatrninfo);
|
212
|
exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
|
213
|
|
214
|
foreach ($netstatrninfo as $nsr) {
|
215
|
if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
|
216
|
$ifinfo['gateway'] = $matches[1];
|
217
|
}
|
218
|
}
|
219
|
}
|
220
|
}
|
221
|
}
|
222
|
|
223
|
return $ifinfo;
|
224
|
}
|
225
|
|
226
|
$pgtitle = "Status: Interfaces";
|
227
|
include("head.inc");
|
228
|
|
229
|
?>
|
230
|
|
231
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
232
|
<?php include("fbegin.inc"); ?>
|
233
|
<p class="pgtitle"><?=$pgtitle?></p>
|
234
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
235
|
<?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
|
236
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
|
237
|
$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
238
|
}
|
239
|
foreach ($ifdescrs as $ifdescr => $ifname):
|
240
|
$ifinfo = get_interface_info($ifdescr);
|
241
|
?>
|
242
|
<form action="status_interfaces.php" method="post">
|
243
|
<input type="hidden" name="interface" value="<?php echo $ifdescr; ?>">
|
244
|
<?php if ($i): ?>
|
245
|
<tr>
|
246
|
<td colspan="8" class="list" height="12"></td>
|
247
|
</tr>
|
248
|
<?php endif; ?>
|
249
|
<tr>
|
250
|
<td colspan="2" class="listtopic">
|
251
|
<?=htmlspecialchars($ifname);?>
|
252
|
interface</td>
|
253
|
</tr>
|
254
|
<tr>
|
255
|
<td width="22%" class="vncellt">Status</td>
|
256
|
<td width="78%" class="listr">
|
257
|
<?=htmlspecialchars($ifinfo['status']);?>
|
258
|
</td>
|
259
|
</tr><?php if ($ifinfo['dhcplink']): ?>
|
260
|
<tr>
|
261
|
<td width="22%" class="vncellt">DHCP</td>
|
262
|
<td width="78%" class="listr">
|
263
|
<?=htmlspecialchars($ifinfo['dhcplink']);?>
|
264
|
<?php if ($ifinfo['dhcplink'] == "up"): ?>
|
265
|
<input type="submit" name="submit" value="Release" class="formbtns">
|
266
|
<?php else: ?>
|
267
|
<input type="submit" name="submit" value="Renew" class="formbtns">
|
268
|
<?php endif; ?>
|
269
|
</td>
|
270
|
</tr><?php endif; if ($ifinfo['pppoelink']): ?>
|
271
|
<tr>
|
272
|
<td width="22%" class="vncellt">PPPoE</td>
|
273
|
<td width="78%" class="listr">
|
274
|
<?=htmlspecialchars($ifinfo['pppoelink']);?>
|
275
|
<?php if ($ifinfo['pppoelink'] == "up"): ?>
|
276
|
<input type="submit" name="submit" value="Disconnect" class="formbtns">
|
277
|
<?php else: ?>
|
278
|
<input type="submit" name="submit" value="Connect" class="formbtns">
|
279
|
<?php endif; ?>
|
280
|
</td>
|
281
|
</tr><?php endif; if ($ifinfo['pptplink']): ?>
|
282
|
<tr>
|
283
|
<td width="22%" class="vncellt">PPTP</td>
|
284
|
<td width="78%" class="listr">
|
285
|
<?=htmlspecialchars($ifinfo['pptplink']);?>
|
286
|
<?php if ($ifinfo['pptplink'] == "up"): ?>
|
287
|
<input type="submit" name="submit" value="Disconnect" class="formbtns">
|
288
|
<?php else: ?>
|
289
|
<input type="submit" name="submit" value="Connect" class="formbtns">
|
290
|
<?php endif; ?>
|
291
|
</td>
|
292
|
</tr><?php endif; if ($ifinfo['macaddr']): ?>
|
293
|
<tr>
|
294
|
<td width="22%" class="vncellt">MAC address</td>
|
295
|
<td width="78%" class="listr">
|
296
|
<?=htmlspecialchars($ifinfo['macaddr']);?>
|
297
|
</td>
|
298
|
</tr>
|
299
|
</form>
|
300
|
<?php endif; if ($ifinfo['status'] != "down"): ?>
|
301
|
<?php if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down"): ?>
|
302
|
<?php if ($ifinfo['ipaddr']): ?>
|
303
|
<tr>
|
304
|
<td width="22%" class="vncellt">IP address</td>
|
305
|
<td width="78%" class="listr">
|
306
|
<?=htmlspecialchars($ifinfo['ipaddr']);?>
|
307
|
</td>
|
308
|
</tr><?php endif; ?><?php if ($ifinfo['subnet']): ?>
|
309
|
<tr>
|
310
|
<td width="22%" class="vncellt">Subnet mask</td>
|
311
|
<td width="78%" class="listr">
|
312
|
<?=htmlspecialchars($ifinfo['subnet']);?>
|
313
|
</td>
|
314
|
</tr><?php endif; ?><?php if ($ifinfo['gateway']): ?>
|
315
|
<tr>
|
316
|
<td width="22%" class="vncellt">Gateway</td>
|
317
|
<td width="78%" class="listr">
|
318
|
<?=htmlspecialchars($ifinfo['gateway']);?>
|
319
|
</td>
|
320
|
</tr><?php endif; if ($ifdescr == "wan" && file_exists("{$g['varetc_path']}/resolv.conf")): ?>
|
321
|
<td width="22%" class="vncellt">ISP DNS servers</td>
|
322
|
<td width="78%" class="listr">
|
323
|
<?php
|
324
|
$dns_servers = get_dns_servers();
|
325
|
foreach($dns_servers as $dns) {
|
326
|
echo "{$dns}<br>";
|
327
|
}
|
328
|
?>
|
329
|
</td>
|
330
|
<?php endif; endif; if ($ifinfo['media']): ?>
|
331
|
<tr>
|
332
|
<td width="22%" class="vncellt">Media</td>
|
333
|
<td width="78%" class="listr">
|
334
|
<?=htmlspecialchars($ifinfo['media']);?>
|
335
|
</td>
|
336
|
</tr><?php endif; ?><?php if ($ifinfo['channel']): ?>
|
337
|
<tr>
|
338
|
<td width="22%" class="vncellt">Channel</td>
|
339
|
<td width="78%" class="listr">
|
340
|
<?=htmlspecialchars($ifinfo['channel']);?>
|
341
|
</td>
|
342
|
</tr><?php endif; ?><?php if ($ifinfo['ssid']): ?>
|
343
|
<tr>
|
344
|
<td width="22%" class="vncellt">SSID</td>
|
345
|
<td width="78%" class="listr">
|
346
|
<?=htmlspecialchars($ifinfo['ssid']);?>
|
347
|
</td>
|
348
|
</tr><?php endif; ?>
|
349
|
<tr>
|
350
|
<td width="22%" class="vncellt">In/out packets</td>
|
351
|
<td width="78%" class="listr">
|
352
|
<?=htmlspecialchars($ifinfo['inpkts'] . "/" . $ifinfo['outpkts'] . " (" .
|
353
|
format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");?>
|
354
|
</td>
|
355
|
</tr><?php if (isset($ifinfo['inerrs'])): ?>
|
356
|
<tr>
|
357
|
<td width="22%" class="vncellt">In/out errors</td>
|
358
|
<td width="78%" class="listr">
|
359
|
<?=htmlspecialchars($ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);?>
|
360
|
</td>
|
361
|
</tr><?php endif; ?><?php if (isset($ifinfo['collisions'])): ?>
|
362
|
<tr>
|
363
|
<td width="22%" class="vncellt">Collisions</td>
|
364
|
<td width="78%" class="listr">
|
365
|
<?=htmlspecialchars($ifinfo['collisions']);?>
|
366
|
</td>
|
367
|
</tr><?php endif; ?>
|
368
|
<?php endif; ?>
|
369
|
<?php $i++; endforeach; ?>
|
370
|
</table>
|
371
|
<br/>
|
372
|
<strong class="red">Note:<br>
|
373
|
In/out counters will wrap at 32bit (4 Gigabyte) ! <br/>
|
374
|
</strong>Using dial-on-demand will bring the connection up again if any packet
|
375
|
triggers it. To substantiate this point: disconnecting manually
|
376
|
will <strong>not</strong> prevent dial-on-demand from making connections
|
377
|
to the outside! Don't use dial-on-demand if you want to make sure that the line
|
378
|
is kept disconnected.
|
379
|
|
380
|
<meta http-equiv="refresh" content="120;url=<?php print $_SERVER['PHP_SELF']; ?>">
|
381
|
|
382
|
<?php include("fend.inc"); ?>
|