Project

General

Profile

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

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

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

    
44
define("ANTENNAS", false);
45

    
46
if (isset($_POST['referer'])) {
47
	$referer = $_POST['referer'];
48
} else {
49
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
50
}
51

    
52
// Get configured interface list
53
$ifdescrs = get_configured_interface_with_descr(true);
54

    
55
$if = "wan";
56

    
57
if ($_REQUEST['if']) {
58
	$if = $_REQUEST['if'];
59
}
60

    
61
if (empty($ifdescrs[$if])) {
62
	header("Location: interfaces.php");
63
	exit;
64
}
65

    
66
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
67
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
68
define("CRON_DAILY_PATTERN", "0 0 * * *");
69
define("CRON_HOURLY_PATTERN", "0 * * * *");
70

    
71
if (!is_array($pconfig)) {
72
	$pconfig = array();
73
}
74

    
75
if (!is_array($config['ppps'])) {
76
	$config['ppps'] = array();
77
}
78
if (!is_array($config['ppps']['ppp'])) {
79
	$config['ppps']['ppp'] = array();
80
}
81
$a_ppps = &$config['ppps']['ppp'];
82

    
83
function remove_bad_chars($string) {
84
	return preg_replace('/[^a-z_0-9]/i', '', $string);
85
}
86

    
87
if (!is_array($config['gateways'])) {
88
	$config['gateways'] = array();
89
}
90

    
91
if (!is_array($config['gateways']['gateway_item'])) {
92
	$config['gateways']['gateway_item'] = array();
93
}
94

    
95
$a_gateways = &$config['gateways']['gateway_item'];
96

    
97
$interfaces = get_configured_interface_with_descr();
98
/* Interfaces which have addresses configired elsewhere and should not be
99
 * configured here. See https://redmine.pfsense.org/issues/8687 */
100
$no_address_interfaces = array("ovpn", "ipsec", "gif", "gre");
101
$show_address_controls = true;
102
$realifname = get_real_interface($if);
103
foreach ($no_address_interfaces as $ifbl) {
104
	if (substr($realifname, 0, strlen($ifbl)) == $ifbl) {
105
		$show_address_controls = false;
106
	}
107
}
108

    
109
$wancfg = &$config['interfaces'][$if];
110
$old_wancfg = $wancfg;
111
$old_wancfg['realif'] = get_real_interface($if);
112
$old_ppps = $a_ppps;
113

    
114
// Populate page descr if it does not exist.
115
if ($if == "wan" && !$wancfg['descr']) {
116
	$wancfg['descr'] = "WAN";
117
} else if ($if == "lan" && !$wancfg['descr']) {
118
	$wancfg['descr'] = "LAN";
119
}
120

    
121
/* NOTE: The code here is used to set the $pppid for the curious */
122
foreach ($a_ppps as $pppid => $ppp) {
123
	if ($wancfg['if'] == $ppp['if']) {
124
		break;
125
	}
126
}
127

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

    
130
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
131
	$pconfig['pppid'] = $pppid;
132
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
133
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
134
	if ($a_ppps[$pppid]['type'] == "ppp") {
135
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
136
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
137

    
138
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
139
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
140
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
141
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
142
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
143
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
144
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
145
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
146

    
147
		/* ================================================ */
148
		/* = force a connection reset at a specific time? = */
149
		/* ================================================ */
150

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

    
205
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
206
$pconfig['alias-address'] = $wancfg['alias-address'];
207
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
208
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
209

    
210
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
211
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
212
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
213
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
214
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
215
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
216

    
217
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
218

    
219
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
220
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
221
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
222
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
223

    
224
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
225
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
226
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
227

    
228
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
229
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
230
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
231
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
232

    
233
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
234
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
235
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
236
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
237
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
238

    
239
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
240
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
241
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
242
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
243
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
244

    
245
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
246
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
247
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
248

    
249
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
250
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
251
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
252
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
253

    
254
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
255
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
256
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
257
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
258
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
259

    
260
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
261
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
262
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
263

    
264
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
265
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
266
$pconfig['enable'] = isset($wancfg['enable']);
267

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

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

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

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

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

    
431
}
432

    
433
$changes_applied = false;
434

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

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

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

    
479
		clear_subsystem_dirty('interfaces');
480

    
481
		$retval |= filter_configure();
482

    
483
		enable_rrd_graphing();
484

    
485
		$changes_applied = true;
486

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
808
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
809
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
810
		$match = false;
811
		foreach ($a_gateways as $gateway) {
812
			if (in_array($_POST['gateway'], $gateway)) {
813
				$match = true;
814
			}
815
		}
816
		if (!$match) {
817
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
818
		}
819
	}
820
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
821
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
822
		$match = false;
823
		foreach ($a_gateways as $gateway) {
824
			if (in_array($_POST['gatewayv6'], $gateway)) {
825
				$match = true;
826
			}
827
		}
828
		if (!$match) {
829
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
830
		}
831
	}
832
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
833
		$input_errors[] = gettext("The service name contains invalid 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
$ip = $_SERVER['REMOTE_ADDR'];
1776
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1777
$mymac = str_replace("\n", "", $mymac);
1778
$defgatewayname4 = $wancfg['descr'] . "GW";
1779
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1780

    
1781
function build_mediaopts_list() {
1782
	global $mediaopts_list;
1783

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

    
1788
	foreach ($mediaopts_list as $mediaopt) {
1789
		$list[$mediaopt] = $mediaopt;
1790
	}
1791

    
1792
	return($list);
1793
}
1794

    
1795
function build_gateway_list() {
1796
	global $a_gateways, $if;
1797

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

    
1805
	return($list);
1806
}
1807

    
1808
function build_gatewayv6_list() {
1809
	global $a_gateways, $if;
1810

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

    
1818
	return($list);
1819
}
1820

    
1821
include("head.inc");
1822

    
1823
if ($input_errors) {
1824
	print_input_errors($input_errors);
1825
}
1826

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

    
1833
if ($changes_applied) {
1834
	print_apply_result_box($retval);
1835
}
1836

    
1837
$form = new Form();
1838

    
1839
$section = new Form_Section('General Configuration');
1840

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

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

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

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

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

    
1906
$section->addInput($macaddress);
1907

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

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

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

    
1934
$form->add($section);
1935

    
1936
$section = new Form_Section('Static IPv4 Configuration');
1937
$section->addClass('staticv4');
1938

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

    
1946
$group = new Form_Group('IPv4 Upstream gateway');
1947

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

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

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

    
1966
$section->add($group);
1967

    
1968
$form->add($section);
1969

    
1970
$section = new Form_Section('Static IPv6 Configuration');
1971
$section->addClass('staticv6');
1972

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

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

    
1987
$group = new Form_Group('IPv6 Upstream gateway');
1988

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

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

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

    
2006
$section->add($group);
2007
$form->add($section);
2008

    
2009
// Add new gateway modal pop-up for IPv6
2010
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2011

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

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

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

    
2033
$modal->addInput(new Form_Input(
2034
	'gatewaydescr6',
2035
	'Description',
2036
	'text',
2037
	$gateway_settings6['descr']
2038
));
2039

    
2040
$btnaddgw6 = new Form_Button(
2041
	'add6',
2042
	'Add',
2043
	null,
2044
	'fa-plus'
2045
);
2046

    
2047
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2048

    
2049
$btncnxgw6 = new Form_Button(
2050
	'cnx6',
2051
	'Cancel',
2052
	null,
2053
	'fa-undo'
2054
);
2055

    
2056
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2057

    
2058
$modal->addInput(new Form_StaticText(
2059
	null,
2060
	$btnaddgw6 . $btncnxgw6
2061
));
2062

    
2063
$form->add($modal);
2064

    
2065
// ==== DHCP client configuration =============================
2066

    
2067
$section = new Form_Section('DHCP Client Configuration');
2068
$section->addClass('dhcp');
2069

    
2070
$group = new Form_Group('Options');
2071

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

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

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

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

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

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

    
2111
if (interface_is_vlan($wancfg['if']) != NULL) {
2112

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

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

    
2128
	$section->add($group);
2129
}
2130

    
2131
$group = new Form_Group('Protocol timing');
2132
$group->addClass('dhcpadvanced');
2133

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

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

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

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

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

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

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

    
2179
$group = new Form_Group('Presets');
2180
$group->addClass('dhcpadvanced');
2181

    
2182
$group->add(new Form_Checkbox(
2183
	'adv_dhcp_pt_values',
2184
	null,
2185
	'FreeBSD default',
2186
	null,
2187
	'DHCP'
2188
))->displayAsRadio();
2189

    
2190
$group->add(new Form_Checkbox(
2191
	'adv_dhcp_pt_values',
2192
	null,
2193
	'Clear',
2194
	null,
2195
	'Clear'
2196
))->displayAsRadio();
2197

    
2198
$group->add(new Form_Checkbox(
2199
	'adv_dhcp_pt_values',
2200
	null,
2201
	'pfSense Default',
2202
	null,
2203
	'pfSense'
2204
))->displayAsRadio();
2205

    
2206
$group->add(new Form_Checkbox(
2207
	'adv_dhcp_pt_values',
2208
	null,
2209
	'Saved Cfg',
2210
	null,
2211
	'SavedCfg'
2212
))->displayAsRadio();
2213

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

    
2217
$section->add($group);
2218

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

    
2229
$form->add($section);
2230

    
2231
$section = new Form_Section('Lease Requirements and Requests');
2232
$section->addClass('dhcpadvanced');
2233

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

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

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

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

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

    
2270
// DHCP6 client config
2271

    
2272
$section = new Form_Section('DHCP6 Client Configuration');
2273
$section->addClass('dhcp6');
2274

    
2275
$group = new Form_Group('Options');
2276

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

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

    
2291
$section->add($group);
2292

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

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

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

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

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

    
2340
if (interface_is_vlan($wancfg['if']) != NULL) {
2341
	$group = new Form_Group('DHCP6 VLAN Priority');
2342

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

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

    
2357
	$section->add($group);
2358
}
2359

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

    
2370
$form->add($section);
2371

    
2372
// DHCP6 client config - Advanced
2373

    
2374
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2375
$section->addClass('dhcp6advanced');
2376

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

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

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

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

    
2411
$group = new Form_Group('Identity Association Statement');
2412

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

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

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

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

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

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

    
2451
// Prefix delegation
2452
$group = new Form_Group('');
2453

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

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

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

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

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

    
2490
$section->add($group);
2491

    
2492
$group = new Form_Group('Prefix interface statement');
2493

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

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

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

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

    
2518
$group = new Form_Group('Authentication statement');
2519

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

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

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

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

    
2548
$section->add($group);
2549

    
2550
$group = new Form_Group('Keyinfo statement');
2551

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

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

    
2566
$section->add($group);
2567

    
2568
$group = new Form_Group('');
2569

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

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

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

    
2591
$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>');
2592

    
2593
$section->add($group);
2594

    
2595
$form->add($section);
2596

    
2597
$section = new Form_Section('6RD Configuration');
2598
$section->addClass('_6rd');
2599

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

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

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

    
2621
$form->add($section);
2622

    
2623
// Track IPv6 ointerface section
2624
$section = new Form_Section('Track IPv6 Interface');
2625
$section->addClass('track6');
2626

    
2627
function build_ipv6interface_list() {
2628
	global $config, $section;
2629

    
2630
	$list = array('' => '');
2631

    
2632
	$interfaces = get_configured_interface_with_descr(true);
2633
	$dynv6ifs = array();
2634

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

    
2650
	foreach ($dynv6ifs as $iface => $ifacedata) {
2651
		$list[$iface] = $ifacedata['name'];
2652

    
2653
		$section->addInput(new Form_Input(
2654
			'ipv6-num-prefix-ids-' . $iface,
2655
			null,
2656
			'hidden',
2657
			$ifacedata['ipv6_num_prefix_ids']
2658
		));
2659
	}
2660

    
2661
	return($list);
2662
}
2663

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

    
2671
if ($pconfig['track6-prefix-id'] == "") {
2672
	$pconfig['track6-prefix-id'] = 0;
2673
}
2674

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

    
2682
$section->addInput(new Form_Input(
2683
	'track6-prefix-id-max',
2684
	null,
2685
	'hidden',
2686
	0
2687
));
2688

    
2689
$form->add($section);
2690

    
2691
/// PPP section
2692

    
2693
$section = new Form_Section('PPP Configuration');
2694
$section->addClass('ppp');
2695

    
2696
$section->addInput(new Form_Select(
2697
	'country',
2698
	'Country',
2699
	$pconfig['country'],
2700
	[]
2701
));
2702

    
2703
$section->addInput(new Form_Select(
2704
	'provider_list',
2705
	'Provider',
2706
	$pconfig['provider_list'],
2707
	[]
2708
));
2709

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

    
2717
$section->addInput(new Form_Input(
2718
	'ppp_username',
2719
	'Username',
2720
	'text',
2721
	$pconfig['ppp_username']
2722
));
2723

    
2724
$section->addPassword(new Form_Input(
2725
	'ppp_password',
2726
	'Password',
2727
	'password',
2728
	$pconfig['ppp_password']
2729
));
2730

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

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

    
2745

    
2746
function build_port_list() {
2747
	$list = array("" => "None");
2748

    
2749
	$portlist = glob("/dev/cua*");
2750
	$modems	  = glob("/dev/modem*");
2751
	$portlist = array_merge($portlist, $modems);
2752

    
2753
	foreach ($portlist as $port) {
2754
		if (preg_match("/\.(lock|init)$/", $port)) {
2755
			continue;
2756
		}
2757

    
2758
	$list[trim($port)] = $port;
2759
	}
2760

    
2761
	return($list);
2762
}
2763

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

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

    
2778
$form->add($section);
2779

    
2780
// PPPoE configuration
2781
$section = new Form_Section('PPPoE Configuration');
2782
$section->addClass('pppoe');
2783

    
2784
$section->addInput(new Form_Input(
2785
	'pppoe_username',
2786
	'*Username',
2787
	'text',
2788
	$pconfig['pppoe_username']
2789
));
2790

    
2791
$section->addPassword(new Form_Input(
2792
	'pppoe_password',
2793
	'*Password',
2794
	'password',
2795
	$pconfig['pppoe_password']
2796
));
2797

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

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

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

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

    
2829
$group = new Form_Group('Custom reset');
2830
$group->addClass('pppoecustom');
2831

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

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

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

    
2855
$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');
2856

    
2857
$section->add($group);
2858

    
2859
$group = new Form_MultiCheckboxGroup('cron based reset');
2860
$group->addClass('pppoepreset');
2861

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

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

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

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

    
2894
$section->add($group);
2895

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

    
2903
$form->add($section);
2904

    
2905
// PPTP & L2TP Configuration section
2906
$section = new Form_Section('PPTP/L2TP Configuration');
2907
$section->addClass('pptp');
2908

    
2909
$section->addInput(new Form_Input(
2910
	'pptp_username',
2911
	'*Username',
2912
	'text',
2913
	$pconfig['pptp_username']
2914
));
2915

    
2916
$section->addPassword(new Form_Input(
2917
	'pptp_password',
2918
	'*Password',
2919
	'password',
2920
	$pconfig['pptp_password']
2921
));
2922

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

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

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

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

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

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

    
2968
$form->add($section);
2969

    
2970
// Wireless interface
2971
if (isset($wancfg['wireless'])) {
2972

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

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

    
2983
	$mode_list = ['auto' => 'Auto'];
2984

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

    
2991
	if (count($mode_list) == 1) {
2992
		$mode_list[''] = '';
2993
	}
2994

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

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

    
3018
	$mode_list = ['0' => gettext('Auto')];
3019

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

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

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

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

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

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

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

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

    
3081
			$section->add($group);
3082
		}
3083
	}
3084

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

    
3094
	$form->add($section);
3095

    
3096
	// Regulatory settings
3097
	$section = new Form_Section('Regulatory Settings');
3098

    
3099
	$domain_list = array("" => 'Default');
3100

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

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

    
3114
	$country_list = array('' => 'Default');
3115

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

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

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

    
3140
	$form->add($section);
3141

    
3142
	$section = new Form_Section('Network-Specific Wireless Configuration');
3143

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

    
3151
	$section->addInput(new Form_Input(
3152
		'ssid',
3153
		'SSID',
3154
		'text',
3155
		$pconfig['ssid']
3156
	));
3157

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

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

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

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

    
3199
	$form->add($section);
3200

    
3201
	// WPA Section
3202
	$section = new Form_Section('WPA');
3203

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

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

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

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

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

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

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

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

    
3264
	$form->add($section);
3265

    
3266
	$section = new Form_Section('802.1x RADIUS Options');
3267

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

    
3276
	$group = new Form_Group('Primary 802.1X server');
3277

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

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

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

    
3298
	$section->add($group);
3299

    
3300
	$group = new Form_Group('Secondary 802.1X server');
3301

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

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

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

    
3322
	$section->add($group);
3323

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

    
3332
	$form->add($section);
3333
}
3334

    
3335
$section = new Form_Section('Reserved Networks');
3336

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

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

    
3357
$form->add($section);
3358

    
3359
$form->addGlobal(new Form_Input(
3360
	'if',
3361
	null,
3362
	'hidden',
3363
	$if
3364
));
3365

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

    
3375
$form->addGlobal(new Form_Input(
3376
	'ptpid',
3377
	null,
3378
	'hidden',
3379
	$pconfig['ptpid']
3380
));
3381

    
3382

    
3383
// Add new gateway modal pop-up
3384
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3385

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

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

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

    
3407
$modal->addInput(new Form_Input(
3408
	'gatewaydescr4',
3409
	'Description',
3410
	'text',
3411
	$gateway_settings4['descr']
3412
));
3413

    
3414
$btnaddgw4 = new Form_Button(
3415
	'add4',
3416
	'Add',
3417
	null,
3418
	'fa-plus'
3419
);
3420

    
3421
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3422

    
3423
$btncnxgw4 = new Form_Button(
3424
	'cnx4',
3425
	'Cancel',
3426
	null,
3427
	'fa-undo'
3428
);
3429

    
3430
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3431

    
3432
$modal->addInput(new Form_StaticText(
3433
	null,
3434
	$btnaddgw4 . $btncnxgw4
3435
));
3436

    
3437
$form->add($modal);
3438

    
3439
print($form);
3440
?>
3441

    
3442
<script type="text/javascript">
3443
//<![CDATA[
3444
events.push(function() {
3445
	function updateType(t) {
3446

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

    
3481
		if (t != "l2tp" && t != "pptp") {
3482
			$('.'+t).show();
3483
		}
3484
	}
3485

    
3486
	function updateTypeSix(t) {
3487
		if (!isNaN(t[0])) {
3488
			t = '_' + t;
3489
		}
3490

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

    
3523
		if (t != "l2tp" && t != "pptp") {
3524
			$('.'+t).show();
3525
		}
3526
	}
3527

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

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

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

    
3552
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3553
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3554
	}
3555

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

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

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

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

    
3581
				var responseTextArr = response.split("\n");
3582
				responseTextArr.sort();
3583

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

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

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

    
3623
				$('#providerplan').append($('<option>', {
3624
					value: '',
3625
					text : ''
3626
				}));
3627

    
3628
				responseTextArr.forEach( function(value) {
3629
					if (value != "") {
3630
						providerplan = value.split(":");
3631

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

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

    
3666
	function show_dhcp6adv() {
3667
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3668
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3669

    
3670
		hideCheckbox('dhcp6usev4iface', ovr);
3671
		hideCheckbox('dhcp6prefixonly', ovr);
3672
		hideInput('dhcp6-ia-pd-len', ovr);
3673
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3674
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3675

    
3676
		hideClass('dhcp6advanced', !adv || ovr);
3677
	}
3678

    
3679
	function setDHCPoptions() {
3680
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3681
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3682

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

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

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

    
3717
	function setPPPoEDialOnDemandItems() {
3718
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3719
	}
3720

    
3721
	function setPPTPDialOnDemandItems() {
3722
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3723
	}
3724

    
3725
	// ---------- On initial page load ------------------------------------------------------------
3726

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

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

    
3745
	// Set preset from value
3746
	setPresets(sv);
3747

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

    
3756
	// ---------- Click checkbox handlers ---------------------------------------------------------
3757

    
3758
	$('#type').on('change', function() {
3759
		updateType(this.value);
3760
	});
3761

    
3762
	$('#type6').on('change', function() {
3763
		updateTypeSix(this.value);
3764
	});
3765

    
3766
	$('#track6-interface').on('change', function() {
3767
		update_track6_prefix();
3768
	});
3769

    
3770
	$('#pppoe-reset-type').on('change', function() {
3771
		show_reset_settings(this.value);
3772
	});
3773

    
3774
	$("#add4").click(function() {
3775
		addOption_v4();
3776
		$("#newgateway4").modal('hide');
3777
	});
3778

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

    
3787
	$("#add6").click(function() {
3788
		addOption_v6();
3789
		$("#newgateway6").modal('hide');
3790
	});
3791

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

    
3800
	$('#country').on('change', function() {
3801
		providers_list();
3802
	});
3803

    
3804
	$('#provider_list').on('change', function() {
3805
		providerplan_list();
3806
	});
3807

    
3808
	$('#providerplan').on('change', function() {
3809
		prefill_provider();
3810
	});
3811

    
3812
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3813
		setDHCPoptions();
3814
	});
3815

    
3816
	$('#adv_dhcp6_config_advanced').click(function () {
3817
		show_dhcp6adv();
3818
	});
3819

    
3820
	$('#adv_dhcp6_config_file_override').click(function () {
3821
		show_dhcp6adv();
3822
	});
3823

    
3824
	// On click . .
3825
	$('#pppoe_dialondemand').click(function () {
3826
		setPPPoEDialOnDemandItems();
3827
	});
3828

    
3829
	$('#pptp_dialondemand').click(function () {
3830
		setPPTPDialOnDemandItems();
3831
	});
3832

    
3833
	$('[name=adv_dhcp_pt_values]').click(function () {
3834
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3835
	});
3836

    
3837
	$('#pppoe_resetdate').datepicker();
3838

    
3839
});
3840
//]]>
3841
</script>
3842

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