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

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

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

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

    
50
define("ANTENNAS", false);
51

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

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

    
61
$if = "wan";
62

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
208
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
209

    
210
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
211
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
212
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
213
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
214

    
215
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
216
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
217
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
218

    
219
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
220
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
221
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
222
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
223

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

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

    
236
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
237
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
238
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
239

    
240
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
241
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
242
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
243
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
244

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

    
251
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
252
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
253
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
254

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

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

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

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

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

    
420
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
421

    
422
}
423

    
424
$changes_applied = false;
425

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

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

    
464
		/*
465
		 * If the parent interface has changed above, the VLANs needs to be
466
		 * redone.
467
		 */
468
		if ($vlan_redo) {
469
			interfaces_vlan_configure();
470
		}
471

    
472
		/* restart snmp so that it binds to correct address */
473
		$retval |= services_snmpd_configure();
474

    
475
		/* sync filter configuration */
476
		setup_gateways_monitor();
477

    
478
		clear_subsystem_dirty('interfaces');
479

    
480
		$retval |= filter_configure();
481

    
482
		enable_rrd_graphing();
483

    
484
		$changes_applied = true;
485

    
486
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
487
			clear_subsystem_dirty('staticroutes');
488
		}
489
	}
490
	@unlink("{$g['tmp_path']}/.interfaces.apply");
491
} else if ($_POST['save']) {
492

    
493
	unset($input_errors);
494
	$pconfig = $_POST;
495

    
496
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
497
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
498
	} else {
499
		$pconfig['track6-prefix-id'] = 0;
500
	}
501

    
502
	/* filter out spaces from descriptions */
503
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
504

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

    
519
	/* input validation */
520
	$reqdfields = explode(" ", "descr");
521
	$reqdfieldsn = array(gettext("Description"));
522
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
523

    
524
	if (!$input_errors) {
525
		/* description unique? */
526
		foreach ($ifdescrs as $ifent => $ifdescr) {
527
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
528
				$input_errors[] = gettext("An interface with the specified description already exists.");
529
				break;
530
			}
531
		}
532

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

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

    
551
		if (is_numeric($_POST['descr'])) {
552
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
553
		}
554

    
555
		/*
556
		 * Packages (e.g. tinc) create interface groups, reserve this
557
		 * namespace pkg_ for them.
558
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
559
		 */
560
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
561
			$input_errors[] = gettext("The interface description cannot start with pkg_");
562
		}
563
	}
564

    
565
	if ($_POST['blockbogons'] == "yes" &&
566
	    isset($config['system']['ipv6allow']) &&
567
	    (!isset($config['system']['maximumtableentries']) ||
568
	     $config['system']['maximumtableentries'] <
569
	     $g['minimumtableentries_bogonsv6'])) {
570
		$input_errors[] = sprintf(gettext(
571
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
572
		    $g['minimumtableentries_bogonsv6']);
573
	}
574

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

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

    
701
			if (empty($_POST['track6-interface'])) {
702
				$input_errors[] = gettext("A valid interface to track must be selected.");
703
			}
704

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

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

    
744
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
745
			if ($_POST['subnet'] < 31) {
746
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
747
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
748
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
749
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
750
				}
751
			}
752

    
753
			foreach ($staticroutes as $route_subnet) {
754
				list($network, $subnet) = explode("/", $route_subnet);
755
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
756
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
757
					break;
758
				}
759
				unset($network, $subnet);
760
			}
761
		}
762
	}
763
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
764
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
765

    
766
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
767
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
768
		} else {
769
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
770
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
771
			}
772
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
773
			if (count($where_ipaddr_configured)) {
774
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
775
				foreach ($where_ipaddr_configured as $subnet_conflict) {
776
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
777
				}
778
				$input_errors[] = $subnet_conflict_text;
779
			}
780

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

    
807
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
808
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
809
		$match = false;
810
		foreach ($a_gateways as $gateway) {
811
			if (in_array($_POST['gateway'], $gateway)) {
812
				$match = true;
813
			}
814
		}
815
		if (!$match) {
816
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
817
		}
818
	}
819
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
820
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
821
		$match = false;
822
		foreach ($a_gateways as $gateway) {
823
			if (in_array($_POST['gatewayv6'], $gateway)) {
824
				$match = true;
825
			}
826
		}
827
		if (!$match) {
828
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
829
		}
830
	}
831

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

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

    
880
		unset($min_mtu, $max_mtu);
881

    
882
		if (interface_is_vlan($wancfg['if']) != NULL) {
883
			$realhwif_array = get_parent_interface($wancfg['if']);
884
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
885
			$parent_realhwif = $realhwif_array[0];
886
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
887
			$mtu = 0;
888
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
889
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
890
			if ($mtu == 0)
891
				$mtu = get_interface_mtu($parent_realhwif);
892
			if ($_POST['mtu'] > $mtu)
893
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
894
		} else {
895
			foreach ($config['interfaces'] as $idx => $ifdata) {
896
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
897
					continue;
898
				}
899

    
900
				$realhwif_array = get_parent_interface($ifdata['if']);
901
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
902
				$parent_realhwif = $realhwif_array[0];
903

    
904
				if ($parent_realhwif != $wancfg['if']) {
905
					continue;
906
				}
907

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

    
995
		if ($_POST['passphrase']) {
996
			$passlen = strlen($_POST['passphrase']);
997
			if ($passlen < 8 || $passlen > 63) {
998
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
999
			}
1000
		}
1001

    
1002
		if ($_POST['wpa_enable'] == "yes") {
1003
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1004
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1005
			}
1006
		}
1007
	}
1008

    
1009
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1010
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1011
	}
1012

    
1013
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1014
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1015
	}
1016

    
1017
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1018
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1019
	}
1020

    
1021
	if ($_POST['gatewayip4']) {
1022
		// The user wants to add an IPv4 gateway - validate the settings
1023
		$gateway_settings4 = array();
1024

    
1025
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1026
		$gateway_settings4['interface'] = $_POST['if'];
1027
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1028
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1029
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1030
		$gateway_settings4['ipprotocol'] = 'inet';
1031
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1032
		foreach ($gw_input_errors as $input_error_text) {
1033
			$input_errors[] = $input_error_text;
1034
		}
1035
	}
1036

    
1037
	if ($_POST['gatewayip6']) {
1038
		// The user wants to add an IPv6 gateway - validate the settings
1039
		$gateway_settings6 = array();
1040

    
1041
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1042
		$gateway_settings6['interface'] = $_POST['if'];
1043
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1044
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1045
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1046
		$gateway_settings6['ipprotocol'] = 'inet6';
1047
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1048
		foreach ($gw_input_errors as $input_error_text) {
1049
			$input_errors[] = $input_error_text;
1050
		}
1051
	}
1052

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

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

    
1101
		unset($wancfg['dhcpvlanenable']);
1102
		unset($wancfg['dhcpcvpt']);
1103

    
1104
		unset($wancfg['adv_dhcp_pt_timeout']);
1105
		unset($wancfg['adv_dhcp_pt_retry']);
1106
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1107
		unset($wancfg['adv_dhcp_pt_reboot']);
1108
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1109
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1110

    
1111
		unset($wancfg['adv_dhcp_pt_values']);
1112

    
1113
		unset($wancfg['adv_dhcp_send_options']);
1114
		unset($wancfg['adv_dhcp_request_options']);
1115
		unset($wancfg['adv_dhcp_required_options']);
1116
		unset($wancfg['adv_dhcp_option_modifiers']);
1117

    
1118
		unset($wancfg['adv_dhcp_config_advanced']);
1119
		unset($wancfg['adv_dhcp_config_file_override']);
1120
		unset($wancfg['adv_dhcp_config_file_override_path']);
1121

    
1122
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1123
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1124
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1125
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1126

    
1127
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1128
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1129
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1130
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1131
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1132

    
1133
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1134
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1135
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1136
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1137
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1138

    
1139
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1140
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1141
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1142

    
1143
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1144
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1145
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1146
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1147

    
1148
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1149
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1150
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1151
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1152
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1153

    
1154
		unset($wancfg['adv_dhcp6_config_advanced']);
1155
		unset($wancfg['adv_dhcp6_config_file_override']);
1156
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1157

    
1158
		unset($wancfg['pppoe_password']);
1159
		unset($wancfg['pptp_username']);
1160
		unset($wancfg['pptp_password']);
1161
		unset($wancfg['provider']);
1162
		unset($wancfg['ondemand']);
1163
		unset($wancfg['timeout']);
1164
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1165
			unset($wancfg['pppoe']['pppoe-reset-type']);
1166
		}
1167
		unset($wancfg['local']);
1168

    
1169
		unset($wancfg['remote']);
1170
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1171
			if ($wancfg['ipaddr'] != 'ppp') {
1172
				unset($a_ppps[$pppid]['apn']);
1173
				unset($a_ppps[$pppid]['phone']);
1174
				unset($a_ppps[$pppid]['provider']);
1175
				unset($a_ppps[$pppid]['ondemand']);
1176
			}
1177
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1178
				unset($a_ppps[$pppid]['localip']);
1179
				unset($a_ppps[$pppid]['subnet']);
1180
				unset($a_ppps[$pppid]['gateway']);
1181
			}
1182
			if ($wancfg['ipaddr'] != 'pppoe') {
1183
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1184
			}
1185
			if ($wancfg['type'] != $_POST['type']) {
1186
				unset($a_ppps[$pppid]['idletimeout']);
1187
			}
1188
		}
1189

    
1190
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1191
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1192

    
1193
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1194
		switch ($_POST['type']) {
1195
			case "staticv4":
1196
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1197
				$wancfg['subnet'] = $_POST['subnet'];
1198
				if ($_POST['gateway'] != "none") {
1199
					$wancfg['gateway'] = $_POST['gateway'];
1200
				}
1201
				break;
1202
			case "dhcp":
1203
				$wancfg['ipaddr'] = "dhcp";
1204
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1205
				$wancfg['alias-address'] = $_POST['alias-address'];
1206
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1207
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1208

    
1209
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1210
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1211
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1212
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1213
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1214
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1215

    
1216
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1217

    
1218
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1219
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1220
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1221
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1222

    
1223
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1224
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1225
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1226

    
1227
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1228
				if ($gateway_item) {
1229
					$a_gateways[] = $gateway_item;
1230
				}
1231
				if ($_POST['dhcpvlanenable'] == "yes") {
1232
					$wancfg['dhcpvlanenable'] = true;
1233
				}
1234
				if (!empty($_POST['dhcpcvpt'])) {
1235
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1236
				} else {
1237
					unset($wancfg['dhcpcvpt']);
1238
				}
1239
				break;
1240
			case "ppp":
1241
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1242
				$a_ppps[$pppid]['type'] = $_POST['type'];
1243
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1244
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1245
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1246
				if ($_POST['ppp_password'] != DMYPWD) {
1247
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1248
				}
1249
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1250
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1251
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1252
				$wancfg['ipaddr'] = $_POST['type'];
1253
				break;
1254

    
1255
			case "pppoe":
1256
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1257
				$a_ppps[$pppid]['type'] = $_POST['type'];
1258
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1259
				if (isset($_POST['ppp_port'])) {
1260
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1261
				} else {
1262
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1263
				}
1264
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1265
				if ($_POST['pppoe_password'] != DMYPWD) {
1266
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1267
				}
1268
				if (!empty($_POST['provider'])) {
1269
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1270
				} else {
1271
					$a_ppps[$pppid]['provider'] = true;
1272
				}
1273
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1274
				if (!empty($_POST['pppoe_idletimeout'])) {
1275
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1276
				} else {
1277
					unset($a_ppps[$pppid]['idletimeout']);
1278
				}
1279

    
1280
				if (!empty($_POST['pppoe-reset-type'])) {
1281
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1282
				} else {
1283
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1284
				}
1285
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1286
				$wancfg['ipaddr'] = $_POST['type'];
1287
				if ($gateway_item) {
1288
					$a_gateways[] = $gateway_item;
1289
				}
1290

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

    
1359
				if ($_POST['dhcp6withoutra'] == "yes") {
1360
					$wancfg['dhcp6withoutra'] = true;
1361
				}
1362
				if ($_POST['dhcp6norelease'] == "yes") {
1363
					$wancfg['dhcp6norelease'] = true;
1364
				}
1365
				if ($_POST['dhcp6vlanenable'] == "yes") {
1366
					$wancfg['dhcp6vlanenable'] = true;
1367
				}
1368
				if (!empty($_POST['dhcp6cvpt'])) {
1369
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1370
				} else {
1371
					unset($wancfg['dhcp6cvpt']);
1372
				}
1373

    
1374
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1375
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1376
				}
1377
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1378
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1379
				}
1380
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1381
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1382
				}
1383
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1384
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1385
				}
1386

    
1387
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1388
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1389
				}
1390
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1391
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1392
				}
1393
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1394
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1395
				}
1396
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1397
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1398
				}
1399
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1400
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1401
				}
1402

    
1403
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1404
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1405
				}
1406
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1407
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1408
				}
1409
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1410
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1411
				}
1412
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1413
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1414
				}
1415
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1416
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1417
				}
1418

    
1419
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1420
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1421
				}
1422
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1423
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1424
				}
1425
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1426
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1427
				}
1428
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1429
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1430
				}
1431
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1432
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1433
				}
1434
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1435
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1436
				}
1437
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1438
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1439
				}
1440

    
1441
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1442
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1443
				}
1444
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1445
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1446
				}
1447
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1448
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1449
				}
1450
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1451
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1452
				}
1453
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1454
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1455
				}
1456

    
1457
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1458
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1459
				}
1460
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1461
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1462
				}
1463
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1464
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1465
				}
1466

    
1467
				if ($gateway_item) {
1468
					$a_gateways[] = $gateway_item;
1469
				}
1470
				break;
1471
			case "6rd":
1472
				$wancfg['ipaddrv6'] = "6rd";
1473
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1474
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1475
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1476
				if ($gateway_item) {
1477
					$a_gateways[] = $gateway_item;
1478
				}
1479
				break;
1480
			case "6to4":
1481
				$wancfg['ipaddrv6'] = "6to4";
1482
				break;
1483
			case "track6":
1484
				$wancfg['ipaddrv6'] = "track6";
1485
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1486
				if ($_POST['track6-prefix-id--hex'] === "") {
1487
					$wancfg['track6-prefix-id'] = 0;
1488
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1489
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1490
				} else {
1491
					$wancfg['track6-prefix-id'] = 0;
1492
				}
1493
				break;
1494
			case "none":
1495
				break;
1496
		}
1497
		handle_pppoe_reset($_POST);
1498

    
1499
		if ($_POST['blockpriv'] == "yes") {
1500
			$wancfg['blockpriv'] = true;
1501
		} else {
1502
			unset($wancfg['blockpriv']);
1503
		}
1504
		if ($_POST['blockbogons'] == "yes") {
1505
			$wancfg['blockbogons'] = true;
1506
		} else {
1507
			unset($wancfg['blockbogons']);
1508
		}
1509
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1510
		if (empty($_POST['mtu'])) {
1511
			unset($wancfg['mtu']);
1512
		} else {
1513
			$wancfg['mtu'] = $_POST['mtu'];
1514
		}
1515
		if (empty($_POST['mss'])) {
1516
			unset($wancfg['mss']);
1517
		} else {
1518
			$wancfg['mss'] = $_POST['mss'];
1519
		}
1520
		if (empty($_POST['mediaopt'])) {
1521
			unset($wancfg['media']);
1522
			unset($wancfg['mediaopt']);
1523
		} else {
1524
			$mediaopts = explode(' ', $_POST['mediaopt']);
1525
			if ($mediaopts[0] != '') {
1526
				$wancfg['media'] = $mediaopts[0];
1527
			}
1528
			if ($mediaopts[1] != '') {
1529
				$wancfg['mediaopt'] = $mediaopts[1];
1530
			} else {
1531
				unset($wancfg['mediaopt']);
1532
			}
1533
		}
1534
		if (isset($wancfg['wireless'])) {
1535
			handle_wireless_post();
1536
		}
1537

    
1538
		write_config();
1539

    
1540
		if ($_POST['gatewayip4']) {
1541
			save_gateway($gateway_settings4);
1542
		}
1543

    
1544
		if ($_POST['gatewayip6']) {
1545
			save_gateway($gateway_settings6);
1546
		}
1547

    
1548
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1549
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1550
		} else {
1551
			$toapplylist = array();
1552
		}
1553
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1554
		$toapplylist[$if]['ppps'] = $old_ppps;
1555
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1556

    
1557
		mark_subsystem_dirty('interfaces');
1558

    
1559
		/* regenerate cron settings/crontab file */
1560
		configure_cron();
1561

    
1562
		header("Location: interfaces.php?if={$if}");
1563
		exit;
1564
	}
1565

    
1566
} // end if ($_POST['save'])
1567

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

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

    
1674
	if ($_POST['wme_enable'] == "yes") {
1675
		if (!is_array($wancfg['wireless']['wme'])) {
1676
			$wancfg['wireless']['wme'] = array();
1677
		}
1678
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1679
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1680
		unset($wancfg['wireless']['wme']['enable']);
1681
	}
1682
	if ($_POST['puremode'] == "11g") {
1683
		if (!is_array($wancfg['wireless']['pureg'])) {
1684
			$wancfg['wireless']['pureg'] = array();
1685
		}
1686
		$wancfg['wireless']['pureg']['enable'] = true;
1687
	} else if ($_POST['puremode'] == "11n") {
1688
		if (!is_array($wancfg['wireless']['puren'])) {
1689
			$wancfg['wireless']['puren'] = array();
1690
		}
1691
		$wancfg['wireless']['puren']['enable'] = true;
1692
	} else {
1693
		if (isset($wancfg['wireless']['pureg'])) {
1694
			unset($wancfg['wireless']['pureg']);
1695
		}
1696
		if (isset($wancfg['wireless']['puren'])) {
1697
			unset($wancfg['wireless']['puren']);
1698
		}
1699
	}
1700
	if ($_POST['apbridge_enable'] == "yes") {
1701
		if (!is_array($wancfg['wireless']['apbridge'])) {
1702
			$wancfg['wireless']['apbridge'] = array();
1703
		}
1704
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1705
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1706
		unset($wancfg['wireless']['apbridge']['enable']);
1707
	}
1708
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1709
		if (!is_array($wancfg['wireless']['turbo'])) {
1710
			$wancfg['wireless']['turbo'] = array();
1711
		}
1712
		$wancfg['wireless']['turbo']['enable'] = true;
1713
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1714
		unset($wancfg['wireless']['turbo']['enable']);
1715
	}
1716

    
1717
	interface_sync_wireless_clones($wancfg, true);
1718
}
1719

    
1720
function check_wireless_mode() {
1721
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1722

    
1723
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1724
		return;
1725
	}
1726

    
1727
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1728
		$clone_count = 1;
1729
	} else {
1730
		$clone_count = 0;
1731
	}
1732

    
1733
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1734
		foreach ($config['wireless']['clone'] as $clone) {
1735
			if ($clone['if'] == $wlanbaseif) {
1736
				$clone_count++;
1737
			}
1738
		}
1739
	}
1740

    
1741
	if ($clone_count > 1) {
1742
		$old_wireless_mode = $wancfg['wireless']['mode'];
1743
		$wancfg['wireless']['mode'] = $_POST['mode'];
1744
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1745
			$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']]);
1746
		} else {
1747
			pfSense_interface_destroy("{$wlanif}_");
1748
		}
1749
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1750
	}
1751
}
1752

    
1753
// Find all possible media options for the interface
1754
$mediaopts_list = array();
1755
$intrealname = $config['interfaces'][$if]['if'];
1756
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1757
foreach ($mediaopts as $mediaopt) {
1758
	preg_match("/media (.*)/", $mediaopt, $matches);
1759
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1760
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1761
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1762
	} else {
1763
		// there is only media like "media 1000baseT"
1764
		array_push($mediaopts_list, $matches[1]);
1765
	}
1766
}
1767

    
1768
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1769
$shortcut_section = "interfaces";
1770

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

    
1774
// Get the MAC address
1775
$defgatewayname4 = $wancfg['descr'] . "GW";
1776
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1777

    
1778
function build_mediaopts_list() {
1779
	global $mediaopts_list;
1780

    
1781
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1782
			 " " =>	 gettext("------- Media Supported by this interface -------")
1783
			];
1784

    
1785
	foreach ($mediaopts_list as $mediaopt) {
1786
		$list[$mediaopt] = $mediaopt;
1787
	}
1788

    
1789
	return($list);
1790
}
1791

    
1792
function build_gateway_list() {
1793
	global $a_gateways, $if;
1794

    
1795
	$list = array("none" => gettext("None"));
1796
	foreach ($a_gateways as $gateway) {
1797
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1798
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1799
		}
1800
	}
1801

    
1802
	return($list);
1803
}
1804

    
1805
function build_gatewayv6_list() {
1806
	global $a_gateways, $if;
1807

    
1808
	$list = array("none" => gettext("None"));
1809
	foreach ($a_gateways as $gateway) {
1810
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1811
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1812
		}
1813
	}
1814

    
1815
	return($list);
1816
}
1817

    
1818
include("head.inc");
1819

    
1820
if ($input_errors) {
1821
	print_input_errors($input_errors);
1822
}
1823

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

    
1830
if ($changes_applied) {
1831
	print_apply_result_box($retval);
1832
}
1833

    
1834
$form = new Form();
1835

    
1836
$section = new Form_Section('General Configuration');
1837

    
1838
$section->addInput(new Form_Checkbox(
1839
	'enable',
1840
	'Enable',
1841
	'Enable interface',
1842
	$pconfig['enable'],
1843
	'yes'
1844
));
1845

    
1846
$section->addInput(new Form_Input(
1847
	'descr',
1848
	'*Description',
1849
	'text',
1850
	$pconfig['descr']
1851
))->setHelp('Enter a description (name) for the interface here.');
1852

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

    
1885
$macaddress = new Form_Input(
1886
	'spoofmac',
1887
	'MAC Address',
1888
	'text',
1889
	$pconfig['spoofmac'],
1890
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1891
);
1892

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

    
1903
$section->addInput($macaddress);
1904

    
1905
$section->addInput(new Form_Input(
1906
	'mtu',
1907
	'MTU',
1908
	'number',
1909
	$pconfig['mtu']
1910
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1911
			'This is typically 1500 bytes but can vary in some circumstances.');
1912

    
1913
$section->addInput(new Form_Input(
1914
	'mss',
1915
	'MSS',
1916
	'number',
1917
	$pconfig['mss']
1918
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1919
			'header size) will be in effect.');
1920

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

    
1931
$form->add($section);
1932

    
1933
$section = new Form_Section('Static IPv4 Configuration');
1934
$section->addClass('staticv4');
1935

    
1936
$section->addInput(new Form_IpAddress(
1937
	'ipaddr',
1938
	'*IPv4 Address',
1939
	$pconfig['ipaddr'],
1940
	'V4'
1941
))->addMask('subnet', $pconfig['subnet'], 32);
1942

    
1943
$group = new Form_Group('IPv4 Upstream gateway');
1944

    
1945
$group->add(new Form_Select(
1946
	'gateway',
1947
	'IPv4 Upstream Gateway',
1948
	$pconfig['gateway'],
1949
	build_gateway_list()
1950
));
1951

    
1952
$group->add(new Form_Button(
1953
	'addgw4',
1954
	'Add a new gateway',
1955
	null,
1956
	'fa-plus'
1957
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1958

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

    
1963
$section->add($group);
1964

    
1965
$form->add($section);
1966

    
1967
$section = new Form_Section('Static IPv6 Configuration');
1968
$section->addClass('staticv6');
1969

    
1970
$section->addInput(new Form_IpAddress(
1971
	'ipaddrv6',
1972
	'*IPv6 address',
1973
	$pconfig['ipaddrv6'],
1974
	'V6'
1975
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1976

    
1977
$section->addInput(new Form_Checkbox(
1978
	'ipv6usev4iface',
1979
	'Use IPv4 connectivity as parent interface',
1980
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1981
	$pconfig['ipv6usev4iface']
1982
));
1983

    
1984
$group = new Form_Group('IPv6 Upstream gateway');
1985

    
1986
$group->add(new Form_Select(
1987
	'gatewayv6',
1988
	'IPv6 Upstream Gateway',
1989
	$pconfig['gatewayv6'],
1990
	build_gatewayv6_list()
1991
));
1992

    
1993
$group->add(new Form_Button(
1994
	'addgw6',
1995
	'Add a new gateway',
1996
	null,
1997
	'fa-plus'
1998
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1999

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

    
2003
$section->add($group);
2004
$form->add($section);
2005

    
2006
// Add new gateway modal pop-up for IPv6
2007
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2008

    
2009
$modal->addInput(new Form_Checkbox(
2010
	'defaultgw6',
2011
	'Default',
2012
	'Default gateway',
2013
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2014
));
2015

    
2016
$modal->addInput(new Form_Input(
2017
	'gatewayname6',
2018
	'Gateway name',
2019
	'text',
2020
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2021
));
2022

    
2023
$modal->addInput(new Form_IpAddress(
2024
	'gatewayip6',
2025
	'Gateway IPv6',
2026
	$gateway_settings6['gateway'],
2027
	'V6'
2028
));
2029

    
2030
$modal->addInput(new Form_Input(
2031
	'gatewaydescr6',
2032
	'Description',
2033
	'text',
2034
	$gateway_settings6['descr']
2035
));
2036

    
2037
$btnaddgw6 = new Form_Button(
2038
	'add6',
2039
	'Add',
2040
	null,
2041
	'fa-plus'
2042
);
2043

    
2044
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2045

    
2046
$btncnxgw6 = new Form_Button(
2047
	'cnx6',
2048
	'Cancel',
2049
	null,
2050
	'fa-undo'
2051
);
2052

    
2053
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2054

    
2055
$modal->addInput(new Form_StaticText(
2056
	null,
2057
	$btnaddgw6 . $btncnxgw6
2058
));
2059

    
2060
$form->add($modal);
2061

    
2062
// ==== DHCP client configuration =============================
2063

    
2064
$section = new Form_Section('DHCP Client Configuration');
2065
$section->addClass('dhcp');
2066

    
2067
$group = new Form_Group('Options');
2068

    
2069
$group->add(new Form_Checkbox(
2070
	'adv_dhcp_config_advanced',
2071
	null,
2072
	'Advanced Configuration',
2073
	$pconfig['adv_dhcp_config_advanced']
2074
))->setHelp('Use advanced DHCP configuration options.');
2075

    
2076
$group->add(new Form_Checkbox(
2077
	'adv_dhcp_config_file_override',
2078
	null,
2079
	'Configuration Override',
2080
	$pconfig['adv_dhcp_config_file_override']
2081
))->setHelp('Override the configuration from this file.');
2082

    
2083
$section->add($group);
2084

    
2085
$section->addInput(new Form_Input(
2086
	'dhcphostname',
2087
	'Hostname',
2088
	'text',
2089
	$pconfig['dhcphostname']
2090
))->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).');
2091

    
2092
$section->addInput(new Form_IpAddress(
2093
	'alias-address',
2094
	'Alias IPv4 address',
2095
	$pconfig['alias-address'],
2096
	'V4'
2097
))->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.');
2098

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

    
2108
if (interface_is_vlan($wancfg['if']) != NULL) {
2109

    
2110
	$group = new Form_Group('DHCP VLAN Priority');
2111
	$group->add(new Form_Checkbox(
2112
		'dhcpvlanenable',
2113
		null,
2114
		'Enable dhcpclient VLAN Priority tagging',
2115
		$pconfig['dhcpvlanenable']
2116
	))->setHelp('Normally off unless specifically required by the ISP.');
2117

    
2118
	$group->add(new Form_Select(
2119
		'dhcpcvpt',
2120
		'VLAN Prio',
2121
		$pconfig['dhcpcvpt'],
2122
		$vlanprio
2123
	))->setHelp('Choose 802.1p priority to set.');
2124

    
2125
	$section->add($group);
2126
}
2127

    
2128
$group = new Form_Group('Protocol timing');
2129
$group->addClass('dhcpadvanced');
2130

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

    
2138
$group->add(new Form_Input(
2139
	'adv_dhcp_pt_retry',
2140
	null,
2141
	'number',
2142
	$pconfig['adv_dhcp_pt_retry']
2143
))->setHelp('Retry');
2144

    
2145
$group->add(new Form_Input(
2146
	'adv_dhcp_pt_select_timeout',
2147
	null,
2148
	'number',
2149
	$pconfig['adv_dhcp_pt_select_timeout'],
2150
	['min' => 0]
2151
))->setHelp('Select timeout');
2152

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

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

    
2167
$group->add(new Form_Input(
2168
	'adv_dhcp_pt_initial_interval',
2169
	null,
2170
	'number',
2171
	$pconfig['adv_dhcp_pt_initial_interval']
2172
))->setHelp('Initial interval');
2173

    
2174
$section->add($group);
2175

    
2176
$group = new Form_Group('Presets');
2177
$group->addClass('dhcpadvanced');
2178

    
2179
$group->add(new Form_Checkbox(
2180
	'adv_dhcp_pt_values',
2181
	null,
2182
	'FreeBSD default',
2183
	null,
2184
	'DHCP'
2185
))->displayAsRadio();
2186

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

    
2195
$group->add(new Form_Checkbox(
2196
	'adv_dhcp_pt_values',
2197
	null,
2198
	'pfSense Default',
2199
	null,
2200
	'pfSense'
2201
))->displayAsRadio();
2202

    
2203
$group->add(new Form_Checkbox(
2204
	'adv_dhcp_pt_values',
2205
	null,
2206
	'Saved Cfg',
2207
	null,
2208
	'SavedCfg'
2209
))->displayAsRadio();
2210

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

    
2214
$section->add($group);
2215

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

    
2226
$form->add($section);
2227

    
2228
$section = new Form_Section('Lease Requirements and Requests');
2229
$section->addClass('dhcpadvanced');
2230

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

    
2241
$section->addInput(new Form_Input(
2242
	'adv_dhcp_request_options',
2243
	'Request options',
2244
	'text',
2245
	$pconfig['adv_dhcp_request_options']
2246
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2247
			'Some ISPs may require certain options be or not be requested.', '<br />');
2248

    
2249
$section->addInput(new Form_Input(
2250
	'adv_dhcp_required_options',
2251
	'Require options',
2252
	'text',
2253
	$pconfig['adv_dhcp_required_options']
2254
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2255

    
2256
$section->addInput(new Form_Input(
2257
	'adv_dhcp_option_modifiers',
2258
	'Option modifiers',
2259
	'text',
2260
	$pconfig['adv_dhcp_option_modifiers']
2261
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2262
			'modifiers: (default, supersede, prepend, append) %1$s' .
2263
			'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>');
2264

    
2265
$form->add($section);
2266

    
2267
// DHCP6 client config
2268

    
2269
$section = new Form_Section('DHCP6 Client Configuration');
2270
$section->addClass('dhcp6');
2271

    
2272
$group = new Form_Group('Options');
2273

    
2274
$group->add(new Form_Checkbox(
2275
	'adv_dhcp6_config_advanced',
2276
	null,
2277
	'Advanced Configuration',
2278
	$pconfig['adv_dhcp6_config_advanced']
2279
))->setHelp('Use advanced DHCPv6 configuration options.');
2280

    
2281
$group->add(new Form_Checkbox(
2282
	'adv_dhcp6_config_file_override',
2283
	null,
2284
	'Configuration Override',
2285
	$pconfig['adv_dhcp6_config_file_override']
2286
))->setHelp('Override the configuration from this file.');
2287

    
2288
$section->add($group);
2289

    
2290
$section->addInput(new Form_Checkbox(
2291
	'dhcp6usev4iface',
2292
	'Use IPv4 connectivity as parent interface',
2293
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2294
	$pconfig['dhcp6usev4iface']
2295
));
2296

    
2297
$section->addInput(new Form_Checkbox(
2298
	'dhcp6prefixonly',
2299
	'Request only an IPv6 prefix',
2300
	'Only request an IPv6 prefix, do not request an IPv6 address',
2301
	$pconfig['dhcp6prefixonly']
2302
));
2303

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

    
2311
$section->addInput(new Form_Checkbox(
2312
	'dhcp6-ia-pd-send-hint',
2313
	'Send IPv6 prefix hint',
2314
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2315
	$pconfig['dhcp6-ia-pd-send-hint']
2316
));
2317

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

    
2337
if (interface_is_vlan($wancfg['if']) != NULL) {
2338
	$group = new Form_Group('DHCP6 VLAN Priority');
2339

    
2340
	$group->add(new Form_Checkbox(
2341
		'dhcp6vlanenable',
2342
		null,
2343
		'Enable dhcp6c VLAN Priority tagging',
2344
		$pconfig['dhcp6vlanenable']
2345
	))->setHelp('Normally off unless specifically required by the ISP.');
2346

    
2347
	$group->add(new Form_Select(
2348
		'dhcp6cvpt',
2349
		'VLAN Prio',
2350
		$pconfig['dhcp6cvpt'],
2351
		$vlanprio
2352
	))->setHelp('Choose 802.1p priority to set.');
2353

    
2354
	$section->add($group);
2355
}
2356

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

    
2367
$form->add($section);
2368

    
2369
// DHCP6 client config - Advanced
2370

    
2371
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2372
$section->addClass('dhcp6advanced');
2373

    
2374
$section->addInput(new Form_Checkbox(
2375
	'adv_dhcp6_interface_statement_information_only_enable',
2376
	'Information only',
2377
	'Exchange Information Only',
2378
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2379
	'Selected'
2380
))->setHelp('Only exchange informational configuration parameters with servers.');
2381

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

    
2392
$section->addInput(new Form_Input(
2393
	'adv_dhcp6_interface_statement_request_options',
2394
	'Request Options',
2395
	'text',
2396
	$pconfig['adv_dhcp6_interface_statement_request_options']
2397
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2398
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2399

    
2400
$section->addInput(new Form_Input(
2401
	'adv_dhcp6_interface_statement_script',
2402
	'Scripts',
2403
	'text',
2404
	$pconfig['adv_dhcp6_interface_statement_script']
2405
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2406
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2407

    
2408
$group = new Form_Group('Identity Association Statement');
2409

    
2410
$group->add(new Form_Checkbox(
2411
	'adv_dhcp6_id_assoc_statement_address_enable',
2412
	null,
2413
	'Non-Temporary Address Allocation',
2414
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2415
	'Selected'
2416
));
2417

    
2418
$group->add(new Form_Input(
2419
	'adv_dhcp6_id_assoc_statement_address_id',
2420
	null,
2421
	'text',
2422
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2423
))->sethelp('id-assoc na ID');
2424

    
2425
$group->add(new Form_IpAddress(
2426
	'adv_dhcp6_id_assoc_statement_address',
2427
	null,
2428
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2429
	'V6'
2430
))->sethelp('IPv6 address');
2431

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

    
2439
$group->add(new Form_Input(
2440
	'adv_dhcp6_id_assoc_statement_address_vltime',
2441
	null,
2442
	'text',
2443
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2444
))->sethelp('vltime');
2445

    
2446
$section->add($group);
2447

    
2448
// Prefix delegation
2449
$group = new Form_Group('');
2450

    
2451
$group->add(new Form_Checkbox(
2452
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2453
	null,
2454
	'Prefix Delegation ',
2455
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2456
	'Selected'
2457
));
2458

    
2459
$group->add(new Form_Input(
2460
	'adv_dhcp6_id_assoc_statement_prefix_id',
2461
	null,
2462
	'text',
2463
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2464
))->sethelp('id-assoc pd ID');
2465

    
2466
$group->add(new Form_IpAddress(
2467
	'adv_dhcp6_id_assoc_statement_prefix',
2468
	null,
2469
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2470
	'V6'
2471
))->sethelp('IPv6 prefix');
2472

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

    
2480
$group->add(new Form_Input(
2481
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2482
	null,
2483
	'text',
2484
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2485
))->sethelp('vltime');
2486

    
2487
$section->add($group);
2488

    
2489
$group = new Form_Group('Prefix interface statement');
2490

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

    
2498
$group->add(new Form_Input(
2499
	'adv_dhcp6_prefix_interface_statement_sla_len',
2500
	null,
2501
	'text',
2502
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2503
))->sethelp('sla-len');
2504

    
2505
$section->add($group);
2506

    
2507
$group = new Form_Group('Select prefix interface');
2508
$section->addInput(new Form_Select(
2509
	'adv_dhcp6_prefix_selected_interface',
2510
	'Prefix Interface',
2511
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2512
	$interfaces
2513
))->setHelp('Select the interface on which to apply the prefix delegation.');
2514

    
2515
$group = new Form_Group('Authentication statement');
2516

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

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

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

    
2538
$group->add(new Form_Input(
2539
	'adv_dhcp6_authentication_statement_rdm',
2540
	null,
2541
	'text',
2542
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2543
))->sethelp('RDM');
2544

    
2545
$section->add($group);
2546

    
2547
$group = new Form_Group('Keyinfo statement');
2548

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

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

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

    
2565
$group = new Form_Group('');
2566

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

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

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

    
2588
$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>');
2589

    
2590
$section->add($group);
2591

    
2592
$form->add($section);
2593

    
2594
$section = new Form_Section('6RD Configuration');
2595
$section->addClass('_6rd');
2596

    
2597
$section->addInput(new Form_Input(
2598
	'prefix-6rd',
2599
	'6RD Prefix',
2600
	'text',
2601
	$pconfig['prefix-6rd']
2602
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2603

    
2604
$section->addInput(new Form_Input(
2605
	'gateway-6rd',
2606
	'*6RD Border relay',
2607
	'text',
2608
	$pconfig['gateway-6rd']
2609
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2610

    
2611
$section->addInput(new Form_Select(
2612
	'prefix-6rd-v4plen',
2613
	'6RD IPv4 Prefix length',
2614
	$pconfig['prefix-6rd-v4plen'],
2615
	array_combine(range(0, 32), range(0, 32))
2616
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2617

    
2618
$form->add($section);
2619

    
2620
// Track IPv6 ointerface section
2621
$section = new Form_Section('Track IPv6 Interface');
2622
$section->addClass('track6');
2623

    
2624
function build_ipv6interface_list() {
2625
	global $config, $form;
2626

    
2627
	$list = array('' => '');
2628

    
2629
	$interfaces = get_configured_interface_with_descr(true);
2630
	$dynv6ifs = array();
2631

    
2632
	foreach ($interfaces as $iface => $ifacename) {
2633
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2634
			case "6to4":
2635
			case "6rd":
2636
			case "dhcp6":
2637
				$dynv6ifs[$iface] = array(
2638
					'name' => $ifacename,
2639
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2640
				);
2641
				break;
2642
			default:
2643
				continue 2;
2644
		}
2645
	}
2646

    
2647
	foreach ($dynv6ifs as $iface => $ifacedata) {
2648
		$list[$iface] = $ifacedata['name'];
2649

    
2650
		$form->addGlobal(new Form_Input(
2651
			'ipv6-num-prefix-ids-' . $iface,
2652
			null,
2653
			'hidden',
2654
			$ifacedata['ipv6_num_prefix_ids']
2655
		));
2656
	}
2657

    
2658
	return($list);
2659
}
2660

    
2661
$section->addInput(new Form_Select(
2662
	'track6-interface',
2663
	'*IPv6 Interface',
2664
	$pconfig['track6-interface'],
2665
	build_ipv6interface_list()
2666
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2667

    
2668
if ($pconfig['track6-prefix-id'] == "") {
2669
	$pconfig['track6-prefix-id'] = 0;
2670
}
2671

    
2672
$section->addInput(new Form_Input(
2673
	'track6-prefix-id--hex',
2674
	'IPv6 Prefix ID',
2675
	'text',
2676
	sprintf("%x", $pconfig['track6-prefix-id'])
2677
))->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>');
2678

    
2679
$form->addGlobal(new Form_Input(
2680
	'track6-prefix-id-max',
2681
	null,
2682
	'hidden',
2683
	0
2684
));
2685

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

    
2688
/// PPP section
2689

    
2690
$section = new Form_Section('PPP Configuration');
2691
$section->addClass('ppp');
2692

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

    
2700
$section->addInput(new Form_Select(
2701
	'provider_list',
2702
	'Provider',
2703
	$pconfig['provider_list'],
2704
	[]
2705
));
2706

    
2707
$section->addInput(new Form_Select(
2708
	'providerplan',
2709
	'Plan',
2710
	$pconfig['providerplan'],
2711
	[]
2712
))->setHelp('Select to fill in service provider data.');
2713

    
2714
$section->addInput(new Form_Input(
2715
	'ppp_username',
2716
	'Username',
2717
	'text',
2718
	$pconfig['ppp_username']
2719
));
2720

    
2721
$section->addPassword(new Form_Input(
2722
	'ppp_password',
2723
	'Password',
2724
	'password',
2725
	$pconfig['ppp_password']
2726
));
2727

    
2728
$section->addInput(new Form_Input(
2729
	'phone',
2730
	'*Phone number',
2731
	'text',
2732
	$pconfig['phone']
2733
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2734

    
2735
$section->addInput(new Form_Input(
2736
	'apn',
2737
	'Access Point Name',
2738
	'text',
2739
	$pconfig['apn']
2740
));
2741

    
2742

    
2743
function build_port_list() {
2744
	$list = array("" => "None");
2745

    
2746
	$portlist = glob("/dev/cua*");
2747
	$modems	  = glob("/dev/modem*");
2748
	$portlist = array_merge($portlist, $modems);
2749

    
2750
	foreach ($portlist as $port) {
2751
		if (preg_match("/\.(lock|init)$/", $port)) {
2752
			continue;
2753
		}
2754

    
2755
	$list[trim($port)] = $port;
2756
	}
2757

    
2758
	return($list);
2759
}
2760

    
2761
$section->addInput(new Form_Select(
2762
	'port',
2763
	"*Modem port",
2764
	$pconfig['port'],
2765
	build_port_list()
2766
));
2767

    
2768
$section->addInput(new Form_Button(
2769
	'btnadvppp',
2770
	'Advanced PPP',
2771
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2772
	'fa-cog'
2773
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2774

    
2775
$form->add($section);
2776

    
2777
// PPPoE configuration
2778
$section = new Form_Section('PPPoE Configuration');
2779
$section->addClass('pppoe');
2780

    
2781
$section->addInput(new Form_Input(
2782
	'pppoe_username',
2783
	'*Username',
2784
	'text',
2785
	$pconfig['pppoe_username']
2786
));
2787

    
2788
$section->addPassword(new Form_Input(
2789
	'pppoe_password',
2790
	'*Password',
2791
	'password',
2792
	$pconfig['pppoe_password']
2793
));
2794

    
2795
$section->addInput(new Form_Input(
2796
	'provider',
2797
	'Service name',
2798
	'text',
2799
	$pconfig['provider']
2800
))->setHelp('This field can usually be left empty.');
2801

    
2802
$section->addInput(new Form_Checkbox(
2803
	'pppoe_dialondemand',
2804
	'Dial on demand',
2805
	'Enable Dial-On-Demand mode ',
2806
	$pconfig['pppoe_dialondemand'],
2807
	'enable'
2808
));
2809

    
2810
$section->addInput(new Form_Input(
2811
	'pppoe_idletimeout',
2812
	'Idle timeout',
2813
	'number',
2814
	$pconfig['pppoe_idletimeout'],
2815
	['min' => 0]
2816
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2817
			'An idle timeout of zero disables this feature.');
2818

    
2819
$section->addInput(new Form_Select(
2820
	'pppoe-reset-type',
2821
	'Periodic reset',
2822
	$pconfig['pppoe-reset-type'],
2823
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2824
))->setHelp('Select a reset timing type.');
2825

    
2826
$group = new Form_Group('Custom reset');
2827
$group->addClass('pppoecustom');
2828

    
2829
$group->add(new Form_Input(
2830
	'pppoe_resethour',
2831
	null,
2832
	'number',
2833
	$pconfig['pppoe_resethour'],
2834
	['min' => 0, 'max' => 23]
2835
))->setHelp('Hour (0-23)');
2836

    
2837
$group->add(new Form_Input(
2838
	'pppoe_resetminute',
2839
	null,
2840
	'number',
2841
	$pconfig['pppoe_resetminute'],
2842
	['min' => 0, 'max' => 59]
2843
))->setHelp('Minutes (0-59)');
2844

    
2845
$group->add(new Form_Input(
2846
	'pppoe_resetdate',
2847
	null,
2848
	'text',
2849
	$pconfig['pppoe_resetdate']
2850
))->setHelp('Specific date (mm/dd/yyyy)');
2851

    
2852
$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');
2853

    
2854
$section->add($group);
2855

    
2856
$group = new Form_MultiCheckboxGroup('cron based reset');
2857
$group->addClass('pppoepreset');
2858

    
2859
$group->add(new Form_MultiCheckbox(
2860
	'pppoe_pr_preset_val',
2861
	null,
2862
	'Reset at each month ("0 0 1 * *")',
2863
	$pconfig['pppoe_monthly'],
2864
	'monthly'
2865
))->displayAsRadio();
2866

    
2867
$group->add(new Form_MultiCheckbox(
2868
	'pppoe_pr_preset_val',
2869
	null,
2870
	'Reset at each week ("0 0 * * 0")',
2871
	$pconfig['pppoe_weekly'],
2872
	'weekly'
2873
))->displayAsRadio();
2874

    
2875
$group->add(new Form_MultiCheckbox(
2876
	'pppoe_pr_preset_val',
2877
	null,
2878
	'Reset at each day ("0 0 * * *")',
2879
	$pconfig['pppoe_daily'],
2880
	'daily'
2881
))->displayAsRadio();
2882

    
2883
$group->add(new Form_MultiCheckbox(
2884
	'pppoe_pr_preset_val',
2885
	null,
2886
	'Reset at each hour ("0 * * * *")',
2887
	$pconfig['pppoe_hourly'],
2888
	'hourly'
2889
))->displayAsRadio();
2890

    
2891
$section->add($group);
2892

    
2893
$section->addInput(new Form_Button(
2894
	'btnadvppp',
2895
	'Advanced and MLPPP',
2896
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2897
	'fa-cog'
2898
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2899

    
2900
$form->add($section);
2901

    
2902
// PPTP & L2TP Configuration section
2903
$section = new Form_Section('PPTP/L2TP Configuration');
2904
$section->addClass('pptp');
2905

    
2906
$section->addInput(new Form_Input(
2907
	'pptp_username',
2908
	'*Username',
2909
	'text',
2910
	$pconfig['pptp_username']
2911
));
2912

    
2913
$section->addPassword(new Form_Input(
2914
	'pptp_password',
2915
	'*Password',
2916
	'password',
2917
	$pconfig['pptp_password']
2918
));
2919

    
2920
$section->addInput(new Form_IpAddress(
2921
	'pptp_local0',
2922
	'*Local IP address',
2923
	$pconfig['pptp_localip'][0],
2924
	'V4'
2925
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2926

    
2927
$section->addInput(new Form_IpAddress(
2928
	'pptp_remote0',
2929
	'*Remote IP address',
2930
	$pconfig['pptp_remote'][0],
2931
	'HOSTV4'
2932
));
2933

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

    
2943
$section->addInput(new Form_Input(
2944
	'pptp_idletimeout',
2945
	'Idle timeout (seconds)',
2946
	'number',
2947
	$pconfig['pptp_idletimeout'],
2948
	['min' => 0]
2949
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2950
			'An idle timeout of zero disables this feature.');
2951

    
2952
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2953
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2954
} else {
2955
	$mlppp_text = "";
2956
}
2957

    
2958
$section->addInput(new Form_Button(
2959
	'btnadvppp',
2960
	'Advanced and MLPPP',
2961
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2962
	'fa-cog'
2963
))->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);
2964

    
2965
$form->add($section);
2966

    
2967
// Wireless interface
2968
if (isset($wancfg['wireless'])) {
2969

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

    
2972
	$section->addInput(new Form_Checkbox(
2973
		'persistcommonwireless',
2974
		'Persist common settings',
2975
		'Preserve common wireless configuration through interface deletions and reassignments.',
2976
		$pconfig['persistcommonwireless'],
2977
		'yes'
2978
	));
2979

    
2980
	$mode_list = ['auto' => 'Auto'];
2981

    
2982
	if (is_array($wl_modes)) {
2983
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2984
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2985
		}
2986
	}
2987

    
2988
	if (count($mode_list) == 1) {
2989
		$mode_list[''] = '';
2990
	}
2991

    
2992
	$section->addInput(new Form_Select(
2993
		'standard',
2994
		'Standard',
2995
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2996
		$mode_list
2997
	));
2998

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

    
3015
	$mode_list = ['0' => gettext('Auto')];
3016

    
3017
	if (is_array($wl_modes)) {
3018
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3019
			if ($wl_standard == "11g") {
3020
				$wl_standard = "11b/g";
3021
			} else if ($wl_standard == "11ng") {
3022
				$wl_standard = "11b/g/n";
3023
			} else if ($wl_standard == "11na") {
3024
				$wl_standard = "11a/n";
3025
			}
3026

    
3027
			foreach ($wl_channels as $wl_channel) {
3028
				if (isset($wl_chaninfo[$wl_channel])) {
3029
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
3030
				} else {
3031
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3032
				}
3033
			}
3034
		}
3035
	}
3036

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

    
3045
	if (ANTENNAS) {
3046
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3047
			$group = new Form_Group('Antenna Settings');
3048

    
3049
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3050
				$group->add(new Form_Select(
3051
					'diversity',
3052
					null,
3053
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3054
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3055
				))->setHelp('Diversity');
3056
			}
3057

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

    
3067
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3068
				$group->add(new Form_Select(
3069
					'rxantenna',
3070
					null,
3071
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3072
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3073
				))->setHelp('Receive antenna');
3074
			}
3075

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

    
3078
			$section->add($group);
3079
		}
3080
	}
3081

    
3082
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3083
			$section->addInput(new Form_Input(
3084
				'distance',
3085
				'Distance setting (meters)',
3086
				'test',
3087
				$pconfig['distance']
3088
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3089
	}
3090

    
3091
	$form->add($section);
3092

    
3093
	// Regulatory settings
3094
	$section = new Form_Section('Regulatory Settings');
3095

    
3096
	$domain_list = array("" => 'Default');
3097

    
3098
	if (is_array($wl_regdomains)) {
3099
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3100
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3101
		}
3102
	}
3103

    
3104
	$section->addInput(new Form_Select(
3105
		'regdomain',
3106
		'Regulatory domain',
3107
		$pconfig['regdomain'],
3108
		$domain_list
3109
	))->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');
3110

    
3111
	$country_list = array('' => 'Default');
3112

    
3113
	if (is_array($wl_countries)) {
3114
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3115
			$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']);
3116
		}
3117
	}
3118

    
3119
	$section->addInput(new Form_Select(
3120
		'regcountry',
3121
		'Country',
3122
		$pconfig['regcountry'],
3123
		$country_list
3124
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3125

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

    
3137
	$form->add($section);
3138

    
3139
	$section = new Form_Section('Network-Specific Wireless Configuration');
3140

    
3141
	$section->addInput(new Form_Select(
3142
		'mode',
3143
		'Mode',
3144
		$pconfig['mode'],
3145
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3146
	));
3147

    
3148
	$section->addInput(new Form_Input(
3149
		'ssid',
3150
		'SSID',
3151
		'text',
3152
		$pconfig['ssid']
3153
	));
3154

    
3155
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3156
		$section->addInput(new Form_Select(
3157
			'puremode',
3158
			'Minimum wireless standard',
3159
			$pconfig['puremode'],
3160
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3161
		))->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)');
3162
	} elseif (isset($wl_modes['11g'])) {
3163
		$section->addInput(new Form_Checkbox(
3164
			'puremode',
3165
			'802.11g only',
3166
			null,
3167
			$pconfig['puremode'],
3168
			'11g'
3169
		))->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)');
3170
	}
3171

    
3172
	$section->addInput(new Form_Checkbox(
3173
		'apbridge_enable',
3174
		'Allow intra-BSS communication',
3175
		'Allow packets to pass between wireless clients directly when operating as an access point',
3176
		$pconfig['apbridge_enable'],
3177
		'yes'
3178
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3179

    
3180
	$section->addInput(new Form_Checkbox(
3181
		'wme_enable',
3182
		'Enable WME',
3183
		'Force the card to use WME (wireless QoS)',
3184
		$pconfig['wme_enable'],
3185
		'yes'
3186
	));
3187

    
3188
	$section->addInput(new Form_Checkbox(
3189
		'hidessid_enable',
3190
		'Hide SSID',
3191
		'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.)',
3192
		$pconfig['hidessid_enable'],
3193
		'yes'
3194
	));
3195

    
3196
	$form->add($section);
3197

    
3198
	// WPA Section
3199
	$section = new Form_Section('WPA');
3200

    
3201
	$section->addInput(new Form_Checkbox(
3202
		'wpa_enable',
3203
		'Enable',
3204
		'Enable WPA',
3205
		$pconfig['wpa_enable'],
3206
		'yes'
3207
	));
3208

    
3209
	$section->addInput(new Form_Input(
3210
		'passphrase',
3211
		'WPA Pre-Shared Key',
3212
		'text',
3213
		$pconfig['passphrase']
3214
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3215

    
3216
	$section->addInput(new Form_Select(
3217
		'wpa_mode',
3218
		'WPA mode',
3219
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3220
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3221
	));
3222

    
3223
	$section->addInput(new Form_Select(
3224
		'wpa_key_mgmt',
3225
		'WPA Key Management Mode',
3226
		$pconfig['wpa_key_mgmt'],
3227
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3228
	));
3229

    
3230
	$section->addInput(new Form_Select(
3231
		'wpa_pairwise',
3232
		'WPA Pairwise',
3233
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3234
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3235
	));
3236

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

    
3245
	$section->addInput(new Form_Input(
3246
		'wpa_gmk_rekey',
3247
		'Group Master Key Regeneration',
3248
		'number',
3249
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3250
		['min' => '1', 'max' => 9999]
3251
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3252

    
3253
	$section->addInput(new Form_Checkbox(
3254
		'wpa_strict_rekey',
3255
		'Strict Key Regeneration',
3256
		'Force the AP to rekey whenever a client disassociates',
3257
		$pconfig['wpa_strict_rekey'],
3258
		'yes'
3259
	));
3260

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

    
3263
	$section = new Form_Section('802.1x RADIUS Options');
3264

    
3265
	$section->addInput(new Form_Checkbox(
3266
		'ieee8021x',
3267
		'IEEE802.1X',
3268
		'Enable 802.1X authentication',
3269
		$pconfig['ieee8021x'],
3270
		'yes'
3271
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3272

    
3273
	$group = new Form_Group('Primary 802.1X server');
3274

    
3275
	$group->add(new Form_IpAddress(
3276
		'auth_server_addr',
3277
		'IP Address',
3278
		$pconfig['auth_server_addr']
3279
	))->setHelp('IP address of the RADIUS server');
3280

    
3281
	$group->add(new Form_Input(
3282
		'auth_server_port',
3283
		'Port',
3284
		'number',
3285
		$pconfig['auth_server_port']
3286
	))->setHelp('Server auth port. Default is 1812');
3287

    
3288
	$group->add(new Form_Input(
3289
		'auth_server_shared_secret',
3290
		'Shared Secret',
3291
		'text',
3292
		$pconfig['auth_server_shared_secret']
3293
	))->setHelp('RADIUS Shared secret for this firewall');
3294

    
3295
	$section->add($group);
3296

    
3297
	$group = new Form_Group('Secondary 802.1X server');
3298

    
3299
	$group->add(new Form_IpAddress(
3300
		'auth_server_addr2',
3301
		'IP Address',
3302
		$pconfig['auth_server_addr2']
3303
	))->setHelp('IP address of the RADIUS server');
3304

    
3305
	$group->add(new Form_Input(
3306
		'auth_server_port2',
3307
		'Port',
3308
		'number',
3309
		$pconfig['auth_server_port2']
3310
	))->setHelp('Server auth port. Default is 1812');
3311

    
3312
	$group->add(new Form_Input(
3313
		'auth_server_shared_secret2',
3314
		'Shared Secret',
3315
		'text',
3316
		$pconfig['auth_server_shared_secret2']
3317
	))->setHelp('RADIUS Shared secret for this firewall');
3318

    
3319
	$section->add($group);
3320

    
3321
	$section->addInput(new Form_Checkbox(
3322
		'rsn_preauth',
3323
		'Authentication Roaming Preauth',
3324
		null,
3325
		$pconfig['rsn_preauth'],
3326
		'yes'
3327
	));
3328

    
3329
	$form->add($section);
3330
}
3331

    
3332
$section = new Form_Section('Reserved Networks');
3333

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

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

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

    
3356
$form->addGlobal(new Form_Input(
3357
	'if',
3358
	null,
3359
	'hidden',
3360
	$if
3361
));
3362

    
3363
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3364
	$form->addGlobal(new Form_Input(
3365
		'ppp_port',
3366
		null,
3367
		'hidden',
3368
		$pconfig['port']
3369
	));
3370
}
3371

    
3372
$form->addGlobal(new Form_Input(
3373
	'ptpid',
3374
	null,
3375
	'hidden',
3376
	$pconfig['ptpid']
3377
));
3378

    
3379

    
3380
// Add new gateway modal pop-up
3381
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3382

    
3383
$modal->addInput(new Form_Checkbox(
3384
	'defaultgw4',
3385
	'Default',
3386
	'Default gateway',
3387
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3388
));
3389

    
3390
$modal->addInput(new Form_Input(
3391
	'gatewayname4',
3392
	'Gateway name',
3393
	'text',
3394
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3395
));
3396

    
3397
$modal->addInput(new Form_IpAddress(
3398
	'gatewayip4',
3399
	'Gateway IPv4',
3400
	$gateway_settings4['gateway'],
3401
	'V4'
3402
));
3403

    
3404
$modal->addInput(new Form_Input(
3405
	'gatewaydescr4',
3406
	'Description',
3407
	'text',
3408
	$gateway_settings4['descr']
3409
));
3410

    
3411
$btnaddgw4 = new Form_Button(
3412
	'add4',
3413
	'Add',
3414
	null,
3415
	'fa-plus'
3416
);
3417

    
3418
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3419

    
3420
$btncnxgw4 = new Form_Button(
3421
	'cnx4',
3422
	'Cancel',
3423
	null,
3424
	'fa-undo'
3425
);
3426

    
3427
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3428

    
3429
$modal->addInput(new Form_StaticText(
3430
	null,
3431
	$btnaddgw4 . $btncnxgw4
3432
));
3433

    
3434
$form->add($modal);
3435

    
3436
print($form);
3437
?>
3438

    
3439
<script type="text/javascript">
3440
//<![CDATA[
3441
events.push(function() {
3442
	function updateType(t) {
3443

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

    
3478
		if (t != "l2tp" && t != "pptp") {
3479
			$('.'+t).show();
3480
		}
3481
	}
3482

    
3483
	function updateTypeSix(t) {
3484
		if (!isNaN(t[0])) {
3485
			t = '_' + t;
3486
		}
3487

    
3488
		switch (t) {
3489
			case "none": {
3490
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3491
				break;
3492
			}
3493
			case "staticv6": {
3494
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3495
				break;
3496
			}
3497
			case "slaac": {
3498
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3499
				break;
3500
			}
3501
			case "dhcp6": {
3502
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3503
				break;
3504
			}
3505
			case "_6rd": {
3506
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3507
				break;
3508
			}
3509
			case "_6to4": {
3510
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3511
				break;
3512
			}
3513
			case "track6": {
3514
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3515
				update_track6_prefix();
3516
				break;
3517
			}
3518
		}
3519

    
3520
		if (t != "l2tp" && t != "pptp") {
3521
			$('.'+t).show();
3522
		}
3523
	}
3524

    
3525
	function show_reset_settings(reset_type) {
3526
		if (reset_type == 'preset') {
3527
			$('.pppoepreset').show();
3528
			$('.pppoecustom').hide();
3529
		} else if (reset_type == 'custom') {
3530
			$('.pppoecustom').show();
3531
			$('.pppoepreset').hide();
3532
		} else {
3533
			$('.pppoecustom').hide();
3534
			$('.pppoepreset').hide();
3535
		}
3536
	}
3537

    
3538
	function update_track6_prefix() {
3539
		var iface = $("#track6-interface").val();
3540
		if (iface == null) {
3541
			return;
3542
		}
3543

    
3544
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3545
		if (track6_prefix_ids == null) {
3546
			return;
3547
		}
3548

    
3549
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3550
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3551
	}
3552

    
3553
	function addOption_v4() {
3554
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3555
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3556
	}
3557

    
3558
	function addOption_v6() {
3559
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3560
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3561
	}
3562

    
3563
	function addSelectboxOption(selectbox, text, value) {
3564
		var optn = document.createElement("OPTION");
3565
		optn.text = text;
3566
		optn.value = value;
3567
		selectbox.append(optn);
3568
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3569
	}
3570

    
3571
	function country_list() {
3572
		$('#country').children().remove();
3573
		$('#provider_list').children().remove();
3574
		$('#providerplan').children().remove();
3575
		$.ajax("getserviceproviders.php",{
3576
			success: function(response) {
3577

    
3578
				var responseTextArr = response.split("\n");
3579
				responseTextArr.sort();
3580

    
3581
				responseTextArr.forEach( function(value) {
3582
					country = value.split(":");
3583
					$('#country').append($('<option>', {
3584
						value: country[1],
3585
						text : country[0]
3586
					}));
3587
				});
3588
			}
3589
		});
3590
	}
3591

    
3592
	function providers_list() {
3593
		$('#provider_list').children().remove();
3594
		$('#providerplan').children().remove();
3595
		$.ajax("getserviceproviders.php",{
3596
			type: 'post',
3597
			data: {country : $('#country').val()},
3598
			success: function(response) {
3599
				var responseTextArr = response.split("\n");
3600
				responseTextArr.sort();
3601
				responseTextArr.forEach( function(value) {
3602
					$('#provider_list').append($('<option>', {
3603
							value: value,
3604
							text : value
3605
					}));
3606
				});
3607
			}
3608
		});
3609
	}
3610

    
3611
	function providerplan_list() {
3612
		$('#providerplan').children().remove();
3613
		$.ajax("getserviceproviders.php",{
3614
			type: 'post',
3615
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3616
			success: function(response) {
3617
				var responseTextArr = response.split("\n");
3618
				responseTextArr.sort();
3619

    
3620
				$('#providerplan').append($('<option>', {
3621
					value: '',
3622
					text : ''
3623
				}));
3624

    
3625
				responseTextArr.forEach( function(value) {
3626
					if (value != "") {
3627
						providerplan = value.split(":");
3628

    
3629
						$('#providerplan').append($('<option>', {
3630
							value: providerplan[1],
3631
							text : providerplan[0] + " - " + providerplan[1]
3632
						}));
3633
					}
3634
				});
3635
			}
3636
		});
3637
	}
3638

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

    
3663
	function show_dhcp6adv() {
3664
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3665
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3666

    
3667
		hideCheckbox('dhcp6usev4iface', ovr);
3668
		hideCheckbox('dhcp6prefixonly', ovr);
3669
		hideInput('dhcp6-ia-pd-len', ovr);
3670
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3671
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3672

    
3673
		hideClass('dhcp6advanced', !adv || ovr);
3674
	}
3675

    
3676
	function setDHCPoptions() {
3677
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3678
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3679

    
3680
		if (ovr) {
3681
			hideInput('dhcphostname', true);
3682
			hideIpAddress('alias-address', true);
3683
			hideInput('dhcprejectfrom', true);
3684
			hideInput('adv_dhcp_config_file_override_path', false);
3685
			hideClass('dhcpadvanced', true);
3686
		} else {
3687
			hideInput('dhcphostname', false);
3688
			hideIpAddress('alias-address', false);
3689
			hideInput('dhcprejectfrom', false);
3690
			hideInput('adv_dhcp_config_file_override_path', true);
3691
			hideClass('dhcpadvanced', !adv);
3692
		}
3693
	}
3694

    
3695
	// DHCP preset actions
3696
	// Set presets from value of radio buttons
3697
	function setPresets(val) {
3698
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3699
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3700
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3701
		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']);?>");
3702
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3703
	}
3704

    
3705
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3706
		$('#adv_dhcp_pt_timeout').val(timeout);
3707
		$('#adv_dhcp_pt_retry').val(retry);
3708
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3709
		$('#adv_dhcp_pt_reboot').val(reboot);
3710
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3711
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3712
	}
3713

    
3714
	function setPPPoEDialOnDemandItems() {
3715
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3716
	}
3717

    
3718
	function setPPTPDialOnDemandItems() {
3719
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3720
	}
3721

    
3722
	// ---------- On initial page load ------------------------------------------------------------
3723

    
3724
	updateType($('#type').val());
3725
	updateTypeSix($('#type6').val());
3726
	show_reset_settings($('#pppoe-reset-type').val());
3727
	hideClass('dhcp6advanced', true);
3728
	hideClass('dhcpadvanced', true);
3729
	show_dhcp6adv();
3730
	setDHCPoptions();
3731
	setPPPoEDialOnDemandItems();
3732
	setPPTPDialOnDemandItems();
3733

    
3734
	// Set preset buttons on page load
3735
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3736
	if (sv == "") {
3737
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3738
	} else {
3739
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3740
	}
3741

    
3742
	// Set preset from value
3743
	setPresets(sv);
3744

    
3745
	// If the user wants to add a gateway, then add that to the gateway selection
3746
	if ($("#gatewayip4").val() != '') {
3747
		addOption_v4();
3748
	}
3749
	if ($("#gatewayip6").val() != '') {
3750
		addOption_v6();
3751
	}
3752

    
3753
	// ---------- Click checkbox handlers ---------------------------------------------------------
3754

    
3755
	$('#type').on('change', function() {
3756
		updateType(this.value);
3757
	});
3758

    
3759
	$('#type6').on('change', function() {
3760
		updateTypeSix(this.value);
3761
	});
3762

    
3763
	$('#track6-interface').on('change', function() {
3764
		update_track6_prefix();
3765
	});
3766

    
3767
	$('#pppoe-reset-type').on('change', function() {
3768
		show_reset_settings(this.value);
3769
	});
3770

    
3771
	$("#add4").click(function() {
3772
		addOption_v4();
3773
		$("#newgateway4").modal('hide');
3774
	});
3775

    
3776
	$("#cnx4").click(function() {
3777
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3778
		$("#gatewayip4").val('');
3779
		$("#gatewaydescr4").val('');
3780
		$("#defaultgw4").prop("checked", false);
3781
		$("#newgateway4").modal('hide');
3782
	});
3783

    
3784
	$("#add6").click(function() {
3785
		addOption_v6();
3786
		$("#newgateway6").modal('hide');
3787
	});
3788

    
3789
	$("#cnx6").click(function() {
3790
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3791
		$("#gatewayip6").val('');
3792
		$("#gatewaydescr6").val('');
3793
		$("#defaultgw6").prop("checked", false);
3794
		$("#newgateway6").modal('hide');
3795
	});
3796

    
3797
	$('#country').on('change', function() {
3798
		providers_list();
3799
	});
3800

    
3801
	$('#provider_list').on('change', function() {
3802
		providerplan_list();
3803
	});
3804

    
3805
	$('#providerplan').on('change', function() {
3806
		prefill_provider();
3807
	});
3808

    
3809
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3810
		setDHCPoptions();
3811
	});
3812

    
3813
	$('#adv_dhcp6_config_advanced').click(function () {
3814
		show_dhcp6adv();
3815
	});
3816

    
3817
	$('#adv_dhcp6_config_file_override').click(function () {
3818
		show_dhcp6adv();
3819
	});
3820

    
3821
	// On click . .
3822
	$('#pppoe_dialondemand').click(function () {
3823
		setPPPoEDialOnDemandItems();
3824
	});
3825

    
3826
	$('#pptp_dialondemand').click(function () {
3827
		setPPTPDialOnDemandItems();
3828
	});
3829

    
3830
	$('[name=adv_dhcp_pt_values]').click(function () {
3831
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3832
	});
3833

    
3834
	$('#pppoe_resetdate').datepicker();
3835

    
3836
});
3837
//]]>
3838
</script>
3839

    
3840
<?php include("foot.inc");
(71-71/225)