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
		/* description unique? */
543
		foreach ($ifdescrs as $ifent => $ifdescr) {
544
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
545
				$input_errors[] = gettext("An interface with the specified description already exists.");
546
				break;
547
			}
548
		}
549

    
550
		/* Is the description already used as an alias name? */
551
		foreach (config_get_path('aliases/alias', []) as $alias) {
552
			if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
553
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
554
			}
555
		}
556

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

    
564
		if (is_numeric($_POST['descr'])) {
565
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
566
		}
567

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

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

    
578
		/*
579
		 * Packages (e.g. tinc) create interface groups, reserve this
580
		 * namespace pkg_ for them.
581
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
582
		 */
583
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
584
			$input_errors[] = gettext("The interface description cannot start with pkg_");
585
		}
586
	}
587

    
588
	if ($_POST['blockbogons'] == "yes" &&
589
	    config_path_enabled('system','ipv6allow') &&
590
	    (config_get_path('system/maximumtableentries', 0) <
591
	     g_get('minimumtableentries_bogonsv6'))) {
592
		$input_errors[] = sprintf(gettext(
593
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
594
		    g_get('minimumtableentries_bogonsv6'));
595
	}
596

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

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

    
747
			if (empty($_POST['track6-interface'])) {
748
				$input_errors[] = gettext("A valid interface to track must be selected.");
749
			}
750

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

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

    
790
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
791
			if ($_POST['subnet'] < 31) {
792
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
793
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
794
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
795
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
796
				}
797
			}
798

    
799
			foreach ($staticroutes as $route_subnet) {
800
				list($network, $subnet) = explode("/", $route_subnet);
801
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
802
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
803
					break;
804
				}
805
				unset($network, $subnet);
806
			}
807
		}
808
	}
809
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
810
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
811

    
812
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
813
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
814
		} else {
815
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
816
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
817
			}
818
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
819
			if (count($where_ipaddr_configured)) {
820
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
821
				foreach ($where_ipaddr_configured as $subnet_conflict) {
822
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
823
				}
824
				$input_errors[] = $subnet_conflict_text;
825
			}
826

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

    
853
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
854
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
855
		$match = false;
856
		foreach ($a_gateways as $gateway) {
857
			if (in_array($_POST['gateway'], $gateway)) {
858
				$match = true;
859
			}
860
		}
861
		if (!$match) {
862
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
863
		}
864
	}
865
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
866
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
867
		$match = false;
868
		foreach ($a_gateways as $gateway) {
869
			if (in_array($_POST['gatewayv6'], $gateway)) {
870
				$match = true;
871
			}
872
		}
873
		if (!$match) {
874
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
875
		}
876
	}
877

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

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

    
932
		unset($min_mtu, $max_mtu);
933

    
934
		if (interface_is_vlan($wancfg['if']) != NULL) {
935
			$realhwif_array = get_parent_interface($wancfg['if']);
936
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
937
			$parent_realhwif = $realhwif_array[0];
938
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
939
			$mtu = 0;
940
			if (!empty($parent_if) && !(config_get_path("interfaces/{$parent_if}/mtu")))
941
				$mtu = intval(config_get_path("interfaces/{$parent_if}/mtu"));
942
			if ($mtu == 0)
943
				$mtu = get_interface_mtu($parent_realhwif);
944
			if ($_POST['mtu'] > $mtu)
945
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
946
		} else {
947
			foreach ($config['interfaces'] as $idx => $ifdata) {
948
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
949
					continue;
950
				}
951

    
952
				$realhwif_array = get_parent_interface($ifdata['if']);
953
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
954
				$parent_realhwif = $realhwif_array[0];
955

    
956
				if ($parent_realhwif != $wancfg['if']) {
957
					continue;
958
				}
959

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

    
1056
		if ($_POST['passphrase']) {
1057
			$passlen = strlen($_POST['passphrase']);
1058
			if ($passlen < 8 || $passlen > 63) {
1059
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1060
			}
1061
		}
1062

    
1063
		if ($_POST['wpa_enable'] == "yes") {
1064
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1065
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1066
			}
1067
			if (($_POST['mode'] == 'bss') & ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1068
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1069
				if (empty($_POST['wpa_eap_inner_id'])) {
1070
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1071
					    "when PEAP/TTLS authentication method is selected.");
1072
				}
1073
				if (empty($_POST['wpa_eap_inner_password'])) {
1074
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1075
					    "when PEAP/TTLS authentication method is selected.");
1076
				}
1077
			}
1078
		}
1079
	}
1080

    
1081
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1082
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1083
	}
1084

    
1085
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1086
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1087
	}
1088

    
1089
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1090
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1091
	}
1092

    
1093
	if ($_POST['gatewayip4']) {
1094
		// The user wants to add an IPv4 gateway - validate the settings
1095
		$gateway_settings4 = array();
1096

    
1097
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1098
		$gateway_settings4['interface'] = $_POST['if'];
1099
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1100
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1101
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1102
		$gateway_settings4['ipprotocol'] = 'inet';
1103
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1104
		foreach ($gw_input_errors as $input_error_text) {
1105
			$input_errors[] = $input_error_text;
1106
		}
1107
	}
1108

    
1109
	if ($_POST['gatewayip6']) {
1110
		// The user wants to add an IPv6 gateway - validate the settings
1111
		$gateway_settings6 = array();
1112

    
1113
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1114
		$gateway_settings6['interface'] = $_POST['if'];
1115
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1116
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1117
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1118
		$gateway_settings6['ipprotocol'] = 'inet6';
1119
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1120
		foreach ($gw_input_errors as $input_error_text) {
1121
			$input_errors[] = $input_error_text;
1122
		}
1123
	}
1124

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

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

    
1172
		unset($wancfg['dhcpvlanenable']);
1173
		unset($wancfg['dhcpcvpt']);
1174

    
1175
		unset($wancfg['adv_dhcp_pt_timeout']);
1176
		unset($wancfg['adv_dhcp_pt_retry']);
1177
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1178
		unset($wancfg['adv_dhcp_pt_reboot']);
1179
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1180
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1181

    
1182
		unset($wancfg['adv_dhcp_pt_values']);
1183

    
1184
		unset($wancfg['adv_dhcp_send_options']);
1185
		unset($wancfg['adv_dhcp_request_options']);
1186
		unset($wancfg['adv_dhcp_required_options']);
1187
		unset($wancfg['adv_dhcp_option_modifiers']);
1188

    
1189
		unset($wancfg['adv_dhcp_config_advanced']);
1190
		unset($wancfg['adv_dhcp_config_file_override']);
1191
		unset($wancfg['adv_dhcp_config_file_override_path']);
1192

    
1193
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1194
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1195
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1196
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1197

    
1198
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1199
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1200
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1201
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1202
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1203

    
1204
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1205
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1206
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1207
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1208
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1209

    
1210
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1211
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1212
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1213

    
1214
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1215
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1216
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1217
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1218

    
1219
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1220
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1221
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1222
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1223
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1224

    
1225
		unset($wancfg['adv_dhcp6_config_advanced']);
1226
		unset($wancfg['adv_dhcp6_config_file_override']);
1227
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1228

    
1229
		unset($wancfg['pppoe_password']);
1230
		unset($wancfg['pptp_username']);
1231
		unset($wancfg['pptp_password']);
1232
		unset($wancfg['l2tp_secret']);
1233
		unset($wancfg['provider']);
1234
		unset($wancfg['hostuniq']);
1235
		unset($wancfg['ondemand']);
1236
		unset($wancfg['timeout']);
1237
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1238
			unset($wancfg['pppoe']['pppoe-reset-type']);
1239
		}
1240
		unset($wancfg['local']);
1241

    
1242
		unset($wancfg['remote']);
1243
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1244
			if ($wancfg['ipaddr'] != 'ppp') {
1245
				unset($a_ppps[$pppid]['apn']);
1246
				unset($a_ppps[$pppid]['phone']);
1247
				unset($a_ppps[$pppid]['provider']);
1248
				unset($a_ppps[$pppid]['ondemand']);
1249
			}
1250
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1251
				unset($a_ppps[$pppid]['localip']);
1252
				unset($a_ppps[$pppid]['subnet']);
1253
				unset($a_ppps[$pppid]['gateway']);
1254
			}
1255
			if ($wancfg['ipaddr'] != 'pppoe') {
1256
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1257
				unset($a_ppps[$pppid]['hostuniq']);
1258
			}
1259
			if ($wancfg['type'] != $_POST['type']) {
1260
				unset($a_ppps[$pppid]['idletimeout']);
1261
			}
1262
		}
1263

    
1264
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1265
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1266

    
1267
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1268
		switch ($_POST['type']) {
1269
			case "staticv4":
1270
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1271
				$wancfg['subnet'] = $_POST['subnet'];
1272
				if ($_POST['gateway'] != "none") {
1273
					$wancfg['gateway'] = $_POST['gateway'];
1274
				}
1275
				break;
1276
			case "dhcp":
1277
				$wancfg['ipaddr'] = "dhcp";
1278
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1279
				$wancfg['alias-address'] = $_POST['alias-address'];
1280
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1281
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1282

    
1283
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1284
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1285
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1286
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1287
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1288
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1289

    
1290
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1291

    
1292
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1293
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1294
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1295
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1296

    
1297
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1298
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1299
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1300

    
1301
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1302
				if ($gateway_item) {
1303
					$a_gateways[] = $gateway_item;
1304
				}
1305
				if ($_POST['dhcpvlanenable'] == "yes") {
1306
					$wancfg['dhcpvlanenable'] = true;
1307
				}
1308
				if (!empty($_POST['dhcpcvpt'])) {
1309
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1310
				} else {
1311
					unset($wancfg['dhcpcvpt']);
1312
				}
1313
				break;
1314
			case "ppp":
1315
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1316
				$a_ppps[$pppid]['type'] = $_POST['type'];
1317
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1318
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1319
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1320
				if ($_POST['ppp_password'] != DMYPWD) {
1321
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1322
				}
1323
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1324
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1325
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1326
				$wancfg['ipaddr'] = $_POST['type'];
1327
				break;
1328

    
1329
			case "pppoe":
1330
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1331
				$a_ppps[$pppid]['type'] = $_POST['type'];
1332
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1333
				if (isset($_POST['ppp_port'])) {
1334
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1335
				} else {
1336
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1337
				}
1338
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1339
				if ($_POST['pppoe_password'] != DMYPWD) {
1340
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1341
				}
1342
				if (!empty($_POST['provider'])) {
1343
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1344
				} else {
1345
					$a_ppps[$pppid]['provider'] = true;
1346
				}
1347
				if (!empty($_POST['hostuniq'])) {
1348
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1349
				} else {
1350
					$a_ppps[$pppid]['hostuniq'] = true;
1351
				}
1352
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1353
				if (!empty($_POST['pppoe_idletimeout'])) {
1354
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1355
				} else {
1356
					unset($a_ppps[$pppid]['idletimeout']);
1357
				}
1358

    
1359
				if (!empty($_POST['pppoe-reset-type'])) {
1360
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1361
				} else {
1362
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1363
				}
1364
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1365
				$wancfg['ipaddr'] = $_POST['type'];
1366
				if ($gateway_item) {
1367
					$a_gateways[] = $gateway_item;
1368
				}
1369

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

    
1454
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1455
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1456
				}
1457
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1458
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1459
				}
1460
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1461
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1462
				}
1463
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1464
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1465
				}
1466

    
1467
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1468
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1469
				}
1470
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1471
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1472
				}
1473
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1474
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1475
				}
1476
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1477
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1478
				}
1479
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1480
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1481
				}
1482

    
1483
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1484
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1485
				}
1486
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1487
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1488
				}
1489
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1490
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1491
				}
1492
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1493
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1494
				}
1495
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1496
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1497
				}
1498

    
1499
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1500
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1501
				}
1502
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1503
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1504
				}
1505
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1506
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1507
				}
1508
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1509
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1510
				}
1511
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1512
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1513
				}
1514
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1515
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1516
				}
1517
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1518
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1519
				}
1520

    
1521
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1522
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1523
				}
1524
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1525
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1526
				}
1527
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1528
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1529
				}
1530
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1531
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1532
				}
1533
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1534
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1535
				}
1536

    
1537
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1538
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1539
				}
1540
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1541
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1542
				}
1543
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1544
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1545
				}
1546

    
1547
				if ($gateway_item) {
1548
					$a_gateways[] = $gateway_item;
1549
				}
1550
				break;
1551
			case "6rd":
1552
				$wancfg['ipaddrv6'] = "6rd";
1553
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1554
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1555
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1556
				if ($gateway_item) {
1557
					$a_gateways[] = $gateway_item;
1558
				}
1559
				break;
1560
			case "6to4":
1561
				$wancfg['ipaddrv6'] = "6to4";
1562
				break;
1563
			case "track6":
1564
				$wancfg['ipaddrv6'] = "track6";
1565
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1566
				if ($_POST['track6-prefix-id--hex'] === "") {
1567
					$wancfg['track6-prefix-id'] = 0;
1568
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1569
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1570
				} else {
1571
					$wancfg['track6-prefix-id'] = 0;
1572
				}
1573
				break;
1574
			case "none":
1575
				break;
1576
		}
1577
		handle_pppoe_reset($_POST);
1578

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

    
1625
		write_config("Interfaces settings changed");
1626

    
1627
		if ($_POST['gatewayip4']) {
1628
			save_gateway($gateway_settings4);
1629
		}
1630

    
1631
		if ($_POST['gatewayip6']) {
1632
			save_gateway($gateway_settings6);
1633
		}
1634

    
1635
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1636
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1637
		} else {
1638
			$toapplylist = array();
1639
		}
1640
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1641
		$toapplylist[$if]['ppps'] = $old_ppps;
1642
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1643

    
1644
		mark_subsystem_dirty('interfaces');
1645

    
1646
		/* regenerate cron settings/crontab file */
1647
		configure_cron();
1648

    
1649
		header("Location: interfaces.php?if={$if}");
1650
		exit;
1651
	}
1652

    
1653
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1654
	if (!empty($_POST['ppp_port'])) {
1655
		$pconfig['port'] = $_POST['ppp_port'];
1656
	}
1657

    
1658
} // end if ($_POST['save'])
1659

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

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

    
1773
	if ($_POST['wme_enable'] == "yes") {
1774
		if (!is_array($wancfg['wireless']['wme'])) {
1775
			$wancfg['wireless']['wme'] = array();
1776
		}
1777
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1778
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1779
		unset($wancfg['wireless']['wme']['enable']);
1780
	}
1781
	if ($_POST['puremode'] == "11g") {
1782
		if (!is_array($wancfg['wireless']['pureg'])) {
1783
			$wancfg['wireless']['pureg'] = array();
1784
		}
1785
		$wancfg['wireless']['pureg']['enable'] = true;
1786
	} else if ($_POST['puremode'] == "11n") {
1787
		if (!is_array($wancfg['wireless']['puren'])) {
1788
			$wancfg['wireless']['puren'] = array();
1789
		}
1790
		$wancfg['wireless']['puren']['enable'] = true;
1791
	} else {
1792
		if (isset($wancfg['wireless']['pureg'])) {
1793
			unset($wancfg['wireless']['pureg']);
1794
		}
1795
		if (isset($wancfg['wireless']['puren'])) {
1796
			unset($wancfg['wireless']['puren']);
1797
		}
1798
	}
1799
	if ($_POST['apbridge_enable'] == "yes") {
1800
		if (!is_array($wancfg['wireless']['apbridge'])) {
1801
			$wancfg['wireless']['apbridge'] = array();
1802
		}
1803
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1804
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1805
		unset($wancfg['wireless']['apbridge']['enable']);
1806
	}
1807
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1808
		if (!is_array($wancfg['wireless']['turbo'])) {
1809
			$wancfg['wireless']['turbo'] = array();
1810
		}
1811
		$wancfg['wireless']['turbo']['enable'] = true;
1812
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1813
		unset($wancfg['wireless']['turbo']['enable']);
1814
	}
1815

    
1816
	interface_sync_wireless_clones($wancfg, true);
1817
}
1818

    
1819
function check_wireless_mode() {
1820
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1821

    
1822
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1823
		return;
1824
	}
1825

    
1826
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1827
		$clone_count = 1;
1828
	} else {
1829
		$clone_count = 0;
1830
	}
1831

    
1832
	foreach (config_get_path('wireless/clone', []) as $clone) {
1833
		if ($clone['if'] == $wlanbaseif) {
1834
				$clone_count++;
1835
		}
1836
	}
1837

    
1838
	if ($clone_count > 1) {
1839
		$old_wireless_mode = $wancfg['wireless']['mode'];
1840
		$wancfg['wireless']['mode'] = $_POST['mode'];
1841
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1842
			$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']]);
1843
		} else {
1844
			pfSense_interface_destroy("{$wlanif}_");
1845
		}
1846
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1847
	}
1848
}
1849

    
1850
// Find all possible media options for the interface
1851
$mediaopts_list = array();
1852
$intrealname = config_get_path("interfaces/{$if}/if");
1853
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1854
foreach ($mediaopts as $mediaopt) {
1855
	preg_match("/media (.*)/", $mediaopt, $matches);
1856
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1857
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1858
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1859
	} else {
1860
		// there is only media like "media 1000baseT"
1861
		array_push($mediaopts_list, $matches[1]);
1862
	}
1863
}
1864

    
1865
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1866
$shortcut_section = "interfaces";
1867

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

    
1870
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1871
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1872
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1873
}
1874

    
1875
$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"));
1876

    
1877
// Get the MAC address
1878
$defgatewayname4 = $wancfg['descr'] . "GW";
1879
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1880

    
1881
function build_mediaopts_list() {
1882
	global $mediaopts_list;
1883

    
1884
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1885
			 " " =>	 gettext("------- Media Supported by this interface -------")
1886
			];
1887

    
1888
	foreach ($mediaopts_list as $mediaopt) {
1889
		$list[$mediaopt] = $mediaopt;
1890
	}
1891

    
1892
	return($list);
1893
}
1894

    
1895
function build_gateway_list() {
1896
	global $a_gateways, $if;
1897

    
1898
	$list = array("none" => gettext("None"));
1899
	foreach ($a_gateways as $gateway) {
1900
		if (empty($gateway)) {
1901
			continue;
1902
		}
1903
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1904
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1905
		}
1906
	}
1907

    
1908
	return($list);
1909
}
1910

    
1911
function build_gatewayv6_list() {
1912
	global $a_gateways, $if;
1913

    
1914
	$list = array("none" => gettext("None"));
1915
	foreach ($a_gateways as $gateway) {
1916
		if (empty($gateway)) {
1917
			continue;
1918
		}
1919
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1920
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1921
		}
1922
	}
1923

    
1924
	return($list);
1925
}
1926

    
1927
include("head.inc");
1928

    
1929
if ($input_errors) {
1930
	print_input_errors($input_errors);
1931
}
1932

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

    
1939
if ($changes_applied) {
1940
	print_apply_result_box($retval);
1941
}
1942

    
1943
$form = new Form();
1944

    
1945
$section = new Form_Section('General Configuration');
1946

    
1947
$section->addInput(new Form_Checkbox(
1948
	'enable',
1949
	'Enable',
1950
	'Enable interface',
1951
	$pconfig['enable'],
1952
	'yes'
1953
));
1954

    
1955
$section->addInput(new Form_Input(
1956
	'descr',
1957
	'*Description',
1958
	'text',
1959
	$pconfig['descr']
1960
))->setHelp('Enter a description (name) for the interface here.');
1961

    
1962
if ($show_address_controls) {
1963
	$section->addInput(new Form_Select(
1964
		'type',
1965
		'IPv4 Configuration Type',
1966
		$pconfig['type'],
1967
		$types4
1968
	));
1969
	$section->addInput(new Form_Select(
1970
		'type6',
1971
		'IPv6 Configuration Type',
1972
		$pconfig['type6'],
1973
		$types6
1974
	));
1975
} else {
1976
	$section->addInput(new Form_StaticText(
1977
		'IPv4/IPv6 Configuration',
1978
		"This interface type does not support manual address configuration on this page. "
1979
	));
1980
	$form->addGlobal(new Form_Input(
1981
		'type',
1982
		null,
1983
		'hidden',
1984
		'none'
1985
	));
1986
	$form->addGlobal(new Form_Input(
1987
		'type6',
1988
		null,
1989
		'hidden',
1990
		'none'
1991
	));
1992
}
1993

    
1994
if (!is_pseudo_interface($intrealname, true)) {
1995
	$macaddress = new Form_Input(
1996
		'spoofmac',
1997
		'MAC Address',
1998
		'text',
1999
		$pconfig['spoofmac'],
2000
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
2001
	);
2002

    
2003
	if (interface_is_vlan($realifname)) {
2004
		$macaddress->setDisabled();
2005
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
2006
		    'set on its parent interface');
2007
	} else {
2008
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
2009
		    'MAC address of this interface.%sEnter a MAC address in the ' .
2010
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
2011
	}
2012

    
2013
	$section->addInput($macaddress);
2014
}
2015

    
2016
$mtuInput = $section->addInput(new Form_Input(
2017
	'mtu',
2018
	'MTU',
2019
	'number',
2020
	$pconfig['mtu'],
2021
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2022
			'This is typically 1500 bytes but can vary in some circumstances.');
2023
/* Do not allow MTU changes for interfaces in a bridge */
2024
if ($bridged) {
2025
	$mtuInput->setDisabled();
2026
	$mtuInput->setHelp('This interface is a bridge member, its MTU is ' .
2027
					   'controlled by its parent bridge interface');
2028
	$mtuInput->setPlaceholder(get_interface_mtu($bridged));
2029
	$mtuInput->setValue(null);
2030
}
2031

    
2032
$section->addInput(new Form_Input(
2033
	'mss',
2034
	'MSS',
2035
	'number',
2036
	$pconfig['mss']
2037
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2038
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2039

    
2040
if (count($mediaopts_list) > 0) {
2041
	$section->addInput(new Form_Select(
2042
		'mediaopt',
2043
		'Speed and Duplex',
2044
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt")),
2045
		build_mediaopts_list() 
2046
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2047
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2048
}
2049

    
2050
$form->add($section);
2051

    
2052
$section = new Form_Section('Static IPv4 Configuration');
2053
$section->addClass('staticv4');
2054

    
2055
$section->addInput(new Form_IpAddress(
2056
	'ipaddr',
2057
	'*IPv4 Address',
2058
	$pconfig['ipaddr'],
2059
	'V4'
2060
))->addMask('subnet', $pconfig['subnet'], 32);
2061

    
2062
$group = new Form_Group('IPv4 Upstream gateway');
2063

    
2064
$group->add(new Form_Select(
2065
	'gateway',
2066
	'IPv4 Upstream Gateway',
2067
	$pconfig['gateway'],
2068
	build_gateway_list()
2069
));
2070

    
2071
$group->add(new Form_Button(
2072
	'addgw4',
2073
	'Add a new gateway',
2074
	null,
2075
	'fa-plus'
2076
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2077

    
2078
$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' .
2079
				'On local area network interfaces the upstream gateway should be "none".%1$s' .
2080
				'Selecting an upstream gateway causes the firewall to treat this interface as a %2$sWAN type interface%4$s.%1$s' .
2081
				'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>');
2082

    
2083
$section->add($group);
2084

    
2085
$form->add($section);
2086

    
2087
$section = new Form_Section('SLAAC IPv6 Configuration');
2088
$section->addClass('slaac');
2089

    
2090
$section->addInput(new Form_Checkbox(
2091
	'slaacusev4iface',
2092
	'Use IPv4 connectivity as parent interface',
2093
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2094
	$pconfig['slaacusev4iface']
2095
));
2096

    
2097
$form->add($section);
2098

    
2099
$section = new Form_Section('Static IPv6 Configuration');
2100
$section->addClass('staticv6');
2101

    
2102
$section->addInput(new Form_IpAddress(
2103
	'ipaddrv6',
2104
	'*IPv6 address',
2105
	$pconfig['ipaddrv6'],
2106
	'V6'
2107
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2108

    
2109
$section->addInput(new Form_Checkbox(
2110
	'ipv6usev4iface',
2111
	'Use IPv4 connectivity as parent interface',
2112
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2113
	$pconfig['ipv6usev4iface']
2114
));
2115

    
2116
$group = new Form_Group('IPv6 Upstream gateway');
2117

    
2118
$group->add(new Form_Select(
2119
	'gatewayv6',
2120
	'IPv6 Upstream Gateway',
2121
	$pconfig['gatewayv6'],
2122
	build_gatewayv6_list()
2123
));
2124

    
2125
$group->add(new Form_Button(
2126
	'addgw6',
2127
	'Add a new gateway',
2128
	null,
2129
	'fa-plus'
2130
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2131

    
2132
$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' .
2133
				'On local LANs the upstream gateway should be "none". ', '<br />');
2134

    
2135
$section->add($group);
2136
$form->add($section);
2137

    
2138
// Add new gateway modal pop-up for IPv6
2139
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2140

    
2141
$modal->addInput(new Form_Checkbox(
2142
	'defaultgw6',
2143
	'Default',
2144
	'Default gateway',
2145
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2146
));
2147

    
2148
$modal->addInput(new Form_Input(
2149
	'gatewayname6',
2150
	'Gateway name',
2151
	'text',
2152
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2153
));
2154

    
2155
$modal->addInput(new Form_IpAddress(
2156
	'gatewayip6',
2157
	'Gateway IPv6',
2158
	$gateway_settings6['gateway'],
2159
	'V6'
2160
));
2161

    
2162
$modal->addInput(new Form_Input(
2163
	'gatewaydescr6',
2164
	'Description',
2165
	'text',
2166
	$gateway_settings6['descr']
2167
));
2168

    
2169
$btnaddgw6 = new Form_Button(
2170
	'add6',
2171
	'Add',
2172
	null,
2173
	'fa-plus'
2174
);
2175

    
2176
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2177

    
2178
$btncnxgw6 = new Form_Button(
2179
	'cnx6',
2180
	'Cancel',
2181
	null,
2182
	'fa-undo'
2183
);
2184

    
2185
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2186

    
2187
$modal->addInput(new Form_StaticText(
2188
	null,
2189
	$btnaddgw6 . $btncnxgw6
2190
));
2191

    
2192
$form->add($modal);
2193

    
2194
// ==== DHCP client configuration =============================
2195

    
2196
$section = new Form_Section('DHCP Client Configuration');
2197
$section->addClass('dhcp');
2198

    
2199
$group = new Form_Group('Options');
2200

    
2201
$group->add(new Form_Checkbox(
2202
	'adv_dhcp_config_advanced',
2203
	null,
2204
	'Advanced Configuration',
2205
	$pconfig['adv_dhcp_config_advanced']
2206
))->setHelp('Use advanced DHCP configuration options.');
2207

    
2208
$group->add(new Form_Checkbox(
2209
	'adv_dhcp_config_file_override',
2210
	null,
2211
	'Configuration Override',
2212
	$pconfig['adv_dhcp_config_file_override']
2213
))->setHelp('Override the configuration from this file.');
2214

    
2215
$section->add($group);
2216

    
2217
$section->addInput(new Form_Input(
2218
	'dhcphostname',
2219
	'Hostname',
2220
	'text',
2221
	$pconfig['dhcphostname']
2222
))->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).');
2223

    
2224
$section->addInput(new Form_IpAddress(
2225
	'alias-address',
2226
	'Alias IPv4 address',
2227
	$pconfig['alias-address'],
2228
	'V4'
2229
))->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.');
2230

    
2231
$section->addInput(new Form_Input(
2232
	'dhcprejectfrom',
2233
	'Reject leases from',
2234
	'text',
2235
	$pconfig['dhcprejectfrom']
2236
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2237
			'(separate multiple entries with a comma). ' .
2238
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2239

    
2240
if (interface_is_vlan($wancfg['if']) != NULL) {
2241

    
2242
	$group = new Form_Group('DHCP VLAN Priority');
2243
	$group->add(new Form_Checkbox(
2244
		'dhcpvlanenable',
2245
		null,
2246
		'Enable dhcpclient VLAN Priority tagging',
2247
		$pconfig['dhcpvlanenable']
2248
	))->setHelp('Normally off unless specifically required by the ISP.');
2249

    
2250
	$group->add(new Form_Select(
2251
		'dhcpcvpt',
2252
		'VLAN Prio',
2253
		$pconfig['dhcpcvpt'],
2254
		$vlanprio
2255
	))->setHelp('Choose 802.1p priority to set.');
2256

    
2257
	$section->add($group);
2258
}
2259

    
2260
$group = new Form_Group('Protocol timing');
2261
$group->addClass('dhcpadvanced');
2262
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.%1$s' .
2263
				'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>');
2264

    
2265
$group->add(new Form_Input(
2266
	'adv_dhcp_pt_timeout',
2267
	null,
2268
	'number',
2269
	$pconfig['adv_dhcp_pt_timeout']
2270
))->setHelp('Timeout');
2271

    
2272
$group->add(new Form_Input(
2273
	'adv_dhcp_pt_retry',
2274
	null,
2275
	'number',
2276
	$pconfig['adv_dhcp_pt_retry']
2277
))->setHelp('Retry');
2278

    
2279
$group->add(new Form_Input(
2280
	'adv_dhcp_pt_select_timeout',
2281
	null,
2282
	'number',
2283
	$pconfig['adv_dhcp_pt_select_timeout'],
2284
	['min' => 0]
2285
))->setHelp('Select timeout');
2286

    
2287
$group->add(new Form_Input(
2288
	'adv_dhcp_pt_reboot',
2289
	null,
2290
	'number',
2291
	$pconfig['adv_dhcp_pt_reboot']
2292
))->setHelp('Reboot');
2293

    
2294
$group->add(new Form_Input(
2295
	'adv_dhcp_pt_backoff_cutoff',
2296
	null,
2297
	'number',
2298
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2299
))->setHelp('Backoff cutoff');
2300

    
2301
$group->add(new Form_Input(
2302
	'adv_dhcp_pt_initial_interval',
2303
	null,
2304
	'number',
2305
	$pconfig['adv_dhcp_pt_initial_interval']
2306
))->setHelp('Initial interval');
2307

    
2308
$section->add($group);
2309

    
2310
$group = new Form_Group('Presets');
2311
$group->addClass('dhcpadvanced');
2312

    
2313
$group->add(new Form_Checkbox(
2314
	'adv_dhcp_pt_values',
2315
	null,
2316
	'FreeBSD default',
2317
	null,
2318
	'DHCP'
2319
))->displayAsRadio();
2320

    
2321
$group->add(new Form_Checkbox(
2322
	'adv_dhcp_pt_values',
2323
	null,
2324
	'Clear',
2325
	null,
2326
	'Clear'
2327
))->displayAsRadio();
2328

    
2329
$group->add(new Form_Checkbox(
2330
	'adv_dhcp_pt_values',
2331
	null,
2332
	'pfSense Default',
2333
	null,
2334
	'pfSense'
2335
))->displayAsRadio();
2336

    
2337
$group->add(new Form_Checkbox(
2338
	'adv_dhcp_pt_values',
2339
	null,
2340
	'Saved Cfg',
2341
	null,
2342
	'SavedCfg'
2343
))->displayAsRadio();
2344

    
2345
$section->add($group);
2346

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

    
2357
$form->add($section);
2358

    
2359
$section = new Form_Section('Lease Requirements and Requests');
2360
$section->addClass('dhcpadvanced');
2361

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

    
2372
$section->addInput(new Form_Input(
2373
	'adv_dhcp_request_options',
2374
	'Request options',
2375
	'text',
2376
	$pconfig['adv_dhcp_request_options']
2377
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2378
			'Some ISPs may require certain options be or not be requested.', '<br />');
2379

    
2380
$section->addInput(new Form_Input(
2381
	'adv_dhcp_required_options',
2382
	'Require options',
2383
	'text',
2384
	$pconfig['adv_dhcp_required_options']
2385
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2386

    
2387
$section->addInput(new Form_Input(
2388
	'adv_dhcp_option_modifiers',
2389
	'Option modifiers',
2390
	'text',
2391
	$pconfig['adv_dhcp_option_modifiers']
2392
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2393
			'modifiers: (default, supersede, prepend, append) %1$s' .
2394
			'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>');
2395

    
2396
$form->add($section);
2397

    
2398
// DHCP6 client config
2399

    
2400
$section = new Form_Section('DHCP6 Client Configuration');
2401
$section->addClass('dhcp6');
2402

    
2403
$group = new Form_Group('Options');
2404

    
2405
$group->add(new Form_Checkbox(
2406
	'adv_dhcp6_config_advanced',
2407
	null,
2408
	'Advanced Configuration',
2409
	$pconfig['adv_dhcp6_config_advanced']
2410
))->setHelp('Use advanced DHCPv6 configuration options.');
2411

    
2412
$group->add(new Form_Checkbox(
2413
	'adv_dhcp6_config_file_override',
2414
	null,
2415
	'Configuration Override',
2416
	$pconfig['adv_dhcp6_config_file_override']
2417
))->setHelp('Override the configuration from this file.');
2418

    
2419
$section->add($group);
2420

    
2421
$section->addInput(new Form_Checkbox(
2422
	'dhcp6usev4iface',
2423
	'Use IPv4 connectivity as parent interface',
2424
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2425
	$pconfig['dhcp6usev4iface']
2426
));
2427

    
2428
$section->addInput(new Form_Checkbox(
2429
	'dhcp6prefixonly',
2430
	'Request only an IPv6 prefix',
2431
	'Only request an IPv6 prefix, do not request an IPv6 address',
2432
	$pconfig['dhcp6prefixonly']
2433
));
2434

    
2435
$section->addInput(new Form_Select(
2436
	'dhcp6-ia-pd-len',
2437
	'DHCPv6 Prefix Delegation size',
2438
	$pconfig['dhcp6-ia-pd-len'],
2439
	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")
2440
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2441

    
2442
$section->addInput(new Form_Checkbox(
2443
	'dhcp6-ia-pd-send-hint',
2444
	'Send IPv6 prefix hint',
2445
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2446
	$pconfig['dhcp6-ia-pd-send-hint']
2447
));
2448

    
2449
$section->addInput(new Form_Checkbox(
2450
	'dhcp6withoutra',
2451
	'Do not wait for a RA',
2452
	'Required by some ISPs, especially those not using PPPoE',
2453
	$pconfig['dhcp6withoutra']
2454
));
2455

    
2456
if (interface_is_vlan($wancfg['if']) != NULL) {
2457
	$group = new Form_Group('DHCP6 VLAN Priority');
2458

    
2459
	$group->add(new Form_Checkbox(
2460
		'dhcp6vlanenable',
2461
		null,
2462
		'Enable dhcp6c VLAN Priority tagging',
2463
		$pconfig['dhcp6vlanenable']
2464
	))->setHelp('Normally off unless specifically required by the ISP.');
2465

    
2466
	$group->add(new Form_Select(
2467
		'dhcp6cvpt',
2468
		'VLAN Prio',
2469
		$pconfig['dhcp6cvpt'],
2470
		$vlanprio
2471
	))->setHelp('Choose 802.1p priority to set.');
2472

    
2473
	$section->add($group);
2474
}
2475

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

    
2486
$form->add($section);
2487

    
2488
// DHCP6 client config - Advanced
2489

    
2490
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2491
$section->addClass('dhcp6advanced');
2492

    
2493
$section->addInput(new Form_Checkbox(
2494
	'adv_dhcp6_interface_statement_information_only_enable',
2495
	'Information only',
2496
	'Exchange Information Only',
2497
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2498
	'Selected'
2499
))->setHelp('Only exchange informational configuration parameters with servers.');
2500

    
2501
$section->addInput(new Form_Input(
2502
	'adv_dhcp6_interface_statement_send_options',
2503
	'Send options',
2504
	'text',
2505
	$pconfig['adv_dhcp6_interface_statement_send_options']
2506
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2507
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2508
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2509
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2510

    
2511
$section->addInput(new Form_Input(
2512
	'adv_dhcp6_interface_statement_request_options',
2513
	'Request Options',
2514
	'text',
2515
	$pconfig['adv_dhcp6_interface_statement_request_options']
2516
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2517
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2518

    
2519
$section->addInput(new Form_Input(
2520
	'adv_dhcp6_interface_statement_script',
2521
	'Scripts',
2522
	'text',
2523
	$pconfig['adv_dhcp6_interface_statement_script']
2524
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2525
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2526

    
2527
$group = new Form_Group('Identity Association Statement');
2528

    
2529
$group->add(new Form_Checkbox(
2530
	'adv_dhcp6_id_assoc_statement_address_enable',
2531
	null,
2532
	'Non-Temporary Address Allocation',
2533
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2534
	'Selected'
2535
));
2536

    
2537
$group->add(new Form_Input(
2538
	'adv_dhcp6_id_assoc_statement_address_id',
2539
	null,
2540
	'text',
2541
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2542
))->sethelp('id-assoc na ID');
2543

    
2544
$group->add(new Form_IpAddress(
2545
	'adv_dhcp6_id_assoc_statement_address',
2546
	null,
2547
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2548
	'V6'
2549
))->sethelp('IPv6 address');
2550

    
2551
$group->add(new Form_Input(
2552
	'adv_dhcp6_id_assoc_statement_address_pltime',
2553
	null,
2554
	'text',
2555
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2556
))->sethelp('pltime');
2557

    
2558
$group->add(new Form_Input(
2559
	'adv_dhcp6_id_assoc_statement_address_vltime',
2560
	null,
2561
	'text',
2562
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2563
))->sethelp('vltime');
2564

    
2565
$section->add($group);
2566

    
2567
// Prefix delegation
2568
$group = new Form_Group('');
2569

    
2570
$group->add(new Form_Checkbox(
2571
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2572
	null,
2573
	'Prefix Delegation ',
2574
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2575
	'Selected'
2576
));
2577

    
2578
$group->add(new Form_Input(
2579
	'adv_dhcp6_id_assoc_statement_prefix_id',
2580
	null,
2581
	'text',
2582
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2583
))->sethelp('id-assoc pd ID');
2584

    
2585
$group->add(new Form_IpAddress(
2586
	'adv_dhcp6_id_assoc_statement_prefix',
2587
	null,
2588
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2589
	'V6'
2590
))->sethelp('IPv6 prefix');
2591

    
2592
$group->add(new Form_Input(
2593
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2594
	null,
2595
	'text',
2596
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2597
))->sethelp('pltime');
2598

    
2599
$group->add(new Form_Input(
2600
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2601
	null,
2602
	'text',
2603
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2604
))->sethelp('vltime');
2605

    
2606
$section->add($group);
2607

    
2608
$group = new Form_Group('Prefix interface statement');
2609

    
2610
$group->add(new Form_Input(
2611
	'adv_dhcp6_prefix_interface_statement_sla_id',
2612
	null,
2613
	'text',
2614
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2615
))->sethelp('Prefix Interface sla-id');
2616

    
2617
$group->add(new Form_Input(
2618
	'adv_dhcp6_prefix_interface_statement_sla_len',
2619
	null,
2620
	'text',
2621
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2622
))->sethelp('sla-len');
2623

    
2624
$section->add($group);
2625

    
2626
$group = new Form_Group('Select prefix interface');
2627
$section->addInput(new Form_Select(
2628
	'adv_dhcp6_prefix_selected_interface',
2629
	'Prefix Interface',
2630
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2631
	$interfaces
2632
))->setHelp('Select the interface on which to apply the prefix delegation.');
2633

    
2634
$group = new Form_Group('Authentication statement');
2635

    
2636
$group->add(new Form_Input(
2637
	'adv_dhcp6_authentication_statement_authname',
2638
	null,
2639
	'text',
2640
	$pconfig['adv_dhcp6_authentication_statement_authname']
2641
))->sethelp('Authname');
2642

    
2643
$group->add(new Form_Input(
2644
	'adv_dhcp6_authentication_statement_protocol',
2645
	null,
2646
	'text',
2647
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2648
))->sethelp('Protocol');
2649

    
2650
$group->add(new Form_Input(
2651
	'adv_dhcp6_authentication_statement_algorithm',
2652
	null,
2653
	'text',
2654
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2655
))->sethelp('Algorithm');
2656

    
2657
$group->add(new Form_Input(
2658
	'adv_dhcp6_authentication_statement_rdm',
2659
	null,
2660
	'text',
2661
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2662
))->sethelp('RDM');
2663

    
2664
$section->add($group);
2665

    
2666
$group = new Form_Group('Keyinfo statement');
2667

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

    
2675
$group->add(new Form_Input(
2676
	'adv_dhcp6_key_info_statement_realm',
2677
	null,
2678
	'text',
2679
	$pconfig['adv_dhcp6_key_info_statement_realm']
2680
))->sethelp('Realm');
2681

    
2682
$section->add($group);
2683

    
2684
$group = new Form_Group('');
2685

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

    
2693
$group->add(new Form_Input(
2694
	'adv_dhcp6_key_info_statement_secret',
2695
	null,
2696
	'text',
2697
	$pconfig['adv_dhcp6_key_info_statement_secret']
2698
))->sethelp('Secret');
2699

    
2700
$group->add(new Form_Input(
2701
	'adv_dhcp6_key_info_statement_expire',
2702
	null,
2703
	'text',
2704
	$pconfig['adv_dhcp6_key_info_statement_expire']
2705
))->sethelp('Expire');
2706

    
2707
$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>');
2708

    
2709
$section->add($group);
2710

    
2711
$form->add($section);
2712

    
2713
$section = new Form_Section('6RD Configuration');
2714
$section->addClass('_6rd');
2715

    
2716
$section->addInput(new Form_Input(
2717
	'prefix-6rd',
2718
	'6RD Prefix',
2719
	'text',
2720
	$pconfig['prefix-6rd']
2721
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2722

    
2723
$section->addInput(new Form_Input(
2724
	'gateway-6rd',
2725
	'*6RD Border relay',
2726
	'text',
2727
	$pconfig['gateway-6rd']
2728
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2729

    
2730
$section->addInput(new Form_Select(
2731
	'prefix-6rd-v4plen',
2732
	'6RD IPv4 Prefix length',
2733
	$pconfig['prefix-6rd-v4plen'],
2734
	array_combine(range(0, 32), range(0, 32))
2735
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2736

    
2737
$form->add($section);
2738

    
2739
// Track IPv6 ointerface section
2740
$section = new Form_Section('Track IPv6 Interface');
2741
$section->addClass('track6');
2742

    
2743
function build_ipv6interface_list() {
2744
	global $config, $form;
2745

    
2746
	$list = array('' => '');
2747

    
2748
	$interfaces = get_configured_interface_with_descr(true);
2749
	$dynv6ifs = array();
2750

    
2751
	foreach ($interfaces as $iface => $ifacename) {
2752
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2753
			case "6to4":
2754
			case "6rd":
2755
			case "dhcp6":
2756
				$dynv6ifs[$iface] = array(
2757
					'name' => $ifacename,
2758
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2759
				);
2760
				break;
2761
			default:
2762
				continue 2;
2763
		}
2764
	}
2765

    
2766
	foreach ($dynv6ifs as $iface => $ifacedata) {
2767
		$list[$iface] = $ifacedata['name'];
2768

    
2769
		$form->addGlobal(new Form_Input(
2770
			'ipv6-num-prefix-ids-' . $iface,
2771
			null,
2772
			'hidden',
2773
			$ifacedata['ipv6_num_prefix_ids']
2774
		));
2775
	}
2776

    
2777
	return($list);
2778
}
2779

    
2780
$section->addInput(new Form_Select(
2781
	'track6-interface',
2782
	'*IPv6 Interface',
2783
	$pconfig['track6-interface'],
2784
	build_ipv6interface_list()
2785
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2786

    
2787
if ($pconfig['track6-prefix-id'] == "") {
2788
	$pconfig['track6-prefix-id'] = 0;
2789
}
2790

    
2791
$section->addInput(new Form_Input(
2792
	'track6-prefix-id--hex',
2793
	'IPv6 Prefix ID',
2794
	'text',
2795
	sprintf("%x", $pconfig['track6-prefix-id'])
2796
))->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>');
2797

    
2798
$form->addGlobal(new Form_Input(
2799
	'track6-prefix-id-max',
2800
	null,
2801
	'hidden',
2802
	0
2803
));
2804

    
2805
$form->add($section);
2806

    
2807
/// PPP section
2808

    
2809
$section = new Form_Section('PPP Configuration');
2810
$section->addClass('ppp');
2811

    
2812
$section->addInput(new Form_Select(
2813
	'country',
2814
	'Country',
2815
	$pconfig['country'],
2816
	[]
2817
));
2818

    
2819
$section->addInput(new Form_Select(
2820
	'provider_list',
2821
	'Provider',
2822
	$pconfig['provider_list'],
2823
	[]
2824
));
2825

    
2826
$section->addInput(new Form_Select(
2827
	'providerplan',
2828
	'Plan',
2829
	$pconfig['providerplan'],
2830
	[]
2831
))->setHelp('Select to fill in service provider data.');
2832

    
2833
$section->addInput(new Form_Input(
2834
	'ppp_username',
2835
	'Username',
2836
	'text',
2837
	$pconfig['ppp_username'],
2838
	['autocomplete' => 'new-password']
2839
));
2840

    
2841
$section->addPassword(new Form_Input(
2842
	'ppp_password',
2843
	'Password',
2844
	'password',
2845
	$pconfig['ppp_password']
2846
));
2847

    
2848
$section->addInput(new Form_Input(
2849
	'phone',
2850
	'*Phone number',
2851
	'text',
2852
	$pconfig['phone']
2853
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2854

    
2855
$section->addInput(new Form_Input(
2856
	'apn',
2857
	'Access Point Name',
2858
	'text',
2859
	$pconfig['apn']
2860
));
2861

    
2862

    
2863
function build_port_list() {
2864
	$list = array("" => "None");
2865

    
2866
	$portlist = glob("/dev/cua*");
2867
	$modems	  = glob("/dev/modem*");
2868
	$portlist = array_merge($portlist, $modems);
2869

    
2870
	foreach ($portlist as $port) {
2871
		if (preg_match("/\.(lock|init)$/", $port)) {
2872
			continue;
2873
		}
2874

    
2875
	$list[trim($port)] = $port;
2876
	}
2877

    
2878
	return($list);
2879
}
2880

    
2881
$section->addInput(new Form_Select(
2882
	'port',
2883
	"*Modem port",
2884
	$pconfig['port'],
2885
	build_port_list()
2886
));
2887

    
2888
$section->addInput(new Form_Button(
2889
	'btnadvppp',
2890
	'Advanced PPP',
2891
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2892
	'fa-cog'
2893
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2894

    
2895
$form->add($section);
2896

    
2897
// PPPoE configuration
2898
$section = new Form_Section('PPPoE Configuration');
2899
$section->addClass('pppoe');
2900

    
2901
$section->addInput(new Form_Input(
2902
	'pppoe_username',
2903
	'*Username',
2904
	'text',
2905
	$pconfig['pppoe_username'],
2906
	['autocomplete' => 'new-password']
2907
));
2908

    
2909
$section->addPassword(new Form_Input(
2910
	'pppoe_password',
2911
	'*Password',
2912
	'password',
2913
	$pconfig['pppoe_password']
2914
));
2915

    
2916
$section->addInput(new Form_Input(
2917
	'provider',
2918
	'Service name',
2919
	'text',
2920
	$pconfig['provider']
2921
))->setHelp('This field can usually be left empty.');
2922

    
2923
$section->addInput(new Form_Input(
2924
	'hostuniq',
2925
	'Host-Uniq',
2926
	'text',
2927
	$pconfig['hostuniq']
2928
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2929

    
2930
$section->addInput(new Form_Checkbox(
2931
	'pppoe_dialondemand',
2932
	'Dial on demand',
2933
	'Enable Dial-On-Demand mode ',
2934
	$pconfig['pppoe_dialondemand'],
2935
	'enable'
2936
));
2937

    
2938
$section->addInput(new Form_Input(
2939
	'pppoe_idletimeout',
2940
	'Idle timeout',
2941
	'number',
2942
	$pconfig['pppoe_idletimeout'],
2943
	['min' => 0]
2944
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2945
			'An idle timeout of zero disables this feature.');
2946

    
2947
$section->addInput(new Form_Select(
2948
	'pppoe-reset-type',
2949
	'Periodic reset',
2950
	$pconfig['pppoe-reset-type'],
2951
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2952
))->setHelp('Select a reset timing type.');
2953

    
2954
$group = new Form_Group('Custom reset');
2955
$group->addClass('pppoecustom');
2956

    
2957
$group->add(new Form_Input(
2958
	'pppoe_resethour',
2959
	null,
2960
	'number',
2961
	(strlen($pconfig['pppoe_resethour']) > 0) ? $pconfig['pppoe_resethour'] : "0",
2962
	['min' => 0, 'max' => 23]
2963
))->setHelp('Hour (0-23), blank for * (every)');
2964

    
2965
$group->add(new Form_Input(
2966
	'pppoe_resetminute',
2967
	null,
2968
	'number',
2969
	(strlen($pconfig['pppoe_resetminute']) > 0) ? $pconfig['pppoe_resetminute'] : "0",
2970
	['min' => 0, 'max' => 59]
2971
))->setHelp('Minute (0-59), blank for * (every)');
2972

    
2973
$group->add(new Form_Input(
2974
	'pppoe_resetdate',
2975
	null,
2976
	'text',
2977
	$pconfig['pppoe_resetdate']
2978
))->setHelp('Specific date (mm/dd/yyyy)');
2979

    
2980
$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');
2981

    
2982
$section->add($group);
2983

    
2984
$group = new Form_MultiCheckboxGroup('cron based reset');
2985
$group->addClass('pppoepreset');
2986

    
2987
$group->add(new Form_MultiCheckbox(
2988
	'pppoe_pr_preset_val',
2989
	null,
2990
	'Reset at each month ("0 0 1 * *")',
2991
	$pconfig['pppoe_monthly'],
2992
	'monthly'
2993
))->displayAsRadio();
2994

    
2995
$group->add(new Form_MultiCheckbox(
2996
	'pppoe_pr_preset_val',
2997
	null,
2998
	'Reset at each week ("0 0 * * 0")',
2999
	$pconfig['pppoe_weekly'],
3000
	'weekly'
3001
))->displayAsRadio();
3002

    
3003
$group->add(new Form_MultiCheckbox(
3004
	'pppoe_pr_preset_val',
3005
	null,
3006
	'Reset at each day ("0 0 * * *")',
3007
	$pconfig['pppoe_daily'],
3008
	'daily'
3009
))->displayAsRadio();
3010

    
3011
$group->add(new Form_MultiCheckbox(
3012
	'pppoe_pr_preset_val',
3013
	null,
3014
	'Reset at each hour ("0 * * * *")',
3015
	$pconfig['pppoe_hourly'],
3016
	'hourly'
3017
))->displayAsRadio();
3018

    
3019
$section->add($group);
3020

    
3021
$section->addInput(new Form_Button(
3022
	'btnadvppp',
3023
	'Advanced and MLPPP',
3024
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3025
	'fa-cog'
3026
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3027

    
3028
$form->add($section);
3029

    
3030
// PPTP & L2TP Configuration section
3031
$section = new Form_Section('PPTP/L2TP Configuration');
3032
$section->addClass('pptp');
3033

    
3034
$section->addInput(new Form_Input(
3035
	'pptp_username',
3036
	'*Username',
3037
	'text',
3038
	$pconfig['pptp_username'],
3039
	['autocomplete' => 'new-password']
3040
));
3041

    
3042
$section->addPassword(new Form_Input(
3043
	'pptp_password',
3044
	'*Password',
3045
	'password',
3046
	$pconfig['pptp_password']
3047
));
3048

    
3049
$group = new Form_Group('Shared Secret');
3050

    
3051
$group->add(new Form_Input(
3052
	'l2tp_secret',
3053
	'*Secret',
3054
	'password',
3055
	$pconfig['l2tp_secret']
3056
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3057
	    'important control packet contents. (Optional)');
3058

    
3059
$group->addClass('l2tp_secret');
3060
$section->add($group);
3061

    
3062
$section->addInput(new Form_IpAddress(
3063
	'pptp_local0',
3064
	'*Local IP address',
3065
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3066
	'V4'
3067
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3068

    
3069
$section->addInput(new Form_IpAddress(
3070
	'pptp_remote0',
3071
	'*Remote IP address',
3072
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3073
	'HOSTV4'
3074
));
3075

    
3076
$section->addInput(new Form_Checkbox(
3077
	'pptp_dialondemand',
3078
	'Dial on demand',
3079
	'Enable Dial-On-Demand mode ',
3080
	$pconfig['pptp_dialondemand'],
3081
	'enable'
3082
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3083
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3084

    
3085
$section->addInput(new Form_Input(
3086
	'pptp_idletimeout',
3087
	'Idle timeout (seconds)',
3088
	'number',
3089
	$pconfig['pptp_idletimeout'],
3090
	['min' => 0]
3091
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3092
			'An idle timeout of zero disables this feature.');
3093

    
3094
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3095
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3096
} else {
3097
	$mlppp_text = "";
3098
}
3099

    
3100
$section->addInput(new Form_Button(
3101
	'btnadvppp',
3102
	'Advanced and MLPPP',
3103
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3104
	'fa-cog'
3105
))->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);
3106

    
3107
$form->add($section);
3108

    
3109
// Wireless interface
3110
if (isset($wancfg['wireless'])) {
3111

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

    
3114
	$section->addInput(new Form_Checkbox(
3115
		'persistcommonwireless',
3116
		'Persist common settings',
3117
		'Preserve common wireless configuration through interface deletions and reassignments.',
3118
		$pconfig['persistcommonwireless'],
3119
		'yes'
3120
	));
3121

    
3122
	$mode_list = ['auto' => 'Auto'];
3123

    
3124
	if (is_array($wl_modes)) {
3125
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3126
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3127
		}
3128
	}
3129

    
3130
	if (count($mode_list) == 1) {
3131
		$mode_list[''] = '';
3132
	}
3133

    
3134
	$section->addInput(new Form_Select(
3135
		'standard',
3136
		'Standard',
3137
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3138
		$mode_list
3139
	));
3140

    
3141
	if (isset($wl_modes['11g'])) {
3142
		$section->addInput(new Form_Select(
3143
			'protmode',
3144
			'802.11g OFDM Protection Mode',
3145
			$pconfig['protmode'],
3146
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3147
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3148
	} else {
3149
		$form->addGlobal(new Form_Input(
3150
			'protmode',
3151
			null,
3152
			'hidden',
3153
			'off'
3154
		));
3155
	}
3156

    
3157
	$mode_list = ['0' => gettext('Auto')];
3158

    
3159
	if (is_array($wl_modes)) {
3160
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3161
			if ($wl_standard == "11g") {
3162
				$wl_standard = "11b/g";
3163
			} else if ($wl_standard == "11ng") {
3164
				$wl_standard = "11b/g/n";
3165
			} else if ($wl_standard == "11na") {
3166
				$wl_standard = "11a/n";
3167
			}
3168

    
3169
			foreach ($wl_channels as $wl_channel) {
3170
				if (isset($wl_chaninfo[$wl_channel])) {
3171
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3172
				} else {
3173
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3174
				}
3175
			}
3176
		}
3177
	}
3178

    
3179
	$section->addInput(new Form_Select(
3180
		'channel',
3181
		'Channel',
3182
		$pconfig['channel'],
3183
		$mode_list
3184
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3185
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3186

    
3187
	$section->addInput(new Form_Select(
3188
		'channel_width',
3189
		'Channel width',
3190
		$pconfig['channel_width'],
3191
		$wl_ht_modes
3192
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3193

    
3194
	if (ANTENNAS) {
3195
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3196
			$group = new Form_Group('Antenna Settings');
3197

    
3198
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3199
				$group->add(new Form_Select(
3200
					'diversity',
3201
					null,
3202
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3203
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3204
				))->setHelp('Diversity');
3205
			}
3206

    
3207
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3208
				$group->add(new Form_Select(
3209
					'txantenna',
3210
					null,
3211
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3212
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3213
				))->setHelp('Transmit antenna');
3214
			}
3215

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

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

    
3227
			$section->add($group);
3228
		}
3229
	}
3230

    
3231
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3232
			$section->addInput(new Form_Input(
3233
				'distance',
3234
				'Distance setting (meters)',
3235
				'test',
3236
				$pconfig['distance']
3237
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3238
	}
3239

    
3240
	$form->add($section);
3241

    
3242
	// Regulatory settings
3243
	$section = new Form_Section('Regulatory Settings');
3244

    
3245
	$domain_list = array("" => 'Default');
3246

    
3247
	if (is_array($wl_regdomains)) {
3248
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3249
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3250
		}
3251
	}
3252

    
3253
	$section->addInput(new Form_Select(
3254
		'regdomain',
3255
		'Regulatory domain',
3256
		$pconfig['regdomain'],
3257
		$domain_list
3258
	))->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');
3259

    
3260
	$country_list = array('' => 'Default');
3261

    
3262
	if (is_array($wl_countries)) {
3263
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3264
			$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']);
3265
		}
3266
	}
3267

    
3268
	$section->addInput(new Form_Select(
3269
		'regcountry',
3270
		'Country',
3271
		$pconfig['regcountry'],
3272
		$country_list
3273
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3274

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

    
3286
	$form->add($section);
3287

    
3288
	$section = new Form_Section('Network-Specific Wireless Configuration');
3289

    
3290
	$section->addInput(new Form_Select(
3291
		'mode',
3292
		'Mode',
3293
		$pconfig['mode'],
3294
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3295
	));
3296

    
3297
	$section->addInput(new Form_Input(
3298
		'ssid',
3299
		'SSID',
3300
		'text',
3301
		$pconfig['ssid']
3302
	));
3303

    
3304
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3305
		$section->addInput(new Form_Select(
3306
			'puremode',
3307
			'Minimum wireless standard',
3308
			$pconfig['puremode'],
3309
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3310
		))->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)');
3311
	} elseif (isset($wl_modes['11g'])) {
3312
		$section->addInput(new Form_Checkbox(
3313
			'puremode',
3314
			'802.11g only',
3315
			null,
3316
			$pconfig['puremode'],
3317
			'11g'
3318
		))->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)');
3319
	}
3320

    
3321
	$section->addInput(new Form_Checkbox(
3322
		'apbridge_enable',
3323
		'Allow intra-BSS communication',
3324
		'Allow packets to pass between wireless clients directly when operating as an access point',
3325
		$pconfig['apbridge_enable'],
3326
		'yes'
3327
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3328

    
3329
	$section->addInput(new Form_Checkbox(
3330
		'wme_enable',
3331
		'Enable WME',
3332
		'Force the card to use WME (wireless QoS)',
3333
		$pconfig['wme_enable'],
3334
		'yes'
3335
	));
3336

    
3337
	$section->addInput(new Form_Checkbox(
3338
		'hidessid_enable',
3339
		'Hide SSID',
3340
		'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.)',
3341
		$pconfig['hidessid_enable'],
3342
		'yes'
3343
	));
3344

    
3345
	$form->add($section);
3346

    
3347
	// WPA Section
3348
	$section = new Form_Section('WPA');
3349

    
3350
	$section->addInput(new Form_Checkbox(
3351
		'wpa_enable',
3352
		'Enable',
3353
		'Enable WPA',
3354
		$pconfig['wpa_enable'],
3355
		'yes'
3356
	));
3357

    
3358
	$section->addInput(new Form_Select(
3359
		'wpa_mode',
3360
		'WPA mode',
3361
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3362
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3363
	));
3364

    
3365
	$section->addInput(new Form_Select(
3366
		'wpa_pairwise',
3367
		'WPA Pairwise',
3368
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3369
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3370
	));
3371

    
3372
	$section->addInput(new Form_Select(
3373
		'wpa_key_mgmt',
3374
		'WPA Key Management Mode',
3375
		$pconfig['wpa_key_mgmt'],
3376
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3377
	));
3378

    
3379
	$section->addInput(new Form_Input(
3380
		'passphrase',
3381
		'WPA Pre-Shared Key',
3382
		'text',
3383
		$pconfig['passphrase']
3384
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3385

    
3386
	$section->addInput(new Form_Select(
3387
		'wpa_eap_client_mode',
3388
		'EAP Client Mode',
3389
		$pconfig['wpa_eap_client_mode'],
3390
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3391
	));
3392

    
3393
	$section->addInput(new Form_Select(
3394
		'wpa_eap_ca',
3395
		'Certificate Authority',
3396
		$pconfig['wpa_eap_ca'],
3397
		cert_build_list('ca', 'HTTPS')
3398
	));
3399

    
3400
	$section->addInput(new Form_Select(
3401
		'wpa_eap_inner_auth',
3402
		'Inner Authentication Method',
3403
		$pconfig['wpa_eap_inner_auth'],
3404
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3405
	));
3406

    
3407
	$section->addInput(new Form_Input(
3408
		'wpa_eap_inner_id',
3409
		'*Inner Authentication Identity',
3410
		'text',
3411
		$pconfig['wpa_eap_inner_id']
3412
	));
3413

    
3414
	$section->addInput(new Form_Input(
3415
		'wpa_eap_inner_password',
3416
		'*Inner Authentication Passphrase',
3417
		'text',
3418
		$pconfig['wpa_eap_inner_password']
3419
	));
3420

    
3421
	$section->addInput(new Form_Select(
3422
		'wpa_eap_cert',
3423
		'TLS/TTLS Client Certificate',
3424
		$pconfig['wpa_eap_cert'],
3425
		cert_build_list('cert', 'HTTPS')
3426
	));
3427

    
3428
	$section->addInput(new Form_Input(
3429
		'wpa_group_rekey',
3430
		'Group Key Rotation',
3431
		'number',
3432
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3433
		['min' => '1', 'max' => 9999]
3434
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3435

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

    
3444
	$section->addInput(new Form_Checkbox(
3445
		'wpa_strict_rekey',
3446
		'Strict Key Regeneration',
3447
		'Force the AP to rekey whenever a client disassociates',
3448
		$pconfig['wpa_strict_rekey'],
3449
		'yes'
3450
	));
3451

    
3452
	$form->add($section);
3453

    
3454
	$section = new Form_Section('802.1x RADIUS Options');
3455
	$section->addClass('ieee8021x_group');
3456

    
3457
	$section->addInput(new Form_Checkbox(
3458
		'ieee8021x',
3459
		'IEEE802.1X',
3460
		'Enable 802.1X authentication',
3461
		$pconfig['ieee8021x'],
3462
		'yes'
3463
	));
3464

    
3465
	$group = new Form_Group('Primary 802.1X server');
3466

    
3467
	$group->add(new Form_IpAddress(
3468
		'auth_server_addr',
3469
		'IP Address',
3470
		$pconfig['auth_server_addr']
3471
	))->setHelp('IP address of the RADIUS server');
3472

    
3473
	$group->add(new Form_Input(
3474
		'auth_server_port',
3475
		'Port',
3476
		'number',
3477
		$pconfig['auth_server_port']
3478
	))->setHelp('Server auth port. Default is 1812');
3479

    
3480
	$group->add(new Form_Input(
3481
		'auth_server_shared_secret',
3482
		'Shared Secret',
3483
		'text',
3484
		$pconfig['auth_server_shared_secret']
3485
	))->setHelp('RADIUS Shared secret for this firewall');
3486

    
3487
	$section->add($group);
3488

    
3489
	$group = new Form_Group('Secondary 802.1X server');
3490

    
3491
	$group->add(new Form_IpAddress(
3492
		'auth_server_addr2',
3493
		'IP Address',
3494
		$pconfig['auth_server_addr2']
3495
	))->setHelp('IP address of the RADIUS server');
3496

    
3497
	$group->add(new Form_Input(
3498
		'auth_server_port2',
3499
		'Port',
3500
		'number',
3501
		$pconfig['auth_server_port2']
3502
	))->setHelp('Server auth port. Default is 1812');
3503

    
3504
	$group->add(new Form_Input(
3505
		'auth_server_shared_secret2',
3506
		'Shared Secret',
3507
		'text',
3508
		$pconfig['auth_server_shared_secret2']
3509
	))->setHelp('RADIUS Shared secret for this firewall');
3510

    
3511
	$section->add($group);
3512

    
3513
	$section->addInput(new Form_Checkbox(
3514
		'rsn_preauth',
3515
		'Authentication Roaming Preauth',
3516
		null,
3517
		$pconfig['rsn_preauth'],
3518
		'yes'
3519
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3520

    
3521
	$form->add($section);
3522
}
3523

    
3524
$section = new Form_Section('Reserved Networks');
3525

    
3526
$section->addInput(new Form_Checkbox(
3527
	'blockpriv',
3528
	'Block private networks and loopback addresses',
3529
	'',
3530
	$pconfig['blockpriv'],
3531
	'yes'
3532
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3533
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3534
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3535

    
3536
$section->addInput(new Form_Checkbox(
3537
	'blockbogons',
3538
	'Block bogon networks',
3539
	'',
3540
	$pconfig['blockbogons'],
3541
	'yes'
3542
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3543
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3544
			'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' .
3545
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3546

    
3547
$form->add($section);
3548

    
3549
$form->addGlobal(new Form_Input(
3550
	'if',
3551
	null,
3552
	'hidden',
3553
	$if
3554
));
3555

    
3556
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3557
	$form->addGlobal(new Form_Input(
3558
		'ppp_port',
3559
		null,
3560
		'hidden',
3561
		$pconfig['port']
3562
	));
3563
}
3564

    
3565
$form->addGlobal(new Form_Input(
3566
	'ptpid',
3567
	null,
3568
	'hidden',
3569
	$pconfig['ptpid']
3570
));
3571

    
3572

    
3573
// Add new gateway modal pop-up
3574
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3575

    
3576
$modal->addInput(new Form_Checkbox(
3577
	'defaultgw4',
3578
	'Default',
3579
	'Default gateway',
3580
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3581
));
3582

    
3583
$modal->addInput(new Form_Input(
3584
	'gatewayname4',
3585
	'Gateway name',
3586
	'text',
3587
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3588
));
3589

    
3590
$modal->addInput(new Form_IpAddress(
3591
	'gatewayip4',
3592
	'Gateway IPv4',
3593
	$gateway_settings4['gateway'],
3594
	'V4'
3595
));
3596

    
3597
$modal->addInput(new Form_Input(
3598
	'gatewaydescr4',
3599
	'Description',
3600
	'text',
3601
	$gateway_settings4['descr']
3602
));
3603

    
3604
$btnaddgw4 = new Form_Button(
3605
	'add4',
3606
	'Add',
3607
	null,
3608
	'fa-plus'
3609
);
3610

    
3611
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3612

    
3613
$btncnxgw4 = new Form_Button(
3614
	'cnx4',
3615
	'Cancel',
3616
	null,
3617
	'fa-undo'
3618
);
3619

    
3620
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3621

    
3622
$modal->addInput(new Form_StaticText(
3623
	null,
3624
	$btnaddgw4 . $btncnxgw4
3625
));
3626

    
3627
$form->add($modal);
3628

    
3629
print($form);
3630
?>
3631

    
3632
<script type="text/javascript">
3633
//<![CDATA[
3634
events.push(function() {
3635
	function updateType(t) {
3636

    
3637
		switch (t) {
3638
			case "none": {
3639
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3640
				break;
3641
			}
3642
			case "staticv4": {
3643
				$('.dhcpadvanced, .none, .dhcp').hide();
3644
				$('.pppoe, .pptp, .ppp').hide();
3645
				break;
3646
			}
3647
			case "dhcp": {
3648
				$('.dhcpadvanced, .none').hide();
3649
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3650
										//			about the staticv4 class
3651
				$('.pppoe, .pptp, .ppp').hide();
3652
				break;
3653
			}
3654
			case "ppp": {
3655
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3656
				country_list();
3657
				break;
3658
			}
3659
			case "pppoe": {
3660
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3661
				break;
3662
			}
3663
			case "l2tp": {
3664
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3665
				$('.pptp, .l2tp_secret').show();
3666
				break;
3667
			}
3668
			case "pptp": {
3669
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3670
				$('.pptp').show();
3671
				break;
3672
			}
3673
		}
3674

    
3675
		if (t != "l2tp" && t != "pptp") {
3676
			$('.'+t).show();
3677
		}
3678
	}
3679

    
3680
	function updateTypeSix(t) {
3681
		if (!isNaN(t[0])) {
3682
			t = '_' + t;
3683
		}
3684

    
3685
		switch (t) {
3686
			case "none": {
3687
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3688
				break;
3689
			}
3690
			case "staticv6": {
3691
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3692
				break;
3693
			}
3694
			case "slaac": {
3695
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3696
				break;
3697
			}
3698
			case "dhcp6": {
3699
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3700
				break;
3701
			}
3702
			case "_6rd": {
3703
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3704
				break;
3705
			}
3706
			case "_6to4": {
3707
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3708
				break;
3709
			}
3710
			case "track6": {
3711
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3712
				update_track6_prefix();
3713
				break;
3714
			}
3715
		}
3716

    
3717
		if (t != "l2tp" && t != "pptp") {
3718
			$('.'+t).show();
3719
		}
3720
	}
3721

    
3722
	function show_reset_settings(reset_type) {
3723
		if (reset_type == 'preset') {
3724
			$('.pppoepreset').show();
3725
			$('.pppoecustom').hide();
3726
		} else if (reset_type == 'custom') {
3727
			$('.pppoecustom').show();
3728
			$('.pppoepreset').hide();
3729
		} else {
3730
			$('.pppoecustom').hide();
3731
			$('.pppoepreset').hide();
3732
		}
3733
	}
3734

    
3735
	function update_track6_prefix() {
3736
		var iface = $("#track6-interface").val();
3737
		if (iface == null) {
3738
			return;
3739
		}
3740

    
3741
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3742
		if (track6_prefix_ids == null) {
3743
			return;
3744
		}
3745

    
3746
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3747
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3748
	}
3749

    
3750
	function addOption_v4() {
3751
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3752
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3753
	}
3754

    
3755
	function addOption_v6() {
3756
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3757
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3758
	}
3759

    
3760
	function addSelectboxOption(selectbox, text, value) {
3761
		var optn = document.createElement("OPTION");
3762
		optn.text = text;
3763
		optn.value = value;
3764
		selectbox.append(optn);
3765
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3766
	}
3767

    
3768
	function country_list() {
3769
		$('#country').children().remove();
3770
		$('#provider_list').children().remove();
3771
		$('#providerplan').children().remove();
3772
		$.ajax("getserviceproviders.php",{
3773
			success: function(response) {
3774

    
3775
				var responseTextArr = response.split("\n");
3776
				responseTextArr.sort();
3777

    
3778
				responseTextArr.forEach( function(value) {
3779
					country = value.split(":");
3780
					$('#country').append($('<option>', {
3781
						value: country[1],
3782
						text : country[0]
3783
					}));
3784
				});
3785
			}
3786
		});
3787
	}
3788

    
3789
	function providers_list() {
3790
		$('#provider_list').children().remove();
3791
		$('#providerplan').children().remove();
3792
		$.ajax("getserviceproviders.php",{
3793
			type: 'post',
3794
			data: {country : $('#country').val()},
3795
			success: function(response) {
3796
				var responseTextArr = response.split("\n");
3797
				responseTextArr.sort();
3798
				responseTextArr.forEach( function(value) {
3799
					$('#provider_list').append($('<option>', {
3800
							value: value,
3801
							text : value
3802
					}));
3803
				});
3804
			}
3805
		});
3806
	}
3807

    
3808
	function providerplan_list() {
3809
		$('#providerplan').children().remove();
3810
		$.ajax("getserviceproviders.php",{
3811
			type: 'post',
3812
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3813
			success: function(response) {
3814
				var responseTextArr = response.split("\n");
3815
				responseTextArr.sort();
3816

    
3817
				$('#providerplan').append($('<option>', {
3818
					value: '',
3819
					text : ''
3820
				}));
3821

    
3822
				responseTextArr.forEach( function(value) {
3823
					if (value != "") {
3824
						providerplan = value.split(":");
3825

    
3826
						$('#providerplan').append($('<option>', {
3827
							value: providerplan[1],
3828
							text : providerplan[0] + " - " + providerplan[1]
3829
						}));
3830
					}
3831
				});
3832
			}
3833
		});
3834
	}
3835

    
3836
	function prefill_provider() {
3837
		$.ajax("getserviceproviders.php",{
3838
			type: 'post',
3839
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3840
			success: function(data, textStatus, response) {
3841
				var xmldoc = response.responseXML;
3842
				var provider = xmldoc.getElementsByTagName('connection')[0];
3843
				$('#ppp_username').val('');
3844
				$('#ppp_password').val('');
3845
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3846
					$('#phone').val('#777');
3847
					$('#apn').val('');
3848
				} else {
3849
					$('#phone').val('*99#');
3850
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3851
				}
3852
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3853
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3854
				$('#ppp_username').val(ppp_username);
3855
				$('#ppp_password').val(ppp_password);
3856
			}
3857
		});
3858
	}
3859

    
3860
	function show_dhcp6adv() {
3861
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3862
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3863

    
3864
		hideCheckbox('dhcp6usev4iface', ovr);
3865
		hideCheckbox('dhcp6prefixonly', ovr);
3866
		hideInput('dhcp6-ia-pd-len', ovr);
3867
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3868
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3869

    
3870
		hideClass('dhcp6advanced', !adv || ovr);
3871
	}
3872

    
3873
	function setDHCPoptions() {
3874
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3875
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3876

    
3877
		if (ovr) {
3878
			hideInput('dhcphostname', true);
3879
			hideIpAddress('alias-address', true);
3880
			hideInput('dhcprejectfrom', true);
3881
			hideInput('adv_dhcp_config_file_override_path', false);
3882
			hideClass('dhcpadvanced', true);
3883
		} else {
3884
			hideInput('dhcphostname', false);
3885
			hideIpAddress('alias-address', false);
3886
			hideInput('dhcprejectfrom', false);
3887
			hideInput('adv_dhcp_config_file_override_path', true);
3888
			hideClass('dhcpadvanced', !adv);
3889
		}
3890
	}
3891

    
3892
	// DHCP preset actions
3893
	// Set presets from value of radio buttons
3894
	function setPresets(val) {
3895
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3896
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3897
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3898
		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']);?>");
3899
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3900
	}
3901

    
3902
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3903
		$('#adv_dhcp_pt_timeout').val(timeout);
3904
		$('#adv_dhcp_pt_retry').val(retry);
3905
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3906
		$('#adv_dhcp_pt_reboot').val(reboot);
3907
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3908
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3909
	}
3910

    
3911
	function setPPPoEDialOnDemandItems() {
3912
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3913
	}
3914

    
3915
	function setPPTPDialOnDemandItems() {
3916
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3917
	}
3918

    
3919
	function show_wpaoptions() {
3920
		var wpa = !($('#wpa_enable').prop('checked'));
3921

    
3922
		hideInput('passphrase', wpa);
3923
		hideInput('wpa_mode', wpa);
3924
		hideInput('wpa_key_mgmt', wpa);
3925
		hideInput('wpa_pairwise', wpa);
3926
		hideCheckbox('wpa_strict_rekey', wpa);
3927
		hideClass('ieee8021x_group', true);
3928
		if ($('#mode').val() == 'hostap') {
3929
			hideInput('wpa_group_rekey', wpa);
3930
			hideInput('wpa_gmk_rekey', wpa);
3931
			hideCheckbox('wpa_strict_rekey', wpa);
3932
		} else {
3933
			hideInput('wpa_group_rekey', true);
3934
			hideInput('wpa_gmk_rekey', true);
3935
			hideCheckbox('wpa_strict_rekey', true);
3936
		}
3937
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3938
	}
3939

    
3940
	function updatewifistandard(s) {
3941
		switch (s) {
3942
			case "auto": {
3943
				hideInput('protmode', false);
3944
				hideInput('channel_width', false);
3945
				break;
3946
			}
3947
			case "11b": {
3948
				hideInput('protmode', true);
3949
				hideInput('channel_width', true);
3950
				break;
3951
			}
3952
			case "11g": {
3953
				hideInput('protmode', false);
3954
				hideInput('channel_width', true);
3955
				break;
3956
			}
3957
			case "11ng": {
3958
				hideInput('protmode', false);
3959
				hideInput('channel_width', false);
3960
				break;
3961
			}
3962
			case "11a": {
3963
				hideInput('protmode', true);
3964
				hideInput('channel_width', true);
3965
				break;
3966
			}
3967
			case "11na": {
3968
				hideInput('protmode', true);
3969
				hideInput('channel_width', false);
3970
				break;
3971
			}
3972
			default: {
3973
				break;
3974
			}
3975
		}
3976
	}
3977

    
3978
	function updatewifimode(m) {
3979
		switch (m) {
3980
			case "adhoc": {
3981
				hideInput('puremode', true);
3982
				hideCheckbox('apbridge_enable', true);
3983
				hideCheckbox('hidessid_enable', false);
3984
				break;
3985
			}
3986
			case "hostap": {
3987
				hideInput('puremode', false);
3988
				hideCheckbox('apbridge_enable', false);
3989
				hideCheckbox('hidessid_enable', false);
3990
				break;
3991
			}
3992
			default: {
3993
				hideInput('puremode', true);
3994
				hideCheckbox('apbridge_enable', true);
3995
				hideCheckbox('hidessid_enable', true);
3996
				break;
3997
			}
3998
		}
3999
		show_wpaoptions();
4000
		updateeapclientmode($('#wpa_eap_client_mode').val());
4001
		updatewpakeymgmt($('#wpa_key_mgmt').val());
4002
	}
4003

    
4004
	function updateeapclientmode(m) {
4005
		if ($('#mode').val() == 'bss') {
4006
			var wpa = !($('#wpa_enable').prop('checked'));
4007
		} else {
4008
			var wpa = true;
4009
		}
4010
		switch (m) {
4011
			case "PEAP": {
4012
				hideInput('wpa_eap_cert', true);
4013
				hideInput('wpa_eap_inner_auth', wpa);
4014
				hideInput('wpa_eap_inner_id', wpa);
4015
				hideInput('wpa_eap_inner_password', wpa);
4016
				break;
4017
			}
4018
			case "TLS": {
4019
				hideInput('wpa_eap_cert', wpa);
4020
				hideInput('wpa_eap_inner_auth', true);
4021
				hideInput('wpa_eap_inner_id', true);
4022
				hideInput('wpa_eap_inner_password', true);
4023
				break;
4024
			}
4025
			case "TTLS": {
4026
				hideInput('wpa_eap_cert', wpa);
4027
				hideInput('wpa_eap_inner_auth', wpa);
4028
				hideInput('wpa_eap_inner_id', wpa);
4029
				hideInput('wpa_eap_inner_password', wpa);
4030
				break;
4031
			}
4032
			default: {
4033
				break;
4034
			}
4035
		}
4036
	}
4037

    
4038
	function updatewpakeymgmt(m) {
4039
		hideInput('passphrase', false);
4040
		hideInput('wpa_eap_client_mode', true);
4041
		hideInput('wpa_eap_ca', true);
4042
		hideInput('wpa_eap_cert', true);
4043
		hideInput('wpa_eap_inner_auth', true);
4044
		hideInput('wpa_eap_inner_id', true);
4045
		hideInput('wpa_eap_inner_password', true);
4046
		hideClass('ieee8021x_group', true);
4047
		if (m == "WPA-EAP") {
4048
			hideInput('passphrase', true);
4049
			if ($('#mode').val() == 'bss') {
4050
				hideInput('wpa_eap_client_mode', false);
4051
				hideInput('wpa_eap_ca', false);
4052
				updateeapclientmode($('#wpa_eap_client_mode').val());
4053
			} else if ($('#mode').val() == 'hostap') {
4054
				hideClass('ieee8021x_group', false);
4055
			}
4056
		} else if (m != "WPA-PSK") {
4057
			hideInput('passphrase', false);
4058
			if ($('#mode').val() == 'bss') {
4059
				hideInput('wpa_eap_client_mode', false);
4060
				hideInput('wpa_eap_ca', false);
4061
				hideInput('wpa_eap_cert', false);
4062
				hideInput('wpa_eap_inner_auth', false);
4063
				hideInput('wpa_eap_inner_id', false);
4064
				hideInput('wpa_eap_inner_password', false);
4065
			} else if ($('#mode').val() == 'hostap') {
4066
				hideClass('ieee8021x_group', false);
4067
			}
4068
		}
4069
	}
4070

    
4071
	// ---------- On initial page load ------------------------------------------------------------
4072

    
4073
	updateType($('#type').val());
4074
	updateTypeSix($('#type6').val());
4075
	show_reset_settings($('#pppoe-reset-type').val());
4076
	hideClass('dhcp6advanced', true);
4077
	hideClass('dhcpadvanced', true);
4078
	show_dhcp6adv();
4079
	setDHCPoptions();
4080
	setPPPoEDialOnDemandItems();
4081
	setPPTPDialOnDemandItems();
4082
	show_wpaoptions();
4083
	updatewifistandard($('#standard').val());
4084
	updatewifimode($('#mode').val());
4085

    
4086
	// Set preset buttons on page load
4087
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4088
	if (sv == "") {
4089
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4090
	} else {
4091
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4092
	}
4093

    
4094
	// Set preset from value
4095
	setPresets(sv);
4096

    
4097
	// If the user wants to add a gateway, then add that to the gateway selection
4098
	if ($("#gatewayip4").val() != '') {
4099
		addOption_v4();
4100
	}
4101
	if ($("#gatewayip6").val() != '') {
4102
		addOption_v6();
4103
	}
4104

    
4105
	// ---------- Click checkbox handlers ---------------------------------------------------------
4106

    
4107
	$('#type').on('change', function() {
4108
		updateType(this.value);
4109
	});
4110

    
4111
	$('#type6').on('change', function() {
4112
		updateTypeSix(this.value);
4113
	});
4114

    
4115
	$('#standard').on('change', function() {
4116
		updatewifistandard(this.value);
4117
	});
4118

    
4119
	$('#mode').on('change', function() {
4120
		updatewifimode(this.value);
4121
	});
4122

    
4123
	$('#wpa_key_mgmt').on('change', function() {
4124
		updatewpakeymgmt(this.value);
4125
	});
4126

    
4127
	$('#wpa_eap_client_mode').on('change', function() {
4128
		updateeapclientmode(this.value);
4129
	});
4130

    
4131
	$('#track6-interface').on('change', function() {
4132
		update_track6_prefix();
4133
	});
4134

    
4135
	$('#pppoe-reset-type').on('change', function() {
4136
		show_reset_settings(this.value);
4137
	});
4138

    
4139
	$("#add4").click(function() {
4140
		addOption_v4();
4141
		$("#newgateway4").modal('hide');
4142
	});
4143

    
4144
	$("#cnx4").click(function() {
4145
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4146
		$("#gatewayip4").val('');
4147
		$("#gatewaydescr4").val('');
4148
		$("#defaultgw4").prop("checked", false);
4149
		$("#newgateway4").modal('hide');
4150
	});
4151

    
4152
	$("#add6").click(function() {
4153
		addOption_v6();
4154
		$("#newgateway6").modal('hide');
4155
	});
4156

    
4157
	$("#cnx6").click(function() {
4158
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4159
		$("#gatewayip6").val('');
4160
		$("#gatewaydescr6").val('');
4161
		$("#defaultgw6").prop("checked", false);
4162
		$("#newgateway6").modal('hide');
4163
	});
4164

    
4165
	$('#country').on('change', function() {
4166
		providers_list();
4167
	});
4168

    
4169
	$('#provider_list').on('change', function() {
4170
		providerplan_list();
4171
	});
4172

    
4173
	$('#providerplan').on('change', function() {
4174
		prefill_provider();
4175
	});
4176

    
4177
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4178
		setDHCPoptions();
4179
	});
4180

    
4181
	$('#adv_dhcp6_config_advanced').click(function () {
4182
		show_dhcp6adv();
4183
	});
4184

    
4185
	$('#adv_dhcp6_config_file_override').click(function () {
4186
		show_dhcp6adv();
4187
	});
4188

    
4189
	// On click . .
4190
	$('#pppoe_dialondemand').click(function () {
4191
		setPPPoEDialOnDemandItems();
4192
	});
4193

    
4194
	$('#pptp_dialondemand').click(function () {
4195
		setPPTPDialOnDemandItems();
4196
	});
4197

    
4198
	$('[name=adv_dhcp_pt_values]').click(function () {
4199
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4200
	});
4201

    
4202
	$('#wpa_enable').click(function () {
4203
		show_wpaoptions();
4204
	});
4205

    
4206
	$('#pppoe_resetdate').datepicker();
4207

    
4208
});
4209
//]]>
4210
</script>
4211

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