Project

General

Profile

Download (122 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(false, true);
54

    
55
$if = "wan";
56
if ($_REQUEST['if']) {
57
	$if = $_REQUEST['if'];
58
}
59

    
60
if (empty($ifdescrs[$if])) {
61
	header("Location: interfaces.php");
62
	exit;
63
}
64

    
65
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
66
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
67
define("CRON_DAILY_PATTERN", "0 0 * * *");
68
define("CRON_HOURLY_PATTERN", "0 * * * *");
69

    
70
if (!is_array($pconfig)) {
71
	$pconfig = array();
72
}
73

    
74
if (!is_array($config['ppps'])) {
75
	$config['ppps'] = array();
76
}
77
if (!is_array($config['ppps']['ppp'])) {
78
	$config['ppps']['ppp'] = array();
79
}
80
$a_ppps = &$config['ppps']['ppp'];
81

    
82
function remove_bad_chars($string) {
83
	return preg_replace('/[^a-z_0-9]/i', '', $string);
84
}
85

    
86
if (!is_array($config['gateways']['gateway_item'])) {
87
	$config['gateways']['gateway_item'] = array();
88
}
89

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

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

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

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

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

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

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

    
130
		/* ================================================ */
131
		/* = force a connection reset at a specific time? = */
132
		/* ================================================ */
133

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

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

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

    
200
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
201

    
202
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
203
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
204
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
205
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
206

    
207
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
208
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
209
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
210

    
211
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
212
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
213
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
214
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
215

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

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

    
228
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
229
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
230

    
231
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
232
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
233
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
234
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
235

    
236
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
237
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
238
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
239
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
240
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
241

    
242
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
243
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
244
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
245

    
246
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
247
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
248
$pconfig['enable'] = isset($wancfg['enable']);
249

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

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

    
324
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
325
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
326
$pconfig['spoofmac'] = $wancfg['spoofmac'];
327
$pconfig['mtu'] = $wancfg['mtu'];
328
$pconfig['mss'] = $wancfg['mss'];
329

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

    
406
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
407

    
408
}
409

    
410
if ($_POST['apply']) {
411
	unset($input_errors);
412
	if (!is_subsystem_dirty('interfaces')) {
413
		$input_errors[] = gettext("The settings have already been applied!");
414
	} else {
415
		unlink_if_exists("{$g['tmp_path']}/config.cache");
416
		clear_subsystem_dirty('interfaces');
417

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

    
445
		/* sync filter configuration */
446
		setup_gateways_monitor();
447

    
448
		clear_subsystem_dirty('interfaces');
449

    
450
		filter_configure();
451

    
452
		enable_rrd_graphing();
453

    
454
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
455
			clear_subsystem_dirty('staticroutes');
456
		}
457
	}
458
	@unlink("{$g['tmp_path']}/.interfaces.apply");
459
	header("Location: interfaces.php?if={$if}");
460
	exit;
461
} else if ($_POST) {
462

    
463
	unset($input_errors);
464
	$pconfig = $_POST;
465

    
466
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
467
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
468
	} else {
469
		$pconfig['track6-prefix-id'] = 0;
470
	}
471

    
472
	/* filter out spaces from descriptions */
473
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
474

    
475
	/* okay first of all, cause we are just hiding the PPPoE HTML
476
	 * fields related to PPPoE resets, we are going to unset $_POST
477
	 * vars, if the reset feature should not be used. Otherwise the
478
	 * data validation procedure below, may trigger a false error
479
	 * message.
480
	 */
481
	if (empty($_POST['pppoe-reset-type'])) {
482
		unset($_POST['pppoe_pr_type']);
483
		unset($_POST['pppoe_resethour']);
484
		unset($_POST['pppoe_resetminute']);
485
		unset($_POST['pppoe_resetdate']);
486
		unset($_POST['pppoe_pr_preset_val']);
487
	}
488
	/* description unique? */
489
	foreach ($ifdescrs as $ifent => $ifdescr) {
490
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
491
			$input_errors[] = gettext("An interface with the specified description already exists.");
492
			break;
493
		}
494
	}
495

    
496
	/* Is the description already used as an alias name? */
497
	if (is_array($config['aliases']['alias'])) {
498
		foreach ($config['aliases']['alias'] as $alias) {
499
			if ($alias['name'] == $_POST['descr']) {
500
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
501
			}
502
		}
503
	}
504

    
505
	/* Is the description already used as an interface group name? */
506
	if (is_array($config['ifgroups']['ifgroupentry'])) {
507
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
508
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
509
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
510
			}
511
		}
512
	}
513

    
514
	if (is_numeric($_POST['descr'])) {
515
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
516
	}
517
	/* input validation */
518
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
519
		if (!preg_match("/^staticv4/", $_POST['type'])) {
520
			$input_errors[] = gettext("The DHCP Server is active " .
521
			    "on this interface and it can be used only with " .
522
			    "a static IP configuration. Please disable the " .
523
			    "DHCP Server service on this interface first, " .
524
			    "then change the interface configuration.");
525
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
526
			$input_errors[] = gettext("The DHCP Server is active " .
527
			    "on this interface and it can be used only with " .
528
			    "IPv4 subnet < 31. Please disable the " .
529
			    "DHCP Server service on this interface first, " .
530
			    "then change the interface configuration.");
531
		}
532
	}
533
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
534
		$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.");
535
	}
536

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

    
644
			if (empty($_POST['track6-interface'])) {
645
				$input_errors[] = gettext("A valid interface to track must be selected.");
646
			}
647

    
648
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
649
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
650
			} else {
651
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
652
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
653
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
654
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
655
				} else {
656
					foreach ($ifdescrs as $ifent => $ifdescr) {
657
						if ($if == $ifent) {
658
							continue;
659
						}
660
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
661
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
662
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
663
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
664
						}
665
					}
666
				}
667
			}
668
			break;
669
	}
670

    
671
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
672
	$staticroutes = get_staticroutes(true);
673
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
674
	if ($_POST['ipaddr']) {
675
		if (!is_ipaddrv4($_POST['ipaddr'])) {
676
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
677
		} else {
678
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
679
			if (count($where_ipaddr_configured)) {
680
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
681
				foreach ($where_ipaddr_configured as $subnet_conflict) {
682
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
683
				}
684
				$input_errors[] = $subnet_conflict_text;
685
			}
686

    
687
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
688
			if ($_POST['subnet'] < 31) {
689
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
690
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
691
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
692
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
693
				}
694
			}
695

    
696
			foreach ($staticroutes as $route_subnet) {
697
				list($network, $subnet) = explode("/", $route_subnet);
698
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
699
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
700
					break;
701
				}
702
				unset($network, $subnet);
703
			}
704
		}
705
	}
706
	if ($_POST['ipaddrv6']) {
707
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
708

    
709
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
710
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
711
		} else {
712
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
713
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
714
			}
715
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
716
			if (count($where_ipaddr_configured)) {
717
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
718
				foreach ($where_ipaddr_configured as $subnet_conflict) {
719
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
720
				}
721
				$input_errors[] = $subnet_conflict_text;
722
			}
723

    
724
			foreach ($staticroutes as $route_subnet) {
725
				list($network, $subnet) = explode("/", $route_subnet);
726
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
727
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
728
					break;
729
				}
730
				unset($network, $subnet);
731
			}
732
		}
733
	}
734
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
735
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
736
	}
737
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
738
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
739
	}
740
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
741
		$input_errors[] = gettext("A valid alias IP address must be specified.");
742
	}
743
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
744
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
745
	}
746
	if ($_POST['dhcprejectfrom'] && !is_ipaddrv4($_POST['dhcprejectfrom'])) {
747
		$input_errors[] = gettext("A valid alias IP address must be specified to reject DHCP Leases from.");
748
	}
749
	if (($_POST['gateway'] != "none") || ($_POST['gatewayv6'] != "none")) {
750
		$match = false;
751
		foreach ($a_gateways as $gateway) {
752
			if (in_array($_POST['gateway'], $gateway)) {
753
				$match = true;
754
			}
755
		}
756
		foreach ($a_gateways as $gateway) {
757
			if (in_array($_POST['gatewayv6'], $gateway)) {
758
				$match = true;
759
			}
760
		}
761
		if (!$match) {
762
			$input_errors[] = gettext("A valid gateway must be specified.");
763
		}
764
	}
765
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
766
		$input_errors[] = gettext("The service name contains invalid characters.");
767
	}
768
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
769
		$input_errors[] = gettext("The idle timeout value must be an integer.");
770
	}
771
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
772
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
773
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
774
	}
775
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
776
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
777
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
778
	}
779
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
780
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
781
	}
782
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
783
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
784
	}
785
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
786
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
787
	}
788
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
789
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
790
	}
791
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
792
		$input_errors[] = gettext("The idle timeout value must be an integer.");
793
	}
794
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
795
		$input_errors[] = gettext("A valid MAC address must be specified.");
796
	}
797
	if ($_POST['mtu']) {
798
		if (!is_numericint($_POST['mtu'])) {
799
			$input_errors[] = "MTU must be an integer.";
800
		}
801
		if (substr($wancfg['if'], 0, 3) == 'gif') {
802
			$min_mtu = 1280;
803
			$max_mtu = 8192;
804
		} else {
805
			$min_mtu = 576;
806
			$max_mtu = 9000;
807
		}
808

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

    
813
		unset($min_mtu, $max_mtu);
814

    
815
		if (stristr($wancfg['if'], "_vlan")) {
816
			$realhwif_array = get_parent_interface($wancfg['if']);
817
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
818
			$parent_realhwif = $realhwif_array[0];
819
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
820
			$mtu = 0;
821
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
822
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
823
			if ($mtu == 0)
824
				$mtu = get_interface_mtu($parent_realhwif);
825
			if ($_POST['mtu'] > $mtu)
826
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
827
		} else {
828
			foreach ($config['interfaces'] as $idx => $ifdata) {
829
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
830
					continue;
831
				}
832

    
833
				$realhwif_array = get_parent_interface($ifdata['if']);
834
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
835
				$parent_realhwif = $realhwif_array[0];
836

    
837
				if ($parent_realhwif != $wancfg['if']) {
838
					continue;
839
				}
840

    
841
				if (isset($ifdata['mtu']) && $ifdata['mtu'] > $_POST['mtu']) {
842
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), $ifdata['descr']);
843
				}
844
			}
845
		}
846
	}
847
	if ($_POST['mss'] != '') {
848
		if (!is_numericint($_POST['mss']) || ($_POST['mss'] < 576 || $_POST['mss'] > 65535)) {
849
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
850
		}
851
	}
852
	/* Wireless interface? */
853
	if (isset($wancfg['wireless'])) {
854
		$reqdfields = array("mode");
855
		$reqdfieldsn = array(gettext("Mode"));
856
		if ($_POST['mode'] == 'hostap') {
857
			$reqdfields[] = "ssid";
858
			$reqdfieldsn[] = gettext("SSID");
859
			if (isset($_POST['channel']) && $_POST['channel'] == "0") {
860
				// auto channel with hostap is broken, prevent this for now.
861
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
862
			}
863
		}
864
		if (stristr($_POST['standard'], '11n')) {
865
			if (!($_POST['wme_enable'])) {
866
				$input_errors[] = gettext("802.11n standards require enabling WME.");
867
			}
868
		}
869
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
870
		check_wireless_mode();
871
		if (isset($_POST['wpa_group_rekey']) && (!is_numericint($_POST['wpa_group_rekey']) || $_POST['wpa_group_rekey'] < 1 || $_POST['wpa_group_rekey'] > 9999)) {
872
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
873
		}
874
		if (isset($_POST['wpa_gmk_rekey']) && (!is_numericint($_POST['wpa_gmk_rekey']) || $_POST['wpa_gmk_rekey'] < 1 || $_POST['wpa_gmk_rekey'] > 9999)) {
875
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
876
		}
877
		if (isset($_POST['wpa_group_rekey']) && isset($_POST['wpa_gmk_rekey'])) {
878
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
879
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
880
			}
881
		}
882
		if (!empty($_POST['auth_server_addr'])) {
883
			if (!is_domain($_POST['auth_server_addr']) && !is_ipaddr($_POST['auth_server_addr'])) {
884
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
885
			}
886
		}
887
		if (!empty($_POST['auth_server_addr2'])) {
888
			if (!is_domain($_POST['auth_server_addr2']) && !is_ipaddr($_POST['auth_server_addr2'])) {
889
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
890
			}
891
		}
892
		if (!empty($_POST['auth_server_port'])) {
893
			if (!is_port($_POST['auth_server_port'])) {
894
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
895
			}
896
		}
897
		if (!empty($_POST['auth_server_port2'])) {
898
			if (!is_port($_POST['auth_server_port2'])) {
899
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
900
			}
901
		}
902
		if (isset($_POST['channel']) && !is_numericint($_POST['channel'])) {
903
			if (!is_numericint($_POST['channel'])) {
904
				$input_errors[] = gettext("Invalid channel specified.");
905
			} else {
906
				if ($_POST['channel'] > 255 || $_POST['channel'] < 0) {
907
					$input_errors[] = gettext("Channel must be between 0-255.");
908
				}
909
			}
910
		}
911
		if (!empty($_POST['distance']) && !is_numericint($_POST['distance'])) {
912
			$input_errors[] = gettext("Distance must be an integer.");
913
		}
914
		if (isset($_POST['standard']) && (stristr($_POST['standard'], '11na') || stristr($_POST['standard'], '11a'))) {
915
			if ($_POST['channel'] != 0 && $_POST['channel'] < 15) {
916
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
917
			}
918
		}
919
		if (isset($_POST['standard']) && ($_POST['standard'] == "11b" || $_POST['standard'] == "11g")) {
920
			if ($_POST['channel'] > 14) {
921
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
922
			}
923
		}
924
		if (!empty($_POST['protmode']) && !in_array($_POST['protmode'], array("off", "cts", "rtscts"))) {
925
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
926
		}
927

    
928
		if ($_POST['passphrase']) {
929
			$passlen = strlen($_POST['passphrase']);
930
			if ($passlen < 8 || $passlen > 63) {
931
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
932
			}
933
		}
934

    
935
		if ($_POST['wpa_enable'] == "yes") {
936
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
937
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
938
			}
939
		}
940
	}
941

    
942
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
943
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
944
	}
945

    
946
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
947
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
948
	}
949

    
950
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
951
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
952
	}
953

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

    
961
		if ($wancfg['ipaddr'] != $_POST['type']) {
962
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
963
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
964
				unset($a_ppps[$pppid]);
965
			} else if ($wancfg['ipaddr'] == "dhcp") {
966
				kill_dhclient_process($wancfg['if']);
967
			}
968
			if ($wancfg['ipaddrv6'] == "dhcp6") {
969
				$pid = find_dhcp6c_process($wancfg['if']);
970
				if ($pid) {
971
					posix_kill($pid, SIGTERM);
972
				}
973
			}
974
		}
975
		$ppp = array();
976
		if ($wancfg['ipaddr'] != "ppp") {
977
			unset($wancfg['ipaddr']);
978
		}
979
		if ($wancfg['ipaddrv6'] != "ppp") {
980
			unset($wancfg['ipaddrv6']);
981
		}
982
		unset($wancfg['subnet']);
983
		unset($wancfg['gateway']);
984
		unset($wancfg['subnetv6']);
985
		unset($wancfg['gatewayv6']);
986
		unset($wancfg['dhcphostname']);
987
		unset($wancfg['dhcprejectfrom']);
988
		unset($wancfg['dhcp6-duid']);
989
		unset($wancfg['dhcp6-ia-pd-len']);
990
		unset($wancfg['dhcp6-ia-pd-send-hint']);
991
		unset($wancfg['dhcp6prefixonly']);
992
		unset($wancfg['dhcp6usev4iface']);
993
		unset($wancfg['dhcp6debug']);
994
		unset($wancfg['track6-interface']);
995
		unset($wancfg['track6-prefix-id']);
996
		unset($wancfg['dhcp6withoutra']);
997
		unset($wancfg['dhcp6norelease']);
998
		unset($wancfg['prefix-6rd']);
999
		unset($wancfg['prefix-6rd-v4plen']);
1000
		unset($wancfg['gateway-6rd']);
1001

    
1002
		unset($wancfg['adv_dhcp_pt_timeout']);
1003
		unset($wancfg['adv_dhcp_pt_retry']);
1004
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1005
		unset($wancfg['adv_dhcp_pt_reboot']);
1006
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1007
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1008

    
1009
		unset($wancfg['adv_dhcp_pt_values']);
1010

    
1011
		unset($wancfg['adv_dhcp_send_options']);
1012
		unset($wancfg['adv_dhcp_request_options']);
1013
		unset($wancfg['adv_dhcp_required_options']);
1014
		unset($wancfg['adv_dhcp_option_modifiers']);
1015

    
1016
		unset($wancfg['adv_dhcp_config_advanced']);
1017
		unset($wancfg['adv_dhcp_config_file_override']);
1018
		unset($wancfg['adv_dhcp_config_file_override_path']);
1019

    
1020
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1021
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1022
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1023
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1024

    
1025
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1026
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1027
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1028
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1029
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1030

    
1031
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1032
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1033
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1034
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1035
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1036

    
1037
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1038
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1039

    
1040
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1041
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1042
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1043
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1044

    
1045
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1046
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1047
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1048
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1049
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1050

    
1051
		unset($wancfg['adv_dhcp6_config_advanced']);
1052
		unset($wancfg['adv_dhcp6_config_file_override']);
1053
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1054

    
1055
		unset($wancfg['pppoe_password']);
1056
		unset($wancfg['pptp_username']);
1057
		unset($wancfg['pptp_password']);
1058
		unset($wancfg['provider']);
1059
		unset($wancfg['ondemand']);
1060
		unset($wancfg['timeout']);
1061
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1062
			unset($wancfg['pppoe']['pppoe-reset-type']);
1063
		}
1064
		unset($wancfg['local']);
1065

    
1066
		unset($wancfg['remote']);
1067
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1068
			if ($wancfg['ipaddr'] != 'ppp') {
1069
				unset($a_ppps[$pppid]['apn']);
1070
				unset($a_ppps[$pppid]['phone']);
1071
				unset($a_ppps[$pppid]['provider']);
1072
				unset($a_ppps[$pppid]['ondemand']);
1073
			}
1074
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1075
				unset($a_ppps[$pppid]['localip']);
1076
				unset($a_ppps[$pppid]['subnet']);
1077
				unset($a_ppps[$pppid]['gateway']);
1078
			}
1079
			if ($wancfg['ipaddr'] != 'pppoe') {
1080
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1081
			}
1082
			if ($wancfg['type'] != $_POST['type']) {
1083
				unset($a_ppps[$pppid]['idletimeout']);
1084
			}
1085
		}
1086

    
1087
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1088
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1089

    
1090
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1091
		switch ($_POST['type']) {
1092
			case "staticv4":
1093
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1094
				$wancfg['subnet'] = $_POST['subnet'];
1095
				if ($_POST['gateway'] != "none") {
1096
					$wancfg['gateway'] = $_POST['gateway'];
1097
				}
1098
				break;
1099
			case "dhcp":
1100
				$wancfg['ipaddr'] = "dhcp";
1101
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1102
				$wancfg['alias-address'] = $_POST['alias-address'];
1103
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1104
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1105

    
1106
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1107
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1108
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1109
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1110
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1111
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1112

    
1113
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1114

    
1115
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1116
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1117
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1118
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1119

    
1120
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1121
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1122
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1123

    
1124
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1125
				if ($gateway_item) {
1126
					$a_gateways[] = $gateway_item;
1127
				}
1128
				break;
1129
			case "ppp":
1130
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1131
				$a_ppps[$pppid]['type'] = $_POST['type'];
1132
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1133
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1134
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1135
				if ($_POST['ppp_password'] != DMYPWD) {
1136
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1137
				}
1138
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1139
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1140
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1141
				$wancfg['ipaddr'] = $_POST['type'];
1142
				break;
1143

    
1144
			case "pppoe":
1145
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1146
				$a_ppps[$pppid]['type'] = $_POST['type'];
1147
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1148
				if (isset($_POST['ppp_port'])) {
1149
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1150
				} else {
1151
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1152
				}
1153
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1154
				if ($_POST['pppoe_password'] != DMYPWD) {
1155
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1156
				}
1157
				if (!empty($_POST['provider'])) {
1158
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1159
				} else {
1160
					$a_ppps[$pppid]['provider'] = true;
1161
				}
1162
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1163
				if (!empty($_POST['pppoe_idletimeout'])) {
1164
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1165
				} else {
1166
					unset($a_ppps[$pppid]['idletimeout']);
1167
				}
1168

    
1169
				if (!empty($_POST['pppoe-reset-type'])) {
1170
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1171
				} else {
1172
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1173
				}
1174
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1175
				$wancfg['ipaddr'] = $_POST['type'];
1176
				if ($gateway_item) {
1177
					$a_gateways[] = $gateway_item;
1178
				}
1179

    
1180
				break;
1181
			case "pptp":
1182
			case "l2tp":
1183
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1184
				$a_ppps[$pppid]['type'] = $_POST['type'];
1185
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1186
				if (isset($_POST['ppp_port'])) {
1187
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1188
				} else {
1189
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1190
				}
1191
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1192
				if ($_POST['pptp_password'] != DMYPWD) {
1193
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1194
				}
1195
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1196
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1197
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1198
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1199
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1200
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1201
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1202
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1203
				if (!empty($_POST['pptp_idletimeout'])) {
1204
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1205
				} else {
1206
					unset($a_ppps[$pppid]['idletimeout']);
1207
				}
1208
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1209
				$wancfg['ipaddr'] = $_POST['type'];
1210
				if ($gateway_item) {
1211
					$a_gateways[] = $gateway_item;
1212
				}
1213
				break;
1214
			case "none":
1215
				break;
1216
		}
1217
		switch ($_POST['type6']) {
1218
			case "staticv6":
1219
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1220
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1221
				if ($_POST['gatewayv6'] != "none") {
1222
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1223
				}
1224
				break;
1225
			case "slaac":
1226
				$wancfg['ipaddrv6'] = "slaac";
1227
				break;
1228
			case "dhcp6":
1229
				$wancfg['ipaddrv6'] = "dhcp6";
1230
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1231
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1232
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1233
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1234
				}
1235
				if ($_POST['dhcp6prefixonly'] == "yes") {
1236
					$wancfg['dhcp6prefixonly'] = true;
1237
				}
1238
				if ($_POST['dhcp6usev4iface'] == "yes") {
1239
					$wancfg['dhcp6usev4iface'] = true;
1240
				}
1241
				if ($_POST['dhcp6debug'] == "yes") {
1242
					$wancfg['dhcp6debug'] = true;
1243
				}
1244

    
1245
				if ($_POST['dhcp6withoutra'] == "yes") {
1246
					$wancfg['dhcp6withoutra'] = true;
1247
				}
1248
				if ($_POST['dhcp6norelease'] == "yes") {
1249
					$wancfg['dhcp6norelease'] = true;
1250
				}
1251
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1252
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1253
				}
1254
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1255
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1256
				}
1257
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1258
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1259
				}
1260
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1261
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1262
				}
1263

    
1264
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1265
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1266
				}
1267
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1268
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1269
				}
1270
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1271
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1272
				}
1273
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1274
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1275
				}
1276
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1277
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1278
				}
1279

    
1280
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1281
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1282
				}
1283
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1284
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1285
				}
1286
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1287
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1288
				}
1289
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1290
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1291
				}
1292
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1293
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1294
				}
1295

    
1296
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1297
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1298
				}
1299
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1300
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1301
				}
1302

    
1303
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1304
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1307
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1310
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1311
				}
1312
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1313
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1314
				}
1315

    
1316
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1317
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1320
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1323
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1326
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1327
				}
1328
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1329
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1330
				}
1331

    
1332
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1333
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1334
				}
1335
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1336
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1339
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1340
				}
1341

    
1342
				if ($gateway_item) {
1343
					$a_gateways[] = $gateway_item;
1344
				}
1345
				break;
1346
			case "6rd":
1347
				$wancfg['ipaddrv6'] = "6rd";
1348
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1349
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1350
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1351
				if ($gateway_item) {
1352
					$a_gateways[] = $gateway_item;
1353
				}
1354
				break;
1355
			case "6to4":
1356
				$wancfg['ipaddrv6'] = "6to4";
1357
				break;
1358
			case "track6":
1359
				$wancfg['ipaddrv6'] = "track6";
1360
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1361
				if ($_POST['track6-prefix-id--hex'] === "") {
1362
					$wancfg['track6-prefix-id'] = 0;
1363
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1364
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1365
				} else {
1366
					$wancfg['track6-prefix-id'] = 0;
1367
				}
1368
				break;
1369
			case "none":
1370
				break;
1371
		}
1372
		handle_pppoe_reset($_POST);
1373

    
1374
		if ($_POST['blockpriv'] == "yes") {
1375
			$wancfg['blockpriv'] = true;
1376
		} else {
1377
			unset($wancfg['blockpriv']);
1378
		}
1379
		if ($_POST['blockbogons'] == "yes") {
1380
			$wancfg['blockbogons'] = true;
1381
		} else {
1382
			unset($wancfg['blockbogons']);
1383
		}
1384
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1385
		if (empty($_POST['mtu'])) {
1386
			unset($wancfg['mtu']);
1387
		} else {
1388
			$wancfg['mtu'] = $_POST['mtu'];
1389
		}
1390
		if (empty($_POST['mss'])) {
1391
			unset($wancfg['mss']);
1392
		} else {
1393
			$wancfg['mss'] = $_POST['mss'];
1394
		}
1395
		if (empty($_POST['mediaopt'])) {
1396
			unset($wancfg['media']);
1397
			unset($wancfg['mediaopt']);
1398
		} else {
1399
			$mediaopts = explode(' ', $_POST['mediaopt']);
1400
			if ($mediaopts[0] != '') {
1401
				$wancfg['media'] = $mediaopts[0];
1402
			}
1403
			if ($mediaopts[1] != '') {
1404
				$wancfg['mediaopt'] = $mediaopts[1];
1405
			} else {
1406
				unset($wancfg['mediaopt']);
1407
			}
1408
		}
1409
		if (isset($wancfg['wireless'])) {
1410
			handle_wireless_post();
1411
		}
1412

    
1413
		write_config();
1414

    
1415
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1416
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1417
		} else {
1418
			$toapplylist = array();
1419
		}
1420
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1421
		$toapplylist[$if]['ppps'] = $old_ppps;
1422
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1423

    
1424
		mark_subsystem_dirty('interfaces');
1425

    
1426
		/* regenerate cron settings/crontab file */
1427
		configure_cron();
1428

    
1429
		header("Location: interfaces.php?if={$if}");
1430
		exit;
1431
	}
1432

    
1433
} // end if ($_POST)
1434

    
1435
function handle_wireless_post() {
1436
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1437
	if (!is_array($wancfg['wireless'])) {
1438
		$wancfg['wireless'] = array();
1439
	}
1440
	$wancfg['wireless']['standard'] = $_POST['standard'];
1441
	$wancfg['wireless']['mode'] = $_POST['mode'];
1442
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1443
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1444
	$wancfg['wireless']['channel'] = $_POST['channel'];
1445
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1446
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1447
	$wancfg['wireless']['distance'] = $_POST['distance'];
1448
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1449
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1450
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1451
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1452
		foreach ($wl_countries_attr as $wl_country) {
1453
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1454
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1455
				break;
1456
			}
1457
		}
1458
	}
1459
	if (!is_array($wancfg['wireless']['wpa'])) {
1460
		$wancfg['wireless']['wpa'] = array();
1461
	}
1462
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1463
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1464
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1465
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1466
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1467
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1468
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1469
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1470
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1471
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1472
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1473
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1474
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1475
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1476

    
1477
	if ($_POST['persistcommonwireless'] == "yes") {
1478
		if (!is_array($config['wireless'])) {
1479
			$config['wireless'] = array();
1480
		}
1481
		if (!is_array($config['wireless']['interfaces'])) {
1482
			$config['wireless']['interfaces'] = array();
1483
		}
1484
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1485
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1486
		}
1487
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1488
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1489
	}
1490
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1491
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1492
	} else if (isset($wancfg['wireless']['diversity'])) {
1493
		unset($wancfg['wireless']['diversity']);
1494
	}
1495
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1496
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1497
	} else if (isset($wancfg['wireless']['txantenna'])) {
1498
		unset($wancfg['wireless']['txantenna']);
1499
	}
1500
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1501
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1502
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1503
		unset($wancfg['wireless']['rxantenna']);
1504
	}
1505
	if ($_POST['hidessid_enable'] == "yes") {
1506
		$wancfg['wireless']['hidessid']['enable'] = true;
1507
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1508
		unset($wancfg['wireless']['hidessid']['enable']);
1509
	}
1510
	if ($_POST['mac_acl_enable'] == "yes") {
1511
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1512
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1513
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1514
	}
1515
	if ($_POST['rsn_preauth'] == "yes") {
1516
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1517
	} else {
1518
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1519
	}
1520
	if ($_POST['ieee8021x'] == "yes") {
1521
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1522
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1523
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1524
	}
1525
	if ($_POST['wpa_strict_rekey'] == "yes") {
1526
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1527
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1528
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1529
	}
1530
	if ($_POST['debug_mode'] == "yes") {
1531
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1532
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1533
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1534
	}
1535
	if ($_POST['wpa_enable'] == "yes") {
1536
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1537
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1538
		unset($wancfg['wireless']['wpa']['enable']);
1539
	}
1540

    
1541
	if ($_POST['wme_enable'] == "yes") {
1542
		if (!is_array($wancfg['wireless']['wme'])) {
1543
			$wancfg['wireless']['wme'] = array();
1544
		}
1545
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1546
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1547
		unset($wancfg['wireless']['wme']['enable']);
1548
	}
1549
	if ($_POST['puremode'] == "11g") {
1550
		if (!is_array($wancfg['wireless']['pureg'])) {
1551
			$wancfg['wireless']['pureg'] = array();
1552
		}
1553
		$wancfg['wireless']['pureg']['enable'] = true;
1554
	} else if ($_POST['puremode'] == "11n") {
1555
		if (!is_array($wancfg['wireless']['puren'])) {
1556
			$wancfg['wireless']['puren'] = array();
1557
		}
1558
		$wancfg['wireless']['puren']['enable'] = true;
1559
	} else {
1560
		if (isset($wancfg['wireless']['pureg'])) {
1561
			unset($wancfg['wireless']['pureg']);
1562
		}
1563
		if (isset($wancfg['wireless']['puren'])) {
1564
			unset($wancfg['wireless']['puren']);
1565
		}
1566
	}
1567
	if ($_POST['apbridge_enable'] == "yes") {
1568
		if (!is_array($wancfg['wireless']['apbridge'])) {
1569
			$wancfg['wireless']['apbridge'] = array();
1570
		}
1571
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1572
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1573
		unset($wancfg['wireless']['apbridge']['enable']);
1574
	}
1575
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1576
		if (!is_array($wancfg['wireless']['turbo'])) {
1577
			$wancfg['wireless']['turbo'] = array();
1578
		}
1579
		$wancfg['wireless']['turbo']['enable'] = true;
1580
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1581
		unset($wancfg['wireless']['turbo']['enable']);
1582
	}
1583

    
1584
	interface_sync_wireless_clones($wancfg, true);
1585
}
1586

    
1587
function check_wireless_mode() {
1588
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1589

    
1590
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1591
		return;
1592
	}
1593

    
1594
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1595
		$clone_count = 1;
1596
	} else {
1597
		$clone_count = 0;
1598
	}
1599

    
1600
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1601
		foreach ($config['wireless']['clone'] as $clone) {
1602
			if ($clone['if'] == $wlanbaseif) {
1603
				$clone_count++;
1604
			}
1605
		}
1606
	}
1607

    
1608
	if ($clone_count > 1) {
1609
		$old_wireless_mode = $wancfg['wireless']['mode'];
1610
		$wancfg['wireless']['mode'] = $_POST['mode'];
1611
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1612
			$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']]);
1613
		} else {
1614
			pfSense_interface_destroy("{$wlanif}_");
1615
		}
1616
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1617
	}
1618
}
1619

    
1620
// Find all possible media options for the interface
1621
$mediaopts_list = array();
1622
$intrealname = $config['interfaces'][$if]['if'];
1623
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1624
foreach ($mediaopts as $mediaopt) {
1625
	preg_match("/media (.*)/", $mediaopt, $matches);
1626
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1627
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1628
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1629
	} else {
1630
		// there is only media like "media 1000baseT"
1631
		array_push($mediaopts_list, $matches[1]);
1632
	}
1633
}
1634

    
1635
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1636
$shortcut_section = "interfaces";
1637

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

    
1641
// Get the MAC address
1642
$ip = $_SERVER['REMOTE_ADDR'];
1643
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1644
$mymac = str_replace("\n", "", $mymac);
1645

    
1646
function build_mediaopts_list() {
1647
	global $mediaopts_list;
1648

    
1649
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1650
			 " " =>	 gettext("------- Media Supported by this interface -------")
1651
			];
1652

    
1653
	foreach ($mediaopts_list as $mediaopt) {
1654
		$list[$mediaopt] = $mediaopt;
1655
	}
1656

    
1657
	return($list);
1658
}
1659

    
1660
function build_gateway_list() {
1661
	global $a_gateways, $if;
1662

    
1663
	$list = array("none" => gettext("None"));
1664
	foreach ($a_gateways as $gateway) {
1665
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1666
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1667
		}
1668
	}
1669

    
1670
	return($list);
1671
}
1672

    
1673
function build_gatewayv6_list() {
1674
	global $a_gateways, $if;
1675

    
1676
	$list = array("none" => gettext("None"));
1677
	foreach ($a_gateways as $gateway) {
1678
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1679
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1680
		}
1681
	}
1682

    
1683
	return($list);
1684
}
1685

    
1686
include("head.inc");
1687

    
1688
if ($input_errors) {
1689
	print_input_errors($input_errors);
1690
}
1691

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

    
1698
if ($savemsg) {
1699
	print_info_box($savemsg, 'success');
1700
}
1701

    
1702

    
1703
$form = new Form();
1704

    
1705
$section = new Form_Section('General Configuration');
1706

    
1707
$section->addInput(new Form_Checkbox(
1708
	'enable',
1709
	'Enable',
1710
	'Enable interface',
1711
	$pconfig['enable'],
1712
	'yes'
1713
));
1714

    
1715
$section->addInput(new Form_Input(
1716
	'descr',
1717
	'Description',
1718
	'text',
1719
	$pconfig['descr']
1720
))->setHelp('Enter a description (name) for the interface here.');
1721

    
1722
$section->addInput(new Form_Select(
1723
	'type',
1724
	'IPv4 Configuration Type',
1725
	$pconfig['type'],
1726
	$types4
1727
));
1728

    
1729
$section->addInput(new Form_Select(
1730
	'type6',
1731
	'IPv6 Configuration Type',
1732
	$pconfig['type6'],
1733
	$types6
1734
));
1735

    
1736
$macaddress = new Form_Input(
1737
	'spoofmac',
1738
	'MAC Address',
1739
	'text',
1740
	$pconfig['spoofmac'],
1741
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1742
);
1743

    
1744
$btnmymac = new Form_Button(
1745
	'btnmymac',
1746
	'Copy My MAC',
1747
	null,
1748
	'fa-clone'
1749
	);
1750

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

    
1753
$group = new Form_Group('MAC Address');
1754
$group->add($macaddress);
1755
// $group->add($btnmymac);
1756
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1757
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.');
1758
$section->add($group);
1759

    
1760
$section->addInput(new Form_Input(
1761
	'mtu',
1762
	'MTU',
1763
	'number',
1764
	$pconfig['mtu']
1765
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1766
			'This is typically 1500 bytes but can vary in some circumstances.');
1767

    
1768
$section->addInput(new Form_Input(
1769
	'mss',
1770
	'MSS',
1771
	'number',
1772
	$pconfig['mss']
1773
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1774
			'header size) will be in effect.');
1775

    
1776
if (count($mediaopts_list) > 0) {
1777
	$section->addInput(new Form_Select(
1778
		'mediaopt',
1779
		'Speed and Duplex',
1780
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1781
		build_mediaopts_list()
1782
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1783
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1784
}
1785

    
1786
$form->add($section);
1787

    
1788
$section = new Form_Section('Static IPv4 Configuration');
1789
$section->addClass('staticv4');
1790

    
1791
$section->addInput(new Form_IpAddress(
1792
	'ipaddr',
1793
	'IPv4 Address',
1794
	$pconfig['ipaddr'],
1795
	'V4'
1796
))->addMask('subnet', $pconfig['subnet'], 32);
1797

    
1798
$group = new Form_Group('IPv4 Upstream gateway');
1799

    
1800
$group->add(new Form_Select(
1801
	'gateway',
1802
	'IPv4 Upstream Gateway',
1803
	$pconfig['gateway'],
1804
	build_gateway_list()
1805
));
1806

    
1807
$group->add(new Form_Button(
1808
	'addgw',
1809
	'Add a new gateway',
1810
	null,
1811
	'fa-plus'
1812
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1813

    
1814
$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.' . '<br />' .
1815
				'On local area network interfaces the upstream gateway should be "none". ' .
1816
				gettext('Gateways can be managed by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>.');
1817

    
1818
$section->add($group);
1819

    
1820
$form->add($section);
1821

    
1822
$section = new Form_Section('Static IPv6 Configuration');
1823
$section->addClass('staticv6');
1824

    
1825
$section->addInput(new Form_IpAddress(
1826
	'ipaddrv6',
1827
	'IPv6 address',
1828
	$pconfig['ipaddrv6'],
1829
	'V6'
1830
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1831

    
1832
$group = new Form_Group('IPv6 Upstream gateway');
1833

    
1834
$group->add(new Form_Select(
1835
	'gatewayv6',
1836
	'IPv6 Upstream Gateway',
1837
	$pconfig['gatewayv6'],
1838
	build_gatewayv6_list()
1839
));
1840

    
1841
$group->add(new Form_Button(
1842
	'addgw6',
1843
	'Add a new gateway',
1844
	null,
1845
	'fa-plus'
1846
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1847

    
1848
$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.' . '<br />' .
1849
				'On local LANs the upstream gateway should be "none". ');
1850

    
1851
$section->add($group);
1852
$form->add($section);
1853

    
1854
// Add new gateway modal pop-up for IPv6
1855
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1856

    
1857
$modal->addInput(new Form_Checkbox(
1858
	'defaultgw6',
1859
	'Default',
1860
	'Default gateway',
1861
	($if == "wan" || $if == "WAN")
1862
));
1863

    
1864
$modal->addInput(new Form_Input(
1865
	'name6',
1866
	'Gateway name',
1867
	'text',
1868
	$wancfg['descr'] . "GWv6"
1869
));
1870

    
1871
$modal->addInput(new Form_IpAddress(
1872
	'gatewayip6',
1873
	'Gateway IPv6',
1874
	null,
1875
	'V6'
1876
));
1877

    
1878
$modal->addInput(new Form_Input(
1879
	'gatewaydescr6',
1880
	'Description',
1881
	'text'
1882
));
1883

    
1884
$btnaddgw6 = new Form_Button(
1885
	'add6',
1886
	'Add',
1887
	null,
1888
	'fa-plus'
1889
);
1890

    
1891
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1892

    
1893
$btncnxgw6 = new Form_Button(
1894
	'cnx6',
1895
	'Cancel',
1896
	null,
1897
	'fa-undo'
1898
);
1899

    
1900
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1901

    
1902
$modal->addInput(new Form_StaticText(
1903
	null,
1904
	$btnaddgw6 . $btncnxgw6
1905
));
1906

    
1907
$form->add($modal);
1908

    
1909
// ==== DHCP client configuration =============================
1910

    
1911
$section = new Form_Section('DHCP Client Configuration');
1912
$section->addClass('dhcp');
1913

    
1914
$group = new Form_Group('Options');
1915

    
1916
$group->add(new Form_Checkbox(
1917
	'adv_dhcp_config_advanced',
1918
	null,
1919
	'Advanced Configuration',
1920
	$pconfig['adv_dhcp_config_advanced']
1921
))->setHelp('Use advanced DHCP configuration options.');
1922

    
1923
$group->add(new Form_Checkbox(
1924
	'adv_dhcp_config_file_override',
1925
	null,
1926
	'Configuration Override',
1927
	$pconfig['adv_dhcp_config_file_override']
1928
))->setHelp('Override the configuration from this file.');
1929

    
1930
$section->add($group);
1931

    
1932
$section->addInput(new Form_Input(
1933
	'dhcphostname',
1934
	'Hostname',
1935
	'text',
1936
	$pconfig['dhcphostname']
1937
))->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).');
1938

    
1939
$section->addInput(new Form_IpAddress(
1940
	'alias-address',
1941
	'Alias IPv4 address',
1942
	$pconfig['alias-address'],
1943
	'V4'
1944
))->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.');
1945

    
1946
$section->addInput(new Form_Input(
1947
	'dhcprejectfrom',
1948
	'Reject leases from',
1949
	'text',
1950
	$pconfig['dhcprejectfrom']
1951
))->setHelp('To make the DHCP client reject leases from an undesirable DHCP server, place the IP address of the DHCP server here. ' .
1952
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
1953

    
1954
$group = new Form_Group('Protocol timing');
1955
$group->addClass('dhcpadvanced');
1956

    
1957
$group->add(new Form_Input(
1958
	'adv_dhcp_pt_timeout',
1959
	null,
1960
	'number',
1961
	$pconfig['adv_dhcp_pt_timeout']
1962
))->setHelp('Timeout');
1963

    
1964
$group->add(new Form_Input(
1965
	'adv_dhcp_pt_retry',
1966
	null,
1967
	'number',
1968
	$pconfig['adv_dhcp_pt_retry']
1969
))->setHelp('Retry');
1970

    
1971
$group->add(new Form_Input(
1972
	'adv_dhcp_pt_select_timeout',
1973
	null,
1974
	'number',
1975
	$pconfig['adv_dhcp_pt_select_timeout'],
1976
	['min' => 0]
1977
))->setHelp('Select timeout');
1978

    
1979
$group->add(new Form_Input(
1980
	'adv_dhcp_pt_reboot',
1981
	null,
1982
	'number',
1983
	$pconfig['adv_dhcp_pt_reboot']
1984
))->setHelp('Reboot');
1985

    
1986
$group->add(new Form_Input(
1987
	'adv_dhcp_pt_backoff_cutoff',
1988
	null,
1989
	'number',
1990
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1991
))->setHelp('Backoff cutoff');
1992

    
1993
$group->add(new Form_Input(
1994
	'adv_dhcp_pt_initial_interval',
1995
	null,
1996
	'number',
1997
	$pconfig['adv_dhcp_pt_initial_interval']
1998
))->setHelp('Initial interval');
1999

    
2000
$section->add($group);
2001

    
2002
$group = new Form_Group('Presets');
2003
$group->addClass('dhcpadvanced');
2004

    
2005
$group->add(new Form_Checkbox(
2006
	'adv_dhcp_pt_values',
2007
	null,
2008
	'FreeBSD default',
2009
	null,
2010
	'DHCP'
2011
))->displayAsRadio();
2012

    
2013
$group->add(new Form_Checkbox(
2014
	'adv_dhcp_pt_values',
2015
	null,
2016
	'Clear',
2017
	null,
2018
	'Clear'
2019
))->displayAsRadio();
2020

    
2021
$group->add(new Form_Checkbox(
2022
	'adv_dhcp_pt_values',
2023
	null,
2024
	'pfSense Default',
2025
	null,
2026
	'pfSense'
2027
))->displayAsRadio();
2028

    
2029
$group->add(new Form_Checkbox(
2030
	'adv_dhcp_pt_values',
2031
	null,
2032
	'Saved Cfg',
2033
	null,
2034
	'SavedCfg'
2035
))->displayAsRadio();
2036

    
2037
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.' . '<br />' .
2038
				'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#PROTOCOL_TIMING">' . 'See here more information' . '</a>');
2039

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

    
2042
$section->addInput(new Form_Input(
2043
	'adv_dhcp_config_file_override_path',
2044
	'Configuration File Override',
2045
	'text',
2046
	$pconfig['adv_dhcp_config_file_override_path']
2047
))->setWidth(9)->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2048
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2049
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2050
			'Some ISPs may require certain options be or not be sent.');
2051

    
2052
$form->add($section);
2053

    
2054
$section = new Form_Section('Lease Requirements and Requests');
2055
$section->addClass('dhcpadvanced');
2056

    
2057
$section->addInput(new Form_Input(
2058
	'adv_dhcp_send_options',
2059
	'Send options',
2060
	'text',
2061
	$pconfig['adv_dhcp_send_options']
2062
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2063
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2064
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2065
			'Some ISPs may require certain options be or not be sent.');
2066

    
2067
$section->addInput(new Form_Input(
2068
	'adv_dhcp_request_options',
2069
	'Request options',
2070
	'text',
2071
	$pconfig['adv_dhcp_request_options']
2072
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2073
			'Some ISPs may require certain options be or not be requested.');
2074

    
2075
$section->addInput(new Form_Input(
2076
	'adv_dhcp_required_options',
2077
	'Require options',
2078
	'text',
2079
	$pconfig['adv_dhcp_required_options']
2080
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2081

    
2082
$section->addInput(new Form_Input(
2083
	'adv_dhcp_option_modifiers',
2084
	'Option modifiers',
2085
	'text',
2086
	$pconfig['adv_dhcp_option_modifiers']
2087
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2088
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2089
			'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">' . 'See here more information' . '</a>');
2090

    
2091
$form->add($section);
2092

    
2093
// DHCP6 client config
2094

    
2095
$section = new Form_Section('DHCP6 Client Configuration');
2096
$section->addClass('dhcp6');
2097

    
2098
$group = new Form_Group('Options');
2099

    
2100
$group->add(new Form_Checkbox(
2101
	'adv_dhcp6_config_advanced',
2102
	null,
2103
	'Advanced Configuration',
2104
	$pconfig['adv_dhcp6_config_advanced']
2105
))->setHelp('Use advanced DHCPv6 configuration options.');
2106

    
2107
$group->add(new Form_Checkbox(
2108
	'adv_dhcp6_config_file_override',
2109
	null,
2110
	'Configuration Override',
2111
	$pconfig['adv_dhcp6_config_file_override']
2112
))->setHelp('Override the configuration from this file.');
2113

    
2114
$section->add($group);
2115

    
2116
$section->addInput(new Form_Checkbox(
2117
	'dhcp6usev4iface',
2118
	'Use IPv4 connectivity as parent interface',
2119
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2120
	$pconfig['dhcp6usev4iface']
2121
));
2122

    
2123
$section->addInput(new Form_Checkbox(
2124
	'dhcp6prefixonly',
2125
	'Request only an IPv6 prefix',
2126
	'Only request an IPv6 prefix, do not request an IPv6 address',
2127
	$pconfig['dhcp6prefixonly']
2128
));
2129

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

    
2137
$section->addInput(new Form_Checkbox(
2138
	'dhcp6-ia-pd-send-hint',
2139
	'Send IPv6 prefix hint',
2140
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2141
	$pconfig['dhcp6-ia-pd-send-hint']
2142
));
2143

    
2144
$section->addInput(new Form_Checkbox(
2145
	'dhcp6debug',
2146
	'Debug',
2147
	'Start DHCP6 client in debug mode',
2148
	$pconfig['dhcp6debug']
2149
));
2150
$section->addInput(new Form_Checkbox(
2151
	'dhcp6withoutra',
2152
	'Do not wait for a RA',
2153
	'Required by some ISPs, especially those not using PPPoE',
2154
	$pconfig['dhcp6withoutra']
2155
));
2156
$section->addInput(new Form_Checkbox(
2157
	'dhcp6norelease',
2158
	'Do not allow PD/Address release',
2159
	'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',
2160
	$pconfig['dhcp6norelease']
2161
));
2162
$section->addInput(new Form_Input(
2163
	'adv_dhcp6_config_file_override_path',
2164
	'Configuration File Override',
2165
	'text',
2166
	$pconfig['adv_dhcp6_config_file_override_path']
2167
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2168
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2169
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2170
			'Some ISPs may require certain options be or not be sent.');
2171

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

    
2174
// DHCP6 client config - Advanced
2175

    
2176
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2177
$section->addClass('dhcp6advanced');
2178

    
2179
$section->addInput(new Form_Checkbox(
2180
	'adv_dhcp6_interface_statement_information_only_enable',
2181
	'Information only',
2182
	'Exchange Information Only',
2183
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2184
	'Selected'
2185
))->setHelp('Only exchange informational configuration parameters with servers.');
2186

    
2187
$section->addInput(new Form_Input(
2188
	'adv_dhcp6_interface_statement_send_options',
2189
	'Send options',
2190
	'text',
2191
	$pconfig['adv_dhcp6_interface_statement_send_options']
2192
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2193
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2194
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2195
			'Some DHCP services may require certain options be or not be sent.');
2196

    
2197
$section->addInput(new Form_Input(
2198
	'adv_dhcp6_interface_statement_request_options',
2199
	'Request Options',
2200
	'text',
2201
	$pconfig['adv_dhcp6_interface_statement_request_options']
2202
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2203
			'Some DHCP services may require certain options be or not be requested.');
2204

    
2205
$section->addInput(new Form_Input(
2206
	'adv_dhcp6_interface_statement_script',
2207
	'Scripts',
2208
	'text',
2209
	$pconfig['adv_dhcp6_interface_statement_script']
2210
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2211
			'[/[dirname/[.../]]filename[.ext]].');
2212

    
2213
$group = new Form_Group('Identity Association Statement');
2214

    
2215
$group->add(new Form_Checkbox(
2216
	'adv_dhcp6_id_assoc_statement_address_enable',
2217
	null,
2218
	'Non-Temporary Address Allocation',
2219
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2220
	'Selected'
2221
));
2222

    
2223
$group->add(new Form_Input(
2224
	'adv_dhcp6_id_assoc_statement_address_id',
2225
	null,
2226
	'text',
2227
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2228
))->sethelp('id-assoc na ID');
2229

    
2230
$group->add(new Form_IpAddress(
2231
	'adv_dhcp6_id_assoc_statement_address',
2232
	null,
2233
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2234
	'V6'
2235
))->sethelp('IPv6 address');
2236

    
2237
$group->add(new Form_Input(
2238
	'adv_dhcp6_id_assoc_statement_address_pltime',
2239
	null,
2240
	'text',
2241
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2242
))->sethelp('pltime');
2243

    
2244
$group->add(new Form_Input(
2245
	'adv_dhcp6_id_assoc_statement_address_vltime',
2246
	null,
2247
	'text',
2248
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2249
))->sethelp('vltime');
2250

    
2251
$section->add($group);
2252

    
2253
// Prefix delegation
2254
$group = new Form_Group('');
2255

    
2256
$group->add(new Form_Checkbox(
2257
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2258
	null,
2259
	'Prefix Delegation ',
2260
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2261
	'Selected'
2262
));
2263

    
2264
$group->add(new Form_Input(
2265
	'adv_dhcp6_id_assoc_statement_prefix_id',
2266
	null,
2267
	'text',
2268
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2269
))->sethelp('id-assoc pd ID');
2270

    
2271
$group->add(new Form_IpAddress(
2272
	'adv_dhcp6_id_assoc_statement_prefix',
2273
	null,
2274
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2275
	'V6'
2276
))->sethelp('IPv6 prefix');
2277

    
2278
$group->add(new Form_Input(
2279
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2280
	null,
2281
	'text',
2282
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2283
))->sethelp('pltime');
2284

    
2285
$group->add(new Form_Input(
2286
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2287
	null,
2288
	'text',
2289
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2290
))->sethelp('vltime');
2291

    
2292
$section->add($group);
2293

    
2294
$group = new Form_Group('Prefix interface statement');
2295

    
2296
$group->add(new Form_Input(
2297
	'adv_dhcp6_prefix_interface_statement_sla_id',
2298
	null,
2299
	'text',
2300
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2301
))->sethelp('Prefix Interface sla-id');
2302

    
2303
$group->add(new Form_Input(
2304
	'adv_dhcp6_prefix_interface_statement_sla_len',
2305
	null,
2306
	'text',
2307
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2308
))->sethelp('sla-len');
2309

    
2310
$section->add($group);
2311

    
2312
$group = new Form_Group('Authentication statement');
2313

    
2314
$group->add(new Form_Input(
2315
	'adv_dhcp6_authentication_statement_authname',
2316
	null,
2317
	'text',
2318
	$pconfig['adv_dhcp6_authentication_statement_authname']
2319
))->sethelp('Authname');
2320

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

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

    
2335
$group->add(new Form_Input(
2336
	'adv_dhcp6_authentication_statement_rdm',
2337
	null,
2338
	'text',
2339
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2340
))->sethelp('RDM');
2341

    
2342
$section->add($group);
2343

    
2344
$group = new Form_Group('Keyinfo statement');
2345

    
2346
$group->add(new Form_Input(
2347
	'adv_dhcp6_key_info_statement_keyname',
2348
	null,
2349
	'text',
2350
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2351
))->sethelp('Keyname');
2352

    
2353
$group->add(new Form_Input(
2354
	'adv_dhcp6_key_info_statement_realm',
2355
	null,
2356
	'text',
2357
	$pconfig['adv_dhcp6_key_info_statement_realm']
2358
))->sethelp('Realm');
2359

    
2360
$section->add($group);
2361

    
2362
$group = new Form_Group('');
2363

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

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

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

    
2385
$group->setHelp('<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhcp6c.conf&sektion=5&apropos=0&manpath=FreeBSD+10.1-RELEASE+and+Ports#Interface_statement">' . 'See here more information' . '</a>');
2386

    
2387
$section->add($group);
2388

    
2389
$form->add($section);
2390

    
2391
$section = new Form_Section('6RD Configuration');
2392
$section->addClass('_6rd');
2393

    
2394
$section->addInput(new Form_Input(
2395
	'prefix-6rd',
2396
	'6RD Prefix',
2397
	'text',
2398
	$pconfig['prefix-6rd']
2399
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2400

    
2401
$section->addInput(new Form_Input(
2402
	'gateway-6rd',
2403
	'6RD Border relay',
2404
	'text',
2405
	$pconfig['gateway-6rd']
2406
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2407

    
2408
$section->addInput(new Form_Select(
2409
	'prefix-6rd-v4plen',
2410
	'6RD IPv4 Prefix length',
2411
	$pconfig['prefix-6rd-v4plen'],
2412
	array_combine(range(0, 32), range(0, 32))
2413
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2414

    
2415
$form->add($section);
2416

    
2417
// Track IPv6 ointerface section
2418
$section = new Form_Section('Track IPv6 Interface');
2419
$section->addClass('track6');
2420

    
2421
function build_ipv6interface_list() {
2422
	global $config, $section;
2423

    
2424
	$list = array('' => '');
2425

    
2426
	$interfaces = get_configured_interface_with_descr(false, true);
2427
	$dynv6ifs = array();
2428

    
2429
	foreach ($interfaces as $iface => $ifacename) {
2430
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2431
			case "6to4":
2432
			case "6rd":
2433
			case "dhcp6":
2434
				$dynv6ifs[$iface] = array(
2435
					'name' => $ifacename,
2436
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2437
				);
2438
				break;
2439
			default:
2440
				continue;
2441
		}
2442
	}
2443

    
2444
	foreach ($dynv6ifs as $iface => $ifacedata) {
2445
		$list[$iface] = $ifacedata['name'];
2446

    
2447
		$section->addInput(new Form_Input(
2448
			'ipv6-num-prefix-ids-' . $iface,
2449
			null,
2450
			'hidden',
2451
			$ifacedata['ipv6_num_prefix_ids']
2452
		));
2453
	}
2454

    
2455
	return($list);
2456
}
2457

    
2458
$section->addInput(new Form_Select(
2459
	'track6-interface',
2460
	'IPv6 Interface',
2461
	$pconfig['track6-interface'],
2462
	build_ipv6interface_list()
2463
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2464

    
2465
if ($pconfig['track6-prefix-id'] == "") {
2466
	$pconfig['track6-prefix-id'] = 0;
2467
}
2468

    
2469
$section->addInput(new Form_Input(
2470
	'track6-prefix-id--hex',
2471
	'IPv6 Prefix ID',
2472
	'text',
2473
	sprintf("%x", $pconfig['track6-prefix-id'])
2474
))->setHelp('<span id="track6-prefix-id-range"></span>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.');
2475

    
2476
$section->addInput(new Form_Input(
2477
	'track6-prefix-id-max',
2478
	null,
2479
	'hidden',
2480
	0
2481
));
2482

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

    
2485
/// PPP section
2486

    
2487
$section = new Form_Section('PPP Configuration');
2488
$section->addClass('ppp');
2489

    
2490
$section->addInput(new Form_Select(
2491
	'country',
2492
	'Country',
2493
	$pconfig['country'],
2494
	[]
2495
));
2496

    
2497
$section->addInput(new Form_Select(
2498
	'provider_list',
2499
	'Provider',
2500
	$pconfig['provider_list'],
2501
	[]
2502
));
2503

    
2504
$section->addInput(new Form_Select(
2505
	'providerplan',
2506
	'Plan',
2507
	$pconfig['providerplan'],
2508
	[]
2509
))->setHelp('Select to fill in service provider data.');
2510

    
2511
$section->addInput(new Form_Input(
2512
	'ppp_username',
2513
	'Username',
2514
	'text',
2515
	$pconfig['ppp_username']
2516
));
2517

    
2518
$section->addPassword(new Form_Input(
2519
	'ppp_password',
2520
	'Password',
2521
	'password',
2522
	$pconfig['ppp_password']
2523
));
2524

    
2525
$section->addInput(new Form_Input(
2526
	'phone',
2527
	'Phone number',
2528
	'text',
2529
	$pconfig['phone']
2530
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2531

    
2532
$section->addInput(new Form_Input(
2533
	'apn',
2534
	'Access Point Name',
2535
	'text',
2536
	$pconfig['apn']
2537
));
2538

    
2539

    
2540
function build_port_list() {
2541
	$list = array("" => "None");
2542

    
2543
	$portlist = glob("/dev/cua*");
2544
	$modems	  = glob("/dev/modem*");
2545
	$portlist = array_merge($portlist, $modems);
2546

    
2547
	foreach ($portlist as $port) {
2548
		if (preg_match("/\.(lock|init)$/", $port)) {
2549
			continue;
2550
		}
2551

    
2552
	$list[trim($port)] = $port;
2553
	}
2554

    
2555
	return($list);
2556
}
2557

    
2558
$section->addInput(new Form_Select(
2559
	'port',
2560
	"Modem port",
2561
	$pconfig['port'],
2562
	build_port_list()
2563
));
2564

    
2565
$section->addInput(new Form_Button(
2566
	'btnadvppp',
2567
	'Advanced PPP',
2568
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2569
	'fa-cog'
2570
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2571

    
2572
$form->add($section);
2573

    
2574
// PPPoE configuration
2575
$section = new Form_Section('PPPoE Configuration');
2576
$section->addClass('pppoe');
2577

    
2578
$section->addInput(new Form_Input(
2579
	'pppoe_username',
2580
	'Username',
2581
	'text',
2582
	$pconfig['pppoe_username']
2583
));
2584

    
2585
$section->addPassword(new Form_Input(
2586
	'pppoe_password',
2587
	'Password',
2588
	'password',
2589
	$pconfig['pppoe_password']
2590
));
2591

    
2592
$section->addInput(new Form_Input(
2593
	'provider',
2594
	'Service name',
2595
	'text',
2596
	$pconfig['provider']
2597
))->setHelp('This field can usually be left empty.');
2598

    
2599
$section->addInput(new Form_Checkbox(
2600
	'pppoe_dialondemand',
2601
	'Dial on demand',
2602
	'Enable Dial-On-Demand mode ',
2603
	$pconfig['pppoe_dialondemand'],
2604
	'enable'
2605
));
2606

    
2607
$section->addInput(new Form_Input(
2608
	'pppoe_idletimeout',
2609
	'Idle timeout',
2610
	'number',
2611
	$pconfig['pppoe_idletimeout'],
2612
	['min' => 0]
2613
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2614
			'An idle timeout of zero disables this feature.');
2615

    
2616
$section->addInput(new Form_Select(
2617
	'pppoe-reset-type',
2618
	'Periodic reset',
2619
	$pconfig['pppoe-reset-type'],
2620
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2621
))->setHelp('Select a reset timing type.');
2622

    
2623
$group = new Form_Group('Custom reset');
2624
$group->addClass('pppoecustom');
2625

    
2626
$group->add(new Form_Input(
2627
	'pppoe_resethour',
2628
	null,
2629
	'number',
2630
	$pconfig['pppoe_resethour'],
2631
	['min' => 0, 'max' => 23]
2632
))->setHelp('Hour (0-23)');
2633

    
2634
$group->add(new Form_Input(
2635
	'pppoe_resetminute',
2636
	null,
2637
	'number',
2638
	$pconfig['pppoe_resetminute'],
2639
	['min' => 0, 'max' => 59]
2640
))->setHelp('Minutes (0-59)');
2641

    
2642
$group->add(new Form_Input(
2643
	'pppoe_resetdate',
2644
	null,
2645
	'text',
2646
	$pconfig['pppoe_resetdate']
2647
))->setHelp('Specific date (mm/dd/yyyy)');
2648

    
2649
$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');
2650

    
2651
$section->add($group);
2652

    
2653
$group = new Form_MultiCheckboxGroup('cron based reset');
2654
$group->addClass('pppoepreset');
2655

    
2656
$group->add(new Form_MultiCheckbox(
2657
	'pppoe_pr_preset_val',
2658
	null,
2659
	'Reset at each month ("0 0 1 * *")',
2660
	$pconfig['pppoe_monthly'],
2661
	'monthly'
2662
))->displayAsRadio();
2663

    
2664
$group->add(new Form_MultiCheckbox(
2665
	'pppoe_pr_preset_val',
2666
	null,
2667
	'Reset at each week ("0 0 * * 0")',
2668
	$pconfig['pppoe_weekly'],
2669
	'weekly'
2670
))->displayAsRadio();
2671

    
2672
$group->add(new Form_MultiCheckbox(
2673
	'pppoe_pr_preset_val',
2674
	null,
2675
	'Reset at each day ("0 0 * * *")',
2676
	$pconfig['pppoe_daily'],
2677
	'daily'
2678
))->displayAsRadio();
2679

    
2680
$group->add(new Form_MultiCheckbox(
2681
	'pppoe_pr_preset_val',
2682
	null,
2683
	'Reset at each hour ("0 * * * *")',
2684
	$pconfig['pppoe_hourly'],
2685
	'hourly'
2686
))->displayAsRadio();
2687

    
2688
$section->add($group);
2689

    
2690
$section->addInput(new Form_Button(
2691
	'btnadvppp',
2692
	'Advanced and MLPPP',
2693
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2694
	'fa-cog'
2695
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2696

    
2697
$form->add($section);
2698

    
2699
// PPTP & L2TP Configuration section
2700
$section = new Form_Section('PPTP/L2TP Configuration');
2701
$section->addClass('pptp');
2702

    
2703
$section->addInput(new Form_Input(
2704
	'pptp_username',
2705
	'Username',
2706
	'text',
2707
	$pconfig['pptp_username']
2708
));
2709

    
2710
$section->addPassword(new Form_Input(
2711
	'pptp_password',
2712
	'Password',
2713
	'password',
2714
	$pconfig['pptp_password']
2715
));
2716

    
2717
$section->addInput(new Form_IpAddress(
2718
	'pptp_local0',
2719
	'Local IP address',
2720
	$pconfig['pptp_localip'][0],
2721
	'V4'
2722
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2723

    
2724
$section->addInput(new Form_IpAddress(
2725
	'pptp_remote0',
2726
	'Remote IP address',
2727
	$pconfig['pptp_remote'][0],
2728
	'HOSTV4'
2729
));
2730

    
2731
$section->addInput(new Form_Checkbox(
2732
	'pptp_dialondemand',
2733
	'Dial on demand',
2734
	'Enable Dial-On-Demand mode ',
2735
	$pconfig['pptp_dialondemand'],
2736
	'enable'
2737
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2738
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2739

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

    
2749
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2750
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2751
} else {
2752
	$mlppp_text = "";
2753
}
2754

    
2755
$section->addInput(new Form_Button(
2756
	'btnadvppp',
2757
	'Advanced and MLPPP',
2758
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2759
	'fa-cog'
2760
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp($mlppp_text . 'Click for additional PPTP and L2TP configuration options. Save first if changes have been made.');
2761

    
2762
$form->add($section);
2763

    
2764
// Wireless interface
2765
if (isset($wancfg['wireless'])) {
2766

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

    
2769
	$section->addInput(new Form_Checkbox(
2770
		'persistcommonwireless',
2771
		'Persist common settings',
2772
		'Preserve common wireless configuration through interface deletions and reassignments.',
2773
		$pconfig['persistcommonwireless'],
2774
		'yes'
2775
	));
2776

    
2777
	$mode_list = ['auto' => 'Auto'];
2778

    
2779
	if (is_array($wl_modes)) {
2780
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2781
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2782
		}
2783
	}
2784

    
2785
	if (count($mode_list) == 1) {
2786
		$mode_list[''] = '';
2787
	}
2788

    
2789
	$section->addInput(new Form_Select(
2790
		'standard',
2791
		'Standard',
2792
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2793
		$mode_list
2794
	));
2795

    
2796
	if (isset($wl_modes['11g'])) {
2797
		$section->addInput(new Form_Select(
2798
			'protmode',
2799
			'802.11g OFDM Protection Mode',
2800
			$pconfig['protmode'],
2801
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2802
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2803
	} else {
2804
		$section->addInput(new Form_Input(
2805
			'protmode',
2806
			null,
2807
			'hidden',
2808
			'off'
2809
		));
2810
	}
2811

    
2812
	$mode_list = ['0' => gettext('Auto')];
2813

    
2814
	if (is_array($wl_modes)) {
2815
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2816
			if ($wl_standard == "11g") {
2817
				$wl_standard = "11b/g";
2818
			} else if ($wl_standard == "11ng") {
2819
				$wl_standard = "11b/g/n";
2820
			} else if ($wl_standard == "11na") {
2821
				$wl_standard = "11a/n";
2822
			}
2823

    
2824
			foreach ($wl_channels as $wl_channel) {
2825
				if (isset($wl_chaninfo[$wl_channel])) {
2826
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2827
				} else {
2828
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2829
				}
2830
			}
2831
		}
2832
	}
2833

    
2834
	$section->addInput(new Form_Select(
2835
		'channel',
2836
		'Channel',
2837
		$pconfig['channel'],
2838
		$mode_list
2839
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2840
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2841

    
2842
	if (ANTENNAS) {
2843
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2844
			$group = new Form_Group('Antenna Settings');
2845

    
2846
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2847
				$group->add(new Form_Select(
2848
					'diversity',
2849
					null,
2850
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2851
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2852
				))->setHelp('Diversity');
2853
			}
2854

    
2855
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2856
				$group->add(new Form_Select(
2857
					'txantenna',
2858
					null,
2859
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2860
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2861
				))->setHelp('Transmit antenna');
2862
			}
2863

    
2864
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2865
				$group->add(new Form_Select(
2866
					'rxantenna',
2867
					null,
2868
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2869
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2870
				))->setHelp('Receive antenna');
2871
			}
2872

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

    
2875
			$section->add($group);
2876
		}
2877
	}
2878

    
2879
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2880
			$section->addInput(new Form_Input(
2881
				'distance',
2882
				'Distance setting (meters)',
2883
				'test',
2884
				$pconfig['distance']
2885
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2886
	}
2887

    
2888
	$form->add($section);
2889

    
2890
	// Regulatory settings
2891
	$section = new Form_Section('Regulatory Settings');
2892

    
2893
	$domain_list = array("" => 'Default');
2894

    
2895
	if (is_array($wl_regdomains)) {
2896
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2897
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2898
		}
2899
	}
2900

    
2901
	$section->addInput(new Form_Select(
2902
		'regdomain',
2903
		'Regulatory domain',
2904
		$pconfig['regdomain'],
2905
		$domain_list
2906
	))->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');
2907

    
2908
	$country_list = array('' => 'Default');
2909

    
2910
	if (is_array($wl_countries)) {
2911
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2912
			$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']);
2913
		}
2914
	}
2915

    
2916
	$section->addInput(new Form_Select(
2917
		'regcountry',
2918
		'Country',
2919
		$pconfig['regcountry'],
2920
		$country_list
2921
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2922

    
2923
	$section->addInput(new Form_Select(
2924
		'reglocation',
2925
		'Location',
2926
		$pconfig['reglocation'],
2927
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
2928
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2929
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2930
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2931
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2932
				'These settings may not be able to add additional channels that are not already supported.');
2933

    
2934
	$form->add($section);
2935

    
2936
	$section = new Form_Section('Network-Specific Wireless Configuration');
2937

    
2938
	$section->addInput(new Form_Select(
2939
		'mode',
2940
		'Mode',
2941
		$pconfig['mode'],
2942
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2943
	));
2944

    
2945
	$section->addInput(new Form_Input(
2946
		'ssid',
2947
		'SSID',
2948
		'text',
2949
		$pconfig['ssid']
2950
	));
2951

    
2952
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2953
		$section->addInput(new Form_Select(
2954
			'puremode',
2955
			'Minimum wireless standard',
2956
			$pconfig['puremode'],
2957
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2958
		))->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)');
2959
	} elseif (isset($wl_modes['11g'])) {
2960
		$section->addInput(new Form_Checkbox(
2961
			'puremode',
2962
			'802.11g only',
2963
			null,
2964
			$pconfig['puremode'],
2965
			'11g'
2966
		))->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)');
2967
	}
2968

    
2969
	$section->addInput(new Form_Checkbox(
2970
		'apbridge_enable',
2971
		'Allow intra-BSS communication',
2972
		'Allow packets to pass between wireless clients directly when operating as an access point',
2973
		$pconfig['apbridge_enable'],
2974
		'yes'
2975
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2976

    
2977
	$section->addInput(new Form_Checkbox(
2978
		'wme_enable',
2979
		'Enable WME',
2980
		'Force the card to use WME (wireless QoS)',
2981
		$pconfig['wme_enable'],
2982
		'yes'
2983
	));
2984

    
2985
	$section->addInput(new Form_Checkbox(
2986
		'hidessid_enable',
2987
		'Hide SSID',
2988
		'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.)',
2989
		$pconfig['hidessid_enable'],
2990
		'yes'
2991
	));
2992

    
2993
	$form->add($section);
2994

    
2995
	// WPA Section
2996
	$section = new Form_Section('WPA');
2997

    
2998
	$section->addInput(new Form_Checkbox(
2999
		'wpa_enable',
3000
		'Enable',
3001
		'Enable WPA',
3002
		$pconfig['wpa_enable'],
3003
		'yes'
3004
	));
3005

    
3006
	$section->addInput(new Form_Input(
3007
		'passphrase',
3008
		'WPA Pre-Shared Key',
3009
		'text',
3010
		$pconfig['passphrase']
3011
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3012

    
3013
	$section->addInput(new Form_Select(
3014
		'wpa_mode',
3015
		'WPA mode',
3016
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3017
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3018
	));
3019

    
3020
	$section->addInput(new Form_Select(
3021
		'wpa_key_mgmt',
3022
		'WPA Key Management Mode',
3023
		$pconfig['wpa_key_mgmt'],
3024
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3025
	));
3026

    
3027
	$section->addInput(new Form_Select(
3028
		'wpa_pairwise',
3029
		'WPA Pairwise',
3030
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3031
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3032
	));
3033

    
3034
	$section->addInput(new Form_Input(
3035
		'wpa_group_rekey',
3036
		'Group Key Rotation',
3037
		'number',
3038
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3039
		['min' => '1', 'max' => 9999]
3040
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3041

    
3042
	$section->addInput(new Form_Input(
3043
		'wpa_gmk_rekey',
3044
		'Group Master Key Regeneration',
3045
		'number',
3046
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3047
		['min' => '1', 'max' => 9999]
3048
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3049

    
3050
	$section->addInput(new Form_Checkbox(
3051
		'wpa_strict_rekey',
3052
		'Strict Key Regeneration',
3053
		'Force the AP to rekey whenever a client disassociates',
3054
		$pconfig['wpa_strict_rekey'],
3055
		'yes'
3056
	));
3057

    
3058
	$form->add($section);
3059

    
3060
	$section = new Form_Section('802.1x RADIUS Options');
3061

    
3062
	$section->addInput(new Form_Checkbox(
3063
		'ieee8021x',
3064
		'IEEE802.1X',
3065
		'Enable 802.1X authentication',
3066
		$pconfig['ieee8021x'],
3067
		'yes'
3068
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3069

    
3070
	$group = new Form_Group('Primary 802.1X server');
3071

    
3072
	$group->add(new Form_IpAddress(
3073
		'auth_server_addr',
3074
		'IP Address',
3075
		$pconfig['auth_server_addr']
3076
	))->setHelp('IP address of the RADIUS server');
3077

    
3078
	$group->add(new Form_Input(
3079
		'auth_server_port',
3080
		'Port',
3081
		'number',
3082
		$pconfig['auth_server_port']
3083
	))->setHelp('Server auth port. Default is 1812');
3084

    
3085
	$group->add(new Form_Input(
3086
		'auth_server_shared_secret',
3087
		'Shared Secret',
3088
		'text',
3089
		$pconfig['auth_server_shared_secret']
3090
	))->setHelp('RADIUS Shared secret for this firewall');
3091

    
3092
	$section->add($group);
3093

    
3094
	$group = new Form_Group('Secondary 802.1X server');
3095

    
3096
	$group->add(new Form_IpAddress(
3097
		'auth_server_addr2',
3098
		'IP Address',
3099
		$pconfig['auth_server_addr2']
3100
	))->setHelp('IP address of the RADIUS server');
3101

    
3102
	$group->add(new Form_Input(
3103
		'auth_server_port2',
3104
		'Port',
3105
		'number',
3106
		$pconfig['auth_server_port2']
3107
	))->setHelp('Server auth port. Default is 1812');
3108

    
3109
	$group->add(new Form_Input(
3110
		'auth_server_shared_secret2',
3111
		'Shared Secret',
3112
		'text',
3113
		$pconfig['auth_server_shared_secret2']
3114
	))->setHelp('RADIUS Shared secret for this firewall');
3115

    
3116
	$section->add($group);
3117

    
3118
	$section->addInput(new Form_Checkbox(
3119
		'rsn_preauth',
3120
		'Authentication Roaming Preauth',
3121
		null,
3122
		$pconfig['rsn_preauth'],
3123
		'yes'
3124
	));
3125

    
3126
	$form->add($section);
3127
}
3128

    
3129
$section = new Form_Section('Reserved Networks');
3130

    
3131
$section->addInput(new Form_Checkbox(
3132
	'blockpriv',
3133
	'Block private networks and loopback addresses',
3134
	'',
3135
	$pconfig['blockpriv'],
3136
	'yes'
3137
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3138
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3139
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3140

    
3141
$section->addInput(new Form_Checkbox(
3142
	'blockbogons',
3143
	'Block bogon networks',
3144
	'',
3145
	$pconfig['blockbogons'],
3146
	'yes'
3147
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3148
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.' . '<br />' .
3149
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.');
3150

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

    
3153
$form->addGlobal(new Form_Input(
3154
	'if',
3155
	null,
3156
	'hidden',
3157
	$if
3158
));
3159

    
3160
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3161
	$form->addGlobal(new Form_Input(
3162
		'ppp_port',
3163
		null,
3164
		'hidden',
3165
		$pconfig['port']
3166
	));
3167
}
3168

    
3169
$form->addGlobal(new Form_Input(
3170
	'ptpid',
3171
	null,
3172
	'hidden',
3173
	$pconfig['ptpid']
3174
));
3175

    
3176

    
3177
// Add new gateway modal pop-up
3178
$modal = new Modal('New Gateway', 'newgateway', 'large');
3179

    
3180
$modal->addInput(new Form_Checkbox(
3181
	'defaultgw',
3182
	'Default',
3183
	'Default gateway',
3184
	($if == "wan" || $if == "WAN")
3185
));
3186

    
3187
$modal->addInput(new Form_Input(
3188
	'name',
3189
	'Gateway name',
3190
	'text',
3191
	$wancfg['descr'] . "GW"
3192
));
3193

    
3194
$modal->addInput(new Form_IpAddress(
3195
	'gatewayip',
3196
	'Gateway IPv4',
3197
	null,
3198
	'V4'
3199
));
3200

    
3201
$modal->addInput(new Form_Input(
3202
	'gatewaydescr',
3203
	'Description',
3204
	'text'
3205
));
3206

    
3207
$btnaddgw = new Form_Button(
3208
	'add',
3209
	'Add',
3210
	null,
3211
	'fa-plus'
3212
);
3213

    
3214
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3215

    
3216
$btncnxgw = new Form_Button(
3217
	'cnx',
3218
	'Cancel',
3219
	null,
3220
	'fa-undo'
3221
);
3222

    
3223
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3224

    
3225
$modal->addInput(new Form_StaticText(
3226
	null,
3227
	$btnaddgw . $btncnxgw
3228
));
3229

    
3230
$form->add($modal);
3231

    
3232
print($form);
3233
?>
3234

    
3235
<script type="text/javascript">
3236
//<![CDATA[
3237
events.push(function() {
3238
	function updateType(t) {
3239

    
3240
		switch (t) {
3241
			case "none": {
3242
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3243
				break;
3244
			}
3245
			case "staticv4": {
3246
				$('.dhcpadvanced, .none, .dhcp').hide();
3247
				$('.pppoe, .pptp, .ppp').hide();
3248
				break;
3249
			}
3250
			case "dhcp": {
3251
				$('.dhcpadvanced, .none').hide();
3252
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3253
										//			about the staticv4 class
3254
				$('.pppoe, .pptp, .ppp').hide();
3255
				break;
3256
			}
3257
			case "ppp": {
3258
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3259
				country_list();
3260
				break;
3261
			}
3262
			case "pppoe": {
3263
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3264
				break;
3265
			}
3266
			case "l2tp":
3267
			case "pptp": {
3268
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3269
				$('.pptp').show();
3270
				break;
3271
			}
3272
		}
3273

    
3274
		if (t != "l2tp" && t != "pptp") {
3275
			$('.'+t).show();
3276
		}
3277
	}
3278

    
3279
	function updateTypeSix(t) {
3280
		if (!isNaN(t[0])) {
3281
			t = '_' + t;
3282
		}
3283

    
3284
		switch (t) {
3285
			case "none": {
3286
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3287
				break;
3288
			}
3289
			case "staticv6": {
3290
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3291
				break;
3292
			}
3293
			case "slaac": {
3294
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3295
				break;
3296
			}
3297
			case "dhcp6": {
3298
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3299
				break;
3300
			}
3301
			case "_6rd": {
3302
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3303
				break;
3304
			}
3305
			case "_6to4": {
3306
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3307
				break;
3308
			}
3309
			case "track6": {
3310
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3311
				update_track6_prefix();
3312
				break;
3313
			}
3314
		}
3315

    
3316
		if (t != "l2tp" && t != "pptp") {
3317
			$('.'+t).show();
3318
		}
3319
	}
3320

    
3321
	function show_reset_settings(reset_type) {
3322
		if (reset_type == 'preset') {
3323
			$('.pppoepreset').show();
3324
			$('.pppoecustom').hide();
3325
		} else if (reset_type == 'custom') {
3326
			$('.pppoecustom').show();
3327
			$('.pppoepreset').hide();
3328
		} else {
3329
			$('.pppoecustom').hide();
3330
			$('.pppoepreset').hide();
3331
		}
3332
	}
3333

    
3334
	function update_track6_prefix() {
3335
		var iface = $("#track6-interface").val();
3336
		if (iface == null) {
3337
			return;
3338
		}
3339

    
3340
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3341
		if (track6_prefix_ids == null) {
3342
			return;
3343
		}
3344

    
3345
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3346
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3347
	}
3348

    
3349
	// Create the new gateway from the data entered in the modal pop-up
3350
	function hide_add_gatewaysave() {
3351
		var iface = $('#if').val();
3352
		name = $('#name').val();
3353
		var descr = $('#gatewaydescr').val();
3354
		gatewayip = $('#gatewayip').val();
3355

    
3356
		var defaultgw = '';
3357
		if ($('#defaultgw').is(':checked')) {
3358
			defaultgw = '&defaultgw=on';
3359
		}
3360

    
3361
		var url = "system_gateways_edit.php";
3362
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3363
		$.ajax(
3364
			url,
3365
			{
3366
				type: 'post',
3367
				data: pars,
3368
				error: report_failure,
3369
				complete: save_callback
3370
			});
3371
		}
3372

    
3373
	function save_callback(response) {
3374
		if (response) {
3375
			var gwtext = escape(name) + " - " + gatewayip;
3376
			addOption($('#gateway'), gwtext, name);
3377
		} else {
3378
			report_failure();
3379
		}
3380

    
3381
		$("#newgateway").modal('hide');
3382
	}
3383

    
3384
	function report_failure(request, textStatus, errorThrown) {
3385
		contenttype = ";"+request.getResponseHeader("Content-Type")+";";
3386
		if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
3387
			alert(request.responseText);
3388
		} else {
3389
			alert("The IPv4 gateway could not be created.");
3390
		}
3391

    
3392
		$("#newgateway").modal('hide');
3393
	}
3394

    
3395
	function addOption(selectbox, text, value) {
3396
		var optn = document.createElement("OPTION");
3397
		optn.text = text;
3398
		optn.value = value;
3399
		selectbox.append(optn);
3400
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3401
	}
3402

    
3403
	function hide_add_gatewaysave_v6() {
3404

    
3405
		var iface = $('#if').val();
3406
		name = $('#name6').val();
3407
		var descr = $('#gatewaydescr6').val();
3408
		gatewayip = $('#gatewayip6').val();
3409
		var defaultgw = '';
3410
		if ($('#defaultgw6').is(':checked')) {
3411
			defaultgw = '&defaultgw=on';
3412
		}
3413
		var url_v6 = "system_gateways_edit.php";
3414
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3415
		$.ajax(
3416
			url_v6,
3417
			{
3418
				type: 'post',
3419
				data: pars_v6,
3420
				error: report_failure_v6,
3421
				success: save_callback_v6
3422
			});
3423
	}
3424

    
3425

    
3426
	function addOption_v6(selectbox, text, value) {
3427
		var optn = document.createElement("OPTION");
3428
		optn.text = text;
3429
		optn.value = value;
3430
		selectbox.append(optn);
3431
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3432
	}
3433

    
3434
	function report_failure_v6(request, textStatus, errorThrown) {
3435
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3436
			alert(request.responseText);
3437
		} else {
3438
			alert("The IPv6 gateway could not be created.");
3439
		}
3440

    
3441
		$("#newgateway6").modal('hide');
3442
	}
3443

    
3444
	function save_callback_v6(response_v6) {
3445
		if (response_v6) {
3446

    
3447
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3448
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3449
		} else {
3450
			report_failure_v6();
3451
		}
3452

    
3453
		$("#newgateway6").modal('hide');
3454
	}
3455

    
3456
	function country_list() {
3457
		$('#country').children().remove();
3458
		$('#provider_list').children().remove();
3459
		$('#providerplan').children().remove();
3460
		$.ajax("getserviceproviders.php",{
3461
			success: function(response) {
3462

    
3463
				var responseTextArr = response.split("\n");
3464
				responseTextArr.sort();
3465

    
3466
				responseTextArr.forEach( function(value) {
3467
					country = value.split(":");
3468
					$('#country').append($('<option>', {
3469
						value: country[1],
3470
						text : country[0]
3471
					}));
3472
				});
3473
			}
3474
		});
3475
	}
3476

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

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

    
3505
				$('#providerplan').append($('<option>', {
3506
					value: '',
3507
					text : ''
3508
				}));
3509

    
3510
				responseTextArr.forEach( function(value) {
3511
					if (value != "") {
3512
						providerplan = value.split(":");
3513

    
3514
						$('#providerplan').append($('<option>', {
3515
							value: providerplan[1],
3516
							text : providerplan[0] + " - " + providerplan[1]
3517
						}));
3518
					}
3519
				});
3520
			}
3521
		});
3522
	}
3523

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

    
3548
	function show_dhcp6adv() {
3549
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3550
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3551

    
3552
		hideCheckbox('dhcp6usev4iface', ovr);
3553
		hideCheckbox('dhcp6prefixonly', ovr);
3554
		hideInput('dhcp6-ia-pd-len', ovr);
3555
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3556
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3557

    
3558
		hideClass('dhcp6advanced', !adv || ovr);
3559
	}
3560

    
3561
	function setDHCPoptions() {
3562
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3563
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3564

    
3565
		if (ovr) {
3566
			hideInput('dhcphostname', true);
3567
			hideIpAddress('alias-address', true);
3568
			hideInput('dhcprejectfrom', true);
3569
			hideInput('adv_dhcp_config_file_override_path', false);
3570
			hideClass('dhcpadvanced', true);
3571
		} else {
3572
			hideInput('dhcphostname', false);
3573
			hideIpAddress('alias-address', false);
3574
			hideInput('dhcprejectfrom', false);
3575
			hideInput('adv_dhcp_config_file_override_path', true);
3576
			hideClass('dhcpadvanced', !adv);
3577
		}
3578
	}
3579

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

    
3590
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3591
		$('#adv_dhcp_pt_timeout').val(timeout);
3592
		$('#adv_dhcp_pt_retry').val(retry);
3593
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3594
		$('#adv_dhcp_pt_reboot').val(reboot);
3595
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3596
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3597
	}
3598

    
3599
	// ---------- On initial page load ------------------------------------------------------------
3600

    
3601
	updateType($('#type').val());
3602
	updateTypeSix($('#type6').val());
3603
	show_reset_settings($('#pppoe-reset-type').val());
3604
	hideClass('dhcp6advanced', true);
3605
	hideClass('dhcpadvanced', true);
3606
	show_dhcp6adv();
3607
	setDHCPoptions()
3608

    
3609
	// Set preset buttons on page load
3610
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3611
	if (sv == "") {
3612
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3613
	} else {
3614
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3615
	}
3616

    
3617
	// Set preset from value
3618
	setPresets(sv);
3619

    
3620
	// ---------- Click checkbox handlers ---------------------------------------------------------
3621

    
3622
	$('#type').on('change', function() {
3623
		updateType(this.value);
3624
	});
3625

    
3626
	$('#type6').on('change', function() {
3627
		updateTypeSix(this.value);
3628
	});
3629

    
3630
	$('#track6-interface').on('change', function() {
3631
		update_track6_prefix();
3632
	});
3633

    
3634
	$('#pppoe-reset-type').on('change', function() {
3635
		show_reset_settings(this.value);
3636
	});
3637

    
3638
	$("#add").click(function() {
3639
		hide_add_gatewaysave();
3640
	});
3641

    
3642
	$("#cnx").click(function() {
3643
		$("#newgateway").modal('hide');
3644
	});
3645

    
3646
	$("#add6").click(function() {
3647
		hide_add_gatewaysave_v6();
3648
	});
3649

    
3650
	$("#cnx6").click(function() {
3651
		$("#newgateway6").modal('hide');
3652
	});
3653

    
3654
	$('#country').on('change', function() {
3655
		providers_list();
3656
	});
3657

    
3658
	$('#provider_list').on('change', function() {
3659
		providerplan_list();
3660
	});
3661

    
3662
	$('#providerplan').on('change', function() {
3663
		prefill_provider();
3664
	});
3665

    
3666
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3667
		setDHCPoptions();
3668
	});
3669

    
3670
	$('#adv_dhcp6_config_advanced').click(function () {
3671
		show_dhcp6adv();
3672
	});
3673

    
3674
	$('#adv_dhcp6_config_file_override').click(function () {
3675
		show_dhcp6adv();
3676
	});
3677

    
3678
	// On click . .
3679
	$('[name=adv_dhcp_pt_values]').click(function () {
3680
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3681
	});
3682

    
3683
	$('#pppoe_resetdate').datepicker();
3684

    
3685
});
3686
//]]>
3687
</script>
3688

    
3689
<?php include("foot.inc");
(67-67/225)