Project

General

Profile

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