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

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

    
50
define("ANTENNAS", false);
51

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

    
58
// Get configured interface list
59
$ifdescrs = get_configured_interface_with_descr(true);
60

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
438
}
439

    
440
$changes_applied = false;
441

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

    
451
		$vlan_redo = array();
452
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
453
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
454
			foreach ($toapplylist as $ifapply => $ifcfgo) {
455
				$ifmtu = get_interface_mtu(get_real_interface($ifapply));
456
				if (isset($config['interfaces'][$ifapply]['enable'])) {
457
					interface_bring_down($ifapply, false, $ifcfgo);
458
					interface_configure($ifapply, true);
459
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
460
						/* call interface_track6_configure with linkup true so
461
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
462
						   just call interface_configure with linkup true as
463
						   that skips bridge membership addition.
464
						*/
465
						$wancfg = $config['interfaces'][$ifapply];
466
						interface_track6_configure($ifapply, $wancfg, true);
467
					}
468
					/* restart RADVD to announce correct IPv6 prefix
469
					 * see https://redmine.pfsense.org/issues/12604 */ 
470
					if ((($ifcfg['ipaddrv6'] == "staticv6") || ($ifcfg['ipaddrv6'] == "track6")) &&
471
					    is_array($config['dhcpdv6'][$ifapply]) &&
472
					    isset($config['dhcpdv6'][$ifapply]['ramode']) &&
473
					    ($config['dhcpdv6'][$ifapply]['ramode'] != "disabled")) {
474
						services_radvd_configure();
475
					}
476
				} else {
477
					interface_bring_down($ifapply, true, $ifcfgo);
478
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
479
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
480
						services_dhcpd_configure();
481
					}
482
				}
483
				if (interface_has_clones(get_real_interface($ifapply)) &&
484
				    (isset($config['interfaces'][$ifapply]['mtu']) &&
485
				    ($config['interfaces'][$ifapply]['mtu'] != $ifmtu)) ||
486
				    (!isset($config['interfaces'][$ifapply]['mtu']) &&
487
				    (get_interface_default_mtu() != $ifmtu))) { 
488
					$vlan_redo[] = get_real_interface($ifapply);
489
				}
490
			}
491
		}
492

    
493
		/*
494
                 * If the parent interface has changed MTU above, the VLANs needs to be
495
                 * redone.
496
		 */
497
		if (!empty($vlan_redo)) {
498
			foreach ($vlan_redo as $vlredo) {
499
				interfaces_vlan_configure_mtu($vlredo);
500
			}
501
		}
502

    
503
		/* restart snmp so that it binds to correct address */
504
		$retval |= services_snmpd_configure();
505

    
506
		/* sync filter configuration */
507
		setup_gateways_monitor();
508

    
509
		clear_subsystem_dirty('interfaces');
510

    
511
		$retval |= filter_configure();
512

    
513
		enable_rrd_graphing();
514

    
515
		$changes_applied = true;
516

    
517
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
518
			clear_subsystem_dirty('staticroutes');
519
		}
520

    
521
		init_config_arr(array('syslog'));
522
		if (isset($config['syslog']['enable']) && ($ifapply == $config['syslog']['sourceip'])) {
523
			system_syslogd_start();
524
		}
525
	}
526
	@unlink("{$g['tmp_path']}/.interfaces.apply");
527
} else if ($_POST['save']) {
528

    
529
	unset($input_errors);
530
	$pconfig = $_POST;
531

    
532
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
533
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
534
	} else {
535
		$pconfig['track6-prefix-id'] = 0;
536
	}
537

    
538
	/* filter out spaces from descriptions */
539
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
540

    
541
	/* okay first of all, cause we are just hiding the PPPoE HTML
542
	 * fields related to PPPoE resets, we are going to unset $_POST
543
	 * vars, if the reset feature should not be used. Otherwise the
544
	 * data validation procedure below, may trigger a false error
545
	 * message.
546
	 */
547
	if (empty($_POST['pppoe-reset-type'])) {
548
		unset($_POST['pppoe_pr_type']);
549
		unset($_POST['pppoe_resethour']);
550
		unset($_POST['pppoe_resetminute']);
551
		unset($_POST['pppoe_resetdate']);
552
		unset($_POST['pppoe_pr_preset_val']);
553
	}
554

    
555
	/* input validation */
556
	$reqdfields = explode(" ", "descr");
557
	$reqdfieldsn = array(gettext("Description"));
558
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
559

    
560
	if (!$input_errors) {
561
		/* description unique? */
562
		foreach ($ifdescrs as $ifent => $ifdescr) {
563
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
564
				$input_errors[] = gettext("An interface with the specified description already exists.");
565
				break;
566
			}
567
		}
568

    
569
		/* Is the description already used as an alias name? */
570
		if (is_array($config['aliases']['alias'])) {
571
			foreach ($config['aliases']['alias'] as $alias) {
572
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
573
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
574
				}
575
			}
576
		}
577

    
578
		/* Is the description already used as an interface group name? */
579
		if (is_array($config['ifgroups']['ifgroupentry'])) {
580
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
581
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
582
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
583
				}
584
			}
585
		}
586

    
587
		if (is_numeric($_POST['descr'])) {
588
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
589
		}
590

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

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

    
601
		/*
602
		 * Packages (e.g. tinc) create interface groups, reserve this
603
		 * namespace pkg_ for them.
604
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
605
		 */
606
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
607
			$input_errors[] = gettext("The interface description cannot start with pkg_");
608
		}
609
	}
610

    
611
	if ($_POST['blockbogons'] == "yes" &&
612
	    isset($config['system']['ipv6allow']) &&
613
	    (!isset($config['system']['maximumtableentries']) ||
614
	     $config['system']['maximumtableentries'] <
615
	     $g['minimumtableentries_bogonsv6'])) {
616
		$input_errors[] = sprintf(gettext(
617
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
618
		    $g['minimumtableentries_bogonsv6']);
619
	}
620

    
621
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
622
		if (!preg_match("/^staticv4/", $_POST['type'])) {
623
			$input_errors[] = gettext("The DHCP Server is active " .
624
			    "on this interface and it can be used only with " .
625
			    "a static IP configuration. Please disable the " .
626
			    "DHCP Server service on this interface first, " .
627
			    "then change the interface configuration.");
628
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
629
			$input_errors[] = gettext("The DHCP Server is active " .
630
			    "on this interface and it can be used only with " .
631
			    "IPv4 subnet < 31. Please disable the " .
632
			    "DHCP Server service on this interface first, " .
633
			    "then change the interface configuration.");
634
		}
635
	}
636
	if (isset($config['dhcpdv6']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
637
		if (isset($config['dhcpdv6'][$if]['enable'])) {
638
			$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only " .
639
			    "with a static IPv6 configuration. Please disable the DHCPv6 Server service on this " .
640
			    "interface first, then change the interface configuration.");
641
		}
642
		if (isset($config['dhcpdv6'][$if]['ramode']) && ($config['dhcpdv6'][$if]['ramode'] != "disabled")) {
643
			$input_errors[] = gettext("The Router Advertisements Server is active on this interface and it can " .
644
			    "be used only with a static IPv6 configuration. Please disable the Router Advertisements " .
645
			    "Server service on this interface first, then change the interface configuration.");
646
		}
647
	}
648

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

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

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

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

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

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

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

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

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

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

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

    
944
		unset($min_mtu, $max_mtu);
945

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1186
		unset($wancfg['dhcpvlanenable']);
1187
		unset($wancfg['dhcpcvpt']);
1188

    
1189
		unset($wancfg['adv_dhcp_pt_timeout']);
1190
		unset($wancfg['adv_dhcp_pt_retry']);
1191
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1192
		unset($wancfg['adv_dhcp_pt_reboot']);
1193
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1194
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1195

    
1196
		unset($wancfg['adv_dhcp_pt_values']);
1197

    
1198
		unset($wancfg['adv_dhcp_send_options']);
1199
		unset($wancfg['adv_dhcp_request_options']);
1200
		unset($wancfg['adv_dhcp_required_options']);
1201
		unset($wancfg['adv_dhcp_option_modifiers']);
1202

    
1203
		unset($wancfg['adv_dhcp_config_advanced']);
1204
		unset($wancfg['adv_dhcp_config_file_override']);
1205
		unset($wancfg['adv_dhcp_config_file_override_path']);
1206

    
1207
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1208
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1209
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1210
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1211

    
1212
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1213
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1214
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1215
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1216
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1217

    
1218
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1219
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1220
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1221
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1222
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1223

    
1224
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1225
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1226
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1227

    
1228
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1229
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1230
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1231
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1232

    
1233
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1234
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1235
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1236
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1237
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1238

    
1239
		unset($wancfg['adv_dhcp6_config_advanced']);
1240
		unset($wancfg['adv_dhcp6_config_file_override']);
1241
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1242

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

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

    
1278
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1279
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1280

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

    
1297
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1298
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1299
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1300
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1301
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1302
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1303

    
1304
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1305

    
1306
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1307
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1308
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1309
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1310

    
1311
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1312
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1313
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1314

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

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

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

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

    
1460
				if ($_POST['dhcp6withoutra'] == "yes") {
1461
					$wancfg['dhcp6withoutra'] = true;
1462
				}
1463
				if ($_POST['dhcp6norelease'] == "yes") {
1464
					$wancfg['dhcp6norelease'] = true;
1465
				}
1466
				if ($_POST['dhcp6vlanenable'] == "yes") {
1467
					$wancfg['dhcp6vlanenable'] = true;
1468
				}
1469
				if (!empty($_POST['dhcp6cvpt'])) {
1470
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1471
				} else {
1472
					unset($wancfg['dhcp6cvpt']);
1473
				}
1474

    
1475
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1476
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1477
				}
1478
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1479
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1480
				}
1481
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1482
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1483
				}
1484
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1485
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1486
				}
1487

    
1488
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1489
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1490
				}
1491
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1492
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1493
				}
1494
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1495
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1496
				}
1497
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1498
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1499
				}
1500
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1501
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1502
				}
1503

    
1504
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1505
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1506
				}
1507
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1508
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1509
				}
1510
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1511
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1512
				}
1513
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1514
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1515
				}
1516
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1517
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1518
				}
1519

    
1520
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1521
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1522
				}
1523
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1524
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1525
				}
1526
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1527
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1528
				}
1529
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1530
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1531
				}
1532
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1533
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1534
				}
1535
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1536
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1537
				}
1538
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1539
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1540
				}
1541

    
1542
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1543
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1544
				}
1545
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1546
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1547
				}
1548
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1549
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1550
				}
1551
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1552
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1553
				}
1554
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1555
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1556
				}
1557

    
1558
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1559
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1560
				}
1561
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1562
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1563
				}
1564
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1565
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1566
				}
1567

    
1568
				if ($gateway_item) {
1569
					$a_gateways[] = $gateway_item;
1570
				}
1571
				break;
1572
			case "6rd":
1573
				$wancfg['ipaddrv6'] = "6rd";
1574
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1575
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1576
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1577
				if ($gateway_item) {
1578
					$a_gateways[] = $gateway_item;
1579
				}
1580
				break;
1581
			case "6to4":
1582
				$wancfg['ipaddrv6'] = "6to4";
1583
				break;
1584
			case "track6":
1585
				$wancfg['ipaddrv6'] = "track6";
1586
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1587
				if ($_POST['track6-prefix-id--hex'] === "") {
1588
					$wancfg['track6-prefix-id'] = 0;
1589
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1590
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1591
				} else {
1592
					$wancfg['track6-prefix-id'] = 0;
1593
				}
1594
				break;
1595
			case "none":
1596
				break;
1597
		}
1598
		handle_pppoe_reset($_POST);
1599

    
1600
		if ($_POST['blockpriv'] == "yes") {
1601
			$wancfg['blockpriv'] = true;
1602
		} else {
1603
			unset($wancfg['blockpriv']);
1604
		}
1605
		if ($_POST['blockbogons'] == "yes") {
1606
			$wancfg['blockbogons'] = true;
1607
		} else {
1608
			unset($wancfg['blockbogons']);
1609
		}
1610
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1611
		if (empty($_POST['mtu'])) {
1612
			unset($wancfg['mtu']);
1613
		} else {
1614
			$wancfg['mtu'] = $_POST['mtu'];
1615
		}
1616
		if (empty($_POST['mss'])) {
1617
			unset($wancfg['mss']);
1618
		} else {
1619
			$wancfg['mss'] = $_POST['mss'];
1620
		}
1621
		if (empty($_POST['mediaopt'])) {
1622
			unset($wancfg['media']);
1623
			unset($wancfg['mediaopt']);
1624
		} else {
1625
			$mediaopts = explode(' ', $_POST['mediaopt']);
1626
			if ($mediaopts[0] != '') {
1627
				$wancfg['media'] = $mediaopts[0];
1628
			}
1629
			if ($mediaopts[1] != '') {
1630
				$wancfg['mediaopt'] = $mediaopts[1];
1631
			} else {
1632
				unset($wancfg['mediaopt']);
1633
			}
1634
		}
1635
		if (isset($wancfg['wireless'])) {
1636
			handle_wireless_post();
1637
		}
1638

    
1639
		write_config("Interfaces settings changed");
1640

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

    
1645
		if ($_POST['gatewayip6']) {
1646
			save_gateway($gateway_settings6);
1647
		}
1648

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

    
1658
		mark_subsystem_dirty('interfaces');
1659

    
1660
		/* regenerate cron settings/crontab file */
1661
		configure_cron();
1662

    
1663
		header("Location: interfaces.php?if={$if}");
1664
		exit;
1665
	}
1666

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

    
1672
} // end if ($_POST['save'])
1673

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

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

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

    
1830
	interface_sync_wireless_clones($wancfg, true);
1831
}
1832

    
1833
function check_wireless_mode() {
1834
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1835

    
1836
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1837
		return;
1838
	}
1839

    
1840
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1841
		$clone_count = 1;
1842
	} else {
1843
		$clone_count = 0;
1844
	}
1845

    
1846
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1847
		foreach ($config['wireless']['clone'] as $clone) {
1848
			if ($clone['if'] == $wlanbaseif) {
1849
				$clone_count++;
1850
			}
1851
		}
1852
	}
1853

    
1854
	if ($clone_count > 1) {
1855
		$old_wireless_mode = $wancfg['wireless']['mode'];
1856
		$wancfg['wireless']['mode'] = $_POST['mode'];
1857
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1858
			$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']]);
1859
		} else {
1860
			pfSense_interface_destroy("{$wlanif}_");
1861
		}
1862
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1863
	}
1864
}
1865

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

    
1881
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1882
$shortcut_section = "interfaces";
1883

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

    
1886
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1887
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1888
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1889
}
1890

    
1891
$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"));
1892

    
1893
// Get the MAC address
1894
$defgatewayname4 = $wancfg['descr'] . "GW";
1895
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1896

    
1897
function build_mediaopts_list() {
1898
	global $mediaopts_list;
1899

    
1900
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1901
			 " " =>	 gettext("------- Media Supported by this interface -------")
1902
			];
1903

    
1904
	foreach ($mediaopts_list as $mediaopt) {
1905
		$list[$mediaopt] = $mediaopt;
1906
	}
1907

    
1908
	return($list);
1909
}
1910

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

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

    
1921
	return($list);
1922
}
1923

    
1924
function build_gatewayv6_list() {
1925
	global $a_gateways, $if;
1926

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

    
1934
	return($list);
1935
}
1936

    
1937
include("head.inc");
1938

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

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

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

    
1953
$form = new Form();
1954

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

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

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

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

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

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

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

    
2026
$section->addInput(new Form_Input(
2027
	'mtu',
2028
	'MTU',
2029
	'number',
2030
	$pconfig['mtu']
2031
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2032
			'This is typically 1500 bytes but can vary in some circumstances.');
2033

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

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

    
2052
$form->add($section);
2053

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

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

    
2064
$group = new Form_Group('IPv4 Upstream gateway');
2065

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

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

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

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

    
2087
$form->add($section);
2088

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

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

    
2099
$form->add($section);
2100

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

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

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

    
2118
$group = new Form_Group('IPv6 Upstream gateway');
2119

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

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

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

    
2137
$section->add($group);
2138
$form->add($section);
2139

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

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

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

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

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

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

    
2178
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2179

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

    
2187
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2188

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

    
2194
$form->add($modal);
2195

    
2196
// ==== DHCP client configuration =============================
2197

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

    
2201
$group = new Form_Group('Options');
2202

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

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

    
2217
$section->add($group);
2218

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

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

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

    
2242
if (interface_is_vlan($wancfg['if']) != NULL) {
2243

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

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

    
2259
	$section->add($group);
2260
}
2261

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

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

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

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

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

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

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

    
2310
$section->add($group);
2311

    
2312
$group = new Form_Group('Presets');
2313
$group->addClass('dhcpadvanced');
2314

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

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

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

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

    
2347
$section->add($group);
2348

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

    
2359
$form->add($section);
2360

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

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

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

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

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

    
2398
$form->add($section);
2399

    
2400
// DHCP6 client config
2401

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

    
2405
$group = new Form_Group('Options');
2406

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

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

    
2421
$section->add($group);
2422

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

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

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

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

    
2451
$section->addInput(new Form_Checkbox(
2452
	'dhcp6debug',
2453
	'Debug',
2454
	'Start DHCP6 client in debug mode',
2455
	$pconfig['dhcp6debug']
2456
));
2457
$section->addInput(new Form_Checkbox(
2458
	'dhcp6withoutra',
2459
	'Do not wait for a RA',
2460
	'Required by some ISPs, especially those not using PPPoE',
2461
	$pconfig['dhcp6withoutra']
2462
));
2463
$section->addInput(new Form_Checkbox(
2464
	'dhcp6norelease',
2465
	'Do not allow PD/Address release',
2466
	'dhcp6c will send a release to the ISP on exit, some ISPs then release the allocated address or prefix. This option prevents that signal ever being sent',
2467
	$pconfig['dhcp6norelease']
2468
));
2469

    
2470
if (interface_is_vlan($wancfg['if']) != NULL) {
2471
	$group = new Form_Group('DHCP6 VLAN Priority');
2472

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

    
2480
	$group->add(new Form_Select(
2481
		'dhcp6cvpt',
2482
		'VLAN Prio',
2483
		$pconfig['dhcp6cvpt'],
2484
		$vlanprio
2485
	))->setHelp('Choose 802.1p priority to set.');
2486

    
2487
	$section->add($group);
2488
}
2489

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

    
2500
$form->add($section);
2501

    
2502
// DHCP6 client config - Advanced
2503

    
2504
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2505
$section->addClass('dhcp6advanced');
2506

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

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

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

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

    
2541
$group = new Form_Group('Identity Association Statement');
2542

    
2543
$group->add(new Form_Checkbox(
2544
	'adv_dhcp6_id_assoc_statement_address_enable',
2545
	null,
2546
	'Non-Temporary Address Allocation',
2547
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2548
	'Selected'
2549
));
2550

    
2551
$group->add(new Form_Input(
2552
	'adv_dhcp6_id_assoc_statement_address_id',
2553
	null,
2554
	'text',
2555
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2556
))->sethelp('id-assoc na ID');
2557

    
2558
$group->add(new Form_IpAddress(
2559
	'adv_dhcp6_id_assoc_statement_address',
2560
	null,
2561
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2562
	'V6'
2563
))->sethelp('IPv6 address');
2564

    
2565
$group->add(new Form_Input(
2566
	'adv_dhcp6_id_assoc_statement_address_pltime',
2567
	null,
2568
	'text',
2569
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2570
))->sethelp('pltime');
2571

    
2572
$group->add(new Form_Input(
2573
	'adv_dhcp6_id_assoc_statement_address_vltime',
2574
	null,
2575
	'text',
2576
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2577
))->sethelp('vltime');
2578

    
2579
$section->add($group);
2580

    
2581
// Prefix delegation
2582
$group = new Form_Group('');
2583

    
2584
$group->add(new Form_Checkbox(
2585
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2586
	null,
2587
	'Prefix Delegation ',
2588
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2589
	'Selected'
2590
));
2591

    
2592
$group->add(new Form_Input(
2593
	'adv_dhcp6_id_assoc_statement_prefix_id',
2594
	null,
2595
	'text',
2596
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2597
))->sethelp('id-assoc pd ID');
2598

    
2599
$group->add(new Form_IpAddress(
2600
	'adv_dhcp6_id_assoc_statement_prefix',
2601
	null,
2602
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2603
	'V6'
2604
))->sethelp('IPv6 prefix');
2605

    
2606
$group->add(new Form_Input(
2607
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2608
	null,
2609
	'text',
2610
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2611
))->sethelp('pltime');
2612

    
2613
$group->add(new Form_Input(
2614
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2615
	null,
2616
	'text',
2617
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2618
))->sethelp('vltime');
2619

    
2620
$section->add($group);
2621

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

    
2624
$group->add(new Form_Input(
2625
	'adv_dhcp6_prefix_interface_statement_sla_id',
2626
	null,
2627
	'text',
2628
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2629
))->sethelp('Prefix Interface sla-id');
2630

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

    
2638
$section->add($group);
2639

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

    
2648
$group = new Form_Group('Authentication statement');
2649

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

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

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

    
2671
$group->add(new Form_Input(
2672
	'adv_dhcp6_authentication_statement_rdm',
2673
	null,
2674
	'text',
2675
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2676
))->sethelp('RDM');
2677

    
2678
$section->add($group);
2679

    
2680
$group = new Form_Group('Keyinfo statement');
2681

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

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

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

    
2698
$group = new Form_Group('');
2699

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

    
2707
$group->add(new Form_Input(
2708
	'adv_dhcp6_key_info_statement_secret',
2709
	null,
2710
	'text',
2711
	$pconfig['adv_dhcp6_key_info_statement_secret']
2712
))->sethelp('Secret');
2713

    
2714
$group->add(new Form_Input(
2715
	'adv_dhcp6_key_info_statement_expire',
2716
	null,
2717
	'text',
2718
	$pconfig['adv_dhcp6_key_info_statement_expire']
2719
))->sethelp('Expire');
2720

    
2721
$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>');
2722

    
2723
$section->add($group);
2724

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

    
2727
$section = new Form_Section('6RD Configuration');
2728
$section->addClass('_6rd');
2729

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

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

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

    
2751
$form->add($section);
2752

    
2753
// Track IPv6 ointerface section
2754
$section = new Form_Section('Track IPv6 Interface');
2755
$section->addClass('track6');
2756

    
2757
function build_ipv6interface_list() {
2758
	global $config, $form;
2759

    
2760
	$list = array('' => '');
2761

    
2762
	$interfaces = get_configured_interface_with_descr(true);
2763
	$dynv6ifs = array();
2764

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

    
2780
	foreach ($dynv6ifs as $iface => $ifacedata) {
2781
		$list[$iface] = $ifacedata['name'];
2782

    
2783
		$form->addGlobal(new Form_Input(
2784
			'ipv6-num-prefix-ids-' . $iface,
2785
			null,
2786
			'hidden',
2787
			$ifacedata['ipv6_num_prefix_ids']
2788
		));
2789
	}
2790

    
2791
	return($list);
2792
}
2793

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

    
2801
if ($pconfig['track6-prefix-id'] == "") {
2802
	$pconfig['track6-prefix-id'] = 0;
2803
}
2804

    
2805
$section->addInput(new Form_Input(
2806
	'track6-prefix-id--hex',
2807
	'IPv6 Prefix ID',
2808
	'text',
2809
	sprintf("%x", $pconfig['track6-prefix-id'])
2810
))->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>');
2811

    
2812
$form->addGlobal(new Form_Input(
2813
	'track6-prefix-id-max',
2814
	null,
2815
	'hidden',
2816
	0
2817
));
2818

    
2819
$form->add($section);
2820

    
2821
/// PPP section
2822

    
2823
$section = new Form_Section('PPP Configuration');
2824
$section->addClass('ppp');
2825

    
2826
$section->addInput(new Form_Select(
2827
	'country',
2828
	'Country',
2829
	$pconfig['country'],
2830
	[]
2831
));
2832

    
2833
$section->addInput(new Form_Select(
2834
	'provider_list',
2835
	'Provider',
2836
	$pconfig['provider_list'],
2837
	[]
2838
));
2839

    
2840
$section->addInput(new Form_Select(
2841
	'providerplan',
2842
	'Plan',
2843
	$pconfig['providerplan'],
2844
	[]
2845
))->setHelp('Select to fill in service provider data.');
2846

    
2847
$section->addInput(new Form_Input(
2848
	'ppp_username',
2849
	'Username',
2850
	'text',
2851
	$pconfig['ppp_username'],
2852
	['autocomplete' => 'new-password']
2853
));
2854

    
2855
$section->addPassword(new Form_Input(
2856
	'ppp_password',
2857
	'Password',
2858
	'password',
2859
	$pconfig['ppp_password']
2860
));
2861

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

    
2869
$section->addInput(new Form_Input(
2870
	'apn',
2871
	'Access Point Name',
2872
	'text',
2873
	$pconfig['apn']
2874
));
2875

    
2876

    
2877
function build_port_list() {
2878
	$list = array("" => "None");
2879

    
2880
	$portlist = glob("/dev/cua*");
2881
	$modems	  = glob("/dev/modem*");
2882
	$portlist = array_merge($portlist, $modems);
2883

    
2884
	foreach ($portlist as $port) {
2885
		if (preg_match("/\.(lock|init)$/", $port)) {
2886
			continue;
2887
		}
2888

    
2889
	$list[trim($port)] = $port;
2890
	}
2891

    
2892
	return($list);
2893
}
2894

    
2895
$section->addInput(new Form_Select(
2896
	'port',
2897
	"*Modem port",
2898
	$pconfig['port'],
2899
	build_port_list()
2900
));
2901

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

    
2909
$form->add($section);
2910

    
2911
// PPPoE configuration
2912
$section = new Form_Section('PPPoE Configuration');
2913
$section->addClass('pppoe');
2914

    
2915
$section->addInput(new Form_Input(
2916
	'pppoe_username',
2917
	'*Username',
2918
	'text',
2919
	$pconfig['pppoe_username'],
2920
	['autocomplete' => 'new-password']
2921
));
2922

    
2923
$section->addPassword(new Form_Input(
2924
	'pppoe_password',
2925
	'*Password',
2926
	'password',
2927
	$pconfig['pppoe_password']
2928
));
2929

    
2930
$section->addInput(new Form_Input(
2931
	'provider',
2932
	'Service name',
2933
	'text',
2934
	$pconfig['provider']
2935
))->setHelp('This field can usually be left empty.');
2936

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

    
2944
$section->addInput(new Form_Checkbox(
2945
	'pppoe_dialondemand',
2946
	'Dial on demand',
2947
	'Enable Dial-On-Demand mode ',
2948
	$pconfig['pppoe_dialondemand'],
2949
	'enable'
2950
));
2951

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

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

    
2968
$group = new Form_Group('Custom reset');
2969
$group->addClass('pppoecustom');
2970

    
2971
$group->add(new Form_Input(
2972
	'pppoe_resethour',
2973
	null,
2974
	'number',
2975
	$pconfig['pppoe_resethour'],
2976
	['min' => 0, 'max' => 23]
2977
))->setHelp('Hour (0-23)');
2978

    
2979
$group->add(new Form_Input(
2980
	'pppoe_resetminute',
2981
	null,
2982
	'number',
2983
	$pconfig['pppoe_resetminute'],
2984
	['min' => 0, 'max' => 59]
2985
))->setHelp('Minutes (0-59)');
2986

    
2987
$group->add(new Form_Input(
2988
	'pppoe_resetdate',
2989
	null,
2990
	'text',
2991
	$pconfig['pppoe_resetdate']
2992
))->setHelp('Specific date (mm/dd/yyyy)');
2993

    
2994
$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');
2995

    
2996
$section->add($group);
2997

    
2998
$group = new Form_MultiCheckboxGroup('cron based reset');
2999
$group->addClass('pppoepreset');
3000

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

    
3009
$group->add(new Form_MultiCheckbox(
3010
	'pppoe_pr_preset_val',
3011
	null,
3012
	'Reset at each week ("0 0 * * 0")',
3013
	$pconfig['pppoe_weekly'],
3014
	'weekly'
3015
))->displayAsRadio();
3016

    
3017
$group->add(new Form_MultiCheckbox(
3018
	'pppoe_pr_preset_val',
3019
	null,
3020
	'Reset at each day ("0 0 * * *")',
3021
	$pconfig['pppoe_daily'],
3022
	'daily'
3023
))->displayAsRadio();
3024

    
3025
$group->add(new Form_MultiCheckbox(
3026
	'pppoe_pr_preset_val',
3027
	null,
3028
	'Reset at each hour ("0 * * * *")',
3029
	$pconfig['pppoe_hourly'],
3030
	'hourly'
3031
))->displayAsRadio();
3032

    
3033
$section->add($group);
3034

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

    
3042
$form->add($section);
3043

    
3044
// PPTP & L2TP Configuration section
3045
$section = new Form_Section('PPTP/L2TP Configuration');
3046
$section->addClass('pptp');
3047

    
3048
$section->addInput(new Form_Input(
3049
	'pptp_username',
3050
	'*Username',
3051
	'text',
3052
	$pconfig['pptp_username'],
3053
	['autocomplete' => 'new-password']
3054
));
3055

    
3056
$section->addPassword(new Form_Input(
3057
	'pptp_password',
3058
	'*Password',
3059
	'password',
3060
	$pconfig['pptp_password']
3061
));
3062

    
3063
$group = new Form_Group('Shared Secret');
3064

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

    
3073
$group->addClass('l2tp_secret');
3074
$section->add($group);
3075

    
3076
$section->addInput(new Form_IpAddress(
3077
	'pptp_local0',
3078
	'*Local IP address',
3079
	$pconfig['pptp_localip'][0],
3080
	'V4'
3081
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
3082

    
3083
$section->addInput(new Form_IpAddress(
3084
	'pptp_remote0',
3085
	'*Remote IP address',
3086
	$pconfig['pptp_remote'][0],
3087
	'HOSTV4'
3088
));
3089

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

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

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

    
3114
$section->addInput(new Form_Button(
3115
	'btnadvppp',
3116
	'Advanced and MLPPP',
3117
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3118
	'fa-cog'
3119
))->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);
3120

    
3121
$form->add($section);
3122

    
3123
// Wireless interface
3124
if (isset($wancfg['wireless'])) {
3125

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

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

    
3136
	$mode_list = ['auto' => 'Auto'];
3137

    
3138
	if (is_array($wl_modes)) {
3139
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3140
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3141
		}
3142
	}
3143

    
3144
	if (count($mode_list) == 1) {
3145
		$mode_list[''] = '';
3146
	}
3147

    
3148
	$section->addInput(new Form_Select(
3149
		'standard',
3150
		'Standard',
3151
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3152
		$mode_list
3153
	));
3154

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

    
3171
	$mode_list = ['0' => gettext('Auto')];
3172

    
3173
	if (is_array($wl_modes)) {
3174
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3175
			if ($wl_standard == "11g") {
3176
				$wl_standard = "11b/g";
3177
			} else if ($wl_standard == "11ng") {
3178
				$wl_standard = "11b/g/n";
3179
			} else if ($wl_standard == "11na") {
3180
				$wl_standard = "11a/n";
3181
			}
3182

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

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

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

    
3208
	if (ANTENNAS) {
3209
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3210
			$group = new Form_Group('Antenna Settings');
3211

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

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

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

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

    
3241
			$section->add($group);
3242
		}
3243
	}
3244

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

    
3254
	$form->add($section);
3255

    
3256
	// Regulatory settings
3257
	$section = new Form_Section('Regulatory Settings');
3258

    
3259
	$domain_list = array("" => 'Default');
3260

    
3261
	if (is_array($wl_regdomains)) {
3262
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3263
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3264
		}
3265
	}
3266

    
3267
	$section->addInput(new Form_Select(
3268
		'regdomain',
3269
		'Regulatory domain',
3270
		$pconfig['regdomain'],
3271
		$domain_list
3272
	))->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');
3273

    
3274
	$country_list = array('' => 'Default');
3275

    
3276
	if (is_array($wl_countries)) {
3277
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3278
			$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']);
3279
		}
3280
	}
3281

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

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

    
3300
	$form->add($section);
3301

    
3302
	$section = new Form_Section('Network-Specific Wireless Configuration');
3303

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

    
3311
	$section->addInput(new Form_Input(
3312
		'ssid',
3313
		'SSID',
3314
		'text',
3315
		$pconfig['ssid']
3316
	));
3317

    
3318
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3319
		$section->addInput(new Form_Select(
3320
			'puremode',
3321
			'Minimum wireless standard',
3322
			$pconfig['puremode'],
3323
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3324
		))->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)');
3325
	} elseif (isset($wl_modes['11g'])) {
3326
		$section->addInput(new Form_Checkbox(
3327
			'puremode',
3328
			'802.11g only',
3329
			null,
3330
			$pconfig['puremode'],
3331
			'11g'
3332
		))->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)');
3333
	}
3334

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

    
3343
	$section->addInput(new Form_Checkbox(
3344
		'wme_enable',
3345
		'Enable WME',
3346
		'Force the card to use WME (wireless QoS)',
3347
		$pconfig['wme_enable'],
3348
		'yes'
3349
	));
3350

    
3351
	$section->addInput(new Form_Checkbox(
3352
		'hidessid_enable',
3353
		'Hide SSID',
3354
		'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.)',
3355
		$pconfig['hidessid_enable'],
3356
		'yes'
3357
	));
3358

    
3359
	$form->add($section);
3360

    
3361
	// WPA Section
3362
	$section = new Form_Section('WPA');
3363

    
3364
	$section->addInput(new Form_Checkbox(
3365
		'wpa_enable',
3366
		'Enable',
3367
		'Enable WPA',
3368
		$pconfig['wpa_enable'],
3369
		'yes'
3370
	));
3371

    
3372
	$section->addInput(new Form_Select(
3373
		'wpa_mode',
3374
		'WPA mode',
3375
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3376
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3377
	));
3378

    
3379
	$section->addInput(new Form_Select(
3380
		'wpa_pairwise',
3381
		'WPA Pairwise',
3382
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3383
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3384
	));
3385

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

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

    
3400
	$section->addInput(new Form_Select(
3401
		'wpa_eap_client_mode',
3402
		'EAP Client Mode',
3403
		$pconfig['wpa_eap_client_mode'],
3404
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3405
	));
3406

    
3407
	$section->addInput(new Form_Select(
3408
		'wpa_eap_ca',
3409
		'Certificate Authority',
3410
		$pconfig['wpa_eap_ca'],
3411
		cert_build_list('ca', 'HTTPS')
3412
	));
3413

    
3414
	$section->addInput(new Form_Select(
3415
		'wpa_eap_inner_auth',
3416
		'Inner Authentication Method',
3417
		$pconfig['wpa_eap_inner_auth'],
3418
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3419
	));
3420

    
3421
	$section->addInput(new Form_Input(
3422
		'wpa_eap_inner_id',
3423
		'*Inner Authentication Identity',
3424
		'text',
3425
		$pconfig['wpa_eap_inner_id']
3426
	));
3427

    
3428
	$section->addInput(new Form_Input(
3429
		'wpa_eap_inner_password',
3430
		'*Inner Authentication Passphrase',
3431
		'text',
3432
		$pconfig['wpa_eap_inner_password']
3433
	));
3434

    
3435
	$section->addInput(new Form_Select(
3436
		'wpa_eap_cert',
3437
		'TLS/TTLS Client Certificate',
3438
		$pconfig['wpa_eap_cert'],
3439
		cert_build_list('cert', 'HTTPS')
3440
	));
3441

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

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

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

    
3466
	$form->add($section);
3467

    
3468
	$section = new Form_Section('802.1x RADIUS Options');
3469
	$section->addClass('ieee8021x_group');
3470

    
3471
	$section->addInput(new Form_Checkbox(
3472
		'ieee8021x',
3473
		'IEEE802.1X',
3474
		'Enable 802.1X authentication',
3475
		$pconfig['ieee8021x'],
3476
		'yes'
3477
	));
3478

    
3479
	$group = new Form_Group('Primary 802.1X server');
3480

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

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

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

    
3501
	$section->add($group);
3502

    
3503
	$group = new Form_Group('Secondary 802.1X server');
3504

    
3505
	$group->add(new Form_IpAddress(
3506
		'auth_server_addr2',
3507
		'IP Address',
3508
		$pconfig['auth_server_addr2']
3509
	))->setHelp('IP address of the RADIUS server');
3510

    
3511
	$group->add(new Form_Input(
3512
		'auth_server_port2',
3513
		'Port',
3514
		'number',
3515
		$pconfig['auth_server_port2']
3516
	))->setHelp('Server auth port. Default is 1812');
3517

    
3518
	$group->add(new Form_Input(
3519
		'auth_server_shared_secret2',
3520
		'Shared Secret',
3521
		'text',
3522
		$pconfig['auth_server_shared_secret2']
3523
	))->setHelp('RADIUS Shared secret for this firewall');
3524

    
3525
	$section->add($group);
3526

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

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

    
3538
$section = new Form_Section('Reserved Networks');
3539

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

    
3550
$section->addInput(new Form_Checkbox(
3551
	'blockbogons',
3552
	'Block bogon networks',
3553
	'',
3554
	$pconfig['blockbogons'],
3555
	'yes'
3556
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3557
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3558
			'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' .
3559
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3560

    
3561
$form->add($section);
3562

    
3563
$form->addGlobal(new Form_Input(
3564
	'if',
3565
	null,
3566
	'hidden',
3567
	$if
3568
));
3569

    
3570
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3571
	$form->addGlobal(new Form_Input(
3572
		'ppp_port',
3573
		null,
3574
		'hidden',
3575
		$pconfig['port']
3576
	));
3577
}
3578

    
3579
$form->addGlobal(new Form_Input(
3580
	'ptpid',
3581
	null,
3582
	'hidden',
3583
	$pconfig['ptpid']
3584
));
3585

    
3586

    
3587
// Add new gateway modal pop-up
3588
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3589

    
3590
$modal->addInput(new Form_Checkbox(
3591
	'defaultgw4',
3592
	'Default',
3593
	'Default gateway',
3594
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3595
));
3596

    
3597
$modal->addInput(new Form_Input(
3598
	'gatewayname4',
3599
	'Gateway name',
3600
	'text',
3601
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3602
));
3603

    
3604
$modal->addInput(new Form_IpAddress(
3605
	'gatewayip4',
3606
	'Gateway IPv4',
3607
	$gateway_settings4['gateway'],
3608
	'V4'
3609
));
3610

    
3611
$modal->addInput(new Form_Input(
3612
	'gatewaydescr4',
3613
	'Description',
3614
	'text',
3615
	$gateway_settings4['descr']
3616
));
3617

    
3618
$btnaddgw4 = new Form_Button(
3619
	'add4',
3620
	'Add',
3621
	null,
3622
	'fa-plus'
3623
);
3624

    
3625
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3626

    
3627
$btncnxgw4 = new Form_Button(
3628
	'cnx4',
3629
	'Cancel',
3630
	null,
3631
	'fa-undo'
3632
);
3633

    
3634
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3635

    
3636
$modal->addInput(new Form_StaticText(
3637
	null,
3638
	$btnaddgw4 . $btncnxgw4
3639
));
3640

    
3641
$form->add($modal);
3642

    
3643
print($form);
3644
?>
3645

    
3646
<script type="text/javascript">
3647
//<![CDATA[
3648
events.push(function() {
3649
	function updateType(t) {
3650

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

    
3689
		if (t != "l2tp" && t != "pptp") {
3690
			$('.'+t).show();
3691
		}
3692
	}
3693

    
3694
	function updateTypeSix(t) {
3695
		if (!isNaN(t[0])) {
3696
			t = '_' + t;
3697
		}
3698

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

    
3731
		if (t != "l2tp" && t != "pptp") {
3732
			$('.'+t).show();
3733
		}
3734
	}
3735

    
3736
	function show_reset_settings(reset_type) {
3737
		if (reset_type == 'preset') {
3738
			$('.pppoepreset').show();
3739
			$('.pppoecustom').hide();
3740
		} else if (reset_type == 'custom') {
3741
			$('.pppoecustom').show();
3742
			$('.pppoepreset').hide();
3743
		} else {
3744
			$('.pppoecustom').hide();
3745
			$('.pppoepreset').hide();
3746
		}
3747
	}
3748

    
3749
	function update_track6_prefix() {
3750
		var iface = $("#track6-interface").val();
3751
		if (iface == null) {
3752
			return;
3753
		}
3754

    
3755
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3756
		if (track6_prefix_ids == null) {
3757
			return;
3758
		}
3759

    
3760
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3761
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3762
	}
3763

    
3764
	function addOption_v4() {
3765
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3766
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3767
	}
3768

    
3769
	function addOption_v6() {
3770
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3771
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3772
	}
3773

    
3774
	function addSelectboxOption(selectbox, text, value) {
3775
		var optn = document.createElement("OPTION");
3776
		optn.text = text;
3777
		optn.value = value;
3778
		selectbox.append(optn);
3779
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3780
	}
3781

    
3782
	function country_list() {
3783
		$('#country').children().remove();
3784
		$('#provider_list').children().remove();
3785
		$('#providerplan').children().remove();
3786
		$.ajax("getserviceproviders.php",{
3787
			success: function(response) {
3788

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3906
	// DHCP preset actions
3907
	// Set presets from value of radio buttons
3908
	function setPresets(val) {
3909
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3910
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3911
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3912
		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']);?>");
3913
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3914
	}
3915

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

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

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

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

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

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

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

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

    
4046
	function updatewpakeymgmt(m) {
4047
		var wpa = !($('#wpa_enable').prop('checked'));
4048
		if ((m == "WPA-EAP") && ($('#mode').val() == 'bss')) {
4049
			hideInput('passphrase', true);
4050
			hideInput('wpa_eap_client_mode', false);
4051
			hideInput('wpa_eap_ca', false);
4052
			updateeapclientmode($('#wpa_eap_client_mode').val());
4053
		} else if ((m != "WPA-PSK") && ($('#mode').val() == 'hostap')) {
4054
			hideClass('ieee8021x_group', false);
4055
		} else {
4056
			hideInput('passphrase', wpa);
4057
			hideInput('wpa_eap_client_mode', true);
4058
			hideInput('wpa_eap_ca', true);
4059
			hideInput('wpa_eap_cert', true);
4060
			hideInput('wpa_eap_inner_auth', true);
4061
			hideInput('wpa_eap_inner_id', true);
4062
			hideInput('wpa_eap_inner_password', true);
4063
			hideClass('ieee8021x_group', true);
4064
		}
4065
	}
4066

    
4067
	// ---------- On initial page load ------------------------------------------------------------
4068

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

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

    
4092
	// Set preset from value
4093
	setPresets(sv);
4094

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

    
4103
	// ---------- Click checkbox handlers ---------------------------------------------------------
4104

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
4179
	$('#adv_dhcp6_config_advanced').click(function () {
4180
		show_dhcp6adv();
4181
	});
4182

    
4183
	$('#adv_dhcp6_config_file_override').click(function () {
4184
		show_dhcp6adv();
4185
	});
4186

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

    
4192
	$('#pptp_dialondemand').click(function () {
4193
		setPPTPDialOnDemandItems();
4194
	});
4195

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

    
4200
	$('#wpa_enable').click(function () {
4201
		show_wpaoptions();
4202
	});
4203

    
4204
	$('#pppoe_resetdate').datepicker();
4205

    
4206
});
4207
//]]>
4208
</script>
4209

    
4210
<?php include("foot.inc");
(71-71/227)