Project

General

Profile

Download (123 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
$changes_applied = false;
411

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

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

    
448
		/* sync filter configuration */
449
		setup_gateways_monitor();
450

    
451
		clear_subsystem_dirty('interfaces');
452

    
453
		$retval |= filter_configure();
454

    
455
		enable_rrd_graphing();
456

    
457
		$changes_applied = true;
458

    
459
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
460
			clear_subsystem_dirty('staticroutes');
461
		}
462
	}
463
	@unlink("{$g['tmp_path']}/.interfaces.apply");
464
} else if ($_POST) {
465

    
466
	unset($input_errors);
467
	$pconfig = $_POST;
468

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

    
475
	/* filter out spaces from descriptions */
476
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
477

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

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

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

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

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

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

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

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

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

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

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

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

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

    
816
		unset($min_mtu, $max_mtu);
817

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

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

    
840
				if ($parent_realhwif != $wancfg['if']) {
841
					continue;
842
				}
843

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

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

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

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

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

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

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

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

    
1005
		unset($wancfg['adv_dhcp_pt_timeout']);
1006
		unset($wancfg['adv_dhcp_pt_retry']);
1007
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1008
		unset($wancfg['adv_dhcp_pt_reboot']);
1009
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1010
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1011

    
1012
		unset($wancfg['adv_dhcp_pt_values']);
1013

    
1014
		unset($wancfg['adv_dhcp_send_options']);
1015
		unset($wancfg['adv_dhcp_request_options']);
1016
		unset($wancfg['adv_dhcp_required_options']);
1017
		unset($wancfg['adv_dhcp_option_modifiers']);
1018

    
1019
		unset($wancfg['adv_dhcp_config_advanced']);
1020
		unset($wancfg['adv_dhcp_config_file_override']);
1021
		unset($wancfg['adv_dhcp_config_file_override_path']);
1022

    
1023
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1024
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1025
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1026
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1027

    
1028
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1029
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1030
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1031
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1032
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1033

    
1034
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1035
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1036
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1037
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1038
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1039

    
1040
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1041
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1042

    
1043
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1044
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1045
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1046
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1047

    
1048
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1049
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1050
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1051
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1052
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1053

    
1054
		unset($wancfg['adv_dhcp6_config_advanced']);
1055
		unset($wancfg['adv_dhcp6_config_file_override']);
1056
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1057

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

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

    
1090
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1091
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1092

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

    
1109
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1110
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1111
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1112
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1113
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1114
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1115

    
1116
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1117

    
1118
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1119
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1120
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1121
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1122

    
1123
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1124
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1125
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1126

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

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

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

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

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

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

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

    
1299
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1300
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1301
				}
1302
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1303
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1304
				}
1305

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

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

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

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

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

    
1416
		write_config();
1417

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

    
1427
		mark_subsystem_dirty('interfaces');
1428

    
1429
		/* regenerate cron settings/crontab file */
1430
		configure_cron();
1431

    
1432
		header("Location: interfaces.php?if={$if}");
1433
		exit;
1434
	}
1435

    
1436
} // end if ($_POST)
1437

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

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

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

    
1587
	interface_sync_wireless_clones($wancfg, true);
1588
}
1589

    
1590
function check_wireless_mode() {
1591
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1592

    
1593
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1594
		return;
1595
	}
1596

    
1597
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1598
		$clone_count = 1;
1599
	} else {
1600
		$clone_count = 0;
1601
	}
1602

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

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

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

    
1638
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1639
$shortcut_section = "interfaces";
1640

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

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

    
1649
function build_mediaopts_list() {
1650
	global $mediaopts_list;
1651

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

    
1656
	foreach ($mediaopts_list as $mediaopt) {
1657
		$list[$mediaopt] = $mediaopt;
1658
	}
1659

    
1660
	return($list);
1661
}
1662

    
1663
function build_gateway_list() {
1664
	global $a_gateways, $if;
1665

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

    
1673
	return($list);
1674
}
1675

    
1676
function build_gatewayv6_list() {
1677
	global $a_gateways, $if;
1678

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

    
1686
	return($list);
1687
}
1688

    
1689
include("head.inc");
1690

    
1691
if ($input_errors) {
1692
	print_input_errors($input_errors);
1693
}
1694

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

    
1701
if ($changes_applied) {
1702
	print_apply_result_box($retval);
1703
}
1704

    
1705
$form = new Form();
1706

    
1707
$section = new Form_Section('General Configuration');
1708

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

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

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

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

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

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

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

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

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

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

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

    
1788
$form->add($section);
1789

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

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

    
1800
$group = new Form_Group('IPv4 Upstream gateway');
1801

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

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

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

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

    
1822
$form->add($section);
1823

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

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

    
1834
$group = new Form_Group('IPv6 Upstream gateway');
1835

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

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

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

    
1853
$section->add($group);
1854
$form->add($section);
1855

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

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

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

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

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

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

    
1893
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1894

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

    
1902
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1903

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

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

    
1911
// ==== DHCP client configuration =============================
1912

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

    
1916
$group = new Form_Group('Options');
1917

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

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

    
1932
$section->add($group);
1933

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

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

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

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

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

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

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

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

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

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

    
2002
$section->add($group);
2003

    
2004
$group = new Form_Group('Presets');
2005
$group->addClass('dhcpadvanced');
2006

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

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

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

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

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

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

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

    
2054
$form->add($section);
2055

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

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

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

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

    
2084
$section->addInput(new Form_Input(
2085
	'adv_dhcp_option_modifiers',
2086
	'Option modifiers',
2087
	'text',
2088
	$pconfig['adv_dhcp_option_modifiers']
2089
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2090
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2091
			'<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>');
2092

    
2093
$form->add($section);
2094

    
2095
// DHCP6 client config
2096

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

    
2100
$group = new Form_Group('Options');
2101

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

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

    
2116
$section->add($group);
2117

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

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

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

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

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

    
2174
$form->add($section);
2175

    
2176
// DHCP6 client config - Advanced
2177

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

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

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

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

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

    
2215
$group = new Form_Group('Identity Association Statement');
2216

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

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

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

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

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

    
2253
$section->add($group);
2254

    
2255
// Prefix delegation
2256
$group = new Form_Group('');
2257

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

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

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

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

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

    
2294
$section->add($group);
2295

    
2296
$group = new Form_Group('Prefix interface statement');
2297

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

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

    
2312
$section->add($group);
2313

    
2314
$group = new Form_Group('Authentication statement');
2315

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

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

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

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

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

    
2346
$group = new Form_Group('Keyinfo statement');
2347

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

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

    
2362
$section->add($group);
2363

    
2364
$group = new Form_Group('');
2365

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

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

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

    
2387
$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>');
2388

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

    
2391
$form->add($section);
2392

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

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

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

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

    
2417
$form->add($section);
2418

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

    
2423
function build_ipv6interface_list() {
2424
	global $config, $section;
2425

    
2426
	$list = array('' => '');
2427

    
2428
	$interfaces = get_configured_interface_with_descr(false, true);
2429
	$dynv6ifs = array();
2430

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

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

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

    
2457
	return($list);
2458
}
2459

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

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

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

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

    
2485
$form->add($section);
2486

    
2487
/// PPP section
2488

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

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

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

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

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

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

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

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

    
2541

    
2542
function build_port_list() {
2543
	$list = array("" => "None");
2544

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

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

    
2554
	$list[trim($port)] = $port;
2555
	}
2556

    
2557
	return($list);
2558
}
2559

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

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

    
2574
$form->add($section);
2575

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

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

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

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

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

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

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

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

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

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

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

    
2651
$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');
2652

    
2653
$section->add($group);
2654

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

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

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

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

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

    
2690
$section->add($group);
2691

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

    
2699
$form->add($section);
2700

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

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

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

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

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

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

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

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

    
2757
$section->addInput(new Form_Button(
2758
	'btnadvppp',
2759
	'Advanced and MLPPP',
2760
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2761
	'fa-cog'
2762
))->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.');
2763

    
2764
$form->add($section);
2765

    
2766
// Wireless interface
2767
if (isset($wancfg['wireless'])) {
2768

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

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

    
2779
	$mode_list = ['auto' => 'Auto'];
2780

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

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

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

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

    
2814
	$mode_list = ['0' => gettext('Auto')];
2815

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

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

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

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

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

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

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

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

    
2877
			$section->add($group);
2878
		}
2879
	}
2880

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

    
2890
	$form->add($section);
2891

    
2892
	// Regulatory settings
2893
	$section = new Form_Section('Regulatory Settings');
2894

    
2895
	$domain_list = array("" => 'Default');
2896

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

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

    
2910
	$country_list = array('' => 'Default');
2911

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

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

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

    
2936
	$form->add($section);
2937

    
2938
	$section = new Form_Section('Network-Specific Wireless Configuration');
2939

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

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

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

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

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

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

    
2995
	$form->add($section);
2996

    
2997
	// WPA Section
2998
	$section = new Form_Section('WPA');
2999

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

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

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

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

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

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

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

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

    
3060
	$form->add($section);
3061

    
3062
	$section = new Form_Section('802.1x RADIUS Options');
3063

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

    
3072
	$group = new Form_Group('Primary 802.1X server');
3073

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

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

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

    
3094
	$section->add($group);
3095

    
3096
	$group = new Form_Group('Secondary 802.1X server');
3097

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

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

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

    
3118
	$section->add($group);
3119

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

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

    
3131
$section = new Form_Section('Reserved Networks');
3132

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

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

    
3153
$form->add($section);
3154

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

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

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

    
3178

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

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

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

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

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

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

    
3216
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3217

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

    
3225
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3226

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

    
3232
$form->add($modal);
3233

    
3234
print($form);
3235
?>
3236

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3383
		$("#newgateway").modal('hide');
3384
	}
3385

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

    
3394
		$("#newgateway").modal('hide');
3395
	}
3396

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

    
3405
	function hide_add_gatewaysave_v6() {
3406

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

    
3427

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

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

    
3443
		$("#newgateway6").modal('hide');
3444
	}
3445

    
3446
	function save_callback_v6(response_v6) {
3447
		if (response_v6) {
3448

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

    
3455
		$("#newgateway6").modal('hide');
3456
	}
3457

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

    
3465
				var responseTextArr = response.split("\n");
3466
				responseTextArr.sort();
3467

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

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

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

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

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

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

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

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

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

    
3560
		hideClass('dhcp6advanced', !adv || ovr);
3561
	}
3562

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

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

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

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

    
3601
	function setDialOnDemandItems() {
3602
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3603
	}
3604

    
3605
	// ---------- On initial page load ------------------------------------------------------------
3606

    
3607
	updateType($('#type').val());
3608
	updateTypeSix($('#type6').val());
3609
	show_reset_settings($('#pppoe-reset-type').val());
3610
	hideClass('dhcp6advanced', true);
3611
	hideClass('dhcpadvanced', true);
3612
	show_dhcp6adv();
3613
	setDHCPoptions();
3614
	setDialOnDemandItems();
3615

    
3616
	// Set preset buttons on page load
3617
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3618
	if (sv == "") {
3619
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3620
	} else {
3621
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3622
	}
3623

    
3624
	// Set preset from value
3625
	setPresets(sv);
3626

    
3627
	// ---------- Click checkbox handlers ---------------------------------------------------------
3628

    
3629
	$('#type').on('change', function() {
3630
		updateType(this.value);
3631
	});
3632

    
3633
	$('#type6').on('change', function() {
3634
		updateTypeSix(this.value);
3635
	});
3636

    
3637
	$('#track6-interface').on('change', function() {
3638
		update_track6_prefix();
3639
	});
3640

    
3641
	$('#pppoe-reset-type').on('change', function() {
3642
		show_reset_settings(this.value);
3643
	});
3644

    
3645
	$("#add").click(function() {
3646
		hide_add_gatewaysave();
3647
	});
3648

    
3649
	$("#cnx").click(function() {
3650
		$("#newgateway").modal('hide');
3651
	});
3652

    
3653
	$("#add6").click(function() {
3654
		hide_add_gatewaysave_v6();
3655
	});
3656

    
3657
	$("#cnx6").click(function() {
3658
		$("#newgateway6").modal('hide');
3659
	});
3660

    
3661
	$('#country').on('change', function() {
3662
		providers_list();
3663
	});
3664

    
3665
	$('#provider_list').on('change', function() {
3666
		providerplan_list();
3667
	});
3668

    
3669
	$('#providerplan').on('change', function() {
3670
		prefill_provider();
3671
	});
3672

    
3673
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3674
		setDHCPoptions();
3675
	});
3676

    
3677
	$('#adv_dhcp6_config_advanced').click(function () {
3678
		show_dhcp6adv();
3679
	});
3680

    
3681
	$('#adv_dhcp6_config_file_override').click(function () {
3682
		show_dhcp6adv();
3683
	});
3684

    
3685
	// On click . .
3686
	$('#pppoe_dialondemand').click(function () {
3687
		setDialOnDemandItems();
3688
	});
3689

    
3690
	$('[name=adv_dhcp_pt_values]').click(function () {
3691
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3692
	});
3693

    
3694
	$('#pppoe_resetdate').datepicker();
3695

    
3696
});
3697
//]]>
3698
</script>
3699

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