Project

General

Profile

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