Project

General

Profile

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

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

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

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

    
50
define("ANTENNAS", false);
51

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

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

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
430
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
431

    
432
}
433

    
434
$changes_applied = false;
435

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

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

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

    
489
		/* restart snmp so that it binds to correct address */
490
		$retval |= services_snmpd_configure();
491

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

    
495
		clear_subsystem_dirty('interfaces');
496

    
497
		$retval |= filter_configure();
498

    
499
		enable_rrd_graphing();
500

    
501
		$changes_applied = true;
502

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

    
507
		init_config_arr(array('syslog'));
508
		if (isset($config['syslog']['enable']) && ($ifapply == $config['syslog']['sourceip'])) {
509
			system_syslogd_start();
510
		}
511
	}
512
	@unlink("{$g['tmp_path']}/.interfaces.apply");
513
} else if ($_POST['save']) {
514

    
515
	unset($input_errors);
516
	$pconfig = $_POST;
517

    
518
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
519
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
520
	} else {
521
		$pconfig['track6-prefix-id'] = 0;
522
	}
523

    
524
	/* filter out spaces from descriptions */
525
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
526

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

    
541
	/* input validation */
542
	$reqdfields = explode(" ", "descr");
543
	$reqdfieldsn = array(gettext("Description"));
544
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
545

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

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

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

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

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

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

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

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

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

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

    
742
			if (empty($_POST['track6-interface'])) {
743
				$input_errors[] = gettext("A valid interface to track must be selected.");
744
			}
745

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

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

    
785
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
786
			if ($_POST['subnet'] < 31) {
787
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
788
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
789
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
790
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
791
				}
792
			}
793

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

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

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

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

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

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

    
927
		unset($min_mtu, $max_mtu);
928

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

    
947
				$realhwif_array = get_parent_interface($ifdata['if']);
948
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
949
				$parent_realhwif = $realhwif_array[0];
950

    
951
				if ($parent_realhwif != $wancfg['if']) {
952
					continue;
953
				}
954

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

    
1051
		if ($_POST['passphrase']) {
1052
			$passlen = strlen($_POST['passphrase']);
1053
			if ($passlen < 8 || $passlen > 63) {
1054
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1055
			}
1056
		}
1057

    
1058
		if ($_POST['wpa_enable'] == "yes") {
1059
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1060
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1061
			}
1062
		}
1063
	}
1064

    
1065
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1066
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1067
	}
1068

    
1069
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1070
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1071
	}
1072

    
1073
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1074
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1075
	}
1076

    
1077
	if ($_POST['gatewayip4']) {
1078
		// The user wants to add an IPv4 gateway - validate the settings
1079
		$gateway_settings4 = array();
1080

    
1081
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1082
		$gateway_settings4['interface'] = $_POST['if'];
1083
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1084
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1085
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1086
		$gateway_settings4['ipprotocol'] = 'inet';
1087
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1088
		foreach ($gw_input_errors as $input_error_text) {
1089
			$input_errors[] = $input_error_text;
1090
		}
1091
	}
1092

    
1093
	if ($_POST['gatewayip6']) {
1094
		// The user wants to add an IPv6 gateway - validate the settings
1095
		$gateway_settings6 = array();
1096

    
1097
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1098
		$gateway_settings6['interface'] = $_POST['if'];
1099
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1100
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1101
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1102
		$gateway_settings6['ipprotocol'] = 'inet6';
1103
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1104
		foreach ($gw_input_errors as $input_error_text) {
1105
			$input_errors[] = $input_error_text;
1106
		}
1107
	}
1108

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

    
1116
		if ($wancfg['ipaddr'] != $_POST['type']) {
1117
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1118
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1119
				unset($a_ppps[$pppid]);
1120
			} else if ($wancfg['ipaddr'] == "dhcp") {
1121
				kill_dhclient_process($wancfg['if']);
1122
			}
1123
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1124
				kill_dhcp6client_process($wancfg['if'],true);
1125
			}
1126
		}
1127
		$ppp = array();
1128
		if ($wancfg['ipaddr'] != "ppp") {
1129
			unset($wancfg['ipaddr']);
1130
		}
1131
		if ($wancfg['ipaddrv6'] != "ppp") {
1132
			unset($wancfg['ipaddrv6']);
1133
		}
1134
		unset($wancfg['subnet']);
1135
		unset($wancfg['gateway']);
1136
		unset($wancfg['subnetv6']);
1137
		unset($wancfg['gatewayv6']);
1138
		unset($wancfg['dhcphostname']);
1139
		unset($wancfg['dhcprejectfrom']);
1140
		unset($wancfg['dhcp6-duid']);
1141
		unset($wancfg['dhcp6-ia-pd-len']);
1142
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1143
		unset($wancfg['dhcp6prefixonly']);
1144
		unset($wancfg['dhcp6usev4iface']);
1145
		unset($wancfg['slaacusev4iface']);
1146
		unset($wancfg['ipv6usev4iface']);
1147
		unset($wancfg['dhcp6debug']);
1148
		unset($wancfg['track6-interface']);
1149
		unset($wancfg['track6-prefix-id']);
1150
		unset($wancfg['dhcp6withoutra']);
1151
		unset($wancfg['dhcp6norelease']);
1152
		unset($wancfg['dhcp6vlanenable']);
1153
		unset($wancfg['dhcp6cvpt']);
1154
		unset($wancfg['prefix-6rd']);
1155
		unset($wancfg['prefix-6rd-v4plen']);
1156
		unset($wancfg['gateway-6rd']);
1157

    
1158
		unset($wancfg['dhcpvlanenable']);
1159
		unset($wancfg['dhcpcvpt']);
1160

    
1161
		unset($wancfg['adv_dhcp_pt_timeout']);
1162
		unset($wancfg['adv_dhcp_pt_retry']);
1163
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1164
		unset($wancfg['adv_dhcp_pt_reboot']);
1165
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1166
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1167

    
1168
		unset($wancfg['adv_dhcp_pt_values']);
1169

    
1170
		unset($wancfg['adv_dhcp_send_options']);
1171
		unset($wancfg['adv_dhcp_request_options']);
1172
		unset($wancfg['adv_dhcp_required_options']);
1173
		unset($wancfg['adv_dhcp_option_modifiers']);
1174

    
1175
		unset($wancfg['adv_dhcp_config_advanced']);
1176
		unset($wancfg['adv_dhcp_config_file_override']);
1177
		unset($wancfg['adv_dhcp_config_file_override_path']);
1178

    
1179
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1180
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1181
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1182
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1183

    
1184
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1185
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1186
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1187
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1188
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1189

    
1190
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1191
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1192
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1193
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1194
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1195

    
1196
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1197
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1198
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1199

    
1200
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1201
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1202
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1203
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1204

    
1205
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1206
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1207
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1208
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1209
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1210

    
1211
		unset($wancfg['adv_dhcp6_config_advanced']);
1212
		unset($wancfg['adv_dhcp6_config_file_override']);
1213
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1214

    
1215
		unset($wancfg['pppoe_password']);
1216
		unset($wancfg['pptp_username']);
1217
		unset($wancfg['pptp_password']);
1218
		unset($wancfg['l2tp_secret']);
1219
		unset($wancfg['provider']);
1220
		unset($wancfg['hostuniq']);
1221
		unset($wancfg['ondemand']);
1222
		unset($wancfg['timeout']);
1223
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1224
			unset($wancfg['pppoe']['pppoe-reset-type']);
1225
		}
1226
		unset($wancfg['local']);
1227

    
1228
		unset($wancfg['remote']);
1229
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1230
			if ($wancfg['ipaddr'] != 'ppp') {
1231
				unset($a_ppps[$pppid]['apn']);
1232
				unset($a_ppps[$pppid]['phone']);
1233
				unset($a_ppps[$pppid]['provider']);
1234
				unset($a_ppps[$pppid]['ondemand']);
1235
			}
1236
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1237
				unset($a_ppps[$pppid]['localip']);
1238
				unset($a_ppps[$pppid]['subnet']);
1239
				unset($a_ppps[$pppid]['gateway']);
1240
			}
1241
			if ($wancfg['ipaddr'] != 'pppoe') {
1242
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1243
				unset($a_ppps[$pppid]['hostuniq']);
1244
			}
1245
			if ($wancfg['type'] != $_POST['type']) {
1246
				unset($a_ppps[$pppid]['idletimeout']);
1247
			}
1248
		}
1249

    
1250
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1251
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1252

    
1253
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1254
		switch ($_POST['type']) {
1255
			case "staticv4":
1256
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1257
				$wancfg['subnet'] = $_POST['subnet'];
1258
				if ($_POST['gateway'] != "none") {
1259
					$wancfg['gateway'] = $_POST['gateway'];
1260
				}
1261
				break;
1262
			case "dhcp":
1263
				$wancfg['ipaddr'] = "dhcp";
1264
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1265
				$wancfg['alias-address'] = $_POST['alias-address'];
1266
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1267
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1268

    
1269
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1270
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1271
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1272
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1273
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1274
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1275

    
1276
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1277

    
1278
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1279
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1280
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1281
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1282

    
1283
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1284
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1285
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1286

    
1287
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1288
				if ($gateway_item) {
1289
					$a_gateways[] = $gateway_item;
1290
				}
1291
				if ($_POST['dhcpvlanenable'] == "yes") {
1292
					$wancfg['dhcpvlanenable'] = true;
1293
				}
1294
				if (!empty($_POST['dhcpcvpt'])) {
1295
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1296
				} else {
1297
					unset($wancfg['dhcpcvpt']);
1298
				}
1299
				break;
1300
			case "ppp":
1301
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1302
				$a_ppps[$pppid]['type'] = $_POST['type'];
1303
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1304
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1305
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1306
				if ($_POST['ppp_password'] != DMYPWD) {
1307
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1308
				}
1309
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1310
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1311
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1312
				$wancfg['ipaddr'] = $_POST['type'];
1313
				break;
1314

    
1315
			case "pppoe":
1316
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1317
				$a_ppps[$pppid]['type'] = $_POST['type'];
1318
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1319
				if (isset($_POST['ppp_port'])) {
1320
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1321
				} else {
1322
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1323
				}
1324
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1325
				if ($_POST['pppoe_password'] != DMYPWD) {
1326
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1327
				}
1328
				if (!empty($_POST['provider'])) {
1329
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1330
				} else {
1331
					$a_ppps[$pppid]['provider'] = true;
1332
				}
1333
				if (!empty($_POST['hostuniq'])) {
1334
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1335
				} else {
1336
					$a_ppps[$pppid]['hostuniq'] = true;
1337
				}
1338
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1339
				if (!empty($_POST['pppoe_idletimeout'])) {
1340
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1341
				} else {
1342
					unset($a_ppps[$pppid]['idletimeout']);
1343
				}
1344

    
1345
				if (!empty($_POST['pppoe-reset-type'])) {
1346
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1347
				} else {
1348
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1349
				}
1350
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1351
				$wancfg['ipaddr'] = $_POST['type'];
1352
				if ($gateway_item) {
1353
					$a_gateways[] = $gateway_item;
1354
				}
1355

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

    
1432
				if ($_POST['dhcp6withoutra'] == "yes") {
1433
					$wancfg['dhcp6withoutra'] = true;
1434
				}
1435
				if ($_POST['dhcp6norelease'] == "yes") {
1436
					$wancfg['dhcp6norelease'] = true;
1437
				}
1438
				if ($_POST['dhcp6vlanenable'] == "yes") {
1439
					$wancfg['dhcp6vlanenable'] = true;
1440
				}
1441
				if (!empty($_POST['dhcp6cvpt'])) {
1442
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1443
				} else {
1444
					unset($wancfg['dhcp6cvpt']);
1445
				}
1446

    
1447
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1448
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1449
				}
1450
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1451
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1452
				}
1453
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1454
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1455
				}
1456
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1457
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1458
				}
1459

    
1460
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1461
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1462
				}
1463
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1464
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1465
				}
1466
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1467
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1468
				}
1469
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1470
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1471
				}
1472
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1473
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1474
				}
1475

    
1476
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1477
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1478
				}
1479
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1480
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1481
				}
1482
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1483
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1484
				}
1485
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1486
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1487
				}
1488
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1489
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1490
				}
1491

    
1492
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1493
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1494
				}
1495
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1496
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1497
				}
1498
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1499
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1500
				}
1501
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1502
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1503
				}
1504
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1505
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1506
				}
1507
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1508
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1509
				}
1510
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1511
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1512
				}
1513

    
1514
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1515
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1516
				}
1517
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1518
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1519
				}
1520
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1521
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1522
				}
1523
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1524
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1525
				}
1526
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1527
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1528
				}
1529

    
1530
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1531
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1532
				}
1533
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1534
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1535
				}
1536
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1537
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1538
				}
1539

    
1540
				if ($gateway_item) {
1541
					$a_gateways[] = $gateway_item;
1542
				}
1543
				break;
1544
			case "6rd":
1545
				$wancfg['ipaddrv6'] = "6rd";
1546
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1547
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1548
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1549
				if ($gateway_item) {
1550
					$a_gateways[] = $gateway_item;
1551
				}
1552
				break;
1553
			case "6to4":
1554
				$wancfg['ipaddrv6'] = "6to4";
1555
				break;
1556
			case "track6":
1557
				$wancfg['ipaddrv6'] = "track6";
1558
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1559
				if ($_POST['track6-prefix-id--hex'] === "") {
1560
					$wancfg['track6-prefix-id'] = 0;
1561
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1562
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1563
				} else {
1564
					$wancfg['track6-prefix-id'] = 0;
1565
				}
1566
				break;
1567
			case "none":
1568
				break;
1569
		}
1570
		handle_pppoe_reset($_POST);
1571

    
1572
		if ($_POST['blockpriv'] == "yes") {
1573
			$wancfg['blockpriv'] = true;
1574
		} else {
1575
			unset($wancfg['blockpriv']);
1576
		}
1577
		if ($_POST['blockbogons'] == "yes") {
1578
			$wancfg['blockbogons'] = true;
1579
		} else {
1580
			unset($wancfg['blockbogons']);
1581
		}
1582
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1583
		if (empty($_POST['mtu'])) {
1584
			unset($wancfg['mtu']);
1585
		} else {
1586
			$wancfg['mtu'] = $_POST['mtu'];
1587
		}
1588
		if (empty($_POST['mss'])) {
1589
			unset($wancfg['mss']);
1590
		} else {
1591
			$wancfg['mss'] = $_POST['mss'];
1592
		}
1593
		if (empty($_POST['mediaopt'])) {
1594
			unset($wancfg['media']);
1595
			unset($wancfg['mediaopt']);
1596
		} else {
1597
			$mediaopts = explode(' ', $_POST['mediaopt']);
1598
			if ($mediaopts[0] != '') {
1599
				$wancfg['media'] = $mediaopts[0];
1600
			}
1601
			if ($mediaopts[1] != '') {
1602
				$wancfg['mediaopt'] = $mediaopts[1];
1603
			} else {
1604
				unset($wancfg['mediaopt']);
1605
			}
1606
		}
1607
		if (isset($wancfg['wireless'])) {
1608
			handle_wireless_post();
1609
		}
1610

    
1611
		write_config("Interfaces settings changed");
1612

    
1613
		if ($_POST['gatewayip4']) {
1614
			save_gateway($gateway_settings4);
1615
		}
1616

    
1617
		if ($_POST['gatewayip6']) {
1618
			save_gateway($gateway_settings6);
1619
		}
1620

    
1621
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1622
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1623
		} else {
1624
			$toapplylist = array();
1625
		}
1626
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1627
		$toapplylist[$if]['ppps'] = $old_ppps;
1628
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1629

    
1630
		mark_subsystem_dirty('interfaces');
1631

    
1632
		/* regenerate cron settings/crontab file */
1633
		configure_cron();
1634

    
1635
		header("Location: interfaces.php?if={$if}");
1636
		exit;
1637
	}
1638

    
1639
} // end if ($_POST['save'])
1640

    
1641
function handle_wireless_post() {
1642
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1643
	if (!is_array($wancfg['wireless'])) {
1644
		$wancfg['wireless'] = array();
1645
	}
1646
	$wancfg['wireless']['standard'] = $_POST['standard'];
1647
	$wancfg['wireless']['mode'] = $_POST['mode'];
1648
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1649
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1650
	$wancfg['wireless']['channel'] = $_POST['channel'];
1651
	$wancfg['wireless']['channel_width'] = $_POST['channel_width'];
1652
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1653
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1654
	$wancfg['wireless']['distance'] = $_POST['distance'];
1655
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1656
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1657
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1658
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1659
		foreach ($wl_countries_attr as $wl_country) {
1660
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1661
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1662
				break;
1663
			}
1664
		}
1665
	}
1666
	if (!is_array($wancfg['wireless']['wpa'])) {
1667
		$wancfg['wireless']['wpa'] = array();
1668
	}
1669
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1670
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1671
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1672
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1673
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1674
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1675
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1676
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1677
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1678
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1679
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1680
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1681
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1682
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1683

    
1684
	if ($_POST['persistcommonwireless'] == "yes") {
1685
		if (!is_array($config['wireless'])) {
1686
			$config['wireless'] = array();
1687
		}
1688
		if (!is_array($config['wireless']['interfaces'])) {
1689
			$config['wireless']['interfaces'] = array();
1690
		}
1691
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1692
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1693
		}
1694
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1695
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1696
	}
1697
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1698
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1699
	} else if (isset($wancfg['wireless']['diversity'])) {
1700
		unset($wancfg['wireless']['diversity']);
1701
	}
1702
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1703
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1704
	} else if (isset($wancfg['wireless']['txantenna'])) {
1705
		unset($wancfg['wireless']['txantenna']);
1706
	}
1707
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1708
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1709
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1710
		unset($wancfg['wireless']['rxantenna']);
1711
	}
1712
	if ($_POST['hidessid_enable'] == "yes") {
1713
		$wancfg['wireless']['hidessid']['enable'] = true;
1714
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1715
		unset($wancfg['wireless']['hidessid']['enable']);
1716
	}
1717
	if ($_POST['mac_acl_enable'] == "yes") {
1718
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1719
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1720
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1721
	}
1722
	if ($_POST['rsn_preauth'] == "yes") {
1723
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1724
	} else {
1725
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1726
	}
1727
	if ($_POST['ieee8021x'] == "yes") {
1728
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1729
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1730
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1731
	}
1732
	if ($_POST['wpa_strict_rekey'] == "yes") {
1733
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1734
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1735
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1736
	}
1737
	if ($_POST['debug_mode'] == "yes") {
1738
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1739
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1740
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1741
	}
1742
	if ($_POST['wpa_enable'] == "yes") {
1743
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1744
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1745
		unset($wancfg['wireless']['wpa']['enable']);
1746
	}
1747

    
1748
	if ($_POST['wme_enable'] == "yes") {
1749
		if (!is_array($wancfg['wireless']['wme'])) {
1750
			$wancfg['wireless']['wme'] = array();
1751
		}
1752
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1753
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1754
		unset($wancfg['wireless']['wme']['enable']);
1755
	}
1756
	if ($_POST['puremode'] == "11g") {
1757
		if (!is_array($wancfg['wireless']['pureg'])) {
1758
			$wancfg['wireless']['pureg'] = array();
1759
		}
1760
		$wancfg['wireless']['pureg']['enable'] = true;
1761
	} else if ($_POST['puremode'] == "11n") {
1762
		if (!is_array($wancfg['wireless']['puren'])) {
1763
			$wancfg['wireless']['puren'] = array();
1764
		}
1765
		$wancfg['wireless']['puren']['enable'] = true;
1766
	} else {
1767
		if (isset($wancfg['wireless']['pureg'])) {
1768
			unset($wancfg['wireless']['pureg']);
1769
		}
1770
		if (isset($wancfg['wireless']['puren'])) {
1771
			unset($wancfg['wireless']['puren']);
1772
		}
1773
	}
1774
	if ($_POST['apbridge_enable'] == "yes") {
1775
		if (!is_array($wancfg['wireless']['apbridge'])) {
1776
			$wancfg['wireless']['apbridge'] = array();
1777
		}
1778
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1779
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1780
		unset($wancfg['wireless']['apbridge']['enable']);
1781
	}
1782
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1783
		if (!is_array($wancfg['wireless']['turbo'])) {
1784
			$wancfg['wireless']['turbo'] = array();
1785
		}
1786
		$wancfg['wireless']['turbo']['enable'] = true;
1787
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1788
		unset($wancfg['wireless']['turbo']['enable']);
1789
	}
1790

    
1791
	interface_sync_wireless_clones($wancfg, true);
1792
}
1793

    
1794
function check_wireless_mode() {
1795
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1796

    
1797
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1798
		return;
1799
	}
1800

    
1801
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1802
		$clone_count = 1;
1803
	} else {
1804
		$clone_count = 0;
1805
	}
1806

    
1807
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1808
		foreach ($config['wireless']['clone'] as $clone) {
1809
			if ($clone['if'] == $wlanbaseif) {
1810
				$clone_count++;
1811
			}
1812
		}
1813
	}
1814

    
1815
	if ($clone_count > 1) {
1816
		$old_wireless_mode = $wancfg['wireless']['mode'];
1817
		$wancfg['wireless']['mode'] = $_POST['mode'];
1818
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1819
			$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']]);
1820
		} else {
1821
			pfSense_interface_destroy("{$wlanif}_");
1822
		}
1823
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1824
	}
1825
}
1826

    
1827
// Find all possible media options for the interface
1828
$mediaopts_list = array();
1829
$intrealname = $config['interfaces'][$if]['if'];
1830
if (!is_pseudo_interface($intrealname, false)) {
1831
	exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1832
	foreach ($mediaopts as $mediaopt) {
1833
		preg_match("/media (.*)/", $mediaopt, $matches);
1834
		if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1835
			// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1836
			array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1837
		} else {
1838
			// there is only media like "media 1000baseT"
1839
			array_push($mediaopts_list, $matches[1]);
1840
		}
1841
	}
1842
}
1843

    
1844
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1845
$shortcut_section = "interfaces";
1846

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

    
1849
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1850
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1851
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1852
}
1853

    
1854
$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"));
1855

    
1856
// Get the MAC address
1857
$defgatewayname4 = $wancfg['descr'] . "GW";
1858
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1859

    
1860
function build_mediaopts_list() {
1861
	global $mediaopts_list;
1862

    
1863
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1864
			 " " =>	 gettext("------- Media Supported by this interface -------")
1865
			];
1866

    
1867
	foreach ($mediaopts_list as $mediaopt) {
1868
		$list[$mediaopt] = $mediaopt;
1869
	}
1870

    
1871
	return($list);
1872
}
1873

    
1874
function build_gateway_list() {
1875
	global $a_gateways, $if;
1876

    
1877
	$list = array("none" => gettext("None"));
1878
	foreach ($a_gateways as $gateway) {
1879
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1880
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1881
		}
1882
	}
1883

    
1884
	return($list);
1885
}
1886

    
1887
function build_gatewayv6_list() {
1888
	global $a_gateways, $if;
1889

    
1890
	$list = array("none" => gettext("None"));
1891
	foreach ($a_gateways as $gateway) {
1892
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1893
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1894
		}
1895
	}
1896

    
1897
	return($list);
1898
}
1899

    
1900
include("head.inc");
1901

    
1902
if ($input_errors) {
1903
	print_input_errors($input_errors);
1904
}
1905

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

    
1912
if ($changes_applied) {
1913
	print_apply_result_box($retval);
1914
}
1915

    
1916
$form = new Form();
1917

    
1918
$section = new Form_Section('General Configuration');
1919

    
1920
$section->addInput(new Form_Checkbox(
1921
	'enable',
1922
	'Enable',
1923
	'Enable interface',
1924
	$pconfig['enable'],
1925
	'yes'
1926
));
1927

    
1928
$section->addInput(new Form_Input(
1929
	'descr',
1930
	'*Description',
1931
	'text',
1932
	$pconfig['descr']
1933
))->setHelp('Enter a description (name) for the interface here.');
1934

    
1935
if ($show_address_controls) {
1936
	$section->addInput(new Form_Select(
1937
		'type',
1938
		'IPv4 Configuration Type',
1939
		$pconfig['type'],
1940
		$types4
1941
	));
1942
	$section->addInput(new Form_Select(
1943
		'type6',
1944
		'IPv6 Configuration Type',
1945
		$pconfig['type6'],
1946
		$types6
1947
	));
1948
} else {
1949
	$section->addInput(new Form_StaticText(
1950
		'IPv4/IPv6 Configuration',
1951
		"This interface type does not support manual address configuration on this page. "
1952
	));
1953
	$form->addGlobal(new Form_Input(
1954
		'type',
1955
		null,
1956
		'hidden',
1957
		'none'
1958
	));
1959
	$form->addGlobal(new Form_Input(
1960
		'type6',
1961
		null,
1962
		'hidden',
1963
		'none'
1964
	));
1965
}
1966

    
1967
$macaddress = new Form_Input(
1968
	'spoofmac',
1969
	'MAC Address',
1970
	'text',
1971
	$pconfig['spoofmac'],
1972
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1973
);
1974

    
1975
if (interface_is_vlan($realifname)) {
1976
	$macaddress->setDisabled();
1977
	$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
1978
	    'set on its parent interface');
1979
} else {
1980
	$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
1981
	    'MAC address of this interface.%sEnter a MAC address in the ' .
1982
	    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1983
}
1984

    
1985
$section->addInput($macaddress);
1986

    
1987
$section->addInput(new Form_Input(
1988
	'mtu',
1989
	'MTU',
1990
	'number',
1991
	$pconfig['mtu']
1992
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1993
			'This is typically 1500 bytes but can vary in some circumstances.');
1994

    
1995
$section->addInput(new Form_Input(
1996
	'mss',
1997
	'MSS',
1998
	'number',
1999
	$pconfig['mss']
2000
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
2001
			'header size) will be in effect.');
2002

    
2003
if (count($mediaopts_list) > 0) {
2004
	$section->addInput(new Form_Select(
2005
		'mediaopt',
2006
		'Speed and Duplex',
2007
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
2008
		build_mediaopts_list()
2009
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2010
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2011
}
2012

    
2013
$form->add($section);
2014

    
2015
$section = new Form_Section('Static IPv4 Configuration');
2016
$section->addClass('staticv4');
2017

    
2018
$section->addInput(new Form_IpAddress(
2019
	'ipaddr',
2020
	'*IPv4 Address',
2021
	$pconfig['ipaddr'],
2022
	'V4'
2023
))->addMask('subnet', $pconfig['subnet'], 32);
2024

    
2025
$group = new Form_Group('IPv4 Upstream gateway');
2026

    
2027
$group->add(new Form_Select(
2028
	'gateway',
2029
	'IPv4 Upstream Gateway',
2030
	$pconfig['gateway'],
2031
	build_gateway_list()
2032
));
2033

    
2034
$group->add(new Form_Button(
2035
	'addgw4',
2036
	'Add a new gateway',
2037
	null,
2038
	'fa-plus'
2039
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2040

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

    
2045
$section->add($group);
2046

    
2047
$form->add($section);
2048

    
2049
$section = new Form_Section('SLAAC IPv6 Configuration');
2050
$section->addClass('slaac');
2051

    
2052
$section->addInput(new Form_Checkbox(
2053
	'slaacusev4iface',
2054
	'Use IPv4 connectivity as parent interface',
2055
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2056
	$pconfig['slaacusev4iface']
2057
));
2058

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

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

    
2064
$section->addInput(new Form_IpAddress(
2065
	'ipaddrv6',
2066
	'*IPv6 address',
2067
	$pconfig['ipaddrv6'],
2068
	'V6'
2069
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2070

    
2071
$section->addInput(new Form_Checkbox(
2072
	'ipv6usev4iface',
2073
	'Use IPv4 connectivity as parent interface',
2074
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2075
	$pconfig['ipv6usev4iface']
2076
));
2077

    
2078
$group = new Form_Group('IPv6 Upstream gateway');
2079

    
2080
$group->add(new Form_Select(
2081
	'gatewayv6',
2082
	'IPv6 Upstream Gateway',
2083
	$pconfig['gatewayv6'],
2084
	build_gatewayv6_list()
2085
));
2086

    
2087
$group->add(new Form_Button(
2088
	'addgw6',
2089
	'Add a new gateway',
2090
	null,
2091
	'fa-plus'
2092
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2093

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

    
2097
$section->add($group);
2098
$form->add($section);
2099

    
2100
// Add new gateway modal pop-up for IPv6
2101
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2102

    
2103
$modal->addInput(new Form_Checkbox(
2104
	'defaultgw6',
2105
	'Default',
2106
	'Default gateway',
2107
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2108
));
2109

    
2110
$modal->addInput(new Form_Input(
2111
	'gatewayname6',
2112
	'Gateway name',
2113
	'text',
2114
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2115
));
2116

    
2117
$modal->addInput(new Form_IpAddress(
2118
	'gatewayip6',
2119
	'Gateway IPv6',
2120
	$gateway_settings6['gateway'],
2121
	'V6'
2122
));
2123

    
2124
$modal->addInput(new Form_Input(
2125
	'gatewaydescr6',
2126
	'Description',
2127
	'text',
2128
	$gateway_settings6['descr']
2129
));
2130

    
2131
$btnaddgw6 = new Form_Button(
2132
	'add6',
2133
	'Add',
2134
	null,
2135
	'fa-plus'
2136
);
2137

    
2138
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2139

    
2140
$btncnxgw6 = new Form_Button(
2141
	'cnx6',
2142
	'Cancel',
2143
	null,
2144
	'fa-undo'
2145
);
2146

    
2147
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2148

    
2149
$modal->addInput(new Form_StaticText(
2150
	null,
2151
	$btnaddgw6 . $btncnxgw6
2152
));
2153

    
2154
$form->add($modal);
2155

    
2156
// ==== DHCP client configuration =============================
2157

    
2158
$section = new Form_Section('DHCP Client Configuration');
2159
$section->addClass('dhcp');
2160

    
2161
$group = new Form_Group('Options');
2162

    
2163
$group->add(new Form_Checkbox(
2164
	'adv_dhcp_config_advanced',
2165
	null,
2166
	'Advanced Configuration',
2167
	$pconfig['adv_dhcp_config_advanced']
2168
))->setHelp('Use advanced DHCP configuration options.');
2169

    
2170
$group->add(new Form_Checkbox(
2171
	'adv_dhcp_config_file_override',
2172
	null,
2173
	'Configuration Override',
2174
	$pconfig['adv_dhcp_config_file_override']
2175
))->setHelp('Override the configuration from this file.');
2176

    
2177
$section->add($group);
2178

    
2179
$section->addInput(new Form_Input(
2180
	'dhcphostname',
2181
	'Hostname',
2182
	'text',
2183
	$pconfig['dhcphostname']
2184
))->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).');
2185

    
2186
$section->addInput(new Form_IpAddress(
2187
	'alias-address',
2188
	'Alias IPv4 address',
2189
	$pconfig['alias-address'],
2190
	'V4'
2191
))->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.');
2192

    
2193
$section->addInput(new Form_Input(
2194
	'dhcprejectfrom',
2195
	'Reject leases from',
2196
	'text',
2197
	$pconfig['dhcprejectfrom']
2198
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2199
			'(separate multiple entries with a comma). ' .
2200
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2201

    
2202
if (interface_is_vlan($wancfg['if']) != NULL) {
2203

    
2204
	$group = new Form_Group('DHCP VLAN Priority');
2205
	$group->add(new Form_Checkbox(
2206
		'dhcpvlanenable',
2207
		null,
2208
		'Enable dhcpclient VLAN Priority tagging',
2209
		$pconfig['dhcpvlanenable']
2210
	))->setHelp('Normally off unless specifically required by the ISP.');
2211

    
2212
	$group->add(new Form_Select(
2213
		'dhcpcvpt',
2214
		'VLAN Prio',
2215
		$pconfig['dhcpcvpt'],
2216
		$vlanprio
2217
	))->setHelp('Choose 802.1p priority to set.');
2218

    
2219
	$section->add($group);
2220
}
2221

    
2222
$group = new Form_Group('Protocol timing');
2223
$group->addClass('dhcpadvanced');
2224

    
2225
$group->add(new Form_Input(
2226
	'adv_dhcp_pt_timeout',
2227
	null,
2228
	'number',
2229
	$pconfig['adv_dhcp_pt_timeout']
2230
))->setHelp('Timeout');
2231

    
2232
$group->add(new Form_Input(
2233
	'adv_dhcp_pt_retry',
2234
	null,
2235
	'number',
2236
	$pconfig['adv_dhcp_pt_retry']
2237
))->setHelp('Retry');
2238

    
2239
$group->add(new Form_Input(
2240
	'adv_dhcp_pt_select_timeout',
2241
	null,
2242
	'number',
2243
	$pconfig['adv_dhcp_pt_select_timeout'],
2244
	['min' => 0]
2245
))->setHelp('Select timeout');
2246

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

    
2254
$group->add(new Form_Input(
2255
	'adv_dhcp_pt_backoff_cutoff',
2256
	null,
2257
	'number',
2258
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2259
))->setHelp('Backoff cutoff');
2260

    
2261
$group->add(new Form_Input(
2262
	'adv_dhcp_pt_initial_interval',
2263
	null,
2264
	'number',
2265
	$pconfig['adv_dhcp_pt_initial_interval']
2266
))->setHelp('Initial interval');
2267

    
2268
$section->add($group);
2269

    
2270
$group = new Form_Group('Presets');
2271
$group->addClass('dhcpadvanced');
2272

    
2273
$group->add(new Form_Checkbox(
2274
	'adv_dhcp_pt_values',
2275
	null,
2276
	'FreeBSD default',
2277
	null,
2278
	'DHCP'
2279
))->displayAsRadio();
2280

    
2281
$group->add(new Form_Checkbox(
2282
	'adv_dhcp_pt_values',
2283
	null,
2284
	'Clear',
2285
	null,
2286
	'Clear'
2287
))->displayAsRadio();
2288

    
2289
$group->add(new Form_Checkbox(
2290
	'adv_dhcp_pt_values',
2291
	null,
2292
	'pfSense Default',
2293
	null,
2294
	'pfSense'
2295
))->displayAsRadio();
2296

    
2297
$group->add(new Form_Checkbox(
2298
	'adv_dhcp_pt_values',
2299
	null,
2300
	'Saved Cfg',
2301
	null,
2302
	'SavedCfg'
2303
))->displayAsRadio();
2304

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

    
2308
$section->add($group);
2309

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

    
2320
$form->add($section);
2321

    
2322
$section = new Form_Section('Lease Requirements and Requests');
2323
$section->addClass('dhcpadvanced');
2324

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

    
2335
$section->addInput(new Form_Input(
2336
	'adv_dhcp_request_options',
2337
	'Request options',
2338
	'text',
2339
	$pconfig['adv_dhcp_request_options']
2340
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2341
			'Some ISPs may require certain options be or not be requested.', '<br />');
2342

    
2343
$section->addInput(new Form_Input(
2344
	'adv_dhcp_required_options',
2345
	'Require options',
2346
	'text',
2347
	$pconfig['adv_dhcp_required_options']
2348
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2349

    
2350
$section->addInput(new Form_Input(
2351
	'adv_dhcp_option_modifiers',
2352
	'Option modifiers',
2353
	'text',
2354
	$pconfig['adv_dhcp_option_modifiers']
2355
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2356
			'modifiers: (default, supersede, prepend, append) %1$s' .
2357
			'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>');
2358

    
2359
$form->add($section);
2360

    
2361
// DHCP6 client config
2362

    
2363
$section = new Form_Section('DHCP6 Client Configuration');
2364
$section->addClass('dhcp6');
2365

    
2366
$group = new Form_Group('Options');
2367

    
2368
$group->add(new Form_Checkbox(
2369
	'adv_dhcp6_config_advanced',
2370
	null,
2371
	'Advanced Configuration',
2372
	$pconfig['adv_dhcp6_config_advanced']
2373
))->setHelp('Use advanced DHCPv6 configuration options.');
2374

    
2375
$group->add(new Form_Checkbox(
2376
	'adv_dhcp6_config_file_override',
2377
	null,
2378
	'Configuration Override',
2379
	$pconfig['adv_dhcp6_config_file_override']
2380
))->setHelp('Override the configuration from this file.');
2381

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

    
2384
$section->addInput(new Form_Checkbox(
2385
	'dhcp6usev4iface',
2386
	'Use IPv4 connectivity as parent interface',
2387
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2388
	$pconfig['dhcp6usev4iface']
2389
));
2390

    
2391
$section->addInput(new Form_Checkbox(
2392
	'dhcp6prefixonly',
2393
	'Request only an IPv6 prefix',
2394
	'Only request an IPv6 prefix, do not request an IPv6 address',
2395
	$pconfig['dhcp6prefixonly']
2396
));
2397

    
2398
$section->addInput(new Form_Select(
2399
	'dhcp6-ia-pd-len',
2400
	'DHCPv6 Prefix Delegation size',
2401
	$pconfig['dhcp6-ia-pd-len'],
2402
	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")
2403
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2404

    
2405
$section->addInput(new Form_Checkbox(
2406
	'dhcp6-ia-pd-send-hint',
2407
	'Send IPv6 prefix hint',
2408
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2409
	$pconfig['dhcp6-ia-pd-send-hint']
2410
));
2411

    
2412
$section->addInput(new Form_Checkbox(
2413
	'dhcp6debug',
2414
	'Debug',
2415
	'Start DHCP6 client in debug mode',
2416
	$pconfig['dhcp6debug']
2417
));
2418
$section->addInput(new Form_Checkbox(
2419
	'dhcp6withoutra',
2420
	'Do not wait for a RA',
2421
	'Required by some ISPs, especially those not using PPPoE',
2422
	$pconfig['dhcp6withoutra']
2423
));
2424
$section->addInput(new Form_Checkbox(
2425
	'dhcp6norelease',
2426
	'Do not allow PD/Address release',
2427
	'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',
2428
	$pconfig['dhcp6norelease']
2429
));
2430

    
2431
if (interface_is_vlan($wancfg['if']) != NULL) {
2432
	$group = new Form_Group('DHCP6 VLAN Priority');
2433

    
2434
	$group->add(new Form_Checkbox(
2435
		'dhcp6vlanenable',
2436
		null,
2437
		'Enable dhcp6c VLAN Priority tagging',
2438
		$pconfig['dhcp6vlanenable']
2439
	))->setHelp('Normally off unless specifically required by the ISP.');
2440

    
2441
	$group->add(new Form_Select(
2442
		'dhcp6cvpt',
2443
		'VLAN Prio',
2444
		$pconfig['dhcp6cvpt'],
2445
		$vlanprio
2446
	))->setHelp('Choose 802.1p priority to set.');
2447

    
2448
	$section->add($group);
2449
}
2450

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

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

    
2463
// DHCP6 client config - Advanced
2464

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

    
2468
$section->addInput(new Form_Checkbox(
2469
	'adv_dhcp6_interface_statement_information_only_enable',
2470
	'Information only',
2471
	'Exchange Information Only',
2472
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2473
	'Selected'
2474
))->setHelp('Only exchange informational configuration parameters with servers.');
2475

    
2476
$section->addInput(new Form_Input(
2477
	'adv_dhcp6_interface_statement_send_options',
2478
	'Send options',
2479
	'text',
2480
	$pconfig['adv_dhcp6_interface_statement_send_options']
2481
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2482
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2483
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2484
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2485

    
2486
$section->addInput(new Form_Input(
2487
	'adv_dhcp6_interface_statement_request_options',
2488
	'Request Options',
2489
	'text',
2490
	$pconfig['adv_dhcp6_interface_statement_request_options']
2491
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2492
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2493

    
2494
$section->addInput(new Form_Input(
2495
	'adv_dhcp6_interface_statement_script',
2496
	'Scripts',
2497
	'text',
2498
	$pconfig['adv_dhcp6_interface_statement_script']
2499
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2500
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2501

    
2502
$group = new Form_Group('Identity Association Statement');
2503

    
2504
$group->add(new Form_Checkbox(
2505
	'adv_dhcp6_id_assoc_statement_address_enable',
2506
	null,
2507
	'Non-Temporary Address Allocation',
2508
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2509
	'Selected'
2510
));
2511

    
2512
$group->add(new Form_Input(
2513
	'adv_dhcp6_id_assoc_statement_address_id',
2514
	null,
2515
	'text',
2516
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2517
))->sethelp('id-assoc na ID');
2518

    
2519
$group->add(new Form_IpAddress(
2520
	'adv_dhcp6_id_assoc_statement_address',
2521
	null,
2522
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2523
	'V6'
2524
))->sethelp('IPv6 address');
2525

    
2526
$group->add(new Form_Input(
2527
	'adv_dhcp6_id_assoc_statement_address_pltime',
2528
	null,
2529
	'text',
2530
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2531
))->sethelp('pltime');
2532

    
2533
$group->add(new Form_Input(
2534
	'adv_dhcp6_id_assoc_statement_address_vltime',
2535
	null,
2536
	'text',
2537
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2538
))->sethelp('vltime');
2539

    
2540
$section->add($group);
2541

    
2542
// Prefix delegation
2543
$group = new Form_Group('');
2544

    
2545
$group->add(new Form_Checkbox(
2546
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2547
	null,
2548
	'Prefix Delegation ',
2549
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2550
	'Selected'
2551
));
2552

    
2553
$group->add(new Form_Input(
2554
	'adv_dhcp6_id_assoc_statement_prefix_id',
2555
	null,
2556
	'text',
2557
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2558
))->sethelp('id-assoc pd ID');
2559

    
2560
$group->add(new Form_IpAddress(
2561
	'adv_dhcp6_id_assoc_statement_prefix',
2562
	null,
2563
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2564
	'V6'
2565
))->sethelp('IPv6 prefix');
2566

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

    
2574
$group->add(new Form_Input(
2575
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2576
	null,
2577
	'text',
2578
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2579
))->sethelp('vltime');
2580

    
2581
$section->add($group);
2582

    
2583
$group = new Form_Group('Prefix interface statement');
2584

    
2585
$group->add(new Form_Input(
2586
	'adv_dhcp6_prefix_interface_statement_sla_id',
2587
	null,
2588
	'text',
2589
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2590
))->sethelp('Prefix Interface sla-id');
2591

    
2592
$group->add(new Form_Input(
2593
	'adv_dhcp6_prefix_interface_statement_sla_len',
2594
	null,
2595
	'text',
2596
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2597
))->sethelp('sla-len');
2598

    
2599
$section->add($group);
2600

    
2601
$group = new Form_Group('Select prefix interface');
2602
$section->addInput(new Form_Select(
2603
	'adv_dhcp6_prefix_selected_interface',
2604
	'Prefix Interface',
2605
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2606
	$interfaces
2607
))->setHelp('Select the interface on which to apply the prefix delegation.');
2608

    
2609
$group = new Form_Group('Authentication statement');
2610

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

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

    
2625
$group->add(new Form_Input(
2626
	'adv_dhcp6_authentication_statement_algorithm',
2627
	null,
2628
	'text',
2629
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2630
))->sethelp('Algorithm');
2631

    
2632
$group->add(new Form_Input(
2633
	'adv_dhcp6_authentication_statement_rdm',
2634
	null,
2635
	'text',
2636
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2637
))->sethelp('RDM');
2638

    
2639
$section->add($group);
2640

    
2641
$group = new Form_Group('Keyinfo statement');
2642

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

    
2650
$group->add(new Form_Input(
2651
	'adv_dhcp6_key_info_statement_realm',
2652
	null,
2653
	'text',
2654
	$pconfig['adv_dhcp6_key_info_statement_realm']
2655
))->sethelp('Realm');
2656

    
2657
$section->add($group);
2658

    
2659
$group = new Form_Group('');
2660

    
2661
$group->add(new Form_Input(
2662
	'adv_dhcp6_key_info_statement_keyid',
2663
	null,
2664
	'text',
2665
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2666
))->sethelp('KeyID');
2667

    
2668
$group->add(new Form_Input(
2669
	'adv_dhcp6_key_info_statement_secret',
2670
	null,
2671
	'text',
2672
	$pconfig['adv_dhcp6_key_info_statement_secret']
2673
))->sethelp('Secret');
2674

    
2675
$group->add(new Form_Input(
2676
	'adv_dhcp6_key_info_statement_expire',
2677
	null,
2678
	'text',
2679
	$pconfig['adv_dhcp6_key_info_statement_expire']
2680
))->sethelp('Expire');
2681

    
2682
$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>');
2683

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

    
2686
$form->add($section);
2687

    
2688
$section = new Form_Section('6RD Configuration');
2689
$section->addClass('_6rd');
2690

    
2691
$section->addInput(new Form_Input(
2692
	'prefix-6rd',
2693
	'6RD Prefix',
2694
	'text',
2695
	$pconfig['prefix-6rd']
2696
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2697

    
2698
$section->addInput(new Form_Input(
2699
	'gateway-6rd',
2700
	'*6RD Border relay',
2701
	'text',
2702
	$pconfig['gateway-6rd']
2703
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2704

    
2705
$section->addInput(new Form_Select(
2706
	'prefix-6rd-v4plen',
2707
	'6RD IPv4 Prefix length',
2708
	$pconfig['prefix-6rd-v4plen'],
2709
	array_combine(range(0, 32), range(0, 32))
2710
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2711

    
2712
$form->add($section);
2713

    
2714
// Track IPv6 ointerface section
2715
$section = new Form_Section('Track IPv6 Interface');
2716
$section->addClass('track6');
2717

    
2718
function build_ipv6interface_list() {
2719
	global $config, $form;
2720

    
2721
	$list = array('' => '');
2722

    
2723
	$interfaces = get_configured_interface_with_descr(true);
2724
	$dynv6ifs = array();
2725

    
2726
	foreach ($interfaces as $iface => $ifacename) {
2727
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2728
			case "6to4":
2729
			case "6rd":
2730
			case "dhcp6":
2731
				$dynv6ifs[$iface] = array(
2732
					'name' => $ifacename,
2733
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2734
				);
2735
				break;
2736
			default:
2737
				continue 2;
2738
		}
2739
	}
2740

    
2741
	foreach ($dynv6ifs as $iface => $ifacedata) {
2742
		$list[$iface] = $ifacedata['name'];
2743

    
2744
		$form->addGlobal(new Form_Input(
2745
			'ipv6-num-prefix-ids-' . $iface,
2746
			null,
2747
			'hidden',
2748
			$ifacedata['ipv6_num_prefix_ids']
2749
		));
2750
	}
2751

    
2752
	return($list);
2753
}
2754

    
2755
$section->addInput(new Form_Select(
2756
	'track6-interface',
2757
	'*IPv6 Interface',
2758
	$pconfig['track6-interface'],
2759
	build_ipv6interface_list()
2760
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2761

    
2762
if ($pconfig['track6-prefix-id'] == "") {
2763
	$pconfig['track6-prefix-id'] = 0;
2764
}
2765

    
2766
$section->addInput(new Form_Input(
2767
	'track6-prefix-id--hex',
2768
	'IPv6 Prefix ID',
2769
	'text',
2770
	sprintf("%x", $pconfig['track6-prefix-id'])
2771
))->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>');
2772

    
2773
$form->addGlobal(new Form_Input(
2774
	'track6-prefix-id-max',
2775
	null,
2776
	'hidden',
2777
	0
2778
));
2779

    
2780
$form->add($section);
2781

    
2782
/// PPP section
2783

    
2784
$section = new Form_Section('PPP Configuration');
2785
$section->addClass('ppp');
2786

    
2787
$section->addInput(new Form_Select(
2788
	'country',
2789
	'Country',
2790
	$pconfig['country'],
2791
	[]
2792
));
2793

    
2794
$section->addInput(new Form_Select(
2795
	'provider_list',
2796
	'Provider',
2797
	$pconfig['provider_list'],
2798
	[]
2799
));
2800

    
2801
$section->addInput(new Form_Select(
2802
	'providerplan',
2803
	'Plan',
2804
	$pconfig['providerplan'],
2805
	[]
2806
))->setHelp('Select to fill in service provider data.');
2807

    
2808
$section->addInput(new Form_Input(
2809
	'ppp_username',
2810
	'Username',
2811
	'text',
2812
	$pconfig['ppp_username'],
2813
	['autocomplete' => 'new-password']
2814
));
2815

    
2816
$section->addPassword(new Form_Input(
2817
	'ppp_password',
2818
	'Password',
2819
	'password',
2820
	$pconfig['ppp_password']
2821
));
2822

    
2823
$section->addInput(new Form_Input(
2824
	'phone',
2825
	'*Phone number',
2826
	'text',
2827
	$pconfig['phone']
2828
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2829

    
2830
$section->addInput(new Form_Input(
2831
	'apn',
2832
	'Access Point Name',
2833
	'text',
2834
	$pconfig['apn']
2835
));
2836

    
2837

    
2838
function build_port_list() {
2839
	$list = array("" => "None");
2840

    
2841
	$portlist = glob("/dev/cua*");
2842
	$modems	  = glob("/dev/modem*");
2843
	$portlist = array_merge($portlist, $modems);
2844

    
2845
	foreach ($portlist as $port) {
2846
		if (preg_match("/\.(lock|init)$/", $port)) {
2847
			continue;
2848
		}
2849

    
2850
	$list[trim($port)] = $port;
2851
	}
2852

    
2853
	return($list);
2854
}
2855

    
2856
$section->addInput(new Form_Select(
2857
	'port',
2858
	"*Modem port",
2859
	$pconfig['port'],
2860
	build_port_list()
2861
));
2862

    
2863
$section->addInput(new Form_Button(
2864
	'btnadvppp',
2865
	'Advanced PPP',
2866
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2867
	'fa-cog'
2868
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2869

    
2870
$form->add($section);
2871

    
2872
// PPPoE configuration
2873
$section = new Form_Section('PPPoE Configuration');
2874
$section->addClass('pppoe');
2875

    
2876
$section->addInput(new Form_Input(
2877
	'pppoe_username',
2878
	'*Username',
2879
	'text',
2880
	$pconfig['pppoe_username'],
2881
	['autocomplete' => 'new-password']
2882
));
2883

    
2884
$section->addPassword(new Form_Input(
2885
	'pppoe_password',
2886
	'*Password',
2887
	'password',
2888
	$pconfig['pppoe_password']
2889
));
2890

    
2891
$section->addInput(new Form_Input(
2892
	'provider',
2893
	'Service name',
2894
	'text',
2895
	$pconfig['provider']
2896
))->setHelp('This field can usually be left empty.');
2897

    
2898
$section->addInput(new Form_Input(
2899
	'hostuniq',
2900
	'Host-Uniq',
2901
	'text',
2902
	$pconfig['hostuniq']
2903
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2904

    
2905
$section->addInput(new Form_Checkbox(
2906
	'pppoe_dialondemand',
2907
	'Dial on demand',
2908
	'Enable Dial-On-Demand mode ',
2909
	$pconfig['pppoe_dialondemand'],
2910
	'enable'
2911
));
2912

    
2913
$section->addInput(new Form_Input(
2914
	'pppoe_idletimeout',
2915
	'Idle timeout',
2916
	'number',
2917
	$pconfig['pppoe_idletimeout'],
2918
	['min' => 0]
2919
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2920
			'An idle timeout of zero disables this feature.');
2921

    
2922
$section->addInput(new Form_Select(
2923
	'pppoe-reset-type',
2924
	'Periodic reset',
2925
	$pconfig['pppoe-reset-type'],
2926
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2927
))->setHelp('Select a reset timing type.');
2928

    
2929
$group = new Form_Group('Custom reset');
2930
$group->addClass('pppoecustom');
2931

    
2932
$group->add(new Form_Input(
2933
	'pppoe_resethour',
2934
	null,
2935
	'number',
2936
	$pconfig['pppoe_resethour'],
2937
	['min' => 0, 'max' => 23]
2938
))->setHelp('Hour (0-23)');
2939

    
2940
$group->add(new Form_Input(
2941
	'pppoe_resetminute',
2942
	null,
2943
	'number',
2944
	$pconfig['pppoe_resetminute'],
2945
	['min' => 0, 'max' => 59]
2946
))->setHelp('Minutes (0-59)');
2947

    
2948
$group->add(new Form_Input(
2949
	'pppoe_resetdate',
2950
	null,
2951
	'text',
2952
	$pconfig['pppoe_resetdate']
2953
))->setHelp('Specific date (mm/dd/yyyy)');
2954

    
2955
$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');
2956

    
2957
$section->add($group);
2958

    
2959
$group = new Form_MultiCheckboxGroup('cron based reset');
2960
$group->addClass('pppoepreset');
2961

    
2962
$group->add(new Form_MultiCheckbox(
2963
	'pppoe_pr_preset_val',
2964
	null,
2965
	'Reset at each month ("0 0 1 * *")',
2966
	$pconfig['pppoe_monthly'],
2967
	'monthly'
2968
))->displayAsRadio();
2969

    
2970
$group->add(new Form_MultiCheckbox(
2971
	'pppoe_pr_preset_val',
2972
	null,
2973
	'Reset at each week ("0 0 * * 0")',
2974
	$pconfig['pppoe_weekly'],
2975
	'weekly'
2976
))->displayAsRadio();
2977

    
2978
$group->add(new Form_MultiCheckbox(
2979
	'pppoe_pr_preset_val',
2980
	null,
2981
	'Reset at each day ("0 0 * * *")',
2982
	$pconfig['pppoe_daily'],
2983
	'daily'
2984
))->displayAsRadio();
2985

    
2986
$group->add(new Form_MultiCheckbox(
2987
	'pppoe_pr_preset_val',
2988
	null,
2989
	'Reset at each hour ("0 * * * *")',
2990
	$pconfig['pppoe_hourly'],
2991
	'hourly'
2992
))->displayAsRadio();
2993

    
2994
$section->add($group);
2995

    
2996
$section->addInput(new Form_Button(
2997
	'btnadvppp',
2998
	'Advanced and MLPPP',
2999
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3000
	'fa-cog'
3001
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3002

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

    
3005
// PPTP & L2TP Configuration section
3006
$section = new Form_Section('PPTP/L2TP Configuration');
3007
$section->addClass('pptp');
3008

    
3009
$section->addInput(new Form_Input(
3010
	'pptp_username',
3011
	'*Username',
3012
	'text',
3013
	$pconfig['pptp_username'],
3014
	['autocomplete' => 'new-password']
3015
));
3016

    
3017
$section->addPassword(new Form_Input(
3018
	'pptp_password',
3019
	'*Password',
3020
	'password',
3021
	$pconfig['pptp_password']
3022
));
3023

    
3024
$group = new Form_Group('Shared Secret');
3025

    
3026
$group->add(new Form_Input(
3027
	'l2tp_secret',
3028
	'*Secret',
3029
	'password',
3030
	$pconfig['l2tp_secret']
3031
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3032
	    'important control packet contents. (Optional)');
3033

    
3034
$group->addClass('l2tp_secret');
3035
$section->add($group);
3036

    
3037
$section->addInput(new Form_IpAddress(
3038
	'pptp_local0',
3039
	'*Local IP address',
3040
	$pconfig['pptp_localip'][0],
3041
	'V4'
3042
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
3043

    
3044
$section->addInput(new Form_IpAddress(
3045
	'pptp_remote0',
3046
	'*Remote IP address',
3047
	$pconfig['pptp_remote'][0],
3048
	'HOSTV4'
3049
));
3050

    
3051
$section->addInput(new Form_Checkbox(
3052
	'pptp_dialondemand',
3053
	'Dial on demand',
3054
	'Enable Dial-On-Demand mode ',
3055
	$pconfig['pptp_dialondemand'],
3056
	'enable'
3057
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3058
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3059

    
3060
$section->addInput(new Form_Input(
3061
	'pptp_idletimeout',
3062
	'Idle timeout (seconds)',
3063
	'number',
3064
	$pconfig['pptp_idletimeout'],
3065
	['min' => 0]
3066
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3067
			'An idle timeout of zero disables this feature.');
3068

    
3069
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3070
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3071
} else {
3072
	$mlppp_text = "";
3073
}
3074

    
3075
$section->addInput(new Form_Button(
3076
	'btnadvppp',
3077
	'Advanced and MLPPP',
3078
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3079
	'fa-cog'
3080
))->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);
3081

    
3082
$form->add($section);
3083

    
3084
// Wireless interface
3085
if (isset($wancfg['wireless'])) {
3086

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

    
3089
	$section->addInput(new Form_Checkbox(
3090
		'persistcommonwireless',
3091
		'Persist common settings',
3092
		'Preserve common wireless configuration through interface deletions and reassignments.',
3093
		$pconfig['persistcommonwireless'],
3094
		'yes'
3095
	));
3096

    
3097
	$mode_list = ['auto' => 'Auto'];
3098

    
3099
	if (is_array($wl_modes)) {
3100
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3101
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3102
		}
3103
	}
3104

    
3105
	if (count($mode_list) == 1) {
3106
		$mode_list[''] = '';
3107
	}
3108

    
3109
	$section->addInput(new Form_Select(
3110
		'standard',
3111
		'Standard',
3112
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3113
		$mode_list
3114
	));
3115

    
3116
	if (isset($wl_modes['11g'])) {
3117
		$section->addInput(new Form_Select(
3118
			'protmode',
3119
			'802.11g OFDM Protection Mode',
3120
			$pconfig['protmode'],
3121
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3122
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3123
	} else {
3124
		$form->addGlobal(new Form_Input(
3125
			'protmode',
3126
			null,
3127
			'hidden',
3128
			'off'
3129
		));
3130
	}
3131

    
3132
	$mode_list = ['0' => gettext('Auto')];
3133

    
3134
	if (is_array($wl_modes)) {
3135
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3136
			if ($wl_standard == "11g") {
3137
				$wl_standard = "11b/g";
3138
			} else if ($wl_standard == "11ng") {
3139
				$wl_standard = "11b/g/n";
3140
			} else if ($wl_standard == "11na") {
3141
				$wl_standard = "11a/n";
3142
			}
3143

    
3144
			foreach ($wl_channels as $wl_channel) {
3145
				if (isset($wl_chaninfo[$wl_channel])) {
3146
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3147
				} else {
3148
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3149
				}
3150
			}
3151
		}
3152
	}
3153

    
3154
	$section->addInput(new Form_Select(
3155
		'channel',
3156
		'Channel',
3157
		$pconfig['channel'],
3158
		$mode_list
3159
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3160
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3161

    
3162
	$section->addInput(new Form_Select(
3163
		'channel_width',
3164
		'Channel width',
3165
		$pconfig['channel_width'],
3166
		$wl_ht_modes
3167
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3168

    
3169
	if (ANTENNAS) {
3170
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3171
			$group = new Form_Group('Antenna Settings');
3172

    
3173
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3174
				$group->add(new Form_Select(
3175
					'diversity',
3176
					null,
3177
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3178
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3179
				))->setHelp('Diversity');
3180
			}
3181

    
3182
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3183
				$group->add(new Form_Select(
3184
					'txantenna',
3185
					null,
3186
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3187
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3188
				))->setHelp('Transmit antenna');
3189
			}
3190

    
3191
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3192
				$group->add(new Form_Select(
3193
					'rxantenna',
3194
					null,
3195
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3196
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3197
				))->setHelp('Receive antenna');
3198
			}
3199

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

    
3202
			$section->add($group);
3203
		}
3204
	}
3205

    
3206
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3207
			$section->addInput(new Form_Input(
3208
				'distance',
3209
				'Distance setting (meters)',
3210
				'test',
3211
				$pconfig['distance']
3212
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3213
	}
3214

    
3215
	$form->add($section);
3216

    
3217
	// Regulatory settings
3218
	$section = new Form_Section('Regulatory Settings');
3219

    
3220
	$domain_list = array("" => 'Default');
3221

    
3222
	if (is_array($wl_regdomains)) {
3223
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3224
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3225
		}
3226
	}
3227

    
3228
	$section->addInput(new Form_Select(
3229
		'regdomain',
3230
		'Regulatory domain',
3231
		$pconfig['regdomain'],
3232
		$domain_list
3233
	))->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');
3234

    
3235
	$country_list = array('' => 'Default');
3236

    
3237
	if (is_array($wl_countries)) {
3238
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3239
			$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']);
3240
		}
3241
	}
3242

    
3243
	$section->addInput(new Form_Select(
3244
		'regcountry',
3245
		'Country',
3246
		$pconfig['regcountry'],
3247
		$country_list
3248
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3249

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

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

    
3263
	$section = new Form_Section('Network-Specific Wireless Configuration');
3264

    
3265
	$section->addInput(new Form_Select(
3266
		'mode',
3267
		'Mode',
3268
		$pconfig['mode'],
3269
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3270
	));
3271

    
3272
	$section->addInput(new Form_Input(
3273
		'ssid',
3274
		'SSID',
3275
		'text',
3276
		$pconfig['ssid']
3277
	));
3278

    
3279
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3280
		$section->addInput(new Form_Select(
3281
			'puremode',
3282
			'Minimum wireless standard',
3283
			$pconfig['puremode'],
3284
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3285
		))->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)');
3286
	} elseif (isset($wl_modes['11g'])) {
3287
		$section->addInput(new Form_Checkbox(
3288
			'puremode',
3289
			'802.11g only',
3290
			null,
3291
			$pconfig['puremode'],
3292
			'11g'
3293
		))->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)');
3294
	}
3295

    
3296
	$section->addInput(new Form_Checkbox(
3297
		'apbridge_enable',
3298
		'Allow intra-BSS communication',
3299
		'Allow packets to pass between wireless clients directly when operating as an access point',
3300
		$pconfig['apbridge_enable'],
3301
		'yes'
3302
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3303

    
3304
	$section->addInput(new Form_Checkbox(
3305
		'wme_enable',
3306
		'Enable WME',
3307
		'Force the card to use WME (wireless QoS)',
3308
		$pconfig['wme_enable'],
3309
		'yes'
3310
	));
3311

    
3312
	$section->addInput(new Form_Checkbox(
3313
		'hidessid_enable',
3314
		'Hide SSID',
3315
		'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.)',
3316
		$pconfig['hidessid_enable'],
3317
		'yes'
3318
	));
3319

    
3320
	$form->add($section);
3321

    
3322
	// WPA Section
3323
	$section = new Form_Section('WPA');
3324

    
3325
	$section->addInput(new Form_Checkbox(
3326
		'wpa_enable',
3327
		'Enable',
3328
		'Enable WPA',
3329
		$pconfig['wpa_enable'],
3330
		'yes'
3331
	));
3332

    
3333
	$section->addInput(new Form_Input(
3334
		'passphrase',
3335
		'WPA Pre-Shared Key',
3336
		'text',
3337
		$pconfig['passphrase']
3338
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3339

    
3340
	$section->addInput(new Form_Select(
3341
		'wpa_mode',
3342
		'WPA mode',
3343
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3344
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3345
	));
3346

    
3347
	$section->addInput(new Form_Select(
3348
		'wpa_key_mgmt',
3349
		'WPA Key Management Mode',
3350
		$pconfig['wpa_key_mgmt'],
3351
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3352
	));
3353

    
3354
	$section->addInput(new Form_Select(
3355
		'wpa_pairwise',
3356
		'WPA Pairwise',
3357
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3358
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3359
	));
3360

    
3361
	$section->addInput(new Form_Input(
3362
		'wpa_group_rekey',
3363
		'Group Key Rotation',
3364
		'number',
3365
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3366
		['min' => '1', 'max' => 9999]
3367
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3368

    
3369
	$section->addInput(new Form_Input(
3370
		'wpa_gmk_rekey',
3371
		'Group Master Key Regeneration',
3372
		'number',
3373
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3374
		['min' => '1', 'max' => 9999]
3375
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3376

    
3377
	$section->addInput(new Form_Checkbox(
3378
		'wpa_strict_rekey',
3379
		'Strict Key Regeneration',
3380
		'Force the AP to rekey whenever a client disassociates',
3381
		$pconfig['wpa_strict_rekey'],
3382
		'yes'
3383
	));
3384

    
3385
	$form->add($section);
3386

    
3387
	$section = new Form_Section('802.1x RADIUS Options');
3388

    
3389
	$section->addInput(new Form_Checkbox(
3390
		'ieee8021x',
3391
		'IEEE802.1X',
3392
		'Enable 802.1X authentication',
3393
		$pconfig['ieee8021x'],
3394
		'yes'
3395
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3396

    
3397
	$group = new Form_Group('Primary 802.1X server');
3398

    
3399
	$group->add(new Form_IpAddress(
3400
		'auth_server_addr',
3401
		'IP Address',
3402
		$pconfig['auth_server_addr']
3403
	))->setHelp('IP address of the RADIUS server');
3404

    
3405
	$group->add(new Form_Input(
3406
		'auth_server_port',
3407
		'Port',
3408
		'number',
3409
		$pconfig['auth_server_port']
3410
	))->setHelp('Server auth port. Default is 1812');
3411

    
3412
	$group->add(new Form_Input(
3413
		'auth_server_shared_secret',
3414
		'Shared Secret',
3415
		'text',
3416
		$pconfig['auth_server_shared_secret']
3417
	))->setHelp('RADIUS Shared secret for this firewall');
3418

    
3419
	$section->add($group);
3420

    
3421
	$group = new Form_Group('Secondary 802.1X server');
3422

    
3423
	$group->add(new Form_IpAddress(
3424
		'auth_server_addr2',
3425
		'IP Address',
3426
		$pconfig['auth_server_addr2']
3427
	))->setHelp('IP address of the RADIUS server');
3428

    
3429
	$group->add(new Form_Input(
3430
		'auth_server_port2',
3431
		'Port',
3432
		'number',
3433
		$pconfig['auth_server_port2']
3434
	))->setHelp('Server auth port. Default is 1812');
3435

    
3436
	$group->add(new Form_Input(
3437
		'auth_server_shared_secret2',
3438
		'Shared Secret',
3439
		'text',
3440
		$pconfig['auth_server_shared_secret2']
3441
	))->setHelp('RADIUS Shared secret for this firewall');
3442

    
3443
	$section->add($group);
3444

    
3445
	$section->addInput(new Form_Checkbox(
3446
		'rsn_preauth',
3447
		'Authentication Roaming Preauth',
3448
		null,
3449
		$pconfig['rsn_preauth'],
3450
		'yes'
3451
	));
3452

    
3453
	$form->add($section);
3454
}
3455

    
3456
$section = new Form_Section('Reserved Networks');
3457

    
3458
$section->addInput(new Form_Checkbox(
3459
	'blockpriv',
3460
	'Block private networks and loopback addresses',
3461
	'',
3462
	$pconfig['blockpriv'],
3463
	'yes'
3464
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3465
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3466
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3467

    
3468
$section->addInput(new Form_Checkbox(
3469
	'blockbogons',
3470
	'Block bogon networks',
3471
	'',
3472
	$pconfig['blockbogons'],
3473
	'yes'
3474
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3475
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3476
			'This option should only be used on external interfaces (WANs), it is not necessary on local interfaces and it can potentially block required local traffic.%1$s' .
3477
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3478

    
3479
$form->add($section);
3480

    
3481
$form->addGlobal(new Form_Input(
3482
	'if',
3483
	null,
3484
	'hidden',
3485
	$if
3486
));
3487

    
3488
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3489
	$form->addGlobal(new Form_Input(
3490
		'ppp_port',
3491
		null,
3492
		'hidden',
3493
		$pconfig['port']
3494
	));
3495
}
3496

    
3497
$form->addGlobal(new Form_Input(
3498
	'ptpid',
3499
	null,
3500
	'hidden',
3501
	$pconfig['ptpid']
3502
));
3503

    
3504

    
3505
// Add new gateway modal pop-up
3506
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3507

    
3508
$modal->addInput(new Form_Checkbox(
3509
	'defaultgw4',
3510
	'Default',
3511
	'Default gateway',
3512
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3513
));
3514

    
3515
$modal->addInput(new Form_Input(
3516
	'gatewayname4',
3517
	'Gateway name',
3518
	'text',
3519
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3520
));
3521

    
3522
$modal->addInput(new Form_IpAddress(
3523
	'gatewayip4',
3524
	'Gateway IPv4',
3525
	$gateway_settings4['gateway'],
3526
	'V4'
3527
));
3528

    
3529
$modal->addInput(new Form_Input(
3530
	'gatewaydescr4',
3531
	'Description',
3532
	'text',
3533
	$gateway_settings4['descr']
3534
));
3535

    
3536
$btnaddgw4 = new Form_Button(
3537
	'add4',
3538
	'Add',
3539
	null,
3540
	'fa-plus'
3541
);
3542

    
3543
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3544

    
3545
$btncnxgw4 = new Form_Button(
3546
	'cnx4',
3547
	'Cancel',
3548
	null,
3549
	'fa-undo'
3550
);
3551

    
3552
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3553

    
3554
$modal->addInput(new Form_StaticText(
3555
	null,
3556
	$btnaddgw4 . $btncnxgw4
3557
));
3558

    
3559
$form->add($modal);
3560

    
3561
print($form);
3562
?>
3563

    
3564
<script type="text/javascript">
3565
//<![CDATA[
3566
events.push(function() {
3567
	function updateType(t) {
3568

    
3569
		switch (t) {
3570
			case "none": {
3571
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3572
				break;
3573
			}
3574
			case "staticv4": {
3575
				$('.dhcpadvanced, .none, .dhcp').hide();
3576
				$('.pppoe, .pptp, .ppp').hide();
3577
				break;
3578
			}
3579
			case "dhcp": {
3580
				$('.dhcpadvanced, .none').hide();
3581
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3582
										//			about the staticv4 class
3583
				$('.pppoe, .pptp, .ppp').hide();
3584
				break;
3585
			}
3586
			case "ppp": {
3587
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3588
				country_list();
3589
				break;
3590
			}
3591
			case "pppoe": {
3592
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3593
				break;
3594
			}
3595
			case "l2tp": {
3596
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3597
				$('.pptp, .l2tp_secret').show();
3598
				break;
3599
			}
3600
			case "pptp": {
3601
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3602
				$('.pptp').show();
3603
				break;
3604
			}
3605
		}
3606

    
3607
		if (t != "l2tp" && t != "pptp") {
3608
			$('.'+t).show();
3609
		}
3610
	}
3611

    
3612
	function updateTypeSix(t) {
3613
		if (!isNaN(t[0])) {
3614
			t = '_' + t;
3615
		}
3616

    
3617
		switch (t) {
3618
			case "none": {
3619
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3620
				break;
3621
			}
3622
			case "staticv6": {
3623
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3624
				break;
3625
			}
3626
			case "slaac": {
3627
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3628
				break;
3629
			}
3630
			case "dhcp6": {
3631
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3632
				break;
3633
			}
3634
			case "_6rd": {
3635
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3636
				break;
3637
			}
3638
			case "_6to4": {
3639
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3640
				break;
3641
			}
3642
			case "track6": {
3643
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3644
				update_track6_prefix();
3645
				break;
3646
			}
3647
		}
3648

    
3649
		if (t != "l2tp" && t != "pptp") {
3650
			$('.'+t).show();
3651
		}
3652
	}
3653

    
3654
	function show_reset_settings(reset_type) {
3655
		if (reset_type == 'preset') {
3656
			$('.pppoepreset').show();
3657
			$('.pppoecustom').hide();
3658
		} else if (reset_type == 'custom') {
3659
			$('.pppoecustom').show();
3660
			$('.pppoepreset').hide();
3661
		} else {
3662
			$('.pppoecustom').hide();
3663
			$('.pppoepreset').hide();
3664
		}
3665
	}
3666

    
3667
	function update_track6_prefix() {
3668
		var iface = $("#track6-interface").val();
3669
		if (iface == null) {
3670
			return;
3671
		}
3672

    
3673
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3674
		if (track6_prefix_ids == null) {
3675
			return;
3676
		}
3677

    
3678
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3679
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3680
	}
3681

    
3682
	function addOption_v4() {
3683
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3684
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3685
	}
3686

    
3687
	function addOption_v6() {
3688
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3689
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3690
	}
3691

    
3692
	function addSelectboxOption(selectbox, text, value) {
3693
		var optn = document.createElement("OPTION");
3694
		optn.text = text;
3695
		optn.value = value;
3696
		selectbox.append(optn);
3697
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3698
	}
3699

    
3700
	function country_list() {
3701
		$('#country').children().remove();
3702
		$('#provider_list').children().remove();
3703
		$('#providerplan').children().remove();
3704
		$.ajax("getserviceproviders.php",{
3705
			success: function(response) {
3706

    
3707
				var responseTextArr = response.split("\n");
3708
				responseTextArr.sort();
3709

    
3710
				responseTextArr.forEach( function(value) {
3711
					country = value.split(":");
3712
					$('#country').append($('<option>', {
3713
						value: country[1],
3714
						text : country[0]
3715
					}));
3716
				});
3717
			}
3718
		});
3719
	}
3720

    
3721
	function providers_list() {
3722
		$('#provider_list').children().remove();
3723
		$('#providerplan').children().remove();
3724
		$.ajax("getserviceproviders.php",{
3725
			type: 'post',
3726
			data: {country : $('#country').val()},
3727
			success: function(response) {
3728
				var responseTextArr = response.split("\n");
3729
				responseTextArr.sort();
3730
				responseTextArr.forEach( function(value) {
3731
					$('#provider_list').append($('<option>', {
3732
							value: value,
3733
							text : value
3734
					}));
3735
				});
3736
			}
3737
		});
3738
	}
3739

    
3740
	function providerplan_list() {
3741
		$('#providerplan').children().remove();
3742
		$.ajax("getserviceproviders.php",{
3743
			type: 'post',
3744
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3745
			success: function(response) {
3746
				var responseTextArr = response.split("\n");
3747
				responseTextArr.sort();
3748

    
3749
				$('#providerplan').append($('<option>', {
3750
					value: '',
3751
					text : ''
3752
				}));
3753

    
3754
				responseTextArr.forEach( function(value) {
3755
					if (value != "") {
3756
						providerplan = value.split(":");
3757

    
3758
						$('#providerplan').append($('<option>', {
3759
							value: providerplan[1],
3760
							text : providerplan[0] + " - " + providerplan[1]
3761
						}));
3762
					}
3763
				});
3764
			}
3765
		});
3766
	}
3767

    
3768
	function prefill_provider() {
3769
		$.ajax("getserviceproviders.php",{
3770
			type: 'post',
3771
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3772
			success: function(data, textStatus, response) {
3773
				var xmldoc = response.responseXML;
3774
				var provider = xmldoc.getElementsByTagName('connection')[0];
3775
				$('#ppp_username').val('');
3776
				$('#ppp_password').val('');
3777
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3778
					$('#phone').val('#777');
3779
					$('#apn').val('');
3780
				} else {
3781
					$('#phone').val('*99#');
3782
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3783
				}
3784
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3785
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3786
				$('#ppp_username').val(ppp_username);
3787
				$('#ppp_password').val(ppp_password);
3788
			}
3789
		});
3790
	}
3791

    
3792
	function show_dhcp6adv() {
3793
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3794
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3795

    
3796
		hideCheckbox('dhcp6usev4iface', ovr);
3797
		hideCheckbox('dhcp6prefixonly', ovr);
3798
		hideInput('dhcp6-ia-pd-len', ovr);
3799
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3800
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3801

    
3802
		hideClass('dhcp6advanced', !adv || ovr);
3803
	}
3804

    
3805
	function setDHCPoptions() {
3806
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3807
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3808

    
3809
		if (ovr) {
3810
			hideInput('dhcphostname', true);
3811
			hideIpAddress('alias-address', true);
3812
			hideInput('dhcprejectfrom', true);
3813
			hideInput('adv_dhcp_config_file_override_path', false);
3814
			hideClass('dhcpadvanced', true);
3815
		} else {
3816
			hideInput('dhcphostname', false);
3817
			hideIpAddress('alias-address', false);
3818
			hideInput('dhcprejectfrom', false);
3819
			hideInput('adv_dhcp_config_file_override_path', true);
3820
			hideClass('dhcpadvanced', !adv);
3821
		}
3822
	}
3823

    
3824
	// DHCP preset actions
3825
	// Set presets from value of radio buttons
3826
	function setPresets(val) {
3827
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3828
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3829
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3830
		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']);?>");
3831
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3832
	}
3833

    
3834
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3835
		$('#adv_dhcp_pt_timeout').val(timeout);
3836
		$('#adv_dhcp_pt_retry').val(retry);
3837
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3838
		$('#adv_dhcp_pt_reboot').val(reboot);
3839
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3840
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3841
	}
3842

    
3843
	function setPPPoEDialOnDemandItems() {
3844
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3845
	}
3846

    
3847
	function setPPTPDialOnDemandItems() {
3848
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3849
	}
3850

    
3851
	// ---------- On initial page load ------------------------------------------------------------
3852

    
3853
	updateType($('#type').val());
3854
	updateTypeSix($('#type6').val());
3855
	show_reset_settings($('#pppoe-reset-type').val());
3856
	hideClass('dhcp6advanced', true);
3857
	hideClass('dhcpadvanced', true);
3858
	show_dhcp6adv();
3859
	setDHCPoptions();
3860
	setPPPoEDialOnDemandItems();
3861
	setPPTPDialOnDemandItems();
3862

    
3863
	// Set preset buttons on page load
3864
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3865
	if (sv == "") {
3866
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3867
	} else {
3868
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3869
	}
3870

    
3871
	// Set preset from value
3872
	setPresets(sv);
3873

    
3874
	// If the user wants to add a gateway, then add that to the gateway selection
3875
	if ($("#gatewayip4").val() != '') {
3876
		addOption_v4();
3877
	}
3878
	if ($("#gatewayip6").val() != '') {
3879
		addOption_v6();
3880
	}
3881

    
3882
	// ---------- Click checkbox handlers ---------------------------------------------------------
3883

    
3884
	$('#type').on('change', function() {
3885
		updateType(this.value);
3886
	});
3887

    
3888
	$('#type6').on('change', function() {
3889
		updateTypeSix(this.value);
3890
	});
3891

    
3892
	$('#track6-interface').on('change', function() {
3893
		update_track6_prefix();
3894
	});
3895

    
3896
	$('#pppoe-reset-type').on('change', function() {
3897
		show_reset_settings(this.value);
3898
	});
3899

    
3900
	$("#add4").click(function() {
3901
		addOption_v4();
3902
		$("#newgateway4").modal('hide');
3903
	});
3904

    
3905
	$("#cnx4").click(function() {
3906
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3907
		$("#gatewayip4").val('');
3908
		$("#gatewaydescr4").val('');
3909
		$("#defaultgw4").prop("checked", false);
3910
		$("#newgateway4").modal('hide');
3911
	});
3912

    
3913
	$("#add6").click(function() {
3914
		addOption_v6();
3915
		$("#newgateway6").modal('hide');
3916
	});
3917

    
3918
	$("#cnx6").click(function() {
3919
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3920
		$("#gatewayip6").val('');
3921
		$("#gatewaydescr6").val('');
3922
		$("#defaultgw6").prop("checked", false);
3923
		$("#newgateway6").modal('hide');
3924
	});
3925

    
3926
	$('#country').on('change', function() {
3927
		providers_list();
3928
	});
3929

    
3930
	$('#provider_list').on('change', function() {
3931
		providerplan_list();
3932
	});
3933

    
3934
	$('#providerplan').on('change', function() {
3935
		prefill_provider();
3936
	});
3937

    
3938
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3939
		setDHCPoptions();
3940
	});
3941

    
3942
	$('#adv_dhcp6_config_advanced').click(function () {
3943
		show_dhcp6adv();
3944
	});
3945

    
3946
	$('#adv_dhcp6_config_file_override').click(function () {
3947
		show_dhcp6adv();
3948
	});
3949

    
3950
	// On click . .
3951
	$('#pppoe_dialondemand').click(function () {
3952
		setPPPoEDialOnDemandItems();
3953
	});
3954

    
3955
	$('#pptp_dialondemand').click(function () {
3956
		setPPTPDialOnDemandItems();
3957
	});
3958

    
3959
	$('[name=adv_dhcp_pt_values]').click(function () {
3960
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3961
	});
3962

    
3963
	$('#pppoe_resetdate').datepicker();
3964

    
3965
});
3966
//]]>
3967
</script>
3968

    
3969
<?php include("foot.inc");
(71-71/229)