Project

General

Profile

Download (125 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 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
		break;
293
	case "6to4":
294
		$pconfig['type6'] = "6to4";
295
		break;
296
	case "track6":
297
		$pconfig['type6'] = "track6";
298
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
299
		if ($wancfg['track6-prefix-id'] == "") {
300
			$pconfig['track6-prefix-id'] = 0;
301
		} else {
302
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
303
		}
304
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
305
		break;
306
	case "6rd":
307
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
308
		if ($wancfg['prefix-6rd-v4plen'] == "") {
309
			$wancfg['prefix-6rd-v4plen'] = "0";
310
		}
311
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
312
		$pconfig['type6'] = "6rd";
313
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
314
		break;
315
	default:
316
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
317
			$pconfig['type6'] = "staticv6";
318
			$pconfig['ipv6usev4iface'] = isset($wancfg['ipv6usev4iface']);
319
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
320
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
321
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
322
		} else {
323
			$pconfig['type6'] = "none";
324
		}
325
		break;
326
}
327

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

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

    
410
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
411

    
412
}
413

    
414
$changes_applied = false;
415

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

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

    
452
		/* sync filter configuration */
453
		setup_gateways_monitor();
454

    
455
		clear_subsystem_dirty('interfaces');
456

    
457
		$retval |= filter_configure();
458

    
459
		enable_rrd_graphing();
460

    
461
		$changes_applied = true;
462

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

    
470
	unset($input_errors);
471
	$pconfig = $_POST;
472

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
846
		unset($min_mtu, $max_mtu);
847

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1063
		unset($wancfg['adv_dhcp_pt_timeout']);
1064
		unset($wancfg['adv_dhcp_pt_retry']);
1065
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1066
		unset($wancfg['adv_dhcp_pt_reboot']);
1067
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1068
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1069

    
1070
		unset($wancfg['adv_dhcp_pt_values']);
1071

    
1072
		unset($wancfg['adv_dhcp_send_options']);
1073
		unset($wancfg['adv_dhcp_request_options']);
1074
		unset($wancfg['adv_dhcp_required_options']);
1075
		unset($wancfg['adv_dhcp_option_modifiers']);
1076

    
1077
		unset($wancfg['adv_dhcp_config_advanced']);
1078
		unset($wancfg['adv_dhcp_config_file_override']);
1079
		unset($wancfg['adv_dhcp_config_file_override_path']);
1080

    
1081
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1082
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1083
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1084
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1085

    
1086
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1087
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1088
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1089
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1090
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1091

    
1092
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1093
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1094
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1095
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1096
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1097

    
1098
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1099
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1100
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1101

    
1102
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1103
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1104
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1105
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1106

    
1107
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1108
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1109
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1110
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1111
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1112

    
1113
		unset($wancfg['adv_dhcp6_config_advanced']);
1114
		unset($wancfg['adv_dhcp6_config_file_override']);
1115
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1116

    
1117
		unset($wancfg['pppoe_password']);
1118
		unset($wancfg['pptp_username']);
1119
		unset($wancfg['pptp_password']);
1120
		unset($wancfg['provider']);
1121
		unset($wancfg['ondemand']);
1122
		unset($wancfg['timeout']);
1123
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1124
			unset($wancfg['pppoe']['pppoe-reset-type']);
1125
		}
1126
		unset($wancfg['local']);
1127

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

    
1149
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1150
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1151

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

    
1168
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1169
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1170
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1171
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1172
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1173
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1174

    
1175
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1176

    
1177
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1178
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1179
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1180
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1181

    
1182
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1183
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1184
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1185

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

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

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

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

    
1310
				if ($_POST['dhcp6withoutra'] == "yes") {
1311
					$wancfg['dhcp6withoutra'] = true;
1312
				}
1313
				if ($_POST['dhcp6norelease'] == "yes") {
1314
					$wancfg['dhcp6norelease'] = true;
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1317
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1320
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1321
				}
1322
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1323
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1326
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1327
				}
1328

    
1329
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1330
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1333
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1334
				}
1335
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1336
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1339
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1340
				}
1341
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1342
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1343
				}
1344

    
1345
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1346
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1347
				}
1348
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1349
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1350
				}
1351
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1352
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1353
				}
1354
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1355
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1356
				}
1357
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1358
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1359
				}
1360

    
1361
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1362
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1363
				}
1364
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1365
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1366
				}
1367
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1368
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1369
				}
1370
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1371
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1372
				}
1373
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1374
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1375
				}
1376
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1377
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1378
				}
1379
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1380
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1381
				}
1382

    
1383
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1384
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1385
				}
1386
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1387
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1388
				}
1389
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1390
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1391
				}
1392
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1393
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1394
				}
1395
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1396
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1397
				}
1398

    
1399
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1400
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1401
				}
1402
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1403
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1404
				}
1405
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1406
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1407
				}
1408

    
1409
				if ($gateway_item) {
1410
					$a_gateways[] = $gateway_item;
1411
				}
1412
				break;
1413
			case "6rd":
1414
				$wancfg['ipaddrv6'] = "6rd";
1415
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1416
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1417
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1418
				if ($gateway_item) {
1419
					$a_gateways[] = $gateway_item;
1420
				}
1421
				break;
1422
			case "6to4":
1423
				$wancfg['ipaddrv6'] = "6to4";
1424
				break;
1425
			case "track6":
1426
				$wancfg['ipaddrv6'] = "track6";
1427
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1428
				if ($_POST['track6-prefix-id--hex'] === "") {
1429
					$wancfg['track6-prefix-id'] = 0;
1430
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1431
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1432
				} else {
1433
					$wancfg['track6-prefix-id'] = 0;
1434
				}
1435
				break;
1436
			case "none":
1437
				break;
1438
		}
1439
		handle_pppoe_reset($_POST);
1440

    
1441
		if ($_POST['blockpriv'] == "yes") {
1442
			$wancfg['blockpriv'] = true;
1443
		} else {
1444
			unset($wancfg['blockpriv']);
1445
		}
1446
		if ($_POST['blockbogons'] == "yes") {
1447
			$wancfg['blockbogons'] = true;
1448
		} else {
1449
			unset($wancfg['blockbogons']);
1450
		}
1451
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1452
		if (empty($_POST['mtu'])) {
1453
			unset($wancfg['mtu']);
1454
		} else {
1455
			$wancfg['mtu'] = $_POST['mtu'];
1456
		}
1457
		if (empty($_POST['mss'])) {
1458
			unset($wancfg['mss']);
1459
		} else {
1460
			$wancfg['mss'] = $_POST['mss'];
1461
		}
1462
		if (empty($_POST['mediaopt'])) {
1463
			unset($wancfg['media']);
1464
			unset($wancfg['mediaopt']);
1465
		} else {
1466
			$mediaopts = explode(' ', $_POST['mediaopt']);
1467
			if ($mediaopts[0] != '') {
1468
				$wancfg['media'] = $mediaopts[0];
1469
			}
1470
			if ($mediaopts[1] != '') {
1471
				$wancfg['mediaopt'] = $mediaopts[1];
1472
			} else {
1473
				unset($wancfg['mediaopt']);
1474
			}
1475
		}
1476
		if (isset($wancfg['wireless'])) {
1477
			handle_wireless_post();
1478
		}
1479

    
1480
		write_config();
1481

    
1482
		if ($_POST['gatewayip4']) {
1483
			save_gateway($gateway_settings4);
1484
		}
1485

    
1486
		if ($_POST['gatewayip6']) {
1487
			save_gateway($gateway_settings6);
1488
		}
1489

    
1490
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1491
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1492
		} else {
1493
			$toapplylist = array();
1494
		}
1495
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1496
		$toapplylist[$if]['ppps'] = $old_ppps;
1497
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1498

    
1499
		mark_subsystem_dirty('interfaces');
1500

    
1501
		/* regenerate cron settings/crontab file */
1502
		configure_cron();
1503

    
1504
		header("Location: interfaces.php?if={$if}");
1505
		exit;
1506
	}
1507

    
1508
} // end if ($_POST['save'])
1509

    
1510
function handle_wireless_post() {
1511
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1512
	if (!is_array($wancfg['wireless'])) {
1513
		$wancfg['wireless'] = array();
1514
	}
1515
	$wancfg['wireless']['standard'] = $_POST['standard'];
1516
	$wancfg['wireless']['mode'] = $_POST['mode'];
1517
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1518
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1519
	$wancfg['wireless']['channel'] = $_POST['channel'];
1520
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1521
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1522
	$wancfg['wireless']['distance'] = $_POST['distance'];
1523
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1524
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1525
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1526
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1527
		foreach ($wl_countries_attr as $wl_country) {
1528
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1529
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1530
				break;
1531
			}
1532
		}
1533
	}
1534
	if (!is_array($wancfg['wireless']['wpa'])) {
1535
		$wancfg['wireless']['wpa'] = array();
1536
	}
1537
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1538
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1539
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1540
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1541
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1542
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1543
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1544
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1545
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1546
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1547
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1548
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1549
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1550
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1551

    
1552
	if ($_POST['persistcommonwireless'] == "yes") {
1553
		if (!is_array($config['wireless'])) {
1554
			$config['wireless'] = array();
1555
		}
1556
		if (!is_array($config['wireless']['interfaces'])) {
1557
			$config['wireless']['interfaces'] = array();
1558
		}
1559
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1560
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1561
		}
1562
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1563
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1564
	}
1565
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1566
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1567
	} else if (isset($wancfg['wireless']['diversity'])) {
1568
		unset($wancfg['wireless']['diversity']);
1569
	}
1570
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1571
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1572
	} else if (isset($wancfg['wireless']['txantenna'])) {
1573
		unset($wancfg['wireless']['txantenna']);
1574
	}
1575
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1576
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1577
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1578
		unset($wancfg['wireless']['rxantenna']);
1579
	}
1580
	if ($_POST['hidessid_enable'] == "yes") {
1581
		$wancfg['wireless']['hidessid']['enable'] = true;
1582
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1583
		unset($wancfg['wireless']['hidessid']['enable']);
1584
	}
1585
	if ($_POST['mac_acl_enable'] == "yes") {
1586
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1587
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1588
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1589
	}
1590
	if ($_POST['rsn_preauth'] == "yes") {
1591
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1592
	} else {
1593
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1594
	}
1595
	if ($_POST['ieee8021x'] == "yes") {
1596
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1597
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1598
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1599
	}
1600
	if ($_POST['wpa_strict_rekey'] == "yes") {
1601
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1602
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1603
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1604
	}
1605
	if ($_POST['debug_mode'] == "yes") {
1606
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1607
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1608
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1609
	}
1610
	if ($_POST['wpa_enable'] == "yes") {
1611
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1612
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1613
		unset($wancfg['wireless']['wpa']['enable']);
1614
	}
1615

    
1616
	if ($_POST['wme_enable'] == "yes") {
1617
		if (!is_array($wancfg['wireless']['wme'])) {
1618
			$wancfg['wireless']['wme'] = array();
1619
		}
1620
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1621
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1622
		unset($wancfg['wireless']['wme']['enable']);
1623
	}
1624
	if ($_POST['puremode'] == "11g") {
1625
		if (!is_array($wancfg['wireless']['pureg'])) {
1626
			$wancfg['wireless']['pureg'] = array();
1627
		}
1628
		$wancfg['wireless']['pureg']['enable'] = true;
1629
	} else if ($_POST['puremode'] == "11n") {
1630
		if (!is_array($wancfg['wireless']['puren'])) {
1631
			$wancfg['wireless']['puren'] = array();
1632
		}
1633
		$wancfg['wireless']['puren']['enable'] = true;
1634
	} else {
1635
		if (isset($wancfg['wireless']['pureg'])) {
1636
			unset($wancfg['wireless']['pureg']);
1637
		}
1638
		if (isset($wancfg['wireless']['puren'])) {
1639
			unset($wancfg['wireless']['puren']);
1640
		}
1641
	}
1642
	if ($_POST['apbridge_enable'] == "yes") {
1643
		if (!is_array($wancfg['wireless']['apbridge'])) {
1644
			$wancfg['wireless']['apbridge'] = array();
1645
		}
1646
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1647
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1648
		unset($wancfg['wireless']['apbridge']['enable']);
1649
	}
1650
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1651
		if (!is_array($wancfg['wireless']['turbo'])) {
1652
			$wancfg['wireless']['turbo'] = array();
1653
		}
1654
		$wancfg['wireless']['turbo']['enable'] = true;
1655
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1656
		unset($wancfg['wireless']['turbo']['enable']);
1657
	}
1658

    
1659
	interface_sync_wireless_clones($wancfg, true);
1660
}
1661

    
1662
function check_wireless_mode() {
1663
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1664

    
1665
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1666
		return;
1667
	}
1668

    
1669
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1670
		$clone_count = 1;
1671
	} else {
1672
		$clone_count = 0;
1673
	}
1674

    
1675
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1676
		foreach ($config['wireless']['clone'] as $clone) {
1677
			if ($clone['if'] == $wlanbaseif) {
1678
				$clone_count++;
1679
			}
1680
		}
1681
	}
1682

    
1683
	if ($clone_count > 1) {
1684
		$old_wireless_mode = $wancfg['wireless']['mode'];
1685
		$wancfg['wireless']['mode'] = $_POST['mode'];
1686
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1687
			$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']]);
1688
		} else {
1689
			pfSense_interface_destroy("{$wlanif}_");
1690
		}
1691
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1692
	}
1693
}
1694

    
1695
// Find all possible media options for the interface
1696
$mediaopts_list = array();
1697
$intrealname = $config['interfaces'][$if]['if'];
1698
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1699
foreach ($mediaopts as $mediaopt) {
1700
	preg_match("/media (.*)/", $mediaopt, $matches);
1701
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1702
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1703
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1704
	} else {
1705
		// there is only media like "media 1000baseT"
1706
		array_push($mediaopts_list, $matches[1]);
1707
	}
1708
}
1709

    
1710
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1711
$shortcut_section = "interfaces";
1712

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

    
1716
// Get the MAC address
1717
$ip = $_SERVER['REMOTE_ADDR'];
1718
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1719
$mymac = str_replace("\n", "", $mymac);
1720
$defgatewayname4 = $wancfg['descr'] . "GW";
1721
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1722

    
1723
function build_mediaopts_list() {
1724
	global $mediaopts_list;
1725

    
1726
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1727
			 " " =>	 gettext("------- Media Supported by this interface -------")
1728
			];
1729

    
1730
	foreach ($mediaopts_list as $mediaopt) {
1731
		$list[$mediaopt] = $mediaopt;
1732
	}
1733

    
1734
	return($list);
1735
}
1736

    
1737
function build_gateway_list() {
1738
	global $a_gateways, $if;
1739

    
1740
	$list = array("none" => gettext("None"));
1741
	foreach ($a_gateways as $gateway) {
1742
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1743
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1744
		}
1745
	}
1746

    
1747
	return($list);
1748
}
1749

    
1750
function build_gatewayv6_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_ipaddrv6($gateway['gateway']))) {
1756
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1757
		}
1758
	}
1759

    
1760
	return($list);
1761
}
1762

    
1763
include("head.inc");
1764

    
1765
if ($input_errors) {
1766
	print_input_errors($input_errors);
1767
}
1768

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

    
1775
if ($changes_applied) {
1776
	print_apply_result_box($retval);
1777
}
1778

    
1779
$form = new Form();
1780

    
1781
$section = new Form_Section('General Configuration');
1782

    
1783
$section->addInput(new Form_Checkbox(
1784
	'enable',
1785
	'Enable',
1786
	'Enable interface',
1787
	$pconfig['enable'],
1788
	'yes'
1789
));
1790

    
1791
$section->addInput(new Form_Input(
1792
	'descr',
1793
	'*Description',
1794
	'text',
1795
	$pconfig['descr']
1796
))->setHelp('Enter a description (name) for the interface here.');
1797

    
1798
$section->addInput(new Form_Select(
1799
	'type',
1800
	'IPv4 Configuration Type',
1801
	$pconfig['type'],
1802
	$types4
1803
));
1804

    
1805
$section->addInput(new Form_Select(
1806
	'type6',
1807
	'IPv6 Configuration Type',
1808
	$pconfig['type6'],
1809
	$types6
1810
));
1811

    
1812
$macaddress = new Form_Input(
1813
	'spoofmac',
1814
	'MAC Address',
1815
	'text',
1816
	$pconfig['spoofmac'],
1817
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1818
);
1819

    
1820
$btnmymac = new Form_Button(
1821
	'btnmymac',
1822
	'Copy My MAC',
1823
	null,
1824
	'fa-clone'
1825
	);
1826

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

    
1829
$group = new Form_Group('MAC Address');
1830
$group->add($macaddress);
1831
// $group->add($btnmymac);
1832
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1833
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1834
$section->add($group);
1835

    
1836
$section->addInput(new Form_Input(
1837
	'mtu',
1838
	'MTU',
1839
	'number',
1840
	$pconfig['mtu']
1841
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1842
			'This is typically 1500 bytes but can vary in some circumstances.');
1843

    
1844
$section->addInput(new Form_Input(
1845
	'mss',
1846
	'MSS',
1847
	'number',
1848
	$pconfig['mss']
1849
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1850
			'header size) will be in effect.');
1851

    
1852
if (count($mediaopts_list) > 0) {
1853
	$section->addInput(new Form_Select(
1854
		'mediaopt',
1855
		'Speed and Duplex',
1856
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1857
		build_mediaopts_list()
1858
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1859
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1860
}
1861

    
1862
$form->add($section);
1863

    
1864
$section = new Form_Section('Static IPv4 Configuration');
1865
$section->addClass('staticv4');
1866

    
1867
$section->addInput(new Form_IpAddress(
1868
	'ipaddr',
1869
	'*IPv4 Address',
1870
	$pconfig['ipaddr'],
1871
	'V4'
1872
))->addMask('subnet', $pconfig['subnet'], 32);
1873

    
1874
$group = new Form_Group('IPv4 Upstream gateway');
1875

    
1876
$group->add(new Form_Select(
1877
	'gateway',
1878
	'IPv4 Upstream Gateway',
1879
	$pconfig['gateway'],
1880
	build_gateway_list()
1881
));
1882

    
1883
$group->add(new Form_Button(
1884
	'addgw4',
1885
	'Add a new gateway',
1886
	null,
1887
	'fa-plus'
1888
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1889

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

    
1894
$section->add($group);
1895

    
1896
$form->add($section);
1897

    
1898
$section = new Form_Section('Static IPv6 Configuration');
1899
$section->addClass('staticv6');
1900

    
1901
$section->addInput(new Form_IpAddress(
1902
	'ipaddrv6',
1903
	'*IPv6 address',
1904
	$pconfig['ipaddrv6'],
1905
	'V6'
1906
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1907

    
1908
$section->addInput(new Form_Checkbox(
1909
	'ipv6usev4iface',
1910
	'Use IPv4 connectivity as parent interface',
1911
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1912
	$pconfig['ipv6usev4iface']
1913
));
1914

    
1915
$group = new Form_Group('IPv6 Upstream gateway');
1916

    
1917
$group->add(new Form_Select(
1918
	'gatewayv6',
1919
	'IPv6 Upstream Gateway',
1920
	$pconfig['gatewayv6'],
1921
	build_gatewayv6_list()
1922
));
1923

    
1924
$group->add(new Form_Button(
1925
	'addgw6',
1926
	'Add a new gateway',
1927
	null,
1928
	'fa-plus'
1929
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1930

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

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

    
1937
// Add new gateway modal pop-up for IPv6
1938
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1939

    
1940
$modal->addInput(new Form_Checkbox(
1941
	'defaultgw6',
1942
	'Default',
1943
	'Default gateway',
1944
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
1945
));
1946

    
1947
$modal->addInput(new Form_Input(
1948
	'gatewayname6',
1949
	'Gateway name',
1950
	'text',
1951
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
1952
));
1953

    
1954
$modal->addInput(new Form_IpAddress(
1955
	'gatewayip6',
1956
	'Gateway IPv6',
1957
	$gateway_settings6['gateway'],
1958
	'V6'
1959
));
1960

    
1961
$modal->addInput(new Form_Input(
1962
	'gatewaydescr6',
1963
	'Description',
1964
	'text',
1965
	$gateway_settings6['descr']
1966
));
1967

    
1968
$btnaddgw6 = new Form_Button(
1969
	'add6',
1970
	'Add',
1971
	null,
1972
	'fa-plus'
1973
);
1974

    
1975
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1976

    
1977
$btncnxgw6 = new Form_Button(
1978
	'cnx6',
1979
	'Cancel',
1980
	null,
1981
	'fa-undo'
1982
);
1983

    
1984
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1985

    
1986
$modal->addInput(new Form_StaticText(
1987
	null,
1988
	$btnaddgw6 . $btncnxgw6
1989
));
1990

    
1991
$form->add($modal);
1992

    
1993
// ==== DHCP client configuration =============================
1994

    
1995
$section = new Form_Section('DHCP Client Configuration');
1996
$section->addClass('dhcp');
1997

    
1998
$group = new Form_Group('Options');
1999

    
2000
$group->add(new Form_Checkbox(
2001
	'adv_dhcp_config_advanced',
2002
	null,
2003
	'Advanced Configuration',
2004
	$pconfig['adv_dhcp_config_advanced']
2005
))->setHelp('Use advanced DHCP configuration options.');
2006

    
2007
$group->add(new Form_Checkbox(
2008
	'adv_dhcp_config_file_override',
2009
	null,
2010
	'Configuration Override',
2011
	$pconfig['adv_dhcp_config_file_override']
2012
))->setHelp('Override the configuration from this file.');
2013

    
2014
$section->add($group);
2015

    
2016
$section->addInput(new Form_Input(
2017
	'dhcphostname',
2018
	'Hostname',
2019
	'text',
2020
	$pconfig['dhcphostname']
2021
))->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).');
2022

    
2023
$section->addInput(new Form_IpAddress(
2024
	'alias-address',
2025
	'Alias IPv4 address',
2026
	$pconfig['alias-address'],
2027
	'V4'
2028
))->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.');
2029

    
2030
$section->addInput(new Form_Input(
2031
	'dhcprejectfrom',
2032
	'Reject leases from',
2033
	'text',
2034
	$pconfig['dhcprejectfrom']
2035
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2036
			'(separate multiple entries with a comma). ' .
2037
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2038

    
2039
$group = new Form_Group('Protocol timing');
2040
$group->addClass('dhcpadvanced');
2041

    
2042
$group->add(new Form_Input(
2043
	'adv_dhcp_pt_timeout',
2044
	null,
2045
	'number',
2046
	$pconfig['adv_dhcp_pt_timeout']
2047
))->setHelp('Timeout');
2048

    
2049
$group->add(new Form_Input(
2050
	'adv_dhcp_pt_retry',
2051
	null,
2052
	'number',
2053
	$pconfig['adv_dhcp_pt_retry']
2054
))->setHelp('Retry');
2055

    
2056
$group->add(new Form_Input(
2057
	'adv_dhcp_pt_select_timeout',
2058
	null,
2059
	'number',
2060
	$pconfig['adv_dhcp_pt_select_timeout'],
2061
	['min' => 0]
2062
))->setHelp('Select timeout');
2063

    
2064
$group->add(new Form_Input(
2065
	'adv_dhcp_pt_reboot',
2066
	null,
2067
	'number',
2068
	$pconfig['adv_dhcp_pt_reboot']
2069
))->setHelp('Reboot');
2070

    
2071
$group->add(new Form_Input(
2072
	'adv_dhcp_pt_backoff_cutoff',
2073
	null,
2074
	'number',
2075
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2076
))->setHelp('Backoff cutoff');
2077

    
2078
$group->add(new Form_Input(
2079
	'adv_dhcp_pt_initial_interval',
2080
	null,
2081
	'number',
2082
	$pconfig['adv_dhcp_pt_initial_interval']
2083
))->setHelp('Initial interval');
2084

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

    
2087
$group = new Form_Group('Presets');
2088
$group->addClass('dhcpadvanced');
2089

    
2090
$group->add(new Form_Checkbox(
2091
	'adv_dhcp_pt_values',
2092
	null,
2093
	'FreeBSD default',
2094
	null,
2095
	'DHCP'
2096
))->displayAsRadio();
2097

    
2098
$group->add(new Form_Checkbox(
2099
	'adv_dhcp_pt_values',
2100
	null,
2101
	'Clear',
2102
	null,
2103
	'Clear'
2104
))->displayAsRadio();
2105

    
2106
$group->add(new Form_Checkbox(
2107
	'adv_dhcp_pt_values',
2108
	null,
2109
	'pfSense Default',
2110
	null,
2111
	'pfSense'
2112
))->displayAsRadio();
2113

    
2114
$group->add(new Form_Checkbox(
2115
	'adv_dhcp_pt_values',
2116
	null,
2117
	'Saved Cfg',
2118
	null,
2119
	'SavedCfg'
2120
))->displayAsRadio();
2121

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

    
2125
$section->add($group);
2126

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

    
2137
$form->add($section);
2138

    
2139
$section = new Form_Section('Lease Requirements and Requests');
2140
$section->addClass('dhcpadvanced');
2141

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

    
2152
$section->addInput(new Form_Input(
2153
	'adv_dhcp_request_options',
2154
	'Request options',
2155
	'text',
2156
	$pconfig['adv_dhcp_request_options']
2157
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2158
			'Some ISPs may require certain options be or not be requested.', '<br />');
2159

    
2160
$section->addInput(new Form_Input(
2161
	'adv_dhcp_required_options',
2162
	'Require options',
2163
	'text',
2164
	$pconfig['adv_dhcp_required_options']
2165
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2166

    
2167
$section->addInput(new Form_Input(
2168
	'adv_dhcp_option_modifiers',
2169
	'Option modifiers',
2170
	'text',
2171
	$pconfig['adv_dhcp_option_modifiers']
2172
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2173
			'modifiers: (default, supersede, prepend, append) %1$s' .
2174
			'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>');
2175

    
2176
$form->add($section);
2177

    
2178
// DHCP6 client config
2179

    
2180
$section = new Form_Section('DHCP6 Client Configuration');
2181
$section->addClass('dhcp6');
2182

    
2183
$group = new Form_Group('Options');
2184

    
2185
$group->add(new Form_Checkbox(
2186
	'adv_dhcp6_config_advanced',
2187
	null,
2188
	'Advanced Configuration',
2189
	$pconfig['adv_dhcp6_config_advanced']
2190
))->setHelp('Use advanced DHCPv6 configuration options.');
2191

    
2192
$group->add(new Form_Checkbox(
2193
	'adv_dhcp6_config_file_override',
2194
	null,
2195
	'Configuration Override',
2196
	$pconfig['adv_dhcp6_config_file_override']
2197
))->setHelp('Override the configuration from this file.');
2198

    
2199
$section->add($group);
2200

    
2201
$section->addInput(new Form_Checkbox(
2202
	'dhcp6usev4iface',
2203
	'Use IPv4 connectivity as parent interface',
2204
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2205
	$pconfig['dhcp6usev4iface']
2206
));
2207

    
2208
$section->addInput(new Form_Checkbox(
2209
	'dhcp6prefixonly',
2210
	'Request only an IPv6 prefix',
2211
	'Only request an IPv6 prefix, do not request an IPv6 address',
2212
	$pconfig['dhcp6prefixonly']
2213
));
2214

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

    
2222
$section->addInput(new Form_Checkbox(
2223
	'dhcp6-ia-pd-send-hint',
2224
	'Send IPv6 prefix hint',
2225
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2226
	$pconfig['dhcp6-ia-pd-send-hint']
2227
));
2228

    
2229
$section->addInput(new Form_Checkbox(
2230
	'dhcp6debug',
2231
	'Debug',
2232
	'Start DHCP6 client in debug mode',
2233
	$pconfig['dhcp6debug']
2234
));
2235
$section->addInput(new Form_Checkbox(
2236
	'dhcp6withoutra',
2237
	'Do not wait for a RA',
2238
	'Required by some ISPs, especially those not using PPPoE',
2239
	$pconfig['dhcp6withoutra']
2240
));
2241
$section->addInput(new Form_Checkbox(
2242
	'dhcp6norelease',
2243
	'Do not allow PD/Address release',
2244
	'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',
2245
	$pconfig['dhcp6norelease']
2246
));
2247
$section->addInput(new Form_Input(
2248
	'adv_dhcp6_config_file_override_path',
2249
	'Configuration File Override',
2250
	'text',
2251
	$pconfig['adv_dhcp6_config_file_override_path']
2252
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2253
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2254
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2255
			'Some ISPs may require certain options be or not be sent.', '<br />');
2256

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

    
2259
// DHCP6 client config - Advanced
2260

    
2261
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2262
$section->addClass('dhcp6advanced');
2263

    
2264
$section->addInput(new Form_Checkbox(
2265
	'adv_dhcp6_interface_statement_information_only_enable',
2266
	'Information only',
2267
	'Exchange Information Only',
2268
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2269
	'Selected'
2270
))->setHelp('Only exchange informational configuration parameters with servers.');
2271

    
2272
$section->addInput(new Form_Input(
2273
	'adv_dhcp6_interface_statement_send_options',
2274
	'Send options',
2275
	'text',
2276
	$pconfig['adv_dhcp6_interface_statement_send_options']
2277
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2278
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2279
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2280
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2281

    
2282
$section->addInput(new Form_Input(
2283
	'adv_dhcp6_interface_statement_request_options',
2284
	'Request Options',
2285
	'text',
2286
	$pconfig['adv_dhcp6_interface_statement_request_options']
2287
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2288
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2289

    
2290
$section->addInput(new Form_Input(
2291
	'adv_dhcp6_interface_statement_script',
2292
	'Scripts',
2293
	'text',
2294
	$pconfig['adv_dhcp6_interface_statement_script']
2295
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2296
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2297

    
2298
$group = new Form_Group('Identity Association Statement');
2299

    
2300
$group->add(new Form_Checkbox(
2301
	'adv_dhcp6_id_assoc_statement_address_enable',
2302
	null,
2303
	'Non-Temporary Address Allocation',
2304
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2305
	'Selected'
2306
));
2307

    
2308
$group->add(new Form_Input(
2309
	'adv_dhcp6_id_assoc_statement_address_id',
2310
	null,
2311
	'text',
2312
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2313
))->sethelp('id-assoc na ID');
2314

    
2315
$group->add(new Form_IpAddress(
2316
	'adv_dhcp6_id_assoc_statement_address',
2317
	null,
2318
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2319
	'V6'
2320
))->sethelp('IPv6 address');
2321

    
2322
$group->add(new Form_Input(
2323
	'adv_dhcp6_id_assoc_statement_address_pltime',
2324
	null,
2325
	'text',
2326
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2327
))->sethelp('pltime');
2328

    
2329
$group->add(new Form_Input(
2330
	'adv_dhcp6_id_assoc_statement_address_vltime',
2331
	null,
2332
	'text',
2333
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2334
))->sethelp('vltime');
2335

    
2336
$section->add($group);
2337

    
2338
// Prefix delegation
2339
$group = new Form_Group('');
2340

    
2341
$group->add(new Form_Checkbox(
2342
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2343
	null,
2344
	'Prefix Delegation ',
2345
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2346
	'Selected'
2347
));
2348

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

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

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

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

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

    
2379
$group = new Form_Group('Prefix interface statement');
2380

    
2381
$group->add(new Form_Input(
2382
	'adv_dhcp6_prefix_interface_statement_sla_id',
2383
	null,
2384
	'text',
2385
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2386
))->sethelp('Prefix Interface sla-id');
2387

    
2388
$group->add(new Form_Input(
2389
	'adv_dhcp6_prefix_interface_statement_sla_len',
2390
	null,
2391
	'text',
2392
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2393
))->sethelp('sla-len');
2394

    
2395
$section->add($group);
2396

    
2397
$group = new Form_Group('Select prefix interface');
2398
$section->addInput(new Form_Select(
2399
	'adv_dhcp6_prefix_selected_interface',
2400
	'Prefix Interface',
2401
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2402
	$interfaces
2403
))->setHelp('Select the interface on which to apply the prefix delegation.');
2404

    
2405
$group = new Form_Group('Authentication statement');
2406

    
2407
$group->add(new Form_Input(
2408
	'adv_dhcp6_authentication_statement_authname',
2409
	null,
2410
	'text',
2411
	$pconfig['adv_dhcp6_authentication_statement_authname']
2412
))->sethelp('Authname');
2413

    
2414
$group->add(new Form_Input(
2415
	'adv_dhcp6_authentication_statement_protocol',
2416
	null,
2417
	'text',
2418
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2419
))->sethelp('Protocol');
2420

    
2421
$group->add(new Form_Input(
2422
	'adv_dhcp6_authentication_statement_algorithm',
2423
	null,
2424
	'text',
2425
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2426
))->sethelp('Algorithm');
2427

    
2428
$group->add(new Form_Input(
2429
	'adv_dhcp6_authentication_statement_rdm',
2430
	null,
2431
	'text',
2432
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2433
))->sethelp('RDM');
2434

    
2435
$section->add($group);
2436

    
2437
$group = new Form_Group('Keyinfo statement');
2438

    
2439
$group->add(new Form_Input(
2440
	'adv_dhcp6_key_info_statement_keyname',
2441
	null,
2442
	'text',
2443
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2444
))->sethelp('Keyname');
2445

    
2446
$group->add(new Form_Input(
2447
	'adv_dhcp6_key_info_statement_realm',
2448
	null,
2449
	'text',
2450
	$pconfig['adv_dhcp6_key_info_statement_realm']
2451
))->sethelp('Realm');
2452

    
2453
$section->add($group);
2454

    
2455
$group = new Form_Group('');
2456

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

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

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

    
2478
$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>');
2479

    
2480
$section->add($group);
2481

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

    
2484
$section = new Form_Section('6RD Configuration');
2485
$section->addClass('_6rd');
2486

    
2487
$section->addInput(new Form_Input(
2488
	'prefix-6rd',
2489
	'6RD Prefix',
2490
	'text',
2491
	$pconfig['prefix-6rd']
2492
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2493

    
2494
$section->addInput(new Form_Input(
2495
	'gateway-6rd',
2496
	'*6RD Border relay',
2497
	'text',
2498
	$pconfig['gateway-6rd']
2499
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2500

    
2501
$section->addInput(new Form_Select(
2502
	'prefix-6rd-v4plen',
2503
	'6RD IPv4 Prefix length',
2504
	$pconfig['prefix-6rd-v4plen'],
2505
	array_combine(range(0, 32), range(0, 32))
2506
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2507

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

    
2510
// Track IPv6 ointerface section
2511
$section = new Form_Section('Track IPv6 Interface');
2512
$section->addClass('track6');
2513

    
2514
function build_ipv6interface_list() {
2515
	global $config, $section;
2516

    
2517
	$list = array('' => '');
2518

    
2519
	$interfaces = get_configured_interface_with_descr(true);
2520
	$dynv6ifs = array();
2521

    
2522
	foreach ($interfaces as $iface => $ifacename) {
2523
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2524
			case "6to4":
2525
			case "6rd":
2526
			case "dhcp6":
2527
				$dynv6ifs[$iface] = array(
2528
					'name' => $ifacename,
2529
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2530
				);
2531
				break;
2532
			default:
2533
				continue;
2534
		}
2535
	}
2536

    
2537
	foreach ($dynv6ifs as $iface => $ifacedata) {
2538
		$list[$iface] = $ifacedata['name'];
2539

    
2540
		$section->addInput(new Form_Input(
2541
			'ipv6-num-prefix-ids-' . $iface,
2542
			null,
2543
			'hidden',
2544
			$ifacedata['ipv6_num_prefix_ids']
2545
		));
2546
	}
2547

    
2548
	return($list);
2549
}
2550

    
2551
$section->addInput(new Form_Select(
2552
	'track6-interface',
2553
	'*IPv6 Interface',
2554
	$pconfig['track6-interface'],
2555
	build_ipv6interface_list()
2556
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2557

    
2558
if ($pconfig['track6-prefix-id'] == "") {
2559
	$pconfig['track6-prefix-id'] = 0;
2560
}
2561

    
2562
$section->addInput(new Form_Input(
2563
	'track6-prefix-id--hex',
2564
	'IPv6 Prefix ID',
2565
	'text',
2566
	sprintf("%x", $pconfig['track6-prefix-id'])
2567
))->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>');
2568

    
2569
$section->addInput(new Form_Input(
2570
	'track6-prefix-id-max',
2571
	null,
2572
	'hidden',
2573
	0
2574
));
2575

    
2576
$form->add($section);
2577

    
2578
/// PPP section
2579

    
2580
$section = new Form_Section('PPP Configuration');
2581
$section->addClass('ppp');
2582

    
2583
$section->addInput(new Form_Select(
2584
	'country',
2585
	'Country',
2586
	$pconfig['country'],
2587
	[]
2588
));
2589

    
2590
$section->addInput(new Form_Select(
2591
	'provider_list',
2592
	'Provider',
2593
	$pconfig['provider_list'],
2594
	[]
2595
));
2596

    
2597
$section->addInput(new Form_Select(
2598
	'providerplan',
2599
	'Plan',
2600
	$pconfig['providerplan'],
2601
	[]
2602
))->setHelp('Select to fill in service provider data.');
2603

    
2604
$section->addInput(new Form_Input(
2605
	'ppp_username',
2606
	'Username',
2607
	'text',
2608
	$pconfig['ppp_username']
2609
));
2610

    
2611
$section->addPassword(new Form_Input(
2612
	'ppp_password',
2613
	'Password',
2614
	'password',
2615
	$pconfig['ppp_password']
2616
));
2617

    
2618
$section->addInput(new Form_Input(
2619
	'phone',
2620
	'*Phone number',
2621
	'text',
2622
	$pconfig['phone']
2623
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2624

    
2625
$section->addInput(new Form_Input(
2626
	'apn',
2627
	'Access Point Name',
2628
	'text',
2629
	$pconfig['apn']
2630
));
2631

    
2632

    
2633
function build_port_list() {
2634
	$list = array("" => "None");
2635

    
2636
	$portlist = glob("/dev/cua*");
2637
	$modems	  = glob("/dev/modem*");
2638
	$portlist = array_merge($portlist, $modems);
2639

    
2640
	foreach ($portlist as $port) {
2641
		if (preg_match("/\.(lock|init)$/", $port)) {
2642
			continue;
2643
		}
2644

    
2645
	$list[trim($port)] = $port;
2646
	}
2647

    
2648
	return($list);
2649
}
2650

    
2651
$section->addInput(new Form_Select(
2652
	'port',
2653
	"*Modem port",
2654
	$pconfig['port'],
2655
	build_port_list()
2656
));
2657

    
2658
$section->addInput(new Form_Button(
2659
	'btnadvppp',
2660
	'Advanced PPP',
2661
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2662
	'fa-cog'
2663
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2664

    
2665
$form->add($section);
2666

    
2667
// PPPoE configuration
2668
$section = new Form_Section('PPPoE Configuration');
2669
$section->addClass('pppoe');
2670

    
2671
$section->addInput(new Form_Input(
2672
	'pppoe_username',
2673
	'*Username',
2674
	'text',
2675
	$pconfig['pppoe_username']
2676
));
2677

    
2678
$section->addPassword(new Form_Input(
2679
	'pppoe_password',
2680
	'*Password',
2681
	'password',
2682
	$pconfig['pppoe_password']
2683
));
2684

    
2685
$section->addInput(new Form_Input(
2686
	'provider',
2687
	'Service name',
2688
	'text',
2689
	$pconfig['provider']
2690
))->setHelp('This field can usually be left empty.');
2691

    
2692
$section->addInput(new Form_Checkbox(
2693
	'pppoe_dialondemand',
2694
	'Dial on demand',
2695
	'Enable Dial-On-Demand mode ',
2696
	$pconfig['pppoe_dialondemand'],
2697
	'enable'
2698
));
2699

    
2700
$section->addInput(new Form_Input(
2701
	'pppoe_idletimeout',
2702
	'Idle timeout',
2703
	'number',
2704
	$pconfig['pppoe_idletimeout'],
2705
	['min' => 0]
2706
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2707
			'An idle timeout of zero disables this feature.');
2708

    
2709
$section->addInput(new Form_Select(
2710
	'pppoe-reset-type',
2711
	'Periodic reset',
2712
	$pconfig['pppoe-reset-type'],
2713
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2714
))->setHelp('Select a reset timing type.');
2715

    
2716
$group = new Form_Group('Custom reset');
2717
$group->addClass('pppoecustom');
2718

    
2719
$group->add(new Form_Input(
2720
	'pppoe_resethour',
2721
	null,
2722
	'number',
2723
	$pconfig['pppoe_resethour'],
2724
	['min' => 0, 'max' => 23]
2725
))->setHelp('Hour (0-23)');
2726

    
2727
$group->add(new Form_Input(
2728
	'pppoe_resetminute',
2729
	null,
2730
	'number',
2731
	$pconfig['pppoe_resetminute'],
2732
	['min' => 0, 'max' => 59]
2733
))->setHelp('Minutes (0-59)');
2734

    
2735
$group->add(new Form_Input(
2736
	'pppoe_resetdate',
2737
	null,
2738
	'text',
2739
	$pconfig['pppoe_resetdate']
2740
))->setHelp('Specific date (mm/dd/yyyy)');
2741

    
2742
$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');
2743

    
2744
$section->add($group);
2745

    
2746
$group = new Form_MultiCheckboxGroup('cron based reset');
2747
$group->addClass('pppoepreset');
2748

    
2749
$group->add(new Form_MultiCheckbox(
2750
	'pppoe_pr_preset_val',
2751
	null,
2752
	'Reset at each month ("0 0 1 * *")',
2753
	$pconfig['pppoe_monthly'],
2754
	'monthly'
2755
))->displayAsRadio();
2756

    
2757
$group->add(new Form_MultiCheckbox(
2758
	'pppoe_pr_preset_val',
2759
	null,
2760
	'Reset at each week ("0 0 * * 0")',
2761
	$pconfig['pppoe_weekly'],
2762
	'weekly'
2763
))->displayAsRadio();
2764

    
2765
$group->add(new Form_MultiCheckbox(
2766
	'pppoe_pr_preset_val',
2767
	null,
2768
	'Reset at each day ("0 0 * * *")',
2769
	$pconfig['pppoe_daily'],
2770
	'daily'
2771
))->displayAsRadio();
2772

    
2773
$group->add(new Form_MultiCheckbox(
2774
	'pppoe_pr_preset_val',
2775
	null,
2776
	'Reset at each hour ("0 * * * *")',
2777
	$pconfig['pppoe_hourly'],
2778
	'hourly'
2779
))->displayAsRadio();
2780

    
2781
$section->add($group);
2782

    
2783
$section->addInput(new Form_Button(
2784
	'btnadvppp',
2785
	'Advanced and MLPPP',
2786
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2787
	'fa-cog'
2788
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2789

    
2790
$form->add($section);
2791

    
2792
// PPTP & L2TP Configuration section
2793
$section = new Form_Section('PPTP/L2TP Configuration');
2794
$section->addClass('pptp');
2795

    
2796
$section->addInput(new Form_Input(
2797
	'pptp_username',
2798
	'*Username',
2799
	'text',
2800
	$pconfig['pptp_username']
2801
));
2802

    
2803
$section->addPassword(new Form_Input(
2804
	'pptp_password',
2805
	'*Password',
2806
	'password',
2807
	$pconfig['pptp_password']
2808
));
2809

    
2810
$section->addInput(new Form_IpAddress(
2811
	'pptp_local0',
2812
	'*Local IP address',
2813
	$pconfig['pptp_localip'][0],
2814
	'V4'
2815
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2816

    
2817
$section->addInput(new Form_IpAddress(
2818
	'pptp_remote0',
2819
	'*Remote IP address',
2820
	$pconfig['pptp_remote'][0],
2821
	'HOSTV4'
2822
));
2823

    
2824
$section->addInput(new Form_Checkbox(
2825
	'pptp_dialondemand',
2826
	'Dial on demand',
2827
	'Enable Dial-On-Demand mode ',
2828
	$pconfig['pptp_dialondemand'],
2829
	'enable'
2830
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2831
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2832

    
2833
$section->addInput(new Form_Input(
2834
	'pptp_idletimeout',
2835
	'Idle timeout (seconds)',
2836
	'number',
2837
	$pconfig['pptp_idletimeout'],
2838
	['min' => 0]
2839
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2840
			'An idle timeout of zero disables this feature.');
2841

    
2842
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2843
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2844
} else {
2845
	$mlppp_text = "";
2846
}
2847

    
2848
$section->addInput(new Form_Button(
2849
	'btnadvppp',
2850
	'Advanced and MLPPP',
2851
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2852
	'fa-cog'
2853
))->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);
2854

    
2855
$form->add($section);
2856

    
2857
// Wireless interface
2858
if (isset($wancfg['wireless'])) {
2859

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

    
2862
	$section->addInput(new Form_Checkbox(
2863
		'persistcommonwireless',
2864
		'Persist common settings',
2865
		'Preserve common wireless configuration through interface deletions and reassignments.',
2866
		$pconfig['persistcommonwireless'],
2867
		'yes'
2868
	));
2869

    
2870
	$mode_list = ['auto' => 'Auto'];
2871

    
2872
	if (is_array($wl_modes)) {
2873
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2874
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2875
		}
2876
	}
2877

    
2878
	if (count($mode_list) == 1) {
2879
		$mode_list[''] = '';
2880
	}
2881

    
2882
	$section->addInput(new Form_Select(
2883
		'standard',
2884
		'Standard',
2885
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2886
		$mode_list
2887
	));
2888

    
2889
	if (isset($wl_modes['11g'])) {
2890
		$section->addInput(new Form_Select(
2891
			'protmode',
2892
			'802.11g OFDM Protection Mode',
2893
			$pconfig['protmode'],
2894
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2895
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2896
	} else {
2897
		$section->addInput(new Form_Input(
2898
			'protmode',
2899
			null,
2900
			'hidden',
2901
			'off'
2902
		));
2903
	}
2904

    
2905
	$mode_list = ['0' => gettext('Auto')];
2906

    
2907
	if (is_array($wl_modes)) {
2908
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2909
			if ($wl_standard == "11g") {
2910
				$wl_standard = "11b/g";
2911
			} else if ($wl_standard == "11ng") {
2912
				$wl_standard = "11b/g/n";
2913
			} else if ($wl_standard == "11na") {
2914
				$wl_standard = "11a/n";
2915
			}
2916

    
2917
			foreach ($wl_channels as $wl_channel) {
2918
				if (isset($wl_chaninfo[$wl_channel])) {
2919
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2920
				} else {
2921
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2922
				}
2923
			}
2924
		}
2925
	}
2926

    
2927
	$section->addInput(new Form_Select(
2928
		'channel',
2929
		'Channel',
2930
		$pconfig['channel'],
2931
		$mode_list
2932
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2933
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2934

    
2935
	if (ANTENNAS) {
2936
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2937
			$group = new Form_Group('Antenna Settings');
2938

    
2939
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2940
				$group->add(new Form_Select(
2941
					'diversity',
2942
					null,
2943
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2944
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2945
				))->setHelp('Diversity');
2946
			}
2947

    
2948
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2949
				$group->add(new Form_Select(
2950
					'txantenna',
2951
					null,
2952
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2953
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2954
				))->setHelp('Transmit antenna');
2955
			}
2956

    
2957
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2958
				$group->add(new Form_Select(
2959
					'rxantenna',
2960
					null,
2961
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2962
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2963
				))->setHelp('Receive antenna');
2964
			}
2965

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

    
2968
			$section->add($group);
2969
		}
2970
	}
2971

    
2972
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2973
			$section->addInput(new Form_Input(
2974
				'distance',
2975
				'Distance setting (meters)',
2976
				'test',
2977
				$pconfig['distance']
2978
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2979
	}
2980

    
2981
	$form->add($section);
2982

    
2983
	// Regulatory settings
2984
	$section = new Form_Section('Regulatory Settings');
2985

    
2986
	$domain_list = array("" => 'Default');
2987

    
2988
	if (is_array($wl_regdomains)) {
2989
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2990
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2991
		}
2992
	}
2993

    
2994
	$section->addInput(new Form_Select(
2995
		'regdomain',
2996
		'Regulatory domain',
2997
		$pconfig['regdomain'],
2998
		$domain_list
2999
	))->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');
3000

    
3001
	$country_list = array('' => 'Default');
3002

    
3003
	if (is_array($wl_countries)) {
3004
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3005
			$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']);
3006
		}
3007
	}
3008

    
3009
	$section->addInput(new Form_Select(
3010
		'regcountry',
3011
		'Country',
3012
		$pconfig['regcountry'],
3013
		$country_list
3014
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3015

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

    
3027
	$form->add($section);
3028

    
3029
	$section = new Form_Section('Network-Specific Wireless Configuration');
3030

    
3031
	$section->addInput(new Form_Select(
3032
		'mode',
3033
		'Mode',
3034
		$pconfig['mode'],
3035
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3036
	));
3037

    
3038
	$section->addInput(new Form_Input(
3039
		'ssid',
3040
		'SSID',
3041
		'text',
3042
		$pconfig['ssid']
3043
	));
3044

    
3045
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3046
		$section->addInput(new Form_Select(
3047
			'puremode',
3048
			'Minimum wireless standard',
3049
			$pconfig['puremode'],
3050
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3051
		))->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)');
3052
	} elseif (isset($wl_modes['11g'])) {
3053
		$section->addInput(new Form_Checkbox(
3054
			'puremode',
3055
			'802.11g only',
3056
			null,
3057
			$pconfig['puremode'],
3058
			'11g'
3059
		))->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)');
3060
	}
3061

    
3062
	$section->addInput(new Form_Checkbox(
3063
		'apbridge_enable',
3064
		'Allow intra-BSS communication',
3065
		'Allow packets to pass between wireless clients directly when operating as an access point',
3066
		$pconfig['apbridge_enable'],
3067
		'yes'
3068
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3069

    
3070
	$section->addInput(new Form_Checkbox(
3071
		'wme_enable',
3072
		'Enable WME',
3073
		'Force the card to use WME (wireless QoS)',
3074
		$pconfig['wme_enable'],
3075
		'yes'
3076
	));
3077

    
3078
	$section->addInput(new Form_Checkbox(
3079
		'hidessid_enable',
3080
		'Hide SSID',
3081
		'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.)',
3082
		$pconfig['hidessid_enable'],
3083
		'yes'
3084
	));
3085

    
3086
	$form->add($section);
3087

    
3088
	// WPA Section
3089
	$section = new Form_Section('WPA');
3090

    
3091
	$section->addInput(new Form_Checkbox(
3092
		'wpa_enable',
3093
		'Enable',
3094
		'Enable WPA',
3095
		$pconfig['wpa_enable'],
3096
		'yes'
3097
	));
3098

    
3099
	$section->addInput(new Form_Input(
3100
		'passphrase',
3101
		'WPA Pre-Shared Key',
3102
		'text',
3103
		$pconfig['passphrase']
3104
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3105

    
3106
	$section->addInput(new Form_Select(
3107
		'wpa_mode',
3108
		'WPA mode',
3109
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3110
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3111
	));
3112

    
3113
	$section->addInput(new Form_Select(
3114
		'wpa_key_mgmt',
3115
		'WPA Key Management Mode',
3116
		$pconfig['wpa_key_mgmt'],
3117
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3118
	));
3119

    
3120
	$section->addInput(new Form_Select(
3121
		'wpa_pairwise',
3122
		'WPA Pairwise',
3123
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3124
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3125
	));
3126

    
3127
	$section->addInput(new Form_Input(
3128
		'wpa_group_rekey',
3129
		'Group Key Rotation',
3130
		'number',
3131
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3132
		['min' => '1', 'max' => 9999]
3133
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3134

    
3135
	$section->addInput(new Form_Input(
3136
		'wpa_gmk_rekey',
3137
		'Group Master Key Regeneration',
3138
		'number',
3139
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3140
		['min' => '1', 'max' => 9999]
3141
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3142

    
3143
	$section->addInput(new Form_Checkbox(
3144
		'wpa_strict_rekey',
3145
		'Strict Key Regeneration',
3146
		'Force the AP to rekey whenever a client disassociates',
3147
		$pconfig['wpa_strict_rekey'],
3148
		'yes'
3149
	));
3150

    
3151
	$form->add($section);
3152

    
3153
	$section = new Form_Section('802.1x RADIUS Options');
3154

    
3155
	$section->addInput(new Form_Checkbox(
3156
		'ieee8021x',
3157
		'IEEE802.1X',
3158
		'Enable 802.1X authentication',
3159
		$pconfig['ieee8021x'],
3160
		'yes'
3161
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3162

    
3163
	$group = new Form_Group('Primary 802.1X server');
3164

    
3165
	$group->add(new Form_IpAddress(
3166
		'auth_server_addr',
3167
		'IP Address',
3168
		$pconfig['auth_server_addr']
3169
	))->setHelp('IP address of the RADIUS server');
3170

    
3171
	$group->add(new Form_Input(
3172
		'auth_server_port',
3173
		'Port',
3174
		'number',
3175
		$pconfig['auth_server_port']
3176
	))->setHelp('Server auth port. Default is 1812');
3177

    
3178
	$group->add(new Form_Input(
3179
		'auth_server_shared_secret',
3180
		'Shared Secret',
3181
		'text',
3182
		$pconfig['auth_server_shared_secret']
3183
	))->setHelp('RADIUS Shared secret for this firewall');
3184

    
3185
	$section->add($group);
3186

    
3187
	$group = new Form_Group('Secondary 802.1X server');
3188

    
3189
	$group->add(new Form_IpAddress(
3190
		'auth_server_addr2',
3191
		'IP Address',
3192
		$pconfig['auth_server_addr2']
3193
	))->setHelp('IP address of the RADIUS server');
3194

    
3195
	$group->add(new Form_Input(
3196
		'auth_server_port2',
3197
		'Port',
3198
		'number',
3199
		$pconfig['auth_server_port2']
3200
	))->setHelp('Server auth port. Default is 1812');
3201

    
3202
	$group->add(new Form_Input(
3203
		'auth_server_shared_secret2',
3204
		'Shared Secret',
3205
		'text',
3206
		$pconfig['auth_server_shared_secret2']
3207
	))->setHelp('RADIUS Shared secret for this firewall');
3208

    
3209
	$section->add($group);
3210

    
3211
	$section->addInput(new Form_Checkbox(
3212
		'rsn_preauth',
3213
		'Authentication Roaming Preauth',
3214
		null,
3215
		$pconfig['rsn_preauth'],
3216
		'yes'
3217
	));
3218

    
3219
	$form->add($section);
3220
}
3221

    
3222
$section = new Form_Section('Reserved Networks');
3223

    
3224
$section->addInput(new Form_Checkbox(
3225
	'blockpriv',
3226
	'Block private networks and loopback addresses',
3227
	'',
3228
	$pconfig['blockpriv'],
3229
	'yes'
3230
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3231
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3232
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3233

    
3234
$section->addInput(new Form_Checkbox(
3235
	'blockbogons',
3236
	'Block bogon networks',
3237
	'',
3238
	$pconfig['blockbogons'],
3239
	'yes'
3240
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3241
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3242
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3243

    
3244
$form->add($section);
3245

    
3246
$form->addGlobal(new Form_Input(
3247
	'if',
3248
	null,
3249
	'hidden',
3250
	$if
3251
));
3252

    
3253
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3254
	$form->addGlobal(new Form_Input(
3255
		'ppp_port',
3256
		null,
3257
		'hidden',
3258
		$pconfig['port']
3259
	));
3260
}
3261

    
3262
$form->addGlobal(new Form_Input(
3263
	'ptpid',
3264
	null,
3265
	'hidden',
3266
	$pconfig['ptpid']
3267
));
3268

    
3269

    
3270
// Add new gateway modal pop-up
3271
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3272

    
3273
$modal->addInput(new Form_Checkbox(
3274
	'defaultgw4',
3275
	'Default',
3276
	'Default gateway',
3277
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3278
));
3279

    
3280
$modal->addInput(new Form_Input(
3281
	'gatewayname4',
3282
	'Gateway name',
3283
	'text',
3284
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3285
));
3286

    
3287
$modal->addInput(new Form_IpAddress(
3288
	'gatewayip4',
3289
	'Gateway IPv4',
3290
	$gateway_settings4['gateway'],
3291
	'V4'
3292
));
3293

    
3294
$modal->addInput(new Form_Input(
3295
	'gatewaydescr4',
3296
	'Description',
3297
	'text',
3298
	$gateway_settings4['descr']
3299
));
3300

    
3301
$btnaddgw4 = new Form_Button(
3302
	'add4',
3303
	'Add',
3304
	null,
3305
	'fa-plus'
3306
);
3307

    
3308
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3309

    
3310
$btncnxgw4 = new Form_Button(
3311
	'cnx4',
3312
	'Cancel',
3313
	null,
3314
	'fa-undo'
3315
);
3316

    
3317
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3318

    
3319
$modal->addInput(new Form_StaticText(
3320
	null,
3321
	$btnaddgw4 . $btncnxgw4
3322
));
3323

    
3324
$form->add($modal);
3325

    
3326
print($form);
3327
?>
3328

    
3329
<script type="text/javascript">
3330
//<![CDATA[
3331
events.push(function() {
3332
	function updateType(t) {
3333

    
3334
		switch (t) {
3335
			case "none": {
3336
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3337
				break;
3338
			}
3339
			case "staticv4": {
3340
				$('.dhcpadvanced, .none, .dhcp').hide();
3341
				$('.pppoe, .pptp, .ppp').hide();
3342
				break;
3343
			}
3344
			case "dhcp": {
3345
				$('.dhcpadvanced, .none').hide();
3346
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3347
										//			about the staticv4 class
3348
				$('.pppoe, .pptp, .ppp').hide();
3349
				break;
3350
			}
3351
			case "ppp": {
3352
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3353
				country_list();
3354
				break;
3355
			}
3356
			case "pppoe": {
3357
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3358
				break;
3359
			}
3360
			case "l2tp":
3361
			case "pptp": {
3362
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3363
				$('.pptp').show();
3364
				break;
3365
			}
3366
		}
3367

    
3368
		if (t != "l2tp" && t != "pptp") {
3369
			$('.'+t).show();
3370
		}
3371
	}
3372

    
3373
	function updateTypeSix(t) {
3374
		if (!isNaN(t[0])) {
3375
			t = '_' + t;
3376
		}
3377

    
3378
		switch (t) {
3379
			case "none": {
3380
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3381
				break;
3382
			}
3383
			case "staticv6": {
3384
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3385
				break;
3386
			}
3387
			case "slaac": {
3388
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3389
				break;
3390
			}
3391
			case "dhcp6": {
3392
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3393
				break;
3394
			}
3395
			case "_6rd": {
3396
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3397
				break;
3398
			}
3399
			case "_6to4": {
3400
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3401
				break;
3402
			}
3403
			case "track6": {
3404
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3405
				update_track6_prefix();
3406
				break;
3407
			}
3408
		}
3409

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

    
3415
	function show_reset_settings(reset_type) {
3416
		if (reset_type == 'preset') {
3417
			$('.pppoepreset').show();
3418
			$('.pppoecustom').hide();
3419
		} else if (reset_type == 'custom') {
3420
			$('.pppoecustom').show();
3421
			$('.pppoepreset').hide();
3422
		} else {
3423
			$('.pppoecustom').hide();
3424
			$('.pppoepreset').hide();
3425
		}
3426
	}
3427

    
3428
	function update_track6_prefix() {
3429
		var iface = $("#track6-interface").val();
3430
		if (iface == null) {
3431
			return;
3432
		}
3433

    
3434
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3435
		if (track6_prefix_ids == null) {
3436
			return;
3437
		}
3438

    
3439
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3440
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3441
	}
3442

    
3443
	function addOption_v4() {
3444
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3445
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3446
	}
3447

    
3448
	function addOption_v6() {
3449
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3450
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3451
	}
3452

    
3453
	function addSelectboxOption(selectbox, text, value) {
3454
		var optn = document.createElement("OPTION");
3455
		optn.text = text;
3456
		optn.value = value;
3457
		selectbox.append(optn);
3458
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3459
	}
3460

    
3461
	function country_list() {
3462
		$('#country').children().remove();
3463
		$('#provider_list').children().remove();
3464
		$('#providerplan').children().remove();
3465
		$.ajax("getserviceproviders.php",{
3466
			success: function(response) {
3467

    
3468
				var responseTextArr = response.split("\n");
3469
				responseTextArr.sort();
3470

    
3471
				responseTextArr.forEach( function(value) {
3472
					country = value.split(":");
3473
					$('#country').append($('<option>', {
3474
						value: country[1],
3475
						text : country[0]
3476
					}));
3477
				});
3478
			}
3479
		});
3480
	}
3481

    
3482
	function providers_list() {
3483
		$('#provider_list').children().remove();
3484
		$('#providerplan').children().remove();
3485
		$.ajax("getserviceproviders.php",{
3486
			type: 'post',
3487
			data: {country : $('#country').val()},
3488
			success: function(response) {
3489
				var responseTextArr = response.split("\n");
3490
				responseTextArr.sort();
3491
				responseTextArr.forEach( function(value) {
3492
					$('#provider_list').append($('<option>', {
3493
							value: value,
3494
							text : value
3495
					}));
3496
				});
3497
			}
3498
		});
3499
	}
3500

    
3501
	function providerplan_list() {
3502
		$('#providerplan').children().remove();
3503
		$.ajax("getserviceproviders.php",{
3504
			type: 'post',
3505
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3506
			success: function(response) {
3507
				var responseTextArr = response.split("\n");
3508
				responseTextArr.sort();
3509

    
3510
				$('#providerplan').append($('<option>', {
3511
					value: '',
3512
					text : ''
3513
				}));
3514

    
3515
				responseTextArr.forEach( function(value) {
3516
					if (value != "") {
3517
						providerplan = value.split(":");
3518

    
3519
						$('#providerplan').append($('<option>', {
3520
							value: providerplan[1],
3521
							text : providerplan[0] + " - " + providerplan[1]
3522
						}));
3523
					}
3524
				});
3525
			}
3526
		});
3527
	}
3528

    
3529
	function prefill_provider() {
3530
		$.ajax("getserviceproviders.php",{
3531
			type: 'post',
3532
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3533
			success: function(data, textStatus, response) {
3534
				var xmldoc = response.responseXML;
3535
				var provider = xmldoc.getElementsByTagName('connection')[0];
3536
				$('#ppp_username').val('');
3537
				$('#ppp_password').val('');
3538
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3539
					$('#phone').val('#777');
3540
					$('#apn').val('');
3541
				} else {
3542
					$('#phone').val('*99#');
3543
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3544
				}
3545
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3546
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3547
				$('#ppp_username').val(ppp_username);
3548
				$('#ppp_password').val(ppp_password);
3549
			}
3550
		});
3551
	}
3552

    
3553
	function show_dhcp6adv() {
3554
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3555
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3556

    
3557
		hideCheckbox('dhcp6usev4iface', ovr);
3558
		hideCheckbox('dhcp6prefixonly', ovr);
3559
		hideInput('dhcp6-ia-pd-len', ovr);
3560
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3561
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3562

    
3563
		hideClass('dhcp6advanced', !adv || ovr);
3564
	}
3565

    
3566
	function setDHCPoptions() {
3567
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3568
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3569

    
3570
		if (ovr) {
3571
			hideInput('dhcphostname', true);
3572
			hideIpAddress('alias-address', true);
3573
			hideInput('dhcprejectfrom', true);
3574
			hideInput('adv_dhcp_config_file_override_path', false);
3575
			hideClass('dhcpadvanced', true);
3576
		} else {
3577
			hideInput('dhcphostname', false);
3578
			hideIpAddress('alias-address', false);
3579
			hideInput('dhcprejectfrom', false);
3580
			hideInput('adv_dhcp_config_file_override_path', true);
3581
			hideClass('dhcpadvanced', !adv);
3582
		}
3583
	}
3584

    
3585
	// DHCP preset actions
3586
	// Set presets from value of radio buttons
3587
	function setPresets(val) {
3588
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3589
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3590
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3591
		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']);?>");
3592
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3593
	}
3594

    
3595
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3596
		$('#adv_dhcp_pt_timeout').val(timeout);
3597
		$('#adv_dhcp_pt_retry').val(retry);
3598
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3599
		$('#adv_dhcp_pt_reboot').val(reboot);
3600
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3601
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3602
	}
3603

    
3604
	function setPPPoEDialOnDemandItems() {
3605
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3606
	}
3607

    
3608
	function setPPTPDialOnDemandItems() {
3609
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3610
	}
3611

    
3612
	// ---------- On initial page load ------------------------------------------------------------
3613

    
3614
	updateType($('#type').val());
3615
	updateTypeSix($('#type6').val());
3616
	show_reset_settings($('#pppoe-reset-type').val());
3617
	hideClass('dhcp6advanced', true);
3618
	hideClass('dhcpadvanced', true);
3619
	show_dhcp6adv();
3620
	setDHCPoptions();
3621
	setPPPoEDialOnDemandItems();
3622
	setPPTPDialOnDemandItems();
3623

    
3624
	// Set preset buttons on page load
3625
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3626
	if (sv == "") {
3627
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3628
	} else {
3629
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3630
	}
3631

    
3632
	// Set preset from value
3633
	setPresets(sv);
3634

    
3635
	// If the user wants to add a gateway, then add that to the gateway selection
3636
	if ($("#gatewayip4").val() != '') {
3637
		addOption_v4();
3638
	}
3639
	if ($("#gatewayip6").val() != '') {
3640
		addOption_v6();
3641
	}
3642

    
3643
	// ---------- Click checkbox handlers ---------------------------------------------------------
3644

    
3645
	$('#type').on('change', function() {
3646
		updateType(this.value);
3647
	});
3648

    
3649
	$('#type6').on('change', function() {
3650
		updateTypeSix(this.value);
3651
	});
3652

    
3653
	$('#track6-interface').on('change', function() {
3654
		update_track6_prefix();
3655
	});
3656

    
3657
	$('#pppoe-reset-type').on('change', function() {
3658
		show_reset_settings(this.value);
3659
	});
3660

    
3661
	$("#add4").click(function() {
3662
		addOption_v4();
3663
		$("#newgateway4").modal('hide');
3664
	});
3665

    
3666
	$("#cnx4").click(function() {
3667
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3668
		$("#gatewayip4").val('');
3669
		$("#gatewaydescr4").val('');
3670
		$("#defaultgw4").prop("checked", false);
3671
		$("#newgateway4").modal('hide');
3672
	});
3673

    
3674
	$("#add6").click(function() {
3675
		addOption_v6();
3676
		$("#newgateway6").modal('hide');
3677
	});
3678

    
3679
	$("#cnx6").click(function() {
3680
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3681
		$("#gatewayip6").val('');
3682
		$("#gatewaydescr6").val('');
3683
		$("#defaultgw6").prop("checked", false);
3684
		$("#newgateway6").modal('hide');
3685
	});
3686

    
3687
	$('#country').on('change', function() {
3688
		providers_list();
3689
	});
3690

    
3691
	$('#provider_list').on('change', function() {
3692
		providerplan_list();
3693
	});
3694

    
3695
	$('#providerplan').on('change', function() {
3696
		prefill_provider();
3697
	});
3698

    
3699
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3700
		setDHCPoptions();
3701
	});
3702

    
3703
	$('#adv_dhcp6_config_advanced').click(function () {
3704
		show_dhcp6adv();
3705
	});
3706

    
3707
	$('#adv_dhcp6_config_file_override').click(function () {
3708
		show_dhcp6adv();
3709
	});
3710

    
3711
	// On click . .
3712
	$('#pppoe_dialondemand').click(function () {
3713
		setPPPoEDialOnDemandItems();
3714
	});
3715

    
3716
	$('#pptp_dialondemand').click(function () {
3717
		setPPTPDialOnDemandItems();
3718
	});
3719

    
3720
	$('[name=adv_dhcp_pt_values]').click(function () {
3721
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3722
	});
3723

    
3724
	$('#pppoe_resetdate').datepicker();
3725

    
3726
});
3727
//]]>
3728
</script>
3729

    
3730
<?php include("foot.inc");
(70-70/229)