Project

General

Profile

Download (10.6 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

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

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

    
40
global $config;
41

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

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

    
67
// Display a term/definition pair
68
function showDef($show, $term, $def) {
69
	// Choose an icon by interface status
70
	if ($term == "Status") {
71
		if ($def == "up" || $def == "associated") {
72
			$icon = 'arrow-up text-success';
73
		} elseif ($def == "no carrier") {
74
			$icon = 'times-circle text-danger';
75
		} elseif ($def == "down") {
76
			$icon = 'arrow-down text-danger';
77
		} else {
78
			$icon = '';
79
		}
80
	}
81
	if ($show) {
82
		print('<dt>' . $term . '</dt>');
83
		print('<dd>' . htmlspecialchars($def) . ' <i class="fa fa-' . $icon . '"></i></dd>');
84
	}
85
}
86

    
87
// Display a term/definition pair with a button
88
function showDefBtn($show, $term, $def, $ifdescr, $btnlbl, $chkbox_relinquish_lease) {
89
	global $formtemplate;
90

    
91
	if ($show) {
92
		print('<dt>' . $term . '</dt>');
93
		print('<dd>');
94
		printf($formtemplate, $term, $ifdescr, $show, htmlspecialchars($def)	. ' ', $btnlbl, $btnlbl, $chkbox_relinquish_lease);
95
		print('</dd>');
96
	}
97
}
98

    
99
// Relinquish the DHCP lease from the server.
100
function dhcp_relinquish_lease($if, $ifdescr, $ipv) {
101
	$leases_db = '/var/db/dhclient.leases.' . $if;
102
	$conf_file = '/var/etc/dhclient_'.$ifdescr.'.conf';
103
	$script_file = '/usr/local/sbin/pfSense-dhclient-script';
104
	$ipv = ((int) $ipv == 6) ? '-6' : '-4';
105

    
106
	if (file_exists($leases_db) && file_exists($script_file)) {
107
		mwexec('/usr/local/sbin/dhclient {$ipv} -d -r' .
108
			' -lf ' . escapeshellarg($leases_db) .
109
			' -cf ' . escapeshellarg($conf_file) .
110
			' -sf ' . escapeshellarg($script_file));
111
	}
112
}
113

    
114
$pgtitle = array(gettext("Status"), gettext("Interfaces"));
115
$shortcut_section = "interfaces";
116
include("head.inc");
117

    
118
$ifdescrs = get_configured_interface_with_descr(true);
119
$ifinterrupts = interfaces_interrupts();
120

    
121
foreach ($ifdescrs as $ifdescr => $ifname):
122
	$ifinfo = get_interface_info($ifdescr);
123
	$mac_man = load_mac_manufacturer_table();
124

    
125
	$chkbox_relinquish_lease = 	'&nbsp;&nbsp;&nbsp;' .
126
								'<input type="checkbox" name="relinquish_lease" value="true" title="' . gettext("Send a gratuitous DHCP release packet to the server.") . '" /> ' . gettext("Relinquish Lease") .
127
								'<input type="hidden" name="if" value='.$ifinfo['if'].' />';
128
	$chkbox_relinquish_lease_v4 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=4 />';
129
	$chkbox_relinquish_lease_v6 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=6 />';
130

    
131
	$ifhwinfo = $ifinfo['hwif'];
132
	$vlan = interface_is_vlan($ifinfo['hwif']);
133
	if ($vlan && is_array($config['switches']['switch'][0]['vlangroups']['vlangroup'])) {
134
		foreach ($config['switches']['switch'][0]['vlangroups']['vlangroup'] as $vlangroup) {
135
			if ($vlangroup['vlanid'] == $vlan['tag']) {
136
				$ifhwinfo .= ', switchports: ' . $vlangroup['members'];
137
				break;
138
			}
139
		}
140
	}
141
?>
142

    
143
<div class="panel panel-default">
144
	<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($ifname)?><?=gettext(" Interface "); ?>(<?=htmlspecialchars($ifdescr)?>, <?=htmlspecialchars($ifhwinfo)?>)</h2></div>
145
	<div class="panel-body">
146
		<dl class="dl-horizontal">
147
<?php
148
		showDef(true, gettext("Status"), $ifinfo['enable'] ? $ifinfo['status'] : gettext('disabled'));
149
		showDefBtn($ifinfo['dhcplink'], 'DHCP', $ifinfo['dhcplink'], $ifdescr, (($ifinfo['dhcplink'] == "up") ? gettext("Release") : gettext("Renew")) . " {$ifname}", $ifinfo['dhcplink'] == "up" ? $chkbox_relinquish_lease_v4 : '');
150
		showDefBtn($ifinfo['dhcp6link'], 'DHCP6', $ifinfo['dhcp6link'], $ifdescr, (($ifinfo['dhcp6link'] == "up") ? gettext("Release") : gettext("Renew")) . " {$ifname}", $ifinfo['dhcp6link'] == "up" ? $chkbox_relinquish_lease_v6 : '');
151
		showDefBtn($ifinfo['pppoelink'], 'PPPoE', $ifinfo['pppoelink'], $ifdescr, (($ifinfo['pppoelink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
152
		showDefBtn($ifinfo['pptplink'], 'PPTP', $ifinfo['pptplink'], $ifdescr, (($ifinfo['pptplink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
153
		showDefBtn($ifinfo['l2tplink'], 'L2TP', $ifinfo['l2tplink'], $ifdescr, (($ifinfo['l2tplink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
154
		showDefBtn($ifinfo['ppplink'], 'PPP', $ifinfo['ppplink'], $ifdescr, (($ifinfo['ppplink'] == "up" && !$ifinfo['nodevice']) ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
155
		showDef($ifinfo['ppp_uptime'] || $ifinfo['ppp_uptime_accumulated'], gettext("Uptime") . ' ' . ($ifinfo['ppp_uptime_accumulated'] ? gettext('(historical)'):''), $ifinfo['ppp_uptime'] . $ifinfo['ppp_uptime_accumulated']);
156
		showDef($ifinfo['cell_rssi'], gettext("Cell Signal (RSSI)"), $ifinfo['cell_rssi']);
157
		showDef($ifinfo['cell_mode'], gettext("Cell Mode"), $ifinfo['cell_mode']);
158
		showDef($ifinfo['cell_simstate'], gettext("Cell SIM State"), $ifinfo['cell_simstate']);
159
		showDef($ifinfo['cell_service'], gettext("Cell Service"), $ifinfo['cell_service']);
160
		showDef($ifinfo['cell_bwupstream'], gettext("Cell Upstream"), $ifinfo['cell_bwupstream']);
161
		showDef($ifinfo['cell_bwdownstream'], gettext("Cell Downstream"), $ifinfo['cell_bwdownstream']);
162
		showDef($ifinfo['cell_upstream'], gettext("Cell Current Up"), $ifinfo['cell_upstream']);
163
		showDef($ifinfo['cell_downstream'], gettext("Cell Current Down"), $ifinfo['cell_downstream']);
164

    
165
		if ($ifinfo['macaddr']) {
166
			$mac=$ifinfo['macaddr'];
167
			$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
168
			showDef( $ifinfo['macaddr'], gettext('MAC Address'), $mac . (isset($mac_man[$mac_hi]) ? ' - ' . $mac_man[$mac_hi] : ''));
169
		}
170

    
171
		if ($ifinfo['status'] != "down") {
172
			if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
173
				showDef($ifinfo['ipaddr'], gettext('IPv4 Address'), $ifinfo['ipaddr']);
174
				showDef($ifinfo['subnet'], gettext('Subnet mask IPv4'), $ifinfo['subnet']);
175
				showDef($ifinfo['gateway'], gettext('Gateway IPv4'), $ifinfo['gateway']);
176
				showDef($ifinfo['linklocal'], gettext('IPv6 Link Local'), $ifinfo['linklocal']);
177
				showDef($ifinfo['ipaddrv6'], gettext('IPv6 Address'), $ifinfo['ipaddrv6']);
178
				showDef($ifinfo['subnetv6'], gettext('Subnet mask IPv6'), $ifinfo['subnetv6']);
179
				showDef($ifinfo['gatewayv6'], gettext("Gateway IPv6"), $config['interfaces'][$ifdescr]['gatewayv6'] . " " . $ifinfo['gatewayv6']);
180

    
181
				$dns_servers = get_dynamic_nameservers($ifdescr);
182
				$dnscnt = 0;
183
				foreach ($dns_servers as $dns) {
184
					showDef(true, $dnscnt == 0 ? gettext('DNS servers'):'', $dns);
185
					$dnscnt++;
186
				}
187
			}
188

    
189
			if ($ifinfo['laggport']) {
190
				$laggport = get_lagg_ports($ifinfo['laggport']);
191
			}
192

    
193
			showDef($ifinfo['mtu'], gettext("MTU"), $ifinfo['mtu']);
194
			showDef($ifinfo['media'], gettext("Media"), $ifinfo['media']);
195
			showDef($ifinfo['laggproto'], gettext("LAGG Protocol"), $ifinfo['laggproto']);
196
			showDef($ifinfo['laggport'], gettext("LAGG Ports"), $laggport);
197
			showDef($ifinfo['channel'], gettext("Channel"), $ifinfo['channel']);
198
			showDef($ifinfo['ssid'], gettext("SSID"), $ifinfo['ssid']);
199
			showDef($ifinfo['bssid'], gettext("BSSID"), $ifinfo['bssid']);
200
			showDef($ifinfo['rate'], gettext("Rate"), $ifinfo['rate']);
201
			showDef($ifinfo['rssi'], gettext("RSSI"), $ifinfo['rssi']);
202
			showDef(true, gettext("In/out packets"),
203
			    $ifinfo['inpkts'] . '/' . $ifinfo['outpkts'] . " (" . format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");
204
			showDef(true, gettext("In/out packets (pass)"),
205
			    $ifinfo['inpktspass'] . '/' . $ifinfo['outpktspass'] . " (" . format_bytes($ifinfo['inbytespass']) . "/" . format_bytes($ifinfo['outbytespass']) . ")");
206
			showDef(true, gettext("In/out packets (block)"),
207
			    $ifinfo['inpktsblock'] . '/' . $ifinfo['outpktsblock'] . " (" . format_bytes($ifinfo['inbytesblock']) . "/" . format_bytes($ifinfo['outbytesblock']) . ")");
208
			showDef(isset($ifinfo['inerrs']), gettext("In/out errors"), $ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);
209
			showDef(isset($ifinfo['collisions']), gettext("Collisions"), $ifinfo['collisions']);
210
		} // e-o-if ($ifinfo['status'] != "down")
211

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

    
214
		if (is_array($ifinterrupts[$ifinfo['hwif']])) {
215
			$interrupt_total = $ifinterrupts[$ifinfo['hwif']]['total'];
216
			$interrupt_sec = $ifinterrupts[$ifinfo['hwif']]['rate'];
217
			showDef($interrupt_total, gettext('Interrupts'), $interrupt_total . " (" . $interrupt_sec . "/s)");
218
		}
219
?>
220
		</dl>
221
	</div>
222
</div>
223

    
224
<?php
225
	endforeach;
226

    
227
print_info_box(sprintf(gettext('Using dial-on-demand will bring the connection up again if any packet ' .
228
	    'triggers it. To substantiate this point: disconnecting manually ' .
229
	    'will %1$snot%2$s prevent dial-on-demand from making connections ' .
230
	    'to the outside! Don\'t use dial-on-demand if the line ' .
231
	    'is to be kept disconnected.'), '<strong>', '</strong>'), 'warning', false);
232
include("foot.inc");
233
?>
(164-164/228)