Project

General

Profile

Download (140 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2006 Daniel S. Haischt
10
 * All rights reserved.
11
 *
12
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27
 */
28

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

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

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

    
51
define("ANTENNAS", false);
52

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

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

    
62
$if = "wan";
63

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
437
}
438

    
439
$changes_applied = false;
440

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

    
450
		$vlan_redo = array();
451
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
452
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
453
			foreach ($toapplylist as $ifapply => $ifcfgo) {
454
				$realif = get_real_interface($ifapply);
455
				$ifmtu = get_interface_mtu($realif);
456
				if (config_path_enabled("interfaces/{$ifapply}")) {
457
					interface_bring_down($ifapply, false, $ifcfgo);
458
					interface_configure($ifapply, true);
459
					if (config_get_path("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_get_path("interfaces/{$ifapply}");
466
						interface_track6_configure($ifapply, $wancfg, true);
467
					}
468
				} else {
469
					interface_bring_down($ifapply, true, $ifcfgo);
470
				}
471
				restart_interface_services($ifapply, $ifcfg['ipaddrv6']);
472
				$mtu = config_get_path("interfaces/{$ifapply}/mtu");
473
				if (interface_has_clones($realif) &&
474
				    ($mtu && ($mtu != $ifmtu)) ||
475
				    (!$mtu && (get_interface_default_mtu() != $ifmtu))) { 
476
					$vlan_redo[] = $realif;
477
				}
478
			}
479
		}
480

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

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

    
494
		clear_subsystem_dirty('interfaces');
495

    
496
		$retval |= filter_configure();
497

    
498
		enable_rrd_graphing();
499

    
500
		$changes_applied = true;
501

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
732
			if (empty($_POST['track6-interface'])) {
733
				$input_errors[] = gettext("A valid interface to track must be selected.");
734
			}
735

    
736
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
737
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
738
			} else {
739
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
740
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
741
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
742
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
743
				} else {
744
					foreach ($ifdescrs as $ifent => $ifdescr) {
745
						if ($if == $ifent) {
746
							continue;
747
						}
748
						if (config_get_path("interfaces/{$ifent}/ipaddrv6") == 'track6' &&
749
						    config_get_path("interfaces/{$ifent}/track6-interface") == $_POST['track6-interface'] &&
750
						    config_get_path("interfaces/{$ifent}/track6-prefix-id") == $track6_prefix_id) {
751
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
752
						}
753
					}
754
				}
755
			}
756
			break;
757
	}
758

    
759
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
760
	$staticroutes = get_staticroutes(true);
761
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
762
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
763
		if (!is_ipaddrv4($_POST['ipaddr'])) {
764
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
765
		} else {
766
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
767
			if (count($where_ipaddr_configured)) {
768
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
769
				foreach ($where_ipaddr_configured as $subnet_conflict) {
770
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
771
				}
772
				$input_errors[] = $subnet_conflict_text;
773
			}
774

    
775
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
776
			if ($_POST['subnet'] < 31) {
777
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
778
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
779
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
780
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
781
				}
782
			}
783

    
784
			foreach ($staticroutes as $route_subnet) {
785
				list($network, $subnet) = explode("/", $route_subnet);
786
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
787
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
788
					break;
789
				}
790
				unset($network, $subnet);
791
			}
792
		}
793
	}
794
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
795
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
796

    
797
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
798
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
799
		} else {
800
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
801
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
802
			}
803
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
804
			if (count($where_ipaddr_configured)) {
805
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
806
				foreach ($where_ipaddr_configured as $subnet_conflict) {
807
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
808
				}
809
				$input_errors[] = $subnet_conflict_text;
810
			}
811

    
812
			foreach ($staticroutes as $route_subnet) {
813
				list($network, $subnet) = explode("/", $route_subnet);
814
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
815
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
816
					break;
817
				}
818
				unset($network, $subnet);
819
			}
820
		}
821
	}
822
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
823
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
824
	}
825
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
826
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
827
	}
828
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
829
		$input_errors[] = gettext("A valid alias IP address must be specified.");
830
	}
831
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
832
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
833
	}
834
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
835
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
836
	}
837

    
838
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
839
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
840
		$match = false;
841
		foreach ($a_gateways as $gateway) {
842
			if (in_array($_POST['gateway'], $gateway)) {
843
				$match = true;
844
			}
845
		}
846
		if (!$match) {
847
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
848
		}
849
	}
850
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
851
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
852
		$match = false;
853
		foreach ($a_gateways as $gateway) {
854
			if (in_array($_POST['gatewayv6'], $gateway)) {
855
				$match = true;
856
			}
857
		}
858
		if (!$match) {
859
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
860
		}
861
	}
862

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

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

    
917
		unset($min_mtu, $max_mtu);
918

    
919
		if (interface_is_vlan($wancfg['if']) != NULL) {
920
			$realhwif_array = get_parent_interface($wancfg['if']);
921
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
922
			$parent_realhwif = $realhwif_array[0];
923
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
924
			$mtu = 0;
925
			if (!empty($parent_if) && !(config_get_path("interfaces/{$parent_if}/mtu")))
926
				$mtu = intval(config_get_path("interfaces/{$parent_if}/mtu"));
927
			if ($mtu == 0)
928
				$mtu = get_interface_mtu($parent_realhwif);
929
			if ($_POST['mtu'] > $mtu)
930
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
931
		} else {
932
			foreach ($config['interfaces'] as $idx => $ifdata) {
933
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
934
					continue;
935
				}
936

    
937
				$realhwif_array = get_parent_interface($ifdata['if']);
938
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
939
				$parent_realhwif = $realhwif_array[0];
940

    
941
				if ($parent_realhwif != $wancfg['if']) {
942
					continue;
943
				}
944

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

    
1041
		if ($_POST['passphrase']) {
1042
			$passlen = strlen($_POST['passphrase']);
1043
			if ($passlen < 8 || $passlen > 63) {
1044
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1045
			}
1046
		}
1047

    
1048
		if ($_POST['wpa_enable'] == "yes") {
1049
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1050
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1051
			}
1052
			if (($_POST['mode'] == 'bss') & ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1053
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1054
				if (empty($_POST['wpa_eap_inner_id'])) {
1055
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1056
					    "when PEAP/TTLS authentication method is selected.");
1057
				}
1058
				if (empty($_POST['wpa_eap_inner_password'])) {
1059
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1060
					    "when PEAP/TTLS authentication method is selected.");
1061
				}
1062
			}
1063
		}
1064
	}
1065

    
1066
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1067
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1068
	}
1069

    
1070
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1071
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1072
	}
1073

    
1074
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1075
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1076
	}
1077

    
1078
	if ($_POST['gatewayip4']) {
1079
		// The user wants to add an IPv4 gateway - validate the settings
1080
		$gateway_settings4 = array();
1081

    
1082
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1083
		$gateway_settings4['interface'] = $_POST['if'];
1084
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1085
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1086
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1087
		$gateway_settings4['ipprotocol'] = 'inet';
1088
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1089
		foreach ($gw_input_errors as $input_error_text) {
1090
			$input_errors[] = $input_error_text;
1091
		}
1092
	}
1093

    
1094
	if ($_POST['gatewayip6']) {
1095
		// The user wants to add an IPv6 gateway - validate the settings
1096
		$gateway_settings6 = array();
1097

    
1098
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1099
		$gateway_settings6['interface'] = $_POST['if'];
1100
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1101
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1102
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1103
		$gateway_settings6['ipprotocol'] = 'inet6';
1104
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1105
		foreach ($gw_input_errors as $input_error_text) {
1106
			$input_errors[] = $input_error_text;
1107
		}
1108
	}
1109

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

    
1117
		if ($wancfg['ipaddr'] != $_POST['type']) {
1118
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1119
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1120
				unset($a_ppps[$pppid]);
1121
			} else if ($wancfg['ipaddr'] == "dhcp") {
1122
				kill_dhclient_process($wancfg['if']);
1123
			}
1124
			if (($wancfg['ipaddrv6'] == "dhcp6") && ($_POST['type6'] != "dhcp6")) {
1125
				interface_dhcpv6_configure($if, $wancfg, true);
1126
			}
1127
		}
1128
		$ppp = array();
1129
		if ($wancfg['ipaddr'] != "ppp") {
1130
			unset($wancfg['ipaddr']);
1131
		}
1132
		if ($wancfg['ipaddrv6'] != "ppp") {
1133
			unset($wancfg['ipaddrv6']);
1134
		}
1135
		unset($wancfg['subnet']);
1136
		unset($wancfg['gateway']);
1137
		unset($wancfg['subnetv6']);
1138
		unset($wancfg['gatewayv6']);
1139
		unset($wancfg['dhcphostname']);
1140
		unset($wancfg['dhcprejectfrom']);
1141
		unset($wancfg['dhcp6-duid']);
1142
		unset($wancfg['dhcp6-ia-pd-len']);
1143
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1144
		unset($wancfg['dhcp6prefixonly']);
1145
		unset($wancfg['dhcp6usev4iface']);
1146
		unset($wancfg['slaacusev4iface']);
1147
		unset($wancfg['ipv6usev4iface']);
1148
		unset($wancfg['track6-interface']);
1149
		unset($wancfg['track6-prefix-id']);
1150
		unset($wancfg['dhcp6withoutra']);
1151
		unset($wancfg['dhcp6vlanenable']);
1152
		unset($wancfg['dhcp6cvpt']);
1153
		unset($wancfg['prefix-6rd']);
1154
		unset($wancfg['prefix-6rd-v4plen']);
1155
		unset($wancfg['gateway-6rd']);
1156

    
1157
		unset($wancfg['dhcpvlanenable']);
1158
		unset($wancfg['dhcpcvpt']);
1159

    
1160
		unset($wancfg['adv_dhcp_pt_timeout']);
1161
		unset($wancfg['adv_dhcp_pt_retry']);
1162
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1163
		unset($wancfg['adv_dhcp_pt_reboot']);
1164
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1165
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1166

    
1167
		unset($wancfg['adv_dhcp_pt_values']);
1168

    
1169
		unset($wancfg['adv_dhcp_send_options']);
1170
		unset($wancfg['adv_dhcp_request_options']);
1171
		unset($wancfg['adv_dhcp_required_options']);
1172
		unset($wancfg['adv_dhcp_option_modifiers']);
1173

    
1174
		unset($wancfg['adv_dhcp_config_advanced']);
1175
		unset($wancfg['adv_dhcp_config_file_override']);
1176
		unset($wancfg['adv_dhcp_config_file_override_path']);
1177

    
1178
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1179
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1180
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1181
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1182

    
1183
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1184
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1185
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1186
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1187
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1188

    
1189
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1190
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1191
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1192
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1193
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1194

    
1195
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1196
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1197
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1198

    
1199
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1200
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1201
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1202
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1203

    
1204
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1205
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1206
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1207
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1208
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1209

    
1210
		unset($wancfg['adv_dhcp6_config_advanced']);
1211
		unset($wancfg['adv_dhcp6_config_file_override']);
1212
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1213

    
1214
		unset($wancfg['pppoe_password']);
1215
		unset($wancfg['pptp_username']);
1216
		unset($wancfg['pptp_password']);
1217
		unset($wancfg['l2tp_secret']);
1218
		unset($wancfg['provider']);
1219
		unset($wancfg['hostuniq']);
1220
		unset($wancfg['ondemand']);
1221
		unset($wancfg['timeout']);
1222
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1223
			unset($wancfg['pppoe']['pppoe-reset-type']);
1224
		}
1225
		unset($wancfg['local']);
1226

    
1227
		unset($wancfg['remote']);
1228
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1229
			if ($wancfg['ipaddr'] != 'ppp') {
1230
				unset($a_ppps[$pppid]['apn']);
1231
				unset($a_ppps[$pppid]['phone']);
1232
				unset($a_ppps[$pppid]['provider']);
1233
				unset($a_ppps[$pppid]['ondemand']);
1234
			}
1235
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1236
				unset($a_ppps[$pppid]['localip']);
1237
				unset($a_ppps[$pppid]['subnet']);
1238
				unset($a_ppps[$pppid]['gateway']);
1239
			}
1240
			if ($wancfg['ipaddr'] != 'pppoe') {
1241
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1242
				unset($a_ppps[$pppid]['hostuniq']);
1243
			}
1244
			if ($wancfg['type'] != $_POST['type']) {
1245
				unset($a_ppps[$pppid]['idletimeout']);
1246
			}
1247
		}
1248

    
1249
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1250
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1251

    
1252
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1253
		switch ($_POST['type']) {
1254
			case "staticv4":
1255
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1256
				$wancfg['subnet'] = $_POST['subnet'];
1257
				if ($_POST['gateway'] != "none") {
1258
					$wancfg['gateway'] = $_POST['gateway'];
1259
				}
1260
				break;
1261
			case "dhcp":
1262
				$wancfg['ipaddr'] = "dhcp";
1263
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1264
				$wancfg['alias-address'] = $_POST['alias-address'];
1265
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1266
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1267

    
1268
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1269
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1270
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1271
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1272
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1273
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1274

    
1275
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1276

    
1277
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1278
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1279
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1280
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1281

    
1282
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1283
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1284
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1285

    
1286
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1287
				if ($gateway_item) {
1288
					$a_gateways[] = $gateway_item;
1289
				}
1290
				if ($_POST['dhcpvlanenable'] == "yes") {
1291
					$wancfg['dhcpvlanenable'] = true;
1292
				}
1293
				if (!empty($_POST['dhcpcvpt'])) {
1294
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1295
				} else {
1296
					unset($wancfg['dhcpcvpt']);
1297
				}
1298
				break;
1299
			case "ppp":
1300
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1301
				$a_ppps[$pppid]['type'] = $_POST['type'];
1302
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1303
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1304
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1305
				if ($_POST['ppp_password'] != DMYPWD) {
1306
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1307
				}
1308
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1309
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1310
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1311
				$wancfg['ipaddr'] = $_POST['type'];
1312
				break;
1313

    
1314
			case "pppoe":
1315
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1316
				$a_ppps[$pppid]['type'] = $_POST['type'];
1317
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1318
				if (isset($_POST['ppp_port'])) {
1319
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1320
				} else {
1321
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1322
				}
1323
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1324
				if ($_POST['pppoe_password'] != DMYPWD) {
1325
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1326
				}
1327
				if (!empty($_POST['provider'])) {
1328
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1329
				} else {
1330
					$a_ppps[$pppid]['provider'] = true;
1331
				}
1332
				if (!empty($_POST['hostuniq'])) {
1333
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1334
				} else {
1335
					$a_ppps[$pppid]['hostuniq'] = true;
1336
				}
1337
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1338
				if (!empty($_POST['pppoe_idletimeout'])) {
1339
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1340
				} else {
1341
					unset($a_ppps[$pppid]['idletimeout']);
1342
				}
1343

    
1344
				if (!empty($_POST['pppoe-reset-type'])) {
1345
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1346
				} else {
1347
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1348
				}
1349
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1350
				$wancfg['ipaddr'] = $_POST['type'];
1351
				if ($gateway_item) {
1352
					$a_gateways[] = $gateway_item;
1353
				}
1354

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

    
1439
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1440
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1441
				}
1442
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1443
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1444
				}
1445
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1446
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1447
				}
1448
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1449
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1450
				}
1451

    
1452
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1453
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1454
				}
1455
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1456
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1457
				}
1458
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1459
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1460
				}
1461
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1462
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1463
				}
1464
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1465
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1466
				}
1467

    
1468
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1469
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1470
				}
1471
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1472
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1473
				}
1474
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1475
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1476
				}
1477
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1478
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1479
				}
1480
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1481
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1482
				}
1483

    
1484
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1485
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1486
				}
1487
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1488
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1489
				}
1490
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1491
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1492
				}
1493
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1494
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1495
				}
1496
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1497
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1498
				}
1499
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1500
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1501
				}
1502
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1503
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1504
				}
1505

    
1506
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1507
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1508
				}
1509
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1510
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1511
				}
1512
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1513
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1514
				}
1515
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1516
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1517
				}
1518
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1519
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1520
				}
1521

    
1522
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1523
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1524
				}
1525
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1526
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1527
				}
1528
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1529
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1530
				}
1531

    
1532
				if ($gateway_item) {
1533
					$a_gateways[] = $gateway_item;
1534
				}
1535
				break;
1536
			case "6rd":
1537
				$wancfg['ipaddrv6'] = "6rd";
1538
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1539
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1540
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1541
				if ($gateway_item) {
1542
					$a_gateways[] = $gateway_item;
1543
				}
1544
				break;
1545
			case "6to4":
1546
				$wancfg['ipaddrv6'] = "6to4";
1547
				break;
1548
			case "track6":
1549
				$wancfg['ipaddrv6'] = "track6";
1550
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1551
				if ($_POST['track6-prefix-id--hex'] === "") {
1552
					$wancfg['track6-prefix-id'] = 0;
1553
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1554
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1555
				} else {
1556
					$wancfg['track6-prefix-id'] = 0;
1557
				}
1558
				break;
1559
			case "none":
1560
				break;
1561
		}
1562
		handle_pppoe_reset($_POST);
1563

    
1564
		if ($_POST['blockpriv'] == "yes") {
1565
			$wancfg['blockpriv'] = true;
1566
		} else {
1567
			unset($wancfg['blockpriv']);
1568
		}
1569
		if ($_POST['blockbogons'] == "yes") {
1570
			$wancfg['blockbogons'] = true;
1571
		} else {
1572
			unset($wancfg['blockbogons']);
1573
		}
1574
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1575
		if (empty($_POST['mtu'])) {
1576
			unset($wancfg['mtu']);
1577
		} else {
1578
			$wancfg['mtu'] = $_POST['mtu'];
1579
		}
1580
		if (empty($_POST['mss'])) {
1581
			unset($wancfg['mss']);
1582
		} else {
1583
			$wancfg['mss'] = $_POST['mss'];
1584
		}
1585
		if (empty($_POST['mediaopt'])) {
1586
			unset($wancfg['media']);
1587
			unset($wancfg['mediaopt']);
1588
		} else {
1589
			$mediaopts = explode(' ', $_POST['mediaopt']);
1590
			if ($mediaopts[0] != '') {
1591
				$wancfg['media'] = $mediaopts[0];
1592
			}
1593
			if ($mediaopts[1] != '') {
1594
				$wancfg['mediaopt'] = $mediaopts[1];
1595
			} else {
1596
				unset($wancfg['mediaopt']);
1597
			}
1598
		}
1599
		if (isset($wancfg['wireless'])) {
1600
			handle_wireless_post();
1601
		}
1602

    
1603
		write_config("Interfaces settings changed");
1604

    
1605
		if ($_POST['gatewayip4']) {
1606
			save_gateway($gateway_settings4);
1607
		}
1608

    
1609
		if ($_POST['gatewayip6']) {
1610
			save_gateway($gateway_settings6);
1611
		}
1612

    
1613
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1614
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1615
		} else {
1616
			$toapplylist = array();
1617
		}
1618
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1619
		$toapplylist[$if]['ppps'] = $old_ppps;
1620
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1621

    
1622
		mark_subsystem_dirty('interfaces');
1623

    
1624
		/* regenerate cron settings/crontab file */
1625
		configure_cron();
1626

    
1627
		header("Location: interfaces.php?if={$if}");
1628
		exit;
1629
	}
1630

    
1631
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1632
	if (!empty($_POST['ppp_port'])) {
1633
		$pconfig['port'] = $_POST['ppp_port'];
1634
	}
1635

    
1636
} // end if ($_POST['save'])
1637

    
1638
function handle_wireless_post() {
1639
	global $_POST, $config, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1640
	if (!is_array($wancfg['wireless'])) {
1641
		$wancfg['wireless'] = array();
1642
	}
1643
	$wancfg['wireless']['standard'] = $_POST['standard'];
1644
	$wancfg['wireless']['mode'] = $_POST['mode'];
1645
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1646
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1647
	$wancfg['wireless']['channel'] = $_POST['channel'];
1648
	$wancfg['wireless']['channel_width'] = $_POST['channel_width'];
1649
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1650
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1651
	$wancfg['wireless']['distance'] = $_POST['distance'];
1652
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1653
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1654
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1655
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1656
		foreach ($wl_countries_attr as $wl_country) {
1657
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1658
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1659
				break;
1660
			}
1661
		}
1662
	}
1663
	if (!is_array($wancfg['wireless']['wpa'])) {
1664
		$wancfg['wireless']['wpa'] = array();
1665
	}
1666
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1667
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1668
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1669
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1670
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1671
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1672
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1673
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1674
	$wancfg['wireless']['wpa']['wpa_eap_client_mode'] = $_POST['wpa_eap_client_mode'];
1675
	$wancfg['wireless']['wpa']['wpa_eap_inner_auth'] = $_POST['wpa_eap_inner_auth'];
1676
	$wancfg['wireless']['wpa']['wpa_eap_inner_id'] = $_POST['wpa_eap_inner_id'];
1677
	$wancfg['wireless']['wpa']['wpa_eap_inner_password'] = base64_encode($_POST['wpa_eap_inner_password']);
1678
	$wancfg['wireless']['wpa']['wpa_eap_cert'] = $_POST['wpa_eap_cert'];
1679
	$wancfg['wireless']['wpa']['wpa_eap_ca'] = $_POST['wpa_eap_ca'];
1680
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1681
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1682
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1683
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1684
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1685
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1686

    
1687
	if ($_POST['persistcommonwireless'] == "yes") {
1688
		if (!is_array($config['wireless'])) {
1689
			$config['wireless'] = array();
1690
		}
1691
		if (!is_array(config_get_path('wireless/interfaces'))) {
1692
			$config['wireless']['interfaces'] = array();
1693
		}
1694
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1695
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1696
		}
1697
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1698
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1699
	}
1700
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1701
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1702
	} else if (isset($wancfg['wireless']['diversity'])) {
1703
		unset($wancfg['wireless']['diversity']);
1704
	}
1705
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1706
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1707
	} else if (isset($wancfg['wireless']['txantenna'])) {
1708
		unset($wancfg['wireless']['txantenna']);
1709
	}
1710
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1711
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1712
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1713
		unset($wancfg['wireless']['rxantenna']);
1714
	}
1715
	if ($_POST['hidessid_enable'] == "yes") {
1716
		$wancfg['wireless']['hidessid']['enable'] = true;
1717
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1718
		unset($wancfg['wireless']['hidessid']['enable']);
1719
	}
1720
	if ($_POST['mac_acl_enable'] == "yes") {
1721
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1722
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1723
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1724
	}
1725
	if ($_POST['rsn_preauth'] == "yes") {
1726
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1727
	} else {
1728
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1729
	}
1730
	if ($_POST['ieee8021x'] == "yes") {
1731
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1732
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1733
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1734
	}
1735
	if ($_POST['wpa_strict_rekey'] == "yes") {
1736
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1737
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1738
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1739
	}
1740
	if ($_POST['debug_mode'] == "yes") {
1741
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1742
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1743
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1744
	}
1745
	if ($_POST['wpa_enable'] == "yes") {
1746
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1747
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1748
		unset($wancfg['wireless']['wpa']['enable']);
1749
	}
1750

    
1751
	if ($_POST['wme_enable'] == "yes") {
1752
		if (!is_array($wancfg['wireless']['wme'])) {
1753
			$wancfg['wireless']['wme'] = array();
1754
		}
1755
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1756
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1757
		unset($wancfg['wireless']['wme']['enable']);
1758
	}
1759
	if ($_POST['puremode'] == "11g") {
1760
		if (!is_array($wancfg['wireless']['pureg'])) {
1761
			$wancfg['wireless']['pureg'] = array();
1762
		}
1763
		$wancfg['wireless']['pureg']['enable'] = true;
1764
	} else if ($_POST['puremode'] == "11n") {
1765
		if (!is_array($wancfg['wireless']['puren'])) {
1766
			$wancfg['wireless']['puren'] = array();
1767
		}
1768
		$wancfg['wireless']['puren']['enable'] = true;
1769
	} else {
1770
		if (isset($wancfg['wireless']['pureg'])) {
1771
			unset($wancfg['wireless']['pureg']);
1772
		}
1773
		if (isset($wancfg['wireless']['puren'])) {
1774
			unset($wancfg['wireless']['puren']);
1775
		}
1776
	}
1777
	if ($_POST['apbridge_enable'] == "yes") {
1778
		if (!is_array($wancfg['wireless']['apbridge'])) {
1779
			$wancfg['wireless']['apbridge'] = array();
1780
		}
1781
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1782
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1783
		unset($wancfg['wireless']['apbridge']['enable']);
1784
	}
1785
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1786
		if (!is_array($wancfg['wireless']['turbo'])) {
1787
			$wancfg['wireless']['turbo'] = array();
1788
		}
1789
		$wancfg['wireless']['turbo']['enable'] = true;
1790
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1791
		unset($wancfg['wireless']['turbo']['enable']);
1792
	}
1793

    
1794
	interface_sync_wireless_clones($wancfg, true);
1795
}
1796

    
1797
function check_wireless_mode() {
1798
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1799

    
1800
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1801
		return;
1802
	}
1803

    
1804
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1805
		$clone_count = 1;
1806
	} else {
1807
		$clone_count = 0;
1808
	}
1809

    
1810
	foreach (config_get_path('wireless/clone', []) as $clone) {
1811
		if ($clone['if'] == $wlanbaseif) {
1812
				$clone_count++;
1813
		}
1814
	}
1815

    
1816
	if ($clone_count > 1) {
1817
		$old_wireless_mode = $wancfg['wireless']['mode'];
1818
		$wancfg['wireless']['mode'] = $_POST['mode'];
1819
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1820
			$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']]);
1821
		} else {
1822
			pfSense_interface_destroy("{$wlanif}_");
1823
		}
1824
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1825
	}
1826
}
1827

    
1828
// Find all possible media options for the interface
1829
$mediaopts_list = array();
1830
$intrealname = config_get_path("interfaces/{$if}/if");
1831
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1832
foreach ($mediaopts as $mediaopt) {
1833
	preg_match("/media (.*)/", $mediaopt, $matches);
1834
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1835
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1836
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1837
	} else {
1838
		// there is only media like "media 1000baseT"
1839
		array_push($mediaopts_list, $matches[1]);
1840
	}
1841
}
1842

    
1843
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1844
$shortcut_section = "interfaces";
1845

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

    
1848
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1849
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1850
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1851
}
1852

    
1853
$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"));
1854

    
1855
// Get the MAC address
1856
$defgatewayname4 = $wancfg['descr'] . "GW";
1857
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1858

    
1859
function build_mediaopts_list() {
1860
	global $mediaopts_list;
1861

    
1862
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1863
			 " " =>	 gettext("------- Media Supported by this interface -------")
1864
			];
1865

    
1866
	foreach ($mediaopts_list as $mediaopt) {
1867
		$list[$mediaopt] = $mediaopt;
1868
	}
1869

    
1870
	return($list);
1871
}
1872

    
1873
function build_gateway_list() {
1874
	global $a_gateways, $if;
1875

    
1876
	$list = array("none" => gettext("None"));
1877
	foreach ($a_gateways as $gateway) {
1878
		if (empty($gateway)) {
1879
			continue;
1880
		}
1881
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1882
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1883
		}
1884
	}
1885

    
1886
	return($list);
1887
}
1888

    
1889
function build_gatewayv6_list() {
1890
	global $a_gateways, $if;
1891

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

    
1902
	return($list);
1903
}
1904

    
1905
include("head.inc");
1906

    
1907
if ($input_errors) {
1908
	print_input_errors($input_errors);
1909
}
1910

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

    
1917
if ($changes_applied) {
1918
	print_apply_result_box($retval);
1919
}
1920

    
1921
$form = new Form();
1922

    
1923
$section = new Form_Section('General Configuration');
1924

    
1925
$section->addInput(new Form_Checkbox(
1926
	'enable',
1927
	'Enable',
1928
	'Enable interface',
1929
	$pconfig['enable'],
1930
	'yes'
1931
));
1932

    
1933
$section->addInput(new Form_Input(
1934
	'descr',
1935
	'*Description',
1936
	'text',
1937
	$pconfig['descr']
1938
))->setHelp('Enter a description (name) for the interface here.');
1939

    
1940
if ($show_address_controls) {
1941
	$section->addInput(new Form_Select(
1942
		'type',
1943
		'IPv4 Configuration Type',
1944
		$pconfig['type'],
1945
		$types4
1946
	));
1947
	$section->addInput(new Form_Select(
1948
		'type6',
1949
		'IPv6 Configuration Type',
1950
		$pconfig['type6'],
1951
		$types6
1952
	));
1953
} else {
1954
	$section->addInput(new Form_StaticText(
1955
		'IPv4/IPv6 Configuration',
1956
		"This interface type does not support manual address configuration on this page. "
1957
	));
1958
	$form->addGlobal(new Form_Input(
1959
		'type',
1960
		null,
1961
		'hidden',
1962
		'none'
1963
	));
1964
	$form->addGlobal(new Form_Input(
1965
		'type6',
1966
		null,
1967
		'hidden',
1968
		'none'
1969
	));
1970
}
1971

    
1972
if (!is_pseudo_interface($intrealname, true)) {
1973
	$macaddress = new Form_Input(
1974
		'spoofmac',
1975
		'MAC Address',
1976
		'text',
1977
		$pconfig['spoofmac'],
1978
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
1979
	);
1980

    
1981
	if (interface_is_vlan($realifname)) {
1982
		$macaddress->setDisabled();
1983
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
1984
		    'set on its parent interface');
1985
	} else {
1986
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
1987
		    'MAC address of this interface.%sEnter a MAC address in the ' .
1988
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1989
	}
1990

    
1991
	$section->addInput($macaddress);
1992
}
1993

    
1994
$section->addInput(new Form_Input(
1995
	'mtu',
1996
	'MTU',
1997
	'number',
1998
	$pconfig['mtu']
1999
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2000
			'This is typically 1500 bytes but can vary in some circumstances.');
2001

    
2002
$section->addInput(new Form_Input(
2003
	'mss',
2004
	'MSS',
2005
	'number',
2006
	$pconfig['mss']
2007
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2008
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2009

    
2010
if (count($mediaopts_list) > 0) {
2011
	$section->addInput(new Form_Select(
2012
		'mediaopt',
2013
		'Speed and Duplex',
2014
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt"), ""),
2015
		build_mediaopts_list() 
2016
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2017
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2018
}
2019

    
2020
$form->add($section);
2021

    
2022
$section = new Form_Section('Static IPv4 Configuration');
2023
$section->addClass('staticv4');
2024

    
2025
$section->addInput(new Form_IpAddress(
2026
	'ipaddr',
2027
	'*IPv4 Address',
2028
	$pconfig['ipaddr'],
2029
	'V4'
2030
))->addMask('subnet', $pconfig['subnet'], 32);
2031

    
2032
$group = new Form_Group('IPv4 Upstream gateway');
2033

    
2034
$group->add(new Form_Select(
2035
	'gateway',
2036
	'IPv4 Upstream Gateway',
2037
	$pconfig['gateway'],
2038
	build_gateway_list()
2039
));
2040

    
2041
$group->add(new Form_Button(
2042
	'addgw4',
2043
	'Add a new gateway',
2044
	null,
2045
	'fa-plus'
2046
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2047

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

    
2053
$section->add($group);
2054

    
2055
$form->add($section);
2056

    
2057
$section = new Form_Section('SLAAC IPv6 Configuration');
2058
$section->addClass('slaac');
2059

    
2060
$section->addInput(new Form_Checkbox(
2061
	'slaacusev4iface',
2062
	'Use IPv4 connectivity as parent interface',
2063
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2064
	$pconfig['slaacusev4iface']
2065
));
2066

    
2067
$form->add($section);
2068

    
2069
$section = new Form_Section('Static IPv6 Configuration');
2070
$section->addClass('staticv6');
2071

    
2072
$section->addInput(new Form_IpAddress(
2073
	'ipaddrv6',
2074
	'*IPv6 address',
2075
	$pconfig['ipaddrv6'],
2076
	'V6'
2077
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2078

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

    
2086
$group = new Form_Group('IPv6 Upstream gateway');
2087

    
2088
$group->add(new Form_Select(
2089
	'gatewayv6',
2090
	'IPv6 Upstream Gateway',
2091
	$pconfig['gatewayv6'],
2092
	build_gatewayv6_list()
2093
));
2094

    
2095
$group->add(new Form_Button(
2096
	'addgw6',
2097
	'Add a new gateway',
2098
	null,
2099
	'fa-plus'
2100
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2101

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

    
2105
$section->add($group);
2106
$form->add($section);
2107

    
2108
// Add new gateway modal pop-up for IPv6
2109
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2110

    
2111
$modal->addInput(new Form_Checkbox(
2112
	'defaultgw6',
2113
	'Default',
2114
	'Default gateway',
2115
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2116
));
2117

    
2118
$modal->addInput(new Form_Input(
2119
	'gatewayname6',
2120
	'Gateway name',
2121
	'text',
2122
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2123
));
2124

    
2125
$modal->addInput(new Form_IpAddress(
2126
	'gatewayip6',
2127
	'Gateway IPv6',
2128
	$gateway_settings6['gateway'],
2129
	'V6'
2130
));
2131

    
2132
$modal->addInput(new Form_Input(
2133
	'gatewaydescr6',
2134
	'Description',
2135
	'text',
2136
	$gateway_settings6['descr']
2137
));
2138

    
2139
$btnaddgw6 = new Form_Button(
2140
	'add6',
2141
	'Add',
2142
	null,
2143
	'fa-plus'
2144
);
2145

    
2146
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2147

    
2148
$btncnxgw6 = new Form_Button(
2149
	'cnx6',
2150
	'Cancel',
2151
	null,
2152
	'fa-undo'
2153
);
2154

    
2155
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2156

    
2157
$modal->addInput(new Form_StaticText(
2158
	null,
2159
	$btnaddgw6 . $btncnxgw6
2160
));
2161

    
2162
$form->add($modal);
2163

    
2164
// ==== DHCP client configuration =============================
2165

    
2166
$section = new Form_Section('DHCP Client Configuration');
2167
$section->addClass('dhcp');
2168

    
2169
$group = new Form_Group('Options');
2170

    
2171
$group->add(new Form_Checkbox(
2172
	'adv_dhcp_config_advanced',
2173
	null,
2174
	'Advanced Configuration',
2175
	$pconfig['adv_dhcp_config_advanced']
2176
))->setHelp('Use advanced DHCP configuration options.');
2177

    
2178
$group->add(new Form_Checkbox(
2179
	'adv_dhcp_config_file_override',
2180
	null,
2181
	'Configuration Override',
2182
	$pconfig['adv_dhcp_config_file_override']
2183
))->setHelp('Override the configuration from this file.');
2184

    
2185
$section->add($group);
2186

    
2187
$section->addInput(new Form_Input(
2188
	'dhcphostname',
2189
	'Hostname',
2190
	'text',
2191
	$pconfig['dhcphostname']
2192
))->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).');
2193

    
2194
$section->addInput(new Form_IpAddress(
2195
	'alias-address',
2196
	'Alias IPv4 address',
2197
	$pconfig['alias-address'],
2198
	'V4'
2199
))->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.');
2200

    
2201
$section->addInput(new Form_Input(
2202
	'dhcprejectfrom',
2203
	'Reject leases from',
2204
	'text',
2205
	$pconfig['dhcprejectfrom']
2206
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2207
			'(separate multiple entries with a comma). ' .
2208
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2209

    
2210
if (interface_is_vlan($wancfg['if']) != NULL) {
2211

    
2212
	$group = new Form_Group('DHCP VLAN Priority');
2213
	$group->add(new Form_Checkbox(
2214
		'dhcpvlanenable',
2215
		null,
2216
		'Enable dhcpclient VLAN Priority tagging',
2217
		$pconfig['dhcpvlanenable']
2218
	))->setHelp('Normally off unless specifically required by the ISP.');
2219

    
2220
	$group->add(new Form_Select(
2221
		'dhcpcvpt',
2222
		'VLAN Prio',
2223
		$pconfig['dhcpcvpt'],
2224
		$vlanprio
2225
	))->setHelp('Choose 802.1p priority to set.');
2226

    
2227
	$section->add($group);
2228
}
2229

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

    
2235
$group->add(new Form_Input(
2236
	'adv_dhcp_pt_timeout',
2237
	null,
2238
	'number',
2239
	$pconfig['adv_dhcp_pt_timeout']
2240
))->setHelp('Timeout');
2241

    
2242
$group->add(new Form_Input(
2243
	'adv_dhcp_pt_retry',
2244
	null,
2245
	'number',
2246
	$pconfig['adv_dhcp_pt_retry']
2247
))->setHelp('Retry');
2248

    
2249
$group->add(new Form_Input(
2250
	'adv_dhcp_pt_select_timeout',
2251
	null,
2252
	'number',
2253
	$pconfig['adv_dhcp_pt_select_timeout'],
2254
	['min' => 0]
2255
))->setHelp('Select timeout');
2256

    
2257
$group->add(new Form_Input(
2258
	'adv_dhcp_pt_reboot',
2259
	null,
2260
	'number',
2261
	$pconfig['adv_dhcp_pt_reboot']
2262
))->setHelp('Reboot');
2263

    
2264
$group->add(new Form_Input(
2265
	'adv_dhcp_pt_backoff_cutoff',
2266
	null,
2267
	'number',
2268
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2269
))->setHelp('Backoff cutoff');
2270

    
2271
$group->add(new Form_Input(
2272
	'adv_dhcp_pt_initial_interval',
2273
	null,
2274
	'number',
2275
	$pconfig['adv_dhcp_pt_initial_interval']
2276
))->setHelp('Initial interval');
2277

    
2278
$section->add($group);
2279

    
2280
$group = new Form_Group('Presets');
2281
$group->addClass('dhcpadvanced');
2282

    
2283
$group->add(new Form_Checkbox(
2284
	'adv_dhcp_pt_values',
2285
	null,
2286
	'FreeBSD default',
2287
	null,
2288
	'DHCP'
2289
))->displayAsRadio();
2290

    
2291
$group->add(new Form_Checkbox(
2292
	'adv_dhcp_pt_values',
2293
	null,
2294
	'Clear',
2295
	null,
2296
	'Clear'
2297
))->displayAsRadio();
2298

    
2299
$group->add(new Form_Checkbox(
2300
	'adv_dhcp_pt_values',
2301
	null,
2302
	'pfSense Default',
2303
	null,
2304
	'pfSense'
2305
))->displayAsRadio();
2306

    
2307
$group->add(new Form_Checkbox(
2308
	'adv_dhcp_pt_values',
2309
	null,
2310
	'Saved Cfg',
2311
	null,
2312
	'SavedCfg'
2313
))->displayAsRadio();
2314

    
2315
$section->add($group);
2316

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

    
2327
$form->add($section);
2328

    
2329
$section = new Form_Section('Lease Requirements and Requests');
2330
$section->addClass('dhcpadvanced');
2331

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

    
2342
$section->addInput(new Form_Input(
2343
	'adv_dhcp_request_options',
2344
	'Request options',
2345
	'text',
2346
	$pconfig['adv_dhcp_request_options']
2347
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2348
			'Some ISPs may require certain options be or not be requested.', '<br />');
2349

    
2350
$section->addInput(new Form_Input(
2351
	'adv_dhcp_required_options',
2352
	'Require options',
2353
	'text',
2354
	$pconfig['adv_dhcp_required_options']
2355
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2356

    
2357
$section->addInput(new Form_Input(
2358
	'adv_dhcp_option_modifiers',
2359
	'Option modifiers',
2360
	'text',
2361
	$pconfig['adv_dhcp_option_modifiers']
2362
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2363
			'modifiers: (default, supersede, prepend, append) %1$s' .
2364
			'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>');
2365

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

    
2368
// DHCP6 client config
2369

    
2370
$section = new Form_Section('DHCP6 Client Configuration');
2371
$section->addClass('dhcp6');
2372

    
2373
$group = new Form_Group('Options');
2374

    
2375
$group->add(new Form_Checkbox(
2376
	'adv_dhcp6_config_advanced',
2377
	null,
2378
	'Advanced Configuration',
2379
	$pconfig['adv_dhcp6_config_advanced']
2380
))->setHelp('Use advanced DHCPv6 configuration options.');
2381

    
2382
$group->add(new Form_Checkbox(
2383
	'adv_dhcp6_config_file_override',
2384
	null,
2385
	'Configuration Override',
2386
	$pconfig['adv_dhcp6_config_file_override']
2387
))->setHelp('Override the configuration from this file.');
2388

    
2389
$section->add($group);
2390

    
2391
$section->addInput(new Form_Checkbox(
2392
	'dhcp6usev4iface',
2393
	'Use IPv4 connectivity as parent interface',
2394
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2395
	$pconfig['dhcp6usev4iface']
2396
));
2397

    
2398
$section->addInput(new Form_Checkbox(
2399
	'dhcp6prefixonly',
2400
	'Request only an IPv6 prefix',
2401
	'Only request an IPv6 prefix, do not request an IPv6 address',
2402
	$pconfig['dhcp6prefixonly']
2403
));
2404

    
2405
$section->addInput(new Form_Select(
2406
	'dhcp6-ia-pd-len',
2407
	'DHCPv6 Prefix Delegation size',
2408
	$pconfig['dhcp6-ia-pd-len'],
2409
	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")
2410
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2411

    
2412
$section->addInput(new Form_Checkbox(
2413
	'dhcp6-ia-pd-send-hint',
2414
	'Send IPv6 prefix hint',
2415
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2416
	$pconfig['dhcp6-ia-pd-send-hint']
2417
));
2418

    
2419
$section->addInput(new Form_Checkbox(
2420
	'dhcp6withoutra',
2421
	'Do not wait for a RA',
2422
	'Required by some ISPs, especially those not using PPPoE',
2423
	$pconfig['dhcp6withoutra']
2424
));
2425

    
2426
if (interface_is_vlan($wancfg['if']) != NULL) {
2427
	$group = new Form_Group('DHCP6 VLAN Priority');
2428

    
2429
	$group->add(new Form_Checkbox(
2430
		'dhcp6vlanenable',
2431
		null,
2432
		'Enable dhcp6c VLAN Priority tagging',
2433
		$pconfig['dhcp6vlanenable']
2434
	))->setHelp('Normally off unless specifically required by the ISP.');
2435

    
2436
	$group->add(new Form_Select(
2437
		'dhcp6cvpt',
2438
		'VLAN Prio',
2439
		$pconfig['dhcp6cvpt'],
2440
		$vlanprio
2441
	))->setHelp('Choose 802.1p priority to set.');
2442

    
2443
	$section->add($group);
2444
}
2445

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

    
2456
$form->add($section);
2457

    
2458
// DHCP6 client config - Advanced
2459

    
2460
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2461
$section->addClass('dhcp6advanced');
2462

    
2463
$section->addInput(new Form_Checkbox(
2464
	'adv_dhcp6_interface_statement_information_only_enable',
2465
	'Information only',
2466
	'Exchange Information Only',
2467
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2468
	'Selected'
2469
))->setHelp('Only exchange informational configuration parameters with servers.');
2470

    
2471
$section->addInput(new Form_Input(
2472
	'adv_dhcp6_interface_statement_send_options',
2473
	'Send options',
2474
	'text',
2475
	$pconfig['adv_dhcp6_interface_statement_send_options']
2476
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2477
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2478
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2479
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2480

    
2481
$section->addInput(new Form_Input(
2482
	'adv_dhcp6_interface_statement_request_options',
2483
	'Request Options',
2484
	'text',
2485
	$pconfig['adv_dhcp6_interface_statement_request_options']
2486
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2487
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2488

    
2489
$section->addInput(new Form_Input(
2490
	'adv_dhcp6_interface_statement_script',
2491
	'Scripts',
2492
	'text',
2493
	$pconfig['adv_dhcp6_interface_statement_script']
2494
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2495
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2496

    
2497
$group = new Form_Group('Identity Association Statement');
2498

    
2499
$group->add(new Form_Checkbox(
2500
	'adv_dhcp6_id_assoc_statement_address_enable',
2501
	null,
2502
	'Non-Temporary Address Allocation',
2503
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2504
	'Selected'
2505
));
2506

    
2507
$group->add(new Form_Input(
2508
	'adv_dhcp6_id_assoc_statement_address_id',
2509
	null,
2510
	'text',
2511
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2512
))->sethelp('id-assoc na ID');
2513

    
2514
$group->add(new Form_IpAddress(
2515
	'adv_dhcp6_id_assoc_statement_address',
2516
	null,
2517
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2518
	'V6'
2519
))->sethelp('IPv6 address');
2520

    
2521
$group->add(new Form_Input(
2522
	'adv_dhcp6_id_assoc_statement_address_pltime',
2523
	null,
2524
	'text',
2525
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2526
))->sethelp('pltime');
2527

    
2528
$group->add(new Form_Input(
2529
	'adv_dhcp6_id_assoc_statement_address_vltime',
2530
	null,
2531
	'text',
2532
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2533
))->sethelp('vltime');
2534

    
2535
$section->add($group);
2536

    
2537
// Prefix delegation
2538
$group = new Form_Group('');
2539

    
2540
$group->add(new Form_Checkbox(
2541
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2542
	null,
2543
	'Prefix Delegation ',
2544
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2545
	'Selected'
2546
));
2547

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

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

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

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

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

    
2578
$group = new Form_Group('Prefix interface statement');
2579

    
2580
$group->add(new Form_Input(
2581
	'adv_dhcp6_prefix_interface_statement_sla_id',
2582
	null,
2583
	'text',
2584
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2585
))->sethelp('Prefix Interface sla-id');
2586

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

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

    
2596
$group = new Form_Group('Select prefix interface');
2597
$section->addInput(new Form_Select(
2598
	'adv_dhcp6_prefix_selected_interface',
2599
	'Prefix Interface',
2600
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2601
	$interfaces
2602
))->setHelp('Select the interface on which to apply the prefix delegation.');
2603

    
2604
$group = new Form_Group('Authentication statement');
2605

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

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

    
2620
$group->add(new Form_Input(
2621
	'adv_dhcp6_authentication_statement_algorithm',
2622
	null,
2623
	'text',
2624
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2625
))->sethelp('Algorithm');
2626

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

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

    
2636
$group = new Form_Group('Keyinfo statement');
2637

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

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

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

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

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

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

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

    
2677
$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>');
2678

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

    
2681
$form->add($section);
2682

    
2683
$section = new Form_Section('6RD Configuration');
2684
$section->addClass('_6rd');
2685

    
2686
$section->addInput(new Form_Input(
2687
	'prefix-6rd',
2688
	'6RD Prefix',
2689
	'text',
2690
	$pconfig['prefix-6rd']
2691
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2692

    
2693
$section->addInput(new Form_Input(
2694
	'gateway-6rd',
2695
	'*6RD Border relay',
2696
	'text',
2697
	$pconfig['gateway-6rd']
2698
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2699

    
2700
$section->addInput(new Form_Select(
2701
	'prefix-6rd-v4plen',
2702
	'6RD IPv4 Prefix length',
2703
	$pconfig['prefix-6rd-v4plen'],
2704
	array_combine(range(0, 32), range(0, 32))
2705
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2706

    
2707
$form->add($section);
2708

    
2709
// Track IPv6 ointerface section
2710
$section = new Form_Section('Track IPv6 Interface');
2711
$section->addClass('track6');
2712

    
2713
function build_ipv6interface_list() {
2714
	global $config, $form;
2715

    
2716
	$list = array('' => '');
2717

    
2718
	$interfaces = get_configured_interface_with_descr(true);
2719
	$dynv6ifs = array();
2720

    
2721
	foreach ($interfaces as $iface => $ifacename) {
2722
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2723
			case "6to4":
2724
			case "6rd":
2725
			case "dhcp6":
2726
				$dynv6ifs[$iface] = array(
2727
					'name' => $ifacename,
2728
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2729
				);
2730
				break;
2731
			default:
2732
				continue 2;
2733
		}
2734
	}
2735

    
2736
	foreach ($dynv6ifs as $iface => $ifacedata) {
2737
		$list[$iface] = $ifacedata['name'];
2738

    
2739
		$form->addGlobal(new Form_Input(
2740
			'ipv6-num-prefix-ids-' . $iface,
2741
			null,
2742
			'hidden',
2743
			$ifacedata['ipv6_num_prefix_ids']
2744
		));
2745
	}
2746

    
2747
	return($list);
2748
}
2749

    
2750
$section->addInput(new Form_Select(
2751
	'track6-interface',
2752
	'*IPv6 Interface',
2753
	$pconfig['track6-interface'],
2754
	build_ipv6interface_list()
2755
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2756

    
2757
if ($pconfig['track6-prefix-id'] == "") {
2758
	$pconfig['track6-prefix-id'] = 0;
2759
}
2760

    
2761
$section->addInput(new Form_Input(
2762
	'track6-prefix-id--hex',
2763
	'IPv6 Prefix ID',
2764
	'text',
2765
	sprintf("%x", $pconfig['track6-prefix-id'])
2766
))->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>');
2767

    
2768
$form->addGlobal(new Form_Input(
2769
	'track6-prefix-id-max',
2770
	null,
2771
	'hidden',
2772
	0
2773
));
2774

    
2775
$form->add($section);
2776

    
2777
/// PPP section
2778

    
2779
$section = new Form_Section('PPP Configuration');
2780
$section->addClass('ppp');
2781

    
2782
$section->addInput(new Form_Select(
2783
	'country',
2784
	'Country',
2785
	$pconfig['country'],
2786
	[]
2787
));
2788

    
2789
$section->addInput(new Form_Select(
2790
	'provider_list',
2791
	'Provider',
2792
	$pconfig['provider_list'],
2793
	[]
2794
));
2795

    
2796
$section->addInput(new Form_Select(
2797
	'providerplan',
2798
	'Plan',
2799
	$pconfig['providerplan'],
2800
	[]
2801
))->setHelp('Select to fill in service provider data.');
2802

    
2803
$section->addInput(new Form_Input(
2804
	'ppp_username',
2805
	'Username',
2806
	'text',
2807
	$pconfig['ppp_username'],
2808
	['autocomplete' => 'new-password']
2809
));
2810

    
2811
$section->addPassword(new Form_Input(
2812
	'ppp_password',
2813
	'Password',
2814
	'password',
2815
	$pconfig['ppp_password']
2816
));
2817

    
2818
$section->addInput(new Form_Input(
2819
	'phone',
2820
	'*Phone number',
2821
	'text',
2822
	$pconfig['phone']
2823
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2824

    
2825
$section->addInput(new Form_Input(
2826
	'apn',
2827
	'Access Point Name',
2828
	'text',
2829
	$pconfig['apn']
2830
));
2831

    
2832

    
2833
function build_port_list() {
2834
	$list = array("" => "None");
2835

    
2836
	$portlist = glob("/dev/cua*");
2837
	$modems	  = glob("/dev/modem*");
2838
	$portlist = array_merge($portlist, $modems);
2839

    
2840
	foreach ($portlist as $port) {
2841
		if (preg_match("/\.(lock|init)$/", $port)) {
2842
			continue;
2843
		}
2844

    
2845
	$list[trim($port)] = $port;
2846
	}
2847

    
2848
	return($list);
2849
}
2850

    
2851
$section->addInput(new Form_Select(
2852
	'port',
2853
	"*Modem port",
2854
	$pconfig['port'],
2855
	build_port_list()
2856
));
2857

    
2858
$section->addInput(new Form_Button(
2859
	'btnadvppp',
2860
	'Advanced PPP',
2861
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2862
	'fa-cog'
2863
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2864

    
2865
$form->add($section);
2866

    
2867
// PPPoE configuration
2868
$section = new Form_Section('PPPoE Configuration');
2869
$section->addClass('pppoe');
2870

    
2871
$section->addInput(new Form_Input(
2872
	'pppoe_username',
2873
	'*Username',
2874
	'text',
2875
	$pconfig['pppoe_username'],
2876
	['autocomplete' => 'new-password']
2877
));
2878

    
2879
$section->addPassword(new Form_Input(
2880
	'pppoe_password',
2881
	'*Password',
2882
	'password',
2883
	$pconfig['pppoe_password']
2884
));
2885

    
2886
$section->addInput(new Form_Input(
2887
	'provider',
2888
	'Service name',
2889
	'text',
2890
	$pconfig['provider']
2891
))->setHelp('This field can usually be left empty.');
2892

    
2893
$section->addInput(new Form_Input(
2894
	'hostuniq',
2895
	'Host-Uniq',
2896
	'text',
2897
	$pconfig['hostuniq']
2898
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2899

    
2900
$section->addInput(new Form_Checkbox(
2901
	'pppoe_dialondemand',
2902
	'Dial on demand',
2903
	'Enable Dial-On-Demand mode ',
2904
	$pconfig['pppoe_dialondemand'],
2905
	'enable'
2906
));
2907

    
2908
$section->addInput(new Form_Input(
2909
	'pppoe_idletimeout',
2910
	'Idle timeout',
2911
	'number',
2912
	$pconfig['pppoe_idletimeout'],
2913
	['min' => 0]
2914
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2915
			'An idle timeout of zero disables this feature.');
2916

    
2917
$section->addInput(new Form_Select(
2918
	'pppoe-reset-type',
2919
	'Periodic reset',
2920
	$pconfig['pppoe-reset-type'],
2921
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2922
))->setHelp('Select a reset timing type.');
2923

    
2924
$group = new Form_Group('Custom reset');
2925
$group->addClass('pppoecustom');
2926

    
2927
$group->add(new Form_Input(
2928
	'pppoe_resethour',
2929
	null,
2930
	'number',
2931
	$pconfig['pppoe_resethour'],
2932
	['min' => 0, 'max' => 23]
2933
))->setHelp('Hour (0-23)');
2934

    
2935
$group->add(new Form_Input(
2936
	'pppoe_resetminute',
2937
	null,
2938
	'number',
2939
	$pconfig['pppoe_resetminute'],
2940
	['min' => 0, 'max' => 59]
2941
))->setHelp('Minutes (0-59)');
2942

    
2943
$group->add(new Form_Input(
2944
	'pppoe_resetdate',
2945
	null,
2946
	'text',
2947
	$pconfig['pppoe_resetdate']
2948
))->setHelp('Specific date (mm/dd/yyyy)');
2949

    
2950
$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');
2951

    
2952
$section->add($group);
2953

    
2954
$group = new Form_MultiCheckboxGroup('cron based reset');
2955
$group->addClass('pppoepreset');
2956

    
2957
$group->add(new Form_MultiCheckbox(
2958
	'pppoe_pr_preset_val',
2959
	null,
2960
	'Reset at each month ("0 0 1 * *")',
2961
	$pconfig['pppoe_monthly'],
2962
	'monthly'
2963
))->displayAsRadio();
2964

    
2965
$group->add(new Form_MultiCheckbox(
2966
	'pppoe_pr_preset_val',
2967
	null,
2968
	'Reset at each week ("0 0 * * 0")',
2969
	$pconfig['pppoe_weekly'],
2970
	'weekly'
2971
))->displayAsRadio();
2972

    
2973
$group->add(new Form_MultiCheckbox(
2974
	'pppoe_pr_preset_val',
2975
	null,
2976
	'Reset at each day ("0 0 * * *")',
2977
	$pconfig['pppoe_daily'],
2978
	'daily'
2979
))->displayAsRadio();
2980

    
2981
$group->add(new Form_MultiCheckbox(
2982
	'pppoe_pr_preset_val',
2983
	null,
2984
	'Reset at each hour ("0 * * * *")',
2985
	$pconfig['pppoe_hourly'],
2986
	'hourly'
2987
))->displayAsRadio();
2988

    
2989
$section->add($group);
2990

    
2991
$section->addInput(new Form_Button(
2992
	'btnadvppp',
2993
	'Advanced and MLPPP',
2994
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2995
	'fa-cog'
2996
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2997

    
2998
$form->add($section);
2999

    
3000
// PPTP & L2TP Configuration section
3001
$section = new Form_Section('PPTP/L2TP Configuration');
3002
$section->addClass('pptp');
3003

    
3004
$section->addInput(new Form_Input(
3005
	'pptp_username',
3006
	'*Username',
3007
	'text',
3008
	$pconfig['pptp_username'],
3009
	['autocomplete' => 'new-password']
3010
));
3011

    
3012
$section->addPassword(new Form_Input(
3013
	'pptp_password',
3014
	'*Password',
3015
	'password',
3016
	$pconfig['pptp_password']
3017
));
3018

    
3019
$group = new Form_Group('Shared Secret');
3020

    
3021
$group->add(new Form_Input(
3022
	'l2tp_secret',
3023
	'*Secret',
3024
	'password',
3025
	$pconfig['l2tp_secret']
3026
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3027
	    'important control packet contents. (Optional)');
3028

    
3029
$group->addClass('l2tp_secret');
3030
$section->add($group);
3031

    
3032
$section->addInput(new Form_IpAddress(
3033
	'pptp_local0',
3034
	'*Local IP address',
3035
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3036
	'V4'
3037
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3038

    
3039
$section->addInput(new Form_IpAddress(
3040
	'pptp_remote0',
3041
	'*Remote IP address',
3042
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3043
	'HOSTV4'
3044
));
3045

    
3046
$section->addInput(new Form_Checkbox(
3047
	'pptp_dialondemand',
3048
	'Dial on demand',
3049
	'Enable Dial-On-Demand mode ',
3050
	$pconfig['pptp_dialondemand'],
3051
	'enable'
3052
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3053
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3054

    
3055
$section->addInput(new Form_Input(
3056
	'pptp_idletimeout',
3057
	'Idle timeout (seconds)',
3058
	'number',
3059
	$pconfig['pptp_idletimeout'],
3060
	['min' => 0]
3061
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3062
			'An idle timeout of zero disables this feature.');
3063

    
3064
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3065
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3066
} else {
3067
	$mlppp_text = "";
3068
}
3069

    
3070
$section->addInput(new Form_Button(
3071
	'btnadvppp',
3072
	'Advanced and MLPPP',
3073
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3074
	'fa-cog'
3075
))->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);
3076

    
3077
$form->add($section);
3078

    
3079
// Wireless interface
3080
if (isset($wancfg['wireless'])) {
3081

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

    
3084
	$section->addInput(new Form_Checkbox(
3085
		'persistcommonwireless',
3086
		'Persist common settings',
3087
		'Preserve common wireless configuration through interface deletions and reassignments.',
3088
		$pconfig['persistcommonwireless'],
3089
		'yes'
3090
	));
3091

    
3092
	$mode_list = ['auto' => 'Auto'];
3093

    
3094
	if (is_array($wl_modes)) {
3095
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3096
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3097
		}
3098
	}
3099

    
3100
	if (count($mode_list) == 1) {
3101
		$mode_list[''] = '';
3102
	}
3103

    
3104
	$section->addInput(new Form_Select(
3105
		'standard',
3106
		'Standard',
3107
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3108
		$mode_list
3109
	));
3110

    
3111
	if (isset($wl_modes['11g'])) {
3112
		$section->addInput(new Form_Select(
3113
			'protmode',
3114
			'802.11g OFDM Protection Mode',
3115
			$pconfig['protmode'],
3116
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3117
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3118
	} else {
3119
		$form->addGlobal(new Form_Input(
3120
			'protmode',
3121
			null,
3122
			'hidden',
3123
			'off'
3124
		));
3125
	}
3126

    
3127
	$mode_list = ['0' => gettext('Auto')];
3128

    
3129
	if (is_array($wl_modes)) {
3130
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3131
			if ($wl_standard == "11g") {
3132
				$wl_standard = "11b/g";
3133
			} else if ($wl_standard == "11ng") {
3134
				$wl_standard = "11b/g/n";
3135
			} else if ($wl_standard == "11na") {
3136
				$wl_standard = "11a/n";
3137
			}
3138

    
3139
			foreach ($wl_channels as $wl_channel) {
3140
				if (isset($wl_chaninfo[$wl_channel])) {
3141
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3142
				} else {
3143
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3144
				}
3145
			}
3146
		}
3147
	}
3148

    
3149
	$section->addInput(new Form_Select(
3150
		'channel',
3151
		'Channel',
3152
		$pconfig['channel'],
3153
		$mode_list
3154
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3155
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3156

    
3157
	$section->addInput(new Form_Select(
3158
		'channel_width',
3159
		'Channel width',
3160
		$pconfig['channel_width'],
3161
		$wl_ht_modes
3162
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3163

    
3164
	if (ANTENNAS) {
3165
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3166
			$group = new Form_Group('Antenna Settings');
3167

    
3168
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3169
				$group->add(new Form_Select(
3170
					'diversity',
3171
					null,
3172
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3173
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3174
				))->setHelp('Diversity');
3175
			}
3176

    
3177
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3178
				$group->add(new Form_Select(
3179
					'txantenna',
3180
					null,
3181
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3182
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3183
				))->setHelp('Transmit antenna');
3184
			}
3185

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

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

    
3197
			$section->add($group);
3198
		}
3199
	}
3200

    
3201
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3202
			$section->addInput(new Form_Input(
3203
				'distance',
3204
				'Distance setting (meters)',
3205
				'test',
3206
				$pconfig['distance']
3207
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3208
	}
3209

    
3210
	$form->add($section);
3211

    
3212
	// Regulatory settings
3213
	$section = new Form_Section('Regulatory Settings');
3214

    
3215
	$domain_list = array("" => 'Default');
3216

    
3217
	if (is_array($wl_regdomains)) {
3218
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3219
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3220
		}
3221
	}
3222

    
3223
	$section->addInput(new Form_Select(
3224
		'regdomain',
3225
		'Regulatory domain',
3226
		$pconfig['regdomain'],
3227
		$domain_list
3228
	))->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');
3229

    
3230
	$country_list = array('' => 'Default');
3231

    
3232
	if (is_array($wl_countries)) {
3233
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3234
			$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']);
3235
		}
3236
	}
3237

    
3238
	$section->addInput(new Form_Select(
3239
		'regcountry',
3240
		'Country',
3241
		$pconfig['regcountry'],
3242
		$country_list
3243
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3244

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

    
3256
	$form->add($section);
3257

    
3258
	$section = new Form_Section('Network-Specific Wireless Configuration');
3259

    
3260
	$section->addInput(new Form_Select(
3261
		'mode',
3262
		'Mode',
3263
		$pconfig['mode'],
3264
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3265
	));
3266

    
3267
	$section->addInput(new Form_Input(
3268
		'ssid',
3269
		'SSID',
3270
		'text',
3271
		$pconfig['ssid']
3272
	));
3273

    
3274
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3275
		$section->addInput(new Form_Select(
3276
			'puremode',
3277
			'Minimum wireless standard',
3278
			$pconfig['puremode'],
3279
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3280
		))->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)');
3281
	} elseif (isset($wl_modes['11g'])) {
3282
		$section->addInput(new Form_Checkbox(
3283
			'puremode',
3284
			'802.11g only',
3285
			null,
3286
			$pconfig['puremode'],
3287
			'11g'
3288
		))->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)');
3289
	}
3290

    
3291
	$section->addInput(new Form_Checkbox(
3292
		'apbridge_enable',
3293
		'Allow intra-BSS communication',
3294
		'Allow packets to pass between wireless clients directly when operating as an access point',
3295
		$pconfig['apbridge_enable'],
3296
		'yes'
3297
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3298

    
3299
	$section->addInput(new Form_Checkbox(
3300
		'wme_enable',
3301
		'Enable WME',
3302
		'Force the card to use WME (wireless QoS)',
3303
		$pconfig['wme_enable'],
3304
		'yes'
3305
	));
3306

    
3307
	$section->addInput(new Form_Checkbox(
3308
		'hidessid_enable',
3309
		'Hide SSID',
3310
		'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.)',
3311
		$pconfig['hidessid_enable'],
3312
		'yes'
3313
	));
3314

    
3315
	$form->add($section);
3316

    
3317
	// WPA Section
3318
	$section = new Form_Section('WPA');
3319

    
3320
	$section->addInput(new Form_Checkbox(
3321
		'wpa_enable',
3322
		'Enable',
3323
		'Enable WPA',
3324
		$pconfig['wpa_enable'],
3325
		'yes'
3326
	));
3327

    
3328
	$section->addInput(new Form_Select(
3329
		'wpa_mode',
3330
		'WPA mode',
3331
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3332
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3333
	));
3334

    
3335
	$section->addInput(new Form_Select(
3336
		'wpa_pairwise',
3337
		'WPA Pairwise',
3338
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3339
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3340
	));
3341

    
3342
	$section->addInput(new Form_Select(
3343
		'wpa_key_mgmt',
3344
		'WPA Key Management Mode',
3345
		$pconfig['wpa_key_mgmt'],
3346
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3347
	));
3348

    
3349
	$section->addInput(new Form_Input(
3350
		'passphrase',
3351
		'WPA Pre-Shared Key',
3352
		'text',
3353
		$pconfig['passphrase']
3354
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3355

    
3356
	$section->addInput(new Form_Select(
3357
		'wpa_eap_client_mode',
3358
		'EAP Client Mode',
3359
		$pconfig['wpa_eap_client_mode'],
3360
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3361
	));
3362

    
3363
	$section->addInput(new Form_Select(
3364
		'wpa_eap_ca',
3365
		'Certificate Authority',
3366
		$pconfig['wpa_eap_ca'],
3367
		cert_build_list('ca', 'HTTPS')
3368
	));
3369

    
3370
	$section->addInput(new Form_Select(
3371
		'wpa_eap_inner_auth',
3372
		'Inner Authentication Method',
3373
		$pconfig['wpa_eap_inner_auth'],
3374
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3375
	));
3376

    
3377
	$section->addInput(new Form_Input(
3378
		'wpa_eap_inner_id',
3379
		'*Inner Authentication Identity',
3380
		'text',
3381
		$pconfig['wpa_eap_inner_id']
3382
	));
3383

    
3384
	$section->addInput(new Form_Input(
3385
		'wpa_eap_inner_password',
3386
		'*Inner Authentication Passphrase',
3387
		'text',
3388
		$pconfig['wpa_eap_inner_password']
3389
	));
3390

    
3391
	$section->addInput(new Form_Select(
3392
		'wpa_eap_cert',
3393
		'TLS/TTLS Client Certificate',
3394
		$pconfig['wpa_eap_cert'],
3395
		cert_build_list('cert', 'HTTPS')
3396
	));
3397

    
3398
	$section->addInput(new Form_Input(
3399
		'wpa_group_rekey',
3400
		'Group Key Rotation',
3401
		'number',
3402
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3403
		['min' => '1', 'max' => 9999]
3404
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3405

    
3406
	$section->addInput(new Form_Input(
3407
		'wpa_gmk_rekey',
3408
		'Group Master Key Regeneration',
3409
		'number',
3410
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3411
		['min' => '1', 'max' => 9999]
3412
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3413

    
3414
	$section->addInput(new Form_Checkbox(
3415
		'wpa_strict_rekey',
3416
		'Strict Key Regeneration',
3417
		'Force the AP to rekey whenever a client disassociates',
3418
		$pconfig['wpa_strict_rekey'],
3419
		'yes'
3420
	));
3421

    
3422
	$form->add($section);
3423

    
3424
	$section = new Form_Section('802.1x RADIUS Options');
3425
	$section->addClass('ieee8021x_group');
3426

    
3427
	$section->addInput(new Form_Checkbox(
3428
		'ieee8021x',
3429
		'IEEE802.1X',
3430
		'Enable 802.1X authentication',
3431
		$pconfig['ieee8021x'],
3432
		'yes'
3433
	));
3434

    
3435
	$group = new Form_Group('Primary 802.1X server');
3436

    
3437
	$group->add(new Form_IpAddress(
3438
		'auth_server_addr',
3439
		'IP Address',
3440
		$pconfig['auth_server_addr']
3441
	))->setHelp('IP address of the RADIUS server');
3442

    
3443
	$group->add(new Form_Input(
3444
		'auth_server_port',
3445
		'Port',
3446
		'number',
3447
		$pconfig['auth_server_port']
3448
	))->setHelp('Server auth port. Default is 1812');
3449

    
3450
	$group->add(new Form_Input(
3451
		'auth_server_shared_secret',
3452
		'Shared Secret',
3453
		'text',
3454
		$pconfig['auth_server_shared_secret']
3455
	))->setHelp('RADIUS Shared secret for this firewall');
3456

    
3457
	$section->add($group);
3458

    
3459
	$group = new Form_Group('Secondary 802.1X server');
3460

    
3461
	$group->add(new Form_IpAddress(
3462
		'auth_server_addr2',
3463
		'IP Address',
3464
		$pconfig['auth_server_addr2']
3465
	))->setHelp('IP address of the RADIUS server');
3466

    
3467
	$group->add(new Form_Input(
3468
		'auth_server_port2',
3469
		'Port',
3470
		'number',
3471
		$pconfig['auth_server_port2']
3472
	))->setHelp('Server auth port. Default is 1812');
3473

    
3474
	$group->add(new Form_Input(
3475
		'auth_server_shared_secret2',
3476
		'Shared Secret',
3477
		'text',
3478
		$pconfig['auth_server_shared_secret2']
3479
	))->setHelp('RADIUS Shared secret for this firewall');
3480

    
3481
	$section->add($group);
3482

    
3483
	$section->addInput(new Form_Checkbox(
3484
		'rsn_preauth',
3485
		'Authentication Roaming Preauth',
3486
		null,
3487
		$pconfig['rsn_preauth'],
3488
		'yes'
3489
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3490

    
3491
	$form->add($section);
3492
}
3493

    
3494
$section = new Form_Section('Reserved Networks');
3495

    
3496
$section->addInput(new Form_Checkbox(
3497
	'blockpriv',
3498
	'Block private networks and loopback addresses',
3499
	'',
3500
	$pconfig['blockpriv'],
3501
	'yes'
3502
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3503
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3504
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3505

    
3506
$section->addInput(new Form_Checkbox(
3507
	'blockbogons',
3508
	'Block bogon networks',
3509
	'',
3510
	$pconfig['blockbogons'],
3511
	'yes'
3512
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3513
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3514
			'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' .
3515
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3516

    
3517
$form->add($section);
3518

    
3519
$form->addGlobal(new Form_Input(
3520
	'if',
3521
	null,
3522
	'hidden',
3523
	$if
3524
));
3525

    
3526
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3527
	$form->addGlobal(new Form_Input(
3528
		'ppp_port',
3529
		null,
3530
		'hidden',
3531
		$pconfig['port']
3532
	));
3533
}
3534

    
3535
$form->addGlobal(new Form_Input(
3536
	'ptpid',
3537
	null,
3538
	'hidden',
3539
	$pconfig['ptpid']
3540
));
3541

    
3542

    
3543
// Add new gateway modal pop-up
3544
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3545

    
3546
$modal->addInput(new Form_Checkbox(
3547
	'defaultgw4',
3548
	'Default',
3549
	'Default gateway',
3550
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3551
));
3552

    
3553
$modal->addInput(new Form_Input(
3554
	'gatewayname4',
3555
	'Gateway name',
3556
	'text',
3557
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3558
));
3559

    
3560
$modal->addInput(new Form_IpAddress(
3561
	'gatewayip4',
3562
	'Gateway IPv4',
3563
	$gateway_settings4['gateway'],
3564
	'V4'
3565
));
3566

    
3567
$modal->addInput(new Form_Input(
3568
	'gatewaydescr4',
3569
	'Description',
3570
	'text',
3571
	$gateway_settings4['descr']
3572
));
3573

    
3574
$btnaddgw4 = new Form_Button(
3575
	'add4',
3576
	'Add',
3577
	null,
3578
	'fa-plus'
3579
);
3580

    
3581
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3582

    
3583
$btncnxgw4 = new Form_Button(
3584
	'cnx4',
3585
	'Cancel',
3586
	null,
3587
	'fa-undo'
3588
);
3589

    
3590
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3591

    
3592
$modal->addInput(new Form_StaticText(
3593
	null,
3594
	$btnaddgw4 . $btncnxgw4
3595
));
3596

    
3597
$form->add($modal);
3598

    
3599
print($form);
3600
?>
3601

    
3602
<script type="text/javascript">
3603
//<![CDATA[
3604
events.push(function() {
3605
	function updateType(t) {
3606

    
3607
		switch (t) {
3608
			case "none": {
3609
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3610
				break;
3611
			}
3612
			case "staticv4": {
3613
				$('.dhcpadvanced, .none, .dhcp').hide();
3614
				$('.pppoe, .pptp, .ppp').hide();
3615
				break;
3616
			}
3617
			case "dhcp": {
3618
				$('.dhcpadvanced, .none').hide();
3619
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3620
										//			about the staticv4 class
3621
				$('.pppoe, .pptp, .ppp').hide();
3622
				break;
3623
			}
3624
			case "ppp": {
3625
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3626
				country_list();
3627
				break;
3628
			}
3629
			case "pppoe": {
3630
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3631
				break;
3632
			}
3633
			case "l2tp": {
3634
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3635
				$('.pptp, .l2tp_secret').show();
3636
				break;
3637
			}
3638
			case "pptp": {
3639
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3640
				$('.pptp').show();
3641
				break;
3642
			}
3643
		}
3644

    
3645
		if (t != "l2tp" && t != "pptp") {
3646
			$('.'+t).show();
3647
		}
3648
	}
3649

    
3650
	function updateTypeSix(t) {
3651
		if (!isNaN(t[0])) {
3652
			t = '_' + t;
3653
		}
3654

    
3655
		switch (t) {
3656
			case "none": {
3657
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3658
				break;
3659
			}
3660
			case "staticv6": {
3661
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3662
				break;
3663
			}
3664
			case "slaac": {
3665
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3666
				break;
3667
			}
3668
			case "dhcp6": {
3669
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3670
				break;
3671
			}
3672
			case "_6rd": {
3673
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3674
				break;
3675
			}
3676
			case "_6to4": {
3677
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3678
				break;
3679
			}
3680
			case "track6": {
3681
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3682
				update_track6_prefix();
3683
				break;
3684
			}
3685
		}
3686

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

    
3692
	function show_reset_settings(reset_type) {
3693
		if (reset_type == 'preset') {
3694
			$('.pppoepreset').show();
3695
			$('.pppoecustom').hide();
3696
		} else if (reset_type == 'custom') {
3697
			$('.pppoecustom').show();
3698
			$('.pppoepreset').hide();
3699
		} else {
3700
			$('.pppoecustom').hide();
3701
			$('.pppoepreset').hide();
3702
		}
3703
	}
3704

    
3705
	function update_track6_prefix() {
3706
		var iface = $("#track6-interface").val();
3707
		if (iface == null) {
3708
			return;
3709
		}
3710

    
3711
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3712
		if (track6_prefix_ids == null) {
3713
			return;
3714
		}
3715

    
3716
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3717
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3718
	}
3719

    
3720
	function addOption_v4() {
3721
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3722
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3723
	}
3724

    
3725
	function addOption_v6() {
3726
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3727
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3728
	}
3729

    
3730
	function addSelectboxOption(selectbox, text, value) {
3731
		var optn = document.createElement("OPTION");
3732
		optn.text = text;
3733
		optn.value = value;
3734
		selectbox.append(optn);
3735
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3736
	}
3737

    
3738
	function country_list() {
3739
		$('#country').children().remove();
3740
		$('#provider_list').children().remove();
3741
		$('#providerplan').children().remove();
3742
		$.ajax("getserviceproviders.php",{
3743
			success: function(response) {
3744

    
3745
				var responseTextArr = response.split("\n");
3746
				responseTextArr.sort();
3747

    
3748
				responseTextArr.forEach( function(value) {
3749
					country = value.split(":");
3750
					$('#country').append($('<option>', {
3751
						value: country[1],
3752
						text : country[0]
3753
					}));
3754
				});
3755
			}
3756
		});
3757
	}
3758

    
3759
	function providers_list() {
3760
		$('#provider_list').children().remove();
3761
		$('#providerplan').children().remove();
3762
		$.ajax("getserviceproviders.php",{
3763
			type: 'post',
3764
			data: {country : $('#country').val()},
3765
			success: function(response) {
3766
				var responseTextArr = response.split("\n");
3767
				responseTextArr.sort();
3768
				responseTextArr.forEach( function(value) {
3769
					$('#provider_list').append($('<option>', {
3770
							value: value,
3771
							text : value
3772
					}));
3773
				});
3774
			}
3775
		});
3776
	}
3777

    
3778
	function providerplan_list() {
3779
		$('#providerplan').children().remove();
3780
		$.ajax("getserviceproviders.php",{
3781
			type: 'post',
3782
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3783
			success: function(response) {
3784
				var responseTextArr = response.split("\n");
3785
				responseTextArr.sort();
3786

    
3787
				$('#providerplan').append($('<option>', {
3788
					value: '',
3789
					text : ''
3790
				}));
3791

    
3792
				responseTextArr.forEach( function(value) {
3793
					if (value != "") {
3794
						providerplan = value.split(":");
3795

    
3796
						$('#providerplan').append($('<option>', {
3797
							value: providerplan[1],
3798
							text : providerplan[0] + " - " + providerplan[1]
3799
						}));
3800
					}
3801
				});
3802
			}
3803
		});
3804
	}
3805

    
3806
	function prefill_provider() {
3807
		$.ajax("getserviceproviders.php",{
3808
			type: 'post',
3809
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3810
			success: function(data, textStatus, response) {
3811
				var xmldoc = response.responseXML;
3812
				var provider = xmldoc.getElementsByTagName('connection')[0];
3813
				$('#ppp_username').val('');
3814
				$('#ppp_password').val('');
3815
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3816
					$('#phone').val('#777');
3817
					$('#apn').val('');
3818
				} else {
3819
					$('#phone').val('*99#');
3820
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3821
				}
3822
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3823
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3824
				$('#ppp_username').val(ppp_username);
3825
				$('#ppp_password').val(ppp_password);
3826
			}
3827
		});
3828
	}
3829

    
3830
	function show_dhcp6adv() {
3831
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3832
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3833

    
3834
		hideCheckbox('dhcp6usev4iface', ovr);
3835
		hideCheckbox('dhcp6prefixonly', ovr);
3836
		hideInput('dhcp6-ia-pd-len', ovr);
3837
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3838
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3839

    
3840
		hideClass('dhcp6advanced', !adv || ovr);
3841
	}
3842

    
3843
	function setDHCPoptions() {
3844
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3845
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3846

    
3847
		if (ovr) {
3848
			hideInput('dhcphostname', true);
3849
			hideIpAddress('alias-address', true);
3850
			hideInput('dhcprejectfrom', true);
3851
			hideInput('adv_dhcp_config_file_override_path', false);
3852
			hideClass('dhcpadvanced', true);
3853
		} else {
3854
			hideInput('dhcphostname', false);
3855
			hideIpAddress('alias-address', false);
3856
			hideInput('dhcprejectfrom', false);
3857
			hideInput('adv_dhcp_config_file_override_path', true);
3858
			hideClass('dhcpadvanced', !adv);
3859
		}
3860
	}
3861

    
3862
	// DHCP preset actions
3863
	// Set presets from value of radio buttons
3864
	function setPresets(val) {
3865
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3866
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3867
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3868
		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']);?>");
3869
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3870
	}
3871

    
3872
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3873
		$('#adv_dhcp_pt_timeout').val(timeout);
3874
		$('#adv_dhcp_pt_retry').val(retry);
3875
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3876
		$('#adv_dhcp_pt_reboot').val(reboot);
3877
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3878
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3879
	}
3880

    
3881
	function setPPPoEDialOnDemandItems() {
3882
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3883
	}
3884

    
3885
	function setPPTPDialOnDemandItems() {
3886
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3887
	}
3888

    
3889
	function show_wpaoptions() {
3890
		var wpa = !($('#wpa_enable').prop('checked'));
3891

    
3892
		hideInput('passphrase', wpa);
3893
		hideInput('wpa_mode', wpa);
3894
		hideInput('wpa_key_mgmt', wpa);
3895
		hideInput('wpa_pairwise', wpa);
3896
		hideCheckbox('wpa_strict_rekey', wpa);
3897
		hideClass('ieee8021x_group', true);
3898
		if ($('#mode').val() == 'hostap') {
3899
			hideInput('wpa_group_rekey', wpa);
3900
			hideInput('wpa_gmk_rekey', wpa);
3901
			hideCheckbox('wpa_strict_rekey', wpa);
3902
		} else {
3903
			hideInput('wpa_group_rekey', true);
3904
			hideInput('wpa_gmk_rekey', true);
3905
			hideCheckbox('wpa_strict_rekey', true);
3906
		}
3907
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3908
	}
3909

    
3910
	function updatewifistandard(s) {
3911
		switch (s) {
3912
			case "auto": {
3913
				hideInput('protmode', false);
3914
				hideInput('channel_width', false);
3915
				break;
3916
			}
3917
			case "11b": {
3918
				hideInput('protmode', true);
3919
				hideInput('channel_width', true);
3920
				break;
3921
			}
3922
			case "11g": {
3923
				hideInput('protmode', false);
3924
				hideInput('channel_width', true);
3925
				break;
3926
			}
3927
			case "11ng": {
3928
				hideInput('protmode', false);
3929
				hideInput('channel_width', false);
3930
				break;
3931
			}
3932
			case "11a": {
3933
				hideInput('protmode', true);
3934
				hideInput('channel_width', true);
3935
				break;
3936
			}
3937
			case "11na": {
3938
				hideInput('protmode', true);
3939
				hideInput('channel_width', false);
3940
				break;
3941
			}
3942
			default: {
3943
				break;
3944
			}
3945
		}
3946
	}
3947

    
3948
	function updatewifimode(m) {
3949
		switch (m) {
3950
			case "adhoc": {
3951
				hideInput('puremode', true);
3952
				hideCheckbox('apbridge_enable', true);
3953
				hideCheckbox('hidessid_enable', false);
3954
				break;
3955
			}
3956
			case "hostap": {
3957
				hideInput('puremode', false);
3958
				hideCheckbox('apbridge_enable', false);
3959
				hideCheckbox('hidessid_enable', false);
3960
				break;
3961
			}
3962
			default: {
3963
				hideInput('puremode', true);
3964
				hideCheckbox('apbridge_enable', true);
3965
				hideCheckbox('hidessid_enable', true);
3966
				break;
3967
			}
3968
		}
3969
		show_wpaoptions();
3970
		updateeapclientmode($('#wpa_eap_client_mode').val());
3971
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3972
	}
3973

    
3974
	function updateeapclientmode(m) {
3975
		if ($('#mode').val() == 'bss') {
3976
			var wpa = !($('#wpa_enable').prop('checked'));
3977
		} else {
3978
			var wpa = true;
3979
		}
3980
		switch (m) {
3981
			case "PEAP": {
3982
				hideInput('wpa_eap_cert', true);
3983
				hideInput('wpa_eap_inner_auth', wpa);
3984
				hideInput('wpa_eap_inner_id', wpa);
3985
				hideInput('wpa_eap_inner_password', wpa);
3986
				break;
3987
			}
3988
			case "TLS": {
3989
				hideInput('wpa_eap_cert', wpa);
3990
				hideInput('wpa_eap_inner_auth', true);
3991
				hideInput('wpa_eap_inner_id', true);
3992
				hideInput('wpa_eap_inner_password', true);
3993
				break;
3994
			}
3995
			case "TTLS": {
3996
				hideInput('wpa_eap_cert', wpa);
3997
				hideInput('wpa_eap_inner_auth', wpa);
3998
				hideInput('wpa_eap_inner_id', wpa);
3999
				hideInput('wpa_eap_inner_password', wpa);
4000
				break;
4001
			}
4002
			default: {
4003
				break;
4004
			}
4005
		}
4006
	}
4007

    
4008
	function updatewpakeymgmt(m) {
4009
		hideInput('passphrase', false);
4010
		hideInput('wpa_eap_client_mode', true);
4011
		hideInput('wpa_eap_ca', true);
4012
		hideInput('wpa_eap_cert', true);
4013
		hideInput('wpa_eap_inner_auth', true);
4014
		hideInput('wpa_eap_inner_id', true);
4015
		hideInput('wpa_eap_inner_password', true);
4016
		hideClass('ieee8021x_group', true);
4017
		if (m == "WPA-EAP") {
4018
			hideInput('passphrase', true);
4019
			if ($('#mode').val() == 'bss') {
4020
				hideInput('wpa_eap_client_mode', false);
4021
				hideInput('wpa_eap_ca', false);
4022
				updateeapclientmode($('#wpa_eap_client_mode').val());
4023
			} else if ($('#mode').val() == 'hostap') {
4024
				hideClass('ieee8021x_group', false);
4025
			}
4026
		} else if (m != "WPA-PSK") {
4027
			hideInput('passphrase', false);
4028
			if ($('#mode').val() == 'bss') {
4029
				hideInput('wpa_eap_client_mode', false);
4030
				hideInput('wpa_eap_ca', false);
4031
				hideInput('wpa_eap_cert', false);
4032
				hideInput('wpa_eap_inner_auth', false);
4033
				hideInput('wpa_eap_inner_id', false);
4034
				hideInput('wpa_eap_inner_password', false);
4035
			} else if ($('#mode').val() == 'hostap') {
4036
				hideClass('ieee8021x_group', false);
4037
			}
4038
		}
4039
	}
4040

    
4041
	// ---------- On initial page load ------------------------------------------------------------
4042

    
4043
	updateType($('#type').val());
4044
	updateTypeSix($('#type6').val());
4045
	show_reset_settings($('#pppoe-reset-type').val());
4046
	hideClass('dhcp6advanced', true);
4047
	hideClass('dhcpadvanced', true);
4048
	show_dhcp6adv();
4049
	setDHCPoptions();
4050
	setPPPoEDialOnDemandItems();
4051
	setPPTPDialOnDemandItems();
4052
	show_wpaoptions();
4053
	updatewifistandard($('#standard').val());
4054
	updatewifimode($('#mode').val());
4055

    
4056
	// Set preset buttons on page load
4057
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4058
	if (sv == "") {
4059
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4060
	} else {
4061
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4062
	}
4063

    
4064
	// Set preset from value
4065
	setPresets(sv);
4066

    
4067
	// If the user wants to add a gateway, then add that to the gateway selection
4068
	if ($("#gatewayip4").val() != '') {
4069
		addOption_v4();
4070
	}
4071
	if ($("#gatewayip6").val() != '') {
4072
		addOption_v6();
4073
	}
4074

    
4075
	// ---------- Click checkbox handlers ---------------------------------------------------------
4076

    
4077
	$('#type').on('change', function() {
4078
		updateType(this.value);
4079
	});
4080

    
4081
	$('#type6').on('change', function() {
4082
		updateTypeSix(this.value);
4083
	});
4084

    
4085
	$('#standard').on('change', function() {
4086
		updatewifistandard(this.value);
4087
	});
4088

    
4089
	$('#mode').on('change', function() {
4090
		updatewifimode(this.value);
4091
	});
4092

    
4093
	$('#wpa_key_mgmt').on('change', function() {
4094
		updatewpakeymgmt(this.value);
4095
	});
4096

    
4097
	$('#wpa_eap_client_mode').on('change', function() {
4098
		updateeapclientmode(this.value);
4099
	});
4100

    
4101
	$('#track6-interface').on('change', function() {
4102
		update_track6_prefix();
4103
	});
4104

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

    
4109
	$("#add4").click(function() {
4110
		addOption_v4();
4111
		$("#newgateway4").modal('hide');
4112
	});
4113

    
4114
	$("#cnx4").click(function() {
4115
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4116
		$("#gatewayip4").val('');
4117
		$("#gatewaydescr4").val('');
4118
		$("#defaultgw4").prop("checked", false);
4119
		$("#newgateway4").modal('hide');
4120
	});
4121

    
4122
	$("#add6").click(function() {
4123
		addOption_v6();
4124
		$("#newgateway6").modal('hide');
4125
	});
4126

    
4127
	$("#cnx6").click(function() {
4128
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4129
		$("#gatewayip6").val('');
4130
		$("#gatewaydescr6").val('');
4131
		$("#defaultgw6").prop("checked", false);
4132
		$("#newgateway6").modal('hide');
4133
	});
4134

    
4135
	$('#country').on('change', function() {
4136
		providers_list();
4137
	});
4138

    
4139
	$('#provider_list').on('change', function() {
4140
		providerplan_list();
4141
	});
4142

    
4143
	$('#providerplan').on('change', function() {
4144
		prefill_provider();
4145
	});
4146

    
4147
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4148
		setDHCPoptions();
4149
	});
4150

    
4151
	$('#adv_dhcp6_config_advanced').click(function () {
4152
		show_dhcp6adv();
4153
	});
4154

    
4155
	$('#adv_dhcp6_config_file_override').click(function () {
4156
		show_dhcp6adv();
4157
	});
4158

    
4159
	// On click . .
4160
	$('#pppoe_dialondemand').click(function () {
4161
		setPPPoEDialOnDemandItems();
4162
	});
4163

    
4164
	$('#pptp_dialondemand').click(function () {
4165
		setPPTPDialOnDemandItems();
4166
	});
4167

    
4168
	$('[name=adv_dhcp_pt_values]').click(function () {
4169
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4170
	});
4171

    
4172
	$('#wpa_enable').click(function () {
4173
		show_wpaoptions();
4174
	});
4175

    
4176
	$('#pppoe_resetdate').datepicker();
4177

    
4178
});
4179
//]]>
4180
</script>
4181

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