Project

General

Profile

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