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
		}
468
		/* restart snmp so that it binds to correct address */
469
		$retval |= services_snmpd_configure();
470

    
471
		/* sync filter configuration */
472
		setup_gateways_monitor();
473

    
474
		clear_subsystem_dirty('interfaces');
475

    
476
		$retval |= filter_configure();
477

    
478
		enable_rrd_graphing();
479

    
480
		$changes_applied = true;
481

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

    
489
	unset($input_errors);
490
	$pconfig = $_POST;
491

    
492
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
493
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
494
	} else {
495
		$pconfig['track6-prefix-id'] = 0;
496
	}
497

    
498
	/* filter out spaces from descriptions */
499
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
500

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

    
515
	/* input validation */
516
	$reqdfields = explode(" ", "descr");
517
	$reqdfieldsn = array(gettext("Description"));
518
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
519

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

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

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

    
547
		if (is_numeric($_POST['descr'])) {
548
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
549
		}
550

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

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

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

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

    
697
			if (empty($_POST['track6-interface'])) {
698
				$input_errors[] = gettext("A valid interface to track must be selected.");
699
			}
700

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

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

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

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

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

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

    
803
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
804
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
805
		$match = false;
806
		foreach ($a_gateways as $gateway) {
807
			if (in_array($_POST['gateway'], $gateway)) {
808
				$match = true;
809
			}
810
		}
811
		if (!$match) {
812
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
813
		}
814
	}
815
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
816
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
817
		$match = false;
818
		foreach ($a_gateways as $gateway) {
819
			if (in_array($_POST['gatewayv6'], $gateway)) {
820
				$match = true;
821
			}
822
		}
823
		if (!$match) {
824
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
825
		}
826
	}
827
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
828
		$input_errors[] = gettext("The service name contains invalid characters.");
829
	}
830
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
831
		$input_errors[] = gettext("The idle timeout value must be an integer.");
832
	}
833
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
834
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
835
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
836
	}
837
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
838
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
839
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
840
	}
841
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
842
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
843
	}
844
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
845
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
846
	}
847
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
848
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
849
	}
850
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
851
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
852
	}
853
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
854
		$input_errors[] = gettext("The idle timeout value must be an integer.");
855
	}
856
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
857
		$input_errors[] = gettext("A valid MAC address must be specified.");
858
	}
859
	if ($_POST['mtu']) {
860
		if (!is_numericint($_POST['mtu'])) {
861
			$input_errors[] = "MTU must be an integer.";
862
		}
863
		if (substr($wancfg['if'], 0, 3) == 'gif') {
864
			$min_mtu = 1280;
865
			$max_mtu = 8192;
866
		} else {
867
			$min_mtu = 576;
868
			$max_mtu = 9000;
869
		}
870

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

    
875
		unset($min_mtu, $max_mtu);
876

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

    
895
				$realhwif_array = get_parent_interface($ifdata['if']);
896
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
897
				$parent_realhwif = $realhwif_array[0];
898

    
899
				if ($parent_realhwif != $wancfg['if']) {
900
					continue;
901
				}
902

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

    
990
		if ($_POST['passphrase']) {
991
			$passlen = strlen($_POST['passphrase']);
992
			if ($passlen < 8 || $passlen > 63) {
993
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
994
			}
995
		}
996

    
997
		if ($_POST['wpa_enable'] == "yes") {
998
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
999
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1000
			}
1001
		}
1002
	}
1003

    
1004
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1005
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1006
	}
1007

    
1008
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1009
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1010
	}
1011

    
1012
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1013
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1014
	}
1015

    
1016
	if ($_POST['gatewayip4']) {
1017
		// The user wants to add an IPv4 gateway - validate the settings
1018
		$gateway_settings4 = array();
1019

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

    
1032
	if ($_POST['gatewayip6']) {
1033
		// The user wants to add an IPv6 gateway - validate the settings
1034
		$gateway_settings6 = array();
1035

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

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

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

    
1096
		unset($wancfg['dhcpvlanenable']);
1097
		unset($wancfg['dhcpcvpt']);
1098

    
1099
		unset($wancfg['adv_dhcp_pt_timeout']);
1100
		unset($wancfg['adv_dhcp_pt_retry']);
1101
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1102
		unset($wancfg['adv_dhcp_pt_reboot']);
1103
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1104
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1105

    
1106
		unset($wancfg['adv_dhcp_pt_values']);
1107

    
1108
		unset($wancfg['adv_dhcp_send_options']);
1109
		unset($wancfg['adv_dhcp_request_options']);
1110
		unset($wancfg['adv_dhcp_required_options']);
1111
		unset($wancfg['adv_dhcp_option_modifiers']);
1112

    
1113
		unset($wancfg['adv_dhcp_config_advanced']);
1114
		unset($wancfg['adv_dhcp_config_file_override']);
1115
		unset($wancfg['adv_dhcp_config_file_override_path']);
1116

    
1117
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1118
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1119
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1120
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1121

    
1122
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1123
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1124
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1125
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1126
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1127

    
1128
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1129
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1130
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1131
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1132
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1133

    
1134
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1135
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1136
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1137

    
1138
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1139
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1140
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1141
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1142

    
1143
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1144
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1145
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1146
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1147
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1148

    
1149
		unset($wancfg['adv_dhcp6_config_advanced']);
1150
		unset($wancfg['adv_dhcp6_config_file_override']);
1151
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1152

    
1153
		unset($wancfg['pppoe_password']);
1154
		unset($wancfg['pptp_username']);
1155
		unset($wancfg['pptp_password']);
1156
		unset($wancfg['provider']);
1157
		unset($wancfg['ondemand']);
1158
		unset($wancfg['timeout']);
1159
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1160
			unset($wancfg['pppoe']['pppoe-reset-type']);
1161
		}
1162
		unset($wancfg['local']);
1163

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

    
1185
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1186
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1187

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

    
1204
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1205
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1206
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1207
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1208
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1209
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1210

    
1211
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1212

    
1213
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1214
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1215
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1216
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1217

    
1218
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1219
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1220
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1221

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

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

    
1275
				if (!empty($_POST['pppoe-reset-type'])) {
1276
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1277
				} else {
1278
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1279
				}
1280
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1281
				$wancfg['ipaddr'] = $_POST['type'];
1282
				if ($gateway_item) {
1283
					$a_gateways[] = $gateway_item;
1284
				}
1285

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

    
1354
				if ($_POST['dhcp6withoutra'] == "yes") {
1355
					$wancfg['dhcp6withoutra'] = true;
1356
				}
1357
				if ($_POST['dhcp6norelease'] == "yes") {
1358
					$wancfg['dhcp6norelease'] = true;
1359
				}
1360
				if ($_POST['dhcp6vlanenable'] == "yes") {
1361
					$wancfg['dhcp6vlanenable'] = true;
1362
				}
1363
				if (!empty($_POST['dhcp6cvpt'])) {
1364
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1365
				} else {
1366
					unset($wancfg['dhcp6cvpt']);
1367
				}
1368

    
1369
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1370
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1371
				}
1372
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1373
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1374
				}
1375
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1376
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1377
				}
1378
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1379
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1380
				}
1381

    
1382
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1383
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1384
				}
1385
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1386
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1387
				}
1388
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1389
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1390
				}
1391
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1392
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1395
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1396
				}
1397

    
1398
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1399
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1400
				}
1401
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1402
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1403
				}
1404
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1405
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1406
				}
1407
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1408
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1409
				}
1410
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1411
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1412
				}
1413

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

    
1436
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1437
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1438
				}
1439
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1440
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1441
				}
1442
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1443
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1444
				}
1445
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1446
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1447
				}
1448
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1449
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1450
				}
1451

    
1452
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1453
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1454
				}
1455
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1456
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1457
				}
1458
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1459
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1460
				}
1461

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

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

    
1533
		write_config();
1534

    
1535
		if ($_POST['gatewayip4']) {
1536
			save_gateway($gateway_settings4);
1537
		}
1538

    
1539
		if ($_POST['gatewayip6']) {
1540
			save_gateway($gateway_settings6);
1541
		}
1542

    
1543
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1544
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1545
		} else {
1546
			$toapplylist = array();
1547
		}
1548
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1549
		$toapplylist[$if]['ppps'] = $old_ppps;
1550
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1551

    
1552
		mark_subsystem_dirty('interfaces');
1553

    
1554
		/* regenerate cron settings/crontab file */
1555
		configure_cron();
1556

    
1557
		header("Location: interfaces.php?if={$if}");
1558
		exit;
1559
	}
1560

    
1561
} // end if ($_POST['save'])
1562

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

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

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

    
1712
	interface_sync_wireless_clones($wancfg, true);
1713
}
1714

    
1715
function check_wireless_mode() {
1716
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1717

    
1718
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1719
		return;
1720
	}
1721

    
1722
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1723
		$clone_count = 1;
1724
	} else {
1725
		$clone_count = 0;
1726
	}
1727

    
1728
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1729
		foreach ($config['wireless']['clone'] as $clone) {
1730
			if ($clone['if'] == $wlanbaseif) {
1731
				$clone_count++;
1732
			}
1733
		}
1734
	}
1735

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

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

    
1763
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1764
$shortcut_section = "interfaces";
1765

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

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

    
1776
function build_mediaopts_list() {
1777
	global $mediaopts_list;
1778

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

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

    
1787
	return($list);
1788
}
1789

    
1790
function build_gateway_list() {
1791
	global $a_gateways, $if;
1792

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

    
1800
	return($list);
1801
}
1802

    
1803
function build_gatewayv6_list() {
1804
	global $a_gateways, $if;
1805

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

    
1813
	return($list);
1814
}
1815

    
1816
include("head.inc");
1817

    
1818
if ($input_errors) {
1819
	print_input_errors($input_errors);
1820
}
1821

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

    
1828
if ($changes_applied) {
1829
	print_apply_result_box($retval);
1830
}
1831

    
1832
$form = new Form();
1833

    
1834
$section = new Form_Section('General Configuration');
1835

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

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

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

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

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

    
1901
$section->addInput($macaddress);
1902

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

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

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

    
1929
$form->add($section);
1930

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

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

    
1941
$group = new Form_Group('IPv4 Upstream gateway');
1942

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

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

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

    
1961
$section->add($group);
1962

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

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

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

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

    
1982
$group = new Form_Group('IPv6 Upstream gateway');
1983

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

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

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

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

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

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

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

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

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

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

    
2042
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2043

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

    
2051
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2052

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

    
2058
$form->add($modal);
2059

    
2060
// ==== DHCP client configuration =============================
2061

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

    
2065
$group = new Form_Group('Options');
2066

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

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

    
2081
$section->add($group);
2082

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

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

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

    
2106
if (interface_is_vlan($wancfg['if']) != NULL) {
2107

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

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

    
2123
	$section->add($group);
2124
}
2125

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

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

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

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

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

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

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

    
2172
$section->add($group);
2173

    
2174
$group = new Form_Group('Presets');
2175
$group->addClass('dhcpadvanced');
2176

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

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

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

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

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

    
2212
$section->add($group);
2213

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

    
2224
$form->add($section);
2225

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

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

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

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

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

    
2263
$form->add($section);
2264

    
2265
// DHCP6 client config
2266

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

    
2270
$group = new Form_Group('Options');
2271

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

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

    
2286
$section->add($group);
2287

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

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

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

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

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

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

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

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

    
2352
	$section->add($group);
2353
}
2354

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

    
2365
$form->add($section);
2366

    
2367
// DHCP6 client config - Advanced
2368

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

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

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

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

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

    
2406
$group = new Form_Group('Identity Association Statement');
2407

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

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

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

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

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

    
2444
$section->add($group);
2445

    
2446
// Prefix delegation
2447
$group = new Form_Group('');
2448

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

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

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

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

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

    
2485
$section->add($group);
2486

    
2487
$group = new Form_Group('Prefix interface statement');
2488

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

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

    
2503
$section->add($group);
2504

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

    
2513
$group = new Form_Group('Authentication statement');
2514

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

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

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

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

    
2543
$section->add($group);
2544

    
2545
$group = new Form_Group('Keyinfo statement');
2546

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

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

    
2561
$section->add($group);
2562

    
2563
$group = new Form_Group('');
2564

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

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

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

    
2586
$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>');
2587

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

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

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

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

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

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

    
2616
$form->add($section);
2617

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

    
2622
function build_ipv6interface_list() {
2623
	global $config, $section;
2624

    
2625
	$list = array('' => '');
2626

    
2627
	$interfaces = get_configured_interface_with_descr(true);
2628
	$dynv6ifs = array();
2629

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

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

    
2648
		$section->addInput(new Form_Input(
2649
			'ipv6-num-prefix-ids-' . $iface,
2650
			null,
2651
			'hidden',
2652
			$ifacedata['ipv6_num_prefix_ids']
2653
		));
2654
	}
2655

    
2656
	return($list);
2657
}
2658

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

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

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

    
2677
$section->addInput(new Form_Input(
2678
	'track6-prefix-id-max',
2679
	null,
2680
	'hidden',
2681
	0
2682
));
2683

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

    
2686
/// PPP section
2687

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

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

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

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

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

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

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

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

    
2740

    
2741
function build_port_list() {
2742
	$list = array("" => "None");
2743

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

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

    
2753
	$list[trim($port)] = $port;
2754
	}
2755

    
2756
	return($list);
2757
}
2758

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

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

    
2773
$form->add($section);
2774

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

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

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

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

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

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

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

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

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

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

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

    
2850
$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');
2851

    
2852
$section->add($group);
2853

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

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

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

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

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

    
2889
$section->add($group);
2890

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

    
2898
$form->add($section);
2899

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

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

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

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

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

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

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

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

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

    
2963
$form->add($section);
2964

    
2965
// Wireless interface
2966
if (isset($wancfg['wireless'])) {
2967

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

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

    
2978
	$mode_list = ['auto' => 'Auto'];
2979

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

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

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

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

    
3013
	$mode_list = ['0' => gettext('Auto')];
3014

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

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

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

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

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

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

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

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

    
3076
			$section->add($group);
3077
		}
3078
	}
3079

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

    
3089
	$form->add($section);
3090

    
3091
	// Regulatory settings
3092
	$section = new Form_Section('Regulatory Settings');
3093

    
3094
	$domain_list = array("" => 'Default');
3095

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

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

    
3109
	$country_list = array('' => 'Default');
3110

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

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

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

    
3135
	$form->add($section);
3136

    
3137
	$section = new Form_Section('Network-Specific Wireless Configuration');
3138

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

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

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

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

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

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

    
3194
	$form->add($section);
3195

    
3196
	// WPA Section
3197
	$section = new Form_Section('WPA');
3198

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

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

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

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

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

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

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

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

    
3259
	$form->add($section);
3260

    
3261
	$section = new Form_Section('802.1x RADIUS Options');
3262

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

    
3271
	$group = new Form_Group('Primary 802.1X server');
3272

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

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

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

    
3293
	$section->add($group);
3294

    
3295
	$group = new Form_Group('Secondary 802.1X server');
3296

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

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

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

    
3317
	$section->add($group);
3318

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

    
3327
	$form->add($section);
3328
}
3329

    
3330
$section = new Form_Section('Reserved Networks');
3331

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

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

    
3352
$form->add($section);
3353

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

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

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

    
3377

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

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

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

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

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

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

    
3416
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3417

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

    
3425
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3426

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

    
3432
$form->add($modal);
3433

    
3434
print($form);
3435
?>
3436

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3576
				var responseTextArr = response.split("\n");
3577
				responseTextArr.sort();
3578

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

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

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

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

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

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

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

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

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

    
3671
		hideClass('dhcp6advanced', !adv || ovr);
3672
	}
3673

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

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

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

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

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

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

    
3720
	// ---------- On initial page load ------------------------------------------------------------
3721

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

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

    
3740
	// Set preset from value
3741
	setPresets(sv);
3742

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

    
3751
	// ---------- Click checkbox handlers ---------------------------------------------------------
3752

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

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

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

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

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

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

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

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

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

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

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

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

    
3811
	$('#adv_dhcp6_config_advanced').click(function () {
3812
		show_dhcp6adv();
3813
	});
3814

    
3815
	$('#adv_dhcp6_config_file_override').click(function () {
3816
		show_dhcp6adv();
3817
	});
3818

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

    
3824
	$('#pptp_dialondemand').click(function () {
3825
		setPPTPDialOnDemandItems();
3826
	});
3827

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

    
3832
	$('#pppoe_resetdate').datepicker();
3833

    
3834
});
3835
//]]>
3836
</script>
3837

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