Project

General

Profile

Download (18.4 KB) Statistics
| Branch: | Tag: | Revision:
1 ef88e1e1 Renato Botelho
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * interfaces_assign.php
4 092e7a96 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 a68f7a3d Luiz Otavio O Souza
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 191cb31d 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
 * Written by Jim McBeath based on existing m0n0wall files
14
 * All rights reserved.
15 092e7a96 Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19 092e7a96 Stephen Beaver
 *
20 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
21 092e7a96 Stephen Beaver
 *
22 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27 092e7a96 Stephen Beaver
 */
28 5b237745 Scott Ullrich
29 6b07c15a Matthew Grooms
##|+PRIV
30
##|*IDENT=page-interfaces-assignnetworkports
31 26b4bef8 k-paulius
##|*NAME=Interfaces: Interface Assignments
32
##|*DESCR=Allow access to the 'Interfaces: Interface Assignments' page.
33 6b07c15a Matthew Grooms
##|*MATCH=interfaces_assign.php*
34
##|-PRIV
35
36 87489e5c loonylion
//$timealla = microtime(true);
37
38 26b4bef8 k-paulius
$pgtitle = array(gettext("Interfaces"), gettext("Interface Assignments"));
39 b32dd0a6 jim-p
$shortcut_section = "interfaces";
40 af1e2031 jim-p
41 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
42
require_once("functions.inc");
43 f6339216 jim-p
require_once("filter.inc");
44 c81ef6e2 Phil Davis
require_once("shaper.inc");
45
require_once("ipsec.inc");
46
require_once("vpn.inc");
47 0730c1a6 Marcos Mendoza
require_once("openvpn.inc");
48 c81ef6e2 Phil Davis
require_once("captiveportal.inc");
49 1b34f8a7 Ermal
require_once("rrd.inc");
50 87489e5c loonylion
require_once("interfaces_fast.inc");
51 772a7b3d loonylion
52 87489e5c loonylion
global $friendlyifnames;
53 5b237745 Scott Ullrich
54 87489e5c loonylion
/*moved most gettext calls to here, we really don't want to be repeatedly calling gettext() within loops if it can be avoided.*/
55
$gettextArray = array('add'=>gettext('Add'),'addif'=>gettext('Add interface'),'delete'=>gettext('Delete'),'deleteif'=>gettext('Delete interface'),'edit'=>gettext('Edit'),'on'=>gettext('on'));
56 772a7b3d loonylion
57 5b237745 Scott Ullrich
/*
58
	In this file, "port" refers to the physical port name,
59
	while "interface" refers to LAN, WAN, or OPTn.
60
*/
61
62
/* get list without VLAN interfaces */
63
$portlist = get_interface_list();
64
65 179377b0 robjarsen
/*another *_fast function from interfaces_fast.inc. These functions are basically the same as the
66 87489e5c loonylion
ones they're named after, except they (usually) take an array and (always) return an array. This means that they only
67
need to be called once per script run, the returned array contains all the data necessary for repeated use */
68
$friendlyifnames = convert_real_interface_to_friendly_interface_name_fast();
69
70 7c53bc7b Erik Fonnesbeck
/* add wireless clone interfaces */
71 63d6bb4f Marcos Mendoza
foreach (config_get_path('wireless/clone', []) as $clone) {
72
	$portlist[$clone['cloneif']] = $clone;
73
	$portlist[$clone['cloneif']]['iswlclone'] = true;
74 7c53bc7b Erik Fonnesbeck
}
75
76 5b237745 Scott Ullrich
/* add VLAN interfaces */
77 63d6bb4f Marcos Mendoza
//$timea = microtime(true);
78
foreach (config_get_path('vlans/vlan', []) as $vlan) {
79
	$portlist[$vlan['vlanif']] = $vlan;
80
	$portlist[$vlan['vlanif']]['isvlan'] = true;
81 5b237745 Scott Ullrich
}
82
83 38738505 Ermal Luçi
/* add Bridge interfaces */
84 63d6bb4f Marcos Mendoza
foreach (config_get_path('bridges/bridged', []) as $bridge) {
85
	$portlist[$bridge['bridgeif']] = $bridge;
86
	$portlist[$bridge['bridgeif']]['isbridge'] = true;
87 38738505 Ermal Luçi
}
88
89
/* add GIF interfaces */
90 63d6bb4f Marcos Mendoza
foreach (config_get_path('gifs/gif', []) as $gif) {
91
	$portlist[$gif['gifif']] = $gif;
92
	$portlist[$gif['gifif']]['isgif'] = true;
93 38738505 Ermal Luçi
}
94
95
/* add GRE interfaces */
96 63d6bb4f Marcos Mendoza
foreach (config_get_path('gres/gre', []) as $gre) {
97
	$portlist[$gre['greif']] = $gre;
98
	$portlist[$gre['greif']]['isgre'] = true;
99 38738505 Ermal Luçi
}
100
101 dbdd08af Ermal Luçi
/* add LAGG interfaces */
102 63d6bb4f Marcos Mendoza
foreach (config_get_path('laggs/lagg', []) as $lagg) {
103
	$portlist[$lagg['laggif']] = $lagg;
104
	$portlist[$lagg['laggif']]['islagg'] = true;
105
	/* LAGG members cannot be assigned */
106
	$lagifs = explode(',', $lagg['members']);
107
	foreach ($lagifs as $lagif) {
108
		if (isset($portlist[$lagif])) {
109
			unset($portlist[$lagif]);
110 2af86dda Phil Davis
		}
111 ef88e1e1 Renato Botelho
	}
112 c720925c Ermal Luçi
}
113
114 265188ea Ermal Lu?i
/* add QinQ interfaces */
115 63d6bb4f Marcos Mendoza
foreach (config_get_path('qinqs/qinqentry', []) as $qinq) {
116
	$portlist["{$qinq['vlanif']}"]['descr'] = "VLAN {$qinq['tag']} on {$qinq['if']}";
117
	$portlist["{$qinq['vlanif']}"]['isqinq'] = true;
118
	/* QinQ members */
119
	$qinqifs = explode(' ', $qinq['members']);
120
	foreach ($qinqifs as $qinqif) {
121
		$portlist["{$qinq['vlanif']}.{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}";
122
		$portlist["{$qinq['vlanif']}.{$qinqif}"]['isqinq'] = true;
123 ef88e1e1 Renato Botelho
	}
124 265188ea Ermal Lu?i
}
125 c720925c Ermal Luçi
126 860c4e80 Chris Buechler
/* add PPP interfaces */
127 63d6bb4f Marcos Mendoza
foreach (config_get_path('ppps/ppp', []) as $ppp) {
128
	$portname = $ppp['if'];
129
	$portlist[$portname] = $ppp;
130
	$portlist[$portname]['isppp'] = true;
131
	$ports_base = basename($ppp['ports']);
132
	if (isset($ppp['descr'])) {
133
		$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
134
	} else if (isset($ppp['username'])) {
135
		$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
136
	} else {
137
		$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
138 860c4e80 Chris Buechler
	}
139
}
140
141 144fbff2 jim-p
$ovpn_descrs = array();
142 0730c1a6 Marcos Mendoza
foreach (['server', 'client'] as $openvpn_mode) {
143
	foreach (config_get_path("openvpn/openvpn-{$openvpn_mode}", []) as $openvpn_settings) {
144
		$portname = openvpn_name($openvpn_mode, $openvpn_settings);
145
		$portlist[$portname] = $openvpn_settings;
146
		$ovpn_descrs[$openvpn_settings['vpnid']] = $openvpn_settings['description'];
147 2af86dda Phil Davis
	}
148 144fbff2 jim-p
}
149
150 bd4c337c jim-p
global $ipsec_descrs;
151 235c051f jim-p
$ipsec_descrs = interface_ipsec_vti_list_all();
152
foreach ($ipsec_descrs as $ifname => $ifdescr) {
153
	$portlist[$ifname] = array('descr' => $ifdescr);
154 bd4c337c jim-p
}
155
156 87489e5c loonylion
157
$ifdescrs = interface_assign_description_fast($portlist,$friendlyifnames);
158 4401107f Steve Beaver
if (isset($_REQUEST['add']) && isset($_REQUEST['if_add'])) {
159 7c611a3e Renato Botelho
	/* Be sure this port is not being used */
160
	$portused = false;
161 ac0a027f Christian McDonald
	foreach (config_get_path('interfaces', []) as $ifdata) {
162 4401107f Steve Beaver
		if ($ifdata['if'] == $_REQUEST['if_add']) {
163 7c611a3e Renato Botelho
			$portused = true;
164
			break;
165
		}
166
	}
167
168
	if ($portused === false) {
169
		/* find next free optional interface number */
170 63d6bb4f Marcos Mendoza
		if (!config_get_path('interfaces/lan')) {
171 a5fd107d Renato Botelho
			$newifname = "lan";
172
			$descr = "LAN";
173 7c611a3e Renato Botelho
		} else {
174 63d6bb4f Marcos Mendoza
			$interface_count = count(config_get_path('interfaces', []));
175
			for ($i = 1; $i <= $interface_count; $i++) {
176
				if (!config_get_path("interfaces/opt{$i}")) {
177 e34c96a3 Steve Beaver
					break;
178
				}
179
			}
180 7c611a3e Renato Botelho
			$newifname = 'opt' . $i;
181
			$descr = "OPT" . $i;
182
		}
183 179377b0 robjarsen
184 63d6bb4f Marcos Mendoza
		config_set_path("interfaces/{$newifname}", [
185
			'descr' => $descr,
186
			'if' => $_POST['if_add']
187
		]);
188 2568e151 Christian McDonald
		if (preg_match(g_get('wireless_regex'), $_POST['if_add'])) {
189 63d6bb4f Marcos Mendoza
			config_set_path("interfaces/{$newifname}/wireless", []);
190
			$new_if_config = config_get_path("interfaces/{$newifname}");
191
			interface_sync_wireless_clones($new_if_config, false);
192
			config_set_path("interfaces/{$newifname}", $new_if_config);
193 7c611a3e Renato Botelho
		}
194
195 179377b0 robjarsen
196 b8f18410 Marcos Mendoza
		$if_config = config_get_path('interfaces', []);
197 63d6bb4f Marcos Mendoza
		uksort($if_config, "compare_interface_friendly_names");
198
		config_set_path('interfaces', $if_config);
199 7c611a3e Renato Botelho
200 e85ae672 Renato Botelho do Couto
		write_config("New interface assigned");
201 7c611a3e Renato Botelho
202 d1d1084e Viktor G
		filter_configure();
203
204 44c42356 Phil Davis
		$action_msg = gettext("Interface has been added.");
205 c8532336 Phil Davis
		$class = "success";
206 7c611a3e Renato Botelho
	}
207
208
} else if (isset($_POST['apply'])) {
209 ca4acbcd Scott Ullrich
	if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
210 eef52225 jim-p
		system_reboot();
211 ca4acbcd Scott Ullrich
		$rebootingnow = true;
212
	} else {
213 fc53bed4 jim-p
		write_config("Interfaces assignment settings changed");
214 d59557dc Ermal Luçi
215 44c42356 Phil Davis
		$changes_applied = true;
216
		$retval = 0;
217
		$retval |= filter_configure();
218 d59557dc Ermal Luçi
	}
219
220 7c611a3e Renato Botelho
} else if (isset($_POST['Submit'])) {
221 5b237745 Scott Ullrich
222
	unset($input_errors);
223
224
	/* input validation */
225
226
	/* Build a list of the port names so we can see how the interfaces map */
227
	$portifmap = array();
228 2af86dda Phil Davis
	foreach ($portlist as $portname => $portinfo) {
229 5b237745 Scott Ullrich
		$portifmap[$portname] = array();
230 2af86dda Phil Davis
	}
231 5b237745 Scott Ullrich
232
	/* Go through the list of ports selected by the user,
233 ef88e1e1 Renato Botelho
	build a list of port-to-interface mappings in portifmap */
234 5b237745 Scott Ullrich
	foreach ($_POST as $ifname => $ifport) {
235 2af86dda Phil Davis
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
236 5cc7d21d jim-p
			if (array_key_exists($ifport, $portlist)) {
237
				$portifmap[$ifport][] = strtoupper($ifname);
238
			} else {
239
				$input_errors[] = sprintf(gettext('Cannot set port %1$s because the submitted interface does not exist.'), $ifname);
240
			}
241 2af86dda Phil Davis
		}
242 5b237745 Scott Ullrich
	}
243
244
	/* Deliver error message for any port with more than one assignment */
245
	foreach ($portifmap as $portname => $ifnames) {
246
		if (count($ifnames) > 1) {
247 ddc55e12 Erik Fonnesbeck
			$errstr = sprintf(gettext('Port %1$s '.
248
				' was assigned to %2$s' .
249
				' interfaces:'), $portname, count($ifnames));
250 ef88e1e1 Renato Botelho
251 2af86dda Phil Davis
			foreach ($portifmap[$portname] as $ifn) {
252 f0eef2ef Phil Davis
				$errstr .= " " . convert_friendly_interface_to_friendly_descr(strtolower($ifn)) . " (" . $ifn . ")";
253 2af86dda Phil Davis
			}
254 ef88e1e1 Renato Botelho
255 5b237745 Scott Ullrich
			$input_errors[] = $errstr;
256 63d6bb4f Marcos Mendoza
		} else if (count($ifnames) == 1 && preg_match('/^bridge[0-9]/', $portname)) {
257 ac0a027f Christian McDonald
			foreach (config_get_path('bridges/bridged', []) as $bridge) {
258 2af86dda Phil Davis
				if ($bridge['bridgeif'] != $portname) {
259 95540233 Renato Botelho
					continue;
260 2af86dda Phil Davis
				}
261 95540233 Renato Botelho
262
				$members = explode(",", strtoupper($bridge['members']));
263
				foreach ($members as $member) {
264
					if ($member == $ifnames[0]) {
265 45654aa0 NOYB
						$input_errors[] = sprintf(gettext('Cannot set port %1$s to interface %2$s because this interface is a member of %3$s.'), $portname, $member, $portname);
266 95540233 Renato Botelho
						break;
267
					}
268
				}
269
			}
270 5b237745 Scott Ullrich
		}
271
	}
272
273 c0d3797c Christian McDonald
	foreach (config_get_path('vlans/vlan', []) as $vlan) {
274
		if (does_interface_exist($vlan['if']) == false) {
275
			$input_errors[] = sprintf(gettext('Vlan parent interface %1$s does not exist anymore so vlan id %2$s cannot be created please fix the issue before continuing.'), $vlan['if'], $vlan['tag']);
276 66bcba1b Ermal
		}
277
	}
278 5b237745 Scott Ullrich
279
	if (!$input_errors) {
280
		/* No errors detected, so update the config */
281 d1d1084e Viktor G
		$filter_reload = false;
282 5b237745 Scott Ullrich
		foreach ($_POST as $ifname => $ifport) {
283 ef88e1e1 Renato Botelho
284
			if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
285
286 5b237745 Scott Ullrich
				if (!is_array($ifport)) {
287 e7bfa231 Ermal Lu?i
					$reloadif = false;
288 63d6bb4f Marcos Mendoza
					if (!empty(config_get_path("interfaces/{$ifname}/if")) && config_get_path("interfaces/{$ifname}/if") <> $ifport) {
289 44088ce8 Ermal Lu?i
						interface_bring_down($ifname);
290 e7bfa231 Ermal Lu?i
						/* Mark this to be reconfigured in any case. */
291
						$reloadif = true;
292 d1d1084e Viktor G
						$filter_reload = true;
293 497ea0a6 Viktor G
						$gateway_monitor_reload = true;
294 44088ce8 Ermal Lu?i
					}
295 63d6bb4f Marcos Mendoza
					$this_if_config = config_get_path("interfaces/{$ifname}");
296
					$this_if_config['if'] = $ifport;
297 2af86dda Phil Davis
					if (isset($portlist[$ifport]['isppp'])) {
298 63d6bb4f Marcos Mendoza
						$this_if_config['ipaddr'] = $portlist[$ifport]['type'];
299 2af86dda Phil Davis
					}
300 ef88e1e1 Renato Botelho
301 3856366b Renato Botelho do Couto
					if ((substr($ifport, 0, 3) == 'gre') ||
302
					    (substr($ifport, 0, 5) == 'gif')) {
303 63d6bb4f Marcos Mendoza
						unset($this_if_config['ipaddr']);
304
						unset($this_if_config['subnet']);
305
						unset($this_if_config['ipaddrv6']);
306
						unset($this_if_config['subnetv6']);
307 f3d88511 Renato Botelho
					}
308
309 5b237745 Scott Ullrich
					/* check for wireless interfaces, set or clear ['wireless'] */
310 2568e151 Christian McDonald
					if (preg_match(g_get('wireless_regex'), $ifport)) {
311 63d6bb4f Marcos Mendoza
						if (!is_array($this_if_config['wireless'])) {
312
							$this_if_config['wireless'] = array();
313 2af86dda Phil Davis
						}
314 5b237745 Scott Ullrich
					} else {
315 63d6bb4f Marcos Mendoza
						unset($this_if_config['wireless']);
316 5b237745 Scott Ullrich
					}
317 ef88e1e1 Renato Botelho
318 d59557dc Ermal Luçi
					/* make sure there is a descr for all interfaces */
319 63d6bb4f Marcos Mendoza
					if (!isset($this_if_config['descr'])) {
320
						$this_if_config['descr'] = strtoupper($ifname);
321 2af86dda Phil Davis
					}
322 63d6bb4f Marcos Mendoza
					config_set_path("interfaces/{$ifname}", $this_if_config);
323 ef88e1e1 Renato Botelho
324 b13efb03 Erik Fonnesbeck
					if ($reloadif == true) {
325 2568e151 Christian McDonald
						if (preg_match(g_get('wireless_regex'), $ifport)) {
326 63d6bb4f Marcos Mendoza
							interface_sync_wireless_clones($this_if_config, false);
327
							config_set_path("interfaces/{$ifname}", $this_if_config);
328 2af86dda Phil Davis
						}
329 e7bfa231 Ermal Lu?i
						/* Reload all for the interface. */
330
						interface_configure($ifname, true);
331 d1d1084e Viktor G
						$filter_reload = true;
332 b13efb03 Erik Fonnesbeck
					}
333 5b237745 Scott Ullrich
				}
334
			}
335
		}
336 d1d1084e Viktor G
		/* regenerated ruleset after re-assigning the interface,
337
		 * see https://redmine.pfsense.org/issues/12949 */
338
		if ($filter_reload) {
339
			filter_configure();
340
		}
341 497ea0a6 Viktor G
		if ($gateway_monitor_reload) {
342
			setup_gateways_monitor();
343
		}
344 fc53bed4 jim-p
		write_config("Interfaces assignment settings changed");
345 ef88e1e1 Renato Botelho
346 6e6233d0 sullrich
		enable_rrd_graphing();
347 5b237745 Scott Ullrich
	}
348 7c611a3e Renato Botelho
} else {
349
	unset($delbtn);
350 62b7615a Marcos Mendoza
	if (!empty($_POST['del']) && is_string(key($_POST['del']))) {
351 41ea4cf3 Sjon Hortensius
		$delbtn = key($_POST['del']);
352 aa82505e Phil Davis
	}
353 5b237745 Scott Ullrich
354 62b7615a Marcos Mendoza
	if (isset($delbtn)) {
355 7c611a3e Renato Botelho
		$id = $delbtn;
356
357 2af86dda Phil Davis
		if (link_interface_to_group($id)) {
358 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
359 2af86dda Phil Davis
		} else if (link_interface_to_bridge($id)) {
360 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
361 a17e9816 Renato Botelho do Couto
		} else if (!empty(link_interface_to_tunnelif($id, 'gre'))) {
362 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
363 a17e9816 Renato Botelho do Couto
		} else if (!empty(link_interface_to_tunnelif($id, 'gif'))) {
364 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
365 85ea9d46 Steve Beaver
		} else if (interface_has_queue($id)) {
366 9267c6c9 Steve Beaver
			$input_errors[] = gettext("The interface has a traffic shaper queue configured.\nPlease remove all queues on the interface to continue.");
367 2af86dda Phil Davis
		} else {
368 7e3ea4a8 Christian McDonald
			config_del_path("interfaces/{$id}/enable");
369 7c611a3e Renato Botelho
			$realid = get_real_interface($id);
370 7e3ea4a8 Christian McDonald
			interface_bring_down($id);
371
			config_del_path("interfaces/{$id}");	/* delete the specified OPTn or LAN*/
372 7c611a3e Renato Botelho
373 63d6bb4f Marcos Mendoza
			if (is_array(config_get_path("dhcpd/{$id}"))) {
374 7e3ea4a8 Christian McDonald
				config_del_path("dhcpd/{$id}");
375 6756052b NewEraCracker
				services_dhcpd_configure('inet');
376 7c611a3e Renato Botelho
			}
377 c3bc7432 Ermal Luçi
378 63d6bb4f Marcos Mendoza
			if (is_array(config_get_path("dhcpdv6/{$id}"))) {
379 7e3ea4a8 Christian McDonald
				config_del_path("dhcpdv6/{$id}");
380 6756052b NewEraCracker
				services_dhcpd_configure('inet6');
381 ff3f0016 Chris Buechler
			}
382
383 ac0a027f Christian McDonald
			foreach (config_get_path('filter/rule', []) as $x => $rule) {
384 71f503d2 Christian McDonald
				if ($rule['interface'] == $id) {
385 7e3ea4a8 Christian McDonald
					config_del_path("filter/rule/{$x}");
386 7c611a3e Renato Botelho
				}
387 e27d0494 Ermal
			}
388 71f503d2 Christian McDonald
		
389 ac0a027f Christian McDonald
			foreach (config_get_path('nat/rule', []) as $x => $rule) {
390 71f503d2 Christian McDonald
				if ($rule['interface'] == $id) {
391 7e3ea4a8 Christian McDonald
					config_del_path("nat/rule/{$x}/interface");
392 7c611a3e Renato Botelho
				}
393 e27d0494 Ermal
			}
394 c3bc7432 Ermal Luçi
395 fc53bed4 jim-p
			write_config(gettext('Interface assignment deleted'));
396 ef88e1e1 Renato Botelho
397 7c611a3e Renato Botelho
			/* If we are in firewall/routing mode (not single interface)
398
			 * then ensure that we are not running DHCP on the wan which
399 f3f98e97 Phil Davis
			 * will make a lot of ISPs unhappy.
400 7c611a3e Renato Botelho
			 */
401 c0d3797c Christian McDonald
			if (config_path_enabled('interfaces', 'lan')
402
				&& config_path_enabled('dhcpd', 'wan')) {
403 2186435b jim-p
					config_del_path('dhcpd/wan');
404 7c611a3e Renato Botelho
			}
405 7850de1c Ermal Lu?i
406 7c611a3e Renato Botelho
			link_interface_to_vlans($realid, "update");
407 ef88e1e1 Renato Botelho
408 d1d1084e Viktor G
			filter_configure();
409
410 44c42356 Phil Davis
			$action_msg = gettext("Interface has been deleted.");
411 c8532336 Phil Davis
			$class = "success";
412 8a648100 Ermal Luçi
		}
413 bda86e8f Scott Ullrich
	}
414 7c611a3e Renato Botelho
}
415 cec4323f Erik Fonnesbeck
416 7c611a3e Renato Botelho
/* Create a list of unused ports */
417
$unused_portlist = array();
418 87489e5c loonylion
$portArray = array_keys($portlist);
419
420 b8f18410 Marcos Mendoza
$ifaceArray = array_column(config_get_path('interfaces', []),'if');
421 87489e5c loonylion
$unused = array_diff($portArray,$ifaceArray);
422
$unused = array_flip($unused);
423
$unused_portlist = array_intersect_key($portlist,$unused);//*/
424
unset($unused,$portArray,$ifaceArray);
425 5b237745 Scott Ullrich
426 7f43ca88 Scott Ullrich
include("head.inc");
427
428 2af86dda Phil Davis
if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
429 ca4acbcd Scott Ullrich
	if ($_POST) {
430 2af86dda Phil Davis
		if ($rebootingnow) {
431 44c42356 Phil Davis
			$action_msg = gettext("The system is now rebooting. Please wait.");
432 c8532336 Phil Davis
			$class = "success";
433 2af86dda Phil Davis
		} else {
434 21c18c3d Phil Davis
			$applymsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
435 c8532336 Phil Davis
			$class = "warning";
436 2af86dda Phil Davis
		}
437 ca4acbcd Scott Ullrich
	} else {
438 44c42356 Phil Davis
		$action_msg = gettext("Interface mismatch detected. Please resolve the mismatch, save and then click 'Apply Changes'. The firewall will reboot afterwards.");
439 c8532336 Phil Davis
		$class = "warning";
440 ca4acbcd Scott Ullrich
	}
441 41ea4cf3 Sjon Hortensius
}
442 f2cb6a9f Scott Ullrich
443 1b0e073e Renato Botelho
if (file_exists("/tmp/reload_interfaces")) {
444
	echo "<p>\n";
445 45654aa0 NOYB
	print_apply_box(gettext("The interface configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
446 1b0e073e Renato Botelho
	echo "<br /></p>\n";
447 21c18c3d Phil Davis
} elseif ($applymsg) {
448
	print_apply_box($applymsg);
449 44c42356 Phil Davis
} elseif ($action_msg) {
450
	print_info_box($action_msg, $class);
451
} elseif ($changes_applied) {
452
	print_apply_result_box($retval);
453 2af86dda Phil Davis
}
454 1b0e073e Renato Botelho
455
pfSense_handle_custom_code("/usr/local/pkg/interfaces_assign/pre_input_errors");
456 a4af095c Renato Botelho
457 aa82505e Phil Davis
if ($input_errors) {
458 1b0e073e Renato Botelho
	print_input_errors($input_errors);
459 aa82505e Phil Davis
}
460 f2cb6a9f Scott Ullrich
461 41ea4cf3 Sjon Hortensius
$tab_array = array();
462 26b4bef8 k-paulius
$tab_array[] = array(gettext("Interface Assignments"), true, "interfaces_assign.php");
463 50e6c063 Renato Botelho
$tab_array[] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
464
$tab_array[] = array(gettext("Wireless"), false, "interfaces_wireless.php");
465
$tab_array[] = array(gettext("VLANs"), false, "interfaces_vlan.php");
466
$tab_array[] = array(gettext("QinQs"), false, "interfaces_qinq.php");
467
$tab_array[] = array(gettext("PPPs"), false, "interfaces_ppps.php");
468 26b4bef8 k-paulius
$tab_array[] = array(gettext("GREs"), false, "interfaces_gre.php");
469
$tab_array[] = array(gettext("GIFs"), false, "interfaces_gif.php");
470 50e6c063 Renato Botelho
$tab_array[] = array(gettext("Bridges"), false, "interfaces_bridge.php");
471 26b4bef8 k-paulius
$tab_array[] = array(gettext("LAGGs"), false, "interfaces_lagg.php");
472 41ea4cf3 Sjon Hortensius
display_top_tabs($tab_array);
473 87489e5c loonylion
474 179377b0 robjarsen
/*Generate the port select box only once.
475 87489e5c loonylion
Not indenting the HTML to produce smaller code
476
and faster page load times */
477
478
$portselect='';
479
foreach ($portlist as $portname => $portinfo) {
480 179377b0 robjarsen
	$portselect.='<option value="'.$portname.'"';
481 87489e5c loonylion
	$portselect.=">".$ifdescrs[$portname]."</option>\n";
482
}
483
484 1b0e073e Renato Botelho
?>
485 41ea4cf3 Sjon Hortensius
<form action="interfaces_assign.php" method="post">
486 89f64f0f Sander van Leeuwen
	<div class="table-responsive">
487
	<table class="table table-striped table-hover">
488 41ea4cf3 Sjon Hortensius
	<thead>
489
		<tr>
490
			<th><?=gettext("Interface")?></th>
491
			<th><?=gettext("Network port")?></th>
492 290566ed NOYB
			<th>&nbsp;</th>
493 41ea4cf3 Sjon Hortensius
		</tr>
494
	</thead>
495
	<tbody>
496 1b0e073e Renato Botelho
<?php
497 87489e5c loonylion
	$i=0;
498 ac0a027f Christian McDonald
	foreach (config_get_path('interfaces', []) as $ifname => $iface):
499 aa82505e Phil Davis
		if ($iface['descr']) {
500 41ea4cf3 Sjon Hortensius
			$ifdescr = $iface['descr'];
501 aa82505e Phil Davis
		} else {
502 41ea4cf3 Sjon Hortensius
			$ifdescr = strtoupper($ifname);
503 aa82505e Phil Davis
		}
504 7c611a3e Renato Botelho
?>
505 41ea4cf3 Sjon Hortensius
		<tr>
506 4401107f Steve Beaver
			<td><a href="/interfaces.php?if=<?=$ifname?>"><?=$ifdescr?></a></td>
507 41ea4cf3 Sjon Hortensius
			<td>
508
				<select name="<?=$ifname?>" id="<?=$ifname?>" class="form-control">
509 179377b0 robjarsen
<?php
510 87489e5c loonylion
/*port select menu generation loop replaced with pre-prepared select menu to reduce page generation time */
511
echo str_replace('value="'.$iface['if'].'">','value="'.$iface['if'].'" selected>',$portselect);
512
?>
513 41ea4cf3 Sjon Hortensius
				</select>
514
			</td>
515
			<td>
516
<?php if ($ifname != 'wan'):?>
517 87489e5c loonylion
				<button type="submit" name="del[<?=$ifname?>]" class="btn btn-danger btn-sm" title="<?=$gettextArray['deleteif']?>">
518 c1d304b3 Marcos Mendoza
					<i class="fa-solid fa-trash-can icon-embed-btn"></i>
519 87489e5c loonylion
					<?=$gettextArray["delete"]?>
520 4419e274 Stephen Beaver
				</button>
521 41ea4cf3 Sjon Hortensius
<?php endif;?>
522
			</td>
523
		</tr>
524 179377b0 robjarsen
<?php $i++;
525 87489e5c loonylion
endforeach;
526 63d6bb4f Marcos Mendoza
	if (count(config_get_path('interfaces', [])) < count($portlist)):
527 1b0e073e Renato Botelho
?>
528 41ea4cf3 Sjon Hortensius
		<tr>
529
			<th>
530
				<?=gettext("Available network ports:")?>
531
			</th>
532
			<td>
533
				<select name="if_add" id="if_add" class="form-control">
534 87489e5c loonylion
<?php
535
/* HTML not indented to save on transmission/render time */
536
foreach ($unused_portlist as $portname => $portinfo):?>
537
<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>><?=$ifdescrs[$portname]?></option>
538
<?php endforeach;
539
?>
540 41ea4cf3 Sjon Hortensius
				</select>
541
			</td>
542
			<td>
543 4419e274 Stephen Beaver
				<button type="submit" name="add" title="<?=gettext("Add selected interface")?>" value="add interface" class="btn btn-success btn-sm" >
544 e0cb987c Marcos Mendoza
					<i class="fa-solid fa-plus icon-embed-btn"></i>
545 87489e5c loonylion
					<?=$gettextArray["add"]?>
546 4419e274 Stephen Beaver
				</button>
547 41ea4cf3 Sjon Hortensius
			</td>
548
		</tr>
549
<?php endif;?>
550
		</tbody>
551
	</table>
552 89f64f0f Sander van Leeuwen
	</div>
553 41ea4cf3 Sjon Hortensius
554 e0cb987c Marcos Mendoza
	<button name="Submit" type="submit" class="btn btn-primary" value="<?=gettext('Save')?>"><i class="fa-solid fa-save icon-embed-btn"></i><?=gettext('Save')?></button>
555 5b237745 Scott Ullrich
</form>
556 4419e274 Stephen Beaver
<br />
557 7c945f74 k-paulius
558
<?php
559 481db4fe jim-p
print_info_box(gettext("Interfaces that are configured as members of a lagg(4) interface will not be shown.") .
560
    '<br/><br/>' .
561
    gettext("Wireless interfaces must be created on the Wireless tab before they can be assigned."), 'info', false);
562 7c945f74 k-paulius
?>
563 89f64f0f Sander van Leeuwen
564 bfa7b33e doktornotor
<?php include("foot.inc")?>