Project

General

Profile

Download (11.4 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-2024 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
if ($_POST['ifdescr'] && $_POST['submit']) {
41
	$interface = $_POST['ifdescr'];
42
	if ($_POST['status'] == "up") {
43
		if ($_POST['relinquish_lease']) {
44
			dhcp_relinquish_lease($_POST['if'], $_POST['ifdescr'], $_POST['ipv']);
45
		}
46
		interface_bring_down($interface);
47
		restart_interface_services($interface);
48
		filter_configure();
49
		system_routing_configure();
50
		send_event("service reload packages");
51
	} else {
52
		interface_configure($interface);
53
	}
54
	header("Location: status_interfaces.php");
55
	exit;
56
}
57

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

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

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

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

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

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

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

    
120
$ifdescrs = get_configured_interface_with_descr(true);
121
$ifinterrupts = interfaces_interrupts();
122
$switch_config = config_get_path('switches/switch/0/vlangroups/vlangroup', []);
123
$if_config = config_get_path('interfaces', []);
124
foreach ($ifdescrs as $ifdescr => $ifname):
125
	$ifinfo = get_interface_info($ifdescr);
126
	$mac_man = load_mac_manufacturer_table();
127

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

    
134
	$ifhwinfo = $ifinfo['hwif'];
135
	$vlan = interface_is_vlan($ifinfo['hwif']);
136
	if ($vlan) {
137
		foreach ($switch_config as $vlangroup) {
138
			if ($vlangroup['vlanid'] == $vlan['tag']) {
139
				$ifhwinfo .= ', switchports: ' . $vlangroup['members'];
140
				break;
141
			}
142
		}
143
	}
144
?>
145

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

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

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

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

    
192
			if ($ifinfo['laggport']) {
193
				$laggport = get_lagg_ports($ifinfo['laggport']);
194
			}
195

    
196
			showDef($ifinfo['mtu'], gettext("MTU"), $ifinfo['mtu']);
197
			showDef($ifinfo['media'], gettext("Media"), $ifinfo['media']);
198
			if ($ifinfo['plugged']) {
199
				showDef($ifinfo['plugged'], gettext("Plugged"), $ifinfo['plugged']);
200
			}
201
			if ($ifinfo['vendor']) {
202
				showDef($ifinfo['vendor'], gettext("Vendor"), $ifinfo['vendor']);
203
			}
204
			if ($ifinfo['temperature']) {
205
				showDef($ifinfo['temperature'], gettext("Temperature"), $ifinfo['temperature']);
206
			}
207
			if ($ifinfo['voltage']) {
208
				showDef($ifinfo['voltage'], gettext("Voltage"), $ifinfo['voltage']);
209
			}
210
			if ($ifinfo['rx']) {
211
				showDef($ifinfo['rx'], gettext("RX"), $ifinfo['rx']);
212
			}
213
			if ($ifinfo['tx']) {
214
				showDef($ifinfo['tx'], gettext("TX"), $ifinfo['tx']);
215
			}
216
			showDef($ifinfo['laggproto'], gettext("LAGG Protocol"), $ifinfo['laggproto']);
217
			showDef($ifinfo['laggport'], gettext("LAGG Ports"), $laggport);
218
			showDef($ifinfo['channel'], gettext("Channel"), $ifinfo['channel']);
219
			showDef($ifinfo['ssid'], gettext("SSID"), $ifinfo['ssid']);
220
			showDef($ifinfo['bssid'], gettext("BSSID"), $ifinfo['bssid']);
221
			showDef($ifinfo['rate'], gettext("Rate"), $ifinfo['rate']);
222
			showDef($ifinfo['rssi'], gettext("RSSI"), $ifinfo['rssi']);
223
			showDef(true, gettext("In/out packets"),
224
			    $ifinfo['inpkts'] . '/' . $ifinfo['outpkts'] . " (" . format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");
225
			showDef(true, gettext("In/out packets (pass)"),
226
			    $ifinfo['inpktspass'] . '/' . $ifinfo['outpktspass'] . " (" . format_bytes($ifinfo['inbytespass']) . "/" . format_bytes($ifinfo['outbytespass']) . ")");
227
			showDef(true, gettext("In/out packets (block)"),
228
			    $ifinfo['inpktsblock'] . '/' . $ifinfo['outpktsblock'] . " (" . format_bytes($ifinfo['inbytesblock']) . "/" . format_bytes($ifinfo['outbytesblock']) . ")");
229
			showDef(isset($ifinfo['inerrs']), gettext("In/out errors"), $ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);
230
			showDef(isset($ifinfo['collisions']), gettext("Collisions"), $ifinfo['collisions']);
231
		} // e-o-if ($ifinfo['status'] != "down")
232

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

    
235
		if (is_array($ifinterrupts[$ifinfo['hwif']])) {
236
			$interrupt_total = $ifinterrupts[$ifinfo['hwif']]['total'];
237
			$interrupt_sec = $ifinterrupts[$ifinfo['hwif']]['rate'];
238
			showDef($interrupt_total, gettext('Interrupts'), $interrupt_total . " (" . $interrupt_sec . "/s)");
239
		}
240
?>
241
		</dl>
242
	</div>
243
</div>
244

    
245
<?php
246
	endforeach;
247

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