Project

General

Profile

Download (122 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
		break;
320
	case "6to4":
321
		$pconfig['type6'] = "6to4";
322
		break;
323
	case "track6":
324
		$pconfig['type6'] = "track6";
325
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
326
		if ($wancfg['track6-prefix-id'] == "") {
327
			$pconfig['track6-prefix-id'] = 0;
328
		} else {
329
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
330
		}
331
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
332
		break;
333
	case "6rd":
334
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
335
		if ($wancfg['prefix-6rd-v4plen'] == "") {
336
			$wancfg['prefix-6rd-v4plen'] = "0";
337
		}
338
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
339
		$pconfig['type6'] = "6rd";
340
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
341
		break;
342
	default:
343
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
344
			$pconfig['type6'] = "staticv6";
345
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
346
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
347
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
348
		} else {
349
			$pconfig['type6'] = "none";
350
		}
351
		break;
352
}
353

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

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

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

    
438
}
439

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

    
448
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
449
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
450
			foreach ($toapplylist as $ifapply => $ifcfgo) {
451
				if (isset($config['interfaces'][$ifapply]['enable'])) {
452
					interface_bring_down($ifapply, false, $ifcfgo);
453
					interface_configure($ifapply, true);
454
				} else {
455
					interface_bring_down($ifapply, true, $ifcfgo);
456
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
457
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
458
						services_dhcpd_configure();
459
					}
460
				}
461
			}
462
		}
463
		/* restart snmp so that it binds to correct address */
464
		services_snmpd_configure();
465

    
466
		/* sync filter configuration */
467
		setup_gateways_monitor();
468

    
469
		clear_subsystem_dirty('interfaces');
470

    
471
		filter_configure();
472

    
473
		enable_rrd_graphing();
474

    
475
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
476
			clear_subsystem_dirty('staticroutes');
477
		}
478
	}
479
	@unlink("{$g['tmp_path']}/.interfaces.apply");
480
	header("Location: interfaces.php?if={$if}");
481
	exit;
482
} else if ($_POST && $_POST['enable'] != "yes") {
483
	unset($wancfg['enable']);
484
	if (isset($wancfg['wireless'])) {
485
		interface_sync_wireless_clones($wancfg, false);
486
	}
487
	write_config(sprintf(gettext('Interface %1$s (%2$s) is now disabled.'), $_POST['descr'], $if));
488
	mark_subsystem_dirty('interfaces');
489
	if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
490
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
491
	} else {
492
		$toapplylist = array();
493
	}
494
	$toapplylist[$if]['ifcfg'] = $wancfg;
495
	$toapplylist[$if]['ppps'] = $a_ppps;
496
	/* we need to be able remove IP aliases for IPv6 */
497
	file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
498
	header("Location: interfaces.php?if={$if}");
499
	exit;
500
} else if ($_POST) {
501

    
502
	unset($input_errors);
503
	$pconfig = $_POST;
504

    
505
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
506
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
507
	} else {
508
		$pconfig['track6-prefix-id'] = 0;
509
	}
510
	conf_mount_rw();
511

    
512
	/* filter out spaces from descriptions */
513
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
514

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

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

    
545
	/* Is the description already used as an interface group name? */
546
	if (is_array($config['ifgroups']['ifgroupentry'])) {
547
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
548
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
549
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
550
			}
551
		}
552
	}
553

    
554
	if (is_numeric($_POST['descr'])) {
555
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
556
	}
557
	/* input validation */
558
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
559
		$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.");
560
	}
561
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
562
		$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.");
563
	}
564

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

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

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

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

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

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

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

    
835
		unset($min_mtu, $max_mtu);
836

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1421
		conf_mount_ro();
1422
		write_config();
1423

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

    
1433
		mark_subsystem_dirty('interfaces');
1434

    
1435
		/* regenerate cron settings/crontab file */
1436
		configure_cron();
1437

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

    
1442
} // end if ($_POST)
1443

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

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

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

    
1593
	interface_sync_wireless_clones($wancfg, true);
1594
}
1595

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

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

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

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

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

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

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

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

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

    
1655
function build_mediaopts_list() {
1656
	global $mediaopts_list;
1657

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

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

    
1666
	return($list);
1667
}
1668

    
1669
function build_gateway_list() {
1670
	global $a_gateways, $if;
1671

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

    
1679
	return($list);
1680
}
1681

    
1682
function build_gatewayv6_list() {
1683
	global $a_gateways, $if;
1684

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

    
1692
	return($list);
1693
}
1694

    
1695
include("head.inc");
1696

    
1697
if ($input_errors) {
1698
	print_input_errors($input_errors);
1699
}
1700

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

    
1706
if ($savemsg) {
1707
	print_info_box($savemsg, 'success');
1708
}
1709

    
1710

    
1711
$form = new Form(new Form_Button(
1712
	'Submit',
1713
	gettext("Save")
1714
));
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
	);
1759

    
1760
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1761

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

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

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

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

    
1795
$form->add($section);
1796

    
1797
$section = new Form_Section('Static IPv4 configuration');
1798
$section->addClass('staticv4');
1799

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

    
1806
$group = new Form_Group('IPv4 Upstream gateway');
1807

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

    
1815
$group->add(new Form_Button(
1816
	'addgw',
1817
	'Add a new gateway'
1818
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1819

    
1820
$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 />' .
1821
				'On local LANs the upstream gateway should be "none".' .
1822
				gettext('You can manage gateways by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>');
1823

    
1824
$section->add($group);
1825

    
1826
$form->add($section);
1827

    
1828
$section = new Form_Section('Static IPv6 configuration');
1829
$section->addClass('staticv6');
1830

    
1831
$section->addInput(new Form_IpAddress(
1832
	'ipaddrv6',
1833
	'IPv6 address',
1834
	$pconfig['ipaddrv6']
1835
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1836

    
1837
$group = new Form_Group('IPv6 Upstream gateway');
1838

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

    
1846
$group->add(new Form_Button(
1847
	'addgw6',
1848
	'Add a new gateway'
1849
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1850

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

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

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

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

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

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

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

    
1886
$btnaddgw6 = new Form_Button(
1887
	'add6',
1888
	'Add'
1889
);
1890

    
1891
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1892

    
1893
$btncnxgw6 = new Form_Button(
1894
	'cnx6',
1895
	'Cancel'
1896
);
1897

    
1898
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1899

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

    
1905
$form->add($modal);
1906

    
1907
// ==== DHCP client configuration =============================
1908

    
1909
$section = new Form_Section('DHCP client configuration');
1910
$section->addClass('dhcp');
1911

    
1912
$group = new Form_Group('Options');
1913

    
1914
$group->add(new Form_Checkbox(
1915
	'dhcpadv',
1916
	null,
1917
	'Show DHCP advanced options',
1918
	false
1919
));
1920

    
1921
$group->add(new Form_Checkbox(
1922
	'dhcpovr',
1923
	null,
1924
	'Config file override',
1925
	false
1926
));
1927

    
1928
$section->add($group);
1929

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

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

    
1943
$section->addInput(new Form_Input(
1944
	'dhcprejectfrom',
1945
	'Reject leases from',
1946
	'text',
1947
	$pconfig['dhcprejectfrom']
1948
))->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. ' .
1949
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1950

    
1951
$group = new Form_Group('Protocol timing');
1952
$group->addClass('dhcpadvanced');
1953

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

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

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

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

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

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

    
1997
$section->add($group);
1998

    
1999
$group = new Form_Group('Presets');
2000
$group->addClass('dhcpadvanced');
2001

    
2002
$group->add(new Form_Checkbox(
2003
	'adv_dhcp_pt_values',
2004
	null,
2005
	'FreeBSD default',
2006
	null,
2007
	'DHCP'
2008
))->displayAsRadio();
2009

    
2010
$group->add(new Form_Checkbox(
2011
	'adv_dhcp_pt_values',
2012
	null,
2013
	'Clear',
2014
	null,
2015
	'Clear'
2016
))->displayAsRadio();
2017

    
2018
$group->add(new Form_Checkbox(
2019
	'adv_dhcp_pt_values',
2020
	null,
2021
	'pfSense Default',
2022
	null,
2023
	'pfSense'
2024
))->displayAsRadio();
2025

    
2026
$group->add(new Form_Checkbox(
2027
	'adv_dhcp_pt_values',
2028
	null,
2029
	'Saved Cfg',
2030
	null,
2031
	'SavedCfg'
2032
))->displayAsRadio();
2033

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

    
2037
$section->add($group);
2038

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

    
2049
$form->add($section);
2050

    
2051
$section = new Form_Section('Lease Requirements and Requests');
2052
$section->addClass('dhcpadvanced');
2053

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

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

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

    
2079
$section->addInput(new Form_Input(
2080
	'adv_dhcp_option_modifiers',
2081
	'Option modifiers',
2082
	'text',
2083
	$pconfig['adv_dhcp_option_modifiers']
2084
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2085
			'modifiers: (default, supersede, prepend, append)');
2086

    
2087
$form->add($section);
2088

    
2089
// DHCP6 client config
2090

    
2091
$section = new Form_Section('DHCP6 client configuration');
2092
$section->addClass('dhcp6');
2093

    
2094
$section->addInput(new Form_Checkbox(
2095
	'adv_dhcp6_config_advanced',
2096
	'Advanced',
2097
	'Show DHCPv6 advanced options',
2098
	$pconfig['adv_dhcp6_config_advanced'],
2099
	'Selected'
2100
));
2101

    
2102
$section->addInput(new Form_Checkbox(
2103
	'adv_dhcp6_config_file_override',
2104
	'Config file override',
2105
	'Override the configuration from this file',
2106
	$pconfig['adv_dhcp6_config_file_override'],
2107
	'Selected'
2108
));
2109

    
2110
$section->addInput(new Form_Checkbox(
2111
	'dhcp6usev4iface',
2112
	'Use IPv4 connectivity as parent interface',
2113
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2114
	$pconfig['dhcp6usev4iface']
2115
));
2116

    
2117
$section->addInput(new Form_Checkbox(
2118
	'dhcp6prefixonly',
2119
	'Request only an IPv6 prefix',
2120
	'Only request an IPv6 prefix, do not request an IPv6 address',
2121
	$pconfig['dhcp6prefixonly']
2122
));
2123

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

    
2131
$section->addInput(new Form_Checkbox(
2132
	'dhcp6-ia-pd-send-hint',
2133
	'Send IPv6 prefix hint',
2134
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2135
	$pconfig['dhcp6-ia-pd-send-hint']
2136
));
2137

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

    
2148
$form->add($section);
2149

    
2150
// DHCP6 client config - Advanced
2151

    
2152
$section = new Form_Section('Advanced DHCP6 client configuration');
2153
$section->addClass('dhcp6advanced');
2154

    
2155
$section->addInput(new Form_Checkbox(
2156
	'adv_dhcp6_interface_statement_information_only_enable',
2157
	'Information only',
2158
	null,
2159
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2160
	'Selected'
2161
));
2162

    
2163
$section->addInput(new Form_Input(
2164
	'adv_dhcp6_interface_statement_send_options',
2165
	'Send options',
2166
	'text',
2167
	$pconfig['adv_dhcp6_interface_statement_send_options']
2168
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2169
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2170
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2171
			'Some DHCP services may require certain options be or not be sent.');
2172

    
2173
$section->addInput(new Form_Input(
2174
	'adv_dhcp6_interface_statement_request_options',
2175
	'Request Options',
2176
	'text',
2177
	$pconfig['adv_dhcp6_interface_statement_request_options']
2178
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2179
			'Some DHCP services may require certain options be or not be requested.');
2180

    
2181
$section->addInput(new Form_Input(
2182
	'adv_dhcp6_interface_statement_script',
2183
	'Scripts',
2184
	'text',
2185
	$pconfig['adv_dhcp6_interface_statement_script']
2186
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2187
			'[/[dirname/[.../]]filename[.ext]].');
2188

    
2189
$group = new Form_Group('Identity Association Statement');
2190

    
2191
$group->add(new Form_Checkbox(
2192
	'adv_dhcp6_id_assoc_statement_address_enable',
2193
	null,
2194
	'Non-Temporary Address Allocation',
2195
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2196
	'Selected'
2197
));
2198

    
2199
$group->add(new Form_Input(
2200
	'adv_dhcp6_id_assoc_statement_address_id',
2201
	null,
2202
	'text',
2203
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2204
))->sethelp('id-assoc na ID');
2205

    
2206
$group->add(new Form_IpAddress(
2207
	'adv_dhcp6_id_assoc_statement_address',
2208
	null,
2209
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2210
))->sethelp('IPv6 address');
2211

    
2212
$group->add(new Form_Input(
2213
	'adv_dhcp6_id_assoc_statement_address_pltime',
2214
	null,
2215
	'text',
2216
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2217
))->sethelp('pltime');
2218

    
2219
$group->add(new Form_Input(
2220
	'adv_dhcp6_id_assoc_statement_address_vltime',
2221
	null,
2222
	'text',
2223
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2224
))->sethelp('vltime');
2225

    
2226
$section->add($group);
2227

    
2228
// Prefix delegation
2229
$group = new Form_Group('');
2230

    
2231
$group->add(new Form_Checkbox(
2232
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2233
	null,
2234
	'Prefix Delegation ',
2235
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2236
	'Selected'
2237
));
2238

    
2239
$group->add(new Form_Input(
2240
	'adv_dhcp6_id_assoc_statement_prefix_id',
2241
	null,
2242
	'text',
2243
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2244
))->sethelp('id-assoc pd ID');
2245

    
2246
$group->add(new Form_IpAddress(
2247
	'adv_dhcp6_id_assoc_statement_prefix',
2248
	null,
2249
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2250
))->sethelp('IPv6 prefix');
2251

    
2252
$group->add(new Form_Input(
2253
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2254
	null,
2255
	'text',
2256
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2257
))->sethelp('pltime');
2258

    
2259
$group->add(new Form_Input(
2260
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2261
	null,
2262
	'text',
2263
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2264
))->sethelp('vltime');
2265

    
2266
$section->add($group);
2267

    
2268
$group = new Form_Group('Prefix interface statement');
2269

    
2270
$group->add(new Form_Input(
2271
	'adv_dhcp6_prefix_interface_statement_sla_id',
2272
	null,
2273
	'text',
2274
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2275
))->sethelp('Prefix Interface sla-id');
2276

    
2277
$group->add(new Form_Input(
2278
	'adv_dhcp6_prefix_interface_statement_sla_len',
2279
	null,
2280
	'text',
2281
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2282
))->sethelp('sla-len');
2283

    
2284
$section->add($group);
2285

    
2286
$group = new Form_Group('Authentication statement');
2287

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

    
2295
$group->add(new Form_Input(
2296
	'adv_dhcp6_authentication_statement_protocol',
2297
	null,
2298
	'text',
2299
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2300
))->sethelp('Protocol');
2301

    
2302
$group->add(new Form_Input(
2303
	'adv_dhcp6_authentication_statement_algorithm',
2304
	null,
2305
	'text',
2306
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2307
))->sethelp('Algorithm');
2308

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

    
2316
$section->add($group);
2317

    
2318
$group = new Form_Group('Keyinfo statement');
2319

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

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

    
2334
$section->add($group);
2335

    
2336
$group = new Form_Group('');
2337

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

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

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

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

    
2361
$form->add($section);
2362

    
2363
$section = new Form_Section('6RD Configuration');
2364
$section->addClass('_6rd');
2365

    
2366
$section->addInput(new Form_Input(
2367
	'prefix-6rd',
2368
	'6RD Prefix',
2369
	'text',
2370
	$pconfig['prefix-6rd']
2371
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2372

    
2373
$section->addInput(new Form_Input(
2374
	'gateway-6rd',
2375
	'6RD Border relay',
2376
	'text',
2377
	$pconfig['gateway-6rd']
2378
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2379

    
2380
$section->addInput(new Form_Select(
2381
	'prefix-6rd-v4plen',
2382
	'6RD IPv4 Prefix length',
2383
	$pconfig['prefix-6rd-v4plen'],
2384
	array_combine(range(0, 32), range(0, 32))
2385
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means we embed the entire IPv4 address in the 6RD prefix.');
2386

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

    
2389
// Track IPv6 ointerface section
2390
$section = new Form_Section('Track IPv6 Interface');
2391
$section->addClass('track6');
2392

    
2393
function build_ipv6interface_list() {
2394
	global $config, $section;
2395

    
2396
	$list = array('' => '');
2397

    
2398
	$interfaces = get_configured_interface_with_descr(false, true);
2399
	$dynv6ifs = array();
2400

    
2401
	foreach ($interfaces as $iface => $ifacename) {
2402
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2403
			case "6to4":
2404
			case "6rd":
2405
			case "dhcp6":
2406
				$dynv6ifs[$iface] = array(
2407
					'name' => $ifacename,
2408
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2409
				);
2410
				break;
2411
			default:
2412
				continue;
2413
		}
2414
	}
2415

    
2416
	foreach ($dynv6ifs as $iface => $ifacedata) {
2417
		$list[$iface] = $ifacedata['name'];
2418

    
2419
		$section->addInput(new Form_Input(
2420
			'ipv6-num-prefix-ids-' . $iface,
2421
			null,
2422
			'hidden',
2423
			$ifacedata['ipv6_num_prefix_ids']
2424
		));
2425
	}
2426

    
2427
	return($list);
2428
}
2429

    
2430
$section->addInput(new Form_Select(
2431
	'track6-interface',
2432
	'IPv6 Interface',
2433
	$pconfig['track6-interface'],
2434
	build_ipv6interface_list()
2435
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2436

    
2437
if ($pconfig['track6-prefix-id'] == "") {
2438
	$pconfig['track6-prefix-id'] = 0;
2439
}
2440

    
2441
$section->addInput(new Form_Input(
2442
	'track6-prefix-id--hex' . $iface,
2443
	'IPv6 Prefix ID',
2444
	'text',
2445
	sprintf("%x", $pconfig['track6-prefix-id'])
2446
))->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.');
2447

    
2448
$section->addInput(new Form_Input(
2449
	'track6-prefix-id-max' . $iface,
2450
	null,
2451
	'hidden',
2452
	0
2453
));
2454

    
2455
$form->add($section);
2456

    
2457
/// PPP section
2458

    
2459
$section = new Form_Section('PPP Configuration');
2460
$section->addClass('ppp');
2461

    
2462
$section->addInput(new Form_Select(
2463
	'country',
2464
	'Country',
2465
	$pconfig['country'],
2466
	[]
2467
));
2468

    
2469
$section->addInput(new Form_Select(
2470
	'provider_list',
2471
	'Provider',
2472
	$pconfig['provider_list'],
2473
	[]
2474
));
2475

    
2476
$section->addInput(new Form_Select(
2477
	'providerplan',
2478
	'Plan',
2479
	$pconfig['providerplan'],
2480
	[]
2481
))->setHelp('Select to fill in data for your service provider.');
2482

    
2483
$section->addInput(new Form_Input(
2484
	'ppp_username',
2485
	'Username',
2486
	'text',
2487
	$pconfig['ppp_username']
2488
));
2489

    
2490
$section->addPassword(new Form_Input(
2491
	'ppp_password',
2492
	'Password',
2493
	'password',
2494
	$pconfig['ppp_password']
2495
));
2496

    
2497
$section->addInput(new Form_Input(
2498
	'phone',
2499
	'Phone number',
2500
	'text',
2501
	$pconfig['phone']
2502
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2503

    
2504
$section->addInput(new Form_Input(
2505
	'apn',
2506
	'Access Point Name',
2507
	'text',
2508
	$pconfig['apn']
2509
));
2510

    
2511

    
2512
function build_port_list() {
2513
	$list = array("" => "None");
2514

    
2515
	$portlist = glob("/dev/cua*");
2516
	$modems	  = glob("/dev/modem*");
2517
	$portlist = array_merge($portlist, $modems);
2518

    
2519
	foreach ($portlist as $port) {
2520
		if (preg_match("/\.(lock|init)$/", $port)) {
2521
			continue;
2522
		}
2523

    
2524
	$list[trim($port)] = $port;
2525
	}
2526

    
2527
	return($list);
2528
}
2529

    
2530
$section->addInput(new Form_Select(
2531
	'port',
2532
	"Modem port",
2533
	$pconfig['port'],
2534
	build_port_list()
2535
));
2536

    
2537
$section->addInput(new Form_Button(
2538
	'btnadvppp',
2539
	'Advanced PPP',
2540
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2541
))->setHelp('Create a new PPP configuration');
2542

    
2543
$form->add($section);
2544

    
2545
// PPPoE configuration
2546
$section = new Form_Section('PPPoE Configuration');
2547
$section->addClass('pppoe');
2548

    
2549
$section->addInput(new Form_Input(
2550
	'pppoe_username',
2551
	'Username',
2552
	'text',
2553
	$pconfig['pppoe_username']
2554
));
2555

    
2556
$section->addPassword(new Form_Input(
2557
	'pppoe_password',
2558
	'Password',
2559
	'password',
2560
	$pconfig['pppoe_password']
2561
));
2562

    
2563
$section->addInput(new Form_Input(
2564
	'provider',
2565
	'Service name',
2566
	'text',
2567
	$pconfig['provider']
2568
))->setHelp('This field can usually be left empty');
2569

    
2570
$section->addInput(new Form_Checkbox(
2571
	'pppoe_dialondemand',
2572
	'Dial on demand',
2573
	'Enable Dial-On-Demand mode ',
2574
	$pconfig['pppoe_dialondemand'],
2575
	'enable'
2576
));
2577

    
2578
$section->addInput(new Form_Input(
2579
	'pppoe_idletimeout',
2580
	'Idle timeout',
2581
	'number',
2582
	$pconfig['pppoe_idletimeout'],
2583
	[min => 0]
2584
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2585
			'An idle timeout of zero disables this feature.');
2586

    
2587
$section->addInput(new Form_Select(
2588
	'pppoe-reset-type',
2589
	'Periodic reset',
2590
	$pconfig['pppoe-reset-type'],
2591
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2592
))->setHelp('Select a reset timing type');
2593

    
2594
$group = new Form_Group('Custom reset');
2595
$group->addClass('pppoecustom');
2596

    
2597
$group->add(new Form_Input(
2598
	'pppoe_resethour',
2599
	null,
2600
	'number',
2601
	$pconfig['pppoe_resethour'],
2602
	[min => 0, max => 23]
2603
))->setHelp('Hour (0-23)');
2604

    
2605
$group->add(new Form_Input(
2606
	'pppoe_resetminute',
2607
	null,
2608
	'number',
2609
	$pconfig['pppoe_resetminute'],
2610
	[min => 0, max => 59]
2611
))->setHelp('Minutes (0-59)');
2612

    
2613
// ToDo: Need a date-picker here
2614
$group->add(new Form_Input(
2615
	'pppoe_resetdate',
2616
	null,
2617
	'text',
2618
	$pconfig['pppoe_resetdate']
2619
))->setHelp('Specific date (mm/dd/yyyy)');
2620

    
2621
$group->setHelp('If you leave the date field empty, the reset will be executed each day at the time you specified using the minutes and hour field');
2622

    
2623
$section->add($group);
2624

    
2625
$group = new Form_MultiCheckboxGroup('cron based reset');
2626
$group->addClass('pppoepreset');
2627

    
2628
$group->add(new Form_MultiCheckbox(
2629
	'pppoe_pr_preset_val',
2630
	null,
2631
	'Reset at each month ("0 0 1 * *")',
2632
	$pconfig['pppoe_monthly'],
2633
	'monthly'
2634
))->displayAsRadio();
2635

    
2636
$group->add(new Form_MultiCheckbox(
2637
	'pppoe_pr_preset_val',
2638
	null,
2639
	'Reset at each week ("0 0 * * 0")',
2640
	$pconfig['pppoe_weekly'],
2641
	'weekly'
2642
))->displayAsRadio();
2643

    
2644
$group->add(new Form_MultiCheckbox(
2645
	'pppoe_pr_preset_val',
2646
	null,
2647
	'Reset at each day ("0 0 * * *")',
2648
	$pconfig['pppoe_daily'],
2649
	'daily'
2650
))->displayAsRadio();
2651

    
2652
$group->add(new Form_MultiCheckbox(
2653
	'pppoe_pr_preset_val',
2654
	null,
2655
	'Reset at each hour ("0 * * * *")',
2656
	$pconfig['pppoe_hourly'],
2657
	'hourly'
2658
))->displayAsRadio();
2659

    
2660
$section->add($group);
2661

    
2662
if (isset($pconfig['pppid'])) {
2663
	$section->addInput(new Form_StaticText(
2664
		'Advanced and MLPPP',
2665
		'<a href="/interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) . '" class="navlnk">Click here for additional PPPoE configuration options. Save first if you made changes.</a>'
2666
	));
2667
} else {
2668
	$section->addInput(new Form_StaticText(
2669
		'Advanced and MLPPP',
2670
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2671
	));
2672
}
2673

    
2674
$form->add($section);
2675

    
2676
// PPTP & L2TP Configuration section
2677
$section = new Form_Section('PPTP/L2TP Configuration');
2678
$section->addClass('pptp');
2679

    
2680
$section->addInput(new Form_Input(
2681
	'pptp_username',
2682
	'Username',
2683
	'text',
2684
	$pconfig['pptp_username']
2685
));
2686

    
2687
$section->addPassword(new Form_Input(
2688
	'pptp_password',
2689
	'Password',
2690
	'password',
2691
	$pconfig['pptp_password']
2692
));
2693

    
2694
$section->addInput(new Form_IpAddress(
2695
	'pptp_local0',
2696
	'Local IP address',
2697
	$pconfig['pptp_localip'][0]
2698
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2699

    
2700
$section->addInput(new Form_IpAddress(
2701
	'pptp_remote0',
2702
	'Remote IP address',
2703
	$pconfig['pptp_remote'][0]
2704
));
2705

    
2706
$section->addInput(new Form_Checkbox(
2707
	'pptp_dialondemand',
2708
	'Dial on demand',
2709
	'Enable Dial-On-Demand mode ',
2710
	$pconfig['pptp_dialondemand'],
2711
	'enable'
2712
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2713
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2714

    
2715
$section->addInput(new Form_Input(
2716
	'pptp_idletimeout',
2717
	'Idle timeout (seconds)',
2718
	'number',
2719
	$pconfig['pptp_idletimeout'],
2720
	[min => 0]
2721
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2722
			'An idle timeout of zero disables this feature.');
2723

    
2724
if (isset($pconfig['pppid'])) {
2725
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2726
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2727
	} else {
2728
		$mlppp_text = "";
2729
	}
2730

    
2731
	$section->addInput(new Form_StaticText(
2732
		'Advanced and MLPPP',
2733
		$mlppp_text . '<a href="/interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) . '" class="navlnk">Click here for additional PPTP and L2TP configuration options. Save first if you made changes.</a>'
2734
	));
2735
} else {
2736
	$section->addInput(new Form_StaticText(
2737
		'Advanced and MLPPP',
2738
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2739
	));
2740
}
2741

    
2742
$form->add($section);
2743

    
2744
// Wireless interface
2745
if (isset($wancfg['wireless'])) {
2746

    
2747
	$section = new Form_Section('Common wireless configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
2748

    
2749
	$section->addInput(new Form_Checkbox(
2750
		'persistcommonwireless',
2751
		'Persist common settings',
2752
		'Preserve common wireless configuration through interface deletions and reassignments.',
2753
		$pconfig['persistcommonwireless'],
2754
		'yes'
2755
	));
2756

    
2757
	$mode_list = ['auto' => 'Auto'];
2758

    
2759
	if (is_array($wl_modes)) {
2760
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2761
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2762
		}
2763
	}
2764

    
2765
	if (count($mode_list) == 1) {
2766
		$mode_list[''] = '';
2767
	}
2768

    
2769
	$section->addInput(new Form_Select(
2770
		'standard',
2771
		'Standard',
2772
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2773
		$mode_list
2774
	));
2775

    
2776
	if (isset($wl_modes['11g'])) {
2777
		$section->addInput(new Form_Select(
2778
			'protmode',
2779
			'802.11g OFDM Protection Mode',
2780
			$pconfig['protmode'],
2781
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2782
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2783
	} else {
2784
		$section->addInput(new Form_Input(
2785
			'protmode',
2786
			null,
2787
			'hidden',
2788
			'off'
2789
		));
2790
	}
2791

    
2792
	$mode_list = ['0' => gettext('Auto')];
2793

    
2794
	if (is_array($wl_modes)) {
2795
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2796
			if ($wl_standard == "11g") {
2797
				$wl_standard = "11b/g";
2798
			} else if ($wl_standard == "11ng") {
2799
				$wl_standard = "11b/g/n";
2800
			} else if ($wl_standard == "11na") {
2801
				$wl_standard = "11a/n";
2802
			}
2803

    
2804
			foreach ($wl_channels as $wl_channel) {
2805
				if (isset($wl_chaninfo[$wl_channel])) {
2806
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2807
				} else {
2808
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2809
				}
2810
			}
2811
		}
2812
	}
2813

    
2814
	$section->addInput(new Form_Select(
2815
		'channel',
2816
		'Channel',
2817
		$pconfig['channel'],
2818
		$mode_list
2819
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2820
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2821

    
2822
	if (ANTENNAS) {
2823
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2824
			$group = new Form_Group('Antenna Settings');
2825

    
2826
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2827
				$group->add(new Form_Select(
2828
					'diversity',
2829
					null,
2830
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2831
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2832
				))->setHelp('Diversity');
2833
			}
2834

    
2835
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2836
				$group->add(new Form_Select(
2837
					'txantenna',
2838
					null,
2839
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2840
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2841
				))->setHelp('Transmit antenna');
2842
			}
2843

    
2844
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2845
				$group->add(new Form_Select(
2846
					'rxantenna',
2847
					null,
2848
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2849
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2850
				))->setHelp('Receive antenna');
2851
			}
2852

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

    
2855
			$section->add($group);
2856
		}
2857
	}
2858

    
2859
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2860
			$section->addInput(new Form_Input(
2861
				'distance',
2862
				'Distance setting (meters)',
2863
				'test',
2864
				$pconfig['distance']
2865
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2866
	}
2867

    
2868
	$form->add($section);
2869

    
2870
	// Regulatory settings
2871
	$section = new Form_Section('Regulatory settings');
2872

    
2873
	$domain_list = array("" => 'Default');
2874

    
2875
	if (is_array($wl_regdomains)) {
2876
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2877
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2878
		}
2879
	}
2880

    
2881
	$section->addInput(new Form_Select(
2882
		'regdomain',
2883
		'Regulatory domain',
2884
		$pconfig['regdomain'],
2885
		$domain_list
2886
	))->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');
2887

    
2888
	$country_list = array('' => 'Default');
2889

    
2890
	if (is_array($wl_countries)) {
2891
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2892
			$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']);
2893
		}
2894
	}
2895

    
2896
	$section->addInput(new Form_Select(
2897
		'regcountry',
2898
		'Country',
2899
		$pconfig['regcountry'],
2900
		$country_list
2901
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2902

    
2903
	$section->addInput(new Form_Select(
2904
		'reglocation',
2905
		'Location',
2906
		$pconfig['reglocation'],
2907
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
2908
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2909
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2910
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2911
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2912
				'These settings may not be able to add additional channels that are not already supported.');
2913

    
2914
	$form->add($section);
2915

    
2916
	$section = new Form_Section('Network-specific wireless configuration');
2917

    
2918
	$section->addInput(new Form_Select(
2919
		'mode',
2920
		'Mode',
2921
		$pconfig['mode'],
2922
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2923
	));
2924

    
2925
	$section->addInput(new Form_Input(
2926
		'ssid',
2927
		'SSID',
2928
		'text',
2929
		$pconfig['ssid']
2930
	));
2931

    
2932
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2933
		$section->addInput(new Form_Select(
2934
			'puremode',
2935
			'Minimum wireless standard',
2936
			$pconfig['puremode'],
2937
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2938
		))->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)');
2939
	} elseif (isset($wl_modes['11g'])) {
2940
		$section->addInput(new Form_Checkbox(
2941
			'puremode',
2942
			'802.11g only',
2943
			null,
2944
			$pconfig['puremode'],
2945
			'11g'
2946
		))->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)');
2947
	}
2948

    
2949
	$section->addInput(new Form_Checkbox(
2950
		'apbridge_enable',
2951
		'Allow intra-BSS communication',
2952
		'Allow packets to pass between wireless clients directly when operating as an access point',
2953
		$pconfig['apbridge_enable'],
2954
		'yes'
2955
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2956

    
2957
	$section->addInput(new Form_Checkbox(
2958
		'wme_enable',
2959
		'Enable WME',
2960
		'Force the card to use WME (wireless QoS)',
2961
		$pconfig['wme_enable'],
2962
		'yes'
2963
	));
2964

    
2965
	$section->addInput(new Form_Checkbox(
2966
		'hidessid_enable',
2967
		'Hide SSID',
2968
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2969
		$pconfig['hidessid_enable'],
2970
		'yes'
2971
	));
2972

    
2973
	$form->add($section);
2974

    
2975
	// WPA Section
2976
	$section = new Form_Section('WPA');
2977

    
2978
	$section->addInput(new Form_Checkbox(
2979
		'wpa_enable',
2980
		'Enable',
2981
		'Enable WPA',
2982
		$pconfig['wpa_enable'],
2983
		'yes'
2984
	));
2985

    
2986
	$section->addInput(new Form_Input(
2987
		'passphrase',
2988
		'WPA Pre-Shared Key',
2989
		'text',
2990
		$pconfig['passphrase']
2991
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2992

    
2993
	$section->addInput(new Form_Select(
2994
		'wpa_mode',
2995
		'WPA mode',
2996
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2997
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
2998
	));
2999

    
3000
	$section->addInput(new Form_Select(
3001
		'wpa_key_mgmt',
3002
		'WPA Key Management Mode',
3003
		$pconfig['wpa_key_mgmt'],
3004
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3005
	));
3006

    
3007
	$section->addInput(new Form_Select(
3008
		'wpa_pairwise',
3009
		'WPA Pairwise',
3010
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3011
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3012
	));
3013

    
3014
	$section->addInput(new Form_Input(
3015
		'wpa_group_rekey',
3016
		'WPA Pre-Shared Key',
3017
		'number',
3018
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3019
		['min' => '1', 'max' => 9999]
3020
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3021

    
3022
	$section->addInput(new Form_Input(
3023
		'wpa_gmk_rekey',
3024
		'Master Key Regeneration',
3025
		'number',
3026
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3027
		['min' => '1', 'max' => 9999]
3028
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3029

    
3030
	$section->addInput(new Form_Checkbox(
3031
		'wpa_strict_rekey',
3032
		'Strict Key Regeneration',
3033
		'Force the AP to rekey whenever a client disassociates',
3034
		$pconfig['wpa_strict_rekey'],
3035
		'yes'
3036
	));
3037

    
3038
	$form->add($section);
3039

    
3040
	$section = new Form_Section('802.1x RADIUS options');
3041

    
3042
	$section->addInput(new Form_Checkbox(
3043
		'ieee8021x',
3044
		'IEEE802.1X',
3045
		'Enable 802.1X authentication',
3046
		$pconfig['ieee8021x'],
3047
		'yes'
3048
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3049

    
3050
	$group = new Form_Group('Primary 802.1X server');
3051

    
3052
	$group->add(new Form_IpAddress(
3053
		'auth_server_addr',
3054
		'IP Address',
3055
		$pconfig['auth_server_addr']
3056
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3057

    
3058
	$group->add(new Form_Input(
3059
		'auth_server_port',
3060
		'Port',
3061
		'number',
3062
		$pconfig['auth_server_port']
3063
	))->setHelp('Server port. Leave blank for the default port 1812');
3064

    
3065
	$group->add(new Form_Input(
3066
		'auth_server_shared_secret',
3067
		'Shared secret',
3068
		'number',
3069
		$pconfig['auth_server_shared_secret']
3070
	))->setHelp('Shared secret');
3071

    
3072
	$section->add($group);
3073

    
3074
	$group = new Form_Group('Secondary 802.1X server');
3075

    
3076
	$group->add(new Form_IpAddress(
3077
		'auth_server_addr2',
3078
		'IP Address',
3079
		$pconfig['auth_server_addr2']
3080
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3081

    
3082
	$group->add(new Form_Input(
3083
		'auth_server_port2',
3084
		'Port',
3085
		'number',
3086
		$pconfig['auth_server_port2']
3087
	))->setHelp('Server port. Leave blank for the default port 1812');
3088

    
3089
	$group->add(new Form_Input(
3090
		'auth_server_shared_secret2',
3091
		'Shared secret',
3092
		'number',
3093
		$pconfig['auth_server_shared_secret2']
3094
	))->setHelp('Shared secret');
3095

    
3096
	$section->add($group);
3097

    
3098
	$section->addInput(new Form_Checkbox(
3099
		'rsn_preauth',
3100
		'Authentication Roaming Preauth',
3101
		null,
3102
		$pconfig['rsn_preauth'],
3103
		'yes'
3104
	));
3105

    
3106
	$form->add($section);
3107
}
3108

    
3109
$section = new Form_Section('Private networks');
3110

    
3111
$section->addInput(new Form_Checkbox(
3112
	'blockpriv',
3113
	'Block private networks',
3114
	'',
3115
	$pconfig['blockpriv'],
3116
	'yes'
3117
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3118
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3119
			'lies in such a private address space, too.');
3120

    
3121
$section->addInput(new Form_Checkbox(
3122
	'blockbogons',
3123
	'Block bogon networks',
3124
	'',
3125
	$pconfig['blockbogons'],
3126
	'yes'
3127
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3128
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3129
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3130

    
3131
$form->add($section);
3132

    
3133
$form->addGlobal(new Form_Input(
3134
	'if',
3135
	null,
3136
	'hidden',
3137
	$if
3138
));
3139

    
3140
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3141
	$form->addGlobal(new Form_Input(
3142
		'ppp_port',
3143
		null,
3144
		'hidden',
3145
		$pconfig['port']
3146
	));
3147
}
3148

    
3149
$form->addGlobal(new Form_Input(
3150
	'ptpid',
3151
	null,
3152
	'hidden',
3153
	$pconfig['ptpid']
3154
));
3155

    
3156

    
3157
// Add new gateway modal pop-up
3158
$modal = new Modal('New gateway', 'newgateway', 'large');
3159

    
3160
$modal->addInput(new Form_Checkbox(
3161
	'defaultgw',
3162
	'Default',
3163
	'Default gateway',
3164
	($if == "wan" || $if == "WAN")
3165
));
3166

    
3167
$modal->addInput(new Form_Input(
3168
	'name',
3169
	'Gateway name',
3170
	'text',
3171
	$wancfg['descr'] . "GW"
3172
));
3173

    
3174
$modal->addInput(new Form_IpAddress(
3175
	'gatewayip',
3176
	'Gateway IPv4',
3177
	null
3178
));
3179

    
3180
$modal->addInput(new Form_Input(
3181
	'gatewaydescr',
3182
	'Description',
3183
	'text'
3184
));
3185

    
3186
$btnaddgw = new Form_Button(
3187
	'add',
3188
	'Add'
3189
);
3190

    
3191
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3192

    
3193
$btncnxgw = new Form_Button(
3194
	'cnx',
3195
	'Cancel'
3196
);
3197

    
3198
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3199

    
3200
$modal->addInput(new Form_StaticText(
3201
	null,
3202
	$btnaddgw . $btncnxgw
3203
));
3204

    
3205
$form->add($modal);
3206

    
3207
print($form);
3208
?>
3209

    
3210
<script type="text/javascript">
3211
//<![CDATA[
3212
events.push(function() {
3213
	function updateType(t) {
3214

    
3215
		switch (t) {
3216
			case "none": {
3217
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3218
				break;
3219
			}
3220
			case "staticv4": {
3221
				$('.dhcpadvanced, .none, .dhcp').hide();
3222
				$('.pppoe, .pptp, .ppp').hide();
3223
				break;
3224
			}
3225
			case "dhcp": {
3226
				$('.dhcpadvanced, .none').hide();
3227
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3228
										//			about the staticv4 class
3229
				$('.pppoe, .pptp, .ppp').hide();
3230
				break;
3231
			}
3232
			case "ppp": {
3233
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3234
				country_list();
3235
				break;
3236
			}
3237
			case "pppoe": {
3238
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3239
				break;
3240
			}
3241
			case "l2tp":
3242
			case "pptp": {
3243
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3244
				$('.pptp').show();
3245
				break;
3246
			}
3247
		}
3248

    
3249
		if (t != "l2tp" && t != "pptp") {
3250
			$('.'+t).show();
3251
		}
3252
	}
3253

    
3254
	function updateTypeSix(t) {
3255
		if (!isNaN(t[0])) {
3256
			t = '_' + t;
3257
		}
3258

    
3259
		switch (t) {
3260
			case "none": {
3261
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3262
				break;
3263
			}
3264
			case "staticv6": {
3265
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3266
				break;
3267
			}
3268
			case "slaac": {
3269
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3270
				break;
3271
			}
3272
			case "dhcp6": {
3273
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3274
				break;
3275
			}
3276
			case "6rd_": {
3277
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3278
				break;
3279
			}
3280
			case "_6to4": {
3281
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3282
				break;
3283
			}
3284
			case "track6": {
3285
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3286
				update_track6_prefix();
3287
				break;
3288
			}
3289
		}
3290

    
3291
		if (t != "l2tp" && t != "pptp") {
3292
			$('.'+t).show();
3293
		}
3294
	}
3295

    
3296
	function show_reset_settings(reset_type) {
3297
		if (reset_type == 'preset') {
3298
			$('.pppoepreset').show();
3299
			$('.pppoecustom').hide();
3300
		} else if (reset_type == 'custom') {
3301
			$('.pppoecustom').show();
3302
			$('.pppoepreset').hide();
3303
		} else {
3304
			$('.pppoecustom').hide();
3305
			$('.pppoepreset').hide();
3306
		}
3307
	}
3308

    
3309
	function update_track6_prefix() {
3310
		var iface = $("#track6-interface").val();
3311
		if (iface == null) {
3312
			return;
3313
		}
3314

    
3315
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3316
		if (track6_prefix_ids == null) {
3317
			return;
3318
		}
3319

    
3320
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3321
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3322
	}
3323

    
3324
	// Create the new gateway from the data entered in the modal pop-up
3325
	function hide_add_gatewaysave() {
3326
		var iface = $('#if').val();
3327
		name = $('#name').val();
3328
		var descr = $('#gatewaydescr').val();
3329
		gatewayip = $('#gatewayip').val();
3330

    
3331
		var defaultgw = '';
3332
		if ($('#defaultgw').is(':checked')) {
3333
			defaultgw = '&defaultgw=on';
3334
		}
3335

    
3336
		var url = "system_gateways_edit.php";
3337
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3338
		$.ajax(
3339
			url,
3340
			{
3341
				type: 'post',
3342
				data: pars,
3343
				error: report_failure,
3344
				complete: save_callback
3345
			});
3346
		}
3347

    
3348
	function save_callback(response) {
3349
		if (response) {
3350
			var gwtext = escape(name) + " - " + gatewayip;
3351
			addOption($('#gateway'), gwtext, name);
3352
		} else {
3353
			report_failure();
3354
		}
3355

    
3356
		$("#newgateway").modal('hide');
3357
	}
3358

    
3359
	function report_failure(request, textStatus, errorThrown) {
3360
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3361
			alert(request.responseText);
3362
		} else {
3363
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3364
		}
3365

    
3366
		$("#newgateway").modal('hide');
3367
	}
3368

    
3369
	function addOption(selectbox, text, value) {
3370
		var optn = document.createElement("OPTION");
3371
		optn.text = text;
3372
		optn.value = value;
3373
		selectbox.append(optn);
3374
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3375
	}
3376

    
3377
	function hide_add_gatewaysave_v6() {
3378

    
3379
		var iface = $('#if').val();
3380
		name = $('#name6').val();
3381
		var descr = $('#gatewaydescr6').val();
3382
		gatewayip = $('#gatewayip6').val();
3383
		var defaultgw = '';
3384
		if ($('#defaultgw6').is(':checked')) {
3385
			defaultgw = '&defaultgw=on';
3386
		}
3387
		var url_v6 = "system_gateways_edit.php";
3388
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3389
		$.ajax(
3390
			url_v6,
3391
			{
3392
				type: 'post',
3393
				data: pars_v6,
3394
				error: report_failure_v6,
3395
				success: save_callback_v6
3396
			});
3397
	}
3398

    
3399

    
3400
	function addOption_v6(selectbox, text, value) {
3401
		var optn = document.createElement("OPTION");
3402
		optn.text = text;
3403
		optn.value = value;
3404
		selectbox.append(optn);
3405
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3406
	}
3407

    
3408
	function report_failure_v6(request, textStatus, errorThrown) {
3409
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3410
			alert(request.responseText);
3411
		} else {
3412
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3413
		}
3414

    
3415
		$("#newgateway6").modal('hide');
3416
	}
3417

    
3418
	function save_callback_v6(response_v6) {
3419
		if (response_v6) {
3420

    
3421
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3422
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3423
		} else {
3424
			report_failure_v6();
3425
		}
3426

    
3427
		$("#newgateway6").modal('hide');
3428
	}
3429

    
3430
	function country_list() {
3431
		$('#country').children().remove();
3432
		$('#provider_list').children().remove();
3433
		$('#providerplan').children().remove();
3434
		$.ajax("getserviceproviders.php",{
3435
			success: function(response) {
3436

    
3437
				var responseTextArr = response.split("\n");
3438
				responseTextArr.sort();
3439

    
3440
				responseTextArr.forEach( function(value) {
3441
					country = value.split(":");
3442
					$('#country').append($('<option>', {
3443
						value: country[1],
3444
						text : country[0]
3445
					}));
3446
				});
3447
			}
3448
		});
3449
	}
3450

    
3451
	function providers_list() {
3452
		$('#provider_list').children().remove();
3453
		$('#providerplan').children().remove();
3454
		$.ajax("getserviceproviders.php",{
3455
			type: 'post',
3456
			data: {country : $('#country').val()},
3457
			success: function(response) {
3458
				var responseTextArr = response.split("\n");
3459
				responseTextArr.sort();
3460
				responseTextArr.forEach( function(value) {
3461
					$('#provider_list').append($('<option>', {
3462
							value: value,
3463
							text : value
3464
					}));
3465
				});
3466
			}
3467
		});
3468
	}
3469

    
3470
	function providerplan_list() {
3471
		$('#providerplan').children().remove();
3472
		$.ajax("getserviceproviders.php",{
3473
			type: 'post',
3474
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3475
			success: function(response) {
3476
				var responseTextArr = response.split("\n");
3477
				responseTextArr.sort();
3478

    
3479
				$('#providerplan').append($('<option>', {
3480
					value: '',
3481
					text : ''
3482
				}));
3483

    
3484
				responseTextArr.forEach( function(value) {
3485
					if (value != "") {
3486
						providerplan = value.split(":");
3487

    
3488
						$('#providerplan').append($('<option>', {
3489
							value: providerplan[1],
3490
							text : providerplan[0] + " - " + providerplan[1]
3491
						}));
3492
					}
3493
				});
3494
			}
3495
		});
3496
	}
3497

    
3498
	function prefill_provider() {
3499
		$.ajax("getserviceproviders.php",{
3500
			type: 'post',
3501
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3502
			success: function(data, textStatus, response) {
3503
				var xmldoc = response.responseXML;
3504
				var provider = xmldoc.getElementsByTagName('connection')[0];
3505
				$('#ppp_username').val('');
3506
				$('#ppp_password').val('');
3507
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3508
					$('#phone').val('#777');
3509
					$('#apn').val('');
3510
				} else {
3511
					$('#phone').val('*99#');
3512
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3513
				}
3514
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3515
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3516
				$('#ppp_username').val(ppp_username);
3517
				$('#ppp_password').val(ppp_password);
3518
			}
3519
		});
3520
	}
3521

    
3522
	function show_dhcp6adv() {
3523
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3524
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3525

    
3526
		hideCheckbox('dhcp6usev4iface', ovr);
3527
		hideCheckbox('dhcp6prefixonly', ovr);
3528
		hideInput('dhcp6-ia-pd-len', ovr);
3529
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3530
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3531

    
3532
		hideClass('dhcp6advanced', !adv || ovr);
3533
	}
3534

    
3535
	function setDHCPoptions() {
3536
		var adv = $('#dhcpadv').prop('checked');
3537
		var ovr = $('#dhcpovr').prop('checked');
3538

    
3539
		if (ovr) {
3540
			hideInput('dhcphostname', true);
3541
			hideIpAddress('alias-address', true);
3542
			hideInput('dhcprejectfrom', true);
3543
			hideInput('adv_dhcp_config_file_override_path', false);
3544
			hideClass('dhcpadvanced', true);
3545
		} else {
3546
			hideInput('dhcphostname', false);
3547
			hideIpAddress('alias-address', false);
3548
			hideInput('dhcprejectfrom', false);
3549
			hideInput('adv_dhcp_config_file_override_path', true);
3550
			hideClass('dhcpadvanced', !adv);
3551
		}
3552
	}
3553

    
3554
	// DHCP preset actions
3555
	// Set presets from value of radio buttons
3556
	function setPresets(val) {
3557
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3558
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3559
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3560
		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']);?>");
3561
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3562
	}
3563

    
3564
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3565
		$('#adv_dhcp_pt_timeout').val(timeout);
3566
		$('#adv_dhcp_pt_retry').val(retry);
3567
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3568
		$('#adv_dhcp_pt_reboot').val(reboot);
3569
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3570
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3571
	}
3572

    
3573
	// ---------- On initial page load ------------------------------------------------------------
3574

    
3575
	updateType($('#type').val());
3576
	updateTypeSix($('#type6').val());
3577
	show_reset_settings($('#pppoe-reset-type').val());
3578
	$("#add").prop('type', 'button');
3579
	$("#cnx").prop('type', 'button');
3580
	$("#addgw").prop('type', 'button');
3581
	$("#add6").prop('type', 'button');
3582
	$("#cnx6").prop('type', 'button');
3583
	$("#addgw6").prop('type', 'button');
3584
	hideClass('dhcp6advanced', true);
3585
	hideClass('dhcpadvanced', true);
3586
	show_dhcp6adv();
3587
	setDHCPoptions()
3588

    
3589
	// Set preset buttons on page load
3590
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3591
	if (sv == "") {
3592
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3593
	} else {
3594
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3595
	}
3596

    
3597
	// Set preset from value
3598
	setPresets(sv);
3599

    
3600
	// ---------- Click checkbox handlers ---------------------------------------------------------
3601

    
3602
	$('#type').on('change', function() {
3603
		updateType(this.value);
3604
	});
3605

    
3606
	$('#type6').on('change', function() {
3607
		updateTypeSix(this.value);
3608
	});
3609

    
3610
	$('#pppoe-reset-type').on('change', function() {
3611
		show_reset_settings(this.value);
3612
	});
3613

    
3614
	$("#add").click(function() {
3615
		hide_add_gatewaysave();
3616
	});
3617

    
3618
	$("#cnx").click(function() {
3619
		$("#newgateway").modal('hide');
3620
	});
3621

    
3622
	$("#add6").click(function() {
3623
		hide_add_gatewaysave_v6();
3624
	});
3625

    
3626
	$("#cnx6").click(function() {
3627
		$("#newgateway6").modal('hide');
3628
	});
3629

    
3630
	$('#country').on('change', function() {
3631
		providers_list();
3632
	});
3633

    
3634
	$('#provider_list').on('change', function() {
3635
		providerplan_list();
3636
	});
3637

    
3638
	$('#providerplan').on('change', function() {
3639
		prefill_provider();
3640
	});
3641

    
3642
	$('#dhcpadv, #dhcpovr').click(function () {
3643
		setDHCPoptions();
3644
	});
3645

    
3646
	$('#adv_dhcp6_config_advanced').click(function () {
3647
		show_dhcp6adv();
3648
	});
3649

    
3650
	$('#adv_dhcp6_config_file_override').click(function () {
3651
		show_dhcp6adv();
3652
	});
3653

    
3654
	// On click . .
3655
	$('[name=adv_dhcp_pt_values]').click(function () {
3656
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3657
	});
3658

    
3659
});
3660
//]]>
3661
</script>
3662

    
3663
<?php include("foot.inc");
(69-69/229)