Project

General

Profile

Download (141 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-2022 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

    
62
$if = "wan";
63

    
64
if ($_REQUEST['if']) {
65
	$if = $_REQUEST['if'];
66
}
67

    
68
if (empty($ifdescrs[$if])) {
69
	header("Location: interfaces.php");
70
	exit;
71
}
72

    
73
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
74
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
75
define("CRON_DAILY_PATTERN", "0 0 * * *");
76
define("CRON_HOURLY_PATTERN", "0 * * * *");
77

    
78
if (!is_array($pconfig)) {
79
	$pconfig = array();
80
}
81

    
82
init_config_arr(array('ppps', 'ppp'));
83
$a_ppps = &$config['ppps']['ppp'];
84

    
85
init_config_arr(array('gateways', 'gateway_item'));
86
$a_gateways = &$config['gateways']['gateway_item'];
87

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

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

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

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

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

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

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

    
142
		/* ================================================ */
143
		/* = force a connection reset at a specific time? = */
144
		/* ================================================ */
145

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

    
203
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
204
$pconfig['alias-address'] = $wancfg['alias-address'];
205
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
206
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
207

    
208
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
209
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
210
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
211
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
212
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
213
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
214

    
215
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
216

    
217
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
218
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
219
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
220
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
221

    
222
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
223
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
224
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
225

    
226
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
227
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
228
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
229
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
230

    
231
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
232
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
233
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
234
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
235
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
236

    
237
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
238
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
239
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
240
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
241
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
242

    
243
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
244
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
245
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
246

    
247
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
248
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
249
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
250
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
251

    
252
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
253
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
254
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
255
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
256
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
257

    
258
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
259
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
260
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
261

    
262
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
263
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
264
$pconfig['enable'] = isset($wancfg['enable']);
265

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

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

    
346
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
347
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
348
$pconfig['spoofmac'] = $wancfg['spoofmac'];
349
$pconfig['mtu'] = $wancfg['mtu'];
350
$pconfig['mss'] = $wancfg['mss'];
351

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

    
437
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
438

    
439
}
440

    
441
$changes_applied = false;
442

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

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

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

    
493
		/* sync filter configuration */
494
		setup_gateways_monitor();
495

    
496
		clear_subsystem_dirty('interfaces');
497

    
498
		$retval |= filter_configure();
499

    
500
		enable_rrd_graphing();
501

    
502
		$changes_applied = true;
503

    
504
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
505
			clear_subsystem_dirty('staticroutes');
506
		}
507

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

    
513
	unset($input_errors);
514
	$pconfig = $_POST;
515

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

    
522
	/* filter out spaces from descriptions */
523
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
524

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

    
539
	/* input validation */
540
	$reqdfields = explode(" ", "descr");
541
	$reqdfieldsn = array(gettext("Description"));
542
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
543

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
935
		unset($min_mtu, $max_mtu);
936

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

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

    
959
				if ($parent_realhwif != $wancfg['if']) {
960
					continue;
961
				}
962

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

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

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

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

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

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

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

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

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

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

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

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

    
1175
		unset($wancfg['dhcpvlanenable']);
1176
		unset($wancfg['dhcpcvpt']);
1177

    
1178
		unset($wancfg['adv_dhcp_pt_timeout']);
1179
		unset($wancfg['adv_dhcp_pt_retry']);
1180
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1181
		unset($wancfg['adv_dhcp_pt_reboot']);
1182
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1183
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1184

    
1185
		unset($wancfg['adv_dhcp_pt_values']);
1186

    
1187
		unset($wancfg['adv_dhcp_send_options']);
1188
		unset($wancfg['adv_dhcp_request_options']);
1189
		unset($wancfg['adv_dhcp_required_options']);
1190
		unset($wancfg['adv_dhcp_option_modifiers']);
1191

    
1192
		unset($wancfg['adv_dhcp_config_advanced']);
1193
		unset($wancfg['adv_dhcp_config_file_override']);
1194
		unset($wancfg['adv_dhcp_config_file_override_path']);
1195

    
1196
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1197
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1198
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1199
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1200

    
1201
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1202
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1203
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1204
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1205
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1206

    
1207
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1208
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1209
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1210
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1211
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1212

    
1213
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1214
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1215
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1216

    
1217
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1218
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1219
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1220
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1221

    
1222
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1223
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1224
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1225
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1226
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1227

    
1228
		unset($wancfg['adv_dhcp6_config_advanced']);
1229
		unset($wancfg['adv_dhcp6_config_file_override']);
1230
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1231

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

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

    
1267
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1268
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1269

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

    
1286
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1287
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1288
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1289
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1290
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1291
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1292

    
1293
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1294

    
1295
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1296
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1297
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1298
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1299

    
1300
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1301
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1302
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1303

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

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

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

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

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

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

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

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

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

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

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

    
1582
		if ($_POST['blockpriv'] == "yes") {
1583
			$wancfg['blockpriv'] = true;
1584
		} else {
1585
			unset($wancfg['blockpriv']);
1586
		}
1587
		if ($_POST['blockbogons'] == "yes") {
1588
			$wancfg['blockbogons'] = true;
1589
		} else {
1590
			unset($wancfg['blockbogons']);
1591
		}
1592
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1593
		if (empty($_POST['mtu'])) {
1594
			unset($wancfg['mtu']);
1595
		} else {
1596
			$wancfg['mtu'] = $_POST['mtu'];
1597
		}
1598
		if (empty($_POST['mss'])) {
1599
			unset($wancfg['mss']);
1600
		} else {
1601
			$wancfg['mss'] = $_POST['mss'];
1602
		}
1603
		if (empty($_POST['mediaopt'])) {
1604
			unset($wancfg['media']);
1605
			unset($wancfg['mediaopt']);
1606
		} else {
1607
			$mediaopts = explode(' ', $_POST['mediaopt']);
1608
			if ($mediaopts[0] != '') {
1609
				$wancfg['media'] = $mediaopts[0];
1610
			}
1611
			if ($mediaopts[1] != '') {
1612
				$wancfg['mediaopt'] = $mediaopts[1];
1613
			} else {
1614
				unset($wancfg['mediaopt']);
1615
			}
1616
		}
1617
		if (isset($wancfg['wireless'])) {
1618
			handle_wireless_post();
1619
		}
1620

    
1621
		write_config("Interfaces settings changed");
1622

    
1623
		if ($_POST['gatewayip4']) {
1624
			save_gateway($gateway_settings4);
1625
		}
1626

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

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

    
1640
		mark_subsystem_dirty('interfaces');
1641

    
1642
		/* regenerate cron settings/crontab file */
1643
		configure_cron();
1644

    
1645
		header("Location: interfaces.php?if={$if}");
1646
		exit;
1647
	}
1648

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

    
1654
} // end if ($_POST['save'])
1655

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

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

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

    
1812
	interface_sync_wireless_clones($wancfg, true);
1813
}
1814

    
1815
function check_wireless_mode() {
1816
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1817

    
1818
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1819
		return;
1820
	}
1821

    
1822
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1823
		$clone_count = 1;
1824
	} else {
1825
		$clone_count = 0;
1826
	}
1827

    
1828
	foreach (config_get_path('wireless/clone', []) as $clone) {
1829
		if ($clone['if'] == $wlanbaseif) {
1830
				$clone_count++;
1831
		}
1832
	}
1833

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

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

    
1861
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1862
$shortcut_section = "interfaces";
1863

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

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

    
1871
$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"));
1872

    
1873
// Get the MAC address
1874
$defgatewayname4 = $wancfg['descr'] . "GW";
1875
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1876

    
1877
function build_mediaopts_list() {
1878
	global $mediaopts_list;
1879

    
1880
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1881
			 " " =>	 gettext("------- Media Supported by this interface -------")
1882
			];
1883

    
1884
	foreach ($mediaopts_list as $mediaopt) {
1885
		$list[$mediaopt] = $mediaopt;
1886
	}
1887

    
1888
	return($list);
1889
}
1890

    
1891
function build_gateway_list() {
1892
	global $a_gateways, $if;
1893

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

    
1904
	return($list);
1905
}
1906

    
1907
function build_gatewayv6_list() {
1908
	global $a_gateways, $if;
1909

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

    
1920
	return($list);
1921
}
1922

    
1923
include("head.inc");
1924

    
1925
if ($input_errors) {
1926
	print_input_errors($input_errors);
1927
}
1928

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

    
1935
if ($changes_applied) {
1936
	print_apply_result_box($retval);
1937
}
1938

    
1939
$form = new Form();
1940

    
1941
$section = new Form_Section('General Configuration');
1942

    
1943
$section->addInput(new Form_Checkbox(
1944
	'enable',
1945
	'Enable',
1946
	'Enable interface',
1947
	$pconfig['enable'],
1948
	'yes'
1949
));
1950

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

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

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

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

    
2009
	$section->addInput($macaddress);
2010
}
2011

    
2012
$section->addInput(new Form_Input(
2013
	'mtu',
2014
	'MTU',
2015
	'number',
2016
	$pconfig['mtu']
2017
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2018
			'This is typically 1500 bytes but can vary in some circumstances.');
2019

    
2020
$section->addInput(new Form_Input(
2021
	'mss',
2022
	'MSS',
2023
	'number',
2024
	$pconfig['mss']
2025
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2026
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2027

    
2028
if (count($mediaopts_list) > 0) {
2029
	$section->addInput(new Form_Select(
2030
		'mediaopt',
2031
		'Speed and Duplex',
2032
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt"), ""),
2033
		build_mediaopts_list() 
2034
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2035
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2036
}
2037

    
2038
$form->add($section);
2039

    
2040
$section = new Form_Section('Static IPv4 Configuration');
2041
$section->addClass('staticv4');
2042

    
2043
$section->addInput(new Form_IpAddress(
2044
	'ipaddr',
2045
	'*IPv4 Address',
2046
	$pconfig['ipaddr'],
2047
	'V4'
2048
))->addMask('subnet', $pconfig['subnet'], 32);
2049

    
2050
$group = new Form_Group('IPv4 Upstream gateway');
2051

    
2052
$group->add(new Form_Select(
2053
	'gateway',
2054
	'IPv4 Upstream Gateway',
2055
	$pconfig['gateway'],
2056
	build_gateway_list()
2057
));
2058

    
2059
$group->add(new Form_Button(
2060
	'addgw4',
2061
	'Add a new gateway',
2062
	null,
2063
	'fa-plus'
2064
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2065

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

    
2071
$section->add($group);
2072

    
2073
$form->add($section);
2074

    
2075
$section = new Form_Section('SLAAC IPv6 Configuration');
2076
$section->addClass('slaac');
2077

    
2078
$section->addInput(new Form_Checkbox(
2079
	'slaacusev4iface',
2080
	'Use IPv4 connectivity as parent interface',
2081
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2082
	$pconfig['slaacusev4iface']
2083
));
2084

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

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

    
2090
$section->addInput(new Form_IpAddress(
2091
	'ipaddrv6',
2092
	'*IPv6 address',
2093
	$pconfig['ipaddrv6'],
2094
	'V6'
2095
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2096

    
2097
$section->addInput(new Form_Checkbox(
2098
	'ipv6usev4iface',
2099
	'Use IPv4 connectivity as parent interface',
2100
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2101
	$pconfig['ipv6usev4iface']
2102
));
2103

    
2104
$group = new Form_Group('IPv6 Upstream gateway');
2105

    
2106
$group->add(new Form_Select(
2107
	'gatewayv6',
2108
	'IPv6 Upstream Gateway',
2109
	$pconfig['gatewayv6'],
2110
	build_gatewayv6_list()
2111
));
2112

    
2113
$group->add(new Form_Button(
2114
	'addgw6',
2115
	'Add a new gateway',
2116
	null,
2117
	'fa-plus'
2118
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2119

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

    
2123
$section->add($group);
2124
$form->add($section);
2125

    
2126
// Add new gateway modal pop-up for IPv6
2127
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2128

    
2129
$modal->addInput(new Form_Checkbox(
2130
	'defaultgw6',
2131
	'Default',
2132
	'Default gateway',
2133
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2134
));
2135

    
2136
$modal->addInput(new Form_Input(
2137
	'gatewayname6',
2138
	'Gateway name',
2139
	'text',
2140
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2141
));
2142

    
2143
$modal->addInput(new Form_IpAddress(
2144
	'gatewayip6',
2145
	'Gateway IPv6',
2146
	$gateway_settings6['gateway'],
2147
	'V6'
2148
));
2149

    
2150
$modal->addInput(new Form_Input(
2151
	'gatewaydescr6',
2152
	'Description',
2153
	'text',
2154
	$gateway_settings6['descr']
2155
));
2156

    
2157
$btnaddgw6 = new Form_Button(
2158
	'add6',
2159
	'Add',
2160
	null,
2161
	'fa-plus'
2162
);
2163

    
2164
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2165

    
2166
$btncnxgw6 = new Form_Button(
2167
	'cnx6',
2168
	'Cancel',
2169
	null,
2170
	'fa-undo'
2171
);
2172

    
2173
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2174

    
2175
$modal->addInput(new Form_StaticText(
2176
	null,
2177
	$btnaddgw6 . $btncnxgw6
2178
));
2179

    
2180
$form->add($modal);
2181

    
2182
// ==== DHCP client configuration =============================
2183

    
2184
$section = new Form_Section('DHCP Client Configuration');
2185
$section->addClass('dhcp');
2186

    
2187
$group = new Form_Group('Options');
2188

    
2189
$group->add(new Form_Checkbox(
2190
	'adv_dhcp_config_advanced',
2191
	null,
2192
	'Advanced Configuration',
2193
	$pconfig['adv_dhcp_config_advanced']
2194
))->setHelp('Use advanced DHCP configuration options.');
2195

    
2196
$group->add(new Form_Checkbox(
2197
	'adv_dhcp_config_file_override',
2198
	null,
2199
	'Configuration Override',
2200
	$pconfig['adv_dhcp_config_file_override']
2201
))->setHelp('Override the configuration from this file.');
2202

    
2203
$section->add($group);
2204

    
2205
$section->addInput(new Form_Input(
2206
	'dhcphostname',
2207
	'Hostname',
2208
	'text',
2209
	$pconfig['dhcphostname']
2210
))->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).');
2211

    
2212
$section->addInput(new Form_IpAddress(
2213
	'alias-address',
2214
	'Alias IPv4 address',
2215
	$pconfig['alias-address'],
2216
	'V4'
2217
))->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.');
2218

    
2219
$section->addInput(new Form_Input(
2220
	'dhcprejectfrom',
2221
	'Reject leases from',
2222
	'text',
2223
	$pconfig['dhcprejectfrom']
2224
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2225
			'(separate multiple entries with a comma). ' .
2226
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2227

    
2228
if (interface_is_vlan($wancfg['if']) != NULL) {
2229

    
2230
	$group = new Form_Group('DHCP VLAN Priority');
2231
	$group->add(new Form_Checkbox(
2232
		'dhcpvlanenable',
2233
		null,
2234
		'Enable dhcpclient VLAN Priority tagging',
2235
		$pconfig['dhcpvlanenable']
2236
	))->setHelp('Normally off unless specifically required by the ISP.');
2237

    
2238
	$group->add(new Form_Select(
2239
		'dhcpcvpt',
2240
		'VLAN Prio',
2241
		$pconfig['dhcpcvpt'],
2242
		$vlanprio
2243
	))->setHelp('Choose 802.1p priority to set.');
2244

    
2245
	$section->add($group);
2246
}
2247

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

    
2253
$group->add(new Form_Input(
2254
	'adv_dhcp_pt_timeout',
2255
	null,
2256
	'number',
2257
	$pconfig['adv_dhcp_pt_timeout']
2258
))->setHelp('Timeout');
2259

    
2260
$group->add(new Form_Input(
2261
	'adv_dhcp_pt_retry',
2262
	null,
2263
	'number',
2264
	$pconfig['adv_dhcp_pt_retry']
2265
))->setHelp('Retry');
2266

    
2267
$group->add(new Form_Input(
2268
	'adv_dhcp_pt_select_timeout',
2269
	null,
2270
	'number',
2271
	$pconfig['adv_dhcp_pt_select_timeout'],
2272
	['min' => 0]
2273
))->setHelp('Select timeout');
2274

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

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

    
2289
$group->add(new Form_Input(
2290
	'adv_dhcp_pt_initial_interval',
2291
	null,
2292
	'number',
2293
	$pconfig['adv_dhcp_pt_initial_interval']
2294
))->setHelp('Initial interval');
2295

    
2296
$section->add($group);
2297

    
2298
$group = new Form_Group('Presets');
2299
$group->addClass('dhcpadvanced');
2300

    
2301
$group->add(new Form_Checkbox(
2302
	'adv_dhcp_pt_values',
2303
	null,
2304
	'FreeBSD default',
2305
	null,
2306
	'DHCP'
2307
))->displayAsRadio();
2308

    
2309
$group->add(new Form_Checkbox(
2310
	'adv_dhcp_pt_values',
2311
	null,
2312
	'Clear',
2313
	null,
2314
	'Clear'
2315
))->displayAsRadio();
2316

    
2317
$group->add(new Form_Checkbox(
2318
	'adv_dhcp_pt_values',
2319
	null,
2320
	'pfSense Default',
2321
	null,
2322
	'pfSense'
2323
))->displayAsRadio();
2324

    
2325
$group->add(new Form_Checkbox(
2326
	'adv_dhcp_pt_values',
2327
	null,
2328
	'Saved Cfg',
2329
	null,
2330
	'SavedCfg'
2331
))->displayAsRadio();
2332

    
2333
$section->add($group);
2334

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

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

    
2347
$section = new Form_Section('Lease Requirements and Requests');
2348
$section->addClass('dhcpadvanced');
2349

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

    
2360
$section->addInput(new Form_Input(
2361
	'adv_dhcp_request_options',
2362
	'Request options',
2363
	'text',
2364
	$pconfig['adv_dhcp_request_options']
2365
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2366
			'Some ISPs may require certain options be or not be requested.', '<br />');
2367

    
2368
$section->addInput(new Form_Input(
2369
	'adv_dhcp_required_options',
2370
	'Require options',
2371
	'text',
2372
	$pconfig['adv_dhcp_required_options']
2373
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2374

    
2375
$section->addInput(new Form_Input(
2376
	'adv_dhcp_option_modifiers',
2377
	'Option modifiers',
2378
	'text',
2379
	$pconfig['adv_dhcp_option_modifiers']
2380
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2381
			'modifiers: (default, supersede, prepend, append) %1$s' .
2382
			'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>');
2383

    
2384
$form->add($section);
2385

    
2386
// DHCP6 client config
2387

    
2388
$section = new Form_Section('DHCP6 Client Configuration');
2389
$section->addClass('dhcp6');
2390

    
2391
$group = new Form_Group('Options');
2392

    
2393
$group->add(new Form_Checkbox(
2394
	'adv_dhcp6_config_advanced',
2395
	null,
2396
	'Advanced Configuration',
2397
	$pconfig['adv_dhcp6_config_advanced']
2398
))->setHelp('Use advanced DHCPv6 configuration options.');
2399

    
2400
$group->add(new Form_Checkbox(
2401
	'adv_dhcp6_config_file_override',
2402
	null,
2403
	'Configuration Override',
2404
	$pconfig['adv_dhcp6_config_file_override']
2405
))->setHelp('Override the configuration from this file.');
2406

    
2407
$section->add($group);
2408

    
2409
$section->addInput(new Form_Checkbox(
2410
	'dhcp6usev4iface',
2411
	'Use IPv4 connectivity as parent interface',
2412
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2413
	$pconfig['dhcp6usev4iface']
2414
));
2415

    
2416
$section->addInput(new Form_Checkbox(
2417
	'dhcp6prefixonly',
2418
	'Request only an IPv6 prefix',
2419
	'Only request an IPv6 prefix, do not request an IPv6 address',
2420
	$pconfig['dhcp6prefixonly']
2421
));
2422

    
2423
$section->addInput(new Form_Select(
2424
	'dhcp6-ia-pd-len',
2425
	'DHCPv6 Prefix Delegation size',
2426
	$pconfig['dhcp6-ia-pd-len'],
2427
	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")
2428
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2429

    
2430
$section->addInput(new Form_Checkbox(
2431
	'dhcp6-ia-pd-send-hint',
2432
	'Send IPv6 prefix hint',
2433
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2434
	$pconfig['dhcp6-ia-pd-send-hint']
2435
));
2436

    
2437
$section->addInput(new Form_Checkbox(
2438
	'dhcp6withoutra',
2439
	'Do not wait for a RA',
2440
	'Required by some ISPs, especially those not using PPPoE',
2441
	$pconfig['dhcp6withoutra']
2442
));
2443

    
2444
if (interface_is_vlan($wancfg['if']) != NULL) {
2445
	$group = new Form_Group('DHCP6 VLAN Priority');
2446

    
2447
	$group->add(new Form_Checkbox(
2448
		'dhcp6vlanenable',
2449
		null,
2450
		'Enable dhcp6c VLAN Priority tagging',
2451
		$pconfig['dhcp6vlanenable']
2452
	))->setHelp('Normally off unless specifically required by the ISP.');
2453

    
2454
	$group->add(new Form_Select(
2455
		'dhcp6cvpt',
2456
		'VLAN Prio',
2457
		$pconfig['dhcp6cvpt'],
2458
		$vlanprio
2459
	))->setHelp('Choose 802.1p priority to set.');
2460

    
2461
	$section->add($group);
2462
}
2463

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

    
2474
$form->add($section);
2475

    
2476
// DHCP6 client config - Advanced
2477

    
2478
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2479
$section->addClass('dhcp6advanced');
2480

    
2481
$section->addInput(new Form_Checkbox(
2482
	'adv_dhcp6_interface_statement_information_only_enable',
2483
	'Information only',
2484
	'Exchange Information Only',
2485
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2486
	'Selected'
2487
))->setHelp('Only exchange informational configuration parameters with servers.');
2488

    
2489
$section->addInput(new Form_Input(
2490
	'adv_dhcp6_interface_statement_send_options',
2491
	'Send options',
2492
	'text',
2493
	$pconfig['adv_dhcp6_interface_statement_send_options']
2494
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2495
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2496
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2497
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2498

    
2499
$section->addInput(new Form_Input(
2500
	'adv_dhcp6_interface_statement_request_options',
2501
	'Request Options',
2502
	'text',
2503
	$pconfig['adv_dhcp6_interface_statement_request_options']
2504
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2505
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2506

    
2507
$section->addInput(new Form_Input(
2508
	'adv_dhcp6_interface_statement_script',
2509
	'Scripts',
2510
	'text',
2511
	$pconfig['adv_dhcp6_interface_statement_script']
2512
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2513
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2514

    
2515
$group = new Form_Group('Identity Association Statement');
2516

    
2517
$group->add(new Form_Checkbox(
2518
	'adv_dhcp6_id_assoc_statement_address_enable',
2519
	null,
2520
	'Non-Temporary Address Allocation',
2521
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2522
	'Selected'
2523
));
2524

    
2525
$group->add(new Form_Input(
2526
	'adv_dhcp6_id_assoc_statement_address_id',
2527
	null,
2528
	'text',
2529
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2530
))->sethelp('id-assoc na ID');
2531

    
2532
$group->add(new Form_IpAddress(
2533
	'adv_dhcp6_id_assoc_statement_address',
2534
	null,
2535
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2536
	'V6'
2537
))->sethelp('IPv6 address');
2538

    
2539
$group->add(new Form_Input(
2540
	'adv_dhcp6_id_assoc_statement_address_pltime',
2541
	null,
2542
	'text',
2543
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2544
))->sethelp('pltime');
2545

    
2546
$group->add(new Form_Input(
2547
	'adv_dhcp6_id_assoc_statement_address_vltime',
2548
	null,
2549
	'text',
2550
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2551
))->sethelp('vltime');
2552

    
2553
$section->add($group);
2554

    
2555
// Prefix delegation
2556
$group = new Form_Group('');
2557

    
2558
$group->add(new Form_Checkbox(
2559
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2560
	null,
2561
	'Prefix Delegation ',
2562
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2563
	'Selected'
2564
));
2565

    
2566
$group->add(new Form_Input(
2567
	'adv_dhcp6_id_assoc_statement_prefix_id',
2568
	null,
2569
	'text',
2570
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2571
))->sethelp('id-assoc pd ID');
2572

    
2573
$group->add(new Form_IpAddress(
2574
	'adv_dhcp6_id_assoc_statement_prefix',
2575
	null,
2576
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2577
	'V6'
2578
))->sethelp('IPv6 prefix');
2579

    
2580
$group->add(new Form_Input(
2581
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2582
	null,
2583
	'text',
2584
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2585
))->sethelp('pltime');
2586

    
2587
$group->add(new Form_Input(
2588
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2589
	null,
2590
	'text',
2591
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2592
))->sethelp('vltime');
2593

    
2594
$section->add($group);
2595

    
2596
$group = new Form_Group('Prefix interface statement');
2597

    
2598
$group->add(new Form_Input(
2599
	'adv_dhcp6_prefix_interface_statement_sla_id',
2600
	null,
2601
	'text',
2602
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2603
))->sethelp('Prefix Interface sla-id');
2604

    
2605
$group->add(new Form_Input(
2606
	'adv_dhcp6_prefix_interface_statement_sla_len',
2607
	null,
2608
	'text',
2609
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2610
))->sethelp('sla-len');
2611

    
2612
$section->add($group);
2613

    
2614
$group = new Form_Group('Select prefix interface');
2615
$section->addInput(new Form_Select(
2616
	'adv_dhcp6_prefix_selected_interface',
2617
	'Prefix Interface',
2618
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2619
	$interfaces
2620
))->setHelp('Select the interface on which to apply the prefix delegation.');
2621

    
2622
$group = new Form_Group('Authentication statement');
2623

    
2624
$group->add(new Form_Input(
2625
	'adv_dhcp6_authentication_statement_authname',
2626
	null,
2627
	'text',
2628
	$pconfig['adv_dhcp6_authentication_statement_authname']
2629
))->sethelp('Authname');
2630

    
2631
$group->add(new Form_Input(
2632
	'adv_dhcp6_authentication_statement_protocol',
2633
	null,
2634
	'text',
2635
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2636
))->sethelp('Protocol');
2637

    
2638
$group->add(new Form_Input(
2639
	'adv_dhcp6_authentication_statement_algorithm',
2640
	null,
2641
	'text',
2642
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2643
))->sethelp('Algorithm');
2644

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

    
2652
$section->add($group);
2653

    
2654
$group = new Form_Group('Keyinfo statement');
2655

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

    
2663
$group->add(new Form_Input(
2664
	'adv_dhcp6_key_info_statement_realm',
2665
	null,
2666
	'text',
2667
	$pconfig['adv_dhcp6_key_info_statement_realm']
2668
))->sethelp('Realm');
2669

    
2670
$section->add($group);
2671

    
2672
$group = new Form_Group('');
2673

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

    
2681
$group->add(new Form_Input(
2682
	'adv_dhcp6_key_info_statement_secret',
2683
	null,
2684
	'text',
2685
	$pconfig['adv_dhcp6_key_info_statement_secret']
2686
))->sethelp('Secret');
2687

    
2688
$group->add(new Form_Input(
2689
	'adv_dhcp6_key_info_statement_expire',
2690
	null,
2691
	'text',
2692
	$pconfig['adv_dhcp6_key_info_statement_expire']
2693
))->sethelp('Expire');
2694

    
2695
$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>');
2696

    
2697
$section->add($group);
2698

    
2699
$form->add($section);
2700

    
2701
$section = new Form_Section('6RD Configuration');
2702
$section->addClass('_6rd');
2703

    
2704
$section->addInput(new Form_Input(
2705
	'prefix-6rd',
2706
	'6RD Prefix',
2707
	'text',
2708
	$pconfig['prefix-6rd']
2709
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2710

    
2711
$section->addInput(new Form_Input(
2712
	'gateway-6rd',
2713
	'*6RD Border relay',
2714
	'text',
2715
	$pconfig['gateway-6rd']
2716
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2717

    
2718
$section->addInput(new Form_Select(
2719
	'prefix-6rd-v4plen',
2720
	'6RD IPv4 Prefix length',
2721
	$pconfig['prefix-6rd-v4plen'],
2722
	array_combine(range(0, 32), range(0, 32))
2723
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2724

    
2725
$form->add($section);
2726

    
2727
// Track IPv6 ointerface section
2728
$section = new Form_Section('Track IPv6 Interface');
2729
$section->addClass('track6');
2730

    
2731
function build_ipv6interface_list() {
2732
	global $config, $form;
2733

    
2734
	$list = array('' => '');
2735

    
2736
	$interfaces = get_configured_interface_with_descr(true);
2737
	$dynv6ifs = array();
2738

    
2739
	foreach ($interfaces as $iface => $ifacename) {
2740
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2741
			case "6to4":
2742
			case "6rd":
2743
			case "dhcp6":
2744
				$dynv6ifs[$iface] = array(
2745
					'name' => $ifacename,
2746
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2747
				);
2748
				break;
2749
			default:
2750
				continue 2;
2751
		}
2752
	}
2753

    
2754
	foreach ($dynv6ifs as $iface => $ifacedata) {
2755
		$list[$iface] = $ifacedata['name'];
2756

    
2757
		$form->addGlobal(new Form_Input(
2758
			'ipv6-num-prefix-ids-' . $iface,
2759
			null,
2760
			'hidden',
2761
			$ifacedata['ipv6_num_prefix_ids']
2762
		));
2763
	}
2764

    
2765
	return($list);
2766
}
2767

    
2768
$section->addInput(new Form_Select(
2769
	'track6-interface',
2770
	'*IPv6 Interface',
2771
	$pconfig['track6-interface'],
2772
	build_ipv6interface_list()
2773
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2774

    
2775
if ($pconfig['track6-prefix-id'] == "") {
2776
	$pconfig['track6-prefix-id'] = 0;
2777
}
2778

    
2779
$section->addInput(new Form_Input(
2780
	'track6-prefix-id--hex',
2781
	'IPv6 Prefix ID',
2782
	'text',
2783
	sprintf("%x", $pconfig['track6-prefix-id'])
2784
))->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>');
2785

    
2786
$form->addGlobal(new Form_Input(
2787
	'track6-prefix-id-max',
2788
	null,
2789
	'hidden',
2790
	0
2791
));
2792

    
2793
$form->add($section);
2794

    
2795
/// PPP section
2796

    
2797
$section = new Form_Section('PPP Configuration');
2798
$section->addClass('ppp');
2799

    
2800
$section->addInput(new Form_Select(
2801
	'country',
2802
	'Country',
2803
	$pconfig['country'],
2804
	[]
2805
));
2806

    
2807
$section->addInput(new Form_Select(
2808
	'provider_list',
2809
	'Provider',
2810
	$pconfig['provider_list'],
2811
	[]
2812
));
2813

    
2814
$section->addInput(new Form_Select(
2815
	'providerplan',
2816
	'Plan',
2817
	$pconfig['providerplan'],
2818
	[]
2819
))->setHelp('Select to fill in service provider data.');
2820

    
2821
$section->addInput(new Form_Input(
2822
	'ppp_username',
2823
	'Username',
2824
	'text',
2825
	$pconfig['ppp_username'],
2826
	['autocomplete' => 'new-password']
2827
));
2828

    
2829
$section->addPassword(new Form_Input(
2830
	'ppp_password',
2831
	'Password',
2832
	'password',
2833
	$pconfig['ppp_password']
2834
));
2835

    
2836
$section->addInput(new Form_Input(
2837
	'phone',
2838
	'*Phone number',
2839
	'text',
2840
	$pconfig['phone']
2841
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2842

    
2843
$section->addInput(new Form_Input(
2844
	'apn',
2845
	'Access Point Name',
2846
	'text',
2847
	$pconfig['apn']
2848
));
2849

    
2850

    
2851
function build_port_list() {
2852
	$list = array("" => "None");
2853

    
2854
	$portlist = glob("/dev/cua*");
2855
	$modems	  = glob("/dev/modem*");
2856
	$portlist = array_merge($portlist, $modems);
2857

    
2858
	foreach ($portlist as $port) {
2859
		if (preg_match("/\.(lock|init)$/", $port)) {
2860
			continue;
2861
		}
2862

    
2863
	$list[trim($port)] = $port;
2864
	}
2865

    
2866
	return($list);
2867
}
2868

    
2869
$section->addInput(new Form_Select(
2870
	'port',
2871
	"*Modem port",
2872
	$pconfig['port'],
2873
	build_port_list()
2874
));
2875

    
2876
$section->addInput(new Form_Button(
2877
	'btnadvppp',
2878
	'Advanced PPP',
2879
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2880
	'fa-cog'
2881
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2882

    
2883
$form->add($section);
2884

    
2885
// PPPoE configuration
2886
$section = new Form_Section('PPPoE Configuration');
2887
$section->addClass('pppoe');
2888

    
2889
$section->addInput(new Form_Input(
2890
	'pppoe_username',
2891
	'*Username',
2892
	'text',
2893
	$pconfig['pppoe_username'],
2894
	['autocomplete' => 'new-password']
2895
));
2896

    
2897
$section->addPassword(new Form_Input(
2898
	'pppoe_password',
2899
	'*Password',
2900
	'password',
2901
	$pconfig['pppoe_password']
2902
));
2903

    
2904
$section->addInput(new Form_Input(
2905
	'provider',
2906
	'Service name',
2907
	'text',
2908
	$pconfig['provider']
2909
))->setHelp('This field can usually be left empty.');
2910

    
2911
$section->addInput(new Form_Input(
2912
	'hostuniq',
2913
	'Host-Uniq',
2914
	'text',
2915
	$pconfig['hostuniq']
2916
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2917

    
2918
$section->addInput(new Form_Checkbox(
2919
	'pppoe_dialondemand',
2920
	'Dial on demand',
2921
	'Enable Dial-On-Demand mode ',
2922
	$pconfig['pppoe_dialondemand'],
2923
	'enable'
2924
));
2925

    
2926
$section->addInput(new Form_Input(
2927
	'pppoe_idletimeout',
2928
	'Idle timeout',
2929
	'number',
2930
	$pconfig['pppoe_idletimeout'],
2931
	['min' => 0]
2932
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2933
			'An idle timeout of zero disables this feature.');
2934

    
2935
$section->addInput(new Form_Select(
2936
	'pppoe-reset-type',
2937
	'Periodic reset',
2938
	$pconfig['pppoe-reset-type'],
2939
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2940
))->setHelp('Select a reset timing type.');
2941

    
2942
$group = new Form_Group('Custom reset');
2943
$group->addClass('pppoecustom');
2944

    
2945
$group->add(new Form_Input(
2946
	'pppoe_resethour',
2947
	null,
2948
	'number',
2949
	(strlen($pconfig['pppoe_resethour']) > 0) ? $pconfig['pppoe_resethour'] : "0",
2950
	['min' => 0, 'max' => 23]
2951
))->setHelp('Hour (0-23), blank for * (every)');
2952

    
2953
$group->add(new Form_Input(
2954
	'pppoe_resetminute',
2955
	null,
2956
	'number',
2957
	(strlen($pconfig['pppoe_resetminute']) > 0) ? $pconfig['pppoe_resetminute'] : "0",
2958
	['min' => 0, 'max' => 59]
2959
))->setHelp('Minute (0-59), blank for * (every)');
2960

    
2961
$group->add(new Form_Input(
2962
	'pppoe_resetdate',
2963
	null,
2964
	'text',
2965
	$pconfig['pppoe_resetdate']
2966
))->setHelp('Specific date (mm/dd/yyyy)');
2967

    
2968
$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');
2969

    
2970
$section->add($group);
2971

    
2972
$group = new Form_MultiCheckboxGroup('cron based reset');
2973
$group->addClass('pppoepreset');
2974

    
2975
$group->add(new Form_MultiCheckbox(
2976
	'pppoe_pr_preset_val',
2977
	null,
2978
	'Reset at each month ("0 0 1 * *")',
2979
	$pconfig['pppoe_monthly'],
2980
	'monthly'
2981
))->displayAsRadio();
2982

    
2983
$group->add(new Form_MultiCheckbox(
2984
	'pppoe_pr_preset_val',
2985
	null,
2986
	'Reset at each week ("0 0 * * 0")',
2987
	$pconfig['pppoe_weekly'],
2988
	'weekly'
2989
))->displayAsRadio();
2990

    
2991
$group->add(new Form_MultiCheckbox(
2992
	'pppoe_pr_preset_val',
2993
	null,
2994
	'Reset at each day ("0 0 * * *")',
2995
	$pconfig['pppoe_daily'],
2996
	'daily'
2997
))->displayAsRadio();
2998

    
2999
$group->add(new Form_MultiCheckbox(
3000
	'pppoe_pr_preset_val',
3001
	null,
3002
	'Reset at each hour ("0 * * * *")',
3003
	$pconfig['pppoe_hourly'],
3004
	'hourly'
3005
))->displayAsRadio();
3006

    
3007
$section->add($group);
3008

    
3009
$section->addInput(new Form_Button(
3010
	'btnadvppp',
3011
	'Advanced and MLPPP',
3012
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3013
	'fa-cog'
3014
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3015

    
3016
$form->add($section);
3017

    
3018
// PPTP & L2TP Configuration section
3019
$section = new Form_Section('PPTP/L2TP Configuration');
3020
$section->addClass('pptp');
3021

    
3022
$section->addInput(new Form_Input(
3023
	'pptp_username',
3024
	'*Username',
3025
	'text',
3026
	$pconfig['pptp_username'],
3027
	['autocomplete' => 'new-password']
3028
));
3029

    
3030
$section->addPassword(new Form_Input(
3031
	'pptp_password',
3032
	'*Password',
3033
	'password',
3034
	$pconfig['pptp_password']
3035
));
3036

    
3037
$group = new Form_Group('Shared Secret');
3038

    
3039
$group->add(new Form_Input(
3040
	'l2tp_secret',
3041
	'*Secret',
3042
	'password',
3043
	$pconfig['l2tp_secret']
3044
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3045
	    'important control packet contents. (Optional)');
3046

    
3047
$group->addClass('l2tp_secret');
3048
$section->add($group);
3049

    
3050
$section->addInput(new Form_IpAddress(
3051
	'pptp_local0',
3052
	'*Local IP address',
3053
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3054
	'V4'
3055
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3056

    
3057
$section->addInput(new Form_IpAddress(
3058
	'pptp_remote0',
3059
	'*Remote IP address',
3060
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3061
	'HOSTV4'
3062
));
3063

    
3064
$section->addInput(new Form_Checkbox(
3065
	'pptp_dialondemand',
3066
	'Dial on demand',
3067
	'Enable Dial-On-Demand mode ',
3068
	$pconfig['pptp_dialondemand'],
3069
	'enable'
3070
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3071
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3072

    
3073
$section->addInput(new Form_Input(
3074
	'pptp_idletimeout',
3075
	'Idle timeout (seconds)',
3076
	'number',
3077
	$pconfig['pptp_idletimeout'],
3078
	['min' => 0]
3079
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3080
			'An idle timeout of zero disables this feature.');
3081

    
3082
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3083
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3084
} else {
3085
	$mlppp_text = "";
3086
}
3087

    
3088
$section->addInput(new Form_Button(
3089
	'btnadvppp',
3090
	'Advanced and MLPPP',
3091
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3092
	'fa-cog'
3093
))->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);
3094

    
3095
$form->add($section);
3096

    
3097
// Wireless interface
3098
if (isset($wancfg['wireless'])) {
3099

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

    
3102
	$section->addInput(new Form_Checkbox(
3103
		'persistcommonwireless',
3104
		'Persist common settings',
3105
		'Preserve common wireless configuration through interface deletions and reassignments.',
3106
		$pconfig['persistcommonwireless'],
3107
		'yes'
3108
	));
3109

    
3110
	$mode_list = ['auto' => 'Auto'];
3111

    
3112
	if (is_array($wl_modes)) {
3113
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3114
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3115
		}
3116
	}
3117

    
3118
	if (count($mode_list) == 1) {
3119
		$mode_list[''] = '';
3120
	}
3121

    
3122
	$section->addInput(new Form_Select(
3123
		'standard',
3124
		'Standard',
3125
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3126
		$mode_list
3127
	));
3128

    
3129
	if (isset($wl_modes['11g'])) {
3130
		$section->addInput(new Form_Select(
3131
			'protmode',
3132
			'802.11g OFDM Protection Mode',
3133
			$pconfig['protmode'],
3134
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3135
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3136
	} else {
3137
		$form->addGlobal(new Form_Input(
3138
			'protmode',
3139
			null,
3140
			'hidden',
3141
			'off'
3142
		));
3143
	}
3144

    
3145
	$mode_list = ['0' => gettext('Auto')];
3146

    
3147
	if (is_array($wl_modes)) {
3148
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3149
			if ($wl_standard == "11g") {
3150
				$wl_standard = "11b/g";
3151
			} else if ($wl_standard == "11ng") {
3152
				$wl_standard = "11b/g/n";
3153
			} else if ($wl_standard == "11na") {
3154
				$wl_standard = "11a/n";
3155
			}
3156

    
3157
			foreach ($wl_channels as $wl_channel) {
3158
				if (isset($wl_chaninfo[$wl_channel])) {
3159
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3160
				} else {
3161
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3162
				}
3163
			}
3164
		}
3165
	}
3166

    
3167
	$section->addInput(new Form_Select(
3168
		'channel',
3169
		'Channel',
3170
		$pconfig['channel'],
3171
		$mode_list
3172
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3173
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3174

    
3175
	$section->addInput(new Form_Select(
3176
		'channel_width',
3177
		'Channel width',
3178
		$pconfig['channel_width'],
3179
		$wl_ht_modes
3180
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3181

    
3182
	if (ANTENNAS) {
3183
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3184
			$group = new Form_Group('Antenna Settings');
3185

    
3186
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3187
				$group->add(new Form_Select(
3188
					'diversity',
3189
					null,
3190
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3191
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3192
				))->setHelp('Diversity');
3193
			}
3194

    
3195
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3196
				$group->add(new Form_Select(
3197
					'txantenna',
3198
					null,
3199
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3200
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3201
				))->setHelp('Transmit antenna');
3202
			}
3203

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

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

    
3215
			$section->add($group);
3216
		}
3217
	}
3218

    
3219
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3220
			$section->addInput(new Form_Input(
3221
				'distance',
3222
				'Distance setting (meters)',
3223
				'test',
3224
				$pconfig['distance']
3225
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3226
	}
3227

    
3228
	$form->add($section);
3229

    
3230
	// Regulatory settings
3231
	$section = new Form_Section('Regulatory Settings');
3232

    
3233
	$domain_list = array("" => 'Default');
3234

    
3235
	if (is_array($wl_regdomains)) {
3236
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3237
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3238
		}
3239
	}
3240

    
3241
	$section->addInput(new Form_Select(
3242
		'regdomain',
3243
		'Regulatory domain',
3244
		$pconfig['regdomain'],
3245
		$domain_list
3246
	))->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');
3247

    
3248
	$country_list = array('' => 'Default');
3249

    
3250
	if (is_array($wl_countries)) {
3251
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3252
			$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']);
3253
		}
3254
	}
3255

    
3256
	$section->addInput(new Form_Select(
3257
		'regcountry',
3258
		'Country',
3259
		$pconfig['regcountry'],
3260
		$country_list
3261
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3262

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

    
3274
	$form->add($section);
3275

    
3276
	$section = new Form_Section('Network-Specific Wireless Configuration');
3277

    
3278
	$section->addInput(new Form_Select(
3279
		'mode',
3280
		'Mode',
3281
		$pconfig['mode'],
3282
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3283
	));
3284

    
3285
	$section->addInput(new Form_Input(
3286
		'ssid',
3287
		'SSID',
3288
		'text',
3289
		$pconfig['ssid']
3290
	));
3291

    
3292
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3293
		$section->addInput(new Form_Select(
3294
			'puremode',
3295
			'Minimum wireless standard',
3296
			$pconfig['puremode'],
3297
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3298
		))->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)');
3299
	} elseif (isset($wl_modes['11g'])) {
3300
		$section->addInput(new Form_Checkbox(
3301
			'puremode',
3302
			'802.11g only',
3303
			null,
3304
			$pconfig['puremode'],
3305
			'11g'
3306
		))->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)');
3307
	}
3308

    
3309
	$section->addInput(new Form_Checkbox(
3310
		'apbridge_enable',
3311
		'Allow intra-BSS communication',
3312
		'Allow packets to pass between wireless clients directly when operating as an access point',
3313
		$pconfig['apbridge_enable'],
3314
		'yes'
3315
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3316

    
3317
	$section->addInput(new Form_Checkbox(
3318
		'wme_enable',
3319
		'Enable WME',
3320
		'Force the card to use WME (wireless QoS)',
3321
		$pconfig['wme_enable'],
3322
		'yes'
3323
	));
3324

    
3325
	$section->addInput(new Form_Checkbox(
3326
		'hidessid_enable',
3327
		'Hide SSID',
3328
		'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.)',
3329
		$pconfig['hidessid_enable'],
3330
		'yes'
3331
	));
3332

    
3333
	$form->add($section);
3334

    
3335
	// WPA Section
3336
	$section = new Form_Section('WPA');
3337

    
3338
	$section->addInput(new Form_Checkbox(
3339
		'wpa_enable',
3340
		'Enable',
3341
		'Enable WPA',
3342
		$pconfig['wpa_enable'],
3343
		'yes'
3344
	));
3345

    
3346
	$section->addInput(new Form_Select(
3347
		'wpa_mode',
3348
		'WPA mode',
3349
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3350
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3351
	));
3352

    
3353
	$section->addInput(new Form_Select(
3354
		'wpa_pairwise',
3355
		'WPA Pairwise',
3356
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3357
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3358
	));
3359

    
3360
	$section->addInput(new Form_Select(
3361
		'wpa_key_mgmt',
3362
		'WPA Key Management Mode',
3363
		$pconfig['wpa_key_mgmt'],
3364
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3365
	));
3366

    
3367
	$section->addInput(new Form_Input(
3368
		'passphrase',
3369
		'WPA Pre-Shared Key',
3370
		'text',
3371
		$pconfig['passphrase']
3372
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3373

    
3374
	$section->addInput(new Form_Select(
3375
		'wpa_eap_client_mode',
3376
		'EAP Client Mode',
3377
		$pconfig['wpa_eap_client_mode'],
3378
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3379
	));
3380

    
3381
	$section->addInput(new Form_Select(
3382
		'wpa_eap_ca',
3383
		'Certificate Authority',
3384
		$pconfig['wpa_eap_ca'],
3385
		cert_build_list('ca', 'HTTPS')
3386
	));
3387

    
3388
	$section->addInput(new Form_Select(
3389
		'wpa_eap_inner_auth',
3390
		'Inner Authentication Method',
3391
		$pconfig['wpa_eap_inner_auth'],
3392
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3393
	));
3394

    
3395
	$section->addInput(new Form_Input(
3396
		'wpa_eap_inner_id',
3397
		'*Inner Authentication Identity',
3398
		'text',
3399
		$pconfig['wpa_eap_inner_id']
3400
	));
3401

    
3402
	$section->addInput(new Form_Input(
3403
		'wpa_eap_inner_password',
3404
		'*Inner Authentication Passphrase',
3405
		'text',
3406
		$pconfig['wpa_eap_inner_password']
3407
	));
3408

    
3409
	$section->addInput(new Form_Select(
3410
		'wpa_eap_cert',
3411
		'TLS/TTLS Client Certificate',
3412
		$pconfig['wpa_eap_cert'],
3413
		cert_build_list('cert', 'HTTPS')
3414
	));
3415

    
3416
	$section->addInput(new Form_Input(
3417
		'wpa_group_rekey',
3418
		'Group Key Rotation',
3419
		'number',
3420
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3421
		['min' => '1', 'max' => 9999]
3422
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3423

    
3424
	$section->addInput(new Form_Input(
3425
		'wpa_gmk_rekey',
3426
		'Group Master Key Regeneration',
3427
		'number',
3428
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3429
		['min' => '1', 'max' => 9999]
3430
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3431

    
3432
	$section->addInput(new Form_Checkbox(
3433
		'wpa_strict_rekey',
3434
		'Strict Key Regeneration',
3435
		'Force the AP to rekey whenever a client disassociates',
3436
		$pconfig['wpa_strict_rekey'],
3437
		'yes'
3438
	));
3439

    
3440
	$form->add($section);
3441

    
3442
	$section = new Form_Section('802.1x RADIUS Options');
3443
	$section->addClass('ieee8021x_group');
3444

    
3445
	$section->addInput(new Form_Checkbox(
3446
		'ieee8021x',
3447
		'IEEE802.1X',
3448
		'Enable 802.1X authentication',
3449
		$pconfig['ieee8021x'],
3450
		'yes'
3451
	));
3452

    
3453
	$group = new Form_Group('Primary 802.1X server');
3454

    
3455
	$group->add(new Form_IpAddress(
3456
		'auth_server_addr',
3457
		'IP Address',
3458
		$pconfig['auth_server_addr']
3459
	))->setHelp('IP address of the RADIUS server');
3460

    
3461
	$group->add(new Form_Input(
3462
		'auth_server_port',
3463
		'Port',
3464
		'number',
3465
		$pconfig['auth_server_port']
3466
	))->setHelp('Server auth port. Default is 1812');
3467

    
3468
	$group->add(new Form_Input(
3469
		'auth_server_shared_secret',
3470
		'Shared Secret',
3471
		'text',
3472
		$pconfig['auth_server_shared_secret']
3473
	))->setHelp('RADIUS Shared secret for this firewall');
3474

    
3475
	$section->add($group);
3476

    
3477
	$group = new Form_Group('Secondary 802.1X server');
3478

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

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

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

    
3499
	$section->add($group);
3500

    
3501
	$section->addInput(new Form_Checkbox(
3502
		'rsn_preauth',
3503
		'Authentication Roaming Preauth',
3504
		null,
3505
		$pconfig['rsn_preauth'],
3506
		'yes'
3507
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3508

    
3509
	$form->add($section);
3510
}
3511

    
3512
$section = new Form_Section('Reserved Networks');
3513

    
3514
$section->addInput(new Form_Checkbox(
3515
	'blockpriv',
3516
	'Block private networks and loopback addresses',
3517
	'',
3518
	$pconfig['blockpriv'],
3519
	'yes'
3520
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3521
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3522
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3523

    
3524
$section->addInput(new Form_Checkbox(
3525
	'blockbogons',
3526
	'Block bogon networks',
3527
	'',
3528
	$pconfig['blockbogons'],
3529
	'yes'
3530
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3531
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3532
			'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' .
3533
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3534

    
3535
$form->add($section);
3536

    
3537
$form->addGlobal(new Form_Input(
3538
	'if',
3539
	null,
3540
	'hidden',
3541
	$if
3542
));
3543

    
3544
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3545
	$form->addGlobal(new Form_Input(
3546
		'ppp_port',
3547
		null,
3548
		'hidden',
3549
		$pconfig['port']
3550
	));
3551
}
3552

    
3553
$form->addGlobal(new Form_Input(
3554
	'ptpid',
3555
	null,
3556
	'hidden',
3557
	$pconfig['ptpid']
3558
));
3559

    
3560

    
3561
// Add new gateway modal pop-up
3562
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3563

    
3564
$modal->addInput(new Form_Checkbox(
3565
	'defaultgw4',
3566
	'Default',
3567
	'Default gateway',
3568
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3569
));
3570

    
3571
$modal->addInput(new Form_Input(
3572
	'gatewayname4',
3573
	'Gateway name',
3574
	'text',
3575
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3576
));
3577

    
3578
$modal->addInput(new Form_IpAddress(
3579
	'gatewayip4',
3580
	'Gateway IPv4',
3581
	$gateway_settings4['gateway'],
3582
	'V4'
3583
));
3584

    
3585
$modal->addInput(new Form_Input(
3586
	'gatewaydescr4',
3587
	'Description',
3588
	'text',
3589
	$gateway_settings4['descr']
3590
));
3591

    
3592
$btnaddgw4 = new Form_Button(
3593
	'add4',
3594
	'Add',
3595
	null,
3596
	'fa-plus'
3597
);
3598

    
3599
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3600

    
3601
$btncnxgw4 = new Form_Button(
3602
	'cnx4',
3603
	'Cancel',
3604
	null,
3605
	'fa-undo'
3606
);
3607

    
3608
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3609

    
3610
$modal->addInput(new Form_StaticText(
3611
	null,
3612
	$btnaddgw4 . $btncnxgw4
3613
));
3614

    
3615
$form->add($modal);
3616

    
3617
print($form);
3618
?>
3619

    
3620
<script type="text/javascript">
3621
//<![CDATA[
3622
events.push(function() {
3623
	function updateType(t) {
3624

    
3625
		switch (t) {
3626
			case "none": {
3627
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3628
				break;
3629
			}
3630
			case "staticv4": {
3631
				$('.dhcpadvanced, .none, .dhcp').hide();
3632
				$('.pppoe, .pptp, .ppp').hide();
3633
				break;
3634
			}
3635
			case "dhcp": {
3636
				$('.dhcpadvanced, .none').hide();
3637
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3638
										//			about the staticv4 class
3639
				$('.pppoe, .pptp, .ppp').hide();
3640
				break;
3641
			}
3642
			case "ppp": {
3643
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3644
				country_list();
3645
				break;
3646
			}
3647
			case "pppoe": {
3648
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3649
				break;
3650
			}
3651
			case "l2tp": {
3652
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3653
				$('.pptp, .l2tp_secret').show();
3654
				break;
3655
			}
3656
			case "pptp": {
3657
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3658
				$('.pptp').show();
3659
				break;
3660
			}
3661
		}
3662

    
3663
		if (t != "l2tp" && t != "pptp") {
3664
			$('.'+t).show();
3665
		}
3666
	}
3667

    
3668
	function updateTypeSix(t) {
3669
		if (!isNaN(t[0])) {
3670
			t = '_' + t;
3671
		}
3672

    
3673
		switch (t) {
3674
			case "none": {
3675
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3676
				break;
3677
			}
3678
			case "staticv6": {
3679
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3680
				break;
3681
			}
3682
			case "slaac": {
3683
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3684
				break;
3685
			}
3686
			case "dhcp6": {
3687
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3688
				break;
3689
			}
3690
			case "_6rd": {
3691
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3692
				break;
3693
			}
3694
			case "_6to4": {
3695
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3696
				break;
3697
			}
3698
			case "track6": {
3699
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3700
				update_track6_prefix();
3701
				break;
3702
			}
3703
		}
3704

    
3705
		if (t != "l2tp" && t != "pptp") {
3706
			$('.'+t).show();
3707
		}
3708
	}
3709

    
3710
	function show_reset_settings(reset_type) {
3711
		if (reset_type == 'preset') {
3712
			$('.pppoepreset').show();
3713
			$('.pppoecustom').hide();
3714
		} else if (reset_type == 'custom') {
3715
			$('.pppoecustom').show();
3716
			$('.pppoepreset').hide();
3717
		} else {
3718
			$('.pppoecustom').hide();
3719
			$('.pppoepreset').hide();
3720
		}
3721
	}
3722

    
3723
	function update_track6_prefix() {
3724
		var iface = $("#track6-interface").val();
3725
		if (iface == null) {
3726
			return;
3727
		}
3728

    
3729
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3730
		if (track6_prefix_ids == null) {
3731
			return;
3732
		}
3733

    
3734
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3735
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3736
	}
3737

    
3738
	function addOption_v4() {
3739
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3740
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3741
	}
3742

    
3743
	function addOption_v6() {
3744
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3745
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3746
	}
3747

    
3748
	function addSelectboxOption(selectbox, text, value) {
3749
		var optn = document.createElement("OPTION");
3750
		optn.text = text;
3751
		optn.value = value;
3752
		selectbox.append(optn);
3753
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3754
	}
3755

    
3756
	function country_list() {
3757
		$('#country').children().remove();
3758
		$('#provider_list').children().remove();
3759
		$('#providerplan').children().remove();
3760
		$.ajax("getserviceproviders.php",{
3761
			success: function(response) {
3762

    
3763
				var responseTextArr = response.split("\n");
3764
				responseTextArr.sort();
3765

    
3766
				responseTextArr.forEach( function(value) {
3767
					country = value.split(":");
3768
					$('#country').append($('<option>', {
3769
						value: country[1],
3770
						text : country[0]
3771
					}));
3772
				});
3773
			}
3774
		});
3775
	}
3776

    
3777
	function providers_list() {
3778
		$('#provider_list').children().remove();
3779
		$('#providerplan').children().remove();
3780
		$.ajax("getserviceproviders.php",{
3781
			type: 'post',
3782
			data: {country : $('#country').val()},
3783
			success: function(response) {
3784
				var responseTextArr = response.split("\n");
3785
				responseTextArr.sort();
3786
				responseTextArr.forEach( function(value) {
3787
					$('#provider_list').append($('<option>', {
3788
							value: value,
3789
							text : value
3790
					}));
3791
				});
3792
			}
3793
		});
3794
	}
3795

    
3796
	function providerplan_list() {
3797
		$('#providerplan').children().remove();
3798
		$.ajax("getserviceproviders.php",{
3799
			type: 'post',
3800
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3801
			success: function(response) {
3802
				var responseTextArr = response.split("\n");
3803
				responseTextArr.sort();
3804

    
3805
				$('#providerplan').append($('<option>', {
3806
					value: '',
3807
					text : ''
3808
				}));
3809

    
3810
				responseTextArr.forEach( function(value) {
3811
					if (value != "") {
3812
						providerplan = value.split(":");
3813

    
3814
						$('#providerplan').append($('<option>', {
3815
							value: providerplan[1],
3816
							text : providerplan[0] + " - " + providerplan[1]
3817
						}));
3818
					}
3819
				});
3820
			}
3821
		});
3822
	}
3823

    
3824
	function prefill_provider() {
3825
		$.ajax("getserviceproviders.php",{
3826
			type: 'post',
3827
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3828
			success: function(data, textStatus, response) {
3829
				var xmldoc = response.responseXML;
3830
				var provider = xmldoc.getElementsByTagName('connection')[0];
3831
				$('#ppp_username').val('');
3832
				$('#ppp_password').val('');
3833
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3834
					$('#phone').val('#777');
3835
					$('#apn').val('');
3836
				} else {
3837
					$('#phone').val('*99#');
3838
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3839
				}
3840
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3841
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3842
				$('#ppp_username').val(ppp_username);
3843
				$('#ppp_password').val(ppp_password);
3844
			}
3845
		});
3846
	}
3847

    
3848
	function show_dhcp6adv() {
3849
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3850
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3851

    
3852
		hideCheckbox('dhcp6usev4iface', ovr);
3853
		hideCheckbox('dhcp6prefixonly', ovr);
3854
		hideInput('dhcp6-ia-pd-len', ovr);
3855
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3856
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3857

    
3858
		hideClass('dhcp6advanced', !adv || ovr);
3859
	}
3860

    
3861
	function setDHCPoptions() {
3862
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3863
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3864

    
3865
		if (ovr) {
3866
			hideInput('dhcphostname', true);
3867
			hideIpAddress('alias-address', true);
3868
			hideInput('dhcprejectfrom', true);
3869
			hideInput('adv_dhcp_config_file_override_path', false);
3870
			hideClass('dhcpadvanced', true);
3871
		} else {
3872
			hideInput('dhcphostname', false);
3873
			hideIpAddress('alias-address', false);
3874
			hideInput('dhcprejectfrom', false);
3875
			hideInput('adv_dhcp_config_file_override_path', true);
3876
			hideClass('dhcpadvanced', !adv);
3877
		}
3878
	}
3879

    
3880
	// DHCP preset actions
3881
	// Set presets from value of radio buttons
3882
	function setPresets(val) {
3883
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3884
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3885
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3886
		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']);?>");
3887
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3888
	}
3889

    
3890
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3891
		$('#adv_dhcp_pt_timeout').val(timeout);
3892
		$('#adv_dhcp_pt_retry').val(retry);
3893
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3894
		$('#adv_dhcp_pt_reboot').val(reboot);
3895
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3896
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3897
	}
3898

    
3899
	function setPPPoEDialOnDemandItems() {
3900
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3901
	}
3902

    
3903
	function setPPTPDialOnDemandItems() {
3904
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3905
	}
3906

    
3907
	function show_wpaoptions() {
3908
		var wpa = !($('#wpa_enable').prop('checked'));
3909

    
3910
		hideInput('passphrase', wpa);
3911
		hideInput('wpa_mode', wpa);
3912
		hideInput('wpa_key_mgmt', wpa);
3913
		hideInput('wpa_pairwise', wpa);
3914
		hideCheckbox('wpa_strict_rekey', wpa);
3915
		hideClass('ieee8021x_group', true);
3916
		if ($('#mode').val() == 'hostap') {
3917
			hideInput('wpa_group_rekey', wpa);
3918
			hideInput('wpa_gmk_rekey', wpa);
3919
			hideCheckbox('wpa_strict_rekey', wpa);
3920
		} else {
3921
			hideInput('wpa_group_rekey', true);
3922
			hideInput('wpa_gmk_rekey', true);
3923
			hideCheckbox('wpa_strict_rekey', true);
3924
		}
3925
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3926
	}
3927

    
3928
	function updatewifistandard(s) {
3929
		switch (s) {
3930
			case "auto": {
3931
				hideInput('protmode', false);
3932
				hideInput('channel_width', false);
3933
				break;
3934
			}
3935
			case "11b": {
3936
				hideInput('protmode', true);
3937
				hideInput('channel_width', true);
3938
				break;
3939
			}
3940
			case "11g": {
3941
				hideInput('protmode', false);
3942
				hideInput('channel_width', true);
3943
				break;
3944
			}
3945
			case "11ng": {
3946
				hideInput('protmode', false);
3947
				hideInput('channel_width', false);
3948
				break;
3949
			}
3950
			case "11a": {
3951
				hideInput('protmode', true);
3952
				hideInput('channel_width', true);
3953
				break;
3954
			}
3955
			case "11na": {
3956
				hideInput('protmode', true);
3957
				hideInput('channel_width', false);
3958
				break;
3959
			}
3960
			default: {
3961
				break;
3962
			}
3963
		}
3964
	}
3965

    
3966
	function updatewifimode(m) {
3967
		switch (m) {
3968
			case "adhoc": {
3969
				hideInput('puremode', true);
3970
				hideCheckbox('apbridge_enable', true);
3971
				hideCheckbox('hidessid_enable', false);
3972
				break;
3973
			}
3974
			case "hostap": {
3975
				hideInput('puremode', false);
3976
				hideCheckbox('apbridge_enable', false);
3977
				hideCheckbox('hidessid_enable', false);
3978
				break;
3979
			}
3980
			default: {
3981
				hideInput('puremode', true);
3982
				hideCheckbox('apbridge_enable', true);
3983
				hideCheckbox('hidessid_enable', true);
3984
				break;
3985
			}
3986
		}
3987
		show_wpaoptions();
3988
		updateeapclientmode($('#wpa_eap_client_mode').val());
3989
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3990
	}
3991

    
3992
	function updateeapclientmode(m) {
3993
		if ($('#mode').val() == 'bss') {
3994
			var wpa = !($('#wpa_enable').prop('checked'));
3995
		} else {
3996
			var wpa = true;
3997
		}
3998
		switch (m) {
3999
			case "PEAP": {
4000
				hideInput('wpa_eap_cert', true);
4001
				hideInput('wpa_eap_inner_auth', wpa);
4002
				hideInput('wpa_eap_inner_id', wpa);
4003
				hideInput('wpa_eap_inner_password', wpa);
4004
				break;
4005
			}
4006
			case "TLS": {
4007
				hideInput('wpa_eap_cert', wpa);
4008
				hideInput('wpa_eap_inner_auth', true);
4009
				hideInput('wpa_eap_inner_id', true);
4010
				hideInput('wpa_eap_inner_password', true);
4011
				break;
4012
			}
4013
			case "TTLS": {
4014
				hideInput('wpa_eap_cert', wpa);
4015
				hideInput('wpa_eap_inner_auth', wpa);
4016
				hideInput('wpa_eap_inner_id', wpa);
4017
				hideInput('wpa_eap_inner_password', wpa);
4018
				break;
4019
			}
4020
			default: {
4021
				break;
4022
			}
4023
		}
4024
	}
4025

    
4026
	function updatewpakeymgmt(m) {
4027
		hideInput('passphrase', false);
4028
		hideInput('wpa_eap_client_mode', true);
4029
		hideInput('wpa_eap_ca', true);
4030
		hideInput('wpa_eap_cert', true);
4031
		hideInput('wpa_eap_inner_auth', true);
4032
		hideInput('wpa_eap_inner_id', true);
4033
		hideInput('wpa_eap_inner_password', true);
4034
		hideClass('ieee8021x_group', true);
4035
		if (m == "WPA-EAP") {
4036
			hideInput('passphrase', true);
4037
			if ($('#mode').val() == 'bss') {
4038
				hideInput('wpa_eap_client_mode', false);
4039
				hideInput('wpa_eap_ca', false);
4040
				updateeapclientmode($('#wpa_eap_client_mode').val());
4041
			} else if ($('#mode').val() == 'hostap') {
4042
				hideClass('ieee8021x_group', false);
4043
			}
4044
		} else if (m != "WPA-PSK") {
4045
			hideInput('passphrase', false);
4046
			if ($('#mode').val() == 'bss') {
4047
				hideInput('wpa_eap_client_mode', false);
4048
				hideInput('wpa_eap_ca', false);
4049
				hideInput('wpa_eap_cert', false);
4050
				hideInput('wpa_eap_inner_auth', false);
4051
				hideInput('wpa_eap_inner_id', false);
4052
				hideInput('wpa_eap_inner_password', false);
4053
			} else if ($('#mode').val() == 'hostap') {
4054
				hideClass('ieee8021x_group', false);
4055
			}
4056
		}
4057
	}
4058

    
4059
	// ---------- On initial page load ------------------------------------------------------------
4060

    
4061
	updateType($('#type').val());
4062
	updateTypeSix($('#type6').val());
4063
	show_reset_settings($('#pppoe-reset-type').val());
4064
	hideClass('dhcp6advanced', true);
4065
	hideClass('dhcpadvanced', true);
4066
	show_dhcp6adv();
4067
	setDHCPoptions();
4068
	setPPPoEDialOnDemandItems();
4069
	setPPTPDialOnDemandItems();
4070
	show_wpaoptions();
4071
	updatewifistandard($('#standard').val());
4072
	updatewifimode($('#mode').val());
4073

    
4074
	// Set preset buttons on page load
4075
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4076
	if (sv == "") {
4077
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4078
	} else {
4079
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4080
	}
4081

    
4082
	// Set preset from value
4083
	setPresets(sv);
4084

    
4085
	// If the user wants to add a gateway, then add that to the gateway selection
4086
	if ($("#gatewayip4").val() != '') {
4087
		addOption_v4();
4088
	}
4089
	if ($("#gatewayip6").val() != '') {
4090
		addOption_v6();
4091
	}
4092

    
4093
	// ---------- Click checkbox handlers ---------------------------------------------------------
4094

    
4095
	$('#type').on('change', function() {
4096
		updateType(this.value);
4097
	});
4098

    
4099
	$('#type6').on('change', function() {
4100
		updateTypeSix(this.value);
4101
	});
4102

    
4103
	$('#standard').on('change', function() {
4104
		updatewifistandard(this.value);
4105
	});
4106

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

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

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

    
4119
	$('#track6-interface').on('change', function() {
4120
		update_track6_prefix();
4121
	});
4122

    
4123
	$('#pppoe-reset-type').on('change', function() {
4124
		show_reset_settings(this.value);
4125
	});
4126

    
4127
	$("#add4").click(function() {
4128
		addOption_v4();
4129
		$("#newgateway4").modal('hide');
4130
	});
4131

    
4132
	$("#cnx4").click(function() {
4133
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4134
		$("#gatewayip4").val('');
4135
		$("#gatewaydescr4").val('');
4136
		$("#defaultgw4").prop("checked", false);
4137
		$("#newgateway4").modal('hide');
4138
	});
4139

    
4140
	$("#add6").click(function() {
4141
		addOption_v6();
4142
		$("#newgateway6").modal('hide');
4143
	});
4144

    
4145
	$("#cnx6").click(function() {
4146
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4147
		$("#gatewayip6").val('');
4148
		$("#gatewaydescr6").val('');
4149
		$("#defaultgw6").prop("checked", false);
4150
		$("#newgateway6").modal('hide');
4151
	});
4152

    
4153
	$('#country').on('change', function() {
4154
		providers_list();
4155
	});
4156

    
4157
	$('#provider_list').on('change', function() {
4158
		providerplan_list();
4159
	});
4160

    
4161
	$('#providerplan').on('change', function() {
4162
		prefill_provider();
4163
	});
4164

    
4165
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4166
		setDHCPoptions();
4167
	});
4168

    
4169
	$('#adv_dhcp6_config_advanced').click(function () {
4170
		show_dhcp6adv();
4171
	});
4172

    
4173
	$('#adv_dhcp6_config_file_override').click(function () {
4174
		show_dhcp6adv();
4175
	});
4176

    
4177
	// On click . .
4178
	$('#pppoe_dialondemand').click(function () {
4179
		setPPPoEDialOnDemandItems();
4180
	});
4181

    
4182
	$('#pptp_dialondemand').click(function () {
4183
		setPPTPDialOnDemandItems();
4184
	});
4185

    
4186
	$('[name=adv_dhcp_pt_values]').click(function () {
4187
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4188
	});
4189

    
4190
	$('#wpa_enable').click(function () {
4191
		show_wpaoptions();
4192
	});
4193

    
4194
	$('#pppoe_resetdate').datepicker();
4195

    
4196
});
4197
//]]>
4198
</script>
4199

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