Project

General

Profile

Download (123 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c) 2006 Daniel S. Haischt
8
 *
9
 *	Some or all of this file is based on the m0n0wall project which is
10
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14
 *
15
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *	  this list of conditions and the following disclaimer.
17
 *
18
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *	  notice, this list of conditions and the following disclaimer in
20
 *	  the documentation and/or other materials provided with the
21
 *	  distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *	  must display the following acknowledgment:
25
 *	  "This product includes software developed by the pfSense Project
26
 *	   for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *	   endorse or promote products derived from this software without
30
 *	   prior written permission. For written permission, please contact
31
 *	   coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *	  nor may "pfSense" appear in their names without prior written
35
 *	  permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *	  acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59

    
60
##|+PRIV
61
##|*IDENT=page-interfaces
62
##|*NAME=Interfaces: WAN
63
##|*DESCR=Allow access to the 'Interfaces' page.
64
##|*MATCH=interfaces.php*
65
##|-PRIV
66

    
67
require_once("guiconfig.inc");
68
require_once("ipsec.inc");
69
require_once("functions.inc");
70
require_once("captiveportal.inc");
71
require_once("filter.inc");
72
require_once("shaper.inc");
73
require_once("rrd.inc");
74
require_once("vpn.inc");
75
require_once("xmlparse_attr.inc");
76

    
77
define("ANTENNAS", false);
78

    
79
if (isset($_POST['referer'])) {
80
	$referer = $_POST['referer'];
81
} else {
82
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
83
}
84

    
85
// Get configured interface list
86
$ifdescrs = get_configured_interface_with_descr(false, true);
87

    
88
$if = "wan";
89
if ($_REQUEST['if']) {
90
	$if = $_REQUEST['if'];
91
}
92

    
93
if (empty($ifdescrs[$if])) {
94
	header("Location: interfaces.php");
95
	exit;
96
}
97

    
98
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
99
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
100
define("CRON_DAILY_PATTERN", "0 0 * * *");
101
define("CRON_HOURLY_PATTERN", "0 * * * *");
102

    
103
if (!is_array($pconfig)) {
104
	$pconfig = array();
105
}
106

    
107
if (!is_array($config['ppps'])) {
108
	$config['ppps'] = array();
109
}
110
if (!is_array($config['ppps']['ppp'])) {
111
	$config['ppps']['ppp'] = array();
112
}
113
$a_ppps = &$config['ppps']['ppp'];
114

    
115
function remove_bad_chars($string) {
116
	return preg_replace('/[^a-z_0-9]/i', '', $string);
117
}
118

    
119
if (!is_array($config['gateways']['gateway_item'])) {
120
	$config['gateways']['gateway_item'] = array();
121
}
122

    
123
$a_gateways = &$config['gateways']['gateway_item'];
124

    
125
$wancfg = &$config['interfaces'][$if];
126
$old_wancfg = $wancfg;
127
$old_wancfg['realif'] = get_real_interface($if);
128
$old_ppps = $a_ppps;
129

    
130
// Populate page descr if it does not exist.
131
if ($if == "wan" && !$wancfg['descr']) {
132
	$wancfg['descr'] = "WAN";
133
} else if ($if == "lan" && !$wancfg['descr']) {
134
	$wancfg['descr'] = "LAN";
135
}
136

    
137
/* NOTE: The code here is used to set the $pppid for the curious */
138
foreach ($a_ppps as $pppid => $ppp) {
139
	if ($wancfg['if'] == $ppp['if']) {
140
		break;
141
	}
142
}
143

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

    
146
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
147
	$pconfig['pppid'] = $pppid;
148
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
149
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
150
	if ($a_ppps[$pppid]['type'] == "ppp") {
151
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
152
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
153

    
154
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
155
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
156
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
157
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
158
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
159
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
160
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
161
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
162

    
163
		/* ================================================ */
164
		/* = force a connection reset at a specific time? = */
165
		/* ================================================ */
166

    
167
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
168
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
169
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
170
			if ($itemhash) {
171
				$cronitem = $itemhash['ITEM'];
172
			}
173
			if (isset($cronitem)) {
174
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
175
			} else {
176
				$resetTime = NULL;
177
			}
178
			//log_error("ResetTime:".$resetTime);
179
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
180
				if ($cronitem) {
181
					$pconfig['pppoe_pr_custom'] = true;
182
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
183
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
184
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
185
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
186
					}
187
				}
188
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
189
				$pconfig['pppoe_pr_preset'] = true;
190
				switch ($resetTime) {
191
					case CRON_MONTHLY_PATTERN:
192
						$pconfig['pppoe_monthly'] = true;
193
						break;
194
					case CRON_WEEKLY_PATTERN:
195
						$pconfig['pppoe_weekly'] = true;
196
						break;
197
					case CRON_DAILY_PATTERN:
198
						$pconfig['pppoe_daily'] = true;
199
						break;
200
					case CRON_HOURLY_PATTERN:
201
						$pconfig['pppoe_hourly'] = true;
202
						break;
203
				}
204
			}
205
		} // End force pppoe reset at specific time
206
		// End if type == pppoe
207
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
208
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
209
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
210
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
211
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
212
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
213
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
214
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
215
	}
216
} else {
217
	$pconfig['ptpid'] = interfaces_ptpid_next();
218
	$pppid = count($a_ppps);
219
}
220

    
221
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
222
$pconfig['alias-address'] = $wancfg['alias-address'];
223
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
224
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
225

    
226
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
227
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
228
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
229
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
230
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
231
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
232

    
233
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
234

    
235
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
236
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
237
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
238
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
239

    
240
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
241
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
242
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
243

    
244
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
245
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
246
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
247
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
248

    
249
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
250
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
251
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
252
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
253
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
254

    
255
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
256
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
257
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
258
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
259
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
260

    
261
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
262
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
263

    
264
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
265
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
266
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
267
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
268

    
269
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
270
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
271
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
272
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
273
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
274

    
275
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
276
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
277
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
278

    
279
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
280
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
281
$pconfig['enable'] = isset($wancfg['enable']);
282

    
283
switch ($wancfg['ipaddr']) {
284
	case "dhcp":
285
		$pconfig['type'] = "dhcp";
286
		break;
287
	case "pppoe":
288
	case "pptp":
289
	case "l2tp":
290
	case "ppp":
291
		$pconfig['type'] = $wancfg['ipaddr'];
292
		break;
293
	default:
294
		if (is_ipaddrv4($wancfg['ipaddr'])) {
295
			$pconfig['type'] = "staticv4";
296
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
297
			$pconfig['subnet'] = $wancfg['subnet'];
298
			$pconfig['gateway'] = $wancfg['gateway'];
299
		} else {
300
			$pconfig['type'] = "none";
301
		}
302
		break;
303
}
304

    
305
switch ($wancfg['ipaddrv6']) {
306
	case "slaac":
307
		$pconfig['type6'] = "slaac";
308
		break;
309
	case "dhcp6":
310
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
311
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
312
			$wancfg['dhcp6-ia-pd-len'] = "none";
313
		}
314
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
315
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
316
		$pconfig['type6'] = "dhcp6";
317
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
318
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
319
		$pconfig['dhcp6debug'] = isset($wancfg['dhcp6debug']);
320
		break;
321
	case "6to4":
322
		$pconfig['type6'] = "6to4";
323
		break;
324
	case "track6":
325
		$pconfig['type6'] = "track6";
326
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
327
		if ($wancfg['track6-prefix-id'] == "") {
328
			$pconfig['track6-prefix-id'] = 0;
329
		} else {
330
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
331
		}
332
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
333
		break;
334
	case "6rd":
335
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
336
		if ($wancfg['prefix-6rd-v4plen'] == "") {
337
			$wancfg['prefix-6rd-v4plen'] = "0";
338
		}
339
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
340
		$pconfig['type6'] = "6rd";
341
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
342
		break;
343
	default:
344
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
345
			$pconfig['type6'] = "staticv6";
346
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
347
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
348
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
349
		} else {
350
			$pconfig['type6'] = "none";
351
		}
352
		break;
353
}
354

    
355
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
356
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
357
$pconfig['spoofmac'] = $wancfg['spoofmac'];
358
$pconfig['mtu'] = $wancfg['mtu'];
359
$pconfig['mss'] = $wancfg['mss'];
360

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

    
437
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
438

    
439
}
440

    
441
if ($_POST['apply']) {
442
	unset($input_errors);
443
	if (!is_subsystem_dirty('interfaces')) {
444
		$input_errors[] = gettext("The settings have already been applied!");
445
	} else {
446
		unlink_if_exists("{$g['tmp_path']}/config.cache");
447
		clear_subsystem_dirty('interfaces');
448

    
449
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
450
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
451
			foreach ($toapplylist as $ifapply => $ifcfgo) {
452
				if (isset($config['interfaces'][$ifapply]['enable'])) {
453
					interface_bring_down($ifapply, false, $ifcfgo);
454
					interface_configure($ifapply, true);
455
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
456
						/* call interface_track6_configure with linkup true so
457
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
458
						   just call interface_configure with linkup true as
459
						   that skips bridge membership addition. 
460
						*/
461
						$wancfg = $config['interfaces'][$ifapply];
462
						interface_track6_configure($ifapply, $wancfg, true);
463
					}
464
				} else {
465
					interface_bring_down($ifapply, true, $ifcfgo);
466
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
467
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
468
						services_dhcpd_configure();
469
					}
470
				}
471
			}
472
		}
473
		/* restart snmp so that it binds to correct address */
474
		services_snmpd_configure();
475

    
476
		/* sync filter configuration */
477
		setup_gateways_monitor();
478

    
479
		clear_subsystem_dirty('interfaces');
480

    
481
		filter_configure();
482

    
483
		enable_rrd_graphing();
484

    
485
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
486
			clear_subsystem_dirty('staticroutes');
487
		}
488
	}
489
	@unlink("{$g['tmp_path']}/.interfaces.apply");
490
	header("Location: interfaces.php?if={$if}");
491
	exit;
492
} else if ($_POST) {
493

    
494
	unset($input_errors);
495
	$pconfig = $_POST;
496

    
497
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
498
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
499
	} else {
500
		$pconfig['track6-prefix-id'] = 0;
501
	}
502
	conf_mount_rw();
503

    
504
	/* filter out spaces from descriptions */
505
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
506

    
507
	/* okay first of all, cause we are just hiding the PPPoE HTML
508
	 * fields related to PPPoE resets, we are going to unset $_POST
509
	 * vars, if the reset feature should not be used. Otherwise the
510
	 * data validation procedure below, may trigger a false error
511
	 * message.
512
	 */
513
	if (empty($_POST['pppoe-reset-type'])) {
514
		unset($_POST['pppoe_pr_type']);
515
		unset($_POST['pppoe_resethour']);
516
		unset($_POST['pppoe_resetminute']);
517
		unset($_POST['pppoe_resetdate']);
518
		unset($_POST['pppoe_pr_preset_val']);
519
	}
520
	/* description unique? */
521
	foreach ($ifdescrs as $ifent => $ifdescr) {
522
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
523
			$input_errors[] = gettext("An interface with the specified description already exists.");
524
			break;
525
		}
526
	}
527

    
528
	/* Is the description already used as an alias name? */
529
	if (is_array($config['aliases']['alias'])) {
530
		foreach ($config['aliases']['alias'] as $alias) {
531
			if ($alias['name'] == $_POST['descr']) {
532
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
533
			}
534
		}
535
	}
536

    
537
	/* Is the description already used as an interface group name? */
538
	if (is_array($config['ifgroups']['ifgroupentry'])) {
539
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
540
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
541
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
542
			}
543
		}
544
	}
545

    
546
	if (is_numeric($_POST['descr'])) {
547
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
548
	}
549
	/* input validation */
550
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
551
		$input_errors[] = gettext("The DHCP Server is active on this interface and it can be used only with a static IP configuration. Please disable the DHCP Server service on this interface first, then change the interface configuration.");
552
	}
553
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
554
		$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.");
555
	}
556

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

    
664
			if (empty($_POST['track6-interface'])) {
665
				$input_errors[] = gettext("A valid interface to track must be selected.");
666
			}
667

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

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

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

    
716
			foreach ($staticroutes as $route_subnet) {
717
				list($network, $subnet) = explode("/", $route_subnet);
718
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
719
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
720
					break;
721
				}
722
				unset($network, $subnet);
723
			}
724
		}
725
	}
726
	if ($_POST['ipaddrv6']) {
727
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
728
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
729
		} else {
730
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
731
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
732
			}
733
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
734
			if (count($where_ipaddr_configured)) {
735
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
736
				foreach ($where_ipaddr_configured as $subnet_conflict) {
737
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
738
				}
739
				$input_errors[] = $subnet_conflict_text;
740
			}
741

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

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

    
831
		unset($min_mtu, $max_mtu);
832

    
833
		if (stristr($wancfg['if'], "_vlan")) {
834
			$realhwif_array = get_parent_interface($wancfg['if']);
835
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
836
			$parent_realhwif = $realhwif_array[0];
837
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
838
			$mtu = 0;
839
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
840
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
841
			if ($mtu == 0)
842
				$mtu = get_interface_mtu($parent_realhwif);
843
			if ($_POST['mtu'] > $mtu)
844
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
845
		} else {
846
			foreach ($config['interfaces'] as $idx => $ifdata) {
847
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
848
					continue;
849
				}
850

    
851
				$realhwif_array = get_parent_interface($ifdata['if']);
852
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
853
				$parent_realhwif = $realhwif_array[0];
854

    
855
				if ($parent_realhwif != $wancfg['if']) {
856
					continue;
857
				}
858

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

    
946
		if ($_POST['passphrase']) {
947
			$passlen = strlen($_POST['passphrase']);
948
			if ($passlen < 8 || $passlen > 63) {
949
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
950
			}
951
		}
952

    
953
		if ($_POST['wpa_enable'] == "yes") {
954
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
955
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
956
			}
957
		}
958
	}
959

    
960
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
961
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
962
	}
963

    
964
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
965
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
966
	}
967

    
968
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
969
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
970
	}
971

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

    
979
		if ($wancfg['ipaddr'] != $_POST['type']) {
980
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
981
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
982
				unset($a_ppps[$pppid]);
983
			} else if ($wancfg['ipaddr'] == "dhcp") {
984
				kill_dhclient_process($wancfg['if']);
985
			}
986
			if ($wancfg['ipaddrv6'] == "dhcp6") {
987
				$pid = find_dhcp6c_process($wancfg['if']);
988
				if ($pid) {
989
					posix_kill($pid, SIGTERM);
990
				}
991
			}
992
		}
993
		$ppp = array();
994
		if ($wancfg['ipaddr'] != "ppp") {
995
			unset($wancfg['ipaddr']);
996
		}
997
		if ($wancfg['ipaddrv6'] != "ppp") {
998
			unset($wancfg['ipaddrv6']);
999
		}
1000
		unset($wancfg['subnet']);
1001
		unset($wancfg['gateway']);
1002
		unset($wancfg['subnetv6']);
1003
		unset($wancfg['gatewayv6']);
1004
		unset($wancfg['dhcphostname']);
1005
		unset($wancfg['dhcprejectfrom']);
1006
		unset($wancfg['dhcp6-duid']);
1007
		unset($wancfg['dhcp6-ia-pd-len']);
1008
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1009
		unset($wancfg['dhcp6prefixonly']);
1010
		unset($wancfg['dhcp6usev4iface']);
1011
		unset($wancfg['dhcp6debug']);
1012
		unset($wancfg['track6-interface']);
1013
		unset($wancfg['track6-prefix-id']);
1014
		unset($wancfg['prefix-6rd']);
1015
		unset($wancfg['prefix-6rd-v4plen']);
1016
		unset($wancfg['gateway-6rd']);
1017

    
1018
		unset($wancfg['adv_dhcp_pt_timeout']);
1019
		unset($wancfg['adv_dhcp_pt_retry']);
1020
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1021
		unset($wancfg['adv_dhcp_pt_reboot']);
1022
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1023
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1024

    
1025
		unset($wancfg['adv_dhcp_pt_values']);
1026

    
1027
		unset($wancfg['adv_dhcp_send_options']);
1028
		unset($wancfg['adv_dhcp_request_options']);
1029
		unset($wancfg['adv_dhcp_required_options']);
1030
		unset($wancfg['adv_dhcp_option_modifiers']);
1031

    
1032
		unset($wancfg['adv_dhcp_config_advanced']);
1033
		unset($wancfg['adv_dhcp_config_file_override']);
1034
		unset($wancfg['adv_dhcp_config_file_override_path']);
1035

    
1036
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1037
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1038
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1039
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1040

    
1041
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1042
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1043
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1044
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1045
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1046

    
1047
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1048
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1049
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1050
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1051
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1052

    
1053
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1054
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1055

    
1056
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1057
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1058
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1059
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1060

    
1061
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1062
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1063
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1064
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1065
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1066

    
1067
		unset($wancfg['adv_dhcp6_config_advanced']);
1068
		unset($wancfg['adv_dhcp6_config_file_override']);
1069
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1070

    
1071
		unset($wancfg['pppoe_password']);
1072
		unset($wancfg['pptp_username']);
1073
		unset($wancfg['pptp_password']);
1074
		unset($wancfg['provider']);
1075
		unset($wancfg['ondemand']);
1076
		unset($wancfg['timeout']);
1077
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1078
			unset($wancfg['pppoe']['pppoe-reset-type']);
1079
		}
1080
		unset($wancfg['local']);
1081

    
1082
		unset($wancfg['remote']);
1083
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1084
			if ($wancfg['ipaddr'] != 'ppp') {
1085
				unset($a_ppps[$pppid]['apn']);
1086
				unset($a_ppps[$pppid]['phone']);
1087
				unset($a_ppps[$pppid]['provider']);
1088
				unset($a_ppps[$pppid]['ondemand']);
1089
			}
1090
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1091
				unset($a_ppps[$pppid]['localip']);
1092
				unset($a_ppps[$pppid]['subnet']);
1093
				unset($a_ppps[$pppid]['gateway']);
1094
			}
1095
			if ($wancfg['ipaddr'] != 'pppoe') {
1096
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1097
			}
1098
			if ($wancfg['type'] != $_POST['type']) {
1099
				unset($a_ppps[$pppid]['idletimeout']);
1100
			}
1101
		}
1102

    
1103
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1104
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1105

    
1106
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1107
		switch ($_POST['type']) {
1108
			case "staticv4":
1109
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1110
				$wancfg['subnet'] = $_POST['subnet'];
1111
				if ($_POST['gateway'] != "none") {
1112
					$wancfg['gateway'] = $_POST['gateway'];
1113
				}
1114
				break;
1115
			case "dhcp":
1116
				$wancfg['ipaddr'] = "dhcp";
1117
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1118
				$wancfg['alias-address'] = $_POST['alias-address'];
1119
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1120
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1121

    
1122
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1123
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1124
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1125
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1126
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1127
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1128

    
1129
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1130

    
1131
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1132
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1133
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1134
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1135

    
1136
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1137
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1138
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1139

    
1140
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1141
				if ($gateway_item) {
1142
					$a_gateways[] = $gateway_item;
1143
				}
1144
				break;
1145
			case "ppp":
1146
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1147
				$a_ppps[$pppid]['type'] = $_POST['type'];
1148
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1149
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1150
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1151
				if ($_POST['ppp_password'] != DMYPWD) {
1152
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1153
				}
1154
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1155
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1156
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1157
				$wancfg['ipaddr'] = $_POST['type'];
1158
				break;
1159

    
1160
			case "pppoe":
1161
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1162
				$a_ppps[$pppid]['type'] = $_POST['type'];
1163
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1164
				if (isset($_POST['ppp_port'])) {
1165
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1166
				} else {
1167
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1168
				}
1169
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1170
				if ($_POST['pppoe_password'] != DMYPWD) {
1171
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1172
				}
1173
				if (!empty($_POST['provider'])) {
1174
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1175
				} else {
1176
					$a_ppps[$pppid]['provider'] = true;
1177
				}
1178
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1179
				if (!empty($_POST['pppoe_idletimeout'])) {
1180
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1181
				} else {
1182
					unset($a_ppps[$pppid]['idletimeout']);
1183
				}
1184

    
1185
				if (!empty($_POST['pppoe-reset-type'])) {
1186
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1187
				} else {
1188
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1189
				}
1190
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1191
				$wancfg['ipaddr'] = $_POST['type'];
1192
				if ($gateway_item) {
1193
					$a_gateways[] = $gateway_item;
1194
				}
1195

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

    
1261
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1262
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1263
				}
1264
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1265
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1266
				}
1267
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1268
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1269
				}
1270
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1271
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1272
				}
1273

    
1274
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1275
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1276
				}
1277
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1278
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1279
				}
1280
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1281
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1282
				}
1283
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1284
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1285
				}
1286
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1287
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1288
				}
1289

    
1290
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1291
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1292
				}
1293
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1294
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1295
				}
1296
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1297
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1298
				}
1299
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1300
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1301
				}
1302
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1303
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1304
				}
1305

    
1306
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1307
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1308
				}
1309
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1310
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1311
				}
1312

    
1313
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1314
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1317
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1320
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1323
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1324
				}
1325

    
1326
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1327
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1328
				}
1329
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1330
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1333
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1334
				}
1335
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1336
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1339
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1340
				}
1341

    
1342
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1343
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1344
				}
1345
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1346
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1347
				}
1348
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1349
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1350
				}
1351

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

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

    
1423
		conf_mount_ro();
1424
		write_config();
1425

    
1426
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1427
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1428
		} else {
1429
			$toapplylist = array();
1430
		}
1431
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1432
		$toapplylist[$if]['ppps'] = $old_ppps;
1433
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1434

    
1435
		mark_subsystem_dirty('interfaces');
1436

    
1437
		/* regenerate cron settings/crontab file */
1438
		configure_cron();
1439

    
1440
		header("Location: interfaces.php?if={$if}");
1441
		exit;
1442
	}
1443

    
1444
} // end if ($_POST)
1445

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

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

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

    
1595
	interface_sync_wireless_clones($wancfg, true);
1596
}
1597

    
1598
function check_wireless_mode() {
1599
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1600

    
1601
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1602
		return;
1603
	}
1604

    
1605
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1606
		$clone_count = 1;
1607
	} else {
1608
		$clone_count = 0;
1609
	}
1610

    
1611
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1612
		foreach ($config['wireless']['clone'] as $clone) {
1613
			if ($clone['if'] == $wlanbaseif) {
1614
				$clone_count++;
1615
			}
1616
		}
1617
	}
1618

    
1619
	if ($clone_count > 1) {
1620
		$old_wireless_mode = $wancfg['wireless']['mode'];
1621
		$wancfg['wireless']['mode'] = $_POST['mode'];
1622
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1623
			$input_errors[] = sprintf(gettext("Unable to change mode to %s.	 May already have the maximum number of wireless clones supported in this mode."), $wlan_modes[$wancfg['wireless']['mode']]);
1624
		} else {
1625
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1626
		}
1627
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1628
	}
1629
}
1630

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

    
1646
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1647
$shortcut_section = "interfaces";
1648

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

    
1652
// Get the MAC address
1653
$ip = $_SERVER['REMOTE_ADDR'];
1654
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1655
$mymac = str_replace("\n", "", $mymac);
1656

    
1657
function build_mediaopts_list() {
1658
	global $mediaopts_list;
1659

    
1660
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1661
			 " " =>	 gettext("------- Media Supported by this interface -------")
1662
			];
1663

    
1664
	foreach ($mediaopts_list as $mediaopt) {
1665
		$list[$mediaopt] = $mediaopt;
1666
	}
1667

    
1668
	return($list);
1669
}
1670

    
1671
function build_gateway_list() {
1672
	global $a_gateways, $if;
1673

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

    
1681
	return($list);
1682
}
1683

    
1684
function build_gatewayv6_list() {
1685
	global $a_gateways, $if;
1686

    
1687
	$list = array("none" => gettext("None"));
1688
	foreach ($a_gateways as $gateway) {
1689
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1690
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1691
		}
1692
	}
1693

    
1694
	return($list);
1695
}
1696

    
1697
include("head.inc");
1698

    
1699
if ($input_errors) {
1700
	print_input_errors($input_errors);
1701
}
1702

    
1703
if (is_subsystem_dirty('interfaces')) {
1704
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1705
					gettext("The changes must be applied in order for them to take effect.") . "<br />" .
1706
					gettext("Don't forget to adjust the DHCP Server range if needed after applying."));
1707
}
1708

    
1709
if ($savemsg) {
1710
	print_info_box($savemsg, 'success');
1711
}
1712

    
1713

    
1714
$form = new Form();
1715

    
1716
$section = new Form_Section('General Configuration');
1717

    
1718
$section->addInput(new Form_Checkbox(
1719
	'enable',
1720
	'Enable',
1721
	'Enable interface',
1722
	$pconfig['enable'],
1723
	'yes'
1724
));
1725

    
1726
$section->addInput(new Form_Input(
1727
	'descr',
1728
	'Description',
1729
	'text',
1730
	$pconfig['descr']
1731
))->setHelp('Enter a description (name) for the interface here.');
1732

    
1733
$section->addInput(new Form_Select(
1734
	'type',
1735
	'IPv4 Configuration Type',
1736
	$pconfig['type'],
1737
	$types4
1738
));
1739

    
1740
$section->addInput(new Form_Select(
1741
	'type6',
1742
	'IPv6 Configuration Type',
1743
	$pconfig['type6'],
1744
	$types6
1745
));
1746

    
1747
$macaddress = new Form_Input(
1748
	'spoofmac',
1749
	'MAC Address',
1750
	'text',
1751
	$pconfig['spoofmac'],
1752
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1753
);
1754

    
1755
$btnmymac = new Form_Button(
1756
	'btnmymac',
1757
	'Copy My MAC',
1758
	null,
1759
	'fa-clone'
1760
	);
1761

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

    
1764
$group = new Form_Group('MAC controls');
1765
$group->add($macaddress);
1766
// $group->add($btnmymac);
1767
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1768
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1769
$section->add($group);
1770

    
1771
$section->addInput(new Form_Input(
1772
	'mtu',
1773
	'MTU',
1774
	'number',
1775
	$pconfig['mtu']
1776
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1777
			'This is typically 1500 bytes but can vary in some circumstances.');
1778

    
1779
$section->addInput(new Form_Input(
1780
	'mss',
1781
	'MSS',
1782
	'number',
1783
	$pconfig['mss']
1784
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1785
			'header size) will be in effect.');
1786

    
1787
if (count($mediaopts_list) > 0) {
1788
	$section->addInput(new Form_Select(
1789
		'mediaopt',
1790
		'Speed and Duplex',
1791
		rtrim($mediaopt_from_config),
1792
		build_mediaopts_list()
1793
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1794
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1795
}
1796

    
1797
$form->add($section);
1798

    
1799
$section = new Form_Section('Static IPv4 Configuration');
1800
$section->addClass('staticv4');
1801

    
1802
$section->addInput(new Form_IpAddress(
1803
	'ipaddr',
1804
	'IPv4 Address',
1805
	$pconfig['ipaddr']
1806
))->addMask('subnet', $pconfig['subnet'], 32);
1807

    
1808
$group = new Form_Group('IPv4 Upstream gateway');
1809

    
1810
$group->add(new Form_Select(
1811
	'gateway',
1812
	'IPv4 Upstream Gateway',
1813
	$pconfig['gateway'],
1814
	build_gateway_list()
1815
));
1816

    
1817
$group->add(new Form_Button(
1818
	'addgw',
1819
	'Add a new gateway',
1820
	null,
1821
	'fa-plus'
1822
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1823

    
1824
$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 />' .
1825
				'On local LANs the upstream gateway should be "none".' .
1826
				gettext('Gateways can be managed by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>');
1827

    
1828
$section->add($group);
1829

    
1830
$form->add($section);
1831

    
1832
$section = new Form_Section('Static IPv6 Configuration');
1833
$section->addClass('staticv6');
1834

    
1835
$section->addInput(new Form_IpAddress(
1836
	'ipaddrv6',
1837
	'IPv6 address',
1838
	$pconfig['ipaddrv6']
1839
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1840

    
1841
$group = new Form_Group('IPv6 Upstream gateway');
1842

    
1843
$group->add(new Form_Select(
1844
	'gatewayv6',
1845
	'IPv6 Upstream Gateway',
1846
	$pconfig['gatewayv6'],
1847
	build_gatewayv6_list()
1848
));
1849

    
1850
$group->add(new Form_Button(
1851
	'addgw6',
1852
	'Add a new gateway',
1853
	null,
1854
	'fa-plus'
1855
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1856

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

    
1860
$section->add($group);
1861
$form->add($section);
1862

    
1863
// Add new gateway modal pop-up for IPv6
1864
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1865

    
1866
$modal->addInput(new Form_Checkbox(
1867
	'defaultgw6',
1868
	'Default',
1869
	'Default gateway',
1870
	($if == "wan" || $if == "WAN")
1871
));
1872

    
1873
$modal->addInput(new Form_Input(
1874
	'name6',
1875
	'Gateway name',
1876
	'text',
1877
	$wancfg['descr'] . "GWv6"
1878
));
1879

    
1880
$modal->addInput(new Form_IpAddress(
1881
	'gatewayip6',
1882
	'Gateway IPv6',
1883
	null
1884
));
1885

    
1886
$modal->addInput(new Form_Input(
1887
	'gatewaydescr6',
1888
	'Description',
1889
	'text'
1890
));
1891

    
1892
$btnaddgw6 = new Form_Button(
1893
	'add6',
1894
	'Add',
1895
	null,
1896
	'fa-plus'
1897
);
1898

    
1899
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1900

    
1901
$btncnxgw6 = new Form_Button(
1902
	'cnx6',
1903
	'Cancel',
1904
	null,
1905
	'fa-undo'
1906
);
1907

    
1908
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1909

    
1910
$modal->addInput(new Form_StaticText(
1911
	null,
1912
	$btnaddgw6 . $btncnxgw6
1913
));
1914

    
1915
$form->add($modal);
1916

    
1917
// ==== DHCP client configuration =============================
1918

    
1919
$section = new Form_Section('DHCP Client Configuration');
1920
$section->addClass('dhcp');
1921

    
1922
$group = new Form_Group('Options');
1923

    
1924
$group->add(new Form_Checkbox(
1925
	'adv_dhcp_config_advanced',
1926
	null,
1927
	'Advanced Configuration',
1928
	$pconfig['adv_dhcp_config_advanced']
1929
))->setHelp('Use advanced DHCP configuration options.');
1930

    
1931
$group->add(new Form_Checkbox(
1932
	'adv_dhcp_config_file_override',
1933
	null,
1934
	'Configuration Override',
1935
	$pconfig['adv_dhcp_config_file_override']
1936
))->setHelp('Override the configuration from this file.');
1937

    
1938
$section->add($group);
1939

    
1940
$section->addInput(new Form_Input(
1941
	'dhcphostname',
1942
	'Hostname',
1943
	'text',
1944
	$pconfig['dhcphostname']
1945
))->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).');
1946

    
1947
$section->addInput(new Form_IpAddress(
1948
	'alias-address',
1949
	'Alias IPv4 address',
1950
	$pconfig['alias-address']
1951
))->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.');
1952

    
1953
$section->addInput(new Form_Input(
1954
	'dhcprejectfrom',
1955
	'Reject leases from',
1956
	'text',
1957
	$pconfig['dhcprejectfrom']
1958
))->setHelp('If there is a certain upstream DHCP server that should be ignored, place the IP address or subnet of the DHCP server to be ignored here. ' .
1959
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1960

    
1961
$group = new Form_Group('Protocol timing');
1962
$group->addClass('dhcpadvanced');
1963

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

    
1971
$group->add(new Form_Input(
1972
	'adv_dhcp_pt_retry',
1973
	null,
1974
	'number',
1975
	$pconfig['adv_dhcp_pt_retry']
1976
))->setHelp('Retry');
1977

    
1978
$group->add(new Form_Input(
1979
	'adv_dhcp_pt_select_timeout',
1980
	null,
1981
	'number',
1982
	$pconfig['adv_dhcp_pt_select_timeout'],
1983
	['min' => 0]
1984
))->setHelp('Select timeout');
1985

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

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

    
2000
$group->add(new Form_Input(
2001
	'adv_dhcp_pt_initial_interval',
2002
	null,
2003
	'number',
2004
	$pconfig['adv_dhcp_pt_initial_interval']
2005
))->setHelp('Initial interval');
2006

    
2007
$section->add($group);
2008

    
2009
$group = new Form_Group('Presets');
2010
$group->addClass('dhcpadvanced');
2011

    
2012
$group->add(new Form_Checkbox(
2013
	'adv_dhcp_pt_values',
2014
	null,
2015
	'FreeBSD default',
2016
	null,
2017
	'DHCP'
2018
))->displayAsRadio();
2019

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

    
2028
$group->add(new Form_Checkbox(
2029
	'adv_dhcp_pt_values',
2030
	null,
2031
	'pfSense Default',
2032
	null,
2033
	'pfSense'
2034
))->displayAsRadio();
2035

    
2036
$group->add(new Form_Checkbox(
2037
	'adv_dhcp_pt_values',
2038
	null,
2039
	'Saved Cfg',
2040
	null,
2041
	'SavedCfg'
2042
))->displayAsRadio();
2043

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

    
2047
$section->add($group);
2048

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

    
2059
$form->add($section);
2060

    
2061
$section = new Form_Section('Lease Requirements and Requests');
2062
$section->addClass('dhcpadvanced');
2063

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

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

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

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

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

    
2100
// DHCP6 client config
2101

    
2102
$section = new Form_Section('DHCP6 Client Configuration');
2103
$section->addClass('dhcp6');
2104

    
2105
$group = new Form_Group('Options');
2106

    
2107
$group->add(new Form_Checkbox(
2108
	'adv_dhcp6_config_advanced',
2109
	null,
2110
	'Advanced Configuration',
2111
	$pconfig['adv_dhcp6_config_advanced']
2112
))->setHelp('Use advanced DHCPv6 configuration options.');
2113

    
2114
$group->add(new Form_Checkbox(
2115
	'adv_dhcp6_config_file_override',
2116
	null,
2117
	'Configuration Override',
2118
	$pconfig['adv_dhcp6_config_file_override']
2119
))->setHelp('Override the configuration from this file.');
2120

    
2121
$section->add($group);
2122

    
2123
$section->addInput(new Form_Checkbox(
2124
	'dhcp6usev4iface',
2125
	'Use IPv4 connectivity as parent interface',
2126
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2127
	$pconfig['dhcp6usev4iface']
2128
));
2129

    
2130
$section->addInput(new Form_Checkbox(
2131
	'dhcp6prefixonly',
2132
	'Request only an IPv6 prefix',
2133
	'Only request an IPv6 prefix, do not request an IPv6 address',
2134
	$pconfig['dhcp6prefixonly']
2135
));
2136

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

    
2144
$section->addInput(new Form_Checkbox(
2145
	'dhcp6-ia-pd-send-hint',
2146
	'Send IPv6 prefix hint',
2147
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2148
	$pconfig['dhcp6-ia-pd-send-hint']
2149
));
2150

    
2151
$section->addInput(new Form_Checkbox(
2152
	'dhcp6debug',
2153
	'Debug',
2154
	'Start DHCP6 client in debug mode',
2155
	$pconfig['dhcp6debug']
2156
));
2157

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

    
2168
$form->add($section);
2169

    
2170
// DHCP6 client config - Advanced
2171

    
2172
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2173
$section->addClass('dhcp6advanced');
2174

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

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

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

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

    
2209
$group = new Form_Group('Identity Association Statement');
2210

    
2211
$group->add(new Form_Checkbox(
2212
	'adv_dhcp6_id_assoc_statement_address_enable',
2213
	null,
2214
	'Non-Temporary Address Allocation',
2215
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2216
	'Selected'
2217
));
2218

    
2219
$group->add(new Form_Input(
2220
	'adv_dhcp6_id_assoc_statement_address_id',
2221
	null,
2222
	'text',
2223
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2224
))->sethelp('id-assoc na ID');
2225

    
2226
$group->add(new Form_IpAddress(
2227
	'adv_dhcp6_id_assoc_statement_address',
2228
	null,
2229
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2230
))->sethelp('IPv6 address');
2231

    
2232
$group->add(new Form_Input(
2233
	'adv_dhcp6_id_assoc_statement_address_pltime',
2234
	null,
2235
	'text',
2236
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2237
))->sethelp('pltime');
2238

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

    
2246
$section->add($group);
2247

    
2248
// Prefix delegation
2249
$group = new Form_Group('');
2250

    
2251
$group->add(new Form_Checkbox(
2252
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2253
	null,
2254
	'Prefix Delegation ',
2255
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2256
	'Selected'
2257
));
2258

    
2259
$group->add(new Form_Input(
2260
	'adv_dhcp6_id_assoc_statement_prefix_id',
2261
	null,
2262
	'text',
2263
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2264
))->sethelp('id-assoc pd ID');
2265

    
2266
$group->add(new Form_IpAddress(
2267
	'adv_dhcp6_id_assoc_statement_prefix',
2268
	null,
2269
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2270
))->sethelp('IPv6 prefix');
2271

    
2272
$group->add(new Form_Input(
2273
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2274
	null,
2275
	'text',
2276
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2277
))->sethelp('pltime');
2278

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

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

    
2288
$group = new Form_Group('Prefix interface statement');
2289

    
2290
$group->add(new Form_Input(
2291
	'adv_dhcp6_prefix_interface_statement_sla_id',
2292
	null,
2293
	'text',
2294
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2295
))->sethelp('Prefix Interface sla-id');
2296

    
2297
$group->add(new Form_Input(
2298
	'adv_dhcp6_prefix_interface_statement_sla_len',
2299
	null,
2300
	'text',
2301
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2302
))->sethelp('sla-len');
2303

    
2304
$section->add($group);
2305

    
2306
$group = new Form_Group('Authentication statement');
2307

    
2308
$group->add(new Form_Input(
2309
	'adv_dhcp6_authentication_statement_authname',
2310
	null,
2311
	'text',
2312
	$pconfig['adv_dhcp6_authentication_statement_authname']
2313
))->sethelp('Authname');
2314

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

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

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

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

    
2338
$group = new Form_Group('Keyinfo statement');
2339

    
2340
$group->add(new Form_Input(
2341
	'adv_dhcp6_key_info_statement_keyname',
2342
	null,
2343
	'text',
2344
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2345
))->sethelp('Keyname');
2346

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

    
2354
$section->add($group);
2355

    
2356
$group = new Form_Group('');
2357

    
2358
$group->add(new Form_Input(
2359
	'adv_dhcp6_key_info_statement_keyid',
2360
	null,
2361
	'text',
2362
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2363
))->sethelp('KeyID');
2364

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

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

    
2379
$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>');
2380

    
2381
$section->add($group);
2382

    
2383
$form->add($section);
2384

    
2385
$section = new Form_Section('6RD Configuration');
2386
$section->addClass('_6rd');
2387

    
2388
$section->addInput(new Form_Input(
2389
	'prefix-6rd',
2390
	'6RD Prefix',
2391
	'text',
2392
	$pconfig['prefix-6rd']
2393
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2394

    
2395
$section->addInput(new Form_Input(
2396
	'gateway-6rd',
2397
	'6RD Border relay',
2398
	'text',
2399
	$pconfig['gateway-6rd']
2400
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2401

    
2402
$section->addInput(new Form_Select(
2403
	'prefix-6rd-v4plen',
2404
	'6RD IPv4 Prefix length',
2405
	$pconfig['prefix-6rd-v4plen'],
2406
	array_combine(range(0, 32), range(0, 32))
2407
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2408

    
2409
$form->add($section);
2410

    
2411
// Track IPv6 ointerface section
2412
$section = new Form_Section('Track IPv6 Interface');
2413
$section->addClass('track6');
2414

    
2415
function build_ipv6interface_list() {
2416
	global $config, $section;
2417

    
2418
	$list = array('' => '');
2419

    
2420
	$interfaces = get_configured_interface_with_descr(false, true);
2421
	$dynv6ifs = array();
2422

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

    
2438
	foreach ($dynv6ifs as $iface => $ifacedata) {
2439
		$list[$iface] = $ifacedata['name'];
2440

    
2441
		$section->addInput(new Form_Input(
2442
			'ipv6-num-prefix-ids-' . $iface,
2443
			null,
2444
			'hidden',
2445
			$ifacedata['ipv6_num_prefix_ids']
2446
		));
2447
	}
2448

    
2449
	return($list);
2450
}
2451

    
2452
$section->addInput(new Form_Select(
2453
	'track6-interface',
2454
	'IPv6 Interface',
2455
	$pconfig['track6-interface'],
2456
	build_ipv6interface_list()
2457
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2458

    
2459
if ($pconfig['track6-prefix-id'] == "") {
2460
	$pconfig['track6-prefix-id'] = 0;
2461
}
2462

    
2463
$section->addInput(new Form_Input(
2464
	'track6-prefix-id--hex',
2465
	'IPv6 Prefix ID',
2466
	'text',
2467
	sprintf("%x", $pconfig['track6-prefix-id'])
2468
))->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.');
2469

    
2470
$section->addInput(new Form_Input(
2471
	'track6-prefix-id-max',
2472
	null,
2473
	'hidden',
2474
	0
2475
));
2476

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

    
2479
/// PPP section
2480

    
2481
$section = new Form_Section('PPP Configuration');
2482
$section->addClass('ppp');
2483

    
2484
$section->addInput(new Form_Select(
2485
	'country',
2486
	'Country',
2487
	$pconfig['country'],
2488
	[]
2489
));
2490

    
2491
$section->addInput(new Form_Select(
2492
	'provider_list',
2493
	'Provider',
2494
	$pconfig['provider_list'],
2495
	[]
2496
));
2497

    
2498
$section->addInput(new Form_Select(
2499
	'providerplan',
2500
	'Plan',
2501
	$pconfig['providerplan'],
2502
	[]
2503
))->setHelp('Select to fill in service provider data.');
2504

    
2505
$section->addInput(new Form_Input(
2506
	'ppp_username',
2507
	'Username',
2508
	'text',
2509
	$pconfig['ppp_username']
2510
));
2511

    
2512
$section->addPassword(new Form_Input(
2513
	'ppp_password',
2514
	'Password',
2515
	'password',
2516
	$pconfig['ppp_password']
2517
));
2518

    
2519
$section->addInput(new Form_Input(
2520
	'phone',
2521
	'Phone number',
2522
	'text',
2523
	$pconfig['phone']
2524
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2525

    
2526
$section->addInput(new Form_Input(
2527
	'apn',
2528
	'Access Point Name',
2529
	'text',
2530
	$pconfig['apn']
2531
));
2532

    
2533

    
2534
function build_port_list() {
2535
	$list = array("" => "None");
2536

    
2537
	$portlist = glob("/dev/cua*");
2538
	$modems	  = glob("/dev/modem*");
2539
	$portlist = array_merge($portlist, $modems);
2540

    
2541
	foreach ($portlist as $port) {
2542
		if (preg_match("/\.(lock|init)$/", $port)) {
2543
			continue;
2544
		}
2545

    
2546
	$list[trim($port)] = $port;
2547
	}
2548

    
2549
	return($list);
2550
}
2551

    
2552
$section->addInput(new Form_Select(
2553
	'port',
2554
	"Modem port",
2555
	$pconfig['port'],
2556
	build_port_list()
2557
));
2558

    
2559
$section->addInput(new Form_Button(
2560
	'btnadvppp',
2561
	'Advanced PPP',
2562
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2563
	'fa-cog'
2564
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration');
2565

    
2566
$form->add($section);
2567

    
2568
// PPPoE configuration
2569
$section = new Form_Section('PPPoE Configuration');
2570
$section->addClass('pppoe');
2571

    
2572
$section->addInput(new Form_Input(
2573
	'pppoe_username',
2574
	'Username',
2575
	'text',
2576
	$pconfig['pppoe_username']
2577
));
2578

    
2579
$section->addPassword(new Form_Input(
2580
	'pppoe_password',
2581
	'Password',
2582
	'password',
2583
	$pconfig['pppoe_password']
2584
));
2585

    
2586
$section->addInput(new Form_Input(
2587
	'provider',
2588
	'Service name',
2589
	'text',
2590
	$pconfig['provider']
2591
))->setHelp('This field can usually be left empty');
2592

    
2593
$section->addInput(new Form_Checkbox(
2594
	'pppoe_dialondemand',
2595
	'Dial on demand',
2596
	'Enable Dial-On-Demand mode ',
2597
	$pconfig['pppoe_dialondemand'],
2598
	'enable'
2599
));
2600

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

    
2610
$section->addInput(new Form_Select(
2611
	'pppoe-reset-type',
2612
	'Periodic reset',
2613
	$pconfig['pppoe-reset-type'],
2614
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2615
))->setHelp('Select a reset timing type');
2616

    
2617
$group = new Form_Group('Custom reset');
2618
$group->addClass('pppoecustom');
2619

    
2620
$group->add(new Form_Input(
2621
	'pppoe_resethour',
2622
	null,
2623
	'number',
2624
	$pconfig['pppoe_resethour'],
2625
	[min => 0, max => 23]
2626
))->setHelp('Hour (0-23)');
2627

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

    
2636
// ToDo: Need a date-picker here
2637
$group->add(new Form_Input(
2638
	'pppoe_resetdate',
2639
	null,
2640
	'text',
2641
	$pconfig['pppoe_resetdate']
2642
))->setHelp('Specific date (mm/dd/yyyy)');
2643

    
2644
$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');
2645

    
2646
$section->add($group);
2647

    
2648
$group = new Form_MultiCheckboxGroup('cron based reset');
2649
$group->addClass('pppoepreset');
2650

    
2651
$group->add(new Form_MultiCheckbox(
2652
	'pppoe_pr_preset_val',
2653
	null,
2654
	'Reset at each month ("0 0 1 * *")',
2655
	$pconfig['pppoe_monthly'],
2656
	'monthly'
2657
))->displayAsRadio();
2658

    
2659
$group->add(new Form_MultiCheckbox(
2660
	'pppoe_pr_preset_val',
2661
	null,
2662
	'Reset at each week ("0 0 * * 0")',
2663
	$pconfig['pppoe_weekly'],
2664
	'weekly'
2665
))->displayAsRadio();
2666

    
2667
$group->add(new Form_MultiCheckbox(
2668
	'pppoe_pr_preset_val',
2669
	null,
2670
	'Reset at each day ("0 0 * * *")',
2671
	$pconfig['pppoe_daily'],
2672
	'daily'
2673
))->displayAsRadio();
2674

    
2675
$group->add(new Form_MultiCheckbox(
2676
	'pppoe_pr_preset_val',
2677
	null,
2678
	'Reset at each hour ("0 * * * *")',
2679
	$pconfig['pppoe_hourly'],
2680
	'hourly'
2681
))->displayAsRadio();
2682

    
2683
$section->add($group);
2684

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

    
2692
$form->add($section);
2693

    
2694
// PPTP & L2TP Configuration section
2695
$section = new Form_Section('PPTP/L2TP Configuration');
2696
$section->addClass('pptp');
2697

    
2698
$section->addInput(new Form_Input(
2699
	'pptp_username',
2700
	'Username',
2701
	'text',
2702
	$pconfig['pptp_username']
2703
));
2704

    
2705
$section->addPassword(new Form_Input(
2706
	'pptp_password',
2707
	'Password',
2708
	'password',
2709
	$pconfig['pptp_password']
2710
));
2711

    
2712
$section->addInput(new Form_IpAddress(
2713
	'pptp_local0',
2714
	'Local IP address',
2715
	$pconfig['pptp_localip'][0]
2716
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2717

    
2718
$section->addInput(new Form_IpAddress(
2719
	'pptp_remote0',
2720
	'Remote IP address',
2721
	$pconfig['pptp_remote'][0]
2722
));
2723

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

    
2733
$section->addInput(new Form_Input(
2734
	'pptp_idletimeout',
2735
	'Idle timeout (seconds)',
2736
	'number',
2737
	$pconfig['pptp_idletimeout'],
2738
	[min => 0]
2739
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2740
			'An idle timeout of zero disables this feature.');
2741

    
2742
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2743
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2744
} else {
2745
	$mlppp_text = "";
2746
}
2747

    
2748
$section->addInput(new Form_Button(
2749
	'btnadvppp',
2750
	'Advanced and MLPPP',
2751
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2752
	'fa-cog'
2753
))->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.');
2754

    
2755
$form->add($section);
2756

    
2757
// Wireless interface
2758
if (isset($wancfg['wireless'])) {
2759

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

    
2762
	$section->addInput(new Form_Checkbox(
2763
		'persistcommonwireless',
2764
		'Persist common settings',
2765
		'Preserve common wireless configuration through interface deletions and reassignments.',
2766
		$pconfig['persistcommonwireless'],
2767
		'yes'
2768
	));
2769

    
2770
	$mode_list = ['auto' => 'Auto'];
2771

    
2772
	if (is_array($wl_modes)) {
2773
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2774
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2775
		}
2776
	}
2777

    
2778
	if (count($mode_list) == 1) {
2779
		$mode_list[''] = '';
2780
	}
2781

    
2782
	$section->addInput(new Form_Select(
2783
		'standard',
2784
		'Standard',
2785
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2786
		$mode_list
2787
	));
2788

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

    
2805
	$mode_list = ['0' => gettext('Auto')];
2806

    
2807
	if (is_array($wl_modes)) {
2808
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2809
			if ($wl_standard == "11g") {
2810
				$wl_standard = "11b/g";
2811
			} else if ($wl_standard == "11ng") {
2812
				$wl_standard = "11b/g/n";
2813
			} else if ($wl_standard == "11na") {
2814
				$wl_standard = "11a/n";
2815
			}
2816

    
2817
			foreach ($wl_channels as $wl_channel) {
2818
				if (isset($wl_chaninfo[$wl_channel])) {
2819
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2820
				} else {
2821
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2822
				}
2823
			}
2824
		}
2825
	}
2826

    
2827
	$section->addInput(new Form_Select(
2828
		'channel',
2829
		'Channel',
2830
		$pconfig['channel'],
2831
		$mode_list
2832
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2833
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2834

    
2835
	if (ANTENNAS) {
2836
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2837
			$group = new Form_Group('Antenna Settings');
2838

    
2839
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2840
				$group->add(new Form_Select(
2841
					'diversity',
2842
					null,
2843
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2844
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2845
				))->setHelp('Diversity');
2846
			}
2847

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

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

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

    
2868
			$section->add($group);
2869
		}
2870
	}
2871

    
2872
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2873
			$section->addInput(new Form_Input(
2874
				'distance',
2875
				'Distance setting (meters)',
2876
				'test',
2877
				$pconfig['distance']
2878
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2879
	}
2880

    
2881
	$form->add($section);
2882

    
2883
	// Regulatory settings
2884
	$section = new Form_Section('Regulatory Settings');
2885

    
2886
	$domain_list = array("" => 'Default');
2887

    
2888
	if (is_array($wl_regdomains)) {
2889
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2890
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2891
		}
2892
	}
2893

    
2894
	$section->addInput(new Form_Select(
2895
		'regdomain',
2896
		'Regulatory domain',
2897
		$pconfig['regdomain'],
2898
		$domain_list
2899
	))->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');
2900

    
2901
	$country_list = array('' => 'Default');
2902

    
2903
	if (is_array($wl_countries)) {
2904
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2905
			$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']);
2906
		}
2907
	}
2908

    
2909
	$section->addInput(new Form_Select(
2910
		'regcountry',
2911
		'Country',
2912
		$pconfig['regcountry'],
2913
		$country_list
2914
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2915

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

    
2927
	$form->add($section);
2928

    
2929
	$section = new Form_Section('Network-Specific Wireless Configuration');
2930

    
2931
	$section->addInput(new Form_Select(
2932
		'mode',
2933
		'Mode',
2934
		$pconfig['mode'],
2935
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2936
	));
2937

    
2938
	$section->addInput(new Form_Input(
2939
		'ssid',
2940
		'SSID',
2941
		'text',
2942
		$pconfig['ssid']
2943
	));
2944

    
2945
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2946
		$section->addInput(new Form_Select(
2947
			'puremode',
2948
			'Minimum wireless standard',
2949
			$pconfig['puremode'],
2950
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2951
		))->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)');
2952
	} elseif (isset($wl_modes['11g'])) {
2953
		$section->addInput(new Form_Checkbox(
2954
			'puremode',
2955
			'802.11g only',
2956
			null,
2957
			$pconfig['puremode'],
2958
			'11g'
2959
		))->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)');
2960
	}
2961

    
2962
	$section->addInput(new Form_Checkbox(
2963
		'apbridge_enable',
2964
		'Allow intra-BSS communication',
2965
		'Allow packets to pass between wireless clients directly when operating as an access point',
2966
		$pconfig['apbridge_enable'],
2967
		'yes'
2968
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2969

    
2970
	$section->addInput(new Form_Checkbox(
2971
		'wme_enable',
2972
		'Enable WME',
2973
		'Force the card to use WME (wireless QoS)',
2974
		$pconfig['wme_enable'],
2975
		'yes'
2976
	));
2977

    
2978
	$section->addInput(new Form_Checkbox(
2979
		'hidessid_enable',
2980
		'Hide SSID',
2981
		'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.)',
2982
		$pconfig['hidessid_enable'],
2983
		'yes'
2984
	));
2985

    
2986
	$form->add($section);
2987

    
2988
	// WPA Section
2989
	$section = new Form_Section('WPA');
2990

    
2991
	$section->addInput(new Form_Checkbox(
2992
		'wpa_enable',
2993
		'Enable',
2994
		'Enable WPA',
2995
		$pconfig['wpa_enable'],
2996
		'yes'
2997
	));
2998

    
2999
	$section->addInput(new Form_Input(
3000
		'passphrase',
3001
		'WPA Pre-Shared Key',
3002
		'text',
3003
		$pconfig['passphrase']
3004
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3005

    
3006
	$section->addInput(new Form_Select(
3007
		'wpa_mode',
3008
		'WPA mode',
3009
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3010
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3011
	));
3012

    
3013
	$section->addInput(new Form_Select(
3014
		'wpa_key_mgmt',
3015
		'WPA Key Management Mode',
3016
		$pconfig['wpa_key_mgmt'],
3017
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3018
	));
3019

    
3020
	$section->addInput(new Form_Select(
3021
		'wpa_pairwise',
3022
		'WPA Pairwise',
3023
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3024
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3025
	));
3026

    
3027
	$section->addInput(new Form_Input(
3028
		'wpa_group_rekey',
3029
		'Group Key Rotation',
3030
		'number',
3031
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3032
		['min' => '1', 'max' => 9999]
3033
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3034

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

    
3043
	$section->addInput(new Form_Checkbox(
3044
		'wpa_strict_rekey',
3045
		'Strict Key Regeneration',
3046
		'Force the AP to rekey whenever a client disassociates',
3047
		$pconfig['wpa_strict_rekey'],
3048
		'yes'
3049
	));
3050

    
3051
	$form->add($section);
3052

    
3053
	$section = new Form_Section('802.1x RADIUS Options');
3054

    
3055
	$section->addInput(new Form_Checkbox(
3056
		'ieee8021x',
3057
		'IEEE802.1X',
3058
		'Enable 802.1X authentication',
3059
		$pconfig['ieee8021x'],
3060
		'yes'
3061
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3062

    
3063
	$group = new Form_Group('Primary 802.1X server');
3064

    
3065
	$group->add(new Form_IpAddress(
3066
		'auth_server_addr',
3067
		'IP Address',
3068
		$pconfig['auth_server_addr']
3069
	))->setHelp('IP address of the RADIUS server');
3070

    
3071
	$group->add(new Form_Input(
3072
		'auth_server_port',
3073
		'Port',
3074
		'number',
3075
		$pconfig['auth_server_port']
3076
	))->setHelp('Server auth port. Default is 1812');
3077

    
3078
	$group->add(new Form_Input(
3079
		'auth_server_shared_secret',
3080
		'Shared Secret',
3081
		'number',
3082
		$pconfig['auth_server_shared_secret']
3083
	))->setHelp('RADIUS Shared secret for this firewall');
3084

    
3085
	$section->add($group);
3086

    
3087
	$group = new Form_Group('Secondary 802.1X server');
3088

    
3089
	$group->add(new Form_IpAddress(
3090
		'auth_server_addr2',
3091
		'IP Address',
3092
		$pconfig['auth_server_addr2']
3093
	))->setHelp('IP address of the RADIUS server');
3094

    
3095
	$group->add(new Form_Input(
3096
		'auth_server_port2',
3097
		'Port',
3098
		'number',
3099
		$pconfig['auth_server_port2']
3100
	))->setHelp('Server auth port. Default is 1812');
3101

    
3102
	$group->add(new Form_Input(
3103
		'auth_server_shared_secret2',
3104
		'Shared Secret',
3105
		'number',
3106
		$pconfig['auth_server_shared_secret2']
3107
	))->setHelp('RADIUS Shared secret for this firewall');
3108

    
3109
	$section->add($group);
3110

    
3111
	$section->addInput(new Form_Checkbox(
3112
		'rsn_preauth',
3113
		'Authentication Roaming Preauth',
3114
		null,
3115
		$pconfig['rsn_preauth'],
3116
		'yes'
3117
	));
3118

    
3119
	$form->add($section);
3120
}
3121

    
3122
$section = new Form_Section('Private Networks');
3123

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

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

    
3144
$form->add($section);
3145

    
3146
$form->addGlobal(new Form_Input(
3147
	'if',
3148
	null,
3149
	'hidden',
3150
	$if
3151
));
3152

    
3153
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3154
	$form->addGlobal(new Form_Input(
3155
		'ppp_port',
3156
		null,
3157
		'hidden',
3158
		$pconfig['port']
3159
	));
3160
}
3161

    
3162
$form->addGlobal(new Form_Input(
3163
	'ptpid',
3164
	null,
3165
	'hidden',
3166
	$pconfig['ptpid']
3167
));
3168

    
3169

    
3170
// Add new gateway modal pop-up
3171
$modal = new Modal('New Gateway', 'newgateway', 'large');
3172

    
3173
$modal->addInput(new Form_Checkbox(
3174
	'defaultgw',
3175
	'Default',
3176
	'Default gateway',
3177
	($if == "wan" || $if == "WAN")
3178
));
3179

    
3180
$modal->addInput(new Form_Input(
3181
	'name',
3182
	'Gateway name',
3183
	'text',
3184
	$wancfg['descr'] . "GW"
3185
));
3186

    
3187
$modal->addInput(new Form_IpAddress(
3188
	'gatewayip',
3189
	'Gateway IPv4',
3190
	null
3191
));
3192

    
3193
$modal->addInput(new Form_Input(
3194
	'gatewaydescr',
3195
	'Description',
3196
	'text'
3197
));
3198

    
3199
$btnaddgw = new Form_Button(
3200
	'add',
3201
	'Add',
3202
	null,
3203
	'fa-plus'
3204
);
3205

    
3206
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3207

    
3208
$btncnxgw = new Form_Button(
3209
	'cnx',
3210
	'Cancel',
3211
	null,
3212
	'fa-undo'
3213
);
3214

    
3215
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3216

    
3217
$modal->addInput(new Form_StaticText(
3218
	null,
3219
	$btnaddgw . $btncnxgw
3220
));
3221

    
3222
$form->add($modal);
3223

    
3224
print($form);
3225
?>
3226

    
3227
<script type="text/javascript">
3228
//<![CDATA[
3229
events.push(function() {
3230
	function updateType(t) {
3231

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

    
3266
		if (t != "l2tp" && t != "pptp") {
3267
			$('.'+t).show();
3268
		}
3269
	}
3270

    
3271
	function updateTypeSix(t) {
3272
		if (!isNaN(t[0])) {
3273
			t = '_' + t;
3274
		}
3275

    
3276
		switch (t) {
3277
			case "none": {
3278
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3279
				break;
3280
			}
3281
			case "staticv6": {
3282
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3283
				break;
3284
			}
3285
			case "slaac": {
3286
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3287
				break;
3288
			}
3289
			case "dhcp6": {
3290
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3291
				break;
3292
			}
3293
			case "_6rd": {
3294
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3295
				break;
3296
			}
3297
			case "_6to4": {
3298
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3299
				break;
3300
			}
3301
			case "track6": {
3302
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3303
				update_track6_prefix();
3304
				break;
3305
			}
3306
		}
3307

    
3308
		if (t != "l2tp" && t != "pptp") {
3309
			$('.'+t).show();
3310
		}
3311
	}
3312

    
3313
	function show_reset_settings(reset_type) {
3314
		if (reset_type == 'preset') {
3315
			$('.pppoepreset').show();
3316
			$('.pppoecustom').hide();
3317
		} else if (reset_type == 'custom') {
3318
			$('.pppoecustom').show();
3319
			$('.pppoepreset').hide();
3320
		} else {
3321
			$('.pppoecustom').hide();
3322
			$('.pppoepreset').hide();
3323
		}
3324
	}
3325

    
3326
	function update_track6_prefix() {
3327
		var iface = $("#track6-interface").val();
3328
		if (iface == null) {
3329
			return;
3330
		}
3331

    
3332
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3333
		if (track6_prefix_ids == null) {
3334
			return;
3335
		}
3336

    
3337
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3338
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3339
	}
3340

    
3341
	// Create the new gateway from the data entered in the modal pop-up
3342
	function hide_add_gatewaysave() {
3343
		var iface = $('#if').val();
3344
		name = $('#name').val();
3345
		var descr = $('#gatewaydescr').val();
3346
		gatewayip = $('#gatewayip').val();
3347

    
3348
		var defaultgw = '';
3349
		if ($('#defaultgw').is(':checked')) {
3350
			defaultgw = '&defaultgw=on';
3351
		}
3352

    
3353
		var url = "system_gateways_edit.php";
3354
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3355
		$.ajax(
3356
			url,
3357
			{
3358
				type: 'post',
3359
				data: pars,
3360
				error: report_failure,
3361
				complete: save_callback
3362
			});
3363
		}
3364

    
3365
	function save_callback(response) {
3366
		if (response) {
3367
			var gwtext = escape(name) + " - " + gatewayip;
3368
			addOption($('#gateway'), gwtext, name);
3369
		} else {
3370
			report_failure();
3371
		}
3372

    
3373
		$("#newgateway").modal('hide');
3374
	}
3375

    
3376
	function report_failure(request, textStatus, errorThrown) {
3377
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3378
			alert(request.responseText);
3379
		} else {
3380
			alert("Could not create the IPv4 gateway at this time.");
3381
		}
3382

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

    
3386
	function addOption(selectbox, text, value) {
3387
		var optn = document.createElement("OPTION");
3388
		optn.text = text;
3389
		optn.value = value;
3390
		selectbox.append(optn);
3391
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3392
	}
3393

    
3394
	function hide_add_gatewaysave_v6() {
3395

    
3396
		var iface = $('#if').val();
3397
		name = $('#name6').val();
3398
		var descr = $('#gatewaydescr6').val();
3399
		gatewayip = $('#gatewayip6').val();
3400
		var defaultgw = '';
3401
		if ($('#defaultgw6').is(':checked')) {
3402
			defaultgw = '&defaultgw=on';
3403
		}
3404
		var url_v6 = "system_gateways_edit.php";
3405
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3406
		$.ajax(
3407
			url_v6,
3408
			{
3409
				type: 'post',
3410
				data: pars_v6,
3411
				error: report_failure_v6,
3412
				success: save_callback_v6
3413
			});
3414
	}
3415

    
3416

    
3417
	function addOption_v6(selectbox, text, value) {
3418
		var optn = document.createElement("OPTION");
3419
		optn.text = text;
3420
		optn.value = value;
3421
		selectbox.append(optn);
3422
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3423
	}
3424

    
3425
	function report_failure_v6(request, textStatus, errorThrown) {
3426
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3427
			alert(request.responseText);
3428
		} else {
3429
			alert("Could not create the IPv6 gateway at this time.");
3430
		}
3431

    
3432
		$("#newgateway6").modal('hide');
3433
	}
3434

    
3435
	function save_callback_v6(response_v6) {
3436
		if (response_v6) {
3437

    
3438
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3439
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3440
		} else {
3441
			report_failure_v6();
3442
		}
3443

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

    
3447
	function country_list() {
3448
		$('#country').children().remove();
3449
		$('#provider_list').children().remove();
3450
		$('#providerplan').children().remove();
3451
		$.ajax("getserviceproviders.php",{
3452
			success: function(response) {
3453

    
3454
				var responseTextArr = response.split("\n");
3455
				responseTextArr.sort();
3456

    
3457
				responseTextArr.forEach( function(value) {
3458
					country = value.split(":");
3459
					$('#country').append($('<option>', {
3460
						value: country[1],
3461
						text : country[0]
3462
					}));
3463
				});
3464
			}
3465
		});
3466
	}
3467

    
3468
	function providers_list() {
3469
		$('#provider_list').children().remove();
3470
		$('#providerplan').children().remove();
3471
		$.ajax("getserviceproviders.php",{
3472
			type: 'post',
3473
			data: {country : $('#country').val()},
3474
			success: function(response) {
3475
				var responseTextArr = response.split("\n");
3476
				responseTextArr.sort();
3477
				responseTextArr.forEach( function(value) {
3478
					$('#provider_list').append($('<option>', {
3479
							value: value,
3480
							text : value
3481
					}));
3482
				});
3483
			}
3484
		});
3485
	}
3486

    
3487
	function providerplan_list() {
3488
		$('#providerplan').children().remove();
3489
		$.ajax("getserviceproviders.php",{
3490
			type: 'post',
3491
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3492
			success: function(response) {
3493
				var responseTextArr = response.split("\n");
3494
				responseTextArr.sort();
3495

    
3496
				$('#providerplan').append($('<option>', {
3497
					value: '',
3498
					text : ''
3499
				}));
3500

    
3501
				responseTextArr.forEach( function(value) {
3502
					if (value != "") {
3503
						providerplan = value.split(":");
3504

    
3505
						$('#providerplan').append($('<option>', {
3506
							value: providerplan[1],
3507
							text : providerplan[0] + " - " + providerplan[1]
3508
						}));
3509
					}
3510
				});
3511
			}
3512
		});
3513
	}
3514

    
3515
	function prefill_provider() {
3516
		$.ajax("getserviceproviders.php",{
3517
			type: 'post',
3518
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3519
			success: function(data, textStatus, response) {
3520
				var xmldoc = response.responseXML;
3521
				var provider = xmldoc.getElementsByTagName('connection')[0];
3522
				$('#ppp_username').val('');
3523
				$('#ppp_password').val('');
3524
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3525
					$('#phone').val('#777');
3526
					$('#apn').val('');
3527
				} else {
3528
					$('#phone').val('*99#');
3529
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3530
				}
3531
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3532
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3533
				$('#ppp_username').val(ppp_username);
3534
				$('#ppp_password').val(ppp_password);
3535
			}
3536
		});
3537
	}
3538

    
3539
	function show_dhcp6adv() {
3540
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3541
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3542

    
3543
		hideCheckbox('dhcp6usev4iface', ovr);
3544
		hideCheckbox('dhcp6prefixonly', ovr);
3545
		hideInput('dhcp6-ia-pd-len', ovr);
3546
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3547
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3548

    
3549
		hideClass('dhcp6advanced', !adv || ovr);
3550
	}
3551

    
3552
	function setDHCPoptions() {
3553
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3554
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3555

    
3556
		if (ovr) {
3557
			hideInput('dhcphostname', true);
3558
			hideIpAddress('alias-address', true);
3559
			hideInput('dhcprejectfrom', true);
3560
			hideInput('adv_dhcp_config_file_override_path', false);
3561
			hideClass('dhcpadvanced', true);
3562
		} else {
3563
			hideInput('dhcphostname', false);
3564
			hideIpAddress('alias-address', false);
3565
			hideInput('dhcprejectfrom', false);
3566
			hideInput('adv_dhcp_config_file_override_path', true);
3567
			hideClass('dhcpadvanced', !adv);
3568
		}
3569
	}
3570

    
3571
	// DHCP preset actions
3572
	// Set presets from value of radio buttons
3573
	function setPresets(val) {
3574
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3575
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3576
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3577
		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']);?>");
3578
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3579
	}
3580

    
3581
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3582
		$('#adv_dhcp_pt_timeout').val(timeout);
3583
		$('#adv_dhcp_pt_retry').val(retry);
3584
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3585
		$('#adv_dhcp_pt_reboot').val(reboot);
3586
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3587
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3588
	}
3589

    
3590
	// ---------- On initial page load ------------------------------------------------------------
3591

    
3592
	updateType($('#type').val());
3593
	updateTypeSix($('#type6').val());
3594
	show_reset_settings($('#pppoe-reset-type').val());
3595
	hideClass('dhcp6advanced', true);
3596
	hideClass('dhcpadvanced', true);
3597
	show_dhcp6adv();
3598
	setDHCPoptions()
3599

    
3600
	// Set preset buttons on page load
3601
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3602
	if (sv == "") {
3603
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3604
	} else {
3605
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3606
	}
3607

    
3608
	// Set preset from value
3609
	setPresets(sv);
3610

    
3611
	// ---------- Click checkbox handlers ---------------------------------------------------------
3612

    
3613
	$('#type').on('change', function() {
3614
		updateType(this.value);
3615
	});
3616

    
3617
	$('#type6').on('change', function() {
3618
		updateTypeSix(this.value);
3619
	});
3620

    
3621
	$('#track6-interface').on('change', function() {
3622
		update_track6_prefix();
3623
	});
3624

    
3625
	$('#pppoe-reset-type').on('change', function() {
3626
		show_reset_settings(this.value);
3627
	});
3628

    
3629
	$("#add").click(function() {
3630
		hide_add_gatewaysave();
3631
	});
3632

    
3633
	$("#cnx").click(function() {
3634
		$("#newgateway").modal('hide');
3635
	});
3636

    
3637
	$("#add6").click(function() {
3638
		hide_add_gatewaysave_v6();
3639
	});
3640

    
3641
	$("#cnx6").click(function() {
3642
		$("#newgateway6").modal('hide');
3643
	});
3644

    
3645
	$('#country').on('change', function() {
3646
		providers_list();
3647
	});
3648

    
3649
	$('#provider_list').on('change', function() {
3650
		providerplan_list();
3651
	});
3652

    
3653
	$('#providerplan').on('change', function() {
3654
		prefill_provider();
3655
	});
3656

    
3657
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3658
		setDHCPoptions();
3659
	});
3660

    
3661
	$('#adv_dhcp6_config_advanced').click(function () {
3662
		show_dhcp6adv();
3663
	});
3664

    
3665
	$('#adv_dhcp6_config_file_override').click(function () {
3666
		show_dhcp6adv();
3667
	});
3668

    
3669
	// On click . .
3670
	$('[name=adv_dhcp_pt_values]').click(function () {
3671
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3672
	});
3673

    
3674
});
3675
//]]>
3676
</script>
3677

    
3678
<?php include("foot.inc");
(69-69/225)