Project

General

Profile

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

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

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

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

    
50
define("ANTENNAS", false);
51

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

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

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
438
}
439

    
440
$changes_applied = false;
441

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

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

    
498
		/*
499
                 * If the parent interface has changed MTU above, the VLANs needs to be
500
                 * redone.
501
		 */
502
		if (!empty($vlan_redo)) {
503
			foreach ($vlan_redo as $vlredo) {
504
				interfaces_vlan_configure_mtu($vlredo);
505
			}
506
		}
507

    
508
		/* restart snmp so that it binds to correct address */
509
		$retval |= services_snmpd_configure($ifapply);
510

    
511
		/* sync filter configuration */
512
		setup_gateways_monitor();
513

    
514
		clear_subsystem_dirty('interfaces');
515

    
516
		$retval |= filter_configure();
517

    
518
		enable_rrd_graphing();
519

    
520
		$changes_applied = true;
521

    
522
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
523
			clear_subsystem_dirty('staticroutes');
524
		}
525

    
526
		init_config_arr(array('syslog'));
527
		if (isset($config['syslog']['enable']) && ($ifapply == $config['syslog']['sourceip'])) {
528
			system_syslogd_start();
529
		}
530

    
531
		services_igmpproxy_configure($ifapply);
532
	}
533
	@unlink("{$g['tmp_path']}/.interfaces.apply");
534
} else if ($_POST['save']) {
535

    
536
	unset($input_errors);
537
	$pconfig = $_POST;
538

    
539
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
540
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
541
	} else {
542
		$pconfig['track6-prefix-id'] = 0;
543
	}
544

    
545
	/* filter out spaces from descriptions */
546
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
547

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

    
562
	/* input validation */
563
	$reqdfields = explode(" ", "descr");
564
	$reqdfieldsn = array(gettext("Description"));
565
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
566

    
567
	if (!$input_errors) {
568
		/* description unique? */
569
		foreach ($ifdescrs as $ifent => $ifdescr) {
570
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
571
				$input_errors[] = gettext("An interface with the specified description already exists.");
572
				break;
573
			}
574
		}
575

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

    
585
		/* Is the description already used as an interface group name? */
586
		if (is_array($config['ifgroups']['ifgroupentry'])) {
587
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
588
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
589
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
590
				}
591
			}
592
		}
593

    
594
		if (is_numeric($_POST['descr'])) {
595
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
596
		}
597

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

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

    
608
		/*
609
		 * Packages (e.g. tinc) create interface groups, reserve this
610
		 * namespace pkg_ for them.
611
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
612
		 */
613
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
614
			$input_errors[] = gettext("The interface description cannot start with pkg_");
615
		}
616
	}
617

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

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

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

    
766
			if (empty($_POST['track6-interface'])) {
767
				$input_errors[] = gettext("A valid interface to track must be selected.");
768
			}
769

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

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

    
809
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
810
			if ($_POST['subnet'] < 31) {
811
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
812
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
813
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
814
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
815
				}
816
			}
817

    
818
			foreach ($staticroutes as $route_subnet) {
819
				list($network, $subnet) = explode("/", $route_subnet);
820
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
821
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
822
					break;
823
				}
824
				unset($network, $subnet);
825
			}
826
		}
827
	}
828
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
829
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
830

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

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

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

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

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

    
951
		unset($min_mtu, $max_mtu);
952

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

    
971
				$realhwif_array = get_parent_interface($ifdata['if']);
972
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
973
				$parent_realhwif = $realhwif_array[0];
974

    
975
				if ($parent_realhwif != $wancfg['if']) {
976
					continue;
977
				}
978

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

    
1075
		if ($_POST['passphrase']) {
1076
			$passlen = strlen($_POST['passphrase']);
1077
			if ($passlen < 8 || $passlen > 63) {
1078
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1079
			}
1080
		}
1081

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

    
1100
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1101
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1102
	}
1103

    
1104
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1105
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1106
	}
1107

    
1108
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1109
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1110
	}
1111

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

    
1116
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1117
		$gateway_settings4['interface'] = $_POST['if'];
1118
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1119
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1120
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1121
		$gateway_settings4['ipprotocol'] = 'inet';
1122
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1123
		foreach ($gw_input_errors as $input_error_text) {
1124
			$input_errors[] = $input_error_text;
1125
		}
1126
	}
1127

    
1128
	if ($_POST['gatewayip6']) {
1129
		// The user wants to add an IPv6 gateway - validate the settings
1130
		$gateway_settings6 = array();
1131

    
1132
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1133
		$gateway_settings6['interface'] = $_POST['if'];
1134
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1135
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1136
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1137
		$gateway_settings6['ipprotocol'] = 'inet6';
1138
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1139
		foreach ($gw_input_errors as $input_error_text) {
1140
			$input_errors[] = $input_error_text;
1141
		}
1142
	}
1143

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

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

    
1193
		unset($wancfg['dhcpvlanenable']);
1194
		unset($wancfg['dhcpcvpt']);
1195

    
1196
		unset($wancfg['adv_dhcp_pt_timeout']);
1197
		unset($wancfg['adv_dhcp_pt_retry']);
1198
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1199
		unset($wancfg['adv_dhcp_pt_reboot']);
1200
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1201
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1202

    
1203
		unset($wancfg['adv_dhcp_pt_values']);
1204

    
1205
		unset($wancfg['adv_dhcp_send_options']);
1206
		unset($wancfg['adv_dhcp_request_options']);
1207
		unset($wancfg['adv_dhcp_required_options']);
1208
		unset($wancfg['adv_dhcp_option_modifiers']);
1209

    
1210
		unset($wancfg['adv_dhcp_config_advanced']);
1211
		unset($wancfg['adv_dhcp_config_file_override']);
1212
		unset($wancfg['adv_dhcp_config_file_override_path']);
1213

    
1214
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1215
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1216
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1217
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1218

    
1219
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1220
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1221
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1222
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1223
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1224

    
1225
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1226
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1227
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1228
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1229
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1230

    
1231
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1232
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1233
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1234

    
1235
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1236
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1237
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1238
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1239

    
1240
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1241
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1242
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1243
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1244
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1245

    
1246
		unset($wancfg['adv_dhcp6_config_advanced']);
1247
		unset($wancfg['adv_dhcp6_config_file_override']);
1248
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1249

    
1250
		unset($wancfg['pppoe_password']);
1251
		unset($wancfg['pptp_username']);
1252
		unset($wancfg['pptp_password']);
1253
		unset($wancfg['l2tp_secret']);
1254
		unset($wancfg['provider']);
1255
		unset($wancfg['hostuniq']);
1256
		unset($wancfg['ondemand']);
1257
		unset($wancfg['timeout']);
1258
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1259
			unset($wancfg['pppoe']['pppoe-reset-type']);
1260
		}
1261
		unset($wancfg['local']);
1262

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

    
1285
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1286
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1287

    
1288
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1289
		switch ($_POST['type']) {
1290
			case "staticv4":
1291
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1292
				$wancfg['subnet'] = $_POST['subnet'];
1293
				if ($_POST['gateway'] != "none") {
1294
					$wancfg['gateway'] = $_POST['gateway'];
1295
				}
1296
				break;
1297
			case "dhcp":
1298
				$wancfg['ipaddr'] = "dhcp";
1299
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1300
				$wancfg['alias-address'] = $_POST['alias-address'];
1301
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1302
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1303

    
1304
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1305
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1306
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1307
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1308
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1309
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1310

    
1311
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1312

    
1313
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1314
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1315
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1316
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1317

    
1318
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1319
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1320
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1321

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

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

    
1380
				if (!empty($_POST['pppoe-reset-type'])) {
1381
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1382
				} else {
1383
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1384
				}
1385
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1386
				$wancfg['ipaddr'] = $_POST['type'];
1387
				if ($gateway_item) {
1388
					$a_gateways[] = $gateway_item;
1389
				}
1390

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

    
1467
				if ($_POST['dhcp6withoutra'] == "yes") {
1468
					$wancfg['dhcp6withoutra'] = true;
1469
				}
1470
				if ($_POST['dhcp6norelease'] == "yes") {
1471
					$wancfg['dhcp6norelease'] = true;
1472
				}
1473
				if ($_POST['dhcp6vlanenable'] == "yes") {
1474
					$wancfg['dhcp6vlanenable'] = true;
1475
				}
1476
				if (!empty($_POST['dhcp6cvpt'])) {
1477
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1478
				} else {
1479
					unset($wancfg['dhcp6cvpt']);
1480
				}
1481

    
1482
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1483
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1484
				}
1485
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1486
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1487
				}
1488
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1489
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1490
				}
1491
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1492
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1493
				}
1494

    
1495
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1496
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1497
				}
1498
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1499
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1500
				}
1501
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1502
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1503
				}
1504
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1505
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1506
				}
1507
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1508
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1509
				}
1510

    
1511
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1512
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1513
				}
1514
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1515
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1516
				}
1517
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1518
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1519
				}
1520
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1521
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1522
				}
1523
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1524
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1525
				}
1526

    
1527
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1528
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1529
				}
1530
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1531
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1532
				}
1533
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1534
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1535
				}
1536
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1537
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1538
				}
1539
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1540
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1541
				}
1542
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1543
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1544
				}
1545
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1546
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1547
				}
1548

    
1549
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1550
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1551
				}
1552
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1553
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1554
				}
1555
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1556
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1557
				}
1558
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1559
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1560
				}
1561
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1562
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1563
				}
1564

    
1565
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1566
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1567
				}
1568
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1569
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1570
				}
1571
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1572
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1573
				}
1574

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

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

    
1646
		write_config("Interfaces settings changed");
1647

    
1648
		if ($_POST['gatewayip4']) {
1649
			save_gateway($gateway_settings4);
1650
		}
1651

    
1652
		if ($_POST['gatewayip6']) {
1653
			save_gateway($gateway_settings6);
1654
		}
1655

    
1656
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1657
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1658
		} else {
1659
			$toapplylist = array();
1660
		}
1661
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1662
		$toapplylist[$if]['ppps'] = $old_ppps;
1663
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1664

    
1665
		mark_subsystem_dirty('interfaces');
1666

    
1667
		/* regenerate cron settings/crontab file */
1668
		configure_cron();
1669

    
1670
		header("Location: interfaces.php?if={$if}");
1671
		exit;
1672
	}
1673

    
1674
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1675
	if (!empty($_POST['ppp_port'])) {
1676
		$pconfig['port'] = $_POST['ppp_port'];
1677
	}
1678

    
1679
} // end if ($_POST['save'])
1680

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

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

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

    
1837
	interface_sync_wireless_clones($wancfg, true);
1838
}
1839

    
1840
function check_wireless_mode() {
1841
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1842

    
1843
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1844
		return;
1845
	}
1846

    
1847
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1848
		$clone_count = 1;
1849
	} else {
1850
		$clone_count = 0;
1851
	}
1852

    
1853
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1854
		foreach ($config['wireless']['clone'] as $clone) {
1855
			if ($clone['if'] == $wlanbaseif) {
1856
				$clone_count++;
1857
			}
1858
		}
1859
	}
1860

    
1861
	if ($clone_count > 1) {
1862
		$old_wireless_mode = $wancfg['wireless']['mode'];
1863
		$wancfg['wireless']['mode'] = $_POST['mode'];
1864
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1865
			$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']]);
1866
		} else {
1867
			pfSense_interface_destroy("{$wlanif}_");
1868
		}
1869
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1870
	}
1871
}
1872

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

    
1888
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1889
$shortcut_section = "interfaces";
1890

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

    
1893
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1894
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1895
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1896
}
1897

    
1898
$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"));
1899

    
1900
// Get the MAC address
1901
$defgatewayname4 = $wancfg['descr'] . "GW";
1902
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1903

    
1904
function build_mediaopts_list() {
1905
	global $mediaopts_list;
1906

    
1907
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1908
			 " " =>	 gettext("------- Media Supported by this interface -------")
1909
			];
1910

    
1911
	foreach ($mediaopts_list as $mediaopt) {
1912
		$list[$mediaopt] = $mediaopt;
1913
	}
1914

    
1915
	return($list);
1916
}
1917

    
1918
function build_gateway_list() {
1919
	global $a_gateways, $if;
1920

    
1921
	$list = array("none" => gettext("None"));
1922
	foreach ($a_gateways as $gateway) {
1923
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1924
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1925
		}
1926
	}
1927

    
1928
	return($list);
1929
}
1930

    
1931
function build_gatewayv6_list() {
1932
	global $a_gateways, $if;
1933

    
1934
	$list = array("none" => gettext("None"));
1935
	foreach ($a_gateways as $gateway) {
1936
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1937
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1938
		}
1939
	}
1940

    
1941
	return($list);
1942
}
1943

    
1944
include("head.inc");
1945

    
1946
if ($input_errors) {
1947
	print_input_errors($input_errors);
1948
}
1949

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

    
1956
if ($changes_applied) {
1957
	print_apply_result_box($retval);
1958
}
1959

    
1960
$form = new Form();
1961

    
1962
$section = new Form_Section('General Configuration');
1963

    
1964
$section->addInput(new Form_Checkbox(
1965
	'enable',
1966
	'Enable',
1967
	'Enable interface',
1968
	$pconfig['enable'],
1969
	'yes'
1970
));
1971

    
1972
$section->addInput(new Form_Input(
1973
	'descr',
1974
	'*Description',
1975
	'text',
1976
	$pconfig['descr']
1977
))->setHelp('Enter a description (name) for the interface here.');
1978

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

    
2011
if (!is_pseudo_interface($intrealname, true)) {
2012
	$macaddress = new Form_Input(
2013
		'spoofmac',
2014
		'MAC Address',
2015
		'text',
2016
		$pconfig['spoofmac'],
2017
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
2018
	);
2019

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

    
2030
	$section->addInput($macaddress);
2031
}
2032

    
2033
$section->addInput(new Form_Input(
2034
	'mtu',
2035
	'MTU',
2036
	'number',
2037
	$pconfig['mtu']
2038
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2039
			'This is typically 1500 bytes but can vary in some circumstances.');
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['interfaces'][$if]['media'] . ' ' . $config['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
	'dhcp6debug',
2460
	'Debug',
2461
	'Start DHCP6 client in debug mode',
2462
	$pconfig['dhcp6debug']
2463
));
2464
$section->addInput(new Form_Checkbox(
2465
	'dhcp6withoutra',
2466
	'Do not wait for a RA',
2467
	'Required by some ISPs, especially those not using PPPoE',
2468
	$pconfig['dhcp6withoutra']
2469
));
2470
$section->addInput(new Form_Checkbox(
2471
	'dhcp6norelease',
2472
	'Do not allow PD/Address release',
2473
	'dhcp6c will send a release to the ISP on exit, some ISPs then release the allocated address or prefix. This option prevents that signal ever being sent',
2474
	$pconfig['dhcp6norelease']
2475
));
2476

    
2477
if (interface_is_vlan($wancfg['if']) != NULL) {
2478
	$group = new Form_Group('DHCP6 VLAN Priority');
2479

    
2480
	$group->add(new Form_Checkbox(
2481
		'dhcp6vlanenable',
2482
		null,
2483
		'Enable dhcp6c VLAN Priority tagging',
2484
		$pconfig['dhcp6vlanenable']
2485
	))->setHelp('Normally off unless specifically required by the ISP.');
2486

    
2487
	$group->add(new Form_Select(
2488
		'dhcp6cvpt',
2489
		'VLAN Prio',
2490
		$pconfig['dhcp6cvpt'],
2491
		$vlanprio
2492
	))->setHelp('Choose 802.1p priority to set.');
2493

    
2494
	$section->add($group);
2495
}
2496

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

    
2507
$form->add($section);
2508

    
2509
// DHCP6 client config - Advanced
2510

    
2511
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2512
$section->addClass('dhcp6advanced');
2513

    
2514
$section->addInput(new Form_Checkbox(
2515
	'adv_dhcp6_interface_statement_information_only_enable',
2516
	'Information only',
2517
	'Exchange Information Only',
2518
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2519
	'Selected'
2520
))->setHelp('Only exchange informational configuration parameters with servers.');
2521

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

    
2532
$section->addInput(new Form_Input(
2533
	'adv_dhcp6_interface_statement_request_options',
2534
	'Request Options',
2535
	'text',
2536
	$pconfig['adv_dhcp6_interface_statement_request_options']
2537
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2538
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2539

    
2540
$section->addInput(new Form_Input(
2541
	'adv_dhcp6_interface_statement_script',
2542
	'Scripts',
2543
	'text',
2544
	$pconfig['adv_dhcp6_interface_statement_script']
2545
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2546
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2547

    
2548
$group = new Form_Group('Identity Association Statement');
2549

    
2550
$group->add(new Form_Checkbox(
2551
	'adv_dhcp6_id_assoc_statement_address_enable',
2552
	null,
2553
	'Non-Temporary Address Allocation',
2554
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2555
	'Selected'
2556
));
2557

    
2558
$group->add(new Form_Input(
2559
	'adv_dhcp6_id_assoc_statement_address_id',
2560
	null,
2561
	'text',
2562
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2563
))->sethelp('id-assoc na ID');
2564

    
2565
$group->add(new Form_IpAddress(
2566
	'adv_dhcp6_id_assoc_statement_address',
2567
	null,
2568
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2569
	'V6'
2570
))->sethelp('IPv6 address');
2571

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

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

    
2586
$section->add($group);
2587

    
2588
// Prefix delegation
2589
$group = new Form_Group('');
2590

    
2591
$group->add(new Form_Checkbox(
2592
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2593
	null,
2594
	'Prefix Delegation ',
2595
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2596
	'Selected'
2597
));
2598

    
2599
$group->add(new Form_Input(
2600
	'adv_dhcp6_id_assoc_statement_prefix_id',
2601
	null,
2602
	'text',
2603
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2604
))->sethelp('id-assoc pd ID');
2605

    
2606
$group->add(new Form_IpAddress(
2607
	'adv_dhcp6_id_assoc_statement_prefix',
2608
	null,
2609
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2610
	'V6'
2611
))->sethelp('IPv6 prefix');
2612

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

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

    
2627
$section->add($group);
2628

    
2629
$group = new Form_Group('Prefix interface statement');
2630

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

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

    
2645
$section->add($group);
2646

    
2647
$group = new Form_Group('Select prefix interface');
2648
$section->addInput(new Form_Select(
2649
	'adv_dhcp6_prefix_selected_interface',
2650
	'Prefix Interface',
2651
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2652
	$interfaces
2653
))->setHelp('Select the interface on which to apply the prefix delegation.');
2654

    
2655
$group = new Form_Group('Authentication statement');
2656

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

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

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

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

    
2685
$section->add($group);
2686

    
2687
$group = new Form_Group('Keyinfo statement');
2688

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

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

    
2703
$section->add($group);
2704

    
2705
$group = new Form_Group('');
2706

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

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

    
2721
$group->add(new Form_Input(
2722
	'adv_dhcp6_key_info_statement_expire',
2723
	null,
2724
	'text',
2725
	$pconfig['adv_dhcp6_key_info_statement_expire']
2726
))->sethelp('Expire');
2727

    
2728
$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>');
2729

    
2730
$section->add($group);
2731

    
2732
$form->add($section);
2733

    
2734
$section = new Form_Section('6RD Configuration');
2735
$section->addClass('_6rd');
2736

    
2737
$section->addInput(new Form_Input(
2738
	'prefix-6rd',
2739
	'6RD Prefix',
2740
	'text',
2741
	$pconfig['prefix-6rd']
2742
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2743

    
2744
$section->addInput(new Form_Input(
2745
	'gateway-6rd',
2746
	'*6RD Border relay',
2747
	'text',
2748
	$pconfig['gateway-6rd']
2749
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2750

    
2751
$section->addInput(new Form_Select(
2752
	'prefix-6rd-v4plen',
2753
	'6RD IPv4 Prefix length',
2754
	$pconfig['prefix-6rd-v4plen'],
2755
	array_combine(range(0, 32), range(0, 32))
2756
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2757

    
2758
$form->add($section);
2759

    
2760
// Track IPv6 ointerface section
2761
$section = new Form_Section('Track IPv6 Interface');
2762
$section->addClass('track6');
2763

    
2764
function build_ipv6interface_list() {
2765
	global $config, $form;
2766

    
2767
	$list = array('' => '');
2768

    
2769
	$interfaces = get_configured_interface_with_descr(true);
2770
	$dynv6ifs = array();
2771

    
2772
	foreach ($interfaces as $iface => $ifacename) {
2773
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2774
			case "6to4":
2775
			case "6rd":
2776
			case "dhcp6":
2777
				$dynv6ifs[$iface] = array(
2778
					'name' => $ifacename,
2779
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2780
				);
2781
				break;
2782
			default:
2783
				continue 2;
2784
		}
2785
	}
2786

    
2787
	foreach ($dynv6ifs as $iface => $ifacedata) {
2788
		$list[$iface] = $ifacedata['name'];
2789

    
2790
		$form->addGlobal(new Form_Input(
2791
			'ipv6-num-prefix-ids-' . $iface,
2792
			null,
2793
			'hidden',
2794
			$ifacedata['ipv6_num_prefix_ids']
2795
		));
2796
	}
2797

    
2798
	return($list);
2799
}
2800

    
2801
$section->addInput(new Form_Select(
2802
	'track6-interface',
2803
	'*IPv6 Interface',
2804
	$pconfig['track6-interface'],
2805
	build_ipv6interface_list()
2806
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2807

    
2808
if ($pconfig['track6-prefix-id'] == "") {
2809
	$pconfig['track6-prefix-id'] = 0;
2810
}
2811

    
2812
$section->addInput(new Form_Input(
2813
	'track6-prefix-id--hex',
2814
	'IPv6 Prefix ID',
2815
	'text',
2816
	sprintf("%x", $pconfig['track6-prefix-id'])
2817
))->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>');
2818

    
2819
$form->addGlobal(new Form_Input(
2820
	'track6-prefix-id-max',
2821
	null,
2822
	'hidden',
2823
	0
2824
));
2825

    
2826
$form->add($section);
2827

    
2828
/// PPP section
2829

    
2830
$section = new Form_Section('PPP Configuration');
2831
$section->addClass('ppp');
2832

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

    
2840
$section->addInput(new Form_Select(
2841
	'provider_list',
2842
	'Provider',
2843
	$pconfig['provider_list'],
2844
	[]
2845
));
2846

    
2847
$section->addInput(new Form_Select(
2848
	'providerplan',
2849
	'Plan',
2850
	$pconfig['providerplan'],
2851
	[]
2852
))->setHelp('Select to fill in service provider data.');
2853

    
2854
$section->addInput(new Form_Input(
2855
	'ppp_username',
2856
	'Username',
2857
	'text',
2858
	$pconfig['ppp_username'],
2859
	['autocomplete' => 'new-password']
2860
));
2861

    
2862
$section->addPassword(new Form_Input(
2863
	'ppp_password',
2864
	'Password',
2865
	'password',
2866
	$pconfig['ppp_password']
2867
));
2868

    
2869
$section->addInput(new Form_Input(
2870
	'phone',
2871
	'*Phone number',
2872
	'text',
2873
	$pconfig['phone']
2874
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2875

    
2876
$section->addInput(new Form_Input(
2877
	'apn',
2878
	'Access Point Name',
2879
	'text',
2880
	$pconfig['apn']
2881
));
2882

    
2883

    
2884
function build_port_list() {
2885
	$list = array("" => "None");
2886

    
2887
	$portlist = glob("/dev/cua*");
2888
	$modems	  = glob("/dev/modem*");
2889
	$portlist = array_merge($portlist, $modems);
2890

    
2891
	foreach ($portlist as $port) {
2892
		if (preg_match("/\.(lock|init)$/", $port)) {
2893
			continue;
2894
		}
2895

    
2896
	$list[trim($port)] = $port;
2897
	}
2898

    
2899
	return($list);
2900
}
2901

    
2902
$section->addInput(new Form_Select(
2903
	'port',
2904
	"*Modem port",
2905
	$pconfig['port'],
2906
	build_port_list()
2907
));
2908

    
2909
$section->addInput(new Form_Button(
2910
	'btnadvppp',
2911
	'Advanced PPP',
2912
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2913
	'fa-cog'
2914
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2915

    
2916
$form->add($section);
2917

    
2918
// PPPoE configuration
2919
$section = new Form_Section('PPPoE Configuration');
2920
$section->addClass('pppoe');
2921

    
2922
$section->addInput(new Form_Input(
2923
	'pppoe_username',
2924
	'*Username',
2925
	'text',
2926
	$pconfig['pppoe_username'],
2927
	['autocomplete' => 'new-password']
2928
));
2929

    
2930
$section->addPassword(new Form_Input(
2931
	'pppoe_password',
2932
	'*Password',
2933
	'password',
2934
	$pconfig['pppoe_password']
2935
));
2936

    
2937
$section->addInput(new Form_Input(
2938
	'provider',
2939
	'Service name',
2940
	'text',
2941
	$pconfig['provider']
2942
))->setHelp('This field can usually be left empty.');
2943

    
2944
$section->addInput(new Form_Input(
2945
	'hostuniq',
2946
	'Host-Uniq',
2947
	'text',
2948
	$pconfig['hostuniq']
2949
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2950

    
2951
$section->addInput(new Form_Checkbox(
2952
	'pppoe_dialondemand',
2953
	'Dial on demand',
2954
	'Enable Dial-On-Demand mode ',
2955
	$pconfig['pppoe_dialondemand'],
2956
	'enable'
2957
));
2958

    
2959
$section->addInput(new Form_Input(
2960
	'pppoe_idletimeout',
2961
	'Idle timeout',
2962
	'number',
2963
	$pconfig['pppoe_idletimeout'],
2964
	['min' => 0]
2965
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2966
			'An idle timeout of zero disables this feature.');
2967

    
2968
$section->addInput(new Form_Select(
2969
	'pppoe-reset-type',
2970
	'Periodic reset',
2971
	$pconfig['pppoe-reset-type'],
2972
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2973
))->setHelp('Select a reset timing type.');
2974

    
2975
$group = new Form_Group('Custom reset');
2976
$group->addClass('pppoecustom');
2977

    
2978
$group->add(new Form_Input(
2979
	'pppoe_resethour',
2980
	null,
2981
	'number',
2982
	$pconfig['pppoe_resethour'],
2983
	['min' => 0, 'max' => 23]
2984
))->setHelp('Hour (0-23)');
2985

    
2986
$group->add(new Form_Input(
2987
	'pppoe_resetminute',
2988
	null,
2989
	'number',
2990
	$pconfig['pppoe_resetminute'],
2991
	['min' => 0, 'max' => 59]
2992
))->setHelp('Minutes (0-59)');
2993

    
2994
$group->add(new Form_Input(
2995
	'pppoe_resetdate',
2996
	null,
2997
	'text',
2998
	$pconfig['pppoe_resetdate']
2999
))->setHelp('Specific date (mm/dd/yyyy)');
3000

    
3001
$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');
3002

    
3003
$section->add($group);
3004

    
3005
$group = new Form_MultiCheckboxGroup('cron based reset');
3006
$group->addClass('pppoepreset');
3007

    
3008
$group->add(new Form_MultiCheckbox(
3009
	'pppoe_pr_preset_val',
3010
	null,
3011
	'Reset at each month ("0 0 1 * *")',
3012
	$pconfig['pppoe_monthly'],
3013
	'monthly'
3014
))->displayAsRadio();
3015

    
3016
$group->add(new Form_MultiCheckbox(
3017
	'pppoe_pr_preset_val',
3018
	null,
3019
	'Reset at each week ("0 0 * * 0")',
3020
	$pconfig['pppoe_weekly'],
3021
	'weekly'
3022
))->displayAsRadio();
3023

    
3024
$group->add(new Form_MultiCheckbox(
3025
	'pppoe_pr_preset_val',
3026
	null,
3027
	'Reset at each day ("0 0 * * *")',
3028
	$pconfig['pppoe_daily'],
3029
	'daily'
3030
))->displayAsRadio();
3031

    
3032
$group->add(new Form_MultiCheckbox(
3033
	'pppoe_pr_preset_val',
3034
	null,
3035
	'Reset at each hour ("0 * * * *")',
3036
	$pconfig['pppoe_hourly'],
3037
	'hourly'
3038
))->displayAsRadio();
3039

    
3040
$section->add($group);
3041

    
3042
$section->addInput(new Form_Button(
3043
	'btnadvppp',
3044
	'Advanced and MLPPP',
3045
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3046
	'fa-cog'
3047
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3048

    
3049
$form->add($section);
3050

    
3051
// PPTP & L2TP Configuration section
3052
$section = new Form_Section('PPTP/L2TP Configuration');
3053
$section->addClass('pptp');
3054

    
3055
$section->addInput(new Form_Input(
3056
	'pptp_username',
3057
	'*Username',
3058
	'text',
3059
	$pconfig['pptp_username'],
3060
	['autocomplete' => 'new-password']
3061
));
3062

    
3063
$section->addPassword(new Form_Input(
3064
	'pptp_password',
3065
	'*Password',
3066
	'password',
3067
	$pconfig['pptp_password']
3068
));
3069

    
3070
$group = new Form_Group('Shared Secret');
3071

    
3072
$group->add(new Form_Input(
3073
	'l2tp_secret',
3074
	'*Secret',
3075
	'password',
3076
	$pconfig['l2tp_secret']
3077
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3078
	    'important control packet contents. (Optional)');
3079

    
3080
$group->addClass('l2tp_secret');
3081
$section->add($group);
3082

    
3083
$section->addInput(new Form_IpAddress(
3084
	'pptp_local0',
3085
	'*Local IP address',
3086
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3087
	'V4'
3088
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3089

    
3090
$section->addInput(new Form_IpAddress(
3091
	'pptp_remote0',
3092
	'*Remote IP address',
3093
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3094
	'HOSTV4'
3095
));
3096

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

    
3106
$section->addInput(new Form_Input(
3107
	'pptp_idletimeout',
3108
	'Idle timeout (seconds)',
3109
	'number',
3110
	$pconfig['pptp_idletimeout'],
3111
	['min' => 0]
3112
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3113
			'An idle timeout of zero disables this feature.');
3114

    
3115
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3116
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3117
} else {
3118
	$mlppp_text = "";
3119
}
3120

    
3121
$section->addInput(new Form_Button(
3122
	'btnadvppp',
3123
	'Advanced and MLPPP',
3124
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3125
	'fa-cog'
3126
))->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);
3127

    
3128
$form->add($section);
3129

    
3130
// Wireless interface
3131
if (isset($wancfg['wireless'])) {
3132

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

    
3135
	$section->addInput(new Form_Checkbox(
3136
		'persistcommonwireless',
3137
		'Persist common settings',
3138
		'Preserve common wireless configuration through interface deletions and reassignments.',
3139
		$pconfig['persistcommonwireless'],
3140
		'yes'
3141
	));
3142

    
3143
	$mode_list = ['auto' => 'Auto'];
3144

    
3145
	if (is_array($wl_modes)) {
3146
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3147
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3148
		}
3149
	}
3150

    
3151
	if (count($mode_list) == 1) {
3152
		$mode_list[''] = '';
3153
	}
3154

    
3155
	$section->addInput(new Form_Select(
3156
		'standard',
3157
		'Standard',
3158
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3159
		$mode_list
3160
	));
3161

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

    
3178
	$mode_list = ['0' => gettext('Auto')];
3179

    
3180
	if (is_array($wl_modes)) {
3181
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3182
			if ($wl_standard == "11g") {
3183
				$wl_standard = "11b/g";
3184
			} else if ($wl_standard == "11ng") {
3185
				$wl_standard = "11b/g/n";
3186
			} else if ($wl_standard == "11na") {
3187
				$wl_standard = "11a/n";
3188
			}
3189

    
3190
			foreach ($wl_channels as $wl_channel) {
3191
				if (isset($wl_chaninfo[$wl_channel])) {
3192
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3193
				} else {
3194
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3195
				}
3196
			}
3197
		}
3198
	}
3199

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

    
3208
	$section->addInput(new Form_Select(
3209
		'channel_width',
3210
		'Channel width',
3211
		$pconfig['channel_width'],
3212
		$wl_ht_modes
3213
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3214

    
3215
	if (ANTENNAS) {
3216
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3217
			$group = new Form_Group('Antenna Settings');
3218

    
3219
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3220
				$group->add(new Form_Select(
3221
					'diversity',
3222
					null,
3223
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3224
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3225
				))->setHelp('Diversity');
3226
			}
3227

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

    
3237
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3238
				$group->add(new Form_Select(
3239
					'rxantenna',
3240
					null,
3241
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3242
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3243
				))->setHelp('Receive antenna');
3244
			}
3245

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

    
3248
			$section->add($group);
3249
		}
3250
	}
3251

    
3252
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3253
			$section->addInput(new Form_Input(
3254
				'distance',
3255
				'Distance setting (meters)',
3256
				'test',
3257
				$pconfig['distance']
3258
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3259
	}
3260

    
3261
	$form->add($section);
3262

    
3263
	// Regulatory settings
3264
	$section = new Form_Section('Regulatory Settings');
3265

    
3266
	$domain_list = array("" => 'Default');
3267

    
3268
	if (is_array($wl_regdomains)) {
3269
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3270
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3271
		}
3272
	}
3273

    
3274
	$section->addInput(new Form_Select(
3275
		'regdomain',
3276
		'Regulatory domain',
3277
		$pconfig['regdomain'],
3278
		$domain_list
3279
	))->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');
3280

    
3281
	$country_list = array('' => 'Default');
3282

    
3283
	if (is_array($wl_countries)) {
3284
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3285
			$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']);
3286
		}
3287
	}
3288

    
3289
	$section->addInput(new Form_Select(
3290
		'regcountry',
3291
		'Country',
3292
		$pconfig['regcountry'],
3293
		$country_list
3294
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3295

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

    
3307
	$form->add($section);
3308

    
3309
	$section = new Form_Section('Network-Specific Wireless Configuration');
3310

    
3311
	$section->addInput(new Form_Select(
3312
		'mode',
3313
		'Mode',
3314
		$pconfig['mode'],
3315
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3316
	));
3317

    
3318
	$section->addInput(new Form_Input(
3319
		'ssid',
3320
		'SSID',
3321
		'text',
3322
		$pconfig['ssid']
3323
	));
3324

    
3325
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3326
		$section->addInput(new Form_Select(
3327
			'puremode',
3328
			'Minimum wireless standard',
3329
			$pconfig['puremode'],
3330
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3331
		))->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)');
3332
	} elseif (isset($wl_modes['11g'])) {
3333
		$section->addInput(new Form_Checkbox(
3334
			'puremode',
3335
			'802.11g only',
3336
			null,
3337
			$pconfig['puremode'],
3338
			'11g'
3339
		))->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)');
3340
	}
3341

    
3342
	$section->addInput(new Form_Checkbox(
3343
		'apbridge_enable',
3344
		'Allow intra-BSS communication',
3345
		'Allow packets to pass between wireless clients directly when operating as an access point',
3346
		$pconfig['apbridge_enable'],
3347
		'yes'
3348
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3349

    
3350
	$section->addInput(new Form_Checkbox(
3351
		'wme_enable',
3352
		'Enable WME',
3353
		'Force the card to use WME (wireless QoS)',
3354
		$pconfig['wme_enable'],
3355
		'yes'
3356
	));
3357

    
3358
	$section->addInput(new Form_Checkbox(
3359
		'hidessid_enable',
3360
		'Hide SSID',
3361
		'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.)',
3362
		$pconfig['hidessid_enable'],
3363
		'yes'
3364
	));
3365

    
3366
	$form->add($section);
3367

    
3368
	// WPA Section
3369
	$section = new Form_Section('WPA');
3370

    
3371
	$section->addInput(new Form_Checkbox(
3372
		'wpa_enable',
3373
		'Enable',
3374
		'Enable WPA',
3375
		$pconfig['wpa_enable'],
3376
		'yes'
3377
	));
3378

    
3379
	$section->addInput(new Form_Select(
3380
		'wpa_mode',
3381
		'WPA mode',
3382
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3383
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3384
	));
3385

    
3386
	$section->addInput(new Form_Select(
3387
		'wpa_pairwise',
3388
		'WPA Pairwise',
3389
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3390
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3391
	));
3392

    
3393
	$section->addInput(new Form_Select(
3394
		'wpa_key_mgmt',
3395
		'WPA Key Management Mode',
3396
		$pconfig['wpa_key_mgmt'],
3397
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3398
	));
3399

    
3400
	$section->addInput(new Form_Input(
3401
		'passphrase',
3402
		'WPA Pre-Shared Key',
3403
		'text',
3404
		$pconfig['passphrase']
3405
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3406

    
3407
	$section->addInput(new Form_Select(
3408
		'wpa_eap_client_mode',
3409
		'EAP Client Mode',
3410
		$pconfig['wpa_eap_client_mode'],
3411
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3412
	));
3413

    
3414
	$section->addInput(new Form_Select(
3415
		'wpa_eap_ca',
3416
		'Certificate Authority',
3417
		$pconfig['wpa_eap_ca'],
3418
		cert_build_list('ca', 'HTTPS')
3419
	));
3420

    
3421
	$section->addInput(new Form_Select(
3422
		'wpa_eap_inner_auth',
3423
		'Inner Authentication Method',
3424
		$pconfig['wpa_eap_inner_auth'],
3425
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3426
	));
3427

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

    
3435
	$section->addInput(new Form_Input(
3436
		'wpa_eap_inner_password',
3437
		'*Inner Authentication Passphrase',
3438
		'text',
3439
		$pconfig['wpa_eap_inner_password']
3440
	));
3441

    
3442
	$section->addInput(new Form_Select(
3443
		'wpa_eap_cert',
3444
		'TLS/TTLS Client Certificate',
3445
		$pconfig['wpa_eap_cert'],
3446
		cert_build_list('cert', 'HTTPS')
3447
	));
3448

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

    
3457
	$section->addInput(new Form_Input(
3458
		'wpa_gmk_rekey',
3459
		'Group Master Key Regeneration',
3460
		'number',
3461
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3462
		['min' => '1', 'max' => 9999]
3463
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3464

    
3465
	$section->addInput(new Form_Checkbox(
3466
		'wpa_strict_rekey',
3467
		'Strict Key Regeneration',
3468
		'Force the AP to rekey whenever a client disassociates',
3469
		$pconfig['wpa_strict_rekey'],
3470
		'yes'
3471
	));
3472

    
3473
	$form->add($section);
3474

    
3475
	$section = new Form_Section('802.1x RADIUS Options');
3476
	$section->addClass('ieee8021x_group');
3477

    
3478
	$section->addInput(new Form_Checkbox(
3479
		'ieee8021x',
3480
		'IEEE802.1X',
3481
		'Enable 802.1X authentication',
3482
		$pconfig['ieee8021x'],
3483
		'yes'
3484
	));
3485

    
3486
	$group = new Form_Group('Primary 802.1X server');
3487

    
3488
	$group->add(new Form_IpAddress(
3489
		'auth_server_addr',
3490
		'IP Address',
3491
		$pconfig['auth_server_addr']
3492
	))->setHelp('IP address of the RADIUS server');
3493

    
3494
	$group->add(new Form_Input(
3495
		'auth_server_port',
3496
		'Port',
3497
		'number',
3498
		$pconfig['auth_server_port']
3499
	))->setHelp('Server auth port. Default is 1812');
3500

    
3501
	$group->add(new Form_Input(
3502
		'auth_server_shared_secret',
3503
		'Shared Secret',
3504
		'text',
3505
		$pconfig['auth_server_shared_secret']
3506
	))->setHelp('RADIUS Shared secret for this firewall');
3507

    
3508
	$section->add($group);
3509

    
3510
	$group = new Form_Group('Secondary 802.1X server');
3511

    
3512
	$group->add(new Form_IpAddress(
3513
		'auth_server_addr2',
3514
		'IP Address',
3515
		$pconfig['auth_server_addr2']
3516
	))->setHelp('IP address of the RADIUS server');
3517

    
3518
	$group->add(new Form_Input(
3519
		'auth_server_port2',
3520
		'Port',
3521
		'number',
3522
		$pconfig['auth_server_port2']
3523
	))->setHelp('Server auth port. Default is 1812');
3524

    
3525
	$group->add(new Form_Input(
3526
		'auth_server_shared_secret2',
3527
		'Shared Secret',
3528
		'text',
3529
		$pconfig['auth_server_shared_secret2']
3530
	))->setHelp('RADIUS Shared secret for this firewall');
3531

    
3532
	$section->add($group);
3533

    
3534
	$section->addInput(new Form_Checkbox(
3535
		'rsn_preauth',
3536
		'Authentication Roaming Preauth',
3537
		null,
3538
		$pconfig['rsn_preauth'],
3539
		'yes'
3540
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3541

    
3542
	$form->add($section);
3543
}
3544

    
3545
$section = new Form_Section('Reserved Networks');
3546

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

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

    
3568
$form->add($section);
3569

    
3570
$form->addGlobal(new Form_Input(
3571
	'if',
3572
	null,
3573
	'hidden',
3574
	$if
3575
));
3576

    
3577
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3578
	$form->addGlobal(new Form_Input(
3579
		'ppp_port',
3580
		null,
3581
		'hidden',
3582
		$pconfig['port']
3583
	));
3584
}
3585

    
3586
$form->addGlobal(new Form_Input(
3587
	'ptpid',
3588
	null,
3589
	'hidden',
3590
	$pconfig['ptpid']
3591
));
3592

    
3593

    
3594
// Add new gateway modal pop-up
3595
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3596

    
3597
$modal->addInput(new Form_Checkbox(
3598
	'defaultgw4',
3599
	'Default',
3600
	'Default gateway',
3601
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3602
));
3603

    
3604
$modal->addInput(new Form_Input(
3605
	'gatewayname4',
3606
	'Gateway name',
3607
	'text',
3608
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3609
));
3610

    
3611
$modal->addInput(new Form_IpAddress(
3612
	'gatewayip4',
3613
	'Gateway IPv4',
3614
	$gateway_settings4['gateway'],
3615
	'V4'
3616
));
3617

    
3618
$modal->addInput(new Form_Input(
3619
	'gatewaydescr4',
3620
	'Description',
3621
	'text',
3622
	$gateway_settings4['descr']
3623
));
3624

    
3625
$btnaddgw4 = new Form_Button(
3626
	'add4',
3627
	'Add',
3628
	null,
3629
	'fa-plus'
3630
);
3631

    
3632
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3633

    
3634
$btncnxgw4 = new Form_Button(
3635
	'cnx4',
3636
	'Cancel',
3637
	null,
3638
	'fa-undo'
3639
);
3640

    
3641
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3642

    
3643
$modal->addInput(new Form_StaticText(
3644
	null,
3645
	$btnaddgw4 . $btncnxgw4
3646
));
3647

    
3648
$form->add($modal);
3649

    
3650
print($form);
3651
?>
3652

    
3653
<script type="text/javascript">
3654
//<![CDATA[
3655
events.push(function() {
3656
	function updateType(t) {
3657

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

    
3696
		if (t != "l2tp" && t != "pptp") {
3697
			$('.'+t).show();
3698
		}
3699
	}
3700

    
3701
	function updateTypeSix(t) {
3702
		if (!isNaN(t[0])) {
3703
			t = '_' + t;
3704
		}
3705

    
3706
		switch (t) {
3707
			case "none": {
3708
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3709
				break;
3710
			}
3711
			case "staticv6": {
3712
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3713
				break;
3714
			}
3715
			case "slaac": {
3716
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3717
				break;
3718
			}
3719
			case "dhcp6": {
3720
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3721
				break;
3722
			}
3723
			case "_6rd": {
3724
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3725
				break;
3726
			}
3727
			case "_6to4": {
3728
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3729
				break;
3730
			}
3731
			case "track6": {
3732
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3733
				update_track6_prefix();
3734
				break;
3735
			}
3736
		}
3737

    
3738
		if (t != "l2tp" && t != "pptp") {
3739
			$('.'+t).show();
3740
		}
3741
	}
3742

    
3743
	function show_reset_settings(reset_type) {
3744
		if (reset_type == 'preset') {
3745
			$('.pppoepreset').show();
3746
			$('.pppoecustom').hide();
3747
		} else if (reset_type == 'custom') {
3748
			$('.pppoecustom').show();
3749
			$('.pppoepreset').hide();
3750
		} else {
3751
			$('.pppoecustom').hide();
3752
			$('.pppoepreset').hide();
3753
		}
3754
	}
3755

    
3756
	function update_track6_prefix() {
3757
		var iface = $("#track6-interface").val();
3758
		if (iface == null) {
3759
			return;
3760
		}
3761

    
3762
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3763
		if (track6_prefix_ids == null) {
3764
			return;
3765
		}
3766

    
3767
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3768
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3769
	}
3770

    
3771
	function addOption_v4() {
3772
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3773
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3774
	}
3775

    
3776
	function addOption_v6() {
3777
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3778
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3779
	}
3780

    
3781
	function addSelectboxOption(selectbox, text, value) {
3782
		var optn = document.createElement("OPTION");
3783
		optn.text = text;
3784
		optn.value = value;
3785
		selectbox.append(optn);
3786
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3787
	}
3788

    
3789
	function country_list() {
3790
		$('#country').children().remove();
3791
		$('#provider_list').children().remove();
3792
		$('#providerplan').children().remove();
3793
		$.ajax("getserviceproviders.php",{
3794
			success: function(response) {
3795

    
3796
				var responseTextArr = response.split("\n");
3797
				responseTextArr.sort();
3798

    
3799
				responseTextArr.forEach( function(value) {
3800
					country = value.split(":");
3801
					$('#country').append($('<option>', {
3802
						value: country[1],
3803
						text : country[0]
3804
					}));
3805
				});
3806
			}
3807
		});
3808
	}
3809

    
3810
	function providers_list() {
3811
		$('#provider_list').children().remove();
3812
		$('#providerplan').children().remove();
3813
		$.ajax("getserviceproviders.php",{
3814
			type: 'post',
3815
			data: {country : $('#country').val()},
3816
			success: function(response) {
3817
				var responseTextArr = response.split("\n");
3818
				responseTextArr.sort();
3819
				responseTextArr.forEach( function(value) {
3820
					$('#provider_list').append($('<option>', {
3821
							value: value,
3822
							text : value
3823
					}));
3824
				});
3825
			}
3826
		});
3827
	}
3828

    
3829
	function providerplan_list() {
3830
		$('#providerplan').children().remove();
3831
		$.ajax("getserviceproviders.php",{
3832
			type: 'post',
3833
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3834
			success: function(response) {
3835
				var responseTextArr = response.split("\n");
3836
				responseTextArr.sort();
3837

    
3838
				$('#providerplan').append($('<option>', {
3839
					value: '',
3840
					text : ''
3841
				}));
3842

    
3843
				responseTextArr.forEach( function(value) {
3844
					if (value != "") {
3845
						providerplan = value.split(":");
3846

    
3847
						$('#providerplan').append($('<option>', {
3848
							value: providerplan[1],
3849
							text : providerplan[0] + " - " + providerplan[1]
3850
						}));
3851
					}
3852
				});
3853
			}
3854
		});
3855
	}
3856

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

    
3881
	function show_dhcp6adv() {
3882
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3883
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3884

    
3885
		hideCheckbox('dhcp6usev4iface', ovr);
3886
		hideCheckbox('dhcp6prefixonly', ovr);
3887
		hideInput('dhcp6-ia-pd-len', ovr);
3888
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3889
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3890

    
3891
		hideClass('dhcp6advanced', !adv || ovr);
3892
	}
3893

    
3894
	function setDHCPoptions() {
3895
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3896
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3897

    
3898
		if (ovr) {
3899
			hideInput('dhcphostname', true);
3900
			hideIpAddress('alias-address', true);
3901
			hideInput('dhcprejectfrom', true);
3902
			hideInput('adv_dhcp_config_file_override_path', false);
3903
			hideClass('dhcpadvanced', true);
3904
		} else {
3905
			hideInput('dhcphostname', false);
3906
			hideIpAddress('alias-address', false);
3907
			hideInput('dhcprejectfrom', false);
3908
			hideInput('adv_dhcp_config_file_override_path', true);
3909
			hideClass('dhcpadvanced', !adv);
3910
		}
3911
	}
3912

    
3913
	// DHCP preset actions
3914
	// Set presets from value of radio buttons
3915
	function setPresets(val) {
3916
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3917
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3918
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3919
		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']);?>");
3920
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3921
	}
3922

    
3923
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3924
		$('#adv_dhcp_pt_timeout').val(timeout);
3925
		$('#adv_dhcp_pt_retry').val(retry);
3926
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3927
		$('#adv_dhcp_pt_reboot').val(reboot);
3928
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3929
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3930
	}
3931

    
3932
	function setPPPoEDialOnDemandItems() {
3933
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3934
	}
3935

    
3936
	function setPPTPDialOnDemandItems() {
3937
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3938
	}
3939

    
3940
	function show_wpaoptions() {
3941
		var wpa = !($('#wpa_enable').prop('checked'));
3942

    
3943
		hideInput('passphrase', wpa);
3944
		hideInput('wpa_mode', wpa);
3945
		hideInput('wpa_key_mgmt', wpa);
3946
		hideInput('wpa_pairwise', wpa);
3947
		hideCheckbox('wpa_strict_rekey', wpa);
3948
		hideClass('ieee8021x_group', true);
3949
		if ($('#mode').val() == 'hostap') {
3950
			hideInput('wpa_group_rekey', wpa);
3951
			hideInput('wpa_gmk_rekey', wpa);
3952
			hideCheckbox('wpa_strict_rekey', wpa);
3953
		} else {
3954
			hideInput('wpa_group_rekey', true);
3955
			hideInput('wpa_gmk_rekey', true);
3956
			hideCheckbox('wpa_strict_rekey', true);
3957
		}
3958
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3959
	}
3960

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

    
3999
	function updatewifimode(m) {
4000
		switch (m) {
4001
			case "adhoc": {
4002
				hideInput('puremode', true);
4003
				hideCheckbox('apbridge_enable', true);
4004
				hideCheckbox('hidessid_enable', false);
4005
				break;
4006
			}
4007
			case "hostap": {
4008
				hideInput('puremode', false);
4009
				hideCheckbox('apbridge_enable', false);
4010
				hideCheckbox('hidessid_enable', false);
4011
				break;
4012
			}
4013
			default: {
4014
				hideInput('puremode', true);
4015
				hideCheckbox('apbridge_enable', true);
4016
				hideCheckbox('hidessid_enable', true);
4017
				break;
4018
			}
4019
		}
4020
		show_wpaoptions();
4021
	}
4022

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

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

    
4074
	// ---------- On initial page load ------------------------------------------------------------
4075

    
4076
	updateType($('#type').val());
4077
	updateTypeSix($('#type6').val());
4078
	show_reset_settings($('#pppoe-reset-type').val());
4079
	hideClass('dhcp6advanced', true);
4080
	hideClass('dhcpadvanced', true);
4081
	show_dhcp6adv();
4082
	setDHCPoptions();
4083
	setPPPoEDialOnDemandItems();
4084
	setPPTPDialOnDemandItems();
4085
	show_wpaoptions();
4086
	updatewifistandard($('#standard').val());
4087
	updatewifimode($('#mode').val());
4088
	updatewpakeymgmt($('#wpa_key_mgmt').val());
4089
	updateeapclientmode($('#wpa_eap_client_mode').val());
4090

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

    
4099
	// Set preset from value
4100
	setPresets(sv);
4101

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

    
4110
	// ---------- Click checkbox handlers ---------------------------------------------------------
4111

    
4112
	$('#type').on('change', function() {
4113
		updateType(this.value);
4114
	});
4115

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

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

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

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

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

    
4136
	$('#track6-interface').on('change', function() {
4137
		update_track6_prefix();
4138
	});
4139

    
4140
	$('#pppoe-reset-type').on('change', function() {
4141
		show_reset_settings(this.value);
4142
	});
4143

    
4144
	$("#add4").click(function() {
4145
		addOption_v4();
4146
		$("#newgateway4").modal('hide');
4147
	});
4148

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

    
4157
	$("#add6").click(function() {
4158
		addOption_v6();
4159
		$("#newgateway6").modal('hide');
4160
	});
4161

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

    
4170
	$('#country').on('change', function() {
4171
		providers_list();
4172
	});
4173

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

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

    
4182
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4183
		setDHCPoptions();
4184
	});
4185

    
4186
	$('#adv_dhcp6_config_advanced').click(function () {
4187
		show_dhcp6adv();
4188
	});
4189

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

    
4194
	// On click . .
4195
	$('#pppoe_dialondemand').click(function () {
4196
		setPPPoEDialOnDemandItems();
4197
	});
4198

    
4199
	$('#pptp_dialondemand').click(function () {
4200
		setPPTPDialOnDemandItems();
4201
	});
4202

    
4203
	$('[name=adv_dhcp_pt_values]').click(function () {
4204
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4205
	});
4206

    
4207
	$('#wpa_enable').click(function () {
4208
		show_wpaoptions();
4209
	});
4210

    
4211
	$('#pppoe_resetdate').datepicker();
4212

    
4213
});
4214
//]]>
4215
</script>
4216

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