Project

General

Profile

Download (10 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status_interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-status-interfaces
28
##|*NAME=Status: Interfaces
29
##|*DESCR=Allow access to the 'Status: Interfaces' page.
30
##|*MATCH=status_interfaces.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("interfaces.inc");
35
require_once("pfsense-utils.inc");
36
require_once("util.inc");
37

    
38
if ($_POST['ifdescr'] && $_POST['submit']) {
39
	$interface = $_POST['ifdescr'];
40
	if ($_POST['status'] == "up") {
41
		if ($_POST['relinquish_lease']) {
42
			dhcp_relinquish_lease($_POST['if'], $_POST['ifdescr'], $_POST['ipv']);
43
		}
44
		interface_bring_down($interface);
45
	} else {
46
		interface_configure($interface);
47
	}
48
	header("Location: status_interfaces.php");
49
	exit;
50
}
51

    
52
$formtemplate = '<form name="%s" action="status_interfaces.php" method="post">' .
53
					'<input type="hidden" name="ifdescr" value="%s" />' .
54
					'<input type="hidden" name="status" value="%s" />' .
55
					'%s' .
56
					'<button type="submit" name="submit" class="btn btn-warning btn-xs" value="%s">' .
57
					'<i class="fa fa-refresh icon-embed-btn"></i>' .
58
					'%s' .
59
					'</button>' .
60
					'%s' .
61
					'</form>';
62

    
63
// Display a term/definition pair
64
function showDef($show, $term, $def) {
65
	if ($show) {
66
		print('<dt>' . $term . '</dt>');
67
		print('<dd>' . htmlspecialchars($def) . '</dd>');
68
	}
69
}
70

    
71
// Display a term/definition pair with a button
72
function showDefBtn($show, $term, $def, $ifdescr, $btnlbl, $chkbox_relinquish_lease) {
73
	global $formtemplate;
74

    
75
	if ($show) {
76
		print('<dt>' . $term . '</dt>');
77
		print('<dd>');
78
		printf($formtemplate, $term, $ifdescr, $show, htmlspecialchars($def)	. ' ', $btnlbl, $btnlbl, $chkbox_relinquish_lease);
79
		print('</dd>');
80
	}
81
}
82

    
83
// Relinquish the DHCP lease from the server.
84
function dhcp_relinquish_lease($if, $ifdescr, $ipv) {
85
	$leases_db = '/var/db/dhclient.leases.' . $if;
86
	$conf_file = '/var/etc/dhclient_'.$ifdescr.'.conf';
87
	$script_file = '/usr/local/sbin/pfSense-dhclient-script';
88
	$ipv = ((int) $ipv == 6) ? '-6' : '-4';
89

    
90
	if (file_exists($leases_db) && file_exists($script_file)) {
91
		mwexec('/usr/local/sbin/dhclient {$ipv} -d -r' .
92
			' -lf ' . escapeshellarg($leases_db) .
93
			' -cf ' . escapeshellarg($conf_file) .
94
			' -sf ' . escapeshellarg($script_file));
95
	}
96
}
97

    
98
$pgtitle = array(gettext("Status"), gettext("Interfaces"));
99
$shortcut_section = "interfaces";
100
include("head.inc");
101

    
102
$ifdescrs = get_configured_interface_with_descr(true);
103

    
104
foreach ($ifdescrs as $ifdescr => $ifname):
105
	$ifinfo = get_interface_info($ifdescr);
106
	$mac_man = load_mac_manufacturer_table();
107

    
108
	$chkbox_relinquish_lease = 	'&nbsp;&nbsp;&nbsp;' .
109
								'<input type="checkbox" name="relinquish_lease" value="true" title="' . gettext("Send a gratuitous DHCP release packet to the server.") . '" /> ' . gettext("Relinquish Lease") .
110
								'<input type="hidden" name="if" value='.$ifinfo['if'].' />';
111
	$chkbox_relinquish_lease_v4 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=4 />';
112
	$chkbox_relinquish_lease_v6 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=6 />';
113
?>
114

    
115
<div class="panel panel-default">
116
	<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($ifname)?><?=gettext(" Interface "); ?>(<?=htmlspecialchars($ifdescr)?>, <?=htmlspecialchars($ifinfo['hwif'])?>)</h2></div>
117
	<div class="panel-body">
118
		<dl class="dl-horizontal">
119
<?php
120
		showDef(true, gettext("Status"), $ifinfo['enable'] ? $ifinfo['status'] : gettext('disabled'));
121
		showDefBtn($ifinfo['dhcplink'], 'DHCP', $ifinfo['dhcplink'], $ifdescr, $ifinfo['dhcplink'] == "up" ? gettext("Release") : gettext("Renew"), $ifinfo['dhcplink'] == "up" ? $chkbox_relinquish_lease_v4 : '');
122
		showDefBtn($ifinfo['dhcp6link'], 'DHCP6', $ifinfo['dhcp6link'], $ifdescr, $ifinfo['dhcp6link'] == "up" ? gettext("Release") : gettext("Renew"), $ifinfo['dhcp6link'] == "up" ? $chkbox_relinquish_lease_v6 : '');
123
		showDefBtn($ifinfo['pppoelink'], 'PPPoE', $ifinfo['pppoelink'], $ifdescr, $ifinfo['pppoelink'] == "up" ? gettext("Disconnect") : gettext("Connect"), '');
124
		showDefBtn($ifinfo['pptplink'], 'PPTP', $ifinfo['pptplink'], $ifdescr, $ifinfo['pptplink'] == "up" ? gettext("Disconnect") : gettext("Connect"), '');
125
		showDefBtn($ifinfo['l2tplink'], 'L2TP', $ifinfo['l2tplink'], $ifdescr, $ifinfo['l2tplink'] == "up" ? gettext("Disconnect") : gettext("Connect"), '');
126
		showDefBtn($ifinfo['ppplink'], 'PPP', $ifinfo['ppplink'], $ifdescr, ($ifinfo['ppplink'] == "up" && !$ifinfo['nodevice']) ? gettext("Disconnect") : gettext("Connect"), '');
127
		showDef($ifinfo['ppp_uptime'] || $ifinfo['ppp_uptime_accumulated'], gettext("Uptime") . ' ' . ($ifinfo['ppp_uptime_accumulated'] ? gettext('(historical)'):''), $ifinfo['ppp_uptime'] . $ifinfo['ppp_uptime_accumulated']);
128
		showDef($ifinfo['cell_rssi'], gettext("Cell Signal (RSSI)"), $ifinfo['cell_rssi']);
129
		showDef($ifinfo['cell_mode'], gettext("Cell Mode"), $ifinfo['cell_mode']);
130
		showDef($ifinfo['cell_simstate'], gettext("Cell SIM State"), $ifinfo['cell_simstate']);
131
		showDef($ifinfo['cell_service'], gettext("Cell Service"), $ifinfo['cell_service']);
132
		showDef($ifinfo['cell_bwupstream'], gettext("Cell Upstream"), $ifinfo['cell_bwupstream']);
133
		showDef($ifinfo['cell_bwdownstream'], gettext("Cell Downstream"), $ifinfo['cell_bwdownstream']);
134
		showDef($ifinfo['cell_upstream'], gettext("Cell Current Up"), $ifinfo['cell_upstream']);
135
		showDef($ifinfo['cell_downstream'], gettext("Cell Current Down"), $ifinfo['cell_downstream']);
136

    
137
		if ($ifinfo['macaddr']) {
138
			$mac=$ifinfo['macaddr'];
139
			$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
140
			showDef( $ifinfo['macaddr'], gettext('MAC Address'), $mac . (isset($mac_man[$mac_hi]) ? ' - ' . $mac_man[$mac_hi] : ''));
141
		}
142

    
143
		if ($ifinfo['status'] != "down") {
144
			if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
145
				showDef($ifinfo['ipaddr'], gettext('IPv4 Address'), $ifinfo['ipaddr']);
146
				showDef($ifinfo['subnet'], gettext('Subnet mask IPv4'), $ifinfo['subnet']);
147
				showDef($ifinfo['gateway'], gettext('Gateway IPv4'), $ifinfo['gateway']);
148
				showDef($ifinfo['linklocal'], gettext('IPv6 Link Local'), $ifinfo['linklocal']);
149
				showDef($ifinfo['ipaddrv6'], gettext('IPv6 Address'), $ifinfo['ipaddrv6']);
150
				showDef($ifinfo['subnetv6'], gettext('Subnet mask IPv6'), $ifinfo['subnetv6']);
151
				showDef($ifinfo['gatewayv6'], gettext("Gateway IPv6"), $config['interfaces'][$ifdescr]['gatewayv6'] . " " . $ifinfo['gatewayv6']);
152

    
153
				if ($ifdescr == "wan" && file_exists("{$g['etc_path']}/resolv.conf")) {
154
					$dns_servers = get_dns_servers();
155
					$dnscnt = 0;
156
					foreach ($dns_servers as $dns) {
157
						showDef(true, $dnscnt == 0 ? gettext('DNS servers'):'', $dns);
158
						$dnscnt++;
159
					}
160
				}
161
			}
162

    
163
			showDef($ifinfo['mtu'], gettext("MTU"), $ifinfo['mtu']);
164
			showDef($ifinfo['media'], gettext("Media"), $ifinfo['media']);
165
			showDef($ifinfo['laggproto'], gettext("LAGG Protocol"), $ifinfo['laggproto']);
166
			showDef($ifinfo['laggport'], gettext("LAGG Ports"), $laggport);
167
			showDef($ifinfo['channel'], gettext("Channel"), $ifinfo['channel']);
168
			showDef($ifinfo['ssid'], gettext("SSID"), $ifinfo['ssid']);
169
			showDef($ifinfo['bssid'], gettext("BSSID"), $ifinfo['bssid']);
170
			showDef($ifinfo['rate'], gettext("Rate"), $ifinfo['rate']);
171
			showDef($ifinfo['rssi'], gettext("RSSI"), $ifinfo['rssi']);
172
			showDef(true, gettext("In/out packets"),
173
			    $ifinfo['inpkts'] . '/' . $ifinfo['outpkts'] . " (" . format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");
174
			showDef(true, gettext("In/out packets (pass)"),
175
			    $ifinfo['inpktspass'] . '/' . $ifinfo['outpktspass'] . " (" . format_bytes($ifinfo['inbytespass']) . "/" . format_bytes($ifinfo['outbytespass']) . ")");
176
			showDef(true, gettext("In/out packets (block)"),
177
			    $ifinfo['inpktsblock'] . '/' . $ifinfo['outpktsblock'] . " (" . format_bytes($ifinfo['inbytesblock']) . "/" . format_bytes($ifinfo['outbytesblock']) . ")");
178
			showDef(isset($ifinfo['inerrs']), gettext("In/out errors"), $ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);
179
			showDef(isset($ifinfo['collisions']), gettext("Collisions"), $ifinfo['collisions']);
180
		} // e-o-if ($ifinfo['status'] != "down")
181

    
182
		showDef($ifinfo['bridge'], sprintf(gettext('Bridge (%1$s)'), $ifinfo['bridgeint']), $ifinfo['bridge']);
183

    
184
		if (file_exists("/usr/bin/vmstat")) {
185
			$real_interface = "";
186
			$interrupt_total = "";
187
			$interrupt_sec = "";
188
			$real_interface = $ifinfo['hwif'];
189
			$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $3 }'`;
190
			$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
191

    
192
			if (strstr($interrupt_total, "hci")) {
193
				$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
194
				$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $5 }'`;
195
			}
196

    
197
			unset($interrupt_total);
198

    
199
			showDef($interrupt_total, gettext('Total interrupts'), $interrupt_total);
200
			showDef($interrupt_total, '', $interrupt_sec . " " . $interrupt_total);
201
		}
202
?>
203
		</dl>
204
	</div>
205
</div>
206

    
207
<?php
208
	endforeach;
209

    
210
print_info_box(sprintf(gettext('Using dial-on-demand will bring the connection up again if any packet ' .
211
	    'triggers it. To substantiate this point: disconnecting manually ' .
212
	    'will %1$snot%2$s prevent dial-on-demand from making connections ' .
213
	    'to the outside! Don\'t use dial-on-demand if the line ' .
214
	    'is to be kept disconnected.'), '<strong>', '</strong>'), 'warning', false);
215
include("foot.inc");
216
?>
(170-170/234)