Project

General

Profile

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