Project

General

Profile

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

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

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

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

    
50
define("ANTENNAS", false);
51

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

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

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
438
}
439

    
440
$changes_applied = false;
441

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

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

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

    
495
		/* restart snmp so that it binds to correct address */
496
		$retval |= services_snmpd_configure();
497

    
498
		/* sync filter configuration */
499
		setup_gateways_monitor();
500

    
501
		clear_subsystem_dirty('interfaces');
502

    
503
		$retval |= filter_configure();
504

    
505
		enable_rrd_graphing();
506

    
507
		$changes_applied = true;
508

    
509
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
510
			clear_subsystem_dirty('staticroutes');
511
		}
512

    
513
		init_config_arr(array('syslog'));
514
		if (isset($config['syslog']['enable']) && ($ifapply == $config['syslog']['sourceip'])) {
515
			system_syslogd_start();
516
		}
517
	}
518
	@unlink("{$g['tmp_path']}/.interfaces.apply");
519
} else if ($_POST['save']) {
520

    
521
	unset($input_errors);
522
	$pconfig = $_POST;
523

    
524
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
525
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
526
	} else {
527
		$pconfig['track6-prefix-id'] = 0;
528
	}
529

    
530
	/* filter out spaces from descriptions */
531
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
532

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

    
547
	/* input validation */
548
	$reqdfields = explode(" ", "descr");
549
	$reqdfieldsn = array(gettext("Description"));
550
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
551

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

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

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

    
579
		if (is_numeric($_POST['descr'])) {
580
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
581
		}
582

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

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

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

    
603
	if ($_POST['blockbogons'] == "yes" &&
604
	    isset($config['system']['ipv6allow']) &&
605
	    (!isset($config['system']['maximumtableentries']) ||
606
	     $config['system']['maximumtableentries'] <
607
	     $g['minimumtableentries_bogonsv6'])) {
608
		$input_errors[] = sprintf(gettext(
609
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
610
		    $g['minimumtableentries_bogonsv6']);
611
	}
612

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

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

    
748
			if (empty($_POST['track6-interface'])) {
749
				$input_errors[] = gettext("A valid interface to track must be selected.");
750
			}
751

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

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

    
791
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
792
			if ($_POST['subnet'] < 31) {
793
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
794
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
795
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
796
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
797
				}
798
			}
799

    
800
			foreach ($staticroutes as $route_subnet) {
801
				list($network, $subnet) = explode("/", $route_subnet);
802
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
803
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
804
					break;
805
				}
806
				unset($network, $subnet);
807
			}
808
		}
809
	}
810
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
811
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
812

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

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

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

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

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

    
933
		unset($min_mtu, $max_mtu);
934

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

    
953
				$realhwif_array = get_parent_interface($ifdata['if']);
954
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
955
				$parent_realhwif = $realhwif_array[0];
956

    
957
				if ($parent_realhwif != $wancfg['if']) {
958
					continue;
959
				}
960

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

    
1057
		if ($_POST['passphrase']) {
1058
			$passlen = strlen($_POST['passphrase']);
1059
			if ($passlen < 8 || $passlen > 63) {
1060
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1061
			}
1062
		}
1063

    
1064
		if ($_POST['wpa_enable'] == "yes") {
1065
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1066
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1067
			}
1068
			if (($_POST['mode'] == 'bss') & ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1069
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1070
				if (empty($_POST['wpa_eap_inner_id'])) {
1071
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1072
					    "when PEAP/TTLS authentication method is selected.");
1073
				}
1074
				if (empty($_POST['wpa_eap_inner_password'])) {
1075
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1076
					    "when PEAP/TTLS authentication method is selected.");
1077
				}
1078
			}
1079
		}
1080
	}
1081

    
1082
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1083
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1084
	}
1085

    
1086
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1087
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1088
	}
1089

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

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

    
1098
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1099
		$gateway_settings4['interface'] = $_POST['if'];
1100
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1101
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1102
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1103
		$gateway_settings4['ipprotocol'] = 'inet';
1104
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1105
		foreach ($gw_input_errors as $input_error_text) {
1106
			$input_errors[] = $input_error_text;
1107
		}
1108
	}
1109

    
1110
	if ($_POST['gatewayip6']) {
1111
		// The user wants to add an IPv6 gateway - validate the settings
1112
		$gateway_settings6 = array();
1113

    
1114
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1115
		$gateway_settings6['interface'] = $_POST['if'];
1116
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1117
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1118
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1119
		$gateway_settings6['ipprotocol'] = 'inet6';
1120
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1121
		foreach ($gw_input_errors as $input_error_text) {
1122
			$input_errors[] = $input_error_text;
1123
		}
1124
	}
1125

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

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

    
1175
		unset($wancfg['dhcpvlanenable']);
1176
		unset($wancfg['dhcpcvpt']);
1177

    
1178
		unset($wancfg['adv_dhcp_pt_timeout']);
1179
		unset($wancfg['adv_dhcp_pt_retry']);
1180
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1181
		unset($wancfg['adv_dhcp_pt_reboot']);
1182
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1183
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1184

    
1185
		unset($wancfg['adv_dhcp_pt_values']);
1186

    
1187
		unset($wancfg['adv_dhcp_send_options']);
1188
		unset($wancfg['adv_dhcp_request_options']);
1189
		unset($wancfg['adv_dhcp_required_options']);
1190
		unset($wancfg['adv_dhcp_option_modifiers']);
1191

    
1192
		unset($wancfg['adv_dhcp_config_advanced']);
1193
		unset($wancfg['adv_dhcp_config_file_override']);
1194
		unset($wancfg['adv_dhcp_config_file_override_path']);
1195

    
1196
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1197
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1198
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1199
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1200

    
1201
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1202
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1203
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1204
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1205
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1206

    
1207
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1208
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1209
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1210
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1211
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1212

    
1213
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1214
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1215
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1216

    
1217
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1218
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1219
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1220
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1221

    
1222
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1223
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1224
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1225
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1226
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1227

    
1228
		unset($wancfg['adv_dhcp6_config_advanced']);
1229
		unset($wancfg['adv_dhcp6_config_file_override']);
1230
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1231

    
1232
		unset($wancfg['pppoe_password']);
1233
		unset($wancfg['pptp_username']);
1234
		unset($wancfg['pptp_password']);
1235
		unset($wancfg['l2tp_secret']);
1236
		unset($wancfg['provider']);
1237
		unset($wancfg['hostuniq']);
1238
		unset($wancfg['ondemand']);
1239
		unset($wancfg['timeout']);
1240
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1241
			unset($wancfg['pppoe']['pppoe-reset-type']);
1242
		}
1243
		unset($wancfg['local']);
1244

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

    
1267
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1268
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1269

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

    
1286
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1287
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1288
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1289
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1290
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1291
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1292

    
1293
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1294

    
1295
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1296
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1297
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1298
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1299

    
1300
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1301
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1302
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1303

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

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

    
1362
				if (!empty($_POST['pppoe-reset-type'])) {
1363
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1364
				} else {
1365
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1366
				}
1367
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1368
				$wancfg['ipaddr'] = $_POST['type'];
1369
				if ($gateway_item) {
1370
					$a_gateways[] = $gateway_item;
1371
				}
1372

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

    
1449
				if ($_POST['dhcp6withoutra'] == "yes") {
1450
					$wancfg['dhcp6withoutra'] = true;
1451
				}
1452
				if ($_POST['dhcp6norelease'] == "yes") {
1453
					$wancfg['dhcp6norelease'] = true;
1454
				}
1455
				if ($_POST['dhcp6vlanenable'] == "yes") {
1456
					$wancfg['dhcp6vlanenable'] = true;
1457
				}
1458
				if (!empty($_POST['dhcp6cvpt'])) {
1459
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1460
				} else {
1461
					unset($wancfg['dhcp6cvpt']);
1462
				}
1463

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

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

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

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

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

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

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

    
1589
		if ($_POST['blockpriv'] == "yes") {
1590
			$wancfg['blockpriv'] = true;
1591
		} else {
1592
			unset($wancfg['blockpriv']);
1593
		}
1594
		if ($_POST['blockbogons'] == "yes") {
1595
			$wancfg['blockbogons'] = true;
1596
		} else {
1597
			unset($wancfg['blockbogons']);
1598
		}
1599
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1600
		if (empty($_POST['mtu'])) {
1601
			unset($wancfg['mtu']);
1602
		} else {
1603
			$wancfg['mtu'] = $_POST['mtu'];
1604
		}
1605
		if (empty($_POST['mss'])) {
1606
			unset($wancfg['mss']);
1607
		} else {
1608
			$wancfg['mss'] = $_POST['mss'];
1609
		}
1610
		if (empty($_POST['mediaopt'])) {
1611
			unset($wancfg['media']);
1612
			unset($wancfg['mediaopt']);
1613
		} else {
1614
			$mediaopts = explode(' ', $_POST['mediaopt']);
1615
			if ($mediaopts[0] != '') {
1616
				$wancfg['media'] = $mediaopts[0];
1617
			}
1618
			if ($mediaopts[1] != '') {
1619
				$wancfg['mediaopt'] = $mediaopts[1];
1620
			} else {
1621
				unset($wancfg['mediaopt']);
1622
			}
1623
		}
1624
		if (isset($wancfg['wireless'])) {
1625
			handle_wireless_post();
1626
		}
1627

    
1628
		write_config("Interfaces settings changed");
1629

    
1630
		if ($_POST['gatewayip4']) {
1631
			save_gateway($gateway_settings4);
1632
		}
1633

    
1634
		if ($_POST['gatewayip6']) {
1635
			save_gateway($gateway_settings6);
1636
		}
1637

    
1638
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1639
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1640
		} else {
1641
			$toapplylist = array();
1642
		}
1643
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1644
		$toapplylist[$if]['ppps'] = $old_ppps;
1645
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1646

    
1647
		mark_subsystem_dirty('interfaces');
1648

    
1649
		/* regenerate cron settings/crontab file */
1650
		configure_cron();
1651

    
1652
		header("Location: interfaces.php?if={$if}");
1653
		exit;
1654
	}
1655

    
1656
} // end if ($_POST['save'])
1657

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

    
1707
	if ($_POST['persistcommonwireless'] == "yes") {
1708
		if (!is_array($config['wireless'])) {
1709
			$config['wireless'] = array();
1710
		}
1711
		if (!is_array($config['wireless']['interfaces'])) {
1712
			$config['wireless']['interfaces'] = array();
1713
		}
1714
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1715
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1716
		}
1717
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1718
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1719
	}
1720
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1721
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1722
	} else if (isset($wancfg['wireless']['diversity'])) {
1723
		unset($wancfg['wireless']['diversity']);
1724
	}
1725
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1726
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1727
	} else if (isset($wancfg['wireless']['txantenna'])) {
1728
		unset($wancfg['wireless']['txantenna']);
1729
	}
1730
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1731
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1732
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1733
		unset($wancfg['wireless']['rxantenna']);
1734
	}
1735
	if ($_POST['hidessid_enable'] == "yes") {
1736
		$wancfg['wireless']['hidessid']['enable'] = true;
1737
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1738
		unset($wancfg['wireless']['hidessid']['enable']);
1739
	}
1740
	if ($_POST['mac_acl_enable'] == "yes") {
1741
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1742
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1743
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1744
	}
1745
	if ($_POST['rsn_preauth'] == "yes") {
1746
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1747
	} else {
1748
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1749
	}
1750
	if ($_POST['ieee8021x'] == "yes") {
1751
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1752
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1753
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1754
	}
1755
	if ($_POST['wpa_strict_rekey'] == "yes") {
1756
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1757
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1758
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1759
	}
1760
	if ($_POST['debug_mode'] == "yes") {
1761
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1762
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1763
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1764
	}
1765
	if ($_POST['wpa_enable'] == "yes") {
1766
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1767
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1768
		unset($wancfg['wireless']['wpa']['enable']);
1769
	}
1770

    
1771
	if ($_POST['wme_enable'] == "yes") {
1772
		if (!is_array($wancfg['wireless']['wme'])) {
1773
			$wancfg['wireless']['wme'] = array();
1774
		}
1775
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1776
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1777
		unset($wancfg['wireless']['wme']['enable']);
1778
	}
1779
	if ($_POST['puremode'] == "11g") {
1780
		if (!is_array($wancfg['wireless']['pureg'])) {
1781
			$wancfg['wireless']['pureg'] = array();
1782
		}
1783
		$wancfg['wireless']['pureg']['enable'] = true;
1784
	} else if ($_POST['puremode'] == "11n") {
1785
		if (!is_array($wancfg['wireless']['puren'])) {
1786
			$wancfg['wireless']['puren'] = array();
1787
		}
1788
		$wancfg['wireless']['puren']['enable'] = true;
1789
	} else {
1790
		if (isset($wancfg['wireless']['pureg'])) {
1791
			unset($wancfg['wireless']['pureg']);
1792
		}
1793
		if (isset($wancfg['wireless']['puren'])) {
1794
			unset($wancfg['wireless']['puren']);
1795
		}
1796
	}
1797
	if ($_POST['apbridge_enable'] == "yes") {
1798
		if (!is_array($wancfg['wireless']['apbridge'])) {
1799
			$wancfg['wireless']['apbridge'] = array();
1800
		}
1801
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1802
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1803
		unset($wancfg['wireless']['apbridge']['enable']);
1804
	}
1805
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1806
		if (!is_array($wancfg['wireless']['turbo'])) {
1807
			$wancfg['wireless']['turbo'] = array();
1808
		}
1809
		$wancfg['wireless']['turbo']['enable'] = true;
1810
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1811
		unset($wancfg['wireless']['turbo']['enable']);
1812
	}
1813

    
1814
	interface_sync_wireless_clones($wancfg, true);
1815
}
1816

    
1817
function check_wireless_mode() {
1818
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1819

    
1820
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1821
		return;
1822
	}
1823

    
1824
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1825
		$clone_count = 1;
1826
	} else {
1827
		$clone_count = 0;
1828
	}
1829

    
1830
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1831
		foreach ($config['wireless']['clone'] as $clone) {
1832
			if ($clone['if'] == $wlanbaseif) {
1833
				$clone_count++;
1834
			}
1835
		}
1836
	}
1837

    
1838
	if ($clone_count > 1) {
1839
		$old_wireless_mode = $wancfg['wireless']['mode'];
1840
		$wancfg['wireless']['mode'] = $_POST['mode'];
1841
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1842
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."), $wlan_modes[$wancfg['wireless']['mode']]);
1843
		} else {
1844
			pfSense_interface_destroy("{$wlanif}_");
1845
		}
1846
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1847
	}
1848
}
1849

    
1850
// Find all possible media options for the interface
1851
$mediaopts_list = array();
1852
$intrealname = $config['interfaces'][$if]['if'];
1853
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1854
foreach ($mediaopts as $mediaopt) {
1855
	preg_match("/media (.*)/", $mediaopt, $matches);
1856
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1857
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1858
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1859
	} else {
1860
		// there is only media like "media 1000baseT"
1861
		array_push($mediaopts_list, $matches[1]);
1862
	}
1863
}
1864

    
1865
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1866
$shortcut_section = "interfaces";
1867

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

    
1870
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1871
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1872
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1873
}
1874

    
1875
$types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), "dhcp6" => gettext("DHCP6"), "slaac" => gettext("SLAAC"), "6rd" => gettext("6rd Tunnel"), "6to4" => gettext("6to4 Tunnel"), "track6" => gettext("Track Interface"));
1876

    
1877
// Get the MAC address
1878
$defgatewayname4 = $wancfg['descr'] . "GW";
1879
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1880

    
1881
function build_mediaopts_list() {
1882
	global $mediaopts_list;
1883

    
1884
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1885
			 " " =>	 gettext("------- Media Supported by this interface -------")
1886
			];
1887

    
1888
	foreach ($mediaopts_list as $mediaopt) {
1889
		$list[$mediaopt] = $mediaopt;
1890
	}
1891

    
1892
	return($list);
1893
}
1894

    
1895
function build_gateway_list() {
1896
	global $a_gateways, $if;
1897

    
1898
	$list = array("none" => gettext("None"));
1899
	foreach ($a_gateways as $gateway) {
1900
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1901
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1902
		}
1903
	}
1904

    
1905
	return($list);
1906
}
1907

    
1908
function build_gatewayv6_list() {
1909
	global $a_gateways, $if;
1910

    
1911
	$list = array("none" => gettext("None"));
1912
	foreach ($a_gateways as $gateway) {
1913
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1914
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1915
		}
1916
	}
1917

    
1918
	return($list);
1919
}
1920

    
1921
include("head.inc");
1922

    
1923
if ($input_errors) {
1924
	print_input_errors($input_errors);
1925
}
1926

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

    
1933
if ($changes_applied) {
1934
	print_apply_result_box($retval);
1935
}
1936

    
1937
$form = new Form();
1938

    
1939
$section = new Form_Section('General Configuration');
1940

    
1941
$section->addInput(new Form_Checkbox(
1942
	'enable',
1943
	'Enable',
1944
	'Enable interface',
1945
	$pconfig['enable'],
1946
	'yes'
1947
));
1948

    
1949
$section->addInput(new Form_Input(
1950
	'descr',
1951
	'*Description',
1952
	'text',
1953
	$pconfig['descr']
1954
))->setHelp('Enter a description (name) for the interface here.');
1955

    
1956
if ($show_address_controls) {
1957
	$section->addInput(new Form_Select(
1958
		'type',
1959
		'IPv4 Configuration Type',
1960
		$pconfig['type'],
1961
		$types4
1962
	));
1963
	$section->addInput(new Form_Select(
1964
		'type6',
1965
		'IPv6 Configuration Type',
1966
		$pconfig['type6'],
1967
		$types6
1968
	));
1969
} else {
1970
	$section->addInput(new Form_StaticText(
1971
		'IPv4/IPv6 Configuration',
1972
		"This interface type does not support manual address configuration on this page. "
1973
	));
1974
	$form->addGlobal(new Form_Input(
1975
		'type',
1976
		null,
1977
		'hidden',
1978
		'none'
1979
	));
1980
	$form->addGlobal(new Form_Input(
1981
		'type6',
1982
		null,
1983
		'hidden',
1984
		'none'
1985
	));
1986
}
1987

    
1988
if (!is_pseudo_interface($intrealname, true)) {
1989
	$macaddress = new Form_Input(
1990
		'spoofmac',
1991
		'MAC Address',
1992
		'text',
1993
		$pconfig['spoofmac'],
1994
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
1995
	);
1996

    
1997
	if (interface_is_vlan($realifname)) {
1998
		$macaddress->setDisabled();
1999
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
2000
		    'set on its parent interface');
2001
	} else {
2002
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
2003
		    'MAC address of this interface.%sEnter a MAC address in the ' .
2004
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
2005
	}
2006

    
2007
	$section->addInput($macaddress);
2008
}
2009

    
2010
$section->addInput(new Form_Input(
2011
	'mtu',
2012
	'MTU',
2013
	'number',
2014
	$pconfig['mtu']
2015
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2016
			'This is typically 1500 bytes but can vary in some circumstances.');
2017

    
2018
$section->addInput(new Form_Input(
2019
	'mss',
2020
	'MSS',
2021
	'number',
2022
	$pconfig['mss']
2023
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2024
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2025

    
2026
if (count($mediaopts_list) > 0) {
2027
	$section->addInput(new Form_Select(
2028
		'mediaopt',
2029
		'Speed and Duplex',
2030
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
2031
		build_mediaopts_list()
2032
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2033
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2034
}
2035

    
2036
$form->add($section);
2037

    
2038
$section = new Form_Section('Static IPv4 Configuration');
2039
$section->addClass('staticv4');
2040

    
2041
$section->addInput(new Form_IpAddress(
2042
	'ipaddr',
2043
	'*IPv4 Address',
2044
	$pconfig['ipaddr'],
2045
	'V4'
2046
))->addMask('subnet', $pconfig['subnet'], 32);
2047

    
2048
$group = new Form_Group('IPv4 Upstream gateway');
2049

    
2050
$group->add(new Form_Select(
2051
	'gateway',
2052
	'IPv4 Upstream Gateway',
2053
	$pconfig['gateway'],
2054
	build_gateway_list()
2055
));
2056

    
2057
$group->add(new Form_Button(
2058
	'addgw4',
2059
	'Add a new gateway',
2060
	null,
2061
	'fa-plus'
2062
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2063

    
2064
$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' .
2065
				'On local area network interfaces the upstream gateway should be "none". ' .
2066
				'Gateways can be managed by %2$sclicking here%3$s.', '<br />', '<a target="_blank" href="system_gateways.php">', '</a>');
2067

    
2068
$section->add($group);
2069

    
2070
$form->add($section);
2071

    
2072
$section = new Form_Section('SLAAC IPv6 Configuration');
2073
$section->addClass('slaac');
2074

    
2075
$section->addInput(new Form_Checkbox(
2076
	'slaacusev4iface',
2077
	'Use IPv4 connectivity as parent interface',
2078
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2079
	$pconfig['slaacusev4iface']
2080
));
2081

    
2082
$form->add($section);
2083

    
2084
$section = new Form_Section('Static IPv6 Configuration');
2085
$section->addClass('staticv6');
2086

    
2087
$section->addInput(new Form_IpAddress(
2088
	'ipaddrv6',
2089
	'*IPv6 address',
2090
	$pconfig['ipaddrv6'],
2091
	'V6'
2092
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2093

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

    
2101
$group = new Form_Group('IPv6 Upstream gateway');
2102

    
2103
$group->add(new Form_Select(
2104
	'gatewayv6',
2105
	'IPv6 Upstream Gateway',
2106
	$pconfig['gatewayv6'],
2107
	build_gatewayv6_list()
2108
));
2109

    
2110
$group->add(new Form_Button(
2111
	'addgw6',
2112
	'Add a new gateway',
2113
	null,
2114
	'fa-plus'
2115
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2116

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

    
2120
$section->add($group);
2121
$form->add($section);
2122

    
2123
// Add new gateway modal pop-up for IPv6
2124
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2125

    
2126
$modal->addInput(new Form_Checkbox(
2127
	'defaultgw6',
2128
	'Default',
2129
	'Default gateway',
2130
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2131
));
2132

    
2133
$modal->addInput(new Form_Input(
2134
	'gatewayname6',
2135
	'Gateway name',
2136
	'text',
2137
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2138
));
2139

    
2140
$modal->addInput(new Form_IpAddress(
2141
	'gatewayip6',
2142
	'Gateway IPv6',
2143
	$gateway_settings6['gateway'],
2144
	'V6'
2145
));
2146

    
2147
$modal->addInput(new Form_Input(
2148
	'gatewaydescr6',
2149
	'Description',
2150
	'text',
2151
	$gateway_settings6['descr']
2152
));
2153

    
2154
$btnaddgw6 = new Form_Button(
2155
	'add6',
2156
	'Add',
2157
	null,
2158
	'fa-plus'
2159
);
2160

    
2161
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2162

    
2163
$btncnxgw6 = new Form_Button(
2164
	'cnx6',
2165
	'Cancel',
2166
	null,
2167
	'fa-undo'
2168
);
2169

    
2170
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2171

    
2172
$modal->addInput(new Form_StaticText(
2173
	null,
2174
	$btnaddgw6 . $btncnxgw6
2175
));
2176

    
2177
$form->add($modal);
2178

    
2179
// ==== DHCP client configuration =============================
2180

    
2181
$section = new Form_Section('DHCP Client Configuration');
2182
$section->addClass('dhcp');
2183

    
2184
$group = new Form_Group('Options');
2185

    
2186
$group->add(new Form_Checkbox(
2187
	'adv_dhcp_config_advanced',
2188
	null,
2189
	'Advanced Configuration',
2190
	$pconfig['adv_dhcp_config_advanced']
2191
))->setHelp('Use advanced DHCP configuration options.');
2192

    
2193
$group->add(new Form_Checkbox(
2194
	'adv_dhcp_config_file_override',
2195
	null,
2196
	'Configuration Override',
2197
	$pconfig['adv_dhcp_config_file_override']
2198
))->setHelp('Override the configuration from this file.');
2199

    
2200
$section->add($group);
2201

    
2202
$section->addInput(new Form_Input(
2203
	'dhcphostname',
2204
	'Hostname',
2205
	'text',
2206
	$pconfig['dhcphostname']
2207
))->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).');
2208

    
2209
$section->addInput(new Form_IpAddress(
2210
	'alias-address',
2211
	'Alias IPv4 address',
2212
	$pconfig['alias-address'],
2213
	'V4'
2214
))->addMask('alias-subnet', $pconfig['alias-subnet'], 32)->setHelp('The value in this field is used as a fixed alias IPv4 address by the DHCP client.');
2215

    
2216
$section->addInput(new Form_Input(
2217
	'dhcprejectfrom',
2218
	'Reject leases from',
2219
	'text',
2220
	$pconfig['dhcprejectfrom']
2221
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2222
			'(separate multiple entries with a comma). ' .
2223
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2224

    
2225
if (interface_is_vlan($wancfg['if']) != NULL) {
2226

    
2227
	$group = new Form_Group('DHCP VLAN Priority');
2228
	$group->add(new Form_Checkbox(
2229
		'dhcpvlanenable',
2230
		null,
2231
		'Enable dhcpclient VLAN Priority tagging',
2232
		$pconfig['dhcpvlanenable']
2233
	))->setHelp('Normally off unless specifically required by the ISP.');
2234

    
2235
	$group->add(new Form_Select(
2236
		'dhcpcvpt',
2237
		'VLAN Prio',
2238
		$pconfig['dhcpcvpt'],
2239
		$vlanprio
2240
	))->setHelp('Choose 802.1p priority to set.');
2241

    
2242
	$section->add($group);
2243
}
2244

    
2245
$group = new Form_Group('Protocol timing');
2246
$group->addClass('dhcpadvanced');
2247

    
2248
$group->add(new Form_Input(
2249
	'adv_dhcp_pt_timeout',
2250
	null,
2251
	'number',
2252
	$pconfig['adv_dhcp_pt_timeout']
2253
))->setHelp('Timeout');
2254

    
2255
$group->add(new Form_Input(
2256
	'adv_dhcp_pt_retry',
2257
	null,
2258
	'number',
2259
	$pconfig['adv_dhcp_pt_retry']
2260
))->setHelp('Retry');
2261

    
2262
$group->add(new Form_Input(
2263
	'adv_dhcp_pt_select_timeout',
2264
	null,
2265
	'number',
2266
	$pconfig['adv_dhcp_pt_select_timeout'],
2267
	['min' => 0]
2268
))->setHelp('Select timeout');
2269

    
2270
$group->add(new Form_Input(
2271
	'adv_dhcp_pt_reboot',
2272
	null,
2273
	'number',
2274
	$pconfig['adv_dhcp_pt_reboot']
2275
))->setHelp('Reboot');
2276

    
2277
$group->add(new Form_Input(
2278
	'adv_dhcp_pt_backoff_cutoff',
2279
	null,
2280
	'number',
2281
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2282
))->setHelp('Backoff cutoff');
2283

    
2284
$group->add(new Form_Input(
2285
	'adv_dhcp_pt_initial_interval',
2286
	null,
2287
	'number',
2288
	$pconfig['adv_dhcp_pt_initial_interval']
2289
))->setHelp('Initial interval');
2290

    
2291
$section->add($group);
2292

    
2293
$group = new Form_Group('Presets');
2294
$group->addClass('dhcpadvanced');
2295

    
2296
$group->add(new Form_Checkbox(
2297
	'adv_dhcp_pt_values',
2298
	null,
2299
	'FreeBSD default',
2300
	null,
2301
	'DHCP'
2302
))->displayAsRadio();
2303

    
2304
$group->add(new Form_Checkbox(
2305
	'adv_dhcp_pt_values',
2306
	null,
2307
	'Clear',
2308
	null,
2309
	'Clear'
2310
))->displayAsRadio();
2311

    
2312
$group->add(new Form_Checkbox(
2313
	'adv_dhcp_pt_values',
2314
	null,
2315
	'pfSense Default',
2316
	null,
2317
	'pfSense'
2318
))->displayAsRadio();
2319

    
2320
$group->add(new Form_Checkbox(
2321
	'adv_dhcp_pt_values',
2322
	null,
2323
	'Saved Cfg',
2324
	null,
2325
	'SavedCfg'
2326
))->displayAsRadio();
2327

    
2328
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.%1$s' .
2329
				'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>');
2330

    
2331
$section->add($group);
2332

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

    
2343
$form->add($section);
2344

    
2345
$section = new Form_Section('Lease Requirements and Requests');
2346
$section->addClass('dhcpadvanced');
2347

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

    
2358
$section->addInput(new Form_Input(
2359
	'adv_dhcp_request_options',
2360
	'Request options',
2361
	'text',
2362
	$pconfig['adv_dhcp_request_options']
2363
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2364
			'Some ISPs may require certain options be or not be requested.', '<br />');
2365

    
2366
$section->addInput(new Form_Input(
2367
	'adv_dhcp_required_options',
2368
	'Require options',
2369
	'text',
2370
	$pconfig['adv_dhcp_required_options']
2371
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2372

    
2373
$section->addInput(new Form_Input(
2374
	'adv_dhcp_option_modifiers',
2375
	'Option modifiers',
2376
	'text',
2377
	$pconfig['adv_dhcp_option_modifiers']
2378
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2379
			'modifiers: (default, supersede, prepend, append) %1$s' .
2380
			'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>');
2381

    
2382
$form->add($section);
2383

    
2384
// DHCP6 client config
2385

    
2386
$section = new Form_Section('DHCP6 Client Configuration');
2387
$section->addClass('dhcp6');
2388

    
2389
$group = new Form_Group('Options');
2390

    
2391
$group->add(new Form_Checkbox(
2392
	'adv_dhcp6_config_advanced',
2393
	null,
2394
	'Advanced Configuration',
2395
	$pconfig['adv_dhcp6_config_advanced']
2396
))->setHelp('Use advanced DHCPv6 configuration options.');
2397

    
2398
$group->add(new Form_Checkbox(
2399
	'adv_dhcp6_config_file_override',
2400
	null,
2401
	'Configuration Override',
2402
	$pconfig['adv_dhcp6_config_file_override']
2403
))->setHelp('Override the configuration from this file.');
2404

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

    
2407
$section->addInput(new Form_Checkbox(
2408
	'dhcp6usev4iface',
2409
	'Use IPv4 connectivity as parent interface',
2410
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2411
	$pconfig['dhcp6usev4iface']
2412
));
2413

    
2414
$section->addInput(new Form_Checkbox(
2415
	'dhcp6prefixonly',
2416
	'Request only an IPv6 prefix',
2417
	'Only request an IPv6 prefix, do not request an IPv6 address',
2418
	$pconfig['dhcp6prefixonly']
2419
));
2420

    
2421
$section->addInput(new Form_Select(
2422
	'dhcp6-ia-pd-len',
2423
	'DHCPv6 Prefix Delegation size',
2424
	$pconfig['dhcp6-ia-pd-len'],
2425
	array("none" => "None", 16 => "48", 15 => "49", 14 => "50", 13 => "51", 12 => "52", 11 => "53", 10 => "54", 9 => "55", 8 => "56", 7 => "57", 6 => "58", 5 => "59", 4 => "60", 3 => "61", 2 => "62", 1 => "63", 0 => "64")
2426
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2427

    
2428
$section->addInput(new Form_Checkbox(
2429
	'dhcp6-ia-pd-send-hint',
2430
	'Send IPv6 prefix hint',
2431
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2432
	$pconfig['dhcp6-ia-pd-send-hint']
2433
));
2434

    
2435
$section->addInput(new Form_Checkbox(
2436
	'dhcp6debug',
2437
	'Debug',
2438
	'Start DHCP6 client in debug mode',
2439
	$pconfig['dhcp6debug']
2440
));
2441
$section->addInput(new Form_Checkbox(
2442
	'dhcp6withoutra',
2443
	'Do not wait for a RA',
2444
	'Required by some ISPs, especially those not using PPPoE',
2445
	$pconfig['dhcp6withoutra']
2446
));
2447
$section->addInput(new Form_Checkbox(
2448
	'dhcp6norelease',
2449
	'Do not allow PD/Address release',
2450
	'dhcp6c will send a release to the ISP on exit, some ISPs then release the allocated address or prefix. This option prevents that signal ever being sent',
2451
	$pconfig['dhcp6norelease']
2452
));
2453

    
2454
if (interface_is_vlan($wancfg['if']) != NULL) {
2455
	$group = new Form_Group('DHCP6 VLAN Priority');
2456

    
2457
	$group->add(new Form_Checkbox(
2458
		'dhcp6vlanenable',
2459
		null,
2460
		'Enable dhcp6c VLAN Priority tagging',
2461
		$pconfig['dhcp6vlanenable']
2462
	))->setHelp('Normally off unless specifically required by the ISP.');
2463

    
2464
	$group->add(new Form_Select(
2465
		'dhcp6cvpt',
2466
		'VLAN Prio',
2467
		$pconfig['dhcp6cvpt'],
2468
		$vlanprio
2469
	))->setHelp('Choose 802.1p priority to set.');
2470

    
2471
	$section->add($group);
2472
}
2473

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

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

    
2486
// DHCP6 client config - Advanced
2487

    
2488
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2489
$section->addClass('dhcp6advanced');
2490

    
2491
$section->addInput(new Form_Checkbox(
2492
	'adv_dhcp6_interface_statement_information_only_enable',
2493
	'Information only',
2494
	'Exchange Information Only',
2495
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2496
	'Selected'
2497
))->setHelp('Only exchange informational configuration parameters with servers.');
2498

    
2499
$section->addInput(new Form_Input(
2500
	'adv_dhcp6_interface_statement_send_options',
2501
	'Send options',
2502
	'text',
2503
	$pconfig['adv_dhcp6_interface_statement_send_options']
2504
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2505
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2506
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2507
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2508

    
2509
$section->addInput(new Form_Input(
2510
	'adv_dhcp6_interface_statement_request_options',
2511
	'Request Options',
2512
	'text',
2513
	$pconfig['adv_dhcp6_interface_statement_request_options']
2514
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2515
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2516

    
2517
$section->addInput(new Form_Input(
2518
	'adv_dhcp6_interface_statement_script',
2519
	'Scripts',
2520
	'text',
2521
	$pconfig['adv_dhcp6_interface_statement_script']
2522
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2523
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2524

    
2525
$group = new Form_Group('Identity Association Statement');
2526

    
2527
$group->add(new Form_Checkbox(
2528
	'adv_dhcp6_id_assoc_statement_address_enable',
2529
	null,
2530
	'Non-Temporary Address Allocation',
2531
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2532
	'Selected'
2533
));
2534

    
2535
$group->add(new Form_Input(
2536
	'adv_dhcp6_id_assoc_statement_address_id',
2537
	null,
2538
	'text',
2539
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2540
))->sethelp('id-assoc na ID');
2541

    
2542
$group->add(new Form_IpAddress(
2543
	'adv_dhcp6_id_assoc_statement_address',
2544
	null,
2545
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2546
	'V6'
2547
))->sethelp('IPv6 address');
2548

    
2549
$group->add(new Form_Input(
2550
	'adv_dhcp6_id_assoc_statement_address_pltime',
2551
	null,
2552
	'text',
2553
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2554
))->sethelp('pltime');
2555

    
2556
$group->add(new Form_Input(
2557
	'adv_dhcp6_id_assoc_statement_address_vltime',
2558
	null,
2559
	'text',
2560
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2561
))->sethelp('vltime');
2562

    
2563
$section->add($group);
2564

    
2565
// Prefix delegation
2566
$group = new Form_Group('');
2567

    
2568
$group->add(new Form_Checkbox(
2569
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2570
	null,
2571
	'Prefix Delegation ',
2572
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2573
	'Selected'
2574
));
2575

    
2576
$group->add(new Form_Input(
2577
	'adv_dhcp6_id_assoc_statement_prefix_id',
2578
	null,
2579
	'text',
2580
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2581
))->sethelp('id-assoc pd ID');
2582

    
2583
$group->add(new Form_IpAddress(
2584
	'adv_dhcp6_id_assoc_statement_prefix',
2585
	null,
2586
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2587
	'V6'
2588
))->sethelp('IPv6 prefix');
2589

    
2590
$group->add(new Form_Input(
2591
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2592
	null,
2593
	'text',
2594
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2595
))->sethelp('pltime');
2596

    
2597
$group->add(new Form_Input(
2598
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2599
	null,
2600
	'text',
2601
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2602
))->sethelp('vltime');
2603

    
2604
$section->add($group);
2605

    
2606
$group = new Form_Group('Prefix interface statement');
2607

    
2608
$group->add(new Form_Input(
2609
	'adv_dhcp6_prefix_interface_statement_sla_id',
2610
	null,
2611
	'text',
2612
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2613
))->sethelp('Prefix Interface sla-id');
2614

    
2615
$group->add(new Form_Input(
2616
	'adv_dhcp6_prefix_interface_statement_sla_len',
2617
	null,
2618
	'text',
2619
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2620
))->sethelp('sla-len');
2621

    
2622
$section->add($group);
2623

    
2624
$group = new Form_Group('Select prefix interface');
2625
$section->addInput(new Form_Select(
2626
	'adv_dhcp6_prefix_selected_interface',
2627
	'Prefix Interface',
2628
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2629
	$interfaces
2630
))->setHelp('Select the interface on which to apply the prefix delegation.');
2631

    
2632
$group = new Form_Group('Authentication statement');
2633

    
2634
$group->add(new Form_Input(
2635
	'adv_dhcp6_authentication_statement_authname',
2636
	null,
2637
	'text',
2638
	$pconfig['adv_dhcp6_authentication_statement_authname']
2639
))->sethelp('Authname');
2640

    
2641
$group->add(new Form_Input(
2642
	'adv_dhcp6_authentication_statement_protocol',
2643
	null,
2644
	'text',
2645
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2646
))->sethelp('Protocol');
2647

    
2648
$group->add(new Form_Input(
2649
	'adv_dhcp6_authentication_statement_algorithm',
2650
	null,
2651
	'text',
2652
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2653
))->sethelp('Algorithm');
2654

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

    
2662
$section->add($group);
2663

    
2664
$group = new Form_Group('Keyinfo statement');
2665

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

    
2673
$group->add(new Form_Input(
2674
	'adv_dhcp6_key_info_statement_realm',
2675
	null,
2676
	'text',
2677
	$pconfig['adv_dhcp6_key_info_statement_realm']
2678
))->sethelp('Realm');
2679

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

    
2682
$group = new Form_Group('');
2683

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

    
2691
$group->add(new Form_Input(
2692
	'adv_dhcp6_key_info_statement_secret',
2693
	null,
2694
	'text',
2695
	$pconfig['adv_dhcp6_key_info_statement_secret']
2696
))->sethelp('Secret');
2697

    
2698
$group->add(new Form_Input(
2699
	'adv_dhcp6_key_info_statement_expire',
2700
	null,
2701
	'text',
2702
	$pconfig['adv_dhcp6_key_info_statement_expire']
2703
))->sethelp('Expire');
2704

    
2705
$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>');
2706

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

    
2709
$form->add($section);
2710

    
2711
$section = new Form_Section('6RD Configuration');
2712
$section->addClass('_6rd');
2713

    
2714
$section->addInput(new Form_Input(
2715
	'prefix-6rd',
2716
	'6RD Prefix',
2717
	'text',
2718
	$pconfig['prefix-6rd']
2719
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2720

    
2721
$section->addInput(new Form_Input(
2722
	'gateway-6rd',
2723
	'*6RD Border relay',
2724
	'text',
2725
	$pconfig['gateway-6rd']
2726
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2727

    
2728
$section->addInput(new Form_Select(
2729
	'prefix-6rd-v4plen',
2730
	'6RD IPv4 Prefix length',
2731
	$pconfig['prefix-6rd-v4plen'],
2732
	array_combine(range(0, 32), range(0, 32))
2733
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2734

    
2735
$form->add($section);
2736

    
2737
// Track IPv6 ointerface section
2738
$section = new Form_Section('Track IPv6 Interface');
2739
$section->addClass('track6');
2740

    
2741
function build_ipv6interface_list() {
2742
	global $config, $form;
2743

    
2744
	$list = array('' => '');
2745

    
2746
	$interfaces = get_configured_interface_with_descr(true);
2747
	$dynv6ifs = array();
2748

    
2749
	foreach ($interfaces as $iface => $ifacename) {
2750
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2751
			case "6to4":
2752
			case "6rd":
2753
			case "dhcp6":
2754
				$dynv6ifs[$iface] = array(
2755
					'name' => $ifacename,
2756
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2757
				);
2758
				break;
2759
			default:
2760
				continue 2;
2761
		}
2762
	}
2763

    
2764
	foreach ($dynv6ifs as $iface => $ifacedata) {
2765
		$list[$iface] = $ifacedata['name'];
2766

    
2767
		$form->addGlobal(new Form_Input(
2768
			'ipv6-num-prefix-ids-' . $iface,
2769
			null,
2770
			'hidden',
2771
			$ifacedata['ipv6_num_prefix_ids']
2772
		));
2773
	}
2774

    
2775
	return($list);
2776
}
2777

    
2778
$section->addInput(new Form_Select(
2779
	'track6-interface',
2780
	'*IPv6 Interface',
2781
	$pconfig['track6-interface'],
2782
	build_ipv6interface_list()
2783
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2784

    
2785
if ($pconfig['track6-prefix-id'] == "") {
2786
	$pconfig['track6-prefix-id'] = 0;
2787
}
2788

    
2789
$section->addInput(new Form_Input(
2790
	'track6-prefix-id--hex',
2791
	'IPv6 Prefix ID',
2792
	'text',
2793
	sprintf("%x", $pconfig['track6-prefix-id'])
2794
))->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>');
2795

    
2796
$form->addGlobal(new Form_Input(
2797
	'track6-prefix-id-max',
2798
	null,
2799
	'hidden',
2800
	0
2801
));
2802

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

    
2805
/// PPP section
2806

    
2807
$section = new Form_Section('PPP Configuration');
2808
$section->addClass('ppp');
2809

    
2810
$section->addInput(new Form_Select(
2811
	'country',
2812
	'Country',
2813
	$pconfig['country'],
2814
	[]
2815
));
2816

    
2817
$section->addInput(new Form_Select(
2818
	'provider_list',
2819
	'Provider',
2820
	$pconfig['provider_list'],
2821
	[]
2822
));
2823

    
2824
$section->addInput(new Form_Select(
2825
	'providerplan',
2826
	'Plan',
2827
	$pconfig['providerplan'],
2828
	[]
2829
))->setHelp('Select to fill in service provider data.');
2830

    
2831
$section->addInput(new Form_Input(
2832
	'ppp_username',
2833
	'Username',
2834
	'text',
2835
	$pconfig['ppp_username'],
2836
	['autocomplete' => 'new-password']
2837
));
2838

    
2839
$section->addPassword(new Form_Input(
2840
	'ppp_password',
2841
	'Password',
2842
	'password',
2843
	$pconfig['ppp_password']
2844
));
2845

    
2846
$section->addInput(new Form_Input(
2847
	'phone',
2848
	'*Phone number',
2849
	'text',
2850
	$pconfig['phone']
2851
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2852

    
2853
$section->addInput(new Form_Input(
2854
	'apn',
2855
	'Access Point Name',
2856
	'text',
2857
	$pconfig['apn']
2858
));
2859

    
2860

    
2861
function build_port_list() {
2862
	$list = array("" => "None");
2863

    
2864
	$portlist = glob("/dev/cua*");
2865
	$modems	  = glob("/dev/modem*");
2866
	$portlist = array_merge($portlist, $modems);
2867

    
2868
	foreach ($portlist as $port) {
2869
		if (preg_match("/\.(lock|init)$/", $port)) {
2870
			continue;
2871
		}
2872

    
2873
	$list[trim($port)] = $port;
2874
	}
2875

    
2876
	return($list);
2877
}
2878

    
2879
$section->addInput(new Form_Select(
2880
	'port',
2881
	"*Modem port",
2882
	$pconfig['port'],
2883
	build_port_list()
2884
));
2885

    
2886
$section->addInput(new Form_Button(
2887
	'btnadvppp',
2888
	'Advanced PPP',
2889
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2890
	'fa-cog'
2891
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2892

    
2893
$form->add($section);
2894

    
2895
// PPPoE configuration
2896
$section = new Form_Section('PPPoE Configuration');
2897
$section->addClass('pppoe');
2898

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

    
2907
$section->addPassword(new Form_Input(
2908
	'pppoe_password',
2909
	'*Password',
2910
	'password',
2911
	$pconfig['pppoe_password']
2912
));
2913

    
2914
$section->addInput(new Form_Input(
2915
	'provider',
2916
	'Service name',
2917
	'text',
2918
	$pconfig['provider']
2919
))->setHelp('This field can usually be left empty.');
2920

    
2921
$section->addInput(new Form_Input(
2922
	'hostuniq',
2923
	'Host-Uniq',
2924
	'text',
2925
	$pconfig['hostuniq']
2926
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2927

    
2928
$section->addInput(new Form_Checkbox(
2929
	'pppoe_dialondemand',
2930
	'Dial on demand',
2931
	'Enable Dial-On-Demand mode ',
2932
	$pconfig['pppoe_dialondemand'],
2933
	'enable'
2934
));
2935

    
2936
$section->addInput(new Form_Input(
2937
	'pppoe_idletimeout',
2938
	'Idle timeout',
2939
	'number',
2940
	$pconfig['pppoe_idletimeout'],
2941
	['min' => 0]
2942
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2943
			'An idle timeout of zero disables this feature.');
2944

    
2945
$section->addInput(new Form_Select(
2946
	'pppoe-reset-type',
2947
	'Periodic reset',
2948
	$pconfig['pppoe-reset-type'],
2949
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2950
))->setHelp('Select a reset timing type.');
2951

    
2952
$group = new Form_Group('Custom reset');
2953
$group->addClass('pppoecustom');
2954

    
2955
$group->add(new Form_Input(
2956
	'pppoe_resethour',
2957
	null,
2958
	'number',
2959
	$pconfig['pppoe_resethour'],
2960
	['min' => 0, 'max' => 23]
2961
))->setHelp('Hour (0-23)');
2962

    
2963
$group->add(new Form_Input(
2964
	'pppoe_resetminute',
2965
	null,
2966
	'number',
2967
	$pconfig['pppoe_resetminute'],
2968
	['min' => 0, 'max' => 59]
2969
))->setHelp('Minutes (0-59)');
2970

    
2971
$group->add(new Form_Input(
2972
	'pppoe_resetdate',
2973
	null,
2974
	'text',
2975
	$pconfig['pppoe_resetdate']
2976
))->setHelp('Specific date (mm/dd/yyyy)');
2977

    
2978
$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');
2979

    
2980
$section->add($group);
2981

    
2982
$group = new Form_MultiCheckboxGroup('cron based reset');
2983
$group->addClass('pppoepreset');
2984

    
2985
$group->add(new Form_MultiCheckbox(
2986
	'pppoe_pr_preset_val',
2987
	null,
2988
	'Reset at each month ("0 0 1 * *")',
2989
	$pconfig['pppoe_monthly'],
2990
	'monthly'
2991
))->displayAsRadio();
2992

    
2993
$group->add(new Form_MultiCheckbox(
2994
	'pppoe_pr_preset_val',
2995
	null,
2996
	'Reset at each week ("0 0 * * 0")',
2997
	$pconfig['pppoe_weekly'],
2998
	'weekly'
2999
))->displayAsRadio();
3000

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

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

    
3017
$section->add($group);
3018

    
3019
$section->addInput(new Form_Button(
3020
	'btnadvppp',
3021
	'Advanced and MLPPP',
3022
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3023
	'fa-cog'
3024
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3025

    
3026
$form->add($section);
3027

    
3028
// PPTP & L2TP Configuration section
3029
$section = new Form_Section('PPTP/L2TP Configuration');
3030
$section->addClass('pptp');
3031

    
3032
$section->addInput(new Form_Input(
3033
	'pptp_username',
3034
	'*Username',
3035
	'text',
3036
	$pconfig['pptp_username'],
3037
	['autocomplete' => 'new-password']
3038
));
3039

    
3040
$section->addPassword(new Form_Input(
3041
	'pptp_password',
3042
	'*Password',
3043
	'password',
3044
	$pconfig['pptp_password']
3045
));
3046

    
3047
$group = new Form_Group('Shared Secret');
3048

    
3049
$group->add(new Form_Input(
3050
	'l2tp_secret',
3051
	'*Secret',
3052
	'password',
3053
	$pconfig['l2tp_secret']
3054
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3055
	    'important control packet contents. (Optional)');
3056

    
3057
$group->addClass('l2tp_secret');
3058
$section->add($group);
3059

    
3060
$section->addInput(new Form_IpAddress(
3061
	'pptp_local0',
3062
	'*Local IP address',
3063
	$pconfig['pptp_localip'][0],
3064
	'V4'
3065
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
3066

    
3067
$section->addInput(new Form_IpAddress(
3068
	'pptp_remote0',
3069
	'*Remote IP address',
3070
	$pconfig['pptp_remote'][0],
3071
	'HOSTV4'
3072
));
3073

    
3074
$section->addInput(new Form_Checkbox(
3075
	'pptp_dialondemand',
3076
	'Dial on demand',
3077
	'Enable Dial-On-Demand mode ',
3078
	$pconfig['pptp_dialondemand'],
3079
	'enable'
3080
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3081
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3082

    
3083
$section->addInput(new Form_Input(
3084
	'pptp_idletimeout',
3085
	'Idle timeout (seconds)',
3086
	'number',
3087
	$pconfig['pptp_idletimeout'],
3088
	['min' => 0]
3089
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3090
			'An idle timeout of zero disables this feature.');
3091

    
3092
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3093
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3094
} else {
3095
	$mlppp_text = "";
3096
}
3097

    
3098
$section->addInput(new Form_Button(
3099
	'btnadvppp',
3100
	'Advanced and MLPPP',
3101
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3102
	'fa-cog'
3103
))->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);
3104

    
3105
$form->add($section);
3106

    
3107
// Wireless interface
3108
if (isset($wancfg['wireless'])) {
3109

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

    
3112
	$section->addInput(new Form_Checkbox(
3113
		'persistcommonwireless',
3114
		'Persist common settings',
3115
		'Preserve common wireless configuration through interface deletions and reassignments.',
3116
		$pconfig['persistcommonwireless'],
3117
		'yes'
3118
	));
3119

    
3120
	$mode_list = ['auto' => 'Auto'];
3121

    
3122
	if (is_array($wl_modes)) {
3123
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3124
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3125
		}
3126
	}
3127

    
3128
	if (count($mode_list) == 1) {
3129
		$mode_list[''] = '';
3130
	}
3131

    
3132
	$section->addInput(new Form_Select(
3133
		'standard',
3134
		'Standard',
3135
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3136
		$mode_list
3137
	));
3138

    
3139
	if (isset($wl_modes['11g'])) {
3140
		$section->addInput(new Form_Select(
3141
			'protmode',
3142
			'802.11g OFDM Protection Mode',
3143
			$pconfig['protmode'],
3144
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3145
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3146
	} else {
3147
		$form->addGlobal(new Form_Input(
3148
			'protmode',
3149
			null,
3150
			'hidden',
3151
			'off'
3152
		));
3153
	}
3154

    
3155
	$mode_list = ['0' => gettext('Auto')];
3156

    
3157
	if (is_array($wl_modes)) {
3158
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3159
			if ($wl_standard == "11g") {
3160
				$wl_standard = "11b/g";
3161
			} else if ($wl_standard == "11ng") {
3162
				$wl_standard = "11b/g/n";
3163
			} else if ($wl_standard == "11na") {
3164
				$wl_standard = "11a/n";
3165
			}
3166

    
3167
			foreach ($wl_channels as $wl_channel) {
3168
				if (isset($wl_chaninfo[$wl_channel])) {
3169
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3170
				} else {
3171
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3172
				}
3173
			}
3174
		}
3175
	}
3176

    
3177
	$section->addInput(new Form_Select(
3178
		'channel',
3179
		'Channel',
3180
		$pconfig['channel'],
3181
		$mode_list
3182
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3183
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3184

    
3185
	$section->addInput(new Form_Select(
3186
		'channel_width',
3187
		'Channel width',
3188
		$pconfig['channel_width'],
3189
		$wl_ht_modes
3190
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3191

    
3192
	if (ANTENNAS) {
3193
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3194
			$group = new Form_Group('Antenna Settings');
3195

    
3196
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3197
				$group->add(new Form_Select(
3198
					'diversity',
3199
					null,
3200
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3201
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3202
				))->setHelp('Diversity');
3203
			}
3204

    
3205
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3206
				$group->add(new Form_Select(
3207
					'txantenna',
3208
					null,
3209
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3210
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3211
				))->setHelp('Transmit antenna');
3212
			}
3213

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

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

    
3225
			$section->add($group);
3226
		}
3227
	}
3228

    
3229
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3230
			$section->addInput(new Form_Input(
3231
				'distance',
3232
				'Distance setting (meters)',
3233
				'test',
3234
				$pconfig['distance']
3235
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3236
	}
3237

    
3238
	$form->add($section);
3239

    
3240
	// Regulatory settings
3241
	$section = new Form_Section('Regulatory Settings');
3242

    
3243
	$domain_list = array("" => 'Default');
3244

    
3245
	if (is_array($wl_regdomains)) {
3246
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3247
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3248
		}
3249
	}
3250

    
3251
	$section->addInput(new Form_Select(
3252
		'regdomain',
3253
		'Regulatory domain',
3254
		$pconfig['regdomain'],
3255
		$domain_list
3256
	))->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');
3257

    
3258
	$country_list = array('' => 'Default');
3259

    
3260
	if (is_array($wl_countries)) {
3261
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3262
			$country_list[	$wl_countries_attr[$wl_country_key]['ID']  ] = $wl_country['name'] ; //. ' -- (' . $wl_countries_attr[$wl_country_key]['ID'] . ', ' . strtoupper($wl_countries_attr[$wl_country_key]['rd'][0]['REF']);
3263
		}
3264
	}
3265

    
3266
	$section->addInput(new Form_Select(
3267
		'regcountry',
3268
		'Country',
3269
		$pconfig['regcountry'],
3270
		$country_list
3271
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3272

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

    
3284
	$form->add($section);
3285

    
3286
	$section = new Form_Section('Network-Specific Wireless Configuration');
3287

    
3288
	$section->addInput(new Form_Select(
3289
		'mode',
3290
		'Mode',
3291
		$pconfig['mode'],
3292
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3293
	));
3294

    
3295
	$section->addInput(new Form_Input(
3296
		'ssid',
3297
		'SSID',
3298
		'text',
3299
		$pconfig['ssid']
3300
	));
3301

    
3302
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3303
		$section->addInput(new Form_Select(
3304
			'puremode',
3305
			'Minimum wireless standard',
3306
			$pconfig['puremode'],
3307
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3308
		))->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)');
3309
	} elseif (isset($wl_modes['11g'])) {
3310
		$section->addInput(new Form_Checkbox(
3311
			'puremode',
3312
			'802.11g only',
3313
			null,
3314
			$pconfig['puremode'],
3315
			'11g'
3316
		))->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)');
3317
	}
3318

    
3319
	$section->addInput(new Form_Checkbox(
3320
		'apbridge_enable',
3321
		'Allow intra-BSS communication',
3322
		'Allow packets to pass between wireless clients directly when operating as an access point',
3323
		$pconfig['apbridge_enable'],
3324
		'yes'
3325
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3326

    
3327
	$section->addInput(new Form_Checkbox(
3328
		'wme_enable',
3329
		'Enable WME',
3330
		'Force the card to use WME (wireless QoS)',
3331
		$pconfig['wme_enable'],
3332
		'yes'
3333
	));
3334

    
3335
	$section->addInput(new Form_Checkbox(
3336
		'hidessid_enable',
3337
		'Hide SSID',
3338
		'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.)',
3339
		$pconfig['hidessid_enable'],
3340
		'yes'
3341
	));
3342

    
3343
	$form->add($section);
3344

    
3345
	// WPA Section
3346
	$section = new Form_Section('WPA');
3347

    
3348
	$section->addInput(new Form_Checkbox(
3349
		'wpa_enable',
3350
		'Enable',
3351
		'Enable WPA',
3352
		$pconfig['wpa_enable'],
3353
		'yes'
3354
	));
3355

    
3356
	$section->addInput(new Form_Select(
3357
		'wpa_mode',
3358
		'WPA mode',
3359
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3360
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3361
	));
3362

    
3363
	$section->addInput(new Form_Select(
3364
		'wpa_pairwise',
3365
		'WPA Pairwise',
3366
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3367
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3368
	));
3369

    
3370
	$section->addInput(new Form_Select(
3371
		'wpa_key_mgmt',
3372
		'WPA Key Management Mode',
3373
		$pconfig['wpa_key_mgmt'],
3374
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3375
	));
3376

    
3377
	$section->addInput(new Form_Input(
3378
		'passphrase',
3379
		'WPA Pre-Shared Key',
3380
		'text',
3381
		$pconfig['passphrase']
3382
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3383

    
3384
	$section->addInput(new Form_Select(
3385
		'wpa_eap_client_mode',
3386
		'EAP Client Mode',
3387
		$pconfig['wpa_eap_client_mode'],
3388
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3389
	));
3390

    
3391
	$section->addInput(new Form_Select(
3392
		'wpa_eap_ca',
3393
		'Certificate Authority',
3394
		$pconfig['wpa_eap_ca'],
3395
		cert_build_list('ca', 'HTTPS')
3396
	));
3397

    
3398
	$section->addInput(new Form_Select(
3399
		'wpa_eap_inner_auth',
3400
		'Inner Authentication Method',
3401
		$pconfig['wpa_eap_inner_auth'],
3402
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3403
	));
3404

    
3405
	$section->addInput(new Form_Input(
3406
		'wpa_eap_inner_id',
3407
		'*Inner Authentication Identity',
3408
		'text',
3409
		$pconfig['wpa_eap_inner_id']
3410
	));
3411

    
3412
	$section->addInput(new Form_Input(
3413
		'wpa_eap_inner_password',
3414
		'*Inner Authentication Passphrase',
3415
		'text',
3416
		$pconfig['wpa_eap_inner_password']
3417
	));
3418

    
3419
	$section->addInput(new Form_Select(
3420
		'wpa_eap_cert',
3421
		'TLS/TTLS Client Certificate',
3422
		$pconfig['wpa_eap_cert'],
3423
		cert_build_list('cert', 'HTTPS')
3424
	));
3425

    
3426
	$section->addInput(new Form_Input(
3427
		'wpa_group_rekey',
3428
		'Group Key Rotation',
3429
		'number',
3430
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3431
		['min' => '1', 'max' => 9999]
3432
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3433

    
3434
	$section->addInput(new Form_Input(
3435
		'wpa_gmk_rekey',
3436
		'Group Master Key Regeneration',
3437
		'number',
3438
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3439
		['min' => '1', 'max' => 9999]
3440
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3441

    
3442
	$section->addInput(new Form_Checkbox(
3443
		'wpa_strict_rekey',
3444
		'Strict Key Regeneration',
3445
		'Force the AP to rekey whenever a client disassociates',
3446
		$pconfig['wpa_strict_rekey'],
3447
		'yes'
3448
	));
3449

    
3450
	$form->add($section);
3451

    
3452
	$section = new Form_Section('802.1x RADIUS Options');
3453
	$section->addClass('ieee8021x_group');
3454

    
3455
	$section->addInput(new Form_Checkbox(
3456
		'ieee8021x',
3457
		'IEEE802.1X',
3458
		'Enable 802.1X authentication',
3459
		$pconfig['ieee8021x'],
3460
		'yes'
3461
	));
3462

    
3463
	$group = new Form_Group('Primary 802.1X server');
3464

    
3465
	$group->add(new Form_IpAddress(
3466
		'auth_server_addr',
3467
		'IP Address',
3468
		$pconfig['auth_server_addr']
3469
	))->setHelp('IP address of the RADIUS server');
3470

    
3471
	$group->add(new Form_Input(
3472
		'auth_server_port',
3473
		'Port',
3474
		'number',
3475
		$pconfig['auth_server_port']
3476
	))->setHelp('Server auth port. Default is 1812');
3477

    
3478
	$group->add(new Form_Input(
3479
		'auth_server_shared_secret',
3480
		'Shared Secret',
3481
		'text',
3482
		$pconfig['auth_server_shared_secret']
3483
	))->setHelp('RADIUS Shared secret for this firewall');
3484

    
3485
	$section->add($group);
3486

    
3487
	$group = new Form_Group('Secondary 802.1X server');
3488

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

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

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

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

    
3511
	$section->addInput(new Form_Checkbox(
3512
		'rsn_preauth',
3513
		'Authentication Roaming Preauth',
3514
		null,
3515
		$pconfig['rsn_preauth'],
3516
		'yes'
3517
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3518

    
3519
	$form->add($section);
3520
}
3521

    
3522
$section = new Form_Section('Reserved Networks');
3523

    
3524
$section->addInput(new Form_Checkbox(
3525
	'blockpriv',
3526
	'Block private networks and loopback addresses',
3527
	'',
3528
	$pconfig['blockpriv'],
3529
	'yes'
3530
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3531
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3532
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3533

    
3534
$section->addInput(new Form_Checkbox(
3535
	'blockbogons',
3536
	'Block bogon networks',
3537
	'',
3538
	$pconfig['blockbogons'],
3539
	'yes'
3540
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3541
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3542
			'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' .
3543
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3544

    
3545
$form->add($section);
3546

    
3547
$form->addGlobal(new Form_Input(
3548
	'if',
3549
	null,
3550
	'hidden',
3551
	$if
3552
));
3553

    
3554
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3555
	$form->addGlobal(new Form_Input(
3556
		'ppp_port',
3557
		null,
3558
		'hidden',
3559
		$pconfig['port']
3560
	));
3561
}
3562

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

    
3570

    
3571
// Add new gateway modal pop-up
3572
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3573

    
3574
$modal->addInput(new Form_Checkbox(
3575
	'defaultgw4',
3576
	'Default',
3577
	'Default gateway',
3578
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3579
));
3580

    
3581
$modal->addInput(new Form_Input(
3582
	'gatewayname4',
3583
	'Gateway name',
3584
	'text',
3585
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3586
));
3587

    
3588
$modal->addInput(new Form_IpAddress(
3589
	'gatewayip4',
3590
	'Gateway IPv4',
3591
	$gateway_settings4['gateway'],
3592
	'V4'
3593
));
3594

    
3595
$modal->addInput(new Form_Input(
3596
	'gatewaydescr4',
3597
	'Description',
3598
	'text',
3599
	$gateway_settings4['descr']
3600
));
3601

    
3602
$btnaddgw4 = new Form_Button(
3603
	'add4',
3604
	'Add',
3605
	null,
3606
	'fa-plus'
3607
);
3608

    
3609
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3610

    
3611
$btncnxgw4 = new Form_Button(
3612
	'cnx4',
3613
	'Cancel',
3614
	null,
3615
	'fa-undo'
3616
);
3617

    
3618
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3619

    
3620
$modal->addInput(new Form_StaticText(
3621
	null,
3622
	$btnaddgw4 . $btncnxgw4
3623
));
3624

    
3625
$form->add($modal);
3626

    
3627
print($form);
3628
?>
3629

    
3630
<script type="text/javascript">
3631
//<![CDATA[
3632
events.push(function() {
3633
	function updateType(t) {
3634

    
3635
		switch (t) {
3636
			case "none": {
3637
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3638
				break;
3639
			}
3640
			case "staticv4": {
3641
				$('.dhcpadvanced, .none, .dhcp').hide();
3642
				$('.pppoe, .pptp, .ppp').hide();
3643
				break;
3644
			}
3645
			case "dhcp": {
3646
				$('.dhcpadvanced, .none').hide();
3647
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3648
										//			about the staticv4 class
3649
				$('.pppoe, .pptp, .ppp').hide();
3650
				break;
3651
			}
3652
			case "ppp": {
3653
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3654
				country_list();
3655
				break;
3656
			}
3657
			case "pppoe": {
3658
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3659
				break;
3660
			}
3661
			case "l2tp": {
3662
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3663
				$('.pptp, .l2tp_secret').show();
3664
				break;
3665
			}
3666
			case "pptp": {
3667
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3668
				$('.pptp').show();
3669
				break;
3670
			}
3671
		}
3672

    
3673
		if (t != "l2tp" && t != "pptp") {
3674
			$('.'+t).show();
3675
		}
3676
	}
3677

    
3678
	function updateTypeSix(t) {
3679
		if (!isNaN(t[0])) {
3680
			t = '_' + t;
3681
		}
3682

    
3683
		switch (t) {
3684
			case "none": {
3685
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3686
				break;
3687
			}
3688
			case "staticv6": {
3689
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3690
				break;
3691
			}
3692
			case "slaac": {
3693
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3694
				break;
3695
			}
3696
			case "dhcp6": {
3697
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3698
				break;
3699
			}
3700
			case "_6rd": {
3701
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3702
				break;
3703
			}
3704
			case "_6to4": {
3705
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3706
				break;
3707
			}
3708
			case "track6": {
3709
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3710
				update_track6_prefix();
3711
				break;
3712
			}
3713
		}
3714

    
3715
		if (t != "l2tp" && t != "pptp") {
3716
			$('.'+t).show();
3717
		}
3718
	}
3719

    
3720
	function show_reset_settings(reset_type) {
3721
		if (reset_type == 'preset') {
3722
			$('.pppoepreset').show();
3723
			$('.pppoecustom').hide();
3724
		} else if (reset_type == 'custom') {
3725
			$('.pppoecustom').show();
3726
			$('.pppoepreset').hide();
3727
		} else {
3728
			$('.pppoecustom').hide();
3729
			$('.pppoepreset').hide();
3730
		}
3731
	}
3732

    
3733
	function update_track6_prefix() {
3734
		var iface = $("#track6-interface").val();
3735
		if (iface == null) {
3736
			return;
3737
		}
3738

    
3739
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3740
		if (track6_prefix_ids == null) {
3741
			return;
3742
		}
3743

    
3744
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3745
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3746
	}
3747

    
3748
	function addOption_v4() {
3749
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3750
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3751
	}
3752

    
3753
	function addOption_v6() {
3754
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3755
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3756
	}
3757

    
3758
	function addSelectboxOption(selectbox, text, value) {
3759
		var optn = document.createElement("OPTION");
3760
		optn.text = text;
3761
		optn.value = value;
3762
		selectbox.append(optn);
3763
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3764
	}
3765

    
3766
	function country_list() {
3767
		$('#country').children().remove();
3768
		$('#provider_list').children().remove();
3769
		$('#providerplan').children().remove();
3770
		$.ajax("getserviceproviders.php",{
3771
			success: function(response) {
3772

    
3773
				var responseTextArr = response.split("\n");
3774
				responseTextArr.sort();
3775

    
3776
				responseTextArr.forEach( function(value) {
3777
					country = value.split(":");
3778
					$('#country').append($('<option>', {
3779
						value: country[1],
3780
						text : country[0]
3781
					}));
3782
				});
3783
			}
3784
		});
3785
	}
3786

    
3787
	function providers_list() {
3788
		$('#provider_list').children().remove();
3789
		$('#providerplan').children().remove();
3790
		$.ajax("getserviceproviders.php",{
3791
			type: 'post',
3792
			data: {country : $('#country').val()},
3793
			success: function(response) {
3794
				var responseTextArr = response.split("\n");
3795
				responseTextArr.sort();
3796
				responseTextArr.forEach( function(value) {
3797
					$('#provider_list').append($('<option>', {
3798
							value: value,
3799
							text : value
3800
					}));
3801
				});
3802
			}
3803
		});
3804
	}
3805

    
3806
	function providerplan_list() {
3807
		$('#providerplan').children().remove();
3808
		$.ajax("getserviceproviders.php",{
3809
			type: 'post',
3810
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3811
			success: function(response) {
3812
				var responseTextArr = response.split("\n");
3813
				responseTextArr.sort();
3814

    
3815
				$('#providerplan').append($('<option>', {
3816
					value: '',
3817
					text : ''
3818
				}));
3819

    
3820
				responseTextArr.forEach( function(value) {
3821
					if (value != "") {
3822
						providerplan = value.split(":");
3823

    
3824
						$('#providerplan').append($('<option>', {
3825
							value: providerplan[1],
3826
							text : providerplan[0] + " - " + providerplan[1]
3827
						}));
3828
					}
3829
				});
3830
			}
3831
		});
3832
	}
3833

    
3834
	function prefill_provider() {
3835
		$.ajax("getserviceproviders.php",{
3836
			type: 'post',
3837
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3838
			success: function(data, textStatus, response) {
3839
				var xmldoc = response.responseXML;
3840
				var provider = xmldoc.getElementsByTagName('connection')[0];
3841
				$('#ppp_username').val('');
3842
				$('#ppp_password').val('');
3843
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3844
					$('#phone').val('#777');
3845
					$('#apn').val('');
3846
				} else {
3847
					$('#phone').val('*99#');
3848
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3849
				}
3850
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3851
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3852
				$('#ppp_username').val(ppp_username);
3853
				$('#ppp_password').val(ppp_password);
3854
			}
3855
		});
3856
	}
3857

    
3858
	function show_dhcp6adv() {
3859
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3860
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3861

    
3862
		hideCheckbox('dhcp6usev4iface', ovr);
3863
		hideCheckbox('dhcp6prefixonly', ovr);
3864
		hideInput('dhcp6-ia-pd-len', ovr);
3865
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3866
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3867

    
3868
		hideClass('dhcp6advanced', !adv || ovr);
3869
	}
3870

    
3871
	function setDHCPoptions() {
3872
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3873
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3874

    
3875
		if (ovr) {
3876
			hideInput('dhcphostname', true);
3877
			hideIpAddress('alias-address', true);
3878
			hideInput('dhcprejectfrom', true);
3879
			hideInput('adv_dhcp_config_file_override_path', false);
3880
			hideClass('dhcpadvanced', true);
3881
		} else {
3882
			hideInput('dhcphostname', false);
3883
			hideIpAddress('alias-address', false);
3884
			hideInput('dhcprejectfrom', false);
3885
			hideInput('adv_dhcp_config_file_override_path', true);
3886
			hideClass('dhcpadvanced', !adv);
3887
		}
3888
	}
3889

    
3890
	// DHCP preset actions
3891
	// Set presets from value of radio buttons
3892
	function setPresets(val) {
3893
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3894
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3895
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3896
		if (val == "SavedCfg")	setPresetsnow("<?=htmlspecialchars($pconfig['adv_dhcp_pt_timeout']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_retry']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_select_timeout']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_reboot']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_backoff_cutoff']);?>", "<?=htmlspecialchars($pconfig['adv_dhcp_pt_initial_interval']);?>");
3897
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3898
	}
3899

    
3900
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3901
		$('#adv_dhcp_pt_timeout').val(timeout);
3902
		$('#adv_dhcp_pt_retry').val(retry);
3903
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3904
		$('#adv_dhcp_pt_reboot').val(reboot);
3905
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3906
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3907
	}
3908

    
3909
	function setPPPoEDialOnDemandItems() {
3910
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3911
	}
3912

    
3913
	function setPPTPDialOnDemandItems() {
3914
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3915
	}
3916

    
3917
	function show_wpaoptions() {
3918
		var wpa = !($('#wpa_enable').prop('checked'));
3919

    
3920
		hideInput('passphrase', wpa);
3921
		hideInput('wpa_mode', wpa);
3922
		hideInput('wpa_key_mgmt', wpa);
3923
		hideInput('wpa_pairwise', wpa);
3924
		hideCheckbox('wpa_strict_rekey', wpa);
3925
		hideClass('ieee8021x_group', true);
3926
		if ($('#mode').val() == 'hostap') {
3927
			hideInput('wpa_group_rekey', wpa);
3928
			hideInput('wpa_gmk_rekey', wpa);
3929
			hideCheckbox('wpa_strict_rekey', wpa);
3930
		} else {
3931
			hideInput('wpa_group_rekey', true);
3932
			hideInput('wpa_gmk_rekey', true);
3933
			hideCheckbox('wpa_strict_rekey', true);
3934
		}
3935
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3936
	}
3937

    
3938
	function updatewifistandard(s) {
3939
		switch (s) {
3940
			case "auto": {
3941
				hideInput('protmode', false);
3942
				hideInput('channel_width', false);
3943
				break;
3944
			}
3945
			case "11b": {
3946
				hideInput('protmode', true);
3947
				hideInput('channel_width', true);
3948
				break;
3949
			}
3950
			case "11g": {
3951
				hideInput('protmode', false);
3952
				hideInput('channel_width', true);
3953
				break;
3954
			}
3955
			case "11ng": {
3956
				hideInput('protmode', false);
3957
				hideInput('channel_width', false);
3958
				break;
3959
			}
3960
			case "11a": {
3961
				hideInput('protmode', true);
3962
				hideInput('channel_width', true);
3963
				break;
3964
			}
3965
			case "11na": {
3966
				hideInput('protmode', true);
3967
				hideInput('channel_width', false);
3968
				break;
3969
			}
3970
			default: {
3971
				break;
3972
			}
3973
		}
3974
	}
3975

    
3976
	function updatewifimode(m) {
3977
		switch (m) {
3978
			case "adhoc": {
3979
				hideInput('puremode', true);
3980
				hideCheckbox('apbridge_enable', true);
3981
				hideCheckbox('hidessid_enable', false);
3982
				break;
3983
			}
3984
			case "hostap": {
3985
				hideInput('puremode', false);
3986
				hideCheckbox('apbridge_enable', false);
3987
				hideCheckbox('hidessid_enable', false);
3988
				break;
3989
			}
3990
			default: {
3991
				hideInput('puremode', true);
3992
				hideCheckbox('apbridge_enable', true);
3993
				hideCheckbox('hidessid_enable', true);
3994
				break;
3995
			}
3996
		}
3997
		show_wpaoptions();
3998
	}
3999

    
4000
	function updateeapclientmode(m) {
4001
		var wpa = !($('#wpa_enable').prop('checked'));
4002
		switch (m) {
4003
			case "peap": {
4004
				hideInput('wpa_eap_cert', true);
4005
				hideInput('wpa_eap_inner_auth', wpa);
4006
				hideInput('wpa_eap_inner_id', wpa);
4007
				hideInput('wpa_eap_inner_password', wpa);
4008
				break;
4009
			}
4010
			case "tls": {
4011
				hideInput('wpa_eap_cert', wpa);
4012
				hideInput('wpa_eap_inner_auth', true);
4013
				hideInput('wpa_eap_inner_id', true);
4014
				hideInput('wpa_eap_inner_password', true);
4015
				break;
4016
			}
4017
			case "ttls": {
4018
				hideInput('wpa_eap_cert', wpa);
4019
				hideInput('wpa_eap_inner_auth', wpa);
4020
				hideInput('wpa_eap_inner_id', wpa);
4021
				hideInput('wpa_eap_inner_password', wpa);
4022
				break;
4023
			}
4024
			default: {
4025
				break;
4026
			}
4027
		}
4028
	}
4029

    
4030
	function updatewpakeymgmt(m) {
4031
		var wpa = !($('#wpa_enable').prop('checked'));
4032
		if ((m == "WPA-EAP") && ($('#mode').val() == 'bss')) {
4033
			hideInput('passphrase', true);
4034
			hideInput('wpa_eap_client_mode', false);
4035
			hideInput('wpa_eap_ca', false);
4036
			updateeapclientmode($('#wpa_eap_client_mode').val());
4037
		} else if ((m != "WPA-PSK") && ($('#mode').val() == 'hostap')) {
4038
			hideClass('ieee8021x_group', false);
4039
		} else {
4040
			hideInput('passphrase', wpa);
4041
			hideInput('wpa_eap_client_mode', true);
4042
			hideInput('wpa_eap_ca', true);
4043
			hideInput('wpa_eap_cert', true);
4044
			hideInput('wpa_eap_inner_auth', true);
4045
			hideInput('wpa_eap_inner_id', true);
4046
			hideInput('wpa_eap_inner_password', true);
4047
			hideClass('ieee8021x_group', true);
4048
		}
4049
	}
4050

    
4051
	// ---------- On initial page load ------------------------------------------------------------
4052

    
4053
	updateType($('#type').val());
4054
	updateTypeSix($('#type6').val());
4055
	show_reset_settings($('#pppoe-reset-type').val());
4056
	hideClass('dhcp6advanced', true);
4057
	hideClass('dhcpadvanced', true);
4058
	show_dhcp6adv();
4059
	setDHCPoptions();
4060
	setPPPoEDialOnDemandItems();
4061
	setPPTPDialOnDemandItems();
4062
	show_wpaoptions();
4063
	updatewifistandard($('#standard').val());
4064
	updatewifimode($('#mode').val());
4065
	updatewpakeymgmt($('#wpa_key_mgmt').val());
4066
	updateeapclientmode($('#wpa_eap_client_mode').val());
4067

    
4068
	// Set preset buttons on page load
4069
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4070
	if (sv == "") {
4071
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4072
	} else {
4073
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4074
	}
4075

    
4076
	// Set preset from value
4077
	setPresets(sv);
4078

    
4079
	// If the user wants to add a gateway, then add that to the gateway selection
4080
	if ($("#gatewayip4").val() != '') {
4081
		addOption_v4();
4082
	}
4083
	if ($("#gatewayip6").val() != '') {
4084
		addOption_v6();
4085
	}
4086

    
4087
	// ---------- Click checkbox handlers ---------------------------------------------------------
4088

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

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

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

    
4101
	$('#mode').on('change', function() {
4102
		updatewifimode(this.value);
4103
	});
4104

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

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

    
4113
	$('#track6-interface').on('change', function() {
4114
		update_track6_prefix();
4115
	});
4116

    
4117
	$('#pppoe-reset-type').on('change', function() {
4118
		show_reset_settings(this.value);
4119
	});
4120

    
4121
	$("#add4").click(function() {
4122
		addOption_v4();
4123
		$("#newgateway4").modal('hide');
4124
	});
4125

    
4126
	$("#cnx4").click(function() {
4127
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4128
		$("#gatewayip4").val('');
4129
		$("#gatewaydescr4").val('');
4130
		$("#defaultgw4").prop("checked", false);
4131
		$("#newgateway4").modal('hide');
4132
	});
4133

    
4134
	$("#add6").click(function() {
4135
		addOption_v6();
4136
		$("#newgateway6").modal('hide');
4137
	});
4138

    
4139
	$("#cnx6").click(function() {
4140
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4141
		$("#gatewayip6").val('');
4142
		$("#gatewaydescr6").val('');
4143
		$("#defaultgw6").prop("checked", false);
4144
		$("#newgateway6").modal('hide');
4145
	});
4146

    
4147
	$('#country').on('change', function() {
4148
		providers_list();
4149
	});
4150

    
4151
	$('#provider_list').on('change', function() {
4152
		providerplan_list();
4153
	});
4154

    
4155
	$('#providerplan').on('change', function() {
4156
		prefill_provider();
4157
	});
4158

    
4159
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4160
		setDHCPoptions();
4161
	});
4162

    
4163
	$('#adv_dhcp6_config_advanced').click(function () {
4164
		show_dhcp6adv();
4165
	});
4166

    
4167
	$('#adv_dhcp6_config_file_override').click(function () {
4168
		show_dhcp6adv();
4169
	});
4170

    
4171
	// On click . .
4172
	$('#pppoe_dialondemand').click(function () {
4173
		setPPPoEDialOnDemandItems();
4174
	});
4175

    
4176
	$('#pptp_dialondemand').click(function () {
4177
		setPPTPDialOnDemandItems();
4178
	});
4179

    
4180
	$('[name=adv_dhcp_pt_values]').click(function () {
4181
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4182
	});
4183

    
4184
	$('#wpa_enable').click(function () {
4185
		show_wpaoptions();
4186
	});
4187

    
4188
	$('#pppoe_resetdate').datepicker();
4189

    
4190
});
4191
//]]>
4192
</script>
4193

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