Project

General

Profile

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

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

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

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

    
51
define("ANTENNAS", false);
52

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

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

    
64

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
436
}
437

    
438
$changes_applied = false;
439

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

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

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

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

    
493
		clear_subsystem_dirty('interfaces');
494

    
495
		$retval |= filter_configure();
496

    
497
		enable_rrd_graphing();
498

    
499
		$changes_applied = true;
500

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
941
		unset($min_mtu, $max_mtu);
942

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1634
		write_config("Interfaces settings changed");
1635

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

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

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

    
1653
		mark_subsystem_dirty('interfaces');
1654

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

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

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

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

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

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

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

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

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

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

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

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

    
1847
	if ($clone_count > 1) {
1848
		$old_wireless_mode = $wancfg['wireless']['mode'];
1849
		$wancfg['wireless']['mode'] = $_POST['mode'];
1850
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1851
			$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']]);
1852
		} else {
1853
			pfSense_interface_destroy("{$wlanif}_");
1854
		}
1855
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1856
	}
1857
}
1858

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

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

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

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

    
1884
$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"));
1885

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

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

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

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

    
1901
	return($list);
1902
}
1903

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

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

    
1917
	return($list);
1918
}
1919

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

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

    
1933
	return($list);
1934
}
1935

    
1936
include("head.inc");
1937

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

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

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

    
1952
$form = new Form();
1953

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2203
// ==== DHCP client configuration =============================
2204

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

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

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

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

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

    
2226
$section->addInput(new Form_Input(
2227
	'dhcphostname',
2228
	'Hostname',
2229
	'text',
2230
	$pconfig['dhcphostname']
2231
))->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).');
2232

    
2233
$section->addInput(new Form_IpAddress(
2234
	'alias-address',
2235
	'Alias IPv4 address',
2236
	$pconfig['alias-address'],
2237
	'V4'
2238
))->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.');
2239

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2396
$section->addInput(new Form_Input(
2397
	'adv_dhcp_option_modifiers',
2398
	'Option modifiers',
2399
	'text',
2400
	$pconfig['adv_dhcp_option_modifiers']
2401
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2402
			'modifiers: (default, supersede, prepend, append) %1$s' .
2403
			'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>');
2404

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

    
2407
// DHCP6 client config
2408

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

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

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

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

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

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

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

    
2444
$section->addInput(new Form_Select(
2445
	'dhcp6-ia-pd-len',
2446
	'DHCPv6 Prefix Delegation size',
2447
	$pconfig['dhcp6-ia-pd-len'],
2448
	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")
2449
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2450

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

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

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

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

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

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

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

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

    
2497
// DHCP6 client config - Advanced
2498

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2716
$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>');
2717

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2786
	return($list);
2787
}
2788

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

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

    
2800
$section->addInput(new Form_Input(
2801
	'track6-prefix-id--hex',
2802
	'IPv6 Prefix ID',
2803
	'text',
2804
	sprintf("%x", $pconfig['track6-prefix-id'])
2805
))->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>');
2806

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

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

    
2816
/// PPP section
2817

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

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

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

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

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

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

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

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

    
2871

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

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

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

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

    
2887
	return($list);
2888
}
2889

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2989
$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');
2990

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3109
$section->addInput(new Form_Button(
3110
	'btnadvppp',
3111
	'Advanced and MLPPP',
3112
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3113
	'fa-cog'
3114
))->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);
3115

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3262
	$section->addInput(new Form_Select(
3263
		'regdomain',
3264
		'Regulatory domain',
3265
		$pconfig['regdomain'],
3266
		$domain_list
3267
	))->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');
3268

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

    
3271
	if (is_array($wl_countries)) {
3272
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3273
			$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']);
3274
		}
3275
	}
3276

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

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

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

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

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

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

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

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

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

    
3346
	$section->addInput(new Form_Checkbox(
3347
		'hidessid_enable',
3348
		'Hide SSID',
3349
		'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.)',
3350
		$pconfig['hidessid_enable'],
3351
		'yes'
3352
	));
3353

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3581

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

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

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

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

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

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

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

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

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

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

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

    
3638
print($form);
3639
?>
3640

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3777
	function country_list() {
3778
		$('#country').children().remove();
3779
		$('#provider_list').children().remove();
3780
		$('#providerplan').children().remove();
3781
		$.ajax("getserviceproviders.php",{
3782
			success: function(response) {
3783

    
3784
				var responseTextArr = response.split("\n");
3785
				responseTextArr.sort();
3786

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

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

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

    
3826
				$('#providerplan').append($('<option>', {
3827
					value: '',
3828
					text : ''
3829
				}));
3830

    
3831
				responseTextArr.forEach( function(value) {
3832
					if (value != "") {
3833
						providerplan = value.split(":");
3834

    
3835
						$('#providerplan').append($('<option>', {
3836
							value: providerplan[1],
3837
							text : providerplan[0] + " - " + providerplan[1]
3838
						}));
3839
					}
3840
				});
3841
			}
3842
		});
3843
	}
3844

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

    
3869
	function show_dhcp6adv() {
3870
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3871
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3872

    
3873
		hideCheckbox('dhcp6usev4iface', ovr);
3874
		hideCheckbox('dhcp6prefixonly', ovr);
3875
		hideInput('dhcp6-ia-pd-len', ovr);
3876
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3877
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3878

    
3879
		hideClass('dhcp6advanced', !adv || ovr);
3880
	}
3881

    
3882
	function setDHCPoptions() {
3883
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3884
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3885

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

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

    
3911
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3912
		$('#adv_dhcp_pt_timeout').val(timeout);
3913
		$('#adv_dhcp_pt_retry').val(retry);
3914
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3915
		$('#adv_dhcp_pt_reboot').val(reboot);
3916
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3917
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3918
	}
3919

    
3920
	function setPPPoEDialOnDemandItems() {
3921
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3922
	}
3923

    
3924
	function setPPTPDialOnDemandItems() {
3925
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3926
	}
3927

    
3928
	function show_wpaoptions() {
3929
		var wpa = !($('#wpa_enable').prop('checked'));
3930

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

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

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

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

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

    
4080
	// ---------- On initial page load ------------------------------------------------------------
4081

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

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

    
4103
	// Set preset from value
4104
	setPresets(sv);
4105

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

    
4114
	// ---------- Click checkbox handlers ---------------------------------------------------------
4115

    
4116
	$('#type').on('change', function() {
4117
		updateType(this.value);
4118
	});
4119

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

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

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

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

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

    
4140
	$('#track6-interface').on('change', function() {
4141
		update_track6_prefix();
4142
	});
4143

    
4144
	$('#pppoe-reset-type').on('change', function() {
4145
		show_reset_settings(this.value);
4146
	});
4147

    
4148
	$("#add4").click(function() {
4149
		addOption_v4();
4150
		$("#newgateway4").modal('hide');
4151
	});
4152

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

    
4161
	$("#add6").click(function() {
4162
		addOption_v6();
4163
		$("#newgateway6").modal('hide');
4164
	});
4165

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

    
4174
	$('#country').on('change', function() {
4175
		providers_list();
4176
	});
4177

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

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

    
4186
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4187
		setDHCPoptions();
4188
	});
4189

    
4190
	$('#adv_dhcp6_config_advanced').click(function () {
4191
		show_dhcp6adv();
4192
	});
4193

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

    
4198
	// On click . .
4199
	$('#pppoe_dialondemand').click(function () {
4200
		setPPPoEDialOnDemandItems();
4201
	});
4202

    
4203
	$('#pptp_dialondemand').click(function () {
4204
		setPPTPDialOnDemandItems();
4205
	});
4206

    
4207
	$('[name=adv_dhcp_pt_values]').click(function () {
4208
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4209
	});
4210

    
4211
	$('#wpa_enable').click(function () {
4212
		show_wpaoptions();
4213
	});
4214

    
4215
	$('#pppoe_resetdate').datepicker();
4216

    
4217
});
4218
//]]>
4219
</script>
4220

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