Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1 8cccee1c Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * status_interfaces.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 402c98a2 Reid Linnemann
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 66c52114 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 66c52114 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * 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 66c52114 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 66c52114 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * 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 66c52114 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-status-interfaces
30 5230f468 jim-p
##|*NAME=Status: Interfaces
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: Interfaces' page.
32
##|*MATCH=status_interfaces.php*
33
##|-PRIV
34
35 51caa77a Scott Ullrich
require_once("guiconfig.inc");
36 8fbe2ea4 doktornotor
require_once("interfaces.inc");
37
require_once("pfsense-utils.inc");
38
require_once("util.inc");
39 5b237745 Scott Ullrich
40 4e5e99a6 Viktor G
global $config;
41
42 db0a2efc NOYB
if ($_POST['ifdescr'] && $_POST['submit']) {
43
	$interface = $_POST['ifdescr'];
44 42b0c921 Phil Davis
	if ($_POST['status'] == "up") {
45 718432f1 NOYB
		if ($_POST['relinquish_lease']) {
46
			dhcp_relinquish_lease($_POST['if'], $_POST['ifdescr'], $_POST['ipv']);
47
		}
48 80bf3f4a Ermal Luçi
		interface_bring_down($interface);
49 318714cb Viktor G
		restart_interface_services($interface);
50
		filter_configure();
51
		system_routing_configure();
52 6292f557 Viktor G
		send_event("service reload packages");
53 42b0c921 Phil Davis
	} else {
54 bd06568f sbeaver
		interface_configure($interface);
55 42b0c921 Phil Davis
	}
56 56e1d16e Ermal Lu?i
	header("Location: status_interfaces.php");
57
	exit;
58 c26e2cf0 Scott Ullrich
}
59
60 bd06568f sbeaver
$formtemplate = '<form name="%s" action="status_interfaces.php" method="post">' .
61 db0a2efc NOYB
					'<input type="hidden" name="ifdescr" value="%s" />' .
62 bd06568f sbeaver
					'<input type="hidden" name="status" value="%s" />' .
63
					'%s' .
64 b8b0c2a3 jim-p
					'<button type="submit" name="submit" class="btn btn-danger btn-xs" value="%s">' .
65 27d6a45b jim-p
					'<i class="fa fa-refresh icon-embed-btn"></i>' .
66
					'%s' .
67
					'</button>' .
68 718432f1 NOYB
					'%s' .
69 bd06568f sbeaver
					'</form>';
70
71
// Display a term/definition pair
72
function showDef($show, $term, $def) {
73 f35f9392 Viktor G
	// Choose an icon by interface status
74
	if ($term == "Status") {
75
		if ($def == "up" || $def == "associated") {
76
			$icon = 'arrow-up text-success';
77
		} elseif ($def == "no carrier") {
78
			$icon = 'times-circle text-danger';
79
		} elseif ($def == "down") {
80
			$icon = 'arrow-down text-danger';
81
		} else {
82
			$icon = '';
83
		}
84
	}
85 abe98adb Phil Davis
	if ($show) {
86 bd06568f sbeaver
		print('<dt>' . $term . '</dt>');
87 f35f9392 Viktor G
		print('<dd>' . htmlspecialchars($def) . ' <i class="fa fa-' . $icon . '"></i></dd>');
88 bd06568f sbeaver
	}
89
}
90
91
// Display a term/definition pair with a button
92 718432f1 NOYB
function showDefBtn($show, $term, $def, $ifdescr, $btnlbl, $chkbox_relinquish_lease) {
93 bd06568f sbeaver
	global $formtemplate;
94
95 abe98adb Phil Davis
	if ($show) {
96 bd06568f sbeaver
		print('<dt>' . $term . '</dt>');
97
		print('<dd>');
98 718432f1 NOYB
		printf($formtemplate, $term, $ifdescr, $show, htmlspecialchars($def)	. ' ', $btnlbl, $btnlbl, $chkbox_relinquish_lease);
99 bd06568f sbeaver
		print('</dd>');
100
	}
101
}
102
103 718432f1 NOYB
// Relinquish the DHCP lease from the server.
104
function dhcp_relinquish_lease($if, $ifdescr, $ipv) {
105
	$leases_db = '/var/db/dhclient.leases.' . $if;
106
	$conf_file = '/var/etc/dhclient_'.$ifdescr.'.conf';
107
	$script_file = '/usr/local/sbin/pfSense-dhclient-script';
108 c45cac34 jim-p
	$ipv = ((int) $ipv == 6) ? '-6' : '-4';
109 718432f1 NOYB
110
	if (file_exists($leases_db) && file_exists($script_file)) {
111 c45cac34 jim-p
		mwexec('/usr/local/sbin/dhclient {$ipv} -d -r' .
112
			' -lf ' . escapeshellarg($leases_db) .
113
			' -cf ' . escapeshellarg($conf_file) .
114
			' -sf ' . escapeshellarg($script_file));
115 718432f1 NOYB
	}
116
}
117
118 abe98adb Phil Davis
$pgtitle = array(gettext("Status"), gettext("Interfaces"));
119 b32dd0a6 jim-p
$shortcut_section = "interfaces";
120 4df96eff Scott Ullrich
include("head.inc");
121
122 f593f80b Phil Davis
$ifdescrs = get_configured_interface_with_descr(true);
123 e638072c Viktor G
$ifinterrupts = interfaces_interrupts();
124 8cccee1c Scott Ullrich
125 66c52114 Stephen Beaver
foreach ($ifdescrs as $ifdescr => $ifname):
126
	$ifinfo = get_interface_info($ifdescr);
127
	$mac_man = load_mac_manufacturer_table();
128 718432f1 NOYB
129
	$chkbox_relinquish_lease = 	'&nbsp;&nbsp;&nbsp;' .
130 d0718a0f NOYB
								'<input type="checkbox" name="relinquish_lease" value="true" title="' . gettext("Send a gratuitous DHCP release packet to the server.") . '" /> ' . gettext("Relinquish Lease") .
131 718432f1 NOYB
								'<input type="hidden" name="if" value='.$ifinfo['if'].' />';
132
	$chkbox_relinquish_lease_v4 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=4 />';
133
	$chkbox_relinquish_lease_v6 = $chkbox_relinquish_lease . '<input type="hidden" name="ipv" value=6 />';
134 4e5e99a6 Viktor G
135
	$ifhwinfo = $ifinfo['hwif'];
136
	$vlan = interface_is_vlan($ifinfo['hwif']);
137
	if ($vlan && is_array($config['switches']['switch'][0]['vlangroups']['vlangroup'])) {
138
		foreach ($config['switches']['switch'][0]['vlangroups']['vlangroup'] as $vlangroup) {
139
			if ($vlangroup['vlanid'] == $vlan['tag']) {
140
				$ifhwinfo .= ', switchports: ' . $vlangroup['members'];
141
				break;
142
			}
143
		}
144
	}
145 0d7b21de sullrich
?>
146 bd06568f sbeaver
147
<div class="panel panel-default">
148 4e5e99a6 Viktor G
	<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($ifname)?><?=gettext(" Interface "); ?>(<?=htmlspecialchars($ifdescr)?>, <?=htmlspecialchars($ifhwinfo)?>)</h2></div>
149 fb6c7bb8 sbeaver
	<div class="panel-body">
150
		<dl class="dl-horizontal">
151 0d7b21de sullrich
<?php
152 c5007d58 Phil Davis
		showDef(true, gettext("Status"), $ifinfo['enable'] ? $ifinfo['status'] : gettext('disabled'));
153 b8b0c2a3 jim-p
		showDefBtn($ifinfo['dhcplink'], 'DHCP', $ifinfo['dhcplink'], $ifdescr, (($ifinfo['dhcplink'] == "up") ? gettext("Release") : gettext("Renew")) . " {$ifname}", $ifinfo['dhcplink'] == "up" ? $chkbox_relinquish_lease_v4 : '');
154
		showDefBtn($ifinfo['dhcp6link'], 'DHCP6', $ifinfo['dhcp6link'], $ifdescr, (($ifinfo['dhcp6link'] == "up") ? gettext("Release") : gettext("Renew")) . " {$ifname}", $ifinfo['dhcp6link'] == "up" ? $chkbox_relinquish_lease_v6 : '');
155
		showDefBtn($ifinfo['pppoelink'], 'PPPoE', $ifinfo['pppoelink'], $ifdescr, (($ifinfo['pppoelink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
156
		showDefBtn($ifinfo['pptplink'], 'PPTP', $ifinfo['pptplink'], $ifdescr, (($ifinfo['pptplink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
157
		showDefBtn($ifinfo['l2tplink'], 'L2TP', $ifinfo['l2tplink'], $ifdescr, (($ifinfo['l2tplink'] == "up") ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
158
		showDefBtn($ifinfo['ppplink'], 'PPP', $ifinfo['ppplink'], $ifdescr, (($ifinfo['ppplink'] == "up" && !$ifinfo['nodevice']) ? gettext("Disconnect") : gettext("Connect")) . " {$ifname}", '');
159 7f0d6ccf Phil Davis
		showDef($ifinfo['ppp_uptime'] || $ifinfo['ppp_uptime_accumulated'], gettext("Uptime") . ' ' . ($ifinfo['ppp_uptime_accumulated'] ? gettext('(historical)'):''), $ifinfo['ppp_uptime'] . $ifinfo['ppp_uptime_accumulated']);
160 fb6c7bb8 sbeaver
		showDef($ifinfo['cell_rssi'], gettext("Cell Signal (RSSI)"), $ifinfo['cell_rssi']);
161
		showDef($ifinfo['cell_mode'], gettext("Cell Mode"), $ifinfo['cell_mode']);
162
		showDef($ifinfo['cell_simstate'], gettext("Cell SIM State"), $ifinfo['cell_simstate']);
163
		showDef($ifinfo['cell_service'], gettext("Cell Service"), $ifinfo['cell_service']);
164
		showDef($ifinfo['cell_bwupstream'], gettext("Cell Upstream"), $ifinfo['cell_bwupstream']);
165
		showDef($ifinfo['cell_bwdownstream'], gettext("Cell Downstream"), $ifinfo['cell_bwdownstream']);
166
		showDef($ifinfo['cell_upstream'], gettext("Cell Current Up"), $ifinfo['cell_upstream']);
167
		showDef($ifinfo['cell_downstream'], gettext("Cell Current Down"), $ifinfo['cell_downstream']);
168
169
		if ($ifinfo['macaddr']) {
170
			$mac=$ifinfo['macaddr'];
171
			$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
172 6bdfbf3b jim-p
			showDef( $ifinfo['macaddr'], gettext('MAC Address'), $mac . (isset($mac_man[$mac_hi]) ? ' - ' . $mac_man[$mac_hi] : ''));
173
		}
174 bd06568f sbeaver
175 fb6c7bb8 sbeaver
		if ($ifinfo['status'] != "down") {
176
			if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
177
				showDef($ifinfo['ipaddr'], gettext('IPv4 Address'), $ifinfo['ipaddr']);
178
				showDef($ifinfo['subnet'], gettext('Subnet mask IPv4'), $ifinfo['subnet']);
179
				showDef($ifinfo['gateway'], gettext('Gateway IPv4'), $ifinfo['gateway']);
180
				showDef($ifinfo['linklocal'], gettext('IPv6 Link Local'), $ifinfo['linklocal']);
181
				showDef($ifinfo['ipaddrv6'], gettext('IPv6 Address'), $ifinfo['ipaddrv6']);
182
				showDef($ifinfo['subnetv6'], gettext('Subnet mask IPv6'), $ifinfo['subnetv6']);
183 510e6f23 Chris Buechler
				showDef($ifinfo['gatewayv6'], gettext("Gateway IPv6"), $config['interfaces'][$ifdescr]['gatewayv6'] . " " . $ifinfo['gatewayv6']);
184 fb6c7bb8 sbeaver
185 35de5b66 Viktor G
				$dns_servers = get_dynamic_nameservers($ifdescr);
186 f0c51530 jim-p
				$dnscnt = 0;
187
				foreach ($dns_servers as $dns) {
188
					showDef(true, $dnscnt == 0 ? gettext('DNS servers'):'', $dns);
189
					$dnscnt++;
190 bd06568f sbeaver
				}
191 fb6c7bb8 sbeaver
			}
192 bd06568f sbeaver
193 84422a37 Viktor Gurov
			if ($ifinfo['laggport']) {
194 49e36202 Viktor Gurov
				$laggport = get_lagg_ports($ifinfo['laggport']);
195 84422a37 Viktor Gurov
			}
196
197 fb6c7bb8 sbeaver
			showDef($ifinfo['mtu'], gettext("MTU"), $ifinfo['mtu']);
198
			showDef($ifinfo['media'], gettext("Media"), $ifinfo['media']);
199 fc455333 Viktor G
			if ($ifinfo['plugged']) {
200
				showDef($ifinfo['plugged'], gettext("Plugged"), $ifinfo['plugged']);
201
			}
202
			if ($ifinfo['vendor']) {
203
				showDef($ifinfo['vendor'], gettext("Vendor"), $ifinfo['vendor']);
204
			}
205
			if ($ifinfo['temperature']) {
206
				showDef($ifinfo['temperature'], gettext("Temperature"), $ifinfo['temperature']);
207
			}
208
			if ($ifinfo['voltage']) {
209
				showDef($ifinfo['voltage'], gettext("voltage"), $ifinfo['voltage']);
210
			}
211 9f534f4b jim-p
			if ($ifinfo['rx']) {
212 fc455333 Viktor G
				showDef($ifinfo['rx'], gettext("RX"), $ifinfo['rx']);
213
			}
214 9f534f4b jim-p
			if ($ifinfo['tx']) {
215 fc455333 Viktor G
				showDef($ifinfo['tx'], gettext("TX"), $ifinfo['tx']);
216
			}
217 fb6c7bb8 sbeaver
			showDef($ifinfo['laggproto'], gettext("LAGG Protocol"), $ifinfo['laggproto']);
218 abe98adb Phil Davis
			showDef($ifinfo['laggport'], gettext("LAGG Ports"), $laggport);
219
			showDef($ifinfo['channel'], gettext("Channel"), $ifinfo['channel']);
220
			showDef($ifinfo['ssid'], gettext("SSID"), $ifinfo['ssid']);
221
			showDef($ifinfo['bssid'], gettext("BSSID"), $ifinfo['bssid']);
222
			showDef($ifinfo['rate'], gettext("Rate"), $ifinfo['rate']);
223
			showDef($ifinfo['rssi'], gettext("RSSI"), $ifinfo['rssi']);
224 34446ef7 Phil Davis
			showDef(true, gettext("In/out packets"),
225
			    $ifinfo['inpkts'] . '/' . $ifinfo['outpkts'] . " (" . format_bytes($ifinfo['inbytes']) . "/" . format_bytes($ifinfo['outbytes']) . ")");
226
			showDef(true, gettext("In/out packets (pass)"),
227
			    $ifinfo['inpktspass'] . '/' . $ifinfo['outpktspass'] . " (" . format_bytes($ifinfo['inbytespass']) . "/" . format_bytes($ifinfo['outbytespass']) . ")");
228
			showDef(true, gettext("In/out packets (block)"),
229
			    $ifinfo['inpktsblock'] . '/' . $ifinfo['outpktsblock'] . " (" . format_bytes($ifinfo['inbytesblock']) . "/" . format_bytes($ifinfo['outbytesblock']) . ")");
230 abe98adb Phil Davis
			showDef(isset($ifinfo['inerrs']), gettext("In/out errors"), $ifinfo['inerrs'] . "/" . $ifinfo['outerrs']);
231
			showDef(isset($ifinfo['collisions']), gettext("Collisions"), $ifinfo['collisions']);
232 fb6c7bb8 sbeaver
		} // e-o-if ($ifinfo['status'] != "down")
233
234 7f0d6ccf Phil Davis
		showDef($ifinfo['bridge'], sprintf(gettext('Bridge (%1$s)'), $ifinfo['bridgeint']), $ifinfo['bridge']);
235 fb6c7bb8 sbeaver
236 e638072c Viktor G
		if (is_array($ifinterrupts[$ifinfo['hwif']])) {
237
			$interrupt_total = $ifinterrupts[$ifinfo['hwif']]['total'];
238
			$interrupt_sec = $ifinterrupts[$ifinfo['hwif']]['rate'];
239
			showDef($interrupt_total, gettext('Interrupts'), $interrupt_total . " (" . $interrupt_sec . "/s)");
240 fb6c7bb8 sbeaver
		}
241 bd06568f sbeaver
?>
242 fb6c7bb8 sbeaver
		</dl>
243 bd06568f sbeaver
	</div>
244
</div>
245 0d7b21de sullrich
246 db794357 Colin Fleming
<?php
247
	endforeach;
248 71d9cd3d Scott Ullrich
249 7f0d6ccf Phil Davis
print_info_box(sprintf(gettext('Using dial-on-demand will bring the connection up again if any packet ' .
250
	    'triggers it. To substantiate this point: disconnecting manually ' .
251
	    'will %1$snot%2$s prevent dial-on-demand from making connections ' .
252
	    'to the outside! Don\'t use dial-on-demand if the line ' .
253
	    'is to be kept disconnected.'), '<strong>', '</strong>'), 'warning', false);
254 7c945f74 k-paulius
include("foot.inc");
255
?>