Project

General

Profile

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

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

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

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

    
50
define("ANTENNAS", false);
51

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

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

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
263
switch ($wancfg['ipaddr']) {
264
	case "dhcp":
265
		$pconfig['type'] = "dhcp";
266
		$pconfig['dhcpvlanenable'] = isset($wancfg['dhcpvlanenable']);
267
		$pconfig['dhcpcvpt'] = $wancfg['dhcpcvpt'];
268
		break;
269
	case "pppoe":
270
	case "pptp":
271
	case "l2tp":
272
	case "ppp":
273
		$pconfig['type'] = $wancfg['ipaddr'];
274
		break;
275
	default:
276
		if (is_ipaddrv4($wancfg['ipaddr'])) {
277
			$pconfig['type'] = "staticv4";
278
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
279
			$pconfig['subnet'] = $wancfg['subnet'];
280
			$pconfig['gateway'] = $wancfg['gateway'];
281
		} 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'))) {
579
			$input_errors[] = gettext("The OpenVPN and VTI interface description 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']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
623
		$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only with a static IPv6 configuration. Please disable the DHCPv6 Server service on this interface first, then change the interface configuration.");
624
	}
625

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

    
733
			if (empty($_POST['track6-interface'])) {
734
				$input_errors[] = gettext("A valid interface to track must be selected.");
735
			}
736

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

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

    
776
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
777
			if ($_POST['subnet'] < 31) {
778
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
779
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
780
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
781
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
782
				}
783
			}
784

    
785
			foreach ($staticroutes as $route_subnet) {
786
				list($network, $subnet) = explode("/", $route_subnet);
787
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
788
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
789
					break;
790
				}
791
				unset($network, $subnet);
792
			}
793
		}
794
	}
795
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
796
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
797

    
798
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
799
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
800
		} else {
801
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
802
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
803
			}
804
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
805
			if (count($where_ipaddr_configured)) {
806
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
807
				foreach ($where_ipaddr_configured as $subnet_conflict) {
808
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
809
				}
810
				$input_errors[] = $subnet_conflict_text;
811
			}
812

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

    
839
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
840
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
841
		$match = false;
842
		foreach ($a_gateways as $gateway) {
843
			if (in_array($_POST['gateway'], $gateway)) {
844
				$match = true;
845
			}
846
		}
847
		if (!$match) {
848
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
849
		}
850
	}
851
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
852
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
853
		$match = false;
854
		foreach ($a_gateways as $gateway) {
855
			if (in_array($_POST['gatewayv6'], $gateway)) {
856
				$match = true;
857
			}
858
		}
859
		if (!$match) {
860
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
861
		}
862
	}
863

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

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

    
918
		unset($min_mtu, $max_mtu);
919

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

    
938
				$realhwif_array = get_parent_interface($ifdata['if']);
939
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
940
				$parent_realhwif = $realhwif_array[0];
941

    
942
				if ($parent_realhwif != $wancfg['if']) {
943
					continue;
944
				}
945

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

    
1042
		if ($_POST['passphrase']) {
1043
			$passlen = strlen($_POST['passphrase']);
1044
			if ($passlen < 8 || $passlen > 63) {
1045
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1046
			}
1047
		}
1048

    
1049
		if ($_POST['wpa_enable'] == "yes") {
1050
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1051
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1052
			}
1053
		}
1054
	}
1055

    
1056
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1057
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1058
	}
1059

    
1060
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1061
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1062
	}
1063

    
1064
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1065
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1066
	}
1067

    
1068
	if ($_POST['gatewayip4']) {
1069
		// The user wants to add an IPv4 gateway - validate the settings
1070
		$gateway_settings4 = array();
1071

    
1072
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1073
		$gateway_settings4['interface'] = $_POST['if'];
1074
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1075
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1076
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1077
		$gateway_settings4['ipprotocol'] = 'inet';
1078
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1079
		foreach ($gw_input_errors as $input_error_text) {
1080
			$input_errors[] = $input_error_text;
1081
		}
1082
	}
1083

    
1084
	if ($_POST['gatewayip6']) {
1085
		// The user wants to add an IPv6 gateway - validate the settings
1086
		$gateway_settings6 = array();
1087

    
1088
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1089
		$gateway_settings6['interface'] = $_POST['if'];
1090
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1091
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1092
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1093
		$gateway_settings6['ipprotocol'] = 'inet6';
1094
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1095
		foreach ($gw_input_errors as $input_error_text) {
1096
			$input_errors[] = $input_error_text;
1097
		}
1098
	}
1099

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

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

    
1149
		unset($wancfg['dhcpvlanenable']);
1150
		unset($wancfg['dhcpcvpt']);
1151

    
1152
		unset($wancfg['adv_dhcp_pt_timeout']);
1153
		unset($wancfg['adv_dhcp_pt_retry']);
1154
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1155
		unset($wancfg['adv_dhcp_pt_reboot']);
1156
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1157
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1158

    
1159
		unset($wancfg['adv_dhcp_pt_values']);
1160

    
1161
		unset($wancfg['adv_dhcp_send_options']);
1162
		unset($wancfg['adv_dhcp_request_options']);
1163
		unset($wancfg['adv_dhcp_required_options']);
1164
		unset($wancfg['adv_dhcp_option_modifiers']);
1165

    
1166
		unset($wancfg['adv_dhcp_config_advanced']);
1167
		unset($wancfg['adv_dhcp_config_file_override']);
1168
		unset($wancfg['adv_dhcp_config_file_override_path']);
1169

    
1170
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1171
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1172
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1173
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1174

    
1175
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1176
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1177
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1178
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1179
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1180

    
1181
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1182
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1183
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1184
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1185
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1186

    
1187
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1188
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1189
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1190

    
1191
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1192
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1193
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1194
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1195

    
1196
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1197
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1198
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1199
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1200
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1201

    
1202
		unset($wancfg['adv_dhcp6_config_advanced']);
1203
		unset($wancfg['adv_dhcp6_config_file_override']);
1204
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1205

    
1206
		unset($wancfg['pppoe_password']);
1207
		unset($wancfg['pptp_username']);
1208
		unset($wancfg['pptp_password']);
1209
		unset($wancfg['l2tp_secret']);
1210
		unset($wancfg['provider']);
1211
		unset($wancfg['hostuniq']);
1212
		unset($wancfg['ondemand']);
1213
		unset($wancfg['timeout']);
1214
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1215
			unset($wancfg['pppoe']['pppoe-reset-type']);
1216
		}
1217
		unset($wancfg['local']);
1218

    
1219
		unset($wancfg['remote']);
1220
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1221
			if ($wancfg['ipaddr'] != 'ppp') {
1222
				unset($a_ppps[$pppid]['apn']);
1223
				unset($a_ppps[$pppid]['phone']);
1224
				unset($a_ppps[$pppid]['provider']);
1225
				unset($a_ppps[$pppid]['ondemand']);
1226
			}
1227
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1228
				unset($a_ppps[$pppid]['localip']);
1229
				unset($a_ppps[$pppid]['subnet']);
1230
				unset($a_ppps[$pppid]['gateway']);
1231
			}
1232
			if ($wancfg['ipaddr'] != 'pppoe') {
1233
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1234
				unset($a_ppps[$pppid]['hostuniq']);
1235
			}
1236
			if ($wancfg['type'] != $_POST['type']) {
1237
				unset($a_ppps[$pppid]['idletimeout']);
1238
			}
1239
		}
1240

    
1241
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1242
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1243

    
1244
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1245
		switch ($_POST['type']) {
1246
			case "staticv4":
1247
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1248
				$wancfg['subnet'] = $_POST['subnet'];
1249
				if ($_POST['gateway'] != "none") {
1250
					$wancfg['gateway'] = $_POST['gateway'];
1251
				}
1252
				break;
1253
			case "dhcp":
1254
				$wancfg['ipaddr'] = "dhcp";
1255
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1256
				$wancfg['alias-address'] = $_POST['alias-address'];
1257
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1258
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1259

    
1260
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1261
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1262
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1263
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1264
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1265
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1266

    
1267
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1268

    
1269
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1270
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1271
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1272
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1273

    
1274
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1275
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1276
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1277

    
1278
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1279
				if ($gateway_item) {
1280
					$a_gateways[] = $gateway_item;
1281
				}
1282
				if ($_POST['dhcpvlanenable'] == "yes") {
1283
					$wancfg['dhcpvlanenable'] = true;
1284
				}
1285
				if (!empty($_POST['dhcpcvpt'])) {
1286
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1287
				} else {
1288
					unset($wancfg['dhcpcvpt']);
1289
				}
1290
				break;
1291
			case "ppp":
1292
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1293
				$a_ppps[$pppid]['type'] = $_POST['type'];
1294
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1295
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1296
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1297
				if ($_POST['ppp_password'] != DMYPWD) {
1298
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1299
				}
1300
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1301
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1302
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1303
				$wancfg['ipaddr'] = $_POST['type'];
1304
				break;
1305

    
1306
			case "pppoe":
1307
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1308
				$a_ppps[$pppid]['type'] = $_POST['type'];
1309
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1310
				if (isset($_POST['ppp_port'])) {
1311
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1312
				} else {
1313
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1314
				}
1315
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1316
				if ($_POST['pppoe_password'] != DMYPWD) {
1317
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1318
				}
1319
				if (!empty($_POST['provider'])) {
1320
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1321
				} else {
1322
					$a_ppps[$pppid]['provider'] = true;
1323
				}
1324
				if (!empty($_POST['hostuniq'])) {
1325
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1326
				} else {
1327
					$a_ppps[$pppid]['hostuniq'] = true;
1328
				}
1329
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1330
				if (!empty($_POST['pppoe_idletimeout'])) {
1331
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1332
				} else {
1333
					unset($a_ppps[$pppid]['idletimeout']);
1334
				}
1335

    
1336
				if (!empty($_POST['pppoe-reset-type'])) {
1337
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1338
				} else {
1339
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1340
				}
1341
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1342
				$wancfg['ipaddr'] = $_POST['type'];
1343
				if ($gateway_item) {
1344
					$a_gateways[] = $gateway_item;
1345
				}
1346

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

    
1423
				if ($_POST['dhcp6withoutra'] == "yes") {
1424
					$wancfg['dhcp6withoutra'] = true;
1425
				}
1426
				if ($_POST['dhcp6norelease'] == "yes") {
1427
					$wancfg['dhcp6norelease'] = true;
1428
				}
1429
				if ($_POST['dhcp6vlanenable'] == "yes") {
1430
					$wancfg['dhcp6vlanenable'] = true;
1431
				}
1432
				if (!empty($_POST['dhcp6cvpt'])) {
1433
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1434
				} else {
1435
					unset($wancfg['dhcp6cvpt']);
1436
				}
1437

    
1438
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1439
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1440
				}
1441
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1442
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1443
				}
1444
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1445
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1446
				}
1447
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1448
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1449
				}
1450

    
1451
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1452
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1453
				}
1454
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1455
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1456
				}
1457
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1458
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1459
				}
1460
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1461
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1462
				}
1463
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1464
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1465
				}
1466

    
1467
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1468
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1469
				}
1470
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1471
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1472
				}
1473
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1474
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1475
				}
1476
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1477
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1478
				}
1479
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1480
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1481
				}
1482

    
1483
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1484
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1485
				}
1486
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1487
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1488
				}
1489
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1490
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1491
				}
1492
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1493
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1494
				}
1495
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1496
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1497
				}
1498
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1499
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1500
				}
1501
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1502
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1503
				}
1504

    
1505
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1506
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1507
				}
1508
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1509
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1510
				}
1511
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1512
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1513
				}
1514
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1515
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1516
				}
1517
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1518
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1519
				}
1520

    
1521
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1522
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1523
				}
1524
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1525
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1526
				}
1527
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1528
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1529
				}
1530

    
1531
				if ($gateway_item) {
1532
					$a_gateways[] = $gateway_item;
1533
				}
1534
				break;
1535
			case "6rd":
1536
				$wancfg['ipaddrv6'] = "6rd";
1537
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1538
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1539
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1540
				if ($gateway_item) {
1541
					$a_gateways[] = $gateway_item;
1542
				}
1543
				break;
1544
			case "6to4":
1545
				$wancfg['ipaddrv6'] = "6to4";
1546
				break;
1547
			case "track6":
1548
				$wancfg['ipaddrv6'] = "track6";
1549
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1550
				if ($_POST['track6-prefix-id--hex'] === "") {
1551
					$wancfg['track6-prefix-id'] = 0;
1552
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1553
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1554
				} else {
1555
					$wancfg['track6-prefix-id'] = 0;
1556
				}
1557
				break;
1558
			case "none":
1559
				break;
1560
		}
1561
		handle_pppoe_reset($_POST);
1562

    
1563
		if ($_POST['blockpriv'] == "yes") {
1564
			$wancfg['blockpriv'] = true;
1565
		} else {
1566
			unset($wancfg['blockpriv']);
1567
		}
1568
		if ($_POST['blockbogons'] == "yes") {
1569
			$wancfg['blockbogons'] = true;
1570
		} else {
1571
			unset($wancfg['blockbogons']);
1572
		}
1573
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1574
		if (empty($_POST['mtu'])) {
1575
			unset($wancfg['mtu']);
1576
		} else {
1577
			$wancfg['mtu'] = $_POST['mtu'];
1578
		}
1579
		if (empty($_POST['mss'])) {
1580
			unset($wancfg['mss']);
1581
		} else {
1582
			$wancfg['mss'] = $_POST['mss'];
1583
		}
1584
		if (empty($_POST['mediaopt'])) {
1585
			unset($wancfg['media']);
1586
			unset($wancfg['mediaopt']);
1587
		} else {
1588
			$mediaopts = explode(' ', $_POST['mediaopt']);
1589
			if ($mediaopts[0] != '') {
1590
				$wancfg['media'] = $mediaopts[0];
1591
			}
1592
			if ($mediaopts[1] != '') {
1593
				$wancfg['mediaopt'] = $mediaopts[1];
1594
			} else {
1595
				unset($wancfg['mediaopt']);
1596
			}
1597
		}
1598
		if (isset($wancfg['wireless'])) {
1599
			handle_wireless_post();
1600
		}
1601

    
1602
		write_config("Interfaces settings changed");
1603

    
1604
		if ($_POST['gatewayip4']) {
1605
			save_gateway($gateway_settings4);
1606
		}
1607

    
1608
		if ($_POST['gatewayip6']) {
1609
			save_gateway($gateway_settings6);
1610
		}
1611

    
1612
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1613
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1614
		} else {
1615
			$toapplylist = array();
1616
		}
1617
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1618
		$toapplylist[$if]['ppps'] = $old_ppps;
1619
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1620

    
1621
		mark_subsystem_dirty('interfaces');
1622

    
1623
		/* regenerate cron settings/crontab file */
1624
		configure_cron();
1625

    
1626
		header("Location: interfaces.php?if={$if}");
1627
		exit;
1628
	}
1629

    
1630
} // end if ($_POST['save'])
1631

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

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

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

    
1782
	interface_sync_wireless_clones($wancfg, true);
1783
}
1784

    
1785
function check_wireless_mode() {
1786
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1787

    
1788
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1789
		return;
1790
	}
1791

    
1792
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1793
		$clone_count = 1;
1794
	} else {
1795
		$clone_count = 0;
1796
	}
1797

    
1798
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1799
		foreach ($config['wireless']['clone'] as $clone) {
1800
			if ($clone['if'] == $wlanbaseif) {
1801
				$clone_count++;
1802
			}
1803
		}
1804
	}
1805

    
1806
	if ($clone_count > 1) {
1807
		$old_wireless_mode = $wancfg['wireless']['mode'];
1808
		$wancfg['wireless']['mode'] = $_POST['mode'];
1809
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1810
			$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']]);
1811
		} else {
1812
			pfSense_interface_destroy("{$wlanif}_");
1813
		}
1814
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1815
	}
1816
}
1817

    
1818
// Find all possible media options for the interface
1819
$mediaopts_list = array();
1820
$intrealname = $config['interfaces'][$if]['if'];
1821
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1822
foreach ($mediaopts as $mediaopt) {
1823
	preg_match("/media (.*)/", $mediaopt, $matches);
1824
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1825
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1826
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1827
	} else {
1828
		// there is only media like "media 1000baseT"
1829
		array_push($mediaopts_list, $matches[1]);
1830
	}
1831
}
1832

    
1833
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1834
$shortcut_section = "interfaces";
1835

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

    
1838
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1839
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1840
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1841
}
1842

    
1843
$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"));
1844

    
1845
// Get the MAC address
1846
$defgatewayname4 = $wancfg['descr'] . "GW";
1847
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1848

    
1849
function build_mediaopts_list() {
1850
	global $mediaopts_list;
1851

    
1852
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1853
			 " " =>	 gettext("------- Media Supported by this interface -------")
1854
			];
1855

    
1856
	foreach ($mediaopts_list as $mediaopt) {
1857
		$list[$mediaopt] = $mediaopt;
1858
	}
1859

    
1860
	return($list);
1861
}
1862

    
1863
function build_gateway_list() {
1864
	global $a_gateways, $if;
1865

    
1866
	$list = array("none" => gettext("None"));
1867
	foreach ($a_gateways as $gateway) {
1868
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1869
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1870
		}
1871
	}
1872

    
1873
	return($list);
1874
}
1875

    
1876
function build_gatewayv6_list() {
1877
	global $a_gateways, $if;
1878

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

    
1886
	return($list);
1887
}
1888

    
1889
include("head.inc");
1890

    
1891
if ($input_errors) {
1892
	print_input_errors($input_errors);
1893
}
1894

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

    
1901
if ($changes_applied) {
1902
	print_apply_result_box($retval);
1903
}
1904

    
1905
$form = new Form();
1906

    
1907
$section = new Form_Section('General Configuration');
1908

    
1909
$section->addInput(new Form_Checkbox(
1910
	'enable',
1911
	'Enable',
1912
	'Enable interface',
1913
	$pconfig['enable'],
1914
	'yes'
1915
));
1916

    
1917
$section->addInput(new Form_Input(
1918
	'descr',
1919
	'*Description',
1920
	'text',
1921
	$pconfig['descr']
1922
))->setHelp('Enter a description (name) for the interface here.');
1923

    
1924
if ($show_address_controls) {
1925
	$section->addInput(new Form_Select(
1926
		'type',
1927
		'IPv4 Configuration Type',
1928
		$pconfig['type'],
1929
		$types4
1930
	));
1931
	$section->addInput(new Form_Select(
1932
		'type6',
1933
		'IPv6 Configuration Type',
1934
		$pconfig['type6'],
1935
		$types6
1936
	));
1937
} else {
1938
	$section->addInput(new Form_StaticText(
1939
		'IPv4/IPv6 Configuration',
1940
		"This interface type does not support manual address configuration on this page. "
1941
	));
1942
	$form->addGlobal(new Form_Input(
1943
		'type',
1944
		null,
1945
		'hidden',
1946
		'none'
1947
	));
1948
	$form->addGlobal(new Form_Input(
1949
		'type6',
1950
		null,
1951
		'hidden',
1952
		'none'
1953
	));
1954
}
1955

    
1956
$macaddress = new Form_Input(
1957
	'spoofmac',
1958
	'MAC Address',
1959
	'text',
1960
	$pconfig['spoofmac'],
1961
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1962
);
1963

    
1964
if (interface_is_vlan($realifname)) {
1965
	$macaddress->setDisabled();
1966
	$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
1967
	    'set on its parent interface');
1968
} else {
1969
	$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
1970
	    'MAC address of this interface.%sEnter a MAC address in the ' .
1971
	    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1972
}
1973

    
1974
$section->addInput($macaddress);
1975

    
1976
$section->addInput(new Form_Input(
1977
	'mtu',
1978
	'MTU',
1979
	'number',
1980
	$pconfig['mtu']
1981
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1982
			'This is typically 1500 bytes but can vary in some circumstances.');
1983

    
1984
$section->addInput(new Form_Input(
1985
	'mss',
1986
	'MSS',
1987
	'number',
1988
	$pconfig['mss']
1989
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1990
			'header size) will be in effect.');
1991

    
1992
if (count($mediaopts_list) > 0) {
1993
	$section->addInput(new Form_Select(
1994
		'mediaopt',
1995
		'Speed and Duplex',
1996
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1997
		build_mediaopts_list()
1998
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1999
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2000
}
2001

    
2002
$form->add($section);
2003

    
2004
$section = new Form_Section('Static IPv4 Configuration');
2005
$section->addClass('staticv4');
2006

    
2007
$section->addInput(new Form_IpAddress(
2008
	'ipaddr',
2009
	'*IPv4 Address',
2010
	$pconfig['ipaddr'],
2011
	'V4'
2012
))->addMask('subnet', $pconfig['subnet'], 32);
2013

    
2014
$group = new Form_Group('IPv4 Upstream gateway');
2015

    
2016
$group->add(new Form_Select(
2017
	'gateway',
2018
	'IPv4 Upstream Gateway',
2019
	$pconfig['gateway'],
2020
	build_gateway_list()
2021
));
2022

    
2023
$group->add(new Form_Button(
2024
	'addgw4',
2025
	'Add a new gateway',
2026
	null,
2027
	'fa-plus'
2028
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2029

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

    
2034
$section->add($group);
2035

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

    
2038
$section = new Form_Section('SLAAC IPv6 Configuration');
2039
$section->addClass('slaac');
2040

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

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

    
2050
$section = new Form_Section('Static IPv6 Configuration');
2051
$section->addClass('staticv6');
2052

    
2053
$section->addInput(new Form_IpAddress(
2054
	'ipaddrv6',
2055
	'*IPv6 address',
2056
	$pconfig['ipaddrv6'],
2057
	'V6'
2058
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2059

    
2060
$section->addInput(new Form_Checkbox(
2061
	'ipv6usev4iface',
2062
	'Use IPv4 connectivity as parent interface',
2063
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2064
	$pconfig['ipv6usev4iface']
2065
));
2066

    
2067
$group = new Form_Group('IPv6 Upstream gateway');
2068

    
2069
$group->add(new Form_Select(
2070
	'gatewayv6',
2071
	'IPv6 Upstream Gateway',
2072
	$pconfig['gatewayv6'],
2073
	build_gatewayv6_list()
2074
));
2075

    
2076
$group->add(new Form_Button(
2077
	'addgw6',
2078
	'Add a new gateway',
2079
	null,
2080
	'fa-plus'
2081
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2082

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

    
2086
$section->add($group);
2087
$form->add($section);
2088

    
2089
// Add new gateway modal pop-up for IPv6
2090
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2091

    
2092
$modal->addInput(new Form_Checkbox(
2093
	'defaultgw6',
2094
	'Default',
2095
	'Default gateway',
2096
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2097
));
2098

    
2099
$modal->addInput(new Form_Input(
2100
	'gatewayname6',
2101
	'Gateway name',
2102
	'text',
2103
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2104
));
2105

    
2106
$modal->addInput(new Form_IpAddress(
2107
	'gatewayip6',
2108
	'Gateway IPv6',
2109
	$gateway_settings6['gateway'],
2110
	'V6'
2111
));
2112

    
2113
$modal->addInput(new Form_Input(
2114
	'gatewaydescr6',
2115
	'Description',
2116
	'text',
2117
	$gateway_settings6['descr']
2118
));
2119

    
2120
$btnaddgw6 = new Form_Button(
2121
	'add6',
2122
	'Add',
2123
	null,
2124
	'fa-plus'
2125
);
2126

    
2127
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2128

    
2129
$btncnxgw6 = new Form_Button(
2130
	'cnx6',
2131
	'Cancel',
2132
	null,
2133
	'fa-undo'
2134
);
2135

    
2136
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2137

    
2138
$modal->addInput(new Form_StaticText(
2139
	null,
2140
	$btnaddgw6 . $btncnxgw6
2141
));
2142

    
2143
$form->add($modal);
2144

    
2145
// ==== DHCP client configuration =============================
2146

    
2147
$section = new Form_Section('DHCP Client Configuration');
2148
$section->addClass('dhcp');
2149

    
2150
$group = new Form_Group('Options');
2151

    
2152
$group->add(new Form_Checkbox(
2153
	'adv_dhcp_config_advanced',
2154
	null,
2155
	'Advanced Configuration',
2156
	$pconfig['adv_dhcp_config_advanced']
2157
))->setHelp('Use advanced DHCP configuration options.');
2158

    
2159
$group->add(new Form_Checkbox(
2160
	'adv_dhcp_config_file_override',
2161
	null,
2162
	'Configuration Override',
2163
	$pconfig['adv_dhcp_config_file_override']
2164
))->setHelp('Override the configuration from this file.');
2165

    
2166
$section->add($group);
2167

    
2168
$section->addInput(new Form_Input(
2169
	'dhcphostname',
2170
	'Hostname',
2171
	'text',
2172
	$pconfig['dhcphostname']
2173
))->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).');
2174

    
2175
$section->addInput(new Form_IpAddress(
2176
	'alias-address',
2177
	'Alias IPv4 address',
2178
	$pconfig['alias-address'],
2179
	'V4'
2180
))->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.');
2181

    
2182
$section->addInput(new Form_Input(
2183
	'dhcprejectfrom',
2184
	'Reject leases from',
2185
	'text',
2186
	$pconfig['dhcprejectfrom']
2187
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2188
			'(separate multiple entries with a comma). ' .
2189
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2190

    
2191
if (interface_is_vlan($wancfg['if']) != NULL) {
2192

    
2193
	$group = new Form_Group('DHCP VLAN Priority');
2194
	$group->add(new Form_Checkbox(
2195
		'dhcpvlanenable',
2196
		null,
2197
		'Enable dhcpclient VLAN Priority tagging',
2198
		$pconfig['dhcpvlanenable']
2199
	))->setHelp('Normally off unless specifically required by the ISP.');
2200

    
2201
	$group->add(new Form_Select(
2202
		'dhcpcvpt',
2203
		'VLAN Prio',
2204
		$pconfig['dhcpcvpt'],
2205
		$vlanprio
2206
	))->setHelp('Choose 802.1p priority to set.');
2207

    
2208
	$section->add($group);
2209
}
2210

    
2211
$group = new Form_Group('Protocol timing');
2212
$group->addClass('dhcpadvanced');
2213

    
2214
$group->add(new Form_Input(
2215
	'adv_dhcp_pt_timeout',
2216
	null,
2217
	'number',
2218
	$pconfig['adv_dhcp_pt_timeout']
2219
))->setHelp('Timeout');
2220

    
2221
$group->add(new Form_Input(
2222
	'adv_dhcp_pt_retry',
2223
	null,
2224
	'number',
2225
	$pconfig['adv_dhcp_pt_retry']
2226
))->setHelp('Retry');
2227

    
2228
$group->add(new Form_Input(
2229
	'adv_dhcp_pt_select_timeout',
2230
	null,
2231
	'number',
2232
	$pconfig['adv_dhcp_pt_select_timeout'],
2233
	['min' => 0]
2234
))->setHelp('Select timeout');
2235

    
2236
$group->add(new Form_Input(
2237
	'adv_dhcp_pt_reboot',
2238
	null,
2239
	'number',
2240
	$pconfig['adv_dhcp_pt_reboot']
2241
))->setHelp('Reboot');
2242

    
2243
$group->add(new Form_Input(
2244
	'adv_dhcp_pt_backoff_cutoff',
2245
	null,
2246
	'number',
2247
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2248
))->setHelp('Backoff cutoff');
2249

    
2250
$group->add(new Form_Input(
2251
	'adv_dhcp_pt_initial_interval',
2252
	null,
2253
	'number',
2254
	$pconfig['adv_dhcp_pt_initial_interval']
2255
))->setHelp('Initial interval');
2256

    
2257
$section->add($group);
2258

    
2259
$group = new Form_Group('Presets');
2260
$group->addClass('dhcpadvanced');
2261

    
2262
$group->add(new Form_Checkbox(
2263
	'adv_dhcp_pt_values',
2264
	null,
2265
	'FreeBSD default',
2266
	null,
2267
	'DHCP'
2268
))->displayAsRadio();
2269

    
2270
$group->add(new Form_Checkbox(
2271
	'adv_dhcp_pt_values',
2272
	null,
2273
	'Clear',
2274
	null,
2275
	'Clear'
2276
))->displayAsRadio();
2277

    
2278
$group->add(new Form_Checkbox(
2279
	'adv_dhcp_pt_values',
2280
	null,
2281
	'pfSense Default',
2282
	null,
2283
	'pfSense'
2284
))->displayAsRadio();
2285

    
2286
$group->add(new Form_Checkbox(
2287
	'adv_dhcp_pt_values',
2288
	null,
2289
	'Saved Cfg',
2290
	null,
2291
	'SavedCfg'
2292
))->displayAsRadio();
2293

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

    
2297
$section->add($group);
2298

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

    
2309
$form->add($section);
2310

    
2311
$section = new Form_Section('Lease Requirements and Requests');
2312
$section->addClass('dhcpadvanced');
2313

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

    
2324
$section->addInput(new Form_Input(
2325
	'adv_dhcp_request_options',
2326
	'Request options',
2327
	'text',
2328
	$pconfig['adv_dhcp_request_options']
2329
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2330
			'Some ISPs may require certain options be or not be requested.', '<br />');
2331

    
2332
$section->addInput(new Form_Input(
2333
	'adv_dhcp_required_options',
2334
	'Require options',
2335
	'text',
2336
	$pconfig['adv_dhcp_required_options']
2337
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2338

    
2339
$section->addInput(new Form_Input(
2340
	'adv_dhcp_option_modifiers',
2341
	'Option modifiers',
2342
	'text',
2343
	$pconfig['adv_dhcp_option_modifiers']
2344
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2345
			'modifiers: (default, supersede, prepend, append) %1$s' .
2346
			'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>');
2347

    
2348
$form->add($section);
2349

    
2350
// DHCP6 client config
2351

    
2352
$section = new Form_Section('DHCP6 Client Configuration');
2353
$section->addClass('dhcp6');
2354

    
2355
$group = new Form_Group('Options');
2356

    
2357
$group->add(new Form_Checkbox(
2358
	'adv_dhcp6_config_advanced',
2359
	null,
2360
	'Advanced Configuration',
2361
	$pconfig['adv_dhcp6_config_advanced']
2362
))->setHelp('Use advanced DHCPv6 configuration options.');
2363

    
2364
$group->add(new Form_Checkbox(
2365
	'adv_dhcp6_config_file_override',
2366
	null,
2367
	'Configuration Override',
2368
	$pconfig['adv_dhcp6_config_file_override']
2369
))->setHelp('Override the configuration from this file.');
2370

    
2371
$section->add($group);
2372

    
2373
$section->addInput(new Form_Checkbox(
2374
	'dhcp6usev4iface',
2375
	'Use IPv4 connectivity as parent interface',
2376
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2377
	$pconfig['dhcp6usev4iface']
2378
));
2379

    
2380
$section->addInput(new Form_Checkbox(
2381
	'dhcp6prefixonly',
2382
	'Request only an IPv6 prefix',
2383
	'Only request an IPv6 prefix, do not request an IPv6 address',
2384
	$pconfig['dhcp6prefixonly']
2385
));
2386

    
2387
$section->addInput(new Form_Select(
2388
	'dhcp6-ia-pd-len',
2389
	'DHCPv6 Prefix Delegation size',
2390
	$pconfig['dhcp6-ia-pd-len'],
2391
	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")
2392
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2393

    
2394
$section->addInput(new Form_Checkbox(
2395
	'dhcp6-ia-pd-send-hint',
2396
	'Send IPv6 prefix hint',
2397
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2398
	$pconfig['dhcp6-ia-pd-send-hint']
2399
));
2400

    
2401
$section->addInput(new Form_Checkbox(
2402
	'dhcp6debug',
2403
	'Debug',
2404
	'Start DHCP6 client in debug mode',
2405
	$pconfig['dhcp6debug']
2406
));
2407
$section->addInput(new Form_Checkbox(
2408
	'dhcp6withoutra',
2409
	'Do not wait for a RA',
2410
	'Required by some ISPs, especially those not using PPPoE',
2411
	$pconfig['dhcp6withoutra']
2412
));
2413
$section->addInput(new Form_Checkbox(
2414
	'dhcp6norelease',
2415
	'Do not allow PD/Address release',
2416
	'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',
2417
	$pconfig['dhcp6norelease']
2418
));
2419

    
2420
if (interface_is_vlan($wancfg['if']) != NULL) {
2421
	$group = new Form_Group('DHCP6 VLAN Priority');
2422

    
2423
	$group->add(new Form_Checkbox(
2424
		'dhcp6vlanenable',
2425
		null,
2426
		'Enable dhcp6c VLAN Priority tagging',
2427
		$pconfig['dhcp6vlanenable']
2428
	))->setHelp('Normally off unless specifically required by the ISP.');
2429

    
2430
	$group->add(new Form_Select(
2431
		'dhcp6cvpt',
2432
		'VLAN Prio',
2433
		$pconfig['dhcp6cvpt'],
2434
		$vlanprio
2435
	))->setHelp('Choose 802.1p priority to set.');
2436

    
2437
	$section->add($group);
2438
}
2439

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

    
2450
$form->add($section);
2451

    
2452
// DHCP6 client config - Advanced
2453

    
2454
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2455
$section->addClass('dhcp6advanced');
2456

    
2457
$section->addInput(new Form_Checkbox(
2458
	'adv_dhcp6_interface_statement_information_only_enable',
2459
	'Information only',
2460
	'Exchange Information Only',
2461
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2462
	'Selected'
2463
))->setHelp('Only exchange informational configuration parameters with servers.');
2464

    
2465
$section->addInput(new Form_Input(
2466
	'adv_dhcp6_interface_statement_send_options',
2467
	'Send options',
2468
	'text',
2469
	$pconfig['adv_dhcp6_interface_statement_send_options']
2470
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2471
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2472
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2473
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2474

    
2475
$section->addInput(new Form_Input(
2476
	'adv_dhcp6_interface_statement_request_options',
2477
	'Request Options',
2478
	'text',
2479
	$pconfig['adv_dhcp6_interface_statement_request_options']
2480
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2481
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2482

    
2483
$section->addInput(new Form_Input(
2484
	'adv_dhcp6_interface_statement_script',
2485
	'Scripts',
2486
	'text',
2487
	$pconfig['adv_dhcp6_interface_statement_script']
2488
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2489
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2490

    
2491
$group = new Form_Group('Identity Association Statement');
2492

    
2493
$group->add(new Form_Checkbox(
2494
	'adv_dhcp6_id_assoc_statement_address_enable',
2495
	null,
2496
	'Non-Temporary Address Allocation',
2497
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2498
	'Selected'
2499
));
2500

    
2501
$group->add(new Form_Input(
2502
	'adv_dhcp6_id_assoc_statement_address_id',
2503
	null,
2504
	'text',
2505
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2506
))->sethelp('id-assoc na ID');
2507

    
2508
$group->add(new Form_IpAddress(
2509
	'adv_dhcp6_id_assoc_statement_address',
2510
	null,
2511
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2512
	'V6'
2513
))->sethelp('IPv6 address');
2514

    
2515
$group->add(new Form_Input(
2516
	'adv_dhcp6_id_assoc_statement_address_pltime',
2517
	null,
2518
	'text',
2519
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2520
))->sethelp('pltime');
2521

    
2522
$group->add(new Form_Input(
2523
	'adv_dhcp6_id_assoc_statement_address_vltime',
2524
	null,
2525
	'text',
2526
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2527
))->sethelp('vltime');
2528

    
2529
$section->add($group);
2530

    
2531
// Prefix delegation
2532
$group = new Form_Group('');
2533

    
2534
$group->add(new Form_Checkbox(
2535
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2536
	null,
2537
	'Prefix Delegation ',
2538
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2539
	'Selected'
2540
));
2541

    
2542
$group->add(new Form_Input(
2543
	'adv_dhcp6_id_assoc_statement_prefix_id',
2544
	null,
2545
	'text',
2546
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2547
))->sethelp('id-assoc pd ID');
2548

    
2549
$group->add(new Form_IpAddress(
2550
	'adv_dhcp6_id_assoc_statement_prefix',
2551
	null,
2552
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2553
	'V6'
2554
))->sethelp('IPv6 prefix');
2555

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

    
2563
$group->add(new Form_Input(
2564
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2565
	null,
2566
	'text',
2567
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2568
))->sethelp('vltime');
2569

    
2570
$section->add($group);
2571

    
2572
$group = new Form_Group('Prefix interface statement');
2573

    
2574
$group->add(new Form_Input(
2575
	'adv_dhcp6_prefix_interface_statement_sla_id',
2576
	null,
2577
	'text',
2578
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2579
))->sethelp('Prefix Interface sla-id');
2580

    
2581
$group->add(new Form_Input(
2582
	'adv_dhcp6_prefix_interface_statement_sla_len',
2583
	null,
2584
	'text',
2585
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2586
))->sethelp('sla-len');
2587

    
2588
$section->add($group);
2589

    
2590
$group = new Form_Group('Select prefix interface');
2591
$section->addInput(new Form_Select(
2592
	'adv_dhcp6_prefix_selected_interface',
2593
	'Prefix Interface',
2594
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2595
	$interfaces
2596
))->setHelp('Select the interface on which to apply the prefix delegation.');
2597

    
2598
$group = new Form_Group('Authentication statement');
2599

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

    
2607
$group->add(new Form_Input(
2608
	'adv_dhcp6_authentication_statement_protocol',
2609
	null,
2610
	'text',
2611
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2612
))->sethelp('Protocol');
2613

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

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

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

    
2630
$group = new Form_Group('Keyinfo statement');
2631

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

    
2639
$group->add(new Form_Input(
2640
	'adv_dhcp6_key_info_statement_realm',
2641
	null,
2642
	'text',
2643
	$pconfig['adv_dhcp6_key_info_statement_realm']
2644
))->sethelp('Realm');
2645

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

    
2648
$group = new Form_Group('');
2649

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

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

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

    
2671
$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>');
2672

    
2673
$section->add($group);
2674

    
2675
$form->add($section);
2676

    
2677
$section = new Form_Section('6RD Configuration');
2678
$section->addClass('_6rd');
2679

    
2680
$section->addInput(new Form_Input(
2681
	'prefix-6rd',
2682
	'6RD Prefix',
2683
	'text',
2684
	$pconfig['prefix-6rd']
2685
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2686

    
2687
$section->addInput(new Form_Input(
2688
	'gateway-6rd',
2689
	'*6RD Border relay',
2690
	'text',
2691
	$pconfig['gateway-6rd']
2692
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2693

    
2694
$section->addInput(new Form_Select(
2695
	'prefix-6rd-v4plen',
2696
	'6RD IPv4 Prefix length',
2697
	$pconfig['prefix-6rd-v4plen'],
2698
	array_combine(range(0, 32), range(0, 32))
2699
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2700

    
2701
$form->add($section);
2702

    
2703
// Track IPv6 ointerface section
2704
$section = new Form_Section('Track IPv6 Interface');
2705
$section->addClass('track6');
2706

    
2707
function build_ipv6interface_list() {
2708
	global $config, $form;
2709

    
2710
	$list = array('' => '');
2711

    
2712
	$interfaces = get_configured_interface_with_descr(true);
2713
	$dynv6ifs = array();
2714

    
2715
	foreach ($interfaces as $iface => $ifacename) {
2716
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2717
			case "6to4":
2718
			case "6rd":
2719
			case "dhcp6":
2720
				$dynv6ifs[$iface] = array(
2721
					'name' => $ifacename,
2722
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2723
				);
2724
				break;
2725
			default:
2726
				continue 2;
2727
		}
2728
	}
2729

    
2730
	foreach ($dynv6ifs as $iface => $ifacedata) {
2731
		$list[$iface] = $ifacedata['name'];
2732

    
2733
		$form->addGlobal(new Form_Input(
2734
			'ipv6-num-prefix-ids-' . $iface,
2735
			null,
2736
			'hidden',
2737
			$ifacedata['ipv6_num_prefix_ids']
2738
		));
2739
	}
2740

    
2741
	return($list);
2742
}
2743

    
2744
$section->addInput(new Form_Select(
2745
	'track6-interface',
2746
	'*IPv6 Interface',
2747
	$pconfig['track6-interface'],
2748
	build_ipv6interface_list()
2749
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2750

    
2751
if ($pconfig['track6-prefix-id'] == "") {
2752
	$pconfig['track6-prefix-id'] = 0;
2753
}
2754

    
2755
$section->addInput(new Form_Input(
2756
	'track6-prefix-id--hex',
2757
	'IPv6 Prefix ID',
2758
	'text',
2759
	sprintf("%x", $pconfig['track6-prefix-id'])
2760
))->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>');
2761

    
2762
$form->addGlobal(new Form_Input(
2763
	'track6-prefix-id-max',
2764
	null,
2765
	'hidden',
2766
	0
2767
));
2768

    
2769
$form->add($section);
2770

    
2771
/// PPP section
2772

    
2773
$section = new Form_Section('PPP Configuration');
2774
$section->addClass('ppp');
2775

    
2776
$section->addInput(new Form_Select(
2777
	'country',
2778
	'Country',
2779
	$pconfig['country'],
2780
	[]
2781
));
2782

    
2783
$section->addInput(new Form_Select(
2784
	'provider_list',
2785
	'Provider',
2786
	$pconfig['provider_list'],
2787
	[]
2788
));
2789

    
2790
$section->addInput(new Form_Select(
2791
	'providerplan',
2792
	'Plan',
2793
	$pconfig['providerplan'],
2794
	[]
2795
))->setHelp('Select to fill in service provider data.');
2796

    
2797
$section->addInput(new Form_Input(
2798
	'ppp_username',
2799
	'Username',
2800
	'text',
2801
	$pconfig['ppp_username'],
2802
	['autocomplete' => 'new-password']
2803
));
2804

    
2805
$section->addPassword(new Form_Input(
2806
	'ppp_password',
2807
	'Password',
2808
	'password',
2809
	$pconfig['ppp_password']
2810
));
2811

    
2812
$section->addInput(new Form_Input(
2813
	'phone',
2814
	'*Phone number',
2815
	'text',
2816
	$pconfig['phone']
2817
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2818

    
2819
$section->addInput(new Form_Input(
2820
	'apn',
2821
	'Access Point Name',
2822
	'text',
2823
	$pconfig['apn']
2824
));
2825

    
2826

    
2827
function build_port_list() {
2828
	$list = array("" => "None");
2829

    
2830
	$portlist = glob("/dev/cua*");
2831
	$modems	  = glob("/dev/modem*");
2832
	$portlist = array_merge($portlist, $modems);
2833

    
2834
	foreach ($portlist as $port) {
2835
		if (preg_match("/\.(lock|init)$/", $port)) {
2836
			continue;
2837
		}
2838

    
2839
	$list[trim($port)] = $port;
2840
	}
2841

    
2842
	return($list);
2843
}
2844

    
2845
$section->addInput(new Form_Select(
2846
	'port',
2847
	"*Modem port",
2848
	$pconfig['port'],
2849
	build_port_list()
2850
));
2851

    
2852
$section->addInput(new Form_Button(
2853
	'btnadvppp',
2854
	'Advanced PPP',
2855
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2856
	'fa-cog'
2857
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2858

    
2859
$form->add($section);
2860

    
2861
// PPPoE configuration
2862
$section = new Form_Section('PPPoE Configuration');
2863
$section->addClass('pppoe');
2864

    
2865
$section->addInput(new Form_Input(
2866
	'pppoe_username',
2867
	'*Username',
2868
	'text',
2869
	$pconfig['pppoe_username'],
2870
	['autocomplete' => 'new-password']
2871
));
2872

    
2873
$section->addPassword(new Form_Input(
2874
	'pppoe_password',
2875
	'*Password',
2876
	'password',
2877
	$pconfig['pppoe_password']
2878
));
2879

    
2880
$section->addInput(new Form_Input(
2881
	'provider',
2882
	'Service name',
2883
	'text',
2884
	$pconfig['provider']
2885
))->setHelp('This field can usually be left empty.');
2886

    
2887
$section->addInput(new Form_Input(
2888
	'hostuniq',
2889
	'Host-Uniq',
2890
	'text',
2891
	$pconfig['hostuniq']
2892
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2893

    
2894
$section->addInput(new Form_Checkbox(
2895
	'pppoe_dialondemand',
2896
	'Dial on demand',
2897
	'Enable Dial-On-Demand mode ',
2898
	$pconfig['pppoe_dialondemand'],
2899
	'enable'
2900
));
2901

    
2902
$section->addInput(new Form_Input(
2903
	'pppoe_idletimeout',
2904
	'Idle timeout',
2905
	'number',
2906
	$pconfig['pppoe_idletimeout'],
2907
	['min' => 0]
2908
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2909
			'An idle timeout of zero disables this feature.');
2910

    
2911
$section->addInput(new Form_Select(
2912
	'pppoe-reset-type',
2913
	'Periodic reset',
2914
	$pconfig['pppoe-reset-type'],
2915
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2916
))->setHelp('Select a reset timing type.');
2917

    
2918
$group = new Form_Group('Custom reset');
2919
$group->addClass('pppoecustom');
2920

    
2921
$group->add(new Form_Input(
2922
	'pppoe_resethour',
2923
	null,
2924
	'number',
2925
	$pconfig['pppoe_resethour'],
2926
	['min' => 0, 'max' => 23]
2927
))->setHelp('Hour (0-23)');
2928

    
2929
$group->add(new Form_Input(
2930
	'pppoe_resetminute',
2931
	null,
2932
	'number',
2933
	$pconfig['pppoe_resetminute'],
2934
	['min' => 0, 'max' => 59]
2935
))->setHelp('Minutes (0-59)');
2936

    
2937
$group->add(new Form_Input(
2938
	'pppoe_resetdate',
2939
	null,
2940
	'text',
2941
	$pconfig['pppoe_resetdate']
2942
))->setHelp('Specific date (mm/dd/yyyy)');
2943

    
2944
$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');
2945

    
2946
$section->add($group);
2947

    
2948
$group = new Form_MultiCheckboxGroup('cron based reset');
2949
$group->addClass('pppoepreset');
2950

    
2951
$group->add(new Form_MultiCheckbox(
2952
	'pppoe_pr_preset_val',
2953
	null,
2954
	'Reset at each month ("0 0 1 * *")',
2955
	$pconfig['pppoe_monthly'],
2956
	'monthly'
2957
))->displayAsRadio();
2958

    
2959
$group->add(new Form_MultiCheckbox(
2960
	'pppoe_pr_preset_val',
2961
	null,
2962
	'Reset at each week ("0 0 * * 0")',
2963
	$pconfig['pppoe_weekly'],
2964
	'weekly'
2965
))->displayAsRadio();
2966

    
2967
$group->add(new Form_MultiCheckbox(
2968
	'pppoe_pr_preset_val',
2969
	null,
2970
	'Reset at each day ("0 0 * * *")',
2971
	$pconfig['pppoe_daily'],
2972
	'daily'
2973
))->displayAsRadio();
2974

    
2975
$group->add(new Form_MultiCheckbox(
2976
	'pppoe_pr_preset_val',
2977
	null,
2978
	'Reset at each hour ("0 * * * *")',
2979
	$pconfig['pppoe_hourly'],
2980
	'hourly'
2981
))->displayAsRadio();
2982

    
2983
$section->add($group);
2984

    
2985
$section->addInput(new Form_Button(
2986
	'btnadvppp',
2987
	'Advanced and MLPPP',
2988
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2989
	'fa-cog'
2990
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2991

    
2992
$form->add($section);
2993

    
2994
// PPTP & L2TP Configuration section
2995
$section = new Form_Section('PPTP/L2TP Configuration');
2996
$section->addClass('pptp');
2997

    
2998
$section->addInput(new Form_Input(
2999
	'pptp_username',
3000
	'*Username',
3001
	'text',
3002
	$pconfig['pptp_username'],
3003
	['autocomplete' => 'new-password']
3004
));
3005

    
3006
$section->addPassword(new Form_Input(
3007
	'pptp_password',
3008
	'*Password',
3009
	'password',
3010
	$pconfig['pptp_password']
3011
));
3012

    
3013
$group = new Form_Group('Shared Secret');
3014

    
3015
$group->add(new Form_Input(
3016
	'l2tp_secret',
3017
	'*Secret',
3018
	'password',
3019
	$pconfig['l2tp_secret']
3020
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3021
	    'important control packet contents. (Optional)');
3022

    
3023
$group->addClass('l2tp_secret');
3024
$section->add($group);
3025

    
3026
$section->addInput(new Form_IpAddress(
3027
	'pptp_local0',
3028
	'*Local IP address',
3029
	$pconfig['pptp_localip'][0],
3030
	'V4'
3031
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
3032

    
3033
$section->addInput(new Form_IpAddress(
3034
	'pptp_remote0',
3035
	'*Remote IP address',
3036
	$pconfig['pptp_remote'][0],
3037
	'HOSTV4'
3038
));
3039

    
3040
$section->addInput(new Form_Checkbox(
3041
	'pptp_dialondemand',
3042
	'Dial on demand',
3043
	'Enable Dial-On-Demand mode ',
3044
	$pconfig['pptp_dialondemand'],
3045
	'enable'
3046
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3047
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3048

    
3049
$section->addInput(new Form_Input(
3050
	'pptp_idletimeout',
3051
	'Idle timeout (seconds)',
3052
	'number',
3053
	$pconfig['pptp_idletimeout'],
3054
	['min' => 0]
3055
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3056
			'An idle timeout of zero disables this feature.');
3057

    
3058
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3059
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3060
} else {
3061
	$mlppp_text = "";
3062
}
3063

    
3064
$section->addInput(new Form_Button(
3065
	'btnadvppp',
3066
	'Advanced and MLPPP',
3067
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3068
	'fa-cog'
3069
))->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);
3070

    
3071
$form->add($section);
3072

    
3073
// Wireless interface
3074
if (isset($wancfg['wireless'])) {
3075

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

    
3078
	$section->addInput(new Form_Checkbox(
3079
		'persistcommonwireless',
3080
		'Persist common settings',
3081
		'Preserve common wireless configuration through interface deletions and reassignments.',
3082
		$pconfig['persistcommonwireless'],
3083
		'yes'
3084
	));
3085

    
3086
	$mode_list = ['auto' => 'Auto'];
3087

    
3088
	if (is_array($wl_modes)) {
3089
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3090
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3091
		}
3092
	}
3093

    
3094
	if (count($mode_list) == 1) {
3095
		$mode_list[''] = '';
3096
	}
3097

    
3098
	$section->addInput(new Form_Select(
3099
		'standard',
3100
		'Standard',
3101
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3102
		$mode_list
3103
	));
3104

    
3105
	if (isset($wl_modes['11g'])) {
3106
		$section->addInput(new Form_Select(
3107
			'protmode',
3108
			'802.11g OFDM Protection Mode',
3109
			$pconfig['protmode'],
3110
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3111
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3112
	} else {
3113
		$form->addGlobal(new Form_Input(
3114
			'protmode',
3115
			null,
3116
			'hidden',
3117
			'off'
3118
		));
3119
	}
3120

    
3121
	$mode_list = ['0' => gettext('Auto')];
3122

    
3123
	if (is_array($wl_modes)) {
3124
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3125
			if ($wl_standard == "11g") {
3126
				$wl_standard = "11b/g";
3127
			} else if ($wl_standard == "11ng") {
3128
				$wl_standard = "11b/g/n";
3129
			} else if ($wl_standard == "11na") {
3130
				$wl_standard = "11a/n";
3131
			}
3132

    
3133
			foreach ($wl_channels as $wl_channel) {
3134
				if (isset($wl_chaninfo[$wl_channel])) {
3135
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3136
				} else {
3137
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3138
				}
3139
			}
3140
		}
3141
	}
3142

    
3143
	$section->addInput(new Form_Select(
3144
		'channel',
3145
		'Channel',
3146
		$pconfig['channel'],
3147
		$mode_list
3148
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3149
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3150

    
3151
	$section->addInput(new Form_Select(
3152
		'channel_width',
3153
		'Channel width',
3154
		$pconfig['channel_width'],
3155
		$wl_ht_modes
3156
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3157

    
3158
	if (ANTENNAS) {
3159
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3160
			$group = new Form_Group('Antenna Settings');
3161

    
3162
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3163
				$group->add(new Form_Select(
3164
					'diversity',
3165
					null,
3166
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3167
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3168
				))->setHelp('Diversity');
3169
			}
3170

    
3171
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3172
				$group->add(new Form_Select(
3173
					'txantenna',
3174
					null,
3175
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3176
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3177
				))->setHelp('Transmit antenna');
3178
			}
3179

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

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

    
3191
			$section->add($group);
3192
		}
3193
	}
3194

    
3195
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3196
			$section->addInput(new Form_Input(
3197
				'distance',
3198
				'Distance setting (meters)',
3199
				'test',
3200
				$pconfig['distance']
3201
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3202
	}
3203

    
3204
	$form->add($section);
3205

    
3206
	// Regulatory settings
3207
	$section = new Form_Section('Regulatory Settings');
3208

    
3209
	$domain_list = array("" => 'Default');
3210

    
3211
	if (is_array($wl_regdomains)) {
3212
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3213
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3214
		}
3215
	}
3216

    
3217
	$section->addInput(new Form_Select(
3218
		'regdomain',
3219
		'Regulatory domain',
3220
		$pconfig['regdomain'],
3221
		$domain_list
3222
	))->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');
3223

    
3224
	$country_list = array('' => 'Default');
3225

    
3226
	if (is_array($wl_countries)) {
3227
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3228
			$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']);
3229
		}
3230
	}
3231

    
3232
	$section->addInput(new Form_Select(
3233
		'regcountry',
3234
		'Country',
3235
		$pconfig['regcountry'],
3236
		$country_list
3237
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3238

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

    
3250
	$form->add($section);
3251

    
3252
	$section = new Form_Section('Network-Specific Wireless Configuration');
3253

    
3254
	$section->addInput(new Form_Select(
3255
		'mode',
3256
		'Mode',
3257
		$pconfig['mode'],
3258
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3259
	));
3260

    
3261
	$section->addInput(new Form_Input(
3262
		'ssid',
3263
		'SSID',
3264
		'text',
3265
		$pconfig['ssid']
3266
	));
3267

    
3268
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3269
		$section->addInput(new Form_Select(
3270
			'puremode',
3271
			'Minimum wireless standard',
3272
			$pconfig['puremode'],
3273
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3274
		))->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)');
3275
	} elseif (isset($wl_modes['11g'])) {
3276
		$section->addInput(new Form_Checkbox(
3277
			'puremode',
3278
			'802.11g only',
3279
			null,
3280
			$pconfig['puremode'],
3281
			'11g'
3282
		))->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)');
3283
	}
3284

    
3285
	$section->addInput(new Form_Checkbox(
3286
		'apbridge_enable',
3287
		'Allow intra-BSS communication',
3288
		'Allow packets to pass between wireless clients directly when operating as an access point',
3289
		$pconfig['apbridge_enable'],
3290
		'yes'
3291
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3292

    
3293
	$section->addInput(new Form_Checkbox(
3294
		'wme_enable',
3295
		'Enable WME',
3296
		'Force the card to use WME (wireless QoS)',
3297
		$pconfig['wme_enable'],
3298
		'yes'
3299
	));
3300

    
3301
	$section->addInput(new Form_Checkbox(
3302
		'hidessid_enable',
3303
		'Hide SSID',
3304
		'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.)',
3305
		$pconfig['hidessid_enable'],
3306
		'yes'
3307
	));
3308

    
3309
	$form->add($section);
3310

    
3311
	// WPA Section
3312
	$section = new Form_Section('WPA');
3313

    
3314
	$section->addInput(new Form_Checkbox(
3315
		'wpa_enable',
3316
		'Enable',
3317
		'Enable WPA',
3318
		$pconfig['wpa_enable'],
3319
		'yes'
3320
	));
3321

    
3322
	$section->addInput(new Form_Input(
3323
		'passphrase',
3324
		'WPA Pre-Shared Key',
3325
		'text',
3326
		$pconfig['passphrase']
3327
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3328

    
3329
	$section->addInput(new Form_Select(
3330
		'wpa_mode',
3331
		'WPA mode',
3332
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3333
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3334
	));
3335

    
3336
	$section->addInput(new Form_Select(
3337
		'wpa_key_mgmt',
3338
		'WPA Key Management Mode',
3339
		$pconfig['wpa_key_mgmt'],
3340
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3341
	));
3342

    
3343
	$section->addInput(new Form_Select(
3344
		'wpa_pairwise',
3345
		'WPA Pairwise',
3346
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3347
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3348
	));
3349

    
3350
	$section->addInput(new Form_Input(
3351
		'wpa_group_rekey',
3352
		'Group Key Rotation',
3353
		'number',
3354
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3355
		['min' => '1', 'max' => 9999]
3356
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3357

    
3358
	$section->addInput(new Form_Input(
3359
		'wpa_gmk_rekey',
3360
		'Group Master Key Regeneration',
3361
		'number',
3362
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3363
		['min' => '1', 'max' => 9999]
3364
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3365

    
3366
	$section->addInput(new Form_Checkbox(
3367
		'wpa_strict_rekey',
3368
		'Strict Key Regeneration',
3369
		'Force the AP to rekey whenever a client disassociates',
3370
		$pconfig['wpa_strict_rekey'],
3371
		'yes'
3372
	));
3373

    
3374
	$form->add($section);
3375

    
3376
	$section = new Form_Section('802.1x RADIUS Options');
3377

    
3378
	$section->addInput(new Form_Checkbox(
3379
		'ieee8021x',
3380
		'IEEE802.1X',
3381
		'Enable 802.1X authentication',
3382
		$pconfig['ieee8021x'],
3383
		'yes'
3384
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3385

    
3386
	$group = new Form_Group('Primary 802.1X server');
3387

    
3388
	$group->add(new Form_IpAddress(
3389
		'auth_server_addr',
3390
		'IP Address',
3391
		$pconfig['auth_server_addr']
3392
	))->setHelp('IP address of the RADIUS server');
3393

    
3394
	$group->add(new Form_Input(
3395
		'auth_server_port',
3396
		'Port',
3397
		'number',
3398
		$pconfig['auth_server_port']
3399
	))->setHelp('Server auth port. Default is 1812');
3400

    
3401
	$group->add(new Form_Input(
3402
		'auth_server_shared_secret',
3403
		'Shared Secret',
3404
		'text',
3405
		$pconfig['auth_server_shared_secret']
3406
	))->setHelp('RADIUS Shared secret for this firewall');
3407

    
3408
	$section->add($group);
3409

    
3410
	$group = new Form_Group('Secondary 802.1X server');
3411

    
3412
	$group->add(new Form_IpAddress(
3413
		'auth_server_addr2',
3414
		'IP Address',
3415
		$pconfig['auth_server_addr2']
3416
	))->setHelp('IP address of the RADIUS server');
3417

    
3418
	$group->add(new Form_Input(
3419
		'auth_server_port2',
3420
		'Port',
3421
		'number',
3422
		$pconfig['auth_server_port2']
3423
	))->setHelp('Server auth port. Default is 1812');
3424

    
3425
	$group->add(new Form_Input(
3426
		'auth_server_shared_secret2',
3427
		'Shared Secret',
3428
		'text',
3429
		$pconfig['auth_server_shared_secret2']
3430
	))->setHelp('RADIUS Shared secret for this firewall');
3431

    
3432
	$section->add($group);
3433

    
3434
	$section->addInput(new Form_Checkbox(
3435
		'rsn_preauth',
3436
		'Authentication Roaming Preauth',
3437
		null,
3438
		$pconfig['rsn_preauth'],
3439
		'yes'
3440
	));
3441

    
3442
	$form->add($section);
3443
}
3444

    
3445
$section = new Form_Section('Reserved Networks');
3446

    
3447
$section->addInput(new Form_Checkbox(
3448
	'blockpriv',
3449
	'Block private networks and loopback addresses',
3450
	'',
3451
	$pconfig['blockpriv'],
3452
	'yes'
3453
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3454
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3455
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3456

    
3457
$section->addInput(new Form_Checkbox(
3458
	'blockbogons',
3459
	'Block bogon networks',
3460
	'',
3461
	$pconfig['blockbogons'],
3462
	'yes'
3463
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3464
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3465
			'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' .
3466
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3467

    
3468
$form->add($section);
3469

    
3470
$form->addGlobal(new Form_Input(
3471
	'if',
3472
	null,
3473
	'hidden',
3474
	$if
3475
));
3476

    
3477
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3478
	$form->addGlobal(new Form_Input(
3479
		'ppp_port',
3480
		null,
3481
		'hidden',
3482
		$pconfig['port']
3483
	));
3484
}
3485

    
3486
$form->addGlobal(new Form_Input(
3487
	'ptpid',
3488
	null,
3489
	'hidden',
3490
	$pconfig['ptpid']
3491
));
3492

    
3493

    
3494
// Add new gateway modal pop-up
3495
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3496

    
3497
$modal->addInput(new Form_Checkbox(
3498
	'defaultgw4',
3499
	'Default',
3500
	'Default gateway',
3501
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3502
));
3503

    
3504
$modal->addInput(new Form_Input(
3505
	'gatewayname4',
3506
	'Gateway name',
3507
	'text',
3508
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3509
));
3510

    
3511
$modal->addInput(new Form_IpAddress(
3512
	'gatewayip4',
3513
	'Gateway IPv4',
3514
	$gateway_settings4['gateway'],
3515
	'V4'
3516
));
3517

    
3518
$modal->addInput(new Form_Input(
3519
	'gatewaydescr4',
3520
	'Description',
3521
	'text',
3522
	$gateway_settings4['descr']
3523
));
3524

    
3525
$btnaddgw4 = new Form_Button(
3526
	'add4',
3527
	'Add',
3528
	null,
3529
	'fa-plus'
3530
);
3531

    
3532
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3533

    
3534
$btncnxgw4 = new Form_Button(
3535
	'cnx4',
3536
	'Cancel',
3537
	null,
3538
	'fa-undo'
3539
);
3540

    
3541
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3542

    
3543
$modal->addInput(new Form_StaticText(
3544
	null,
3545
	$btnaddgw4 . $btncnxgw4
3546
));
3547

    
3548
$form->add($modal);
3549

    
3550
print($form);
3551
?>
3552

    
3553
<script type="text/javascript">
3554
//<![CDATA[
3555
events.push(function() {
3556
	function updateType(t) {
3557

    
3558
		switch (t) {
3559
			case "none": {
3560
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3561
				break;
3562
			}
3563
			case "staticv4": {
3564
				$('.dhcpadvanced, .none, .dhcp').hide();
3565
				$('.pppoe, .pptp, .ppp').hide();
3566
				break;
3567
			}
3568
			case "dhcp": {
3569
				$('.dhcpadvanced, .none').hide();
3570
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3571
										//			about the staticv4 class
3572
				$('.pppoe, .pptp, .ppp').hide();
3573
				break;
3574
			}
3575
			case "ppp": {
3576
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3577
				country_list();
3578
				break;
3579
			}
3580
			case "pppoe": {
3581
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3582
				break;
3583
			}
3584
			case "l2tp": {
3585
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3586
				$('.pptp, .l2tp_secret').show();
3587
				break;
3588
			}
3589
			case "pptp": {
3590
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3591
				$('.pptp').show();
3592
				break;
3593
			}
3594
		}
3595

    
3596
		if (t != "l2tp" && t != "pptp") {
3597
			$('.'+t).show();
3598
		}
3599
	}
3600

    
3601
	function updateTypeSix(t) {
3602
		if (!isNaN(t[0])) {
3603
			t = '_' + t;
3604
		}
3605

    
3606
		switch (t) {
3607
			case "none": {
3608
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3609
				break;
3610
			}
3611
			case "staticv6": {
3612
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3613
				break;
3614
			}
3615
			case "slaac": {
3616
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3617
				break;
3618
			}
3619
			case "dhcp6": {
3620
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3621
				break;
3622
			}
3623
			case "_6rd": {
3624
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3625
				break;
3626
			}
3627
			case "_6to4": {
3628
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3629
				break;
3630
			}
3631
			case "track6": {
3632
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3633
				update_track6_prefix();
3634
				break;
3635
			}
3636
		}
3637

    
3638
		if (t != "l2tp" && t != "pptp") {
3639
			$('.'+t).show();
3640
		}
3641
	}
3642

    
3643
	function show_reset_settings(reset_type) {
3644
		if (reset_type == 'preset') {
3645
			$('.pppoepreset').show();
3646
			$('.pppoecustom').hide();
3647
		} else if (reset_type == 'custom') {
3648
			$('.pppoecustom').show();
3649
			$('.pppoepreset').hide();
3650
		} else {
3651
			$('.pppoecustom').hide();
3652
			$('.pppoepreset').hide();
3653
		}
3654
	}
3655

    
3656
	function update_track6_prefix() {
3657
		var iface = $("#track6-interface").val();
3658
		if (iface == null) {
3659
			return;
3660
		}
3661

    
3662
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3663
		if (track6_prefix_ids == null) {
3664
			return;
3665
		}
3666

    
3667
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3668
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3669
	}
3670

    
3671
	function addOption_v4() {
3672
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3673
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3674
	}
3675

    
3676
	function addOption_v6() {
3677
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3678
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3679
	}
3680

    
3681
	function addSelectboxOption(selectbox, text, value) {
3682
		var optn = document.createElement("OPTION");
3683
		optn.text = text;
3684
		optn.value = value;
3685
		selectbox.append(optn);
3686
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3687
	}
3688

    
3689
	function country_list() {
3690
		$('#country').children().remove();
3691
		$('#provider_list').children().remove();
3692
		$('#providerplan').children().remove();
3693
		$.ajax("getserviceproviders.php",{
3694
			success: function(response) {
3695

    
3696
				var responseTextArr = response.split("\n");
3697
				responseTextArr.sort();
3698

    
3699
				responseTextArr.forEach( function(value) {
3700
					country = value.split(":");
3701
					$('#country').append($('<option>', {
3702
						value: country[1],
3703
						text : country[0]
3704
					}));
3705
				});
3706
			}
3707
		});
3708
	}
3709

    
3710
	function providers_list() {
3711
		$('#provider_list').children().remove();
3712
		$('#providerplan').children().remove();
3713
		$.ajax("getserviceproviders.php",{
3714
			type: 'post',
3715
			data: {country : $('#country').val()},
3716
			success: function(response) {
3717
				var responseTextArr = response.split("\n");
3718
				responseTextArr.sort();
3719
				responseTextArr.forEach( function(value) {
3720
					$('#provider_list').append($('<option>', {
3721
							value: value,
3722
							text : value
3723
					}));
3724
				});
3725
			}
3726
		});
3727
	}
3728

    
3729
	function providerplan_list() {
3730
		$('#providerplan').children().remove();
3731
		$.ajax("getserviceproviders.php",{
3732
			type: 'post',
3733
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3734
			success: function(response) {
3735
				var responseTextArr = response.split("\n");
3736
				responseTextArr.sort();
3737

    
3738
				$('#providerplan').append($('<option>', {
3739
					value: '',
3740
					text : ''
3741
				}));
3742

    
3743
				responseTextArr.forEach( function(value) {
3744
					if (value != "") {
3745
						providerplan = value.split(":");
3746

    
3747
						$('#providerplan').append($('<option>', {
3748
							value: providerplan[1],
3749
							text : providerplan[0] + " - " + providerplan[1]
3750
						}));
3751
					}
3752
				});
3753
			}
3754
		});
3755
	}
3756

    
3757
	function prefill_provider() {
3758
		$.ajax("getserviceproviders.php",{
3759
			type: 'post',
3760
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3761
			success: function(data, textStatus, response) {
3762
				var xmldoc = response.responseXML;
3763
				var provider = xmldoc.getElementsByTagName('connection')[0];
3764
				$('#ppp_username').val('');
3765
				$('#ppp_password').val('');
3766
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3767
					$('#phone').val('#777');
3768
					$('#apn').val('');
3769
				} else {
3770
					$('#phone').val('*99#');
3771
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3772
				}
3773
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3774
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3775
				$('#ppp_username').val(ppp_username);
3776
				$('#ppp_password').val(ppp_password);
3777
			}
3778
		});
3779
	}
3780

    
3781
	function show_dhcp6adv() {
3782
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3783
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3784

    
3785
		hideCheckbox('dhcp6usev4iface', ovr);
3786
		hideCheckbox('dhcp6prefixonly', ovr);
3787
		hideInput('dhcp6-ia-pd-len', ovr);
3788
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3789
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3790

    
3791
		hideClass('dhcp6advanced', !adv || ovr);
3792
	}
3793

    
3794
	function setDHCPoptions() {
3795
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3796
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3797

    
3798
		if (ovr) {
3799
			hideInput('dhcphostname', true);
3800
			hideIpAddress('alias-address', true);
3801
			hideInput('dhcprejectfrom', true);
3802
			hideInput('adv_dhcp_config_file_override_path', false);
3803
			hideClass('dhcpadvanced', true);
3804
		} else {
3805
			hideInput('dhcphostname', false);
3806
			hideIpAddress('alias-address', false);
3807
			hideInput('dhcprejectfrom', false);
3808
			hideInput('adv_dhcp_config_file_override_path', true);
3809
			hideClass('dhcpadvanced', !adv);
3810
		}
3811
	}
3812

    
3813
	// DHCP preset actions
3814
	// Set presets from value of radio buttons
3815
	function setPresets(val) {
3816
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3817
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3818
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3819
		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']);?>");
3820
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3821
	}
3822

    
3823
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3824
		$('#adv_dhcp_pt_timeout').val(timeout);
3825
		$('#adv_dhcp_pt_retry').val(retry);
3826
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3827
		$('#adv_dhcp_pt_reboot').val(reboot);
3828
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3829
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3830
	}
3831

    
3832
	function setPPPoEDialOnDemandItems() {
3833
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3834
	}
3835

    
3836
	function setPPTPDialOnDemandItems() {
3837
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3838
	}
3839

    
3840
	// ---------- On initial page load ------------------------------------------------------------
3841

    
3842
	updateType($('#type').val());
3843
	updateTypeSix($('#type6').val());
3844
	show_reset_settings($('#pppoe-reset-type').val());
3845
	hideClass('dhcp6advanced', true);
3846
	hideClass('dhcpadvanced', true);
3847
	show_dhcp6adv();
3848
	setDHCPoptions();
3849
	setPPPoEDialOnDemandItems();
3850
	setPPTPDialOnDemandItems();
3851

    
3852
	// Set preset buttons on page load
3853
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3854
	if (sv == "") {
3855
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3856
	} else {
3857
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3858
	}
3859

    
3860
	// Set preset from value
3861
	setPresets(sv);
3862

    
3863
	// If the user wants to add a gateway, then add that to the gateway selection
3864
	if ($("#gatewayip4").val() != '') {
3865
		addOption_v4();
3866
	}
3867
	if ($("#gatewayip6").val() != '') {
3868
		addOption_v6();
3869
	}
3870

    
3871
	// ---------- Click checkbox handlers ---------------------------------------------------------
3872

    
3873
	$('#type').on('change', function() {
3874
		updateType(this.value);
3875
	});
3876

    
3877
	$('#type6').on('change', function() {
3878
		updateTypeSix(this.value);
3879
	});
3880

    
3881
	$('#track6-interface').on('change', function() {
3882
		update_track6_prefix();
3883
	});
3884

    
3885
	$('#pppoe-reset-type').on('change', function() {
3886
		show_reset_settings(this.value);
3887
	});
3888

    
3889
	$("#add4").click(function() {
3890
		addOption_v4();
3891
		$("#newgateway4").modal('hide');
3892
	});
3893

    
3894
	$("#cnx4").click(function() {
3895
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3896
		$("#gatewayip4").val('');
3897
		$("#gatewaydescr4").val('');
3898
		$("#defaultgw4").prop("checked", false);
3899
		$("#newgateway4").modal('hide');
3900
	});
3901

    
3902
	$("#add6").click(function() {
3903
		addOption_v6();
3904
		$("#newgateway6").modal('hide');
3905
	});
3906

    
3907
	$("#cnx6").click(function() {
3908
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3909
		$("#gatewayip6").val('');
3910
		$("#gatewaydescr6").val('');
3911
		$("#defaultgw6").prop("checked", false);
3912
		$("#newgateway6").modal('hide');
3913
	});
3914

    
3915
	$('#country').on('change', function() {
3916
		providers_list();
3917
	});
3918

    
3919
	$('#provider_list').on('change', function() {
3920
		providerplan_list();
3921
	});
3922

    
3923
	$('#providerplan').on('change', function() {
3924
		prefill_provider();
3925
	});
3926

    
3927
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3928
		setDHCPoptions();
3929
	});
3930

    
3931
	$('#adv_dhcp6_config_advanced').click(function () {
3932
		show_dhcp6adv();
3933
	});
3934

    
3935
	$('#adv_dhcp6_config_file_override').click(function () {
3936
		show_dhcp6adv();
3937
	});
3938

    
3939
	// On click . .
3940
	$('#pppoe_dialondemand').click(function () {
3941
		setPPPoEDialOnDemandItems();
3942
	});
3943

    
3944
	$('#pptp_dialondemand').click(function () {
3945
		setPPTPDialOnDemandItems();
3946
	});
3947

    
3948
	$('[name=adv_dhcp_pt_values]').click(function () {
3949
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3950
	});
3951

    
3952
	$('#pppoe_resetdate').datepicker();
3953

    
3954
});
3955
//]]>
3956
</script>
3957

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