Project

General

Profile

Download (123 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004-2008 Scott Ullrich
9
 *	Copyright (c) 2006 Daniel S. Haischt
10
 *	Copyright (c) 2008-2010 Ermal Luçi
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
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
61
	pfSense_MODULE: interfaces
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-interfaces
66
##|*NAME=Interfaces: WAN page
67
##|*DESCR=Allow access to the 'Interfaces' page.
68
##|*MATCH=interfaces.php*
69
##|-PRIV
70

    
71
require_once("guiconfig.inc");
72
require_once("ipsec.inc");
73
require_once("functions.inc");
74
require_once("captiveportal.inc");
75
require_once("filter.inc");
76
require_once("shaper.inc");
77
require_once("rrd.inc");
78
require_once("vpn.inc");
79
require_once("xmlparse_attr.inc");
80

    
81
define("ALLOWWEP", false);
82
define("ANTENNAS", false);
83

    
84
if (isset($_POST['referer'])) {
85
	$referer = $_POST['referer'];
86
} else {
87
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
88
}
89

    
90
// Get configured interface list
91
$ifdescrs = get_configured_interface_with_descr(false, true);
92

    
93
$if = "wan";
94
if ($_REQUEST['if']) {
95
	$if = $_REQUEST['if'];
96
}
97

    
98
if (empty($ifdescrs[$if])) {
99
	header("Location: interfaces.php");
100
	exit;
101
}
102

    
103
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
104
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
105
define("CRON_DAILY_PATTERN", "0 0 * * *");
106
define("CRON_HOURLY_PATTERN", "0 * * * *");
107

    
108
if (!is_array($pconfig)) {
109
	$pconfig = array();
110
}
111

    
112
if (!is_array($config['ppps'])) {
113
	$config['ppps'] = array();
114
}
115
if (!is_array($config['ppps']['ppp'])) {
116
	$config['ppps']['ppp'] = array();
117
}
118
$a_ppps = &$config['ppps']['ppp'];
119

    
120
function remove_bad_chars($string) {
121
	return preg_replace('/[^a-z_0-9]/i', '', $string);
122
}
123

    
124
if (!is_array($config['gateways']['gateway_item'])) {
125
	$config['gateways']['gateway_item'] = array();
126
}
127
$a_gateways = &$config['gateways']['gateway_item'];
128

    
129
$wancfg = &$config['interfaces'][$if];
130
$old_wancfg = $wancfg;
131
$old_wancfg['realif'] = get_real_interface($if);
132
$old_ppps = $a_ppps;
133
// Populate page descr if it does not exist.
134
if ($if == "wan" && !$wancfg['descr']) {
135
	$wancfg['descr'] = "WAN";
136
} else if ($if == "lan" && !$wancfg['descr']) {
137
	$wancfg['descr'] = "LAN";
138
}
139

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

    
147
$type_disabled = (substr($wancfg['if'], 0, 3) == 'gre') ? 'disabled="disabled"' : '';
148

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

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

    
166
		/* ================================================ */
167
		/* = force a connection reset at a specific time? = */
168
		/* ================================================ */
169

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

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

    
235
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
236

    
237
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
238
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
239
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
240
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
241

    
242
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
243
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
244
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
245

    
246
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
247
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
248
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
249
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
250

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

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

    
263
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
264
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
265

    
266
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
267
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
268
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
269
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
270

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

    
277
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
278
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
279
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
280

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

    
285
if (is_array($config['aliases']['alias'])) {
286
	foreach ($config['aliases']['alias'] as $alias) {
287
		if ($alias['name'] == $wancfg['descr']) {
288
			$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $wancfg['descr']);
289
		}
290
	}
291
}
292

    
293
switch ($wancfg['ipaddr']) {
294
	case "dhcp":
295
		$pconfig['type'] = "dhcp";
296
		break;
297
	case "pppoe":
298
	case "pptp":
299
	case "l2tp":
300
	case "ppp":
301
		$pconfig['type'] = $wancfg['ipaddr'];
302
		break;
303
	default:
304
		if (is_ipaddrv4($wancfg['ipaddr'])) {
305
			$pconfig['type'] = "staticv4";
306
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
307
			$pconfig['subnet'] = $wancfg['subnet'];
308
			$pconfig['gateway'] = $wancfg['gateway'];
309
		} else {
310
			$pconfig['type'] = "none";
311
		}
312
		break;
313
}
314

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

    
364
// print_r($pconfig);
365

    
366
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
367
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
368
$pconfig['spoofmac'] = $wancfg['spoofmac'];
369
$pconfig['mtu'] = $wancfg['mtu'];
370
$pconfig['mss'] = $wancfg['mss'];
371

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

    
449
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
450

    
451
	if(ALLOWWEP) {
452
		$pconfig['wep_enable'] = isset($wancfg['wireless']['wep']['enable']);
453

    
454
		if (is_array($wancfg['wireless']['wep']) && is_array($wancfg['wireless']['wep']['key'])) {
455
			$i = 1;
456
			foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
457
				$pconfig['key' . $i] = $wepkey['value'];
458
				if (isset($wepkey['txkey'])) {
459
					$pconfig['txkey'] = $i;
460
				}
461
				$i++;
462
			}
463
			if (!isset($wepkey['txkey'])) {
464
				$pconfig['txkey'] = 1;
465
			}
466
		}
467
	}
468
}
469

    
470
if ($_POST['apply']) {
471
	unset($input_errors);
472
	if (!is_subsystem_dirty('interfaces')) {
473
		$input_errors[] = gettext("You have already applied your settings!");
474
	} else {
475
		unlink_if_exists("{$g['tmp_path']}/config.cache");
476
		clear_subsystem_dirty('interfaces');
477

    
478
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
479
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
480
			foreach ($toapplylist as $ifapply => $ifcfgo) {
481
				if (isset($config['interfaces'][$ifapply]['enable'])) {
482
					interface_bring_down($ifapply, false, $ifcfgo);
483
					interface_configure($ifapply, true);
484
				} else {
485
					interface_bring_down($ifapply, true, $ifcfgo);
486
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
487
						isset($config['dhcpdv6'][$ifapply]['enable'])) {
488
						services_dhcpd_configure();
489
					}
490
				}
491
			}
492
		}
493
		/* restart snmp so that it binds to correct address */
494
		services_snmpd_configure();
495

    
496
		/* sync filter configuration */
497
		setup_gateways_monitor();
498

    
499
		clear_subsystem_dirty('interfaces');
500

    
501
		filter_configure();
502

    
503
		enable_rrd_graphing();
504

    
505
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
506
			clear_subsystem_dirty('staticroutes');
507
		}
508
	}
509
	@unlink("{$g['tmp_path']}/.interfaces.apply");
510
	header("Location: interfaces.php?if={$if}");
511
	exit;
512
} else if ($_POST && $_POST['enable'] != "yes") {
513
	unset($wancfg['enable']);
514
	if (isset($wancfg['wireless'])) {
515
		interface_sync_wireless_clones($wancfg, false);
516
	}
517
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
518
	mark_subsystem_dirty('interfaces');
519
	if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
520
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
521
	} else {
522
		$toapplylist = array();
523
	}
524
	$toapplylist[$if]['ifcfg'] = $wancfg;
525
	$toapplylist[$if]['ppps'] = $a_ppps;
526
	/* we need to be able remove IP aliases for IPv6 */
527
	file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
528
	header("Location: interfaces.php?if={$if}");
529
	exit;
530
} else if ($_POST) {
531

    
532
	unset($input_errors);
533
	$pconfig = $_POST;
534

    
535
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
536
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
537
	} else {
538
		$pconfig['track6-prefix-id'] = 0;
539
	}
540
	conf_mount_rw();
541

    
542
	/* filter out spaces from descriptions */
543
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
544

    
545
	/* okay first of all, cause we are just hiding the PPPoE HTML
546
	 * fields related to PPPoE resets, we are going to unset $_POST
547
	 * vars, if the reset feature should not be used. Otherwise the
548
	 * data validation procedure below, may trigger a false error
549
	 * message.
550
	 */
551
	if (empty($_POST['pppoe-reset-type'])) {
552
		unset($_POST['pppoe_pr_type']);
553
		unset($_POST['pppoe_resethour']);
554
		unset($_POST['pppoe_resetminute']);
555
		unset($_POST['pppoe_resetdate']);
556
		unset($_POST['pppoe_pr_preset_val']);
557
	}
558
	/* description unique? */
559
	foreach ($ifdescrs as $ifent => $ifdescr) {
560
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
561
			$input_errors[] = gettext("An interface with the specified description already exists.");
562
			break;
563
		}
564
	}
565
	if (is_numeric($_POST['descr'])) {
566
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
567
	}
568
	/* input validation */
569
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
570
		$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.");
571
	}
572
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
573
		$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.");
574
	}
575

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

    
683
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
684
				$input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID.");
685
			} else {
686
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
687
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
688
					$input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range.") .
689
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
690
				} else {
691
					foreach ($ifdescrs as $ifent => $ifdescr) {
692
						if ($if == $ifent) {
693
							continue;
694
						}
695
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
696
							$config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
697
							$config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
698
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
699
						}
700
					}
701
				}
702
			}
703
			break;
704
	}
705

    
706
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
707
	$staticroutes = get_staticroutes(true);
708
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
709
	if ($_POST['ipaddr']) {
710
		if (!is_ipaddrv4($_POST['ipaddr'])) {
711
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
712
		} else {
713
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
714
			if (count($where_ipaddr_configured)) {
715
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
716
				foreach ($where_ipaddr_configured as $subnet_conflict) {
717
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
718
				}
719
				$input_errors[] = $subnet_conflict_text;
720
			}
721

    
722
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
723
			if ($_POST['subnet'] < 31) {
724
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
725
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
726
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
727
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
728
				}
729
			}
730

    
731
			foreach ($staticroutes as $route_subnet) {
732
				list($network, $subnet) = explode("/", $route_subnet);
733
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
734
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
735
					break;
736
				}
737
				unset($network, $subnet);
738
			}
739
		}
740
	}
741
	if ($_POST['ipaddrv6']) {
742
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
743
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
744
		} else {
745
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
746
			if (count($where_ipaddr_configured)) {
747
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
748
				foreach ($where_ipaddr_configured as $subnet_conflict) {
749
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
750
				}
751
				$input_errors[] = $subnet_conflict_text;
752
			}
753

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

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

    
843
		unset($min_mtu, $max_mtu);
844

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

    
861
				$realhwif_array = get_parent_interface($ifdata['if']);
862
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
863
				$parent_realhwif = $realhwif_array[0];
864

    
865
				if ($parent_realhwif != $wancfg['if']) {
866
					continue;
867
				}
868

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

    
956
		if(ALLOWWEP) {
957
			/* loop through keys and enforce size */
958
			for ($i = 1; $i <= 4; $i++) {
959
				if ($_POST['key' . $i]) {
960
					/* 64 bit */
961
					if (strlen($_POST['key' . $i]) == 5) {
962
						continue;
963
					}
964

    
965
					if (strlen($_POST['key' . $i]) == 10) {
966
						/* hex key */
967
						if (stristr($_POST['key' . $i], "0x") == false) {
968
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
969
						}
970
						continue;
971
					}
972

    
973
					if (strlen($_POST['key' . $i]) == 12) {
974
						/* hex key */
975
						if (stristr($_POST['key' . $i], "0x") == false) {
976
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
977
						}
978
						continue;
979
					}
980

    
981
					/* 128 bit */
982
					if (strlen($_POST['key' . $i]) == 13) {
983
						continue;
984
					}
985

    
986
					if (strlen($_POST['key' . $i]) == 26) {
987
						/* hex key */
988
						if (stristr($_POST['key' . $i], "0x") == false) {
989
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
990
						}
991
						continue;
992
					}
993

    
994
					if (strlen($_POST['key' . $i]) == 28) {
995
						continue;
996
					}
997

    
998
					$input_errors[] = gettext("Invalid WEP key. Enter a valid 40, 64, 104 or 128 bit WEP key.");
999
					break;
1000
				}
1001
			}
1002
		}
1003

    
1004
		if ($_POST['passphrase']) {
1005
			$passlen = strlen($_POST['passphrase']);
1006
			if ($passlen < 8 || $passlen > 63) {
1007
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1008
			}
1009
		}
1010

    
1011
		if ($_POST['wpa_enable'] == "yes") {
1012
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1013
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1014
			}
1015
		}
1016
	}
1017
	if (!$input_errors) {
1018
		if ($wancfg['ipaddr'] != $_POST['type']) {
1019
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1020
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1021
				unset($a_ppps[$pppid]);
1022
			} else if ($wancfg['ipaddr'] == "dhcp") {
1023
				kill_dhclient_process($wancfg['if']);
1024
			}
1025
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1026
				$pid = find_dhcp6c_process($wancfg['if']);
1027
				if ($pid) {
1028
					posix_kill($pid, SIGTERM);
1029
				}
1030
			}
1031
		}
1032
		$ppp = array();
1033
		if ($wancfg['ipaddr'] != "ppp") {
1034
			unset($wancfg['ipaddr']);
1035
		}
1036
		if ($wancfg['ipaddrv6'] != "ppp") {
1037
			unset($wancfg['ipaddrv6']);
1038
		}
1039
		unset($wancfg['subnet']);
1040
		unset($wancfg['gateway']);
1041
		unset($wancfg['subnetv6']);
1042
		unset($wancfg['gatewayv6']);
1043
		unset($wancfg['dhcphostname']);
1044
		unset($wancfg['dhcprejectfrom']);
1045
		unset($wancfg['dhcp6-duid']);
1046
		unset($wancfg['dhcp6-ia-pd-len']);
1047
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1048
		unset($wancfg['dhcp6prefixonly']);
1049
		unset($wancfg['dhcp6usev4iface']);
1050
		unset($wancfg['track6-interface']);
1051
		unset($wancfg['track6-prefix-id']);
1052
		unset($wancfg['prefix-6rd']);
1053
		unset($wancfg['prefix-6rd-v4plen']);
1054
		unset($wancfg['gateway-6rd']);
1055

    
1056
		unset($wancfg['adv_dhcp_pt_timeout']);
1057
		unset($wancfg['adv_dhcp_pt_retry']);
1058
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1059
		unset($wancfg['adv_dhcp_pt_reboot']);
1060
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1061
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1062

    
1063
		unset($wancfg['adv_dhcp_pt_values']);
1064

    
1065
		unset($wancfg['adv_dhcp_send_options']);
1066
		unset($wancfg['adv_dhcp_request_options']);
1067
		unset($wancfg['adv_dhcp_required_options']);
1068
		unset($wancfg['adv_dhcp_option_modifiers']);
1069

    
1070
		unset($wancfg['adv_dhcp_config_advanced']);
1071
		unset($wancfg['adv_dhcp_config_file_override']);
1072
		unset($wancfg['adv_dhcp_config_file_override_path']);
1073

    
1074
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1075
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1076
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1077
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1078

    
1079
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1080
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1081
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1082
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1083
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1084

    
1085
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1086
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1087
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1088
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1089
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1090

    
1091
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1092
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1093

    
1094
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1095
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1096
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1097
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1098

    
1099
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1100
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1101
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1102
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1103
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1104

    
1105
		unset($wancfg['adv_dhcp6_config_advanced']);
1106
		unset($wancfg['adv_dhcp6_config_file_override']);
1107
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1108

    
1109
		unset($wancfg['pppoe_password']);
1110
		unset($wancfg['pptp_username']);
1111
		unset($wancfg['pptp_password']);
1112
		unset($wancfg['provider']);
1113
		unset($wancfg['ondemand']);
1114
		unset($wancfg['timeout']);
1115
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1116
			unset($wancfg['pppoe']['pppoe-reset-type']);
1117
		}
1118
		unset($wancfg['local']);
1119

    
1120
		unset($wancfg['remote']);
1121
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1122
			if ($wancfg['ipaddr'] != 'ppp') {
1123
				unset($a_ppps[$pppid]['apn']);
1124
				unset($a_ppps[$pppid]['phone']);
1125
				unset($a_ppps[$pppid]['provider']);
1126
				unset($a_ppps[$pppid]['ondemand']);
1127
			}
1128
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1129
				unset($a_ppps[$pppid]['localip']);
1130
				unset($a_ppps[$pppid]['subnet']);
1131
				unset($a_ppps[$pppid]['gateway']);
1132
			}
1133
			if ($wancfg['ipaddr'] != 'pppoe') {
1134
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1135
			}
1136
			if ($wancfg['type'] != $_POST['type']) {
1137
				unset($a_ppps[$pppid]['idletimeout']);
1138
			}
1139
		}
1140

    
1141
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1142
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1143

    
1144
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1145
		switch ($_POST['type']) {
1146
			case "staticv4":
1147
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1148
				$wancfg['subnet'] = $_POST['subnet'];
1149
				if ($_POST['gateway'] != "none") {
1150
					$wancfg['gateway'] = $_POST['gateway'];
1151
				}
1152
				break;
1153
			case "dhcp":
1154
				$wancfg['ipaddr'] = "dhcp";
1155
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1156
				$wancfg['alias-address'] = $_POST['alias-address'];
1157
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1158
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1159

    
1160
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1161
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1162
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1163
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1164
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1165
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1166

    
1167
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1168

    
1169
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1170
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1171
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1172
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1173

    
1174
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1175
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1176
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1177

    
1178
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1179
				if ($gateway_item) {
1180
					$a_gateways[] = $gateway_item;
1181
				}
1182
				break;
1183
			case "ppp":
1184
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1185
				$a_ppps[$pppid]['type'] = $_POST['type'];
1186
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1187
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1188
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1189
				$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1190
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1191
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1192
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1193
				$wancfg['ipaddr'] = $_POST['type'];
1194
				break;
1195

    
1196
			case "pppoe":
1197
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1198
				$a_ppps[$pppid]['type'] = $_POST['type'];
1199
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1200
				if (isset($_POST['ppp_port'])) {
1201
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1202
				} else {
1203
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1204
				}
1205
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1206
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1207
				if (!empty($_POST['provider'])) {
1208
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1209
				} else {
1210
					$a_ppps[$pppid]['provider'] = true;
1211
				}
1212
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1213
				if (!empty($_POST['pppoe_idletimeout'])) {
1214
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1215
				} else {
1216
					unset($a_ppps[$pppid]['idletimeout']);
1217
				}
1218

    
1219
				if (!empty($_POST['pppoe-reset-type'])) {
1220
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1221
				} else {
1222
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1223
				}
1224
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1225
				$wancfg['ipaddr'] = $_POST['type'];
1226
				if ($gateway_item) {
1227
					$a_gateways[] = $gateway_item;
1228
				}
1229

    
1230
				break;
1231
			case "pptp":
1232
			case "l2tp":
1233
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1234
				$a_ppps[$pppid]['type'] = $_POST['type'];
1235
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1236
				if (isset($_POST['ppp_port'])) {
1237
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1238
				} else {
1239
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1240
				}
1241
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1242
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1243
				$a_ppps[$pppid]['localip'] = $_POST['pptp_local'];
1244
				$a_ppps[$pppid]['subnet'] = $_POST['pptp_subnet'];
1245
				$a_ppps[$pppid]['gateway'] = $_POST['pptp_remote'];
1246
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1247
				if (!empty($_POST['pptp_idletimeout'])) {
1248
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1249
				} else {
1250
					unset($a_ppps[$pppid]['idletimeout']);
1251
				}
1252
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1253
				$wancfg['ipaddr'] = $_POST['type'];
1254
				if ($gateway_item) {
1255
					$a_gateways[] = $gateway_item;
1256
				}
1257
				break;
1258
			case "none":
1259
				break;
1260
		}
1261
		switch ($_POST['type6']) {
1262
			case "staticv6":
1263
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1264
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1265
				if ($_POST['gatewayv6'] != "none") {
1266
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1267
				}
1268
				break;
1269
			case "slaac":
1270
				$wancfg['ipaddrv6'] = "slaac";
1271
				break;
1272
			case "dhcp6":
1273
				$wancfg['ipaddrv6'] = "dhcp6";
1274
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1275
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1276
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1277
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1278
				}
1279
				if ($_POST['dhcp6prefixonly'] == "yes") {
1280
					$wancfg['dhcp6prefixonly'] = true;
1281
				}
1282
				if ($_POST['dhcp6usev4iface'] == "yes") {
1283
					$wancfg['dhcp6usev4iface'] = true;
1284
				}
1285

    
1286
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1287
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1288
				}
1289
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1290
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1291
				}
1292
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1293
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1294
				}
1295
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1296
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1297
				}
1298

    
1299
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1300
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1301
				}
1302
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1303
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1304
				}
1305
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1306
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1307
				}
1308
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1309
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1310
				}
1311
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1312
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1313
				}
1314

    
1315
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1316
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1317
				}
1318
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1319
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1320
				}
1321
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1322
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1323
				}
1324
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1325
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1326
				}
1327
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1328
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1329
				}
1330

    
1331
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1332
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1333
				}
1334
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1335
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1336
				}
1337

    
1338
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1339
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1340
				}
1341
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1342
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1343
				}
1344
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1345
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1346
				}
1347
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1348
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1349
				}
1350

    
1351
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1352
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1353
				}
1354
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1355
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1356
				}
1357
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1358
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1359
				}
1360
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1361
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1362
				}
1363
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1364
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1365
				}
1366

    
1367
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1368
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1369
				}
1370
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1371
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1372
				}
1373
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1374
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1375
				}
1376

    
1377
				if ($gateway_item) {
1378
					$a_gateways[] = $gateway_item;
1379
				}
1380
				break;
1381
			case "6rd":
1382
				$wancfg['ipaddrv6'] = "6rd";
1383
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1384
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1385
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1386
				if ($gateway_item) {
1387
					$a_gateways[] = $gateway_item;
1388
				}
1389
				break;
1390
			case "6to4":
1391
				$wancfg['ipaddrv6'] = "6to4";
1392
				break;
1393
			case "track6":
1394
				$wancfg['ipaddrv6'] = "track6";
1395
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1396
				if ($_POST['track6-prefix-id--hex'] === "") {
1397
					$wancfg['track6-prefix-id'] = 0;
1398
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1399
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1400
				} else {
1401
					$wancfg['track6-prefix-id'] = 0;
1402
				}
1403
				break;
1404
			case "none":
1405
				break;
1406
		}
1407
		handle_pppoe_reset($_POST);
1408

    
1409
		if ($_POST['blockpriv'] == "yes") {
1410
			$wancfg['blockpriv'] = true;
1411
		} else {
1412
			unset($wancfg['blockpriv']);
1413
		}
1414
		if ($_POST['blockbogons'] == "yes") {
1415
			$wancfg['blockbogons'] = true;
1416
		} else {
1417
			unset($wancfg['blockbogons']);
1418
		}
1419
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1420
		if (empty($_POST['mtu'])) {
1421
			unset($wancfg['mtu']);
1422
		} else {
1423
			$wancfg['mtu'] = $_POST['mtu'];
1424
		}
1425
		if (empty($_POST['mss'])) {
1426
			unset($wancfg['mss']);
1427
		} else {
1428
			$wancfg['mss'] = $_POST['mss'];
1429
		}
1430
		if (empty($_POST['mediaopt'])) {
1431
			unset($wancfg['media']);
1432
			unset($wancfg['mediaopt']);
1433
		} else {
1434
			$mediaopts = explode(' ', $_POST['mediaopt']);
1435
			if ($mediaopts[0] != '') {
1436
				$wancfg['media'] = $mediaopts[0];
1437
			}
1438
			if ($mediaopts[1] != '') {
1439
				$wancfg['mediaopt'] = $mediaopts[1];
1440
			} else {
1441
				unset($wancfg['mediaopt']);
1442
			}
1443
		}
1444
		if (isset($wancfg['wireless'])) {
1445
			handle_wireless_post();
1446
		}
1447

    
1448
		conf_mount_ro();
1449
		write_config();
1450

    
1451
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1452
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1453
		} else {
1454
			$toapplylist = array();
1455
		}
1456
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1457
		$toapplylist[$if]['ppps'] = $old_ppps;
1458
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1459

    
1460
		mark_subsystem_dirty('interfaces');
1461

    
1462
		/* regenerate cron settings/crontab file */
1463
		configure_cron();
1464

    
1465
		header("Location: interfaces.php?if={$if}");
1466
		exit;
1467
	}
1468

    
1469
} // end if ($_POST)
1470

    
1471
function handle_wireless_post() {
1472
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1473
	if (!is_array($wancfg['wireless'])) {
1474
		$wancfg['wireless'] = array();
1475
	}
1476
	$wancfg['wireless']['standard'] = $_POST['standard'];
1477
	$wancfg['wireless']['mode'] = $_POST['mode'];
1478
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1479
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1480
	$wancfg['wireless']['channel'] = $_POST['channel'];
1481
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1482
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1483
	$wancfg['wireless']['distance'] = $_POST['distance'];
1484
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1485
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1486
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1487
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1488
		foreach ($wl_countries_attr as $wl_country) {
1489
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1490
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1491
				break;
1492
			}
1493
		}
1494
	}
1495
	if (!is_array($wancfg['wireless']['wpa'])) {
1496
		$wancfg['wireless']['wpa'] = array();
1497
	}
1498
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1499
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
1500
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1501
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1502
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1503
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1504
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1505
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1506
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1507
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1508
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1509
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1510
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1511
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1512
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1513

    
1514
	if ($_POST['persistcommonwireless'] == "yes") {
1515
		if (!is_array($config['wireless'])) {
1516
			$config['wireless'] = array();
1517
		}
1518
		if (!is_array($config['wireless']['interfaces'])) {
1519
			$config['wireless']['interfaces'] = array();
1520
		}
1521
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1522
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1523
		}
1524
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1525
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1526
	}
1527
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1528
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1529
	} else if (isset($wancfg['wireless']['diversity'])) {
1530
		unset($wancfg['wireless']['diversity']);
1531
	}
1532
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1533
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1534
	} else if (isset($wancfg['wireless']['txantenna'])) {
1535
		unset($wancfg['wireless']['txantenna']);
1536
	}
1537
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1538
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1539
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1540
		unset($wancfg['wireless']['rxantenna']);
1541
	}
1542
	if ($_POST['hidessid_enable'] == "yes") {
1543
		$wancfg['wireless']['hidessid']['enable'] = true;
1544
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1545
		unset($wancfg['wireless']['hidessid']['enable']);
1546
	}
1547
	if ($_POST['mac_acl_enable'] == "yes") {
1548
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1549
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1550
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1551
	}
1552
	if ($_POST['rsn_preauth'] == "yes") {
1553
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1554
	} else {
1555
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1556
	}
1557
	if ($_POST['ieee8021x'] == "yes") {
1558
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1559
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1560
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1561
	}
1562
	if ($_POST['wpa_strict_rekey'] == "yes") {
1563
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1564
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1565
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1566
	}
1567
	if ($_POST['debug_mode'] == "yes") {
1568
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1569
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1570
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1571
	}
1572
	if ($_POST['wpa_enable'] == "yes") {
1573
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1574
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1575
		unset($wancfg['wireless']['wpa']['enable']);
1576
	}
1577

    
1578
	if(ALLOWWEP) {
1579
		if ($_POST['wep_enable'] == "yes") {
1580
			if (!is_array($wancfg['wireless']['wep'])) {
1581
				$wancfg['wireless']['wep'] = array();
1582
			}
1583
			$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
1584
		} else if (isset($wancfg['wireless']['wep'])) {
1585
			unset($wancfg['wireless']['wep']);
1586
		}
1587
	}
1588

    
1589
	if ($_POST['wme_enable'] == "yes") {
1590
		if (!is_array($wancfg['wireless']['wme'])) {
1591
			$wancfg['wireless']['wme'] = array();
1592
		}
1593
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1594
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1595
		unset($wancfg['wireless']['wme']['enable']);
1596
	}
1597
	if ($_POST['puremode'] == "11g") {
1598
		if (!is_array($wancfg['wireless']['pureg'])) {
1599
			$wancfg['wireless']['pureg'] = array();
1600
		}
1601
		$wancfg['wireless']['pureg']['enable'] = true;
1602
	} else if ($_POST['puremode'] == "11n") {
1603
		if (!is_array($wancfg['wireless']['puren'])) {
1604
			$wancfg['wireless']['puren'] = array();
1605
		}
1606
		$wancfg['wireless']['puren']['enable'] = true;
1607
	} else {
1608
		if (isset($wancfg['wireless']['pureg'])) {
1609
			unset($wancfg['wireless']['pureg']);
1610
		}
1611
		if (isset($wancfg['wireless']['puren'])) {
1612
			unset($wancfg['wireless']['puren']);
1613
		}
1614
	}
1615
	if ($_POST['apbridge_enable'] == "yes") {
1616
		if (!is_array($wancfg['wireless']['apbridge'])) {
1617
			$wancfg['wireless']['apbridge'] = array();
1618
		}
1619
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1620
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1621
		unset($wancfg['wireless']['apbridge']['enable']);
1622
	}
1623
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1624
		if (!is_array($wancfg['wireless']['turbo'])) {
1625
			$wancfg['wireless']['turbo'] = array();
1626
		}
1627
		$wancfg['wireless']['turbo']['enable'] = true;
1628
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1629
		unset($wancfg['wireless']['turbo']['enable']);
1630
	}
1631

    
1632
	if(ALLOWWEP) {
1633
		$wancfg['wireless']['wep']['key'] = array();
1634
		for ($i = 1; $i <= 4; $i++) {
1635
			if ($_POST['key' . $i]) {
1636
				$newkey = array();
1637
				$newkey['value'] = $_POST['key' . $i];
1638
				if ($_POST['txkey'] == $i) {
1639
					$newkey['txkey'] = true;
1640
				}
1641
				$wancfg['wireless']['wep']['key'][] = $newkey;
1642
			}
1643
		}
1644
	}
1645

    
1646
	interface_sync_wireless_clones($wancfg, true);
1647
}
1648

    
1649
function check_wireless_mode() {
1650
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1651

    
1652
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1653
		return;
1654
	}
1655

    
1656
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1657
		$clone_count = 1;
1658
	} else {
1659
		$clone_count = 0;
1660
	}
1661

    
1662
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1663
		foreach ($config['wireless']['clone'] as $clone) {
1664
			if ($clone['if'] == $wlanbaseif) {
1665
				$clone_count++;
1666
			}
1667
		}
1668
	}
1669

    
1670
	if ($clone_count > 1) {
1671
		$old_wireless_mode = $wancfg['wireless']['mode'];
1672
		$wancfg['wireless']['mode'] = $_POST['mode'];
1673
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1674
			$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']]);
1675
		} else {
1676
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1677
		}
1678
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1679
	}
1680
}
1681

    
1682
// Find all possible media options for the interface
1683
$mediaopts_list = array();
1684
$intrealname = $config['interfaces'][$if]['if'];
1685
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1686
foreach ($mediaopts as $mediaopt) {
1687
	preg_match("/media (.*)/", $mediaopt, $matches);
1688
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1689
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1690
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1691
	} else {
1692
		// there is only media like "media 1000baseT"
1693
		array_push($mediaopts_list, $matches[1]);
1694
	}
1695
}
1696

    
1697
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1698
$shortcut_section = "interfaces";
1699

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

    
1703
$closehead = false;
1704

    
1705
// Get the MAC address
1706
$ip = $_SERVER['REMOTE_ADDR'];
1707
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1708
$mymac = str_replace("\n", "", $mymac);
1709

    
1710
function build_mediaopts_list() {
1711
	global $mediaopts_list;
1712

    
1713
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1714
			 " " =>	 "------- Media Supported by this interface -------"
1715
			];
1716

    
1717
	foreach ($mediaopts_list as $mediaopt) {
1718
		$list[$mediaopt] = $mediaopt;
1719
	}
1720

    
1721
	return($list);
1722
}
1723

    
1724
function build_gateway_list() {
1725
	global $a_gateways;
1726

    
1727
	$list = array("none" => "None");
1728
	foreach ($a_gateways as $gateway) {
1729
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1730
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1731
		}
1732
	}
1733

    
1734
	return($list);
1735
}
1736

    
1737
include("head.inc");
1738

    
1739
if ($input_errors)
1740
	print_input_errors($input_errors);
1741

    
1742
if (is_subsystem_dirty('interfaces'))
1743
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1744
					  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."));
1745

    
1746
if ($savemsg)
1747
	print_info_box($savemsg, 'success');
1748

    
1749

    
1750
require_once('classes/Form.class.php');
1751
require_once('classes/Modal.class.php');
1752

    
1753
$form = new Form(new Form_Button(
1754
	'Submit',
1755
	gettext("Save")
1756
));
1757

    
1758
$section = new Form_Section('General configuration');
1759

    
1760
$section->addInput(new Form_Checkbox(
1761
	'enable',
1762
	'Enable',
1763
	'Enable interface',
1764
	$pconfig['enable'],
1765
	'yes'
1766
));
1767

    
1768
$section->addInput(new Form_Input(
1769
	'descr',
1770
	'Description',
1771
	'text',
1772
	$pconfig['descr']
1773
))->setHelp('Enter a description (name) for the interface here.');
1774

    
1775
$section->addInput(new Form_Select(
1776
	'type',
1777
	'IPv4 Configuration Type',
1778
	$pconfig['type'],
1779
	$types4
1780
));
1781

    
1782
$section->addInput(new Form_Select(
1783
	'type6',
1784
	'IPv6 Configuration Type',
1785
	$pconfig['type6'],
1786
	$types6
1787
));
1788

    
1789
$macaddress = new Form_Input(
1790
	'mac',
1791
	'MAC Address',
1792
	'text',
1793
	$pconfig['mac'],
1794
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1795
);
1796

    
1797
$btnmymac = new Form_Button(
1798
	'btnmymac',
1799
	'Copy My MAC'
1800
	);
1801

    
1802
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1803

    
1804
$group = new Form_Group('MAC controls');
1805
$group->add($macaddress);
1806
// $group->add($btnmymac);
1807
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1808
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1809
$section->add($group);
1810

    
1811
$section->addInput(new Form_Input(
1812
	'mtu',
1813
	'MTU',
1814
	'number',
1815
	$pconfig['mtu']
1816
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1817
			'This is typically 1500 bytes but can vary in some circumstances.');
1818

    
1819
$section->addInput(new Form_Input(
1820
	'mss',
1821
	'MSS',
1822
	'number',
1823
	$pconfig['mss']
1824
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1825
			'header size) will be in effect.');
1826

    
1827
if (count($mediaopts_list) > 0) {
1828
	$section->addInput(new Form_Select(
1829
		'mediaopt',
1830
		'Speed and Duplex',
1831
		rtrim($mediaopt_from_config),
1832
		build_mediaopts_list()
1833
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1834
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1835
}
1836

    
1837
$form->add($section);
1838

    
1839
$section = new Form_Section('Static IPv4 configuration');
1840
$section->addClass('staticv4');
1841

    
1842
$section->addInput(new Form_IpAddress(
1843
	'ipaddr',
1844
	'IPv4 Address',
1845
	$pconfig['ipaddr']
1846
))->addMask('subnet', $pconfig['subnet'], 32);
1847

    
1848
$group = new Form_Group('IPv4 Upstream gateway');
1849

    
1850
$group->add(new Form_Select(
1851
	'gateway',
1852
	'IPv4 Upstream Gateway',
1853
	$pconfig['gateway'],
1854
	build_gateway_list()
1855
));
1856

    
1857
$group->add(new Form_Button(
1858
	'addgw',
1859
	'Add a new gateway'
1860
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1861

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

    
1866
$section->add($group);
1867

    
1868
$form->add($section);
1869

    
1870
// Add new gateway modal pop-up
1871
$modal = new Modal('New gateway', 'newgateway', 'large');
1872

    
1873
$modal->addInput(new Form_Checkbox(
1874
	'defaultgw',
1875
	'Default',
1876
	'Default gateway',
1877
	($if == "wan" || $if == "WAN")
1878
));
1879

    
1880
$modal->addInput(new Form_Input(
1881
	'name',
1882
	'Gateway name',
1883
	'text',
1884
	$wancfg['descr'] . "GW"
1885
));
1886

    
1887
$modal->addInput(new Form_IpAddress(
1888
	'gatewayip',
1889
	'Gateway IPv4',
1890
	null
1891
));
1892

    
1893
$modal->addInput(new Form_Input(
1894
	'gatewaydescr',
1895
	'Description',
1896
	'text'
1897
));
1898

    
1899
$btnaddgw = new Form_Button(
1900
	'add',
1901
	'Add'
1902
);
1903

    
1904
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
1905

    
1906
$btncnxgw = new Form_Button(
1907
	'cnx',
1908
	'Cancel'
1909
);
1910

    
1911
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
1912

    
1913
$modal->addInput(new Form_StaticText(
1914
	null,
1915
	$btnaddgw . $btncnxgw
1916
));
1917

    
1918
$form->add($modal);
1919

    
1920
$section = new Form_Section('Static IPv6 configuration');
1921
$section->addClass('staticv6');
1922

    
1923
$section->addInput(new Form_IpAddress(
1924
	'ipaddrv6',
1925
	'IPv6 address',
1926
	$pconfig['ipaddrv6']
1927
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1928

    
1929
$group = new Form_Group('IPv6 Upstream gateway');
1930

    
1931
$group->add(new Form_Select(
1932
	'gatewayv6',
1933
	'IPv4 Upstream Gateway',
1934
	$pconfig['gateway'],
1935
	build_gateway_list()
1936
));
1937

    
1938
$group->add(new Form_Button(
1939
	'addgw6',
1940
	'Add a new gateway'
1941
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1942

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

    
1946
$section->add($group);
1947
$form->add($section);
1948

    
1949
// Add new gateway modal pop-up for IPv6
1950
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1951

    
1952
$modal->addInput(new Form_Checkbox(
1953
	'defaultgw6',
1954
	'Default',
1955
	'Default gateway',
1956
	($if == "wan" || $if == "WAN")
1957
));
1958

    
1959
$modal->addInput(new Form_Input(
1960
	'name6',
1961
	'Gateway name',
1962
	'text',
1963
	$wancfg['descr'] . "GW"
1964
));
1965

    
1966
$modal->addInput(new Form_IpAddress(
1967
	'gatewayip6',
1968
	'Gateway IPv4',
1969
	null
1970
));
1971

    
1972
$modal->addInput(new Form_Input(
1973
	'gatewaydescr6',
1974
	'Description',
1975
	'text'
1976
));
1977

    
1978
$btnaddgw6 = new Form_Button(
1979
	'add6',
1980
	'Add'
1981
);
1982

    
1983
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1984

    
1985
$btncnxgw6 = new Form_Button(
1986
	'cnx6',
1987
	'Cancel'
1988
);
1989

    
1990
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1991

    
1992
$modal->addInput(new Form_StaticText(
1993
	null,
1994
	$btnaddgw6 . $btncnxgw6
1995
));
1996

    
1997
$form->add($modal);
1998

    
1999
// ==== DHCP client configuration =============================
2000

    
2001
$section = new Form_Section('DHCP client configuration');
2002
$section->addClass('dhcp');
2003

    
2004
$group = new Form_Group('Options');
2005

    
2006
$group->add(new Form_Checkbox(
2007
	'dhcpadv',
2008
	null,
2009
	'Show DHCP advanced options',
2010
	false
2011
));
2012

    
2013
$group->add(new Form_Checkbox(
2014
	'dhcpovr',
2015
	null,
2016
	'Config file override',
2017
	false
2018
));
2019

    
2020
$section->add($group);
2021

    
2022
$section->addInput(new Form_Input(
2023
	'dhcphostname',
2024
	'Hostname',
2025
	'text',
2026
	$pconfig['dhcphostname']
2027
))->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).');
2028

    
2029
$section->addInput(new Form_IpAddress(
2030
	'alias-address',
2031
	'Alias IPv4 address',
2032
	$pconfig['alias-address']
2033
))->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.');
2034

    
2035
$section->addInput(new Form_Input(
2036
	'dhcprejectfrom',
2037
	'Reject leases from',
2038
	'text',
2039
	$pconfig['dhcprejectfrom']
2040
))->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. ' .
2041
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
2042

    
2043
$group = new Form_Group('Protocol timing');
2044
$group->addClass('dhcpadvanced');
2045

    
2046
$group->add(new Form_Input(
2047
	'adv_dhcp_pt_timeout',
2048
	null,
2049
	'number',
2050
	$pconfig['adv_dhcp_pt_timeout']
2051
))->setHelp('Timeout');
2052

    
2053
$group->add(new Form_Input(
2054
	'adv_dhcp_pt_retry',
2055
	null,
2056
	'number',
2057
	$pconfig['adv_dhcp_pt_retry']
2058
))->setHelp('Retry');
2059

    
2060
$group->add(new Form_Input(
2061
	'adv_dhcp_pt_select_timeout',
2062
	null,
2063
	'number',
2064
	$pconfig['adv_dhcp_pt_select_timeout']
2065
))->setHelp('Select timeout');
2066

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

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

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

    
2088
$section->add($group);
2089

    
2090
$group = new Form_Group('Presets');
2091
$group->addClass('dhcpadvanced');
2092

    
2093
$group->add(new Form_Checkbox(
2094
	'adv_dhcp_pt_values',
2095
	null,
2096
	'FreeBSD default',
2097
	null,
2098
	'DHCP'
2099
))->displayAsRadio();
2100

    
2101
$group->add(new Form_Checkbox(
2102
	'adv_dhcp_pt_values',
2103
	null,
2104
	'Clear',
2105
	null,
2106
	'Clear'
2107
))->displayAsRadio();
2108

    
2109
$group->add(new Form_Checkbox(
2110
	'adv_dhcp_pt_values',
2111
	null,
2112
	'pfSense Default',
2113
	null,
2114
	'pfSense'
2115
))->displayAsRadio();
2116

    
2117
$group->add(new Form_Checkbox(
2118
	'adv_dhcp_pt_values',
2119
	null,
2120
	'Saved Cfg',
2121
	null,
2122
	'SavedCfg'
2123
))->displayAsRadio();
2124

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

    
2128
$section->add($group);
2129

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

    
2140
$form->add($section);
2141

    
2142
$section = new Form_Section('Lease Requirements and Requests');
2143
$section->addClass('dhcpadvanced');
2144

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

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

    
2163
$section->addInput(new Form_Input(
2164
	'adv_dhcp_require_options',
2165
	'Request options',
2166
	'text',
2167
	$pconfig['adv_dhcp_require_options']
2168
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2169

    
2170
$section->addInput(new Form_Input(
2171
	'adv_dhcp_option_modifiers',
2172
	'Option modifiers',
2173
	'text',
2174
	$pconfig['adv_dhcp_option_modifiers']
2175
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2176
			'modifiers: (default, supersede, prepend, append)');
2177

    
2178
$form->add($section);
2179

    
2180
// DHCP6 client config
2181

    
2182
$section = new Form_Section('DHCP6 client configuration');
2183
$section->addClass('dhcp6');
2184

    
2185
$section->addInput(new Form_Checkbox(
2186
	'dhcp6adv',
2187
	'Advanced',
2188
	'Show DHCPv6 advanced options',
2189
	$pconfig['adv_dhcp6_config_advanced']
2190
));
2191

    
2192
$section->addInput(new Form_Checkbox(
2193
	'adv_dhcp6_config_file_override',
2194
	'Config file override',
2195
	'Override the configuration from this file',
2196
	$pconfig['adv_dhcp6_config_file_override']
2197
));
2198

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

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

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

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

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

    
2237
$form->add($section);
2238

    
2239
// DHCP6 client config - Advanced
2240

    
2241
$section = new Form_Section('Advanced DHCP6 client configuration');
2242
$section->addClass('dhcp6advanced');
2243

    
2244
$section->addInput(new Form_Checkbox(
2245
	'adv_dhcp6_interface_statement_information_only_enable',
2246
	'Information only',
2247
	null,
2248
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2249
));
2250

    
2251
$section->addInput(new Form_Input(
2252
	'adv_dhcp6_interface_statement_send_options',
2253
	'Send options',
2254
	'text',
2255
	$pconfig['adv_dhcp6_interface_statement_send_options']
2256
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2257
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2258
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2259
			'Some DHCP services may require certain options be or not be sent.');
2260

    
2261
$section->addInput(new Form_Input(
2262
	'adv_dhcp6_interface_statement_request_options',
2263
	'Request Options',
2264
	'text',
2265
	$pconfig['adv_dhcp6_interface_statement_request_options']
2266
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2267
			'Some DHCP services may require certain options be or not be requested.');
2268

    
2269
$section->addInput(new Form_Input(
2270
	'adv_dhcp6_interface_statement_script',
2271
	'Scripts',
2272
	'text',
2273
	$pconfig['adv_dhcp6_interface_statement_script']
2274
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2275
			'[/[dirname/[.../]]filename[.ext]].');
2276

    
2277
$group = new Form_Group('Identity Association Statement');
2278

    
2279
$group->add(new Form_Checkbox(
2280
	'adv_dhcp6_id_assoc_statement_address_enable',
2281
	null,
2282
	'Non-Temporary Address Allocation',
2283
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2284
));
2285

    
2286
$group->add(new Form_Input(
2287
	'adv_dhcp6_id_assoc_statement_address_id',
2288
	null,
2289
	'text',
2290
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2291
))->sethelp('id-assoc na ID');
2292

    
2293
$group->add(new Form_IpAddress(
2294
	'adv_dhcp6_id_assoc_statement_address',
2295
	null,
2296
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2297
))->sethelp('IPv6 address');
2298

    
2299
$group->add(new Form_Input(
2300
	'adv_dhcp6_id_assoc_statement_address_pltime',
2301
	null,
2302
	'text',
2303
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2304
))->sethelp('pltime');
2305

    
2306
$group->add(new Form_Input(
2307
	'adv_dhcp6_id_assoc_statement_address_vltime',
2308
	null,
2309
	'text',
2310
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2311
))->sethelp('vltime');
2312

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

    
2315
// Prefix delegation
2316
$group = new Form_Group('');
2317

    
2318
$group->add(new Form_Checkbox(
2319
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2320
	null,
2321
	'Prefix Delegation ',
2322
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2323
));
2324

    
2325
$group->add(new Form_Input(
2326
	'adv_dhcp6_id_assoc_statement_prefix_id',
2327
	null,
2328
	'text',
2329
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2330
))->sethelp('id-assoc pd ID');
2331

    
2332
$group->add(new Form_IpAddress(
2333
	'adv_dhcp6_id_assoc_statement_prefix',
2334
	null,
2335
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2336
))->sethelp('IPv6 prefix');
2337

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

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

    
2352
$section->add($group);
2353

    
2354
$group = new Form_Group('Prefix interface statement');
2355

    
2356
$group->add(new Form_Input(
2357
	'adv_dhcp6_prefix_interface_statement_sla_id',
2358
	null,
2359
	'text',
2360
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2361
))->sethelp('Prefix Interface sla-id');
2362

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

    
2370
$section->add($group);
2371

    
2372
$group = new Form_Group('Authentication statement');
2373

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

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

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

    
2395
$group->add(new Form_Input(
2396
	'adv_dhcp6_authentication_statement_rdm',
2397
	null,
2398
	'text',
2399
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2400
))->sethelp('RDM');
2401

    
2402
$section->add($group);
2403

    
2404
$group = new Form_Group('Keyinfo statement');
2405

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

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

    
2420
$section->add($group);
2421

    
2422
$group = new Form_Group('');
2423

    
2424
$group->add(new Form_Input(
2425
	'adv_dhcp6_key_info_statement_keyid',
2426
	null,
2427
	'text',
2428
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2429
))->sethelp('KeyID');
2430

    
2431
$group->add(new Form_Input(
2432
	'adv_dhcp6_key_info_statement_secret',
2433
	null,
2434
	'text',
2435
	$pconfig['adv_dhcp6_key_info_statement_secret']
2436
))->sethelp('Secret');
2437

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

    
2445
$section->add($group);
2446

    
2447
$form->add($section);
2448

    
2449
$section = new Form_Section('6RD Configuration');
2450
$section->addClass('6rd');
2451

    
2452
$section->addInput(new Form_Input(
2453
	'prefix-6rd',
2454
	'6RD Prefix',
2455
	'text',
2456
	$pconfig['prefix-6rd']
2457
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2458

    
2459
$section->addInput(new Form_Input(
2460
	'gateway-6rd',
2461
	'6RD Border relay',
2462
	'text',
2463
	$pconfig['gateway-6rd']
2464
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2465

    
2466
$section->addInput(new Form_Select(
2467
	'prefix-6rd-v4plen',
2468
	'DHCPv6 Prefix Delegation size',
2469
	$pconfig['prefix-6rd-v4plen'],
2470
	array_combine(range(0, 32), range(0, 32))
2471
))->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..');
2472

    
2473
$form->add($section);
2474

    
2475
// Track IPv6 ointerface section
2476
$section = new Form_Section('Track IPv6 Interface');
2477
$section->addClass('track6');
2478

    
2479
function build_ipv6interface_list() {
2480
	$list = array('' => '');
2481

    
2482
	$interfaces = get_configured_interface_with_descr(false, true);
2483
	$dynv6ifs = array();
2484

    
2485
	foreach ($interfaces as $iface => $ifacename) {
2486
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2487
			case "6to4":
2488
			case "6rd":
2489
			case "dhcp6":
2490
				$dynv6ifs[$iface] = array(
2491
					'name' => $ifacename,
2492
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2493
				);
2494
				break;
2495
			default:
2496
				continue;
2497
		}
2498
	}
2499

    
2500
	foreach ($dynv6ifs as $iface => $ifacedata) {
2501
		$list[$iface] = $ifacedata['name'];
2502

    
2503
		$section->addInput(new Form_Input(
2504
			'ipv6-num-prefix-ids-' . $iface,
2505
			null,
2506
			'hidden',
2507
			$ifacedata['ipv6_num_prefix_ids']
2508
		));
2509
	}
2510

    
2511
	return($list);
2512
}
2513

    
2514
$section->addInput(new Form_Select(
2515
	'track6-interface',
2516
	'IPv6 Interface',
2517
	$pconfig['track6-interface'],
2518
	build_ipv6interface_list()
2519
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2520

    
2521
if ($pconfig['track6-prefix-id'] == "") {
2522
	$pconfig['track6-prefix-id'] = 0;
2523
}
2524

    
2525
$section->addInput(new Form_Input(
2526
	'track6-prefix-id--hex' . $iface,
2527
	'IPv6 Prefix ID',
2528
	'text',
2529
	sprintf("%x", $pconfig['track6-prefix-id'])
2530
))->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.');
2531

    
2532
$section->addInput(new Form_Input(
2533
	'track6-prefix-id-max' . $iface,
2534
	null,
2535
	'hidden',
2536
	0
2537
));
2538

    
2539
$form->add($section);
2540

    
2541
/// PPP section
2542

    
2543
$section = new Form_Section('PPP Configuration');
2544
$section->addClass('ppp');
2545

    
2546
$section->addInput(new Form_Select(
2547
	'country',
2548
	'Country',
2549
	$pconfig['country'],
2550
	[]
2551
));
2552

    
2553
$section->addInput(new Form_Select(
2554
	'provider_list',
2555
	'Provider',
2556
	$pconfig['provider_list'],
2557
	[]
2558
));
2559

    
2560
$section->addInput(new Form_Select(
2561
	'providerplan',
2562
	'Plan',
2563
	$pconfig['providerplan'],
2564
	[]
2565
))->setHelp('Select to fill in data for your service provider.');
2566

    
2567
$section->addInput(new Form_Input(
2568
	'ppp_username',
2569
	'Username',
2570
	'text',
2571
	$pconfig['ppp_username']
2572
));
2573

    
2574
$section->addInput(new Form_Input(
2575
	'ppp_password',
2576
	'Password',
2577
	'password',
2578
	$pconfig['ppp_password']
2579
));
2580

    
2581
$section->addInput(new Form_Input(
2582
	'phone',
2583
	'Phone number',
2584
	'text',
2585
	$pconfig['phone']
2586
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2587

    
2588
$section->addInput(new Form_Input(
2589
	'apn',
2590
	'Access Point Name',
2591
	'text',
2592
	$pconfig['apn']
2593
));
2594

    
2595

    
2596
function build_port_list() {
2597
	$list = array("" => "None");
2598

    
2599
	$portlist = glob("/dev/cua*");
2600
	$modems	  = glob("/dev/modem*");
2601
	$portlist = array_merge($portlist, $modems);
2602

    
2603
	foreach ($portlist as $port) {
2604
		if (preg_match("/\.(lock|init)$/", $port)) {
2605
			continue;
2606
		}
2607

    
2608
	$list[trim($port)] = $port;
2609
	}
2610

    
2611
	return($list);
2612
}
2613

    
2614
$section->addInput(new Form_Select(
2615
	'port',
2616
	"Modem port",
2617
	$pconfig['port'],
2618
	build_port_list()
2619
));
2620

    
2621
$section->addInput(new Form_Button(
2622
	'btnadvppp',
2623
	'Advanced PPP',
2624
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2625
))->setHelp('Create a new PPP configuration');
2626

    
2627
$form->add($section);
2628

    
2629
// PPPoE configuration
2630
$section = new Form_Section('PPPoE Configuration');
2631
$section->addClass('pppoe');
2632

    
2633
$section->addInput(new Form_Input(
2634
	'pppoe_username',
2635
	'Username',
2636
	'text',
2637
	$pconfig['pppoe_username']
2638
));
2639

    
2640
$section->addInput(new Form_Input(
2641
	'pppoe_password',
2642
	'Password',
2643
	'password',
2644
	$pconfig['pppoe_password']
2645
));
2646

    
2647
$section->addInput(new Form_Input(
2648
	'provider',
2649
	'Service name',
2650
	'text',
2651
	$pconfig['provider']
2652
))->setHelp('This field can usually be left empty');
2653

    
2654
$section->addInput(new Form_Checkbox(
2655
	'pppoe_dialondemand',
2656
	'Dial on demand',
2657
	'Enable Dial-On-Demand mode ',
2658
	$pconfig['pppoe_dialondemand'],
2659
	'enable'
2660
));
2661

    
2662
$section->addInput(new Form_Input(
2663
	'pppoe_idletimeout',
2664
	'Idle timeout',
2665
	'number',
2666
	$pconfig['pppoe_idletimeout'],
2667
	[min => 0]
2668
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2669
			'An idle timeout of zero disables this feature.');
2670

    
2671
$section->addInput(new Form_Select(
2672
	'pppoe-reset-type',
2673
	'Periodic reset',
2674
	$pconfig['pppoe-reset-type'],
2675
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2676
))->setHelp('Select a reset timing type');
2677

    
2678
$group = new Form_Group('Custom reset');
2679
$group->addClass('pppoecustom');
2680

    
2681
$group->add(new Form_Input(
2682
	'pppoe_resethour',
2683
	null,
2684
	'number',
2685
	$pconfig['pppoe_resethour'],
2686
	[min => 0, max => 23]
2687
))->setHelp('Hour (0-23)');
2688

    
2689
$group->add(new Form_Input(
2690
	'pppoe_resetminute',
2691
	null,
2692
	'number',
2693
	$pconfig['pppoe_resetminute'],
2694
	[min => 0, max => 59]
2695
))->setHelp('Minutes (0-59)');
2696

    
2697
// ToDo: Need a date-picker here
2698
$group->add(new Form_Input(
2699
	'pppoe_resetdate',
2700
	null,
2701
	'text',
2702
	$pconfig['pppoe_resetdate']
2703
))->setHelp('Specific date (mm/dd/yyyy)');
2704

    
2705
$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');
2706

    
2707
$section->add($group);
2708

    
2709
$group = new Form_MultiCheckboxGroup('cron based reset');
2710
$group->addClass('pppoepreset');
2711

    
2712
$group->add(new Form_MultiCheckbox(
2713
	'pppoe_pr_preset_val',
2714
	null,
2715
	'Reset at each month ("0 0 1 * *")',
2716
	$pconfig['pppoe_monthly'],
2717
	'monthly'
2718
))->displayAsRadio();
2719

    
2720
$group->add(new Form_MultiCheckbox(
2721
	'pppoe_pr_preset_val',
2722
	null,
2723
	'Reset at each week ("0 0 * * 0")',
2724
	$pconfig['pppoe_weekly'],
2725
	'weekly'
2726
))->displayAsRadio();
2727

    
2728
$group->add(new Form_MultiCheckbox(
2729
	'pppoe_pr_preset_val',
2730
	null,
2731
	'Reset at each day ("0 0 * * *")',
2732
	$pconfig['pppoe_daily'],
2733
	'daily'
2734
))->displayAsRadio();
2735

    
2736
$group->add(new Form_MultiCheckbox(
2737
	'pppoe_pr_preset_val',
2738
	null,
2739
	'Reset at each hour ("0 * * * *")',
2740
	$pconfig['pppoe_hourly'],
2741
	'hourly'
2742
))->displayAsRadio();
2743

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

    
2746
if (isset($pconfig['pppid'])) {
2747
	$section->addInput(new Form_StaticText(
2748
		'Advanced and MLPPP',
2749
		'<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>'
2750
	));
2751
} else {
2752
	$section->addInput(new Form_StaticText(
2753
		'Advanced and MLPPP',
2754
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2755
	));
2756
}
2757

    
2758
$form->add($section);
2759

    
2760
// PPTP & L2TP Configuration section
2761
$section = new Form_Section('PPTP/L2TP Configuration');
2762
$section->addClass('pptp');
2763

    
2764
$section->addInput(new Form_Input(
2765
	'pptp_username',
2766
	'Username',
2767
	'text',
2768
	$pconfig['pptp_username']
2769
));
2770

    
2771
$section->addInput(new Form_Input(
2772
	'pptp_password',
2773
	'Password',
2774
	'password',
2775
	$pconfig['pptp_password']
2776
));
2777

    
2778
$section->addInput(new Form_IpAddress(
2779
	'pptp_local',
2780
	'Local IP address',
2781
	$pconfig['pptp_local'][0]
2782
))->addMask('pptp_subnet', $pconfig['pptp_subnet'][0]);
2783

    
2784
$section->addInput(new Form_IpAddress(
2785
	'pptp_remote',
2786
	'Remote IP address',
2787
	$pconfig['pptp_remote'][0]
2788
));
2789

    
2790
$section->addInput(new Form_Checkbox(
2791
	'pptp_dialondemand',
2792
	'Dial on demand',
2793
	'Enable Dial-On-Demand mode ',
2794
	$pconfig['pptp_dialondemand'],
2795
	'enable'
2796
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2797
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2798

    
2799
$section->addInput(new Form_Input(
2800
	'pptp_idletimeout',
2801
	'Idle timeout (seconds)',
2802
	'number',
2803
	$pconfig['pptp_idletimeout'],
2804
	[min => 0]
2805
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2806
			'An idle timeout of zero disables this feature.');
2807

    
2808
if (isset($pconfig['pppid'])) {
2809
	$section->addInput(new Form_StaticText(
2810
		'Advanced and MLPPP',
2811
		'<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>'
2812
	));
2813
} else {
2814
	$section->addInput(new Form_StaticText(
2815
		'Advanced and MLPPP',
2816
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2817
	));
2818
}
2819

    
2820
$form->add($section);
2821

    
2822
// Wireless interface
2823
if (isset($wancfg['wireless'])) {
2824

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

    
2827
	$section->addInput(new Form_Checkbox(
2828
		'persistcommonwireless',
2829
		'Persist common settings',
2830
		'Preserve common wireless configuration through interface deletions and reassignments.',
2831
		$pconfig['persistcommonwireless'],
2832
		'yes'
2833
	));
2834

    
2835
	$mode_list = ['auto' => 'Auto'];
2836

    
2837
	if (is_array($wl_modes)) {
2838
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2839
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2840
		}
2841
	}
2842

    
2843
	if (count($mode_list) == 1)
2844
		$mode_list[''] = '';
2845

    
2846
	$section->addInput(new Form_Select(
2847
		'standard',
2848
		'Standard',
2849
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2850
		$mode_list
2851
	));
2852

    
2853
	if (isset($wl_modes['11g'])) {
2854
		$section->addInput(new Form_Select(
2855
			'protmode',
2856
			'802.11g OFDM Protection Mode',
2857
			$pconfig['protmode'],
2858
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2859
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2860
	}
2861
	else
2862
	{
2863
		$section->addInput(new Form_Input(
2864
			'protmode',
2865
			null,
2866
			'hidden',
2867
			'off'
2868
		));
2869
	}
2870

    
2871
	$mode_list = ['0' => 'Auto'];
2872

    
2873
	if (is_array($wl_modes)) {
2874
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2875
			if ($wl_standard == "11g") {
2876
				$wl_standard = "11b/g";
2877
			} else if ($wl_standard == "11ng") {
2878
				$wl_standard = "11b/g/n";
2879
			} else if ($wl_standard == "11na") {
2880
				$wl_standard = "11a/n";
2881
			}
2882

    
2883
			foreach ($wl_channels as $wl_channel) {
2884
				if (isset($wl_chaninfo[$wl_channel])) {
2885
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2886
				} else {
2887
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2888
				}
2889
			}
2890
		}
2891
	}
2892

    
2893
	$section->addInput(new Form_Select(
2894
		'channel',
2895
		'Channel',
2896
		$pconfig['channel'],
2897
		$mode_list
2898
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2899
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2900

    
2901
	if (ANTENNAS && isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2902
		$group = new Form_Group('Antenna Settings');
2903

    
2904
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2905
			$group->add(new Form_Select(
2906
				'diversity',
2907
				null,
2908
				(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2909
				['' => 'Default', '0' => 'Off', '1' => 'On']
2910
			))->setHelp('Diversity');
2911
		}
2912

    
2913
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2914
			$group->add(new Form_Select(
2915
				'txantenna',
2916
				null,
2917
				(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2918
				['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2919
			))->setHelp('Transmit antenna');
2920
		}
2921

    
2922
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2923
			$group->add(new Form_Select(
2924
				'rxantenna',
2925
				null,
2926
				(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2927
				['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2928
			))->setHelp('Receive antenna');
2929
		}
2930

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

    
2933
		$section->add($group);
2934
	}
2935

    
2936
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2937
			$section->addInput(new Form_Input(
2938
				'distance',
2939
				'Distance setting (meters)',
2940
				'test',
2941
				$pconfig['distance']
2942
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2943
	}
2944

    
2945
	$form->add($section);
2946

    
2947
	// Regulatory settings
2948
	$section = new Form_Section('Regulatory settings');
2949

    
2950
	$domain_list = array("" => 'Default');
2951

    
2952
	if (is_array($wl_regdomains)) {
2953
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2954
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2955
		}
2956
	}
2957

    
2958
	$section->addInput(new Form_Select(
2959
		'regdomain',
2960
		'Regulatory domain',
2961
		$pconfig['regdomain'],
2962
		$domain_list
2963
	))->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');
2964

    
2965
	$country_list = array('' => 'Default');
2966

    
2967
	if (is_array($wl_countries)) {
2968
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2969
			$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']);
2970
		}
2971
	}
2972

    
2973
	$section->addInput(new Form_Select(
2974
		'regcountry',
2975
		'Country',
2976
		$pconfig['regcountry'],
2977
		$country_list
2978
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2979

    
2980
	$section->addInput(new Form_Select(
2981
		'reglocation',
2982
		'Location',
2983
		$pconfig['reglocation'],
2984
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2985
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2986
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2987
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2988
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2989
				'These settings may not be able to add additional channels that are not already supported.');
2990

    
2991
	$form->add($section);
2992

    
2993
	$section = new Form_Section('Network-specific wireless configuration');
2994

    
2995
	$section->addInput(new Form_Select(
2996
		'mode',
2997
		'Mode',
2998
		$pconfig['mode'],
2999
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
3000
	));
3001

    
3002
	$section->addInput(new Form_Input(
3003
		'ssid',
3004
		'SSID',
3005
		'text',
3006
		$pconfig['ssid']
3007
	));
3008

    
3009
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3010
		$section->addInput(new Form_Select(
3011
			'puremode',
3012
			'Minimum wireless standard',
3013
			$pconfig['puremode'],
3014
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
3015
		))->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)');
3016
	} elseif (isset($wl_modes['11g'])) {
3017
		$section->addInput(new Form_Checkbox(
3018
			'puremode',
3019
			'802.11g only',
3020
			null,
3021
			$pconfig['puremode'],
3022
			'11g'
3023
		))->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)');
3024
	}
3025

    
3026
	$section->addInput(new Form_Checkbox(
3027
		'apbridge_enable',
3028
		'Allow intra-BSS communication',
3029
		'Allow packets to pass between wireless clients directly when operating as an access point',
3030
		$pconfig['apbridge_enable'],
3031
		'yes'
3032
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
3033

    
3034
	$section->addInput(new Form_Checkbox(
3035
		'wme_enable',
3036
		'Enable WME',
3037
		'Force the card to use WME (wireless QoS)',
3038
		$pconfig['wme_enable'],
3039
		'yes'
3040
	));
3041

    
3042
	$section->addInput(new Form_Checkbox(
3043
		'hidessid_enable',
3044
		'Hide SSID',
3045
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
3046
		$pconfig['hidessid_enable'],
3047
		'yes'
3048
	));
3049

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

    
3052
	if(ALLOWWEP) {
3053
		// WEP Section
3054
		$section = new Form_Section('WEP');
3055

    
3056
		$section->addInput(new Form_Checkbox(
3057
			'wep_enable',
3058
			'Enable',
3059
			'Enable WEP',
3060
			$pconfig['wep_enable'],
3061
			'yes'
3062
		));
3063

    
3064
		for($idx=1; $idx <= 4; $idx++) {
3065
			$group = new Form_Group('Key' . $idx);
3066

    
3067
			$group->add(new Form_Input(
3068
				'key' . $idx,
3069
				null,
3070
				'text',
3071
				$pconfig['key' . $idx]
3072
			));
3073

    
3074
			$group->add(new Form_Checkbox(
3075
				'txkey',
3076
				null,
3077
				null,
3078
				$pconfig['txkey'],
3079
				$idx
3080
			))->displayAsRadio()->setHelp($idx == 4 ? 'Tx key':'');
3081

    
3082
			$section->add($group);
3083
		}
3084

    
3085
		$section->addInput(new Form_StaticText(
3086
			null,
3087
			'<span class="help-block">' .
3088
			gettext('40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by "0x"') . '<br />' .
3089
			gettext('104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by "0x"') .
3090
			'</span>'
3091
		));
3092

    
3093
		$form->add($section);
3094
	}
3095

    
3096
	// WPA Section
3097
	$section = new Form_Section('WPA');
3098

    
3099
	$section->addInput(new Form_Checkbox(
3100
		'wpa_enable',
3101
		'Enable',
3102
		'Enable WPA',
3103
		$pconfig['wpa_enable'],
3104
		'yes'
3105
	));
3106

    
3107
	$section->addInput(new Form_Input(
3108
		'passphrase',
3109
		'WPA Pre-Shared Key',
3110
		'text',
3111
		$pconfig['passphrase']
3112
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3113

    
3114
	$section->addInput(new Form_Select(
3115
		'wpa_mode',
3116
		'WPA mode',
3117
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3118
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
3119
	));
3120

    
3121
	$section->addInput(new Form_Select(
3122
		'wpa_key_mgmt',
3123
		'WPA Key Management Mode',
3124
		$pconfig['wpa_key_mgmt'],
3125
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
3126
	));
3127

    
3128
	if(ALLOWWEP) {
3129
		$section->addInput(new Form_Select(
3130
			'auth_algs',
3131
			'Authentication',
3132
			$pconfig['auth_algs'],
3133
			['1' => 'Open System Authentication', '2' => 'Shared Key Authentication', '3' => 'Both']
3134
		))->setHelp('Shared Key Authentication requires WEP');
3135
	} else {
3136
		$section->addInput(new Form_Input(
3137
			'auth_algs',
3138
			null,
3139
			'hidden',
3140
			'1'
3141
		));;
3142
	}
3143

    
3144
	$section->addInput(new Form_Select(
3145
		'wpa_pairwise',
3146
		'WPA Pairwise',
3147
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3148
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3149
	));
3150

    
3151
	$section->addInput(new Form_Input(
3152
		'wpa_group_rekey',
3153
		'WPA Pre-Shared Key',
3154
		'number',
3155
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3156
		['min' => '1', 'max' => 9999]
3157
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3158

    
3159
	$section->addInput(new Form_Input(
3160
		'wpa_gmk_rekey',
3161
		'Master Key Regeneration',
3162
		'number',
3163
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3164
		['min' => '1', 'max' => 9999]
3165
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3166

    
3167
	$section->addInput(new Form_Checkbox(
3168
		'wpa_strict_rekey',
3169
		'Strict Key Regeneration',
3170
		'Force the AP to rekey whenever a client disassociates',
3171
		$pconfig['wpa_strict_rekey'],
3172
		'yes'
3173
	));
3174

    
3175
	$section->addInput(new Form_Checkbox(
3176
		'ieee8021x',
3177
		'IEEE802.1X',
3178
		'Enable 802.1X authentication',
3179
		$pconfig['ieee8021x'],
3180
		'yes'
3181
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3182

    
3183
	$group = new Form_Group('Primary 802.1X server');
3184

    
3185
	$group->add(new Form_IpAddress(
3186
		'auth_server_addr',
3187
		'IP Address',
3188
		$pconfig['auth_server_addr']
3189
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3190

    
3191
	$group->add(new Form_Input(
3192
		'auth_server_port',
3193
		'Port',
3194
		'number',
3195
		$pconfig['auth_server_port']
3196
	))->setHelp('Server port. Leave blank for the default port 1812');
3197

    
3198
	$group->add(new Form_Input(
3199
		'auth_server_shared_secret',
3200
		'Shared secret',
3201
		'number',
3202
		$pconfig['auth_server_shared_secret']
3203
	))->setHelp('Shared secret');
3204

    
3205
	$section->add($group);
3206

    
3207
	$group = new Form_Group('Secondary 802.1X server');
3208

    
3209
	$group->add(new Form_IpAddress(
3210
		'auth_server_addr2',
3211
		'IP Address',
3212
		$pconfig['auth_server_addr2']
3213
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3214

    
3215
	$group->add(new Form_Input(
3216
		'auth_server_port2',
3217
		'Port',
3218
		'number',
3219
		$pconfig['auth_server_port2']
3220
	))->setHelp('Server port. Leave blank for the default port 1812');
3221

    
3222
	$group->add(new Form_Input(
3223
		'auth_server_shared_secret2',
3224
		'Shared secret',
3225
		'number',
3226
		$pconfig['auth_server_shared_secret2']
3227
	))->setHelp('Shared secret');
3228

    
3229
	$section->add($group);
3230

    
3231
	$section->addInput(new Form_Checkbox(
3232
		'rsn_preauth',
3233
		'Authentication Roaming Preauth',
3234
		null,
3235
		$pconfig['rsn_preauth'],
3236
		'yes'
3237
	));
3238

    
3239
	$form->add($section);
3240
}
3241

    
3242
$section = new Form_Section('Private networks');
3243

    
3244
$section->addInput(new Form_Checkbox(
3245
	'blockpriv',
3246
	'Block private networks',
3247
	'',
3248
	$pconfig['blockpriv'],
3249
	'yes'
3250
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3251
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3252
			'lies in such a private address space, too.');
3253

    
3254
	$section->addInput(new Form_Checkbox(
3255
	'blockbogons',
3256
	'Block bogon networks',
3257
	'',
3258
	$pconfig['blockbogons'],
3259
	'yes'
3260
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3261
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3262
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3263

    
3264
$form->add($section);
3265

    
3266
$form->addGlobal(new Form_Input(
3267
	'if',
3268
	null,
3269
	'hidden',
3270
	$if
3271
));
3272

    
3273
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3274
	$form->addGlobal(new Form_Input(
3275
		'ppp_port',
3276
		null,
3277
		'hidden',
3278
		$pconfig['port']
3279
	));
3280
}
3281

    
3282
$form->addGlobal(new Form_Input(
3283
	'ptpid',
3284
	null,
3285
	'hidden',
3286
	$pconfig['ptpid']
3287
));
3288

    
3289
print($form);
3290
?>
3291

    
3292
<script type="text/javascript">
3293
//<![CDATA[
3294
events.push(function(){
3295

    
3296
	function updateType(t) {
3297
		switch (t) {
3298
			case "none": {
3299
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3300
				break;
3301
			}
3302
			case "staticv4": {
3303
				$('.dhcpadvanced, .none, .dhcp, .pppoe, .pptp, .ppp').hide();
3304
				break;
3305
			}
3306
			case "dhcp": {
3307
				$('.dhcpadvanced, .none, .staticv4, .pppoe, .pptp, .ppp').hide();
3308
				break;
3309
			}
3310
			case "ppp": {
3311
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3312
				country_list();
3313
				break;
3314
			}
3315
			case "pppoe": {
3316
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3317
				break;
3318
			}
3319
			case "l2tp":
3320
			case "pptp": {
3321
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3322
				$('.pptp').show();
3323
				break;
3324
			}
3325
		}
3326

    
3327
		if (t != "l2tp" && t != "pptp") {
3328
			$('.'+t).show();
3329
		}
3330
	}
3331

    
3332
	function updateTypeSix(t) {
3333
		if (!isNaN(t[0]))
3334
			t = '_' + t;
3335

    
3336
		switch (t) {
3337
			case "none": {
3338
				$('.dhcp6advanced, .staticv6, .dhcp6, .6rd, ._6to4, .track6, .slaac').hide();
3339
				break;
3340
			}
3341
			case "staticv6": {
3342
				$('.dhcp6advanced, .none, .dhcp6, .6rd, ._6to4, .track6, .slaac').hide();
3343
				break;
3344
			}
3345
			case "slaac": {
3346
				$('.dhcp6advanced, .none, .staticv6, .6rd, ._6to4, .track6, .dhcp6').hide();
3347
				break;
3348
			}
3349
			case "dhcp6": {
3350
				$('.dhcp6advanced, .none, .staticv6, .6rd, ._6to4, .track6, .slaac').hide();
3351
				break;
3352
			}
3353
			case "_6rd": {
3354
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, .6to4, .track6, .slaac').hide();
3355
				break;
3356
			}
3357
			case "_6to4": {
3358
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, .6rd, .track6, .slaac').hide();
3359
				break;
3360
			}
3361
			case "track6": {
3362
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, .6rd, .6to4, .slaac').hide();
3363
				update_track6_prefix();
3364
				break;
3365
			}
3366
		}
3367

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

    
3373
	function show_reset_settings(reset_type) {
3374
		if (reset_type == 'preset') {
3375
			$('.pppoepreset').show();
3376
			$('.pppoecustom').hide();
3377
		} else if (reset_type == 'custom') {
3378
			$('.pppoecustom').show();
3379
			$('.pppoepreset').hide();
3380
		} else {
3381
			$('.pppoecustom').hide();
3382
			$('.pppoepreset').hide();
3383
		}
3384
	}
3385

    
3386
	function update_track6_prefix() {
3387
		var iface = $("#track6-interface").val();
3388
		if (iface == null) {
3389
			return;
3390
		}
3391

    
3392
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3393
		if (track6_prefix_ids == null) {
3394
			return;
3395
		}
3396

    
3397
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3398
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3399
	}
3400

    
3401
	// Create the new gateway from the data entered in the modal pop-up
3402
	function hide_add_gatewaysave() {
3403
		var iface = $('#if').val();
3404
		name = $('#name').val();
3405
		var descr = $('#gatewaydescr').val();
3406
		gatewayip = $('#gatewayip').val();
3407

    
3408
		var defaultgw = '';
3409
		if ($('#defaultgw').is(':checked')) {
3410
			defaultgw = '&defaultgw=on';
3411
		}
3412

    
3413
		var url = "system_gateways_edit.php";
3414
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3415
		$.ajax(
3416
			url,
3417
			{
3418
				type: 'post',
3419
				data: pars,
3420
				error: report_failure,
3421
				complete: save_callback
3422
			});
3423
		}
3424

    
3425
	function save_callback(response) {
3426
		if (response) {
3427
			var gwtext = escape(name) + " - " + gatewayip;
3428
			addOption($('#gateway'), gwtext, name);
3429
		} else {
3430
			report_failure();
3431
		}
3432

    
3433
		$("#newgateway").modal('hide');
3434
	}
3435

    
3436
	function report_failure(request, textStatus, errorThrown) {
3437
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3438
			alert(request.responseText);
3439
		} else {
3440
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3441
		}
3442

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

    
3446
	function addOption(selectbox, text, value)
3447
	{
3448
		var optn = document.createElement("OPTION");
3449
		optn.text = text;
3450
		optn.value = value;
3451
		selectbox.append(optn);
3452
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3453
	}
3454

    
3455
	function hide_add_gatewaysave_v6() {
3456

    
3457
		var iface = $('#if').val();
3458
		name = $('#namev6').val();
3459
		var descr = $('#gatewaydescrv6').val();
3460
		gatewayip = $('#gatewayipv6').val();
3461
		var defaultgw = '';
3462
		if ($('#defaultgwv6').is(':checked')) {
3463
			defaultgw = '&defaultgw=on';
3464
		}
3465
		var url_v6 = "system_gateways_edit.php";
3466
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3467
		$.ajax(
3468
			url_v6,
3469
			{
3470
				type: 'post',
3471
				data: pars_v6,
3472
				error: report_failure_v6,
3473
				success: save_callback_v6
3474
			});
3475
	}
3476

    
3477

    
3478
	function addOption_v6(selectbox, text, value)
3479
	{
3480
		var optn = document.createElement("OPTION");
3481
		optn.text = text;
3482
		optn.value = value;
3483
		selectbox.append(optn);
3484
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3485
	}
3486

    
3487
	function report_failure_v6(request, textStatus, errorThrown) {
3488
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3489
			alert(request.responseText);
3490
		} else {
3491
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3492
		}
3493

    
3494
		$("#newgateway6").modal('hide');
3495
	}
3496

    
3497
	function save_callback_v6(response_v6) {
3498
		if (response_v6) {
3499

    
3500
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3501
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3502
		} else {
3503
			report_failure_v6();
3504
		}
3505

    
3506
		$("#newgateway6").modal('hide');
3507
	}
3508

    
3509
	function country_list() {
3510

    
3511
		$('#country').children().remove();
3512
		$('#provider_list').children().remove();
3513
		$('#providerplan').children().remove();
3514
		$.ajax("getserviceproviders.php",{
3515
			success: function(response) {
3516

    
3517
				var responseTextArr = response.split("\n");
3518
				responseTextArr.sort();
3519

    
3520
				responseTextArr.forEach( function(value) {
3521
					country = value.split(":");
3522
					$('#country').append($('<option>', {
3523
						value: country[1],
3524
						text : country[0]
3525
					}));
3526
				});
3527
			}
3528
		});
3529
	}
3530

    
3531
	function providers_list() {
3532
		$('#provider_list').children().remove();
3533
		$('#providerplan').children().remove();
3534
		$.ajax("getserviceproviders.php",{
3535
			type: 'post',
3536
			data: {country : $('#country').val()},
3537
			success: function(response) {
3538
				var responseTextArr = response.split("\n");
3539
				responseTextArr.sort();
3540
				responseTextArr.forEach( function(value) {
3541
					$('#provider_list').append($('<option>', {
3542
							value: value,
3543
							text : value
3544
					}));
3545
				});
3546
			}
3547
		});
3548
	}
3549

    
3550
	function providerplan_list() {
3551
		$('#providerplan').children().remove();
3552
		$.ajax("getserviceproviders.php",{
3553
			type: 'post',
3554
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3555
			success: function(response) {
3556
				var responseTextArr = response.split("\n");
3557
				responseTextArr.sort();
3558

    
3559
				$('#providerplan').append($('<option>', {
3560
					value: '',
3561
					text : ''
3562
				}));
3563

    
3564
				responseTextArr.forEach( function(value) {
3565
					if (value != "") {
3566
						providerplan = value.split(":");
3567

    
3568
						$('#providerplan').append($('<option>', {
3569
							value: providerplan[1],
3570
							text : providerplan[0] + " - " + providerplan[1]
3571
						}));
3572
					}
3573
				});
3574
			}
3575
		});
3576
	}
3577

    
3578
	function prefill_provider() {
3579
		$.ajax("getserviceproviders.php",{
3580
			type: 'post',
3581
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3582
			success: function(data, textStatus, response) {
3583
				var xmldoc = response.responseXML;
3584
				var provider = xmldoc.getElementsByTagName('connection')[0];
3585
				$('#ppp_username').val('');
3586
				$('#ppp_password').val('');
3587
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3588
					$('#phone').val('#777');
3589
					$('#apn').val('');
3590
				} else {
3591
					$('#phone').val('*99#');
3592
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3593
				}
3594
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3595
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3596
				$('#ppp_username').val(ppp_username);
3597
				$('#ppp_password').val(ppp_password);
3598
			}
3599
		});
3600
	}
3601

    
3602
	// Hides all elements of the specified class. This will usually be a section
3603
	function hideClass(s_class, hide) {
3604
		if(hide)
3605
			$('.' + s_class).hide();
3606
		else
3607
			$('.' + s_class).show();
3608
	}
3609

    
3610
	// Hides the <div> in which the specified input element lives so that the input, its label and help text are hidden
3611
	function hideInput(id, hide) {
3612
		if(hide)
3613
			$('#' + id).parent().parent('div').addClass('hidden');
3614
		else
3615
			$('#' + id).parent().parent('div').removeClass('hidden');
3616
	}
3617

    
3618
	// Hides the <div> in which the specified IP address element lives so that the input, its label and help text are hidden
3619
	function hideIpAddress(id, hide) {
3620
		if(hide)
3621
			$('#' + id).parent().parent().parent('div').addClass('hidden');
3622
		else
3623
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
3624
	}
3625

    
3626
	// Hides the <div> in which the specified checkbox lives so that the checkbox, its label and help text are hidden
3627
	function hideCheckbox(id, hide) {
3628
		if(hide)
3629
			$('#' + id).parent().parent().parent('div').addClass('hidden');
3630
		else
3631
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
3632
	}
3633

    
3634
	function show_dhcp6adv() {
3635
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3636
		var adv = $('#dhcp6adv').prop('checked');
3637

    
3638
		hideCheckbox('dhcp6usev4iface', ovr);
3639
		hideCheckbox('dhcp6prefixonly', ovr);
3640
		hideInput('dhcp6-ia-pd-len', ovr);
3641
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3642
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3643

    
3644
		hideClass('dhcp6advanced', !adv || ovr);
3645
	}
3646

    
3647
	function setDHCPoptions() {
3648
		var adv = $('#dhcpadv').prop('checked');
3649
		var ovr = $('#dhcpovr').prop('checked');
3650

    
3651
		if(ovr) {
3652
			hideInput('dhcphostname', true);
3653
			hideIpAddress('alias-address', true);
3654
			hideInput('dhcprejectfrom', true);
3655
			hideInput('adv_dhcp_config_file_override_path', false);
3656
			hideClass('dhcpadvanced', true);
3657
		} else {
3658
			hideInput('dhcphostname', false);
3659
			hideIpAddress('alias-address', false);
3660
			hideInput('dhcprejectfrom', false);
3661
			hideInput('adv_dhcp_config_file_override_path', true);
3662
			hideClass('dhcpadvanced', !adv);
3663
		}
3664
	}
3665

    
3666
	// On page load . .
3667
	updateType($('#type').val());
3668
	updateTypeSix($('#type6').val());
3669
	show_reset_settings($('#pppoe-reset-type').val());
3670
	$("#add").prop('type' ,'button');
3671
	$("#cnx").prop('type' ,'button');
3672
	$("#addgw").prop('type' ,'button');
3673
	$("#add6").prop('type' ,'button');
3674
	$("#cnx6").prop('type' ,'button');
3675
	$("#addgw6").prop('type' ,'button');
3676
	hideClass('dhcp6advanced', true);
3677
	hideClass('dhcpadvanced', true);
3678
	show_dhcp6adv();
3679
	setDHCPoptions()
3680

    
3681
	// On click . .
3682
   $('#type').on('change', function() {
3683
		updateType( this.value );
3684
	});
3685

    
3686
	$('#type6').on('change', function() {
3687
		updateTypeSix( this.value );
3688
	});
3689

    
3690
	$('#pppoe-reset-type').on('change', function() {
3691
		show_reset_settings( this.value );
3692
	});
3693

    
3694
	$("#add").click(function() {
3695
		hide_add_gatewaysave();
3696
	});
3697

    
3698
	$("#cnx").click(function() {
3699
		$("#newgateway").modal('hide');
3700
	});
3701

    
3702
	$("#add6").click(function() {
3703
		hide_add_gatewaysave_v6();
3704
	});
3705

    
3706
	$("#cnx6").click(function() {
3707
		$("#newgateway6").modal('hide');
3708
	});
3709

    
3710
	$('#country').on('change', function() {
3711
		providers_list();
3712
	});
3713

    
3714
	$('#provider_list').on('change', function() {
3715
		providerplan_list();
3716
	});
3717

    
3718
	$('#providerplan').on('change', function() {
3719
		prefill_provider();
3720
	});
3721

    
3722
	$('#dhcpadv, #dhcpovr').click(function () {
3723
		setDHCPoptions();
3724
	});
3725

    
3726
	$('#dhcp6adv').click(function () {
3727
		show_dhcp6adv();
3728
	});
3729

    
3730
	$('#adv_dhcp6_config_file_override').click(function () {
3731
		show_dhcp6adv();
3732
	});
3733

    
3734
	// DHCP preset actions
3735
	// Set presets from value of radio buttons
3736
	function setPresets(val) {
3737
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3738
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3739
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3740
		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']);?>");
3741
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3742
	}
3743

    
3744
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3745
		$('#adv_dhcp_pt_timeout').val(timeout);
3746
		$('#adv_dhcp_pt_retry').val(retry);
3747
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3748
		$('#adv_dhcp_pt_reboot').val(reboot);
3749
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3750
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3751
	}
3752

    
3753
	// Set preset buttons on page load
3754
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3755
	if(sv == "")
3756
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3757

    
3758
	// Set preset from value
3759
	setPresets(sv);
3760

    
3761
	// On click . .
3762
	$('[id=adv_dhcp_pt_values]').click(function () {
3763
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3764
	});
3765
});
3766
//]]>
3767
</script>
3768

    
3769
<?php include("foot.inc");
(83-83/235)