Project

General

Profile

Download (16.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_interfaces.php
5
        part of pfSense
6
	Copyright (C) 2005 Scott Ullrich <sullrich@gmail.com>.
7
	All rights reserved.
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
require_once("guiconfig.inc");
36

    
37
$wancfg = &$config['interfaces']['wan'];
38

    
39
if ($_POST) {
40
	$interface = $_POST['interface'];
41
	$ifcfg = &$config['interfaces'][$interface];
42
	if ($_POST['submit'] == "Disconnect" || $_POST['submit'] == "Release") {
43
		if ($ifcfg['ipaddr'] == "dhcp")
44
			interfaces_dhcp_down($interface);
45
		else if ($ifcfg['ipaddr'] == "pppoe")
46
			interfaces_wan_pppoe_down(); // FIXME: when we support multi-pppoe
47
		else if ($ifcfg['ipaddr'] == "pptp")
48
			interfaces_wan_pptp_down(); // FIXME: when we support multi-pptp
49
	} else if ($_POST['submit'] == "Connect" || $_POST['submit'] == "Renew") {
50
		if ($ifcfg['ipaddr'] == "dhcp")
51
			interfaces_dhcp_up($interface);
52
		else if ($ifcfg['ipaddr'] == "pppoe")
53
			interfaces_wan_pppoe_up(); // FIXME: when we support multi-pppoe
54
		else if ($ifcfg['ipaddr'] == "pptp")
55
			interfaces_wan_pptp_up(); // FIXME: when we support multi-pptp
56
	} else {
57
		header("Location: index.php");
58
		exit;
59
	}
60
}
61

    
62
function get_interface_info($ifdescr) {
63

    
64
	global $config, $linkinfo, $netstatrninfo;
65

    
66
	$ifinfo = array();
67

    
68
	/* find out interface name */
69
	$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
70
	if ($ifdescr == "wan")
71
		$ifinfo['if'] = get_real_wan_interface();
72
	else
73
		$ifinfo['if'] = $ifinfo['hwif'];
74

    
75
	/* run netstat to determine link info */
76

    
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
			$ifconfiginfo = "";
132
			unset($ifconfiginfo);
133
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
134

    
135
			$ifinfo['pppoelink'] = "up";
136

    
137
			foreach ($ifconfiginfo as $ici) {
138
				if (strpos($ici, 'LINK0') !== false)
139
					$ifinfo['pppoelink'] = "down";
140
			}
141
		}
142
	}
143

    
144
	/* PPTP interface? -> get status from virtual interface */
145
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
146
		unset($linkinfo);
147
		exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
148
		$linkinfo = preg_split("/\s+/", $linkinfo[1]);
149
		if (preg_match("/\*$/", $linkinfo[0])) {
150
			$ifinfo['pptplink'] = "down";
151
		} else {
152
			/* get PPTP link status for dial on demand */
153
			unset($ifconfiginfo);
154
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
155

    
156
			$ifinfo['pptplink'] = "up";
157

    
158
			foreach ($ifconfiginfo as $ici) {
159
				if (strpos($ici, 'LINK0') !== false)
160
					$ifinfo['pptplink'] = "down";
161
			}
162
		}
163
	}
164

    
165
	if ($ifinfo['status'] == "up") {
166
		/* try to determine media with ifconfig */
167
		unset($ifconfiginfo);
168
		exec("/sbin/ifconfig " . $ifinfo['hwif'], $ifconfiginfo);
169
		$matches = "";
170
		foreach ($ifconfiginfo as $ici) {
171

    
172
			/* don't list media/speed for wireless cards, as it always
173
			   displays 2 Mbps even though clients can connect at 11 Mbps */
174
			if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
175
				$ifinfo['media'] = $matches[1];
176
			} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
177
				$ifinfo['media'] = $matches[1];
178
			} else if (preg_match("/media: IEEE 802.11 Wireless Ethernet (.*)/", $ici, $matches)) {
179
				$ifinfo['media'] = $matches[1];
180
			}
181

    
182
			if (preg_match("/status: (.*)$/", $ici, $matches)) {
183
				if ($matches[1] != "active")
184
					$ifinfo['status'] = $matches[1];
185
			}
186
			if (preg_match("/channel (\S*)/", $ici, $matches)) {
187
				$ifinfo['channel'] = $matches[1];
188
			}
189
			if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
190
				if ($matches[1][0] == '"')
191
					$ifinfo['ssid'] = substr($matches[1], 1, -1);
192
				else
193
					$ifinfo['ssid'] = $matches[1];
194
			}
195
		}
196

    
197
		if ($ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
198
			/* try to determine IP address and netmask with ifconfig */
199
			unset($ifconfiginfo);
200
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
201

    
202
			foreach ($ifconfiginfo as $ici) {
203
				if (preg_match("/inet (\S+)/", $ici, $matches)) {
204
					$ifinfo['ipaddr'] = $matches[1];
205
				}
206
				if (preg_match("/netmask (\S+)/", $ici, $matches)) {
207
					if (preg_match("/^0x/", $matches[1]))
208
						$ifinfo['subnet'] = long2ip(hexdec($matches[1]));
209
				}
210
			}
211

    
212
			if ($ifdescr == "wan") {
213
				/* run netstat to determine the default gateway */
214
				unset($netstatrninfo);
215
				exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
216

    
217
				foreach ($netstatrninfo as $nsr) {
218
					if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
219
						$ifinfo['gateway'] = $matches[1];
220
					}
221
				}
222
			} else {
223
				/* deterimine interface gateway */
224
				$int = convert_friendly_interface_to_real_interface_name($ifdescr);
225
				$gw = get_interface_gateway($int);
226
				if($gw)
227
					$ifinfo['gateway'] = $gw;
228
			}
229
		}
230
	}
231

    
232
	$bridge = "";
233
	$int = "";
234
	$int = convert_friendly_interface_to_real_interface_name($ifdescr);
235
	$bridge = link_int_to_bridge_interface($int);
236
	if($bridge) {
237
		$bridge_text = `/sbin/ifconfig {$bridge}`;
238
		if(stristr($bridge_text, "blocking") <> false) {
239
			$ifinfo['bridge'] = "<b><font color='red'>blocking</font></b> - check for ethernet loops";
240
			$ifinfo['bridgeint'] = $bridge;
241
		} else if(stristr($bridge_text, "learning") <> false) {
242
			$ifinfo['bridge'] = "learning";
243
			$ifinfo['bridgeint'] = $bridge;
244
		} else if(stristr($bridge_text, "forwarding") <> false) {
245
			$ifinfo['bridge'] = "forwarding";
246
			$ifinfo['bridgeint'] = $bridge;
247
		}
248
	}
249

    
250
	return $ifinfo;
251
}
252

    
253
$pgtitle = "Status: Interfaces";
254
include("head.inc");
255

    
256
?>
257

    
258
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
259
<?php include("fbegin.inc"); ?>
260
<p class="pgtitle"><?=$pgtitle?></p>
261
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
262
              <?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
263
		for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
264
			$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
265
		}
266
		foreach ($ifdescrs as $ifdescr => $ifname):
267
			$ifinfo = get_interface_info($ifdescr);
268
		?>
269
		<form action="status_interfaces.php" method="post">
270
		<input type="hidden" name="interface" value="<?php echo $ifdescr; ?>">
271
              <?php if ($i): ?>
272
              <tr>
273
			<td colspan="8" class="list" height="12"></td>
274
			</tr>
275
			<?php endif; ?>
276
              <tr>
277
                <td colspan="2" class="listtopic">
278
                  <?=htmlspecialchars($ifname);?>
279
				  interface
280
				  (<?=convert_friendly_interface_to_real_interface_name($ifname);?>)
281
				</td>
282
              </tr>
283
              <tr>
284
                <td width="22%" class="vncellt">Status</td>
285
                <td width="78%" class="listr">
286
                  <?=htmlspecialchars($ifinfo['status']);?>
287
                </td>
288
              </tr><?php if ($ifinfo['dhcplink']): ?>
289
			  <tr>
290
				<td width="22%" class="vncellt">DHCP</td>
291
				<td width="78%" class="listr">
292
				  <?=htmlspecialchars($ifinfo['dhcplink']);?>&nbsp;&nbsp;
293
				  <?php if ($ifinfo['dhcplink'] == "up"): ?>
294
				  <input type="submit" name="submit" value="Release" class="formbtns">
295
				  <?php else: ?>
296
				  <input type="submit" name="submit" value="Renew" class="formbtns">
297
				  <?php endif; ?>
298
				</td>
299
			  </tr><?php endif; if ($ifinfo['pppoelink']): ?>
300
              <tr>
301
                <td width="22%" class="vncellt">PPPoE</td>
302
                <td width="78%" class="listr">
303
                  <?=htmlspecialchars($ifinfo['pppoelink']);?>&nbsp;&nbsp;
304
				  <?php if ($ifinfo['pppoelink'] == "up"): ?>
305
				  <input type="submit" name="submit" value="Disconnect" class="formbtns">
306
				  <?php else: ?>
307
				  <input type="submit" name="submit" value="Connect" class="formbtns">
308
				  <?php endif; ?>
309
                </td>
310
              </tr><?php  endif; if ($ifinfo['pptplink']): ?>
311
              <tr>
312
                <td width="22%" class="vncellt">PPTP</td>
313
                <td width="78%" class="listr">
314
                  <?=htmlspecialchars($ifinfo['pptplink']);?>&nbsp;&nbsp;
315
				  <?php if ($ifinfo['pptplink'] == "up"): ?>
316
				  <input type="submit" name="submit" value="Disconnect" class="formbtns">
317
				  <?php else: ?>
318
				  <input type="submit" name="submit" value="Connect" class="formbtns">
319
				  <?php endif; ?>
320
                </td>
321
              </tr><?php  endif; if ($ifinfo['macaddr']): ?>
322
              <tr>
323
                <td width="22%" class="vncellt">MAC address</td>
324
                <td width="78%" class="listr">
325
                  <?=htmlspecialchars($ifinfo['macaddr']);?>
326
                </td>
327
              </tr>
328
	      </form>
329
		<?php endif; if ($ifinfo['status'] != "down"): ?>
330
			  <?php if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down"): ?>
331
			  <?php if ($ifinfo['ipaddr']): ?>
332
              <tr>
333
                <td width="22%" class="vncellt">IP address</td>
334
                <td width="78%" class="listr">
335
                  <?=htmlspecialchars($ifinfo['ipaddr']);?>
336
                  &nbsp; </td>
337
              </tr><?php endif; ?><?php if ($ifinfo['subnet']): ?>
338
              <tr>
339
                <td width="22%" class="vncellt">Subnet mask</td>
340
                <td width="78%" class="listr">
341
                  <?=htmlspecialchars($ifinfo['subnet']);?>
342
                </td>
343
              </tr><?php endif; ?><?php if ($ifinfo['gateway']): ?>
344
              <tr>
345
                <td width="22%" class="vncellt">Gateway</td>
346
                <td width="78%" class="listr">
347
                  <?=htmlspecialchars($ifinfo['gateway']);?>
348
                </td>
349
              </tr><?php endif; if ($ifdescr == "wan" && file_exists("{$g['varetc_path']}/resolv.conf")): ?>
350
                <td width="22%" class="vncellt">ISP DNS servers</td>
351
                <td width="78%" class="listr">
352
		<?php
353
			$dns_servers = get_dns_servers();
354
			foreach($dns_servers as $dns) {
355
				echo "{$dns}<br>";
356
			}
357
		?>
358
		</td>
359
			  <?php endif; endif; if ($ifinfo['media']): ?>
360
              <tr>
361
                <td width="22%" class="vncellt">Media</td>
362
                <td width="78%" class="listr">
363
                  <?=htmlspecialchars($ifinfo['media']);?>
364
                </td>
365
              </tr><?php endif; ?><?php if ($ifinfo['channel']): ?>
366
              <tr>
367
                <td width="22%" class="vncellt">Channel</td>
368
                <td width="78%" class="listr">
369
                  <?=htmlspecialchars($ifinfo['channel']);?>
370
                </td>
371
              </tr><?php endif; ?><?php if ($ifinfo['ssid']): ?>
372
              <tr>
373
                <td width="22%" class="vncellt">SSID</td>
374
                <td width="78%" class="listr">
375
                  <?=htmlspecialchars($ifinfo['ssid']);?>
376
                </td>
377
              </tr><?php endif; ?>
378
              <tr>
379
                <td width="22%" class="vncellt">In/out packets</td>
380
                <td width="78%" class="listr">
381
                  <?=htmlspecialchars($ifinfo['inpkts'] . "/" . $ifinfo['outpkts'] . " (" .
382
			format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");?>
383
                </td>
384
              </tr><?php if (isset($ifinfo['inerrs'])): ?>
385
              <tr>
386
                <td width="22%" class="vncellt">In/out errors</td>
387
                <td width="78%" class="listr">
388
                  <?=htmlspecialchars($ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);?>
389
                </td>
390
              </tr><?php endif; ?><?php if (isset($ifinfo['collisions'])): ?>
391
              <tr>
392
                <td width="22%" class="vncellt">Collisions</td>
393
                <td width="78%" class="listr">
394
                  <?=htmlspecialchars($ifinfo['collisions']);?>
395
                </td>
396
              </tr><?php endif; ?>
397
	      <?php endif; ?>
398

    
399
		  <?php if ($ifinfo['bridge']): ?>
400
		  <tr>
401
		    <td width="22%" class="vncellt">Bridge (<?=$ifinfo['bridgeint']?>)</td>
402
		    <td width="78%" class="listr">
403
		      <?=$ifinfo['bridge'];?>
404
		    </td>
405
		  </tr>
406
		  <?php endif; ?>
407

    
408
	<?php if(file_exists("/usr/bin/vmstat")): ?>
409
	<?php
410
			$real_interface = "";
411
			$interrupt_total = "";
412
			$interrupt_sec = "";
413
			$real_interface = convert_friendly_interface_to_real_interface_name($ifname);
414
          	$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $3 }'`;
415
          	$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
416
          	if(strstr($interrupt_total, "hci")) {
417
    	      	$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
418
	          	$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $5 }'`;          	
419
          	}	
420
          	$interrupt_total = "";
421
	?>
422
	<?php if($interrupt_total): ?>
423
     <tr>
424
        <td width="22%" class="vncellt">Interrupts/Second</td>
425
        <td width="78%" class="listr">
426
          <?php
427

    
428
          	echo $interrupt_total . " total";
429
          	echo "<br/>";
430
          	echo $interrupt_sec . " rate";
431
          ?>
432
        </td>
433
      </tr>
434
     <?php endif; ?>
435
	<?php endif; ?>
436
	
437
              <?php $i++; endforeach; ?>
438
            </table>
439
<br/>
440
</strong>Using dial-on-demand will bring the connection up again if any packet
441
triggers it. To substantiate this point: disconnecting manually
442
will <strong>not</strong> prevent dial-on-demand from making connections
443
to the outside! Don't use dial-on-demand if you want to make sure that the line
444
is kept disconnected.
445
<p>
446
<span class="red"><strong>Note:</strong></span> In/out counters will wrap at 32bit (4 Gigabyte) ! <br/>
447

    
448
<meta http-equiv="refresh" content="120;url=<?php print $_SERVER['SCRIPT_NAME']; ?>">
449

    
450
<?php include("fend.inc"); ?>
(125-125/171)