Project

General

Profile

Download (127 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
$wancfg = &$config['interfaces'][$if];
99
$old_wancfg = $wancfg;
100
$old_wancfg['realif'] = get_real_interface($if);
101
$old_ppps = $a_ppps;
102

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
416
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
417

    
418
}
419

    
420
$changes_applied = false;
421

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

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

    
458
		/* sync filter configuration */
459
		setup_gateways_monitor();
460

    
461
		clear_subsystem_dirty('interfaces');
462

    
463
		$retval |= filter_configure();
464

    
465
		enable_rrd_graphing();
466

    
467
		$changes_applied = true;
468

    
469
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
470
			clear_subsystem_dirty('staticroutes');
471
		}
472
	}
473
	@unlink("{$g['tmp_path']}/.interfaces.apply");
474
} else if ($_POST['save']) {
475

    
476
	unset($input_errors);
477
	$pconfig = $_POST;
478

    
479
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
480
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
481
	} else {
482
		$pconfig['track6-prefix-id'] = 0;
483
	}
484

    
485
	/* filter out spaces from descriptions */
486
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
487

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

    
502
	/* input validation */
503
	$reqdfields = explode(" ", "descr");
504
	$reqdfieldsn = array(gettext("Description"));
505
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
506

    
507
	if (!$input_errors) {
508
		/* description unique? */
509
		foreach ($ifdescrs as $ifent => $ifdescr) {
510
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
511
				$input_errors[] = gettext("An interface with the specified description already exists.");
512
				break;
513
			}
514
		}
515

    
516
		/* Is the description already used as an alias name? */
517
		if (is_array($config['aliases']['alias'])) {
518
			foreach ($config['aliases']['alias'] as $alias) {
519
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
520
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
521
				}
522
			}
523
		}
524

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

    
534
		if (is_numeric($_POST['descr'])) {
535
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
536
		}
537

    
538
		/*
539
		 * Packages (e.g. tinc) create interface groups, reserve this
540
		 * namespace pkg_ for them.
541
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
542
		 */
543
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
544
			$input_errors[] = gettext("The interface description cannot start with pkg_");
545
		}
546
	}
547

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

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

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

    
684
			if (empty($_POST['track6-interface'])) {
685
				$input_errors[] = gettext("A valid interface to track must be selected.");
686
			}
687

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

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

    
727
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
728
			if ($_POST['subnet'] < 31) {
729
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
730
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
731
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
732
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
733
				}
734
			}
735

    
736
			foreach ($staticroutes as $route_subnet) {
737
				list($network, $subnet) = explode("/", $route_subnet);
738
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
739
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
740
					break;
741
				}
742
				unset($network, $subnet);
743
			}
744
		}
745
	}
746
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
747
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
748

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

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

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

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

    
862
		unset($min_mtu, $max_mtu);
863

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

    
882
				$realhwif_array = get_parent_interface($ifdata['if']);
883
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
884
				$parent_realhwif = $realhwif_array[0];
885

    
886
				if ($parent_realhwif != $wancfg['if']) {
887
					continue;
888
				}
889

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

    
977
		if ($_POST['passphrase']) {
978
			$passlen = strlen($_POST['passphrase']);
979
			if ($passlen < 8 || $passlen > 63) {
980
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
981
			}
982
		}
983

    
984
		if ($_POST['wpa_enable'] == "yes") {
985
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
986
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
987
			}
988
		}
989
	}
990

    
991
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
992
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
993
	}
994

    
995
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
996
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
997
	}
998

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

    
1003
	if ($_POST['gatewayip4']) {
1004
		// The user wants to add an IPv4 gateway - validate the settings
1005
		$gateway_settings4 = array();
1006

    
1007
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1008
		$gateway_settings4['interface'] = $_POST['if'];
1009
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1010
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1011
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1012
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1013
		foreach ($gw_input_errors as $input_error_text) {
1014
			$input_errors[] = $input_error_text;
1015
		}
1016
	}
1017

    
1018
	if ($_POST['gatewayip6']) {
1019
		// The user wants to add an IPv6 gateway - validate the settings
1020
		$gateway_settings6 = array();
1021

    
1022
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1023
		$gateway_settings6['interface'] = $_POST['if'];
1024
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1025
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1026
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1027
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1028
		foreach ($gw_input_errors as $input_error_text) {
1029
			$input_errors[] = $input_error_text;
1030
		}
1031
	}
1032

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

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

    
1081
		unset($wancfg['adv_dhcp_pt_timeout']);
1082
		unset($wancfg['adv_dhcp_pt_retry']);
1083
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1084
		unset($wancfg['adv_dhcp_pt_reboot']);
1085
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1086
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1087

    
1088
		unset($wancfg['adv_dhcp_pt_values']);
1089

    
1090
		unset($wancfg['adv_dhcp_send_options']);
1091
		unset($wancfg['adv_dhcp_request_options']);
1092
		unset($wancfg['adv_dhcp_required_options']);
1093
		unset($wancfg['adv_dhcp_option_modifiers']);
1094

    
1095
		unset($wancfg['adv_dhcp_config_advanced']);
1096
		unset($wancfg['adv_dhcp_config_file_override']);
1097
		unset($wancfg['adv_dhcp_config_file_override_path']);
1098

    
1099
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1100
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1101
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1102
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1103

    
1104
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1105
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1106
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1107
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1108
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1109

    
1110
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1111
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1112
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1113
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1114
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1115

    
1116
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1117
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1118
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1119

    
1120
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1121
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1122
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1123
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1124

    
1125
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1126
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1127
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1128
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1129
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1130

    
1131
		unset($wancfg['adv_dhcp6_config_advanced']);
1132
		unset($wancfg['adv_dhcp6_config_file_override']);
1133
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1134

    
1135
		unset($wancfg['pppoe_password']);
1136
		unset($wancfg['pptp_username']);
1137
		unset($wancfg['pptp_password']);
1138
		unset($wancfg['provider']);
1139
		unset($wancfg['ondemand']);
1140
		unset($wancfg['timeout']);
1141
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1142
			unset($wancfg['pppoe']['pppoe-reset-type']);
1143
		}
1144
		unset($wancfg['local']);
1145

    
1146
		unset($wancfg['remote']);
1147
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1148
			if ($wancfg['ipaddr'] != 'ppp') {
1149
				unset($a_ppps[$pppid]['apn']);
1150
				unset($a_ppps[$pppid]['phone']);
1151
				unset($a_ppps[$pppid]['provider']);
1152
				unset($a_ppps[$pppid]['ondemand']);
1153
			}
1154
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1155
				unset($a_ppps[$pppid]['localip']);
1156
				unset($a_ppps[$pppid]['subnet']);
1157
				unset($a_ppps[$pppid]['gateway']);
1158
			}
1159
			if ($wancfg['ipaddr'] != 'pppoe') {
1160
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1161
			}
1162
			if ($wancfg['type'] != $_POST['type']) {
1163
				unset($a_ppps[$pppid]['idletimeout']);
1164
			}
1165
		}
1166

    
1167
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1168
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1169

    
1170
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1171
		switch ($_POST['type']) {
1172
			case "staticv4":
1173
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1174
				$wancfg['subnet'] = $_POST['subnet'];
1175
				if ($_POST['gateway'] != "none") {
1176
					$wancfg['gateway'] = $_POST['gateway'];
1177
				}
1178
				break;
1179
			case "dhcp":
1180
				$wancfg['ipaddr'] = "dhcp";
1181
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1182
				$wancfg['alias-address'] = $_POST['alias-address'];
1183
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1184
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1185

    
1186
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1187
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1188
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1189
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1190
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1191
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1192

    
1193
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1194

    
1195
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1196
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1197
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1198
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1199

    
1200
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1201
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1202
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1203

    
1204
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1205
				if ($gateway_item) {
1206
					$a_gateways[] = $gateway_item;
1207
				}
1208
				break;
1209
			case "ppp":
1210
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1211
				$a_ppps[$pppid]['type'] = $_POST['type'];
1212
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1213
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1214
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1215
				if ($_POST['ppp_password'] != DMYPWD) {
1216
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1217
				}
1218
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1219
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1220
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1221
				$wancfg['ipaddr'] = $_POST['type'];
1222
				break;
1223

    
1224
			case "pppoe":
1225
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1226
				$a_ppps[$pppid]['type'] = $_POST['type'];
1227
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1228
				if (isset($_POST['ppp_port'])) {
1229
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1230
				} else {
1231
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1232
				}
1233
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1234
				if ($_POST['pppoe_password'] != DMYPWD) {
1235
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1236
				}
1237
				if (!empty($_POST['provider'])) {
1238
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1239
				} else {
1240
					$a_ppps[$pppid]['provider'] = true;
1241
				}
1242
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1243
				if (!empty($_POST['pppoe_idletimeout'])) {
1244
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1245
				} else {
1246
					unset($a_ppps[$pppid]['idletimeout']);
1247
				}
1248

    
1249
				if (!empty($_POST['pppoe-reset-type'])) {
1250
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1251
				} else {
1252
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1253
				}
1254
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1255
				$wancfg['ipaddr'] = $_POST['type'];
1256
				if ($gateway_item) {
1257
					$a_gateways[] = $gateway_item;
1258
				}
1259

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

    
1328
				if ($_POST['dhcp6withoutra'] == "yes") {
1329
					$wancfg['dhcp6withoutra'] = true;
1330
				}
1331
				if ($_POST['dhcp6norelease'] == "yes") {
1332
					$wancfg['dhcp6norelease'] = true;
1333
				}
1334
				if ($_POST['dhcp6vlanenable'] == "yes") {
1335
					$wancfg['dhcp6vlanenable'] = true;
1336
				}
1337
				if (!empty($_POST['dhcp6cvpt'])) {
1338
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1339
				} else {
1340
					unset($wancfg['dhcp6cvpt']);
1341
				}
1342

    
1343
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1344
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1345
				}
1346
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1347
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1348
				}
1349
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1350
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1351
				}
1352
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1353
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1354
				}
1355

    
1356
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1357
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1358
				}
1359
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1360
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1361
				}
1362
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1363
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1364
				}
1365
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1366
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1367
				}
1368
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1369
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1370
				}
1371

    
1372
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1373
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1374
				}
1375
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1376
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1377
				}
1378
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1379
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1380
				}
1381
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1382
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1383
				}
1384
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1385
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1386
				}
1387

    
1388
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1389
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1390
				}
1391
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1392
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1395
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1396
				}
1397
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1398
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1399
				}
1400
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1401
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1402
				}
1403
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1404
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1405
				}
1406
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1407
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1408
				}
1409

    
1410
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1411
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1412
				}
1413
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1414
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1415
				}
1416
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1417
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1418
				}
1419
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1420
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1421
				}
1422
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1423
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1424
				}
1425

    
1426
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1427
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1428
				}
1429
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1430
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1431
				}
1432
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1433
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1434
				}
1435

    
1436
				if ($gateway_item) {
1437
					$a_gateways[] = $gateway_item;
1438
				}
1439
				break;
1440
			case "6rd":
1441
				$wancfg['ipaddrv6'] = "6rd";
1442
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1443
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1444
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1445
				if ($gateway_item) {
1446
					$a_gateways[] = $gateway_item;
1447
				}
1448
				break;
1449
			case "6to4":
1450
				$wancfg['ipaddrv6'] = "6to4";
1451
				break;
1452
			case "track6":
1453
				$wancfg['ipaddrv6'] = "track6";
1454
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1455
				if ($_POST['track6-prefix-id--hex'] === "") {
1456
					$wancfg['track6-prefix-id'] = 0;
1457
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1458
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1459
				} else {
1460
					$wancfg['track6-prefix-id'] = 0;
1461
				}
1462
				break;
1463
			case "none":
1464
				break;
1465
		}
1466
		handle_pppoe_reset($_POST);
1467

    
1468
		if ($_POST['blockpriv'] == "yes") {
1469
			$wancfg['blockpriv'] = true;
1470
		} else {
1471
			unset($wancfg['blockpriv']);
1472
		}
1473
		if ($_POST['blockbogons'] == "yes") {
1474
			$wancfg['blockbogons'] = true;
1475
		} else {
1476
			unset($wancfg['blockbogons']);
1477
		}
1478
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1479
		if (empty($_POST['mtu'])) {
1480
			unset($wancfg['mtu']);
1481
		} else {
1482
			$wancfg['mtu'] = $_POST['mtu'];
1483
		}
1484
		if (empty($_POST['mss'])) {
1485
			unset($wancfg['mss']);
1486
		} else {
1487
			$wancfg['mss'] = $_POST['mss'];
1488
		}
1489
		if (empty($_POST['mediaopt'])) {
1490
			unset($wancfg['media']);
1491
			unset($wancfg['mediaopt']);
1492
		} else {
1493
			$mediaopts = explode(' ', $_POST['mediaopt']);
1494
			if ($mediaopts[0] != '') {
1495
				$wancfg['media'] = $mediaopts[0];
1496
			}
1497
			if ($mediaopts[1] != '') {
1498
				$wancfg['mediaopt'] = $mediaopts[1];
1499
			} else {
1500
				unset($wancfg['mediaopt']);
1501
			}
1502
		}
1503
		if (isset($wancfg['wireless'])) {
1504
			handle_wireless_post();
1505
		}
1506

    
1507
		write_config();
1508

    
1509
		if ($_POST['gatewayip4']) {
1510
			save_gateway($gateway_settings4);
1511
		}
1512

    
1513
		if ($_POST['gatewayip6']) {
1514
			save_gateway($gateway_settings6);
1515
		}
1516

    
1517
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1518
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1519
		} else {
1520
			$toapplylist = array();
1521
		}
1522
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1523
		$toapplylist[$if]['ppps'] = $old_ppps;
1524
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1525

    
1526
		mark_subsystem_dirty('interfaces');
1527

    
1528
		/* regenerate cron settings/crontab file */
1529
		configure_cron();
1530

    
1531
		header("Location: interfaces.php?if={$if}");
1532
		exit;
1533
	}
1534

    
1535
} // end if ($_POST['save'])
1536

    
1537
function handle_wireless_post() {
1538
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1539
	if (!is_array($wancfg['wireless'])) {
1540
		$wancfg['wireless'] = array();
1541
	}
1542
	$wancfg['wireless']['standard'] = $_POST['standard'];
1543
	$wancfg['wireless']['mode'] = $_POST['mode'];
1544
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1545
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1546
	$wancfg['wireless']['channel'] = $_POST['channel'];
1547
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1548
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1549
	$wancfg['wireless']['distance'] = $_POST['distance'];
1550
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1551
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1552
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1553
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1554
		foreach ($wl_countries_attr as $wl_country) {
1555
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1556
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1557
				break;
1558
			}
1559
		}
1560
	}
1561
	if (!is_array($wancfg['wireless']['wpa'])) {
1562
		$wancfg['wireless']['wpa'] = array();
1563
	}
1564
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1565
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1566
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1567
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1568
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1569
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1570
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1571
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1572
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1573
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1574
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1575
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1576
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1577
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1578

    
1579
	if ($_POST['persistcommonwireless'] == "yes") {
1580
		if (!is_array($config['wireless'])) {
1581
			$config['wireless'] = array();
1582
		}
1583
		if (!is_array($config['wireless']['interfaces'])) {
1584
			$config['wireless']['interfaces'] = array();
1585
		}
1586
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1587
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1588
		}
1589
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1590
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1591
	}
1592
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1593
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1594
	} else if (isset($wancfg['wireless']['diversity'])) {
1595
		unset($wancfg['wireless']['diversity']);
1596
	}
1597
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1598
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1599
	} else if (isset($wancfg['wireless']['txantenna'])) {
1600
		unset($wancfg['wireless']['txantenna']);
1601
	}
1602
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1603
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1604
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1605
		unset($wancfg['wireless']['rxantenna']);
1606
	}
1607
	if ($_POST['hidessid_enable'] == "yes") {
1608
		$wancfg['wireless']['hidessid']['enable'] = true;
1609
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1610
		unset($wancfg['wireless']['hidessid']['enable']);
1611
	}
1612
	if ($_POST['mac_acl_enable'] == "yes") {
1613
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1614
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1615
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1616
	}
1617
	if ($_POST['rsn_preauth'] == "yes") {
1618
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1619
	} else {
1620
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1621
	}
1622
	if ($_POST['ieee8021x'] == "yes") {
1623
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1624
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1625
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1626
	}
1627
	if ($_POST['wpa_strict_rekey'] == "yes") {
1628
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1629
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1630
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1631
	}
1632
	if ($_POST['debug_mode'] == "yes") {
1633
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1634
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1635
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1636
	}
1637
	if ($_POST['wpa_enable'] == "yes") {
1638
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1639
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1640
		unset($wancfg['wireless']['wpa']['enable']);
1641
	}
1642

    
1643
	if ($_POST['wme_enable'] == "yes") {
1644
		if (!is_array($wancfg['wireless']['wme'])) {
1645
			$wancfg['wireless']['wme'] = array();
1646
		}
1647
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1648
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1649
		unset($wancfg['wireless']['wme']['enable']);
1650
	}
1651
	if ($_POST['puremode'] == "11g") {
1652
		if (!is_array($wancfg['wireless']['pureg'])) {
1653
			$wancfg['wireless']['pureg'] = array();
1654
		}
1655
		$wancfg['wireless']['pureg']['enable'] = true;
1656
	} else if ($_POST['puremode'] == "11n") {
1657
		if (!is_array($wancfg['wireless']['puren'])) {
1658
			$wancfg['wireless']['puren'] = array();
1659
		}
1660
		$wancfg['wireless']['puren']['enable'] = true;
1661
	} else {
1662
		if (isset($wancfg['wireless']['pureg'])) {
1663
			unset($wancfg['wireless']['pureg']);
1664
		}
1665
		if (isset($wancfg['wireless']['puren'])) {
1666
			unset($wancfg['wireless']['puren']);
1667
		}
1668
	}
1669
	if ($_POST['apbridge_enable'] == "yes") {
1670
		if (!is_array($wancfg['wireless']['apbridge'])) {
1671
			$wancfg['wireless']['apbridge'] = array();
1672
		}
1673
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1674
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1675
		unset($wancfg['wireless']['apbridge']['enable']);
1676
	}
1677
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1678
		if (!is_array($wancfg['wireless']['turbo'])) {
1679
			$wancfg['wireless']['turbo'] = array();
1680
		}
1681
		$wancfg['wireless']['turbo']['enable'] = true;
1682
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1683
		unset($wancfg['wireless']['turbo']['enable']);
1684
	}
1685

    
1686
	interface_sync_wireless_clones($wancfg, true);
1687
}
1688

    
1689
function check_wireless_mode() {
1690
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1691

    
1692
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1693
		return;
1694
	}
1695

    
1696
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1697
		$clone_count = 1;
1698
	} else {
1699
		$clone_count = 0;
1700
	}
1701

    
1702
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1703
		foreach ($config['wireless']['clone'] as $clone) {
1704
			if ($clone['if'] == $wlanbaseif) {
1705
				$clone_count++;
1706
			}
1707
		}
1708
	}
1709

    
1710
	if ($clone_count > 1) {
1711
		$old_wireless_mode = $wancfg['wireless']['mode'];
1712
		$wancfg['wireless']['mode'] = $_POST['mode'];
1713
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1714
			$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']]);
1715
		} else {
1716
			pfSense_interface_destroy("{$wlanif}_");
1717
		}
1718
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1719
	}
1720
}
1721

    
1722
// Find all possible media options for the interface
1723
$mediaopts_list = array();
1724
$intrealname = $config['interfaces'][$if]['if'];
1725
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1726
foreach ($mediaopts as $mediaopt) {
1727
	preg_match("/media (.*)/", $mediaopt, $matches);
1728
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1729
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1730
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1731
	} else {
1732
		// there is only media like "media 1000baseT"
1733
		array_push($mediaopts_list, $matches[1]);
1734
	}
1735
}
1736

    
1737
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1738
$shortcut_section = "interfaces";
1739

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

    
1743
// Get the MAC address
1744
$ip = $_SERVER['REMOTE_ADDR'];
1745
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1746
$mymac = str_replace("\n", "", $mymac);
1747
$defgatewayname4 = $wancfg['descr'] . "GW";
1748
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1749

    
1750
function build_mediaopts_list() {
1751
	global $mediaopts_list;
1752

    
1753
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1754
			 " " =>	 gettext("------- Media Supported by this interface -------")
1755
			];
1756

    
1757
	foreach ($mediaopts_list as $mediaopt) {
1758
		$list[$mediaopt] = $mediaopt;
1759
	}
1760

    
1761
	return($list);
1762
}
1763

    
1764
function build_gateway_list() {
1765
	global $a_gateways, $if;
1766

    
1767
	$list = array("none" => gettext("None"));
1768
	foreach ($a_gateways as $gateway) {
1769
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1770
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1771
		}
1772
	}
1773

    
1774
	return($list);
1775
}
1776

    
1777
function build_gatewayv6_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_ipaddrv6($gateway['gateway']))) {
1783
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1784
		}
1785
	}
1786

    
1787
	return($list);
1788
}
1789

    
1790
include("head.inc");
1791

    
1792
if ($input_errors) {
1793
	print_input_errors($input_errors);
1794
}
1795

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

    
1802
if ($changes_applied) {
1803
	print_apply_result_box($retval);
1804
}
1805

    
1806
$form = new Form();
1807

    
1808
$section = new Form_Section('General Configuration');
1809

    
1810
$section->addInput(new Form_Checkbox(
1811
	'enable',
1812
	'Enable',
1813
	'Enable interface',
1814
	$pconfig['enable'],
1815
	'yes'
1816
));
1817

    
1818
$section->addInput(new Form_Input(
1819
	'descr',
1820
	'*Description',
1821
	'text',
1822
	$pconfig['descr']
1823
))->setHelp('Enter a description (name) for the interface here.');
1824

    
1825
$section->addInput(new Form_Select(
1826
	'type',
1827
	'IPv4 Configuration Type',
1828
	$pconfig['type'],
1829
	$types4
1830
));
1831

    
1832
$section->addInput(new Form_Select(
1833
	'type6',
1834
	'IPv6 Configuration Type',
1835
	$pconfig['type6'],
1836
	$types6
1837
));
1838

    
1839
$macaddress = new Form_Input(
1840
	'spoofmac',
1841
	'MAC Address',
1842
	'text',
1843
	$pconfig['spoofmac'],
1844
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1845
);
1846

    
1847
$btnmymac = new Form_Button(
1848
	'btnmymac',
1849
	'Copy My MAC',
1850
	null,
1851
	'fa-clone'
1852
	);
1853

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

    
1856
$group = new Form_Group('MAC Address');
1857
$group->add($macaddress);
1858
// $group->add($btnmymac);
1859
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1860
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1861
$section->add($group);
1862

    
1863
$section->addInput(new Form_Input(
1864
	'mtu',
1865
	'MTU',
1866
	'number',
1867
	$pconfig['mtu']
1868
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1869
			'This is typically 1500 bytes but can vary in some circumstances.');
1870

    
1871
$section->addInput(new Form_Input(
1872
	'mss',
1873
	'MSS',
1874
	'number',
1875
	$pconfig['mss']
1876
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1877
			'header size) will be in effect.');
1878

    
1879
if (count($mediaopts_list) > 0) {
1880
	$section->addInput(new Form_Select(
1881
		'mediaopt',
1882
		'Speed and Duplex',
1883
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1884
		build_mediaopts_list()
1885
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1886
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1887
}
1888

    
1889
$form->add($section);
1890

    
1891
$section = new Form_Section('Static IPv4 Configuration');
1892
$section->addClass('staticv4');
1893

    
1894
$section->addInput(new Form_IpAddress(
1895
	'ipaddr',
1896
	'*IPv4 Address',
1897
	$pconfig['ipaddr'],
1898
	'V4'
1899
))->addMask('subnet', $pconfig['subnet'], 32);
1900

    
1901
$group = new Form_Group('IPv4 Upstream gateway');
1902

    
1903
$group->add(new Form_Select(
1904
	'gateway',
1905
	'IPv4 Upstream Gateway',
1906
	$pconfig['gateway'],
1907
	build_gateway_list()
1908
));
1909

    
1910
$group->add(new Form_Button(
1911
	'addgw4',
1912
	'Add a new gateway',
1913
	null,
1914
	'fa-plus'
1915
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1916

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

    
1921
$section->add($group);
1922

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

    
1925
$section = new Form_Section('Static IPv6 Configuration');
1926
$section->addClass('staticv6');
1927

    
1928
$section->addInput(new Form_IpAddress(
1929
	'ipaddrv6',
1930
	'*IPv6 address',
1931
	$pconfig['ipaddrv6'],
1932
	'V6'
1933
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1934

    
1935
$section->addInput(new Form_Checkbox(
1936
	'ipv6usev4iface',
1937
	'Use IPv4 connectivity as parent interface',
1938
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1939
	$pconfig['ipv6usev4iface']
1940
));
1941

    
1942
$group = new Form_Group('IPv6 Upstream gateway');
1943

    
1944
$group->add(new Form_Select(
1945
	'gatewayv6',
1946
	'IPv6 Upstream Gateway',
1947
	$pconfig['gatewayv6'],
1948
	build_gatewayv6_list()
1949
));
1950

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

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

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

    
1964
// Add new gateway modal pop-up for IPv6
1965
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1966

    
1967
$modal->addInput(new Form_Checkbox(
1968
	'defaultgw6',
1969
	'Default',
1970
	'Default gateway',
1971
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
1972
));
1973

    
1974
$modal->addInput(new Form_Input(
1975
	'gatewayname6',
1976
	'Gateway name',
1977
	'text',
1978
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
1979
));
1980

    
1981
$modal->addInput(new Form_IpAddress(
1982
	'gatewayip6',
1983
	'Gateway IPv6',
1984
	$gateway_settings6['gateway'],
1985
	'V6'
1986
));
1987

    
1988
$modal->addInput(new Form_Input(
1989
	'gatewaydescr6',
1990
	'Description',
1991
	'text',
1992
	$gateway_settings6['descr']
1993
));
1994

    
1995
$btnaddgw6 = new Form_Button(
1996
	'add6',
1997
	'Add',
1998
	null,
1999
	'fa-plus'
2000
);
2001

    
2002
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2003

    
2004
$btncnxgw6 = new Form_Button(
2005
	'cnx6',
2006
	'Cancel',
2007
	null,
2008
	'fa-undo'
2009
);
2010

    
2011
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2012

    
2013
$modal->addInput(new Form_StaticText(
2014
	null,
2015
	$btnaddgw6 . $btncnxgw6
2016
));
2017

    
2018
$form->add($modal);
2019

    
2020
// ==== DHCP client configuration =============================
2021

    
2022
$section = new Form_Section('DHCP Client Configuration');
2023
$section->addClass('dhcp');
2024

    
2025
$group = new Form_Group('Options');
2026

    
2027
$group->add(new Form_Checkbox(
2028
	'adv_dhcp_config_advanced',
2029
	null,
2030
	'Advanced Configuration',
2031
	$pconfig['adv_dhcp_config_advanced']
2032
))->setHelp('Use advanced DHCP configuration options.');
2033

    
2034
$group->add(new Form_Checkbox(
2035
	'adv_dhcp_config_file_override',
2036
	null,
2037
	'Configuration Override',
2038
	$pconfig['adv_dhcp_config_file_override']
2039
))->setHelp('Override the configuration from this file.');
2040

    
2041
$section->add($group);
2042

    
2043
$section->addInput(new Form_Input(
2044
	'dhcphostname',
2045
	'Hostname',
2046
	'text',
2047
	$pconfig['dhcphostname']
2048
))->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).');
2049

    
2050
$section->addInput(new Form_IpAddress(
2051
	'alias-address',
2052
	'Alias IPv4 address',
2053
	$pconfig['alias-address'],
2054
	'V4'
2055
))->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.');
2056

    
2057
$section->addInput(new Form_Input(
2058
	'dhcprejectfrom',
2059
	'Reject leases from',
2060
	'text',
2061
	$pconfig['dhcprejectfrom']
2062
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2063
			'(separate multiple entries with a comma). ' .
2064
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2065

    
2066
$group = new Form_Group('Protocol timing');
2067
$group->addClass('dhcpadvanced');
2068

    
2069
$group->add(new Form_Input(
2070
	'adv_dhcp_pt_timeout',
2071
	null,
2072
	'number',
2073
	$pconfig['adv_dhcp_pt_timeout']
2074
))->setHelp('Timeout');
2075

    
2076
$group->add(new Form_Input(
2077
	'adv_dhcp_pt_retry',
2078
	null,
2079
	'number',
2080
	$pconfig['adv_dhcp_pt_retry']
2081
))->setHelp('Retry');
2082

    
2083
$group->add(new Form_Input(
2084
	'adv_dhcp_pt_select_timeout',
2085
	null,
2086
	'number',
2087
	$pconfig['adv_dhcp_pt_select_timeout'],
2088
	['min' => 0]
2089
))->setHelp('Select timeout');
2090

    
2091
$group->add(new Form_Input(
2092
	'adv_dhcp_pt_reboot',
2093
	null,
2094
	'number',
2095
	$pconfig['adv_dhcp_pt_reboot']
2096
))->setHelp('Reboot');
2097

    
2098
$group->add(new Form_Input(
2099
	'adv_dhcp_pt_backoff_cutoff',
2100
	null,
2101
	'number',
2102
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2103
))->setHelp('Backoff cutoff');
2104

    
2105
$group->add(new Form_Input(
2106
	'adv_dhcp_pt_initial_interval',
2107
	null,
2108
	'number',
2109
	$pconfig['adv_dhcp_pt_initial_interval']
2110
))->setHelp('Initial interval');
2111

    
2112
$section->add($group);
2113

    
2114
$group = new Form_Group('Presets');
2115
$group->addClass('dhcpadvanced');
2116

    
2117
$group->add(new Form_Checkbox(
2118
	'adv_dhcp_pt_values',
2119
	null,
2120
	'FreeBSD default',
2121
	null,
2122
	'DHCP'
2123
))->displayAsRadio();
2124

    
2125
$group->add(new Form_Checkbox(
2126
	'adv_dhcp_pt_values',
2127
	null,
2128
	'Clear',
2129
	null,
2130
	'Clear'
2131
))->displayAsRadio();
2132

    
2133
$group->add(new Form_Checkbox(
2134
	'adv_dhcp_pt_values',
2135
	null,
2136
	'pfSense Default',
2137
	null,
2138
	'pfSense'
2139
))->displayAsRadio();
2140

    
2141
$group->add(new Form_Checkbox(
2142
	'adv_dhcp_pt_values',
2143
	null,
2144
	'Saved Cfg',
2145
	null,
2146
	'SavedCfg'
2147
))->displayAsRadio();
2148

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

    
2152
$section->add($group);
2153

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

    
2164
$form->add($section);
2165

    
2166
$section = new Form_Section('Lease Requirements and Requests');
2167
$section->addClass('dhcpadvanced');
2168

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

    
2179
$section->addInput(new Form_Input(
2180
	'adv_dhcp_request_options',
2181
	'Request options',
2182
	'text',
2183
	$pconfig['adv_dhcp_request_options']
2184
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2185
			'Some ISPs may require certain options be or not be requested.', '<br />');
2186

    
2187
$section->addInput(new Form_Input(
2188
	'adv_dhcp_required_options',
2189
	'Require options',
2190
	'text',
2191
	$pconfig['adv_dhcp_required_options']
2192
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2193

    
2194
$section->addInput(new Form_Input(
2195
	'adv_dhcp_option_modifiers',
2196
	'Option modifiers',
2197
	'text',
2198
	$pconfig['adv_dhcp_option_modifiers']
2199
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2200
			'modifiers: (default, supersede, prepend, append) %1$s' .
2201
			'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>');
2202

    
2203
$form->add($section);
2204

    
2205
// DHCP6 client config
2206

    
2207
$section = new Form_Section('DHCP6 Client Configuration');
2208
$section->addClass('dhcp6');
2209

    
2210
$group = new Form_Group('Options');
2211

    
2212
$group->add(new Form_Checkbox(
2213
	'adv_dhcp6_config_advanced',
2214
	null,
2215
	'Advanced Configuration',
2216
	$pconfig['adv_dhcp6_config_advanced']
2217
))->setHelp('Use advanced DHCPv6 configuration options.');
2218

    
2219
$group->add(new Form_Checkbox(
2220
	'adv_dhcp6_config_file_override',
2221
	null,
2222
	'Configuration Override',
2223
	$pconfig['adv_dhcp6_config_file_override']
2224
))->setHelp('Override the configuration from this file.');
2225

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

    
2228
$section->addInput(new Form_Checkbox(
2229
	'dhcp6usev4iface',
2230
	'Use IPv4 connectivity as parent interface',
2231
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2232
	$pconfig['dhcp6usev4iface']
2233
));
2234

    
2235
$section->addInput(new Form_Checkbox(
2236
	'dhcp6prefixonly',
2237
	'Request only an IPv6 prefix',
2238
	'Only request an IPv6 prefix, do not request an IPv6 address',
2239
	$pconfig['dhcp6prefixonly']
2240
));
2241

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

    
2249
$section->addInput(new Form_Checkbox(
2250
	'dhcp6-ia-pd-send-hint',
2251
	'Send IPv6 prefix hint',
2252
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2253
	$pconfig['dhcp6-ia-pd-send-hint']
2254
));
2255

    
2256
$section->addInput(new Form_Checkbox(
2257
	'dhcp6debug',
2258
	'Debug',
2259
	'Start DHCP6 client in debug mode',
2260
	$pconfig['dhcp6debug']
2261
));
2262
$section->addInput(new Form_Checkbox(
2263
	'dhcp6withoutra',
2264
	'Do not wait for a RA',
2265
	'Required by some ISPs, especially those not using PPPoE',
2266
	$pconfig['dhcp6withoutra']
2267
));
2268
$section->addInput(new Form_Checkbox(
2269
	'dhcp6norelease',
2270
	'Do not allow PD/Address release',
2271
	'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',
2272
	$pconfig['dhcp6norelease']
2273
));
2274

    
2275
$group = new Form_Group('DHCP6 VLAN Priority');
2276

    
2277
$vlanprio = array(
2278
	"bk" => "Background (BK, 0)",
2279
	"be" => "Best Effort (BE, 1)",
2280
	"ee" => "Excellent Effort (EE, 2)",
2281
	"ca" => "Critical Applications (CA, 3)",
2282
	"vi" => "Video (VI, 4)",
2283
	"vo" => "Voice (VO, 5)",
2284
	"ic" => "Internetwork Control (IC, 6)",
2285
	"nc" => "Network Control (NC, 7)");
2286

    
2287
$group->add(new Form_Checkbox(
2288
	'dhcp6vlanenable',
2289
	null,
2290
	'Enable dhcp6c VLAN Priority tagging',
2291
	$pconfig['dhcp6vlanenable']
2292
))->setHelp('Normally off unless specifically required by the ISP.');
2293

    
2294
$group->add(new Form_Select(
2295
	'dhcp6cvpt',
2296
	'VLAN Prio',
2297
	$pconfig['dhcp6cvpt'],
2298
	$vlanprio
2299
))->setHelp('Choose 802.1p priority to set.');
2300

    
2301
$section->add($group);
2302

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

    
2313
$form->add($section);
2314

    
2315
// DHCP6 client config - Advanced
2316

    
2317
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2318
$section->addClass('dhcp6advanced');
2319

    
2320
$section->addInput(new Form_Checkbox(
2321
	'adv_dhcp6_interface_statement_information_only_enable',
2322
	'Information only',
2323
	'Exchange Information Only',
2324
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2325
	'Selected'
2326
))->setHelp('Only exchange informational configuration parameters with servers.');
2327

    
2328
$section->addInput(new Form_Input(
2329
	'adv_dhcp6_interface_statement_send_options',
2330
	'Send options',
2331
	'text',
2332
	$pconfig['adv_dhcp6_interface_statement_send_options']
2333
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2334
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2335
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2336
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2337

    
2338
$section->addInput(new Form_Input(
2339
	'adv_dhcp6_interface_statement_request_options',
2340
	'Request Options',
2341
	'text',
2342
	$pconfig['adv_dhcp6_interface_statement_request_options']
2343
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2344
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2345

    
2346
$section->addInput(new Form_Input(
2347
	'adv_dhcp6_interface_statement_script',
2348
	'Scripts',
2349
	'text',
2350
	$pconfig['adv_dhcp6_interface_statement_script']
2351
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2352
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2353

    
2354
$group = new Form_Group('Identity Association Statement');
2355

    
2356
$group->add(new Form_Checkbox(
2357
	'adv_dhcp6_id_assoc_statement_address_enable',
2358
	null,
2359
	'Non-Temporary Address Allocation',
2360
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2361
	'Selected'
2362
));
2363

    
2364
$group->add(new Form_Input(
2365
	'adv_dhcp6_id_assoc_statement_address_id',
2366
	null,
2367
	'text',
2368
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2369
))->sethelp('id-assoc na ID');
2370

    
2371
$group->add(new Form_IpAddress(
2372
	'adv_dhcp6_id_assoc_statement_address',
2373
	null,
2374
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2375
	'V6'
2376
))->sethelp('IPv6 address');
2377

    
2378
$group->add(new Form_Input(
2379
	'adv_dhcp6_id_assoc_statement_address_pltime',
2380
	null,
2381
	'text',
2382
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2383
))->sethelp('pltime');
2384

    
2385
$group->add(new Form_Input(
2386
	'adv_dhcp6_id_assoc_statement_address_vltime',
2387
	null,
2388
	'text',
2389
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2390
))->sethelp('vltime');
2391

    
2392
$section->add($group);
2393

    
2394
// Prefix delegation
2395
$group = new Form_Group('');
2396

    
2397
$group->add(new Form_Checkbox(
2398
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2399
	null,
2400
	'Prefix Delegation ',
2401
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2402
	'Selected'
2403
));
2404

    
2405
$group->add(new Form_Input(
2406
	'adv_dhcp6_id_assoc_statement_prefix_id',
2407
	null,
2408
	'text',
2409
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2410
))->sethelp('id-assoc pd ID');
2411

    
2412
$group->add(new Form_IpAddress(
2413
	'adv_dhcp6_id_assoc_statement_prefix',
2414
	null,
2415
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2416
	'V6'
2417
))->sethelp('IPv6 prefix');
2418

    
2419
$group->add(new Form_Input(
2420
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2421
	null,
2422
	'text',
2423
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2424
))->sethelp('pltime');
2425

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

    
2433
$section->add($group);
2434

    
2435
$group = new Form_Group('Prefix interface statement');
2436

    
2437
$group->add(new Form_Input(
2438
	'adv_dhcp6_prefix_interface_statement_sla_id',
2439
	null,
2440
	'text',
2441
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2442
))->sethelp('Prefix Interface sla-id');
2443

    
2444
$group->add(new Form_Input(
2445
	'adv_dhcp6_prefix_interface_statement_sla_len',
2446
	null,
2447
	'text',
2448
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2449
))->sethelp('sla-len');
2450

    
2451
$section->add($group);
2452

    
2453
$group = new Form_Group('Select prefix interface');
2454
$section->addInput(new Form_Select(
2455
	'adv_dhcp6_prefix_selected_interface',
2456
	'Prefix Interface',
2457
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2458
	$interfaces
2459
))->setHelp('Select the interface on which to apply the prefix delegation.');
2460

    
2461
$group = new Form_Group('Authentication statement');
2462

    
2463
$group->add(new Form_Input(
2464
	'adv_dhcp6_authentication_statement_authname',
2465
	null,
2466
	'text',
2467
	$pconfig['adv_dhcp6_authentication_statement_authname']
2468
))->sethelp('Authname');
2469

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

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

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

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

    
2493
$group = new Form_Group('Keyinfo statement');
2494

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

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

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

    
2511
$group = new Form_Group('');
2512

    
2513
$group->add(new Form_Input(
2514
	'adv_dhcp6_key_info_statement_keyid',
2515
	null,
2516
	'text',
2517
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2518
))->sethelp('KeyID');
2519

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

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

    
2534
$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>');
2535

    
2536
$section->add($group);
2537

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

    
2540
$section = new Form_Section('6RD Configuration');
2541
$section->addClass('_6rd');
2542

    
2543
$section->addInput(new Form_Input(
2544
	'prefix-6rd',
2545
	'6RD Prefix',
2546
	'text',
2547
	$pconfig['prefix-6rd']
2548
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2549

    
2550
$section->addInput(new Form_Input(
2551
	'gateway-6rd',
2552
	'*6RD Border relay',
2553
	'text',
2554
	$pconfig['gateway-6rd']
2555
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2556

    
2557
$section->addInput(new Form_Select(
2558
	'prefix-6rd-v4plen',
2559
	'6RD IPv4 Prefix length',
2560
	$pconfig['prefix-6rd-v4plen'],
2561
	array_combine(range(0, 32), range(0, 32))
2562
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2563

    
2564
$form->add($section);
2565

    
2566
// Track IPv6 ointerface section
2567
$section = new Form_Section('Track IPv6 Interface');
2568
$section->addClass('track6');
2569

    
2570
function build_ipv6interface_list() {
2571
	global $config, $section;
2572

    
2573
	$list = array('' => '');
2574

    
2575
	$interfaces = get_configured_interface_with_descr(true);
2576
	$dynv6ifs = array();
2577

    
2578
	foreach ($interfaces as $iface => $ifacename) {
2579
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2580
			case "6to4":
2581
			case "6rd":
2582
			case "dhcp6":
2583
				$dynv6ifs[$iface] = array(
2584
					'name' => $ifacename,
2585
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2586
				);
2587
				break;
2588
			default:
2589
				continue;
2590
		}
2591
	}
2592

    
2593
	foreach ($dynv6ifs as $iface => $ifacedata) {
2594
		$list[$iface] = $ifacedata['name'];
2595

    
2596
		$section->addInput(new Form_Input(
2597
			'ipv6-num-prefix-ids-' . $iface,
2598
			null,
2599
			'hidden',
2600
			$ifacedata['ipv6_num_prefix_ids']
2601
		));
2602
	}
2603

    
2604
	return($list);
2605
}
2606

    
2607
$section->addInput(new Form_Select(
2608
	'track6-interface',
2609
	'*IPv6 Interface',
2610
	$pconfig['track6-interface'],
2611
	build_ipv6interface_list()
2612
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2613

    
2614
if ($pconfig['track6-prefix-id'] == "") {
2615
	$pconfig['track6-prefix-id'] = 0;
2616
}
2617

    
2618
$section->addInput(new Form_Input(
2619
	'track6-prefix-id--hex',
2620
	'IPv6 Prefix ID',
2621
	'text',
2622
	sprintf("%x", $pconfig['track6-prefix-id'])
2623
))->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>');
2624

    
2625
$section->addInput(new Form_Input(
2626
	'track6-prefix-id-max',
2627
	null,
2628
	'hidden',
2629
	0
2630
));
2631

    
2632
$form->add($section);
2633

    
2634
/// PPP section
2635

    
2636
$section = new Form_Section('PPP Configuration');
2637
$section->addClass('ppp');
2638

    
2639
$section->addInput(new Form_Select(
2640
	'country',
2641
	'Country',
2642
	$pconfig['country'],
2643
	[]
2644
));
2645

    
2646
$section->addInput(new Form_Select(
2647
	'provider_list',
2648
	'Provider',
2649
	$pconfig['provider_list'],
2650
	[]
2651
));
2652

    
2653
$section->addInput(new Form_Select(
2654
	'providerplan',
2655
	'Plan',
2656
	$pconfig['providerplan'],
2657
	[]
2658
))->setHelp('Select to fill in service provider data.');
2659

    
2660
$section->addInput(new Form_Input(
2661
	'ppp_username',
2662
	'Username',
2663
	'text',
2664
	$pconfig['ppp_username']
2665
));
2666

    
2667
$section->addPassword(new Form_Input(
2668
	'ppp_password',
2669
	'Password',
2670
	'password',
2671
	$pconfig['ppp_password']
2672
));
2673

    
2674
$section->addInput(new Form_Input(
2675
	'phone',
2676
	'*Phone number',
2677
	'text',
2678
	$pconfig['phone']
2679
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2680

    
2681
$section->addInput(new Form_Input(
2682
	'apn',
2683
	'Access Point Name',
2684
	'text',
2685
	$pconfig['apn']
2686
));
2687

    
2688

    
2689
function build_port_list() {
2690
	$list = array("" => "None");
2691

    
2692
	$portlist = glob("/dev/cua*");
2693
	$modems	  = glob("/dev/modem*");
2694
	$portlist = array_merge($portlist, $modems);
2695

    
2696
	foreach ($portlist as $port) {
2697
		if (preg_match("/\.(lock|init)$/", $port)) {
2698
			continue;
2699
		}
2700

    
2701
	$list[trim($port)] = $port;
2702
	}
2703

    
2704
	return($list);
2705
}
2706

    
2707
$section->addInput(new Form_Select(
2708
	'port',
2709
	"*Modem port",
2710
	$pconfig['port'],
2711
	build_port_list()
2712
));
2713

    
2714
$section->addInput(new Form_Button(
2715
	'btnadvppp',
2716
	'Advanced PPP',
2717
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2718
	'fa-cog'
2719
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2720

    
2721
$form->add($section);
2722

    
2723
// PPPoE configuration
2724
$section = new Form_Section('PPPoE Configuration');
2725
$section->addClass('pppoe');
2726

    
2727
$section->addInput(new Form_Input(
2728
	'pppoe_username',
2729
	'*Username',
2730
	'text',
2731
	$pconfig['pppoe_username']
2732
));
2733

    
2734
$section->addPassword(new Form_Input(
2735
	'pppoe_password',
2736
	'*Password',
2737
	'password',
2738
	$pconfig['pppoe_password']
2739
));
2740

    
2741
$section->addInput(new Form_Input(
2742
	'provider',
2743
	'Service name',
2744
	'text',
2745
	$pconfig['provider']
2746
))->setHelp('This field can usually be left empty.');
2747

    
2748
$section->addInput(new Form_Checkbox(
2749
	'pppoe_dialondemand',
2750
	'Dial on demand',
2751
	'Enable Dial-On-Demand mode ',
2752
	$pconfig['pppoe_dialondemand'],
2753
	'enable'
2754
));
2755

    
2756
$section->addInput(new Form_Input(
2757
	'pppoe_idletimeout',
2758
	'Idle timeout',
2759
	'number',
2760
	$pconfig['pppoe_idletimeout'],
2761
	['min' => 0]
2762
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2763
			'An idle timeout of zero disables this feature.');
2764

    
2765
$section->addInput(new Form_Select(
2766
	'pppoe-reset-type',
2767
	'Periodic reset',
2768
	$pconfig['pppoe-reset-type'],
2769
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2770
))->setHelp('Select a reset timing type.');
2771

    
2772
$group = new Form_Group('Custom reset');
2773
$group->addClass('pppoecustom');
2774

    
2775
$group->add(new Form_Input(
2776
	'pppoe_resethour',
2777
	null,
2778
	'number',
2779
	$pconfig['pppoe_resethour'],
2780
	['min' => 0, 'max' => 23]
2781
))->setHelp('Hour (0-23)');
2782

    
2783
$group->add(new Form_Input(
2784
	'pppoe_resetminute',
2785
	null,
2786
	'number',
2787
	$pconfig['pppoe_resetminute'],
2788
	['min' => 0, 'max' => 59]
2789
))->setHelp('Minutes (0-59)');
2790

    
2791
$group->add(new Form_Input(
2792
	'pppoe_resetdate',
2793
	null,
2794
	'text',
2795
	$pconfig['pppoe_resetdate']
2796
))->setHelp('Specific date (mm/dd/yyyy)');
2797

    
2798
$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');
2799

    
2800
$section->add($group);
2801

    
2802
$group = new Form_MultiCheckboxGroup('cron based reset');
2803
$group->addClass('pppoepreset');
2804

    
2805
$group->add(new Form_MultiCheckbox(
2806
	'pppoe_pr_preset_val',
2807
	null,
2808
	'Reset at each month ("0 0 1 * *")',
2809
	$pconfig['pppoe_monthly'],
2810
	'monthly'
2811
))->displayAsRadio();
2812

    
2813
$group->add(new Form_MultiCheckbox(
2814
	'pppoe_pr_preset_val',
2815
	null,
2816
	'Reset at each week ("0 0 * * 0")',
2817
	$pconfig['pppoe_weekly'],
2818
	'weekly'
2819
))->displayAsRadio();
2820

    
2821
$group->add(new Form_MultiCheckbox(
2822
	'pppoe_pr_preset_val',
2823
	null,
2824
	'Reset at each day ("0 0 * * *")',
2825
	$pconfig['pppoe_daily'],
2826
	'daily'
2827
))->displayAsRadio();
2828

    
2829
$group->add(new Form_MultiCheckbox(
2830
	'pppoe_pr_preset_val',
2831
	null,
2832
	'Reset at each hour ("0 * * * *")',
2833
	$pconfig['pppoe_hourly'],
2834
	'hourly'
2835
))->displayAsRadio();
2836

    
2837
$section->add($group);
2838

    
2839
$section->addInput(new Form_Button(
2840
	'btnadvppp',
2841
	'Advanced and MLPPP',
2842
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2843
	'fa-cog'
2844
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2845

    
2846
$form->add($section);
2847

    
2848
// PPTP & L2TP Configuration section
2849
$section = new Form_Section('PPTP/L2TP Configuration');
2850
$section->addClass('pptp');
2851

    
2852
$section->addInput(new Form_Input(
2853
	'pptp_username',
2854
	'*Username',
2855
	'text',
2856
	$pconfig['pptp_username']
2857
));
2858

    
2859
$section->addPassword(new Form_Input(
2860
	'pptp_password',
2861
	'*Password',
2862
	'password',
2863
	$pconfig['pptp_password']
2864
));
2865

    
2866
$section->addInput(new Form_IpAddress(
2867
	'pptp_local0',
2868
	'*Local IP address',
2869
	$pconfig['pptp_localip'][0],
2870
	'V4'
2871
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2872

    
2873
$section->addInput(new Form_IpAddress(
2874
	'pptp_remote0',
2875
	'*Remote IP address',
2876
	$pconfig['pptp_remote'][0],
2877
	'HOSTV4'
2878
));
2879

    
2880
$section->addInput(new Form_Checkbox(
2881
	'pptp_dialondemand',
2882
	'Dial on demand',
2883
	'Enable Dial-On-Demand mode ',
2884
	$pconfig['pptp_dialondemand'],
2885
	'enable'
2886
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2887
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2888

    
2889
$section->addInput(new Form_Input(
2890
	'pptp_idletimeout',
2891
	'Idle timeout (seconds)',
2892
	'number',
2893
	$pconfig['pptp_idletimeout'],
2894
	['min' => 0]
2895
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2896
			'An idle timeout of zero disables this feature.');
2897

    
2898
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2899
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2900
} else {
2901
	$mlppp_text = "";
2902
}
2903

    
2904
$section->addInput(new Form_Button(
2905
	'btnadvppp',
2906
	'Advanced and MLPPP',
2907
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2908
	'fa-cog'
2909
))->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);
2910

    
2911
$form->add($section);
2912

    
2913
// Wireless interface
2914
if (isset($wancfg['wireless'])) {
2915

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

    
2918
	$section->addInput(new Form_Checkbox(
2919
		'persistcommonwireless',
2920
		'Persist common settings',
2921
		'Preserve common wireless configuration through interface deletions and reassignments.',
2922
		$pconfig['persistcommonwireless'],
2923
		'yes'
2924
	));
2925

    
2926
	$mode_list = ['auto' => 'Auto'];
2927

    
2928
	if (is_array($wl_modes)) {
2929
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2930
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2931
		}
2932
	}
2933

    
2934
	if (count($mode_list) == 1) {
2935
		$mode_list[''] = '';
2936
	}
2937

    
2938
	$section->addInput(new Form_Select(
2939
		'standard',
2940
		'Standard',
2941
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2942
		$mode_list
2943
	));
2944

    
2945
	if (isset($wl_modes['11g'])) {
2946
		$section->addInput(new Form_Select(
2947
			'protmode',
2948
			'802.11g OFDM Protection Mode',
2949
			$pconfig['protmode'],
2950
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2951
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2952
	} else {
2953
		$section->addInput(new Form_Input(
2954
			'protmode',
2955
			null,
2956
			'hidden',
2957
			'off'
2958
		));
2959
	}
2960

    
2961
	$mode_list = ['0' => gettext('Auto')];
2962

    
2963
	if (is_array($wl_modes)) {
2964
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2965
			if ($wl_standard == "11g") {
2966
				$wl_standard = "11b/g";
2967
			} else if ($wl_standard == "11ng") {
2968
				$wl_standard = "11b/g/n";
2969
			} else if ($wl_standard == "11na") {
2970
				$wl_standard = "11a/n";
2971
			}
2972

    
2973
			foreach ($wl_channels as $wl_channel) {
2974
				if (isset($wl_chaninfo[$wl_channel])) {
2975
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2976
				} else {
2977
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2978
				}
2979
			}
2980
		}
2981
	}
2982

    
2983
	$section->addInput(new Form_Select(
2984
		'channel',
2985
		'Channel',
2986
		$pconfig['channel'],
2987
		$mode_list
2988
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2989
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2990

    
2991
	if (ANTENNAS) {
2992
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2993
			$group = new Form_Group('Antenna Settings');
2994

    
2995
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2996
				$group->add(new Form_Select(
2997
					'diversity',
2998
					null,
2999
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3000
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3001
				))->setHelp('Diversity');
3002
			}
3003

    
3004
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3005
				$group->add(new Form_Select(
3006
					'txantenna',
3007
					null,
3008
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3009
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3010
				))->setHelp('Transmit antenna');
3011
			}
3012

    
3013
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3014
				$group->add(new Form_Select(
3015
					'rxantenna',
3016
					null,
3017
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3018
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3019
				))->setHelp('Receive antenna');
3020
			}
3021

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

    
3024
			$section->add($group);
3025
		}
3026
	}
3027

    
3028
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3029
			$section->addInput(new Form_Input(
3030
				'distance',
3031
				'Distance setting (meters)',
3032
				'test',
3033
				$pconfig['distance']
3034
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3035
	}
3036

    
3037
	$form->add($section);
3038

    
3039
	// Regulatory settings
3040
	$section = new Form_Section('Regulatory Settings');
3041

    
3042
	$domain_list = array("" => 'Default');
3043

    
3044
	if (is_array($wl_regdomains)) {
3045
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3046
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3047
		}
3048
	}
3049

    
3050
	$section->addInput(new Form_Select(
3051
		'regdomain',
3052
		'Regulatory domain',
3053
		$pconfig['regdomain'],
3054
		$domain_list
3055
	))->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');
3056

    
3057
	$country_list = array('' => 'Default');
3058

    
3059
	if (is_array($wl_countries)) {
3060
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3061
			$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']);
3062
		}
3063
	}
3064

    
3065
	$section->addInput(new Form_Select(
3066
		'regcountry',
3067
		'Country',
3068
		$pconfig['regcountry'],
3069
		$country_list
3070
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3071

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

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

    
3085
	$section = new Form_Section('Network-Specific Wireless Configuration');
3086

    
3087
	$section->addInput(new Form_Select(
3088
		'mode',
3089
		'Mode',
3090
		$pconfig['mode'],
3091
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3092
	));
3093

    
3094
	$section->addInput(new Form_Input(
3095
		'ssid',
3096
		'SSID',
3097
		'text',
3098
		$pconfig['ssid']
3099
	));
3100

    
3101
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3102
		$section->addInput(new Form_Select(
3103
			'puremode',
3104
			'Minimum wireless standard',
3105
			$pconfig['puremode'],
3106
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3107
		))->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)');
3108
	} elseif (isset($wl_modes['11g'])) {
3109
		$section->addInput(new Form_Checkbox(
3110
			'puremode',
3111
			'802.11g only',
3112
			null,
3113
			$pconfig['puremode'],
3114
			'11g'
3115
		))->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)');
3116
	}
3117

    
3118
	$section->addInput(new Form_Checkbox(
3119
		'apbridge_enable',
3120
		'Allow intra-BSS communication',
3121
		'Allow packets to pass between wireless clients directly when operating as an access point',
3122
		$pconfig['apbridge_enable'],
3123
		'yes'
3124
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3125

    
3126
	$section->addInput(new Form_Checkbox(
3127
		'wme_enable',
3128
		'Enable WME',
3129
		'Force the card to use WME (wireless QoS)',
3130
		$pconfig['wme_enable'],
3131
		'yes'
3132
	));
3133

    
3134
	$section->addInput(new Form_Checkbox(
3135
		'hidessid_enable',
3136
		'Hide SSID',
3137
		'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.)',
3138
		$pconfig['hidessid_enable'],
3139
		'yes'
3140
	));
3141

    
3142
	$form->add($section);
3143

    
3144
	// WPA Section
3145
	$section = new Form_Section('WPA');
3146

    
3147
	$section->addInput(new Form_Checkbox(
3148
		'wpa_enable',
3149
		'Enable',
3150
		'Enable WPA',
3151
		$pconfig['wpa_enable'],
3152
		'yes'
3153
	));
3154

    
3155
	$section->addInput(new Form_Input(
3156
		'passphrase',
3157
		'WPA Pre-Shared Key',
3158
		'text',
3159
		$pconfig['passphrase']
3160
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3161

    
3162
	$section->addInput(new Form_Select(
3163
		'wpa_mode',
3164
		'WPA mode',
3165
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3166
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3167
	));
3168

    
3169
	$section->addInput(new Form_Select(
3170
		'wpa_key_mgmt',
3171
		'WPA Key Management Mode',
3172
		$pconfig['wpa_key_mgmt'],
3173
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3174
	));
3175

    
3176
	$section->addInput(new Form_Select(
3177
		'wpa_pairwise',
3178
		'WPA Pairwise',
3179
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3180
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3181
	));
3182

    
3183
	$section->addInput(new Form_Input(
3184
		'wpa_group_rekey',
3185
		'Group Key Rotation',
3186
		'number',
3187
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3188
		['min' => '1', 'max' => 9999]
3189
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3190

    
3191
	$section->addInput(new Form_Input(
3192
		'wpa_gmk_rekey',
3193
		'Group Master Key Regeneration',
3194
		'number',
3195
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3196
		['min' => '1', 'max' => 9999]
3197
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3198

    
3199
	$section->addInput(new Form_Checkbox(
3200
		'wpa_strict_rekey',
3201
		'Strict Key Regeneration',
3202
		'Force the AP to rekey whenever a client disassociates',
3203
		$pconfig['wpa_strict_rekey'],
3204
		'yes'
3205
	));
3206

    
3207
	$form->add($section);
3208

    
3209
	$section = new Form_Section('802.1x RADIUS Options');
3210

    
3211
	$section->addInput(new Form_Checkbox(
3212
		'ieee8021x',
3213
		'IEEE802.1X',
3214
		'Enable 802.1X authentication',
3215
		$pconfig['ieee8021x'],
3216
		'yes'
3217
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3218

    
3219
	$group = new Form_Group('Primary 802.1X server');
3220

    
3221
	$group->add(new Form_IpAddress(
3222
		'auth_server_addr',
3223
		'IP Address',
3224
		$pconfig['auth_server_addr']
3225
	))->setHelp('IP address of the RADIUS server');
3226

    
3227
	$group->add(new Form_Input(
3228
		'auth_server_port',
3229
		'Port',
3230
		'number',
3231
		$pconfig['auth_server_port']
3232
	))->setHelp('Server auth port. Default is 1812');
3233

    
3234
	$group->add(new Form_Input(
3235
		'auth_server_shared_secret',
3236
		'Shared Secret',
3237
		'text',
3238
		$pconfig['auth_server_shared_secret']
3239
	))->setHelp('RADIUS Shared secret for this firewall');
3240

    
3241
	$section->add($group);
3242

    
3243
	$group = new Form_Group('Secondary 802.1X server');
3244

    
3245
	$group->add(new Form_IpAddress(
3246
		'auth_server_addr2',
3247
		'IP Address',
3248
		$pconfig['auth_server_addr2']
3249
	))->setHelp('IP address of the RADIUS server');
3250

    
3251
	$group->add(new Form_Input(
3252
		'auth_server_port2',
3253
		'Port',
3254
		'number',
3255
		$pconfig['auth_server_port2']
3256
	))->setHelp('Server auth port. Default is 1812');
3257

    
3258
	$group->add(new Form_Input(
3259
		'auth_server_shared_secret2',
3260
		'Shared Secret',
3261
		'text',
3262
		$pconfig['auth_server_shared_secret2']
3263
	))->setHelp('RADIUS Shared secret for this firewall');
3264

    
3265
	$section->add($group);
3266

    
3267
	$section->addInput(new Form_Checkbox(
3268
		'rsn_preauth',
3269
		'Authentication Roaming Preauth',
3270
		null,
3271
		$pconfig['rsn_preauth'],
3272
		'yes'
3273
	));
3274

    
3275
	$form->add($section);
3276
}
3277

    
3278
$section = new Form_Section('Reserved Networks');
3279

    
3280
$section->addInput(new Form_Checkbox(
3281
	'blockpriv',
3282
	'Block private networks and loopback addresses',
3283
	'',
3284
	$pconfig['blockpriv'],
3285
	'yes'
3286
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3287
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3288
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3289

    
3290
$section->addInput(new Form_Checkbox(
3291
	'blockbogons',
3292
	'Block bogon networks',
3293
	'',
3294
	$pconfig['blockbogons'],
3295
	'yes'
3296
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3297
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3298
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3299

    
3300
$form->add($section);
3301

    
3302
$form->addGlobal(new Form_Input(
3303
	'if',
3304
	null,
3305
	'hidden',
3306
	$if
3307
));
3308

    
3309
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3310
	$form->addGlobal(new Form_Input(
3311
		'ppp_port',
3312
		null,
3313
		'hidden',
3314
		$pconfig['port']
3315
	));
3316
}
3317

    
3318
$form->addGlobal(new Form_Input(
3319
	'ptpid',
3320
	null,
3321
	'hidden',
3322
	$pconfig['ptpid']
3323
));
3324

    
3325

    
3326
// Add new gateway modal pop-up
3327
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3328

    
3329
$modal->addInput(new Form_Checkbox(
3330
	'defaultgw4',
3331
	'Default',
3332
	'Default gateway',
3333
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3334
));
3335

    
3336
$modal->addInput(new Form_Input(
3337
	'gatewayname4',
3338
	'Gateway name',
3339
	'text',
3340
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3341
));
3342

    
3343
$modal->addInput(new Form_IpAddress(
3344
	'gatewayip4',
3345
	'Gateway IPv4',
3346
	$gateway_settings4['gateway'],
3347
	'V4'
3348
));
3349

    
3350
$modal->addInput(new Form_Input(
3351
	'gatewaydescr4',
3352
	'Description',
3353
	'text',
3354
	$gateway_settings4['descr']
3355
));
3356

    
3357
$btnaddgw4 = new Form_Button(
3358
	'add4',
3359
	'Add',
3360
	null,
3361
	'fa-plus'
3362
);
3363

    
3364
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3365

    
3366
$btncnxgw4 = new Form_Button(
3367
	'cnx4',
3368
	'Cancel',
3369
	null,
3370
	'fa-undo'
3371
);
3372

    
3373
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3374

    
3375
$modal->addInput(new Form_StaticText(
3376
	null,
3377
	$btnaddgw4 . $btncnxgw4
3378
));
3379

    
3380
$form->add($modal);
3381

    
3382
print($form);
3383
?>
3384

    
3385
<script type="text/javascript">
3386
//<![CDATA[
3387
events.push(function() {
3388
	function updateType(t) {
3389

    
3390
		switch (t) {
3391
			case "none": {
3392
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3393
				break;
3394
			}
3395
			case "staticv4": {
3396
				$('.dhcpadvanced, .none, .dhcp').hide();
3397
				$('.pppoe, .pptp, .ppp').hide();
3398
				break;
3399
			}
3400
			case "dhcp": {
3401
				$('.dhcpadvanced, .none').hide();
3402
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3403
										//			about the staticv4 class
3404
				$('.pppoe, .pptp, .ppp').hide();
3405
				break;
3406
			}
3407
			case "ppp": {
3408
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3409
				country_list();
3410
				break;
3411
			}
3412
			case "pppoe": {
3413
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3414
				break;
3415
			}
3416
			case "l2tp":
3417
			case "pptp": {
3418
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3419
				$('.pptp').show();
3420
				break;
3421
			}
3422
		}
3423

    
3424
		if (t != "l2tp" && t != "pptp") {
3425
			$('.'+t).show();
3426
		}
3427
	}
3428

    
3429
	function updateTypeSix(t) {
3430
		if (!isNaN(t[0])) {
3431
			t = '_' + t;
3432
		}
3433

    
3434
		switch (t) {
3435
			case "none": {
3436
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3437
				break;
3438
			}
3439
			case "staticv6": {
3440
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3441
				break;
3442
			}
3443
			case "slaac": {
3444
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3445
				break;
3446
			}
3447
			case "dhcp6": {
3448
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3449
				break;
3450
			}
3451
			case "_6rd": {
3452
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3453
				break;
3454
			}
3455
			case "_6to4": {
3456
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3457
				break;
3458
			}
3459
			case "track6": {
3460
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3461
				update_track6_prefix();
3462
				break;
3463
			}
3464
		}
3465

    
3466
		if (t != "l2tp" && t != "pptp") {
3467
			$('.'+t).show();
3468
		}
3469
	}
3470

    
3471
	function show_reset_settings(reset_type) {
3472
		if (reset_type == 'preset') {
3473
			$('.pppoepreset').show();
3474
			$('.pppoecustom').hide();
3475
		} else if (reset_type == 'custom') {
3476
			$('.pppoecustom').show();
3477
			$('.pppoepreset').hide();
3478
		} else {
3479
			$('.pppoecustom').hide();
3480
			$('.pppoepreset').hide();
3481
		}
3482
	}
3483

    
3484
	function update_track6_prefix() {
3485
		var iface = $("#track6-interface").val();
3486
		if (iface == null) {
3487
			return;
3488
		}
3489

    
3490
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3491
		if (track6_prefix_ids == null) {
3492
			return;
3493
		}
3494

    
3495
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3496
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3497
	}
3498

    
3499
	function addOption_v4() {
3500
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3501
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3502
	}
3503

    
3504
	function addOption_v6() {
3505
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3506
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3507
	}
3508

    
3509
	function addSelectboxOption(selectbox, text, value) {
3510
		var optn = document.createElement("OPTION");
3511
		optn.text = text;
3512
		optn.value = value;
3513
		selectbox.append(optn);
3514
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3515
	}
3516

    
3517
	function country_list() {
3518
		$('#country').children().remove();
3519
		$('#provider_list').children().remove();
3520
		$('#providerplan').children().remove();
3521
		$.ajax("getserviceproviders.php",{
3522
			success: function(response) {
3523

    
3524
				var responseTextArr = response.split("\n");
3525
				responseTextArr.sort();
3526

    
3527
				responseTextArr.forEach( function(value) {
3528
					country = value.split(":");
3529
					$('#country').append($('<option>', {
3530
						value: country[1],
3531
						text : country[0]
3532
					}));
3533
				});
3534
			}
3535
		});
3536
	}
3537

    
3538
	function providers_list() {
3539
		$('#provider_list').children().remove();
3540
		$('#providerplan').children().remove();
3541
		$.ajax("getserviceproviders.php",{
3542
			type: 'post',
3543
			data: {country : $('#country').val()},
3544
			success: function(response) {
3545
				var responseTextArr = response.split("\n");
3546
				responseTextArr.sort();
3547
				responseTextArr.forEach( function(value) {
3548
					$('#provider_list').append($('<option>', {
3549
							value: value,
3550
							text : value
3551
					}));
3552
				});
3553
			}
3554
		});
3555
	}
3556

    
3557
	function providerplan_list() {
3558
		$('#providerplan').children().remove();
3559
		$.ajax("getserviceproviders.php",{
3560
			type: 'post',
3561
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3562
			success: function(response) {
3563
				var responseTextArr = response.split("\n");
3564
				responseTextArr.sort();
3565

    
3566
				$('#providerplan').append($('<option>', {
3567
					value: '',
3568
					text : ''
3569
				}));
3570

    
3571
				responseTextArr.forEach( function(value) {
3572
					if (value != "") {
3573
						providerplan = value.split(":");
3574

    
3575
						$('#providerplan').append($('<option>', {
3576
							value: providerplan[1],
3577
							text : providerplan[0] + " - " + providerplan[1]
3578
						}));
3579
					}
3580
				});
3581
			}
3582
		});
3583
	}
3584

    
3585
	function prefill_provider() {
3586
		$.ajax("getserviceproviders.php",{
3587
			type: 'post',
3588
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3589
			success: function(data, textStatus, response) {
3590
				var xmldoc = response.responseXML;
3591
				var provider = xmldoc.getElementsByTagName('connection')[0];
3592
				$('#ppp_username').val('');
3593
				$('#ppp_password').val('');
3594
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3595
					$('#phone').val('#777');
3596
					$('#apn').val('');
3597
				} else {
3598
					$('#phone').val('*99#');
3599
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3600
				}
3601
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3602
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3603
				$('#ppp_username').val(ppp_username);
3604
				$('#ppp_password').val(ppp_password);
3605
			}
3606
		});
3607
	}
3608

    
3609
	function show_dhcp6adv() {
3610
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3611
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3612

    
3613
		hideCheckbox('dhcp6usev4iface', ovr);
3614
		hideCheckbox('dhcp6prefixonly', ovr);
3615
		hideInput('dhcp6-ia-pd-len', ovr);
3616
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3617
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3618

    
3619
		hideClass('dhcp6advanced', !adv || ovr);
3620
	}
3621

    
3622
	function setDHCPoptions() {
3623
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3624
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3625

    
3626
		if (ovr) {
3627
			hideInput('dhcphostname', true);
3628
			hideIpAddress('alias-address', true);
3629
			hideInput('dhcprejectfrom', true);
3630
			hideInput('adv_dhcp_config_file_override_path', false);
3631
			hideClass('dhcpadvanced', true);
3632
		} else {
3633
			hideInput('dhcphostname', false);
3634
			hideIpAddress('alias-address', false);
3635
			hideInput('dhcprejectfrom', false);
3636
			hideInput('adv_dhcp_config_file_override_path', true);
3637
			hideClass('dhcpadvanced', !adv);
3638
		}
3639
	}
3640

    
3641
	// DHCP preset actions
3642
	// Set presets from value of radio buttons
3643
	function setPresets(val) {
3644
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3645
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3646
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3647
		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']);?>");
3648
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3649
	}
3650

    
3651
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3652
		$('#adv_dhcp_pt_timeout').val(timeout);
3653
		$('#adv_dhcp_pt_retry').val(retry);
3654
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3655
		$('#adv_dhcp_pt_reboot').val(reboot);
3656
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3657
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3658
	}
3659

    
3660
	function setPPPoEDialOnDemandItems() {
3661
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3662
	}
3663

    
3664
	function setPPTPDialOnDemandItems() {
3665
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3666
	}
3667

    
3668
	// ---------- On initial page load ------------------------------------------------------------
3669

    
3670
	updateType($('#type').val());
3671
	updateTypeSix($('#type6').val());
3672
	show_reset_settings($('#pppoe-reset-type').val());
3673
	hideClass('dhcp6advanced', true);
3674
	hideClass('dhcpadvanced', true);
3675
	show_dhcp6adv();
3676
	setDHCPoptions();
3677
	setPPPoEDialOnDemandItems();
3678
	setPPTPDialOnDemandItems();
3679

    
3680
	// Set preset buttons on page load
3681
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3682
	if (sv == "") {
3683
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3684
	} else {
3685
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3686
	}
3687

    
3688
	// Set preset from value
3689
	setPresets(sv);
3690

    
3691
	// If the user wants to add a gateway, then add that to the gateway selection
3692
	if ($("#gatewayip4").val() != '') {
3693
		addOption_v4();
3694
	}
3695
	if ($("#gatewayip6").val() != '') {
3696
		addOption_v6();
3697
	}
3698

    
3699
	// ---------- Click checkbox handlers ---------------------------------------------------------
3700

    
3701
	$('#type').on('change', function() {
3702
		updateType(this.value);
3703
	});
3704

    
3705
	$('#type6').on('change', function() {
3706
		updateTypeSix(this.value);
3707
	});
3708

    
3709
	$('#track6-interface').on('change', function() {
3710
		update_track6_prefix();
3711
	});
3712

    
3713
	$('#pppoe-reset-type').on('change', function() {
3714
		show_reset_settings(this.value);
3715
	});
3716

    
3717
	$("#add4").click(function() {
3718
		addOption_v4();
3719
		$("#newgateway4").modal('hide');
3720
	});
3721

    
3722
	$("#cnx4").click(function() {
3723
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3724
		$("#gatewayip4").val('');
3725
		$("#gatewaydescr4").val('');
3726
		$("#defaultgw4").prop("checked", false);
3727
		$("#newgateway4").modal('hide');
3728
	});
3729

    
3730
	$("#add6").click(function() {
3731
		addOption_v6();
3732
		$("#newgateway6").modal('hide');
3733
	});
3734

    
3735
	$("#cnx6").click(function() {
3736
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3737
		$("#gatewayip6").val('');
3738
		$("#gatewaydescr6").val('');
3739
		$("#defaultgw6").prop("checked", false);
3740
		$("#newgateway6").modal('hide');
3741
	});
3742

    
3743
	$('#country').on('change', function() {
3744
		providers_list();
3745
	});
3746

    
3747
	$('#provider_list').on('change', function() {
3748
		providerplan_list();
3749
	});
3750

    
3751
	$('#providerplan').on('change', function() {
3752
		prefill_provider();
3753
	});
3754

    
3755
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3756
		setDHCPoptions();
3757
	});
3758

    
3759
	$('#adv_dhcp6_config_advanced').click(function () {
3760
		show_dhcp6adv();
3761
	});
3762

    
3763
	$('#adv_dhcp6_config_file_override').click(function () {
3764
		show_dhcp6adv();
3765
	});
3766

    
3767
	// On click . .
3768
	$('#pppoe_dialondemand').click(function () {
3769
		setPPPoEDialOnDemandItems();
3770
	});
3771

    
3772
	$('#pptp_dialondemand').click(function () {
3773
		setPPTPDialOnDemandItems();
3774
	});
3775

    
3776
	$('[name=adv_dhcp_pt_values]').click(function () {
3777
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3778
	});
3779

    
3780
	$('#pppoe_resetdate').datepicker();
3781

    
3782
});
3783
//]]>
3784
</script>
3785

    
3786
<?php include("foot.inc");
(71-71/232)