Project

General

Profile

Download (19.9 KB) Statistics
| Branch: | Tag: | Revision:
1 ef88e1e1 Renato Botelho
<?php
2 5b237745 Scott Ullrich
/*
3 aaec5634 Renato Botelho
 * interfaces_assign.php
4 092e7a96 Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8 191cb31d Stephen Beaver
 *
9 aaec5634 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * Written by Jim McBeath based on existing m0n0wall files
12
 * All rights reserved.
13 092e7a96 Stephen Beaver
 *
14 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16 092e7a96 Stephen Beaver
 *
17 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
18
 *    this list of conditions and the following disclaimer.
19 092e7a96 Stephen Beaver
 *
20 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
21
 *    notice, this list of conditions and the following disclaimer in
22
 *    the documentation and/or other materials provided with the
23
 *    distribution.
24 092e7a96 Stephen Beaver
 *
25 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
26
 *    must display the following acknowledgment:
27
 *    "This product includes software developed by the pfSense Project
28
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
29 092e7a96 Stephen Beaver
 *
30 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
31
 *    endorse or promote products derived from this software without
32
 *    prior written permission. For written permission, please contact
33
 *    coreteam@pfsense.org.
34 092e7a96 Stephen Beaver
 *
35 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
36
 *    nor may "pfSense" appear in their names without prior written
37
 *    permission of the Electric Sheep Fencing, LLC.
38 092e7a96 Stephen Beaver
 *
39 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
40
 *    acknowledgment:
41 092e7a96 Stephen Beaver
 *
42 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
43
 * for use in the pfSense software distribution (http://www.pfsense.org/).
44 092e7a96 Stephen Beaver
 *
45 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
46
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
49
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
56
 * OF THE POSSIBILITY OF SUCH DAMAGE.
57 092e7a96 Stephen Beaver
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-interfaces-assignnetworkports
61 26b4bef8 k-paulius
##|*NAME=Interfaces: Interface Assignments
62
##|*DESCR=Allow access to the 'Interfaces: Interface Assignments' page.
63 6b07c15a Matthew Grooms
##|*MATCH=interfaces_assign.php*
64
##|-PRIV
65
66 26b4bef8 k-paulius
$pgtitle = array(gettext("Interfaces"), gettext("Interface Assignments"));
67 b32dd0a6 jim-p
$shortcut_section = "interfaces";
68 af1e2031 jim-p
69 aceaf18c Phil Davis
require_once("guiconfig.inc");
70
require_once("functions.inc");
71 f6339216 jim-p
require_once("filter.inc");
72 aceaf18c Phil Davis
require_once("shaper.inc");
73
require_once("ipsec.inc");
74
require_once("vpn.inc");
75
require_once("captiveportal.inc");
76 1b34f8a7 Ermal
require_once("rrd.inc");
77 5b237745 Scott Ullrich
78 1c4b1636 Renato Botelho
function interface_assign_description($portinfo, $portname) {
79 d4b9bc5a Phil Davis
	global $ovpn_descrs;
80 1c4b1636 Renato Botelho
	if ($portinfo['isvlan']) {
81 6c07db48 Phil Davis
		$descr = sprintf(gettext('VLAN %1$s on %2$s'), $portinfo['tag'], $portinfo['if']);
82 9fcc7581 Luiz Otavio O Souza
		$iface = convert_real_interface_to_friendly_interface_name($portinfo['if']);
83
		if (isset($iface) && strlen($iface) > 0) {
84
			$descr .= " - $iface";
85
		}
86 2af86dda Phil Davis
		if ($portinfo['descr']) {
87 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
88 2af86dda Phil Davis
		}
89 1c4b1636 Renato Botelho
	} elseif ($portinfo['iswlclone']) {
90
		$descr = $portinfo['cloneif'];
91 2af86dda Phil Davis
		if ($portinfo['descr']) {
92 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
93 2af86dda Phil Davis
		}
94 1c4b1636 Renato Botelho
	} elseif ($portinfo['isppp']) {
95
		$descr = $portinfo['descr'];
96
	} elseif ($portinfo['isbridge']) {
97
		$descr = strtoupper($portinfo['bridgeif']);
98 2af86dda Phil Davis
		if ($portinfo['descr']) {
99 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
100 2af86dda Phil Davis
		}
101 1c4b1636 Renato Botelho
	} elseif ($portinfo['isgre']) {
102
		$descr = "GRE {$portinfo['remote-addr']}";
103 2af86dda Phil Davis
		if ($portinfo['descr']) {
104 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
105 2af86dda Phil Davis
		}
106 1c4b1636 Renato Botelho
	} elseif ($portinfo['isgif']) {
107
		$descr = "GIF {$portinfo['remote-addr']}";
108 2af86dda Phil Davis
		if ($portinfo['descr']) {
109 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
110 2af86dda Phil Davis
		}
111 1c4b1636 Renato Botelho
	} elseif ($portinfo['islagg']) {
112
		$descr = strtoupper($portinfo['laggif']);
113 2af86dda Phil Davis
		if ($portinfo['descr']) {
114 1c4b1636 Renato Botelho
			$descr .= " (" . $portinfo['descr'] . ")";
115 2af86dda Phil Davis
		}
116 1c4b1636 Renato Botelho
	} elseif ($portinfo['isqinq']) {
117 6c07db48 Phil Davis
		$descr = $portinfo['descr'];
118 1c4b1636 Renato Botelho
	} elseif (substr($portname, 0, 4) == 'ovpn') {
119
		$descr = $portname . " (" . $ovpn_descrs[substr($portname, 5)] . ")";
120 2af86dda Phil Davis
	} else {
121 1c4b1636 Renato Botelho
		$descr = $portname . " (" . $portinfo['mac'] . ")";
122 2af86dda Phil Davis
	}
123 1c4b1636 Renato Botelho
124
	return htmlspecialchars($descr);
125
}
126
127 5b237745 Scott Ullrich
/*
128
	In this file, "port" refers to the physical port name,
129
	while "interface" refers to LAN, WAN, or OPTn.
130
*/
131
132
/* get list without VLAN interfaces */
133
$portlist = get_interface_list();
134
135 7c53bc7b Erik Fonnesbeck
/* add wireless clone interfaces */
136
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
137
	foreach ($config['wireless']['clone'] as $clone) {
138
		$portlist[$clone['cloneif']] = $clone;
139
		$portlist[$clone['cloneif']]['iswlclone'] = true;
140
	}
141
}
142
143 5b237745 Scott Ullrich
/* add VLAN interfaces */
144
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
145
	foreach ($config['vlans']['vlan'] as $vlan) {
146 d59557dc Ermal Luçi
		$portlist[$vlan['vlanif']] = $vlan;
147
		$portlist[$vlan['vlanif']]['isvlan'] = true;
148 5b237745 Scott Ullrich
	}
149
}
150
151 38738505 Ermal Luçi
/* add Bridge interfaces */
152 b47c94bd Ermal Luçi
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
153 ef88e1e1 Renato Botelho
	foreach ($config['bridges']['bridged'] as $bridge) {
154
		$portlist[$bridge['bridgeif']] = $bridge;
155
		$portlist[$bridge['bridgeif']]['isbridge'] = true;
156
	}
157 38738505 Ermal Luçi
}
158
159
/* add GIF interfaces */
160
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
161 ef88e1e1 Renato Botelho
	foreach ($config['gifs']['gif'] as $gif) {
162
		$portlist[$gif['gifif']] = $gif;
163
		$portlist[$gif['gifif']]['isgif'] = true;
164
	}
165 38738505 Ermal Luçi
}
166
167
/* add GRE interfaces */
168
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
169 ef88e1e1 Renato Botelho
	foreach ($config['gres']['gre'] as $gre) {
170
		$portlist[$gre['greif']] = $gre;
171
		$portlist[$gre['greif']]['isgre'] = true;
172
	}
173 38738505 Ermal Luçi
}
174
175 dbdd08af Ermal Luçi
/* add LAGG interfaces */
176 c720925c Ermal Luçi
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
177 ef88e1e1 Renato Botelho
	foreach ($config['laggs']['lagg'] as $lagg) {
178
		$portlist[$lagg['laggif']] = $lagg;
179
		$portlist[$lagg['laggif']]['islagg'] = true;
180 dbdd08af Ermal Luçi
		/* LAGG members cannot be assigned */
181
		$lagifs = explode(',', $lagg['members']);
182 2af86dda Phil Davis
		foreach ($lagifs as $lagif) {
183
			if (isset($portlist[$lagif])) {
184 dbdd08af Ermal Luçi
				unset($portlist[$lagif]);
185 2af86dda Phil Davis
			}
186
		}
187 ef88e1e1 Renato Botelho
	}
188 c720925c Ermal Luçi
}
189
190 265188ea Ermal Lu?i
/* add QinQ interfaces */
191
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
192 ef88e1e1 Renato Botelho
	foreach ($config['qinqs']['qinqentry'] as $qinq) {
193 de1bacbc Chris Rowe
		$portlist["{$qinq['vlanif']}"]['descr'] = "VLAN {$qinq['tag']} on {$qinq['if']}";
194
		$portlist["{$qinq['vlanif']}"]['isqinq'] = true;
195 ef88e1e1 Renato Botelho
		/* QinQ members */
196
		$qinqifs = explode(' ', $qinq['members']);
197
		foreach ($qinqifs as $qinqif) {
198 de1bacbc Chris Rowe
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}";
199
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['isqinq'] = true;
200 ef88e1e1 Renato Botelho
		}
201
	}
202 265188ea Ermal Lu?i
}
203 c720925c Ermal Luçi
204 860c4e80 Chris Buechler
/* add PPP interfaces */
205
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
206 611ae852 Ermal
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
207 99c26d44 gnhb
		$portname = $ppp['if'];
208 860c4e80 Chris Buechler
		$portlist[$portname] = $ppp;
209
		$portlist[$portname]['isppp'] = true;
210 3f2ef8d7 gnhb
		$ports_base = basename($ppp['ports']);
211 2af86dda Phil Davis
		if (isset($ppp['descr'])) {
212 99c26d44 gnhb
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
213 2af86dda Phil Davis
		} else if (isset($ppp['username'])) {
214 99c26d44 gnhb
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
215 2af86dda Phil Davis
		} else {
216 99c26d44 gnhb
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
217 2af86dda Phil Davis
		}
218 860c4e80 Chris Buechler
	}
219
}
220
221 144fbff2 jim-p
$ovpn_descrs = array();
222
if (is_array($config['openvpn'])) {
223 2af86dda Phil Davis
	if (is_array($config['openvpn']['openvpn-server'])) {
224
		foreach ($config['openvpn']['openvpn-server'] as $s) {
225 bfa7b33e doktornotor
			$portname = "ovpns{$s['vpnid']}";
226
			$portlist[$portname] = $s;
227 144fbff2 jim-p
			$ovpn_descrs[$s['vpnid']] = $s['description'];
228 2af86dda Phil Davis
		}
229
	}
230
	if (is_array($config['openvpn']['openvpn-client'])) {
231
		foreach ($config['openvpn']['openvpn-client'] as $c) {
232 bfa7b33e doktornotor
			$portname = "ovpnc{$c['vpnid']}";
233
			$portlist[$portname] = $c;
234 144fbff2 jim-p
			$ovpn_descrs[$c['vpnid']] = $c['description'];
235 2af86dda Phil Davis
		}
236
	}
237 144fbff2 jim-p
}
238
239 ad2879b8 PiBa-NL
if (isset($_POST['add']) && isset($_POST['if_add'])) {
240 7c611a3e Renato Botelho
	/* Be sure this port is not being used */
241
	$portused = false;
242
	foreach ($config['interfaces'] as $ifname => $ifdata) {
243 3f6930f7 Phil Davis
		if ($ifdata['if'] == $_POST['if_add']) {
244 7c611a3e Renato Botelho
			$portused = true;
245
			break;
246
		}
247
	}
248
249
	if ($portused === false) {
250
		/* find next free optional interface number */
251 2af86dda Phil Davis
		if (!$config['interfaces']['lan']) {
252 7c611a3e Renato Botelho
			$newifname = gettext("lan");
253
			$descr = gettext("LAN");
254
		} else {
255
			for ($i = 1; $i <= count($config['interfaces']); $i++) {
256 2af86dda Phil Davis
				if (!$config['interfaces']["opt{$i}"]) {
257 7c611a3e Renato Botelho
					break;
258 2af86dda Phil Davis
				}
259 7c611a3e Renato Botelho
			}
260
			$newifname = 'opt' . $i;
261
			$descr = "OPT" . $i;
262
		}
263
264
		$config['interfaces'][$newifname] = array();
265
		$config['interfaces'][$newifname]['descr'] = $descr;
266
		$config['interfaces'][$newifname]['if'] = $_POST['if_add'];
267
		if (preg_match($g['wireless_regex'], $_POST['if_add'])) {
268
			$config['interfaces'][$newifname]['wireless'] = array();
269
			interface_sync_wireless_clones($config['interfaces'][$newifname], false);
270
		}
271
272
		uksort($config['interfaces'], "compare_interface_friendly_names");
273
274
		/* XXX: Do not remove this. */
275
		unlink_if_exists("{$g['tmp_path']}/config.cache");
276
277
		write_config();
278
279
		$savemsg = gettext("Interface has been added.");
280 c8532336 Phil Davis
		$class = "success";
281 7c611a3e Renato Botelho
	}
282
283
} else if (isset($_POST['apply'])) {
284 ca4acbcd Scott Ullrich
	if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
285 eef52225 jim-p
		system_reboot();
286 ca4acbcd Scott Ullrich
		$rebootingnow = true;
287
	} else {
288 d59557dc Ermal Luçi
		write_config();
289
290
		$retval = filter_configure();
291
292 2af86dda Phil Davis
		if (stristr($retval, "error") <> true) {
293 d59557dc Ermal Luçi
			$savemsg = get_std_save_message($retval);
294 c8532336 Phil Davis
			$class = "success";
295 2af86dda Phil Davis
		} else {
296 d59557dc Ermal Luçi
			$savemsg = $retval;
297 c8532336 Phil Davis
			$class = "danger";
298 2af86dda Phil Davis
		}
299 d59557dc Ermal Luçi
	}
300
301 7c611a3e Renato Botelho
} else if (isset($_POST['Submit'])) {
302 5b237745 Scott Ullrich
303
	unset($input_errors);
304
305
	/* input validation */
306
307
	/* Build a list of the port names so we can see how the interfaces map */
308
	$portifmap = array();
309 2af86dda Phil Davis
	foreach ($portlist as $portname => $portinfo) {
310 5b237745 Scott Ullrich
		$portifmap[$portname] = array();
311 2af86dda Phil Davis
	}
312 5b237745 Scott Ullrich
313
	/* Go through the list of ports selected by the user,
314 ef88e1e1 Renato Botelho
	build a list of port-to-interface mappings in portifmap */
315 5b237745 Scott Ullrich
	foreach ($_POST as $ifname => $ifport) {
316 2af86dda Phil Davis
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
317 5b237745 Scott Ullrich
			$portifmap[$ifport][] = strtoupper($ifname);
318 2af86dda Phil Davis
		}
319 5b237745 Scott Ullrich
	}
320
321
	/* Deliver error message for any port with more than one assignment */
322
	foreach ($portifmap as $portname => $ifnames) {
323
		if (count($ifnames) > 1) {
324 ddc55e12 Erik Fonnesbeck
			$errstr = sprintf(gettext('Port %1$s '.
325
				' was assigned to %2$s' .
326
				' interfaces:'), $portname, count($ifnames));
327 ef88e1e1 Renato Botelho
328 2af86dda Phil Davis
			foreach ($portifmap[$portname] as $ifn) {
329 f0eef2ef Phil Davis
				$errstr .= " " . convert_friendly_interface_to_friendly_descr(strtolower($ifn)) . " (" . $ifn . ")";
330 2af86dda Phil Davis
			}
331 ef88e1e1 Renato Botelho
332 5b237745 Scott Ullrich
			$input_errors[] = $errstr;
333 95540233 Renato Botelho
		} else if (count($ifnames) == 1 && preg_match('/^bridge[0-9]/', $portname) && is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
334
			foreach ($config['bridges']['bridged'] as $bridge) {
335 2af86dda Phil Davis
				if ($bridge['bridgeif'] != $portname) {
336 95540233 Renato Botelho
					continue;
337 2af86dda Phil Davis
				}
338 95540233 Renato Botelho
339
				$members = explode(",", strtoupper($bridge['members']));
340
				foreach ($members as $member) {
341
					if ($member == $ifnames[0]) {
342 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);
343 95540233 Renato Botelho
						break;
344
					}
345
				}
346
			}
347 5b237745 Scott Ullrich
		}
348
	}
349
350 66bcba1b Ermal
	if (is_array($config['vlans']['vlan'])) {
351
		foreach ($config['vlans']['vlan'] as $vlan) {
352 2af86dda Phil Davis
			if (does_interface_exist($vlan['if']) == false) {
353 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']);
354 2af86dda Phil Davis
			}
355 66bcba1b Ermal
		}
356
	}
357 5b237745 Scott Ullrich
358
	if (!$input_errors) {
359
		/* No errors detected, so update the config */
360
		foreach ($_POST as $ifname => $ifport) {
361 ef88e1e1 Renato Botelho
362
			if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
363
364 5b237745 Scott Ullrich
				if (!is_array($ifport)) {
365 e7bfa231 Ermal Lu?i
					$reloadif = false;
366 44088ce8 Ermal Lu?i
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
367
						interface_bring_down($ifname);
368 e7bfa231 Ermal Lu?i
						/* Mark this to be reconfigured in any case. */
369
						$reloadif = true;
370 44088ce8 Ermal Lu?i
					}
371 5b237745 Scott Ullrich
					$config['interfaces'][$ifname]['if'] = $ifport;
372 2af86dda Phil Davis
					if (isset($portlist[$ifport]['isppp'])) {
373 c86e8f76 gnhb
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
374 2af86dda Phil Davis
					}
375 ef88e1e1 Renato Botelho
376 0b5fc1d1 Ermal
					if (substr($ifport, 0, 3) == 'gre' || substr($ifport, 0, 3) == 'gif') {
377 f3d88511 Renato Botelho
						unset($config['interfaces'][$ifname]['ipaddr']);
378
						unset($config['interfaces'][$ifname]['subnet']);
379
						unset($config['interfaces'][$ifname]['ipaddrv6']);
380
						unset($config['interfaces'][$ifname]['subnetv6']);
381
					}
382
383 5b237745 Scott Ullrich
					/* check for wireless interfaces, set or clear ['wireless'] */
384 94a77286 Scott Ullrich
					if (preg_match($g['wireless_regex'], $ifport)) {
385 2af86dda Phil Davis
						if (!is_array($config['interfaces'][$ifname]['wireless'])) {
386 5b237745 Scott Ullrich
							$config['interfaces'][$ifname]['wireless'] = array();
387 2af86dda Phil Davis
						}
388 5b237745 Scott Ullrich
					} else {
389
						unset($config['interfaces'][$ifname]['wireless']);
390
					}
391 ef88e1e1 Renato Botelho
392 d59557dc Ermal Luçi
					/* make sure there is a descr for all interfaces */
393 2af86dda Phil Davis
					if (!isset($config['interfaces'][$ifname]['descr'])) {
394 d59557dc Ermal Luçi
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
395 2af86dda Phil Davis
					}
396 ef88e1e1 Renato Botelho
397 b13efb03 Erik Fonnesbeck
					if ($reloadif == true) {
398 2af86dda Phil Davis
						if (preg_match($g['wireless_regex'], $ifport)) {
399 b13efb03 Erik Fonnesbeck
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
400 2af86dda Phil Davis
						}
401 e7bfa231 Ermal Lu?i
						/* Reload all for the interface. */
402
						interface_configure($ifname, true);
403 b13efb03 Erik Fonnesbeck
					}
404 5b237745 Scott Ullrich
				}
405
			}
406
		}
407 ef88e1e1 Renato Botelho
408 5b237745 Scott Ullrich
		write_config();
409 ef88e1e1 Renato Botelho
410 6e6233d0 sullrich
		enable_rrd_graphing();
411 5b237745 Scott Ullrich
	}
412 7c611a3e Renato Botelho
} else {
413
	unset($delbtn);
414 aa82505e Phil Davis
	if (!empty($_POST['del'])) {
415 41ea4cf3 Sjon Hortensius
		$delbtn = key($_POST['del']);
416 aa82505e Phil Davis
	}
417 5b237745 Scott Ullrich
418 7c611a3e Renato Botelho
	if (isset($delbtn)) {
419
		$id = $delbtn;
420
421 2af86dda Phil Davis
		if (link_interface_to_group($id)) {
422 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
423 2af86dda Phil Davis
		} else if (link_interface_to_bridge($id)) {
424 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
425 2af86dda Phil Davis
		} else if (link_interface_to_gre($id)) {
426 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
427 2af86dda Phil Davis
		} else if (link_interface_to_gif($id)) {
428 7c611a3e Renato Botelho
			$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
429 2af86dda Phil Davis
		} else {
430 7c611a3e Renato Botelho
			unset($config['interfaces'][$id]['enable']);
431
			$realid = get_real_interface($id);
432
			interface_bring_down($id);   /* down the interface */
433
434
			unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
435
436
			if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) {
437
				unset($config['dhcpd'][$id]);
438
				services_dhcpd_configure();
439
			}
440 c3bc7432 Ermal Luçi
441 dce5a715 Chris Buechler
			if (is_array($config['dhcpdv6']) && is_array($config['dhcpdv6'][$id])) {
442
				unset($config['dhcpdv6'][$id]);
443
				services_dhcpdv6_configure();
444
			}
445
446 7c611a3e Renato Botelho
			if (count($config['filter']['rule']) > 0) {
447
				foreach ($config['filter']['rule'] as $x => $rule) {
448 2af86dda Phil Davis
					if ($rule['interface'] == $id) {
449 7c611a3e Renato Botelho
						unset($config['filter']['rule'][$x]);
450 2af86dda Phil Davis
					}
451 7c611a3e Renato Botelho
				}
452 e27d0494 Ermal
			}
453 7c611a3e Renato Botelho
			if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
454
				foreach ($config['nat']['rule'] as $x => $rule) {
455 2af86dda Phil Davis
					if ($rule['interface'] == $id) {
456 7c611a3e Renato Botelho
						unset($config['nat']['rule'][$x]['interface']);
457 2af86dda Phil Davis
					}
458 7c611a3e Renato Botelho
				}
459 e27d0494 Ermal
			}
460 c3bc7432 Ermal Luçi
461 7c611a3e Renato Botelho
			write_config();
462 ef88e1e1 Renato Botelho
463 7c611a3e Renato Botelho
			/* If we are in firewall/routing mode (not single interface)
464
			 * then ensure that we are not running DHCP on the wan which
465
			 * will make a lot of ISP's unhappy.
466
			 */
467 2af86dda Phil Davis
			if ($config['interfaces']['lan'] && $config['dhcpd']['wan']) {
468 7c611a3e Renato Botelho
				unset($config['dhcpd']['wan']);
469
			}
470 7850de1c Ermal Lu?i
471 7c611a3e Renato Botelho
			link_interface_to_vlans($realid, "update");
472 ef88e1e1 Renato Botelho
473 7c611a3e Renato Botelho
			$savemsg = gettext("Interface has been deleted.");
474 c8532336 Phil Davis
			$class = "success";
475 8a648100 Ermal Luçi
		}
476 bda86e8f Scott Ullrich
	}
477 7c611a3e Renato Botelho
}
478 cec4323f Erik Fonnesbeck
479 7c611a3e Renato Botelho
/* Create a list of unused ports */
480
$unused_portlist = array();
481
foreach ($portlist as $portname => $portinfo) {
482
	$portused = false;
483
	foreach ($config['interfaces'] as $ifname => $ifdata) {
484
		if ($ifdata['if'] == $portname) {
485
			$portused = true;
486 5b237745 Scott Ullrich
			break;
487
		}
488
	}
489 2af86dda Phil Davis
	if ($portused === false) {
490 7c611a3e Renato Botelho
		$unused_portlist[$portname] = $portinfo;
491 2af86dda Phil Davis
	}
492 7c611a3e Renato Botelho
}
493 5b237745 Scott Ullrich
494 7f43ca88 Scott Ullrich
include("head.inc");
495
496 2af86dda Phil Davis
if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
497 ca4acbcd Scott Ullrich
	if ($_POST) {
498 2af86dda Phil Davis
		if ($rebootingnow) {
499 8545adde k-paulius
			$savemsg = gettext("The system is now rebooting. Please wait.");
500 c8532336 Phil Davis
			$class = "success";
501 2af86dda Phil Davis
		} else {
502 f4ede227 Phil Davis
			$applymsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
503 c8532336 Phil Davis
			$class = "warning";
504 2af86dda Phil Davis
		}
505 ca4acbcd Scott Ullrich
	} else {
506 42f47efc Phil Davis
		$savemsg = gettext("Interface mismatch detected. Please resolve the mismatch, save and then click 'Apply Changes'. The firewall will reboot afterwards.");
507 c8532336 Phil Davis
		$class = "warning";
508 ca4acbcd Scott Ullrich
	}
509 41ea4cf3 Sjon Hortensius
}
510 f2cb6a9f Scott Ullrich
511 1b0e073e Renato Botelho
if (file_exists("/tmp/reload_interfaces")) {
512
	echo "<p>\n";
513 45654aa0 NOYB
	print_apply_box(gettext("The interface configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
514 1b0e073e Renato Botelho
	echo "<br /></p>\n";
515 f4ede227 Phil Davis
} elseif ($applymsg) {
516
	print_apply_box($applymsg);
517 2af86dda Phil Davis
} elseif ($savemsg) {
518 c8532336 Phil Davis
	print_info_box($savemsg, $class);
519 2af86dda Phil Davis
}
520 1b0e073e Renato Botelho
521
pfSense_handle_custom_code("/usr/local/pkg/interfaces_assign/pre_input_errors");
522 a4af095c Renato Botelho
523 aa82505e Phil Davis
if ($input_errors) {
524 1b0e073e Renato Botelho
	print_input_errors($input_errors);
525 aa82505e Phil Davis
}
526 f2cb6a9f Scott Ullrich
527 41ea4cf3 Sjon Hortensius
$tab_array = array();
528 26b4bef8 k-paulius
$tab_array[] = array(gettext("Interface Assignments"), true, "interfaces_assign.php");
529 50e6c063 Renato Botelho
$tab_array[] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
530
$tab_array[] = array(gettext("Wireless"), false, "interfaces_wireless.php");
531
$tab_array[] = array(gettext("VLANs"), false, "interfaces_vlan.php");
532
$tab_array[] = array(gettext("QinQs"), false, "interfaces_qinq.php");
533
$tab_array[] = array(gettext("PPPs"), false, "interfaces_ppps.php");
534 26b4bef8 k-paulius
$tab_array[] = array(gettext("GREs"), false, "interfaces_gre.php");
535
$tab_array[] = array(gettext("GIFs"), false, "interfaces_gif.php");
536 50e6c063 Renato Botelho
$tab_array[] = array(gettext("Bridges"), false, "interfaces_bridge.php");
537 26b4bef8 k-paulius
$tab_array[] = array(gettext("LAGGs"), false, "interfaces_lagg.php");
538 41ea4cf3 Sjon Hortensius
display_top_tabs($tab_array);
539 1b0e073e Renato Botelho
?>
540 41ea4cf3 Sjon Hortensius
<form action="interfaces_assign.php" method="post">
541 89f64f0f Sander van Leeuwen
	<div class="table-responsive">
542
	<table class="table table-striped table-hover">
543 41ea4cf3 Sjon Hortensius
	<thead>
544
		<tr>
545
			<th><?=gettext("Interface")?></th>
546
			<th><?=gettext("Network port")?></th>
547 290566ed NOYB
			<th>&nbsp;</th>
548 41ea4cf3 Sjon Hortensius
		</tr>
549
	</thead>
550
	<tbody>
551 1b0e073e Renato Botelho
<?php
552 41ea4cf3 Sjon Hortensius
	foreach ($config['interfaces'] as $ifname => $iface):
553 aa82505e Phil Davis
		if ($iface['descr']) {
554 41ea4cf3 Sjon Hortensius
			$ifdescr = $iface['descr'];
555 aa82505e Phil Davis
		} else {
556 41ea4cf3 Sjon Hortensius
			$ifdescr = strtoupper($ifname);
557 aa82505e Phil Davis
		}
558 7c611a3e Renato Botelho
?>
559 41ea4cf3 Sjon Hortensius
		<tr>
560
			<td><a href="/interfaces.php?if=<?=$ifname?>"><?=$ifdescr?></a></td>
561
			<td>
562
				<select name="<?=$ifname?>" id="<?=$ifname?>" class="form-control">
563
<?php foreach ($portlist as $portname => $portinfo):?>
564 c4b60a9a Colin Fleming
					<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>>
565 41ea4cf3 Sjon Hortensius
						<?=interface_assign_description($portinfo, $portname)?>
566
					</option>
567
<?php endforeach;?>
568
				</select>
569
			</td>
570
			<td>
571
<?php if ($ifname != 'wan'):?>
572 4419e274 Stephen Beaver
				<button type="submit" name="del[<?=$ifname?>]" class="btn btn-danger btn-sm" title="<?=gettext("Delete interface")?>">
573
					<i class="fa fa-trash icon-embed-btn"></i>
574 6a667f30 Stephen Beaver
					<?=gettext("Delete")?>
575 4419e274 Stephen Beaver
				</button>
576 41ea4cf3 Sjon Hortensius
<?php endif;?>
577
			</td>
578
		</tr>
579
<?php endforeach;
580
	if (count($config['interfaces']) < count($portlist)):
581 1b0e073e Renato Botelho
?>
582 41ea4cf3 Sjon Hortensius
		<tr>
583
			<th>
584
				<?=gettext("Available network ports:")?>
585
			</th>
586
			<td>
587
				<select name="if_add" id="if_add" class="form-control">
588
<?php foreach ($unused_portlist as $portname => $portinfo):?>
589 c4b60a9a Colin Fleming
					<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>>
590 41ea4cf3 Sjon Hortensius
						<?=interface_assign_description($portinfo, $portname)?>
591
					</option>
592
<?php endforeach;?>
593
				</select>
594
			</td>
595
			<td>
596 4419e274 Stephen Beaver
				<button type="submit" name="add" title="<?=gettext("Add selected interface")?>" value="add interface" class="btn btn-success btn-sm" >
597
					<i class="fa fa-plus icon-embed-btn"></i>
598 6a667f30 Stephen Beaver
					<?=gettext("Add")?>
599 4419e274 Stephen Beaver
				</button>
600 41ea4cf3 Sjon Hortensius
			</td>
601
		</tr>
602
<?php endif;?>
603
		</tbody>
604
	</table>
605 89f64f0f Sander van Leeuwen
	</div>
606 41ea4cf3 Sjon Hortensius
607 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>
608 5b237745 Scott Ullrich
</form>
609 4419e274 Stephen Beaver
<br />
610 7c945f74 k-paulius
611
<?php
612
print_info_box(gettext("Interfaces that are configured as members of a lagg(4) interface will not be shown."), 'info', false);
613
?>
614 89f64f0f Sander van Leeuwen
615 bfa7b33e doktornotor
<?php include("foot.inc")?>