Project

General

Profile

Download (149 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-2024 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2006 Daniel S. Haischt
10
 * All rights reserved.
11
 *
12
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27
 */
28

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

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

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

    
51
define("ANTENNAS", false);
52

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

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

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

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

    
74
if (!is_array($pconfig)) {
75
	$pconfig = [];
76
}
77

    
78
$a_ppps = config_get_path('ppps/ppp', []);
79
$old_ppps = $a_ppps;
80

    
81
$a_gateways = config_get_path('gateways/gateway_item', []);
82

    
83
$wancfg = config_get_path("interfaces/{$if}", []);
84
$realifname = get_real_interface($if);
85
$old_wancfg = $wancfg;
86
array_set_path($old_wancfg, 'realif', $realifname);
87

    
88
$interfaces = get_configured_interface_with_descr();
89

    
90
$gateway_settings4 = [];
91
$gateway_settings6 = [];
92

    
93
/* Interfaces which have addresses configured elsewhere and should not be
94
 * configured here. See https://redmine.pfsense.org/issues/8687 */
95
$no_address_interfaces = ["ovpn", "ipsec", "gif", "gre", "l2tps"];
96
$show_address_controls = true;
97
foreach ($no_address_interfaces as $ifbl) {
98
	if (substr($realifname, 0, strlen($ifbl)) == $ifbl) {
99
		$show_address_controls = false;
100
	}
101
}
102

    
103
// Populate page descr if it does not exist.
104
if ((strtolower($if) == "wan") &&
105
    empty(array_get_path($wancfg, 'descr'))) {
106
	array_set_path($wancfg, 'descr', "WAN");
107
} elseif ((strtolower($if) == "lan") &&
108
    empty(array_get_path($wancfg, 'descr'))) {
109
	array_set_path($wancfg, 'descr', "LAN");
110
}
111

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

    
121
$type_disabled = (substr(array_get_path($wancfg, 'if', ''), 0, 3) == 'gre') ? 'disabled' : '';
122

    
123
if (array_get_path($wancfg, 'if') == array_get_path($a_ppps, "{$pppid}/if")) {
124
	array_set_path($pconfig, 'pppid', $pppid);
125
	array_set_path($pconfig, 'ptpid', array_get_path($a_ppps, "{$pppid}/ptpid"));
126
	array_set_path($pconfig, 'port', array_get_path($a_ppps, "{$pppid}/ports"));
127
	if (array_get_path($a_ppps, "{$pppid}/type") == "ppp") {
128
		array_set_path($pconfig, 'ppp_username', array_get_path($a_ppps, "{$pppid}/username", ''));
129
		array_set_path($pconfig, 'ppp_password', base64_decode(array_get_path($a_ppps, "{$pppid}/password", '')));
130
		array_set_path($pconfig, 'phone', array_get_path($a_ppps, "{$pppid}/phone", ''));
131
		array_set_path($pconfig, 'apn', array_get_path($a_ppps, "{$pppid}/apn", ''));
132
	} elseif (array_get_path($a_ppps, "{$pppid}/type") == "pppoe") {
133
		array_set_path($pconfig, 'pppoe_username', array_get_path($a_ppps, "{$pppid}/username", ''));
134
		array_set_path($pconfig, 'pppoe_password', base64_decode(array_get_path($a_ppps, "{$pppid}/password", '')));
135

    
136
		array_set_path($pconfig, 'provider', array_get_path($a_ppps, "{$pppid}/provider"));
137
		array_set_path($pconfig, 'hostuniq', array_get_path($a_ppps, "{$pppid}/hostuniq"));
138
		array_set_path($pconfig, 'pppoe_dialondemand', array_path_enabled($a_ppps, $pppid, 'ondemand'));
139
		array_set_path($pconfig, 'pppoe_idletimeout', array_get_path($a_ppps, "{$pppid}/idletimeout"));
140

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

    
145
		if (array_path_enabled($a_ppps, $pppid, 'pppoe-reset-type')) {
146
			array_set_path($pconfig, 'pppoe-reset-type', array_get_path($a_ppps, "{$pppid}/pppoe-reset-type"));
147
			$itemhash = getMPDCRONSettings(array_get_path($a_ppps, "{$pppid}/if"));
148
			if (is_array($itemhash) &&
149
			    !empty($itemhash)) {
150
				$cronitem = array_get_path($itemhash, 'ITEM');
151
			}
152
			if (isset($cronitem)) {
153
				$resetTime  = array_get_path($cronitem, 'minute') . ' ';
154
				$resetTime .= array_get_path($cronitem, 'hour') . ' ';
155
				$resetTime .= array_get_path($cronitem, 'mday') . ' ';
156
				$resetTime .= array_get_path($cronitem, 'month') . ' ';
157
				$resetTime .= array_get_path($cronitem, 'wday');
158
			} else {
159
				$resetTime = NULL;
160
			}
161

    
162
			if (array_get_path($a_ppps, "{$pppid}/pppoe-reset-type") == 'custom') {
163
				if ($cronitem) {
164
					array_set_path($pconfig, 'pppoe_pr_custom', true);
165
					array_set_path($pconfig, 'pppoe_resetminute', array_get_path($cronitem, 'minute'));
166
					array_set_path($pconfig, 'pppoe_resethour', array_get_path($cronitem, 'hour'));
167
					if ((array_get_path($cronitem, 'mday') != "*") &&
168
					    (array_get_path($cronitem, 'month') != "*")) {
169
						$resetDate  = array_get_path($cronitem, 'month') . '/';
170
						$resetDate .= array_get_path($cronitem, 'mday') . '/';
171
						$resetDate .= date("Y");
172
						array_set_path($pconfig, 'pppoe_resetdate', $resetDate);
173
					}
174
				}
175
			} elseif (array_get_path($a_ppps, "{$pppid}/pppoe-reset-type") == 'preset') {
176
				array_set_path($pconfig, 'pppoe_pr_preset', true);
177
				switch ($resetTime) {
178
					case CRON_MONTHLY_PATTERN:
179
						array_set_path($pconfig, 'pppoe_monthly', true);
180
						break;
181
					case CRON_WEEKLY_PATTERN:
182
						array_set_path($pconfig, 'pppoe_weekly', true);
183
						break;
184
					case CRON_DAILY_PATTERN:
185
						array_set_path($pconfig, 'pppoe_daily', true);
186
						break;
187
					case CRON_HOURLY_PATTERN:
188
						array_set_path($pconfig, 'pppoe_hourly', true);
189
						break;
190
				}
191
			}
192
		} // End force pppoe reset at specific time
193
		// End if type == pppoe
194
	} elseif ((array_get_path($a_ppps, "{$pppid}/type") == "pptp") ||
195
		  array_get_path($a_ppps, "{$pppid}/type") == "l2tp") {
196
		array_set_path($pconfig, 'pptp_username', array_get_path($a_ppps, "{$pppid}/username", ''));
197
		array_set_path($pconfig, 'pptp_password', base64_decode(array_get_path($a_ppps, "{$pppid}/password", '')));
198
		if ((array_get_path($a_ppps, "{$pppid}/type") == 'l2tp') &&
199
		    !empty(array_get_path($a_ppps, "{$pppid}/secret"))) {
200
			array_set_path($pconfig, 'l2tp_secret', base64_decode(array_get_path($a_ppps, "{$pppid}/secret")));
201
		}
202
		array_set_path($pconfig, 'pptp_localip', explode(",", array_get_path($a_ppps, "{$pppid}/localip")));
203
		array_set_path($pconfig, 'pptp_subnet', explode(",", array_get_path($a_ppps, "{$pppid}/subnet")));
204
		array_set_path($pconfig, 'pptp_remote', explode(",", array_get_path($a_ppps, "{$pppid}/gateway")));
205
		array_set_path($pconfig, 'pptp_dialondemand', array_path_enabled($a_ppps, $pppid, 'ondemand'));
206
		array_set_path($pconfig, 'pptp_idletimeout', array_get_path($a_ppps, "{$pppid}/timeout"));
207
	}
208
} else {
209
	array_set_path($pconfig, 'ptpid', interfaces_ptpid_next());
210
	$pppid = count($a_ppps);
211
}
212

    
213
/* Settings to copy from $wancfg to $pconfig */
214
$copy_list = [
215
	'dhcphostname',
216
	'alias-address',
217
	'alias-subnet',
218
	'dhcprejectfrom',
219
	'adv_dhcp_pt_timeout',
220
	'adv_dhcp_pt_retry',
221
	'adv_dhcp_pt_select_timeout',
222
	'adv_dhcp_pt_reboot',
223
	'adv_dhcp_pt_backoff_cutoff',
224
	'adv_dhcp_pt_initial_interval',
225
	'adv_dhcp_pt_values',
226
	'adv_dhcp_send_options',
227
	'adv_dhcp_request_options',
228
	'adv_dhcp_required_options',
229
	'adv_dhcp_option_modifiers',
230
	'adv_dhcp_config_advanced',
231
	'adv_dhcp_config_file_override',
232
	'adv_dhcp_config_file_override_path',
233
	'adv_dhcp6_interface_statement_send_options',
234
	'adv_dhcp6_interface_statement_request_options',
235
	'adv_dhcp6_interface_statement_information_only_enable',
236
	'adv_dhcp6_interface_statement_script',
237
	'adv_dhcp6_id_assoc_statement_address_enable',
238
	'adv_dhcp6_id_assoc_statement_address',
239
	'adv_dhcp6_id_assoc_statement_address_id',
240
	'adv_dhcp6_id_assoc_statement_address_pltime',
241
	'adv_dhcp6_id_assoc_statement_address_vltime',
242
	'adv_dhcp6_id_assoc_statement_prefix_enable',
243
	'adv_dhcp6_id_assoc_statement_prefix',
244
	'adv_dhcp6_id_assoc_statement_prefix_id',
245
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
246
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
247
	'adv_dhcp6_prefix_interface_statement_sla_id',
248
	'adv_dhcp6_prefix_interface_statement_sla_len',
249
	'adv_dhcp6_prefix_selected_interface',
250
	'adv_dhcp6_authentication_statement_authname',
251
	'adv_dhcp6_authentication_statement_protocol',
252
	'adv_dhcp6_authentication_statement_algorithm',
253
	'adv_dhcp6_authentication_statement_rdm',
254
	'adv_dhcp6_key_info_statement_keyname',
255
	'adv_dhcp6_key_info_statement_realm',
256
	'adv_dhcp6_key_info_statement_keyid',
257
	'adv_dhcp6_key_info_statement_secret',
258
	'adv_dhcp6_key_info_statement_expire',
259
	'adv_dhcp6_config_advanced',
260
	'adv_dhcp6_config_file_override',
261
	'adv_dhcp6_config_file_override_path',
262
];
263
foreach ($copy_list as $sn) {
264
	array_set_path($pconfig, $sn, array_get_path($wancfg, $sn));
265
}
266

    
267
array_set_path($pconfig, 'dhcp_plus', array_path_enabled($wancfg, '', 'dhcp_plus'));
268
array_set_path($pconfig, 'descr', remove_bad_chars(array_get_path($wancfg, 'descr')));
269
array_set_path($pconfig, 'enable', array_path_enabled($wancfg, ''));
270

    
271
switch (array_get_path($wancfg, 'ipaddr')) {
272
	case "dhcp":
273
		array_set_path($pconfig, 'type', 'dhcp');
274
		array_set_path($pconfig, 'dhcpvlanenable', array_path_enabled($wancfg, '', 'dhcpvlanenable'));
275
		array_set_path($pconfig, 'dhcpcvpt', array_get_path($wancfg, 'dhcpcvpt'));
276
		break;
277
	case "pppoe":
278
	case "pptp":
279
	case "l2tp":
280
	case "ppp":
281
		array_set_path($pconfig, 'type', array_get_path($wancfg, 'ipaddr'));
282
		break;
283
	default:
284
		if (is_ipaddrv4(array_get_path($wancfg, 'ipaddr'))) {
285
			array_set_path($pconfig, 'type', 'staticv4');
286
			array_set_path($pconfig, 'ipaddr', array_get_path($wancfg, 'ipaddr'));
287
			array_set_path($pconfig, 'subnet', array_get_path($wancfg, 'subnet'));
288
			array_set_path($pconfig, 'gateway', array_get_path($wancfg, 'gateway'));
289
		} elseif (in_array(remove_ifindex(array_get_path($wancfg, 'if')), ["ppp", "pppoe", "pptp", "l2tp"])) {
290
			array_set_path($pconfig, 'type', remove_ifindex(array_get_path($wancfg, 'if')));
291
		} else {
292
			array_set_path($pconfig, 'type', 'none');
293
		}
294
		break;
295
}
296

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

    
344
array_set_path($pconfig, 'blockpriv', array_path_enabled($wancfg, '', 'blockpriv'));
345
array_set_path($pconfig, 'blockbogons', array_path_enabled($wancfg, '', 'blockbogons'));
346
array_set_path($pconfig, 'spoofmac', array_get_path($wancfg, 'spoofmac'));
347
array_set_path($pconfig, 'mtu', array_get_path($wancfg, 'mtu'));
348
array_set_path($pconfig, 'mss', array_get_path($wancfg, 'mss'));
349

    
350
/* Wireless interface? */
351
if (is_array(array_get_path($wancfg, 'wireless'))) {
352
	/* Sync first to be sure it displays the actual settings that will be used */
353
	interface_sync_wireless_clones($wancfg, false);
354
	/* Get wireless modes */
355
	$wlanif = get_real_interface($if);
356
	if (!does_interface_exist($wlanif)) {
357
		interface_wireless_clone($wlanif, $wancfg);
358
	}
359
	$wlanbaseif = interface_get_wireless_base(array_get_path($wancfg, 'if'));
360
	preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split);
361
	$wl_modes = get_wireless_modes($if);
362
	$wl_ht_modes = get_wireless_ht_modes($if);
363
	$wl_ht_list = get_wireless_ht_list($if);
364
	$wl_chaninfo = get_wireless_channel_info($if);
365
	$wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2];
366
	$wl_sysctl = get_sysctl(
367
		[
368
			"{$wl_sysctl_prefix}.diversity",
369
			"{$wl_sysctl_prefix}.txantenna",
370
			"{$wl_sysctl_prefix}.rxantenna",
371
			"{$wl_sysctl_prefix}.slottime",
372
			"{$wl_sysctl_prefix}.acktimeout",
373
			"{$wl_sysctl_prefix}.ctstimeout"
374
		]);
375
	$wl_regdomain_xml_attr = [];
376
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
377
	$wl_regdomains = array_get_path($wl_regdomain_xml, 'regulatory-domains/rd');
378
	$wl_regdomains_attr = array_get_path($wl_regdomain_xml_attr, 'regulatory-domains/rd');
379
	$wl_countries = array_get_path($wl_regdomain_xml, 'country-codes/country');
380
	$wl_countries_attr = array_get_path($wl_regdomain_xml_attr, 'country-codes/country');
381

    
382
	array_set_path($pconfig, 'persistcommonwireless', config_path_enabled('wireless/interfaces', $wlanbaseif));
383
	array_set_path($pconfig, 'standard', array_get_path($wancfg, 'wireless/standard'));
384
	array_set_path($pconfig, 'mode', array_get_path($wancfg, 'wireless/mode'));
385
	array_set_path($pconfig, 'protmode', array_get_path($wancfg, 'wireless/protmode'));
386
	array_set_path($pconfig, 'ssid', array_get_path($wancfg, 'wireless/ssid'));
387
	array_set_path($pconfig, 'channel', array_get_path($wancfg, 'wireless/channel'));
388
	array_set_path($pconfig, 'channel_width', array_get_path($wancfg, 'wireless/channel_width'));
389
	array_set_path($pconfig, 'txpower', array_get_path($wancfg, 'wireless/txpower'));
390
	array_set_path($pconfig, 'diversity', array_get_path($wancfg, 'wireless/diversity'));
391
	array_set_path($pconfig, 'txantenna', array_get_path($wancfg, 'wireless/txantenna'));
392
	array_set_path($pconfig, 'rxantenna', array_get_path($wancfg, 'wireless/rxantenna'));
393
	array_set_path($pconfig, 'distance', array_get_path($wancfg, 'wireless/distance'));
394
	array_set_path($pconfig, 'regdomain', array_get_path($wancfg, 'wireless/regdomain'));
395
	array_set_path($pconfig, 'regcountry', array_get_path($wancfg, 'wireless/regcountry'));
396
	array_set_path($pconfig, 'reglocation', array_get_path($wancfg, 'wireless/reglocation'));
397
	array_set_path($pconfig, 'wme_enable', array_path_enabled($wancfg, 'wireless/wme'));
398

    
399
	if (array_path_enabled($wancfg, 'wireless/puren')) {
400
		array_set_path($pconfig, 'puremode', '11n');
401
	} elseif (array_path_enabled($wancfg, 'wireless/pureg')) {
402
		array_set_path($pconfig, 'puremode', '11g');
403
	} else {
404
		array_set_path($pconfig, 'puremode', 'any');
405
	}
406
	array_set_path($pconfig, 'apbridge_enable', array_path_enabled($wancfg, 'wireless/apbridge'));
407
	array_set_path($pconfig, 'authmode', array_get_path($wancfg, 'wireless/authmode'));
408
	array_set_path($pconfig, 'hidessid_enable', array_path_enabled($wancfg, 'wireless/hidessid'));
409
	array_set_path($pconfig, 'auth_server_addr', array_get_path($wancfg, 'wireless/auth_server_addr'));
410
	array_set_path($pconfig, 'auth_server_port', array_get_path($wancfg, 'wireless/auth_server_port'));
411
	array_set_path($pconfig, 'auth_server_shared_secret', array_get_path($wancfg, 'wireless/auth_server_shared_secret'));
412
	array_set_path($pconfig, 'auth_server_addr2', array_get_path($wancfg, 'wireless/auth_server_addr2'));
413
	array_set_path($pconfig, 'auth_server_port2', array_get_path($wancfg, 'wireless/auth_server_port2'));
414
	array_set_path($pconfig, 'auth_server_shared_secret2', array_get_path($wancfg, 'wireless/auth_server_shared_secret2'));
415
	if (is_array(array_get_path($wancfg, 'wireless/wpa'))) {
416
		array_set_path($pconfig, 'wpa_enable', array_path_enabled($wancfg, 'wireless/wpa'));
417
		array_set_path($pconfig, 'debug_mode', array_get_path($wancfg, 'wireless/wpa/debug_mode'));
418
		array_set_path($pconfig, 'macaddr_acl', array_get_path($wancfg, 'wireless/wpa/macaddr_acl'));
419
		array_set_path($pconfig, 'mac_acl_enable', array_path_enabled($wancfg, 'wireless/wpa', 'mac_acl_enable'));
420
		array_set_path($pconfig, 'wpa_mode', array_get_path($wancfg, 'wireless/wpa/wpa_mode'));
421
		array_set_path($pconfig, 'wpa_key_mgmt', array_get_path($wancfg, 'wireless/wpa/wpa_key_mgmt'));
422
		array_set_path($pconfig, 'wpa_pairwise', array_get_path($wancfg, 'wireless/wpa/wpa_pairwise'));
423
		array_set_path($pconfig, 'wpa_group_rekey', array_get_path($wancfg, 'wireless/wpa/wpa_group_rekey'));
424
		array_set_path($pconfig, 'wpa_gmk_rekey', array_get_path($wancfg, 'wireless/wpa/wpa_gmk_rekey'));
425
		array_set_path($pconfig, 'wpa_strict_rekey', array_path_enabled($wancfg, 'wireless/wpa', 'wpa_strict_rekey'));
426
		array_set_path($pconfig, 'passphrase', array_get_path($wancfg, 'wireless/wpa/passphrase'));
427
		array_set_path($pconfig, 'ieee8021x', array_path_enabled($wancfg, 'wireless/wpa/ieee8021x'));
428
		array_set_path($pconfig, 'rsn_preauth', array_path_enabled($wancfg, 'wireless/wpa', 'rsn_preauth'));
429
		array_set_path($pconfig, 'ext_wpa_sw', array_get_path($wancfg, 'wireless/wpa/ext_wpa_sw'));
430
		array_set_path($pconfig, 'wpa_eap_client_mode', array_get_path($wancfg, 'wireless/wpa/wpa_eap_client_mode'));
431
		array_set_path($pconfig, 'wpa_eap_inner_auth', array_get_path($wancfg, 'wireless/wpa/wpa_eap_inner_auth'));
432
		array_set_path($pconfig, 'wpa_eap_inner_id', array_get_path($wancfg, 'wireless/wpa/wpa_eap_inner_id'));
433
		array_set_path($pconfig, 'wpa_eap_inner_password', base64_decode(array_get_path($wancfg, 'wireless/wpa/wpa_eap_inner_password')));
434
		array_set_path($pconfig, 'wpa_eap_cert', array_get_path($wancfg, 'wireless/wpa/wpa_eap_cert'));
435
		array_set_path($pconfig, 'wpa_eap_ca', array_get_path($wancfg, 'wireless/wpa/wpa_eap_ca'));
436
	}
437
	array_set_path($pconfig, 'mac_acl', array_get_path($wancfg, 'wireless/mac_acl'));
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_get('tmp_path') . '/config.cache');
449
		clear_subsystem_dirty('interfaces');
450

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

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

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

    
495
		clear_subsystem_dirty('interfaces');
496

    
497
		$retval |= filter_configure();
498

    
499
		enable_rrd_graphing();
500

    
501
		$changes_applied = true;
502

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

    
508
		send_event("service reload packages");
509
	}
510
	@unlink(g_get('tmp_path') . '/.interfaces.apply');
511
} elseif ($_POST['save']) {
512
	unset($input_errors);
513
	$pconfig = $_POST;
514

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

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

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

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

    
543
	if (!$input_errors) {
544
		/* Reserved name? */
545
		if (get_pf_reserved($_POST['descr'], false)) {
546
			$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as an interface name: %s"), $_POST['descr']);
547
		}
548

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

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

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

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

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

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

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

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

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

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

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

    
769
			if (($_POST['track6-prefix-id--hex'] != "") &&
770
			    !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) ||
775
				    ($track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']])) {
776
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
777
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
778
				} else {
779
					foreach ($ifdescrs as $ifent => $ifdescr) {
780
						if ($if == $ifent) {
781
							continue;
782
						}
783
						if (config_get_path("interfaces/{$ifent}/ipaddrv6") == 'track6' &&
784
						    config_get_path("interfaces/{$ifent}/track6-interface") == $_POST['track6-interface'] &&
785
						    config_get_path("interfaces/{$ifent}/track6-prefix-id") == $track6_prefix_id) {
786
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
787
						}
788
					}
789
				}
790
			}
791
			break;
792
	}
793

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

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

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

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

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

    
883
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
884
	if (($_POST['gateway'] != "none") &&
885
	    (!$_POST['gatewayip4'] ||
886
	    ($_POST['gateway'] != $_POST['gatewayname4']))) {
887
		$match = false;
888
		foreach ($a_gateways as $gateway) {
889
			if (in_array($_POST['gateway'], $gateway)) {
890
				$match = true;
891
			}
892
		}
893
		if (!$match) {
894
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
895
		}
896
	}
897
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
898
	if (($_POST['gatewayv6'] != "none") &&
899
	    (!$_POST['gatewayip6'] ||
900
	    ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
901
		$match = false;
902
		foreach ($a_gateways as $gateway) {
903
			if (in_array($_POST['gatewayv6'], $gateway)) {
904
				$match = true;
905
			}
906
		}
907
		if (!$match) {
908
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
909
		}
910
	}
911

    
912
	if ($_POST['provider'] &&
913
	    strpos($_POST['provider'], "\"")) {
914
		$input_errors[] = gettext("The service name may not contain quote characters.");
915
	}
916
	if ($_POST['hostuniq'] &&
917
	    !preg_match('/^[a-zA-Z0-9]+$/i', $_POST['hostuniq'])) {
918
		$input_errors[] = gettext("The Host-Uniq value can only be hexadecimal or letters and numbers.");
919
	}
920
	if (($_POST['pppoe_idletimeout'] != "") &&
921
	   !is_numericint($_POST['pppoe_idletimeout'])) {
922
		$input_errors[] = gettext("The idle timeout value must be an integer.");
923
	}
924
	if (($_POST['pppoe_resethour'] != "") &&
925
	    !is_numericint($_POST['pppoe_resethour']) &&
926
	    ($_POST['pppoe_resethour'] >= 0) &&
927
	    ($_POST['pppoe_resethour'] <= 23)) {
928
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
929
	}
930
	if (($_POST['pppoe_resetminute'] != "") &&
931
	    !is_numericint($_POST['pppoe_resetminute']) &&
932
	    ($_POST['pppoe_resetminute'] >= 0) &&
933
	    ($_POST['pppoe_resetminute'] <= 59)) {
934
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
935
	}
936
	if (($_POST['pppoe_resetdate'] != "") &&
937
	    !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
938
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
939
	}
940
	if (($_POST['pptp_local0'] &&
941
	    !is_ipaddrv4($_POST['pptp_local0']))) {
942
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
943
	}
944
	if (($_POST['pptp_subnet0'] &&
945
	    !is_numeric($_POST['pptp_subnet0']))) {
946
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
947
	}
948
	if (($_POST['pptp_remote0'] &&
949
	    !is_ipaddrv4($_POST['pptp_remote0']) &&
950
	    !is_hostname($_POST['pptp_remote0']))) {
951
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
952
	}
953
	if (($_POST['pptp_idletimeout'] != "") &&
954
	    !is_numericint($_POST['pptp_idletimeout'])) {
955
		$input_errors[] = gettext("The idle timeout value must be an integer.");
956
	}
957
	if (($_POST['spoofmac'] &&
958
	    !is_macaddr($_POST['spoofmac']))) {
959
		$input_errors[] = gettext("A valid MAC address must be specified.");
960
	}
961
	if ($_POST['mtu']) {
962
		if (!is_numericint($_POST['mtu'])) {
963
			$input_errors[] = "MTU must be an integer.";
964
		}
965
		if (substr(array_get_path($wancfg, 'if'), 0, 3) == 'gif') {
966
			$min_mtu = 1280;
967
			$max_mtu = 8192;
968
		} elseif (($_POST['ipaddrv6'] == '6rd') ||
969
			  ($_POST['ipaddrv6'] == '6to4')) {
970
			$min_mtu = 1300;
971
			$max_mtu = 9000;
972
		} else {
973
			$min_mtu = 576;
974
			$max_mtu = 9000;
975
		}
976

    
977
		if (($_POST['mtu'] < $min_mtu) ||
978
		    ($_POST['mtu'] > $max_mtu)) {
979
			$input_errors[] = sprintf(gettext("The MTU must be between %d and %d bytes."), $min_mtu, $max_mtu);
980
		}
981

    
982
		unset($min_mtu, $max_mtu);
983

    
984
		if (interface_is_vlan(array_get_path($wancfg, 'if')) != NULL) {
985
			$realhwif_array = get_parent_interface(array_get_path($wancfg, 'if'));
986
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
987
			$parent_realhwif = $realhwif_array[0];
988
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
989
			$mtu = 0;
990
			if (!empty($parent_if) &&
991
			    !(config_get_path("interfaces/{$parent_if}/mtu"))) {
992
				$mtu = intval(config_get_path("interfaces/{$parent_if}/mtu"));
993
			}
994
			if ($mtu == 0) {
995
				$mtu = get_interface_mtu($parent_realhwif);
996
			}
997
			if ($_POST['mtu'] > $mtu) {
998
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
999
			}
1000
		} else {
1001
			foreach (config_get_path('interfaces', []) as $idx => $ifdata) {
1002
				if (($idx == $if) ||
1003
				    (interface_is_vlan(array_get_path($ifdata, 'if')) == NULL)) {
1004
					continue;
1005
				}
1006

    
1007
				$realhwif_array = get_parent_interface(array_get_path($ifdata, 'if'));
1008
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
1009
				$parent_realhwif = $realhwif_array[0];
1010

    
1011
				if ($parent_realhwif != array_get_path($wancfg, 'if')) {
1012
					continue;
1013
				}
1014

    
1015
				if (array_path_enabled($ifdata, '', 'mtu') &&
1016
				    (array_get_path($ifdata, 'mtu') > $_POST['mtu'])) {
1017
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), array_get_path($ifdata, 'descr'));
1018
				}
1019
			}
1020
		}
1021
	}
1022
	if ($_POST['mss'] != '') {
1023
		if (!is_numericint($_POST['mss']) ||
1024
		    (($_POST['mss'] < 576) ||
1025
		    ($_POST['mss'] > 65535))) {
1026
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
1027
		}
1028
	}
1029
	/* Wireless interface? */
1030
	if (is_array(array_get_path($wancfg, 'wireless'))) {
1031
		$reqdfields = ["mode"];
1032
		$reqdfieldsn = [gettext("Mode")];
1033
		if ($_POST['mode'] == 'hostap') {
1034
			$reqdfields[] = "ssid";
1035
			$reqdfieldsn[] = gettext("SSID");
1036
			if (isset($_POST['channel']) &&
1037
			    ($_POST['channel'] == "0")) {
1038
				// auto channel with hostap is broken, prevent this for now.
1039
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
1040
			}
1041
		}
1042
		if (!stristr($_POST['standard'], '11n') &&
1043
		    ($_POST['channel_width'] != "0")) {
1044
			$input_errors[] = gettext("Channel width selection is only supported by 802.11n standards.");
1045
		}
1046
		if (stristr($_POST['standard'], '11n')) {
1047
			if (!($_POST['wme_enable'])) {
1048
				$input_errors[] = gettext("802.11n standards require enabling WME.");
1049
			}
1050
			$whl = array_get_path($wl_ht_list, array_get_path($_POST, 'standard') . '/' . array_get_path($_POST, 'channel'), []);
1051
			if (($_POST['channel_width'] != "0") &&
1052
			    ($_POST['channel'] != "0") &&
1053
			    !empty($whl) &&
1054
			    !in_array($_POST['channel_width'], $whl)) {
1055
				$input_errors[] = sprintf(gettext("Unable to use %s channel width with channel %s."), strtoupper($_POST['channel_width']), $_POST['channel']);
1056
			}
1057
		}
1058
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
1059
		check_wireless_mode();
1060
		if (isset($_POST['wpa_group_rekey']) &&
1061
		    (!is_numericint($_POST['wpa_group_rekey']) ||
1062
		    ($_POST['wpa_group_rekey'] < 1) ||
1063
		    ($_POST['wpa_group_rekey'] > 9999))) {
1064
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
1065
		}
1066
		if (isset($_POST['wpa_gmk_rekey']) &&
1067
		    (!is_numericint($_POST['wpa_gmk_rekey']) ||
1068
		    ($_POST['wpa_gmk_rekey'] < 1) ||
1069
		    ($_POST['wpa_gmk_rekey'] > 9999))) {
1070
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
1071
		}
1072
		if (isset($_POST['wpa_group_rekey']) &&
1073
		    isset($_POST['wpa_gmk_rekey'])) {
1074
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
1075
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
1076
			}
1077
		}
1078
		if (!empty($_POST['auth_server_addr'])) {
1079
			if (!is_domain($_POST['auth_server_addr']) &&
1080
			    !is_ipaddr($_POST['auth_server_addr'])) {
1081
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
1082
			}
1083
		}
1084
		if (!empty($_POST['auth_server_addr2'])) {
1085
			if (!is_domain($_POST['auth_server_addr2']) &&
1086
			    !is_ipaddr($_POST['auth_server_addr2'])) {
1087
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
1088
			}
1089
		}
1090
		if (!empty($_POST['auth_server_port'])) {
1091
			if (!is_port($_POST['auth_server_port'])) {
1092
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
1093
			}
1094
		}
1095
		if (!empty($_POST['auth_server_port2'])) {
1096
			if (!is_port($_POST['auth_server_port2'])) {
1097
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
1098
			}
1099
		}
1100
		if (isset($_POST['channel']) &&
1101
		    !is_numericint($_POST['channel'])) {
1102
			if (!is_numericint($_POST['channel'])) {
1103
				$input_errors[] = gettext("Invalid channel specified.");
1104
			} else {
1105
				if (($_POST['channel'] > 255) ||
1106
				    ($_POST['channel'] < 0)) {
1107
					$input_errors[] = gettext("Channel must be between 0-255.");
1108
				}
1109
			}
1110
		}
1111
		if (!empty($_POST['distance']) &&
1112
		    !is_numericint($_POST['distance'])) {
1113
			$input_errors[] = gettext("Distance must be an integer.");
1114
		}
1115
		if (isset($_POST['standard']) &&
1116
		    (stristr($_POST['standard'], '11na') ||
1117
		    stristr($_POST['standard'], '11a'))) {
1118
			if (($_POST['channel'] != 0) &&
1119
			    ($_POST['channel'] < 15)) {
1120
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
1121
			}
1122
		}
1123
		if (isset($_POST['standard']) &&
1124
		    (($_POST['standard'] == "11b") ||
1125
		    ($_POST['standard'] == "11g"))) {
1126
			if ($_POST['channel'] > 14) {
1127
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
1128
			}
1129
		}
1130
		if (!empty($_POST['protmode']) &&
1131
		    !in_array($_POST['protmode'], ["off", "cts", "rtscts"])) {
1132
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
1133
		}
1134

    
1135
		if ($_POST['passphrase']) {
1136
			$passlen = strlen($_POST['passphrase']);
1137
			if (($passlen < 8) ||
1138
			    ($passlen > 63)) {
1139
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1140
			}
1141
		}
1142

    
1143
		if ($_POST['wpa_enable'] == "yes") {
1144
			if (empty($_POST['passphrase']) &&
1145
			    stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1146
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1147
			}
1148
			if (($_POST['mode'] == 'bss') &&
1149
			    ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1150
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1151
				if (empty($_POST['wpa_eap_inner_id'])) {
1152
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1153
					    "when PEAP/TTLS authentication method is selected.");
1154
				}
1155
				if (empty($_POST['wpa_eap_inner_password'])) {
1156
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1157
					    "when PEAP/TTLS authentication method is selected.");
1158
				}
1159
			}
1160
		}
1161
	}
1162

    
1163
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1164
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1165
	}
1166

    
1167
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1168
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1169
	}
1170

    
1171
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1172
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1173
	}
1174

    
1175
	if ($_POST['gatewayip4']) {
1176
		// The user wants to add an IPv4 gateway - validate the settings
1177
		$gateway_settings4 = [
1178
			'name' => $_POST['gatewayname4'],
1179
			'interface' => $_POST['if'],
1180
			'gateway' => $_POST['gatewayip4'],
1181
			'descr' => $_POST['gatewaydescr4'],
1182
			'defaultgw' => $_POST['defaultgw4'],
1183
			'ipprotocol' => 'inet',
1184
		];
1185
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1186
		foreach ($gw_input_errors as $input_error_text) {
1187
			$input_errors[] = $input_error_text;
1188
		}
1189
	}
1190

    
1191
	if ($_POST['gatewayip6']) {
1192
		// The user wants to add an IPv6 gateway - validate the settings
1193
		$gateway_settings6 = [
1194
			'name' => $_POST['gatewayname6'],
1195
			'interface' => $_POST['if'],
1196
			'gateway' => $_POST['gatewayip6'],
1197
			'descr' => $_POST['gatewaydescr6'],
1198
			'defaultgw' => $_POST['defaultgw6'],
1199
			'ipprotocol' => 'inet6',
1200
		];
1201
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1202
		foreach ($gw_input_errors as $input_error_text) {
1203
			$input_errors[] = $input_error_text;
1204
		}
1205
	}
1206

    
1207
	if (!$input_errors) {
1208
		$poriginal = [];
1209
		// These 3 fields can be a list of multiple data items when used for MLPPP.
1210
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
1211
		array_set_path($poriginal, 'pptp_localip', explode(",", array_get_path($a_ppps, "{$pppid}/localip")));
1212
		array_set_path($poriginal, 'pptp_subnet',  explode(",", array_get_path($a_ppps, "{$pppid}/subnet")));
1213
		array_set_path($poriginal, 'pptp_remote',  explode(",", array_get_path($a_ppps, "{$pppid}/gateway")));
1214

    
1215
		if (array_get_path($wancfg, 'ipaddr') != $_POST['type']) {
1216
			if (in_array(array_get_path($wancfg, 'ipaddr'), ["ppp", "pppoe", "pptp", "l2tp"])) {
1217
				array_set_path($wancfg, 'if', array_get_path($a_ppps, "{$pppid}/ports"));
1218
				array_del_path($a_ppps, $pppid);
1219
			} elseif (array_get_path($wancfg, 'ipaddr') == "dhcp") {
1220
				kill_dhclient_process(array_get_path($wancfg, 'if'));
1221
			}
1222
			if ((array_get_path($wancfg, 'ipaddrv6') == "dhcp6") &&
1223
			    ($_POST['type6'] != "dhcp6")) {
1224
				interface_dhcpv6_configure($if, $wancfg, true);
1225
			}
1226
		}
1227
		$ppp = [];
1228
		if (array_get_path($wancfg, 'ipaddr') != "ppp") {
1229
			array_del_path($wancfg, 'ipaddr');
1230
		}
1231
		if (array_get_path($wancfg, 'ipaddrv6') != "ppp") {
1232
			array_del_path($wancfg, 'ipaddrv6');
1233
		}
1234

    
1235
		$wancfg_to_delelete = [
1236
			'subnet',
1237
			'gateway',
1238
			'subnetv6',
1239
			'gatewayv6',
1240
			'dhcphostname',
1241
			'dhcprejectfrom',
1242
			'dhcp6-duid',
1243
			'dhcp6-ia-pd-len',
1244
			'dhcp6-ia-pd-send-hint',
1245
			'dhcp6prefixonly',
1246
			'dhcp6usev4iface',
1247
			'slaacusev4iface',
1248
			'ipv6usev4iface',
1249
			'track6-interface',
1250
			'track6-prefix-id',
1251
			'dhcp6withoutra',
1252
			'dhcp6vlanenable',
1253
			'dhcp6cvpt',
1254
			'prefix-6rd',
1255
			'prefix-6rd-v4plen',
1256
			'gateway-6rd',
1257
			'dhcpvlanenable',
1258
			'dhcpcvpt',
1259
			'adv_dhcp_pt_timeout',
1260
			'adv_dhcp_pt_retry',
1261
			'adv_dhcp_pt_select_timeout',
1262
			'adv_dhcp_pt_reboot',
1263
			'adv_dhcp_pt_backoff_cutoff',
1264
			'adv_dhcp_pt_initial_interval',
1265
			'adv_dhcp_pt_values',
1266
			'adv_dhcp_send_options',
1267
			'adv_dhcp_request_options',
1268
			'adv_dhcp_required_options',
1269
			'adv_dhcp_option_modifiers',
1270
			'adv_dhcp_config_advanced',
1271
			'adv_dhcp_config_file_override',
1272
			'adv_dhcp_config_file_override_path',
1273
			'adv_dhcp6_interface_statement_send_options',
1274
			'adv_dhcp6_interface_statement_request_options',
1275
			'adv_dhcp6_interface_statement_information_only_enable',
1276
			'adv_dhcp6_interface_statement_script',
1277
			'adv_dhcp6_id_assoc_statement_address_enable',
1278
			'adv_dhcp6_id_assoc_statement_address',
1279
			'adv_dhcp6_id_assoc_statement_address_id',
1280
			'adv_dhcp6_id_assoc_statement_address_pltime',
1281
			'adv_dhcp6_id_assoc_statement_address_vltime',
1282
			'adv_dhcp6_id_assoc_statement_prefix_enable',
1283
			'adv_dhcp6_id_assoc_statement_prefix',
1284
			'adv_dhcp6_id_assoc_statement_prefix_id',
1285
			'adv_dhcp6_id_assoc_statement_prefix_pltime',
1286
			'adv_dhcp6_id_assoc_statement_prefix_vltime',
1287
			'adv_dhcp6_prefix_interface_statement_sla_id',
1288
			'adv_dhcp6_prefix_interface_statement_sla_len',
1289
			'adv_dhcp6_prefix_selected_interface',
1290
			'adv_dhcp6_authentication_statement_authname',
1291
			'adv_dhcp6_authentication_statement_protocol',
1292
			'adv_dhcp6_authentication_statement_algorithm',
1293
			'adv_dhcp6_authentication_statement_rdm',
1294
			'adv_dhcp6_key_info_statement_keyname',
1295
			'adv_dhcp6_key_info_statement_realm',
1296
			'adv_dhcp6_key_info_statement_keyid',
1297
			'adv_dhcp6_key_info_statement_secret',
1298
			'adv_dhcp6_key_info_statement_expire',
1299
			'adv_dhcp6_config_advanced',
1300
			'adv_dhcp6_config_file_override',
1301
			'adv_dhcp6_config_file_override_path',
1302
			'pppoe_password',
1303
			'pptp_username',
1304
			'pptp_password',
1305
			'l2tp_secret',
1306
			'provider',
1307
			'hostuniq',
1308
			'ondemand',
1309
			'timeout',
1310
			'local',
1311
			'remote',
1312
		];
1313
		foreach ($wancfg_to_delelete as $todel) {
1314
			array_del_path($wancfg, $todel);
1315
		}
1316

    
1317
		if (empty(array_get_path($wancfg, 'pppoe/pppoe-reset-type'))) {
1318
			array_del_path($wancfg, 'pppoe/pppoe-reset-type');
1319
		}
1320
		if (is_array(array_get_path($a_ppps, $pppid)) &&
1321
		    in_array(array_get_path($wancfg, 'ipaddr'), ["ppp", "pppoe", "pptp", "l2tp"])) {
1322
			if (array_get_path($wancfg, 'ipaddr') != 'ppp') {
1323
				array_del_path($a_ppps, "{$pppid}/apn");
1324
				array_del_path($a_ppps, "{$pppid}/phone");
1325
				array_del_path($a_ppps, "{$pppid}/provider");
1326
				array_del_path($a_ppps, "{$pppid}/ondemand");
1327
			}
1328
			if (in_array(array_get_path($wancfg, 'ipaddr'), ["pppoe", "pptp", "l2tp"])) {
1329
				array_del_path($a_ppps, "{$pppid}/localip");
1330
				array_del_path($a_ppps, "{$pppid}/subnet");
1331
				array_del_path($a_ppps, "{$pppid}/gateway");
1332
			}
1333
			if (array_get_path($wancfg, 'ipaddr') != 'pppoe') {
1334
				array_del_path($a_ppps, "{$pppid}/pppoe-reset-type");
1335
				array_del_path($a_ppps, "{$pppid}/hostuniq");
1336
			}
1337
			if (array_get_path($wancfg, 'type') != $_POST['type']) {
1338
				array_del_path($a_ppps, "{$pppid}/idletimeout");
1339
			}
1340
		}
1341

    
1342
		array_set_path($wancfg, 'descr', remove_bad_chars($_POST['descr']));
1343
		array_set_path($wancfg, 'enable', (($_POST['enable'] == "yes") ? true : false));
1344

    
1345
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1346
		switch ($_POST['type']) {
1347
			case "staticv4":
1348
				array_set_path($wancfg, 'ipaddr', $_POST['ipaddr']);
1349
				array_set_path($wancfg, 'subnet', $_POST['subnet']);
1350
				if ($_POST['gateway'] != "none") {
1351
					array_set_path($wancfg, 'gateway', $_POST['gateway']);
1352
				}
1353
				break;
1354
			case "dhcp":
1355
				array_set_path($wancfg, 'ipaddr', 'dhcp');
1356

    
1357
				array_set_path($wancfg, 'dhcphostname', $_POST['dhcphostname']);
1358
				array_set_path($wancfg, 'alias-address', $_POST['alias-address']);
1359
				array_set_path($wancfg, 'alias-subnet', $_POST['alias-subnet']);
1360
				array_set_path($wancfg, 'dhcprejectfrom', $_POST['dhcprejectfrom']);
1361

    
1362
				array_set_path($wancfg, 'adv_dhcp_pt_timeout', $_POST['adv_dhcp_pt_timeout']);
1363
				array_set_path($wancfg, 'adv_dhcp_pt_retry', $_POST['adv_dhcp_pt_retry']);
1364
				array_set_path($wancfg, 'adv_dhcp_pt_select_timeout', $_POST['adv_dhcp_pt_select_timeout']);
1365
				array_set_path($wancfg, 'adv_dhcp_pt_reboot', $_POST['adv_dhcp_pt_reboot']);
1366
				array_set_path($wancfg, 'adv_dhcp_pt_backoff_cutoff', $_POST['adv_dhcp_pt_backoff_cutoff']);
1367
				array_set_path($wancfg, 'adv_dhcp_pt_initial_interval', $_POST['adv_dhcp_pt_initial_interval']);
1368
				array_set_path($wancfg, 'adv_dhcp_pt_values', $_POST['adv_dhcp_pt_values']);
1369

    
1370
				array_set_path($wancfg, 'adv_dhcp_send_options', $_POST['adv_dhcp_send_options']);
1371
				array_set_path($wancfg, 'adv_dhcp_request_options', $_POST['adv_dhcp_request_options']);
1372
				array_set_path($wancfg, 'adv_dhcp_required_options', $_POST['adv_dhcp_required_options']);
1373
				array_set_path($wancfg, 'adv_dhcp_option_modifiers', $_POST['adv_dhcp_option_modifiers']);
1374

    
1375
				array_set_path($wancfg, 'adv_dhcp_config_advanced', $_POST['adv_dhcp_config_advanced']);
1376
				array_set_path($wancfg, 'adv_dhcp_config_file_override', $_POST['adv_dhcp_config_file_override']);
1377
				array_set_path($wancfg, 'adv_dhcp_config_file_override_path', $_POST['adv_dhcp_config_file_override_path']);
1378

    
1379
				array_set_path($wancfg, 'dhcp_plus', (($_POST['dhcp_plus'] == "yes") ? true : false));
1380

    
1381
				if ($gateway_item) {
1382
					$a_gateways[] = $gateway_item;
1383
				}
1384
				if ($_POST['dhcpvlanenable'] == "yes") {
1385
					array_set_path($wancfg, 'dhcpvlanenable', true);
1386
				}
1387
				if (!empty($_POST['dhcpcvpt'])) {
1388
					array_set_path($wancfg, 'dhcpcvpt', $_POST['dhcpcvpt']);
1389
				} else {
1390
					array_del_path($wancfg, 'dhcpcvpt');
1391
				}
1392
				break;
1393
			case "ppp":
1394
				array_set_path($a_ppps, "{$pppid}/ptpid", $_POST['ptpid']);
1395
				array_set_path($a_ppps, "{$pppid}/type", $_POST['type']);
1396
				array_set_path($a_ppps, "{$pppid}/if", $_POST['type'] . $_POST['ptpid']);
1397
				array_set_path($a_ppps, "{$pppid}/ports", $_POST['port']);
1398
				array_set_path($a_ppps, "{$pppid}/username", $_POST['ppp_username']);
1399
				if ($_POST['ppp_password'] != DMYPWD) {
1400
					array_set_path($a_ppps, "{$pppid}/password", base64_encode($_POST['ppp_password']));
1401
				}
1402
				array_set_path($a_ppps, "{$pppid}/phone", $_POST['phone']);
1403
				array_set_path($a_ppps, "{$pppid}/apn", $_POST['apn']);
1404

    
1405
				array_set_path($wancfg, 'if', $_POST['type'] . $_POST['ptpid']);
1406
				array_set_path($wancfg, 'ipaddr', $_POST['type']);
1407
				break;
1408
			case "pppoe":
1409
				array_set_path($a_ppps, "{$pppid}/ptpid", $_POST['ptpid']);
1410
				array_set_path($a_ppps, "{$pppid}/type", $_POST['type']);
1411
				array_set_path($a_ppps, "{$pppid}/if", $_POST['type'] . $_POST['ptpid']);
1412
				if (isset($_POST['ppp_port'])) {
1413
					array_set_path($a_ppps, "{$pppid}/ports", $_POST['ppp_port']);
1414
				} else {
1415
					array_set_path($a_ppps, "{$pppid}/ports", array_get_path($wancfg, 'if'));
1416
				}
1417
				array_set_path($a_ppps, "{$pppid}/username", $_POST['pppoe_username']);
1418
				if ($_POST['pppoe_password'] != DMYPWD) {
1419
					array_set_path($a_ppps, "{$pppid}/password", base64_encode($_POST['pppoe_password']));
1420
				}
1421
				if (!empty($_POST['provider'])) {
1422
					array_set_path($a_ppps, "{$pppid}/provider", $_POST['provider']);
1423
				} else {
1424
					array_set_path($a_ppps, "{$pppid}/provider", true);
1425
				}
1426
				if (!empty($_POST['hostuniq'])) {
1427
					array_set_path($a_ppps, "{$pppid}/hostuniq", strtolower($_POST['hostuniq']));
1428
				} else {
1429
					array_set_path($a_ppps, "{$pppid}/hostuniq", true);
1430
				}
1431
				array_set_path($a_ppps, "{$pppid}/ondemand", ($_POST['pppoe_dialondemand'] ? true : false));
1432

    
1433
				if (!empty($_POST['pppoe_idletimeout'])) {
1434
					array_set_path($a_ppps, "{$pppid}/idletimeout", $_POST['pppoe_idletimeout']);
1435
				} else {
1436
					array_del_path($a_ppps, "{$pppid}/idletimeout");
1437
				}
1438

    
1439
				if (!empty($_POST['pppoe-reset-type'])) {
1440
					array_set_path($a_ppps, "{$pppid}/pppoe-reset-type", $_POST['pppoe-reset-type']);
1441
				} else {
1442
					array_del_path($a_ppps, "{$pppid}/pppoe-reset-type");
1443
				}
1444

    
1445
				array_set_path($wancfg, 'if', $_POST['type'] . $_POST['ptpid']);
1446
				array_set_path($wancfg, 'ipaddr', $_POST['type']);
1447
				if ($gateway_item) {
1448
					$a_gateways[] = $gateway_item;
1449
				}
1450

    
1451
				break;
1452
			case "pptp":
1453
			case "l2tp":
1454
				array_set_path($a_ppps, "{$pppid}/ptpid", $_POST['ptpid']);
1455
				array_set_path($a_ppps, "{$pppid}/type", $_POST['type']);
1456
				array_set_path($a_ppps, "{$pppid}/if", $_POST['type'] . $_POST['ptpid']);
1457
				if (isset($_POST['ppp_port'])) {
1458
					array_set_path($a_ppps, "{$pppid}/ports", $_POST['ppp_port']);
1459
				} else {
1460
					array_set_path($a_ppps, "{$pppid}/ports", array_get_path($wancfg, 'if'));
1461
				}
1462
				array_set_path($a_ppps, "{$pppid}/username", $_POST['pptp_username']);
1463
				if ($_POST['pptp_password'] != DMYPWD) {
1464
					array_set_path($a_ppps, "{$pppid}/password", base64_encode($_POST['pptp_password']));
1465
				}
1466
				if (($_POST['type'] == 'l2tp') &&
1467
				    !empty($_POST['l2tp_secret'])) {
1468
					array_set_path($a_ppps, "{$pppid}/secret", base64_encode($_POST['l2tp_secret']));
1469
				} else {
1470
					array_del_path($a_ppps, "{$pppid}/secret");
1471
				}
1472
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1473
				array_set_path($poriginal, 'pptp_localip/0', $_POST['pptp_local0']);
1474
				array_set_path($a_ppps, "{$pppid}/localip", implode(',', array_get_path($poriginal, 'pptp_localip')));
1475
				array_set_path($poriginal, 'pptp_subnet/0', $_POST['pptp_subnet0']);
1476
				array_set_path($a_ppps, "{$pppid}/subnet", implode(',', array_get_path($poriginal, 'pptp_subnet')));
1477
				array_set_path($poriginal, 'pptp_remote/0', $_POST['pptp_remote0']);
1478
				array_set_path($a_ppps, "{$pppid}/gateway", implode(',', array_get_path($poriginal, 'pptp_remote')));
1479
				array_set_path($a_ppps, "{$pppid}/ondemand", ($_POST['pptp_dialondemand'] ? true : false));
1480
				if (!empty($_POST['pptp_idletimeout'])) {
1481
					array_set_path($a_ppps, "{$pppid}/idletimeout", $_POST['pptp_idletimeout']);
1482
				} else {
1483
					array_del_path($a_ppps, "{$pppid}/idletimeout");
1484
				}
1485
				array_set_path($wancfg, 'if', $_POST['type'] . $_POST['ptpid']);
1486
				array_set_path($wancfg, 'ipaddr', $_POST['type']);
1487
				if ($gateway_item) {
1488
					$a_gateways[] = $gateway_item;
1489
				}
1490
				break;
1491
			case "none":
1492
				break;
1493
		}
1494
		switch ($_POST['type6']) {
1495
			case "staticv6":
1496
				array_set_path($wancfg, 'ipaddrv6', $_POST['ipaddrv6']);
1497
				array_set_path($wancfg, 'subnetv6', $_POST['subnetv6']);
1498
				if ($_POST['ipv6usev4iface'] == "yes") {
1499
					array_set_path($wancfg, 'ipv6usev4iface', true);
1500
				}
1501
				if ($_POST['gatewayv6'] != "none") {
1502
					array_set_path($wancfg, 'gatewayv6', $_POST['gatewayv6']);
1503
				}
1504
				break;
1505
			case "slaac":
1506
				array_set_path($wancfg, 'ipaddrv6', 'slaac');
1507
				if ($_POST['slaacusev4iface'] == "yes") {
1508
					array_set_path($wancfg, 'slaacusev4iface', true);
1509
				}
1510
				break;
1511
			case "dhcp6":
1512
				array_set_path($wancfg, 'ipaddrv6', 'dhcp6');
1513
				array_set_path($wancfg, 'dhcp6-duid', $_POST['dhcp6-duid']);
1514
				array_set_path($wancfg, 'dhcp6-ia-pd-len', $_POST['dhcp6-ia-pd-len']);
1515
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1516
					array_set_path($wancfg, 'dhcp6-ia-pd-send-hint', true);
1517
				}
1518
				if ($_POST['dhcp6prefixonly'] == "yes") {
1519
					array_set_path($wancfg, 'dhcp6prefixonly', true);
1520
				}
1521
				if ($_POST['dhcp6usev4iface'] == "yes") {
1522
					array_set_path($wancfg, 'dhcp6usev4iface', true);
1523
				}
1524
				if ($_POST['dhcp6withoutra'] == "yes") {
1525
					array_set_path($wancfg, 'dhcp6withoutra', true);
1526
				}
1527
				if ($_POST['dhcp6vlanenable'] == "yes") {
1528
					array_set_path($wancfg, 'dhcp6vlanenable', true);
1529
				}
1530
				if (!empty($_POST['dhcp6cvpt'])) {
1531
					array_set_path($wancfg, 'dhcp6cvpt', $_POST['dhcp6cvpt']);
1532
				} else {
1533
					array_del_path($wancfg, 'dhcp6cvpt');
1534
				}
1535

    
1536
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1537
					array_set_path($wancfg, 'adv_dhcp6_interface_statement_send_options', $_POST['adv_dhcp6_interface_statement_send_options']);
1538
				}
1539
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1540
					array_set_path($wancfg, 'adv_dhcp6_interface_statement_request_options', $_POST['adv_dhcp6_interface_statement_request_options']);
1541
				}
1542
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1543
					array_set_path($wancfg, 'adv_dhcp6_interface_statement_information_only_enable', $_POST['adv_dhcp6_interface_statement_information_only_enable']);
1544
				}
1545
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1546
					array_set_path($wancfg, 'adv_dhcp6_interface_statement_script', $_POST['adv_dhcp6_interface_statement_script']);
1547
				}
1548

    
1549
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1550
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_address_enable', $_POST['adv_dhcp6_id_assoc_statement_address_enable']);
1551
				}
1552
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1553
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_address', $_POST['adv_dhcp6_id_assoc_statement_address']);
1554
				}
1555
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1556
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_address_id', $_POST['adv_dhcp6_id_assoc_statement_address_id']);
1557
				}
1558
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1559
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_address_pltime', $_POST['adv_dhcp6_id_assoc_statement_address_pltime']);
1560
				}
1561
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1562
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_address_vltime', $_POST['adv_dhcp6_id_assoc_statement_address_vltime']);
1563
				}
1564

    
1565
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1566
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_prefix_enable', $_POST['adv_dhcp6_id_assoc_statement_prefix_enable']);
1567
				}
1568
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1569
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_prefix', $_POST['adv_dhcp6_id_assoc_statement_prefix']);
1570
				}
1571
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1572
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_prefix_id', $_POST['adv_dhcp6_id_assoc_statement_prefix_id']);
1573
				}
1574
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1575
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_prefix_pltime', $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1576
				}
1577
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1578
					array_set_path($wancfg, 'adv_dhcp6_id_assoc_statement_prefix_vltime', $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1579
				}
1580

    
1581
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1582
					array_set_path($wancfg, 'adv_dhcp6_prefix_interface_statement_sla_id', $_POST['adv_dhcp6_prefix_interface_statement_sla_id']);
1583
				}
1584
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1585
					array_set_path($wancfg, 'adv_dhcp6_prefix_interface_statement_sla_len', $_POST['adv_dhcp6_prefix_interface_statement_sla_len']);
1586
				}
1587
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1588
					array_set_path($wancfg, 'adv_dhcp6_prefix_selected_interface', $_POST['adv_dhcp6_prefix_selected_interface']);
1589
				}
1590
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1591
					array_set_path($wancfg, 'adv_dhcp6_authentication_statement_authname', $_POST['adv_dhcp6_authentication_statement_authname']);
1592
				}
1593
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1594
					array_set_path($wancfg, 'adv_dhcp6_authentication_statement_protocol', $_POST['adv_dhcp6_authentication_statement_protocol']);
1595
				}
1596
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1597
					array_set_path($wancfg, 'adv_dhcp6_authentication_statement_algorithm', $_POST['adv_dhcp6_authentication_statement_algorithm']);
1598
				}
1599
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1600
					array_set_path($wancfg, 'adv_dhcp6_authentication_statement_rdm', $_POST['adv_dhcp6_authentication_statement_rdm']);
1601
				}
1602

    
1603
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1604
					array_set_path($wancfg, 'adv_dhcp6_key_info_statement_keyname', $_POST['adv_dhcp6_key_info_statement_keyname']);
1605
				}
1606
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1607
					array_set_path($wancfg, 'adv_dhcp6_key_info_statement_realm', $_POST['adv_dhcp6_key_info_statement_realm']);
1608
				}
1609
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1610
					array_set_path($wancfg, 'adv_dhcp6_key_info_statement_keyid', $_POST['adv_dhcp6_key_info_statement_keyid']);
1611
				}
1612
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1613
					array_set_path($wancfg, 'adv_dhcp6_key_info_statement_secret', $_POST['adv_dhcp6_key_info_statement_secret']);
1614
				}
1615
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1616
					array_set_path($wancfg, 'adv_dhcp6_key_info_statement_expire', $_POST['adv_dhcp6_key_info_statement_expire']);
1617
				}
1618

    
1619
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1620
					array_set_path($wancfg, 'adv_dhcp6_config_advanced', $_POST['adv_dhcp6_config_advanced']);
1621
				}
1622
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1623
					array_set_path($wancfg, 'adv_dhcp6_config_file_override', $_POST['adv_dhcp6_config_file_override']);
1624
				}
1625
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1626
					array_set_path($wancfg, 'adv_dhcp6_config_file_override_path', $_POST['adv_dhcp6_config_file_override_path']);
1627
				}
1628

    
1629
				if ($gateway_item) {
1630
					$a_gateways[] = $gateway_item;
1631
				}
1632
				break;
1633
			case "6rd":
1634
				array_set_path($wancfg, 'ipaddrv6', '6rd');
1635
				array_set_path($wancfg, 'prefix-6rd', $_POST['prefix-6rd']);
1636
				array_set_path($wancfg, 'prefix-6rd-v4plen', $_POST['prefix-6rd-v4plen']);
1637
				array_set_path($wancfg, 'gateway-6rd', $_POST['gateway-6rd']);
1638
				if ($gateway_item) {
1639
					$a_gateways[] = $gateway_item;
1640
				}
1641
				break;
1642
			case "6to4":
1643
				array_set_path($wancfg, 'ipaddrv6', '6to4');
1644
				break;
1645
			case "track6":
1646
				array_set_path($wancfg, 'ipaddrv6', 'track6');
1647
				array_set_path($wancfg, 'track6-interface', $_POST['track6-interface']);
1648
				if ($_POST['track6-prefix-id--hex'] === "") {
1649
					array_set_path($wancfg, 'track6-prefix-id', 0);
1650
				} elseif (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1651
					array_set_path($wancfg, 'track6-prefix-id', intval($_POST['track6-prefix-id--hex'], 16));
1652
				} else {
1653
					array_set_path($wancfg, 'track6-prefix-id', 0);
1654
				}
1655
				break;
1656
			case "none":
1657
				break;
1658
		}
1659
		handle_pppoe_reset($_POST);
1660

    
1661
		if ($_POST['blockpriv'] == "yes") {
1662
			array_set_path($wancfg, 'blockpriv', true);
1663
		} else {
1664
			array_del_path($wancfg, 'blockpriv');
1665
		}
1666
		if ($_POST['blockbogons'] == "yes") {
1667
			array_set_path($wancfg, 'blockbogons', true);
1668
		} else {
1669
			array_del_path($wancfg, 'blockbogons');
1670
		}
1671
		array_set_path($wancfg, 'spoofmac', $_POST['spoofmac']);
1672
		/* Only update MTU in the config if the if is not a member of a
1673
		 * bridge. The display will show the bridge MTU in a disabled input
1674
		 * field, and we will maintain the user configured MTU for initial
1675
		 * configuration and in the event that the interface is removed from the
1676
		 * bridge it will return to its original MTU. */
1677
		if (!$bridged) {
1678
			if (empty($_POST['mtu'])) {
1679
				array_del_path($wancfg, 'mtu');
1680
			} else {
1681
				array_set_path($wancfg, 'mtu', $_POST['mtu']);
1682
			}
1683
		}
1684
		if (empty($_POST['mss'])) {
1685
			array_del_path($wancfg, 'mss');
1686
		} else {
1687
			array_set_path($wancfg, 'mss', $_POST['mss']);
1688
		}
1689
		if (empty($_POST['mediaopt'])) {
1690
			array_del_path($wancfg, 'media');
1691
			array_del_path($wancfg, 'mediaopt');
1692
		} else {
1693
			$mediaopts = explode(' ', $_POST['mediaopt']);
1694
			if ($mediaopts[0] != '') {
1695
				array_set_path($wancfg, 'media', $mediaopts[0]);
1696
			}
1697
			if ($mediaopts[1] != '') {
1698
				array_set_path($wancfg, 'mediaopt', $mediaopts[1]);
1699
			} else {
1700
				array_del_path($wancfg, 'mediaopt');
1701
			}
1702
		}
1703
		if (!empty(array_get_path($wancfg, 'wireless'))) {
1704
			handle_wireless_post();
1705
		}
1706

    
1707
		config_set_path('ppps/ppp', $a_ppps);
1708
		config_set_path('gateways/gateway_item', $a_gateways);
1709
		config_set_path("interfaces/{$if}", $wancfg);
1710
		write_config("Interfaces settings changed");
1711

    
1712
		if ($_POST['gatewayip4']) {
1713
			save_gateway($gateway_settings4);
1714
		}
1715

    
1716
		if ($_POST['gatewayip6']) {
1717
			save_gateway($gateway_settings6);
1718
		}
1719

    
1720
		if (file_exists(g_get('tmp_path') . '/.interfaces.apply')) {
1721
			$toapplylist = unserialize(file_get_contents(g_get('tmp_path') . '/.interfaces.apply'));
1722
		} else {
1723
			$toapplylist = [];
1724
		}
1725
		array_set_path($toapplylist, "{$if}/ifcfg", $old_wancfg);
1726
		array_set_path($toapplylist, "{$if}/ppps", $old_ppps);
1727
		file_put_contents(g_get('tmp_path') . '/.interfaces.apply', serialize($toapplylist));
1728

    
1729
		mark_subsystem_dirty('interfaces');
1730

    
1731
		/* regenerate cron settings/crontab file */
1732
		configure_cron();
1733

    
1734
		header("Location: interfaces.php?if={$if}");
1735
		exit;
1736
	}
1737

    
1738
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1739
	if (!empty($_POST['ppp_port'])) {
1740
		array_set_path($pconfig, 'port', $_POST['ppp_port']);
1741
	}
1742

    
1743
} // end if ($_POST['save'])
1744

    
1745
function handle_wireless_post() {
1746
	global $_POST, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1747

    
1748
	array_set_path($wancfg, 'wireless/standard', $_POST['standard']);
1749
	array_set_path($wancfg, 'wireless/mode', $_POST['mode']);
1750
	array_set_path($wancfg, 'wireless/protmode', $_POST['protmode']);
1751
	array_set_path($wancfg, 'wireless/ssid', $_POST['ssid']);
1752
	array_set_path($wancfg, 'wireless/channel', $_POST['channel']);
1753
	array_set_path($wancfg, 'wireless/channel_width', $_POST['channel_width']);
1754
	array_set_path($wancfg, 'wireless/authmode', $_POST['authmode']);
1755
	array_set_path($wancfg, 'wireless/txpower', $_POST['txpower']);
1756
	array_set_path($wancfg, 'wireless/distance', $_POST['distance']);
1757
	array_set_path($wancfg, 'wireless/regdomain', $_POST['regdomain']);
1758
	array_set_path($wancfg, 'wireless/regcountry', $_POST['regcountry']);
1759
	array_set_path($wancfg, 'wireless/reglocation', $_POST['reglocation']);
1760

    
1761
	if (!empty(array_get_path($wancfg, 'wireless/regdomain')) &&
1762
	    !empty(array_get_path($wancfg, 'wireless/regcountry'))) {
1763
		foreach ($wl_countries_attr as $wl_country) {
1764
			if (array_get_path($wancfg, 'wireless/regcountry') == array_get_path($wl_country, 'ID')) {
1765
				array_set_path($wancfg, 'wireless/regdomain', array_get_path($wl_country, 'rd/0/REF'));
1766
				break;
1767
			}
1768
		}
1769
	}
1770

    
1771
	array_set_path($wancfg, 'wireless/wpa/macaddr_acl', $_POST['macaddr_acl']);
1772
	array_set_path($wancfg, 'wireless/wpa/wpa_mode', $_POST['wpa_mode']);
1773
	array_set_path($wancfg, 'wireless/wpa/wpa_key_mgmt', $_POST['wpa_key_mgmt']);
1774
	array_set_path($wancfg, 'wireless/wpa/wpa_pairwise', $_POST['wpa_pairwise']);
1775
	array_set_path($wancfg, 'wireless/wpa/wpa_group_rekey', $_POST['wpa_group_rekey']);
1776
	array_set_path($wancfg, 'wireless/wpa/wpa_gmk_rekey', $_POST['wpa_gmk_rekey']);
1777
	array_set_path($wancfg, 'wireless/wpa/passphrase', $_POST['passphrase']);
1778
	array_set_path($wancfg, 'wireless/wpa/ext_wpa_sw', $_POST['ext_wpa_sw']);
1779
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_client_mode', $_POST['wpa_eap_client_mode']);
1780
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_inner_auth', $_POST['wpa_eap_inner_auth']);
1781
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_inner_id', $_POST['wpa_eap_inner_id']);
1782
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_inner_password', base64_encode($_POST['wpa_eap_inner_password']));
1783
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_cert', $_POST['wpa_eap_cert']);
1784
	array_set_path($wancfg, 'wireless/wpa/wpa_eap_ca', $_POST['wpa_eap_ca']);
1785
	array_set_path($wancfg, 'wireless/wpa/auth_server_addr', $_POST['auth_server_addr']);
1786
	array_set_path($wancfg, 'wireless/wpa/auth_server_port', $_POST['auth_server_port']);
1787
	array_set_path($wancfg, 'wireless/wpa/auth_server_shared_secret', $_POST['auth_server_shared_secret']);
1788
	array_set_path($wancfg, 'wireless/wpa/auth_server_addr2', $_POST['auth_server_addr2']);
1789
	array_set_path($wancfg, 'wireless/wpa/auth_server_port2', $_POST['auth_server_port2']);
1790
	array_set_path($wancfg, 'wireless/wpa/auth_server_shared_secret2', $_POST['auth_server_shared_secret2']);
1791

    
1792
	if ($_POST['persistcommonwireless'] == "yes") {
1793
		config_set_path("wireless/interfaces/{$wlanbaseif}", []);
1794
	} elseif (config_path_enabled('wireless/interfaces', $wlanbaseif)) {
1795
		config_del_path("wireless/interfaces/{$wlanbaseif}");
1796
	}
1797
	if (isset($_POST['diversity']) &&
1798
	    is_numeric($_POST['diversity'])) {
1799
		array_set_path($wancfg, 'wireless/diversity', $_POST['diversity']);
1800
	} elseif (array_path_enabled($wancfg, 'wireless', 'diversity')) {
1801
		array_del_path($wancfg, 'wireless/diversity');
1802
	}
1803
	if (isset($_POST['txantenna']) &&
1804
	    is_numeric($_POST['txantenna'])) {
1805
		array_set_path($wancfg, 'wireless/txantenna', $_POST['txantenna']);
1806
	} elseif (array_path_enabled($wancfg, 'wireless', 'txantenna')) {
1807
		array_del_path($wancfg, 'wireless/txantenna');
1808
	}
1809
	if (isset($_POST['rxantenna']) &&
1810
	    is_numeric($_POST['rxantenna'])) {
1811
		array_set_path($wancfg, 'wireless/rxantenna', $_POST['rxantenna']);
1812
	} elseif (array_path_enabled($wancfg, 'wireless', 'rxantenna')) {
1813
		array_del_path($wancfg, 'wireless/rxantenna');
1814
	}
1815
	if ($_POST['hidessid_enable'] == "yes") {
1816
		array_set_path($wancfg, 'wireless/hidessid/enable', true);
1817
	} elseif (array_path_enabled($wancfg, 'wireless/hidessid')) {
1818
		array_del_path($wancfg, 'wireless/hidessid/enable');
1819
	}
1820
	if ($_POST['mac_acl_enable'] == "yes") {
1821
		array_set_path($wancfg, 'wireless/wpa/mac_acl_enable', true);
1822
	} elseif (array_path_enabled($wancfg, 'wireless/wpa', 'mac_acl_enable')) {
1823
		array_del_path($wancfg, 'wireless/wpa/mac_acl_enable');
1824
	}
1825
	if ($_POST['rsn_preauth'] == "yes") {
1826
		array_set_path($wancfg, 'wireless/wpa/rsn_preauth', true);
1827
	} else {
1828
		array_del_path($wancfg, 'wireless/wpa/rsn_preauth');
1829
	}
1830
	if ($_POST['ieee8021x'] == "yes") {
1831
		array_set_path($wancfg, 'wireless/wpa/ieee8021x/enable', true);
1832
	} elseif (array_path_enabled($wancfg, 'wireless/wpa/ieee8021x')) {
1833
		array_del_path($wancfg, 'wireless/wpa/ieee8021x/enable');
1834
	}
1835
	if ($_POST['wpa_strict_rekey'] == "yes") {
1836
		array_set_path($wancfg, 'wireless/wpa/wpa_strict_rekey', true);
1837
	} elseif (array_path_enabled($wancfg, 'wireless/wpa', 'wpa_strict_rekey')) {
1838
		array_del_path($wancfg, 'wireless/wpa/wpa_strict_rekey');
1839
	}
1840
	if ($_POST['debug_mode'] == "yes") {
1841
		array_set_path($wancfg, 'wireless/wpa/debug_mode', true);
1842
	} elseif (array_path_enabled($wancfg, 'wireless/wpa', 'debug_mode')) {
1843
		array_del_path($wancfg, 'wireless/wpa/debug_mode');
1844
	}
1845
	if ($_POST['wpa_enable'] == "yes") {
1846
		$_POST['wpa_enable'] = true;
1847
		array_set_path($wancfg, 'wireless/wpa/enable', true);
1848
	} elseif (array_path_enabled($wancfg, 'wireless/wpa')) {
1849
		array_del_path($wancfg, 'wireless/wpa/enable');
1850
	}
1851

    
1852
	if ($_POST['wme_enable'] == "yes") {
1853
		$_POST['wme_enable'] = true;
1854
		array_set_path($wancfg, 'wireless/wme/enable', true);
1855
	} elseif (array_path_enabled($wancfg, 'wireless/wme')) {
1856
		array_del_path($wancfg, 'wireless/wme/enable');
1857
	}
1858
	if ($_POST['puremode'] == "11g") {
1859
		array_set_path($wancfg, 'wireless/pureg/enable', true);
1860
	} elseif ($_POST['puremode'] == "11n") {
1861
		array_set_path($wancfg, 'wireless/puren/enable', true);
1862
	} else {
1863
		array_del_path($wancfg, 'wireless/pureg');
1864
		array_del_path($wancfg, 'wireless/puren');
1865
	}
1866
	if ($_POST['apbridge_enable'] == "yes") {
1867
		$_POST['apbridge_enable'] = true;
1868
		array_set_path($wancfg, 'wireless/apbridge/enable', true);
1869
	} elseif (array_path_enabled($wancfg, 'wireless/apbridge')) {
1870
		array_del_path($wancfg, 'wireless/apbridge/enable');
1871
	}
1872
	if (($_POST['standard'] == "11g Turbo") ||
1873
	    ($_POST['standard'] == "11a Turbo")) {
1874
		array_set_path($wancfg, 'wireless/turbo/enable', true);
1875
	} elseif (array_path_enabled($wancfg, 'wireless/turbo')) {
1876
		array_del_path($wancfg, 'wireless/turbo/enable');
1877
	}
1878

    
1879
	interface_sync_wireless_clones($wancfg, true);
1880
}
1881

    
1882
function check_wireless_mode() {
1883
	global $_POST, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1884

    
1885
	if (array_get_path($wancfg, 'wireless/mode') == $_POST['mode']) {
1886
		return;
1887
	}
1888

    
1889
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1890
		$clone_count = 1;
1891
	} else {
1892
		$clone_count = 0;
1893
	}
1894

    
1895
	foreach (config_get_path('wireless/clone', []) as $clone) {
1896
		if (array_get_path($clone, 'if') == $wlanbaseif) {
1897
				$clone_count++;
1898
		}
1899
	}
1900

    
1901
	if ($clone_count > 1) {
1902
		$old_wireless_mode = array_get_path($wancfg, 'wireless/mode');
1903
		array_set_path($wancfg, 'wireless/mode', $_POST['mode']);
1904
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1905
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."),
1906
					array_get_path($wlan_modes, array_get_path($wancfg, 'wireless/mode')));
1907
		} else {
1908
			pfSense_interface_destroy("{$wlanif}_");
1909
		}
1910
		array_set_path($wancfg, 'wireless/mode', $old_wireless_mode);
1911
	}
1912
}
1913

    
1914
// Find all possible media options for the interface
1915
$mediaopts_list = [];
1916
$intrealname = config_get_path("interfaces/{$if}/if");
1917
exec("/sbin/ifconfig -m " . escapeshellarg($intrealname) . " | /usr/bin/grep \"media \"", $mediaopts);
1918
foreach ($mediaopts as $mediaopt) {
1919
	preg_match("/media (.*)/", $mediaopt, $matches);
1920
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1921
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1922
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1923
	} else {
1924
		// there is only media like "media 1000baseT"
1925
		array_push($mediaopts_list, $matches[1]);
1926
	}
1927
}
1928

    
1929
$pgtitle = [gettext("Interfaces"), array_get_path($wancfg, 'descr') . " ({$realifname})"];
1930
$shortcut_section = "interfaces";
1931

    
1932
$types4 = ["ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP")];
1933

    
1934
if (!in_array(array_get_path($pconfig, 'type'), ["ppp", "pppoe", "pptp", "l2tp"]) ||
1935
    !array_intersect_key(explode(",", array_get_path($a_ppps, "{$pppid}/ports", "")), get_configured_interface_list_by_realif())) {
1936
	$types4 = array_merge(["none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")], $types4);
1937
}
1938

    
1939
$types6 = ["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")];
1940

    
1941
// Get the MAC address
1942
$defgatewayname4 = array_get_path($wancfg, 'descr') . "GW";
1943
$defgatewayname6 = array_get_path($wancfg, 'descr') . "GWv6";
1944

    
1945
function build_mediaopts_list() {
1946
	global $mediaopts_list;
1947

    
1948
	$list = [
1949
		"" => gettext("Default (no preference, typically autoselect)"),
1950
		" " => gettext("------- Media Supported by this interface -------")
1951
		];
1952

    
1953
	foreach ($mediaopts_list as $mediaopt) {
1954
		/* Output may include a '/' so we can't use array_set_path() */
1955
		$list[$mediaopt] = $mediaopt;
1956
	}
1957

    
1958
	return($list);
1959
}
1960

    
1961
function build_gateway_list() {
1962
	global $a_gateways, $if;
1963

    
1964
	$list = ["none" => gettext("None")];
1965
	foreach ($a_gateways as $gateway) {
1966
		if ((array_get_path($gateway, 'interface') == $if) &&
1967
		    is_ipaddrv4(array_get_path($gateway, 'gateway'))) {
1968
			array_set_path($list,
1969
				array_get_path($gateway, 'name'),
1970
				array_get_path($gateway, 'name') . " - " . array_get_path($gateway, 'gateway'));
1971
		}
1972
	}
1973

    
1974
	return($list);
1975
}
1976

    
1977
function build_gatewayv6_list() {
1978
	global $a_gateways, $if;
1979

    
1980
	$list = ["none" => gettext("None")];
1981
	foreach ($a_gateways as $gateway) {
1982
		if ((array_get_path($gateway, 'interface') == $if) &&
1983
		    is_ipaddrv6(array_get_path($gateway, 'gateway'))) {
1984
			array_set_path($list,
1985
				array_get_path($gateway, 'name'),
1986
				array_get_path($gateway, 'name') . " - " . array_get_path($gateway, 'gateway'));
1987
		}
1988
	}
1989

    
1990
	return($list);
1991
}
1992

    
1993
include("head.inc");
1994

    
1995
if ($input_errors) {
1996
	print_input_errors($input_errors);
1997
}
1998

    
1999
if (is_subsystem_dirty('interfaces')) {
2000
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), array_get_path($wancfg, 'descr')) . "<br />" .
2001
					gettext("The changes must be applied to take effect.") . "<br />" .
2002
					gettext("Don't forget to adjust the DHCP Server range if needed after applying."));
2003
}
2004

    
2005
if ($changes_applied) {
2006
	print_apply_result_box($retval);
2007
}
2008

    
2009
$form = new Form();
2010

    
2011
$section = new Form_Section('General Configuration');
2012

    
2013
$section->addInput(new Form_Checkbox(
2014
	'enable',
2015
	'Enable',
2016
	'Enable interface',
2017
	array_get_path($pconfig, 'enable'),
2018
	'yes'
2019
));
2020

    
2021
$section->addInput(new Form_Input(
2022
	'descr',
2023
	'*Description',
2024
	'text',
2025
	array_get_path($pconfig, 'descr'),
2026
))->setHelp('Enter a description (name) for the interface here.');
2027

    
2028
if ($show_address_controls) {
2029
	$section->addInput(new Form_Select(
2030
		'type',
2031
		'IPv4 Configuration Type',
2032
		array_get_path($pconfig, 'type'),
2033
		$types4
2034
	));
2035
	$section->addInput(new Form_Select(
2036
		'type6',
2037
		'IPv6 Configuration Type',
2038
		array_get_path($pconfig, 'type6'),
2039
		$types6
2040
	));
2041
} else {
2042
	$section->addInput(new Form_StaticText(
2043
		'IPv4/IPv6 Configuration',
2044
		"This interface type does not support manual address configuration on this page. "
2045
	));
2046
	$form->addGlobal(new Form_Input(
2047
		'type',
2048
		null,
2049
		'hidden',
2050
		'none'
2051
	));
2052
	$form->addGlobal(new Form_Input(
2053
		'type6',
2054
		null,
2055
		'hidden',
2056
		'none'
2057
	));
2058
}
2059

    
2060
if (!is_pseudo_interface($intrealname, true)) {
2061
	$macaddress = new Form_Input(
2062
		'spoofmac',
2063
		'MAC Address',
2064
		'text',
2065
		array_get_path($pconfig, 'spoofmac'),
2066
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
2067
	);
2068

    
2069
	if (interface_is_vlan($realifname)) {
2070
		$macaddress->setDisabled();
2071
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
2072
		    'set on its parent interface');
2073
	} else {
2074
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
2075
		    'MAC address of this interface.%sEnter a MAC address in the ' .
2076
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
2077
	}
2078

    
2079
	$section->addInput($macaddress);
2080
}
2081

    
2082
$mtuInput = $section->addInput(new Form_Input(
2083
	'mtu',
2084
	'MTU',
2085
	'number',
2086
	array_get_path($pconfig, 'mtu'),
2087
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2088
			'This is typically 1500 bytes but can vary in some circumstances.');
2089
/* Do not allow MTU changes for interfaces in a bridge */
2090
if ($bridged) {
2091
	$mtuInput->setDisabled();
2092
	$mtuInput->setHelp('This interface is a bridge member, its MTU is ' .
2093
					   'controlled by its parent bridge interface');
2094
	$mtuInput->setPlaceholder(get_interface_mtu($bridged));
2095
	$mtuInput->setValue(null);
2096
}
2097

    
2098
$section->addInput(new Form_Input(
2099
	'mss',
2100
	'MSS',
2101
	'number',
2102
	array_get_path($pconfig, 'mss'),
2103
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2104
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2105

    
2106
if (count($mediaopts_list) > 0) {
2107
	$section->addInput(new Form_Select(
2108
		'mediaopt',
2109
		'Speed and Duplex',
2110
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt")),
2111
		build_mediaopts_list()
2112
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2113
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2114
}
2115

    
2116
$form->add($section);
2117

    
2118
$section = new Form_Section('Static IPv4 Configuration');
2119
$section->addClass('staticv4');
2120

    
2121
$section->addInput(new Form_IpAddress(
2122
	'ipaddr',
2123
	'*IPv4 Address',
2124
	array_get_path($pconfig, 'ipaddr'),
2125
	'V4'
2126
))->addMask('subnet', array_get_path($pconfig, 'subnet'), 32);
2127

    
2128
$group = new Form_Group('IPv4 Upstream gateway');
2129

    
2130
$group->add(new Form_Select(
2131
	'gateway',
2132
	'IPv4 Upstream Gateway',
2133
	array_get_path($pconfig, 'gateway'),
2134
	build_gateway_list()
2135
));
2136

    
2137
$group->add(new Form_Button(
2138
	'addgw4',
2139
	'Add a new gateway',
2140
	null,
2141
	'fa-solid fa-plus'
2142
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2143

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

    
2149
$section->add($group);
2150

    
2151
$form->add($section);
2152

    
2153
$section = new Form_Section('SLAAC IPv6 Configuration');
2154
$section->addClass('slaac');
2155

    
2156
$section->addInput(new Form_Checkbox(
2157
	'slaacusev4iface',
2158
	'Use IPv4 connectivity as parent interface',
2159
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2160
	array_get_path($pconfig, 'slaacusev4iface'),
2161
));
2162

    
2163
$form->add($section);
2164

    
2165
$section = new Form_Section('Static IPv6 Configuration');
2166
$section->addClass('staticv6');
2167

    
2168
$section->addInput(new Form_IpAddress(
2169
	'ipaddrv6',
2170
	'*IPv6 address',
2171
	array_get_path($pconfig, 'ipaddrv6'),
2172
	'V6'
2173
))->addMask('subnetv6', array_get_path($pconfig, 'subnetv6'), 128);
2174

    
2175
$section->addInput(new Form_Checkbox(
2176
	'ipv6usev4iface',
2177
	'Use IPv4 connectivity as parent interface',
2178
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2179
	array_get_path($pconfig, 'ipv6usev4iface'),
2180
));
2181

    
2182
$group = new Form_Group('IPv6 Upstream gateway');
2183

    
2184
$group->add(new Form_Select(
2185
	'gatewayv6',
2186
	'IPv6 Upstream Gateway',
2187
	array_get_path($pconfig, 'gatewayv6'),
2188
	build_gatewayv6_list()
2189
));
2190

    
2191
$group->add(new Form_Button(
2192
	'addgw6',
2193
	'Add a new gateway',
2194
	null,
2195
	'fa-solid fa-plus'
2196
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2197

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

    
2201
$section->add($group);
2202
$form->add($section);
2203

    
2204
// Add new gateway modal pop-up for IPv6
2205
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2206

    
2207
$modal->addInput(new Form_Checkbox(
2208
	'defaultgw6',
2209
	'Default',
2210
	'Default gateway',
2211
	array_set_path($gateway_settings6, 'defaultgw', (strtolower($if) == "wan")),
2212
));
2213

    
2214
$modal->addInput(new Form_Input(
2215
	'gatewayname6',
2216
	'Gateway name',
2217
	'text',
2218
	array_set_path($gateway_settings6, 'name', $defgatewayname6),
2219
));
2220

    
2221
$modal->addInput(new Form_IpAddress(
2222
	'gatewayip6',
2223
	'Gateway IPv6',
2224
	array_get_path($gateway_settings6, 'gateway'),
2225
	'V6'
2226
));
2227

    
2228
$modal->addInput(new Form_Input(
2229
	'gatewaydescr6',
2230
	'Description',
2231
	'text',
2232
	array_get_path($gateway_settings6, 'descr')
2233
));
2234

    
2235
$btnaddgw6 = new Form_Button(
2236
	'add6',
2237
	'Add',
2238
	null,
2239
	'fa-solid fa-plus'
2240
);
2241

    
2242
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2243

    
2244
$btncnxgw6 = new Form_Button(
2245
	'cnx6',
2246
	'Cancel',
2247
	null,
2248
	'fa-solid fa-undo'
2249
);
2250

    
2251
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2252

    
2253
$modal->addInput(new Form_StaticText(
2254
	null,
2255
	$btnaddgw6 . $btncnxgw6
2256
));
2257

    
2258
$form->add($modal);
2259

    
2260
// ==== DHCP client configuration =============================
2261

    
2262
$section = new Form_Section('DHCP Client Configuration');
2263
$section->addClass('dhcp');
2264

    
2265
$group = new Form_Group('Options');
2266

    
2267
$group->add(new Form_Checkbox(
2268
	'adv_dhcp_config_advanced',
2269
	null,
2270
	'Advanced Configuration',
2271
	array_get_path($pconfig, 'adv_dhcp_config_advanced'),
2272
))->setHelp('Use advanced DHCP configuration options.');
2273

    
2274
$group->add(new Form_Checkbox(
2275
	'adv_dhcp_config_file_override',
2276
	null,
2277
	'Configuration Override',
2278
	array_get_path($pconfig, 'adv_dhcp_config_file_override'),
2279
))->setHelp('Override the configuration from this file.');
2280

    
2281
$section->add($group);
2282

    
2283
$section->addInput(new Form_Input(
2284
	'dhcphostname',
2285
	'Hostname',
2286
	'text',
2287
	array_get_path($pconfig, 'dhcphostname'),
2288
))->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).');
2289

    
2290
$section->addInput(new Form_IpAddress(
2291
	'alias-address',
2292
	'Alias IPv4 address',
2293
	array_get_path($pconfig, 'alias-address'),
2294
	'V4'
2295
))->addMask('alias-subnet', array_get_path($pconfig, 'alias-subnet'), 32)->setHelp('The value in this field is used as a fixed alias IPv4 address by the DHCP client.');
2296

    
2297
$section->addInput(new Form_Input(
2298
	'dhcprejectfrom',
2299
	'Reject leases from',
2300
	'text',
2301
	array_get_path($pconfig, 'dhcprejectfrom'),
2302
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2303
			'(separate multiple entries with a comma). ' .
2304
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2305

    
2306
if (interface_is_vlan(array_get_path($wancfg, 'if')) != NULL) {
2307
	$group = new Form_Group('DHCP VLAN Priority');
2308
	$group->add(new Form_Checkbox(
2309
		'dhcpvlanenable',
2310
		null,
2311
		'Enable dhcpclient VLAN Priority tagging',
2312
		array_get_path($pconfig, 'dhcpvlanenable'),
2313
	))->setHelp('Normally off unless specifically required by the ISP.');
2314

    
2315
	$group->add(new Form_Select(
2316
		'dhcpcvpt',
2317
		'VLAN Prio',
2318
		array_get_path($pconfig, 'dhcpcvpt'),
2319
		$vlanprio
2320
	))->setHelp('Choose 802.1p priority to set.');
2321

    
2322
	$section->add($group);
2323
}
2324

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

    
2330
$group->add(new Form_Input(
2331
	'adv_dhcp_pt_timeout',
2332
	null,
2333
	'number',
2334
	array_get_path($pconfig, 'adv_dhcp_pt_timeout'),
2335
))->setHelp('Timeout');
2336

    
2337
$group->add(new Form_Input(
2338
	'adv_dhcp_pt_retry',
2339
	null,
2340
	'number',
2341
	array_get_path($pconfig, 'adv_dhcp_pt_retry'),
2342
))->setHelp('Retry');
2343

    
2344
$group->add(new Form_Input(
2345
	'adv_dhcp_pt_select_timeout',
2346
	null,
2347
	'number',
2348
	array_get_path($pconfig, 'adv_dhcp_pt_select_timeout'),
2349
	['min' => 0]
2350
))->setHelp('Select timeout');
2351

    
2352
$group->add(new Form_Input(
2353
	'adv_dhcp_pt_reboot',
2354
	null,
2355
	'number',
2356
	array_get_path($pconfig, 'adv_dhcp_pt_reboot'),
2357
))->setHelp('Reboot');
2358

    
2359
$group->add(new Form_Input(
2360
	'adv_dhcp_pt_backoff_cutoff',
2361
	null,
2362
	'number',
2363
	array_get_path($pconfig, 'adv_dhcp_pt_backoff_cutoff'),
2364
))->setHelp('Backoff cutoff');
2365

    
2366
$group->add(new Form_Input(
2367
	'adv_dhcp_pt_initial_interval',
2368
	null,
2369
	'number',
2370
	array_get_path($pconfig, 'adv_dhcp_pt_initial_interval'),
2371
))->setHelp('Initial interval');
2372

    
2373
$section->add($group);
2374

    
2375
$group = new Form_Group('Presets');
2376
$group->addClass('dhcpadvanced');
2377

    
2378
$group->add(new Form_Checkbox(
2379
	'adv_dhcp_pt_values',
2380
	null,
2381
	'FreeBSD default',
2382
	null,
2383
	'DHCP'
2384
))->displayAsRadio();
2385

    
2386
$group->add(new Form_Checkbox(
2387
	'adv_dhcp_pt_values',
2388
	null,
2389
	'Clear',
2390
	null,
2391
	'Clear'
2392
))->displayAsRadio();
2393

    
2394
$group->add(new Form_Checkbox(
2395
	'adv_dhcp_pt_values',
2396
	null,
2397
	'pfSense Default',
2398
	null,
2399
	'pfSense'
2400
))->displayAsRadio();
2401

    
2402
$group->add(new Form_Checkbox(
2403
	'adv_dhcp_pt_values',
2404
	null,
2405
	'Saved Cfg',
2406
	null,
2407
	'SavedCfg'
2408
))->displayAsRadio();
2409

    
2410
$section->add($group);
2411

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

    
2422
$form->add($section);
2423

    
2424
$section = new Form_Section('Lease Requirements and Requests');
2425
$section->addClass('dhcpadvanced');
2426

    
2427
$section->addInput(new Form_Input(
2428
	'adv_dhcp_send_options',
2429
	'Send options',
2430
	'text',
2431
	array_get_path($pconfig, 'adv_dhcp_send_options'),
2432
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2433
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2434
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2435
			'Some ISPs may require certain options be or not be sent.', '<br />');
2436

    
2437
$section->addInput(new Form_Input(
2438
	'adv_dhcp_request_options',
2439
	'Request options',
2440
	'text',
2441
	array_get_path($pconfig, 'adv_dhcp_request_options'),
2442
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2443
			'Some ISPs may require certain options be or not be requested.', '<br />');
2444

    
2445
$section->addInput(new Form_Input(
2446
	'adv_dhcp_required_options',
2447
	'Require options',
2448
	'text',
2449
	array_get_path($pconfig, 'adv_dhcp_required_options'),
2450
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2451

    
2452
$section->addInput(new Form_Input(
2453
	'adv_dhcp_option_modifiers',
2454
	'Option modifiers',
2455
	'text',
2456
	array_get_path($pconfig, 'adv_dhcp_option_modifiers'),
2457
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2458
			'modifiers: (default, supersede, prepend, append) %1$s' .
2459
			'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>');
2460

    
2461
$form->add($section);
2462

    
2463
// DHCP6 client config
2464

    
2465
$section = new Form_Section('DHCP6 Client Configuration');
2466
$section->addClass('dhcp6');
2467

    
2468
$group = new Form_Group('Options');
2469

    
2470
$group->add(new Form_Checkbox(
2471
	'adv_dhcp6_config_advanced',
2472
	null,
2473
	'Advanced Configuration',
2474
	array_get_path($pconfig, 'adv_dhcp6_config_advanced'),
2475
))->setHelp('Use advanced DHCPv6 configuration options.');
2476

    
2477
$group->add(new Form_Checkbox(
2478
	'adv_dhcp6_config_file_override',
2479
	null,
2480
	'Configuration Override',
2481
	array_get_path($pconfig, 'adv_dhcp6_config_file_override'),
2482
))->setHelp('Override the configuration from this file.');
2483

    
2484
$section->add($group);
2485

    
2486
$section->addInput(new Form_Checkbox(
2487
	'dhcp6usev4iface',
2488
	'Use IPv4 connectivity as parent interface',
2489
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2490
	array_get_path($pconfig, 'dhcp6usev4iface'),
2491
));
2492

    
2493
$section->addInput(new Form_Checkbox(
2494
	'dhcp6prefixonly',
2495
	'Request only an IPv6 prefix',
2496
	'Only request an IPv6 prefix, do not request an IPv6 address',
2497
	array_get_path($pconfig, 'dhcp6prefixonly'),
2498
));
2499

    
2500
$section->addInput(new Form_Select(
2501
	'dhcp6-ia-pd-len',
2502
	'DHCPv6 Prefix Delegation size',
2503
	array_get_path($pconfig, 'dhcp6-ia-pd-len'),
2504
	["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"]
2505
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2506

    
2507
$section->addInput(new Form_Checkbox(
2508
	'dhcp6-ia-pd-send-hint',
2509
	'Send IPv6 prefix hint',
2510
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2511
	array_get_path($pconfig, 'dhcp6-ia-pd-send-hint'),
2512
));
2513

    
2514
$section->addInput(new Form_Checkbox(
2515
	'dhcp6withoutra',
2516
	'Do not wait for a RA',
2517
	'Required by some ISPs, especially those not using PPPoE',
2518
	array_get_path($pconfig, 'dhcp6withoutra'),
2519
));
2520

    
2521
if (interface_is_vlan(array_get_path($wancfg, 'if')) != NULL) {
2522
	$group = new Form_Group('DHCP6 VLAN Priority');
2523

    
2524
	$group->add(new Form_Checkbox(
2525
		'dhcp6vlanenable',
2526
		null,
2527
		'Enable dhcp6c VLAN Priority tagging',
2528
		array_get_path($pconfig, 'dhcp6vlanenable'),
2529
	))->setHelp('Normally off unless specifically required by the ISP.');
2530

    
2531
	$group->add(new Form_Select(
2532
		'dhcp6cvpt',
2533
		'VLAN Prio',
2534
		array_get_path($pconfig, 'dhcp6cvpt'),
2535
		$vlanprio
2536
	))->setHelp('Choose 802.1p priority to set.');
2537

    
2538
	$section->add($group);
2539
}
2540

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

    
2551
$form->add($section);
2552

    
2553
// DHCP6 client config - Advanced
2554

    
2555
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2556
$section->addClass('dhcp6advanced');
2557

    
2558
$section->addInput(new Form_Checkbox(
2559
	'adv_dhcp6_interface_statement_information_only_enable',
2560
	'Information only',
2561
	'Exchange Information Only',
2562
	array_get_path($pconfig, 'adv_dhcp6_interface_statement_information_only_enable'),
2563
	'Selected'
2564
))->setHelp('Only exchange informational configuration parameters with servers.');
2565

    
2566
$section->addInput(new Form_Input(
2567
	'adv_dhcp6_interface_statement_send_options',
2568
	'Send options',
2569
	'text',
2570
	array_get_path($pconfig, 'adv_dhcp6_interface_statement_send_options'),
2571
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2572
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2573
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2574
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2575

    
2576
$section->addInput(new Form_Input(
2577
	'adv_dhcp6_interface_statement_request_options',
2578
	'Request Options',
2579
	'text',
2580
	array_get_path($pconfig, 'adv_dhcp6_interface_statement_request_options'),
2581
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2582
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2583

    
2584
$section->addInput(new Form_Input(
2585
	'adv_dhcp6_interface_statement_script',
2586
	'Scripts',
2587
	'text',
2588
	array_get_path($pconfig, 'adv_dhcp6_interface_statement_script'),
2589
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2590
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2591

    
2592
$group = new Form_Group('Identity Association Statement');
2593

    
2594
$group->add(new Form_Checkbox(
2595
	'adv_dhcp6_id_assoc_statement_address_enable',
2596
	null,
2597
	'Non-Temporary Address Allocation',
2598
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_address_enable'),
2599
	'Selected'
2600
));
2601

    
2602
$group->add(new Form_Input(
2603
	'adv_dhcp6_id_assoc_statement_address_id',
2604
	null,
2605
	'text',
2606
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_address_id'),
2607
))->sethelp('id-assoc na ID');
2608

    
2609
$group->add(new Form_IpAddress(
2610
	'adv_dhcp6_id_assoc_statement_address',
2611
	null,
2612
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_address'),
2613
	'V6'
2614
))->sethelp('IPv6 address');
2615

    
2616
$group->add(new Form_Input(
2617
	'adv_dhcp6_id_assoc_statement_address_pltime',
2618
	null,
2619
	'text',
2620
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_address_pltime'),
2621
))->sethelp('pltime');
2622

    
2623
$group->add(new Form_Input(
2624
	'adv_dhcp6_id_assoc_statement_address_vltime',
2625
	null,
2626
	'text',
2627
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_address_vltime'),
2628
))->sethelp('vltime');
2629

    
2630
$section->add($group);
2631

    
2632
// Prefix delegation
2633
$group = new Form_Group('');
2634

    
2635
$group->add(new Form_Checkbox(
2636
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2637
	null,
2638
	'Prefix Delegation ',
2639
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_prefix_enable'),
2640
	'Selected'
2641
));
2642

    
2643
$group->add(new Form_Input(
2644
	'adv_dhcp6_id_assoc_statement_prefix_id',
2645
	null,
2646
	'text',
2647
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_prefix_id'),
2648
))->sethelp('id-assoc pd ID');
2649

    
2650
$group->add(new Form_IpAddress(
2651
	'adv_dhcp6_id_assoc_statement_prefix',
2652
	null,
2653
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_prefix'),
2654
	'V6'
2655
))->sethelp('IPv6 prefix');
2656

    
2657
$group->add(new Form_Input(
2658
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2659
	null,
2660
	'text',
2661
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_prefix_pltime'),
2662
))->sethelp('pltime');
2663

    
2664
$group->add(new Form_Input(
2665
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2666
	null,
2667
	'text',
2668
	array_get_path($pconfig, 'adv_dhcp6_id_assoc_statement_prefix_vltime'),
2669
))->sethelp('vltime');
2670

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

    
2673
$group = new Form_Group('Prefix interface statement');
2674

    
2675
$group->add(new Form_Input(
2676
	'adv_dhcp6_prefix_interface_statement_sla_id',
2677
	null,
2678
	'text',
2679
	array_get_path($pconfig, 'adv_dhcp6_prefix_interface_statement_sla_id'),
2680
))->sethelp('Prefix Interface sla-id');
2681

    
2682
$group->add(new Form_Input(
2683
	'adv_dhcp6_prefix_interface_statement_sla_len',
2684
	null,
2685
	'text',
2686
	array_get_path($pconfig, 'adv_dhcp6_prefix_interface_statement_sla_len'),
2687
))->sethelp('sla-len');
2688

    
2689
$section->add($group);
2690

    
2691
$group = new Form_Group('Select prefix interface');
2692
$section->addInput(new Form_Select(
2693
	'adv_dhcp6_prefix_selected_interface',
2694
	'Prefix Interface',
2695
	array_get_path($pconfig, 'adv_dhcp6_prefix_selected_interface'),
2696
	$interfaces
2697
))->setHelp('Select the interface on which to apply the prefix delegation.');
2698

    
2699
$group = new Form_Group('Authentication statement');
2700

    
2701
$group->add(new Form_Input(
2702
	'adv_dhcp6_authentication_statement_authname',
2703
	null,
2704
	'text',
2705
	array_get_path($pconfig, 'adv_dhcp6_authentication_statement_authname'),
2706
))->sethelp('Authname');
2707

    
2708
$group->add(new Form_Input(
2709
	'adv_dhcp6_authentication_statement_protocol',
2710
	null,
2711
	'text',
2712
	array_get_path($pconfig, 'adv_dhcp6_authentication_statement_protocol'),
2713
))->sethelp('Protocol');
2714

    
2715
$group->add(new Form_Input(
2716
	'adv_dhcp6_authentication_statement_algorithm',
2717
	null,
2718
	'text',
2719
	array_get_path($pconfig, 'adv_dhcp6_authentication_statement_algorithm'),
2720
))->sethelp('Algorithm');
2721

    
2722
$group->add(new Form_Input(
2723
	'adv_dhcp6_authentication_statement_rdm',
2724
	null,
2725
	'text',
2726
	array_get_path($pconfig, 'adv_dhcp6_authentication_statement_rdm'),
2727
))->sethelp('RDM');
2728

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

    
2731
$group = new Form_Group('Keyinfo statement');
2732

    
2733
$group->add(new Form_Input(
2734
	'adv_dhcp6_key_info_statement_keyname',
2735
	null,
2736
	'text',
2737
	array_get_path($pconfig, 'adv_dhcp6_key_info_statement_keyname'),
2738
))->sethelp('Keyname');
2739

    
2740
$group->add(new Form_Input(
2741
	'adv_dhcp6_key_info_statement_realm',
2742
	null,
2743
	'text',
2744
	array_get_path($pconfig, 'adv_dhcp6_key_info_statement_realm'),
2745
))->sethelp('Realm');
2746

    
2747
$section->add($group);
2748

    
2749
$group = new Form_Group('');
2750

    
2751
$group->add(new Form_Input(
2752
	'adv_dhcp6_key_info_statement_keyid',
2753
	null,
2754
	'text',
2755
	array_get_path($pconfig, 'adv_dhcp6_key_info_statement_keyid'),
2756
))->sethelp('KeyID');
2757

    
2758
$group->add(new Form_Input(
2759
	'adv_dhcp6_key_info_statement_secret',
2760
	null,
2761
	'text',
2762
	array_get_path($pconfig, 'adv_dhcp6_key_info_statement_secret'),
2763
))->sethelp('Secret');
2764

    
2765
$group->add(new Form_Input(
2766
	'adv_dhcp6_key_info_statement_expire',
2767
	null,
2768
	'text',
2769
	array_get_path($pconfig, 'adv_dhcp6_key_info_statement_expire'),
2770
))->sethelp('Expire');
2771

    
2772
$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>');
2773

    
2774
$section->add($group);
2775

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

    
2778
$section = new Form_Section('6RD Configuration');
2779
$section->addClass('_6rd');
2780

    
2781
$section->addInput(new Form_Input(
2782
	'prefix-6rd',
2783
	'6RD Prefix',
2784
	'text',
2785
	array_get_path($pconfig, 'prefix-6rd'),
2786
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2787

    
2788
$section->addInput(new Form_Input(
2789
	'gateway-6rd',
2790
	'*6RD Border relay',
2791
	'text',
2792
	array_get_path($pconfig, 'gateway-6rd'),
2793
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2794

    
2795
$section->addInput(new Form_Select(
2796
	'prefix-6rd-v4plen',
2797
	'6RD IPv4 Prefix length',
2798
	array_get_path($pconfig, 'prefix-6rd-v4plen'),
2799
	array_combine(range(0, 32), range(0, 32))
2800
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2801

    
2802
$form->add($section);
2803

    
2804
// Track IPv6 ointerface section
2805
$section = new Form_Section('Track IPv6 Interface');
2806
$section->addClass('track6');
2807

    
2808
function build_ipv6interface_list() {
2809
	global $form;
2810

    
2811
	$list = ['' => ''];
2812

    
2813
	$interfaces = get_configured_interface_with_descr(true);
2814
	$dynv6ifs = [];
2815

    
2816
	foreach ($interfaces as $iface => $ifacename) {
2817
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2818
			case "6to4":
2819
			case "6rd":
2820
			case "dhcp6":
2821
				array_set_path($dynv6ifs,
2822
					$iface,
2823
					[
2824
						'name' => $ifacename,
2825
						'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2826
					]);
2827
				break;
2828
			default:
2829
				continue 2;
2830
		}
2831
	}
2832

    
2833
	foreach ($dynv6ifs as $iface => $ifacedata) {
2834
		array_set_path($list, $iface, array_get_path($ifacedata, 'name'));
2835

    
2836
		$form->addGlobal(new Form_Input(
2837
			'ipv6-num-prefix-ids-' . $iface,
2838
			null,
2839
			'hidden',
2840
			array_get_path($ifacedata, 'ipv6_num_prefix_ids')
2841
		));
2842
	}
2843

    
2844
	return($list);
2845
}
2846

    
2847
$section->addInput(new Form_Select(
2848
	'track6-interface',
2849
	'*IPv6 Interface',
2850
	array_get_path($pconfig, 'track6-interface'),
2851
	build_ipv6interface_list()
2852
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2853

    
2854
if (array_get_path($pconfig, 'track6-prefix-id') == "") {
2855
	array_set_path($pconfig, 'track6-prefix-id', 0);
2856
}
2857

    
2858
$section->addInput(new Form_Input(
2859
	'track6-prefix-id--hex',
2860
	'IPv6 Prefix ID',
2861
	'text',
2862
	sprintf("%x", array_get_path($pconfig, 'track6-prefix-id'))
2863
))->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>');
2864

    
2865
$form->addGlobal(new Form_Input(
2866
	'track6-prefix-id-max',
2867
	null,
2868
	'hidden',
2869
	0
2870
));
2871

    
2872
$form->add($section);
2873

    
2874
/// PPP section
2875

    
2876
$section = new Form_Section('PPP Configuration');
2877
$section->addClass('ppp');
2878

    
2879
$section->addInput(new Form_Select(
2880
	'country',
2881
	'Country',
2882
	array_get_path($pconfig, 'country'),
2883
	[]
2884
));
2885

    
2886
$section->addInput(new Form_Select(
2887
	'provider_list',
2888
	'Provider',
2889
	array_get_path($pconfig, 'provider_list'),
2890
	[]
2891
));
2892

    
2893
$section->addInput(new Form_Select(
2894
	'providerplan',
2895
	'Plan',
2896
	array_get_path($pconfig, 'providerplan'),
2897
	[]
2898
))->setHelp('Select to fill in service provider data.');
2899

    
2900
$section->addInput(new Form_Input(
2901
	'ppp_username',
2902
	'Username',
2903
	'text',
2904
	array_get_path($pconfig, 'ppp_username'),
2905
	['autocomplete' => 'new-password']
2906
));
2907

    
2908
$section->addPassword(new Form_Input(
2909
	'ppp_password',
2910
	'Password',
2911
	'password',
2912
	array_get_path($pconfig, 'ppp_password'),
2913
));
2914

    
2915
$section->addInput(new Form_Input(
2916
	'phone',
2917
	'*Phone number',
2918
	'text',
2919
	array_get_path($pconfig, 'phone'),
2920
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2921

    
2922
$section->addInput(new Form_Input(
2923
	'apn',
2924
	'Access Point Name',
2925
	'text',
2926
	array_get_path($pconfig, 'apn'),
2927
));
2928

    
2929

    
2930
function build_port_list() {
2931
	$list = ["" => "None"];
2932

    
2933
	$portlist = glob("/dev/cua*");
2934
	$modems	  = glob("/dev/modem*");
2935
	$portlist = array_merge($portlist, $modems);
2936

    
2937
	foreach ($portlist as $port) {
2938
		if (preg_match("/\.(lock|init)$/", $port)) {
2939
			continue;
2940
		}
2941

    
2942
		$port = trim($port);
2943
		$list[$port] = $port;
2944
	}
2945

    
2946
	return($list);
2947
}
2948

    
2949
$section->addInput(new Form_Select(
2950
	'port',
2951
	"*Modem port",
2952
	array_get_path($pconfig, 'port'),
2953
	build_port_list()
2954
));
2955

    
2956
$section->addInput(new Form_Button(
2957
	'btnadvppp',
2958
	'Advanced PPP',
2959
	array_path_enabled($pconfig, '', 'pppid') ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars(array_get_path($pconfig, 'pppid')) : 'interfaces_ppps_edit.php',
2960
	'fa-solid fa-cog'
2961
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2962

    
2963
$form->add($section);
2964

    
2965
// PPPoE configuration
2966
$section = new Form_Section('PPPoE Configuration');
2967
$section->addClass('pppoe');
2968

    
2969
$section->addInput(new Form_Input(
2970
	'pppoe_username',
2971
	'*Username',
2972
	'text',
2973
	array_get_path($pconfig, 'pppoe_username'),
2974
	['autocomplete' => 'new-password']
2975
));
2976

    
2977
$section->addPassword(new Form_Input(
2978
	'pppoe_password',
2979
	'*Password',
2980
	'password',
2981
	array_get_path($pconfig, 'pppoe_password'),
2982
));
2983

    
2984
$section->addInput(new Form_Input(
2985
	'provider',
2986
	'Service name',
2987
	'text',
2988
	array_get_path($pconfig, 'provider'),
2989
))->setHelp('This field can usually be left empty.');
2990

    
2991
$section->addInput(new Form_Input(
2992
	'hostuniq',
2993
	'Host-Uniq',
2994
	'text',
2995
	array_get_path($pconfig, 'hostuniq'),
2996
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2997

    
2998
$section->addInput(new Form_Checkbox(
2999
	'pppoe_dialondemand',
3000
	'Dial on demand',
3001
	'Enable Dial-On-Demand mode ',
3002
	array_get_path($pconfig, 'pppoe_dialondemand'),
3003
	'enable'
3004
));
3005

    
3006
$section->addInput(new Form_Input(
3007
	'pppoe_idletimeout',
3008
	'Idle timeout',
3009
	'number',
3010
	array_get_path($pconfig, 'pppoe_idletimeout'),
3011
	['min' => 0]
3012
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3013
			'An idle timeout of zero disables this feature.');
3014

    
3015
$section->addInput(new Form_Select(
3016
	'pppoe-reset-type',
3017
	'Periodic reset',
3018
	array_get_path($pconfig, 'pppoe-reset-type'),
3019
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
3020
))->setHelp('Select a reset timing type.');
3021

    
3022
$group = new Form_Group('Custom reset');
3023
$group->addClass('pppoecustom');
3024

    
3025
$group->add(new Form_Input(
3026
	'pppoe_resethour',
3027
	null,
3028
	'number',
3029
	(strlen(array_get_path($pconfig, 'pppoe_resethour')) > 0) ? array_get_path($pconfig, 'pppoe_resethour'): "0",
3030
	['min' => 0, 'max' => 23]
3031
))->setHelp('Hour (0-23), blank for * (every)');
3032

    
3033
$group->add(new Form_Input(
3034
	'pppoe_resetminute',
3035
	null,
3036
	'number',
3037
	(strlen(array_get_path($pconfig, 'pppoe_resetminute')) > 0) ? array_get_path($pconfig, 'pppoe_resetminute') : "0",
3038
	['min' => 0, 'max' => 59]
3039
))->setHelp('Minute (0-59), blank for * (every)');
3040

    
3041
$group->add(new Form_Input(
3042
	'pppoe_resetdate',
3043
	null,
3044
	'text',
3045
	array_get_path($pconfig, 'pppoe_resetdate'),
3046
))->setHelp('Specific date (mm/dd/yyyy)');
3047

    
3048
$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');
3049

    
3050
$section->add($group);
3051

    
3052
$group = new Form_MultiCheckboxGroup('cron based reset');
3053
$group->addClass('pppoepreset');
3054

    
3055
$group->add(new Form_MultiCheckbox(
3056
	'pppoe_pr_preset_val',
3057
	null,
3058
	'Reset at each month ("0 0 1 * *")',
3059
	array_get_path($pconfig, 'pppoe_monthly'),
3060
	'monthly'
3061
))->displayAsRadio();
3062

    
3063
$group->add(new Form_MultiCheckbox(
3064
	'pppoe_pr_preset_val',
3065
	null,
3066
	'Reset at each week ("0 0 * * 0")',
3067
	array_get_path($pconfig, 'pppoe_weekly'),
3068
	'weekly'
3069
))->displayAsRadio();
3070

    
3071
$group->add(new Form_MultiCheckbox(
3072
	'pppoe_pr_preset_val',
3073
	null,
3074
	'Reset at each day ("0 0 * * *")',
3075
	array_get_path($pconfig, 'pppoe_daily'),
3076
	'daily'
3077
))->displayAsRadio();
3078

    
3079
$group->add(new Form_MultiCheckbox(
3080
	'pppoe_pr_preset_val',
3081
	null,
3082
	'Reset at each hour ("0 * * * *")',
3083
	array_get_path($pconfig, 'pppoe_hourly'),
3084
	'hourly'
3085
))->displayAsRadio();
3086

    
3087
$section->add($group);
3088

    
3089
$section->addInput(new Form_Button(
3090
	'btnadvppp',
3091
	'Advanced and MLPPP',
3092
	array_path_enabled($pconfig, '', 'pppid') ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars(array_get_path($pconfig, 'pppid')) : 'interfaces_ppps_edit.php',
3093
	'fa-solid fa-cog'
3094
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3095

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

    
3098
// PPTP & L2TP Configuration section
3099
$section = new Form_Section('PPTP/L2TP Configuration');
3100
$section->addClass('pptp');
3101

    
3102
$section->addInput(new Form_Input(
3103
	'pptp_username',
3104
	'*Username',
3105
	'text',
3106
	array_get_path($pconfig, 'pptp_username'),
3107
	['autocomplete' => 'new-password']
3108
));
3109

    
3110
$section->addPassword(new Form_Input(
3111
	'pptp_password',
3112
	'*Password',
3113
	'password',
3114
	array_get_path($pconfig, 'pptp_password'),
3115
));
3116

    
3117
$group = new Form_Group('Shared Secret');
3118

    
3119
$group->add(new Form_Input(
3120
	'l2tp_secret',
3121
	'*Secret',
3122
	'password',
3123
	array_get_path($pconfig, 'l2tp_secret'),
3124
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3125
	    'important control packet contents. (Optional)');
3126

    
3127
$group->addClass('l2tp_secret');
3128
$section->add($group);
3129

    
3130
$section->addInput(new Form_IpAddress(
3131
	'pptp_local0',
3132
	'*Local IP address',
3133
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : array_get_path($pconfig, 'pptp_localip', [])[0],
3134
	'V4'
3135
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : array_get_path($pconfig, 'pptp_subnet', [])[0]);
3136

    
3137
$section->addInput(new Form_IpAddress(
3138
	'pptp_remote0',
3139
	'*Remote IP address',
3140
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : array_get_path($pconfig, 'pptp_remote', [])[0],
3141
	'HOSTV4'
3142
));
3143

    
3144
$section->addInput(new Form_Checkbox(
3145
	'pptp_dialondemand',
3146
	'Dial on demand',
3147
	'Enable Dial-On-Demand mode ',
3148
	array_get_path($pconfig, 'pptp_dialondemand'),
3149
	'enable'
3150
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3151
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3152

    
3153
$section->addInput(new Form_Input(
3154
	'pptp_idletimeout',
3155
	'Idle timeout (seconds)',
3156
	'number',
3157
	array_get_path($pconfig, 'pptp_idletimeout'),
3158
	['min' => 0]
3159
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3160
			'An idle timeout of zero disables this feature.');
3161

    
3162
if (array_path_enabled($pconfig, 'pptp_localip', '1') ||
3163
    array_path_enabled($pconfig, 'pptp_subnet', '1') |
3164
    array_path_enabled($pconfig, 'pptp_remote', '1')) {
3165
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3166
} else {
3167
	$mlppp_text = "";
3168
}
3169

    
3170
$section->addInput(new Form_Button(
3171
	'btnadvppp',
3172
	'Advanced and MLPPP',
3173
	array_path_enabled($pconfig, '', 'pppid') ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars(array_get_path($pconfig, 'pppid')) : 'interfaces_ppps_edit.php',
3174
	'fa-solid fa-cog'
3175
))->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);
3176

    
3177
$form->add($section);
3178

    
3179
// Wireless interface
3180
if (is_array(array_get_path($wancfg, 'wireless'))) {
3181
	$section = new Form_Section('Common Wireless Configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
3182

    
3183
	$section->addInput(new Form_Checkbox(
3184
		'persistcommonwireless',
3185
		'Persist common settings',
3186
		'Preserve common wireless configuration through interface deletions and reassignments.',
3187
		array_get_path($pconfig, 'persistcommonwireless'),
3188
		'yes'
3189
	));
3190

    
3191
	$mode_list = ['auto' => 'Auto'];
3192

    
3193
	if (is_array($wl_modes)) {
3194
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3195
			array_set_path($mode_list, $wl_standard, '802.' . $wl_standard);
3196
		}
3197
	}
3198

    
3199
	if (count($mode_list) == 1) {
3200
		$mode_list[''] = '';
3201
	}
3202

    
3203
	$section->addInput(new Form_Select(
3204
		'standard',
3205
		'Standard',
3206
		(array_get_path($pconfig, 'standard') == "") ? "11ng" : array_get_path($pconfig, 'standard'),
3207
		$mode_list
3208
	));
3209

    
3210
	if (isset($wl_modes['11g'])) {
3211
		$section->addInput(new Form_Select(
3212
			'protmode',
3213
			'802.11g OFDM Protection Mode',
3214
			array_get_path($pconfig, 'protmode'),
3215
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3216
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3217
	} else {
3218
		$form->addGlobal(new Form_Input(
3219
			'protmode',
3220
			null,
3221
			'hidden',
3222
			'off'
3223
		));
3224
	}
3225

    
3226
	$mode_list = ['0' => gettext('Auto')];
3227

    
3228
	if (is_array($wl_modes)) {
3229
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3230
			if ($wl_standard == "11g") {
3231
				$wl_standard = "11b/g";
3232
			} elseif ($wl_standard == "11ng") {
3233
				$wl_standard = "11b/g/n";
3234
			} elseif ($wl_standard == "11na") {
3235
				$wl_standard = "11a/n";
3236
			}
3237

    
3238
			foreach ($wl_channels as $wl_channel) {
3239
				if (isset($wl_chaninfo[$wl_channel])) {
3240
					array_set_path($mode_list, $wl_channel, $wl_standard . ' - ' . $wl_channel);
3241
				} else {
3242
					$tcinfo = array_get_path($wl_chaninfo, $wl_channel, []);
3243
					array_set_path($mode_list, $wl_channel, $wl_standard . ' - ' . $wl_channel . ' (' . $tcinfo[1] . ' @ ' . $tcinfo[2] . ' / ' . $tcinfo[3] . ')');
3244
				}
3245
			}
3246
		}
3247
	}
3248

    
3249
	$section->addInput(new Form_Select(
3250
		'channel',
3251
		'Channel',
3252
		array_get_path($pconfig, 'channel'),
3253
		$mode_list
3254
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3255
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3256

    
3257
	$section->addInput(new Form_Select(
3258
		'channel_width',
3259
		'Channel width',
3260
		array_get_path($pconfig, 'channel_width'),
3261
		$wl_ht_modes
3262
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3263

    
3264
	if (ANTENNAS) {
3265
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) ||
3266
		    isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) ||
3267
		    isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3268
			$group = new Form_Group('Antenna Settings');
3269

    
3270
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3271
				$group->add(new Form_Select(
3272
					'diversity',
3273
					null,
3274
					array_get_path($pconfig, 'diversity', ''),
3275
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3276
				))->setHelp('Diversity');
3277
			}
3278

    
3279
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3280
				$group->add(new Form_Select(
3281
					'txantenna',
3282
					null,
3283
					array_get_path($pconfig, 'txantenna', ''),
3284
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3285
				))->setHelp('Transmit antenna');
3286
			}
3287

    
3288
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3289
				$group->add(new Form_Select(
3290
					'rxantenna',
3291
					null,
3292
					array_get_path($pconfig, 'rxantenna', ''),
3293
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3294
				))->setHelp('Receive antenna');
3295
			}
3296

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

    
3299
			$section->add($group);
3300
		}
3301
	}
3302

    
3303
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) &&
3304
	    isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) &&
3305
	    isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3306
			$section->addInput(new Form_Input(
3307
				'distance',
3308
				'Distance setting (meters)',
3309
				'test',
3310
				array_get_path($pconfig, 'distance'),
3311
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3312
	}
3313

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

    
3316
	// Regulatory settings
3317
	$section = new Form_Section('Regulatory Settings');
3318

    
3319
	$domain_list = ["" => 'Default'];
3320

    
3321
	if (is_array($wl_regdomains)) {
3322
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3323
			array_set_path($domain_list, array_get_path($wl_regdomains_attr, "{$wl_regdomain_key}/ID"), array_get_path($wl_regdomain, 'name'));
3324
		}
3325
	}
3326

    
3327
	$section->addInput(new Form_Select(
3328
		'regdomain',
3329
		'Regulatory domain',
3330
		array_get_path($pconfig, 'regdomain'),
3331
		$domain_list
3332
	))->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');
3333

    
3334
	$country_list = ['' => 'Default'];
3335

    
3336
	if (is_array($wl_countries)) {
3337
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3338
			array_set_path($country_list, array_get_path($wl_countries_attr, "{$wl_country_key}/ID"), array_get_path($wl_country, 'name'));
3339
		}
3340
	}
3341

    
3342
	$section->addInput(new Form_Select(
3343
		'regcountry',
3344
		'Country',
3345
		array_get_path($pconfig, 'regcountry'),
3346
		$country_list
3347
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3348

    
3349
	$section->addInput(new Form_Select(
3350
		'reglocation',
3351
		'Location',
3352
		array_get_path($pconfig, 'reglocation'),
3353
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
3354
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3355
				'Using the correct settings to comply with local regulatory requirements is recommended.%1$s' .
3356
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3357
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3358
				'These settings may not be able to add additional channels that are not already supported.', '<br />');
3359

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

    
3362
	$section = new Form_Section('Network-Specific Wireless Configuration');
3363

    
3364
	$section->addInput(new Form_Select(
3365
		'mode',
3366
		'Mode',
3367
		array_get_path($pconfig, 'mode'),
3368
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3369
	));
3370

    
3371
	$section->addInput(new Form_Input(
3372
		'ssid',
3373
		'SSID',
3374
		'text',
3375
		array_get_path($pconfig, 'ssid'),
3376
	));
3377

    
3378
	if (isset($wl_modes['11ng']) ||
3379
	    isset($wl_modes['11na'])) {
3380
		$section->addInput(new Form_Select(
3381
			'puremode',
3382
			'Minimum wireless standard',
3383
			array_get_path($pconfig, 'puremode'),
3384
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3385
		))->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)');
3386
	} elseif (isset($wl_modes['11g'])) {
3387
		$section->addInput(new Form_Checkbox(
3388
			'puremode',
3389
			'802.11g only',
3390
			null,
3391
			array_get_path($pconfig, 'puremode'),
3392
			'11g'
3393
		))->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)');
3394
	}
3395

    
3396
	$section->addInput(new Form_Checkbox(
3397
		'apbridge_enable',
3398
		'Allow intra-BSS communication',
3399
		'Allow packets to pass between wireless clients directly when operating as an access point',
3400
		array_get_path($pconfig, 'apbridge_enable'),
3401
		'yes'
3402
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3403

    
3404
	$section->addInput(new Form_Checkbox(
3405
		'wme_enable',
3406
		'Enable WME',
3407
		'Force the card to use WME (wireless QoS)',
3408
		array_get_path($pconfig, 'wme_enable'),
3409
		'yes'
3410
	));
3411

    
3412
	$section->addInput(new Form_Checkbox(
3413
		'hidessid_enable',
3414
		'Hide SSID',
3415
		'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.)',
3416
		array_get_path($pconfig, 'hidessid_enable'),
3417
		'yes'
3418
	));
3419

    
3420
	$form->add($section);
3421

    
3422
	// WPA Section
3423
	$section = new Form_Section('WPA');
3424

    
3425
	$section->addInput(new Form_Checkbox(
3426
		'wpa_enable',
3427
		'Enable',
3428
		'Enable WPA',
3429
		array_get_path($pconfig, 'wpa_enable'),
3430
		'yes'
3431
	));
3432

    
3433
	$section->addInput(new Form_Select(
3434
		'wpa_mode',
3435
		'WPA mode',
3436
		array_get_path($pconfig, 'wpa_mode', 2),
3437
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3438
	));
3439

    
3440
	$section->addInput(new Form_Select(
3441
		'wpa_pairwise',
3442
		'WPA Pairwise',
3443
		array_get_path($pconfig, 'wpa_pairwise', 'CCMP'),
3444
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3445
	));
3446

    
3447
	$section->addInput(new Form_Select(
3448
		'wpa_key_mgmt',
3449
		'WPA Key Management Mode',
3450
		array_get_path($pconfig, 'wpa_key_mgmt'),
3451
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3452
	));
3453

    
3454
	$section->addInput(new Form_Input(
3455
		'passphrase',
3456
		'WPA Pre-Shared Key',
3457
		'text',
3458
		array_get_path($pconfig, 'passphrase'),
3459
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3460

    
3461
	$section->addInput(new Form_Select(
3462
		'wpa_eap_client_mode',
3463
		'EAP Client Mode',
3464
		array_get_path($pconfig, 'wpa_eap_client_mode'),
3465
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3466
	));
3467

    
3468
	$section->addInput(new Form_Select(
3469
		'wpa_eap_ca',
3470
		'Certificate Authority',
3471
		array_get_path($pconfig, 'wpa_eap_ca'),
3472
		cert_build_list('ca', 'HTTPS')
3473
	));
3474

    
3475
	$section->addInput(new Form_Select(
3476
		'wpa_eap_inner_auth',
3477
		'Inner Authentication Method',
3478
		array_get_path($pconfig, 'wpa_eap_inner_auth'),
3479
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3480
	));
3481

    
3482
	$section->addInput(new Form_Input(
3483
		'wpa_eap_inner_id',
3484
		'*Inner Authentication Identity',
3485
		'text',
3486
		array_get_path($pconfig, 'wpa_eap_inner_id'),
3487
	));
3488

    
3489
	$section->addInput(new Form_Input(
3490
		'wpa_eap_inner_password',
3491
		'*Inner Authentication Passphrase',
3492
		'text',
3493
		array_get_path($pconfig, 'wpa_eap_inner_password'),
3494
	));
3495

    
3496
	$section->addInput(new Form_Select(
3497
		'wpa_eap_cert',
3498
		'TLS/TTLS Client Certificate',
3499
		array_get_path($pconfig, 'wpa_eap_cert'),
3500
		cert_build_list('cert', 'HTTPS')
3501
	));
3502

    
3503
	$section->addInput(new Form_Input(
3504
		'wpa_group_rekey',
3505
		'Group Key Rotation',
3506
		'number',
3507
		array_get_path($pconfig, 'wpa_group_rekey', 60),
3508
		['min' => '1', 'max' => 9999]
3509
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3510

    
3511
	$section->addInput(new Form_Input(
3512
		'wpa_gmk_rekey',
3513
		'Group Master Key Regeneration',
3514
		'number',
3515
		array_get_path($pconfig, 'wpa_gmk_rekey', 3600),
3516
		['min' => '1', 'max' => 9999]
3517
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3518

    
3519
	$section->addInput(new Form_Checkbox(
3520
		'wpa_strict_rekey',
3521
		'Strict Key Regeneration',
3522
		'Force the AP to rekey whenever a client disassociates',
3523
		array_get_path($pconfig, 'wpa_strict_rekey'),
3524
		'yes'
3525
	));
3526

    
3527
	$form->add($section);
3528

    
3529
	$section = new Form_Section('802.1x RADIUS Options');
3530
	$section->addClass('ieee8021x_group');
3531

    
3532
	$section->addInput(new Form_Checkbox(
3533
		'ieee8021x',
3534
		'IEEE802.1X',
3535
		'Enable 802.1X authentication',
3536
		array_get_path($pconfig, 'ieee8021x'),
3537
		'yes'
3538
	));
3539

    
3540
	$group = new Form_Group('Primary 802.1X server');
3541

    
3542
	$group->add(new Form_IpAddress(
3543
		'auth_server_addr',
3544
		'IP Address',
3545
		array_get_path($pconfig, 'auth_server_addr'),
3546
	))->setHelp('IP address of the RADIUS server');
3547

    
3548
	$group->add(new Form_Input(
3549
		'auth_server_port',
3550
		'Port',
3551
		'number',
3552
		array_get_path($pconfig, 'auth_server_port'),
3553
	))->setHelp('Server auth port. Default is 1812');
3554

    
3555
	$group->add(new Form_Input(
3556
		'auth_server_shared_secret',
3557
		'Shared Secret',
3558
		'text',
3559
		array_get_path($pconfig, 'auth_server_shared_secret'),
3560
	))->setHelp('RADIUS Shared secret for this firewall');
3561

    
3562
	$section->add($group);
3563

    
3564
	$group = new Form_Group('Secondary 802.1X server');
3565

    
3566
	$group->add(new Form_IpAddress(
3567
		'auth_server_addr2',
3568
		'IP Address',
3569
		array_get_path($pconfig, 'auth_server_addr2'),
3570
	))->setHelp('IP address of the RADIUS server');
3571

    
3572
	$group->add(new Form_Input(
3573
		'auth_server_port2',
3574
		'Port',
3575
		'number',
3576
		array_get_path($pconfig, 'auth_server_port2'),
3577
	))->setHelp('Server auth port. Default is 1812');
3578

    
3579
	$group->add(new Form_Input(
3580
		'auth_server_shared_secret2',
3581
		'Shared Secret',
3582
		'text',
3583
		array_get_path($pconfig, 'auth_server_shared_secret2'),
3584
	))->setHelp('RADIUS Shared secret for this firewall');
3585

    
3586
	$section->add($group);
3587

    
3588
	$section->addInput(new Form_Checkbox(
3589
		'rsn_preauth',
3590
		'Authentication Roaming Preauth',
3591
		null,
3592
		array_get_path($pconfig, 'rsn_preauth'),
3593
		'yes'
3594
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3595

    
3596
	$form->add($section);
3597
}
3598

    
3599
$section = new Form_Section('Reserved Networks');
3600

    
3601
$section->addInput(new Form_Checkbox(
3602
	'blockpriv',
3603
	'Block private networks and loopback addresses',
3604
	'',
3605
	array_get_path($pconfig, 'blockpriv'),
3606
	'yes'
3607
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3608
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3609
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3610

    
3611
$section->addInput(new Form_Checkbox(
3612
	'blockbogons',
3613
	'Block bogon networks',
3614
	'',
3615
	array_get_path($pconfig, 'blockbogons'),
3616
	'yes'
3617
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3618
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3619
			'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' .
3620
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3621

    
3622
$form->add($section);
3623

    
3624
$form->addGlobal(new Form_Input(
3625
	'if',
3626
	null,
3627
	'hidden',
3628
	$if
3629
));
3630

    
3631
if (array_get_path($wancfg, 'if') == array_get_path($a_ppps, "{$pppid}/if")) {
3632
	$form->addGlobal(new Form_Input(
3633
		'ppp_port',
3634
		null,
3635
		'hidden',
3636
		array_get_path($pconfig, 'port'),
3637
	));
3638
}
3639

    
3640
$form->addGlobal(new Form_Input(
3641
	'ptpid',
3642
	null,
3643
	'hidden',
3644
	array_get_path($pconfig, 'ptpid'),
3645
));
3646

    
3647

    
3648
// Add new gateway modal pop-up
3649
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3650

    
3651
$modal->addInput(new Form_Checkbox(
3652
	'defaultgw4',
3653
	'Default',
3654
	'Default gateway',
3655
	array_get_path($gateway_settings4, 'defaultgw', (strtolower($if) == "wan")),
3656
));
3657

    
3658
$modal->addInput(new Form_Input(
3659
	'gatewayname4',
3660
	'Gateway name',
3661
	'text',
3662
	array_get_path($gateway_settings4, 'name', $defgatewayname4),
3663
));
3664

    
3665
$modal->addInput(new Form_IpAddress(
3666
	'gatewayip4',
3667
	'Gateway IPv4',
3668
	array_get_path($gateway_settings4, 'gateway'),
3669
	'V4'
3670
));
3671

    
3672
$modal->addInput(new Form_Input(
3673
	'gatewaydescr4',
3674
	'Description',
3675
	'text',
3676
	array_get_path($gateway_settings4, 'descr'),
3677
));
3678

    
3679
$btnaddgw4 = new Form_Button(
3680
	'add4',
3681
	'Add',
3682
	null,
3683
	'fa-solid fa-plus'
3684
);
3685

    
3686
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3687

    
3688
$btncnxgw4 = new Form_Button(
3689
	'cnx4',
3690
	'Cancel',
3691
	null,
3692
	'fa-solid fa-undo'
3693
);
3694

    
3695
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3696

    
3697
$modal->addInput(new Form_StaticText(
3698
	null,
3699
	$btnaddgw4 . $btncnxgw4
3700
));
3701

    
3702
$form->add($modal);
3703

    
3704
print($form);
3705
?>
3706

    
3707
<script type="text/javascript">
3708
//<![CDATA[
3709
events.push(function() {
3710
	function updateType(t) {
3711

    
3712
		switch (t) {
3713
			case "none": {
3714
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3715
				break;
3716
			}
3717
			case "staticv4": {
3718
				$('.dhcpadvanced, .none, .dhcp').hide();
3719
				$('.pppoe, .pptp, .ppp').hide();
3720
				break;
3721
			}
3722
			case "dhcp": {
3723
				$('.dhcpadvanced, .none').hide();
3724
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3725
										//			about the staticv4 class
3726
				$('.pppoe, .pptp, .ppp').hide();
3727
				break;
3728
			}
3729
			case "ppp": {
3730
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3731
				country_list();
3732
				break;
3733
			}
3734
			case "pppoe": {
3735
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3736
				break;
3737
			}
3738
			case "l2tp": {
3739
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3740
				$('.pptp, .l2tp_secret').show();
3741
				break;
3742
			}
3743
			case "pptp": {
3744
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3745
				$('.pptp').show();
3746
				break;
3747
			}
3748
		}
3749

    
3750
		if ((t != "l2tp") && (t != "pptp")) {
3751
			$('.'+t).show();
3752
		}
3753
	}
3754

    
3755
	function updateTypeSix(t) {
3756
		if (!isNaN(t[0])) {
3757
			t = '_' + t;
3758
		}
3759

    
3760
		switch (t) {
3761
			case "none": {
3762
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3763
				break;
3764
			}
3765
			case "staticv6": {
3766
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3767
				break;
3768
			}
3769
			case "slaac": {
3770
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3771
				break;
3772
			}
3773
			case "dhcp6": {
3774
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3775
				break;
3776
			}
3777
			case "_6rd": {
3778
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3779
				break;
3780
			}
3781
			case "_6to4": {
3782
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3783
				break;
3784
			}
3785
			case "track6": {
3786
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3787
				update_track6_prefix();
3788
				break;
3789
			}
3790
		}
3791

    
3792
		if ((t != "l2tp") && (t != "pptp")) {
3793
			$('.'+t).show();
3794
		}
3795
	}
3796

    
3797
	function show_reset_settings(reset_type) {
3798
		if (reset_type == 'preset') {
3799
			$('.pppoepreset').show();
3800
			$('.pppoecustom').hide();
3801
		} else if (reset_type == 'custom') {
3802
			$('.pppoecustom').show();
3803
			$('.pppoepreset').hide();
3804
		} else {
3805
			$('.pppoecustom').hide();
3806
			$('.pppoepreset').hide();
3807
		}
3808
	}
3809

    
3810
	function update_track6_prefix() {
3811
		var iface = $("#track6-interface").val();
3812
		if (iface == null) {
3813
			return;
3814
		}
3815

    
3816
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3817
		if (track6_prefix_ids == null) {
3818
			return;
3819
		}
3820

    
3821
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3822
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3823
	}
3824

    
3825
	function addOption_v4() {
3826
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3827
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3828
	}
3829

    
3830
	function addOption_v6() {
3831
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3832
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3833
	}
3834

    
3835
	function addSelectboxOption(selectbox, text, value) {
3836
		var optn = document.createElement("OPTION");
3837
		optn.text = text;
3838
		optn.value = value;
3839
		selectbox.append(optn);
3840
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3841
	}
3842

    
3843
	function country_list() {
3844
		$('#country').children().remove();
3845
		$('#provider_list').children().remove();
3846
		$('#providerplan').children().remove();
3847
		$.ajax({
3848
			type: 'post',
3849
			url: 'getserviceproviders.php',
3850
			data: { get_country_list: true },
3851
			success: function(response) {
3852

    
3853
				var responseTextArr = response.split("\n");
3854
				responseTextArr.sort();
3855

    
3856
				responseTextArr.forEach( function(value) {
3857
					country = value.split(":");
3858
					$('#country').append($('<option>', {
3859
						value: country[1],
3860
						text : country[0]
3861
					}));
3862
				});
3863
			}
3864
		});
3865
	}
3866

    
3867
	function providers_list() {
3868
		$('#provider_list').children().remove();
3869
		$('#providerplan').children().remove();
3870
		$.ajax("getserviceproviders.php",{
3871
			type: 'post',
3872
			data: {country : $('#country').val()},
3873
			success: function(response) {
3874
				var responseTextArr = response.split("\n");
3875
				responseTextArr.sort();
3876
				responseTextArr.forEach( function(value) {
3877
					$('#provider_list').append($('<option>', {
3878
							value: value,
3879
							text : value
3880
					}));
3881
				});
3882
			}
3883
		});
3884
	}
3885

    
3886
	function providerplan_list() {
3887
		$('#providerplan').children().remove();
3888
		$.ajax("getserviceproviders.php",{
3889
			type: 'post',
3890
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3891
			success: function(response) {
3892
				var responseTextArr = response.split("\n");
3893
				responseTextArr.sort();
3894

    
3895
				$('#providerplan').append($('<option>', {
3896
					value: '',
3897
					text : ''
3898
				}));
3899

    
3900
				responseTextArr.forEach( function(value) {
3901
					if (value != "") {
3902
						providerplan = value.split(":");
3903

    
3904
						$('#providerplan').append($('<option>', {
3905
							value: providerplan[1],
3906
							text : providerplan[0] + " - " + providerplan[1]
3907
						}));
3908
					}
3909
				});
3910
			}
3911
		});
3912
	}
3913

    
3914
	function prefill_provider() {
3915
		$.ajax("getserviceproviders.php",{
3916
			type: 'POST',
3917
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3918
			success: function(data, textStatus, response) {
3919
				var xmldoc = response.responseXML;
3920
				var provider = xmldoc.getElementsByTagName('connection')[0];
3921
				$('#ppp_username').val('');
3922
				$('#ppp_password').val('');
3923
				$('#ppp_password_confirm').val('');
3924
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3925
					$('#phone').val('#777');
3926
					$('#apn').val('');
3927
				} else {
3928
					$('#phone').val('*99#');
3929
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3930
				}
3931
				ppp_username = provider.getElementsByTagName('username')[0].firstChild.data;
3932
				ppp_password = provider.getElementsByTagName('password')[0].firstChild.data;
3933
				$('#ppp_username').val(ppp_username);
3934
				$('#ppp_password').val(ppp_password);
3935
				$('#ppp_password_confirm').val(ppp_password);
3936
			}
3937
		});
3938
	}
3939

    
3940
	function show_dhcp6adv() {
3941
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3942
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3943

    
3944
		hideCheckbox('dhcp6usev4iface', ovr);
3945
		hideCheckbox('dhcp6prefixonly', ovr);
3946
		hideInput('dhcp6-ia-pd-len', ovr);
3947
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3948
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3949

    
3950
		hideClass('dhcp6advanced', !adv || ovr);
3951
	}
3952

    
3953
	function setDHCPoptions() {
3954
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3955
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3956

    
3957
		if (ovr) {
3958
			hideInput('dhcphostname', true);
3959
			hideIpAddress('alias-address', true);
3960
			hideInput('dhcprejectfrom', true);
3961
			hideInput('adv_dhcp_config_file_override_path', false);
3962
			hideClass('dhcpadvanced', true);
3963
		} else {
3964
			hideInput('dhcphostname', false);
3965
			hideIpAddress('alias-address', false);
3966
			hideInput('dhcprejectfrom', false);
3967
			hideInput('adv_dhcp_config_file_override_path', true);
3968
			hideClass('dhcpadvanced', !adv);
3969
		}
3970
	}
3971

    
3972
	// DHCP preset actions
3973
	// Set presets from value of radio buttons
3974
	function setPresets(val) {
3975
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3976
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3977
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3978
		if (val == "SavedCfg")	setPresetsnow("<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_timeout'));?>", "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_retry'));?>", "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_select_timeout'));?>", "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_reboot'));?>", "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_backoff_cutoff'));?>", "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_initial_interval'));?>");
3979
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3980
	}
3981

    
3982
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3983
		$('#adv_dhcp_pt_timeout').val(timeout);
3984
		$('#adv_dhcp_pt_retry').val(retry);
3985
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3986
		$('#adv_dhcp_pt_reboot').val(reboot);
3987
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3988
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3989
	}
3990

    
3991
	function setPPPoEDialOnDemandItems() {
3992
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3993
	}
3994

    
3995
	function setPPTPDialOnDemandItems() {
3996
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3997
	}
3998

    
3999
	function show_wpaoptions() {
4000
		var wpa = !($('#wpa_enable').prop('checked'));
4001

    
4002
		hideInput('passphrase', wpa);
4003
		hideInput('wpa_mode', wpa);
4004
		hideInput('wpa_key_mgmt', wpa);
4005
		hideInput('wpa_pairwise', wpa);
4006
		hideCheckbox('wpa_strict_rekey', wpa);
4007
		hideClass('ieee8021x_group', true);
4008
		if ($('#mode').val() == 'hostap') {
4009
			hideInput('wpa_group_rekey', wpa);
4010
			hideInput('wpa_gmk_rekey', wpa);
4011
			hideCheckbox('wpa_strict_rekey', wpa);
4012
		} else {
4013
			hideInput('wpa_group_rekey', true);
4014
			hideInput('wpa_gmk_rekey', true);
4015
			hideCheckbox('wpa_strict_rekey', true);
4016
		}
4017
		updatewpakeymgmt($('#wpa_key_mgmt').val());
4018
	}
4019

    
4020
	function updatewifistandard(s) {
4021
		switch (s) {
4022
			case "auto": {
4023
				hideInput('protmode', false);
4024
				hideInput('channel_width', false);
4025
				break;
4026
			}
4027
			case "11b": {
4028
				hideInput('protmode', true);
4029
				hideInput('channel_width', true);
4030
				break;
4031
			}
4032
			case "11g": {
4033
				hideInput('protmode', false);
4034
				hideInput('channel_width', true);
4035
				break;
4036
			}
4037
			case "11ng": {
4038
				hideInput('protmode', false);
4039
				hideInput('channel_width', false);
4040
				break;
4041
			}
4042
			case "11a": {
4043
				hideInput('protmode', true);
4044
				hideInput('channel_width', true);
4045
				break;
4046
			}
4047
			case "11na": {
4048
				hideInput('protmode', true);
4049
				hideInput('channel_width', false);
4050
				break;
4051
			}
4052
			default: {
4053
				break;
4054
			}
4055
		}
4056
	}
4057

    
4058
	function updatewifimode(m) {
4059
		switch (m) {
4060
			case "adhoc": {
4061
				hideInput('puremode', true);
4062
				hideCheckbox('apbridge_enable', true);
4063
				hideCheckbox('hidessid_enable', false);
4064
				break;
4065
			}
4066
			case "hostap": {
4067
				hideInput('puremode', false);
4068
				hideCheckbox('apbridge_enable', false);
4069
				hideCheckbox('hidessid_enable', false);
4070
				break;
4071
			}
4072
			default: {
4073
				hideInput('puremode', true);
4074
				hideCheckbox('apbridge_enable', true);
4075
				hideCheckbox('hidessid_enable', true);
4076
				break;
4077
			}
4078
		}
4079
		show_wpaoptions();
4080
		updateeapclientmode($('#wpa_eap_client_mode').val());
4081
		updatewpakeymgmt($('#wpa_key_mgmt').val());
4082
	}
4083

    
4084
	function updateeapclientmode(m) {
4085
		if ($('#mode').val() == 'bss') {
4086
			var wpa = !($('#wpa_enable').prop('checked'));
4087
		} else {
4088
			var wpa = true;
4089
		}
4090
		switch (m) {
4091
			case "PEAP": {
4092
				hideInput('wpa_eap_cert', true);
4093
				hideInput('wpa_eap_inner_auth', wpa);
4094
				hideInput('wpa_eap_inner_id', wpa);
4095
				hideInput('wpa_eap_inner_password', wpa);
4096
				break;
4097
			}
4098
			case "TLS": {
4099
				hideInput('wpa_eap_cert', wpa);
4100
				hideInput('wpa_eap_inner_auth', true);
4101
				hideInput('wpa_eap_inner_id', true);
4102
				hideInput('wpa_eap_inner_password', true);
4103
				break;
4104
			}
4105
			case "TTLS": {
4106
				hideInput('wpa_eap_cert', wpa);
4107
				hideInput('wpa_eap_inner_auth', wpa);
4108
				hideInput('wpa_eap_inner_id', wpa);
4109
				hideInput('wpa_eap_inner_password', wpa);
4110
				break;
4111
			}
4112
			default: {
4113
				break;
4114
			}
4115
		}
4116
	}
4117

    
4118
	function updatewpakeymgmt(m) {
4119
		hideInput('passphrase', false);
4120
		hideInput('wpa_eap_client_mode', true);
4121
		hideInput('wpa_eap_ca', true);
4122
		hideInput('wpa_eap_cert', true);
4123
		hideInput('wpa_eap_inner_auth', true);
4124
		hideInput('wpa_eap_inner_id', true);
4125
		hideInput('wpa_eap_inner_password', true);
4126
		hideClass('ieee8021x_group', true);
4127
		if (m == "WPA-EAP") {
4128
			hideInput('passphrase', true);
4129
			if ($('#mode').val() == 'bss') {
4130
				hideInput('wpa_eap_client_mode', false);
4131
				hideInput('wpa_eap_ca', false);
4132
				updateeapclientmode($('#wpa_eap_client_mode').val());
4133
			} else if ($('#mode').val() == 'hostap') {
4134
				hideClass('ieee8021x_group', false);
4135
			}
4136
		} else if (m != "WPA-PSK") {
4137
			hideInput('passphrase', false);
4138
			if ($('#mode').val() == 'bss') {
4139
				hideInput('wpa_eap_client_mode', false);
4140
				hideInput('wpa_eap_ca', false);
4141
				hideInput('wpa_eap_cert', false);
4142
				hideInput('wpa_eap_inner_auth', false);
4143
				hideInput('wpa_eap_inner_id', false);
4144
				hideInput('wpa_eap_inner_password', false);
4145
			} else if ($('#mode').val() == 'hostap') {
4146
				hideClass('ieee8021x_group', false);
4147
			}
4148
		}
4149
	}
4150

    
4151
	// ---------- On initial page load ------------------------------------------------------------
4152

    
4153
	updateType($('#type').val());
4154
	updateTypeSix($('#type6').val());
4155
	show_reset_settings($('#pppoe-reset-type').val());
4156
	hideClass('dhcp6advanced', true);
4157
	hideClass('dhcpadvanced', true);
4158
	show_dhcp6adv();
4159
	setDHCPoptions();
4160
	setPPPoEDialOnDemandItems();
4161
	setPPTPDialOnDemandItems();
4162
	show_wpaoptions();
4163
	updatewifistandard($('#standard').val());
4164
	updatewifimode($('#mode').val());
4165

    
4166
	// Set preset buttons on page load
4167
	var sv = "<?=htmlspecialchars(array_get_path($pconfig, 'adv_dhcp_pt_values'));?>";
4168
	if (sv == "") {
4169
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4170
	} else {
4171
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4172
	}
4173

    
4174
	// Set preset from value
4175
	setPresets(sv);
4176

    
4177
	// If the user wants to add a gateway, then add that to the gateway selection
4178
	if ($("#gatewayip4").val() != '') {
4179
		addOption_v4();
4180
	}
4181
	if ($("#gatewayip6").val() != '') {
4182
		addOption_v6();
4183
	}
4184

    
4185
	// ---------- Click checkbox handlers ---------------------------------------------------------
4186

    
4187
	$('#type').on('change', function() {
4188
		updateType(this.value);
4189
	});
4190

    
4191
	$('#type6').on('change', function() {
4192
		updateTypeSix(this.value);
4193
	});
4194

    
4195
	$('#standard').on('change', function() {
4196
		updatewifistandard(this.value);
4197
	});
4198

    
4199
	$('#mode').on('change', function() {
4200
		updatewifimode(this.value);
4201
	});
4202

    
4203
	$('#wpa_key_mgmt').on('change', function() {
4204
		updatewpakeymgmt(this.value);
4205
	});
4206

    
4207
	$('#wpa_eap_client_mode').on('change', function() {
4208
		updateeapclientmode(this.value);
4209
	});
4210

    
4211
	$('#track6-interface').on('change', function() {
4212
		update_track6_prefix();
4213
	});
4214

    
4215
	$('#pppoe-reset-type').on('change', function() {
4216
		show_reset_settings(this.value);
4217
	});
4218

    
4219
	$("#add4").click(function() {
4220
		addOption_v4();
4221
		$("#newgateway4").modal('hide');
4222
	});
4223

    
4224
	$("#cnx4").click(function() {
4225
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4226
		$("#gatewayip4").val('');
4227
		$("#gatewaydescr4").val('');
4228
		$("#defaultgw4").prop("checked", false);
4229
		$("#newgateway4").modal('hide');
4230
	});
4231

    
4232
	$("#add6").click(function() {
4233
		addOption_v6();
4234
		$("#newgateway6").modal('hide');
4235
	});
4236

    
4237
	$("#cnx6").click(function() {
4238
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4239
		$("#gatewayip6").val('');
4240
		$("#gatewaydescr6").val('');
4241
		$("#defaultgw6").prop("checked", false);
4242
		$("#newgateway6").modal('hide');
4243
	});
4244

    
4245
	$('#country').on('change', function() {
4246
		providers_list();
4247
	});
4248

    
4249
	$('#provider_list').on('change', function() {
4250
		providerplan_list();
4251
	});
4252

    
4253
	$('#providerplan').on('change', function() {
4254
		prefill_provider();
4255
	});
4256

    
4257
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4258
		setDHCPoptions();
4259
	});
4260

    
4261
	$('#adv_dhcp6_config_advanced').click(function () {
4262
		show_dhcp6adv();
4263
	});
4264

    
4265
	$('#adv_dhcp6_config_file_override').click(function () {
4266
		show_dhcp6adv();
4267
	});
4268

    
4269
	// On click . .
4270
	$('#pppoe_dialondemand').click(function () {
4271
		setPPPoEDialOnDemandItems();
4272
	});
4273

    
4274
	$('#pptp_dialondemand').click(function () {
4275
		setPPTPDialOnDemandItems();
4276
	});
4277

    
4278
	$('[name=adv_dhcp_pt_values]').click(function () {
4279
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4280
	});
4281

    
4282
	$('#wpa_enable').click(function () {
4283
		show_wpaoptions();
4284
	});
4285

    
4286
	$('#pppoe_resetdate').datepicker();
4287

    
4288
});
4289
//]]>
4290
</script>
4291

    
4292
<?php include("foot.inc");
(73-73/230)