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
		break;
272
	case "pppoe":
273
	case "pptp":
274
	case "l2tp":
275
	case "ppp":
276
		$pconfig['type'] = $wancfg['ipaddr'];
277
		break;
278
	default:
279
		if (is_ipaddrv4($wancfg['ipaddr'])) {
280
			$pconfig['type'] = "staticv4";
281
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
282
			$pconfig['subnet'] = $wancfg['subnet'];
283
			$pconfig['gateway'] = $wancfg['gateway'];
284
		} else {
285
			$pconfig['type'] = "none";
286
		}
287
		break;
288
}
289

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

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

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

    
427
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
428

    
429
}
430

    
431
$changes_applied = false;
432

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

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

    
469
		/* sync filter configuration */
470
		setup_gateways_monitor();
471

    
472
		clear_subsystem_dirty('interfaces');
473

    
474
		$retval |= filter_configure();
475

    
476
		enable_rrd_graphing();
477

    
478
		$changes_applied = true;
479

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

    
487
	unset($input_errors);
488
	$pconfig = $_POST;
489

    
490
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
491
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
492
	} else {
493
		$pconfig['track6-prefix-id'] = 0;
494
	}
495

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
873
		unset($min_mtu, $max_mtu);
874

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1237
			case "pppoe":
1238
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1239
				$a_ppps[$pppid]['type'] = $_POST['type'];
1240
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1241
				if (isset($_POST['ppp_port'])) {
1242
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1243
				} else {
1244
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1245
				}
1246
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1247
				if ($_POST['pppoe_password'] != DMYPWD) {
1248
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1249
				}
1250
				if (!empty($_POST['provider'])) {
1251
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1252
				} else {
1253
					$a_ppps[$pppid]['provider'] = true;
1254
				}
1255
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1256
				if (!empty($_POST['pppoe_idletimeout'])) {
1257
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1258
				} else {
1259
					unset($a_ppps[$pppid]['idletimeout']);
1260
				}
1261

    
1262
				if (!empty($_POST['pppoe-reset-type'])) {
1263
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1264
				} else {
1265
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1266
				}
1267
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1268
				$wancfg['ipaddr'] = $_POST['type'];
1269
				if ($gateway_item) {
1270
					$a_gateways[] = $gateway_item;
1271
				}
1272

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

    
1341
				if ($_POST['dhcp6withoutra'] == "yes") {
1342
					$wancfg['dhcp6withoutra'] = true;
1343
				}
1344
				if ($_POST['dhcp6norelease'] == "yes") {
1345
					$wancfg['dhcp6norelease'] = true;
1346
				}
1347
				if ($_POST['dhcp6vlanenable'] == "yes") {
1348
					$wancfg['dhcp6vlanenable'] = true;
1349
				}
1350
				if (!empty($_POST['dhcp6cvpt'])) {
1351
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1352
				} else {
1353
					unset($wancfg['dhcp6cvpt']);
1354
				}
1355

    
1356
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1357
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1358
				}
1359
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1360
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1361
				}
1362
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1363
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1364
				}
1365
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1366
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1367
				}
1368

    
1369
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1370
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1371
				}
1372
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1373
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1374
				}
1375
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1376
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1377
				}
1378
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1379
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1380
				}
1381
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1382
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1383
				}
1384

    
1385
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1386
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1387
				}
1388
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1389
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1390
				}
1391
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1392
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1395
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1396
				}
1397
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1398
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1399
				}
1400

    
1401
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1402
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1403
				}
1404
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1405
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1406
				}
1407
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1408
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1409
				}
1410
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1411
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1412
				}
1413
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1414
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1415
				}
1416
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1417
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1418
				}
1419
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1420
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1421
				}
1422

    
1423
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1424
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1425
				}
1426
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1427
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1428
				}
1429
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1430
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1431
				}
1432
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1433
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1434
				}
1435
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1436
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1437
				}
1438

    
1439
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1440
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1441
				}
1442
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1443
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1444
				}
1445
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1446
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1447
				}
1448

    
1449
				if ($gateway_item) {
1450
					$a_gateways[] = $gateway_item;
1451
				}
1452
				break;
1453
			case "6rd":
1454
				$wancfg['ipaddrv6'] = "6rd";
1455
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1456
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1457
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1458
				if ($gateway_item) {
1459
					$a_gateways[] = $gateway_item;
1460
				}
1461
				break;
1462
			case "6to4":
1463
				$wancfg['ipaddrv6'] = "6to4";
1464
				break;
1465
			case "track6":
1466
				$wancfg['ipaddrv6'] = "track6";
1467
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1468
				if ($_POST['track6-prefix-id--hex'] === "") {
1469
					$wancfg['track6-prefix-id'] = 0;
1470
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1471
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1472
				} else {
1473
					$wancfg['track6-prefix-id'] = 0;
1474
				}
1475
				break;
1476
			case "none":
1477
				break;
1478
		}
1479
		handle_pppoe_reset($_POST);
1480

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

    
1520
		write_config();
1521

    
1522
		if ($_POST['gatewayip4']) {
1523
			save_gateway($gateway_settings4);
1524
		}
1525

    
1526
		if ($_POST['gatewayip6']) {
1527
			save_gateway($gateway_settings6);
1528
		}
1529

    
1530
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1531
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1532
		} else {
1533
			$toapplylist = array();
1534
		}
1535
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1536
		$toapplylist[$if]['ppps'] = $old_ppps;
1537
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1538

    
1539
		mark_subsystem_dirty('interfaces');
1540

    
1541
		/* regenerate cron settings/crontab file */
1542
		configure_cron();
1543

    
1544
		header("Location: interfaces.php?if={$if}");
1545
		exit;
1546
	}
1547

    
1548
} // end if ($_POST['save'])
1549

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

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

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

    
1699
	interface_sync_wireless_clones($wancfg, true);
1700
}
1701

    
1702
function check_wireless_mode() {
1703
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1704

    
1705
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1706
		return;
1707
	}
1708

    
1709
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1710
		$clone_count = 1;
1711
	} else {
1712
		$clone_count = 0;
1713
	}
1714

    
1715
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1716
		foreach ($config['wireless']['clone'] as $clone) {
1717
			if ($clone['if'] == $wlanbaseif) {
1718
				$clone_count++;
1719
			}
1720
		}
1721
	}
1722

    
1723
	if ($clone_count > 1) {
1724
		$old_wireless_mode = $wancfg['wireless']['mode'];
1725
		$wancfg['wireless']['mode'] = $_POST['mode'];
1726
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1727
			$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']]);
1728
		} else {
1729
			pfSense_interface_destroy("{$wlanif}_");
1730
		}
1731
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1732
	}
1733
}
1734

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

    
1750
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1751
$shortcut_section = "interfaces";
1752

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

    
1756
// Get the MAC address
1757
$ip = $_SERVER['REMOTE_ADDR'];
1758
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1759
$mymac = str_replace("\n", "", $mymac);
1760
$defgatewayname4 = $wancfg['descr'] . "GW";
1761
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1762

    
1763
function build_mediaopts_list() {
1764
	global $mediaopts_list;
1765

    
1766
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1767
			 " " =>	 gettext("------- Media Supported by this interface -------")
1768
			];
1769

    
1770
	foreach ($mediaopts_list as $mediaopt) {
1771
		$list[$mediaopt] = $mediaopt;
1772
	}
1773

    
1774
	return($list);
1775
}
1776

    
1777
function build_gateway_list() {
1778
	global $a_gateways, $if;
1779

    
1780
	$list = array("none" => gettext("None"));
1781
	foreach ($a_gateways as $gateway) {
1782
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1783
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1784
		}
1785
	}
1786

    
1787
	return($list);
1788
}
1789

    
1790
function build_gatewayv6_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_ipaddrv6($gateway['gateway']))) {
1796
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1797
		}
1798
	}
1799

    
1800
	return($list);
1801
}
1802

    
1803
include("head.inc");
1804

    
1805
if ($input_errors) {
1806
	print_input_errors($input_errors);
1807
}
1808

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

    
1815
if ($changes_applied) {
1816
	print_apply_result_box($retval);
1817
}
1818

    
1819
$form = new Form();
1820

    
1821
$section = new Form_Section('General Configuration');
1822

    
1823
$section->addInput(new Form_Checkbox(
1824
	'enable',
1825
	'Enable',
1826
	'Enable interface',
1827
	$pconfig['enable'],
1828
	'yes'
1829
));
1830

    
1831
$section->addInput(new Form_Input(
1832
	'descr',
1833
	'*Description',
1834
	'text',
1835
	$pconfig['descr']
1836
))->setHelp('Enter a description (name) for the interface here.');
1837

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

    
1870
$macaddress = new Form_Input(
1871
	'spoofmac',
1872
	'MAC Address',
1873
	'text',
1874
	$pconfig['spoofmac'],
1875
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1876
);
1877

    
1878
$btnmymac = new Form_Button(
1879
	'btnmymac',
1880
	'Copy My MAC',
1881
	null,
1882
	'fa-clone'
1883
	);
1884

    
1885
$btnmymac->setAttribute('type','button')->addClass('btn-success btn-sm');
1886

    
1887
$group = new Form_Group('MAC Address');
1888
$group->add($macaddress);
1889
// $group->add($btnmymac);
1890
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1891
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1892
$section->add($group);
1893

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

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

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

    
1920
$form->add($section);
1921

    
1922
$section = new Form_Section('Static IPv4 Configuration');
1923
$section->addClass('staticv4');
1924

    
1925
$section->addInput(new Form_IpAddress(
1926
	'ipaddr',
1927
	'*IPv4 Address',
1928
	$pconfig['ipaddr'],
1929
	'V4'
1930
))->addMask('subnet', $pconfig['subnet'], 32);
1931

    
1932
$group = new Form_Group('IPv4 Upstream gateway');
1933

    
1934
$group->add(new Form_Select(
1935
	'gateway',
1936
	'IPv4 Upstream Gateway',
1937
	$pconfig['gateway'],
1938
	build_gateway_list()
1939
));
1940

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

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

    
1952
$section->add($group);
1953

    
1954
$form->add($section);
1955

    
1956
$section = new Form_Section('Static IPv6 Configuration');
1957
$section->addClass('staticv6');
1958

    
1959
$section->addInput(new Form_IpAddress(
1960
	'ipaddrv6',
1961
	'*IPv6 address',
1962
	$pconfig['ipaddrv6'],
1963
	'V6'
1964
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1965

    
1966
$section->addInput(new Form_Checkbox(
1967
	'ipv6usev4iface',
1968
	'Use IPv4 connectivity as parent interface',
1969
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1970
	$pconfig['ipv6usev4iface']
1971
));
1972

    
1973
$group = new Form_Group('IPv6 Upstream gateway');
1974

    
1975
$group->add(new Form_Select(
1976
	'gatewayv6',
1977
	'IPv6 Upstream Gateway',
1978
	$pconfig['gatewayv6'],
1979
	build_gatewayv6_list()
1980
));
1981

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

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

    
1992
$section->add($group);
1993
$form->add($section);
1994

    
1995
// Add new gateway modal pop-up for IPv6
1996
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1997

    
1998
$modal->addInput(new Form_Checkbox(
1999
	'defaultgw6',
2000
	'Default',
2001
	'Default gateway',
2002
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2003
));
2004

    
2005
$modal->addInput(new Form_Input(
2006
	'gatewayname6',
2007
	'Gateway name',
2008
	'text',
2009
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2010
));
2011

    
2012
$modal->addInput(new Form_IpAddress(
2013
	'gatewayip6',
2014
	'Gateway IPv6',
2015
	$gateway_settings6['gateway'],
2016
	'V6'
2017
));
2018

    
2019
$modal->addInput(new Form_Input(
2020
	'gatewaydescr6',
2021
	'Description',
2022
	'text',
2023
	$gateway_settings6['descr']
2024
));
2025

    
2026
$btnaddgw6 = new Form_Button(
2027
	'add6',
2028
	'Add',
2029
	null,
2030
	'fa-plus'
2031
);
2032

    
2033
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2034

    
2035
$btncnxgw6 = new Form_Button(
2036
	'cnx6',
2037
	'Cancel',
2038
	null,
2039
	'fa-undo'
2040
);
2041

    
2042
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2043

    
2044
$modal->addInput(new Form_StaticText(
2045
	null,
2046
	$btnaddgw6 . $btncnxgw6
2047
));
2048

    
2049
$form->add($modal);
2050

    
2051
// ==== DHCP client configuration =============================
2052

    
2053
$section = new Form_Section('DHCP Client Configuration');
2054
$section->addClass('dhcp');
2055

    
2056
$group = new Form_Group('Options');
2057

    
2058
$group->add(new Form_Checkbox(
2059
	'adv_dhcp_config_advanced',
2060
	null,
2061
	'Advanced Configuration',
2062
	$pconfig['adv_dhcp_config_advanced']
2063
))->setHelp('Use advanced DHCP configuration options.');
2064

    
2065
$group->add(new Form_Checkbox(
2066
	'adv_dhcp_config_file_override',
2067
	null,
2068
	'Configuration Override',
2069
	$pconfig['adv_dhcp_config_file_override']
2070
))->setHelp('Override the configuration from this file.');
2071

    
2072
$section->add($group);
2073

    
2074
$section->addInput(new Form_Input(
2075
	'dhcphostname',
2076
	'Hostname',
2077
	'text',
2078
	$pconfig['dhcphostname']
2079
))->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).');
2080

    
2081
$section->addInput(new Form_IpAddress(
2082
	'alias-address',
2083
	'Alias IPv4 address',
2084
	$pconfig['alias-address'],
2085
	'V4'
2086
))->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.');
2087

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

    
2097
$group = new Form_Group('Protocol timing');
2098
$group->addClass('dhcpadvanced');
2099

    
2100
$group->add(new Form_Input(
2101
	'adv_dhcp_pt_timeout',
2102
	null,
2103
	'number',
2104
	$pconfig['adv_dhcp_pt_timeout']
2105
))->setHelp('Timeout');
2106

    
2107
$group->add(new Form_Input(
2108
	'adv_dhcp_pt_retry',
2109
	null,
2110
	'number',
2111
	$pconfig['adv_dhcp_pt_retry']
2112
))->setHelp('Retry');
2113

    
2114
$group->add(new Form_Input(
2115
	'adv_dhcp_pt_select_timeout',
2116
	null,
2117
	'number',
2118
	$pconfig['adv_dhcp_pt_select_timeout'],
2119
	['min' => 0]
2120
))->setHelp('Select timeout');
2121

    
2122
$group->add(new Form_Input(
2123
	'adv_dhcp_pt_reboot',
2124
	null,
2125
	'number',
2126
	$pconfig['adv_dhcp_pt_reboot']
2127
))->setHelp('Reboot');
2128

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

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

    
2143
$section->add($group);
2144

    
2145
$group = new Form_Group('Presets');
2146
$group->addClass('dhcpadvanced');
2147

    
2148
$group->add(new Form_Checkbox(
2149
	'adv_dhcp_pt_values',
2150
	null,
2151
	'FreeBSD default',
2152
	null,
2153
	'DHCP'
2154
))->displayAsRadio();
2155

    
2156
$group->add(new Form_Checkbox(
2157
	'adv_dhcp_pt_values',
2158
	null,
2159
	'Clear',
2160
	null,
2161
	'Clear'
2162
))->displayAsRadio();
2163

    
2164
$group->add(new Form_Checkbox(
2165
	'adv_dhcp_pt_values',
2166
	null,
2167
	'pfSense Default',
2168
	null,
2169
	'pfSense'
2170
))->displayAsRadio();
2171

    
2172
$group->add(new Form_Checkbox(
2173
	'adv_dhcp_pt_values',
2174
	null,
2175
	'Saved Cfg',
2176
	null,
2177
	'SavedCfg'
2178
))->displayAsRadio();
2179

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

    
2183
$section->add($group);
2184

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

    
2195
$form->add($section);
2196

    
2197
$section = new Form_Section('Lease Requirements and Requests');
2198
$section->addClass('dhcpadvanced');
2199

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

    
2210
$section->addInput(new Form_Input(
2211
	'adv_dhcp_request_options',
2212
	'Request options',
2213
	'text',
2214
	$pconfig['adv_dhcp_request_options']
2215
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2216
			'Some ISPs may require certain options be or not be requested.', '<br />');
2217

    
2218
$section->addInput(new Form_Input(
2219
	'adv_dhcp_required_options',
2220
	'Require options',
2221
	'text',
2222
	$pconfig['adv_dhcp_required_options']
2223
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2224

    
2225
$section->addInput(new Form_Input(
2226
	'adv_dhcp_option_modifiers',
2227
	'Option modifiers',
2228
	'text',
2229
	$pconfig['adv_dhcp_option_modifiers']
2230
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2231
			'modifiers: (default, supersede, prepend, append) %1$s' .
2232
			'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>');
2233

    
2234
$form->add($section);
2235

    
2236
// DHCP6 client config
2237

    
2238
$section = new Form_Section('DHCP6 Client Configuration');
2239
$section->addClass('dhcp6');
2240

    
2241
$group = new Form_Group('Options');
2242

    
2243
$group->add(new Form_Checkbox(
2244
	'adv_dhcp6_config_advanced',
2245
	null,
2246
	'Advanced Configuration',
2247
	$pconfig['adv_dhcp6_config_advanced']
2248
))->setHelp('Use advanced DHCPv6 configuration options.');
2249

    
2250
$group->add(new Form_Checkbox(
2251
	'adv_dhcp6_config_file_override',
2252
	null,
2253
	'Configuration Override',
2254
	$pconfig['adv_dhcp6_config_file_override']
2255
))->setHelp('Override the configuration from this file.');
2256

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

    
2259
$section->addInput(new Form_Checkbox(
2260
	'dhcp6usev4iface',
2261
	'Use IPv4 connectivity as parent interface',
2262
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2263
	$pconfig['dhcp6usev4iface']
2264
));
2265

    
2266
$section->addInput(new Form_Checkbox(
2267
	'dhcp6prefixonly',
2268
	'Request only an IPv6 prefix',
2269
	'Only request an IPv6 prefix, do not request an IPv6 address',
2270
	$pconfig['dhcp6prefixonly']
2271
));
2272

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

    
2280
$section->addInput(new Form_Checkbox(
2281
	'dhcp6-ia-pd-send-hint',
2282
	'Send IPv6 prefix hint',
2283
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2284
	$pconfig['dhcp6-ia-pd-send-hint']
2285
));
2286

    
2287
$section->addInput(new Form_Checkbox(
2288
	'dhcp6debug',
2289
	'Debug',
2290
	'Start DHCP6 client in debug mode',
2291
	$pconfig['dhcp6debug']
2292
));
2293
$section->addInput(new Form_Checkbox(
2294
	'dhcp6withoutra',
2295
	'Do not wait for a RA',
2296
	'Required by some ISPs, especially those not using PPPoE',
2297
	$pconfig['dhcp6withoutra']
2298
));
2299
$section->addInput(new Form_Checkbox(
2300
	'dhcp6norelease',
2301
	'Do not allow PD/Address release',
2302
	'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',
2303
	$pconfig['dhcp6norelease']
2304
));
2305

    
2306
$group = new Form_Group('DHCP6 VLAN Priority');
2307

    
2308
$vlanprio = array(
2309
	"bk" => "Background (BK, 0)",
2310
	"be" => "Best Effort (BE, 1)",
2311
	"ee" => "Excellent Effort (EE, 2)",
2312
	"ca" => "Critical Applications (CA, 3)",
2313
	"vi" => "Video (VI, 4)",
2314
	"vo" => "Voice (VO, 5)",
2315
	"ic" => "Internetwork Control (IC, 6)",
2316
	"nc" => "Network Control (NC, 7)");
2317

    
2318
$group->add(new Form_Checkbox(
2319
	'dhcp6vlanenable',
2320
	null,
2321
	'Enable dhcp6c VLAN Priority tagging',
2322
	$pconfig['dhcp6vlanenable']
2323
))->setHelp('Normally off unless specifically required by the ISP.');
2324

    
2325
$group->add(new Form_Select(
2326
	'dhcp6cvpt',
2327
	'VLAN Prio',
2328
	$pconfig['dhcp6cvpt'],
2329
	$vlanprio
2330
))->setHelp('Choose 802.1p priority to set.');
2331

    
2332
$section->add($group);
2333

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

    
2344
$form->add($section);
2345

    
2346
// DHCP6 client config - Advanced
2347

    
2348
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2349
$section->addClass('dhcp6advanced');
2350

    
2351
$section->addInput(new Form_Checkbox(
2352
	'adv_dhcp6_interface_statement_information_only_enable',
2353
	'Information only',
2354
	'Exchange Information Only',
2355
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2356
	'Selected'
2357
))->setHelp('Only exchange informational configuration parameters with servers.');
2358

    
2359
$section->addInput(new Form_Input(
2360
	'adv_dhcp6_interface_statement_send_options',
2361
	'Send options',
2362
	'text',
2363
	$pconfig['adv_dhcp6_interface_statement_send_options']
2364
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2365
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2366
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2367
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2368

    
2369
$section->addInput(new Form_Input(
2370
	'adv_dhcp6_interface_statement_request_options',
2371
	'Request Options',
2372
	'text',
2373
	$pconfig['adv_dhcp6_interface_statement_request_options']
2374
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2375
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2376

    
2377
$section->addInput(new Form_Input(
2378
	'adv_dhcp6_interface_statement_script',
2379
	'Scripts',
2380
	'text',
2381
	$pconfig['adv_dhcp6_interface_statement_script']
2382
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2383
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2384

    
2385
$group = new Form_Group('Identity Association Statement');
2386

    
2387
$group->add(new Form_Checkbox(
2388
	'adv_dhcp6_id_assoc_statement_address_enable',
2389
	null,
2390
	'Non-Temporary Address Allocation',
2391
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2392
	'Selected'
2393
));
2394

    
2395
$group->add(new Form_Input(
2396
	'adv_dhcp6_id_assoc_statement_address_id',
2397
	null,
2398
	'text',
2399
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2400
))->sethelp('id-assoc na ID');
2401

    
2402
$group->add(new Form_IpAddress(
2403
	'adv_dhcp6_id_assoc_statement_address',
2404
	null,
2405
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2406
	'V6'
2407
))->sethelp('IPv6 address');
2408

    
2409
$group->add(new Form_Input(
2410
	'adv_dhcp6_id_assoc_statement_address_pltime',
2411
	null,
2412
	'text',
2413
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2414
))->sethelp('pltime');
2415

    
2416
$group->add(new Form_Input(
2417
	'adv_dhcp6_id_assoc_statement_address_vltime',
2418
	null,
2419
	'text',
2420
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2421
))->sethelp('vltime');
2422

    
2423
$section->add($group);
2424

    
2425
// Prefix delegation
2426
$group = new Form_Group('');
2427

    
2428
$group->add(new Form_Checkbox(
2429
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2430
	null,
2431
	'Prefix Delegation ',
2432
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2433
	'Selected'
2434
));
2435

    
2436
$group->add(new Form_Input(
2437
	'adv_dhcp6_id_assoc_statement_prefix_id',
2438
	null,
2439
	'text',
2440
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2441
))->sethelp('id-assoc pd ID');
2442

    
2443
$group->add(new Form_IpAddress(
2444
	'adv_dhcp6_id_assoc_statement_prefix',
2445
	null,
2446
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2447
	'V6'
2448
))->sethelp('IPv6 prefix');
2449

    
2450
$group->add(new Form_Input(
2451
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2452
	null,
2453
	'text',
2454
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2455
))->sethelp('pltime');
2456

    
2457
$group->add(new Form_Input(
2458
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2459
	null,
2460
	'text',
2461
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2462
))->sethelp('vltime');
2463

    
2464
$section->add($group);
2465

    
2466
$group = new Form_Group('Prefix interface statement');
2467

    
2468
$group->add(new Form_Input(
2469
	'adv_dhcp6_prefix_interface_statement_sla_id',
2470
	null,
2471
	'text',
2472
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2473
))->sethelp('Prefix Interface sla-id');
2474

    
2475
$group->add(new Form_Input(
2476
	'adv_dhcp6_prefix_interface_statement_sla_len',
2477
	null,
2478
	'text',
2479
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2480
))->sethelp('sla-len');
2481

    
2482
$section->add($group);
2483

    
2484
$group = new Form_Group('Select prefix interface');
2485
$section->addInput(new Form_Select(
2486
	'adv_dhcp6_prefix_selected_interface',
2487
	'Prefix Interface',
2488
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2489
	$interfaces
2490
))->setHelp('Select the interface on which to apply the prefix delegation.');
2491

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

    
2494
$group->add(new Form_Input(
2495
	'adv_dhcp6_authentication_statement_authname',
2496
	null,
2497
	'text',
2498
	$pconfig['adv_dhcp6_authentication_statement_authname']
2499
))->sethelp('Authname');
2500

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

    
2508
$group->add(new Form_Input(
2509
	'adv_dhcp6_authentication_statement_algorithm',
2510
	null,
2511
	'text',
2512
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2513
))->sethelp('Algorithm');
2514

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

    
2522
$section->add($group);
2523

    
2524
$group = new Form_Group('Keyinfo statement');
2525

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

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

    
2540
$section->add($group);
2541

    
2542
$group = new Form_Group('');
2543

    
2544
$group->add(new Form_Input(
2545
	'adv_dhcp6_key_info_statement_keyid',
2546
	null,
2547
	'text',
2548
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2549
))->sethelp('KeyID');
2550

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

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

    
2565
$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>');
2566

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

    
2569
$form->add($section);
2570

    
2571
$section = new Form_Section('6RD Configuration');
2572
$section->addClass('_6rd');
2573

    
2574
$section->addInput(new Form_Input(
2575
	'prefix-6rd',
2576
	'6RD Prefix',
2577
	'text',
2578
	$pconfig['prefix-6rd']
2579
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2580

    
2581
$section->addInput(new Form_Input(
2582
	'gateway-6rd',
2583
	'*6RD Border relay',
2584
	'text',
2585
	$pconfig['gateway-6rd']
2586
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2587

    
2588
$section->addInput(new Form_Select(
2589
	'prefix-6rd-v4plen',
2590
	'6RD IPv4 Prefix length',
2591
	$pconfig['prefix-6rd-v4plen'],
2592
	array_combine(range(0, 32), range(0, 32))
2593
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2594

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

    
2597
// Track IPv6 ointerface section
2598
$section = new Form_Section('Track IPv6 Interface');
2599
$section->addClass('track6');
2600

    
2601
function build_ipv6interface_list() {
2602
	global $config, $section;
2603

    
2604
	$list = array('' => '');
2605

    
2606
	$interfaces = get_configured_interface_with_descr(true);
2607
	$dynv6ifs = array();
2608

    
2609
	foreach ($interfaces as $iface => $ifacename) {
2610
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2611
			case "6to4":
2612
			case "6rd":
2613
			case "dhcp6":
2614
				$dynv6ifs[$iface] = array(
2615
					'name' => $ifacename,
2616
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2617
				);
2618
				break;
2619
			default:
2620
				continue;
2621
		}
2622
	}
2623

    
2624
	foreach ($dynv6ifs as $iface => $ifacedata) {
2625
		$list[$iface] = $ifacedata['name'];
2626

    
2627
		$section->addInput(new Form_Input(
2628
			'ipv6-num-prefix-ids-' . $iface,
2629
			null,
2630
			'hidden',
2631
			$ifacedata['ipv6_num_prefix_ids']
2632
		));
2633
	}
2634

    
2635
	return($list);
2636
}
2637

    
2638
$section->addInput(new Form_Select(
2639
	'track6-interface',
2640
	'*IPv6 Interface',
2641
	$pconfig['track6-interface'],
2642
	build_ipv6interface_list()
2643
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2644

    
2645
if ($pconfig['track6-prefix-id'] == "") {
2646
	$pconfig['track6-prefix-id'] = 0;
2647
}
2648

    
2649
$section->addInput(new Form_Input(
2650
	'track6-prefix-id--hex',
2651
	'IPv6 Prefix ID',
2652
	'text',
2653
	sprintf("%x", $pconfig['track6-prefix-id'])
2654
))->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>');
2655

    
2656
$section->addInput(new Form_Input(
2657
	'track6-prefix-id-max',
2658
	null,
2659
	'hidden',
2660
	0
2661
));
2662

    
2663
$form->add($section);
2664

    
2665
/// PPP section
2666

    
2667
$section = new Form_Section('PPP Configuration');
2668
$section->addClass('ppp');
2669

    
2670
$section->addInput(new Form_Select(
2671
	'country',
2672
	'Country',
2673
	$pconfig['country'],
2674
	[]
2675
));
2676

    
2677
$section->addInput(new Form_Select(
2678
	'provider_list',
2679
	'Provider',
2680
	$pconfig['provider_list'],
2681
	[]
2682
));
2683

    
2684
$section->addInput(new Form_Select(
2685
	'providerplan',
2686
	'Plan',
2687
	$pconfig['providerplan'],
2688
	[]
2689
))->setHelp('Select to fill in service provider data.');
2690

    
2691
$section->addInput(new Form_Input(
2692
	'ppp_username',
2693
	'Username',
2694
	'text',
2695
	$pconfig['ppp_username']
2696
));
2697

    
2698
$section->addPassword(new Form_Input(
2699
	'ppp_password',
2700
	'Password',
2701
	'password',
2702
	$pconfig['ppp_password']
2703
));
2704

    
2705
$section->addInput(new Form_Input(
2706
	'phone',
2707
	'*Phone number',
2708
	'text',
2709
	$pconfig['phone']
2710
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2711

    
2712
$section->addInput(new Form_Input(
2713
	'apn',
2714
	'Access Point Name',
2715
	'text',
2716
	$pconfig['apn']
2717
));
2718

    
2719

    
2720
function build_port_list() {
2721
	$list = array("" => "None");
2722

    
2723
	$portlist = glob("/dev/cua*");
2724
	$modems	  = glob("/dev/modem*");
2725
	$portlist = array_merge($portlist, $modems);
2726

    
2727
	foreach ($portlist as $port) {
2728
		if (preg_match("/\.(lock|init)$/", $port)) {
2729
			continue;
2730
		}
2731

    
2732
	$list[trim($port)] = $port;
2733
	}
2734

    
2735
	return($list);
2736
}
2737

    
2738
$section->addInput(new Form_Select(
2739
	'port',
2740
	"*Modem port",
2741
	$pconfig['port'],
2742
	build_port_list()
2743
));
2744

    
2745
$section->addInput(new Form_Button(
2746
	'btnadvppp',
2747
	'Advanced PPP',
2748
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2749
	'fa-cog'
2750
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2751

    
2752
$form->add($section);
2753

    
2754
// PPPoE configuration
2755
$section = new Form_Section('PPPoE Configuration');
2756
$section->addClass('pppoe');
2757

    
2758
$section->addInput(new Form_Input(
2759
	'pppoe_username',
2760
	'*Username',
2761
	'text',
2762
	$pconfig['pppoe_username']
2763
));
2764

    
2765
$section->addPassword(new Form_Input(
2766
	'pppoe_password',
2767
	'*Password',
2768
	'password',
2769
	$pconfig['pppoe_password']
2770
));
2771

    
2772
$section->addInput(new Form_Input(
2773
	'provider',
2774
	'Service name',
2775
	'text',
2776
	$pconfig['provider']
2777
))->setHelp('This field can usually be left empty.');
2778

    
2779
$section->addInput(new Form_Checkbox(
2780
	'pppoe_dialondemand',
2781
	'Dial on demand',
2782
	'Enable Dial-On-Demand mode ',
2783
	$pconfig['pppoe_dialondemand'],
2784
	'enable'
2785
));
2786

    
2787
$section->addInput(new Form_Input(
2788
	'pppoe_idletimeout',
2789
	'Idle timeout',
2790
	'number',
2791
	$pconfig['pppoe_idletimeout'],
2792
	['min' => 0]
2793
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2794
			'An idle timeout of zero disables this feature.');
2795

    
2796
$section->addInput(new Form_Select(
2797
	'pppoe-reset-type',
2798
	'Periodic reset',
2799
	$pconfig['pppoe-reset-type'],
2800
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2801
))->setHelp('Select a reset timing type.');
2802

    
2803
$group = new Form_Group('Custom reset');
2804
$group->addClass('pppoecustom');
2805

    
2806
$group->add(new Form_Input(
2807
	'pppoe_resethour',
2808
	null,
2809
	'number',
2810
	$pconfig['pppoe_resethour'],
2811
	['min' => 0, 'max' => 23]
2812
))->setHelp('Hour (0-23)');
2813

    
2814
$group->add(new Form_Input(
2815
	'pppoe_resetminute',
2816
	null,
2817
	'number',
2818
	$pconfig['pppoe_resetminute'],
2819
	['min' => 0, 'max' => 59]
2820
))->setHelp('Minutes (0-59)');
2821

    
2822
$group->add(new Form_Input(
2823
	'pppoe_resetdate',
2824
	null,
2825
	'text',
2826
	$pconfig['pppoe_resetdate']
2827
))->setHelp('Specific date (mm/dd/yyyy)');
2828

    
2829
$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');
2830

    
2831
$section->add($group);
2832

    
2833
$group = new Form_MultiCheckboxGroup('cron based reset');
2834
$group->addClass('pppoepreset');
2835

    
2836
$group->add(new Form_MultiCheckbox(
2837
	'pppoe_pr_preset_val',
2838
	null,
2839
	'Reset at each month ("0 0 1 * *")',
2840
	$pconfig['pppoe_monthly'],
2841
	'monthly'
2842
))->displayAsRadio();
2843

    
2844
$group->add(new Form_MultiCheckbox(
2845
	'pppoe_pr_preset_val',
2846
	null,
2847
	'Reset at each week ("0 0 * * 0")',
2848
	$pconfig['pppoe_weekly'],
2849
	'weekly'
2850
))->displayAsRadio();
2851

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

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

    
2868
$section->add($group);
2869

    
2870
$section->addInput(new Form_Button(
2871
	'btnadvppp',
2872
	'Advanced and MLPPP',
2873
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2874
	'fa-cog'
2875
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2876

    
2877
$form->add($section);
2878

    
2879
// PPTP & L2TP Configuration section
2880
$section = new Form_Section('PPTP/L2TP Configuration');
2881
$section->addClass('pptp');
2882

    
2883
$section->addInput(new Form_Input(
2884
	'pptp_username',
2885
	'*Username',
2886
	'text',
2887
	$pconfig['pptp_username']
2888
));
2889

    
2890
$section->addPassword(new Form_Input(
2891
	'pptp_password',
2892
	'*Password',
2893
	'password',
2894
	$pconfig['pptp_password']
2895
));
2896

    
2897
$section->addInput(new Form_IpAddress(
2898
	'pptp_local0',
2899
	'*Local IP address',
2900
	$pconfig['pptp_localip'][0],
2901
	'V4'
2902
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2903

    
2904
$section->addInput(new Form_IpAddress(
2905
	'pptp_remote0',
2906
	'*Remote IP address',
2907
	$pconfig['pptp_remote'][0],
2908
	'HOSTV4'
2909
));
2910

    
2911
$section->addInput(new Form_Checkbox(
2912
	'pptp_dialondemand',
2913
	'Dial on demand',
2914
	'Enable Dial-On-Demand mode ',
2915
	$pconfig['pptp_dialondemand'],
2916
	'enable'
2917
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2918
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2919

    
2920
$section->addInput(new Form_Input(
2921
	'pptp_idletimeout',
2922
	'Idle timeout (seconds)',
2923
	'number',
2924
	$pconfig['pptp_idletimeout'],
2925
	['min' => 0]
2926
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2927
			'An idle timeout of zero disables this feature.');
2928

    
2929
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2930
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2931
} else {
2932
	$mlppp_text = "";
2933
}
2934

    
2935
$section->addInput(new Form_Button(
2936
	'btnadvppp',
2937
	'Advanced and MLPPP',
2938
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2939
	'fa-cog'
2940
))->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);
2941

    
2942
$form->add($section);
2943

    
2944
// Wireless interface
2945
if (isset($wancfg['wireless'])) {
2946

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

    
2949
	$section->addInput(new Form_Checkbox(
2950
		'persistcommonwireless',
2951
		'Persist common settings',
2952
		'Preserve common wireless configuration through interface deletions and reassignments.',
2953
		$pconfig['persistcommonwireless'],
2954
		'yes'
2955
	));
2956

    
2957
	$mode_list = ['auto' => 'Auto'];
2958

    
2959
	if (is_array($wl_modes)) {
2960
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2961
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2962
		}
2963
	}
2964

    
2965
	if (count($mode_list) == 1) {
2966
		$mode_list[''] = '';
2967
	}
2968

    
2969
	$section->addInput(new Form_Select(
2970
		'standard',
2971
		'Standard',
2972
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2973
		$mode_list
2974
	));
2975

    
2976
	if (isset($wl_modes['11g'])) {
2977
		$section->addInput(new Form_Select(
2978
			'protmode',
2979
			'802.11g OFDM Protection Mode',
2980
			$pconfig['protmode'],
2981
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2982
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2983
	} else {
2984
		$section->addInput(new Form_Input(
2985
			'protmode',
2986
			null,
2987
			'hidden',
2988
			'off'
2989
		));
2990
	}
2991

    
2992
	$mode_list = ['0' => gettext('Auto')];
2993

    
2994
	if (is_array($wl_modes)) {
2995
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2996
			if ($wl_standard == "11g") {
2997
				$wl_standard = "11b/g";
2998
			} else if ($wl_standard == "11ng") {
2999
				$wl_standard = "11b/g/n";
3000
			} else if ($wl_standard == "11na") {
3001
				$wl_standard = "11a/n";
3002
			}
3003

    
3004
			foreach ($wl_channels as $wl_channel) {
3005
				if (isset($wl_chaninfo[$wl_channel])) {
3006
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
3007
				} else {
3008
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3009
				}
3010
			}
3011
		}
3012
	}
3013

    
3014
	$section->addInput(new Form_Select(
3015
		'channel',
3016
		'Channel',
3017
		$pconfig['channel'],
3018
		$mode_list
3019
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3020
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3021

    
3022
	if (ANTENNAS) {
3023
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3024
			$group = new Form_Group('Antenna Settings');
3025

    
3026
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3027
				$group->add(new Form_Select(
3028
					'diversity',
3029
					null,
3030
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3031
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3032
				))->setHelp('Diversity');
3033
			}
3034

    
3035
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3036
				$group->add(new Form_Select(
3037
					'txantenna',
3038
					null,
3039
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3040
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3041
				))->setHelp('Transmit antenna');
3042
			}
3043

    
3044
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3045
				$group->add(new Form_Select(
3046
					'rxantenna',
3047
					null,
3048
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3049
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3050
				))->setHelp('Receive antenna');
3051
			}
3052

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

    
3055
			$section->add($group);
3056
		}
3057
	}
3058

    
3059
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3060
			$section->addInput(new Form_Input(
3061
				'distance',
3062
				'Distance setting (meters)',
3063
				'test',
3064
				$pconfig['distance']
3065
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3066
	}
3067

    
3068
	$form->add($section);
3069

    
3070
	// Regulatory settings
3071
	$section = new Form_Section('Regulatory Settings');
3072

    
3073
	$domain_list = array("" => 'Default');
3074

    
3075
	if (is_array($wl_regdomains)) {
3076
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3077
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3078
		}
3079
	}
3080

    
3081
	$section->addInput(new Form_Select(
3082
		'regdomain',
3083
		'Regulatory domain',
3084
		$pconfig['regdomain'],
3085
		$domain_list
3086
	))->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');
3087

    
3088
	$country_list = array('' => 'Default');
3089

    
3090
	if (is_array($wl_countries)) {
3091
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3092
			$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']);
3093
		}
3094
	}
3095

    
3096
	$section->addInput(new Form_Select(
3097
		'regcountry',
3098
		'Country',
3099
		$pconfig['regcountry'],
3100
		$country_list
3101
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3102

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

    
3114
	$form->add($section);
3115

    
3116
	$section = new Form_Section('Network-Specific Wireless Configuration');
3117

    
3118
	$section->addInput(new Form_Select(
3119
		'mode',
3120
		'Mode',
3121
		$pconfig['mode'],
3122
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3123
	));
3124

    
3125
	$section->addInput(new Form_Input(
3126
		'ssid',
3127
		'SSID',
3128
		'text',
3129
		$pconfig['ssid']
3130
	));
3131

    
3132
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3133
		$section->addInput(new Form_Select(
3134
			'puremode',
3135
			'Minimum wireless standard',
3136
			$pconfig['puremode'],
3137
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3138
		))->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)');
3139
	} elseif (isset($wl_modes['11g'])) {
3140
		$section->addInput(new Form_Checkbox(
3141
			'puremode',
3142
			'802.11g only',
3143
			null,
3144
			$pconfig['puremode'],
3145
			'11g'
3146
		))->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)');
3147
	}
3148

    
3149
	$section->addInput(new Form_Checkbox(
3150
		'apbridge_enable',
3151
		'Allow intra-BSS communication',
3152
		'Allow packets to pass between wireless clients directly when operating as an access point',
3153
		$pconfig['apbridge_enable'],
3154
		'yes'
3155
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3156

    
3157
	$section->addInput(new Form_Checkbox(
3158
		'wme_enable',
3159
		'Enable WME',
3160
		'Force the card to use WME (wireless QoS)',
3161
		$pconfig['wme_enable'],
3162
		'yes'
3163
	));
3164

    
3165
	$section->addInput(new Form_Checkbox(
3166
		'hidessid_enable',
3167
		'Hide SSID',
3168
		'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.)',
3169
		$pconfig['hidessid_enable'],
3170
		'yes'
3171
	));
3172

    
3173
	$form->add($section);
3174

    
3175
	// WPA Section
3176
	$section = new Form_Section('WPA');
3177

    
3178
	$section->addInput(new Form_Checkbox(
3179
		'wpa_enable',
3180
		'Enable',
3181
		'Enable WPA',
3182
		$pconfig['wpa_enable'],
3183
		'yes'
3184
	));
3185

    
3186
	$section->addInput(new Form_Input(
3187
		'passphrase',
3188
		'WPA Pre-Shared Key',
3189
		'text',
3190
		$pconfig['passphrase']
3191
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3192

    
3193
	$section->addInput(new Form_Select(
3194
		'wpa_mode',
3195
		'WPA mode',
3196
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3197
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3198
	));
3199

    
3200
	$section->addInput(new Form_Select(
3201
		'wpa_key_mgmt',
3202
		'WPA Key Management Mode',
3203
		$pconfig['wpa_key_mgmt'],
3204
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3205
	));
3206

    
3207
	$section->addInput(new Form_Select(
3208
		'wpa_pairwise',
3209
		'WPA Pairwise',
3210
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3211
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3212
	));
3213

    
3214
	$section->addInput(new Form_Input(
3215
		'wpa_group_rekey',
3216
		'Group Key Rotation',
3217
		'number',
3218
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3219
		['min' => '1', 'max' => 9999]
3220
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3221

    
3222
	$section->addInput(new Form_Input(
3223
		'wpa_gmk_rekey',
3224
		'Group Master Key Regeneration',
3225
		'number',
3226
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3227
		['min' => '1', 'max' => 9999]
3228
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3229

    
3230
	$section->addInput(new Form_Checkbox(
3231
		'wpa_strict_rekey',
3232
		'Strict Key Regeneration',
3233
		'Force the AP to rekey whenever a client disassociates',
3234
		$pconfig['wpa_strict_rekey'],
3235
		'yes'
3236
	));
3237

    
3238
	$form->add($section);
3239

    
3240
	$section = new Form_Section('802.1x RADIUS Options');
3241

    
3242
	$section->addInput(new Form_Checkbox(
3243
		'ieee8021x',
3244
		'IEEE802.1X',
3245
		'Enable 802.1X authentication',
3246
		$pconfig['ieee8021x'],
3247
		'yes'
3248
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3249

    
3250
	$group = new Form_Group('Primary 802.1X server');
3251

    
3252
	$group->add(new Form_IpAddress(
3253
		'auth_server_addr',
3254
		'IP Address',
3255
		$pconfig['auth_server_addr']
3256
	))->setHelp('IP address of the RADIUS server');
3257

    
3258
	$group->add(new Form_Input(
3259
		'auth_server_port',
3260
		'Port',
3261
		'number',
3262
		$pconfig['auth_server_port']
3263
	))->setHelp('Server auth port. Default is 1812');
3264

    
3265
	$group->add(new Form_Input(
3266
		'auth_server_shared_secret',
3267
		'Shared Secret',
3268
		'text',
3269
		$pconfig['auth_server_shared_secret']
3270
	))->setHelp('RADIUS Shared secret for this firewall');
3271

    
3272
	$section->add($group);
3273

    
3274
	$group = new Form_Group('Secondary 802.1X server');
3275

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

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

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

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

    
3298
	$section->addInput(new Form_Checkbox(
3299
		'rsn_preauth',
3300
		'Authentication Roaming Preauth',
3301
		null,
3302
		$pconfig['rsn_preauth'],
3303
		'yes'
3304
	));
3305

    
3306
	$form->add($section);
3307
}
3308

    
3309
$section = new Form_Section('Reserved Networks');
3310

    
3311
$section->addInput(new Form_Checkbox(
3312
	'blockpriv',
3313
	'Block private networks and loopback addresses',
3314
	'',
3315
	$pconfig['blockpriv'],
3316
	'yes'
3317
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3318
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3319
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3320

    
3321
$section->addInput(new Form_Checkbox(
3322
	'blockbogons',
3323
	'Block bogon networks',
3324
	'',
3325
	$pconfig['blockbogons'],
3326
	'yes'
3327
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3328
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3329
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3330

    
3331
$form->add($section);
3332

    
3333
$form->addGlobal(new Form_Input(
3334
	'if',
3335
	null,
3336
	'hidden',
3337
	$if
3338
));
3339

    
3340
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3341
	$form->addGlobal(new Form_Input(
3342
		'ppp_port',
3343
		null,
3344
		'hidden',
3345
		$pconfig['port']
3346
	));
3347
}
3348

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

    
3356

    
3357
// Add new gateway modal pop-up
3358
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3359

    
3360
$modal->addInput(new Form_Checkbox(
3361
	'defaultgw4',
3362
	'Default',
3363
	'Default gateway',
3364
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3365
));
3366

    
3367
$modal->addInput(new Form_Input(
3368
	'gatewayname4',
3369
	'Gateway name',
3370
	'text',
3371
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3372
));
3373

    
3374
$modal->addInput(new Form_IpAddress(
3375
	'gatewayip4',
3376
	'Gateway IPv4',
3377
	$gateway_settings4['gateway'],
3378
	'V4'
3379
));
3380

    
3381
$modal->addInput(new Form_Input(
3382
	'gatewaydescr4',
3383
	'Description',
3384
	'text',
3385
	$gateway_settings4['descr']
3386
));
3387

    
3388
$btnaddgw4 = new Form_Button(
3389
	'add4',
3390
	'Add',
3391
	null,
3392
	'fa-plus'
3393
);
3394

    
3395
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3396

    
3397
$btncnxgw4 = new Form_Button(
3398
	'cnx4',
3399
	'Cancel',
3400
	null,
3401
	'fa-undo'
3402
);
3403

    
3404
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3405

    
3406
$modal->addInput(new Form_StaticText(
3407
	null,
3408
	$btnaddgw4 . $btncnxgw4
3409
));
3410

    
3411
$form->add($modal);
3412

    
3413
print($form);
3414
?>
3415

    
3416
<script type="text/javascript">
3417
//<![CDATA[
3418
events.push(function() {
3419
	function updateType(t) {
3420

    
3421
		switch (t) {
3422
			case "none": {
3423
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3424
				break;
3425
			}
3426
			case "staticv4": {
3427
				$('.dhcpadvanced, .none, .dhcp').hide();
3428
				$('.pppoe, .pptp, .ppp').hide();
3429
				break;
3430
			}
3431
			case "dhcp": {
3432
				$('.dhcpadvanced, .none').hide();
3433
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3434
										//			about the staticv4 class
3435
				$('.pppoe, .pptp, .ppp').hide();
3436
				break;
3437
			}
3438
			case "ppp": {
3439
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3440
				country_list();
3441
				break;
3442
			}
3443
			case "pppoe": {
3444
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3445
				break;
3446
			}
3447
			case "l2tp":
3448
			case "pptp": {
3449
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3450
				$('.pptp').show();
3451
				break;
3452
			}
3453
		}
3454

    
3455
		if (t != "l2tp" && t != "pptp") {
3456
			$('.'+t).show();
3457
		}
3458
	}
3459

    
3460
	function updateTypeSix(t) {
3461
		if (!isNaN(t[0])) {
3462
			t = '_' + t;
3463
		}
3464

    
3465
		switch (t) {
3466
			case "none": {
3467
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3468
				break;
3469
			}
3470
			case "staticv6": {
3471
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3472
				break;
3473
			}
3474
			case "slaac": {
3475
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3476
				break;
3477
			}
3478
			case "dhcp6": {
3479
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3480
				break;
3481
			}
3482
			case "_6rd": {
3483
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3484
				break;
3485
			}
3486
			case "_6to4": {
3487
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3488
				break;
3489
			}
3490
			case "track6": {
3491
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3492
				update_track6_prefix();
3493
				break;
3494
			}
3495
		}
3496

    
3497
		if (t != "l2tp" && t != "pptp") {
3498
			$('.'+t).show();
3499
		}
3500
	}
3501

    
3502
	function show_reset_settings(reset_type) {
3503
		if (reset_type == 'preset') {
3504
			$('.pppoepreset').show();
3505
			$('.pppoecustom').hide();
3506
		} else if (reset_type == 'custom') {
3507
			$('.pppoecustom').show();
3508
			$('.pppoepreset').hide();
3509
		} else {
3510
			$('.pppoecustom').hide();
3511
			$('.pppoepreset').hide();
3512
		}
3513
	}
3514

    
3515
	function update_track6_prefix() {
3516
		var iface = $("#track6-interface").val();
3517
		if (iface == null) {
3518
			return;
3519
		}
3520

    
3521
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3522
		if (track6_prefix_ids == null) {
3523
			return;
3524
		}
3525

    
3526
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3527
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3528
	}
3529

    
3530
	function addOption_v4() {
3531
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3532
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3533
	}
3534

    
3535
	function addOption_v6() {
3536
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3537
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3538
	}
3539

    
3540
	function addSelectboxOption(selectbox, text, value) {
3541
		var optn = document.createElement("OPTION");
3542
		optn.text = text;
3543
		optn.value = value;
3544
		selectbox.append(optn);
3545
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3546
	}
3547

    
3548
	function country_list() {
3549
		$('#country').children().remove();
3550
		$('#provider_list').children().remove();
3551
		$('#providerplan').children().remove();
3552
		$.ajax("getserviceproviders.php",{
3553
			success: function(response) {
3554

    
3555
				var responseTextArr = response.split("\n");
3556
				responseTextArr.sort();
3557

    
3558
				responseTextArr.forEach( function(value) {
3559
					country = value.split(":");
3560
					$('#country').append($('<option>', {
3561
						value: country[1],
3562
						text : country[0]
3563
					}));
3564
				});
3565
			}
3566
		});
3567
	}
3568

    
3569
	function providers_list() {
3570
		$('#provider_list').children().remove();
3571
		$('#providerplan').children().remove();
3572
		$.ajax("getserviceproviders.php",{
3573
			type: 'post',
3574
			data: {country : $('#country').val()},
3575
			success: function(response) {
3576
				var responseTextArr = response.split("\n");
3577
				responseTextArr.sort();
3578
				responseTextArr.forEach( function(value) {
3579
					$('#provider_list').append($('<option>', {
3580
							value: value,
3581
							text : value
3582
					}));
3583
				});
3584
			}
3585
		});
3586
	}
3587

    
3588
	function providerplan_list() {
3589
		$('#providerplan').children().remove();
3590
		$.ajax("getserviceproviders.php",{
3591
			type: 'post',
3592
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3593
			success: function(response) {
3594
				var responseTextArr = response.split("\n");
3595
				responseTextArr.sort();
3596

    
3597
				$('#providerplan').append($('<option>', {
3598
					value: '',
3599
					text : ''
3600
				}));
3601

    
3602
				responseTextArr.forEach( function(value) {
3603
					if (value != "") {
3604
						providerplan = value.split(":");
3605

    
3606
						$('#providerplan').append($('<option>', {
3607
							value: providerplan[1],
3608
							text : providerplan[0] + " - " + providerplan[1]
3609
						}));
3610
					}
3611
				});
3612
			}
3613
		});
3614
	}
3615

    
3616
	function prefill_provider() {
3617
		$.ajax("getserviceproviders.php",{
3618
			type: 'post',
3619
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3620
			success: function(data, textStatus, response) {
3621
				var xmldoc = response.responseXML;
3622
				var provider = xmldoc.getElementsByTagName('connection')[0];
3623
				$('#ppp_username').val('');
3624
				$('#ppp_password').val('');
3625
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3626
					$('#phone').val('#777');
3627
					$('#apn').val('');
3628
				} else {
3629
					$('#phone').val('*99#');
3630
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3631
				}
3632
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3633
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3634
				$('#ppp_username').val(ppp_username);
3635
				$('#ppp_password').val(ppp_password);
3636
			}
3637
		});
3638
	}
3639

    
3640
	function show_dhcp6adv() {
3641
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3642
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3643

    
3644
		hideCheckbox('dhcp6usev4iface', ovr);
3645
		hideCheckbox('dhcp6prefixonly', ovr);
3646
		hideInput('dhcp6-ia-pd-len', ovr);
3647
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3648
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3649

    
3650
		hideClass('dhcp6advanced', !adv || ovr);
3651
	}
3652

    
3653
	function setDHCPoptions() {
3654
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3655
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3656

    
3657
		if (ovr) {
3658
			hideInput('dhcphostname', true);
3659
			hideIpAddress('alias-address', true);
3660
			hideInput('dhcprejectfrom', true);
3661
			hideInput('adv_dhcp_config_file_override_path', false);
3662
			hideClass('dhcpadvanced', true);
3663
		} else {
3664
			hideInput('dhcphostname', false);
3665
			hideIpAddress('alias-address', false);
3666
			hideInput('dhcprejectfrom', false);
3667
			hideInput('adv_dhcp_config_file_override_path', true);
3668
			hideClass('dhcpadvanced', !adv);
3669
		}
3670
	}
3671

    
3672
	// DHCP preset actions
3673
	// Set presets from value of radio buttons
3674
	function setPresets(val) {
3675
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3676
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3677
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3678
		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']);?>");
3679
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3680
	}
3681

    
3682
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3683
		$('#adv_dhcp_pt_timeout').val(timeout);
3684
		$('#adv_dhcp_pt_retry').val(retry);
3685
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3686
		$('#adv_dhcp_pt_reboot').val(reboot);
3687
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3688
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3689
	}
3690

    
3691
	function setPPPoEDialOnDemandItems() {
3692
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3693
	}
3694

    
3695
	function setPPTPDialOnDemandItems() {
3696
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3697
	}
3698

    
3699
	// ---------- On initial page load ------------------------------------------------------------
3700

    
3701
	updateType($('#type').val());
3702
	updateTypeSix($('#type6').val());
3703
	show_reset_settings($('#pppoe-reset-type').val());
3704
	hideClass('dhcp6advanced', true);
3705
	hideClass('dhcpadvanced', true);
3706
	show_dhcp6adv();
3707
	setDHCPoptions();
3708
	setPPPoEDialOnDemandItems();
3709
	setPPTPDialOnDemandItems();
3710

    
3711
	// Set preset buttons on page load
3712
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3713
	if (sv == "") {
3714
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3715
	} else {
3716
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3717
	}
3718

    
3719
	// Set preset from value
3720
	setPresets(sv);
3721

    
3722
	// If the user wants to add a gateway, then add that to the gateway selection
3723
	if ($("#gatewayip4").val() != '') {
3724
		addOption_v4();
3725
	}
3726
	if ($("#gatewayip6").val() != '') {
3727
		addOption_v6();
3728
	}
3729

    
3730
	// ---------- Click checkbox handlers ---------------------------------------------------------
3731

    
3732
	$('#type').on('change', function() {
3733
		updateType(this.value);
3734
	});
3735

    
3736
	$('#type6').on('change', function() {
3737
		updateTypeSix(this.value);
3738
	});
3739

    
3740
	$('#track6-interface').on('change', function() {
3741
		update_track6_prefix();
3742
	});
3743

    
3744
	$('#pppoe-reset-type').on('change', function() {
3745
		show_reset_settings(this.value);
3746
	});
3747

    
3748
	$("#add4").click(function() {
3749
		addOption_v4();
3750
		$("#newgateway4").modal('hide');
3751
	});
3752

    
3753
	$("#cnx4").click(function() {
3754
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3755
		$("#gatewayip4").val('');
3756
		$("#gatewaydescr4").val('');
3757
		$("#defaultgw4").prop("checked", false);
3758
		$("#newgateway4").modal('hide');
3759
	});
3760

    
3761
	$("#add6").click(function() {
3762
		addOption_v6();
3763
		$("#newgateway6").modal('hide');
3764
	});
3765

    
3766
	$("#cnx6").click(function() {
3767
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3768
		$("#gatewayip6").val('');
3769
		$("#gatewaydescr6").val('');
3770
		$("#defaultgw6").prop("checked", false);
3771
		$("#newgateway6").modal('hide');
3772
	});
3773

    
3774
	$('#country').on('change', function() {
3775
		providers_list();
3776
	});
3777

    
3778
	$('#provider_list').on('change', function() {
3779
		providerplan_list();
3780
	});
3781

    
3782
	$('#providerplan').on('change', function() {
3783
		prefill_provider();
3784
	});
3785

    
3786
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3787
		setDHCPoptions();
3788
	});
3789

    
3790
	$('#adv_dhcp6_config_advanced').click(function () {
3791
		show_dhcp6adv();
3792
	});
3793

    
3794
	$('#adv_dhcp6_config_file_override').click(function () {
3795
		show_dhcp6adv();
3796
	});
3797

    
3798
	// On click . .
3799
	$('#pppoe_dialondemand').click(function () {
3800
		setPPPoEDialOnDemandItems();
3801
	});
3802

    
3803
	$('#pptp_dialondemand').click(function () {
3804
		setPPTPDialOnDemandItems();
3805
	});
3806

    
3807
	$('[name=adv_dhcp_pt_values]').click(function () {
3808
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3809
	});
3810

    
3811
	$('#pppoe_resetdate').datepicker();
3812

    
3813
});
3814
//]]>
3815
</script>
3816

    
3817
<?php include("foot.inc");
(71-71/235)