Project

General

Profile

Download (126 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']['gateway_item'])) {
88
	$config['gateways']['gateway_item'] = array();
89
}
90

    
91
$a_gateways = &$config['gateways']['gateway_item'];
92

    
93
$interfaces = get_configured_interface_with_descr();
94
$wancfg = &$config['interfaces'][$if];
95
$old_wancfg = $wancfg;
96
$old_wancfg['realif'] = get_real_interface($if);
97
$old_ppps = $a_ppps;
98

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

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

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

    
115
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
116
	$pconfig['pppid'] = $pppid;
117
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
118
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
119
	if ($a_ppps[$pppid]['type'] == "ppp") {
120
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
121
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
122

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

    
132
		/* ================================================ */
133
		/* = force a connection reset at a specific time? = */
134
		/* ================================================ */
135

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

    
190
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
191
$pconfig['alias-address'] = $wancfg['alias-address'];
192
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
193
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
194

    
195
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
196
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
197
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
198
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
199
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
200
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
201

    
202
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
203

    
204
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
205
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
206
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
207
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
208

    
209
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
210
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
211
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
212

    
213
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
214
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
215
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
216
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
217

    
218
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
219
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
220
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
221
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
222
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
223

    
224
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
225
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
226
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
227
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
228
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
229

    
230
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
231
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
232
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
233

    
234
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
235
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
236
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
237
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
238

    
239
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
240
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
241
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
242
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
243
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
244

    
245
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
246
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
247
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
248

    
249
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
250
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
251
$pconfig['enable'] = isset($wancfg['enable']);
252

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

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

    
330
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
331
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
332
$pconfig['spoofmac'] = $wancfg['spoofmac'];
333
$pconfig['mtu'] = $wancfg['mtu'];
334
$pconfig['mss'] = $wancfg['mss'];
335

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

    
412
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
413

    
414
}
415

    
416
$changes_applied = false;
417

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

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

    
454
		/* sync filter configuration */
455
		setup_gateways_monitor();
456

    
457
		clear_subsystem_dirty('interfaces');
458

    
459
		$retval |= filter_configure();
460

    
461
		enable_rrd_graphing();
462

    
463
		$changes_applied = true;
464

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

    
472
	unset($input_errors);
473
	$pconfig = $_POST;
474

    
475
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
476
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
477
	} else {
478
		$pconfig['track6-prefix-id'] = 0;
479
	}
480

    
481
	/* filter out spaces from descriptions */
482
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
483

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

    
498
	/* input validation */
499
	$reqdfields = explode(" ", "descr");
500
	$reqdfieldsn = array(gettext("Description"));
501
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
502

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

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

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

    
530
		if (is_numeric($_POST['descr'])) {
531
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
532
		}
533

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

    
544
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
545
		if (!preg_match("/^staticv4/", $_POST['type'])) {
546
			$input_errors[] = gettext("The DHCP Server is active " .
547
			    "on this interface and it can be used only with " .
548
			    "a static IP configuration. Please disable the " .
549
			    "DHCP Server service on this interface first, " .
550
			    "then change the interface configuration.");
551
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
552
			$input_errors[] = gettext("The DHCP Server is active " .
553
			    "on this interface and it can be used only with " .
554
			    "IPv4 subnet < 31. Please disable the " .
555
			    "DHCP Server service on this interface first, " .
556
			    "then change the interface configuration.");
557
		}
558
	}
559
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
560
		$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.");
561
	}
562

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

    
670
			if (empty($_POST['track6-interface'])) {
671
				$input_errors[] = gettext("A valid interface to track must be selected.");
672
			}
673

    
674
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
675
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
676
			} else {
677
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
678
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
679
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
680
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
681
				} else {
682
					foreach ($ifdescrs as $ifent => $ifdescr) {
683
						if ($if == $ifent) {
684
							continue;
685
						}
686
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
687
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
688
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
689
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
690
						}
691
					}
692
				}
693
			}
694
			break;
695
	}
696

    
697
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
698
	$staticroutes = get_staticroutes(true);
699
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
700
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
701
		if (!is_ipaddrv4($_POST['ipaddr'])) {
702
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
703
		} else {
704
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
705
			if (count($where_ipaddr_configured)) {
706
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
707
				foreach ($where_ipaddr_configured as $subnet_conflict) {
708
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
709
				}
710
				$input_errors[] = $subnet_conflict_text;
711
			}
712

    
713
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
714
			if ($_POST['subnet'] < 31) {
715
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
716
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
717
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
718
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
719
				}
720
			}
721

    
722
			foreach ($staticroutes as $route_subnet) {
723
				list($network, $subnet) = explode("/", $route_subnet);
724
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
725
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
726
					break;
727
				}
728
				unset($network, $subnet);
729
			}
730
		}
731
	}
732
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
733
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
734

    
735
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
736
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
737
		} else {
738
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
739
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
740
			}
741
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
742
			if (count($where_ipaddr_configured)) {
743
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
744
				foreach ($where_ipaddr_configured as $subnet_conflict) {
745
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
746
				}
747
				$input_errors[] = $subnet_conflict_text;
748
			}
749

    
750
			foreach ($staticroutes as $route_subnet) {
751
				list($network, $subnet) = explode("/", $route_subnet);
752
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
753
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
754
					break;
755
				}
756
				unset($network, $subnet);
757
			}
758
		}
759
	}
760
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
761
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
762
	}
763
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
764
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
765
	}
766
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
767
		$input_errors[] = gettext("A valid alias IP address must be specified.");
768
	}
769
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
770
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
771
	}
772
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
773
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
774
	}
775

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

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

    
848
		unset($min_mtu, $max_mtu);
849

    
850
		if (interface_is_vlan($wancfg['if']) != NULL) {
851
			$realhwif_array = get_parent_interface($wancfg['if']);
852
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
853
			$parent_realhwif = $realhwif_array[0];
854
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
855
			$mtu = 0;
856
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
857
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
858
			if ($mtu == 0)
859
				$mtu = get_interface_mtu($parent_realhwif);
860
			if ($_POST['mtu'] > $mtu)
861
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
862
		} else {
863
			foreach ($config['interfaces'] as $idx => $ifdata) {
864
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
865
					continue;
866
				}
867

    
868
				$realhwif_array = get_parent_interface($ifdata['if']);
869
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
870
				$parent_realhwif = $realhwif_array[0];
871

    
872
				if ($parent_realhwif != $wancfg['if']) {
873
					continue;
874
				}
875

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

    
963
		if ($_POST['passphrase']) {
964
			$passlen = strlen($_POST['passphrase']);
965
			if ($passlen < 8 || $passlen > 63) {
966
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
967
			}
968
		}
969

    
970
		if ($_POST['wpa_enable'] == "yes") {
971
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
972
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
973
			}
974
		}
975
	}
976

    
977
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
978
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
979
	}
980

    
981
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
982
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
983
	}
984

    
985
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
986
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
987
	}
988

    
989
	if ($_POST['gatewayip4']) {
990
		// The user wants to add an IPv4 gateway - validate the settings
991
		$gateway_settings4 = array();
992

    
993
		$gateway_settings4['name'] = $_POST['gatewayname4'];
994
		$gateway_settings4['interface'] = $_POST['if'];
995
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
996
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
997
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
998
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
999
		foreach ($gw_input_errors as $input_error_text) {
1000
			$input_errors[] = $input_error_text;
1001
		}
1002
	}
1003

    
1004
	if ($_POST['gatewayip6']) {
1005
		// The user wants to add an IPv6 gateway - validate the settings
1006
		$gateway_settings6 = array();
1007

    
1008
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1009
		$gateway_settings6['interface'] = $_POST['if'];
1010
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1011
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1012
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1013
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1014
		foreach ($gw_input_errors as $input_error_text) {
1015
			$input_errors[] = $input_error_text;
1016
		}
1017
	}
1018

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

    
1026
		if ($wancfg['ipaddr'] != $_POST['type']) {
1027
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1028
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1029
				unset($a_ppps[$pppid]);
1030
			} else if ($wancfg['ipaddr'] == "dhcp") {
1031
				kill_dhclient_process($wancfg['if']);
1032
			}
1033
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1034
				kill_dhcp6client_process($wancfg['if'],true);
1035
			}
1036
		}
1037
		$ppp = array();
1038
		if ($wancfg['ipaddr'] != "ppp") {
1039
			unset($wancfg['ipaddr']);
1040
		}
1041
		if ($wancfg['ipaddrv6'] != "ppp") {
1042
			unset($wancfg['ipaddrv6']);
1043
		}
1044
		unset($wancfg['subnet']);
1045
		unset($wancfg['gateway']);
1046
		unset($wancfg['subnetv6']);
1047
		unset($wancfg['gatewayv6']);
1048
		unset($wancfg['dhcphostname']);
1049
		unset($wancfg['dhcprejectfrom']);
1050
		unset($wancfg['dhcp6-duid']);
1051
		unset($wancfg['dhcp6-ia-pd-len']);
1052
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1053
		unset($wancfg['dhcp6prefixonly']);
1054
		unset($wancfg['dhcp6usev4iface']);
1055
		unset($wancfg['ipv6usev4iface']);
1056
		unset($wancfg['dhcp6debug']);
1057
		unset($wancfg['track6-interface']);
1058
		unset($wancfg['track6-prefix-id']);
1059
		unset($wancfg['dhcp6withoutra']);
1060
		unset($wancfg['dhcp6norelease']);
1061
		unset($wancfg['dhcp6vlanenable']);
1062
		unset($wancfg['dhcp6cvpt']);
1063
		unset($wancfg['prefix-6rd']);
1064
		unset($wancfg['prefix-6rd-v4plen']);
1065
		unset($wancfg['gateway-6rd']);
1066

    
1067
		unset($wancfg['adv_dhcp_pt_timeout']);
1068
		unset($wancfg['adv_dhcp_pt_retry']);
1069
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1070
		unset($wancfg['adv_dhcp_pt_reboot']);
1071
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1072
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1073

    
1074
		unset($wancfg['adv_dhcp_pt_values']);
1075

    
1076
		unset($wancfg['adv_dhcp_send_options']);
1077
		unset($wancfg['adv_dhcp_request_options']);
1078
		unset($wancfg['adv_dhcp_required_options']);
1079
		unset($wancfg['adv_dhcp_option_modifiers']);
1080

    
1081
		unset($wancfg['adv_dhcp_config_advanced']);
1082
		unset($wancfg['adv_dhcp_config_file_override']);
1083
		unset($wancfg['adv_dhcp_config_file_override_path']);
1084

    
1085
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1086
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1087
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1088
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1089

    
1090
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1091
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1092
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1093
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1094
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1095

    
1096
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1097
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1098
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1099
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1100
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1101

    
1102
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1103
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1104
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1105

    
1106
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1107
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1108
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1109
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1110

    
1111
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1112
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1113
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1114
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1115
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1116

    
1117
		unset($wancfg['adv_dhcp6_config_advanced']);
1118
		unset($wancfg['adv_dhcp6_config_file_override']);
1119
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1120

    
1121
		unset($wancfg['pppoe_password']);
1122
		unset($wancfg['pptp_username']);
1123
		unset($wancfg['pptp_password']);
1124
		unset($wancfg['provider']);
1125
		unset($wancfg['ondemand']);
1126
		unset($wancfg['timeout']);
1127
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1128
			unset($wancfg['pppoe']['pppoe-reset-type']);
1129
		}
1130
		unset($wancfg['local']);
1131

    
1132
		unset($wancfg['remote']);
1133
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1134
			if ($wancfg['ipaddr'] != 'ppp') {
1135
				unset($a_ppps[$pppid]['apn']);
1136
				unset($a_ppps[$pppid]['phone']);
1137
				unset($a_ppps[$pppid]['provider']);
1138
				unset($a_ppps[$pppid]['ondemand']);
1139
			}
1140
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1141
				unset($a_ppps[$pppid]['localip']);
1142
				unset($a_ppps[$pppid]['subnet']);
1143
				unset($a_ppps[$pppid]['gateway']);
1144
			}
1145
			if ($wancfg['ipaddr'] != 'pppoe') {
1146
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1147
			}
1148
			if ($wancfg['type'] != $_POST['type']) {
1149
				unset($a_ppps[$pppid]['idletimeout']);
1150
			}
1151
		}
1152

    
1153
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1154
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1155

    
1156
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1157
		switch ($_POST['type']) {
1158
			case "staticv4":
1159
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1160
				$wancfg['subnet'] = $_POST['subnet'];
1161
				if ($_POST['gateway'] != "none") {
1162
					$wancfg['gateway'] = $_POST['gateway'];
1163
				}
1164
				break;
1165
			case "dhcp":
1166
				$wancfg['ipaddr'] = "dhcp";
1167
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1168
				$wancfg['alias-address'] = $_POST['alias-address'];
1169
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1170
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1171

    
1172
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1173
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1174
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1175
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1176
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1177
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1178

    
1179
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1180

    
1181
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1182
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1183
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1184
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1185

    
1186
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1187
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1188
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1189

    
1190
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1191
				if ($gateway_item) {
1192
					$a_gateways[] = $gateway_item;
1193
				}
1194
				break;
1195
			case "ppp":
1196
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1197
				$a_ppps[$pppid]['type'] = $_POST['type'];
1198
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1199
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1200
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1201
				if ($_POST['ppp_password'] != DMYPWD) {
1202
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1203
				}
1204
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1205
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1206
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1207
				$wancfg['ipaddr'] = $_POST['type'];
1208
				break;
1209

    
1210
			case "pppoe":
1211
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1212
				$a_ppps[$pppid]['type'] = $_POST['type'];
1213
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1214
				if (isset($_POST['ppp_port'])) {
1215
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1216
				} else {
1217
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1218
				}
1219
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1220
				if ($_POST['pppoe_password'] != DMYPWD) {
1221
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1222
				}
1223
				if (!empty($_POST['provider'])) {
1224
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1225
				} else {
1226
					$a_ppps[$pppid]['provider'] = true;
1227
				}
1228
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1229
				if (!empty($_POST['pppoe_idletimeout'])) {
1230
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1231
				} else {
1232
					unset($a_ppps[$pppid]['idletimeout']);
1233
				}
1234

    
1235
				if (!empty($_POST['pppoe-reset-type'])) {
1236
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1237
				} else {
1238
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1239
				}
1240
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1241
				$wancfg['ipaddr'] = $_POST['type'];
1242
				if ($gateway_item) {
1243
					$a_gateways[] = $gateway_item;
1244
				}
1245

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

    
1314
				if ($_POST['dhcp6withoutra'] == "yes") {
1315
					$wancfg['dhcp6withoutra'] = true;
1316
				}
1317
				if ($_POST['dhcp6norelease'] == "yes") {
1318
					$wancfg['dhcp6norelease'] = true;
1319
				}
1320
				if ($_POST['dhcp6vlanenable'] == "yes") {
1321
					$wancfg['dhcp6vlanenable'] = true;
1322
				}
1323
				if (!empty($_POST['dhcp6cvpt'])) {
1324
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1325
				} else {
1326
					unset($wancfg['dhcp6cvpt']);
1327
				}
1328

    
1329
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1330
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1333
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1334
				}
1335
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1336
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1339
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1340
				}
1341

    
1342
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1343
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1344
				}
1345
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1346
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1347
				}
1348
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1349
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1350
				}
1351
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1352
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1353
				}
1354
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1355
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1356
				}
1357

    
1358
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1359
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1360
				}
1361
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1362
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1363
				}
1364
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1365
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1366
				}
1367
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1368
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1369
				}
1370
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1371
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1372
				}
1373

    
1374
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1375
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1376
				}
1377
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1378
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1379
				}
1380
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1381
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1382
				}
1383
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1384
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1385
				}
1386
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1387
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1388
				}
1389
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1390
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1391
				}
1392
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1393
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1394
				}
1395

    
1396
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1397
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1398
				}
1399
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1400
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1401
				}
1402
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1403
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1404
				}
1405
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1406
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1407
				}
1408
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1409
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1410
				}
1411

    
1412
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1413
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1414
				}
1415
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1416
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1417
				}
1418
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1419
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1420
				}
1421

    
1422
				if ($gateway_item) {
1423
					$a_gateways[] = $gateway_item;
1424
				}
1425
				break;
1426
			case "6rd":
1427
				$wancfg['ipaddrv6'] = "6rd";
1428
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1429
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1430
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1431
				if ($gateway_item) {
1432
					$a_gateways[] = $gateway_item;
1433
				}
1434
				break;
1435
			case "6to4":
1436
				$wancfg['ipaddrv6'] = "6to4";
1437
				break;
1438
			case "track6":
1439
				$wancfg['ipaddrv6'] = "track6";
1440
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1441
				if ($_POST['track6-prefix-id--hex'] === "") {
1442
					$wancfg['track6-prefix-id'] = 0;
1443
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1444
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1445
				} else {
1446
					$wancfg['track6-prefix-id'] = 0;
1447
				}
1448
				break;
1449
			case "none":
1450
				break;
1451
		}
1452
		handle_pppoe_reset($_POST);
1453

    
1454
		if ($_POST['blockpriv'] == "yes") {
1455
			$wancfg['blockpriv'] = true;
1456
		} else {
1457
			unset($wancfg['blockpriv']);
1458
		}
1459
		if ($_POST['blockbogons'] == "yes") {
1460
			$wancfg['blockbogons'] = true;
1461
		} else {
1462
			unset($wancfg['blockbogons']);
1463
		}
1464
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1465
		if (empty($_POST['mtu'])) {
1466
			unset($wancfg['mtu']);
1467
		} else {
1468
			$wancfg['mtu'] = $_POST['mtu'];
1469
		}
1470
		if (empty($_POST['mss'])) {
1471
			unset($wancfg['mss']);
1472
		} else {
1473
			$wancfg['mss'] = $_POST['mss'];
1474
		}
1475
		if (empty($_POST['mediaopt'])) {
1476
			unset($wancfg['media']);
1477
			unset($wancfg['mediaopt']);
1478
		} else {
1479
			$mediaopts = explode(' ', $_POST['mediaopt']);
1480
			if ($mediaopts[0] != '') {
1481
				$wancfg['media'] = $mediaopts[0];
1482
			}
1483
			if ($mediaopts[1] != '') {
1484
				$wancfg['mediaopt'] = $mediaopts[1];
1485
			} else {
1486
				unset($wancfg['mediaopt']);
1487
			}
1488
		}
1489
		if (isset($wancfg['wireless'])) {
1490
			handle_wireless_post();
1491
		}
1492

    
1493
		write_config();
1494

    
1495
		if ($_POST['gatewayip4']) {
1496
			save_gateway($gateway_settings4);
1497
		}
1498

    
1499
		if ($_POST['gatewayip6']) {
1500
			save_gateway($gateway_settings6);
1501
		}
1502

    
1503
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1504
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1505
		} else {
1506
			$toapplylist = array();
1507
		}
1508
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1509
		$toapplylist[$if]['ppps'] = $old_ppps;
1510
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1511

    
1512
		mark_subsystem_dirty('interfaces');
1513

    
1514
		/* regenerate cron settings/crontab file */
1515
		configure_cron();
1516

    
1517
		header("Location: interfaces.php?if={$if}");
1518
		exit;
1519
	}
1520

    
1521
} // end if ($_POST['save'])
1522

    
1523
function handle_wireless_post() {
1524
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1525
	if (!is_array($wancfg['wireless'])) {
1526
		$wancfg['wireless'] = array();
1527
	}
1528
	$wancfg['wireless']['standard'] = $_POST['standard'];
1529
	$wancfg['wireless']['mode'] = $_POST['mode'];
1530
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1531
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1532
	$wancfg['wireless']['channel'] = $_POST['channel'];
1533
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1534
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1535
	$wancfg['wireless']['distance'] = $_POST['distance'];
1536
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1537
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1538
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1539
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1540
		foreach ($wl_countries_attr as $wl_country) {
1541
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1542
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1543
				break;
1544
			}
1545
		}
1546
	}
1547
	if (!is_array($wancfg['wireless']['wpa'])) {
1548
		$wancfg['wireless']['wpa'] = array();
1549
	}
1550
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1551
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1552
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1553
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1554
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1555
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1556
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1557
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1558
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1559
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1560
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1561
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1562
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1563
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1564

    
1565
	if ($_POST['persistcommonwireless'] == "yes") {
1566
		if (!is_array($config['wireless'])) {
1567
			$config['wireless'] = array();
1568
		}
1569
		if (!is_array($config['wireless']['interfaces'])) {
1570
			$config['wireless']['interfaces'] = array();
1571
		}
1572
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1573
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1574
		}
1575
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1576
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1577
	}
1578
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1579
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1580
	} else if (isset($wancfg['wireless']['diversity'])) {
1581
		unset($wancfg['wireless']['diversity']);
1582
	}
1583
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1584
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1585
	} else if (isset($wancfg['wireless']['txantenna'])) {
1586
		unset($wancfg['wireless']['txantenna']);
1587
	}
1588
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1589
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1590
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1591
		unset($wancfg['wireless']['rxantenna']);
1592
	}
1593
	if ($_POST['hidessid_enable'] == "yes") {
1594
		$wancfg['wireless']['hidessid']['enable'] = true;
1595
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1596
		unset($wancfg['wireless']['hidessid']['enable']);
1597
	}
1598
	if ($_POST['mac_acl_enable'] == "yes") {
1599
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1600
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1601
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1602
	}
1603
	if ($_POST['rsn_preauth'] == "yes") {
1604
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1605
	} else {
1606
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1607
	}
1608
	if ($_POST['ieee8021x'] == "yes") {
1609
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1610
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1611
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1612
	}
1613
	if ($_POST['wpa_strict_rekey'] == "yes") {
1614
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1615
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1616
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1617
	}
1618
	if ($_POST['debug_mode'] == "yes") {
1619
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1620
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1621
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1622
	}
1623
	if ($_POST['wpa_enable'] == "yes") {
1624
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1625
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1626
		unset($wancfg['wireless']['wpa']['enable']);
1627
	}
1628

    
1629
	if ($_POST['wme_enable'] == "yes") {
1630
		if (!is_array($wancfg['wireless']['wme'])) {
1631
			$wancfg['wireless']['wme'] = array();
1632
		}
1633
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1634
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1635
		unset($wancfg['wireless']['wme']['enable']);
1636
	}
1637
	if ($_POST['puremode'] == "11g") {
1638
		if (!is_array($wancfg['wireless']['pureg'])) {
1639
			$wancfg['wireless']['pureg'] = array();
1640
		}
1641
		$wancfg['wireless']['pureg']['enable'] = true;
1642
	} else if ($_POST['puremode'] == "11n") {
1643
		if (!is_array($wancfg['wireless']['puren'])) {
1644
			$wancfg['wireless']['puren'] = array();
1645
		}
1646
		$wancfg['wireless']['puren']['enable'] = true;
1647
	} else {
1648
		if (isset($wancfg['wireless']['pureg'])) {
1649
			unset($wancfg['wireless']['pureg']);
1650
		}
1651
		if (isset($wancfg['wireless']['puren'])) {
1652
			unset($wancfg['wireless']['puren']);
1653
		}
1654
	}
1655
	if ($_POST['apbridge_enable'] == "yes") {
1656
		if (!is_array($wancfg['wireless']['apbridge'])) {
1657
			$wancfg['wireless']['apbridge'] = array();
1658
		}
1659
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1660
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1661
		unset($wancfg['wireless']['apbridge']['enable']);
1662
	}
1663
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1664
		if (!is_array($wancfg['wireless']['turbo'])) {
1665
			$wancfg['wireless']['turbo'] = array();
1666
		}
1667
		$wancfg['wireless']['turbo']['enable'] = true;
1668
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1669
		unset($wancfg['wireless']['turbo']['enable']);
1670
	}
1671

    
1672
	interface_sync_wireless_clones($wancfg, true);
1673
}
1674

    
1675
function check_wireless_mode() {
1676
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1677

    
1678
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1679
		return;
1680
	}
1681

    
1682
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1683
		$clone_count = 1;
1684
	} else {
1685
		$clone_count = 0;
1686
	}
1687

    
1688
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1689
		foreach ($config['wireless']['clone'] as $clone) {
1690
			if ($clone['if'] == $wlanbaseif) {
1691
				$clone_count++;
1692
			}
1693
		}
1694
	}
1695

    
1696
	if ($clone_count > 1) {
1697
		$old_wireless_mode = $wancfg['wireless']['mode'];
1698
		$wancfg['wireless']['mode'] = $_POST['mode'];
1699
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1700
			$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']]);
1701
		} else {
1702
			pfSense_interface_destroy("{$wlanif}_");
1703
		}
1704
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1705
	}
1706
}
1707

    
1708
// Find all possible media options for the interface
1709
$mediaopts_list = array();
1710
$intrealname = $config['interfaces'][$if]['if'];
1711
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1712
foreach ($mediaopts as $mediaopt) {
1713
	preg_match("/media (.*)/", $mediaopt, $matches);
1714
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1715
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1716
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1717
	} else {
1718
		// there is only media like "media 1000baseT"
1719
		array_push($mediaopts_list, $matches[1]);
1720
	}
1721
}
1722

    
1723
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1724
$shortcut_section = "interfaces";
1725

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

    
1729
// Get the MAC address
1730
$ip = $_SERVER['REMOTE_ADDR'];
1731
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1732
$mymac = str_replace("\n", "", $mymac);
1733
$defgatewayname4 = $wancfg['descr'] . "GW";
1734
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1735

    
1736
function build_mediaopts_list() {
1737
	global $mediaopts_list;
1738

    
1739
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1740
			 " " =>	 gettext("------- Media Supported by this interface -------")
1741
			];
1742

    
1743
	foreach ($mediaopts_list as $mediaopt) {
1744
		$list[$mediaopt] = $mediaopt;
1745
	}
1746

    
1747
	return($list);
1748
}
1749

    
1750
function build_gateway_list() {
1751
	global $a_gateways, $if;
1752

    
1753
	$list = array("none" => gettext("None"));
1754
	foreach ($a_gateways as $gateway) {
1755
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1756
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1757
		}
1758
	}
1759

    
1760
	return($list);
1761
}
1762

    
1763
function build_gatewayv6_list() {
1764
	global $a_gateways, $if;
1765

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

    
1773
	return($list);
1774
}
1775

    
1776
include("head.inc");
1777

    
1778
if ($input_errors) {
1779
	print_input_errors($input_errors);
1780
}
1781

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

    
1788
if ($changes_applied) {
1789
	print_apply_result_box($retval);
1790
}
1791

    
1792
$form = new Form();
1793

    
1794
$section = new Form_Section('General Configuration');
1795

    
1796
$section->addInput(new Form_Checkbox(
1797
	'enable',
1798
	'Enable',
1799
	'Enable interface',
1800
	$pconfig['enable'],
1801
	'yes'
1802
));
1803

    
1804
$section->addInput(new Form_Input(
1805
	'descr',
1806
	'*Description',
1807
	'text',
1808
	$pconfig['descr']
1809
))->setHelp('Enter a description (name) for the interface here.');
1810

    
1811
$section->addInput(new Form_Select(
1812
	'type',
1813
	'IPv4 Configuration Type',
1814
	$pconfig['type'],
1815
	$types4
1816
));
1817

    
1818
$section->addInput(new Form_Select(
1819
	'type6',
1820
	'IPv6 Configuration Type',
1821
	$pconfig['type6'],
1822
	$types6
1823
));
1824

    
1825
$macaddress = new Form_Input(
1826
	'spoofmac',
1827
	'MAC Address',
1828
	'text',
1829
	$pconfig['spoofmac'],
1830
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1831
);
1832

    
1833
$btnmymac = new Form_Button(
1834
	'btnmymac',
1835
	'Copy My MAC',
1836
	null,
1837
	'fa-clone'
1838
	);
1839

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

    
1842
$group = new Form_Group('MAC Address');
1843
$group->add($macaddress);
1844
// $group->add($btnmymac);
1845
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1846
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1847
$section->add($group);
1848

    
1849
$section->addInput(new Form_Input(
1850
	'mtu',
1851
	'MTU',
1852
	'number',
1853
	$pconfig['mtu']
1854
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1855
			'This is typically 1500 bytes but can vary in some circumstances.');
1856

    
1857
$section->addInput(new Form_Input(
1858
	'mss',
1859
	'MSS',
1860
	'number',
1861
	$pconfig['mss']
1862
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1863
			'header size) will be in effect.');
1864

    
1865
if (count($mediaopts_list) > 0) {
1866
	$section->addInput(new Form_Select(
1867
		'mediaopt',
1868
		'Speed and Duplex',
1869
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1870
		build_mediaopts_list()
1871
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1872
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1873
}
1874

    
1875
$form->add($section);
1876

    
1877
$section = new Form_Section('Static IPv4 Configuration');
1878
$section->addClass('staticv4');
1879

    
1880
$section->addInput(new Form_IpAddress(
1881
	'ipaddr',
1882
	'*IPv4 Address',
1883
	$pconfig['ipaddr'],
1884
	'V4'
1885
))->addMask('subnet', $pconfig['subnet'], 32);
1886

    
1887
$group = new Form_Group('IPv4 Upstream gateway');
1888

    
1889
$group->add(new Form_Select(
1890
	'gateway',
1891
	'IPv4 Upstream Gateway',
1892
	$pconfig['gateway'],
1893
	build_gateway_list()
1894
));
1895

    
1896
$group->add(new Form_Button(
1897
	'addgw4',
1898
	'Add a new gateway',
1899
	null,
1900
	'fa-plus'
1901
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1902

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

    
1907
$section->add($group);
1908

    
1909
$form->add($section);
1910

    
1911
$section = new Form_Section('Static IPv6 Configuration');
1912
$section->addClass('staticv6');
1913

    
1914
$section->addInput(new Form_IpAddress(
1915
	'ipaddrv6',
1916
	'*IPv6 address',
1917
	$pconfig['ipaddrv6'],
1918
	'V6'
1919
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1920

    
1921
$section->addInput(new Form_Checkbox(
1922
	'ipv6usev4iface',
1923
	'Use IPv4 connectivity as parent interface',
1924
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1925
	$pconfig['ipv6usev4iface']
1926
));
1927

    
1928
$group = new Form_Group('IPv6 Upstream gateway');
1929

    
1930
$group->add(new Form_Select(
1931
	'gatewayv6',
1932
	'IPv6 Upstream Gateway',
1933
	$pconfig['gatewayv6'],
1934
	build_gatewayv6_list()
1935
));
1936

    
1937
$group->add(new Form_Button(
1938
	'addgw6',
1939
	'Add a new gateway',
1940
	null,
1941
	'fa-plus'
1942
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1943

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

    
1947
$section->add($group);
1948
$form->add($section);
1949

    
1950
// Add new gateway modal pop-up for IPv6
1951
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1952

    
1953
$modal->addInput(new Form_Checkbox(
1954
	'defaultgw6',
1955
	'Default',
1956
	'Default gateway',
1957
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
1958
));
1959

    
1960
$modal->addInput(new Form_Input(
1961
	'gatewayname6',
1962
	'Gateway name',
1963
	'text',
1964
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
1965
));
1966

    
1967
$modal->addInput(new Form_IpAddress(
1968
	'gatewayip6',
1969
	'Gateway IPv6',
1970
	$gateway_settings6['gateway'],
1971
	'V6'
1972
));
1973

    
1974
$modal->addInput(new Form_Input(
1975
	'gatewaydescr6',
1976
	'Description',
1977
	'text',
1978
	$gateway_settings6['descr']
1979
));
1980

    
1981
$btnaddgw6 = new Form_Button(
1982
	'add6',
1983
	'Add',
1984
	null,
1985
	'fa-plus'
1986
);
1987

    
1988
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1989

    
1990
$btncnxgw6 = new Form_Button(
1991
	'cnx6',
1992
	'Cancel',
1993
	null,
1994
	'fa-undo'
1995
);
1996

    
1997
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1998

    
1999
$modal->addInput(new Form_StaticText(
2000
	null,
2001
	$btnaddgw6 . $btncnxgw6
2002
));
2003

    
2004
$form->add($modal);
2005

    
2006
// ==== DHCP client configuration =============================
2007

    
2008
$section = new Form_Section('DHCP Client Configuration');
2009
$section->addClass('dhcp');
2010

    
2011
$group = new Form_Group('Options');
2012

    
2013
$group->add(new Form_Checkbox(
2014
	'adv_dhcp_config_advanced',
2015
	null,
2016
	'Advanced Configuration',
2017
	$pconfig['adv_dhcp_config_advanced']
2018
))->setHelp('Use advanced DHCP configuration options.');
2019

    
2020
$group->add(new Form_Checkbox(
2021
	'adv_dhcp_config_file_override',
2022
	null,
2023
	'Configuration Override',
2024
	$pconfig['adv_dhcp_config_file_override']
2025
))->setHelp('Override the configuration from this file.');
2026

    
2027
$section->add($group);
2028

    
2029
$section->addInput(new Form_Input(
2030
	'dhcphostname',
2031
	'Hostname',
2032
	'text',
2033
	$pconfig['dhcphostname']
2034
))->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).');
2035

    
2036
$section->addInput(new Form_IpAddress(
2037
	'alias-address',
2038
	'Alias IPv4 address',
2039
	$pconfig['alias-address'],
2040
	'V4'
2041
))->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.');
2042

    
2043
$section->addInput(new Form_Input(
2044
	'dhcprejectfrom',
2045
	'Reject leases from',
2046
	'text',
2047
	$pconfig['dhcprejectfrom']
2048
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2049
			'(separate multiple entries with a comma). ' .
2050
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2051

    
2052
$group = new Form_Group('Protocol timing');
2053
$group->addClass('dhcpadvanced');
2054

    
2055
$group->add(new Form_Input(
2056
	'adv_dhcp_pt_timeout',
2057
	null,
2058
	'number',
2059
	$pconfig['adv_dhcp_pt_timeout']
2060
))->setHelp('Timeout');
2061

    
2062
$group->add(new Form_Input(
2063
	'adv_dhcp_pt_retry',
2064
	null,
2065
	'number',
2066
	$pconfig['adv_dhcp_pt_retry']
2067
))->setHelp('Retry');
2068

    
2069
$group->add(new Form_Input(
2070
	'adv_dhcp_pt_select_timeout',
2071
	null,
2072
	'number',
2073
	$pconfig['adv_dhcp_pt_select_timeout'],
2074
	['min' => 0]
2075
))->setHelp('Select timeout');
2076

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

    
2084
$group->add(new Form_Input(
2085
	'adv_dhcp_pt_backoff_cutoff',
2086
	null,
2087
	'number',
2088
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2089
))->setHelp('Backoff cutoff');
2090

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

    
2098
$section->add($group);
2099

    
2100
$group = new Form_Group('Presets');
2101
$group->addClass('dhcpadvanced');
2102

    
2103
$group->add(new Form_Checkbox(
2104
	'adv_dhcp_pt_values',
2105
	null,
2106
	'FreeBSD default',
2107
	null,
2108
	'DHCP'
2109
))->displayAsRadio();
2110

    
2111
$group->add(new Form_Checkbox(
2112
	'adv_dhcp_pt_values',
2113
	null,
2114
	'Clear',
2115
	null,
2116
	'Clear'
2117
))->displayAsRadio();
2118

    
2119
$group->add(new Form_Checkbox(
2120
	'adv_dhcp_pt_values',
2121
	null,
2122
	'pfSense Default',
2123
	null,
2124
	'pfSense'
2125
))->displayAsRadio();
2126

    
2127
$group->add(new Form_Checkbox(
2128
	'adv_dhcp_pt_values',
2129
	null,
2130
	'Saved Cfg',
2131
	null,
2132
	'SavedCfg'
2133
))->displayAsRadio();
2134

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

    
2138
$section->add($group);
2139

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

    
2150
$form->add($section);
2151

    
2152
$section = new Form_Section('Lease Requirements and Requests');
2153
$section->addClass('dhcpadvanced');
2154

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

    
2165
$section->addInput(new Form_Input(
2166
	'adv_dhcp_request_options',
2167
	'Request options',
2168
	'text',
2169
	$pconfig['adv_dhcp_request_options']
2170
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2171
			'Some ISPs may require certain options be or not be requested.', '<br />');
2172

    
2173
$section->addInput(new Form_Input(
2174
	'adv_dhcp_required_options',
2175
	'Require options',
2176
	'text',
2177
	$pconfig['adv_dhcp_required_options']
2178
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2179

    
2180
$section->addInput(new Form_Input(
2181
	'adv_dhcp_option_modifiers',
2182
	'Option modifiers',
2183
	'text',
2184
	$pconfig['adv_dhcp_option_modifiers']
2185
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2186
			'modifiers: (default, supersede, prepend, append) %1$s' .
2187
			'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>');
2188

    
2189
$form->add($section);
2190

    
2191
// DHCP6 client config
2192

    
2193
$section = new Form_Section('DHCP6 Client Configuration');
2194
$section->addClass('dhcp6');
2195

    
2196
$group = new Form_Group('Options');
2197

    
2198
$group->add(new Form_Checkbox(
2199
	'adv_dhcp6_config_advanced',
2200
	null,
2201
	'Advanced Configuration',
2202
	$pconfig['adv_dhcp6_config_advanced']
2203
))->setHelp('Use advanced DHCPv6 configuration options.');
2204

    
2205
$group->add(new Form_Checkbox(
2206
	'adv_dhcp6_config_file_override',
2207
	null,
2208
	'Configuration Override',
2209
	$pconfig['adv_dhcp6_config_file_override']
2210
))->setHelp('Override the configuration from this file.');
2211

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

    
2214
$section->addInput(new Form_Checkbox(
2215
	'dhcp6usev4iface',
2216
	'Use IPv4 connectivity as parent interface',
2217
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2218
	$pconfig['dhcp6usev4iface']
2219
));
2220

    
2221
$section->addInput(new Form_Checkbox(
2222
	'dhcp6prefixonly',
2223
	'Request only an IPv6 prefix',
2224
	'Only request an IPv6 prefix, do not request an IPv6 address',
2225
	$pconfig['dhcp6prefixonly']
2226
));
2227

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

    
2235
$section->addInput(new Form_Checkbox(
2236
	'dhcp6-ia-pd-send-hint',
2237
	'Send IPv6 prefix hint',
2238
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2239
	$pconfig['dhcp6-ia-pd-send-hint']
2240
));
2241

    
2242
$section->addInput(new Form_Checkbox(
2243
	'dhcp6debug',
2244
	'Debug',
2245
	'Start DHCP6 client in debug mode',
2246
	$pconfig['dhcp6debug']
2247
));
2248
$section->addInput(new Form_Checkbox(
2249
	'dhcp6withoutra',
2250
	'Do not wait for a RA',
2251
	'Required by some ISPs, especially those not using PPPoE',
2252
	$pconfig['dhcp6withoutra']
2253
));
2254
$section->addInput(new Form_Checkbox(
2255
	'dhcp6norelease',
2256
	'Do not allow PD/Address release',
2257
	'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',
2258
	$pconfig['dhcp6norelease']
2259
));
2260

    
2261
$group = new Form_Group('DHCP6 VLAN Priority');
2262

    
2263
$vlanprio = array(
2264
	"bk" => "Background (BK, 0)",
2265
	"be" => "Best Effort (BE, 1)",
2266
	"ee" => "Excellent Effort (EE, 2)",
2267
	"ca" => "Critical Applications (CA, 3)",
2268
	"vi" => "Video (VI, 4)",
2269
	"vo" => "Voice (VO, 5)",
2270
	"ic" => "Internetwork Control (IC, 6)",
2271
	"nc" => "Network Control (NC, 7)");
2272

    
2273
$group->add(new Form_Checkbox(
2274
	'dhcp6vlanenable',
2275
	null,
2276
	'Enable dhcp6c VLAN Priority tagging',
2277
	$pconfig['dhcp6vlanenable']
2278
))->setHelp('Normally off unless specifically required by the ISP.');
2279

    
2280
$group->add(new Form_Select(
2281
	'dhcp6cvpt',
2282
	'VLAN Prio',
2283
	$pconfig['dhcp6cvpt'],
2284
	$vlanprio
2285
))->setHelp('Choose 802.1p priority to set.');
2286

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

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

    
2299
$form->add($section);
2300

    
2301
// DHCP6 client config - Advanced
2302

    
2303
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2304
$section->addClass('dhcp6advanced');
2305

    
2306
$section->addInput(new Form_Checkbox(
2307
	'adv_dhcp6_interface_statement_information_only_enable',
2308
	'Information only',
2309
	'Exchange Information Only',
2310
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2311
	'Selected'
2312
))->setHelp('Only exchange informational configuration parameters with servers.');
2313

    
2314
$section->addInput(new Form_Input(
2315
	'adv_dhcp6_interface_statement_send_options',
2316
	'Send options',
2317
	'text',
2318
	$pconfig['adv_dhcp6_interface_statement_send_options']
2319
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2320
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2321
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2322
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2323

    
2324
$section->addInput(new Form_Input(
2325
	'adv_dhcp6_interface_statement_request_options',
2326
	'Request Options',
2327
	'text',
2328
	$pconfig['adv_dhcp6_interface_statement_request_options']
2329
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2330
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2331

    
2332
$section->addInput(new Form_Input(
2333
	'adv_dhcp6_interface_statement_script',
2334
	'Scripts',
2335
	'text',
2336
	$pconfig['adv_dhcp6_interface_statement_script']
2337
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2338
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2339

    
2340
$group = new Form_Group('Identity Association Statement');
2341

    
2342
$group->add(new Form_Checkbox(
2343
	'adv_dhcp6_id_assoc_statement_address_enable',
2344
	null,
2345
	'Non-Temporary Address Allocation',
2346
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2347
	'Selected'
2348
));
2349

    
2350
$group->add(new Form_Input(
2351
	'adv_dhcp6_id_assoc_statement_address_id',
2352
	null,
2353
	'text',
2354
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2355
))->sethelp('id-assoc na ID');
2356

    
2357
$group->add(new Form_IpAddress(
2358
	'adv_dhcp6_id_assoc_statement_address',
2359
	null,
2360
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2361
	'V6'
2362
))->sethelp('IPv6 address');
2363

    
2364
$group->add(new Form_Input(
2365
	'adv_dhcp6_id_assoc_statement_address_pltime',
2366
	null,
2367
	'text',
2368
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2369
))->sethelp('pltime');
2370

    
2371
$group->add(new Form_Input(
2372
	'adv_dhcp6_id_assoc_statement_address_vltime',
2373
	null,
2374
	'text',
2375
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2376
))->sethelp('vltime');
2377

    
2378
$section->add($group);
2379

    
2380
// Prefix delegation
2381
$group = new Form_Group('');
2382

    
2383
$group->add(new Form_Checkbox(
2384
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2385
	null,
2386
	'Prefix Delegation ',
2387
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2388
	'Selected'
2389
));
2390

    
2391
$group->add(new Form_Input(
2392
	'adv_dhcp6_id_assoc_statement_prefix_id',
2393
	null,
2394
	'text',
2395
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2396
))->sethelp('id-assoc pd ID');
2397

    
2398
$group->add(new Form_IpAddress(
2399
	'adv_dhcp6_id_assoc_statement_prefix',
2400
	null,
2401
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2402
	'V6'
2403
))->sethelp('IPv6 prefix');
2404

    
2405
$group->add(new Form_Input(
2406
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2407
	null,
2408
	'text',
2409
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2410
))->sethelp('pltime');
2411

    
2412
$group->add(new Form_Input(
2413
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2414
	null,
2415
	'text',
2416
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2417
))->sethelp('vltime');
2418

    
2419
$section->add($group);
2420

    
2421
$group = new Form_Group('Prefix interface statement');
2422

    
2423
$group->add(new Form_Input(
2424
	'adv_dhcp6_prefix_interface_statement_sla_id',
2425
	null,
2426
	'text',
2427
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2428
))->sethelp('Prefix Interface sla-id');
2429

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

    
2437
$section->add($group);
2438

    
2439
$group = new Form_Group('Select prefix interface');
2440
$section->addInput(new Form_Select(
2441
	'adv_dhcp6_prefix_selected_interface',
2442
	'Prefix Interface',
2443
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2444
	$interfaces
2445
))->setHelp('Select the interface on which to apply the prefix delegation.');
2446

    
2447
$group = new Form_Group('Authentication statement');
2448

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

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

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

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

    
2477
$section->add($group);
2478

    
2479
$group = new Form_Group('Keyinfo statement');
2480

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

    
2488
$group->add(new Form_Input(
2489
	'adv_dhcp6_key_info_statement_realm',
2490
	null,
2491
	'text',
2492
	$pconfig['adv_dhcp6_key_info_statement_realm']
2493
))->sethelp('Realm');
2494

    
2495
$section->add($group);
2496

    
2497
$group = new Form_Group('');
2498

    
2499
$group->add(new Form_Input(
2500
	'adv_dhcp6_key_info_statement_keyid',
2501
	null,
2502
	'text',
2503
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2504
))->sethelp('KeyID');
2505

    
2506
$group->add(new Form_Input(
2507
	'adv_dhcp6_key_info_statement_secret',
2508
	null,
2509
	'text',
2510
	$pconfig['adv_dhcp6_key_info_statement_secret']
2511
))->sethelp('Secret');
2512

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

    
2520
$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>');
2521

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

    
2524
$form->add($section);
2525

    
2526
$section = new Form_Section('6RD Configuration');
2527
$section->addClass('_6rd');
2528

    
2529
$section->addInput(new Form_Input(
2530
	'prefix-6rd',
2531
	'6RD Prefix',
2532
	'text',
2533
	$pconfig['prefix-6rd']
2534
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2535

    
2536
$section->addInput(new Form_Input(
2537
	'gateway-6rd',
2538
	'*6RD Border relay',
2539
	'text',
2540
	$pconfig['gateway-6rd']
2541
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2542

    
2543
$section->addInput(new Form_Select(
2544
	'prefix-6rd-v4plen',
2545
	'6RD IPv4 Prefix length',
2546
	$pconfig['prefix-6rd-v4plen'],
2547
	array_combine(range(0, 32), range(0, 32))
2548
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2549

    
2550
$form->add($section);
2551

    
2552
// Track IPv6 ointerface section
2553
$section = new Form_Section('Track IPv6 Interface');
2554
$section->addClass('track6');
2555

    
2556
function build_ipv6interface_list() {
2557
	global $config, $section;
2558

    
2559
	$list = array('' => '');
2560

    
2561
	$interfaces = get_configured_interface_with_descr(true);
2562
	$dynv6ifs = array();
2563

    
2564
	foreach ($interfaces as $iface => $ifacename) {
2565
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2566
			case "6to4":
2567
			case "6rd":
2568
			case "dhcp6":
2569
				$dynv6ifs[$iface] = array(
2570
					'name' => $ifacename,
2571
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2572
				);
2573
				break;
2574
			default:
2575
				continue;
2576
		}
2577
	}
2578

    
2579
	foreach ($dynv6ifs as $iface => $ifacedata) {
2580
		$list[$iface] = $ifacedata['name'];
2581

    
2582
		$section->addInput(new Form_Input(
2583
			'ipv6-num-prefix-ids-' . $iface,
2584
			null,
2585
			'hidden',
2586
			$ifacedata['ipv6_num_prefix_ids']
2587
		));
2588
	}
2589

    
2590
	return($list);
2591
}
2592

    
2593
$section->addInput(new Form_Select(
2594
	'track6-interface',
2595
	'*IPv6 Interface',
2596
	$pconfig['track6-interface'],
2597
	build_ipv6interface_list()
2598
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2599

    
2600
if ($pconfig['track6-prefix-id'] == "") {
2601
	$pconfig['track6-prefix-id'] = 0;
2602
}
2603

    
2604
$section->addInput(new Form_Input(
2605
	'track6-prefix-id--hex',
2606
	'IPv6 Prefix ID',
2607
	'text',
2608
	sprintf("%x", $pconfig['track6-prefix-id'])
2609
))->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>');
2610

    
2611
$section->addInput(new Form_Input(
2612
	'track6-prefix-id-max',
2613
	null,
2614
	'hidden',
2615
	0
2616
));
2617

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

    
2620
/// PPP section
2621

    
2622
$section = new Form_Section('PPP Configuration');
2623
$section->addClass('ppp');
2624

    
2625
$section->addInput(new Form_Select(
2626
	'country',
2627
	'Country',
2628
	$pconfig['country'],
2629
	[]
2630
));
2631

    
2632
$section->addInput(new Form_Select(
2633
	'provider_list',
2634
	'Provider',
2635
	$pconfig['provider_list'],
2636
	[]
2637
));
2638

    
2639
$section->addInput(new Form_Select(
2640
	'providerplan',
2641
	'Plan',
2642
	$pconfig['providerplan'],
2643
	[]
2644
))->setHelp('Select to fill in service provider data.');
2645

    
2646
$section->addInput(new Form_Input(
2647
	'ppp_username',
2648
	'Username',
2649
	'text',
2650
	$pconfig['ppp_username']
2651
));
2652

    
2653
$section->addPassword(new Form_Input(
2654
	'ppp_password',
2655
	'Password',
2656
	'password',
2657
	$pconfig['ppp_password']
2658
));
2659

    
2660
$section->addInput(new Form_Input(
2661
	'phone',
2662
	'*Phone number',
2663
	'text',
2664
	$pconfig['phone']
2665
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2666

    
2667
$section->addInput(new Form_Input(
2668
	'apn',
2669
	'Access Point Name',
2670
	'text',
2671
	$pconfig['apn']
2672
));
2673

    
2674

    
2675
function build_port_list() {
2676
	$list = array("" => "None");
2677

    
2678
	$portlist = glob("/dev/cua*");
2679
	$modems	  = glob("/dev/modem*");
2680
	$portlist = array_merge($portlist, $modems);
2681

    
2682
	foreach ($portlist as $port) {
2683
		if (preg_match("/\.(lock|init)$/", $port)) {
2684
			continue;
2685
		}
2686

    
2687
	$list[trim($port)] = $port;
2688
	}
2689

    
2690
	return($list);
2691
}
2692

    
2693
$section->addInput(new Form_Select(
2694
	'port',
2695
	"*Modem port",
2696
	$pconfig['port'],
2697
	build_port_list()
2698
));
2699

    
2700
$section->addInput(new Form_Button(
2701
	'btnadvppp',
2702
	'Advanced PPP',
2703
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2704
	'fa-cog'
2705
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2706

    
2707
$form->add($section);
2708

    
2709
// PPPoE configuration
2710
$section = new Form_Section('PPPoE Configuration');
2711
$section->addClass('pppoe');
2712

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

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

    
2727
$section->addInput(new Form_Input(
2728
	'provider',
2729
	'Service name',
2730
	'text',
2731
	$pconfig['provider']
2732
))->setHelp('This field can usually be left empty.');
2733

    
2734
$section->addInput(new Form_Checkbox(
2735
	'pppoe_dialondemand',
2736
	'Dial on demand',
2737
	'Enable Dial-On-Demand mode ',
2738
	$pconfig['pppoe_dialondemand'],
2739
	'enable'
2740
));
2741

    
2742
$section->addInput(new Form_Input(
2743
	'pppoe_idletimeout',
2744
	'Idle timeout',
2745
	'number',
2746
	$pconfig['pppoe_idletimeout'],
2747
	['min' => 0]
2748
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2749
			'An idle timeout of zero disables this feature.');
2750

    
2751
$section->addInput(new Form_Select(
2752
	'pppoe-reset-type',
2753
	'Periodic reset',
2754
	$pconfig['pppoe-reset-type'],
2755
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2756
))->setHelp('Select a reset timing type.');
2757

    
2758
$group = new Form_Group('Custom reset');
2759
$group->addClass('pppoecustom');
2760

    
2761
$group->add(new Form_Input(
2762
	'pppoe_resethour',
2763
	null,
2764
	'number',
2765
	$pconfig['pppoe_resethour'],
2766
	['min' => 0, 'max' => 23]
2767
))->setHelp('Hour (0-23)');
2768

    
2769
$group->add(new Form_Input(
2770
	'pppoe_resetminute',
2771
	null,
2772
	'number',
2773
	$pconfig['pppoe_resetminute'],
2774
	['min' => 0, 'max' => 59]
2775
))->setHelp('Minutes (0-59)');
2776

    
2777
$group->add(new Form_Input(
2778
	'pppoe_resetdate',
2779
	null,
2780
	'text',
2781
	$pconfig['pppoe_resetdate']
2782
))->setHelp('Specific date (mm/dd/yyyy)');
2783

    
2784
$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');
2785

    
2786
$section->add($group);
2787

    
2788
$group = new Form_MultiCheckboxGroup('cron based reset');
2789
$group->addClass('pppoepreset');
2790

    
2791
$group->add(new Form_MultiCheckbox(
2792
	'pppoe_pr_preset_val',
2793
	null,
2794
	'Reset at each month ("0 0 1 * *")',
2795
	$pconfig['pppoe_monthly'],
2796
	'monthly'
2797
))->displayAsRadio();
2798

    
2799
$group->add(new Form_MultiCheckbox(
2800
	'pppoe_pr_preset_val',
2801
	null,
2802
	'Reset at each week ("0 0 * * 0")',
2803
	$pconfig['pppoe_weekly'],
2804
	'weekly'
2805
))->displayAsRadio();
2806

    
2807
$group->add(new Form_MultiCheckbox(
2808
	'pppoe_pr_preset_val',
2809
	null,
2810
	'Reset at each day ("0 0 * * *")',
2811
	$pconfig['pppoe_daily'],
2812
	'daily'
2813
))->displayAsRadio();
2814

    
2815
$group->add(new Form_MultiCheckbox(
2816
	'pppoe_pr_preset_val',
2817
	null,
2818
	'Reset at each hour ("0 * * * *")',
2819
	$pconfig['pppoe_hourly'],
2820
	'hourly'
2821
))->displayAsRadio();
2822

    
2823
$section->add($group);
2824

    
2825
$section->addInput(new Form_Button(
2826
	'btnadvppp',
2827
	'Advanced and MLPPP',
2828
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2829
	'fa-cog'
2830
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2831

    
2832
$form->add($section);
2833

    
2834
// PPTP & L2TP Configuration section
2835
$section = new Form_Section('PPTP/L2TP Configuration');
2836
$section->addClass('pptp');
2837

    
2838
$section->addInput(new Form_Input(
2839
	'pptp_username',
2840
	'*Username',
2841
	'text',
2842
	$pconfig['pptp_username']
2843
));
2844

    
2845
$section->addPassword(new Form_Input(
2846
	'pptp_password',
2847
	'*Password',
2848
	'password',
2849
	$pconfig['pptp_password']
2850
));
2851

    
2852
$section->addInput(new Form_IpAddress(
2853
	'pptp_local0',
2854
	'*Local IP address',
2855
	$pconfig['pptp_localip'][0],
2856
	'V4'
2857
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2858

    
2859
$section->addInput(new Form_IpAddress(
2860
	'pptp_remote0',
2861
	'*Remote IP address',
2862
	$pconfig['pptp_remote'][0],
2863
	'HOSTV4'
2864
));
2865

    
2866
$section->addInput(new Form_Checkbox(
2867
	'pptp_dialondemand',
2868
	'Dial on demand',
2869
	'Enable Dial-On-Demand mode ',
2870
	$pconfig['pptp_dialondemand'],
2871
	'enable'
2872
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2873
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2874

    
2875
$section->addInput(new Form_Input(
2876
	'pptp_idletimeout',
2877
	'Idle timeout (seconds)',
2878
	'number',
2879
	$pconfig['pptp_idletimeout'],
2880
	['min' => 0]
2881
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2882
			'An idle timeout of zero disables this feature.');
2883

    
2884
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2885
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2886
} else {
2887
	$mlppp_text = "";
2888
}
2889

    
2890
$section->addInput(new Form_Button(
2891
	'btnadvppp',
2892
	'Advanced and MLPPP',
2893
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2894
	'fa-cog'
2895
))->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);
2896

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

    
2899
// Wireless interface
2900
if (isset($wancfg['wireless'])) {
2901

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

    
2904
	$section->addInput(new Form_Checkbox(
2905
		'persistcommonwireless',
2906
		'Persist common settings',
2907
		'Preserve common wireless configuration through interface deletions and reassignments.',
2908
		$pconfig['persistcommonwireless'],
2909
		'yes'
2910
	));
2911

    
2912
	$mode_list = ['auto' => 'Auto'];
2913

    
2914
	if (is_array($wl_modes)) {
2915
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2916
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2917
		}
2918
	}
2919

    
2920
	if (count($mode_list) == 1) {
2921
		$mode_list[''] = '';
2922
	}
2923

    
2924
	$section->addInput(new Form_Select(
2925
		'standard',
2926
		'Standard',
2927
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2928
		$mode_list
2929
	));
2930

    
2931
	if (isset($wl_modes['11g'])) {
2932
		$section->addInput(new Form_Select(
2933
			'protmode',
2934
			'802.11g OFDM Protection Mode',
2935
			$pconfig['protmode'],
2936
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2937
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2938
	} else {
2939
		$section->addInput(new Form_Input(
2940
			'protmode',
2941
			null,
2942
			'hidden',
2943
			'off'
2944
		));
2945
	}
2946

    
2947
	$mode_list = ['0' => gettext('Auto')];
2948

    
2949
	if (is_array($wl_modes)) {
2950
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2951
			if ($wl_standard == "11g") {
2952
				$wl_standard = "11b/g";
2953
			} else if ($wl_standard == "11ng") {
2954
				$wl_standard = "11b/g/n";
2955
			} else if ($wl_standard == "11na") {
2956
				$wl_standard = "11a/n";
2957
			}
2958

    
2959
			foreach ($wl_channels as $wl_channel) {
2960
				if (isset($wl_chaninfo[$wl_channel])) {
2961
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2962
				} else {
2963
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2964
				}
2965
			}
2966
		}
2967
	}
2968

    
2969
	$section->addInput(new Form_Select(
2970
		'channel',
2971
		'Channel',
2972
		$pconfig['channel'],
2973
		$mode_list
2974
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2975
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2976

    
2977
	if (ANTENNAS) {
2978
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2979
			$group = new Form_Group('Antenna Settings');
2980

    
2981
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2982
				$group->add(new Form_Select(
2983
					'diversity',
2984
					null,
2985
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2986
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2987
				))->setHelp('Diversity');
2988
			}
2989

    
2990
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2991
				$group->add(new Form_Select(
2992
					'txantenna',
2993
					null,
2994
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2995
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2996
				))->setHelp('Transmit antenna');
2997
			}
2998

    
2999
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3000
				$group->add(new Form_Select(
3001
					'rxantenna',
3002
					null,
3003
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3004
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3005
				))->setHelp('Receive antenna');
3006
			}
3007

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

    
3010
			$section->add($group);
3011
		}
3012
	}
3013

    
3014
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3015
			$section->addInput(new Form_Input(
3016
				'distance',
3017
				'Distance setting (meters)',
3018
				'test',
3019
				$pconfig['distance']
3020
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3021
	}
3022

    
3023
	$form->add($section);
3024

    
3025
	// Regulatory settings
3026
	$section = new Form_Section('Regulatory Settings');
3027

    
3028
	$domain_list = array("" => 'Default');
3029

    
3030
	if (is_array($wl_regdomains)) {
3031
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3032
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3033
		}
3034
	}
3035

    
3036
	$section->addInput(new Form_Select(
3037
		'regdomain',
3038
		'Regulatory domain',
3039
		$pconfig['regdomain'],
3040
		$domain_list
3041
	))->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');
3042

    
3043
	$country_list = array('' => 'Default');
3044

    
3045
	if (is_array($wl_countries)) {
3046
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3047
			$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']);
3048
		}
3049
	}
3050

    
3051
	$section->addInput(new Form_Select(
3052
		'regcountry',
3053
		'Country',
3054
		$pconfig['regcountry'],
3055
		$country_list
3056
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3057

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

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

    
3071
	$section = new Form_Section('Network-Specific Wireless Configuration');
3072

    
3073
	$section->addInput(new Form_Select(
3074
		'mode',
3075
		'Mode',
3076
		$pconfig['mode'],
3077
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3078
	));
3079

    
3080
	$section->addInput(new Form_Input(
3081
		'ssid',
3082
		'SSID',
3083
		'text',
3084
		$pconfig['ssid']
3085
	));
3086

    
3087
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3088
		$section->addInput(new Form_Select(
3089
			'puremode',
3090
			'Minimum wireless standard',
3091
			$pconfig['puremode'],
3092
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3093
		))->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)');
3094
	} elseif (isset($wl_modes['11g'])) {
3095
		$section->addInput(new Form_Checkbox(
3096
			'puremode',
3097
			'802.11g only',
3098
			null,
3099
			$pconfig['puremode'],
3100
			'11g'
3101
		))->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)');
3102
	}
3103

    
3104
	$section->addInput(new Form_Checkbox(
3105
		'apbridge_enable',
3106
		'Allow intra-BSS communication',
3107
		'Allow packets to pass between wireless clients directly when operating as an access point',
3108
		$pconfig['apbridge_enable'],
3109
		'yes'
3110
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3111

    
3112
	$section->addInput(new Form_Checkbox(
3113
		'wme_enable',
3114
		'Enable WME',
3115
		'Force the card to use WME (wireless QoS)',
3116
		$pconfig['wme_enable'],
3117
		'yes'
3118
	));
3119

    
3120
	$section->addInput(new Form_Checkbox(
3121
		'hidessid_enable',
3122
		'Hide SSID',
3123
		'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.)',
3124
		$pconfig['hidessid_enable'],
3125
		'yes'
3126
	));
3127

    
3128
	$form->add($section);
3129

    
3130
	// WPA Section
3131
	$section = new Form_Section('WPA');
3132

    
3133
	$section->addInput(new Form_Checkbox(
3134
		'wpa_enable',
3135
		'Enable',
3136
		'Enable WPA',
3137
		$pconfig['wpa_enable'],
3138
		'yes'
3139
	));
3140

    
3141
	$section->addInput(new Form_Input(
3142
		'passphrase',
3143
		'WPA Pre-Shared Key',
3144
		'text',
3145
		$pconfig['passphrase']
3146
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3147

    
3148
	$section->addInput(new Form_Select(
3149
		'wpa_mode',
3150
		'WPA mode',
3151
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3152
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3153
	));
3154

    
3155
	$section->addInput(new Form_Select(
3156
		'wpa_key_mgmt',
3157
		'WPA Key Management Mode',
3158
		$pconfig['wpa_key_mgmt'],
3159
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3160
	));
3161

    
3162
	$section->addInput(new Form_Select(
3163
		'wpa_pairwise',
3164
		'WPA Pairwise',
3165
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3166
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3167
	));
3168

    
3169
	$section->addInput(new Form_Input(
3170
		'wpa_group_rekey',
3171
		'Group Key Rotation',
3172
		'number',
3173
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3174
		['min' => '1', 'max' => 9999]
3175
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3176

    
3177
	$section->addInput(new Form_Input(
3178
		'wpa_gmk_rekey',
3179
		'Group Master Key Regeneration',
3180
		'number',
3181
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3182
		['min' => '1', 'max' => 9999]
3183
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3184

    
3185
	$section->addInput(new Form_Checkbox(
3186
		'wpa_strict_rekey',
3187
		'Strict Key Regeneration',
3188
		'Force the AP to rekey whenever a client disassociates',
3189
		$pconfig['wpa_strict_rekey'],
3190
		'yes'
3191
	));
3192

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

    
3195
	$section = new Form_Section('802.1x RADIUS Options');
3196

    
3197
	$section->addInput(new Form_Checkbox(
3198
		'ieee8021x',
3199
		'IEEE802.1X',
3200
		'Enable 802.1X authentication',
3201
		$pconfig['ieee8021x'],
3202
		'yes'
3203
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3204

    
3205
	$group = new Form_Group('Primary 802.1X server');
3206

    
3207
	$group->add(new Form_IpAddress(
3208
		'auth_server_addr',
3209
		'IP Address',
3210
		$pconfig['auth_server_addr']
3211
	))->setHelp('IP address of the RADIUS server');
3212

    
3213
	$group->add(new Form_Input(
3214
		'auth_server_port',
3215
		'Port',
3216
		'number',
3217
		$pconfig['auth_server_port']
3218
	))->setHelp('Server auth port. Default is 1812');
3219

    
3220
	$group->add(new Form_Input(
3221
		'auth_server_shared_secret',
3222
		'Shared Secret',
3223
		'text',
3224
		$pconfig['auth_server_shared_secret']
3225
	))->setHelp('RADIUS Shared secret for this firewall');
3226

    
3227
	$section->add($group);
3228

    
3229
	$group = new Form_Group('Secondary 802.1X server');
3230

    
3231
	$group->add(new Form_IpAddress(
3232
		'auth_server_addr2',
3233
		'IP Address',
3234
		$pconfig['auth_server_addr2']
3235
	))->setHelp('IP address of the RADIUS server');
3236

    
3237
	$group->add(new Form_Input(
3238
		'auth_server_port2',
3239
		'Port',
3240
		'number',
3241
		$pconfig['auth_server_port2']
3242
	))->setHelp('Server auth port. Default is 1812');
3243

    
3244
	$group->add(new Form_Input(
3245
		'auth_server_shared_secret2',
3246
		'Shared Secret',
3247
		'text',
3248
		$pconfig['auth_server_shared_secret2']
3249
	))->setHelp('RADIUS Shared secret for this firewall');
3250

    
3251
	$section->add($group);
3252

    
3253
	$section->addInput(new Form_Checkbox(
3254
		'rsn_preauth',
3255
		'Authentication Roaming Preauth',
3256
		null,
3257
		$pconfig['rsn_preauth'],
3258
		'yes'
3259
	));
3260

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

    
3264
$section = new Form_Section('Reserved Networks');
3265

    
3266
$section->addInput(new Form_Checkbox(
3267
	'blockpriv',
3268
	'Block private networks and loopback addresses',
3269
	'',
3270
	$pconfig['blockpriv'],
3271
	'yes'
3272
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3273
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3274
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3275

    
3276
$section->addInput(new Form_Checkbox(
3277
	'blockbogons',
3278
	'Block bogon networks',
3279
	'',
3280
	$pconfig['blockbogons'],
3281
	'yes'
3282
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3283
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3284
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3285

    
3286
$form->add($section);
3287

    
3288
$form->addGlobal(new Form_Input(
3289
	'if',
3290
	null,
3291
	'hidden',
3292
	$if
3293
));
3294

    
3295
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3296
	$form->addGlobal(new Form_Input(
3297
		'ppp_port',
3298
		null,
3299
		'hidden',
3300
		$pconfig['port']
3301
	));
3302
}
3303

    
3304
$form->addGlobal(new Form_Input(
3305
	'ptpid',
3306
	null,
3307
	'hidden',
3308
	$pconfig['ptpid']
3309
));
3310

    
3311

    
3312
// Add new gateway modal pop-up
3313
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3314

    
3315
$modal->addInput(new Form_Checkbox(
3316
	'defaultgw4',
3317
	'Default',
3318
	'Default gateway',
3319
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3320
));
3321

    
3322
$modal->addInput(new Form_Input(
3323
	'gatewayname4',
3324
	'Gateway name',
3325
	'text',
3326
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3327
));
3328

    
3329
$modal->addInput(new Form_IpAddress(
3330
	'gatewayip4',
3331
	'Gateway IPv4',
3332
	$gateway_settings4['gateway'],
3333
	'V4'
3334
));
3335

    
3336
$modal->addInput(new Form_Input(
3337
	'gatewaydescr4',
3338
	'Description',
3339
	'text',
3340
	$gateway_settings4['descr']
3341
));
3342

    
3343
$btnaddgw4 = new Form_Button(
3344
	'add4',
3345
	'Add',
3346
	null,
3347
	'fa-plus'
3348
);
3349

    
3350
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3351

    
3352
$btncnxgw4 = new Form_Button(
3353
	'cnx4',
3354
	'Cancel',
3355
	null,
3356
	'fa-undo'
3357
);
3358

    
3359
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3360

    
3361
$modal->addInput(new Form_StaticText(
3362
	null,
3363
	$btnaddgw4 . $btncnxgw4
3364
));
3365

    
3366
$form->add($modal);
3367

    
3368
print($form);
3369
?>
3370

    
3371
<script type="text/javascript">
3372
//<![CDATA[
3373
events.push(function() {
3374
	function updateType(t) {
3375

    
3376
		switch (t) {
3377
			case "none": {
3378
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3379
				break;
3380
			}
3381
			case "staticv4": {
3382
				$('.dhcpadvanced, .none, .dhcp').hide();
3383
				$('.pppoe, .pptp, .ppp').hide();
3384
				break;
3385
			}
3386
			case "dhcp": {
3387
				$('.dhcpadvanced, .none').hide();
3388
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3389
										//			about the staticv4 class
3390
				$('.pppoe, .pptp, .ppp').hide();
3391
				break;
3392
			}
3393
			case "ppp": {
3394
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3395
				country_list();
3396
				break;
3397
			}
3398
			case "pppoe": {
3399
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3400
				break;
3401
			}
3402
			case "l2tp":
3403
			case "pptp": {
3404
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3405
				$('.pptp').show();
3406
				break;
3407
			}
3408
		}
3409

    
3410
		if (t != "l2tp" && t != "pptp") {
3411
			$('.'+t).show();
3412
		}
3413
	}
3414

    
3415
	function updateTypeSix(t) {
3416
		if (!isNaN(t[0])) {
3417
			t = '_' + t;
3418
		}
3419

    
3420
		switch (t) {
3421
			case "none": {
3422
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3423
				break;
3424
			}
3425
			case "staticv6": {
3426
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3427
				break;
3428
			}
3429
			case "slaac": {
3430
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3431
				break;
3432
			}
3433
			case "dhcp6": {
3434
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3435
				break;
3436
			}
3437
			case "_6rd": {
3438
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3439
				break;
3440
			}
3441
			case "_6to4": {
3442
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3443
				break;
3444
			}
3445
			case "track6": {
3446
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3447
				update_track6_prefix();
3448
				break;
3449
			}
3450
		}
3451

    
3452
		if (t != "l2tp" && t != "pptp") {
3453
			$('.'+t).show();
3454
		}
3455
	}
3456

    
3457
	function show_reset_settings(reset_type) {
3458
		if (reset_type == 'preset') {
3459
			$('.pppoepreset').show();
3460
			$('.pppoecustom').hide();
3461
		} else if (reset_type == 'custom') {
3462
			$('.pppoecustom').show();
3463
			$('.pppoepreset').hide();
3464
		} else {
3465
			$('.pppoecustom').hide();
3466
			$('.pppoepreset').hide();
3467
		}
3468
	}
3469

    
3470
	function update_track6_prefix() {
3471
		var iface = $("#track6-interface").val();
3472
		if (iface == null) {
3473
			return;
3474
		}
3475

    
3476
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3477
		if (track6_prefix_ids == null) {
3478
			return;
3479
		}
3480

    
3481
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3482
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3483
	}
3484

    
3485
	function addOption_v4() {
3486
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3487
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3488
	}
3489

    
3490
	function addOption_v6() {
3491
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3492
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3493
	}
3494

    
3495
	function addSelectboxOption(selectbox, text, value) {
3496
		var optn = document.createElement("OPTION");
3497
		optn.text = text;
3498
		optn.value = value;
3499
		selectbox.append(optn);
3500
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3501
	}
3502

    
3503
	function country_list() {
3504
		$('#country').children().remove();
3505
		$('#provider_list').children().remove();
3506
		$('#providerplan').children().remove();
3507
		$.ajax("getserviceproviders.php",{
3508
			success: function(response) {
3509

    
3510
				var responseTextArr = response.split("\n");
3511
				responseTextArr.sort();
3512

    
3513
				responseTextArr.forEach( function(value) {
3514
					country = value.split(":");
3515
					$('#country').append($('<option>', {
3516
						value: country[1],
3517
						text : country[0]
3518
					}));
3519
				});
3520
			}
3521
		});
3522
	}
3523

    
3524
	function providers_list() {
3525
		$('#provider_list').children().remove();
3526
		$('#providerplan').children().remove();
3527
		$.ajax("getserviceproviders.php",{
3528
			type: 'post',
3529
			data: {country : $('#country').val()},
3530
			success: function(response) {
3531
				var responseTextArr = response.split("\n");
3532
				responseTextArr.sort();
3533
				responseTextArr.forEach( function(value) {
3534
					$('#provider_list').append($('<option>', {
3535
							value: value,
3536
							text : value
3537
					}));
3538
				});
3539
			}
3540
		});
3541
	}
3542

    
3543
	function providerplan_list() {
3544
		$('#providerplan').children().remove();
3545
		$.ajax("getserviceproviders.php",{
3546
			type: 'post',
3547
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3548
			success: function(response) {
3549
				var responseTextArr = response.split("\n");
3550
				responseTextArr.sort();
3551

    
3552
				$('#providerplan').append($('<option>', {
3553
					value: '',
3554
					text : ''
3555
				}));
3556

    
3557
				responseTextArr.forEach( function(value) {
3558
					if (value != "") {
3559
						providerplan = value.split(":");
3560

    
3561
						$('#providerplan').append($('<option>', {
3562
							value: providerplan[1],
3563
							text : providerplan[0] + " - " + providerplan[1]
3564
						}));
3565
					}
3566
				});
3567
			}
3568
		});
3569
	}
3570

    
3571
	function prefill_provider() {
3572
		$.ajax("getserviceproviders.php",{
3573
			type: 'post',
3574
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3575
			success: function(data, textStatus, response) {
3576
				var xmldoc = response.responseXML;
3577
				var provider = xmldoc.getElementsByTagName('connection')[0];
3578
				$('#ppp_username').val('');
3579
				$('#ppp_password').val('');
3580
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3581
					$('#phone').val('#777');
3582
					$('#apn').val('');
3583
				} else {
3584
					$('#phone').val('*99#');
3585
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3586
				}
3587
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3588
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3589
				$('#ppp_username').val(ppp_username);
3590
				$('#ppp_password').val(ppp_password);
3591
			}
3592
		});
3593
	}
3594

    
3595
	function show_dhcp6adv() {
3596
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3597
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3598

    
3599
		hideCheckbox('dhcp6usev4iface', ovr);
3600
		hideCheckbox('dhcp6prefixonly', ovr);
3601
		hideInput('dhcp6-ia-pd-len', ovr);
3602
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3603
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3604

    
3605
		hideClass('dhcp6advanced', !adv || ovr);
3606
	}
3607

    
3608
	function setDHCPoptions() {
3609
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3610
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3611

    
3612
		if (ovr) {
3613
			hideInput('dhcphostname', true);
3614
			hideIpAddress('alias-address', true);
3615
			hideInput('dhcprejectfrom', true);
3616
			hideInput('adv_dhcp_config_file_override_path', false);
3617
			hideClass('dhcpadvanced', true);
3618
		} else {
3619
			hideInput('dhcphostname', false);
3620
			hideIpAddress('alias-address', false);
3621
			hideInput('dhcprejectfrom', false);
3622
			hideInput('adv_dhcp_config_file_override_path', true);
3623
			hideClass('dhcpadvanced', !adv);
3624
		}
3625
	}
3626

    
3627
	// DHCP preset actions
3628
	// Set presets from value of radio buttons
3629
	function setPresets(val) {
3630
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3631
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3632
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3633
		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']);?>");
3634
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3635
	}
3636

    
3637
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3638
		$('#adv_dhcp_pt_timeout').val(timeout);
3639
		$('#adv_dhcp_pt_retry').val(retry);
3640
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3641
		$('#adv_dhcp_pt_reboot').val(reboot);
3642
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3643
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3644
	}
3645

    
3646
	function setPPPoEDialOnDemandItems() {
3647
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3648
	}
3649

    
3650
	function setPPTPDialOnDemandItems() {
3651
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3652
	}
3653

    
3654
	// ---------- On initial page load ------------------------------------------------------------
3655

    
3656
	updateType($('#type').val());
3657
	updateTypeSix($('#type6').val());
3658
	show_reset_settings($('#pppoe-reset-type').val());
3659
	hideClass('dhcp6advanced', true);
3660
	hideClass('dhcpadvanced', true);
3661
	show_dhcp6adv();
3662
	setDHCPoptions();
3663
	setPPPoEDialOnDemandItems();
3664
	setPPTPDialOnDemandItems();
3665

    
3666
	// Set preset buttons on page load
3667
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3668
	if (sv == "") {
3669
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3670
	} else {
3671
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3672
	}
3673

    
3674
	// Set preset from value
3675
	setPresets(sv);
3676

    
3677
	// If the user wants to add a gateway, then add that to the gateway selection
3678
	if ($("#gatewayip4").val() != '') {
3679
		addOption_v4();
3680
	}
3681
	if ($("#gatewayip6").val() != '') {
3682
		addOption_v6();
3683
	}
3684

    
3685
	// ---------- Click checkbox handlers ---------------------------------------------------------
3686

    
3687
	$('#type').on('change', function() {
3688
		updateType(this.value);
3689
	});
3690

    
3691
	$('#type6').on('change', function() {
3692
		updateTypeSix(this.value);
3693
	});
3694

    
3695
	$('#track6-interface').on('change', function() {
3696
		update_track6_prefix();
3697
	});
3698

    
3699
	$('#pppoe-reset-type').on('change', function() {
3700
		show_reset_settings(this.value);
3701
	});
3702

    
3703
	$("#add4").click(function() {
3704
		addOption_v4();
3705
		$("#newgateway4").modal('hide');
3706
	});
3707

    
3708
	$("#cnx4").click(function() {
3709
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3710
		$("#gatewayip4").val('');
3711
		$("#gatewaydescr4").val('');
3712
		$("#defaultgw4").prop("checked", false);
3713
		$("#newgateway4").modal('hide');
3714
	});
3715

    
3716
	$("#add6").click(function() {
3717
		addOption_v6();
3718
		$("#newgateway6").modal('hide');
3719
	});
3720

    
3721
	$("#cnx6").click(function() {
3722
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3723
		$("#gatewayip6").val('');
3724
		$("#gatewaydescr6").val('');
3725
		$("#defaultgw6").prop("checked", false);
3726
		$("#newgateway6").modal('hide');
3727
	});
3728

    
3729
	$('#country').on('change', function() {
3730
		providers_list();
3731
	});
3732

    
3733
	$('#provider_list').on('change', function() {
3734
		providerplan_list();
3735
	});
3736

    
3737
	$('#providerplan').on('change', function() {
3738
		prefill_provider();
3739
	});
3740

    
3741
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3742
		setDHCPoptions();
3743
	});
3744

    
3745
	$('#adv_dhcp6_config_advanced').click(function () {
3746
		show_dhcp6adv();
3747
	});
3748

    
3749
	$('#adv_dhcp6_config_file_override').click(function () {
3750
		show_dhcp6adv();
3751
	});
3752

    
3753
	// On click . .
3754
	$('#pppoe_dialondemand').click(function () {
3755
		setPPPoEDialOnDemandItems();
3756
	});
3757

    
3758
	$('#pptp_dialondemand').click(function () {
3759
		setPPTPDialOnDemandItems();
3760
	});
3761

    
3762
	$('[name=adv_dhcp_pt_values]').click(function () {
3763
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3764
	});
3765

    
3766
	$('#pppoe_resetdate').datepicker();
3767

    
3768
});
3769
//]]>
3770
</script>
3771

    
3772
<?php include("foot.inc");
(72-72/232)