Project

General

Profile

Download (142 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2006 Daniel S. Haischt
10
 * All rights reserved.
11
 *
12
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * 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
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * 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
 */
28

    
29
##|+PRIV
30
##|*IDENT=page-interfaces
31
##|*NAME=Interfaces: WAN
32
##|*DESCR=Allow access to the 'Interfaces' page.
33
##|*MATCH=interfaces.php*
34
##|-PRIV
35

    
36
require_once("guiconfig.inc");
37
require_once("ipsec.inc");
38
require_once("functions.inc");
39
require_once("captiveportal.inc");
40
require_once("filter.inc");
41
require_once("shaper.inc");
42
require_once("rrd.inc");
43
require_once("vpn.inc");
44
require_once("xmlparse_attr.inc");
45
require_once("util.inc");
46

    
47
function remove_bad_chars($string) {
48
	return preg_replace('/[^a-z_0-9]/i', '', $string);
49
}
50

    
51
define("ANTENNAS", false);
52

    
53
if (isset($_POST['referer'])) {
54
	$referer = $_POST['referer'];
55
} else {
56
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
57
}
58

    
59
// Get configured interface list
60
$ifdescrs = get_configured_interface_with_descr(true);
61
$if = $_REQUEST['if'] ?? 'wan';
62
$bridged = link_interface_to_bridge($if);
63

    
64

    
65
if (empty($ifdescrs[$if])) {
66
	header("Location: interfaces.php");
67
	exit;
68
}
69

    
70
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
71
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
72
define("CRON_DAILY_PATTERN", "0 0 * * *");
73
define("CRON_HOURLY_PATTERN", "0 * * * *");
74

    
75
if (!is_array($pconfig)) {
76
	$pconfig = array();
77
}
78

    
79
init_config_arr(array('ppps', 'ppp'));
80
$a_ppps = &$config['ppps']['ppp'];
81

    
82
init_config_arr(array('gateways', 'gateway_item'));
83
$a_gateways = &$config['gateways']['gateway_item'];
84

    
85
$interfaces = get_configured_interface_with_descr();
86
/* Interfaces which have addresses configured elsewhere and should not be
87
 * configured here. See https://redmine.pfsense.org/issues/8687 */
88
$no_address_interfaces = array("ovpn", "ipsec", "gif", "gre", "l2tps");
89
$show_address_controls = true;
90
$realifname = get_real_interface($if);
91
foreach ($no_address_interfaces as $ifbl) {
92
	if (substr($realifname, 0, strlen($ifbl)) == $ifbl) {
93
		$show_address_controls = false;
94
	}
95
}
96

    
97
init_config_arr(array('interfaces', $if));
98
$wancfg = &$config['interfaces'][$if];
99
$old_wancfg = $wancfg;
100
$old_wancfg['realif'] = get_real_interface($if);
101
$old_ppps = $a_ppps;
102

    
103
// Populate page descr if it does not exist.
104
if ($if == "wan" && !$wancfg['descr']) {
105
	$wancfg['descr'] = "WAN";
106
} else if ($if == "lan" && !$wancfg['descr']) {
107
	$wancfg['descr'] = "LAN";
108
}
109

    
110
/* NOTE: The code here is used to set the $pppid for the curious */
111
$pppid = null;
112
foreach ($a_ppps as $pid => $ppp) {
113
	if ($wancfg['if'] == $ppp['if']) {
114
		$pppid = $pid;
115
		break;
116
	}
117
}
118

    
119
$type_disabled = (substr($wancfg['if'], 0, 3) == 'gre') ? 'disabled' : '';
120

    
121
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
122
	$pconfig['pppid'] = $pppid;
123
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
124
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
125
	if ($a_ppps[$pppid]['type'] == "ppp") {
126
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
127
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
128

    
129
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
130
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
131
	} elseif ($a_ppps[$pppid]['type'] == "pppoe") {
132
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
133
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
134
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
135
		$pconfig['hostuniq'] = $a_ppps[$pppid]['hostuniq'];
136
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
137
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
138

    
139
		/* ================================================ */
140
		/* = force a connection reset at a specific time? = */
141
		/* ================================================ */
142

    
143
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
144
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
145
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
146
			if ($itemhash) {
147
				$cronitem = $itemhash['ITEM'];
148
			}
149
			if (isset($cronitem)) {
150
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
151
			} else {
152
				$resetTime = NULL;
153
			}
154
			//log_error("ResetTime:".$resetTime);
155
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
156
				if ($cronitem) {
157
					$pconfig['pppoe_pr_custom'] = true;
158
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
159
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
160
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
161
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
162
					}
163
				}
164
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
165
				$pconfig['pppoe_pr_preset'] = true;
166
				switch ($resetTime) {
167
					case CRON_MONTHLY_PATTERN:
168
						$pconfig['pppoe_monthly'] = true;
169
						break;
170
					case CRON_WEEKLY_PATTERN:
171
						$pconfig['pppoe_weekly'] = true;
172
						break;
173
					case CRON_DAILY_PATTERN:
174
						$pconfig['pppoe_daily'] = true;
175
						break;
176
					case CRON_HOURLY_PATTERN:
177
						$pconfig['pppoe_hourly'] = true;
178
						break;
179
				}
180
			}
181
		} // End force pppoe reset at specific time
182
		// End if type == pppoe
183
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
184
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
185
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
186
		if (($a_ppps[$pppid]['type'] == 'l2tp') && isset($a_ppps[$pppid]['secret'])) {
187
			$pconfig['l2tp_secret'] = base64_decode($a_ppps[$pppid]['secret']);
188
		}
189
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
190
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
191
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
192
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
193
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
194
	}
195
} else {
196
	$pconfig['ptpid'] = interfaces_ptpid_next();
197
	$pppid = count($a_ppps);
198
}
199

    
200
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
201
$pconfig['alias-address'] = $wancfg['alias-address'];
202
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
203
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
204

    
205
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
206
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
207
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
208
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
209
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
210
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
211

    
212
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
213

    
214
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
215
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
216
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
217
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
218

    
219
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
220
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
221
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
222

    
223
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
224
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
225
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
226
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
227

    
228
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
229
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
230
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
231
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
232
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
233

    
234
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
235
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
236
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
237
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
238
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
239

    
240
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
241
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
242
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
243

    
244
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
245
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
246
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
247
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
248

    
249
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
250
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
251
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
252
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
253
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
254

    
255
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
256
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
257
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
258

    
259
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
260
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
261
$pconfig['enable'] = isset($wancfg['enable']);
262

    
263
switch ($wancfg['ipaddr']) {
264
	case "dhcp":
265
		$pconfig['type'] = "dhcp";
266
		$pconfig['dhcpvlanenable'] = isset($wancfg['dhcpvlanenable']);
267
		$pconfig['dhcpcvpt'] = $wancfg['dhcpcvpt'];
268
		break;
269
	case "pppoe":
270
	case "pptp":
271
	case "l2tp":
272
	case "ppp":
273
		$pconfig['type'] = $wancfg['ipaddr'];
274
		break;
275
	default:
276
		if (is_ipaddrv4($wancfg['ipaddr'])) {
277
			$pconfig['type'] = "staticv4";
278
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
279
			$pconfig['subnet'] = $wancfg['subnet'];
280
			$pconfig['gateway'] = $wancfg['gateway'];
281
		} elseif (in_array(remove_ifindex($wancfg['if']), array("ppp", "pppoe", "pptp", "l2tp"))) {
282
			$pconfig['type'] = remove_ifindex($wancfg['if']);
283
		} else {
284
			$pconfig['type'] = "none";
285
		}
286
		break;
287
}
288

    
289
switch ($wancfg['ipaddrv6']) {
290
	case "slaac":
291
		$pconfig['type6'] = "slaac";
292
		$pconfig['slaacusev4iface'] = isset($wancfg['slaacusev4iface']);
293
		break;
294
	case "dhcp6":
295
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
296
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
297
			$wancfg['dhcp6-ia-pd-len'] = "none";
298
		}
299
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
300
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
301
		$pconfig['type6'] = "dhcp6";
302
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
303
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
304
		$pconfig['dhcp6withoutra'] = isset($wancfg['dhcp6withoutra']);
305
		$pconfig['dhcp6vlanenable'] = isset($wancfg['dhcp6vlanenable']);
306
		$pconfig['dhcp6cvpt'] = $wancfg['dhcp6cvpt'];
307
		break;
308
	case "6to4":
309
		$pconfig['type6'] = "6to4";
310
		break;
311
	case "track6":
312
		$pconfig['type6'] = "track6";
313
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
314
		if ($wancfg['track6-prefix-id'] == "") {
315
			$pconfig['track6-prefix-id'] = 0;
316
		} else {
317
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
318
		}
319
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
320
		break;
321
	case "6rd":
322
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
323
		if ($wancfg['prefix-6rd-v4plen'] == "") {
324
			$wancfg['prefix-6rd-v4plen'] = "0";
325
		}
326
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
327
		$pconfig['type6'] = "6rd";
328
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
329
		break;
330
	default:
331
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
332
			$pconfig['type6'] = "staticv6";
333
			$pconfig['ipv6usev4iface'] = isset($wancfg['ipv6usev4iface']);
334
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
335
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
336
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
337
		} else {
338
			$pconfig['type6'] = "none";
339
		}
340
		break;
341
}
342

    
343
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
344
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
345
$pconfig['spoofmac'] = $wancfg['spoofmac'];
346
$pconfig['mtu'] = $wancfg['mtu'];
347
$pconfig['mss'] = $wancfg['mss'];
348

    
349
/* Wireless interface? */
350
if (isset($wancfg['wireless'])) {
351
	/* Sync first to be sure it displays the actual settings that will be used */
352
	interface_sync_wireless_clones($wancfg, false);
353
	/* Get wireless modes */
354
	$wlanif = get_real_interface($if);
355
	if (!does_interface_exist($wlanif)) {
356
		interface_wireless_clone($wlanif, $wancfg);
357
	}
358
	$wlanbaseif = interface_get_wireless_base($wancfg['if']);
359
	preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split);
360
	$wl_modes = get_wireless_modes($if);
361
	$wl_ht_modes = get_wireless_ht_modes($if);
362
	$wl_ht_list = get_wireless_ht_list($if);
363
	$wl_chaninfo = get_wireless_channel_info($if);
364
	$wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2];
365
	$wl_sysctl = get_sysctl(
366
		array(
367
			"{$wl_sysctl_prefix}.diversity",
368
			"{$wl_sysctl_prefix}.txantenna",
369
			"{$wl_sysctl_prefix}.rxantenna",
370
			"{$wl_sysctl_prefix}.slottime",
371
			"{$wl_sysctl_prefix}.acktimeout",
372
			"{$wl_sysctl_prefix}.ctstimeout"));
373
	$wl_regdomain_xml_attr = array();
374
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
375
	$wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd'];
376
	$wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd'];
377
	$wl_countries = &$wl_regdomain_xml['country-codes']['country'];
378
	$wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country'];
379
	$pconfig['persistcommonwireless'] = isset($config['wireless']['interfaces'][$wlanbaseif]);
380
	$pconfig['standard'] = $wancfg['wireless']['standard'];
381
	$pconfig['mode'] = $wancfg['wireless']['mode'];
382
	$pconfig['protmode'] = $wancfg['wireless']['protmode'];
383
	$pconfig['ssid'] = $wancfg['wireless']['ssid'];
384
	$pconfig['channel'] = $wancfg['wireless']['channel'];
385
	$pconfig['channel_width'] = $wancfg['wireless']['channel_width'];
386
	$pconfig['txpower'] = $wancfg['wireless']['txpower'];
387
	$pconfig['diversity'] = $wancfg['wireless']['diversity'];
388
	$pconfig['txantenna'] = $wancfg['wireless']['txantenna'];
389
	$pconfig['rxantenna'] = $wancfg['wireless']['rxantenna'];
390
	$pconfig['distance'] = $wancfg['wireless']['distance'];
391
	$pconfig['regdomain'] = $wancfg['wireless']['regdomain'];
392
	$pconfig['regcountry'] = $wancfg['wireless']['regcountry'];
393
	$pconfig['reglocation'] = $wancfg['wireless']['reglocation'];
394
	$pconfig['wme_enable'] = isset($wancfg['wireless']['wme']['enable']);
395
	if (isset($wancfg['wireless']['puren']['enable'])) {
396
		$pconfig['puremode'] = '11n';
397
	} else if (isset($wancfg['wireless']['pureg']['enable'])) {
398
		$pconfig['puremode'] = '11g';
399
	} else {
400
		$pconfig['puremode'] = 'any';
401
	}
402
	$pconfig['apbridge_enable'] = isset($wancfg['wireless']['apbridge']['enable']);
403
	$pconfig['authmode'] = $wancfg['wireless']['authmode'];
404
	$pconfig['hidessid_enable'] = isset($wancfg['wireless']['hidessid']['enable']);
405
	$pconfig['auth_server_addr'] = $wancfg['wireless']['auth_server_addr'];
406
	$pconfig['auth_server_port'] = $wancfg['wireless']['auth_server_port'];
407
	$pconfig['auth_server_shared_secret'] = $wancfg['wireless']['auth_server_shared_secret'];
408
	$pconfig['auth_server_addr2'] = $wancfg['wireless']['auth_server_addr2'];
409
	$pconfig['auth_server_port2'] = $wancfg['wireless']['auth_server_port2'];
410
	$pconfig['auth_server_shared_secret2'] = $wancfg['wireless']['auth_server_shared_secret2'];
411
	if (is_array($wancfg['wireless']['wpa'])) {
412
		$pconfig['debug_mode'] = $wancfg['wireless']['wpa']['debug_mode'];
413
		$pconfig['macaddr_acl'] = $wancfg['wireless']['wpa']['macaddr_acl'];
414
		$pconfig['mac_acl_enable'] = isset($wancfg['wireless']['wpa']['mac_acl_enable']);
415
		$pconfig['wpa_mode'] = $wancfg['wireless']['wpa']['wpa_mode'];
416
		$pconfig['wpa_key_mgmt'] = $wancfg['wireless']['wpa']['wpa_key_mgmt'];
417
		$pconfig['wpa_pairwise'] = $wancfg['wireless']['wpa']['wpa_pairwise'];
418
		$pconfig['wpa_group_rekey'] = $wancfg['wireless']['wpa']['wpa_group_rekey'];
419
		$pconfig['wpa_gmk_rekey'] = $wancfg['wireless']['wpa']['wpa_gmk_rekey'];
420
		$pconfig['wpa_strict_rekey'] = isset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
421
		$pconfig['passphrase'] = $wancfg['wireless']['wpa']['passphrase'];
422
		$pconfig['ieee8021x'] = isset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
423
		$pconfig['rsn_preauth'] = isset($wancfg['wireless']['wpa']['rsn_preauth']);
424
		$pconfig['ext_wpa_sw'] = $wancfg['wireless']['wpa']['ext_wpa_sw'];
425
		$pconfig['wpa_enable'] = isset($wancfg['wireless']['wpa']['enable']);
426
		$pconfig['wpa_eap_client_mode'] = $wancfg['wireless']['wpa']['wpa_eap_client_mode'];
427
		$pconfig['wpa_eap_inner_auth'] = $wancfg['wireless']['wpa']['wpa_eap_inner_auth'];
428
		$pconfig['wpa_eap_inner_id'] = $wancfg['wireless']['wpa']['wpa_eap_inner_id'];
429
		$pconfig['wpa_eap_inner_password'] = base64_decode($wancfg['wireless']['wpa']['wpa_eap_inner_password']);
430
		$pconfig['wpa_eap_cert'] = $wancfg['wireless']['wpa']['wpa_eap_cert'];
431
		$pconfig['wpa_eap_ca'] = $wancfg['wireless']['wpa']['wpa_eap_ca'];
432
	}
433

    
434
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
435

    
436
}
437

    
438
$changes_applied = false;
439

    
440
if ($_POST['apply']) {
441
	unset($input_errors);
442
	if (!is_subsystem_dirty('interfaces')) {
443
		$input_errors[] = gettext("The settings have already been applied!");
444
	} else {
445
		$retval = 0;
446
		unlink_if_exists("{$g['tmp_path']}/config.cache");
447
		clear_subsystem_dirty('interfaces');
448

    
449
		$vlan_redo = array();
450
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
451
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
452
			foreach ($toapplylist as $ifapply => $ifcfgo) {
453
				$realif = get_real_interface($ifapply);
454
				$ifmtu = get_interface_mtu($realif);
455
				if (config_path_enabled("interfaces/{$ifapply}")) {
456
					interface_bring_down($ifapply, false, $ifcfgo);
457
					interface_configure($ifapply, true);
458
					if (config_get_path("interfaces/{$ifapply}/ipaddrv6") == "track6") {
459
						/* call interface_track6_configure with linkup true so
460
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
461
						   just call interface_configure with linkup true as
462
						   that skips bridge membership addition.
463
						*/
464
						$wancfg = config_get_path("interfaces/{$ifapply}");
465
						interface_track6_configure($ifapply, $wancfg, true);
466
					}
467
				} else {
468
					interface_bring_down($ifapply, true, $ifcfgo);
469
				}
470
				restart_interface_services($ifapply, $ifcfg['ipaddrv6']);
471
				$mtu = config_get_path("interfaces/{$ifapply}/mtu");
472
				if (interface_has_clones($realif) &&
473
				    ($mtu && ($mtu != $ifmtu)) ||
474
				    (!$mtu && (get_interface_default_mtu() != $ifmtu))) { 
475
					$vlan_redo[] = $realif;
476
				}
477
			}
478
		}
479

    
480
		/*
481
                 * If the parent interface has changed MTU above, the VLANs needs to be
482
                 * redone.
483
		 */
484
		if (!empty($vlan_redo)) {
485
			foreach ($vlan_redo as $vlredo) {
486
				interfaces_vlan_configure_mtu($vlredo);
487
			}
488
		}
489

    
490
		/* sync filter configuration */
491
		setup_gateways_monitor();
492

    
493
		clear_subsystem_dirty('interfaces');
494

    
495
		$retval |= filter_configure();
496

    
497
		enable_rrd_graphing();
498

    
499
		$changes_applied = true;
500

    
501
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
502
			clear_subsystem_dirty('staticroutes');
503
		}
504

    
505
		send_event("service reload packages");
506
	}
507
	@unlink("{$g['tmp_path']}/.interfaces.apply");
508
} else if ($_POST['save']) {
509

    
510
	unset($input_errors);
511
	$pconfig = $_POST;
512

    
513
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
514
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
515
	} else {
516
		$pconfig['track6-prefix-id'] = 0;
517
	}
518

    
519
	/* filter out spaces from descriptions */
520
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
521

    
522
	/* okay first of all, cause we are just hiding the PPPoE HTML
523
	 * fields related to PPPoE resets, we are going to unset $_POST
524
	 * vars, if the reset feature should not be used. Otherwise the
525
	 * data validation procedure below, may trigger a false error
526
	 * message.
527
	 */
528
	if (empty($_POST['pppoe-reset-type'])) {
529
		unset($_POST['pppoe_pr_type']);
530
		unset($_POST['pppoe_resethour']);
531
		unset($_POST['pppoe_resetminute']);
532
		unset($_POST['pppoe_resetdate']);
533
		unset($_POST['pppoe_pr_preset_val']);
534
	}
535

    
536
	/* input validation */
537
	$reqdfields = explode(" ", "descr");
538
	$reqdfieldsn = array(gettext("Description"));
539
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
540

    
541
	if (!$input_errors) {
542
		/* Reserved name? */
543
		global $pf_reserved_keywords, $reserved_table_names;
544
		$pf_reserved_keywords = array_merge($pf_reserved_keywords, $reserved_table_names);
545
		foreach ($pf_reserved_keywords as $rk) {
546
			if (strcasecmp($rk, $_POST['descr']) == 0) {
547
				$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as an interface name: %s"), $rk);
548
			}
549
		}
550

    
551
		/* description unique? */
552
		foreach ($ifdescrs as $ifent => $ifdescr) {
553
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
554
				$input_errors[] = gettext("An interface with the specified description already exists.");
555
				break;
556
			}
557
		}
558

    
559
		/* Is the description already used as an alias name? */
560
		foreach (config_get_path('aliases/alias', []) as $alias) {
561
			if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
562
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
563
			}
564
		}
565

    
566
		/* Is the description already used as an interface group name? */
567
		foreach (config_get_path('ifgroups/ifgroupentry', []) as $ifgroupentry) {
568
			if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
569
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
570
			}
571
		}
572

    
573
		if (is_numeric($_POST['descr'])) {
574
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
575
		}
576

    
577
		if ((strlen(trim($_POST['descr'])) > 25) && ((substr($realifname, 0, 4) == 'ovpn') ||
578
		    (substr($realifname, 0, 5) == 'ipsec'))) {
579
			$input_errors[] = gettext("The OpenVPN and VTI interface description must be less than 26 characters long.");
580
		}
581

    
582
		if ((strlen(trim($_POST['descr'])) > 22) && ((substr($realifname, 0, 3) == 'gif') ||
583
		    (substr($realifname, 0, 3) == 'gre'))) {
584
			$input_errors[] = gettext("The GIF and GRE interface description must be less than 23 characters long.");
585
		}
586

    
587
		/*
588
		 * Packages (e.g. tinc) create interface groups, reserve this
589
		 * namespace pkg_ for them.
590
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
591
		 */
592
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
593
			$input_errors[] = gettext("The interface description cannot start with pkg_");
594
		}
595
	}
596

    
597
	if ($_POST['blockbogons'] == "yes" &&
598
	    config_path_enabled('system','ipv6allow') &&
599
	    (config_get_path('system/maximumtableentries', 0) <
600
	     g_get('minimumtableentries_bogonsv6'))) {
601
		$input_errors[] = sprintf(gettext(
602
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
603
		    g_get('minimumtableentries_bogonsv6'));
604
	}
605

    
606
	if (config_path_enabled("dhcpd/{$if}")) {
607
		if (!preg_match("/^staticv4/", $_POST['type'])) {
608
			$input_errors[] = gettext("The DHCP Server is active " .
609
			    "on this interface and it can be used only with " .
610
			    "a static IP configuration. Please disable the " .
611
			    "DHCP Server service on this interface first, " .
612
			    "then change the interface configuration.");
613
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
614
			$input_errors[] = gettext("The DHCP Server is active " .
615
			    "on this interface and it can be used only with " .
616
			    "IPv4 subnet < 31. Please disable the " .
617
			    "DHCP Server service on this interface first, " .
618
			    "then change the interface configuration.");
619
		}
620
	}
621
	if (isset($config['dhcpdv6']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
622
		if (config_path_enabled("dhcpdv6/{$if}")) {
623
			$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only " .
624
			    "with a static IPv6 configuration. Please disable the DHCPv6 Server service on this " .
625
			    "interface first, then change the interface configuration.");
626
		}
627
		if (config_get_path("dhcpdv6/{$if}/ramode", "disabled") != "disabled") {
628
			$input_errors[] = gettext("The Router Advertisements Server is active on this interface and it can " .
629
			    "be used only with a static IPv6 configuration. Please disable the Router Advertisements " .
630
			    "Server service on this interface first, then change the interface configuration.");
631
		}
632
	}
633

    
634
	switch (strtolower($_POST['type'])) {
635
		case "staticv4":
636
			$reqdfields = explode(" ", "ipaddr subnet gateway");
637
			$reqdfieldsn = array(gettext("IPv4 address"), gettext("Subnet bit count"), gettext("Gateway"));
638
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
639
			break;
640
		case "none":
641
			foreach (config_get_path('virtualip/vip', []) as $vip) {
642
				if (is_ipaddrv4($vip['subnet']) && $vip['interface'] == $if) {
643
					$input_errors[] = gettext("This interface is referenced by IPv4 VIPs. Please delete those before setting the interface to 'none' configuration.");
644
				}
645
			}
646
			break;
647
		case "ppp":
648
			$reqdfields = explode(" ", "port phone");
649
			$reqdfieldsn = array(gettext("Modem Port"), gettext("Phone Number"));
650
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
651
			break;
652
		case "pppoe":
653
			if ($_POST['pppoe_dialondemand']) {
654
				$reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
655
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"), gettext("Dial on demand"), gettext("Idle timeout value"));
656
			} else {
657
				$reqdfields = explode(" ", "pppoe_username pppoe_password");
658
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"));
659
			}
660
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
661
			break;
662
		case "pptp":
663
			if ($_POST['pptp_dialondemand']) {
664
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0 pptp_dialondemand pptp_idletimeout");
665
				$reqdfieldsn = array(gettext("PPTP username"), gettext("PPTP password"), gettext("PPTP local IP address"), gettext("PPTP subnet"), gettext("PPTP remote IP address"), gettext("Dial on demand"), gettext("Idle timeout value"));
666
			} else {
667
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0");
668
				$reqdfieldsn = array(gettext("PPTP username"), gettext("PPTP password"), gettext("PPTP local IP address"), gettext("PPTP subnet"), gettext("PPTP remote IP address"));
669
			}
670
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
671
			break;
672
		case "l2tp":
673
			if ($_POST['pptp_dialondemand']) {
674
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0 pptp_dialondemand pptp_idletimeout");
675
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"), gettext("Dial on demand"), gettext("Idle timeout value"));
676
			} else {
677
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0");
678
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"));
679
			}
680
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
681
			break;
682
	}
683
	switch (strtolower($_POST['type6'])) {
684
		case "staticv6":
685
			$reqdfields = explode(" ", "ipaddrv6 subnetv6 gatewayv6");
686
			$reqdfieldsn = array(gettext("IPv6 address"), gettext("Subnet bit count"), gettext("Gateway"));
687
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
688
			break;
689
		case "none":
690
			foreach (config_get_path('virtualip/vip', []) as $vip) {
691
				if (is_ipaddrv6($vip['subnet']) && $vip['interface'] == $if) {
692
					$input_errors[] = gettext("This interface is referenced by IPv6 VIPs. Please delete those before setting the interface to 'none' configuration.");
693
				}
694
			}
695
			break;
696
		case "dhcp6":
697
			if (in_array($wancfg['ipaddrv6'], array())) {
698
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
699
			}
700
			if ($_POST['dhcp6-ia-pd-send-hint'] && strtolower($_POST['dhcp6-ia-pd-len']) == 'none') {
701
				$input_errors[] = gettext('DHCPv6 Prefix Delegation size must be provided when Send IPv6 prefix hint flag is checked');
702
			}
703
			if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_id']) &&
704
			    !is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
705
				$input_errors[] = gettext('DHCPv6 advanced id-assoc na ID value must be empty or an integer.');
706
			}
707
			if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_id']) &&
708
			    !is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
709
				$input_errors[] = gettext('DHCPv6 advanced id-assoc pd ID value must be empty or an integer.');
710
			}
711
			if (!empty($_POST['adv_dhcp6_prefix_interface_statement_sla_id']) &&
712
			    !is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
713
				$input_errors[] = gettext('DHCPv6 advanced Prefix Interface sla-id value must be empty or an integer.');
714
			}
715
			if (!empty($_POST['adv_dhcp6_prefix_interface_statement_sla_len']) &&
716
			    !is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
717
				$input_errors[] = gettext('DHCPv6 advanced Prefix Interface sla-len value must be empty or an integer.');
718
			}
719
			break;
720
		case "6rd":
721
			foreach ($ifdescrs as $ifent => $ifdescr) {
722
				if ($if != $ifent && (config_get_path("interfaces/{$ifent}/ipaddrv6") == $_POST['type6'])) {
723
					if (config_get_path("interfaces/{$ifent}/prefix-6rd") == $_POST['prefix-6rd']) {
724
						$input_errors[] = gettext("Only one interface can be configured within a single 6rd prefix.");
725
						break;
726
					}
727
				}
728
			}
729
			if (!is_subnetv6($_POST['prefix-6rd'])) {
730
				$input_errors[] = gettext("6RD Prefix must be a valid IPv6 prefix.");
731
			}
732
			if (!is_ipaddrv4($_POST['gateway-6rd'])) {
733
				$input_errors[] = gettext("6RD Border Relay must be an IPv4 address.");
734
			}
735
			if (in_array($wancfg['ipaddrv6'], array())) {
736
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
737
			}
738
			break;
739
		case "6to4":
740
			foreach ($ifdescrs as $ifent => $ifdescr) {
741
				if ($if != $ifent && (config_get_path("interfaces/{$ifent}/ipaddrv6") == $_POST['type6'])) {
742
					$input_errors[] = sprintf(gettext("Only one interface can be configured as 6to4."), $_POST['type6']);
743
					break;
744
				}
745
			}
746
			if (in_array($wancfg['ipaddrv6'], array())) {
747
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
748
			}
749
			break;
750
		case "track6":
751
			/* needs to check if $track6-prefix-id is used on another interface */
752
			if (in_array($wancfg['ipaddrv6'], array())) {
753
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
754
			}
755

    
756
			if (empty($_POST['track6-interface'])) {
757
				$input_errors[] = gettext("A valid interface to track must be selected.");
758
			}
759

    
760
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
761
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
762
			} else {
763
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
764
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
765
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
766
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
767
				} else {
768
					foreach ($ifdescrs as $ifent => $ifdescr) {
769
						if ($if == $ifent) {
770
							continue;
771
						}
772
						if (config_get_path("interfaces/{$ifent}/ipaddrv6") == 'track6' &&
773
						    config_get_path("interfaces/{$ifent}/track6-interface") == $_POST['track6-interface'] &&
774
						    config_get_path("interfaces/{$ifent}/track6-prefix-id") == $track6_prefix_id) {
775
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
776
						}
777
					}
778
				}
779
			}
780
			break;
781
	}
782

    
783
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
784
	$staticroutes = get_staticroutes(true);
785
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
786
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
787
		$_POST['ipaddr'] = trim($_POST['ipaddr']);
788
		if (!is_ipaddrv4($_POST['ipaddr'])) {
789
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
790
		} else {
791
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
792
			if (count($where_ipaddr_configured)) {
793
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
794
				foreach ($where_ipaddr_configured as $subnet_conflict) {
795
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
796
				}
797
				$input_errors[] = $subnet_conflict_text;
798
			}
799

    
800
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
801
			if ($_POST['subnet'] < 31) {
802
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
803
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
804
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
805
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
806
				}
807
			}
808

    
809
			foreach ($staticroutes as $route_subnet) {
810
				list($network, $subnet) = explode("/", $route_subnet);
811
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
812
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
813
					break;
814
				}
815
				unset($network, $subnet);
816
			}
817
		}
818
	}
819
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
820
		$_POST['ipaddrv6'] = trim(addrtolower($_POST['ipaddrv6']));
821

    
822
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
823
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
824
		} else {
825
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
826
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
827
			}
828
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
829
			if (count($where_ipaddr_configured)) {
830
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
831
				foreach ($where_ipaddr_configured as $subnet_conflict) {
832
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
833
				}
834
				$input_errors[] = $subnet_conflict_text;
835
			}
836

    
837
			foreach ($staticroutes as $route_subnet) {
838
				list($network, $subnet) = explode("/", $route_subnet);
839
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
840
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
841
					break;
842
				}
843
				unset($network, $subnet);
844
			}
845
		}
846
	}
847
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
848
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
849
	}
850
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
851
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
852
	}
853
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
854
		$input_errors[] = gettext("A valid alias IP address must be specified.");
855
	}
856
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
857
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
858
	}
859
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
860
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
861
	}
862

    
863
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
864
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
865
		$match = false;
866
		foreach ($a_gateways as $gateway) {
867
			if (in_array($_POST['gateway'], $gateway)) {
868
				$match = true;
869
			}
870
		}
871
		if (!$match) {
872
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
873
		}
874
	}
875
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
876
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
877
		$match = false;
878
		foreach ($a_gateways as $gateway) {
879
			if (in_array($_POST['gatewayv6'], $gateway)) {
880
				$match = true;
881
			}
882
		}
883
		if (!$match) {
884
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
885
		}
886
	}
887

    
888
	if ($_POST['provider'] && strpos($_POST['provider'], "\"")) {
889
		$input_errors[] = gettext("The service name may not contain quote characters.");
890
	}
891
	if ($_POST['hostuniq'] && !preg_match('/^[a-zA-Z0-9]+$/i', $_POST['hostuniq'])) {
892
		$input_errors[] = gettext("The Host-Uniq value can only be hexadecimal or letters and numbers.");
893
	}
894
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
895
		$input_errors[] = gettext("The idle timeout value must be an integer.");
896
	}
897
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
898
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
899
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
900
	}
901
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
902
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
903
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
904
	}
905
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
906
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
907
	}
908
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
909
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
910
	}
911
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
912
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
913
	}
914
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
915
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
916
	}
917
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
918
		$input_errors[] = gettext("The idle timeout value must be an integer.");
919
	}
920
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
921
		$input_errors[] = gettext("A valid MAC address must be specified.");
922
	}
923
	if ($_POST['mtu']) {
924
		if (!is_numericint($_POST['mtu'])) {
925
			$input_errors[] = "MTU must be an integer.";
926
		}
927
		if (substr($wancfg['if'], 0, 3) == 'gif') {
928
			$min_mtu = 1280;
929
			$max_mtu = 8192;
930
		} elseif (($_POST['ipaddrv6'] == '6rd') || ($_POST['ipaddrv6'] == '6to4')) {
931
			$min_mtu = 1300;
932
			$max_mtu = 9000;
933
		} else {
934
			$min_mtu = 576;
935
			$max_mtu = 9000;
936
		}
937

    
938
		if ($_POST['mtu'] < $min_mtu || $_POST['mtu'] > $max_mtu) {
939
			$input_errors[] = sprintf(gettext("The MTU must be between %d and %d bytes."), $min_mtu, $max_mtu);
940
		}
941

    
942
		unset($min_mtu, $max_mtu);
943

    
944
		if (interface_is_vlan($wancfg['if']) != NULL) {
945
			$realhwif_array = get_parent_interface($wancfg['if']);
946
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
947
			$parent_realhwif = $realhwif_array[0];
948
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
949
			$mtu = 0;
950
			if (!empty($parent_if) && !(config_get_path("interfaces/{$parent_if}/mtu")))
951
				$mtu = intval(config_get_path("interfaces/{$parent_if}/mtu"));
952
			if ($mtu == 0)
953
				$mtu = get_interface_mtu($parent_realhwif);
954
			if ($_POST['mtu'] > $mtu)
955
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
956
		} else {
957
			foreach ($config['interfaces'] as $idx => $ifdata) {
958
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
959
					continue;
960
				}
961

    
962
				$realhwif_array = get_parent_interface($ifdata['if']);
963
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
964
				$parent_realhwif = $realhwif_array[0];
965

    
966
				if ($parent_realhwif != $wancfg['if']) {
967
					continue;
968
				}
969

    
970
				if (isset($ifdata['mtu']) && $ifdata['mtu'] > $_POST['mtu']) {
971
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), $ifdata['descr']);
972
				}
973
			}
974
		}
975
	}
976
	if ($_POST['mss'] != '') {
977
		if (!is_numericint($_POST['mss']) || ($_POST['mss'] < 576 || $_POST['mss'] > 65535)) {
978
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
979
		}
980
	}
981
	/* Wireless interface? */
982
	if (isset($wancfg['wireless'])) {
983
		$reqdfields = array("mode");
984
		$reqdfieldsn = array(gettext("Mode"));
985
		if ($_POST['mode'] == 'hostap') {
986
			$reqdfields[] = "ssid";
987
			$reqdfieldsn[] = gettext("SSID");
988
			if (isset($_POST['channel']) && $_POST['channel'] == "0") {
989
				// auto channel with hostap is broken, prevent this for now.
990
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
991
			}
992
		}
993
		if (!stristr($_POST['standard'], '11n') && ($_POST['channel_width'] != "0")) {
994
			$input_errors[] = gettext("Channel width selection is only supported by 802.11n standards.");
995
		}
996
		if (stristr($_POST['standard'], '11n')) {
997
			if (!($_POST['wme_enable'])) {
998
				$input_errors[] = gettext("802.11n standards require enabling WME.");
999
			}
1000
			if (($_POST['channel_width'] != "0") && ($_POST['channel'] != "0") &&
1001
			    is_array($wl_ht_list[$_POST['standard']][$_POST['channel']]) &&
1002
			    !empty($wl_ht_list[$_POST['standard']][$_POST['channel']]) &&
1003
			    !in_array($_POST['channel_width'], $wl_ht_list[$_POST['standard']][$_POST['channel']])) {
1004
				$input_errors[] = sprintf(gettext("Unable to use %s channel width with channel %s."), strtoupper($_POST['channel_width']), $_POST['channel']);
1005
			}
1006
		}
1007
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
1008
		check_wireless_mode();
1009
		if (isset($_POST['wpa_group_rekey']) && (!is_numericint($_POST['wpa_group_rekey']) || $_POST['wpa_group_rekey'] < 1 || $_POST['wpa_group_rekey'] > 9999)) {
1010
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
1011
		}
1012
		if (isset($_POST['wpa_gmk_rekey']) && (!is_numericint($_POST['wpa_gmk_rekey']) || $_POST['wpa_gmk_rekey'] < 1 || $_POST['wpa_gmk_rekey'] > 9999)) {
1013
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
1014
		}
1015
		if (isset($_POST['wpa_group_rekey']) && isset($_POST['wpa_gmk_rekey'])) {
1016
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
1017
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
1018
			}
1019
		}
1020
		if (!empty($_POST['auth_server_addr'])) {
1021
			if (!is_domain($_POST['auth_server_addr']) && !is_ipaddr($_POST['auth_server_addr'])) {
1022
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
1023
			}
1024
		}
1025
		if (!empty($_POST['auth_server_addr2'])) {
1026
			if (!is_domain($_POST['auth_server_addr2']) && !is_ipaddr($_POST['auth_server_addr2'])) {
1027
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
1028
			}
1029
		}
1030
		if (!empty($_POST['auth_server_port'])) {
1031
			if (!is_port($_POST['auth_server_port'])) {
1032
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
1033
			}
1034
		}
1035
		if (!empty($_POST['auth_server_port2'])) {
1036
			if (!is_port($_POST['auth_server_port2'])) {
1037
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
1038
			}
1039
		}
1040
		if (isset($_POST['channel']) && !is_numericint($_POST['channel'])) {
1041
			if (!is_numericint($_POST['channel'])) {
1042
				$input_errors[] = gettext("Invalid channel specified.");
1043
			} else {
1044
				if ($_POST['channel'] > 255 || $_POST['channel'] < 0) {
1045
					$input_errors[] = gettext("Channel must be between 0-255.");
1046
				}
1047
			}
1048
		}
1049
		if (!empty($_POST['distance']) && !is_numericint($_POST['distance'])) {
1050
			$input_errors[] = gettext("Distance must be an integer.");
1051
		}
1052
		if (isset($_POST['standard']) && (stristr($_POST['standard'], '11na') || stristr($_POST['standard'], '11a'))) {
1053
			if ($_POST['channel'] != 0 && $_POST['channel'] < 15) {
1054
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
1055
			}
1056
		}
1057
		if (isset($_POST['standard']) && ($_POST['standard'] == "11b" || $_POST['standard'] == "11g")) {
1058
			if ($_POST['channel'] > 14) {
1059
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
1060
			}
1061
		}
1062
		if (!empty($_POST['protmode']) && !in_array($_POST['protmode'], array("off", "cts", "rtscts"))) {
1063
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
1064
		}
1065

    
1066
		if ($_POST['passphrase']) {
1067
			$passlen = strlen($_POST['passphrase']);
1068
			if ($passlen < 8 || $passlen > 63) {
1069
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1070
			}
1071
		}
1072

    
1073
		if ($_POST['wpa_enable'] == "yes") {
1074
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1075
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1076
			}
1077
			if (($_POST['mode'] == 'bss') & ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1078
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1079
				if (empty($_POST['wpa_eap_inner_id'])) {
1080
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1081
					    "when PEAP/TTLS authentication method is selected.");
1082
				}
1083
				if (empty($_POST['wpa_eap_inner_password'])) {
1084
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1085
					    "when PEAP/TTLS authentication method is selected.");
1086
				}
1087
			}
1088
		}
1089
	}
1090

    
1091
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1092
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1093
	}
1094

    
1095
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1096
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1097
	}
1098

    
1099
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1100
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1101
	}
1102

    
1103
	if ($_POST['gatewayip4']) {
1104
		// The user wants to add an IPv4 gateway - validate the settings
1105
		$gateway_settings4 = array();
1106

    
1107
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1108
		$gateway_settings4['interface'] = $_POST['if'];
1109
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1110
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1111
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1112
		$gateway_settings4['ipprotocol'] = 'inet';
1113
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1114
		foreach ($gw_input_errors as $input_error_text) {
1115
			$input_errors[] = $input_error_text;
1116
		}
1117
	}
1118

    
1119
	if ($_POST['gatewayip6']) {
1120
		// The user wants to add an IPv6 gateway - validate the settings
1121
		$gateway_settings6 = array();
1122

    
1123
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1124
		$gateway_settings6['interface'] = $_POST['if'];
1125
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1126
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1127
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1128
		$gateway_settings6['ipprotocol'] = 'inet6';
1129
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1130
		foreach ($gw_input_errors as $input_error_text) {
1131
			$input_errors[] = $input_error_text;
1132
		}
1133
	}
1134

    
1135
	if (!$input_errors) {
1136
		// These 3 fields can be a list of multiple data items when used for MLPPP.
1137
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
1138
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
1139
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
1140
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
1141

    
1142
		if ($wancfg['ipaddr'] != $_POST['type']) {
1143
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1144
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1145
				unset($a_ppps[$pppid]);
1146
			} else if ($wancfg['ipaddr'] == "dhcp") {
1147
				kill_dhclient_process($wancfg['if']);
1148
			}
1149
			if (($wancfg['ipaddrv6'] == "dhcp6") && ($_POST['type6'] != "dhcp6")) {
1150
				interface_dhcpv6_configure($if, $wancfg, true);
1151
			}
1152
		}
1153
		$ppp = array();
1154
		if ($wancfg['ipaddr'] != "ppp") {
1155
			unset($wancfg['ipaddr']);
1156
		}
1157
		if ($wancfg['ipaddrv6'] != "ppp") {
1158
			unset($wancfg['ipaddrv6']);
1159
		}
1160
		unset($wancfg['subnet']);
1161
		unset($wancfg['gateway']);
1162
		unset($wancfg['subnetv6']);
1163
		unset($wancfg['gatewayv6']);
1164
		unset($wancfg['dhcphostname']);
1165
		unset($wancfg['dhcprejectfrom']);
1166
		unset($wancfg['dhcp6-duid']);
1167
		unset($wancfg['dhcp6-ia-pd-len']);
1168
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1169
		unset($wancfg['dhcp6prefixonly']);
1170
		unset($wancfg['dhcp6usev4iface']);
1171
		unset($wancfg['slaacusev4iface']);
1172
		unset($wancfg['ipv6usev4iface']);
1173
		unset($wancfg['track6-interface']);
1174
		unset($wancfg['track6-prefix-id']);
1175
		unset($wancfg['dhcp6withoutra']);
1176
		unset($wancfg['dhcp6vlanenable']);
1177
		unset($wancfg['dhcp6cvpt']);
1178
		unset($wancfg['prefix-6rd']);
1179
		unset($wancfg['prefix-6rd-v4plen']);
1180
		unset($wancfg['gateway-6rd']);
1181

    
1182
		unset($wancfg['dhcpvlanenable']);
1183
		unset($wancfg['dhcpcvpt']);
1184

    
1185
		unset($wancfg['adv_dhcp_pt_timeout']);
1186
		unset($wancfg['adv_dhcp_pt_retry']);
1187
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1188
		unset($wancfg['adv_dhcp_pt_reboot']);
1189
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1190
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1191

    
1192
		unset($wancfg['adv_dhcp_pt_values']);
1193

    
1194
		unset($wancfg['adv_dhcp_send_options']);
1195
		unset($wancfg['adv_dhcp_request_options']);
1196
		unset($wancfg['adv_dhcp_required_options']);
1197
		unset($wancfg['adv_dhcp_option_modifiers']);
1198

    
1199
		unset($wancfg['adv_dhcp_config_advanced']);
1200
		unset($wancfg['adv_dhcp_config_file_override']);
1201
		unset($wancfg['adv_dhcp_config_file_override_path']);
1202

    
1203
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1204
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1205
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1206
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1207

    
1208
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1209
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1210
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1211
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1212
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1213

    
1214
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1215
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1216
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1217
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1218
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1219

    
1220
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1221
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1222
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1223

    
1224
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1225
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1226
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1227
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1228

    
1229
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1230
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1231
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1232
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1233
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1234

    
1235
		unset($wancfg['adv_dhcp6_config_advanced']);
1236
		unset($wancfg['adv_dhcp6_config_file_override']);
1237
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1238

    
1239
		unset($wancfg['pppoe_password']);
1240
		unset($wancfg['pptp_username']);
1241
		unset($wancfg['pptp_password']);
1242
		unset($wancfg['l2tp_secret']);
1243
		unset($wancfg['provider']);
1244
		unset($wancfg['hostuniq']);
1245
		unset($wancfg['ondemand']);
1246
		unset($wancfg['timeout']);
1247
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1248
			unset($wancfg['pppoe']['pppoe-reset-type']);
1249
		}
1250
		unset($wancfg['local']);
1251

    
1252
		unset($wancfg['remote']);
1253
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1254
			if ($wancfg['ipaddr'] != 'ppp') {
1255
				unset($a_ppps[$pppid]['apn']);
1256
				unset($a_ppps[$pppid]['phone']);
1257
				unset($a_ppps[$pppid]['provider']);
1258
				unset($a_ppps[$pppid]['ondemand']);
1259
			}
1260
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1261
				unset($a_ppps[$pppid]['localip']);
1262
				unset($a_ppps[$pppid]['subnet']);
1263
				unset($a_ppps[$pppid]['gateway']);
1264
			}
1265
			if ($wancfg['ipaddr'] != 'pppoe') {
1266
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1267
				unset($a_ppps[$pppid]['hostuniq']);
1268
			}
1269
			if ($wancfg['type'] != $_POST['type']) {
1270
				unset($a_ppps[$pppid]['idletimeout']);
1271
			}
1272
		}
1273

    
1274
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1275
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1276

    
1277
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1278
		switch ($_POST['type']) {
1279
			case "staticv4":
1280
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1281
				$wancfg['subnet'] = $_POST['subnet'];
1282
				if ($_POST['gateway'] != "none") {
1283
					$wancfg['gateway'] = $_POST['gateway'];
1284
				}
1285
				break;
1286
			case "dhcp":
1287
				$wancfg['ipaddr'] = "dhcp";
1288
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1289
				$wancfg['alias-address'] = $_POST['alias-address'];
1290
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1291
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1292

    
1293
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1294
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1295
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1296
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1297
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1298
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1299

    
1300
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1301

    
1302
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1303
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1304
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1305
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1306

    
1307
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1308
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1309
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1310

    
1311
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1312
				if ($gateway_item) {
1313
					$a_gateways[] = $gateway_item;
1314
				}
1315
				if ($_POST['dhcpvlanenable'] == "yes") {
1316
					$wancfg['dhcpvlanenable'] = true;
1317
				}
1318
				if (!empty($_POST['dhcpcvpt'])) {
1319
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1320
				} else {
1321
					unset($wancfg['dhcpcvpt']);
1322
				}
1323
				break;
1324
			case "ppp":
1325
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1326
				$a_ppps[$pppid]['type'] = $_POST['type'];
1327
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1328
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1329
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1330
				if ($_POST['ppp_password'] != DMYPWD) {
1331
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1332
				}
1333
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1334
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1335
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1336
				$wancfg['ipaddr'] = $_POST['type'];
1337
				break;
1338

    
1339
			case "pppoe":
1340
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1341
				$a_ppps[$pppid]['type'] = $_POST['type'];
1342
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1343
				if (isset($_POST['ppp_port'])) {
1344
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1345
				} else {
1346
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1347
				}
1348
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1349
				if ($_POST['pppoe_password'] != DMYPWD) {
1350
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1351
				}
1352
				if (!empty($_POST['provider'])) {
1353
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1354
				} else {
1355
					$a_ppps[$pppid]['provider'] = true;
1356
				}
1357
				if (!empty($_POST['hostuniq'])) {
1358
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1359
				} else {
1360
					$a_ppps[$pppid]['hostuniq'] = true;
1361
				}
1362
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1363
				if (!empty($_POST['pppoe_idletimeout'])) {
1364
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1365
				} else {
1366
					unset($a_ppps[$pppid]['idletimeout']);
1367
				}
1368

    
1369
				if (!empty($_POST['pppoe-reset-type'])) {
1370
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1371
				} else {
1372
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1373
				}
1374
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1375
				$wancfg['ipaddr'] = $_POST['type'];
1376
				if ($gateway_item) {
1377
					$a_gateways[] = $gateway_item;
1378
				}
1379

    
1380
				break;
1381
			case "pptp":
1382
			case "l2tp":
1383
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1384
				$a_ppps[$pppid]['type'] = $_POST['type'];
1385
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1386
				if (isset($_POST['ppp_port'])) {
1387
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1388
				} else {
1389
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1390
				}
1391
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1392
				if ($_POST['pptp_password'] != DMYPWD) {
1393
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1394
				}
1395
				if (($_POST['type'] == 'l2tp') && (!empty($_POST['l2tp_secret']))) {
1396
					$a_ppps[$pppid]['secret'] = base64_encode($_POST['l2tp_secret']);
1397
				} else {
1398
					unset($a_ppps[$pppid]['secret']);
1399
				}
1400
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1401
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1402
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1403
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1404
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1405
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1406
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1407
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1408
				if (!empty($_POST['pptp_idletimeout'])) {
1409
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1410
				} else {
1411
					unset($a_ppps[$pppid]['idletimeout']);
1412
				}
1413
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1414
				$wancfg['ipaddr'] = $_POST['type'];
1415
				if ($gateway_item) {
1416
					$a_gateways[] = $gateway_item;
1417
				}
1418
				break;
1419
			case "none":
1420
				break;
1421
		}
1422
		switch ($_POST['type6']) {
1423
			case "staticv6":
1424
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1425
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1426
				if ($_POST['ipv6usev4iface'] == "yes") {
1427
					$wancfg['ipv6usev4iface'] = true;
1428
				}
1429
				if ($_POST['gatewayv6'] != "none") {
1430
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1431
				}
1432
				break;
1433
			case "slaac":
1434
				$wancfg['ipaddrv6'] = "slaac";
1435
				if ($_POST['slaacusev4iface'] == "yes") {
1436
					$wancfg['slaacusev4iface'] = true;
1437
				}
1438
				break;
1439
			case "dhcp6":
1440
				$wancfg['ipaddrv6'] = "dhcp6";
1441
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1442
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1443
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1444
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1445
				}
1446
				if ($_POST['dhcp6prefixonly'] == "yes") {
1447
					$wancfg['dhcp6prefixonly'] = true;
1448
				}
1449
				if ($_POST['dhcp6usev4iface'] == "yes") {
1450
					$wancfg['dhcp6usev4iface'] = true;
1451
				}
1452
				if ($_POST['dhcp6withoutra'] == "yes") {
1453
					$wancfg['dhcp6withoutra'] = true;
1454
				}
1455
				if ($_POST['dhcp6vlanenable'] == "yes") {
1456
					$wancfg['dhcp6vlanenable'] = true;
1457
				}
1458
				if (!empty($_POST['dhcp6cvpt'])) {
1459
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1460
				} else {
1461
					unset($wancfg['dhcp6cvpt']);
1462
				}
1463

    
1464
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1465
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1466
				}
1467
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1468
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1469
				}
1470
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1471
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1472
				}
1473
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1474
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1475
				}
1476

    
1477
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1478
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1479
				}
1480
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1481
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1482
				}
1483
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1484
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1485
				}
1486
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1487
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1488
				}
1489
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1490
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1491
				}
1492

    
1493
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1494
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1495
				}
1496
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1497
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1498
				}
1499
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1500
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1501
				}
1502
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1503
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1504
				}
1505
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1506
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1507
				}
1508

    
1509
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1510
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1511
				}
1512
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1513
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1514
				}
1515
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1516
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1517
				}
1518
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1519
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1520
				}
1521
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1522
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1523
				}
1524
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1525
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1526
				}
1527
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1528
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1529
				}
1530

    
1531
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1532
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1533
				}
1534
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1535
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1536
				}
1537
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1538
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1539
				}
1540
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1541
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1542
				}
1543
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1544
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1545
				}
1546

    
1547
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1548
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1549
				}
1550
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1551
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1552
				}
1553
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1554
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1555
				}
1556

    
1557
				if ($gateway_item) {
1558
					$a_gateways[] = $gateway_item;
1559
				}
1560
				break;
1561
			case "6rd":
1562
				$wancfg['ipaddrv6'] = "6rd";
1563
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1564
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1565
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1566
				if ($gateway_item) {
1567
					$a_gateways[] = $gateway_item;
1568
				}
1569
				break;
1570
			case "6to4":
1571
				$wancfg['ipaddrv6'] = "6to4";
1572
				break;
1573
			case "track6":
1574
				$wancfg['ipaddrv6'] = "track6";
1575
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1576
				if ($_POST['track6-prefix-id--hex'] === "") {
1577
					$wancfg['track6-prefix-id'] = 0;
1578
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1579
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1580
				} else {
1581
					$wancfg['track6-prefix-id'] = 0;
1582
				}
1583
				break;
1584
			case "none":
1585
				break;
1586
		}
1587
		handle_pppoe_reset($_POST);
1588

    
1589
		if ($_POST['blockpriv'] == "yes") {
1590
			$wancfg['blockpriv'] = true;
1591
		} else {
1592
			unset($wancfg['blockpriv']);
1593
		}
1594
		if ($_POST['blockbogons'] == "yes") {
1595
			$wancfg['blockbogons'] = true;
1596
		} else {
1597
			unset($wancfg['blockbogons']);
1598
		}
1599
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1600
		/* Only update MTU in the config if the if is not a member of a
1601
		 * bridge. The display will show the bridge MTU in a disabled input
1602
		 * field, and we will maintain the user configured MTU for initial
1603
		 * configuration and in the event that the interface is removed from the
1604
		 * bridge it will return to its original MTU. */
1605
		if (!$bridged) {
1606
			if (empty($_POST['mtu'])) {
1607
				unset($wancfg['mtu']);
1608
			} else {
1609
				$wancfg['mtu'] = $_POST['mtu'];
1610
			}
1611
		}
1612
		if (empty($_POST['mss'])) {
1613
			unset($wancfg['mss']);
1614
		} else {
1615
			$wancfg['mss'] = $_POST['mss'];
1616
		}
1617
		if (empty($_POST['mediaopt'])) {
1618
			unset($wancfg['media']);
1619
			unset($wancfg['mediaopt']);
1620
		} else {
1621
			$mediaopts = explode(' ', $_POST['mediaopt']);
1622
			if ($mediaopts[0] != '') {
1623
				$wancfg['media'] = $mediaopts[0];
1624
			}
1625
			if ($mediaopts[1] != '') {
1626
				$wancfg['mediaopt'] = $mediaopts[1];
1627
			} else {
1628
				unset($wancfg['mediaopt']);
1629
			}
1630
		}
1631
		if (isset($wancfg['wireless'])) {
1632
			handle_wireless_post();
1633
		}
1634

    
1635
		write_config("Interfaces settings changed");
1636

    
1637
		if ($_POST['gatewayip4']) {
1638
			save_gateway($gateway_settings4);
1639
		}
1640

    
1641
		if ($_POST['gatewayip6']) {
1642
			save_gateway($gateway_settings6);
1643
		}
1644

    
1645
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1646
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1647
		} else {
1648
			$toapplylist = array();
1649
		}
1650
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1651
		$toapplylist[$if]['ppps'] = $old_ppps;
1652
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1653

    
1654
		mark_subsystem_dirty('interfaces');
1655

    
1656
		/* regenerate cron settings/crontab file */
1657
		configure_cron();
1658

    
1659
		header("Location: interfaces.php?if={$if}");
1660
		exit;
1661
	}
1662

    
1663
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1664
	if (!empty($_POST['ppp_port'])) {
1665
		$pconfig['port'] = $_POST['ppp_port'];
1666
	}
1667

    
1668
} // end if ($_POST['save'])
1669

    
1670
function handle_wireless_post() {
1671
	global $_POST, $config, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1672
	if (!is_array($wancfg['wireless'])) {
1673
		$wancfg['wireless'] = array();
1674
	}
1675
	$wancfg['wireless']['standard'] = $_POST['standard'];
1676
	$wancfg['wireless']['mode'] = $_POST['mode'];
1677
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1678
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1679
	$wancfg['wireless']['channel'] = $_POST['channel'];
1680
	$wancfg['wireless']['channel_width'] = $_POST['channel_width'];
1681
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1682
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1683
	$wancfg['wireless']['distance'] = $_POST['distance'];
1684
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1685
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1686
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1687
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1688
		foreach ($wl_countries_attr as $wl_country) {
1689
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1690
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1691
				break;
1692
			}
1693
		}
1694
	}
1695
	if (!is_array($wancfg['wireless']['wpa'])) {
1696
		$wancfg['wireless']['wpa'] = array();
1697
	}
1698
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1699
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1700
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1701
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1702
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1703
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1704
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1705
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1706
	$wancfg['wireless']['wpa']['wpa_eap_client_mode'] = $_POST['wpa_eap_client_mode'];
1707
	$wancfg['wireless']['wpa']['wpa_eap_inner_auth'] = $_POST['wpa_eap_inner_auth'];
1708
	$wancfg['wireless']['wpa']['wpa_eap_inner_id'] = $_POST['wpa_eap_inner_id'];
1709
	$wancfg['wireless']['wpa']['wpa_eap_inner_password'] = base64_encode($_POST['wpa_eap_inner_password']);
1710
	$wancfg['wireless']['wpa']['wpa_eap_cert'] = $_POST['wpa_eap_cert'];
1711
	$wancfg['wireless']['wpa']['wpa_eap_ca'] = $_POST['wpa_eap_ca'];
1712
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1713
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1714
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1715
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1716
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1717
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1718

    
1719
	if ($_POST['persistcommonwireless'] == "yes") {
1720
		if (!is_array($config['wireless'])) {
1721
			config_set_path('wireless', array());
1722
		}
1723
		if (!is_array(config_get_path('wireless/interfaces'))) {
1724
			config_set_path('wireless/interfaces', array());
1725
		}
1726
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1727
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1728
		}
1729
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1730
		config_del_path("wireless/interfaces/{$wlanbaseif}");
1731
	}
1732
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1733
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1734
	} else if (isset($wancfg['wireless']['diversity'])) {
1735
		unset($wancfg['wireless']['diversity']);
1736
	}
1737
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1738
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1739
	} else if (isset($wancfg['wireless']['txantenna'])) {
1740
		unset($wancfg['wireless']['txantenna']);
1741
	}
1742
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1743
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1744
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1745
		unset($wancfg['wireless']['rxantenna']);
1746
	}
1747
	if ($_POST['hidessid_enable'] == "yes") {
1748
		$wancfg['wireless']['hidessid']['enable'] = true;
1749
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1750
		unset($wancfg['wireless']['hidessid']['enable']);
1751
	}
1752
	if ($_POST['mac_acl_enable'] == "yes") {
1753
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1754
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1755
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1756
	}
1757
	if ($_POST['rsn_preauth'] == "yes") {
1758
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1759
	} else {
1760
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1761
	}
1762
	if ($_POST['ieee8021x'] == "yes") {
1763
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1764
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1765
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1766
	}
1767
	if ($_POST['wpa_strict_rekey'] == "yes") {
1768
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1769
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1770
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1771
	}
1772
	if ($_POST['debug_mode'] == "yes") {
1773
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1774
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1775
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1776
	}
1777
	if ($_POST['wpa_enable'] == "yes") {
1778
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1779
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1780
		unset($wancfg['wireless']['wpa']['enable']);
1781
	}
1782

    
1783
	if ($_POST['wme_enable'] == "yes") {
1784
		if (!is_array($wancfg['wireless']['wme'])) {
1785
			$wancfg['wireless']['wme'] = array();
1786
		}
1787
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1788
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1789
		unset($wancfg['wireless']['wme']['enable']);
1790
	}
1791
	if ($_POST['puremode'] == "11g") {
1792
		if (!is_array($wancfg['wireless']['pureg'])) {
1793
			$wancfg['wireless']['pureg'] = array();
1794
		}
1795
		$wancfg['wireless']['pureg']['enable'] = true;
1796
	} else if ($_POST['puremode'] == "11n") {
1797
		if (!is_array($wancfg['wireless']['puren'])) {
1798
			$wancfg['wireless']['puren'] = array();
1799
		}
1800
		$wancfg['wireless']['puren']['enable'] = true;
1801
	} else {
1802
		if (isset($wancfg['wireless']['pureg'])) {
1803
			unset($wancfg['wireless']['pureg']);
1804
		}
1805
		if (isset($wancfg['wireless']['puren'])) {
1806
			unset($wancfg['wireless']['puren']);
1807
		}
1808
	}
1809
	if ($_POST['apbridge_enable'] == "yes") {
1810
		if (!is_array($wancfg['wireless']['apbridge'])) {
1811
			$wancfg['wireless']['apbridge'] = array();
1812
		}
1813
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1814
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1815
		unset($wancfg['wireless']['apbridge']['enable']);
1816
	}
1817
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1818
		if (!is_array($wancfg['wireless']['turbo'])) {
1819
			$wancfg['wireless']['turbo'] = array();
1820
		}
1821
		$wancfg['wireless']['turbo']['enable'] = true;
1822
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1823
		unset($wancfg['wireless']['turbo']['enable']);
1824
	}
1825

    
1826
	interface_sync_wireless_clones($wancfg, true);
1827
}
1828

    
1829
function check_wireless_mode() {
1830
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1831

    
1832
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1833
		return;
1834
	}
1835

    
1836
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1837
		$clone_count = 1;
1838
	} else {
1839
		$clone_count = 0;
1840
	}
1841

    
1842
	foreach (config_get_path('wireless/clone', []) as $clone) {
1843
		if ($clone['if'] == $wlanbaseif) {
1844
				$clone_count++;
1845
		}
1846
	}
1847

    
1848
	if ($clone_count > 1) {
1849
		$old_wireless_mode = $wancfg['wireless']['mode'];
1850
		$wancfg['wireless']['mode'] = $_POST['mode'];
1851
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1852
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."), $wlan_modes[$wancfg['wireless']['mode']]);
1853
		} else {
1854
			pfSense_interface_destroy("{$wlanif}_");
1855
		}
1856
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1857
	}
1858
}
1859

    
1860
// Find all possible media options for the interface
1861
$mediaopts_list = array();
1862
$intrealname = config_get_path("interfaces/{$if}/if");
1863
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1864
foreach ($mediaopts as $mediaopt) {
1865
	preg_match("/media (.*)/", $mediaopt, $matches);
1866
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1867
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1868
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1869
	} else {
1870
		// there is only media like "media 1000baseT"
1871
		array_push($mediaopts_list, $matches[1]);
1872
	}
1873
}
1874

    
1875
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1876
$shortcut_section = "interfaces";
1877

    
1878
$types4 = array("ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP"));
1879

    
1880
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1881
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1882
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1883
}
1884

    
1885
$types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), "dhcp6" => gettext("DHCP6"), "slaac" => gettext("SLAAC"), "6rd" => gettext("6rd Tunnel"), "6to4" => gettext("6to4 Tunnel"), "track6" => gettext("Track Interface"));
1886

    
1887
// Get the MAC address
1888
$defgatewayname4 = $wancfg['descr'] . "GW";
1889
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1890

    
1891
function build_mediaopts_list() {
1892
	global $mediaopts_list;
1893

    
1894
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1895
			 " " =>	 gettext("------- Media Supported by this interface -------")
1896
			];
1897

    
1898
	foreach ($mediaopts_list as $mediaopt) {
1899
		$list[$mediaopt] = $mediaopt;
1900
	}
1901

    
1902
	return($list);
1903
}
1904

    
1905
function build_gateway_list() {
1906
	global $a_gateways, $if;
1907

    
1908
	$list = array("none" => gettext("None"));
1909
	foreach ($a_gateways as $gateway) {
1910
		if (empty($gateway)) {
1911
			continue;
1912
		}
1913
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1914
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1915
		}
1916
	}
1917

    
1918
	return($list);
1919
}
1920

    
1921
function build_gatewayv6_list() {
1922
	global $a_gateways, $if;
1923

    
1924
	$list = array("none" => gettext("None"));
1925
	foreach ($a_gateways as $gateway) {
1926
		if (empty($gateway)) {
1927
			continue;
1928
		}
1929
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1930
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1931
		}
1932
	}
1933

    
1934
	return($list);
1935
}
1936

    
1937
include("head.inc");
1938

    
1939
if ($input_errors) {
1940
	print_input_errors($input_errors);
1941
}
1942

    
1943
if (is_subsystem_dirty('interfaces')) {
1944
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1945
					gettext("The changes must be applied to take effect.") . "<br />" .
1946
					gettext("Don't forget to adjust the DHCP Server range if needed after applying."));
1947
}
1948

    
1949
if ($changes_applied) {
1950
	print_apply_result_box($retval);
1951
}
1952

    
1953
$form = new Form();
1954

    
1955
$section = new Form_Section('General Configuration');
1956

    
1957
$section->addInput(new Form_Checkbox(
1958
	'enable',
1959
	'Enable',
1960
	'Enable interface',
1961
	$pconfig['enable'],
1962
	'yes'
1963
));
1964

    
1965
$section->addInput(new Form_Input(
1966
	'descr',
1967
	'*Description',
1968
	'text',
1969
	$pconfig['descr']
1970
))->setHelp('Enter a description (name) for the interface here.');
1971

    
1972
if ($show_address_controls) {
1973
	$section->addInput(new Form_Select(
1974
		'type',
1975
		'IPv4 Configuration Type',
1976
		$pconfig['type'],
1977
		$types4
1978
	));
1979
	$section->addInput(new Form_Select(
1980
		'type6',
1981
		'IPv6 Configuration Type',
1982
		$pconfig['type6'],
1983
		$types6
1984
	));
1985
} else {
1986
	$section->addInput(new Form_StaticText(
1987
		'IPv4/IPv6 Configuration',
1988
		"This interface type does not support manual address configuration on this page. "
1989
	));
1990
	$form->addGlobal(new Form_Input(
1991
		'type',
1992
		null,
1993
		'hidden',
1994
		'none'
1995
	));
1996
	$form->addGlobal(new Form_Input(
1997
		'type6',
1998
		null,
1999
		'hidden',
2000
		'none'
2001
	));
2002
}
2003

    
2004
if (!is_pseudo_interface($intrealname, true)) {
2005
	$macaddress = new Form_Input(
2006
		'spoofmac',
2007
		'MAC Address',
2008
		'text',
2009
		$pconfig['spoofmac'],
2010
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
2011
	);
2012

    
2013
	if (interface_is_vlan($realifname)) {
2014
		$macaddress->setDisabled();
2015
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
2016
		    'set on its parent interface');
2017
	} else {
2018
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
2019
		    'MAC address of this interface.%sEnter a MAC address in the ' .
2020
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
2021
	}
2022

    
2023
	$section->addInput($macaddress);
2024
}
2025

    
2026
$mtuInput = $section->addInput(new Form_Input(
2027
	'mtu',
2028
	'MTU',
2029
	'number',
2030
	$pconfig['mtu'],
2031
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2032
			'This is typically 1500 bytes but can vary in some circumstances.');
2033
/* Do not allow MTU changes for interfaces in a bridge */
2034
if ($bridged) {
2035
	$mtuInput->setDisabled();
2036
	$mtuInput->setHelp('This interface is a bridge member, its MTU is ' .
2037
					   'controlled by its parent bridge interface');
2038
	$mtuInput->setPlaceholder(get_interface_mtu($bridged));
2039
	$mtuInput->setValue(null);
2040
}
2041

    
2042
$section->addInput(new Form_Input(
2043
	'mss',
2044
	'MSS',
2045
	'number',
2046
	$pconfig['mss']
2047
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2048
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2049

    
2050
if (count($mediaopts_list) > 0) {
2051
	$section->addInput(new Form_Select(
2052
		'mediaopt',
2053
		'Speed and Duplex',
2054
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt")),
2055
		build_mediaopts_list() 
2056
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2057
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2058
}
2059

    
2060
$form->add($section);
2061

    
2062
$section = new Form_Section('Static IPv4 Configuration');
2063
$section->addClass('staticv4');
2064

    
2065
$section->addInput(new Form_IpAddress(
2066
	'ipaddr',
2067
	'*IPv4 Address',
2068
	$pconfig['ipaddr'],
2069
	'V4'
2070
))->addMask('subnet', $pconfig['subnet'], 32);
2071

    
2072
$group = new Form_Group('IPv4 Upstream gateway');
2073

    
2074
$group->add(new Form_Select(
2075
	'gateway',
2076
	'IPv4 Upstream Gateway',
2077
	$pconfig['gateway'],
2078
	build_gateway_list()
2079
));
2080

    
2081
$group->add(new Form_Button(
2082
	'addgw4',
2083
	'Add a new gateway',
2084
	null,
2085
	'fa-plus'
2086
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2087

    
2088
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.%1$s' .
2089
				'On local area network interfaces the upstream gateway should be "none".%1$s' .
2090
				'Selecting an upstream gateway causes the firewall to treat this interface as a %2$sWAN type interface%4$s.%1$s' .
2091
				'Gateways can be managed by %3$sclicking here%4$s.', '<br />', '<a target="_blank" href="https://docs.netgate.com/pfsense/en/latest/interfaces/wanvslan.html">', '<a target="_blank" href="system_gateways.php">', '</a>');
2092

    
2093
$section->add($group);
2094

    
2095
$form->add($section);
2096

    
2097
$section = new Form_Section('SLAAC IPv6 Configuration');
2098
$section->addClass('slaac');
2099

    
2100
$section->addInput(new Form_Checkbox(
2101
	'slaacusev4iface',
2102
	'Use IPv4 connectivity as parent interface',
2103
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2104
	$pconfig['slaacusev4iface']
2105
));
2106

    
2107
$form->add($section);
2108

    
2109
$section = new Form_Section('Static IPv6 Configuration');
2110
$section->addClass('staticv6');
2111

    
2112
$section->addInput(new Form_IpAddress(
2113
	'ipaddrv6',
2114
	'*IPv6 address',
2115
	$pconfig['ipaddrv6'],
2116
	'V6'
2117
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2118

    
2119
$section->addInput(new Form_Checkbox(
2120
	'ipv6usev4iface',
2121
	'Use IPv4 connectivity as parent interface',
2122
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2123
	$pconfig['ipv6usev4iface']
2124
));
2125

    
2126
$group = new Form_Group('IPv6 Upstream gateway');
2127

    
2128
$group->add(new Form_Select(
2129
	'gatewayv6',
2130
	'IPv6 Upstream Gateway',
2131
	$pconfig['gatewayv6'],
2132
	build_gatewayv6_list()
2133
));
2134

    
2135
$group->add(new Form_Button(
2136
	'addgw6',
2137
	'Add a new gateway',
2138
	null,
2139
	'fa-plus'
2140
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2141

    
2142
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.%s' .
2143
				'On local LANs the upstream gateway should be "none". ', '<br />');
2144

    
2145
$section->add($group);
2146
$form->add($section);
2147

    
2148
// Add new gateway modal pop-up for IPv6
2149
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2150

    
2151
$modal->addInput(new Form_Checkbox(
2152
	'defaultgw6',
2153
	'Default',
2154
	'Default gateway',
2155
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2156
));
2157

    
2158
$modal->addInput(new Form_Input(
2159
	'gatewayname6',
2160
	'Gateway name',
2161
	'text',
2162
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2163
));
2164

    
2165
$modal->addInput(new Form_IpAddress(
2166
	'gatewayip6',
2167
	'Gateway IPv6',
2168
	$gateway_settings6['gateway'],
2169
	'V6'
2170
));
2171

    
2172
$modal->addInput(new Form_Input(
2173
	'gatewaydescr6',
2174
	'Description',
2175
	'text',
2176
	$gateway_settings6['descr']
2177
));
2178

    
2179
$btnaddgw6 = new Form_Button(
2180
	'add6',
2181
	'Add',
2182
	null,
2183
	'fa-plus'
2184
);
2185

    
2186
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2187

    
2188
$btncnxgw6 = new Form_Button(
2189
	'cnx6',
2190
	'Cancel',
2191
	null,
2192
	'fa-undo'
2193
);
2194

    
2195
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2196

    
2197
$modal->addInput(new Form_StaticText(
2198
	null,
2199
	$btnaddgw6 . $btncnxgw6
2200
));
2201

    
2202
$form->add($modal);
2203

    
2204
// ==== DHCP client configuration =============================
2205

    
2206
$section = new Form_Section('DHCP Client Configuration');
2207
$section->addClass('dhcp');
2208

    
2209
$group = new Form_Group('Options');
2210

    
2211
$group->add(new Form_Checkbox(
2212
	'adv_dhcp_config_advanced',
2213
	null,
2214
	'Advanced Configuration',
2215
	$pconfig['adv_dhcp_config_advanced']
2216
))->setHelp('Use advanced DHCP configuration options.');
2217

    
2218
$group->add(new Form_Checkbox(
2219
	'adv_dhcp_config_file_override',
2220
	null,
2221
	'Configuration Override',
2222
	$pconfig['adv_dhcp_config_file_override']
2223
))->setHelp('Override the configuration from this file.');
2224

    
2225
$section->add($group);
2226

    
2227
$section->addInput(new Form_Input(
2228
	'dhcphostname',
2229
	'Hostname',
2230
	'text',
2231
	$pconfig['dhcphostname']
2232
))->setHelp('The value in this field is sent as the DHCP client identifier and hostname when requesting a DHCP lease. Some ISPs may require this (for client identification).');
2233

    
2234
$section->addInput(new Form_IpAddress(
2235
	'alias-address',
2236
	'Alias IPv4 address',
2237
	$pconfig['alias-address'],
2238
	'V4'
2239
))->addMask('alias-subnet', $pconfig['alias-subnet'], 32)->setHelp('The value in this field is used as a fixed alias IPv4 address by the DHCP client.');
2240

    
2241
$section->addInput(new Form_Input(
2242
	'dhcprejectfrom',
2243
	'Reject leases from',
2244
	'text',
2245
	$pconfig['dhcprejectfrom']
2246
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2247
			'(separate multiple entries with a comma). ' .
2248
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2249

    
2250
if (interface_is_vlan($wancfg['if']) != NULL) {
2251

    
2252
	$group = new Form_Group('DHCP VLAN Priority');
2253
	$group->add(new Form_Checkbox(
2254
		'dhcpvlanenable',
2255
		null,
2256
		'Enable dhcpclient VLAN Priority tagging',
2257
		$pconfig['dhcpvlanenable']
2258
	))->setHelp('Normally off unless specifically required by the ISP.');
2259

    
2260
	$group->add(new Form_Select(
2261
		'dhcpcvpt',
2262
		'VLAN Prio',
2263
		$pconfig['dhcpcvpt'],
2264
		$vlanprio
2265
	))->setHelp('Choose 802.1p priority to set.');
2266

    
2267
	$section->add($group);
2268
}
2269

    
2270
$group = new Form_Group('Protocol timing');
2271
$group->addClass('dhcpadvanced');
2272
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.%1$s' .
2273
				'See %2$shere%3$s for more information.', '<br />', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#PROTOCOL_TIMING">', '</a>');
2274

    
2275
$group->add(new Form_Input(
2276
	'adv_dhcp_pt_timeout',
2277
	null,
2278
	'number',
2279
	$pconfig['adv_dhcp_pt_timeout']
2280
))->setHelp('Timeout');
2281

    
2282
$group->add(new Form_Input(
2283
	'adv_dhcp_pt_retry',
2284
	null,
2285
	'number',
2286
	$pconfig['adv_dhcp_pt_retry']
2287
))->setHelp('Retry');
2288

    
2289
$group->add(new Form_Input(
2290
	'adv_dhcp_pt_select_timeout',
2291
	null,
2292
	'number',
2293
	$pconfig['adv_dhcp_pt_select_timeout'],
2294
	['min' => 0]
2295
))->setHelp('Select timeout');
2296

    
2297
$group->add(new Form_Input(
2298
	'adv_dhcp_pt_reboot',
2299
	null,
2300
	'number',
2301
	$pconfig['adv_dhcp_pt_reboot']
2302
))->setHelp('Reboot');
2303

    
2304
$group->add(new Form_Input(
2305
	'adv_dhcp_pt_backoff_cutoff',
2306
	null,
2307
	'number',
2308
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2309
))->setHelp('Backoff cutoff');
2310

    
2311
$group->add(new Form_Input(
2312
	'adv_dhcp_pt_initial_interval',
2313
	null,
2314
	'number',
2315
	$pconfig['adv_dhcp_pt_initial_interval']
2316
))->setHelp('Initial interval');
2317

    
2318
$section->add($group);
2319

    
2320
$group = new Form_Group('Presets');
2321
$group->addClass('dhcpadvanced');
2322

    
2323
$group->add(new Form_Checkbox(
2324
	'adv_dhcp_pt_values',
2325
	null,
2326
	'FreeBSD default',
2327
	null,
2328
	'DHCP'
2329
))->displayAsRadio();
2330

    
2331
$group->add(new Form_Checkbox(
2332
	'adv_dhcp_pt_values',
2333
	null,
2334
	'Clear',
2335
	null,
2336
	'Clear'
2337
))->displayAsRadio();
2338

    
2339
$group->add(new Form_Checkbox(
2340
	'adv_dhcp_pt_values',
2341
	null,
2342
	'pfSense Default',
2343
	null,
2344
	'pfSense'
2345
))->displayAsRadio();
2346

    
2347
$group->add(new Form_Checkbox(
2348
	'adv_dhcp_pt_values',
2349
	null,
2350
	'Saved Cfg',
2351
	null,
2352
	'SavedCfg'
2353
))->displayAsRadio();
2354

    
2355
$section->add($group);
2356

    
2357
$section->addInput(new Form_Input(
2358
	'adv_dhcp_config_file_override_path',
2359
	'Configuration File Override',
2360
	'text',
2361
	$pconfig['adv_dhcp_config_file_override_path']
2362
))->setWidth(9)->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2363
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s'.
2364
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2365
			'Some ISPs may require certain options be or not be sent.', '<br />');
2366

    
2367
$form->add($section);
2368

    
2369
$section = new Form_Section('Lease Requirements and Requests');
2370
$section->addClass('dhcpadvanced');
2371

    
2372
$section->addInput(new Form_Input(
2373
	'adv_dhcp_send_options',
2374
	'Send options',
2375
	'text',
2376
	$pconfig['adv_dhcp_send_options']
2377
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2378
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2379
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2380
			'Some ISPs may require certain options be or not be sent.', '<br />');
2381

    
2382
$section->addInput(new Form_Input(
2383
	'adv_dhcp_request_options',
2384
	'Request options',
2385
	'text',
2386
	$pconfig['adv_dhcp_request_options']
2387
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2388
			'Some ISPs may require certain options be or not be requested.', '<br />');
2389

    
2390
$section->addInput(new Form_Input(
2391
	'adv_dhcp_required_options',
2392
	'Require options',
2393
	'text',
2394
	$pconfig['adv_dhcp_required_options']
2395
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2396

    
2397
$section->addInput(new Form_Input(
2398
	'adv_dhcp_option_modifiers',
2399
	'Option modifiers',
2400
	'text',
2401
	$pconfig['adv_dhcp_option_modifiers']
2402
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2403
			'modifiers: (default, supersede, prepend, append) %1$s' .
2404
			'See %2$shere%3$s more information', '<br />', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">', '</a>');
2405

    
2406
$form->add($section);
2407

    
2408
// DHCP6 client config
2409

    
2410
$section = new Form_Section('DHCP6 Client Configuration');
2411
$section->addClass('dhcp6');
2412

    
2413
$group = new Form_Group('Options');
2414

    
2415
$group->add(new Form_Checkbox(
2416
	'adv_dhcp6_config_advanced',
2417
	null,
2418
	'Advanced Configuration',
2419
	$pconfig['adv_dhcp6_config_advanced']
2420
))->setHelp('Use advanced DHCPv6 configuration options.');
2421

    
2422
$group->add(new Form_Checkbox(
2423
	'adv_dhcp6_config_file_override',
2424
	null,
2425
	'Configuration Override',
2426
	$pconfig['adv_dhcp6_config_file_override']
2427
))->setHelp('Override the configuration from this file.');
2428

    
2429
$section->add($group);
2430

    
2431
$section->addInput(new Form_Checkbox(
2432
	'dhcp6usev4iface',
2433
	'Use IPv4 connectivity as parent interface',
2434
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2435
	$pconfig['dhcp6usev4iface']
2436
));
2437

    
2438
$section->addInput(new Form_Checkbox(
2439
	'dhcp6prefixonly',
2440
	'Request only an IPv6 prefix',
2441
	'Only request an IPv6 prefix, do not request an IPv6 address',
2442
	$pconfig['dhcp6prefixonly']
2443
));
2444

    
2445
$section->addInput(new Form_Select(
2446
	'dhcp6-ia-pd-len',
2447
	'DHCPv6 Prefix Delegation size',
2448
	$pconfig['dhcp6-ia-pd-len'],
2449
	array("none" => "None", 16 => "48", 15 => "49", 14 => "50", 13 => "51", 12 => "52", 11 => "53", 10 => "54", 9 => "55", 8 => "56", 7 => "57", 6 => "58", 5 => "59", 4 => "60", 3 => "61", 2 => "62", 1 => "63", 0 => "64")
2450
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2451

    
2452
$section->addInput(new Form_Checkbox(
2453
	'dhcp6-ia-pd-send-hint',
2454
	'Send IPv6 prefix hint',
2455
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2456
	$pconfig['dhcp6-ia-pd-send-hint']
2457
));
2458

    
2459
$section->addInput(new Form_Checkbox(
2460
	'dhcp6withoutra',
2461
	'Do not wait for a RA',
2462
	'Required by some ISPs, especially those not using PPPoE',
2463
	$pconfig['dhcp6withoutra']
2464
));
2465

    
2466
if (interface_is_vlan($wancfg['if']) != NULL) {
2467
	$group = new Form_Group('DHCP6 VLAN Priority');
2468

    
2469
	$group->add(new Form_Checkbox(
2470
		'dhcp6vlanenable',
2471
		null,
2472
		'Enable dhcp6c VLAN Priority tagging',
2473
		$pconfig['dhcp6vlanenable']
2474
	))->setHelp('Normally off unless specifically required by the ISP.');
2475

    
2476
	$group->add(new Form_Select(
2477
		'dhcp6cvpt',
2478
		'VLAN Prio',
2479
		$pconfig['dhcp6cvpt'],
2480
		$vlanprio
2481
	))->setHelp('Choose 802.1p priority to set.');
2482

    
2483
	$section->add($group);
2484
}
2485

    
2486
$section->addInput(new Form_Input(
2487
	'adv_dhcp6_config_file_override_path',
2488
	'Configuration File Override',
2489
	'text',
2490
	$pconfig['adv_dhcp6_config_file_override_path']
2491
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2492
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2493
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2494
			'Some ISPs may require certain options be or not be sent.', '<br />');
2495

    
2496
$form->add($section);
2497

    
2498
// DHCP6 client config - Advanced
2499

    
2500
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2501
$section->addClass('dhcp6advanced');
2502

    
2503
$section->addInput(new Form_Checkbox(
2504
	'adv_dhcp6_interface_statement_information_only_enable',
2505
	'Information only',
2506
	'Exchange Information Only',
2507
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2508
	'Selected'
2509
))->setHelp('Only exchange informational configuration parameters with servers.');
2510

    
2511
$section->addInput(new Form_Input(
2512
	'adv_dhcp6_interface_statement_send_options',
2513
	'Send options',
2514
	'text',
2515
	$pconfig['adv_dhcp6_interface_statement_send_options']
2516
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2517
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2518
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2519
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2520

    
2521
$section->addInput(new Form_Input(
2522
	'adv_dhcp6_interface_statement_request_options',
2523
	'Request Options',
2524
	'text',
2525
	$pconfig['adv_dhcp6_interface_statement_request_options']
2526
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2527
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2528

    
2529
$section->addInput(new Form_Input(
2530
	'adv_dhcp6_interface_statement_script',
2531
	'Scripts',
2532
	'text',
2533
	$pconfig['adv_dhcp6_interface_statement_script']
2534
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2535
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2536

    
2537
$group = new Form_Group('Identity Association Statement');
2538

    
2539
$group->add(new Form_Checkbox(
2540
	'adv_dhcp6_id_assoc_statement_address_enable',
2541
	null,
2542
	'Non-Temporary Address Allocation',
2543
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2544
	'Selected'
2545
));
2546

    
2547
$group->add(new Form_Input(
2548
	'adv_dhcp6_id_assoc_statement_address_id',
2549
	null,
2550
	'text',
2551
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2552
))->sethelp('id-assoc na ID');
2553

    
2554
$group->add(new Form_IpAddress(
2555
	'adv_dhcp6_id_assoc_statement_address',
2556
	null,
2557
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2558
	'V6'
2559
))->sethelp('IPv6 address');
2560

    
2561
$group->add(new Form_Input(
2562
	'adv_dhcp6_id_assoc_statement_address_pltime',
2563
	null,
2564
	'text',
2565
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2566
))->sethelp('pltime');
2567

    
2568
$group->add(new Form_Input(
2569
	'adv_dhcp6_id_assoc_statement_address_vltime',
2570
	null,
2571
	'text',
2572
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2573
))->sethelp('vltime');
2574

    
2575
$section->add($group);
2576

    
2577
// Prefix delegation
2578
$group = new Form_Group('');
2579

    
2580
$group->add(new Form_Checkbox(
2581
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2582
	null,
2583
	'Prefix Delegation ',
2584
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2585
	'Selected'
2586
));
2587

    
2588
$group->add(new Form_Input(
2589
	'adv_dhcp6_id_assoc_statement_prefix_id',
2590
	null,
2591
	'text',
2592
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2593
))->sethelp('id-assoc pd ID');
2594

    
2595
$group->add(new Form_IpAddress(
2596
	'adv_dhcp6_id_assoc_statement_prefix',
2597
	null,
2598
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2599
	'V6'
2600
))->sethelp('IPv6 prefix');
2601

    
2602
$group->add(new Form_Input(
2603
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2604
	null,
2605
	'text',
2606
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2607
))->sethelp('pltime');
2608

    
2609
$group->add(new Form_Input(
2610
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2611
	null,
2612
	'text',
2613
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2614
))->sethelp('vltime');
2615

    
2616
$section->add($group);
2617

    
2618
$group = new Form_Group('Prefix interface statement');
2619

    
2620
$group->add(new Form_Input(
2621
	'adv_dhcp6_prefix_interface_statement_sla_id',
2622
	null,
2623
	'text',
2624
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2625
))->sethelp('Prefix Interface sla-id');
2626

    
2627
$group->add(new Form_Input(
2628
	'adv_dhcp6_prefix_interface_statement_sla_len',
2629
	null,
2630
	'text',
2631
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2632
))->sethelp('sla-len');
2633

    
2634
$section->add($group);
2635

    
2636
$group = new Form_Group('Select prefix interface');
2637
$section->addInput(new Form_Select(
2638
	'adv_dhcp6_prefix_selected_interface',
2639
	'Prefix Interface',
2640
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2641
	$interfaces
2642
))->setHelp('Select the interface on which to apply the prefix delegation.');
2643

    
2644
$group = new Form_Group('Authentication statement');
2645

    
2646
$group->add(new Form_Input(
2647
	'adv_dhcp6_authentication_statement_authname',
2648
	null,
2649
	'text',
2650
	$pconfig['adv_dhcp6_authentication_statement_authname']
2651
))->sethelp('Authname');
2652

    
2653
$group->add(new Form_Input(
2654
	'adv_dhcp6_authentication_statement_protocol',
2655
	null,
2656
	'text',
2657
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2658
))->sethelp('Protocol');
2659

    
2660
$group->add(new Form_Input(
2661
	'adv_dhcp6_authentication_statement_algorithm',
2662
	null,
2663
	'text',
2664
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2665
))->sethelp('Algorithm');
2666

    
2667
$group->add(new Form_Input(
2668
	'adv_dhcp6_authentication_statement_rdm',
2669
	null,
2670
	'text',
2671
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2672
))->sethelp('RDM');
2673

    
2674
$section->add($group);
2675

    
2676
$group = new Form_Group('Keyinfo statement');
2677

    
2678
$group->add(new Form_Input(
2679
	'adv_dhcp6_key_info_statement_keyname',
2680
	null,
2681
	'text',
2682
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2683
))->sethelp('Keyname');
2684

    
2685
$group->add(new Form_Input(
2686
	'adv_dhcp6_key_info_statement_realm',
2687
	null,
2688
	'text',
2689
	$pconfig['adv_dhcp6_key_info_statement_realm']
2690
))->sethelp('Realm');
2691

    
2692
$section->add($group);
2693

    
2694
$group = new Form_Group('');
2695

    
2696
$group->add(new Form_Input(
2697
	'adv_dhcp6_key_info_statement_keyid',
2698
	null,
2699
	'text',
2700
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2701
))->sethelp('KeyID');
2702

    
2703
$group->add(new Form_Input(
2704
	'adv_dhcp6_key_info_statement_secret',
2705
	null,
2706
	'text',
2707
	$pconfig['adv_dhcp6_key_info_statement_secret']
2708
))->sethelp('Secret');
2709

    
2710
$group->add(new Form_Input(
2711
	'adv_dhcp6_key_info_statement_expire',
2712
	null,
2713
	'text',
2714
	$pconfig['adv_dhcp6_key_info_statement_expire']
2715
))->sethelp('Expire');
2716

    
2717
$group->setHelp('See %1$shere%2$s more information', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhcp6c.conf&sektion=5&apropos=0&manpath=FreeBSD+11.0-RELEASE+and+Ports#Interface_statement">', '</a>');
2718

    
2719
$section->add($group);
2720

    
2721
$form->add($section);
2722

    
2723
$section = new Form_Section('6RD Configuration');
2724
$section->addClass('_6rd');
2725

    
2726
$section->addInput(new Form_Input(
2727
	'prefix-6rd',
2728
	'6RD Prefix',
2729
	'text',
2730
	$pconfig['prefix-6rd']
2731
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2732

    
2733
$section->addInput(new Form_Input(
2734
	'gateway-6rd',
2735
	'*6RD Border relay',
2736
	'text',
2737
	$pconfig['gateway-6rd']
2738
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2739

    
2740
$section->addInput(new Form_Select(
2741
	'prefix-6rd-v4plen',
2742
	'6RD IPv4 Prefix length',
2743
	$pconfig['prefix-6rd-v4plen'],
2744
	array_combine(range(0, 32), range(0, 32))
2745
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2746

    
2747
$form->add($section);
2748

    
2749
// Track IPv6 ointerface section
2750
$section = new Form_Section('Track IPv6 Interface');
2751
$section->addClass('track6');
2752

    
2753
function build_ipv6interface_list() {
2754
	global $config, $form;
2755

    
2756
	$list = array('' => '');
2757

    
2758
	$interfaces = get_configured_interface_with_descr(true);
2759
	$dynv6ifs = array();
2760

    
2761
	foreach ($interfaces as $iface => $ifacename) {
2762
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2763
			case "6to4":
2764
			case "6rd":
2765
			case "dhcp6":
2766
				$dynv6ifs[$iface] = array(
2767
					'name' => $ifacename,
2768
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2769
				);
2770
				break;
2771
			default:
2772
				continue 2;
2773
		}
2774
	}
2775

    
2776
	foreach ($dynv6ifs as $iface => $ifacedata) {
2777
		$list[$iface] = $ifacedata['name'];
2778

    
2779
		$form->addGlobal(new Form_Input(
2780
			'ipv6-num-prefix-ids-' . $iface,
2781
			null,
2782
			'hidden',
2783
			$ifacedata['ipv6_num_prefix_ids']
2784
		));
2785
	}
2786

    
2787
	return($list);
2788
}
2789

    
2790
$section->addInput(new Form_Select(
2791
	'track6-interface',
2792
	'*IPv6 Interface',
2793
	$pconfig['track6-interface'],
2794
	build_ipv6interface_list()
2795
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2796

    
2797
if ($pconfig['track6-prefix-id'] == "") {
2798
	$pconfig['track6-prefix-id'] = 0;
2799
}
2800

    
2801
$section->addInput(new Form_Input(
2802
	'track6-prefix-id--hex',
2803
	'IPv6 Prefix ID',
2804
	'text',
2805
	sprintf("%x", $pconfig['track6-prefix-id'])
2806
))->setHelp('(%1$shexadecimal%2$s from 0 to %3$s) The value in this field is the (Delegated) IPv6 prefix ID. This determines the configurable network ID based on the dynamic IPv6 connection. The default value is 0.', '<b>', '</b>', '<span id="track6-prefix-id-range"></span>');
2807

    
2808
$form->addGlobal(new Form_Input(
2809
	'track6-prefix-id-max',
2810
	null,
2811
	'hidden',
2812
	0
2813
));
2814

    
2815
$form->add($section);
2816

    
2817
/// PPP section
2818

    
2819
$section = new Form_Section('PPP Configuration');
2820
$section->addClass('ppp');
2821

    
2822
$section->addInput(new Form_Select(
2823
	'country',
2824
	'Country',
2825
	$pconfig['country'],
2826
	[]
2827
));
2828

    
2829
$section->addInput(new Form_Select(
2830
	'provider_list',
2831
	'Provider',
2832
	$pconfig['provider_list'],
2833
	[]
2834
));
2835

    
2836
$section->addInput(new Form_Select(
2837
	'providerplan',
2838
	'Plan',
2839
	$pconfig['providerplan'],
2840
	[]
2841
))->setHelp('Select to fill in service provider data.');
2842

    
2843
$section->addInput(new Form_Input(
2844
	'ppp_username',
2845
	'Username',
2846
	'text',
2847
	$pconfig['ppp_username'],
2848
	['autocomplete' => 'new-password']
2849
));
2850

    
2851
$section->addPassword(new Form_Input(
2852
	'ppp_password',
2853
	'Password',
2854
	'password',
2855
	$pconfig['ppp_password']
2856
));
2857

    
2858
$section->addInput(new Form_Input(
2859
	'phone',
2860
	'*Phone number',
2861
	'text',
2862
	$pconfig['phone']
2863
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2864

    
2865
$section->addInput(new Form_Input(
2866
	'apn',
2867
	'Access Point Name',
2868
	'text',
2869
	$pconfig['apn']
2870
));
2871

    
2872

    
2873
function build_port_list() {
2874
	$list = array("" => "None");
2875

    
2876
	$portlist = glob("/dev/cua*");
2877
	$modems	  = glob("/dev/modem*");
2878
	$portlist = array_merge($portlist, $modems);
2879

    
2880
	foreach ($portlist as $port) {
2881
		if (preg_match("/\.(lock|init)$/", $port)) {
2882
			continue;
2883
		}
2884

    
2885
	$list[trim($port)] = $port;
2886
	}
2887

    
2888
	return($list);
2889
}
2890

    
2891
$section->addInput(new Form_Select(
2892
	'port',
2893
	"*Modem port",
2894
	$pconfig['port'],
2895
	build_port_list()
2896
));
2897

    
2898
$section->addInput(new Form_Button(
2899
	'btnadvppp',
2900
	'Advanced PPP',
2901
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2902
	'fa-cog'
2903
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2904

    
2905
$form->add($section);
2906

    
2907
// PPPoE configuration
2908
$section = new Form_Section('PPPoE Configuration');
2909
$section->addClass('pppoe');
2910

    
2911
$section->addInput(new Form_Input(
2912
	'pppoe_username',
2913
	'*Username',
2914
	'text',
2915
	$pconfig['pppoe_username'],
2916
	['autocomplete' => 'new-password']
2917
));
2918

    
2919
$section->addPassword(new Form_Input(
2920
	'pppoe_password',
2921
	'*Password',
2922
	'password',
2923
	$pconfig['pppoe_password']
2924
));
2925

    
2926
$section->addInput(new Form_Input(
2927
	'provider',
2928
	'Service name',
2929
	'text',
2930
	$pconfig['provider']
2931
))->setHelp('This field can usually be left empty.');
2932

    
2933
$section->addInput(new Form_Input(
2934
	'hostuniq',
2935
	'Host-Uniq',
2936
	'text',
2937
	$pconfig['hostuniq']
2938
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2939

    
2940
$section->addInput(new Form_Checkbox(
2941
	'pppoe_dialondemand',
2942
	'Dial on demand',
2943
	'Enable Dial-On-Demand mode ',
2944
	$pconfig['pppoe_dialondemand'],
2945
	'enable'
2946
));
2947

    
2948
$section->addInput(new Form_Input(
2949
	'pppoe_idletimeout',
2950
	'Idle timeout',
2951
	'number',
2952
	$pconfig['pppoe_idletimeout'],
2953
	['min' => 0]
2954
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2955
			'An idle timeout of zero disables this feature.');
2956

    
2957
$section->addInput(new Form_Select(
2958
	'pppoe-reset-type',
2959
	'Periodic reset',
2960
	$pconfig['pppoe-reset-type'],
2961
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2962
))->setHelp('Select a reset timing type.');
2963

    
2964
$group = new Form_Group('Custom reset');
2965
$group->addClass('pppoecustom');
2966

    
2967
$group->add(new Form_Input(
2968
	'pppoe_resethour',
2969
	null,
2970
	'number',
2971
	(strlen($pconfig['pppoe_resethour']) > 0) ? $pconfig['pppoe_resethour'] : "0",
2972
	['min' => 0, 'max' => 23]
2973
))->setHelp('Hour (0-23), blank for * (every)');
2974

    
2975
$group->add(new Form_Input(
2976
	'pppoe_resetminute',
2977
	null,
2978
	'number',
2979
	(strlen($pconfig['pppoe_resetminute']) > 0) ? $pconfig['pppoe_resetminute'] : "0",
2980
	['min' => 0, 'max' => 59]
2981
))->setHelp('Minute (0-59), blank for * (every)');
2982

    
2983
$group->add(new Form_Input(
2984
	'pppoe_resetdate',
2985
	null,
2986
	'text',
2987
	$pconfig['pppoe_resetdate']
2988
))->setHelp('Specific date (mm/dd/yyyy)');
2989

    
2990
$group->setHelp('Leave the date field empty, for the reset to be executed each day at the time specified by the minutes and hour fields');
2991

    
2992
$section->add($group);
2993

    
2994
$group = new Form_MultiCheckboxGroup('cron based reset');
2995
$group->addClass('pppoepreset');
2996

    
2997
$group->add(new Form_MultiCheckbox(
2998
	'pppoe_pr_preset_val',
2999
	null,
3000
	'Reset at each month ("0 0 1 * *")',
3001
	$pconfig['pppoe_monthly'],
3002
	'monthly'
3003
))->displayAsRadio();
3004

    
3005
$group->add(new Form_MultiCheckbox(
3006
	'pppoe_pr_preset_val',
3007
	null,
3008
	'Reset at each week ("0 0 * * 0")',
3009
	$pconfig['pppoe_weekly'],
3010
	'weekly'
3011
))->displayAsRadio();
3012

    
3013
$group->add(new Form_MultiCheckbox(
3014
	'pppoe_pr_preset_val',
3015
	null,
3016
	'Reset at each day ("0 0 * * *")',
3017
	$pconfig['pppoe_daily'],
3018
	'daily'
3019
))->displayAsRadio();
3020

    
3021
$group->add(new Form_MultiCheckbox(
3022
	'pppoe_pr_preset_val',
3023
	null,
3024
	'Reset at each hour ("0 * * * *")',
3025
	$pconfig['pppoe_hourly'],
3026
	'hourly'
3027
))->displayAsRadio();
3028

    
3029
$section->add($group);
3030

    
3031
$section->addInput(new Form_Button(
3032
	'btnadvppp',
3033
	'Advanced and MLPPP',
3034
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3035
	'fa-cog'
3036
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3037

    
3038
$form->add($section);
3039

    
3040
// PPTP & L2TP Configuration section
3041
$section = new Form_Section('PPTP/L2TP Configuration');
3042
$section->addClass('pptp');
3043

    
3044
$section->addInput(new Form_Input(
3045
	'pptp_username',
3046
	'*Username',
3047
	'text',
3048
	$pconfig['pptp_username'],
3049
	['autocomplete' => 'new-password']
3050
));
3051

    
3052
$section->addPassword(new Form_Input(
3053
	'pptp_password',
3054
	'*Password',
3055
	'password',
3056
	$pconfig['pptp_password']
3057
));
3058

    
3059
$group = new Form_Group('Shared Secret');
3060

    
3061
$group->add(new Form_Input(
3062
	'l2tp_secret',
3063
	'*Secret',
3064
	'password',
3065
	$pconfig['l2tp_secret']
3066
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3067
	    'important control packet contents. (Optional)');
3068

    
3069
$group->addClass('l2tp_secret');
3070
$section->add($group);
3071

    
3072
$section->addInput(new Form_IpAddress(
3073
	'pptp_local0',
3074
	'*Local IP address',
3075
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3076
	'V4'
3077
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3078

    
3079
$section->addInput(new Form_IpAddress(
3080
	'pptp_remote0',
3081
	'*Remote IP address',
3082
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3083
	'HOSTV4'
3084
));
3085

    
3086
$section->addInput(new Form_Checkbox(
3087
	'pptp_dialondemand',
3088
	'Dial on demand',
3089
	'Enable Dial-On-Demand mode ',
3090
	$pconfig['pptp_dialondemand'],
3091
	'enable'
3092
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3093
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3094

    
3095
$section->addInput(new Form_Input(
3096
	'pptp_idletimeout',
3097
	'Idle timeout (seconds)',
3098
	'number',
3099
	$pconfig['pptp_idletimeout'],
3100
	['min' => 0]
3101
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3102
			'An idle timeout of zero disables this feature.');
3103

    
3104
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3105
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3106
} else {
3107
	$mlppp_text = "";
3108
}
3109

    
3110
$section->addInput(new Form_Button(
3111
	'btnadvppp',
3112
	'Advanced and MLPPP',
3113
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3114
	'fa-cog'
3115
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('%sClick for additional PPTP and L2TP configuration options. Save first if changes have been made.', $mlppp_text);
3116

    
3117
$form->add($section);
3118

    
3119
// Wireless interface
3120
if (isset($wancfg['wireless'])) {
3121

    
3122
	$section = new Form_Section('Common Wireless Configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
3123

    
3124
	$section->addInput(new Form_Checkbox(
3125
		'persistcommonwireless',
3126
		'Persist common settings',
3127
		'Preserve common wireless configuration through interface deletions and reassignments.',
3128
		$pconfig['persistcommonwireless'],
3129
		'yes'
3130
	));
3131

    
3132
	$mode_list = ['auto' => 'Auto'];
3133

    
3134
	if (is_array($wl_modes)) {
3135
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3136
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3137
		}
3138
	}
3139

    
3140
	if (count($mode_list) == 1) {
3141
		$mode_list[''] = '';
3142
	}
3143

    
3144
	$section->addInput(new Form_Select(
3145
		'standard',
3146
		'Standard',
3147
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3148
		$mode_list
3149
	));
3150

    
3151
	if (isset($wl_modes['11g'])) {
3152
		$section->addInput(new Form_Select(
3153
			'protmode',
3154
			'802.11g OFDM Protection Mode',
3155
			$pconfig['protmode'],
3156
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3157
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3158
	} else {
3159
		$form->addGlobal(new Form_Input(
3160
			'protmode',
3161
			null,
3162
			'hidden',
3163
			'off'
3164
		));
3165
	}
3166

    
3167
	$mode_list = ['0' => gettext('Auto')];
3168

    
3169
	if (is_array($wl_modes)) {
3170
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3171
			if ($wl_standard == "11g") {
3172
				$wl_standard = "11b/g";
3173
			} else if ($wl_standard == "11ng") {
3174
				$wl_standard = "11b/g/n";
3175
			} else if ($wl_standard == "11na") {
3176
				$wl_standard = "11a/n";
3177
			}
3178

    
3179
			foreach ($wl_channels as $wl_channel) {
3180
				if (isset($wl_chaninfo[$wl_channel])) {
3181
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3182
				} else {
3183
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3184
				}
3185
			}
3186
		}
3187
	}
3188

    
3189
	$section->addInput(new Form_Select(
3190
		'channel',
3191
		'Channel',
3192
		$pconfig['channel'],
3193
		$mode_list
3194
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3195
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3196

    
3197
	$section->addInput(new Form_Select(
3198
		'channel_width',
3199
		'Channel width',
3200
		$pconfig['channel_width'],
3201
		$wl_ht_modes
3202
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3203

    
3204
	if (ANTENNAS) {
3205
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3206
			$group = new Form_Group('Antenna Settings');
3207

    
3208
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3209
				$group->add(new Form_Select(
3210
					'diversity',
3211
					null,
3212
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3213
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3214
				))->setHelp('Diversity');
3215
			}
3216

    
3217
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3218
				$group->add(new Form_Select(
3219
					'txantenna',
3220
					null,
3221
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3222
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3223
				))->setHelp('Transmit antenna');
3224
			}
3225

    
3226
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3227
				$group->add(new Form_Select(
3228
					'rxantenna',
3229
					null,
3230
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3231
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3232
				))->setHelp('Receive antenna');
3233
			}
3234

    
3235
			$group->setHelp('Note: The antenna numbers do not always match up with the labels on the card.');
3236

    
3237
			$section->add($group);
3238
		}
3239
	}
3240

    
3241
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3242
			$section->addInput(new Form_Input(
3243
				'distance',
3244
				'Distance setting (meters)',
3245
				'test',
3246
				$pconfig['distance']
3247
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3248
	}
3249

    
3250
	$form->add($section);
3251

    
3252
	// Regulatory settings
3253
	$section = new Form_Section('Regulatory Settings');
3254

    
3255
	$domain_list = array("" => 'Default');
3256

    
3257
	if (is_array($wl_regdomains)) {
3258
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3259
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3260
		}
3261
	}
3262

    
3263
	$section->addInput(new Form_Select(
3264
		'regdomain',
3265
		'Regulatory domain',
3266
		$pconfig['regdomain'],
3267
		$domain_list
3268
	))->setHelp('Some cards have a default that is not recognized and require changing the regulatory domain to one in this list for the changes to other regulatory settings to work');
3269

    
3270
	$country_list = array('' => 'Default');
3271

    
3272
	if (is_array($wl_countries)) {
3273
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3274
			$country_list[	$wl_countries_attr[$wl_country_key]['ID']  ] = $wl_country['name'] ; //. ' -- (' . $wl_countries_attr[$wl_country_key]['ID'] . ', ' . strtoupper($wl_countries_attr[$wl_country_key]['rd'][0]['REF']);
3275
		}
3276
	}
3277

    
3278
	$section->addInput(new Form_Select(
3279
		'regcountry',
3280
		'Country',
3281
		$pconfig['regcountry'],
3282
		$country_list
3283
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3284

    
3285
	$section->addInput(new Form_Select(
3286
		'reglocation',
3287
		'Location',
3288
		$pconfig['reglocation'],
3289
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
3290
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3291
				'Using the correct settings to comply with local regulatory requirements is recommended.%1$s' .
3292
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3293
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3294
				'These settings may not be able to add additional channels that are not already supported.', '<br />');
3295

    
3296
	$form->add($section);
3297

    
3298
	$section = new Form_Section('Network-Specific Wireless Configuration');
3299

    
3300
	$section->addInput(new Form_Select(
3301
		'mode',
3302
		'Mode',
3303
		$pconfig['mode'],
3304
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3305
	));
3306

    
3307
	$section->addInput(new Form_Input(
3308
		'ssid',
3309
		'SSID',
3310
		'text',
3311
		$pconfig['ssid']
3312
	));
3313

    
3314
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3315
		$section->addInput(new Form_Select(
3316
			'puremode',
3317
			'Minimum wireless standard',
3318
			$pconfig['puremode'],
3319
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3320
		))->setHelp('When operating as an access point, allow only stations capable of the selected wireless standard to associate (stations not capable are not permitted to associate)');
3321
	} elseif (isset($wl_modes['11g'])) {
3322
		$section->addInput(new Form_Checkbox(
3323
			'puremode',
3324
			'802.11g only',
3325
			null,
3326
			$pconfig['puremode'],
3327
			'11g'
3328
		))->setHelp('When operating as an access point in 802.11g mode, allow only 11g-capable stations to associate (11b-only stations are not permitted to associate)');
3329
	}
3330

    
3331
	$section->addInput(new Form_Checkbox(
3332
		'apbridge_enable',
3333
		'Allow intra-BSS communication',
3334
		'Allow packets to pass between wireless clients directly when operating as an access point',
3335
		$pconfig['apbridge_enable'],
3336
		'yes'
3337
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3338

    
3339
	$section->addInput(new Form_Checkbox(
3340
		'wme_enable',
3341
		'Enable WME',
3342
		'Force the card to use WME (wireless QoS)',
3343
		$pconfig['wme_enable'],
3344
		'yes'
3345
	));
3346

    
3347
	$section->addInput(new Form_Checkbox(
3348
		'hidessid_enable',
3349
		'Hide SSID',
3350
		'Disable broadcasting of the SSID for this network (This may cause problems for some clients, and the SSID may still be discovered by other means.)',
3351
		$pconfig['hidessid_enable'],
3352
		'yes'
3353
	));
3354

    
3355
	$form->add($section);
3356

    
3357
	// WPA Section
3358
	$section = new Form_Section('WPA');
3359

    
3360
	$section->addInput(new Form_Checkbox(
3361
		'wpa_enable',
3362
		'Enable',
3363
		'Enable WPA',
3364
		$pconfig['wpa_enable'],
3365
		'yes'
3366
	));
3367

    
3368
	$section->addInput(new Form_Select(
3369
		'wpa_mode',
3370
		'WPA mode',
3371
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3372
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3373
	));
3374

    
3375
	$section->addInput(new Form_Select(
3376
		'wpa_pairwise',
3377
		'WPA Pairwise',
3378
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3379
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3380
	));
3381

    
3382
	$section->addInput(new Form_Select(
3383
		'wpa_key_mgmt',
3384
		'WPA Key Management Mode',
3385
		$pconfig['wpa_key_mgmt'],
3386
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3387
	));
3388

    
3389
	$section->addInput(new Form_Input(
3390
		'passphrase',
3391
		'WPA Pre-Shared Key',
3392
		'text',
3393
		$pconfig['passphrase']
3394
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3395

    
3396
	$section->addInput(new Form_Select(
3397
		'wpa_eap_client_mode',
3398
		'EAP Client Mode',
3399
		$pconfig['wpa_eap_client_mode'],
3400
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3401
	));
3402

    
3403
	$section->addInput(new Form_Select(
3404
		'wpa_eap_ca',
3405
		'Certificate Authority',
3406
		$pconfig['wpa_eap_ca'],
3407
		cert_build_list('ca', 'HTTPS')
3408
	));
3409

    
3410
	$section->addInput(new Form_Select(
3411
		'wpa_eap_inner_auth',
3412
		'Inner Authentication Method',
3413
		$pconfig['wpa_eap_inner_auth'],
3414
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3415
	));
3416

    
3417
	$section->addInput(new Form_Input(
3418
		'wpa_eap_inner_id',
3419
		'*Inner Authentication Identity',
3420
		'text',
3421
		$pconfig['wpa_eap_inner_id']
3422
	));
3423

    
3424
	$section->addInput(new Form_Input(
3425
		'wpa_eap_inner_password',
3426
		'*Inner Authentication Passphrase',
3427
		'text',
3428
		$pconfig['wpa_eap_inner_password']
3429
	));
3430

    
3431
	$section->addInput(new Form_Select(
3432
		'wpa_eap_cert',
3433
		'TLS/TTLS Client Certificate',
3434
		$pconfig['wpa_eap_cert'],
3435
		cert_build_list('cert', 'HTTPS')
3436
	));
3437

    
3438
	$section->addInput(new Form_Input(
3439
		'wpa_group_rekey',
3440
		'Group Key Rotation',
3441
		'number',
3442
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3443
		['min' => '1', 'max' => 9999]
3444
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3445

    
3446
	$section->addInput(new Form_Input(
3447
		'wpa_gmk_rekey',
3448
		'Group Master Key Regeneration',
3449
		'number',
3450
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3451
		['min' => '1', 'max' => 9999]
3452
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3453

    
3454
	$section->addInput(new Form_Checkbox(
3455
		'wpa_strict_rekey',
3456
		'Strict Key Regeneration',
3457
		'Force the AP to rekey whenever a client disassociates',
3458
		$pconfig['wpa_strict_rekey'],
3459
		'yes'
3460
	));
3461

    
3462
	$form->add($section);
3463

    
3464
	$section = new Form_Section('802.1x RADIUS Options');
3465
	$section->addClass('ieee8021x_group');
3466

    
3467
	$section->addInput(new Form_Checkbox(
3468
		'ieee8021x',
3469
		'IEEE802.1X',
3470
		'Enable 802.1X authentication',
3471
		$pconfig['ieee8021x'],
3472
		'yes'
3473
	));
3474

    
3475
	$group = new Form_Group('Primary 802.1X server');
3476

    
3477
	$group->add(new Form_IpAddress(
3478
		'auth_server_addr',
3479
		'IP Address',
3480
		$pconfig['auth_server_addr']
3481
	))->setHelp('IP address of the RADIUS server');
3482

    
3483
	$group->add(new Form_Input(
3484
		'auth_server_port',
3485
		'Port',
3486
		'number',
3487
		$pconfig['auth_server_port']
3488
	))->setHelp('Server auth port. Default is 1812');
3489

    
3490
	$group->add(new Form_Input(
3491
		'auth_server_shared_secret',
3492
		'Shared Secret',
3493
		'text',
3494
		$pconfig['auth_server_shared_secret']
3495
	))->setHelp('RADIUS Shared secret for this firewall');
3496

    
3497
	$section->add($group);
3498

    
3499
	$group = new Form_Group('Secondary 802.1X server');
3500

    
3501
	$group->add(new Form_IpAddress(
3502
		'auth_server_addr2',
3503
		'IP Address',
3504
		$pconfig['auth_server_addr2']
3505
	))->setHelp('IP address of the RADIUS server');
3506

    
3507
	$group->add(new Form_Input(
3508
		'auth_server_port2',
3509
		'Port',
3510
		'number',
3511
		$pconfig['auth_server_port2']
3512
	))->setHelp('Server auth port. Default is 1812');
3513

    
3514
	$group->add(new Form_Input(
3515
		'auth_server_shared_secret2',
3516
		'Shared Secret',
3517
		'text',
3518
		$pconfig['auth_server_shared_secret2']
3519
	))->setHelp('RADIUS Shared secret for this firewall');
3520

    
3521
	$section->add($group);
3522

    
3523
	$section->addInput(new Form_Checkbox(
3524
		'rsn_preauth',
3525
		'Authentication Roaming Preauth',
3526
		null,
3527
		$pconfig['rsn_preauth'],
3528
		'yes'
3529
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3530

    
3531
	$form->add($section);
3532
}
3533

    
3534
$section = new Form_Section('Reserved Networks');
3535

    
3536
$section->addInput(new Form_Checkbox(
3537
	'blockpriv',
3538
	'Block private networks and loopback addresses',
3539
	'',
3540
	$pconfig['blockpriv'],
3541
	'yes'
3542
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3543
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3544
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3545

    
3546
$section->addInput(new Form_Checkbox(
3547
	'blockbogons',
3548
	'Block bogon networks',
3549
	'',
3550
	$pconfig['blockbogons'],
3551
	'yes'
3552
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3553
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3554
			'This option should only be used on external interfaces (WANs), it is not necessary on local interfaces and it can potentially block required local traffic.%1$s' .
3555
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3556

    
3557
$form->add($section);
3558

    
3559
$form->addGlobal(new Form_Input(
3560
	'if',
3561
	null,
3562
	'hidden',
3563
	$if
3564
));
3565

    
3566
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3567
	$form->addGlobal(new Form_Input(
3568
		'ppp_port',
3569
		null,
3570
		'hidden',
3571
		$pconfig['port']
3572
	));
3573
}
3574

    
3575
$form->addGlobal(new Form_Input(
3576
	'ptpid',
3577
	null,
3578
	'hidden',
3579
	$pconfig['ptpid']
3580
));
3581

    
3582

    
3583
// Add new gateway modal pop-up
3584
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3585

    
3586
$modal->addInput(new Form_Checkbox(
3587
	'defaultgw4',
3588
	'Default',
3589
	'Default gateway',
3590
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3591
));
3592

    
3593
$modal->addInput(new Form_Input(
3594
	'gatewayname4',
3595
	'Gateway name',
3596
	'text',
3597
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3598
));
3599

    
3600
$modal->addInput(new Form_IpAddress(
3601
	'gatewayip4',
3602
	'Gateway IPv4',
3603
	$gateway_settings4['gateway'],
3604
	'V4'
3605
));
3606

    
3607
$modal->addInput(new Form_Input(
3608
	'gatewaydescr4',
3609
	'Description',
3610
	'text',
3611
	$gateway_settings4['descr']
3612
));
3613

    
3614
$btnaddgw4 = new Form_Button(
3615
	'add4',
3616
	'Add',
3617
	null,
3618
	'fa-plus'
3619
);
3620

    
3621
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3622

    
3623
$btncnxgw4 = new Form_Button(
3624
	'cnx4',
3625
	'Cancel',
3626
	null,
3627
	'fa-undo'
3628
);
3629

    
3630
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3631

    
3632
$modal->addInput(new Form_StaticText(
3633
	null,
3634
	$btnaddgw4 . $btncnxgw4
3635
));
3636

    
3637
$form->add($modal);
3638

    
3639
print($form);
3640
?>
3641

    
3642
<script type="text/javascript">
3643
//<![CDATA[
3644
events.push(function() {
3645
	function updateType(t) {
3646

    
3647
		switch (t) {
3648
			case "none": {
3649
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3650
				break;
3651
			}
3652
			case "staticv4": {
3653
				$('.dhcpadvanced, .none, .dhcp').hide();
3654
				$('.pppoe, .pptp, .ppp').hide();
3655
				break;
3656
			}
3657
			case "dhcp": {
3658
				$('.dhcpadvanced, .none').hide();
3659
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3660
										//			about the staticv4 class
3661
				$('.pppoe, .pptp, .ppp').hide();
3662
				break;
3663
			}
3664
			case "ppp": {
3665
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3666
				country_list();
3667
				break;
3668
			}
3669
			case "pppoe": {
3670
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3671
				break;
3672
			}
3673
			case "l2tp": {
3674
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3675
				$('.pptp, .l2tp_secret').show();
3676
				break;
3677
			}
3678
			case "pptp": {
3679
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3680
				$('.pptp').show();
3681
				break;
3682
			}
3683
		}
3684

    
3685
		if (t != "l2tp" && t != "pptp") {
3686
			$('.'+t).show();
3687
		}
3688
	}
3689

    
3690
	function updateTypeSix(t) {
3691
		if (!isNaN(t[0])) {
3692
			t = '_' + t;
3693
		}
3694

    
3695
		switch (t) {
3696
			case "none": {
3697
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3698
				break;
3699
			}
3700
			case "staticv6": {
3701
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3702
				break;
3703
			}
3704
			case "slaac": {
3705
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3706
				break;
3707
			}
3708
			case "dhcp6": {
3709
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3710
				break;
3711
			}
3712
			case "_6rd": {
3713
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3714
				break;
3715
			}
3716
			case "_6to4": {
3717
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3718
				break;
3719
			}
3720
			case "track6": {
3721
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3722
				update_track6_prefix();
3723
				break;
3724
			}
3725
		}
3726

    
3727
		if (t != "l2tp" && t != "pptp") {
3728
			$('.'+t).show();
3729
		}
3730
	}
3731

    
3732
	function show_reset_settings(reset_type) {
3733
		if (reset_type == 'preset') {
3734
			$('.pppoepreset').show();
3735
			$('.pppoecustom').hide();
3736
		} else if (reset_type == 'custom') {
3737
			$('.pppoecustom').show();
3738
			$('.pppoepreset').hide();
3739
		} else {
3740
			$('.pppoecustom').hide();
3741
			$('.pppoepreset').hide();
3742
		}
3743
	}
3744

    
3745
	function update_track6_prefix() {
3746
		var iface = $("#track6-interface").val();
3747
		if (iface == null) {
3748
			return;
3749
		}
3750

    
3751
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3752
		if (track6_prefix_ids == null) {
3753
			return;
3754
		}
3755

    
3756
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3757
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3758
	}
3759

    
3760
	function addOption_v4() {
3761
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3762
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3763
	}
3764

    
3765
	function addOption_v6() {
3766
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3767
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3768
	}
3769

    
3770
	function addSelectboxOption(selectbox, text, value) {
3771
		var optn = document.createElement("OPTION");
3772
		optn.text = text;
3773
		optn.value = value;
3774
		selectbox.append(optn);
3775
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3776
	}
3777

    
3778
	function country_list() {
3779
		$('#country').children().remove();
3780
		$('#provider_list').children().remove();
3781
		$('#providerplan').children().remove();
3782
		$.ajax({
3783
			type: 'post',
3784
			url: 'getserviceproviders.php',
3785
			data: { get_country_list: true },
3786
			success: function(response) {
3787

    
3788
				var responseTextArr = response.split("\n");
3789
				responseTextArr.sort();
3790

    
3791
				responseTextArr.forEach( function(value) {
3792
					country = value.split(":");
3793
					$('#country').append($('<option>', {
3794
						value: country[1],
3795
						text : country[0]
3796
					}));
3797
				});
3798
			}
3799
		});
3800
	}
3801

    
3802
	function providers_list() {
3803
		$('#provider_list').children().remove();
3804
		$('#providerplan').children().remove();
3805
		$.ajax("getserviceproviders.php",{
3806
			type: 'post',
3807
			data: {country : $('#country').val()},
3808
			success: function(response) {
3809
				var responseTextArr = response.split("\n");
3810
				responseTextArr.sort();
3811
				responseTextArr.forEach( function(value) {
3812
					$('#provider_list').append($('<option>', {
3813
							value: value,
3814
							text : value
3815
					}));
3816
				});
3817
			}
3818
		});
3819
	}
3820

    
3821
	function providerplan_list() {
3822
		$('#providerplan').children().remove();
3823
		$.ajax("getserviceproviders.php",{
3824
			type: 'post',
3825
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3826
			success: function(response) {
3827
				var responseTextArr = response.split("\n");
3828
				responseTextArr.sort();
3829

    
3830
				$('#providerplan').append($('<option>', {
3831
					value: '',
3832
					text : ''
3833
				}));
3834

    
3835
				responseTextArr.forEach( function(value) {
3836
					if (value != "") {
3837
						providerplan = value.split(":");
3838

    
3839
						$('#providerplan').append($('<option>', {
3840
							value: providerplan[1],
3841
							text : providerplan[0] + " - " + providerplan[1]
3842
						}));
3843
					}
3844
				});
3845
			}
3846
		});
3847
	}
3848

    
3849
	function prefill_provider() {
3850
		$.ajax("getserviceproviders.php",{
3851
			type: 'post',
3852
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3853
			success: function(data, textStatus, response) {
3854
				var xmldoc = response.responseXML;
3855
				var provider = xmldoc.getElementsByTagName('connection')[0];
3856
				$('#ppp_username').val('');
3857
				$('#ppp_password').val('');
3858
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3859
					$('#phone').val('#777');
3860
					$('#apn').val('');
3861
				} else {
3862
					$('#phone').val('*99#');
3863
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3864
				}
3865
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3866
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3867
				$('#ppp_username').val(ppp_username);
3868
				$('#ppp_password').val(ppp_password);
3869
			}
3870
		});
3871
	}
3872

    
3873
	function show_dhcp6adv() {
3874
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3875
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3876

    
3877
		hideCheckbox('dhcp6usev4iface', ovr);
3878
		hideCheckbox('dhcp6prefixonly', ovr);
3879
		hideInput('dhcp6-ia-pd-len', ovr);
3880
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3881
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3882

    
3883
		hideClass('dhcp6advanced', !adv || ovr);
3884
	}
3885

    
3886
	function setDHCPoptions() {
3887
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3888
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3889

    
3890
		if (ovr) {
3891
			hideInput('dhcphostname', true);
3892
			hideIpAddress('alias-address', true);
3893
			hideInput('dhcprejectfrom', true);
3894
			hideInput('adv_dhcp_config_file_override_path', false);
3895
			hideClass('dhcpadvanced', true);
3896
		} else {
3897
			hideInput('dhcphostname', false);
3898
			hideIpAddress('alias-address', false);
3899
			hideInput('dhcprejectfrom', false);
3900
			hideInput('adv_dhcp_config_file_override_path', true);
3901
			hideClass('dhcpadvanced', !adv);
3902
		}
3903
	}
3904

    
3905
	// DHCP preset actions
3906
	// Set presets from value of radio buttons
3907
	function setPresets(val) {
3908
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3909
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3910
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3911
		if (val == "SavedCfg")	setPresetsnow("<?=htmlspecialchars($pconfig['adv_dhcp_pt_timeout']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_retry']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_select_timeout']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_reboot']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_backoff_cutoff']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_initial_interval']);?>");
3912
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3913
	}
3914

    
3915
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3916
		$('#adv_dhcp_pt_timeout').val(timeout);
3917
		$('#adv_dhcp_pt_retry').val(retry);
3918
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3919
		$('#adv_dhcp_pt_reboot').val(reboot);
3920
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3921
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3922
	}
3923

    
3924
	function setPPPoEDialOnDemandItems() {
3925
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3926
	}
3927

    
3928
	function setPPTPDialOnDemandItems() {
3929
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3930
	}
3931

    
3932
	function show_wpaoptions() {
3933
		var wpa = !($('#wpa_enable').prop('checked'));
3934

    
3935
		hideInput('passphrase', wpa);
3936
		hideInput('wpa_mode', wpa);
3937
		hideInput('wpa_key_mgmt', wpa);
3938
		hideInput('wpa_pairwise', wpa);
3939
		hideCheckbox('wpa_strict_rekey', wpa);
3940
		hideClass('ieee8021x_group', true);
3941
		if ($('#mode').val() == 'hostap') {
3942
			hideInput('wpa_group_rekey', wpa);
3943
			hideInput('wpa_gmk_rekey', wpa);
3944
			hideCheckbox('wpa_strict_rekey', wpa);
3945
		} else {
3946
			hideInput('wpa_group_rekey', true);
3947
			hideInput('wpa_gmk_rekey', true);
3948
			hideCheckbox('wpa_strict_rekey', true);
3949
		}
3950
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3951
	}
3952

    
3953
	function updatewifistandard(s) {
3954
		switch (s) {
3955
			case "auto": {
3956
				hideInput('protmode', false);
3957
				hideInput('channel_width', false);
3958
				break;
3959
			}
3960
			case "11b": {
3961
				hideInput('protmode', true);
3962
				hideInput('channel_width', true);
3963
				break;
3964
			}
3965
			case "11g": {
3966
				hideInput('protmode', false);
3967
				hideInput('channel_width', true);
3968
				break;
3969
			}
3970
			case "11ng": {
3971
				hideInput('protmode', false);
3972
				hideInput('channel_width', false);
3973
				break;
3974
			}
3975
			case "11a": {
3976
				hideInput('protmode', true);
3977
				hideInput('channel_width', true);
3978
				break;
3979
			}
3980
			case "11na": {
3981
				hideInput('protmode', true);
3982
				hideInput('channel_width', false);
3983
				break;
3984
			}
3985
			default: {
3986
				break;
3987
			}
3988
		}
3989
	}
3990

    
3991
	function updatewifimode(m) {
3992
		switch (m) {
3993
			case "adhoc": {
3994
				hideInput('puremode', true);
3995
				hideCheckbox('apbridge_enable', true);
3996
				hideCheckbox('hidessid_enable', false);
3997
				break;
3998
			}
3999
			case "hostap": {
4000
				hideInput('puremode', false);
4001
				hideCheckbox('apbridge_enable', false);
4002
				hideCheckbox('hidessid_enable', false);
4003
				break;
4004
			}
4005
			default: {
4006
				hideInput('puremode', true);
4007
				hideCheckbox('apbridge_enable', true);
4008
				hideCheckbox('hidessid_enable', true);
4009
				break;
4010
			}
4011
		}
4012
		show_wpaoptions();
4013
		updateeapclientmode($('#wpa_eap_client_mode').val());
4014
		updatewpakeymgmt($('#wpa_key_mgmt').val());
4015
	}
4016

    
4017
	function updateeapclientmode(m) {
4018
		if ($('#mode').val() == 'bss') {
4019
			var wpa = !($('#wpa_enable').prop('checked'));
4020
		} else {
4021
			var wpa = true;
4022
		}
4023
		switch (m) {
4024
			case "PEAP": {
4025
				hideInput('wpa_eap_cert', true);
4026
				hideInput('wpa_eap_inner_auth', wpa);
4027
				hideInput('wpa_eap_inner_id', wpa);
4028
				hideInput('wpa_eap_inner_password', wpa);
4029
				break;
4030
			}
4031
			case "TLS": {
4032
				hideInput('wpa_eap_cert', wpa);
4033
				hideInput('wpa_eap_inner_auth', true);
4034
				hideInput('wpa_eap_inner_id', true);
4035
				hideInput('wpa_eap_inner_password', true);
4036
				break;
4037
			}
4038
			case "TTLS": {
4039
				hideInput('wpa_eap_cert', wpa);
4040
				hideInput('wpa_eap_inner_auth', wpa);
4041
				hideInput('wpa_eap_inner_id', wpa);
4042
				hideInput('wpa_eap_inner_password', wpa);
4043
				break;
4044
			}
4045
			default: {
4046
				break;
4047
			}
4048
		}
4049
	}
4050

    
4051
	function updatewpakeymgmt(m) {
4052
		hideInput('passphrase', false);
4053
		hideInput('wpa_eap_client_mode', true);
4054
		hideInput('wpa_eap_ca', true);
4055
		hideInput('wpa_eap_cert', true);
4056
		hideInput('wpa_eap_inner_auth', true);
4057
		hideInput('wpa_eap_inner_id', true);
4058
		hideInput('wpa_eap_inner_password', true);
4059
		hideClass('ieee8021x_group', true);
4060
		if (m == "WPA-EAP") {
4061
			hideInput('passphrase', true);
4062
			if ($('#mode').val() == 'bss') {
4063
				hideInput('wpa_eap_client_mode', false);
4064
				hideInput('wpa_eap_ca', false);
4065
				updateeapclientmode($('#wpa_eap_client_mode').val());
4066
			} else if ($('#mode').val() == 'hostap') {
4067
				hideClass('ieee8021x_group', false);
4068
			}
4069
		} else if (m != "WPA-PSK") {
4070
			hideInput('passphrase', false);
4071
			if ($('#mode').val() == 'bss') {
4072
				hideInput('wpa_eap_client_mode', false);
4073
				hideInput('wpa_eap_ca', false);
4074
				hideInput('wpa_eap_cert', false);
4075
				hideInput('wpa_eap_inner_auth', false);
4076
				hideInput('wpa_eap_inner_id', false);
4077
				hideInput('wpa_eap_inner_password', false);
4078
			} else if ($('#mode').val() == 'hostap') {
4079
				hideClass('ieee8021x_group', false);
4080
			}
4081
		}
4082
	}
4083

    
4084
	// ---------- On initial page load ------------------------------------------------------------
4085

    
4086
	updateType($('#type').val());
4087
	updateTypeSix($('#type6').val());
4088
	show_reset_settings($('#pppoe-reset-type').val());
4089
	hideClass('dhcp6advanced', true);
4090
	hideClass('dhcpadvanced', true);
4091
	show_dhcp6adv();
4092
	setDHCPoptions();
4093
	setPPPoEDialOnDemandItems();
4094
	setPPTPDialOnDemandItems();
4095
	show_wpaoptions();
4096
	updatewifistandard($('#standard').val());
4097
	updatewifimode($('#mode').val());
4098

    
4099
	// Set preset buttons on page load
4100
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4101
	if (sv == "") {
4102
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4103
	} else {
4104
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4105
	}
4106

    
4107
	// Set preset from value
4108
	setPresets(sv);
4109

    
4110
	// If the user wants to add a gateway, then add that to the gateway selection
4111
	if ($("#gatewayip4").val() != '') {
4112
		addOption_v4();
4113
	}
4114
	if ($("#gatewayip6").val() != '') {
4115
		addOption_v6();
4116
	}
4117

    
4118
	// ---------- Click checkbox handlers ---------------------------------------------------------
4119

    
4120
	$('#type').on('change', function() {
4121
		updateType(this.value);
4122
	});
4123

    
4124
	$('#type6').on('change', function() {
4125
		updateTypeSix(this.value);
4126
	});
4127

    
4128
	$('#standard').on('change', function() {
4129
		updatewifistandard(this.value);
4130
	});
4131

    
4132
	$('#mode').on('change', function() {
4133
		updatewifimode(this.value);
4134
	});
4135

    
4136
	$('#wpa_key_mgmt').on('change', function() {
4137
		updatewpakeymgmt(this.value);
4138
	});
4139

    
4140
	$('#wpa_eap_client_mode').on('change', function() {
4141
		updateeapclientmode(this.value);
4142
	});
4143

    
4144
	$('#track6-interface').on('change', function() {
4145
		update_track6_prefix();
4146
	});
4147

    
4148
	$('#pppoe-reset-type').on('change', function() {
4149
		show_reset_settings(this.value);
4150
	});
4151

    
4152
	$("#add4").click(function() {
4153
		addOption_v4();
4154
		$("#newgateway4").modal('hide');
4155
	});
4156

    
4157
	$("#cnx4").click(function() {
4158
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4159
		$("#gatewayip4").val('');
4160
		$("#gatewaydescr4").val('');
4161
		$("#defaultgw4").prop("checked", false);
4162
		$("#newgateway4").modal('hide');
4163
	});
4164

    
4165
	$("#add6").click(function() {
4166
		addOption_v6();
4167
		$("#newgateway6").modal('hide');
4168
	});
4169

    
4170
	$("#cnx6").click(function() {
4171
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4172
		$("#gatewayip6").val('');
4173
		$("#gatewaydescr6").val('');
4174
		$("#defaultgw6").prop("checked", false);
4175
		$("#newgateway6").modal('hide');
4176
	});
4177

    
4178
	$('#country').on('change', function() {
4179
		providers_list();
4180
	});
4181

    
4182
	$('#provider_list').on('change', function() {
4183
		providerplan_list();
4184
	});
4185

    
4186
	$('#providerplan').on('change', function() {
4187
		prefill_provider();
4188
	});
4189

    
4190
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4191
		setDHCPoptions();
4192
	});
4193

    
4194
	$('#adv_dhcp6_config_advanced').click(function () {
4195
		show_dhcp6adv();
4196
	});
4197

    
4198
	$('#adv_dhcp6_config_file_override').click(function () {
4199
		show_dhcp6adv();
4200
	});
4201

    
4202
	// On click . .
4203
	$('#pppoe_dialondemand').click(function () {
4204
		setPPPoEDialOnDemandItems();
4205
	});
4206

    
4207
	$('#pptp_dialondemand').click(function () {
4208
		setPPTPDialOnDemandItems();
4209
	});
4210

    
4211
	$('[name=adv_dhcp_pt_values]').click(function () {
4212
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4213
	});
4214

    
4215
	$('#wpa_enable').click(function () {
4216
		show_wpaoptions();
4217
	});
4218

    
4219
	$('#pppoe_resetdate').datepicker();
4220

    
4221
});
4222
//]]>
4223
</script>
4224

    
4225
<?php include("foot.inc");
(71-71/228)