Project

General

Profile

Download (13.2 KB) Statistics
| Branch: | Tag: | Revision:
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-2005 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
$pgtitle = array("Status", "Interfaces");
33
require("guiconfig.inc");
34

    
35
$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
function get_interface_info($ifdescr) {
59

    
60
	global $config, $g;
61

    
62
	$ifinfo = array();
63

    
64
	/* find out interface name */
65
	$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
66
	if ($ifdescr == "wan")
67
		$ifinfo['if'] = get_real_wan_interface();
68
	else
69
		$ifinfo['if'] = $ifinfo['hwif'];
70

    
71
	/* run netstat to determine link info */
72
	unset($linkinfo);
73
	exec("/usr/bin/netstat -I " . $ifinfo['hwif'] . " -nWb -f link", $linkinfo);
74
	$linkinfo = preg_split("/\s+/", $linkinfo[1]);
75
	if (preg_match("/\*$/", $linkinfo[0])) {
76
		$ifinfo['status'] = "down";
77
	} else {
78
		$ifinfo['status'] = "up";
79
	}
80

    
81
	if (!strstr($ifinfo['if'],'tun')) {
82
		$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

    
97
	/* 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

    
106
	/* 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

    
118
			$ifinfo['pppoelink'] = "up";
119

    
120
			foreach ($ifconfiginfo as $ici) {
121
				if (strpos($ici, 'LINK0') !== false)
122
					$ifinfo['pppoelink'] = "down";
123
			}
124
		}
125
	}
126

    
127
	/* 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

    
139
			$ifinfo['pptplink'] = "up";
140

    
141
			foreach ($ifconfiginfo as $ici) {
142
				if (strpos($ici, 'LINK0') !== false)
143
					$ifinfo['pptplink'] = "down";
144
			}
145
		}
146
	}
147

    
148
	if ($ifinfo['status'] == "up") {
149
		/* try to determine media with ifconfig */
150
		unset($ifconfiginfo);
151
		exec("/sbin/ifconfig " . $ifinfo['hwif'], $ifconfiginfo);
152

    
153
		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
			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
			}
176
		}
177

    
178
		if ($ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
179
			/* try to determine IP address and netmask with ifconfig */
180
			unset($ifconfiginfo);
181
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
182

    
183
			foreach ($ifconfiginfo as $ici) {
184
				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
				}
191
			}
192

    
193
			if ($ifdescr == "wan") {
194
				/* run netstat to determine the default gateway */
195
				unset($netstatrninfo);
196
				exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
197

    
198
				foreach ($netstatrninfo as $nsr) {
199
					if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
200
						$ifinfo['gateway'] = $matches[1];
201
					}
202
				}
203
			}
204
		}
205
	}
206

    
207
	return $ifinfo;
208
}
209

    
210
?>
211
<!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
<?php include("fbegin.inc"); ?>
221
<form action="status_interfaces.php" method="post">
222
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
223
              <?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
224

    
225
					for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
226
						$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
227
					}
228

    
229
			      foreach ($ifdescrs as $ifdescr => $ifname):
230
				  $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
              <tr>
238
                <td colspan="2" class="listtopic">
239
                  <?=htmlspecialchars($ifname);?>
240
                  interface</td>
241
              </tr>
242
              <tr>
243
                <td width="22%" class="vncellt">Status</td>
244
                <td width="78%" class="listr">
245
                  <?=htmlspecialchars($ifinfo['status']);?>
246
                </td>
247
              </tr><?php if ($ifinfo['dhcplink']): ?>
248
			  <tr>
249
				<td width="22%" class="vncellt">DHCP</td>
250
				<td width="78%" class="listr">
251
				  <?=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
              <tr>
260
                <td width="22%" class="vncellt">PPPoE</td>
261
                <td width="78%" class="listr">
262
                  <?=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
                </td>
269
              </tr><?php  endif; if ($ifinfo['pptplink']): ?>
270
              <tr>
271
                <td width="22%" class="vncellt">PPTP</td>
272
                <td width="78%" class="listr">
273
                  <?=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
                </td>
280
              </tr><?php  endif; if ($ifinfo['macaddr']): ?>
281
              <tr>
282
                <td width="22%" class="vncellt">MAC address</td>
283
                <td width="78%" class="listr">
284
                  <?=htmlspecialchars($ifinfo['macaddr']);?>
285
                </td>
286
              </tr><?php endif; if ($ifinfo['status'] != "down"): ?>
287
			  <?php if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down"): ?>
288
			  <?php if ($ifinfo['ipaddr']): ?>
289
              <tr>
290
                <td width="22%" class="vncellt">IP address</td>
291
                <td width="78%" class="listr">
292
                  <?=htmlspecialchars($ifinfo['ipaddr']);?>
293
                  &nbsp; </td>
294
              </tr><?php endif; ?><?php if ($ifinfo['subnet']): ?>
295
              <tr>
296
                <td width="22%" class="vncellt">Subnet mask</td>
297
                <td width="78%" class="listr">
298
                  <?=htmlspecialchars($ifinfo['subnet']);?>
299
                </td>
300
              </tr><?php endif; ?><?php if ($ifinfo['gateway']): ?>
301
              <tr>
302
                <td width="22%" class="vncellt">Gateway</td>
303
                <td width="78%" class="listr">
304
                  <?=htmlspecialchars($ifinfo['gateway']);?>
305
                </td>
306
              </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
              <tr>
311
                <td width="22%" class="vncellt">Media</td>
312
                <td width="78%" class="listr">
313
                  <?=htmlspecialchars($ifinfo['media']);?>
314
                </td>
315
              </tr><?php endif; ?><?php if ($ifinfo['channel']): ?>
316
              <tr>
317
                <td width="22%" class="vncellt">Channel</td>
318
                <td width="78%" class="listr">
319
                  <?=htmlspecialchars($ifinfo['channel']);?>
320
                </td>
321
              </tr><?php endif; ?><?php if ($ifinfo['ssid']): ?>
322
              <tr>
323
                <td width="22%" class="vncellt">SSID</td>
324
                <td width="78%" class="listr">
325
                  <?=htmlspecialchars($ifinfo['ssid']);?>
326
                </td>
327
              </tr><?php endif; ?>
328
              <tr>
329
                <td width="22%" class="vncellt">In/out packets</td>
330
                <td width="78%" class="listr">
331
                  <?=htmlspecialchars($ifinfo['inpkts'] . "/" . $ifinfo['outpkts'] . " (" .
332
				  		format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");?>
333
                </td>
334
              </tr><?php if (isset($ifinfo['inerrs'])): ?>
335
              <tr>
336
                <td width="22%" class="vncellt">In/out errors</td>
337
                <td width="78%" class="listr">
338
                  <?=htmlspecialchars($ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);?>
339
                </td>
340
              </tr><?php endif; ?><?php if (isset($ifinfo['collisions'])): ?>
341
              <tr>
342
                <td width="22%" class="vncellt">Collisions</td>
343
                <td width="78%" class="listr">
344
                  <?=htmlspecialchars($ifinfo['collisions']);?>
345
                </td>
346
              </tr><?php endif; ?>
347
	      <?php endif; ?>
348
              <?php $i++; endforeach; ?>
349
            </table>
350
</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
triggers it. To substantiate this point: disconnecting manually
355
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
<?php include("fend.inc"); ?>
(91-91/117)