Project

General

Profile

Download (13.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 8cccee1c Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4
	status_interfaces.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 8cccee1c Scott Ullrich
7 c26e2cf0 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8 5b237745 Scott Ullrich
	All rights reserved.
9 8cccee1c Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 8cccee1c Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 8cccee1c Scott Ullrich
16 5b237745 Scott Ullrich
	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 8cccee1c Scott Ullrich
20 5b237745 Scott Ullrich
	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 c26e2cf0 Scott Ullrich
$pgtitle = array("Status", "Interfaces");
33 5b237745 Scott Ullrich
require("guiconfig.inc");
34
35 c26e2cf0 Scott Ullrich
$wancfg = &$config['interfaces']['wan'];
36
37
if ($_POST) {
38
	if ($_POST['submit'] == "Disconnect" || $_POST['submit'] == "Release") {
39
		if ($wancfg['ipaddr'] == "dhcp")
40
			interfaces_wan_dhcp_down();
41
		else if ($wancfg['ipaddr'] == "pppoe")
42
			interfaces_wan_pppoe_down();
43
		else if ($wancfg['ipaddr'] == "pptp")
44
			interfaces_wan_pptp_down();
45
	} else if ($_POST['submit'] == "Connect" || $_POST['submit'] == "Renew") {
46
		if ($wancfg['ipaddr'] == "dhcp")
47
			interfaces_wan_dhcp_up();
48
		else if ($wancfg['ipaddr'] == "pppoe")
49
			interfaces_wan_pppoe_up();
50
		else if ($wancfg['ipaddr'] == "pptp")
51
			interfaces_wan_pptp_up();
52
	} else {
53
		header("Location: index.php");
54
		exit;
55
	}
56
}
57
58 5b237745 Scott Ullrich
function get_interface_info($ifdescr) {
59 8cccee1c Scott Ullrich
60 5b237745 Scott Ullrich
	global $config, $g;
61 8cccee1c Scott Ullrich
62 5b237745 Scott Ullrich
	$ifinfo = array();
63 8cccee1c Scott Ullrich
64 5b237745 Scott Ullrich
	/* find out interface name */
65 c26e2cf0 Scott Ullrich
	$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
66 5b237745 Scott Ullrich
	if ($ifdescr == "wan")
67
		$ifinfo['if'] = get_real_wan_interface();
68
	else
69 c26e2cf0 Scott Ullrich
		$ifinfo['if'] = $ifinfo['hwif'];
70 8cccee1c Scott Ullrich
71 5b237745 Scott Ullrich
	/* run netstat to determine link info */
72
	unset($linkinfo);
73 c26e2cf0 Scott Ullrich
	exec("/usr/bin/netstat -I " . $ifinfo['hwif'] . " -nWb -f link", $linkinfo);
74 5b237745 Scott Ullrich
	$linkinfo = preg_split("/\s+/", $linkinfo[1]);
75
	if (preg_match("/\*$/", $linkinfo[0])) {
76
		$ifinfo['status'] = "down";
77
	} else {
78
		$ifinfo['status'] = "up";
79
	}
80 8cccee1c Scott Ullrich
81 c26e2cf0 Scott Ullrich
	if (!strstr($ifinfo['if'],'tun')) {
82 5b237745 Scott Ullrich
		$ifinfo['macaddr'] = $linkinfo[3];
83
		$ifinfo['inpkts'] = $linkinfo[4];
84
		$ifinfo['inerrs'] = $linkinfo[5];
85
		$ifinfo['inbytes'] = $linkinfo[6];
86
		$ifinfo['outpkts'] = $linkinfo[7];
87
		$ifinfo['outerrs'] = $linkinfo[8];
88
		$ifinfo['outbytes'] = $linkinfo[9];
89
		$ifinfo['collisions'] = $linkinfo[10];
90
	} else {
91
		$ifinfo['inpkts'] = $linkinfo[3];
92
		$ifinfo['inbytes'] = $linkinfo[5];
93
		$ifinfo['outpkts'] = $linkinfo[6];
94
		$ifinfo['outbytes'] = $linkinfo[8];
95
	}
96 8cccee1c Scott Ullrich
97 c26e2cf0 Scott Ullrich
	/* DHCP? -> see if dhclient is up */
98
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "dhcp")) {
99
		/* see if dhclient is up */
100
		if ($ifinfo['status'] == "up" && file_exists("{$g['varrun_path']}/dhclient.pid"))
101
			$ifinfo['dhcplink'] = "up";
102
		else
103
			$ifinfo['dhcplink'] = "down";
104
	}
105 8cccee1c Scott Ullrich
106 c26e2cf0 Scott Ullrich
	/* PPPoE interface? -> get status from virtual interface */
107
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pppoe")) {
108
		unset($linkinfo);
109
		exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
110
		$linkinfo = preg_split("/\s+/", $linkinfo[1]);
111
		if (preg_match("/\*$/", $linkinfo[0])) {
112
			$ifinfo['pppoelink'] = "down";
113
		} else {
114
			/* get PPPoE link status for dial on demand */
115
			unset($ifconfiginfo);
116
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
117 8cccee1c Scott Ullrich
118 c26e2cf0 Scott Ullrich
			$ifinfo['pppoelink'] = "up";
119 8cccee1c Scott Ullrich
120 c26e2cf0 Scott Ullrich
			foreach ($ifconfiginfo as $ici) {
121
				if (strpos($ici, 'LINK0') !== false)
122
					$ifinfo['pppoelink'] = "down";
123 5b237745 Scott Ullrich
			}
124
		}
125 c26e2cf0 Scott Ullrich
	}
126 8cccee1c Scott Ullrich
127 c26e2cf0 Scott Ullrich
	/* PPTP interface? -> get status from virtual interface */
128
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
129
		unset($linkinfo);
130
		exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
131
		$linkinfo = preg_split("/\s+/", $linkinfo[1]);
132
		if (preg_match("/\*$/", $linkinfo[0])) {
133
			$ifinfo['pptplink'] = "down";
134
		} else {
135
			/* get PPTP link status for dial on demand */
136
			unset($ifconfiginfo);
137
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
138 8cccee1c Scott Ullrich
139 c26e2cf0 Scott Ullrich
			$ifinfo['pptplink'] = "up";
140 8cccee1c Scott Ullrich
141 c26e2cf0 Scott Ullrich
			foreach ($ifconfiginfo as $ici) {
142
				if (strpos($ici, 'LINK0') !== false)
143
					$ifinfo['pptplink'] = "down";
144
			}
145
		}
146
	}
147 8cccee1c Scott Ullrich
148 c26e2cf0 Scott Ullrich
	if ($ifinfo['status'] == "up") {
149
		/* try to determine media with ifconfig */
150 5b237745 Scott Ullrich
		unset($ifconfiginfo);
151 c26e2cf0 Scott Ullrich
		exec("/sbin/ifconfig " . $ifinfo['hwif'], $ifconfiginfo);
152 8cccee1c Scott Ullrich
153 5b237745 Scott Ullrich
		foreach ($ifconfiginfo as $ici) {
154
			if (!isset($config['interfaces'][$ifdescr]['wireless'])) {
155
				/* don't list media/speed for wireless cards, as it always
156
				   displays 2 Mbps even though clients can connect at 11 Mbps */
157
				if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
158
					$ifinfo['media'] = $matches[1];
159
				} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
160
					$ifinfo['media'] = $matches[1];
161
				}
162
			}
163
			if (preg_match("/status: (.*)$/", $ici, $matches)) {
164
				if ($matches[1] != "active")
165
					$ifinfo['status'] = $matches[1];
166
			}
167
			if (preg_match("/channel (\S*)/", $ici, $matches)) {
168
				$ifinfo['channel'] = $matches[1];
169
			}
170 c26e2cf0 Scott Ullrich
			if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
171
				if ($matches[1][0] == '"')
172
					$ifinfo['ssid'] = substr($matches[1], 1, -1);
173
				else
174
					$ifinfo['ssid'] = $matches[1];
175 5b237745 Scott Ullrich
			}
176
		}
177 8cccee1c Scott Ullrich
178 c26e2cf0 Scott Ullrich
		if ($ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
179
			/* try to determine IP address and netmask with ifconfig */
180 5b237745 Scott Ullrich
			unset($ifconfiginfo);
181 c26e2cf0 Scott Ullrich
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
182 8cccee1c Scott Ullrich
183 5b237745 Scott Ullrich
			foreach ($ifconfiginfo as $ici) {
184 c26e2cf0 Scott Ullrich
				if (preg_match("/inet (\S+)/", $ici, $matches)) {
185
					$ifinfo['ipaddr'] = $matches[1];
186
				}
187
				if (preg_match("/netmask (\S+)/", $ici, $matches)) {
188
					if (preg_match("/^0x/", $matches[1]))
189
						$ifinfo['subnet'] = long2ip(hexdec($matches[1]));
190 5b237745 Scott Ullrich
				}
191
			}
192 8cccee1c Scott Ullrich
193 c26e2cf0 Scott Ullrich
			if ($ifdescr == "wan") {
194
				/* run netstat to determine the default gateway */
195
				unset($netstatrninfo);
196
				exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
197 8cccee1c Scott Ullrich
198 c26e2cf0 Scott Ullrich
				foreach ($netstatrninfo as $nsr) {
199
					if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
200
						$ifinfo['gateway'] = $matches[1];
201
					}
202
				}
203 5b237745 Scott Ullrich
			}
204
		}
205
	}
206 8cccee1c Scott Ullrich
207 5b237745 Scott Ullrich
	return $ifinfo;
208
}
209
210
?>
211 8cccee1c Scott Ullrich
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
212
<html>
213
<head>
214
<title><?=gentitle("pfSense webGUI");?></title>
215
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
216
<link href="gui.css" rel="stylesheet" type="text/css">
217
</head>
218
219
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
221 d875f273 Bill Marquette
<form action="status_interfaces.php" method="post">
222 5b237745 Scott Ullrich
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
223
              <?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
224 8cccee1c Scott Ullrich
225 5b237745 Scott Ullrich
					for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
226
						$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
227
					}
228 8cccee1c Scott Ullrich
229
			      foreach ($ifdescrs as $ifdescr => $ifname):
230 5b237745 Scott Ullrich
				  $ifinfo = get_interface_info($ifdescr);
231
				  ?>
232
              <?php if ($i): ?>
233
              <tr>
234
				  <td colspan="8" class="list" height="12"></td>
235
				</tr>
236
				<?php endif; ?>
237 8cccee1c Scott Ullrich
              <tr>
238
                <td colspan="2" class="listtopic">
239 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifname);?>
240
                  interface</td>
241
              </tr>
242 8cccee1c Scott Ullrich
              <tr>
243 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Status</td>
244 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
245 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['status']);?>
246
                </td>
247 c26e2cf0 Scott Ullrich
              </tr><?php if ($ifinfo['dhcplink']): ?>
248 8cccee1c Scott Ullrich
			  <tr>
249 c26e2cf0 Scott Ullrich
				<td width="22%" class="vncellt">DHCP</td>
250 8cccee1c Scott Ullrich
				<td width="78%" class="listr">
251 c26e2cf0 Scott Ullrich
				  <?=htmlspecialchars($ifinfo['dhcplink']);?>&nbsp;&nbsp;
252
				  <?php if ($ifinfo['dhcplink'] == "up"): ?>
253
				  <input type="submit" name="submit" value="Release" class="formbtns">
254
				  <?php else: ?>
255
				  <input type="submit" name="submit" value="Renew" class="formbtns">
256
				  <?php endif; ?>
257
				</td>
258
			  </tr><?php endif; if ($ifinfo['pppoelink']): ?>
259 8cccee1c Scott Ullrich
              <tr>
260 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">PPPoE</td>
261 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
262 c26e2cf0 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['pppoelink']);?>&nbsp;&nbsp;
263
				  <?php if ($ifinfo['pppoelink'] == "up"): ?>
264
				  <input type="submit" name="submit" value="Disconnect" class="formbtns">
265
				  <?php else: ?>
266
				  <input type="submit" name="submit" value="Connect" class="formbtns">
267
				  <?php endif; ?>
268 5b237745 Scott Ullrich
                </td>
269
              </tr><?php  endif; if ($ifinfo['pptplink']): ?>
270 8cccee1c Scott Ullrich
              <tr>
271 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">PPTP</td>
272 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
273 c26e2cf0 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['pptplink']);?>&nbsp;&nbsp;
274
				  <?php if ($ifinfo['pptplink'] == "up"): ?>
275
				  <input type="submit" name="submit" value="Disconnect" class="formbtns">
276
				  <?php else: ?>
277
				  <input type="submit" name="submit" value="Connect" class="formbtns">
278
				  <?php endif; ?>
279 5b237745 Scott Ullrich
                </td>
280
              </tr><?php  endif; if ($ifinfo['macaddr']): ?>
281 8cccee1c Scott Ullrich
              <tr>
282 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">MAC address</td>
283 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
284 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['macaddr']);?>
285
                </td>
286
              </tr><?php endif; if ($ifinfo['status'] != "down"): ?>
287 c26e2cf0 Scott Ullrich
			  <?php if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down"): ?>
288 5b237745 Scott Ullrich
			  <?php if ($ifinfo['ipaddr']): ?>
289 8cccee1c Scott Ullrich
              <tr>
290 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">IP address</td>
291 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
292 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['ipaddr']);?>
293
                  &nbsp; </td>
294
              </tr><?php endif; ?><?php if ($ifinfo['subnet']): ?>
295 8cccee1c Scott Ullrich
              <tr>
296 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Subnet mask</td>
297 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
298 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['subnet']);?>
299
                </td>
300
              </tr><?php endif; ?><?php if ($ifinfo['gateway']): ?>
301 8cccee1c Scott Ullrich
              <tr>
302 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Gateway</td>
303 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
304 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['gateway']);?>
305
                </td>
306 c26e2cf0 Scott Ullrich
              </tr><?php endif; if ($ifdescr == "wan" && file_exists("{$g['varetc_path']}/nameservers.conf")): ?>
307
                <td width="22%" class="vncellt">ISP DNS servers</td>
308
                <td width="78%" class="listr"><?php echo nl2br(file_get_contents("{$g['varetc_path']}/nameservers.conf")); ?></td>
309
			  <?php endif; endif; if ($ifinfo['media']): ?>
310 8cccee1c Scott Ullrich
              <tr>
311 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Media</td>
312 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
313 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['media']);?>
314
                </td>
315
              </tr><?php endif; ?><?php if ($ifinfo['channel']): ?>
316 8cccee1c Scott Ullrich
              <tr>
317 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Channel</td>
318 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
319 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['channel']);?>
320
                </td>
321
              </tr><?php endif; ?><?php if ($ifinfo['ssid']): ?>
322 8cccee1c Scott Ullrich
              <tr>
323 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">SSID</td>
324 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
325 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['ssid']);?>
326
                </td>
327
              </tr><?php endif; ?>
328 8cccee1c Scott Ullrich
              <tr>
329 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">In/out packets</td>
330 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
331
                  <?=htmlspecialchars($ifinfo['inpkts'] . "/" . $ifinfo['outpkts'] . " (" .
332 5b237745 Scott Ullrich
				  		format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");?>
333
                </td>
334
              </tr><?php if (isset($ifinfo['inerrs'])): ?>
335 8cccee1c Scott Ullrich
              <tr>
336 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">In/out errors</td>
337 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
338 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);?>
339
                </td>
340
              </tr><?php endif; ?><?php if (isset($ifinfo['collisions'])): ?>
341 8cccee1c Scott Ullrich
              <tr>
342 c26e2cf0 Scott Ullrich
                <td width="22%" class="vncellt">Collisions</td>
343 8cccee1c Scott Ullrich
                <td width="78%" class="listr">
344 5b237745 Scott Ullrich
                  <?=htmlspecialchars($ifinfo['collisions']);?>
345
                </td>
346
              </tr><?php endif; ?>
347
	      <?php endif; ?>
348
              <?php $i++; endforeach; ?>
349
            </table>
350 c26e2cf0 Scott Ullrich
</form>
351
<br>
352
<strong class="red">Note:<br>
353
</strong>Using dial-on-demand will bring the connection up again if any packet
354 8cccee1c Scott Ullrich
triggers it. To substantiate this point: disconnecting manually
355 c26e2cf0 Scott Ullrich
will <strong>not</strong> prevent dial-on-demand from making connections
356
to the outside! Don't use dial-on-demand if you want to make sure that the line is kept disconnected.
357 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>