Project

General

Profile

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

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

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

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

    
48
define("ANTENNAS", false);
49

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

    
56
// Get configured interface list
57
$ifdescrs = get_configured_interface_with_descr(true);
58

    
59
$if = "wan";
60

    
61
if ($_REQUEST['if']) {
62
	$if = $_REQUEST['if'];
63
}
64

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

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

    
75
if (!is_array($pconfig)) {
76
	$pconfig = array();
77
}
78

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

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

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

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

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

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

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

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

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

    
136
		/* ================================================ */
137
		/* = force a connection reset at a specific time? = */
138
		/* ================================================ */
139

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

    
194
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
195
$pconfig['alias-address'] = $wancfg['alias-address'];
196
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
197
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
198

    
199
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
200
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
201
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
202
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
203
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
204
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
205

    
206
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
207

    
208
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
209
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
210
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
211
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
212

    
213
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
214
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
215
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
216

    
217
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
218
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
219
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
220
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
221

    
222
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
223
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
224
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
225
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
226
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
227

    
228
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
229
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
230
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
231
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
232
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
233

    
234
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
235
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
236
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
237

    
238
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
239
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
240
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
241
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
242

    
243
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
244
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
245
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
246
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
247
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
248

    
249
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
250
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
251
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
252

    
253
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
254
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
255
$pconfig['enable'] = isset($wancfg['enable']);
256

    
257
switch ($wancfg['ipaddr']) {
258
	case "dhcp":
259
		$pconfig['type'] = "dhcp";
260
		$pconfig['dhcpvlanenable'] = isset($wancfg['dhcpvlanenable']);
261
		$pconfig['dhcpcvpt'] = $wancfg['dhcpcvpt'];
262
		break;
263
	case "pppoe":
264
	case "pptp":
265
	case "l2tp":
266
	case "ppp":
267
		$pconfig['type'] = $wancfg['ipaddr'];
268
		break;
269
	default:
270
		if (is_ipaddrv4($wancfg['ipaddr'])) {
271
			$pconfig['type'] = "staticv4";
272
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
273
			$pconfig['subnet'] = $wancfg['subnet'];
274
			$pconfig['gateway'] = $wancfg['gateway'];
275
		} else {
276
			$pconfig['type'] = "none";
277
		}
278
		break;
279
}
280

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

    
336
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
337
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
338
$pconfig['spoofmac'] = $wancfg['spoofmac'];
339
$pconfig['mtu'] = $wancfg['mtu'];
340
$pconfig['mss'] = $wancfg['mss'];
341

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

    
418
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
419

    
420
}
421

    
422
$changes_applied = false;
423

    
424
if ($_POST['apply']) {
425
	unset($input_errors);
426
	if (!is_subsystem_dirty('interfaces')) {
427
		$input_errors[] = gettext("The settings have already been applied!");
428
	} else {
429
		$retval = 0;
430
		unlink_if_exists("{$g['tmp_path']}/config.cache");
431
		clear_subsystem_dirty('interfaces');
432

    
433
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
434
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
435
			foreach ($toapplylist as $ifapply => $ifcfgo) {
436
				if (isset($config['interfaces'][$ifapply]['enable'])) {
437
					interface_bring_down($ifapply, false, $ifcfgo);
438
					interface_configure($ifapply, true);
439
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
440
						/* call interface_track6_configure with linkup true so
441
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
442
						   just call interface_configure with linkup true as
443
						   that skips bridge membership addition.
444
						*/
445
						$wancfg = $config['interfaces'][$ifapply];
446
						interface_track6_configure($ifapply, $wancfg, true);
447
					}
448
				} else {
449
					interface_bring_down($ifapply, true, $ifcfgo);
450
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
451
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
452
						services_dhcpd_configure();
453
					}
454
				}
455
				/*
456
				 * If the parent interface has changed above, the VLANs needs to be
457
				 * redone.
458
				 */
459
				interfaces_vlan_configure();
460
			}
461
		}
462
		/* restart snmp so that it binds to correct address */
463
		$retval |= services_snmpd_configure();
464

    
465
		/* sync filter configuration */
466
		setup_gateways_monitor();
467

    
468
		clear_subsystem_dirty('interfaces');
469

    
470
		$retval |= filter_configure();
471

    
472
		enable_rrd_graphing();
473

    
474
		$changes_applied = true;
475

    
476
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
477
			clear_subsystem_dirty('staticroutes');
478
		}
479
	}
480
	@unlink("{$g['tmp_path']}/.interfaces.apply");
481
} else if ($_POST['save']) {
482

    
483
	unset($input_errors);
484
	$pconfig = $_POST;
485

    
486
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
487
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
488
	} else {
489
		$pconfig['track6-prefix-id'] = 0;
490
	}
491

    
492
	/* filter out spaces from descriptions */
493
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
494

    
495
	/* okay first of all, cause we are just hiding the PPPoE HTML
496
	 * fields related to PPPoE resets, we are going to unset $_POST
497
	 * vars, if the reset feature should not be used. Otherwise the
498
	 * data validation procedure below, may trigger a false error
499
	 * message.
500
	 */
501
	if (empty($_POST['pppoe-reset-type'])) {
502
		unset($_POST['pppoe_pr_type']);
503
		unset($_POST['pppoe_resethour']);
504
		unset($_POST['pppoe_resetminute']);
505
		unset($_POST['pppoe_resetdate']);
506
		unset($_POST['pppoe_pr_preset_val']);
507
	}
508

    
509
	/* input validation */
510
	$reqdfields = explode(" ", "descr");
511
	$reqdfieldsn = array(gettext("Description"));
512
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
513

    
514
	if (!$input_errors) {
515
		/* description unique? */
516
		foreach ($ifdescrs as $ifent => $ifdescr) {
517
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
518
				$input_errors[] = gettext("An interface with the specified description already exists.");
519
				break;
520
			}
521
		}
522

    
523
		/* Is the description already used as an alias name? */
524
		if (is_array($config['aliases']['alias'])) {
525
			foreach ($config['aliases']['alias'] as $alias) {
526
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
527
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
528
				}
529
			}
530
		}
531

    
532
		/* Is the description already used as an interface group name? */
533
		if (is_array($config['ifgroups']['ifgroupentry'])) {
534
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
535
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
536
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
537
				}
538
			}
539
		}
540

    
541
		if (is_numeric($_POST['descr'])) {
542
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
543
		}
544

    
545
		/*
546
		 * Packages (e.g. tinc) create interface groups, reserve this
547
		 * namespace pkg_ for them.
548
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
549
		 */
550
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
551
			$input_errors[] = gettext("The interface description cannot start with pkg_");
552
		}
553
	}
554

    
555
	if ($_POST['blockbogons'] == "yes" &&
556
	    isset($config['system']['ipv6allow']) &&
557
	    (!isset($config['system']['maximumtableentries']) ||
558
	     $config['system']['maximumtableentries'] <
559
	     $g['minimumtableentries_bogonsv6'])) {
560
		$input_errors[] = sprintf(gettext(
561
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
562
		    $g['minimumtableentries_bogonsv6']);
563
	}
564

    
565
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
566
		if (!preg_match("/^staticv4/", $_POST['type'])) {
567
			$input_errors[] = gettext("The DHCP Server is active " .
568
			    "on this interface and it can be used only with " .
569
			    "a static IP configuration. Please disable the " .
570
			    "DHCP Server service on this interface first, " .
571
			    "then change the interface configuration.");
572
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
573
			$input_errors[] = gettext("The DHCP Server is active " .
574
			    "on this interface and it can be used only with " .
575
			    "IPv4 subnet < 31. Please disable the " .
576
			    "DHCP Server service on this interface first, " .
577
			    "then change the interface configuration.");
578
		}
579
	}
580
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
581
		$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.");
582
	}
583

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

    
691
			if (empty($_POST['track6-interface'])) {
692
				$input_errors[] = gettext("A valid interface to track must be selected.");
693
			}
694

    
695
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
696
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
697
			} else {
698
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
699
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
700
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
701
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
702
				} else {
703
					foreach ($ifdescrs as $ifent => $ifdescr) {
704
						if ($if == $ifent) {
705
							continue;
706
						}
707
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
708
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
709
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
710
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
711
						}
712
					}
713
				}
714
			}
715
			break;
716
	}
717

    
718
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
719
	$staticroutes = get_staticroutes(true);
720
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
721
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
722
		if (!is_ipaddrv4($_POST['ipaddr'])) {
723
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
724
		} else {
725
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
726
			if (count($where_ipaddr_configured)) {
727
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
728
				foreach ($where_ipaddr_configured as $subnet_conflict) {
729
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
730
				}
731
				$input_errors[] = $subnet_conflict_text;
732
			}
733

    
734
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
735
			if ($_POST['subnet'] < 31) {
736
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
737
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
738
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
739
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
740
				}
741
			}
742

    
743
			foreach ($staticroutes as $route_subnet) {
744
				list($network, $subnet) = explode("/", $route_subnet);
745
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
746
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
747
					break;
748
				}
749
				unset($network, $subnet);
750
			}
751
		}
752
	}
753
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
754
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
755

    
756
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
757
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
758
		} else {
759
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
760
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
761
			}
762
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
763
			if (count($where_ipaddr_configured)) {
764
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
765
				foreach ($where_ipaddr_configured as $subnet_conflict) {
766
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
767
				}
768
				$input_errors[] = $subnet_conflict_text;
769
			}
770

    
771
			foreach ($staticroutes as $route_subnet) {
772
				list($network, $subnet) = explode("/", $route_subnet);
773
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
774
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
775
					break;
776
				}
777
				unset($network, $subnet);
778
			}
779
		}
780
	}
781
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
782
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
783
	}
784
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
785
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
786
	}
787
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
788
		$input_errors[] = gettext("A valid alias IP address must be specified.");
789
	}
790
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
791
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
792
	}
793
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
794
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
795
	}
796

    
797
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
798
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
799
		$match = false;
800
		foreach ($a_gateways as $gateway) {
801
			if (in_array($_POST['gateway'], $gateway)) {
802
				$match = true;
803
			}
804
		}
805
		if (!$match) {
806
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
807
		}
808
	}
809
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
810
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
811
		$match = false;
812
		foreach ($a_gateways as $gateway) {
813
			if (in_array($_POST['gatewayv6'], $gateway)) {
814
				$match = true;
815
			}
816
		}
817
		if (!$match) {
818
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
819
		}
820
	}
821

    
822
	if (($_POST['provider'] && (strpos($_POST['provider'], "\"")))) {
823
		$input_errors[] = gettext("The service name may not contain quote characters.");
824
	}
825
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
826
		$input_errors[] = gettext("The idle timeout value must be an integer.");
827
	}
828
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
829
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
830
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
831
	}
832
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
833
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
834
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
835
	}
836
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
837
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
838
	}
839
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
840
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
841
	}
842
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
843
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
844
	}
845
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
846
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
847
	}
848
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
849
		$input_errors[] = gettext("The idle timeout value must be an integer.");
850
	}
851
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
852
		$input_errors[] = gettext("A valid MAC address must be specified.");
853
	}
854
	if ($_POST['mtu']) {
855
		if (!is_numericint($_POST['mtu'])) {
856
			$input_errors[] = "MTU must be an integer.";
857
		}
858
		if (substr($wancfg['if'], 0, 3) == 'gif') {
859
			$min_mtu = 1280;
860
			$max_mtu = 8192;
861
		} else {
862
			$min_mtu = 576;
863
			$max_mtu = 9000;
864
		}
865

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

    
870
		unset($min_mtu, $max_mtu);
871

    
872
		if (interface_is_vlan($wancfg['if']) != NULL) {
873
			$realhwif_array = get_parent_interface($wancfg['if']);
874
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
875
			$parent_realhwif = $realhwif_array[0];
876
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
877
			$mtu = 0;
878
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
879
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
880
			if ($mtu == 0)
881
				$mtu = get_interface_mtu($parent_realhwif);
882
			if ($_POST['mtu'] > $mtu)
883
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
884
		} else {
885
			foreach ($config['interfaces'] as $idx => $ifdata) {
886
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
887
					continue;
888
				}
889

    
890
				$realhwif_array = get_parent_interface($ifdata['if']);
891
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
892
				$parent_realhwif = $realhwif_array[0];
893

    
894
				if ($parent_realhwif != $wancfg['if']) {
895
					continue;
896
				}
897

    
898
				if (isset($ifdata['mtu']) && $ifdata['mtu'] > $_POST['mtu']) {
899
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), $ifdata['descr']);
900
				}
901
			}
902
		}
903
	}
904
	if ($_POST['mss'] != '') {
905
		if (!is_numericint($_POST['mss']) || ($_POST['mss'] < 576 || $_POST['mss'] > 65535)) {
906
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
907
		}
908
	}
909
	/* Wireless interface? */
910
	if (isset($wancfg['wireless'])) {
911
		$reqdfields = array("mode");
912
		$reqdfieldsn = array(gettext("Mode"));
913
		if ($_POST['mode'] == 'hostap') {
914
			$reqdfields[] = "ssid";
915
			$reqdfieldsn[] = gettext("SSID");
916
			if (isset($_POST['channel']) && $_POST['channel'] == "0") {
917
				// auto channel with hostap is broken, prevent this for now.
918
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
919
			}
920
		}
921
		if (stristr($_POST['standard'], '11n')) {
922
			if (!($_POST['wme_enable'])) {
923
				$input_errors[] = gettext("802.11n standards require enabling WME.");
924
			}
925
		}
926
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
927
		check_wireless_mode();
928
		if (isset($_POST['wpa_group_rekey']) && (!is_numericint($_POST['wpa_group_rekey']) || $_POST['wpa_group_rekey'] < 1 || $_POST['wpa_group_rekey'] > 9999)) {
929
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
930
		}
931
		if (isset($_POST['wpa_gmk_rekey']) && (!is_numericint($_POST['wpa_gmk_rekey']) || $_POST['wpa_gmk_rekey'] < 1 || $_POST['wpa_gmk_rekey'] > 9999)) {
932
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
933
		}
934
		if (isset($_POST['wpa_group_rekey']) && isset($_POST['wpa_gmk_rekey'])) {
935
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
936
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
937
			}
938
		}
939
		if (!empty($_POST['auth_server_addr'])) {
940
			if (!is_domain($_POST['auth_server_addr']) && !is_ipaddr($_POST['auth_server_addr'])) {
941
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
942
			}
943
		}
944
		if (!empty($_POST['auth_server_addr2'])) {
945
			if (!is_domain($_POST['auth_server_addr2']) && !is_ipaddr($_POST['auth_server_addr2'])) {
946
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
947
			}
948
		}
949
		if (!empty($_POST['auth_server_port'])) {
950
			if (!is_port($_POST['auth_server_port'])) {
951
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
952
			}
953
		}
954
		if (!empty($_POST['auth_server_port2'])) {
955
			if (!is_port($_POST['auth_server_port2'])) {
956
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
957
			}
958
		}
959
		if (isset($_POST['channel']) && !is_numericint($_POST['channel'])) {
960
			if (!is_numericint($_POST['channel'])) {
961
				$input_errors[] = gettext("Invalid channel specified.");
962
			} else {
963
				if ($_POST['channel'] > 255 || $_POST['channel'] < 0) {
964
					$input_errors[] = gettext("Channel must be between 0-255.");
965
				}
966
			}
967
		}
968
		if (!empty($_POST['distance']) && !is_numericint($_POST['distance'])) {
969
			$input_errors[] = gettext("Distance must be an integer.");
970
		}
971
		if (isset($_POST['standard']) && (stristr($_POST['standard'], '11na') || stristr($_POST['standard'], '11a'))) {
972
			if ($_POST['channel'] != 0 && $_POST['channel'] < 15) {
973
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
974
			}
975
		}
976
		if (isset($_POST['standard']) && ($_POST['standard'] == "11b" || $_POST['standard'] == "11g")) {
977
			if ($_POST['channel'] > 14) {
978
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
979
			}
980
		}
981
		if (!empty($_POST['protmode']) && !in_array($_POST['protmode'], array("off", "cts", "rtscts"))) {
982
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
983
		}
984

    
985
		if ($_POST['passphrase']) {
986
			$passlen = strlen($_POST['passphrase']);
987
			if ($passlen < 8 || $passlen > 63) {
988
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
989
			}
990
		}
991

    
992
		if ($_POST['wpa_enable'] == "yes") {
993
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
994
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
995
			}
996
		}
997
	}
998

    
999
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1000
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1001
	}
1002

    
1003
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1004
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1005
	}
1006

    
1007
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1008
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1009
	}
1010

    
1011
	if ($_POST['gatewayip4']) {
1012
		// The user wants to add an IPv4 gateway - validate the settings
1013
		$gateway_settings4 = array();
1014

    
1015
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1016
		$gateway_settings4['interface'] = $_POST['if'];
1017
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1018
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1019
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1020
		$gateway_settings4['ipprotocol'] = 'inet';
1021
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1022
		foreach ($gw_input_errors as $input_error_text) {
1023
			$input_errors[] = $input_error_text;
1024
		}
1025
	}
1026

    
1027
	if ($_POST['gatewayip6']) {
1028
		// The user wants to add an IPv6 gateway - validate the settings
1029
		$gateway_settings6 = array();
1030

    
1031
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1032
		$gateway_settings6['interface'] = $_POST['if'];
1033
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1034
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1035
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1036
		$gateway_settings6['ipprotocol'] = 'inet6';
1037
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1038
		foreach ($gw_input_errors as $input_error_text) {
1039
			$input_errors[] = $input_error_text;
1040
		}
1041
	}
1042

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

    
1050
		if ($wancfg['ipaddr'] != $_POST['type']) {
1051
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1052
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1053
				unset($a_ppps[$pppid]);
1054
			} else if ($wancfg['ipaddr'] == "dhcp") {
1055
				kill_dhclient_process($wancfg['if']);
1056
			}
1057
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1058
				kill_dhcp6client_process($wancfg['if'],true);
1059
			}
1060
		}
1061
		$ppp = array();
1062
		if ($wancfg['ipaddr'] != "ppp") {
1063
			unset($wancfg['ipaddr']);
1064
		}
1065
		if ($wancfg['ipaddrv6'] != "ppp") {
1066
			unset($wancfg['ipaddrv6']);
1067
		}
1068
		unset($wancfg['subnet']);
1069
		unset($wancfg['gateway']);
1070
		unset($wancfg['subnetv6']);
1071
		unset($wancfg['gatewayv6']);
1072
		unset($wancfg['dhcphostname']);
1073
		unset($wancfg['dhcprejectfrom']);
1074
		unset($wancfg['dhcp6-duid']);
1075
		unset($wancfg['dhcp6-ia-pd-len']);
1076
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1077
		unset($wancfg['dhcp6prefixonly']);
1078
		unset($wancfg['dhcp6usev4iface']);
1079
		unset($wancfg['ipv6usev4iface']);
1080
		unset($wancfg['dhcp6debug']);
1081
		unset($wancfg['track6-interface']);
1082
		unset($wancfg['track6-prefix-id']);
1083
		unset($wancfg['dhcp6withoutra']);
1084
		unset($wancfg['dhcp6norelease']);
1085
		unset($wancfg['dhcp6vlanenable']);
1086
		unset($wancfg['dhcp6cvpt']);
1087
		unset($wancfg['prefix-6rd']);
1088
		unset($wancfg['prefix-6rd-v4plen']);
1089
		unset($wancfg['gateway-6rd']);
1090

    
1091
		unset($wancfg['dhcpvlanenable']);
1092
		unset($wancfg['dhcpcvpt']);
1093

    
1094
		unset($wancfg['adv_dhcp_pt_timeout']);
1095
		unset($wancfg['adv_dhcp_pt_retry']);
1096
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1097
		unset($wancfg['adv_dhcp_pt_reboot']);
1098
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1099
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1100

    
1101
		unset($wancfg['adv_dhcp_pt_values']);
1102

    
1103
		unset($wancfg['adv_dhcp_send_options']);
1104
		unset($wancfg['adv_dhcp_request_options']);
1105
		unset($wancfg['adv_dhcp_required_options']);
1106
		unset($wancfg['adv_dhcp_option_modifiers']);
1107

    
1108
		unset($wancfg['adv_dhcp_config_advanced']);
1109
		unset($wancfg['adv_dhcp_config_file_override']);
1110
		unset($wancfg['adv_dhcp_config_file_override_path']);
1111

    
1112
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1113
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1114
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1115
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1116

    
1117
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1118
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1119
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1120
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1121
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1122

    
1123
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1124
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1125
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1126
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1127
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1128

    
1129
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1130
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1131
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1132

    
1133
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1134
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1135
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1136
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1137

    
1138
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1139
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1140
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1141
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1142
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1143

    
1144
		unset($wancfg['adv_dhcp6_config_advanced']);
1145
		unset($wancfg['adv_dhcp6_config_file_override']);
1146
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1147

    
1148
		unset($wancfg['pppoe_password']);
1149
		unset($wancfg['pptp_username']);
1150
		unset($wancfg['pptp_password']);
1151
		unset($wancfg['provider']);
1152
		unset($wancfg['ondemand']);
1153
		unset($wancfg['timeout']);
1154
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1155
			unset($wancfg['pppoe']['pppoe-reset-type']);
1156
		}
1157
		unset($wancfg['local']);
1158

    
1159
		unset($wancfg['remote']);
1160
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1161
			if ($wancfg['ipaddr'] != 'ppp') {
1162
				unset($a_ppps[$pppid]['apn']);
1163
				unset($a_ppps[$pppid]['phone']);
1164
				unset($a_ppps[$pppid]['provider']);
1165
				unset($a_ppps[$pppid]['ondemand']);
1166
			}
1167
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1168
				unset($a_ppps[$pppid]['localip']);
1169
				unset($a_ppps[$pppid]['subnet']);
1170
				unset($a_ppps[$pppid]['gateway']);
1171
			}
1172
			if ($wancfg['ipaddr'] != 'pppoe') {
1173
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1174
			}
1175
			if ($wancfg['type'] != $_POST['type']) {
1176
				unset($a_ppps[$pppid]['idletimeout']);
1177
			}
1178
		}
1179

    
1180
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1181
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1182

    
1183
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1184
		switch ($_POST['type']) {
1185
			case "staticv4":
1186
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1187
				$wancfg['subnet'] = $_POST['subnet'];
1188
				if ($_POST['gateway'] != "none") {
1189
					$wancfg['gateway'] = $_POST['gateway'];
1190
				}
1191
				break;
1192
			case "dhcp":
1193
				$wancfg['ipaddr'] = "dhcp";
1194
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1195
				$wancfg['alias-address'] = $_POST['alias-address'];
1196
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1197
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1198

    
1199
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1200
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1201
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1202
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1203
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1204
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1205

    
1206
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1207

    
1208
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1209
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1210
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1211
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1212

    
1213
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1214
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1215
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1216

    
1217
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1218
				if ($gateway_item) {
1219
					$a_gateways[] = $gateway_item;
1220
				}
1221
				if ($_POST['dhcpvlanenable'] == "yes") {
1222
					$wancfg['dhcpvlanenable'] = true;
1223
				}
1224
				if (!empty($_POST['dhcpcvpt'])) {
1225
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1226
				} else {
1227
					unset($wancfg['dhcpcvpt']);
1228
				}
1229
				break;
1230
			case "ppp":
1231
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1232
				$a_ppps[$pppid]['type'] = $_POST['type'];
1233
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1234
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1235
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1236
				if ($_POST['ppp_password'] != DMYPWD) {
1237
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1238
				}
1239
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1240
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1241
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1242
				$wancfg['ipaddr'] = $_POST['type'];
1243
				break;
1244

    
1245
			case "pppoe":
1246
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1247
				$a_ppps[$pppid]['type'] = $_POST['type'];
1248
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1249
				if (isset($_POST['ppp_port'])) {
1250
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1251
				} else {
1252
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1253
				}
1254
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1255
				if ($_POST['pppoe_password'] != DMYPWD) {
1256
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1257
				}
1258
				if (!empty($_POST['provider'])) {
1259
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1260
				} else {
1261
					$a_ppps[$pppid]['provider'] = true;
1262
				}
1263
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1264
				if (!empty($_POST['pppoe_idletimeout'])) {
1265
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1266
				} else {
1267
					unset($a_ppps[$pppid]['idletimeout']);
1268
				}
1269

    
1270
				if (!empty($_POST['pppoe-reset-type'])) {
1271
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1272
				} else {
1273
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1274
				}
1275
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1276
				$wancfg['ipaddr'] = $_POST['type'];
1277
				if ($gateway_item) {
1278
					$a_gateways[] = $gateway_item;
1279
				}
1280

    
1281
				break;
1282
			case "pptp":
1283
			case "l2tp":
1284
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1285
				$a_ppps[$pppid]['type'] = $_POST['type'];
1286
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1287
				if (isset($_POST['ppp_port'])) {
1288
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1289
				} else {
1290
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1291
				}
1292
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1293
				if ($_POST['pptp_password'] != DMYPWD) {
1294
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1295
				}
1296
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1297
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1298
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1299
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1300
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1301
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1302
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1303
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1304
				if (!empty($_POST['pptp_idletimeout'])) {
1305
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1306
				} else {
1307
					unset($a_ppps[$pppid]['idletimeout']);
1308
				}
1309
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1310
				$wancfg['ipaddr'] = $_POST['type'];
1311
				if ($gateway_item) {
1312
					$a_gateways[] = $gateway_item;
1313
				}
1314
				break;
1315
			case "none":
1316
				break;
1317
		}
1318
		switch ($_POST['type6']) {
1319
			case "staticv6":
1320
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1321
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1322
				if ($_POST['ipv6usev4iface'] == "yes") {
1323
					$wancfg['ipv6usev4iface'] = true;
1324
				}
1325
				if ($_POST['gatewayv6'] != "none") {
1326
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1327
				}
1328
				break;
1329
			case "slaac":
1330
				$wancfg['ipaddrv6'] = "slaac";
1331
				break;
1332
			case "dhcp6":
1333
				$wancfg['ipaddrv6'] = "dhcp6";
1334
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1335
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1336
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1337
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1338
				}
1339
				if ($_POST['dhcp6prefixonly'] == "yes") {
1340
					$wancfg['dhcp6prefixonly'] = true;
1341
				}
1342
				if ($_POST['dhcp6usev4iface'] == "yes") {
1343
					$wancfg['dhcp6usev4iface'] = true;
1344
				}
1345
				if ($_POST['dhcp6debug'] == "yes") {
1346
					$wancfg['dhcp6debug'] = true;
1347
				}
1348

    
1349
				if ($_POST['dhcp6withoutra'] == "yes") {
1350
					$wancfg['dhcp6withoutra'] = true;
1351
				}
1352
				if ($_POST['dhcp6norelease'] == "yes") {
1353
					$wancfg['dhcp6norelease'] = true;
1354
				}
1355
				if ($_POST['dhcp6vlanenable'] == "yes") {
1356
					$wancfg['dhcp6vlanenable'] = true;
1357
				}
1358
				if (!empty($_POST['dhcp6cvpt'])) {
1359
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1360
				} else {
1361
					unset($wancfg['dhcp6cvpt']);
1362
				}
1363

    
1364
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1365
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1366
				}
1367
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1368
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1369
				}
1370
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1371
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1372
				}
1373
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1374
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1375
				}
1376

    
1377
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1378
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1379
				}
1380
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1381
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1382
				}
1383
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1384
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1385
				}
1386
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1387
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1388
				}
1389
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1390
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1391
				}
1392

    
1393
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1394
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1395
				}
1396
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1397
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1398
				}
1399
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1400
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1401
				}
1402
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1403
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1404
				}
1405
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1406
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1407
				}
1408

    
1409
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1410
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1411
				}
1412
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1413
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1414
				}
1415
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1416
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1417
				}
1418
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1419
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1420
				}
1421
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1422
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1423
				}
1424
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1425
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1426
				}
1427
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1428
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1429
				}
1430

    
1431
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1432
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1433
				}
1434
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1435
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1436
				}
1437
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1438
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1439
				}
1440
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1441
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1442
				}
1443
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1444
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1445
				}
1446

    
1447
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1448
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1449
				}
1450
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1451
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1452
				}
1453
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1454
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1455
				}
1456

    
1457
				if ($gateway_item) {
1458
					$a_gateways[] = $gateway_item;
1459
				}
1460
				break;
1461
			case "6rd":
1462
				$wancfg['ipaddrv6'] = "6rd";
1463
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1464
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1465
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1466
				if ($gateway_item) {
1467
					$a_gateways[] = $gateway_item;
1468
				}
1469
				break;
1470
			case "6to4":
1471
				$wancfg['ipaddrv6'] = "6to4";
1472
				break;
1473
			case "track6":
1474
				$wancfg['ipaddrv6'] = "track6";
1475
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1476
				if ($_POST['track6-prefix-id--hex'] === "") {
1477
					$wancfg['track6-prefix-id'] = 0;
1478
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1479
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1480
				} else {
1481
					$wancfg['track6-prefix-id'] = 0;
1482
				}
1483
				break;
1484
			case "none":
1485
				break;
1486
		}
1487
		handle_pppoe_reset($_POST);
1488

    
1489
		if ($_POST['blockpriv'] == "yes") {
1490
			$wancfg['blockpriv'] = true;
1491
		} else {
1492
			unset($wancfg['blockpriv']);
1493
		}
1494
		if ($_POST['blockbogons'] == "yes") {
1495
			$wancfg['blockbogons'] = true;
1496
		} else {
1497
			unset($wancfg['blockbogons']);
1498
		}
1499
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1500
		if (empty($_POST['mtu'])) {
1501
			unset($wancfg['mtu']);
1502
		} else {
1503
			$wancfg['mtu'] = $_POST['mtu'];
1504
		}
1505
		if (empty($_POST['mss'])) {
1506
			unset($wancfg['mss']);
1507
		} else {
1508
			$wancfg['mss'] = $_POST['mss'];
1509
		}
1510
		if (empty($_POST['mediaopt'])) {
1511
			unset($wancfg['media']);
1512
			unset($wancfg['mediaopt']);
1513
		} else {
1514
			$mediaopts = explode(' ', $_POST['mediaopt']);
1515
			if ($mediaopts[0] != '') {
1516
				$wancfg['media'] = $mediaopts[0];
1517
			}
1518
			if ($mediaopts[1] != '') {
1519
				$wancfg['mediaopt'] = $mediaopts[1];
1520
			} else {
1521
				unset($wancfg['mediaopt']);
1522
			}
1523
		}
1524
		if (isset($wancfg['wireless'])) {
1525
			handle_wireless_post();
1526
		}
1527

    
1528
		write_config();
1529

    
1530
		if ($_POST['gatewayip4']) {
1531
			save_gateway($gateway_settings4);
1532
		}
1533

    
1534
		if ($_POST['gatewayip6']) {
1535
			save_gateway($gateway_settings6);
1536
		}
1537

    
1538
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1539
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1540
		} else {
1541
			$toapplylist = array();
1542
		}
1543
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1544
		$toapplylist[$if]['ppps'] = $old_ppps;
1545
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1546

    
1547
		mark_subsystem_dirty('interfaces');
1548

    
1549
		/* regenerate cron settings/crontab file */
1550
		configure_cron();
1551

    
1552
		header("Location: interfaces.php?if={$if}");
1553
		exit;
1554
	}
1555

    
1556
} // end if ($_POST['save'])
1557

    
1558
function handle_wireless_post() {
1559
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1560
	if (!is_array($wancfg['wireless'])) {
1561
		$wancfg['wireless'] = array();
1562
	}
1563
	$wancfg['wireless']['standard'] = $_POST['standard'];
1564
	$wancfg['wireless']['mode'] = $_POST['mode'];
1565
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1566
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1567
	$wancfg['wireless']['channel'] = $_POST['channel'];
1568
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1569
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1570
	$wancfg['wireless']['distance'] = $_POST['distance'];
1571
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1572
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1573
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1574
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1575
		foreach ($wl_countries_attr as $wl_country) {
1576
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1577
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1578
				break;
1579
			}
1580
		}
1581
	}
1582
	if (!is_array($wancfg['wireless']['wpa'])) {
1583
		$wancfg['wireless']['wpa'] = array();
1584
	}
1585
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1586
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1587
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1588
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1589
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1590
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1591
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1592
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1593
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1594
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1595
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1596
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1597
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1598
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1599

    
1600
	if ($_POST['persistcommonwireless'] == "yes") {
1601
		if (!is_array($config['wireless'])) {
1602
			$config['wireless'] = array();
1603
		}
1604
		if (!is_array($config['wireless']['interfaces'])) {
1605
			$config['wireless']['interfaces'] = array();
1606
		}
1607
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1608
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1609
		}
1610
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1611
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1612
	}
1613
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1614
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1615
	} else if (isset($wancfg['wireless']['diversity'])) {
1616
		unset($wancfg['wireless']['diversity']);
1617
	}
1618
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1619
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1620
	} else if (isset($wancfg['wireless']['txantenna'])) {
1621
		unset($wancfg['wireless']['txantenna']);
1622
	}
1623
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1624
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1625
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1626
		unset($wancfg['wireless']['rxantenna']);
1627
	}
1628
	if ($_POST['hidessid_enable'] == "yes") {
1629
		$wancfg['wireless']['hidessid']['enable'] = true;
1630
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1631
		unset($wancfg['wireless']['hidessid']['enable']);
1632
	}
1633
	if ($_POST['mac_acl_enable'] == "yes") {
1634
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1635
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1636
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1637
	}
1638
	if ($_POST['rsn_preauth'] == "yes") {
1639
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1640
	} else {
1641
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1642
	}
1643
	if ($_POST['ieee8021x'] == "yes") {
1644
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1645
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1646
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1647
	}
1648
	if ($_POST['wpa_strict_rekey'] == "yes") {
1649
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1650
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1651
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1652
	}
1653
	if ($_POST['debug_mode'] == "yes") {
1654
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1655
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1656
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1657
	}
1658
	if ($_POST['wpa_enable'] == "yes") {
1659
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1660
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1661
		unset($wancfg['wireless']['wpa']['enable']);
1662
	}
1663

    
1664
	if ($_POST['wme_enable'] == "yes") {
1665
		if (!is_array($wancfg['wireless']['wme'])) {
1666
			$wancfg['wireless']['wme'] = array();
1667
		}
1668
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1669
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1670
		unset($wancfg['wireless']['wme']['enable']);
1671
	}
1672
	if ($_POST['puremode'] == "11g") {
1673
		if (!is_array($wancfg['wireless']['pureg'])) {
1674
			$wancfg['wireless']['pureg'] = array();
1675
		}
1676
		$wancfg['wireless']['pureg']['enable'] = true;
1677
	} else if ($_POST['puremode'] == "11n") {
1678
		if (!is_array($wancfg['wireless']['puren'])) {
1679
			$wancfg['wireless']['puren'] = array();
1680
		}
1681
		$wancfg['wireless']['puren']['enable'] = true;
1682
	} else {
1683
		if (isset($wancfg['wireless']['pureg'])) {
1684
			unset($wancfg['wireless']['pureg']);
1685
		}
1686
		if (isset($wancfg['wireless']['puren'])) {
1687
			unset($wancfg['wireless']['puren']);
1688
		}
1689
	}
1690
	if ($_POST['apbridge_enable'] == "yes") {
1691
		if (!is_array($wancfg['wireless']['apbridge'])) {
1692
			$wancfg['wireless']['apbridge'] = array();
1693
		}
1694
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1695
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1696
		unset($wancfg['wireless']['apbridge']['enable']);
1697
	}
1698
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1699
		if (!is_array($wancfg['wireless']['turbo'])) {
1700
			$wancfg['wireless']['turbo'] = array();
1701
		}
1702
		$wancfg['wireless']['turbo']['enable'] = true;
1703
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1704
		unset($wancfg['wireless']['turbo']['enable']);
1705
	}
1706

    
1707
	interface_sync_wireless_clones($wancfg, true);
1708
}
1709

    
1710
function check_wireless_mode() {
1711
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1712

    
1713
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1714
		return;
1715
	}
1716

    
1717
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1718
		$clone_count = 1;
1719
	} else {
1720
		$clone_count = 0;
1721
	}
1722

    
1723
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1724
		foreach ($config['wireless']['clone'] as $clone) {
1725
			if ($clone['if'] == $wlanbaseif) {
1726
				$clone_count++;
1727
			}
1728
		}
1729
	}
1730

    
1731
	if ($clone_count > 1) {
1732
		$old_wireless_mode = $wancfg['wireless']['mode'];
1733
		$wancfg['wireless']['mode'] = $_POST['mode'];
1734
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1735
			$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']]);
1736
		} else {
1737
			pfSense_interface_destroy("{$wlanif}_");
1738
		}
1739
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1740
	}
1741
}
1742

    
1743
// Find all possible media options for the interface
1744
$mediaopts_list = array();
1745
$intrealname = $config['interfaces'][$if]['if'];
1746
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1747
foreach ($mediaopts as $mediaopt) {
1748
	preg_match("/media (.*)/", $mediaopt, $matches);
1749
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1750
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1751
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1752
	} else {
1753
		// there is only media like "media 1000baseT"
1754
		array_push($mediaopts_list, $matches[1]);
1755
	}
1756
}
1757

    
1758
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1759
$shortcut_section = "interfaces";
1760

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

    
1764
// Get the MAC address
1765
$ip = $_SERVER['REMOTE_ADDR'];
1766
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1767
$mymac = str_replace("\n", "", $mymac);
1768
$defgatewayname4 = $wancfg['descr'] . "GW";
1769
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1770

    
1771
function build_mediaopts_list() {
1772
	global $mediaopts_list;
1773

    
1774
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1775
			 " " =>	 gettext("------- Media Supported by this interface -------")
1776
			];
1777

    
1778
	foreach ($mediaopts_list as $mediaopt) {
1779
		$list[$mediaopt] = $mediaopt;
1780
	}
1781

    
1782
	return($list);
1783
}
1784

    
1785
function build_gateway_list() {
1786
	global $a_gateways, $if;
1787

    
1788
	$list = array("none" => gettext("None"));
1789
	foreach ($a_gateways as $gateway) {
1790
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1791
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1792
		}
1793
	}
1794

    
1795
	return($list);
1796
}
1797

    
1798
function build_gatewayv6_list() {
1799
	global $a_gateways, $if;
1800

    
1801
	$list = array("none" => gettext("None"));
1802
	foreach ($a_gateways as $gateway) {
1803
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1804
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1805
		}
1806
	}
1807

    
1808
	return($list);
1809
}
1810

    
1811
include("head.inc");
1812

    
1813
if ($input_errors) {
1814
	print_input_errors($input_errors);
1815
}
1816

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

    
1823
if ($changes_applied) {
1824
	print_apply_result_box($retval);
1825
}
1826

    
1827
$form = new Form();
1828

    
1829
$section = new Form_Section('General Configuration');
1830

    
1831
$section->addInput(new Form_Checkbox(
1832
	'enable',
1833
	'Enable',
1834
	'Enable interface',
1835
	$pconfig['enable'],
1836
	'yes'
1837
));
1838

    
1839
$section->addInput(new Form_Input(
1840
	'descr',
1841
	'*Description',
1842
	'text',
1843
	$pconfig['descr']
1844
))->setHelp('Enter a description (name) for the interface here.');
1845

    
1846
if ($show_address_controls) {
1847
	$section->addInput(new Form_Select(
1848
		'type',
1849
		'IPv4 Configuration Type',
1850
		$pconfig['type'],
1851
		$types4
1852
	));
1853
	$section->addInput(new Form_Select(
1854
		'type6',
1855
		'IPv6 Configuration Type',
1856
		$pconfig['type6'],
1857
		$types6
1858
	));
1859
} else {
1860
	$section->addInput(new Form_StaticText(
1861
		'IPv4/IPv6 Configuration',
1862
		"This interface type does not support manual address configuration on this page. "
1863
	));
1864
	$section->addInput(new Form_Input(
1865
		'type',
1866
		null,
1867
		'hidden',
1868
		'none'
1869
	));
1870
	$section->addInput(new Form_Input(
1871
		'type6',
1872
		null,
1873
		'hidden',
1874
		'none'
1875
	));
1876
}
1877

    
1878
$macaddress = new Form_Input(
1879
	'spoofmac',
1880
	'MAC Address',
1881
	'text',
1882
	$pconfig['spoofmac'],
1883
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1884
);
1885

    
1886
if (interface_is_vlan($realifname)) {
1887
	$macaddress->setDisabled();
1888
	$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
1889
	    'set on its parent interface');
1890
} else {
1891
	$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
1892
	    'MAC address of this interface.%sEnter a MAC address in the ' .
1893
	    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1894
}
1895

    
1896
$section->addInput($macaddress);
1897

    
1898
$section->addInput(new Form_Input(
1899
	'mtu',
1900
	'MTU',
1901
	'number',
1902
	$pconfig['mtu']
1903
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1904
			'This is typically 1500 bytes but can vary in some circumstances.');
1905

    
1906
$section->addInput(new Form_Input(
1907
	'mss',
1908
	'MSS',
1909
	'number',
1910
	$pconfig['mss']
1911
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1912
			'header size) will be in effect.');
1913

    
1914
if (count($mediaopts_list) > 0) {
1915
	$section->addInput(new Form_Select(
1916
		'mediaopt',
1917
		'Speed and Duplex',
1918
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1919
		build_mediaopts_list()
1920
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1921
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1922
}
1923

    
1924
$form->add($section);
1925

    
1926
$section = new Form_Section('Static IPv4 Configuration');
1927
$section->addClass('staticv4');
1928

    
1929
$section->addInput(new Form_IpAddress(
1930
	'ipaddr',
1931
	'*IPv4 Address',
1932
	$pconfig['ipaddr'],
1933
	'V4'
1934
))->addMask('subnet', $pconfig['subnet'], 32);
1935

    
1936
$group = new Form_Group('IPv4 Upstream gateway');
1937

    
1938
$group->add(new Form_Select(
1939
	'gateway',
1940
	'IPv4 Upstream Gateway',
1941
	$pconfig['gateway'],
1942
	build_gateway_list()
1943
));
1944

    
1945
$group->add(new Form_Button(
1946
	'addgw4',
1947
	'Add a new gateway',
1948
	null,
1949
	'fa-plus'
1950
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1951

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

    
1956
$section->add($group);
1957

    
1958
$form->add($section);
1959

    
1960
$section = new Form_Section('Static IPv6 Configuration');
1961
$section->addClass('staticv6');
1962

    
1963
$section->addInput(new Form_IpAddress(
1964
	'ipaddrv6',
1965
	'*IPv6 address',
1966
	$pconfig['ipaddrv6'],
1967
	'V6'
1968
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1969

    
1970
$section->addInput(new Form_Checkbox(
1971
	'ipv6usev4iface',
1972
	'Use IPv4 connectivity as parent interface',
1973
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1974
	$pconfig['ipv6usev4iface']
1975
));
1976

    
1977
$group = new Form_Group('IPv6 Upstream gateway');
1978

    
1979
$group->add(new Form_Select(
1980
	'gatewayv6',
1981
	'IPv6 Upstream Gateway',
1982
	$pconfig['gatewayv6'],
1983
	build_gatewayv6_list()
1984
));
1985

    
1986
$group->add(new Form_Button(
1987
	'addgw6',
1988
	'Add a new gateway',
1989
	null,
1990
	'fa-plus'
1991
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1992

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

    
1996
$section->add($group);
1997
$form->add($section);
1998

    
1999
// Add new gateway modal pop-up for IPv6
2000
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2001

    
2002
$modal->addInput(new Form_Checkbox(
2003
	'defaultgw6',
2004
	'Default',
2005
	'Default gateway',
2006
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2007
));
2008

    
2009
$modal->addInput(new Form_Input(
2010
	'gatewayname6',
2011
	'Gateway name',
2012
	'text',
2013
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2014
));
2015

    
2016
$modal->addInput(new Form_IpAddress(
2017
	'gatewayip6',
2018
	'Gateway IPv6',
2019
	$gateway_settings6['gateway'],
2020
	'V6'
2021
));
2022

    
2023
$modal->addInput(new Form_Input(
2024
	'gatewaydescr6',
2025
	'Description',
2026
	'text',
2027
	$gateway_settings6['descr']
2028
));
2029

    
2030
$btnaddgw6 = new Form_Button(
2031
	'add6',
2032
	'Add',
2033
	null,
2034
	'fa-plus'
2035
);
2036

    
2037
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2038

    
2039
$btncnxgw6 = new Form_Button(
2040
	'cnx6',
2041
	'Cancel',
2042
	null,
2043
	'fa-undo'
2044
);
2045

    
2046
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2047

    
2048
$modal->addInput(new Form_StaticText(
2049
	null,
2050
	$btnaddgw6 . $btncnxgw6
2051
));
2052

    
2053
$form->add($modal);
2054

    
2055
// ==== DHCP client configuration =============================
2056

    
2057
$section = new Form_Section('DHCP Client Configuration');
2058
$section->addClass('dhcp');
2059

    
2060
$group = new Form_Group('Options');
2061

    
2062
$group->add(new Form_Checkbox(
2063
	'adv_dhcp_config_advanced',
2064
	null,
2065
	'Advanced Configuration',
2066
	$pconfig['adv_dhcp_config_advanced']
2067
))->setHelp('Use advanced DHCP configuration options.');
2068

    
2069
$group->add(new Form_Checkbox(
2070
	'adv_dhcp_config_file_override',
2071
	null,
2072
	'Configuration Override',
2073
	$pconfig['adv_dhcp_config_file_override']
2074
))->setHelp('Override the configuration from this file.');
2075

    
2076
$section->add($group);
2077

    
2078
$section->addInput(new Form_Input(
2079
	'dhcphostname',
2080
	'Hostname',
2081
	'text',
2082
	$pconfig['dhcphostname']
2083
))->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).');
2084

    
2085
$section->addInput(new Form_IpAddress(
2086
	'alias-address',
2087
	'Alias IPv4 address',
2088
	$pconfig['alias-address'],
2089
	'V4'
2090
))->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.');
2091

    
2092
$section->addInput(new Form_Input(
2093
	'dhcprejectfrom',
2094
	'Reject leases from',
2095
	'text',
2096
	$pconfig['dhcprejectfrom']
2097
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2098
			'(separate multiple entries with a comma). ' .
2099
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2100

    
2101
if (interface_is_vlan($wancfg['if']) != NULL) {
2102

    
2103
	$group = new Form_Group('DHCP VLAN Priority');
2104
	$group->add(new Form_Checkbox(
2105
		'dhcpvlanenable',
2106
		null,
2107
		'Enable dhcpclient VLAN Priority tagging',
2108
		$pconfig['dhcpvlanenable']
2109
	))->setHelp('Normally off unless specifically required by the ISP.');
2110

    
2111
	$group->add(new Form_Select(
2112
		'dhcpcvpt',
2113
		'VLAN Prio',
2114
		$pconfig['dhcpcvpt'],
2115
		$vlanprio
2116
	))->setHelp('Choose 802.1p priority to set.');
2117

    
2118
	$section->add($group);
2119
}
2120

    
2121
$group = new Form_Group('Protocol timing');
2122
$group->addClass('dhcpadvanced');
2123

    
2124
$group->add(new Form_Input(
2125
	'adv_dhcp_pt_timeout',
2126
	null,
2127
	'number',
2128
	$pconfig['adv_dhcp_pt_timeout']
2129
))->setHelp('Timeout');
2130

    
2131
$group->add(new Form_Input(
2132
	'adv_dhcp_pt_retry',
2133
	null,
2134
	'number',
2135
	$pconfig['adv_dhcp_pt_retry']
2136
))->setHelp('Retry');
2137

    
2138
$group->add(new Form_Input(
2139
	'adv_dhcp_pt_select_timeout',
2140
	null,
2141
	'number',
2142
	$pconfig['adv_dhcp_pt_select_timeout'],
2143
	['min' => 0]
2144
))->setHelp('Select timeout');
2145

    
2146
$group->add(new Form_Input(
2147
	'adv_dhcp_pt_reboot',
2148
	null,
2149
	'number',
2150
	$pconfig['adv_dhcp_pt_reboot']
2151
))->setHelp('Reboot');
2152

    
2153
$group->add(new Form_Input(
2154
	'adv_dhcp_pt_backoff_cutoff',
2155
	null,
2156
	'number',
2157
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2158
))->setHelp('Backoff cutoff');
2159

    
2160
$group->add(new Form_Input(
2161
	'adv_dhcp_pt_initial_interval',
2162
	null,
2163
	'number',
2164
	$pconfig['adv_dhcp_pt_initial_interval']
2165
))->setHelp('Initial interval');
2166

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

    
2169
$group = new Form_Group('Presets');
2170
$group->addClass('dhcpadvanced');
2171

    
2172
$group->add(new Form_Checkbox(
2173
	'adv_dhcp_pt_values',
2174
	null,
2175
	'FreeBSD default',
2176
	null,
2177
	'DHCP'
2178
))->displayAsRadio();
2179

    
2180
$group->add(new Form_Checkbox(
2181
	'adv_dhcp_pt_values',
2182
	null,
2183
	'Clear',
2184
	null,
2185
	'Clear'
2186
))->displayAsRadio();
2187

    
2188
$group->add(new Form_Checkbox(
2189
	'adv_dhcp_pt_values',
2190
	null,
2191
	'pfSense Default',
2192
	null,
2193
	'pfSense'
2194
))->displayAsRadio();
2195

    
2196
$group->add(new Form_Checkbox(
2197
	'adv_dhcp_pt_values',
2198
	null,
2199
	'Saved Cfg',
2200
	null,
2201
	'SavedCfg'
2202
))->displayAsRadio();
2203

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

    
2207
$section->add($group);
2208

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

    
2219
$form->add($section);
2220

    
2221
$section = new Form_Section('Lease Requirements and Requests');
2222
$section->addClass('dhcpadvanced');
2223

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

    
2234
$section->addInput(new Form_Input(
2235
	'adv_dhcp_request_options',
2236
	'Request options',
2237
	'text',
2238
	$pconfig['adv_dhcp_request_options']
2239
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2240
			'Some ISPs may require certain options be or not be requested.', '<br />');
2241

    
2242
$section->addInput(new Form_Input(
2243
	'adv_dhcp_required_options',
2244
	'Require options',
2245
	'text',
2246
	$pconfig['adv_dhcp_required_options']
2247
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2248

    
2249
$section->addInput(new Form_Input(
2250
	'adv_dhcp_option_modifiers',
2251
	'Option modifiers',
2252
	'text',
2253
	$pconfig['adv_dhcp_option_modifiers']
2254
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2255
			'modifiers: (default, supersede, prepend, append) %1$s' .
2256
			'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>');
2257

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

    
2260
// DHCP6 client config
2261

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

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

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

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

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

    
2283
$section->addInput(new Form_Checkbox(
2284
	'dhcp6usev4iface',
2285
	'Use IPv4 connectivity as parent interface',
2286
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2287
	$pconfig['dhcp6usev4iface']
2288
));
2289

    
2290
$section->addInput(new Form_Checkbox(
2291
	'dhcp6prefixonly',
2292
	'Request only an IPv6 prefix',
2293
	'Only request an IPv6 prefix, do not request an IPv6 address',
2294
	$pconfig['dhcp6prefixonly']
2295
));
2296

    
2297
$section->addInput(new Form_Select(
2298
	'dhcp6-ia-pd-len',
2299
	'DHCPv6 Prefix Delegation size',
2300
	$pconfig['dhcp6-ia-pd-len'],
2301
	array("none" => "None", 16 => "48", 12 => "52", 8 => "56", 5 => "59", 4 => "60", 3 => "61",  2 => "62", 1 => "63", 0 => "64")
2302
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2303

    
2304
$section->addInput(new Form_Checkbox(
2305
	'dhcp6-ia-pd-send-hint',
2306
	'Send IPv6 prefix hint',
2307
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2308
	$pconfig['dhcp6-ia-pd-send-hint']
2309
));
2310

    
2311
$section->addInput(new Form_Checkbox(
2312
	'dhcp6debug',
2313
	'Debug',
2314
	'Start DHCP6 client in debug mode',
2315
	$pconfig['dhcp6debug']
2316
));
2317
$section->addInput(new Form_Checkbox(
2318
	'dhcp6withoutra',
2319
	'Do not wait for a RA',
2320
	'Required by some ISPs, especially those not using PPPoE',
2321
	$pconfig['dhcp6withoutra']
2322
));
2323
$section->addInput(new Form_Checkbox(
2324
	'dhcp6norelease',
2325
	'Do not allow PD/Address release',
2326
	'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',
2327
	$pconfig['dhcp6norelease']
2328
));
2329

    
2330
if (interface_is_vlan($wancfg['if']) != NULL) {
2331
	$group = new Form_Group('DHCP6 VLAN Priority');
2332

    
2333
	$group->add(new Form_Checkbox(
2334
		'dhcp6vlanenable',
2335
		null,
2336
		'Enable dhcp6c VLAN Priority tagging',
2337
		$pconfig['dhcp6vlanenable']
2338
	))->setHelp('Normally off unless specifically required by the ISP.');
2339

    
2340
	$group->add(new Form_Select(
2341
		'dhcp6cvpt',
2342
		'VLAN Prio',
2343
		$pconfig['dhcp6cvpt'],
2344
		$vlanprio
2345
	))->setHelp('Choose 802.1p priority to set.');
2346

    
2347
	$section->add($group);
2348
}
2349

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

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

    
2362
// DHCP6 client config - Advanced
2363

    
2364
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2365
$section->addClass('dhcp6advanced');
2366

    
2367
$section->addInput(new Form_Checkbox(
2368
	'adv_dhcp6_interface_statement_information_only_enable',
2369
	'Information only',
2370
	'Exchange Information Only',
2371
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2372
	'Selected'
2373
))->setHelp('Only exchange informational configuration parameters with servers.');
2374

    
2375
$section->addInput(new Form_Input(
2376
	'adv_dhcp6_interface_statement_send_options',
2377
	'Send options',
2378
	'text',
2379
	$pconfig['adv_dhcp6_interface_statement_send_options']
2380
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2381
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2382
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2383
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2384

    
2385
$section->addInput(new Form_Input(
2386
	'adv_dhcp6_interface_statement_request_options',
2387
	'Request Options',
2388
	'text',
2389
	$pconfig['adv_dhcp6_interface_statement_request_options']
2390
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2391
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2392

    
2393
$section->addInput(new Form_Input(
2394
	'adv_dhcp6_interface_statement_script',
2395
	'Scripts',
2396
	'text',
2397
	$pconfig['adv_dhcp6_interface_statement_script']
2398
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2399
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2400

    
2401
$group = new Form_Group('Identity Association Statement');
2402

    
2403
$group->add(new Form_Checkbox(
2404
	'adv_dhcp6_id_assoc_statement_address_enable',
2405
	null,
2406
	'Non-Temporary Address Allocation',
2407
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2408
	'Selected'
2409
));
2410

    
2411
$group->add(new Form_Input(
2412
	'adv_dhcp6_id_assoc_statement_address_id',
2413
	null,
2414
	'text',
2415
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2416
))->sethelp('id-assoc na ID');
2417

    
2418
$group->add(new Form_IpAddress(
2419
	'adv_dhcp6_id_assoc_statement_address',
2420
	null,
2421
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2422
	'V6'
2423
))->sethelp('IPv6 address');
2424

    
2425
$group->add(new Form_Input(
2426
	'adv_dhcp6_id_assoc_statement_address_pltime',
2427
	null,
2428
	'text',
2429
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2430
))->sethelp('pltime');
2431

    
2432
$group->add(new Form_Input(
2433
	'adv_dhcp6_id_assoc_statement_address_vltime',
2434
	null,
2435
	'text',
2436
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2437
))->sethelp('vltime');
2438

    
2439
$section->add($group);
2440

    
2441
// Prefix delegation
2442
$group = new Form_Group('');
2443

    
2444
$group->add(new Form_Checkbox(
2445
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2446
	null,
2447
	'Prefix Delegation ',
2448
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2449
	'Selected'
2450
));
2451

    
2452
$group->add(new Form_Input(
2453
	'adv_dhcp6_id_assoc_statement_prefix_id',
2454
	null,
2455
	'text',
2456
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2457
))->sethelp('id-assoc pd ID');
2458

    
2459
$group->add(new Form_IpAddress(
2460
	'adv_dhcp6_id_assoc_statement_prefix',
2461
	null,
2462
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2463
	'V6'
2464
))->sethelp('IPv6 prefix');
2465

    
2466
$group->add(new Form_Input(
2467
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2468
	null,
2469
	'text',
2470
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2471
))->sethelp('pltime');
2472

    
2473
$group->add(new Form_Input(
2474
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2475
	null,
2476
	'text',
2477
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2478
))->sethelp('vltime');
2479

    
2480
$section->add($group);
2481

    
2482
$group = new Form_Group('Prefix interface statement');
2483

    
2484
$group->add(new Form_Input(
2485
	'adv_dhcp6_prefix_interface_statement_sla_id',
2486
	null,
2487
	'text',
2488
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2489
))->sethelp('Prefix Interface sla-id');
2490

    
2491
$group->add(new Form_Input(
2492
	'adv_dhcp6_prefix_interface_statement_sla_len',
2493
	null,
2494
	'text',
2495
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2496
))->sethelp('sla-len');
2497

    
2498
$section->add($group);
2499

    
2500
$group = new Form_Group('Select prefix interface');
2501
$section->addInput(new Form_Select(
2502
	'adv_dhcp6_prefix_selected_interface',
2503
	'Prefix Interface',
2504
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2505
	$interfaces
2506
))->setHelp('Select the interface on which to apply the prefix delegation.');
2507

    
2508
$group = new Form_Group('Authentication statement');
2509

    
2510
$group->add(new Form_Input(
2511
	'adv_dhcp6_authentication_statement_authname',
2512
	null,
2513
	'text',
2514
	$pconfig['adv_dhcp6_authentication_statement_authname']
2515
))->sethelp('Authname');
2516

    
2517
$group->add(new Form_Input(
2518
	'adv_dhcp6_authentication_statement_protocol',
2519
	null,
2520
	'text',
2521
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2522
))->sethelp('Protocol');
2523

    
2524
$group->add(new Form_Input(
2525
	'adv_dhcp6_authentication_statement_algorithm',
2526
	null,
2527
	'text',
2528
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2529
))->sethelp('Algorithm');
2530

    
2531
$group->add(new Form_Input(
2532
	'adv_dhcp6_authentication_statement_rdm',
2533
	null,
2534
	'text',
2535
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2536
))->sethelp('RDM');
2537

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

    
2540
$group = new Form_Group('Keyinfo statement');
2541

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

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

    
2556
$section->add($group);
2557

    
2558
$group = new Form_Group('');
2559

    
2560
$group->add(new Form_Input(
2561
	'adv_dhcp6_key_info_statement_keyid',
2562
	null,
2563
	'text',
2564
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2565
))->sethelp('KeyID');
2566

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

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

    
2581
$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>');
2582

    
2583
$section->add($group);
2584

    
2585
$form->add($section);
2586

    
2587
$section = new Form_Section('6RD Configuration');
2588
$section->addClass('_6rd');
2589

    
2590
$section->addInput(new Form_Input(
2591
	'prefix-6rd',
2592
	'6RD Prefix',
2593
	'text',
2594
	$pconfig['prefix-6rd']
2595
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2596

    
2597
$section->addInput(new Form_Input(
2598
	'gateway-6rd',
2599
	'*6RD Border relay',
2600
	'text',
2601
	$pconfig['gateway-6rd']
2602
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2603

    
2604
$section->addInput(new Form_Select(
2605
	'prefix-6rd-v4plen',
2606
	'6RD IPv4 Prefix length',
2607
	$pconfig['prefix-6rd-v4plen'],
2608
	array_combine(range(0, 32), range(0, 32))
2609
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2610

    
2611
$form->add($section);
2612

    
2613
// Track IPv6 ointerface section
2614
$section = new Form_Section('Track IPv6 Interface');
2615
$section->addClass('track6');
2616

    
2617
function build_ipv6interface_list() {
2618
	global $config, $section;
2619

    
2620
	$list = array('' => '');
2621

    
2622
	$interfaces = get_configured_interface_with_descr(true);
2623
	$dynv6ifs = array();
2624

    
2625
	foreach ($interfaces as $iface => $ifacename) {
2626
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2627
			case "6to4":
2628
			case "6rd":
2629
			case "dhcp6":
2630
				$dynv6ifs[$iface] = array(
2631
					'name' => $ifacename,
2632
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2633
				);
2634
				break;
2635
			default:
2636
				continue;
2637
		}
2638
	}
2639

    
2640
	foreach ($dynv6ifs as $iface => $ifacedata) {
2641
		$list[$iface] = $ifacedata['name'];
2642

    
2643
		$section->addInput(new Form_Input(
2644
			'ipv6-num-prefix-ids-' . $iface,
2645
			null,
2646
			'hidden',
2647
			$ifacedata['ipv6_num_prefix_ids']
2648
		));
2649
	}
2650

    
2651
	return($list);
2652
}
2653

    
2654
$section->addInput(new Form_Select(
2655
	'track6-interface',
2656
	'*IPv6 Interface',
2657
	$pconfig['track6-interface'],
2658
	build_ipv6interface_list()
2659
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2660

    
2661
if ($pconfig['track6-prefix-id'] == "") {
2662
	$pconfig['track6-prefix-id'] = 0;
2663
}
2664

    
2665
$section->addInput(new Form_Input(
2666
	'track6-prefix-id--hex',
2667
	'IPv6 Prefix ID',
2668
	'text',
2669
	sprintf("%x", $pconfig['track6-prefix-id'])
2670
))->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>');
2671

    
2672
$section->addInput(new Form_Input(
2673
	'track6-prefix-id-max',
2674
	null,
2675
	'hidden',
2676
	0
2677
));
2678

    
2679
$form->add($section);
2680

    
2681
/// PPP section
2682

    
2683
$section = new Form_Section('PPP Configuration');
2684
$section->addClass('ppp');
2685

    
2686
$section->addInput(new Form_Select(
2687
	'country',
2688
	'Country',
2689
	$pconfig['country'],
2690
	[]
2691
));
2692

    
2693
$section->addInput(new Form_Select(
2694
	'provider_list',
2695
	'Provider',
2696
	$pconfig['provider_list'],
2697
	[]
2698
));
2699

    
2700
$section->addInput(new Form_Select(
2701
	'providerplan',
2702
	'Plan',
2703
	$pconfig['providerplan'],
2704
	[]
2705
))->setHelp('Select to fill in service provider data.');
2706

    
2707
$section->addInput(new Form_Input(
2708
	'ppp_username',
2709
	'Username',
2710
	'text',
2711
	$pconfig['ppp_username']
2712
));
2713

    
2714
$section->addPassword(new Form_Input(
2715
	'ppp_password',
2716
	'Password',
2717
	'password',
2718
	$pconfig['ppp_password']
2719
));
2720

    
2721
$section->addInput(new Form_Input(
2722
	'phone',
2723
	'*Phone number',
2724
	'text',
2725
	$pconfig['phone']
2726
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2727

    
2728
$section->addInput(new Form_Input(
2729
	'apn',
2730
	'Access Point Name',
2731
	'text',
2732
	$pconfig['apn']
2733
));
2734

    
2735

    
2736
function build_port_list() {
2737
	$list = array("" => "None");
2738

    
2739
	$portlist = glob("/dev/cua*");
2740
	$modems	  = glob("/dev/modem*");
2741
	$portlist = array_merge($portlist, $modems);
2742

    
2743
	foreach ($portlist as $port) {
2744
		if (preg_match("/\.(lock|init)$/", $port)) {
2745
			continue;
2746
		}
2747

    
2748
	$list[trim($port)] = $port;
2749
	}
2750

    
2751
	return($list);
2752
}
2753

    
2754
$section->addInput(new Form_Select(
2755
	'port',
2756
	"*Modem port",
2757
	$pconfig['port'],
2758
	build_port_list()
2759
));
2760

    
2761
$section->addInput(new Form_Button(
2762
	'btnadvppp',
2763
	'Advanced PPP',
2764
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2765
	'fa-cog'
2766
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2767

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

    
2770
// PPPoE configuration
2771
$section = new Form_Section('PPPoE Configuration');
2772
$section->addClass('pppoe');
2773

    
2774
$section->addInput(new Form_Input(
2775
	'pppoe_username',
2776
	'*Username',
2777
	'text',
2778
	$pconfig['pppoe_username']
2779
));
2780

    
2781
$section->addPassword(new Form_Input(
2782
	'pppoe_password',
2783
	'*Password',
2784
	'password',
2785
	$pconfig['pppoe_password']
2786
));
2787

    
2788
$section->addInput(new Form_Input(
2789
	'provider',
2790
	'Service name',
2791
	'text',
2792
	$pconfig['provider']
2793
))->setHelp('This field can usually be left empty.');
2794

    
2795
$section->addInput(new Form_Checkbox(
2796
	'pppoe_dialondemand',
2797
	'Dial on demand',
2798
	'Enable Dial-On-Demand mode ',
2799
	$pconfig['pppoe_dialondemand'],
2800
	'enable'
2801
));
2802

    
2803
$section->addInput(new Form_Input(
2804
	'pppoe_idletimeout',
2805
	'Idle timeout',
2806
	'number',
2807
	$pconfig['pppoe_idletimeout'],
2808
	['min' => 0]
2809
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2810
			'An idle timeout of zero disables this feature.');
2811

    
2812
$section->addInput(new Form_Select(
2813
	'pppoe-reset-type',
2814
	'Periodic reset',
2815
	$pconfig['pppoe-reset-type'],
2816
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2817
))->setHelp('Select a reset timing type.');
2818

    
2819
$group = new Form_Group('Custom reset');
2820
$group->addClass('pppoecustom');
2821

    
2822
$group->add(new Form_Input(
2823
	'pppoe_resethour',
2824
	null,
2825
	'number',
2826
	$pconfig['pppoe_resethour'],
2827
	['min' => 0, 'max' => 23]
2828
))->setHelp('Hour (0-23)');
2829

    
2830
$group->add(new Form_Input(
2831
	'pppoe_resetminute',
2832
	null,
2833
	'number',
2834
	$pconfig['pppoe_resetminute'],
2835
	['min' => 0, 'max' => 59]
2836
))->setHelp('Minutes (0-59)');
2837

    
2838
$group->add(new Form_Input(
2839
	'pppoe_resetdate',
2840
	null,
2841
	'text',
2842
	$pconfig['pppoe_resetdate']
2843
))->setHelp('Specific date (mm/dd/yyyy)');
2844

    
2845
$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');
2846

    
2847
$section->add($group);
2848

    
2849
$group = new Form_MultiCheckboxGroup('cron based reset');
2850
$group->addClass('pppoepreset');
2851

    
2852
$group->add(new Form_MultiCheckbox(
2853
	'pppoe_pr_preset_val',
2854
	null,
2855
	'Reset at each month ("0 0 1 * *")',
2856
	$pconfig['pppoe_monthly'],
2857
	'monthly'
2858
))->displayAsRadio();
2859

    
2860
$group->add(new Form_MultiCheckbox(
2861
	'pppoe_pr_preset_val',
2862
	null,
2863
	'Reset at each week ("0 0 * * 0")',
2864
	$pconfig['pppoe_weekly'],
2865
	'weekly'
2866
))->displayAsRadio();
2867

    
2868
$group->add(new Form_MultiCheckbox(
2869
	'pppoe_pr_preset_val',
2870
	null,
2871
	'Reset at each day ("0 0 * * *")',
2872
	$pconfig['pppoe_daily'],
2873
	'daily'
2874
))->displayAsRadio();
2875

    
2876
$group->add(new Form_MultiCheckbox(
2877
	'pppoe_pr_preset_val',
2878
	null,
2879
	'Reset at each hour ("0 * * * *")',
2880
	$pconfig['pppoe_hourly'],
2881
	'hourly'
2882
))->displayAsRadio();
2883

    
2884
$section->add($group);
2885

    
2886
$section->addInput(new Form_Button(
2887
	'btnadvppp',
2888
	'Advanced and MLPPP',
2889
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2890
	'fa-cog'
2891
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2892

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

    
2895
// PPTP & L2TP Configuration section
2896
$section = new Form_Section('PPTP/L2TP Configuration');
2897
$section->addClass('pptp');
2898

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

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

    
2913
$section->addInput(new Form_IpAddress(
2914
	'pptp_local0',
2915
	'*Local IP address',
2916
	$pconfig['pptp_localip'][0],
2917
	'V4'
2918
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2919

    
2920
$section->addInput(new Form_IpAddress(
2921
	'pptp_remote0',
2922
	'*Remote IP address',
2923
	$pconfig['pptp_remote'][0],
2924
	'HOSTV4'
2925
));
2926

    
2927
$section->addInput(new Form_Checkbox(
2928
	'pptp_dialondemand',
2929
	'Dial on demand',
2930
	'Enable Dial-On-Demand mode ',
2931
	$pconfig['pptp_dialondemand'],
2932
	'enable'
2933
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2934
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2935

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

    
2945
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2946
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2947
} else {
2948
	$mlppp_text = "";
2949
}
2950

    
2951
$section->addInput(new Form_Button(
2952
	'btnadvppp',
2953
	'Advanced and MLPPP',
2954
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2955
	'fa-cog'
2956
))->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);
2957

    
2958
$form->add($section);
2959

    
2960
// Wireless interface
2961
if (isset($wancfg['wireless'])) {
2962

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

    
2965
	$section->addInput(new Form_Checkbox(
2966
		'persistcommonwireless',
2967
		'Persist common settings',
2968
		'Preserve common wireless configuration through interface deletions and reassignments.',
2969
		$pconfig['persistcommonwireless'],
2970
		'yes'
2971
	));
2972

    
2973
	$mode_list = ['auto' => 'Auto'];
2974

    
2975
	if (is_array($wl_modes)) {
2976
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2977
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2978
		}
2979
	}
2980

    
2981
	if (count($mode_list) == 1) {
2982
		$mode_list[''] = '';
2983
	}
2984

    
2985
	$section->addInput(new Form_Select(
2986
		'standard',
2987
		'Standard',
2988
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2989
		$mode_list
2990
	));
2991

    
2992
	if (isset($wl_modes['11g'])) {
2993
		$section->addInput(new Form_Select(
2994
			'protmode',
2995
			'802.11g OFDM Protection Mode',
2996
			$pconfig['protmode'],
2997
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2998
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2999
	} else {
3000
		$section->addInput(new Form_Input(
3001
			'protmode',
3002
			null,
3003
			'hidden',
3004
			'off'
3005
		));
3006
	}
3007

    
3008
	$mode_list = ['0' => gettext('Auto')];
3009

    
3010
	if (is_array($wl_modes)) {
3011
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3012
			if ($wl_standard == "11g") {
3013
				$wl_standard = "11b/g";
3014
			} else if ($wl_standard == "11ng") {
3015
				$wl_standard = "11b/g/n";
3016
			} else if ($wl_standard == "11na") {
3017
				$wl_standard = "11a/n";
3018
			}
3019

    
3020
			foreach ($wl_channels as $wl_channel) {
3021
				if (isset($wl_chaninfo[$wl_channel])) {
3022
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
3023
				} else {
3024
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3025
				}
3026
			}
3027
		}
3028
	}
3029

    
3030
	$section->addInput(new Form_Select(
3031
		'channel',
3032
		'Channel',
3033
		$pconfig['channel'],
3034
		$mode_list
3035
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3036
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3037

    
3038
	if (ANTENNAS) {
3039
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3040
			$group = new Form_Group('Antenna Settings');
3041

    
3042
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3043
				$group->add(new Form_Select(
3044
					'diversity',
3045
					null,
3046
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3047
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3048
				))->setHelp('Diversity');
3049
			}
3050

    
3051
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3052
				$group->add(new Form_Select(
3053
					'txantenna',
3054
					null,
3055
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3056
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3057
				))->setHelp('Transmit antenna');
3058
			}
3059

    
3060
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3061
				$group->add(new Form_Select(
3062
					'rxantenna',
3063
					null,
3064
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3065
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3066
				))->setHelp('Receive antenna');
3067
			}
3068

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

    
3071
			$section->add($group);
3072
		}
3073
	}
3074

    
3075
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3076
			$section->addInput(new Form_Input(
3077
				'distance',
3078
				'Distance setting (meters)',
3079
				'test',
3080
				$pconfig['distance']
3081
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3082
	}
3083

    
3084
	$form->add($section);
3085

    
3086
	// Regulatory settings
3087
	$section = new Form_Section('Regulatory Settings');
3088

    
3089
	$domain_list = array("" => 'Default');
3090

    
3091
	if (is_array($wl_regdomains)) {
3092
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3093
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3094
		}
3095
	}
3096

    
3097
	$section->addInput(new Form_Select(
3098
		'regdomain',
3099
		'Regulatory domain',
3100
		$pconfig['regdomain'],
3101
		$domain_list
3102
	))->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');
3103

    
3104
	$country_list = array('' => 'Default');
3105

    
3106
	if (is_array($wl_countries)) {
3107
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3108
			$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']);
3109
		}
3110
	}
3111

    
3112
	$section->addInput(new Form_Select(
3113
		'regcountry',
3114
		'Country',
3115
		$pconfig['regcountry'],
3116
		$country_list
3117
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3118

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

    
3130
	$form->add($section);
3131

    
3132
	$section = new Form_Section('Network-Specific Wireless Configuration');
3133

    
3134
	$section->addInput(new Form_Select(
3135
		'mode',
3136
		'Mode',
3137
		$pconfig['mode'],
3138
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3139
	));
3140

    
3141
	$section->addInput(new Form_Input(
3142
		'ssid',
3143
		'SSID',
3144
		'text',
3145
		$pconfig['ssid']
3146
	));
3147

    
3148
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3149
		$section->addInput(new Form_Select(
3150
			'puremode',
3151
			'Minimum wireless standard',
3152
			$pconfig['puremode'],
3153
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3154
		))->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)');
3155
	} elseif (isset($wl_modes['11g'])) {
3156
		$section->addInput(new Form_Checkbox(
3157
			'puremode',
3158
			'802.11g only',
3159
			null,
3160
			$pconfig['puremode'],
3161
			'11g'
3162
		))->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)');
3163
	}
3164

    
3165
	$section->addInput(new Form_Checkbox(
3166
		'apbridge_enable',
3167
		'Allow intra-BSS communication',
3168
		'Allow packets to pass between wireless clients directly when operating as an access point',
3169
		$pconfig['apbridge_enable'],
3170
		'yes'
3171
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3172

    
3173
	$section->addInput(new Form_Checkbox(
3174
		'wme_enable',
3175
		'Enable WME',
3176
		'Force the card to use WME (wireless QoS)',
3177
		$pconfig['wme_enable'],
3178
		'yes'
3179
	));
3180

    
3181
	$section->addInput(new Form_Checkbox(
3182
		'hidessid_enable',
3183
		'Hide SSID',
3184
		'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.)',
3185
		$pconfig['hidessid_enable'],
3186
		'yes'
3187
	));
3188

    
3189
	$form->add($section);
3190

    
3191
	// WPA Section
3192
	$section = new Form_Section('WPA');
3193

    
3194
	$section->addInput(new Form_Checkbox(
3195
		'wpa_enable',
3196
		'Enable',
3197
		'Enable WPA',
3198
		$pconfig['wpa_enable'],
3199
		'yes'
3200
	));
3201

    
3202
	$section->addInput(new Form_Input(
3203
		'passphrase',
3204
		'WPA Pre-Shared Key',
3205
		'text',
3206
		$pconfig['passphrase']
3207
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3208

    
3209
	$section->addInput(new Form_Select(
3210
		'wpa_mode',
3211
		'WPA mode',
3212
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3213
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3214
	));
3215

    
3216
	$section->addInput(new Form_Select(
3217
		'wpa_key_mgmt',
3218
		'WPA Key Management Mode',
3219
		$pconfig['wpa_key_mgmt'],
3220
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3221
	));
3222

    
3223
	$section->addInput(new Form_Select(
3224
		'wpa_pairwise',
3225
		'WPA Pairwise',
3226
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3227
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3228
	));
3229

    
3230
	$section->addInput(new Form_Input(
3231
		'wpa_group_rekey',
3232
		'Group Key Rotation',
3233
		'number',
3234
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3235
		['min' => '1', 'max' => 9999]
3236
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3237

    
3238
	$section->addInput(new Form_Input(
3239
		'wpa_gmk_rekey',
3240
		'Group Master Key Regeneration',
3241
		'number',
3242
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3243
		['min' => '1', 'max' => 9999]
3244
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3245

    
3246
	$section->addInput(new Form_Checkbox(
3247
		'wpa_strict_rekey',
3248
		'Strict Key Regeneration',
3249
		'Force the AP to rekey whenever a client disassociates',
3250
		$pconfig['wpa_strict_rekey'],
3251
		'yes'
3252
	));
3253

    
3254
	$form->add($section);
3255

    
3256
	$section = new Form_Section('802.1x RADIUS Options');
3257

    
3258
	$section->addInput(new Form_Checkbox(
3259
		'ieee8021x',
3260
		'IEEE802.1X',
3261
		'Enable 802.1X authentication',
3262
		$pconfig['ieee8021x'],
3263
		'yes'
3264
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3265

    
3266
	$group = new Form_Group('Primary 802.1X server');
3267

    
3268
	$group->add(new Form_IpAddress(
3269
		'auth_server_addr',
3270
		'IP Address',
3271
		$pconfig['auth_server_addr']
3272
	))->setHelp('IP address of the RADIUS server');
3273

    
3274
	$group->add(new Form_Input(
3275
		'auth_server_port',
3276
		'Port',
3277
		'number',
3278
		$pconfig['auth_server_port']
3279
	))->setHelp('Server auth port. Default is 1812');
3280

    
3281
	$group->add(new Form_Input(
3282
		'auth_server_shared_secret',
3283
		'Shared Secret',
3284
		'text',
3285
		$pconfig['auth_server_shared_secret']
3286
	))->setHelp('RADIUS Shared secret for this firewall');
3287

    
3288
	$section->add($group);
3289

    
3290
	$group = new Form_Group('Secondary 802.1X server');
3291

    
3292
	$group->add(new Form_IpAddress(
3293
		'auth_server_addr2',
3294
		'IP Address',
3295
		$pconfig['auth_server_addr2']
3296
	))->setHelp('IP address of the RADIUS server');
3297

    
3298
	$group->add(new Form_Input(
3299
		'auth_server_port2',
3300
		'Port',
3301
		'number',
3302
		$pconfig['auth_server_port2']
3303
	))->setHelp('Server auth port. Default is 1812');
3304

    
3305
	$group->add(new Form_Input(
3306
		'auth_server_shared_secret2',
3307
		'Shared Secret',
3308
		'text',
3309
		$pconfig['auth_server_shared_secret2']
3310
	))->setHelp('RADIUS Shared secret for this firewall');
3311

    
3312
	$section->add($group);
3313

    
3314
	$section->addInput(new Form_Checkbox(
3315
		'rsn_preauth',
3316
		'Authentication Roaming Preauth',
3317
		null,
3318
		$pconfig['rsn_preauth'],
3319
		'yes'
3320
	));
3321

    
3322
	$form->add($section);
3323
}
3324

    
3325
$section = new Form_Section('Reserved Networks');
3326

    
3327
$section->addInput(new Form_Checkbox(
3328
	'blockpriv',
3329
	'Block private networks and loopback addresses',
3330
	'',
3331
	$pconfig['blockpriv'],
3332
	'yes'
3333
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3334
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3335
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3336

    
3337
$section->addInput(new Form_Checkbox(
3338
	'blockbogons',
3339
	'Block bogon networks',
3340
	'',
3341
	$pconfig['blockbogons'],
3342
	'yes'
3343
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3344
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3345
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3346

    
3347
$form->add($section);
3348

    
3349
$form->addGlobal(new Form_Input(
3350
	'if',
3351
	null,
3352
	'hidden',
3353
	$if
3354
));
3355

    
3356
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3357
	$form->addGlobal(new Form_Input(
3358
		'ppp_port',
3359
		null,
3360
		'hidden',
3361
		$pconfig['port']
3362
	));
3363
}
3364

    
3365
$form->addGlobal(new Form_Input(
3366
	'ptpid',
3367
	null,
3368
	'hidden',
3369
	$pconfig['ptpid']
3370
));
3371

    
3372

    
3373
// Add new gateway modal pop-up
3374
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3375

    
3376
$modal->addInput(new Form_Checkbox(
3377
	'defaultgw4',
3378
	'Default',
3379
	'Default gateway',
3380
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3381
));
3382

    
3383
$modal->addInput(new Form_Input(
3384
	'gatewayname4',
3385
	'Gateway name',
3386
	'text',
3387
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3388
));
3389

    
3390
$modal->addInput(new Form_IpAddress(
3391
	'gatewayip4',
3392
	'Gateway IPv4',
3393
	$gateway_settings4['gateway'],
3394
	'V4'
3395
));
3396

    
3397
$modal->addInput(new Form_Input(
3398
	'gatewaydescr4',
3399
	'Description',
3400
	'text',
3401
	$gateway_settings4['descr']
3402
));
3403

    
3404
$btnaddgw4 = new Form_Button(
3405
	'add4',
3406
	'Add',
3407
	null,
3408
	'fa-plus'
3409
);
3410

    
3411
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3412

    
3413
$btncnxgw4 = new Form_Button(
3414
	'cnx4',
3415
	'Cancel',
3416
	null,
3417
	'fa-undo'
3418
);
3419

    
3420
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3421

    
3422
$modal->addInput(new Form_StaticText(
3423
	null,
3424
	$btnaddgw4 . $btncnxgw4
3425
));
3426

    
3427
$form->add($modal);
3428

    
3429
print($form);
3430
?>
3431

    
3432
<script type="text/javascript">
3433
//<![CDATA[
3434
events.push(function() {
3435
	function updateType(t) {
3436

    
3437
		switch (t) {
3438
			case "none": {
3439
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3440
				break;
3441
			}
3442
			case "staticv4": {
3443
				$('.dhcpadvanced, .none, .dhcp').hide();
3444
				$('.pppoe, .pptp, .ppp').hide();
3445
				break;
3446
			}
3447
			case "dhcp": {
3448
				$('.dhcpadvanced, .none').hide();
3449
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3450
										//			about the staticv4 class
3451
				$('.pppoe, .pptp, .ppp').hide();
3452
				break;
3453
			}
3454
			case "ppp": {
3455
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3456
				country_list();
3457
				break;
3458
			}
3459
			case "pppoe": {
3460
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3461
				break;
3462
			}
3463
			case "l2tp":
3464
			case "pptp": {
3465
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3466
				$('.pptp').show();
3467
				break;
3468
			}
3469
		}
3470

    
3471
		if (t != "l2tp" && t != "pptp") {
3472
			$('.'+t).show();
3473
		}
3474
	}
3475

    
3476
	function updateTypeSix(t) {
3477
		if (!isNaN(t[0])) {
3478
			t = '_' + t;
3479
		}
3480

    
3481
		switch (t) {
3482
			case "none": {
3483
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3484
				break;
3485
			}
3486
			case "staticv6": {
3487
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3488
				break;
3489
			}
3490
			case "slaac": {
3491
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3492
				break;
3493
			}
3494
			case "dhcp6": {
3495
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3496
				break;
3497
			}
3498
			case "_6rd": {
3499
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3500
				break;
3501
			}
3502
			case "_6to4": {
3503
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3504
				break;
3505
			}
3506
			case "track6": {
3507
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3508
				update_track6_prefix();
3509
				break;
3510
			}
3511
		}
3512

    
3513
		if (t != "l2tp" && t != "pptp") {
3514
			$('.'+t).show();
3515
		}
3516
	}
3517

    
3518
	function show_reset_settings(reset_type) {
3519
		if (reset_type == 'preset') {
3520
			$('.pppoepreset').show();
3521
			$('.pppoecustom').hide();
3522
		} else if (reset_type == 'custom') {
3523
			$('.pppoecustom').show();
3524
			$('.pppoepreset').hide();
3525
		} else {
3526
			$('.pppoecustom').hide();
3527
			$('.pppoepreset').hide();
3528
		}
3529
	}
3530

    
3531
	function update_track6_prefix() {
3532
		var iface = $("#track6-interface").val();
3533
		if (iface == null) {
3534
			return;
3535
		}
3536

    
3537
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3538
		if (track6_prefix_ids == null) {
3539
			return;
3540
		}
3541

    
3542
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3543
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3544
	}
3545

    
3546
	function addOption_v4() {
3547
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3548
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3549
	}
3550

    
3551
	function addOption_v6() {
3552
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3553
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3554
	}
3555

    
3556
	function addSelectboxOption(selectbox, text, value) {
3557
		var optn = document.createElement("OPTION");
3558
		optn.text = text;
3559
		optn.value = value;
3560
		selectbox.append(optn);
3561
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3562
	}
3563

    
3564
	function country_list() {
3565
		$('#country').children().remove();
3566
		$('#provider_list').children().remove();
3567
		$('#providerplan').children().remove();
3568
		$.ajax("getserviceproviders.php",{
3569
			success: function(response) {
3570

    
3571
				var responseTextArr = response.split("\n");
3572
				responseTextArr.sort();
3573

    
3574
				responseTextArr.forEach( function(value) {
3575
					country = value.split(":");
3576
					$('#country').append($('<option>', {
3577
						value: country[1],
3578
						text : country[0]
3579
					}));
3580
				});
3581
			}
3582
		});
3583
	}
3584

    
3585
	function providers_list() {
3586
		$('#provider_list').children().remove();
3587
		$('#providerplan').children().remove();
3588
		$.ajax("getserviceproviders.php",{
3589
			type: 'post',
3590
			data: {country : $('#country').val()},
3591
			success: function(response) {
3592
				var responseTextArr = response.split("\n");
3593
				responseTextArr.sort();
3594
				responseTextArr.forEach( function(value) {
3595
					$('#provider_list').append($('<option>', {
3596
							value: value,
3597
							text : value
3598
					}));
3599
				});
3600
			}
3601
		});
3602
	}
3603

    
3604
	function providerplan_list() {
3605
		$('#providerplan').children().remove();
3606
		$.ajax("getserviceproviders.php",{
3607
			type: 'post',
3608
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3609
			success: function(response) {
3610
				var responseTextArr = response.split("\n");
3611
				responseTextArr.sort();
3612

    
3613
				$('#providerplan').append($('<option>', {
3614
					value: '',
3615
					text : ''
3616
				}));
3617

    
3618
				responseTextArr.forEach( function(value) {
3619
					if (value != "") {
3620
						providerplan = value.split(":");
3621

    
3622
						$('#providerplan').append($('<option>', {
3623
							value: providerplan[1],
3624
							text : providerplan[0] + " - " + providerplan[1]
3625
						}));
3626
					}
3627
				});
3628
			}
3629
		});
3630
	}
3631

    
3632
	function prefill_provider() {
3633
		$.ajax("getserviceproviders.php",{
3634
			type: 'post',
3635
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3636
			success: function(data, textStatus, response) {
3637
				var xmldoc = response.responseXML;
3638
				var provider = xmldoc.getElementsByTagName('connection')[0];
3639
				$('#ppp_username').val('');
3640
				$('#ppp_password').val('');
3641
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3642
					$('#phone').val('#777');
3643
					$('#apn').val('');
3644
				} else {
3645
					$('#phone').val('*99#');
3646
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3647
				}
3648
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3649
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3650
				$('#ppp_username').val(ppp_username);
3651
				$('#ppp_password').val(ppp_password);
3652
			}
3653
		});
3654
	}
3655

    
3656
	function show_dhcp6adv() {
3657
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3658
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3659

    
3660
		hideCheckbox('dhcp6usev4iface', ovr);
3661
		hideCheckbox('dhcp6prefixonly', ovr);
3662
		hideInput('dhcp6-ia-pd-len', ovr);
3663
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3664
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3665

    
3666
		hideClass('dhcp6advanced', !adv || ovr);
3667
	}
3668

    
3669
	function setDHCPoptions() {
3670
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3671
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3672

    
3673
		if (ovr) {
3674
			hideInput('dhcphostname', true);
3675
			hideIpAddress('alias-address', true);
3676
			hideInput('dhcprejectfrom', true);
3677
			hideInput('adv_dhcp_config_file_override_path', false);
3678
			hideClass('dhcpadvanced', true);
3679
		} else {
3680
			hideInput('dhcphostname', false);
3681
			hideIpAddress('alias-address', false);
3682
			hideInput('dhcprejectfrom', false);
3683
			hideInput('adv_dhcp_config_file_override_path', true);
3684
			hideClass('dhcpadvanced', !adv);
3685
		}
3686
	}
3687

    
3688
	// DHCP preset actions
3689
	// Set presets from value of radio buttons
3690
	function setPresets(val) {
3691
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3692
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3693
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3694
		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']);?>");
3695
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3696
	}
3697

    
3698
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3699
		$('#adv_dhcp_pt_timeout').val(timeout);
3700
		$('#adv_dhcp_pt_retry').val(retry);
3701
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3702
		$('#adv_dhcp_pt_reboot').val(reboot);
3703
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3704
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3705
	}
3706

    
3707
	function setPPPoEDialOnDemandItems() {
3708
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3709
	}
3710

    
3711
	function setPPTPDialOnDemandItems() {
3712
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3713
	}
3714

    
3715
	// ---------- On initial page load ------------------------------------------------------------
3716

    
3717
	updateType($('#type').val());
3718
	updateTypeSix($('#type6').val());
3719
	show_reset_settings($('#pppoe-reset-type').val());
3720
	hideClass('dhcp6advanced', true);
3721
	hideClass('dhcpadvanced', true);
3722
	show_dhcp6adv();
3723
	setDHCPoptions();
3724
	setPPPoEDialOnDemandItems();
3725
	setPPTPDialOnDemandItems();
3726

    
3727
	// Set preset buttons on page load
3728
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3729
	if (sv == "") {
3730
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3731
	} else {
3732
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3733
	}
3734

    
3735
	// Set preset from value
3736
	setPresets(sv);
3737

    
3738
	// If the user wants to add a gateway, then add that to the gateway selection
3739
	if ($("#gatewayip4").val() != '') {
3740
		addOption_v4();
3741
	}
3742
	if ($("#gatewayip6").val() != '') {
3743
		addOption_v6();
3744
	}
3745

    
3746
	// ---------- Click checkbox handlers ---------------------------------------------------------
3747

    
3748
	$('#type').on('change', function() {
3749
		updateType(this.value);
3750
	});
3751

    
3752
	$('#type6').on('change', function() {
3753
		updateTypeSix(this.value);
3754
	});
3755

    
3756
	$('#track6-interface').on('change', function() {
3757
		update_track6_prefix();
3758
	});
3759

    
3760
	$('#pppoe-reset-type').on('change', function() {
3761
		show_reset_settings(this.value);
3762
	});
3763

    
3764
	$("#add4").click(function() {
3765
		addOption_v4();
3766
		$("#newgateway4").modal('hide');
3767
	});
3768

    
3769
	$("#cnx4").click(function() {
3770
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3771
		$("#gatewayip4").val('');
3772
		$("#gatewaydescr4").val('');
3773
		$("#defaultgw4").prop("checked", false);
3774
		$("#newgateway4").modal('hide');
3775
	});
3776

    
3777
	$("#add6").click(function() {
3778
		addOption_v6();
3779
		$("#newgateway6").modal('hide');
3780
	});
3781

    
3782
	$("#cnx6").click(function() {
3783
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3784
		$("#gatewayip6").val('');
3785
		$("#gatewaydescr6").val('');
3786
		$("#defaultgw6").prop("checked", false);
3787
		$("#newgateway6").modal('hide');
3788
	});
3789

    
3790
	$('#country').on('change', function() {
3791
		providers_list();
3792
	});
3793

    
3794
	$('#provider_list').on('change', function() {
3795
		providerplan_list();
3796
	});
3797

    
3798
	$('#providerplan').on('change', function() {
3799
		prefill_provider();
3800
	});
3801

    
3802
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3803
		setDHCPoptions();
3804
	});
3805

    
3806
	$('#adv_dhcp6_config_advanced').click(function () {
3807
		show_dhcp6adv();
3808
	});
3809

    
3810
	$('#adv_dhcp6_config_file_override').click(function () {
3811
		show_dhcp6adv();
3812
	});
3813

    
3814
	// On click . .
3815
	$('#pppoe_dialondemand').click(function () {
3816
		setPPPoEDialOnDemandItems();
3817
	});
3818

    
3819
	$('#pptp_dialondemand').click(function () {
3820
		setPPTPDialOnDemandItems();
3821
	});
3822

    
3823
	$('[name=adv_dhcp_pt_values]').click(function () {
3824
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3825
	});
3826

    
3827
	$('#pppoe_resetdate').datepicker();
3828

    
3829
});
3830
//]]>
3831
</script>
3832

    
3833
<?php include("foot.inc");
(71-71/234)