Project

General

Profile

Download (132 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-2020 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
		} else {
282
			$pconfig['type'] = "none";
283
		}
284
		break;
285
}
286

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

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

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

    
428
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
429

    
430
}
431

    
432
$changes_applied = false;
433

    
434
if ($_POST['apply']) {
435
	unset($input_errors);
436
	if (!is_subsystem_dirty('interfaces')) {
437
		$input_errors[] = gettext("The settings have already been applied!");
438
	} else {
439
		$retval = 0;
440
		unlink_if_exists("{$g['tmp_path']}/config.cache");
441
		clear_subsystem_dirty('interfaces');
442

    
443
		$vlan_redo = false;
444
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
445
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
446
			foreach ($toapplylist as $ifapply => $ifcfgo) {
447
				if (isset($config['interfaces'][$ifapply]['enable'])) {
448
					interface_bring_down($ifapply, false, $ifcfgo);
449
					interface_configure($ifapply, true);
450
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
451
						/* call interface_track6_configure with linkup true so
452
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
453
						   just call interface_configure with linkup true as
454
						   that skips bridge membership addition.
455
						*/
456
						$wancfg = $config['interfaces'][$ifapply];
457
						interface_track6_configure($ifapply, $wancfg, true);
458
					}
459
				} else {
460
					interface_bring_down($ifapply, true, $ifcfgo);
461
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
462
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
463
						services_dhcpd_configure();
464
					}
465
				}
466
				if (interface_has_clones(get_real_interface($ifapply))) {
467
					$vlan_redo = true;
468
				}
469
			}
470
		}
471

    
472
		/*
473
		 * If the parent interface has changed above, the VLANs needs to be
474
		 * redone.
475
		 */
476
		if ($vlan_redo) {
477
			interfaces_vlan_configure();
478
		}
479

    
480
		/* restart snmp so that it binds to correct address */
481
		$retval |= services_snmpd_configure();
482

    
483
		/* sync filter configuration */
484
		setup_gateways_monitor();
485

    
486
		clear_subsystem_dirty('interfaces');
487

    
488
		$retval |= filter_configure();
489

    
490
		enable_rrd_graphing();
491

    
492
		$changes_applied = true;
493

    
494
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
495
			clear_subsystem_dirty('staticroutes');
496
		}
497
	}
498
	@unlink("{$g['tmp_path']}/.interfaces.apply");
499
} else if ($_POST['save']) {
500

    
501
	unset($input_errors);
502
	$pconfig = $_POST;
503

    
504
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
505
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
506
	} else {
507
		$pconfig['track6-prefix-id'] = 0;
508
	}
509

    
510
	/* filter out spaces from descriptions */
511
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
512

    
513
	/* okay first of all, cause we are just hiding the PPPoE HTML
514
	 * fields related to PPPoE resets, we are going to unset $_POST
515
	 * vars, if the reset feature should not be used. Otherwise the
516
	 * data validation procedure below, may trigger a false error
517
	 * message.
518
	 */
519
	if (empty($_POST['pppoe-reset-type'])) {
520
		unset($_POST['pppoe_pr_type']);
521
		unset($_POST['pppoe_resethour']);
522
		unset($_POST['pppoe_resetminute']);
523
		unset($_POST['pppoe_resetdate']);
524
		unset($_POST['pppoe_pr_preset_val']);
525
	}
526

    
527
	/* input validation */
528
	$reqdfields = explode(" ", "descr");
529
	$reqdfieldsn = array(gettext("Description"));
530
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
531

    
532
	if (!$input_errors) {
533
		/* description unique? */
534
		foreach ($ifdescrs as $ifent => $ifdescr) {
535
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
536
				$input_errors[] = gettext("An interface with the specified description already exists.");
537
				break;
538
			}
539
		}
540

    
541
		/* Is the description already used as an alias name? */
542
		if (is_array($config['aliases']['alias'])) {
543
			foreach ($config['aliases']['alias'] as $alias) {
544
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
545
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
546
				}
547
			}
548
		}
549

    
550
		/* Is the description already used as an interface group name? */
551
		if (is_array($config['ifgroups']['ifgroupentry'])) {
552
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
553
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
554
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
555
				}
556
			}
557
		}
558

    
559
		if (is_numeric($_POST['descr'])) {
560
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
561
		}
562

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

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

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

    
583
	if ($_POST['blockbogons'] == "yes" &&
584
	    isset($config['system']['ipv6allow']) &&
585
	    (!isset($config['system']['maximumtableentries']) ||
586
	     $config['system']['maximumtableentries'] <
587
	     $g['minimumtableentries_bogonsv6'])) {
588
		$input_errors[] = sprintf(gettext(
589
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
590
		    $g['minimumtableentries_bogonsv6']);
591
	}
592

    
593
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
594
		if (!preg_match("/^staticv4/", $_POST['type'])) {
595
			$input_errors[] = gettext("The DHCP Server is active " .
596
			    "on this interface and it can be used only with " .
597
			    "a static IP configuration. Please disable the " .
598
			    "DHCP Server service on this interface first, " .
599
			    "then change the interface configuration.");
600
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
601
			$input_errors[] = gettext("The DHCP Server is active " .
602
			    "on this interface and it can be used only with " .
603
			    "IPv4 subnet < 31. Please disable the " .
604
			    "DHCP Server service on this interface first, " .
605
			    "then change the interface configuration.");
606
		}
607
	}
608
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
609
		$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only with a static IPv6 configuration. Please disable the DHCPv6 Server service on this interface first, then change the interface configuration.");
610
	}
611

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

    
719
			if (empty($_POST['track6-interface'])) {
720
				$input_errors[] = gettext("A valid interface to track must be selected.");
721
			}
722

    
723
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
724
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
725
			} else {
726
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
727
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
728
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
729
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
730
				} else {
731
					foreach ($ifdescrs as $ifent => $ifdescr) {
732
						if ($if == $ifent) {
733
							continue;
734
						}
735
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
736
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
737
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
738
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
739
						}
740
					}
741
				}
742
			}
743
			break;
744
	}
745

    
746
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
747
	$staticroutes = get_staticroutes(true);
748
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
749
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
750
		if (!is_ipaddrv4($_POST['ipaddr'])) {
751
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
752
		} else {
753
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
754
			if (count($where_ipaddr_configured)) {
755
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
756
				foreach ($where_ipaddr_configured as $subnet_conflict) {
757
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
758
				}
759
				$input_errors[] = $subnet_conflict_text;
760
			}
761

    
762
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
763
			if ($_POST['subnet'] < 31) {
764
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
765
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
766
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
767
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
768
				}
769
			}
770

    
771
			foreach ($staticroutes as $route_subnet) {
772
				list($network, $subnet) = explode("/", $route_subnet);
773
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
774
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
775
					break;
776
				}
777
				unset($network, $subnet);
778
			}
779
		}
780
	}
781
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
782
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
783

    
784
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
785
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
786
		} else {
787
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
788
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
789
			}
790
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
791
			if (count($where_ipaddr_configured)) {
792
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
793
				foreach ($where_ipaddr_configured as $subnet_conflict) {
794
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
795
				}
796
				$input_errors[] = $subnet_conflict_text;
797
			}
798

    
799
			foreach ($staticroutes as $route_subnet) {
800
				list($network, $subnet) = explode("/", $route_subnet);
801
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
802
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
803
					break;
804
				}
805
				unset($network, $subnet);
806
			}
807
		}
808
	}
809
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
810
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
811
	}
812
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
813
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
814
	}
815
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
816
		$input_errors[] = gettext("A valid alias IP address must be specified.");
817
	}
818
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
819
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
820
	}
821
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
822
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
823
	}
824

    
825
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
826
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
827
		$match = false;
828
		foreach ($a_gateways as $gateway) {
829
			if (in_array($_POST['gateway'], $gateway)) {
830
				$match = true;
831
			}
832
		}
833
		if (!$match) {
834
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
835
		}
836
	}
837
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
838
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
839
		$match = false;
840
		foreach ($a_gateways as $gateway) {
841
			if (in_array($_POST['gatewayv6'], $gateway)) {
842
				$match = true;
843
			}
844
		}
845
		if (!$match) {
846
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
847
		}
848
	}
849

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

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

    
904
		unset($min_mtu, $max_mtu);
905

    
906
		if (interface_is_vlan($wancfg['if']) != NULL) {
907
			$realhwif_array = get_parent_interface($wancfg['if']);
908
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
909
			$parent_realhwif = $realhwif_array[0];
910
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
911
			$mtu = 0;
912
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
913
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
914
			if ($mtu == 0)
915
				$mtu = get_interface_mtu($parent_realhwif);
916
			if ($_POST['mtu'] > $mtu)
917
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
918
		} else {
919
			foreach ($config['interfaces'] as $idx => $ifdata) {
920
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
921
					continue;
922
				}
923

    
924
				$realhwif_array = get_parent_interface($ifdata['if']);
925
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
926
				$parent_realhwif = $realhwif_array[0];
927

    
928
				if ($parent_realhwif != $wancfg['if']) {
929
					continue;
930
				}
931

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

    
1028
		if ($_POST['passphrase']) {
1029
			$passlen = strlen($_POST['passphrase']);
1030
			if ($passlen < 8 || $passlen > 63) {
1031
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1032
			}
1033
		}
1034

    
1035
		if ($_POST['wpa_enable'] == "yes") {
1036
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1037
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1038
			}
1039
		}
1040
	}
1041

    
1042
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1043
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1044
	}
1045

    
1046
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1047
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1048
	}
1049

    
1050
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1051
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1052
	}
1053

    
1054
	if ($_POST['gatewayip4']) {
1055
		// The user wants to add an IPv4 gateway - validate the settings
1056
		$gateway_settings4 = array();
1057

    
1058
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1059
		$gateway_settings4['interface'] = $_POST['if'];
1060
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1061
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1062
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1063
		$gateway_settings4['ipprotocol'] = 'inet';
1064
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1065
		foreach ($gw_input_errors as $input_error_text) {
1066
			$input_errors[] = $input_error_text;
1067
		}
1068
	}
1069

    
1070
	if ($_POST['gatewayip6']) {
1071
		// The user wants to add an IPv6 gateway - validate the settings
1072
		$gateway_settings6 = array();
1073

    
1074
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1075
		$gateway_settings6['interface'] = $_POST['if'];
1076
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1077
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1078
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1079
		$gateway_settings6['ipprotocol'] = 'inet6';
1080
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1081
		foreach ($gw_input_errors as $input_error_text) {
1082
			$input_errors[] = $input_error_text;
1083
		}
1084
	}
1085

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

    
1093
		if ($wancfg['ipaddr'] != $_POST['type']) {
1094
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1095
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1096
				unset($a_ppps[$pppid]);
1097
			} else if ($wancfg['ipaddr'] == "dhcp") {
1098
				kill_dhclient_process($wancfg['if']);
1099
			}
1100
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1101
				kill_dhcp6client_process($wancfg['if'],true);
1102
			}
1103
		}
1104
		$ppp = array();
1105
		if ($wancfg['ipaddr'] != "ppp") {
1106
			unset($wancfg['ipaddr']);
1107
		}
1108
		if ($wancfg['ipaddrv6'] != "ppp") {
1109
			unset($wancfg['ipaddrv6']);
1110
		}
1111
		unset($wancfg['subnet']);
1112
		unset($wancfg['gateway']);
1113
		unset($wancfg['subnetv6']);
1114
		unset($wancfg['gatewayv6']);
1115
		unset($wancfg['dhcphostname']);
1116
		unset($wancfg['dhcprejectfrom']);
1117
		unset($wancfg['dhcp6-duid']);
1118
		unset($wancfg['dhcp6-ia-pd-len']);
1119
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1120
		unset($wancfg['dhcp6prefixonly']);
1121
		unset($wancfg['dhcp6usev4iface']);
1122
		unset($wancfg['slaacusev4iface']);
1123
		unset($wancfg['ipv6usev4iface']);
1124
		unset($wancfg['dhcp6debug']);
1125
		unset($wancfg['track6-interface']);
1126
		unset($wancfg['track6-prefix-id']);
1127
		unset($wancfg['dhcp6withoutra']);
1128
		unset($wancfg['dhcp6norelease']);
1129
		unset($wancfg['dhcp6vlanenable']);
1130
		unset($wancfg['dhcp6cvpt']);
1131
		unset($wancfg['prefix-6rd']);
1132
		unset($wancfg['prefix-6rd-v4plen']);
1133
		unset($wancfg['gateway-6rd']);
1134

    
1135
		unset($wancfg['dhcpvlanenable']);
1136
		unset($wancfg['dhcpcvpt']);
1137

    
1138
		unset($wancfg['adv_dhcp_pt_timeout']);
1139
		unset($wancfg['adv_dhcp_pt_retry']);
1140
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1141
		unset($wancfg['adv_dhcp_pt_reboot']);
1142
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1143
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1144

    
1145
		unset($wancfg['adv_dhcp_pt_values']);
1146

    
1147
		unset($wancfg['adv_dhcp_send_options']);
1148
		unset($wancfg['adv_dhcp_request_options']);
1149
		unset($wancfg['adv_dhcp_required_options']);
1150
		unset($wancfg['adv_dhcp_option_modifiers']);
1151

    
1152
		unset($wancfg['adv_dhcp_config_advanced']);
1153
		unset($wancfg['adv_dhcp_config_file_override']);
1154
		unset($wancfg['adv_dhcp_config_file_override_path']);
1155

    
1156
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1157
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1158
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1159
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1160

    
1161
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1162
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1163
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1164
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1165
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1166

    
1167
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1168
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1169
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1170
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1171
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1172

    
1173
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1174
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1175
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1176

    
1177
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1178
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1179
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1180
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1181

    
1182
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1183
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1184
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1185
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1186
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1187

    
1188
		unset($wancfg['adv_dhcp6_config_advanced']);
1189
		unset($wancfg['adv_dhcp6_config_file_override']);
1190
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1191

    
1192
		unset($wancfg['pppoe_password']);
1193
		unset($wancfg['pptp_username']);
1194
		unset($wancfg['pptp_password']);
1195
		unset($wancfg['l2tp_secret']);
1196
		unset($wancfg['provider']);
1197
		unset($wancfg['hostuniq']);
1198
		unset($wancfg['ondemand']);
1199
		unset($wancfg['timeout']);
1200
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1201
			unset($wancfg['pppoe']['pppoe-reset-type']);
1202
		}
1203
		unset($wancfg['local']);
1204

    
1205
		unset($wancfg['remote']);
1206
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1207
			if ($wancfg['ipaddr'] != 'ppp') {
1208
				unset($a_ppps[$pppid]['apn']);
1209
				unset($a_ppps[$pppid]['phone']);
1210
				unset($a_ppps[$pppid]['provider']);
1211
				unset($a_ppps[$pppid]['ondemand']);
1212
			}
1213
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1214
				unset($a_ppps[$pppid]['localip']);
1215
				unset($a_ppps[$pppid]['subnet']);
1216
				unset($a_ppps[$pppid]['gateway']);
1217
			}
1218
			if ($wancfg['ipaddr'] != 'pppoe') {
1219
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1220
				unset($a_ppps[$pppid]['hostuniq']);
1221
			}
1222
			if ($wancfg['type'] != $_POST['type']) {
1223
				unset($a_ppps[$pppid]['idletimeout']);
1224
			}
1225
		}
1226

    
1227
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1228
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1229

    
1230
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1231
		switch ($_POST['type']) {
1232
			case "staticv4":
1233
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1234
				$wancfg['subnet'] = $_POST['subnet'];
1235
				if ($_POST['gateway'] != "none") {
1236
					$wancfg['gateway'] = $_POST['gateway'];
1237
				}
1238
				break;
1239
			case "dhcp":
1240
				$wancfg['ipaddr'] = "dhcp";
1241
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1242
				$wancfg['alias-address'] = $_POST['alias-address'];
1243
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1244
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1245

    
1246
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1247
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1248
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1249
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1250
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1251
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1252

    
1253
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1254

    
1255
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1256
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1257
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1258
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1259

    
1260
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1261
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1262
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1263

    
1264
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1265
				if ($gateway_item) {
1266
					$a_gateways[] = $gateway_item;
1267
				}
1268
				if ($_POST['dhcpvlanenable'] == "yes") {
1269
					$wancfg['dhcpvlanenable'] = true;
1270
				}
1271
				if (!empty($_POST['dhcpcvpt'])) {
1272
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1273
				} else {
1274
					unset($wancfg['dhcpcvpt']);
1275
				}
1276
				break;
1277
			case "ppp":
1278
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1279
				$a_ppps[$pppid]['type'] = $_POST['type'];
1280
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1281
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1282
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1283
				if ($_POST['ppp_password'] != DMYPWD) {
1284
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1285
				}
1286
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1287
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1288
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1289
				$wancfg['ipaddr'] = $_POST['type'];
1290
				break;
1291

    
1292
			case "pppoe":
1293
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1294
				$a_ppps[$pppid]['type'] = $_POST['type'];
1295
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1296
				if (isset($_POST['ppp_port'])) {
1297
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1298
				} else {
1299
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1300
				}
1301
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1302
				if ($_POST['pppoe_password'] != DMYPWD) {
1303
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1304
				}
1305
				if (!empty($_POST['provider'])) {
1306
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1307
				} else {
1308
					$a_ppps[$pppid]['provider'] = true;
1309
				}
1310
				if (!empty($_POST['hostuniq'])) {
1311
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1312
				} else {
1313
					$a_ppps[$pppid]['hostuniq'] = true;
1314
				}
1315
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1316
				if (!empty($_POST['pppoe_idletimeout'])) {
1317
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1318
				} else {
1319
					unset($a_ppps[$pppid]['idletimeout']);
1320
				}
1321

    
1322
				if (!empty($_POST['pppoe-reset-type'])) {
1323
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1324
				} else {
1325
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1326
				}
1327
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1328
				$wancfg['ipaddr'] = $_POST['type'];
1329
				if ($gateway_item) {
1330
					$a_gateways[] = $gateway_item;
1331
				}
1332

    
1333
				break;
1334
			case "pptp":
1335
			case "l2tp":
1336
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1337
				$a_ppps[$pppid]['type'] = $_POST['type'];
1338
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1339
				if (isset($_POST['ppp_port'])) {
1340
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1341
				} else {
1342
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1343
				}
1344
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1345
				if ($_POST['pptp_password'] != DMYPWD) {
1346
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1347
				}
1348
				if (($_POST['type'] == 'l2tp') && (!empty($_POST['l2tp_secret']))) {
1349
					$a_ppps[$pppid]['secret'] = base64_encode($_POST['l2tp_secret']);
1350
				} else {
1351
					unset($a_ppps[$pppid]['secret']);
1352
				}
1353
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1354
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1355
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1356
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1357
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1358
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1359
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1360
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1361
				if (!empty($_POST['pptp_idletimeout'])) {
1362
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1363
				} else {
1364
					unset($a_ppps[$pppid]['idletimeout']);
1365
				}
1366
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1367
				$wancfg['ipaddr'] = $_POST['type'];
1368
				if ($gateway_item) {
1369
					$a_gateways[] = $gateway_item;
1370
				}
1371
				break;
1372
			case "none":
1373
				break;
1374
		}
1375
		switch ($_POST['type6']) {
1376
			case "staticv6":
1377
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1378
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1379
				if ($_POST['ipv6usev4iface'] == "yes") {
1380
					$wancfg['ipv6usev4iface'] = true;
1381
				}
1382
				if ($_POST['gatewayv6'] != "none") {
1383
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1384
				}
1385
				break;
1386
			case "slaac":
1387
				$wancfg['ipaddrv6'] = "slaac";
1388
				if ($_POST['slaacusev4iface'] == "yes") {
1389
					$wancfg['slaacusev4iface'] = true;
1390
				}
1391
				break;
1392
			case "dhcp6":
1393
				$wancfg['ipaddrv6'] = "dhcp6";
1394
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1395
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1396
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1397
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1398
				}
1399
				if ($_POST['dhcp6prefixonly'] == "yes") {
1400
					$wancfg['dhcp6prefixonly'] = true;
1401
				}
1402
				if ($_POST['dhcp6usev4iface'] == "yes") {
1403
					$wancfg['dhcp6usev4iface'] = true;
1404
				}
1405
				if ($_POST['dhcp6debug'] == "yes") {
1406
					$wancfg['dhcp6debug'] = true;
1407
				}
1408

    
1409
				if ($_POST['dhcp6withoutra'] == "yes") {
1410
					$wancfg['dhcp6withoutra'] = true;
1411
				}
1412
				if ($_POST['dhcp6norelease'] == "yes") {
1413
					$wancfg['dhcp6norelease'] = true;
1414
				}
1415
				if ($_POST['dhcp6vlanenable'] == "yes") {
1416
					$wancfg['dhcp6vlanenable'] = true;
1417
				}
1418
				if (!empty($_POST['dhcp6cvpt'])) {
1419
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1420
				} else {
1421
					unset($wancfg['dhcp6cvpt']);
1422
				}
1423

    
1424
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1425
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1426
				}
1427
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1428
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1429
				}
1430
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1431
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1432
				}
1433
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1434
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1435
				}
1436

    
1437
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1438
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1439
				}
1440
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1441
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1442
				}
1443
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1444
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1445
				}
1446
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1447
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1448
				}
1449
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1450
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1451
				}
1452

    
1453
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1454
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1455
				}
1456
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1457
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1458
				}
1459
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1460
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1461
				}
1462
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1463
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1464
				}
1465
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1466
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1467
				}
1468

    
1469
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1470
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1471
				}
1472
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1473
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1474
				}
1475
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1476
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1477
				}
1478
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1479
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1480
				}
1481
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1482
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1483
				}
1484
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1485
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1486
				}
1487
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1488
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1489
				}
1490

    
1491
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1492
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1493
				}
1494
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1495
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1496
				}
1497
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1498
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1499
				}
1500
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1501
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1502
				}
1503
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1504
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1505
				}
1506

    
1507
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1508
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1509
				}
1510
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1511
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1512
				}
1513
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1514
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1515
				}
1516

    
1517
				if ($gateway_item) {
1518
					$a_gateways[] = $gateway_item;
1519
				}
1520
				break;
1521
			case "6rd":
1522
				$wancfg['ipaddrv6'] = "6rd";
1523
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1524
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1525
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1526
				if ($gateway_item) {
1527
					$a_gateways[] = $gateway_item;
1528
				}
1529
				break;
1530
			case "6to4":
1531
				$wancfg['ipaddrv6'] = "6to4";
1532
				break;
1533
			case "track6":
1534
				$wancfg['ipaddrv6'] = "track6";
1535
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1536
				if ($_POST['track6-prefix-id--hex'] === "") {
1537
					$wancfg['track6-prefix-id'] = 0;
1538
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1539
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1540
				} else {
1541
					$wancfg['track6-prefix-id'] = 0;
1542
				}
1543
				break;
1544
			case "none":
1545
				break;
1546
		}
1547
		handle_pppoe_reset($_POST);
1548

    
1549
		if ($_POST['blockpriv'] == "yes") {
1550
			$wancfg['blockpriv'] = true;
1551
		} else {
1552
			unset($wancfg['blockpriv']);
1553
		}
1554
		if ($_POST['blockbogons'] == "yes") {
1555
			$wancfg['blockbogons'] = true;
1556
		} else {
1557
			unset($wancfg['blockbogons']);
1558
		}
1559
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1560
		if (empty($_POST['mtu'])) {
1561
			unset($wancfg['mtu']);
1562
		} else {
1563
			$wancfg['mtu'] = $_POST['mtu'];
1564
		}
1565
		if (empty($_POST['mss'])) {
1566
			unset($wancfg['mss']);
1567
		} else {
1568
			$wancfg['mss'] = $_POST['mss'];
1569
		}
1570
		if (empty($_POST['mediaopt'])) {
1571
			unset($wancfg['media']);
1572
			unset($wancfg['mediaopt']);
1573
		} else {
1574
			$mediaopts = explode(' ', $_POST['mediaopt']);
1575
			if ($mediaopts[0] != '') {
1576
				$wancfg['media'] = $mediaopts[0];
1577
			}
1578
			if ($mediaopts[1] != '') {
1579
				$wancfg['mediaopt'] = $mediaopts[1];
1580
			} else {
1581
				unset($wancfg['mediaopt']);
1582
			}
1583
		}
1584
		if (isset($wancfg['wireless'])) {
1585
			handle_wireless_post();
1586
		}
1587

    
1588
		write_config();
1589

    
1590
		if ($_POST['gatewayip4']) {
1591
			save_gateway($gateway_settings4);
1592
		}
1593

    
1594
		if ($_POST['gatewayip6']) {
1595
			save_gateway($gateway_settings6);
1596
		}
1597

    
1598
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1599
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1600
		} else {
1601
			$toapplylist = array();
1602
		}
1603
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1604
		$toapplylist[$if]['ppps'] = $old_ppps;
1605
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1606

    
1607
		mark_subsystem_dirty('interfaces');
1608

    
1609
		/* regenerate cron settings/crontab file */
1610
		configure_cron();
1611

    
1612
		header("Location: interfaces.php?if={$if}");
1613
		exit;
1614
	}
1615

    
1616
} // end if ($_POST['save'])
1617

    
1618
function handle_wireless_post() {
1619
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1620
	if (!is_array($wancfg['wireless'])) {
1621
		$wancfg['wireless'] = array();
1622
	}
1623
	$wancfg['wireless']['standard'] = $_POST['standard'];
1624
	$wancfg['wireless']['mode'] = $_POST['mode'];
1625
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1626
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1627
	$wancfg['wireless']['channel'] = $_POST['channel'];
1628
	$wancfg['wireless']['channel_width'] = $_POST['channel_width'];
1629
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1630
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1631
	$wancfg['wireless']['distance'] = $_POST['distance'];
1632
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1633
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1634
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1635
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1636
		foreach ($wl_countries_attr as $wl_country) {
1637
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1638
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1639
				break;
1640
			}
1641
		}
1642
	}
1643
	if (!is_array($wancfg['wireless']['wpa'])) {
1644
		$wancfg['wireless']['wpa'] = array();
1645
	}
1646
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1647
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1648
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1649
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1650
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1651
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1652
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1653
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1654
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1655
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1656
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1657
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1658
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1659
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1660

    
1661
	if ($_POST['persistcommonwireless'] == "yes") {
1662
		if (!is_array($config['wireless'])) {
1663
			$config['wireless'] = array();
1664
		}
1665
		if (!is_array($config['wireless']['interfaces'])) {
1666
			$config['wireless']['interfaces'] = array();
1667
		}
1668
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1669
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1670
		}
1671
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1672
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1673
	}
1674
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1675
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1676
	} else if (isset($wancfg['wireless']['diversity'])) {
1677
		unset($wancfg['wireless']['diversity']);
1678
	}
1679
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1680
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1681
	} else if (isset($wancfg['wireless']['txantenna'])) {
1682
		unset($wancfg['wireless']['txantenna']);
1683
	}
1684
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1685
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1686
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1687
		unset($wancfg['wireless']['rxantenna']);
1688
	}
1689
	if ($_POST['hidessid_enable'] == "yes") {
1690
		$wancfg['wireless']['hidessid']['enable'] = true;
1691
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1692
		unset($wancfg['wireless']['hidessid']['enable']);
1693
	}
1694
	if ($_POST['mac_acl_enable'] == "yes") {
1695
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1696
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1697
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1698
	}
1699
	if ($_POST['rsn_preauth'] == "yes") {
1700
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1701
	} else {
1702
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1703
	}
1704
	if ($_POST['ieee8021x'] == "yes") {
1705
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1706
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1707
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1708
	}
1709
	if ($_POST['wpa_strict_rekey'] == "yes") {
1710
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1711
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1712
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1713
	}
1714
	if ($_POST['debug_mode'] == "yes") {
1715
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1716
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1717
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1718
	}
1719
	if ($_POST['wpa_enable'] == "yes") {
1720
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1721
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1722
		unset($wancfg['wireless']['wpa']['enable']);
1723
	}
1724

    
1725
	if ($_POST['wme_enable'] == "yes") {
1726
		if (!is_array($wancfg['wireless']['wme'])) {
1727
			$wancfg['wireless']['wme'] = array();
1728
		}
1729
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1730
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1731
		unset($wancfg['wireless']['wme']['enable']);
1732
	}
1733
	if ($_POST['puremode'] == "11g") {
1734
		if (!is_array($wancfg['wireless']['pureg'])) {
1735
			$wancfg['wireless']['pureg'] = array();
1736
		}
1737
		$wancfg['wireless']['pureg']['enable'] = true;
1738
	} else if ($_POST['puremode'] == "11n") {
1739
		if (!is_array($wancfg['wireless']['puren'])) {
1740
			$wancfg['wireless']['puren'] = array();
1741
		}
1742
		$wancfg['wireless']['puren']['enable'] = true;
1743
	} else {
1744
		if (isset($wancfg['wireless']['pureg'])) {
1745
			unset($wancfg['wireless']['pureg']);
1746
		}
1747
		if (isset($wancfg['wireless']['puren'])) {
1748
			unset($wancfg['wireless']['puren']);
1749
		}
1750
	}
1751
	if ($_POST['apbridge_enable'] == "yes") {
1752
		if (!is_array($wancfg['wireless']['apbridge'])) {
1753
			$wancfg['wireless']['apbridge'] = array();
1754
		}
1755
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1756
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1757
		unset($wancfg['wireless']['apbridge']['enable']);
1758
	}
1759
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1760
		if (!is_array($wancfg['wireless']['turbo'])) {
1761
			$wancfg['wireless']['turbo'] = array();
1762
		}
1763
		$wancfg['wireless']['turbo']['enable'] = true;
1764
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1765
		unset($wancfg['wireless']['turbo']['enable']);
1766
	}
1767

    
1768
	interface_sync_wireless_clones($wancfg, true);
1769
}
1770

    
1771
function check_wireless_mode() {
1772
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1773

    
1774
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1775
		return;
1776
	}
1777

    
1778
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1779
		$clone_count = 1;
1780
	} else {
1781
		$clone_count = 0;
1782
	}
1783

    
1784
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1785
		foreach ($config['wireless']['clone'] as $clone) {
1786
			if ($clone['if'] == $wlanbaseif) {
1787
				$clone_count++;
1788
			}
1789
		}
1790
	}
1791

    
1792
	if ($clone_count > 1) {
1793
		$old_wireless_mode = $wancfg['wireless']['mode'];
1794
		$wancfg['wireless']['mode'] = $_POST['mode'];
1795
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1796
			$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']]);
1797
		} else {
1798
			pfSense_interface_destroy("{$wlanif}_");
1799
		}
1800
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1801
	}
1802
}
1803

    
1804
// Find all possible media options for the interface
1805
$mediaopts_list = array();
1806
$intrealname = $config['interfaces'][$if]['if'];
1807
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1808
foreach ($mediaopts as $mediaopt) {
1809
	preg_match("/media (.*)/", $mediaopt, $matches);
1810
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1811
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1812
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1813
	} else {
1814
		// there is only media like "media 1000baseT"
1815
		array_push($mediaopts_list, $matches[1]);
1816
	}
1817
}
1818

    
1819
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1820
$shortcut_section = "interfaces";
1821

    
1822
$types4 = array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP"), "ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP"));
1823
$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"));
1824

    
1825
// Get the MAC address
1826
$defgatewayname4 = $wancfg['descr'] . "GW";
1827
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1828

    
1829
function build_mediaopts_list() {
1830
	global $mediaopts_list;
1831

    
1832
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1833
			 " " =>	 gettext("------- Media Supported by this interface -------")
1834
			];
1835

    
1836
	foreach ($mediaopts_list as $mediaopt) {
1837
		$list[$mediaopt] = $mediaopt;
1838
	}
1839

    
1840
	return($list);
1841
}
1842

    
1843
function build_gateway_list() {
1844
	global $a_gateways, $if;
1845

    
1846
	$list = array("none" => gettext("None"));
1847
	foreach ($a_gateways as $gateway) {
1848
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1849
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1850
		}
1851
	}
1852

    
1853
	return($list);
1854
}
1855

    
1856
function build_gatewayv6_list() {
1857
	global $a_gateways, $if;
1858

    
1859
	$list = array("none" => gettext("None"));
1860
	foreach ($a_gateways as $gateway) {
1861
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1862
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1863
		}
1864
	}
1865

    
1866
	return($list);
1867
}
1868

    
1869
include("head.inc");
1870

    
1871
if ($input_errors) {
1872
	print_input_errors($input_errors);
1873
}
1874

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

    
1881
if ($changes_applied) {
1882
	print_apply_result_box($retval);
1883
}
1884

    
1885
$form = new Form();
1886

    
1887
$section = new Form_Section('General Configuration');
1888

    
1889
$section->addInput(new Form_Checkbox(
1890
	'enable',
1891
	'Enable',
1892
	'Enable interface',
1893
	$pconfig['enable'],
1894
	'yes'
1895
));
1896

    
1897
$section->addInput(new Form_Input(
1898
	'descr',
1899
	'*Description',
1900
	'text',
1901
	$pconfig['descr']
1902
))->setHelp('Enter a description (name) for the interface here.');
1903

    
1904
if ($show_address_controls) {
1905
	$section->addInput(new Form_Select(
1906
		'type',
1907
		'IPv4 Configuration Type',
1908
		$pconfig['type'],
1909
		$types4
1910
	));
1911
	$section->addInput(new Form_Select(
1912
		'type6',
1913
		'IPv6 Configuration Type',
1914
		$pconfig['type6'],
1915
		$types6
1916
	));
1917
} else {
1918
	$section->addInput(new Form_StaticText(
1919
		'IPv4/IPv6 Configuration',
1920
		"This interface type does not support manual address configuration on this page. "
1921
	));
1922
	$form->addGlobal(new Form_Input(
1923
		'type',
1924
		null,
1925
		'hidden',
1926
		'none'
1927
	));
1928
	$form->addGlobal(new Form_Input(
1929
		'type6',
1930
		null,
1931
		'hidden',
1932
		'none'
1933
	));
1934
}
1935

    
1936
$macaddress = new Form_Input(
1937
	'spoofmac',
1938
	'MAC Address',
1939
	'text',
1940
	$pconfig['spoofmac'],
1941
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1942
);
1943

    
1944
if (interface_is_vlan($realifname)) {
1945
	$macaddress->setDisabled();
1946
	$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
1947
	    'set on its parent interface');
1948
} else {
1949
	$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
1950
	    'MAC address of this interface.%sEnter a MAC address in the ' .
1951
	    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1952
}
1953

    
1954
$section->addInput($macaddress);
1955

    
1956
$section->addInput(new Form_Input(
1957
	'mtu',
1958
	'MTU',
1959
	'number',
1960
	$pconfig['mtu']
1961
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1962
			'This is typically 1500 bytes but can vary in some circumstances.');
1963

    
1964
$section->addInput(new Form_Input(
1965
	'mss',
1966
	'MSS',
1967
	'number',
1968
	$pconfig['mss']
1969
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1970
			'header size) will be in effect.');
1971

    
1972
if (count($mediaopts_list) > 0) {
1973
	$section->addInput(new Form_Select(
1974
		'mediaopt',
1975
		'Speed and Duplex',
1976
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1977
		build_mediaopts_list()
1978
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1979
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1980
}
1981

    
1982
$form->add($section);
1983

    
1984
$section = new Form_Section('Static IPv4 Configuration');
1985
$section->addClass('staticv4');
1986

    
1987
$section->addInput(new Form_IpAddress(
1988
	'ipaddr',
1989
	'*IPv4 Address',
1990
	$pconfig['ipaddr'],
1991
	'V4'
1992
))->addMask('subnet', $pconfig['subnet'], 32);
1993

    
1994
$group = new Form_Group('IPv4 Upstream gateway');
1995

    
1996
$group->add(new Form_Select(
1997
	'gateway',
1998
	'IPv4 Upstream Gateway',
1999
	$pconfig['gateway'],
2000
	build_gateway_list()
2001
));
2002

    
2003
$group->add(new Form_Button(
2004
	'addgw4',
2005
	'Add a new gateway',
2006
	null,
2007
	'fa-plus'
2008
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2009

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

    
2014
$section->add($group);
2015

    
2016
$form->add($section);
2017

    
2018
$section = new Form_Section('SLAAC IPv6 Configuration');
2019
$section->addClass('slaac');
2020

    
2021
$section->addInput(new Form_Checkbox(
2022
	'slaacusev4iface',
2023
	'Use IPv4 connectivity as parent interface',
2024
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2025
	$pconfig['slaacusev4iface']
2026
));
2027

    
2028
$form->add($section);
2029

    
2030
$section = new Form_Section('Static IPv6 Configuration');
2031
$section->addClass('staticv6');
2032

    
2033
$section->addInput(new Form_IpAddress(
2034
	'ipaddrv6',
2035
	'*IPv6 address',
2036
	$pconfig['ipaddrv6'],
2037
	'V6'
2038
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2039

    
2040
$section->addInput(new Form_Checkbox(
2041
	'ipv6usev4iface',
2042
	'Use IPv4 connectivity as parent interface',
2043
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2044
	$pconfig['ipv6usev4iface']
2045
));
2046

    
2047
$group = new Form_Group('IPv6 Upstream gateway');
2048

    
2049
$group->add(new Form_Select(
2050
	'gatewayv6',
2051
	'IPv6 Upstream Gateway',
2052
	$pconfig['gatewayv6'],
2053
	build_gatewayv6_list()
2054
));
2055

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

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

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

    
2069
// Add new gateway modal pop-up for IPv6
2070
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2071

    
2072
$modal->addInput(new Form_Checkbox(
2073
	'defaultgw6',
2074
	'Default',
2075
	'Default gateway',
2076
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2077
));
2078

    
2079
$modal->addInput(new Form_Input(
2080
	'gatewayname6',
2081
	'Gateway name',
2082
	'text',
2083
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2084
));
2085

    
2086
$modal->addInput(new Form_IpAddress(
2087
	'gatewayip6',
2088
	'Gateway IPv6',
2089
	$gateway_settings6['gateway'],
2090
	'V6'
2091
));
2092

    
2093
$modal->addInput(new Form_Input(
2094
	'gatewaydescr6',
2095
	'Description',
2096
	'text',
2097
	$gateway_settings6['descr']
2098
));
2099

    
2100
$btnaddgw6 = new Form_Button(
2101
	'add6',
2102
	'Add',
2103
	null,
2104
	'fa-plus'
2105
);
2106

    
2107
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2108

    
2109
$btncnxgw6 = new Form_Button(
2110
	'cnx6',
2111
	'Cancel',
2112
	null,
2113
	'fa-undo'
2114
);
2115

    
2116
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2117

    
2118
$modal->addInput(new Form_StaticText(
2119
	null,
2120
	$btnaddgw6 . $btncnxgw6
2121
));
2122

    
2123
$form->add($modal);
2124

    
2125
// ==== DHCP client configuration =============================
2126

    
2127
$section = new Form_Section('DHCP Client Configuration');
2128
$section->addClass('dhcp');
2129

    
2130
$group = new Form_Group('Options');
2131

    
2132
$group->add(new Form_Checkbox(
2133
	'adv_dhcp_config_advanced',
2134
	null,
2135
	'Advanced Configuration',
2136
	$pconfig['adv_dhcp_config_advanced']
2137
))->setHelp('Use advanced DHCP configuration options.');
2138

    
2139
$group->add(new Form_Checkbox(
2140
	'adv_dhcp_config_file_override',
2141
	null,
2142
	'Configuration Override',
2143
	$pconfig['adv_dhcp_config_file_override']
2144
))->setHelp('Override the configuration from this file.');
2145

    
2146
$section->add($group);
2147

    
2148
$section->addInput(new Form_Input(
2149
	'dhcphostname',
2150
	'Hostname',
2151
	'text',
2152
	$pconfig['dhcphostname']
2153
))->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).');
2154

    
2155
$section->addInput(new Form_IpAddress(
2156
	'alias-address',
2157
	'Alias IPv4 address',
2158
	$pconfig['alias-address'],
2159
	'V4'
2160
))->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.');
2161

    
2162
$section->addInput(new Form_Input(
2163
	'dhcprejectfrom',
2164
	'Reject leases from',
2165
	'text',
2166
	$pconfig['dhcprejectfrom']
2167
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2168
			'(separate multiple entries with a comma). ' .
2169
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2170

    
2171
if (interface_is_vlan($wancfg['if']) != NULL) {
2172

    
2173
	$group = new Form_Group('DHCP VLAN Priority');
2174
	$group->add(new Form_Checkbox(
2175
		'dhcpvlanenable',
2176
		null,
2177
		'Enable dhcpclient VLAN Priority tagging',
2178
		$pconfig['dhcpvlanenable']
2179
	))->setHelp('Normally off unless specifically required by the ISP.');
2180

    
2181
	$group->add(new Form_Select(
2182
		'dhcpcvpt',
2183
		'VLAN Prio',
2184
		$pconfig['dhcpcvpt'],
2185
		$vlanprio
2186
	))->setHelp('Choose 802.1p priority to set.');
2187

    
2188
	$section->add($group);
2189
}
2190

    
2191
$group = new Form_Group('Protocol timing');
2192
$group->addClass('dhcpadvanced');
2193

    
2194
$group->add(new Form_Input(
2195
	'adv_dhcp_pt_timeout',
2196
	null,
2197
	'number',
2198
	$pconfig['adv_dhcp_pt_timeout']
2199
))->setHelp('Timeout');
2200

    
2201
$group->add(new Form_Input(
2202
	'adv_dhcp_pt_retry',
2203
	null,
2204
	'number',
2205
	$pconfig['adv_dhcp_pt_retry']
2206
))->setHelp('Retry');
2207

    
2208
$group->add(new Form_Input(
2209
	'adv_dhcp_pt_select_timeout',
2210
	null,
2211
	'number',
2212
	$pconfig['adv_dhcp_pt_select_timeout'],
2213
	['min' => 0]
2214
))->setHelp('Select timeout');
2215

    
2216
$group->add(new Form_Input(
2217
	'adv_dhcp_pt_reboot',
2218
	null,
2219
	'number',
2220
	$pconfig['adv_dhcp_pt_reboot']
2221
))->setHelp('Reboot');
2222

    
2223
$group->add(new Form_Input(
2224
	'adv_dhcp_pt_backoff_cutoff',
2225
	null,
2226
	'number',
2227
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2228
))->setHelp('Backoff cutoff');
2229

    
2230
$group->add(new Form_Input(
2231
	'adv_dhcp_pt_initial_interval',
2232
	null,
2233
	'number',
2234
	$pconfig['adv_dhcp_pt_initial_interval']
2235
))->setHelp('Initial interval');
2236

    
2237
$section->add($group);
2238

    
2239
$group = new Form_Group('Presets');
2240
$group->addClass('dhcpadvanced');
2241

    
2242
$group->add(new Form_Checkbox(
2243
	'adv_dhcp_pt_values',
2244
	null,
2245
	'FreeBSD default',
2246
	null,
2247
	'DHCP'
2248
))->displayAsRadio();
2249

    
2250
$group->add(new Form_Checkbox(
2251
	'adv_dhcp_pt_values',
2252
	null,
2253
	'Clear',
2254
	null,
2255
	'Clear'
2256
))->displayAsRadio();
2257

    
2258
$group->add(new Form_Checkbox(
2259
	'adv_dhcp_pt_values',
2260
	null,
2261
	'pfSense Default',
2262
	null,
2263
	'pfSense'
2264
))->displayAsRadio();
2265

    
2266
$group->add(new Form_Checkbox(
2267
	'adv_dhcp_pt_values',
2268
	null,
2269
	'Saved Cfg',
2270
	null,
2271
	'SavedCfg'
2272
))->displayAsRadio();
2273

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

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

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

    
2289
$form->add($section);
2290

    
2291
$section = new Form_Section('Lease Requirements and Requests');
2292
$section->addClass('dhcpadvanced');
2293

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

    
2304
$section->addInput(new Form_Input(
2305
	'adv_dhcp_request_options',
2306
	'Request options',
2307
	'text',
2308
	$pconfig['adv_dhcp_request_options']
2309
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2310
			'Some ISPs may require certain options be or not be requested.', '<br />');
2311

    
2312
$section->addInput(new Form_Input(
2313
	'adv_dhcp_required_options',
2314
	'Require options',
2315
	'text',
2316
	$pconfig['adv_dhcp_required_options']
2317
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2318

    
2319
$section->addInput(new Form_Input(
2320
	'adv_dhcp_option_modifiers',
2321
	'Option modifiers',
2322
	'text',
2323
	$pconfig['adv_dhcp_option_modifiers']
2324
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2325
			'modifiers: (default, supersede, prepend, append) %1$s' .
2326
			'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>');
2327

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

    
2330
// DHCP6 client config
2331

    
2332
$section = new Form_Section('DHCP6 Client Configuration');
2333
$section->addClass('dhcp6');
2334

    
2335
$group = new Form_Group('Options');
2336

    
2337
$group->add(new Form_Checkbox(
2338
	'adv_dhcp6_config_advanced',
2339
	null,
2340
	'Advanced Configuration',
2341
	$pconfig['adv_dhcp6_config_advanced']
2342
))->setHelp('Use advanced DHCPv6 configuration options.');
2343

    
2344
$group->add(new Form_Checkbox(
2345
	'adv_dhcp6_config_file_override',
2346
	null,
2347
	'Configuration Override',
2348
	$pconfig['adv_dhcp6_config_file_override']
2349
))->setHelp('Override the configuration from this file.');
2350

    
2351
$section->add($group);
2352

    
2353
$section->addInput(new Form_Checkbox(
2354
	'dhcp6usev4iface',
2355
	'Use IPv4 connectivity as parent interface',
2356
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2357
	$pconfig['dhcp6usev4iface']
2358
));
2359

    
2360
$section->addInput(new Form_Checkbox(
2361
	'dhcp6prefixonly',
2362
	'Request only an IPv6 prefix',
2363
	'Only request an IPv6 prefix, do not request an IPv6 address',
2364
	$pconfig['dhcp6prefixonly']
2365
));
2366

    
2367
$section->addInput(new Form_Select(
2368
	'dhcp6-ia-pd-len',
2369
	'DHCPv6 Prefix Delegation size',
2370
	$pconfig['dhcp6-ia-pd-len'],
2371
	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")
2372
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2373

    
2374
$section->addInput(new Form_Checkbox(
2375
	'dhcp6-ia-pd-send-hint',
2376
	'Send IPv6 prefix hint',
2377
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2378
	$pconfig['dhcp6-ia-pd-send-hint']
2379
));
2380

    
2381
$section->addInput(new Form_Checkbox(
2382
	'dhcp6debug',
2383
	'Debug',
2384
	'Start DHCP6 client in debug mode',
2385
	$pconfig['dhcp6debug']
2386
));
2387
$section->addInput(new Form_Checkbox(
2388
	'dhcp6withoutra',
2389
	'Do not wait for a RA',
2390
	'Required by some ISPs, especially those not using PPPoE',
2391
	$pconfig['dhcp6withoutra']
2392
));
2393
$section->addInput(new Form_Checkbox(
2394
	'dhcp6norelease',
2395
	'Do not allow PD/Address release',
2396
	'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',
2397
	$pconfig['dhcp6norelease']
2398
));
2399

    
2400
if (interface_is_vlan($wancfg['if']) != NULL) {
2401
	$group = new Form_Group('DHCP6 VLAN Priority');
2402

    
2403
	$group->add(new Form_Checkbox(
2404
		'dhcp6vlanenable',
2405
		null,
2406
		'Enable dhcp6c VLAN Priority tagging',
2407
		$pconfig['dhcp6vlanenable']
2408
	))->setHelp('Normally off unless specifically required by the ISP.');
2409

    
2410
	$group->add(new Form_Select(
2411
		'dhcp6cvpt',
2412
		'VLAN Prio',
2413
		$pconfig['dhcp6cvpt'],
2414
		$vlanprio
2415
	))->setHelp('Choose 802.1p priority to set.');
2416

    
2417
	$section->add($group);
2418
}
2419

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

    
2430
$form->add($section);
2431

    
2432
// DHCP6 client config - Advanced
2433

    
2434
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2435
$section->addClass('dhcp6advanced');
2436

    
2437
$section->addInput(new Form_Checkbox(
2438
	'adv_dhcp6_interface_statement_information_only_enable',
2439
	'Information only',
2440
	'Exchange Information Only',
2441
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2442
	'Selected'
2443
))->setHelp('Only exchange informational configuration parameters with servers.');
2444

    
2445
$section->addInput(new Form_Input(
2446
	'adv_dhcp6_interface_statement_send_options',
2447
	'Send options',
2448
	'text',
2449
	$pconfig['adv_dhcp6_interface_statement_send_options']
2450
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2451
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2452
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2453
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2454

    
2455
$section->addInput(new Form_Input(
2456
	'adv_dhcp6_interface_statement_request_options',
2457
	'Request Options',
2458
	'text',
2459
	$pconfig['adv_dhcp6_interface_statement_request_options']
2460
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2461
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2462

    
2463
$section->addInput(new Form_Input(
2464
	'adv_dhcp6_interface_statement_script',
2465
	'Scripts',
2466
	'text',
2467
	$pconfig['adv_dhcp6_interface_statement_script']
2468
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2469
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2470

    
2471
$group = new Form_Group('Identity Association Statement');
2472

    
2473
$group->add(new Form_Checkbox(
2474
	'adv_dhcp6_id_assoc_statement_address_enable',
2475
	null,
2476
	'Non-Temporary Address Allocation',
2477
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2478
	'Selected'
2479
));
2480

    
2481
$group->add(new Form_Input(
2482
	'adv_dhcp6_id_assoc_statement_address_id',
2483
	null,
2484
	'text',
2485
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2486
))->sethelp('id-assoc na ID');
2487

    
2488
$group->add(new Form_IpAddress(
2489
	'adv_dhcp6_id_assoc_statement_address',
2490
	null,
2491
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2492
	'V6'
2493
))->sethelp('IPv6 address');
2494

    
2495
$group->add(new Form_Input(
2496
	'adv_dhcp6_id_assoc_statement_address_pltime',
2497
	null,
2498
	'text',
2499
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2500
))->sethelp('pltime');
2501

    
2502
$group->add(new Form_Input(
2503
	'adv_dhcp6_id_assoc_statement_address_vltime',
2504
	null,
2505
	'text',
2506
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2507
))->sethelp('vltime');
2508

    
2509
$section->add($group);
2510

    
2511
// Prefix delegation
2512
$group = new Form_Group('');
2513

    
2514
$group->add(new Form_Checkbox(
2515
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2516
	null,
2517
	'Prefix Delegation ',
2518
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2519
	'Selected'
2520
));
2521

    
2522
$group->add(new Form_Input(
2523
	'adv_dhcp6_id_assoc_statement_prefix_id',
2524
	null,
2525
	'text',
2526
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2527
))->sethelp('id-assoc pd ID');
2528

    
2529
$group->add(new Form_IpAddress(
2530
	'adv_dhcp6_id_assoc_statement_prefix',
2531
	null,
2532
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2533
	'V6'
2534
))->sethelp('IPv6 prefix');
2535

    
2536
$group->add(new Form_Input(
2537
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2538
	null,
2539
	'text',
2540
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2541
))->sethelp('pltime');
2542

    
2543
$group->add(new Form_Input(
2544
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2545
	null,
2546
	'text',
2547
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2548
))->sethelp('vltime');
2549

    
2550
$section->add($group);
2551

    
2552
$group = new Form_Group('Prefix interface statement');
2553

    
2554
$group->add(new Form_Input(
2555
	'adv_dhcp6_prefix_interface_statement_sla_id',
2556
	null,
2557
	'text',
2558
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2559
))->sethelp('Prefix Interface sla-id');
2560

    
2561
$group->add(new Form_Input(
2562
	'adv_dhcp6_prefix_interface_statement_sla_len',
2563
	null,
2564
	'text',
2565
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2566
))->sethelp('sla-len');
2567

    
2568
$section->add($group);
2569

    
2570
$group = new Form_Group('Select prefix interface');
2571
$section->addInput(new Form_Select(
2572
	'adv_dhcp6_prefix_selected_interface',
2573
	'Prefix Interface',
2574
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2575
	$interfaces
2576
))->setHelp('Select the interface on which to apply the prefix delegation.');
2577

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

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

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

    
2594
$group->add(new Form_Input(
2595
	'adv_dhcp6_authentication_statement_algorithm',
2596
	null,
2597
	'text',
2598
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2599
))->sethelp('Algorithm');
2600

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

    
2608
$section->add($group);
2609

    
2610
$group = new Form_Group('Keyinfo statement');
2611

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

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

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

    
2628
$group = new Form_Group('');
2629

    
2630
$group->add(new Form_Input(
2631
	'adv_dhcp6_key_info_statement_keyid',
2632
	null,
2633
	'text',
2634
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2635
))->sethelp('KeyID');
2636

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

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

    
2651
$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>');
2652

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

    
2655
$form->add($section);
2656

    
2657
$section = new Form_Section('6RD Configuration');
2658
$section->addClass('_6rd');
2659

    
2660
$section->addInput(new Form_Input(
2661
	'prefix-6rd',
2662
	'6RD Prefix',
2663
	'text',
2664
	$pconfig['prefix-6rd']
2665
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2666

    
2667
$section->addInput(new Form_Input(
2668
	'gateway-6rd',
2669
	'*6RD Border relay',
2670
	'text',
2671
	$pconfig['gateway-6rd']
2672
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2673

    
2674
$section->addInput(new Form_Select(
2675
	'prefix-6rd-v4plen',
2676
	'6RD IPv4 Prefix length',
2677
	$pconfig['prefix-6rd-v4plen'],
2678
	array_combine(range(0, 32), range(0, 32))
2679
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2680

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

    
2683
// Track IPv6 ointerface section
2684
$section = new Form_Section('Track IPv6 Interface');
2685
$section->addClass('track6');
2686

    
2687
function build_ipv6interface_list() {
2688
	global $config, $form;
2689

    
2690
	$list = array('' => '');
2691

    
2692
	$interfaces = get_configured_interface_with_descr(true);
2693
	$dynv6ifs = array();
2694

    
2695
	foreach ($interfaces as $iface => $ifacename) {
2696
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2697
			case "6to4":
2698
			case "6rd":
2699
			case "dhcp6":
2700
				$dynv6ifs[$iface] = array(
2701
					'name' => $ifacename,
2702
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2703
				);
2704
				break;
2705
			default:
2706
				continue 2;
2707
		}
2708
	}
2709

    
2710
	foreach ($dynv6ifs as $iface => $ifacedata) {
2711
		$list[$iface] = $ifacedata['name'];
2712

    
2713
		$form->addGlobal(new Form_Input(
2714
			'ipv6-num-prefix-ids-' . $iface,
2715
			null,
2716
			'hidden',
2717
			$ifacedata['ipv6_num_prefix_ids']
2718
		));
2719
	}
2720

    
2721
	return($list);
2722
}
2723

    
2724
$section->addInput(new Form_Select(
2725
	'track6-interface',
2726
	'*IPv6 Interface',
2727
	$pconfig['track6-interface'],
2728
	build_ipv6interface_list()
2729
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2730

    
2731
if ($pconfig['track6-prefix-id'] == "") {
2732
	$pconfig['track6-prefix-id'] = 0;
2733
}
2734

    
2735
$section->addInput(new Form_Input(
2736
	'track6-prefix-id--hex',
2737
	'IPv6 Prefix ID',
2738
	'text',
2739
	sprintf("%x", $pconfig['track6-prefix-id'])
2740
))->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>');
2741

    
2742
$form->addGlobal(new Form_Input(
2743
	'track6-prefix-id-max',
2744
	null,
2745
	'hidden',
2746
	0
2747
));
2748

    
2749
$form->add($section);
2750

    
2751
/// PPP section
2752

    
2753
$section = new Form_Section('PPP Configuration');
2754
$section->addClass('ppp');
2755

    
2756
$section->addInput(new Form_Select(
2757
	'country',
2758
	'Country',
2759
	$pconfig['country'],
2760
	[]
2761
));
2762

    
2763
$section->addInput(new Form_Select(
2764
	'provider_list',
2765
	'Provider',
2766
	$pconfig['provider_list'],
2767
	[]
2768
));
2769

    
2770
$section->addInput(new Form_Select(
2771
	'providerplan',
2772
	'Plan',
2773
	$pconfig['providerplan'],
2774
	[]
2775
))->setHelp('Select to fill in service provider data.');
2776

    
2777
$section->addInput(new Form_Input(
2778
	'ppp_username',
2779
	'Username',
2780
	'text',
2781
	$pconfig['ppp_username'],
2782
	['autocomplete' => 'new-password']
2783
));
2784

    
2785
$section->addPassword(new Form_Input(
2786
	'ppp_password',
2787
	'Password',
2788
	'password',
2789
	$pconfig['ppp_password']
2790
));
2791

    
2792
$section->addInput(new Form_Input(
2793
	'phone',
2794
	'*Phone number',
2795
	'text',
2796
	$pconfig['phone']
2797
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2798

    
2799
$section->addInput(new Form_Input(
2800
	'apn',
2801
	'Access Point Name',
2802
	'text',
2803
	$pconfig['apn']
2804
));
2805

    
2806

    
2807
function build_port_list() {
2808
	$list = array("" => "None");
2809

    
2810
	$portlist = glob("/dev/cua*");
2811
	$modems	  = glob("/dev/modem*");
2812
	$portlist = array_merge($portlist, $modems);
2813

    
2814
	foreach ($portlist as $port) {
2815
		if (preg_match("/\.(lock|init)$/", $port)) {
2816
			continue;
2817
		}
2818

    
2819
	$list[trim($port)] = $port;
2820
	}
2821

    
2822
	return($list);
2823
}
2824

    
2825
$section->addInput(new Form_Select(
2826
	'port',
2827
	"*Modem port",
2828
	$pconfig['port'],
2829
	build_port_list()
2830
));
2831

    
2832
$section->addInput(new Form_Button(
2833
	'btnadvppp',
2834
	'Advanced PPP',
2835
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2836
	'fa-cog'
2837
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2838

    
2839
$form->add($section);
2840

    
2841
// PPPoE configuration
2842
$section = new Form_Section('PPPoE Configuration');
2843
$section->addClass('pppoe');
2844

    
2845
$section->addInput(new Form_Input(
2846
	'pppoe_username',
2847
	'*Username',
2848
	'text',
2849
	$pconfig['pppoe_username'],
2850
	['autocomplete' => 'new-password']
2851
));
2852

    
2853
$section->addPassword(new Form_Input(
2854
	'pppoe_password',
2855
	'*Password',
2856
	'password',
2857
	$pconfig['pppoe_password']
2858
));
2859

    
2860
$section->addInput(new Form_Input(
2861
	'provider',
2862
	'Service name',
2863
	'text',
2864
	$pconfig['provider']
2865
))->setHelp('This field can usually be left empty.');
2866

    
2867
$section->addInput(new Form_Input(
2868
	'hostuniq',
2869
	'Host-Uniq',
2870
	'text',
2871
	$pconfig['hostuniq']
2872
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2873

    
2874
$section->addInput(new Form_Checkbox(
2875
	'pppoe_dialondemand',
2876
	'Dial on demand',
2877
	'Enable Dial-On-Demand mode ',
2878
	$pconfig['pppoe_dialondemand'],
2879
	'enable'
2880
));
2881

    
2882
$section->addInput(new Form_Input(
2883
	'pppoe_idletimeout',
2884
	'Idle timeout',
2885
	'number',
2886
	$pconfig['pppoe_idletimeout'],
2887
	['min' => 0]
2888
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2889
			'An idle timeout of zero disables this feature.');
2890

    
2891
$section->addInput(new Form_Select(
2892
	'pppoe-reset-type',
2893
	'Periodic reset',
2894
	$pconfig['pppoe-reset-type'],
2895
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2896
))->setHelp('Select a reset timing type.');
2897

    
2898
$group = new Form_Group('Custom reset');
2899
$group->addClass('pppoecustom');
2900

    
2901
$group->add(new Form_Input(
2902
	'pppoe_resethour',
2903
	null,
2904
	'number',
2905
	$pconfig['pppoe_resethour'],
2906
	['min' => 0, 'max' => 23]
2907
))->setHelp('Hour (0-23)');
2908

    
2909
$group->add(new Form_Input(
2910
	'pppoe_resetminute',
2911
	null,
2912
	'number',
2913
	$pconfig['pppoe_resetminute'],
2914
	['min' => 0, 'max' => 59]
2915
))->setHelp('Minutes (0-59)');
2916

    
2917
$group->add(new Form_Input(
2918
	'pppoe_resetdate',
2919
	null,
2920
	'text',
2921
	$pconfig['pppoe_resetdate']
2922
))->setHelp('Specific date (mm/dd/yyyy)');
2923

    
2924
$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');
2925

    
2926
$section->add($group);
2927

    
2928
$group = new Form_MultiCheckboxGroup('cron based reset');
2929
$group->addClass('pppoepreset');
2930

    
2931
$group->add(new Form_MultiCheckbox(
2932
	'pppoe_pr_preset_val',
2933
	null,
2934
	'Reset at each month ("0 0 1 * *")',
2935
	$pconfig['pppoe_monthly'],
2936
	'monthly'
2937
))->displayAsRadio();
2938

    
2939
$group->add(new Form_MultiCheckbox(
2940
	'pppoe_pr_preset_val',
2941
	null,
2942
	'Reset at each week ("0 0 * * 0")',
2943
	$pconfig['pppoe_weekly'],
2944
	'weekly'
2945
))->displayAsRadio();
2946

    
2947
$group->add(new Form_MultiCheckbox(
2948
	'pppoe_pr_preset_val',
2949
	null,
2950
	'Reset at each day ("0 0 * * *")',
2951
	$pconfig['pppoe_daily'],
2952
	'daily'
2953
))->displayAsRadio();
2954

    
2955
$group->add(new Form_MultiCheckbox(
2956
	'pppoe_pr_preset_val',
2957
	null,
2958
	'Reset at each hour ("0 * * * *")',
2959
	$pconfig['pppoe_hourly'],
2960
	'hourly'
2961
))->displayAsRadio();
2962

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

    
2965
$section->addInput(new Form_Button(
2966
	'btnadvppp',
2967
	'Advanced and MLPPP',
2968
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2969
	'fa-cog'
2970
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2971

    
2972
$form->add($section);
2973

    
2974
// PPTP & L2TP Configuration section
2975
$section = new Form_Section('PPTP/L2TP Configuration');
2976
$section->addClass('pptp');
2977

    
2978
$section->addInput(new Form_Input(
2979
	'pptp_username',
2980
	'*Username',
2981
	'text',
2982
	$pconfig['pptp_username'],
2983
	['autocomplete' => 'new-password']
2984
));
2985

    
2986
$section->addPassword(new Form_Input(
2987
	'pptp_password',
2988
	'*Password',
2989
	'password',
2990
	$pconfig['pptp_password']
2991
));
2992

    
2993
$group = new Form_Group('Shared Secret');
2994

    
2995
$group->add(new Form_Input(
2996
	'l2tp_secret',
2997
	'*Secret',
2998
	'password',
2999
	$pconfig['l2tp_secret']
3000
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3001
	    'important control packet contents. (Optional)');
3002

    
3003
$group->addClass('l2tp_secret');
3004
$section->add($group);
3005

    
3006
$section->addInput(new Form_IpAddress(
3007
	'pptp_local0',
3008
	'*Local IP address',
3009
	$pconfig['pptp_localip'][0],
3010
	'V4'
3011
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
3012

    
3013
$section->addInput(new Form_IpAddress(
3014
	'pptp_remote0',
3015
	'*Remote IP address',
3016
	$pconfig['pptp_remote'][0],
3017
	'HOSTV4'
3018
));
3019

    
3020
$section->addInput(new Form_Checkbox(
3021
	'pptp_dialondemand',
3022
	'Dial on demand',
3023
	'Enable Dial-On-Demand mode ',
3024
	$pconfig['pptp_dialondemand'],
3025
	'enable'
3026
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3027
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3028

    
3029
$section->addInput(new Form_Input(
3030
	'pptp_idletimeout',
3031
	'Idle timeout (seconds)',
3032
	'number',
3033
	$pconfig['pptp_idletimeout'],
3034
	['min' => 0]
3035
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3036
			'An idle timeout of zero disables this feature.');
3037

    
3038
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3039
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3040
} else {
3041
	$mlppp_text = "";
3042
}
3043

    
3044
$section->addInput(new Form_Button(
3045
	'btnadvppp',
3046
	'Advanced and MLPPP',
3047
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3048
	'fa-cog'
3049
))->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);
3050

    
3051
$form->add($section);
3052

    
3053
// Wireless interface
3054
if (isset($wancfg['wireless'])) {
3055

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

    
3058
	$section->addInput(new Form_Checkbox(
3059
		'persistcommonwireless',
3060
		'Persist common settings',
3061
		'Preserve common wireless configuration through interface deletions and reassignments.',
3062
		$pconfig['persistcommonwireless'],
3063
		'yes'
3064
	));
3065

    
3066
	$mode_list = ['auto' => 'Auto'];
3067

    
3068
	if (is_array($wl_modes)) {
3069
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3070
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3071
		}
3072
	}
3073

    
3074
	if (count($mode_list) == 1) {
3075
		$mode_list[''] = '';
3076
	}
3077

    
3078
	$section->addInput(new Form_Select(
3079
		'standard',
3080
		'Standard',
3081
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3082
		$mode_list
3083
	));
3084

    
3085
	if (isset($wl_modes['11g'])) {
3086
		$section->addInput(new Form_Select(
3087
			'protmode',
3088
			'802.11g OFDM Protection Mode',
3089
			$pconfig['protmode'],
3090
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3091
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3092
	} else {
3093
		$form->addGlobal(new Form_Input(
3094
			'protmode',
3095
			null,
3096
			'hidden',
3097
			'off'
3098
		));
3099
	}
3100

    
3101
	$mode_list = ['0' => gettext('Auto')];
3102

    
3103
	if (is_array($wl_modes)) {
3104
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3105
			if ($wl_standard == "11g") {
3106
				$wl_standard = "11b/g";
3107
			} else if ($wl_standard == "11ng") {
3108
				$wl_standard = "11b/g/n";
3109
			} else if ($wl_standard == "11na") {
3110
				$wl_standard = "11a/n";
3111
			}
3112

    
3113
			foreach ($wl_channels as $wl_channel) {
3114
				if (isset($wl_chaninfo[$wl_channel])) {
3115
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3116
				} else {
3117
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3118
				}
3119
			}
3120
		}
3121
	}
3122

    
3123
	$section->addInput(new Form_Select(
3124
		'channel',
3125
		'Channel',
3126
		$pconfig['channel'],
3127
		$mode_list
3128
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3129
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3130

    
3131
	$section->addInput(new Form_Select(
3132
		'channel_width',
3133
		'Channel width',
3134
		$pconfig['channel_width'],
3135
		$wl_ht_modes
3136
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3137

    
3138
	if (ANTENNAS) {
3139
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3140
			$group = new Form_Group('Antenna Settings');
3141

    
3142
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3143
				$group->add(new Form_Select(
3144
					'diversity',
3145
					null,
3146
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3147
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3148
				))->setHelp('Diversity');
3149
			}
3150

    
3151
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3152
				$group->add(new Form_Select(
3153
					'txantenna',
3154
					null,
3155
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3156
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3157
				))->setHelp('Transmit antenna');
3158
			}
3159

    
3160
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3161
				$group->add(new Form_Select(
3162
					'rxantenna',
3163
					null,
3164
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3165
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3166
				))->setHelp('Receive antenna');
3167
			}
3168

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

    
3171
			$section->add($group);
3172
		}
3173
	}
3174

    
3175
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3176
			$section->addInput(new Form_Input(
3177
				'distance',
3178
				'Distance setting (meters)',
3179
				'test',
3180
				$pconfig['distance']
3181
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3182
	}
3183

    
3184
	$form->add($section);
3185

    
3186
	// Regulatory settings
3187
	$section = new Form_Section('Regulatory Settings');
3188

    
3189
	$domain_list = array("" => 'Default');
3190

    
3191
	if (is_array($wl_regdomains)) {
3192
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3193
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3194
		}
3195
	}
3196

    
3197
	$section->addInput(new Form_Select(
3198
		'regdomain',
3199
		'Regulatory domain',
3200
		$pconfig['regdomain'],
3201
		$domain_list
3202
	))->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');
3203

    
3204
	$country_list = array('' => 'Default');
3205

    
3206
	if (is_array($wl_countries)) {
3207
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3208
			$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']);
3209
		}
3210
	}
3211

    
3212
	$section->addInput(new Form_Select(
3213
		'regcountry',
3214
		'Country',
3215
		$pconfig['regcountry'],
3216
		$country_list
3217
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3218

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

    
3230
	$form->add($section);
3231

    
3232
	$section = new Form_Section('Network-Specific Wireless Configuration');
3233

    
3234
	$section->addInput(new Form_Select(
3235
		'mode',
3236
		'Mode',
3237
		$pconfig['mode'],
3238
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3239
	));
3240

    
3241
	$section->addInput(new Form_Input(
3242
		'ssid',
3243
		'SSID',
3244
		'text',
3245
		$pconfig['ssid']
3246
	));
3247

    
3248
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3249
		$section->addInput(new Form_Select(
3250
			'puremode',
3251
			'Minimum wireless standard',
3252
			$pconfig['puremode'],
3253
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3254
		))->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)');
3255
	} elseif (isset($wl_modes['11g'])) {
3256
		$section->addInput(new Form_Checkbox(
3257
			'puremode',
3258
			'802.11g only',
3259
			null,
3260
			$pconfig['puremode'],
3261
			'11g'
3262
		))->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)');
3263
	}
3264

    
3265
	$section->addInput(new Form_Checkbox(
3266
		'apbridge_enable',
3267
		'Allow intra-BSS communication',
3268
		'Allow packets to pass between wireless clients directly when operating as an access point',
3269
		$pconfig['apbridge_enable'],
3270
		'yes'
3271
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3272

    
3273
	$section->addInput(new Form_Checkbox(
3274
		'wme_enable',
3275
		'Enable WME',
3276
		'Force the card to use WME (wireless QoS)',
3277
		$pconfig['wme_enable'],
3278
		'yes'
3279
	));
3280

    
3281
	$section->addInput(new Form_Checkbox(
3282
		'hidessid_enable',
3283
		'Hide SSID',
3284
		'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.)',
3285
		$pconfig['hidessid_enable'],
3286
		'yes'
3287
	));
3288

    
3289
	$form->add($section);
3290

    
3291
	// WPA Section
3292
	$section = new Form_Section('WPA');
3293

    
3294
	$section->addInput(new Form_Checkbox(
3295
		'wpa_enable',
3296
		'Enable',
3297
		'Enable WPA',
3298
		$pconfig['wpa_enable'],
3299
		'yes'
3300
	));
3301

    
3302
	$section->addInput(new Form_Input(
3303
		'passphrase',
3304
		'WPA Pre-Shared Key',
3305
		'text',
3306
		$pconfig['passphrase']
3307
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3308

    
3309
	$section->addInput(new Form_Select(
3310
		'wpa_mode',
3311
		'WPA mode',
3312
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3313
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3314
	));
3315

    
3316
	$section->addInput(new Form_Select(
3317
		'wpa_key_mgmt',
3318
		'WPA Key Management Mode',
3319
		$pconfig['wpa_key_mgmt'],
3320
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3321
	));
3322

    
3323
	$section->addInput(new Form_Select(
3324
		'wpa_pairwise',
3325
		'WPA Pairwise',
3326
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3327
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3328
	));
3329

    
3330
	$section->addInput(new Form_Input(
3331
		'wpa_group_rekey',
3332
		'Group Key Rotation',
3333
		'number',
3334
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3335
		['min' => '1', 'max' => 9999]
3336
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3337

    
3338
	$section->addInput(new Form_Input(
3339
		'wpa_gmk_rekey',
3340
		'Group Master Key Regeneration',
3341
		'number',
3342
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3343
		['min' => '1', 'max' => 9999]
3344
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3345

    
3346
	$section->addInput(new Form_Checkbox(
3347
		'wpa_strict_rekey',
3348
		'Strict Key Regeneration',
3349
		'Force the AP to rekey whenever a client disassociates',
3350
		$pconfig['wpa_strict_rekey'],
3351
		'yes'
3352
	));
3353

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

    
3356
	$section = new Form_Section('802.1x RADIUS Options');
3357

    
3358
	$section->addInput(new Form_Checkbox(
3359
		'ieee8021x',
3360
		'IEEE802.1X',
3361
		'Enable 802.1X authentication',
3362
		$pconfig['ieee8021x'],
3363
		'yes'
3364
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3365

    
3366
	$group = new Form_Group('Primary 802.1X server');
3367

    
3368
	$group->add(new Form_IpAddress(
3369
		'auth_server_addr',
3370
		'IP Address',
3371
		$pconfig['auth_server_addr']
3372
	))->setHelp('IP address of the RADIUS server');
3373

    
3374
	$group->add(new Form_Input(
3375
		'auth_server_port',
3376
		'Port',
3377
		'number',
3378
		$pconfig['auth_server_port']
3379
	))->setHelp('Server auth port. Default is 1812');
3380

    
3381
	$group->add(new Form_Input(
3382
		'auth_server_shared_secret',
3383
		'Shared Secret',
3384
		'text',
3385
		$pconfig['auth_server_shared_secret']
3386
	))->setHelp('RADIUS Shared secret for this firewall');
3387

    
3388
	$section->add($group);
3389

    
3390
	$group = new Form_Group('Secondary 802.1X server');
3391

    
3392
	$group->add(new Form_IpAddress(
3393
		'auth_server_addr2',
3394
		'IP Address',
3395
		$pconfig['auth_server_addr2']
3396
	))->setHelp('IP address of the RADIUS server');
3397

    
3398
	$group->add(new Form_Input(
3399
		'auth_server_port2',
3400
		'Port',
3401
		'number',
3402
		$pconfig['auth_server_port2']
3403
	))->setHelp('Server auth port. Default is 1812');
3404

    
3405
	$group->add(new Form_Input(
3406
		'auth_server_shared_secret2',
3407
		'Shared Secret',
3408
		'text',
3409
		$pconfig['auth_server_shared_secret2']
3410
	))->setHelp('RADIUS Shared secret for this firewall');
3411

    
3412
	$section->add($group);
3413

    
3414
	$section->addInput(new Form_Checkbox(
3415
		'rsn_preauth',
3416
		'Authentication Roaming Preauth',
3417
		null,
3418
		$pconfig['rsn_preauth'],
3419
		'yes'
3420
	));
3421

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

    
3425
$section = new Form_Section('Reserved Networks');
3426

    
3427
$section->addInput(new Form_Checkbox(
3428
	'blockpriv',
3429
	'Block private networks and loopback addresses',
3430
	'',
3431
	$pconfig['blockpriv'],
3432
	'yes'
3433
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3434
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3435
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3436

    
3437
$section->addInput(new Form_Checkbox(
3438
	'blockbogons',
3439
	'Block bogon networks',
3440
	'',
3441
	$pconfig['blockbogons'],
3442
	'yes'
3443
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3444
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3445
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3446

    
3447
$form->add($section);
3448

    
3449
$form->addGlobal(new Form_Input(
3450
	'if',
3451
	null,
3452
	'hidden',
3453
	$if
3454
));
3455

    
3456
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3457
	$form->addGlobal(new Form_Input(
3458
		'ppp_port',
3459
		null,
3460
		'hidden',
3461
		$pconfig['port']
3462
	));
3463
}
3464

    
3465
$form->addGlobal(new Form_Input(
3466
	'ptpid',
3467
	null,
3468
	'hidden',
3469
	$pconfig['ptpid']
3470
));
3471

    
3472

    
3473
// Add new gateway modal pop-up
3474
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3475

    
3476
$modal->addInput(new Form_Checkbox(
3477
	'defaultgw4',
3478
	'Default',
3479
	'Default gateway',
3480
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3481
));
3482

    
3483
$modal->addInput(new Form_Input(
3484
	'gatewayname4',
3485
	'Gateway name',
3486
	'text',
3487
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3488
));
3489

    
3490
$modal->addInput(new Form_IpAddress(
3491
	'gatewayip4',
3492
	'Gateway IPv4',
3493
	$gateway_settings4['gateway'],
3494
	'V4'
3495
));
3496

    
3497
$modal->addInput(new Form_Input(
3498
	'gatewaydescr4',
3499
	'Description',
3500
	'text',
3501
	$gateway_settings4['descr']
3502
));
3503

    
3504
$btnaddgw4 = new Form_Button(
3505
	'add4',
3506
	'Add',
3507
	null,
3508
	'fa-plus'
3509
);
3510

    
3511
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3512

    
3513
$btncnxgw4 = new Form_Button(
3514
	'cnx4',
3515
	'Cancel',
3516
	null,
3517
	'fa-undo'
3518
);
3519

    
3520
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3521

    
3522
$modal->addInput(new Form_StaticText(
3523
	null,
3524
	$btnaddgw4 . $btncnxgw4
3525
));
3526

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

    
3529
print($form);
3530
?>
3531

    
3532
<script type="text/javascript">
3533
//<![CDATA[
3534
events.push(function() {
3535
	function updateType(t) {
3536

    
3537
		switch (t) {
3538
			case "none": {
3539
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3540
				break;
3541
			}
3542
			case "staticv4": {
3543
				$('.dhcpadvanced, .none, .dhcp').hide();
3544
				$('.pppoe, .pptp, .ppp').hide();
3545
				break;
3546
			}
3547
			case "dhcp": {
3548
				$('.dhcpadvanced, .none').hide();
3549
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3550
										//			about the staticv4 class
3551
				$('.pppoe, .pptp, .ppp').hide();
3552
				break;
3553
			}
3554
			case "ppp": {
3555
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3556
				country_list();
3557
				break;
3558
			}
3559
			case "pppoe": {
3560
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3561
				break;
3562
			}
3563
			case "l2tp": {
3564
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3565
				$('.pptp, .l2tp_secret').show();
3566
				break;
3567
			}
3568
			case "pptp": {
3569
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3570
				$('.pptp').show();
3571
				break;
3572
			}
3573
		}
3574

    
3575
		if (t != "l2tp" && t != "pptp") {
3576
			$('.'+t).show();
3577
		}
3578
	}
3579

    
3580
	function updateTypeSix(t) {
3581
		if (!isNaN(t[0])) {
3582
			t = '_' + t;
3583
		}
3584

    
3585
		switch (t) {
3586
			case "none": {
3587
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3588
				break;
3589
			}
3590
			case "staticv6": {
3591
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3592
				break;
3593
			}
3594
			case "slaac": {
3595
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3596
				break;
3597
			}
3598
			case "dhcp6": {
3599
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3600
				break;
3601
			}
3602
			case "_6rd": {
3603
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3604
				break;
3605
			}
3606
			case "_6to4": {
3607
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3608
				break;
3609
			}
3610
			case "track6": {
3611
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3612
				update_track6_prefix();
3613
				break;
3614
			}
3615
		}
3616

    
3617
		if (t != "l2tp" && t != "pptp") {
3618
			$('.'+t).show();
3619
		}
3620
	}
3621

    
3622
	function show_reset_settings(reset_type) {
3623
		if (reset_type == 'preset') {
3624
			$('.pppoepreset').show();
3625
			$('.pppoecustom').hide();
3626
		} else if (reset_type == 'custom') {
3627
			$('.pppoecustom').show();
3628
			$('.pppoepreset').hide();
3629
		} else {
3630
			$('.pppoecustom').hide();
3631
			$('.pppoepreset').hide();
3632
		}
3633
	}
3634

    
3635
	function update_track6_prefix() {
3636
		var iface = $("#track6-interface").val();
3637
		if (iface == null) {
3638
			return;
3639
		}
3640

    
3641
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3642
		if (track6_prefix_ids == null) {
3643
			return;
3644
		}
3645

    
3646
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3647
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3648
	}
3649

    
3650
	function addOption_v4() {
3651
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3652
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3653
	}
3654

    
3655
	function addOption_v6() {
3656
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3657
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3658
	}
3659

    
3660
	function addSelectboxOption(selectbox, text, value) {
3661
		var optn = document.createElement("OPTION");
3662
		optn.text = text;
3663
		optn.value = value;
3664
		selectbox.append(optn);
3665
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3666
	}
3667

    
3668
	function country_list() {
3669
		$('#country').children().remove();
3670
		$('#provider_list').children().remove();
3671
		$('#providerplan').children().remove();
3672
		$.ajax("getserviceproviders.php",{
3673
			success: function(response) {
3674

    
3675
				var responseTextArr = response.split("\n");
3676
				responseTextArr.sort();
3677

    
3678
				responseTextArr.forEach( function(value) {
3679
					country = value.split(":");
3680
					$('#country').append($('<option>', {
3681
						value: country[1],
3682
						text : country[0]
3683
					}));
3684
				});
3685
			}
3686
		});
3687
	}
3688

    
3689
	function providers_list() {
3690
		$('#provider_list').children().remove();
3691
		$('#providerplan').children().remove();
3692
		$.ajax("getserviceproviders.php",{
3693
			type: 'post',
3694
			data: {country : $('#country').val()},
3695
			success: function(response) {
3696
				var responseTextArr = response.split("\n");
3697
				responseTextArr.sort();
3698
				responseTextArr.forEach( function(value) {
3699
					$('#provider_list').append($('<option>', {
3700
							value: value,
3701
							text : value
3702
					}));
3703
				});
3704
			}
3705
		});
3706
	}
3707

    
3708
	function providerplan_list() {
3709
		$('#providerplan').children().remove();
3710
		$.ajax("getserviceproviders.php",{
3711
			type: 'post',
3712
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3713
			success: function(response) {
3714
				var responseTextArr = response.split("\n");
3715
				responseTextArr.sort();
3716

    
3717
				$('#providerplan').append($('<option>', {
3718
					value: '',
3719
					text : ''
3720
				}));
3721

    
3722
				responseTextArr.forEach( function(value) {
3723
					if (value != "") {
3724
						providerplan = value.split(":");
3725

    
3726
						$('#providerplan').append($('<option>', {
3727
							value: providerplan[1],
3728
							text : providerplan[0] + " - " + providerplan[1]
3729
						}));
3730
					}
3731
				});
3732
			}
3733
		});
3734
	}
3735

    
3736
	function prefill_provider() {
3737
		$.ajax("getserviceproviders.php",{
3738
			type: 'post',
3739
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3740
			success: function(data, textStatus, response) {
3741
				var xmldoc = response.responseXML;
3742
				var provider = xmldoc.getElementsByTagName('connection')[0];
3743
				$('#ppp_username').val('');
3744
				$('#ppp_password').val('');
3745
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3746
					$('#phone').val('#777');
3747
					$('#apn').val('');
3748
				} else {
3749
					$('#phone').val('*99#');
3750
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3751
				}
3752
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3753
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3754
				$('#ppp_username').val(ppp_username);
3755
				$('#ppp_password').val(ppp_password);
3756
			}
3757
		});
3758
	}
3759

    
3760
	function show_dhcp6adv() {
3761
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3762
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3763

    
3764
		hideCheckbox('dhcp6usev4iface', ovr);
3765
		hideCheckbox('dhcp6prefixonly', ovr);
3766
		hideInput('dhcp6-ia-pd-len', ovr);
3767
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3768
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3769

    
3770
		hideClass('dhcp6advanced', !adv || ovr);
3771
	}
3772

    
3773
	function setDHCPoptions() {
3774
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3775
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3776

    
3777
		if (ovr) {
3778
			hideInput('dhcphostname', true);
3779
			hideIpAddress('alias-address', true);
3780
			hideInput('dhcprejectfrom', true);
3781
			hideInput('adv_dhcp_config_file_override_path', false);
3782
			hideClass('dhcpadvanced', true);
3783
		} else {
3784
			hideInput('dhcphostname', false);
3785
			hideIpAddress('alias-address', false);
3786
			hideInput('dhcprejectfrom', false);
3787
			hideInput('adv_dhcp_config_file_override_path', true);
3788
			hideClass('dhcpadvanced', !adv);
3789
		}
3790
	}
3791

    
3792
	// DHCP preset actions
3793
	// Set presets from value of radio buttons
3794
	function setPresets(val) {
3795
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3796
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3797
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3798
		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']);?>");
3799
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3800
	}
3801

    
3802
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3803
		$('#adv_dhcp_pt_timeout').val(timeout);
3804
		$('#adv_dhcp_pt_retry').val(retry);
3805
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3806
		$('#adv_dhcp_pt_reboot').val(reboot);
3807
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3808
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3809
	}
3810

    
3811
	function setPPPoEDialOnDemandItems() {
3812
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3813
	}
3814

    
3815
	function setPPTPDialOnDemandItems() {
3816
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3817
	}
3818

    
3819
	// ---------- On initial page load ------------------------------------------------------------
3820

    
3821
	updateType($('#type').val());
3822
	updateTypeSix($('#type6').val());
3823
	show_reset_settings($('#pppoe-reset-type').val());
3824
	hideClass('dhcp6advanced', true);
3825
	hideClass('dhcpadvanced', true);
3826
	show_dhcp6adv();
3827
	setDHCPoptions();
3828
	setPPPoEDialOnDemandItems();
3829
	setPPTPDialOnDemandItems();
3830

    
3831
	// Set preset buttons on page load
3832
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3833
	if (sv == "") {
3834
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3835
	} else {
3836
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3837
	}
3838

    
3839
	// Set preset from value
3840
	setPresets(sv);
3841

    
3842
	// If the user wants to add a gateway, then add that to the gateway selection
3843
	if ($("#gatewayip4").val() != '') {
3844
		addOption_v4();
3845
	}
3846
	if ($("#gatewayip6").val() != '') {
3847
		addOption_v6();
3848
	}
3849

    
3850
	// ---------- Click checkbox handlers ---------------------------------------------------------
3851

    
3852
	$('#type').on('change', function() {
3853
		updateType(this.value);
3854
	});
3855

    
3856
	$('#type6').on('change', function() {
3857
		updateTypeSix(this.value);
3858
	});
3859

    
3860
	$('#track6-interface').on('change', function() {
3861
		update_track6_prefix();
3862
	});
3863

    
3864
	$('#pppoe-reset-type').on('change', function() {
3865
		show_reset_settings(this.value);
3866
	});
3867

    
3868
	$("#add4").click(function() {
3869
		addOption_v4();
3870
		$("#newgateway4").modal('hide');
3871
	});
3872

    
3873
	$("#cnx4").click(function() {
3874
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3875
		$("#gatewayip4").val('');
3876
		$("#gatewaydescr4").val('');
3877
		$("#defaultgw4").prop("checked", false);
3878
		$("#newgateway4").modal('hide');
3879
	});
3880

    
3881
	$("#add6").click(function() {
3882
		addOption_v6();
3883
		$("#newgateway6").modal('hide');
3884
	});
3885

    
3886
	$("#cnx6").click(function() {
3887
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3888
		$("#gatewayip6").val('');
3889
		$("#gatewaydescr6").val('');
3890
		$("#defaultgw6").prop("checked", false);
3891
		$("#newgateway6").modal('hide');
3892
	});
3893

    
3894
	$('#country').on('change', function() {
3895
		providers_list();
3896
	});
3897

    
3898
	$('#provider_list').on('change', function() {
3899
		providerplan_list();
3900
	});
3901

    
3902
	$('#providerplan').on('change', function() {
3903
		prefill_provider();
3904
	});
3905

    
3906
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3907
		setDHCPoptions();
3908
	});
3909

    
3910
	$('#adv_dhcp6_config_advanced').click(function () {
3911
		show_dhcp6adv();
3912
	});
3913

    
3914
	$('#adv_dhcp6_config_file_override').click(function () {
3915
		show_dhcp6adv();
3916
	});
3917

    
3918
	// On click . .
3919
	$('#pppoe_dialondemand').click(function () {
3920
		setPPPoEDialOnDemandItems();
3921
	});
3922

    
3923
	$('#pptp_dialondemand').click(function () {
3924
		setPPTPDialOnDemandItems();
3925
	});
3926

    
3927
	$('[name=adv_dhcp_pt_values]').click(function () {
3928
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3929
	});
3930

    
3931
	$('#pppoe_resetdate').datepicker();
3932

    
3933
});
3934
//]]>
3935
</script>
3936

    
3937
<?php include("foot.inc");
(72-72/228)