Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
365
// print_r($pconfig);
366

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

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

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

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

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

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

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

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

    
500
		clear_subsystem_dirty('interfaces');
501

    
502
		filter_configure();
503

    
504
		enable_rrd_graphing();
505

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

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

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

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

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

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

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

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

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

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

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

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

    
847
		unset($min_mtu, $max_mtu);
848

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

    
865
				$realhwif_array = get_parent_interface($ifdata['if']);
866
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
867
				$parent_realhwif = $realhwif_array[0];
868

    
869
				if ($parent_realhwif != $wancfg['if']) {
870
					continue;
871
				}
872

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

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

    
969
					if (strlen($_POST['key' . $i]) == 10) {
970
						/* hex key */
971
						if (stristr($_POST['key' . $i], "0x") == false) {
972
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
973
						}
974
						continue;
975
					}
976

    
977
					if (strlen($_POST['key' . $i]) == 12) {
978
						/* hex key */
979
						if (stristr($_POST['key' . $i], "0x") == false) {
980
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
981
						}
982
						continue;
983
					}
984

    
985
					/* 128 bit */
986
					if (strlen($_POST['key' . $i]) == 13) {
987
						continue;
988
					}
989

    
990
					if (strlen($_POST['key' . $i]) == 26) {
991
						/* hex key */
992
						if (stristr($_POST['key' . $i], "0x") == false) {
993
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
994
						}
995
						continue;
996
					}
997

    
998
					if (strlen($_POST['key' . $i]) == 28) {
999
						continue;
1000
					}
1001

    
1002
					$input_errors[] = gettext("Invalid WEP key. Enter a valid 40, 64, 104 or 128 bit WEP key.");
1003
					break;
1004
				}
1005
			}
1006
		}
1007

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

    
1015
		if ($_POST['wpa_enable'] == "yes") {
1016
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1017
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1018
			}
1019
		}
1020
	}
1021
	if (!$input_errors) {
1022
		// These 3 fields can be a list of multiple data items when used for MLPPP.
1023
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
1024
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
1025
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
1026
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
1027

    
1028
		if ($wancfg['ipaddr'] != $_POST['type']) {
1029
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1030
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1031
				unset($a_ppps[$pppid]);
1032
			} else if ($wancfg['ipaddr'] == "dhcp") {
1033
				kill_dhclient_process($wancfg['if']);
1034
			}
1035
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1036
				$pid = find_dhcp6c_process($wancfg['if']);
1037
				if ($pid) {
1038
					posix_kill($pid, SIGTERM);
1039
				}
1040
			}
1041
		}
1042
		$ppp = array();
1043
		if ($wancfg['ipaddr'] != "ppp") {
1044
			unset($wancfg['ipaddr']);
1045
		}
1046
		if ($wancfg['ipaddrv6'] != "ppp") {
1047
			unset($wancfg['ipaddrv6']);
1048
		}
1049
		unset($wancfg['subnet']);
1050
		unset($wancfg['gateway']);
1051
		unset($wancfg['subnetv6']);
1052
		unset($wancfg['gatewayv6']);
1053
		unset($wancfg['dhcphostname']);
1054
		unset($wancfg['dhcprejectfrom']);
1055
		unset($wancfg['dhcp6-duid']);
1056
		unset($wancfg['dhcp6-ia-pd-len']);
1057
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1058
		unset($wancfg['dhcp6prefixonly']);
1059
		unset($wancfg['dhcp6usev4iface']);
1060
		unset($wancfg['track6-interface']);
1061
		unset($wancfg['track6-prefix-id']);
1062
		unset($wancfg['prefix-6rd']);
1063
		unset($wancfg['prefix-6rd-v4plen']);
1064
		unset($wancfg['gateway-6rd']);
1065

    
1066
		unset($wancfg['adv_dhcp_pt_timeout']);
1067
		unset($wancfg['adv_dhcp_pt_retry']);
1068
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1069
		unset($wancfg['adv_dhcp_pt_reboot']);
1070
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1071
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1072

    
1073
		unset($wancfg['adv_dhcp_pt_values']);
1074

    
1075
		unset($wancfg['adv_dhcp_send_options']);
1076
		unset($wancfg['adv_dhcp_request_options']);
1077
		unset($wancfg['adv_dhcp_required_options']);
1078
		unset($wancfg['adv_dhcp_option_modifiers']);
1079

    
1080
		unset($wancfg['adv_dhcp_config_advanced']);
1081
		unset($wancfg['adv_dhcp_config_file_override']);
1082
		unset($wancfg['adv_dhcp_config_file_override_path']);
1083

    
1084
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1085
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1086
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1087
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1088

    
1089
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1090
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1091
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1092
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1093
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1094

    
1095
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1096
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1097
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1098
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1099
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1100

    
1101
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1102
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1103

    
1104
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1105
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1106
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1107
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1108

    
1109
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1110
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1111
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1112
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1113
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1114

    
1115
		unset($wancfg['adv_dhcp6_config_advanced']);
1116
		unset($wancfg['adv_dhcp6_config_file_override']);
1117
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1118

    
1119
		unset($wancfg['pppoe_password']);
1120
		unset($wancfg['pptp_username']);
1121
		unset($wancfg['pptp_password']);
1122
		unset($wancfg['provider']);
1123
		unset($wancfg['ondemand']);
1124
		unset($wancfg['timeout']);
1125
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1126
			unset($wancfg['pppoe']['pppoe-reset-type']);
1127
		}
1128
		unset($wancfg['local']);
1129

    
1130
		unset($wancfg['remote']);
1131
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1132
			if ($wancfg['ipaddr'] != 'ppp') {
1133
				unset($a_ppps[$pppid]['apn']);
1134
				unset($a_ppps[$pppid]['phone']);
1135
				unset($a_ppps[$pppid]['provider']);
1136
				unset($a_ppps[$pppid]['ondemand']);
1137
			}
1138
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1139
				unset($a_ppps[$pppid]['localip']);
1140
				unset($a_ppps[$pppid]['subnet']);
1141
				unset($a_ppps[$pppid]['gateway']);
1142
			}
1143
			if ($wancfg['ipaddr'] != 'pppoe') {
1144
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1145
			}
1146
			if ($wancfg['type'] != $_POST['type']) {
1147
				unset($a_ppps[$pppid]['idletimeout']);
1148
			}
1149
		}
1150

    
1151
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1152
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1153

    
1154
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1155
		switch ($_POST['type']) {
1156
			case "staticv4":
1157
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1158
				$wancfg['subnet'] = $_POST['subnet'];
1159
				if ($_POST['gateway'] != "none") {
1160
					$wancfg['gateway'] = $_POST['gateway'];
1161
				}
1162
				break;
1163
			case "dhcp":
1164
				$wancfg['ipaddr'] = "dhcp";
1165
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1166
				$wancfg['alias-address'] = $_POST['alias-address'];
1167
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1168
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1169

    
1170
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1171
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1172
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1173
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1174
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1175
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1176

    
1177
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1178

    
1179
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1180
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1181
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1182
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1183

    
1184
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1185
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1186
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1187

    
1188
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1189
				if ($gateway_item) {
1190
					$a_gateways[] = $gateway_item;
1191
				}
1192
				break;
1193
			case "ppp":
1194
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1195
				$a_ppps[$pppid]['type'] = $_POST['type'];
1196
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1197
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1198
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1199
				$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1200
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1201
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1202
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1203
				$wancfg['ipaddr'] = $_POST['type'];
1204
				break;
1205

    
1206
			case "pppoe":
1207
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1208
				$a_ppps[$pppid]['type'] = $_POST['type'];
1209
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1210
				if (isset($_POST['ppp_port'])) {
1211
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1212
				} else {
1213
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1214
				}
1215
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1216
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1217
				if (!empty($_POST['provider'])) {
1218
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1219
				} else {
1220
					$a_ppps[$pppid]['provider'] = true;
1221
				}
1222
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1223
				if (!empty($_POST['pppoe_idletimeout'])) {
1224
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1225
				} else {
1226
					unset($a_ppps[$pppid]['idletimeout']);
1227
				}
1228

    
1229
				if (!empty($_POST['pppoe-reset-type'])) {
1230
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1231
				} else {
1232
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1233
				}
1234
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1235
				$wancfg['ipaddr'] = $_POST['type'];
1236
				if ($gateway_item) {
1237
					$a_gateways[] = $gateway_item;
1238
				}
1239

    
1240
				break;
1241
			case "pptp":
1242
			case "l2tp":
1243
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1244
				$a_ppps[$pppid]['type'] = $_POST['type'];
1245
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1246
				if (isset($_POST['ppp_port'])) {
1247
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1248
				} else {
1249
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1250
				}
1251
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1252
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1253
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1254
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1255
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1256
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1257
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1258
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1259
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1260
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1261
				if (!empty($_POST['pptp_idletimeout'])) {
1262
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1263
				} else {
1264
					unset($a_ppps[$pppid]['idletimeout']);
1265
				}
1266
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1267
				$wancfg['ipaddr'] = $_POST['type'];
1268
				if ($gateway_item) {
1269
					$a_gateways[] = $gateway_item;
1270
				}
1271
				break;
1272
			case "none":
1273
				break;
1274
		}
1275
		switch ($_POST['type6']) {
1276
			case "staticv6":
1277
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1278
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1279
				if ($_POST['gatewayv6'] != "none") {
1280
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1281
				}
1282
				break;
1283
			case "slaac":
1284
				$wancfg['ipaddrv6'] = "slaac";
1285
				break;
1286
			case "dhcp6":
1287
				$wancfg['ipaddrv6'] = "dhcp6";
1288
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1289
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1290
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1291
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1292
				}
1293
				if ($_POST['dhcp6prefixonly'] == "yes") {
1294
					$wancfg['dhcp6prefixonly'] = true;
1295
				}
1296
				if ($_POST['dhcp6usev4iface'] == "yes") {
1297
					$wancfg['dhcp6usev4iface'] = true;
1298
				}
1299

    
1300
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1301
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1304
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1305
				}
1306
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1307
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1310
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1311
				}
1312

    
1313
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1314
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1317
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1318
				}
1319
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1320
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1323
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1326
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1327
				}
1328

    
1329
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1330
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1333
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1334
				}
1335
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1336
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1339
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1340
				}
1341
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1342
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1343
				}
1344

    
1345
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1346
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1347
				}
1348
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1349
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1350
				}
1351

    
1352
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1353
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1354
				}
1355
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1356
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1357
				}
1358
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1359
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1360
				}
1361
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1362
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1363
				}
1364

    
1365
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1366
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1367
				}
1368
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1369
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1370
				}
1371
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1372
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1373
				}
1374
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1375
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1376
				}
1377
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1378
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1379
				}
1380

    
1381
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1382
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1383
				}
1384
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1385
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1386
				}
1387
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1388
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1389
				}
1390

    
1391
				if ($gateway_item) {
1392
					$a_gateways[] = $gateway_item;
1393
				}
1394
				break;
1395
			case "6rd":
1396
				$wancfg['ipaddrv6'] = "6rd";
1397
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1398
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1399
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1400
				if ($gateway_item) {
1401
					$a_gateways[] = $gateway_item;
1402
				}
1403
				break;
1404
			case "6to4":
1405
				$wancfg['ipaddrv6'] = "6to4";
1406
				break;
1407
			case "track6":
1408
				$wancfg['ipaddrv6'] = "track6";
1409
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1410
				if ($_POST['track6-prefix-id--hex'] === "") {
1411
					$wancfg['track6-prefix-id'] = 0;
1412
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1413
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1414
				} else {
1415
					$wancfg['track6-prefix-id'] = 0;
1416
				}
1417
				break;
1418
			case "none":
1419
				break;
1420
		}
1421
		handle_pppoe_reset($_POST);
1422

    
1423
		if ($_POST['blockpriv'] == "yes") {
1424
			$wancfg['blockpriv'] = true;
1425
		} else {
1426
			unset($wancfg['blockpriv']);
1427
		}
1428
		if ($_POST['blockbogons'] == "yes") {
1429
			$wancfg['blockbogons'] = true;
1430
		} else {
1431
			unset($wancfg['blockbogons']);
1432
		}
1433
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1434
		if (empty($_POST['mtu'])) {
1435
			unset($wancfg['mtu']);
1436
		} else {
1437
			$wancfg['mtu'] = $_POST['mtu'];
1438
		}
1439
		if (empty($_POST['mss'])) {
1440
			unset($wancfg['mss']);
1441
		} else {
1442
			$wancfg['mss'] = $_POST['mss'];
1443
		}
1444
		if (empty($_POST['mediaopt'])) {
1445
			unset($wancfg['media']);
1446
			unset($wancfg['mediaopt']);
1447
		} else {
1448
			$mediaopts = explode(' ', $_POST['mediaopt']);
1449
			if ($mediaopts[0] != '') {
1450
				$wancfg['media'] = $mediaopts[0];
1451
			}
1452
			if ($mediaopts[1] != '') {
1453
				$wancfg['mediaopt'] = $mediaopts[1];
1454
			} else {
1455
				unset($wancfg['mediaopt']);
1456
			}
1457
		}
1458
		if (isset($wancfg['wireless'])) {
1459
			handle_wireless_post();
1460
		}
1461

    
1462
		conf_mount_ro();
1463
		write_config();
1464

    
1465
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1466
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1467
		} else {
1468
			$toapplylist = array();
1469
		}
1470
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1471
		$toapplylist[$if]['ppps'] = $old_ppps;
1472
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1473

    
1474
		mark_subsystem_dirty('interfaces');
1475

    
1476
		/* regenerate cron settings/crontab file */
1477
		configure_cron();
1478

    
1479
		header("Location: interfaces.php?if={$if}");
1480
		exit;
1481
	}
1482

    
1483
} // end if ($_POST)
1484

    
1485
function handle_wireless_post() {
1486
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1487
	if (!is_array($wancfg['wireless'])) {
1488
		$wancfg['wireless'] = array();
1489
	}
1490
	$wancfg['wireless']['standard'] = $_POST['standard'];
1491
	$wancfg['wireless']['mode'] = $_POST['mode'];
1492
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1493
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1494
	$wancfg['wireless']['channel'] = $_POST['channel'];
1495
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1496
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1497
	$wancfg['wireless']['distance'] = $_POST['distance'];
1498
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1499
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1500
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1501
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1502
		foreach ($wl_countries_attr as $wl_country) {
1503
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1504
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1505
				break;
1506
			}
1507
		}
1508
	}
1509
	if (!is_array($wancfg['wireless']['wpa'])) {
1510
		$wancfg['wireless']['wpa'] = array();
1511
	}
1512
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1513
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
1514
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1515
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1516
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1517
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1518
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1519
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1520
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1521
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1522
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1523
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1524
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1525
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1526
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1527

    
1528
	if ($_POST['persistcommonwireless'] == "yes") {
1529
		if (!is_array($config['wireless'])) {
1530
			$config['wireless'] = array();
1531
		}
1532
		if (!is_array($config['wireless']['interfaces'])) {
1533
			$config['wireless']['interfaces'] = array();
1534
		}
1535
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1536
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1537
		}
1538
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1539
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1540
	}
1541
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1542
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1543
	} else if (isset($wancfg['wireless']['diversity'])) {
1544
		unset($wancfg['wireless']['diversity']);
1545
	}
1546
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1547
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1548
	} else if (isset($wancfg['wireless']['txantenna'])) {
1549
		unset($wancfg['wireless']['txantenna']);
1550
	}
1551
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1552
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1553
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1554
		unset($wancfg['wireless']['rxantenna']);
1555
	}
1556
	if ($_POST['hidessid_enable'] == "yes") {
1557
		$wancfg['wireless']['hidessid']['enable'] = true;
1558
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1559
		unset($wancfg['wireless']['hidessid']['enable']);
1560
	}
1561
	if ($_POST['mac_acl_enable'] == "yes") {
1562
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1563
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1564
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1565
	}
1566
	if ($_POST['rsn_preauth'] == "yes") {
1567
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1568
	} else {
1569
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1570
	}
1571
	if ($_POST['ieee8021x'] == "yes") {
1572
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1573
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1574
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1575
	}
1576
	if ($_POST['wpa_strict_rekey'] == "yes") {
1577
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1578
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1579
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1580
	}
1581
	if ($_POST['debug_mode'] == "yes") {
1582
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1583
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1584
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1585
	}
1586
	if ($_POST['wpa_enable'] == "yes") {
1587
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1588
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1589
		unset($wancfg['wireless']['wpa']['enable']);
1590
	}
1591

    
1592
	if(ALLOWWEP) {
1593
		if ($_POST['wep_enable'] == "yes") {
1594
			if (!is_array($wancfg['wireless']['wep'])) {
1595
				$wancfg['wireless']['wep'] = array();
1596
			}
1597
			$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
1598
		} else if (isset($wancfg['wireless']['wep'])) {
1599
			unset($wancfg['wireless']['wep']);
1600
		}
1601
	}
1602

    
1603
	if ($_POST['wme_enable'] == "yes") {
1604
		if (!is_array($wancfg['wireless']['wme'])) {
1605
			$wancfg['wireless']['wme'] = array();
1606
		}
1607
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1608
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1609
		unset($wancfg['wireless']['wme']['enable']);
1610
	}
1611
	if ($_POST['puremode'] == "11g") {
1612
		if (!is_array($wancfg['wireless']['pureg'])) {
1613
			$wancfg['wireless']['pureg'] = array();
1614
		}
1615
		$wancfg['wireless']['pureg']['enable'] = true;
1616
	} else if ($_POST['puremode'] == "11n") {
1617
		if (!is_array($wancfg['wireless']['puren'])) {
1618
			$wancfg['wireless']['puren'] = array();
1619
		}
1620
		$wancfg['wireless']['puren']['enable'] = true;
1621
	} else {
1622
		if (isset($wancfg['wireless']['pureg'])) {
1623
			unset($wancfg['wireless']['pureg']);
1624
		}
1625
		if (isset($wancfg['wireless']['puren'])) {
1626
			unset($wancfg['wireless']['puren']);
1627
		}
1628
	}
1629
	if ($_POST['apbridge_enable'] == "yes") {
1630
		if (!is_array($wancfg['wireless']['apbridge'])) {
1631
			$wancfg['wireless']['apbridge'] = array();
1632
		}
1633
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1634
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1635
		unset($wancfg['wireless']['apbridge']['enable']);
1636
	}
1637
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1638
		if (!is_array($wancfg['wireless']['turbo'])) {
1639
			$wancfg['wireless']['turbo'] = array();
1640
		}
1641
		$wancfg['wireless']['turbo']['enable'] = true;
1642
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1643
		unset($wancfg['wireless']['turbo']['enable']);
1644
	}
1645

    
1646
	if(ALLOWWEP) {
1647
		$wancfg['wireless']['wep']['key'] = array();
1648
		for ($i = 1; $i <= 4; $i++) {
1649
			if ($_POST['key' . $i]) {
1650
				$newkey = array();
1651
				$newkey['value'] = $_POST['key' . $i];
1652
				if ($_POST['txkey'] == $i) {
1653
					$newkey['txkey'] = true;
1654
				}
1655
				$wancfg['wireless']['wep']['key'][] = $newkey;
1656
			}
1657
		}
1658
	}
1659

    
1660
	interface_sync_wireless_clones($wancfg, true);
1661
}
1662

    
1663
function check_wireless_mode() {
1664
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1665

    
1666
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1667
		return;
1668
	}
1669

    
1670
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1671
		$clone_count = 1;
1672
	} else {
1673
		$clone_count = 0;
1674
	}
1675

    
1676
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1677
		foreach ($config['wireless']['clone'] as $clone) {
1678
			if ($clone['if'] == $wlanbaseif) {
1679
				$clone_count++;
1680
			}
1681
		}
1682
	}
1683

    
1684
	if ($clone_count > 1) {
1685
		$old_wireless_mode = $wancfg['wireless']['mode'];
1686
		$wancfg['wireless']['mode'] = $_POST['mode'];
1687
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1688
			$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']]);
1689
		} else {
1690
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1691
		}
1692
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1693
	}
1694
}
1695

    
1696
// Find all possible media options for the interface
1697
$mediaopts_list = array();
1698
$intrealname = $config['interfaces'][$if]['if'];
1699
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1700
foreach ($mediaopts as $mediaopt) {
1701
	preg_match("/media (.*)/", $mediaopt, $matches);
1702
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1703
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1704
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1705
	} else {
1706
		// there is only media like "media 1000baseT"
1707
		array_push($mediaopts_list, $matches[1]);
1708
	}
1709
}
1710

    
1711
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1712
$shortcut_section = "interfaces";
1713

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

    
1717
$closehead = false;
1718

    
1719
// Get the MAC address
1720
$ip = $_SERVER['REMOTE_ADDR'];
1721
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1722
$mymac = str_replace("\n", "", $mymac);
1723

    
1724
function build_mediaopts_list() {
1725
	global $mediaopts_list;
1726

    
1727
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1728
			 " " =>	 "------- Media Supported by this interface -------"
1729
			];
1730

    
1731
	foreach ($mediaopts_list as $mediaopt) {
1732
		$list[$mediaopt] = $mediaopt;
1733
	}
1734

    
1735
	return($list);
1736
}
1737

    
1738
function build_gateway_list() {
1739
	global $a_gateways, $if;
1740

    
1741
	$list = array("none" => "None");
1742
	foreach ($a_gateways as $gateway) {
1743
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1744
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1745
		}
1746
	}
1747

    
1748
	return($list);
1749
}
1750

    
1751
function build_gatewayv6_list() {
1752
	global $a_gateways, $if;
1753

    
1754
	$list = array("none" => "None");
1755
	foreach ($a_gateways as $gateway) {
1756
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1757
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1758
		}
1759
	}
1760

    
1761
	return($list);
1762
}
1763

    
1764
include("head.inc");
1765

    
1766
if ($input_errors)
1767
	print_input_errors($input_errors);
1768

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

    
1773
if ($savemsg)
1774
	print_info_box($savemsg, 'success');
1775

    
1776

    
1777
require_once('classes/Form.class.php');
1778
require_once('classes/Modal.class.php');
1779

    
1780
$form = new Form(new Form_Button(
1781
	'Submit',
1782
	gettext("Save")
1783
));
1784

    
1785
$section = new Form_Section('General configuration');
1786

    
1787
$section->addInput(new Form_Checkbox(
1788
	'enable',
1789
	'Enable',
1790
	'Enable interface',
1791
	$pconfig['enable'],
1792
	'yes'
1793
));
1794

    
1795
$section->addInput(new Form_Input(
1796
	'descr',
1797
	'Description',
1798
	'text',
1799
	$pconfig['descr']
1800
))->setHelp('Enter a description (name) for the interface here.');
1801

    
1802
$section->addInput(new Form_Select(
1803
	'type',
1804
	'IPv4 Configuration Type',
1805
	$pconfig['type'],
1806
	$types4
1807
));
1808

    
1809
$section->addInput(new Form_Select(
1810
	'type6',
1811
	'IPv6 Configuration Type',
1812
	$pconfig['type6'],
1813
	$types6
1814
));
1815

    
1816
$macaddress = new Form_Input(
1817
	'mac',
1818
	'MAC Address',
1819
	'text',
1820
	$pconfig['mac'],
1821
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1822
);
1823

    
1824
$btnmymac = new Form_Button(
1825
	'btnmymac',
1826
	'Copy My MAC'
1827
	);
1828

    
1829
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1830

    
1831
$group = new Form_Group('MAC controls');
1832
$group->add($macaddress);
1833
// $group->add($btnmymac);
1834
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1835
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1836
$section->add($group);
1837

    
1838
$section->addInput(new Form_Input(
1839
	'mtu',
1840
	'MTU',
1841
	'number',
1842
	$pconfig['mtu']
1843
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1844
			'This is typically 1500 bytes but can vary in some circumstances.');
1845

    
1846
$section->addInput(new Form_Input(
1847
	'mss',
1848
	'MSS',
1849
	'number',
1850
	$pconfig['mss']
1851
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1852
			'header size) will be in effect.');
1853

    
1854
if (count($mediaopts_list) > 0) {
1855
	$section->addInput(new Form_Select(
1856
		'mediaopt',
1857
		'Speed and Duplex',
1858
		rtrim($mediaopt_from_config),
1859
		build_mediaopts_list()
1860
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1861
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1862
}
1863

    
1864
$form->add($section);
1865

    
1866
$section = new Form_Section('Static IPv4 configuration');
1867
$section->addClass('staticv4');
1868

    
1869
$section->addInput(new Form_IpAddress(
1870
	'ipaddr',
1871
	'IPv4 Address',
1872
	$pconfig['ipaddr']
1873
))->addMask('subnet', $pconfig['subnet'], 32);
1874

    
1875
$group = new Form_Group('IPv4 Upstream gateway');
1876

    
1877
$group->add(new Form_Select(
1878
	'gateway',
1879
	'IPv4 Upstream Gateway',
1880
	$pconfig['gateway'],
1881
	build_gateway_list()
1882
));
1883

    
1884
$group->add(new Form_Button(
1885
	'addgw',
1886
	'Add a new gateway'
1887
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1888

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

    
1893
$section->add($group);
1894

    
1895
$form->add($section);
1896

    
1897
// Add new gateway modal pop-up
1898
$modal = new Modal('New gateway', 'newgateway', 'large');
1899

    
1900
$modal->addInput(new Form_Checkbox(
1901
	'defaultgw',
1902
	'Default',
1903
	'Default gateway',
1904
	($if == "wan" || $if == "WAN")
1905
));
1906

    
1907
$modal->addInput(new Form_Input(
1908
	'name',
1909
	'Gateway name',
1910
	'text',
1911
	$wancfg['descr'] . "GW"
1912
));
1913

    
1914
$modal->addInput(new Form_IpAddress(
1915
	'gatewayip',
1916
	'Gateway IPv4',
1917
	null
1918
));
1919

    
1920
$modal->addInput(new Form_Input(
1921
	'gatewaydescr',
1922
	'Description',
1923
	'text'
1924
));
1925

    
1926
$btnaddgw = new Form_Button(
1927
	'add',
1928
	'Add'
1929
);
1930

    
1931
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
1932

    
1933
$btncnxgw = new Form_Button(
1934
	'cnx',
1935
	'Cancel'
1936
);
1937

    
1938
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
1939

    
1940
$modal->addInput(new Form_StaticText(
1941
	null,
1942
	$btnaddgw . $btncnxgw
1943
));
1944

    
1945
$form->add($modal);
1946

    
1947
$section = new Form_Section('Static IPv6 configuration');
1948
$section->addClass('staticv6');
1949

    
1950
$section->addInput(new Form_IpAddress(
1951
	'ipaddrv6',
1952
	'IPv6 address',
1953
	$pconfig['ipaddrv6']
1954
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1955

    
1956
$group = new Form_Group('IPv6 Upstream gateway');
1957

    
1958
$group->add(new Form_Select(
1959
	'gatewayv6',
1960
	'IPv6 Upstream Gateway',
1961
	$pconfig['gatewayv6'],
1962
	build_gatewayv6_list()
1963
));
1964

    
1965
$group->add(new Form_Button(
1966
	'addgw6',
1967
	'Add a new gateway'
1968
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1969

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

    
1973
$section->add($group);
1974
$form->add($section);
1975

    
1976
// Add new gateway modal pop-up for IPv6
1977
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1978

    
1979
$modal->addInput(new Form_Checkbox(
1980
	'defaultgw6',
1981
	'Default',
1982
	'Default gateway',
1983
	($if == "wan" || $if == "WAN")
1984
));
1985

    
1986
$modal->addInput(new Form_Input(
1987
	'name6',
1988
	'Gateway name',
1989
	'text',
1990
	$wancfg['descr'] . "GWv6"
1991
));
1992

    
1993
$modal->addInput(new Form_IpAddress(
1994
	'gatewayip6',
1995
	'Gateway IPv6',
1996
	null
1997
));
1998

    
1999
$modal->addInput(new Form_Input(
2000
	'gatewaydescr6',
2001
	'Description',
2002
	'text'
2003
));
2004

    
2005
$btnaddgw6 = new Form_Button(
2006
	'add6',
2007
	'Add'
2008
);
2009

    
2010
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
2011

    
2012
$btncnxgw6 = new Form_Button(
2013
	'cnx6',
2014
	'Cancel'
2015
);
2016

    
2017
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
2018

    
2019
$modal->addInput(new Form_StaticText(
2020
	null,
2021
	$btnaddgw6 . $btncnxgw6
2022
));
2023

    
2024
$form->add($modal);
2025

    
2026
// ==== DHCP client configuration =============================
2027

    
2028
$section = new Form_Section('DHCP client configuration');
2029
$section->addClass('dhcp');
2030

    
2031
$group = new Form_Group('Options');
2032

    
2033
$group->add(new Form_Checkbox(
2034
	'dhcpadv',
2035
	null,
2036
	'Show DHCP advanced options',
2037
	false
2038
));
2039

    
2040
$group->add(new Form_Checkbox(
2041
	'dhcpovr',
2042
	null,
2043
	'Config file override',
2044
	false
2045
));
2046

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

    
2049
$section->addInput(new Form_Input(
2050
	'dhcphostname',
2051
	'Hostname',
2052
	'text',
2053
	$pconfig['dhcphostname']
2054
))->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).');
2055

    
2056
$section->addInput(new Form_IpAddress(
2057
	'alias-address',
2058
	'Alias IPv4 address',
2059
	$pconfig['alias-address']
2060
))->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.');
2061

    
2062
$section->addInput(new Form_Input(
2063
	'dhcprejectfrom',
2064
	'Reject leases from',
2065
	'text',
2066
	$pconfig['dhcprejectfrom']
2067
))->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. ' .
2068
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
2069

    
2070
$group = new Form_Group('Protocol timing');
2071
$group->addClass('dhcpadvanced');
2072

    
2073
$group->add(new Form_Input(
2074
	'adv_dhcp_pt_timeout',
2075
	null,
2076
	'number',
2077
	$pconfig['adv_dhcp_pt_timeout']
2078
))->setHelp('Timeout');
2079

    
2080
$group->add(new Form_Input(
2081
	'adv_dhcp_pt_retry',
2082
	null,
2083
	'number',
2084
	$pconfig['adv_dhcp_pt_retry']
2085
))->setHelp('Retry');
2086

    
2087
$group->add(new Form_Input(
2088
	'adv_dhcp_pt_select_timeout',
2089
	null,
2090
	'number',
2091
	$pconfig['adv_dhcp_pt_select_timeout']
2092
))->setHelp('Select timeout');
2093

    
2094
$group->add(new Form_Input(
2095
	'adv_dhcp_pt_reboot',
2096
	null,
2097
	'number',
2098
	$pconfig['adv_dhcp_pt_reboot']
2099
))->setHelp('Reboot');
2100

    
2101
$group->add(new Form_Input(
2102
	'adv_dhcp_pt_backoff_cutoff',
2103
	null,
2104
	'number',
2105
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2106
))->setHelp('Backoff cutoff');
2107

    
2108
$group->add(new Form_Input(
2109
	'adv_dhcp_pt_initial_interval',
2110
	null,
2111
	'number',
2112
	$pconfig['adv_dhcp_pt_initial_interval']
2113
))->setHelp('Initial interval');
2114

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

    
2117
$group = new Form_Group('Presets');
2118
$group->addClass('dhcpadvanced');
2119

    
2120
$group->add(new Form_Checkbox(
2121
	'adv_dhcp_pt_values',
2122
	null,
2123
	'FreeBSD default',
2124
	null,
2125
	'DHCP'
2126
))->displayAsRadio();
2127

    
2128
$group->add(new Form_Checkbox(
2129
	'adv_dhcp_pt_values',
2130
	null,
2131
	'Clear',
2132
	null,
2133
	'Clear'
2134
))->displayAsRadio();
2135

    
2136
$group->add(new Form_Checkbox(
2137
	'adv_dhcp_pt_values',
2138
	null,
2139
	'pfSense Default',
2140
	null,
2141
	'pfSense'
2142
))->displayAsRadio();
2143

    
2144
$group->add(new Form_Checkbox(
2145
	'adv_dhcp_pt_values',
2146
	null,
2147
	'Saved Cfg',
2148
	null,
2149
	'SavedCfg'
2150
))->displayAsRadio();
2151

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

    
2155
$section->add($group);
2156

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

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

    
2169
$section = new Form_Section('Lease Requirements and Requests');
2170
$section->addClass('dhcpadvanced');
2171

    
2172
$section->addInput(new Form_Input(
2173
	'adv_dhcp_send_options',
2174
	'Send options',
2175
	'text',
2176
	$pconfig['adv_dhcp_send_options']
2177
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2178
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2179
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2180
			'Some ISPs may require certain options be or not be sent.');
2181

    
2182
$section->addInput(new Form_Input(
2183
	'adv_dhcp_request_options',
2184
	'Request options',
2185
	'text',
2186
	$pconfig['adv_dhcp_request_options']
2187
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2188
			'Some ISPs may require certain options be or not be requested.');
2189

    
2190
$section->addInput(new Form_Input(
2191
	'adv_dhcp_require_options',
2192
	'Request options',
2193
	'text',
2194
	$pconfig['adv_dhcp_require_options']
2195
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2196

    
2197
$section->addInput(new Form_Input(
2198
	'adv_dhcp_option_modifiers',
2199
	'Option modifiers',
2200
	'text',
2201
	$pconfig['adv_dhcp_option_modifiers']
2202
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2203
			'modifiers: (default, supersede, prepend, append)');
2204

    
2205
$form->add($section);
2206

    
2207
// DHCP6 client config
2208

    
2209
$section = new Form_Section('DHCP6 client configuration');
2210
$section->addClass('dhcp6');
2211

    
2212
$section->addInput(new Form_Checkbox(
2213
	'dhcp6adv',
2214
	'Advanced',
2215
	'Show DHCPv6 advanced options',
2216
	$pconfig['adv_dhcp6_config_advanced']
2217
));
2218

    
2219
$section->addInput(new Form_Checkbox(
2220
	'adv_dhcp6_config_file_override',
2221
	'Config file override',
2222
	'Override the configuration from this file',
2223
	$pconfig['adv_dhcp6_config_file_override']
2224
));
2225

    
2226
$section->addInput(new Form_Checkbox(
2227
	'dhcp6usev4iface',
2228
	'Use IPv4 connectivity as parent interface',
2229
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2230
	$pconfig['dhcp6usev4iface']
2231
));
2232

    
2233
$section->addInput(new Form_Checkbox(
2234
	'dhcp6prefixonly',
2235
	'Request only an IPv6 prefix',
2236
	'Only request an IPv6 prefix, do not request an IPv6 address',
2237
	$pconfig['dhcp6prefixonly']
2238
));
2239

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

    
2247
$section->addInput(new Form_Checkbox(
2248
	'dhcp6-ia-pd-send-hint',
2249
	'Send IPv6 prefix hint',
2250
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2251
	$pconfig['dhcp6-ia-pd-send-hint']
2252
));
2253

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

    
2264
$form->add($section);
2265

    
2266
// DHCP6 client config - Advanced
2267

    
2268
$section = new Form_Section('Advanced DHCP6 client configuration');
2269
$section->addClass('dhcp6advanced');
2270

    
2271
$section->addInput(new Form_Checkbox(
2272
	'adv_dhcp6_interface_statement_information_only_enable',
2273
	'Information only',
2274
	null,
2275
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2276
));
2277

    
2278
$section->addInput(new Form_Input(
2279
	'adv_dhcp6_interface_statement_send_options',
2280
	'Send options',
2281
	'text',
2282
	$pconfig['adv_dhcp6_interface_statement_send_options']
2283
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2284
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2285
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2286
			'Some DHCP services may require certain options be or not be sent.');
2287

    
2288
$section->addInput(new Form_Input(
2289
	'adv_dhcp6_interface_statement_request_options',
2290
	'Request Options',
2291
	'text',
2292
	$pconfig['adv_dhcp6_interface_statement_request_options']
2293
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2294
			'Some DHCP services may require certain options be or not be requested.');
2295

    
2296
$section->addInput(new Form_Input(
2297
	'adv_dhcp6_interface_statement_script',
2298
	'Scripts',
2299
	'text',
2300
	$pconfig['adv_dhcp6_interface_statement_script']
2301
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2302
			'[/[dirname/[.../]]filename[.ext]].');
2303

    
2304
$group = new Form_Group('Identity Association Statement');
2305

    
2306
$group->add(new Form_Checkbox(
2307
	'adv_dhcp6_id_assoc_statement_address_enable',
2308
	null,
2309
	'Non-Temporary Address Allocation',
2310
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2311
));
2312

    
2313
$group->add(new Form_Input(
2314
	'adv_dhcp6_id_assoc_statement_address_id',
2315
	null,
2316
	'text',
2317
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2318
))->sethelp('id-assoc na ID');
2319

    
2320
$group->add(new Form_IpAddress(
2321
	'adv_dhcp6_id_assoc_statement_address',
2322
	null,
2323
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2324
))->sethelp('IPv6 address');
2325

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

    
2333
$group->add(new Form_Input(
2334
	'adv_dhcp6_id_assoc_statement_address_vltime',
2335
	null,
2336
	'text',
2337
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2338
))->sethelp('vltime');
2339

    
2340
$section->add($group);
2341

    
2342
// Prefix delegation
2343
$group = new Form_Group('');
2344

    
2345
$group->add(new Form_Checkbox(
2346
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2347
	null,
2348
	'Prefix Delegation ',
2349
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2350
));
2351

    
2352
$group->add(new Form_Input(
2353
	'adv_dhcp6_id_assoc_statement_prefix_id',
2354
	null,
2355
	'text',
2356
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2357
))->sethelp('id-assoc pd ID');
2358

    
2359
$group->add(new Form_IpAddress(
2360
	'adv_dhcp6_id_assoc_statement_prefix',
2361
	null,
2362
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2363
))->sethelp('IPv6 prefix');
2364

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

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

    
2379
$section->add($group);
2380

    
2381
$group = new Form_Group('Prefix interface statement');
2382

    
2383
$group->add(new Form_Input(
2384
	'adv_dhcp6_prefix_interface_statement_sla_id',
2385
	null,
2386
	'text',
2387
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2388
))->sethelp('Prefix Interface sla-id');
2389

    
2390
$group->add(new Form_Input(
2391
	'adv_dhcp6_prefix_interface_statement_sla_len',
2392
	null,
2393
	'text',
2394
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2395
))->sethelp('sla-len');
2396

    
2397
$section->add($group);
2398

    
2399
$group = new Form_Group('Authentication statement');
2400

    
2401
$group->add(new Form_Input(
2402
	'adv_dhcp6_authentication_statement_authname',
2403
	null,
2404
	'text',
2405
	$pconfig['adv_dhcp6_authentication_statement_authname']
2406
))->sethelp('Authname');
2407

    
2408
$group->add(new Form_Input(
2409
	'adv_dhcp6_authentication_statement_protocol',
2410
	null,
2411
	'text',
2412
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2413
))->sethelp('Protocol');
2414

    
2415
$group->add(new Form_Input(
2416
	'adv_dhcp6_authentication_statement_algorithm',
2417
	null,
2418
	'text',
2419
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2420
))->sethelp('Algorithm');
2421

    
2422
$group->add(new Form_Input(
2423
	'adv_dhcp6_authentication_statement_rdm',
2424
	null,
2425
	'text',
2426
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2427
))->sethelp('RDM');
2428

    
2429
$section->add($group);
2430

    
2431
$group = new Form_Group('Keyinfo statement');
2432

    
2433
$group->add(new Form_Input(
2434
	'adv_dhcp6_key_info_statement_keyname',
2435
	null,
2436
	'text',
2437
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2438
))->sethelp('Keyname');
2439

    
2440
$group->add(new Form_Input(
2441
	'adv_dhcp6_key_info_statement_realm',
2442
	null,
2443
	'text',
2444
	$pconfig['adv_dhcp6_key_info_statement_realm']
2445
))->sethelp('Realm');
2446

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

    
2449
$group = new Form_Group('');
2450

    
2451
$group->add(new Form_Input(
2452
	'adv_dhcp6_key_info_statement_keyid',
2453
	null,
2454
	'text',
2455
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2456
))->sethelp('KeyID');
2457

    
2458
$group->add(new Form_Input(
2459
	'adv_dhcp6_key_info_statement_secret',
2460
	null,
2461
	'text',
2462
	$pconfig['adv_dhcp6_key_info_statement_secret']
2463
))->sethelp('Secret');
2464

    
2465
$group->add(new Form_Input(
2466
	'adv_dhcp6_key_info_statement_expire',
2467
	null,
2468
	'text',
2469
	$pconfig['adv_dhcp6_key_info_statement_expire']
2470
))->sethelp('Expire');
2471

    
2472
$section->add($group);
2473

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

    
2476
$section = new Form_Section('6RD Configuration');
2477
$section->addClass('_6rd');
2478

    
2479
$section->addInput(new Form_Input(
2480
	'prefix-6rd',
2481
	'6RD Prefix',
2482
	'text',
2483
	$pconfig['prefix-6rd']
2484
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2485

    
2486
$section->addInput(new Form_Input(
2487
	'gateway-6rd',
2488
	'6RD Border relay',
2489
	'text',
2490
	$pconfig['gateway-6rd']
2491
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2492

    
2493
$section->addInput(new Form_Select(
2494
	'prefix-6rd-v4plen',
2495
	'6RD IPv4 Prefix length',
2496
	$pconfig['prefix-6rd-v4plen'],
2497
	array_combine(range(0, 32), range(0, 32))
2498
))->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.');
2499

    
2500
$form->add($section);
2501

    
2502
// Track IPv6 ointerface section
2503
$section = new Form_Section('Track IPv6 Interface');
2504
$section->addClass('track6');
2505

    
2506
function build_ipv6interface_list() {
2507
	global $config, $section;
2508

    
2509
	$list = array('' => '');
2510

    
2511
	$interfaces = get_configured_interface_with_descr(false, true);
2512
	$dynv6ifs = array();
2513

    
2514
	foreach ($interfaces as $iface => $ifacename) {
2515
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2516
			case "6to4":
2517
			case "6rd":
2518
			case "dhcp6":
2519
				$dynv6ifs[$iface] = array(
2520
					'name' => $ifacename,
2521
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2522
				);
2523
				break;
2524
			default:
2525
				continue;
2526
		}
2527
	}
2528

    
2529
	foreach ($dynv6ifs as $iface => $ifacedata) {
2530
		$list[$iface] = $ifacedata['name'];
2531

    
2532
		$section->addInput(new Form_Input(
2533
			'ipv6-num-prefix-ids-' . $iface,
2534
			null,
2535
			'hidden',
2536
			$ifacedata['ipv6_num_prefix_ids']
2537
		));
2538
	}
2539

    
2540
	return($list);
2541
}
2542

    
2543
$section->addInput(new Form_Select(
2544
	'track6-interface',
2545
	'IPv6 Interface',
2546
	$pconfig['track6-interface'],
2547
	build_ipv6interface_list()
2548
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2549

    
2550
if ($pconfig['track6-prefix-id'] == "") {
2551
	$pconfig['track6-prefix-id'] = 0;
2552
}
2553

    
2554
$section->addInput(new Form_Input(
2555
	'track6-prefix-id--hex' . $iface,
2556
	'IPv6 Prefix ID',
2557
	'text',
2558
	sprintf("%x", $pconfig['track6-prefix-id'])
2559
))->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.');
2560

    
2561
$section->addInput(new Form_Input(
2562
	'track6-prefix-id-max' . $iface,
2563
	null,
2564
	'hidden',
2565
	0
2566
));
2567

    
2568
$form->add($section);
2569

    
2570
/// PPP section
2571

    
2572
$section = new Form_Section('PPP Configuration');
2573
$section->addClass('ppp');
2574

    
2575
$section->addInput(new Form_Select(
2576
	'country',
2577
	'Country',
2578
	$pconfig['country'],
2579
	[]
2580
));
2581

    
2582
$section->addInput(new Form_Select(
2583
	'provider_list',
2584
	'Provider',
2585
	$pconfig['provider_list'],
2586
	[]
2587
));
2588

    
2589
$section->addInput(new Form_Select(
2590
	'providerplan',
2591
	'Plan',
2592
	$pconfig['providerplan'],
2593
	[]
2594
))->setHelp('Select to fill in data for your service provider.');
2595

    
2596
$section->addInput(new Form_Input(
2597
	'ppp_username',
2598
	'Username',
2599
	'text',
2600
	$pconfig['ppp_username']
2601
));
2602

    
2603
$section->addInput(new Form_Input(
2604
	'ppp_password',
2605
	'Password',
2606
	'password',
2607
	$pconfig['ppp_password']
2608
));
2609

    
2610
$section->addInput(new Form_Input(
2611
	'phone',
2612
	'Phone number',
2613
	'text',
2614
	$pconfig['phone']
2615
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2616

    
2617
$section->addInput(new Form_Input(
2618
	'apn',
2619
	'Access Point Name',
2620
	'text',
2621
	$pconfig['apn']
2622
));
2623

    
2624

    
2625
function build_port_list() {
2626
	$list = array("" => "None");
2627

    
2628
	$portlist = glob("/dev/cua*");
2629
	$modems	  = glob("/dev/modem*");
2630
	$portlist = array_merge($portlist, $modems);
2631

    
2632
	foreach ($portlist as $port) {
2633
		if (preg_match("/\.(lock|init)$/", $port)) {
2634
			continue;
2635
		}
2636

    
2637
	$list[trim($port)] = $port;
2638
	}
2639

    
2640
	return($list);
2641
}
2642

    
2643
$section->addInput(new Form_Select(
2644
	'port',
2645
	"Modem port",
2646
	$pconfig['port'],
2647
	build_port_list()
2648
));
2649

    
2650
$section->addInput(new Form_Button(
2651
	'btnadvppp',
2652
	'Advanced PPP',
2653
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2654
))->setHelp('Create a new PPP configuration');
2655

    
2656
$form->add($section);
2657

    
2658
// PPPoE configuration
2659
$section = new Form_Section('PPPoE Configuration');
2660
$section->addClass('pppoe');
2661

    
2662
$section->addInput(new Form_Input(
2663
	'pppoe_username',
2664
	'Username',
2665
	'text',
2666
	$pconfig['pppoe_username']
2667
));
2668

    
2669
$section->addInput(new Form_Input(
2670
	'pppoe_password',
2671
	'Password',
2672
	'password',
2673
	$pconfig['pppoe_password']
2674
));
2675

    
2676
$section->addInput(new Form_Input(
2677
	'provider',
2678
	'Service name',
2679
	'text',
2680
	$pconfig['provider']
2681
))->setHelp('This field can usually be left empty');
2682

    
2683
$section->addInput(new Form_Checkbox(
2684
	'pppoe_dialondemand',
2685
	'Dial on demand',
2686
	'Enable Dial-On-Demand mode ',
2687
	$pconfig['pppoe_dialondemand'],
2688
	'enable'
2689
));
2690

    
2691
$section->addInput(new Form_Input(
2692
	'pppoe_idletimeout',
2693
	'Idle timeout',
2694
	'number',
2695
	$pconfig['pppoe_idletimeout'],
2696
	[min => 0]
2697
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2698
			'An idle timeout of zero disables this feature.');
2699

    
2700
$section->addInput(new Form_Select(
2701
	'pppoe-reset-type',
2702
	'Periodic reset',
2703
	$pconfig['pppoe-reset-type'],
2704
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2705
))->setHelp('Select a reset timing type');
2706

    
2707
$group = new Form_Group('Custom reset');
2708
$group->addClass('pppoecustom');
2709

    
2710
$group->add(new Form_Input(
2711
	'pppoe_resethour',
2712
	null,
2713
	'number',
2714
	$pconfig['pppoe_resethour'],
2715
	[min => 0, max => 23]
2716
))->setHelp('Hour (0-23)');
2717

    
2718
$group->add(new Form_Input(
2719
	'pppoe_resetminute',
2720
	null,
2721
	'number',
2722
	$pconfig['pppoe_resetminute'],
2723
	[min => 0, max => 59]
2724
))->setHelp('Minutes (0-59)');
2725

    
2726
// ToDo: Need a date-picker here
2727
$group->add(new Form_Input(
2728
	'pppoe_resetdate',
2729
	null,
2730
	'text',
2731
	$pconfig['pppoe_resetdate']
2732
))->setHelp('Specific date (mm/dd/yyyy)');
2733

    
2734
$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');
2735

    
2736
$section->add($group);
2737

    
2738
$group = new Form_MultiCheckboxGroup('cron based reset');
2739
$group->addClass('pppoepreset');
2740

    
2741
$group->add(new Form_MultiCheckbox(
2742
	'pppoe_pr_preset_val',
2743
	null,
2744
	'Reset at each month ("0 0 1 * *")',
2745
	$pconfig['pppoe_monthly'],
2746
	'monthly'
2747
))->displayAsRadio();
2748

    
2749
$group->add(new Form_MultiCheckbox(
2750
	'pppoe_pr_preset_val',
2751
	null,
2752
	'Reset at each week ("0 0 * * 0")',
2753
	$pconfig['pppoe_weekly'],
2754
	'weekly'
2755
))->displayAsRadio();
2756

    
2757
$group->add(new Form_MultiCheckbox(
2758
	'pppoe_pr_preset_val',
2759
	null,
2760
	'Reset at each day ("0 0 * * *")',
2761
	$pconfig['pppoe_daily'],
2762
	'daily'
2763
))->displayAsRadio();
2764

    
2765
$group->add(new Form_MultiCheckbox(
2766
	'pppoe_pr_preset_val',
2767
	null,
2768
	'Reset at each hour ("0 * * * *")',
2769
	$pconfig['pppoe_hourly'],
2770
	'hourly'
2771
))->displayAsRadio();
2772

    
2773
$section->add($group);
2774

    
2775
if (isset($pconfig['pppid'])) {
2776
	$section->addInput(new Form_StaticText(
2777
		'Advanced and MLPPP',
2778
		'<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>'
2779
	));
2780
} else {
2781
	$section->addInput(new Form_StaticText(
2782
		'Advanced and MLPPP',
2783
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2784
	));
2785
}
2786

    
2787
$form->add($section);
2788

    
2789
// PPTP & L2TP Configuration section
2790
$section = new Form_Section('PPTP/L2TP Configuration');
2791
$section->addClass('pptp');
2792

    
2793
$section->addInput(new Form_Input(
2794
	'pptp_username',
2795
	'Username',
2796
	'text',
2797
	$pconfig['pptp_username']
2798
));
2799

    
2800
$section->addInput(new Form_Input(
2801
	'pptp_password',
2802
	'Password',
2803
	'password',
2804
	$pconfig['pptp_password']
2805
));
2806

    
2807
$section->addInput(new Form_IpAddress(
2808
	'pptp_local0',
2809
	'Local IP address',
2810
	$pconfig['pptp_localip'][0]
2811
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2812

    
2813
$section->addInput(new Form_IpAddress(
2814
	'pptp_remote0',
2815
	'Remote IP address',
2816
	$pconfig['pptp_remote'][0]
2817
));
2818

    
2819
$section->addInput(new Form_Checkbox(
2820
	'pptp_dialondemand',
2821
	'Dial on demand',
2822
	'Enable Dial-On-Demand mode ',
2823
	$pconfig['pptp_dialondemand'],
2824
	'enable'
2825
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2826
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2827

    
2828
$section->addInput(new Form_Input(
2829
	'pptp_idletimeout',
2830
	'Idle timeout (seconds)',
2831
	'number',
2832
	$pconfig['pptp_idletimeout'],
2833
	[min => 0]
2834
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2835
			'An idle timeout of zero disables this feature.');
2836

    
2837
if (isset($pconfig['pppid'])) {
2838
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2839
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2840
	} else {
2841
		$mlppp_text = "";
2842
	}
2843

    
2844
	$section->addInput(new Form_StaticText(
2845
		'Advanced and MLPPP',
2846
		$mlppp_text . '<a href="/interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) . '" class="navlnk">Click here for additional PPTP and L2TP configuration options. Save first if you made changes.</a>'
2847
	));
2848
} else {
2849
	$section->addInput(new Form_StaticText(
2850
		'Advanced and MLPPP',
2851
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2852
	));
2853
}
2854

    
2855
$form->add($section);
2856

    
2857
// Wireless interface
2858
if (isset($wancfg['wireless'])) {
2859

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

    
2862
	$section->addInput(new Form_Checkbox(
2863
		'persistcommonwireless',
2864
		'Persist common settings',
2865
		'Preserve common wireless configuration through interface deletions and reassignments.',
2866
		$pconfig['persistcommonwireless'],
2867
		'yes'
2868
	));
2869

    
2870
	$mode_list = ['auto' => 'Auto'];
2871

    
2872
	if (is_array($wl_modes)) {
2873
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2874
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2875
		}
2876
	}
2877

    
2878
	if (count($mode_list) == 1)
2879
		$mode_list[''] = '';
2880

    
2881
	$section->addInput(new Form_Select(
2882
		'standard',
2883
		'Standard',
2884
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2885
		$mode_list
2886
	));
2887

    
2888
	if (isset($wl_modes['11g'])) {
2889
		$section->addInput(new Form_Select(
2890
			'protmode',
2891
			'802.11g OFDM Protection Mode',
2892
			$pconfig['protmode'],
2893
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2894
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2895
	}
2896
	else
2897
	{
2898
		$section->addInput(new Form_Input(
2899
			'protmode',
2900
			null,
2901
			'hidden',
2902
			'off'
2903
		));
2904
	}
2905

    
2906
	$mode_list = ['0' => 'Auto'];
2907

    
2908
	if (is_array($wl_modes)) {
2909
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2910
			if ($wl_standard == "11g") {
2911
				$wl_standard = "11b/g";
2912
			} else if ($wl_standard == "11ng") {
2913
				$wl_standard = "11b/g/n";
2914
			} else if ($wl_standard == "11na") {
2915
				$wl_standard = "11a/n";
2916
			}
2917

    
2918
			foreach ($wl_channels as $wl_channel) {
2919
				if (isset($wl_chaninfo[$wl_channel])) {
2920
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2921
				} else {
2922
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2923
				}
2924
			}
2925
		}
2926
	}
2927

    
2928
	$section->addInput(new Form_Select(
2929
		'channel',
2930
		'Channel',
2931
		$pconfig['channel'],
2932
		$mode_list
2933
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2934
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2935

    
2936
	if (ANTENNAS) {
2937
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2938
			$group = new Form_Group('Antenna Settings');
2939

    
2940
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2941
				$group->add(new Form_Select(
2942
					'diversity',
2943
					null,
2944
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2945
					['' => 'Default', '0' => 'Off', '1' => 'On']
2946
				))->setHelp('Diversity');
2947
			}
2948

    
2949
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2950
				$group->add(new Form_Select(
2951
					'txantenna',
2952
					null,
2953
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2954
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2955
				))->setHelp('Transmit antenna');
2956
			}
2957

    
2958
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2959
				$group->add(new Form_Select(
2960
					'rxantenna',
2961
					null,
2962
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2963
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2964
				))->setHelp('Receive antenna');
2965
			}
2966

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

    
2969
			$section->add($group);
2970
		}
2971
	}
2972

    
2973
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2974
			$section->addInput(new Form_Input(
2975
				'distance',
2976
				'Distance setting (meters)',
2977
				'test',
2978
				$pconfig['distance']
2979
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2980
	}
2981

    
2982
	$form->add($section);
2983

    
2984
	// Regulatory settings
2985
	$section = new Form_Section('Regulatory settings');
2986

    
2987
	$domain_list = array("" => 'Default');
2988

    
2989
	if (is_array($wl_regdomains)) {
2990
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2991
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2992
		}
2993
	}
2994

    
2995
	$section->addInput(new Form_Select(
2996
		'regdomain',
2997
		'Regulatory domain',
2998
		$pconfig['regdomain'],
2999
		$domain_list
3000
	))->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');
3001

    
3002
	$country_list = array('' => 'Default');
3003

    
3004
	if (is_array($wl_countries)) {
3005
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3006
			$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']);
3007
		}
3008
	}
3009

    
3010
	$section->addInput(new Form_Select(
3011
		'regcountry',
3012
		'Country',
3013
		$pconfig['regcountry'],
3014
		$country_list
3015
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3016

    
3017
	$section->addInput(new Form_Select(
3018
		'reglocation',
3019
		'Location',
3020
		$pconfig['reglocation'],
3021
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
3022
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3023
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
3024
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3025
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3026
				'These settings may not be able to add additional channels that are not already supported.');
3027

    
3028
	$form->add($section);
3029

    
3030
	$section = new Form_Section('Network-specific wireless configuration');
3031

    
3032
	$section->addInput(new Form_Select(
3033
		'mode',
3034
		'Mode',
3035
		$pconfig['mode'],
3036
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
3037
	));
3038

    
3039
	$section->addInput(new Form_Input(
3040
		'ssid',
3041
		'SSID',
3042
		'text',
3043
		$pconfig['ssid']
3044
	));
3045

    
3046
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3047
		$section->addInput(new Form_Select(
3048
			'puremode',
3049
			'Minimum wireless standard',
3050
			$pconfig['puremode'],
3051
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
3052
		))->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)');
3053
	} elseif (isset($wl_modes['11g'])) {
3054
		$section->addInput(new Form_Checkbox(
3055
			'puremode',
3056
			'802.11g only',
3057
			null,
3058
			$pconfig['puremode'],
3059
			'11g'
3060
		))->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)');
3061
	}
3062

    
3063
	$section->addInput(new Form_Checkbox(
3064
		'apbridge_enable',
3065
		'Allow intra-BSS communication',
3066
		'Allow packets to pass between wireless clients directly when operating as an access point',
3067
		$pconfig['apbridge_enable'],
3068
		'yes'
3069
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
3070

    
3071
	$section->addInput(new Form_Checkbox(
3072
		'wme_enable',
3073
		'Enable WME',
3074
		'Force the card to use WME (wireless QoS)',
3075
		$pconfig['wme_enable'],
3076
		'yes'
3077
	));
3078

    
3079
	$section->addInput(new Form_Checkbox(
3080
		'hidessid_enable',
3081
		'Hide SSID',
3082
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
3083
		$pconfig['hidessid_enable'],
3084
		'yes'
3085
	));
3086

    
3087
	$form->add($section);
3088

    
3089
	if(ALLOWWEP) {
3090
		// WEP Section
3091
		$section = new Form_Section('WEP');
3092

    
3093
		$section->addInput(new Form_Checkbox(
3094
			'wep_enable',
3095
			'Enable',
3096
			'Enable WEP',
3097
			$pconfig['wep_enable'],
3098
			'yes'
3099
		));
3100

    
3101
		for($idx=1; $idx <= 4; $idx++) {
3102
			$group = new Form_Group('Key' . $idx);
3103

    
3104
			$group->add(new Form_Input(
3105
				'key' . $idx,
3106
				null,
3107
				'text',
3108
				$pconfig['key' . $idx]
3109
			));
3110

    
3111
			$group->add(new Form_Checkbox(
3112
				'txkey',
3113
				null,
3114
				null,
3115
				$pconfig['txkey'],
3116
				$idx
3117
			))->displayAsRadio()->setHelp($idx == 4 ? 'Tx key':'');
3118

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

    
3122
		$section->addInput(new Form_StaticText(
3123
			null,
3124
			'<span class="help-block">' .
3125
			gettext('40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by "0x"') . '<br />' .
3126
			gettext('104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by "0x"') .
3127
			'</span>'
3128
		));
3129

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

    
3133
	// WPA Section
3134
	$section = new Form_Section('WPA');
3135

    
3136
	$section->addInput(new Form_Checkbox(
3137
		'wpa_enable',
3138
		'Enable',
3139
		'Enable WPA',
3140
		$pconfig['wpa_enable'],
3141
		'yes'
3142
	));
3143

    
3144
	$section->addInput(new Form_Input(
3145
		'passphrase',
3146
		'WPA Pre-Shared Key',
3147
		'text',
3148
		$pconfig['passphrase']
3149
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3150

    
3151
	$section->addInput(new Form_Select(
3152
		'wpa_mode',
3153
		'WPA mode',
3154
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3155
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
3156
	));
3157

    
3158
	$section->addInput(new Form_Select(
3159
		'wpa_key_mgmt',
3160
		'WPA Key Management Mode',
3161
		$pconfig['wpa_key_mgmt'],
3162
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
3163
	));
3164

    
3165
	if(ALLOWWEP) {
3166
		$section->addInput(new Form_Select(
3167
			'auth_algs',
3168
			'Authentication',
3169
			$pconfig['auth_algs'],
3170
			['1' => 'Open System Authentication', '2' => 'Shared Key Authentication', '3' => 'Both']
3171
		))->setHelp('Shared Key Authentication requires WEP');
3172
	} else {
3173
		$section->addInput(new Form_Input(
3174
			'auth_algs',
3175
			null,
3176
			'hidden',
3177
			'1'
3178
		));;
3179
	}
3180

    
3181
	$section->addInput(new Form_Select(
3182
		'wpa_pairwise',
3183
		'WPA Pairwise',
3184
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3185
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3186
	));
3187

    
3188
	$section->addInput(new Form_Input(
3189
		'wpa_group_rekey',
3190
		'WPA Pre-Shared Key',
3191
		'number',
3192
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3193
		['min' => '1', 'max' => 9999]
3194
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3195

    
3196
	$section->addInput(new Form_Input(
3197
		'wpa_gmk_rekey',
3198
		'Master Key Regeneration',
3199
		'number',
3200
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3201
		['min' => '1', 'max' => 9999]
3202
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3203

    
3204
	$section->addInput(new Form_Checkbox(
3205
		'wpa_strict_rekey',
3206
		'Strict Key Regeneration',
3207
		'Force the AP to rekey whenever a client disassociates',
3208
		$pconfig['wpa_strict_rekey'],
3209
		'yes'
3210
	));
3211

    
3212
	$form->add($section);
3213

    
3214
	$section = new Form_Section('802.1x RADIUS options');
3215

    
3216
	$section->addInput(new Form_Checkbox(
3217
		'ieee8021x',
3218
		'IEEE802.1X',
3219
		'Enable 802.1X authentication',
3220
		$pconfig['ieee8021x'],
3221
		'yes'
3222
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3223

    
3224
	$group = new Form_Group('Primary 802.1X server');
3225

    
3226
	$group->add(new Form_IpAddress(
3227
		'auth_server_addr',
3228
		'IP Address',
3229
		$pconfig['auth_server_addr']
3230
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3231

    
3232
	$group->add(new Form_Input(
3233
		'auth_server_port',
3234
		'Port',
3235
		'number',
3236
		$pconfig['auth_server_port']
3237
	))->setHelp('Server port. Leave blank for the default port 1812');
3238

    
3239
	$group->add(new Form_Input(
3240
		'auth_server_shared_secret',
3241
		'Shared secret',
3242
		'number',
3243
		$pconfig['auth_server_shared_secret']
3244
	))->setHelp('Shared secret');
3245

    
3246
	$section->add($group);
3247

    
3248
	$group = new Form_Group('Secondary 802.1X server');
3249

    
3250
	$group->add(new Form_IpAddress(
3251
		'auth_server_addr2',
3252
		'IP Address',
3253
		$pconfig['auth_server_addr2']
3254
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3255

    
3256
	$group->add(new Form_Input(
3257
		'auth_server_port2',
3258
		'Port',
3259
		'number',
3260
		$pconfig['auth_server_port2']
3261
	))->setHelp('Server port. Leave blank for the default port 1812');
3262

    
3263
	$group->add(new Form_Input(
3264
		'auth_server_shared_secret2',
3265
		'Shared secret',
3266
		'number',
3267
		$pconfig['auth_server_shared_secret2']
3268
	))->setHelp('Shared secret');
3269

    
3270
	$section->add($group);
3271

    
3272
	$section->addInput(new Form_Checkbox(
3273
		'rsn_preauth',
3274
		'Authentication Roaming Preauth',
3275
		null,
3276
		$pconfig['rsn_preauth'],
3277
		'yes'
3278
	));
3279

    
3280
	$form->add($section);
3281
}
3282

    
3283
$section = new Form_Section('Private networks');
3284

    
3285
$section->addInput(new Form_Checkbox(
3286
	'blockpriv',
3287
	'Block private networks',
3288
	'',
3289
	$pconfig['blockpriv'],
3290
	'yes'
3291
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3292
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3293
			'lies in such a private address space, too.');
3294

    
3295
	$section->addInput(new Form_Checkbox(
3296
	'blockbogons',
3297
	'Block bogon networks',
3298
	'',
3299
	$pconfig['blockbogons'],
3300
	'yes'
3301
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3302
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3303
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3304

    
3305
$form->add($section);
3306

    
3307
$form->addGlobal(new Form_Input(
3308
	'if',
3309
	null,
3310
	'hidden',
3311
	$if
3312
));
3313

    
3314
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3315
	$form->addGlobal(new Form_Input(
3316
		'ppp_port',
3317
		null,
3318
		'hidden',
3319
		$pconfig['port']
3320
	));
3321
}
3322

    
3323
$form->addGlobal(new Form_Input(
3324
	'ptpid',
3325
	null,
3326
	'hidden',
3327
	$pconfig['ptpid']
3328
));
3329

    
3330
print($form);
3331
?>
3332

    
3333
<script type="text/javascript">
3334
//<![CDATA[
3335
events.push(function(){
3336

    
3337
	function updateType(t) {
3338
		switch (t) {
3339
			case "none": {
3340
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3341
				break;
3342
			}
3343
			case "staticv4": {
3344
				$('.dhcpadvanced, .none, .dhcp, .pppoe, .pptp, .ppp').hide();
3345
				break;
3346
			}
3347
			case "dhcp": {
3348
				$('.dhcpadvanced, .none, .staticv4, .pppoe, .pptp, .ppp').hide();
3349
				break;
3350
			}
3351
			case "ppp": {
3352
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3353
				country_list();
3354
				break;
3355
			}
3356
			case "pppoe": {
3357
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3358
				break;
3359
			}
3360
			case "l2tp":
3361
			case "pptp": {
3362
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3363
				$('.pptp').show();
3364
				break;
3365
			}
3366
		}
3367

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

    
3373
	function updateTypeSix(t) {
3374
		if (!isNaN(t[0]))
3375
			t = '_' + t;
3376

    
3377
		switch (t) {
3378
			case "none": {
3379
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3380
				break;
3381
			}
3382
			case "staticv6": {
3383
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3384
				break;
3385
			}
3386
			case "slaac": {
3387
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3388
				break;
3389
			}
3390
			case "dhcp6": {
3391
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3392
				break;
3393
			}
3394
			case "6rd_": {
3395
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3396
				break;
3397
			}
3398
			case "_6to4": {
3399
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3400
				break;
3401
			}
3402
			case "track6": {
3403
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3404
				update_track6_prefix();
3405
				break;
3406
			}
3407
		}
3408

    
3409
		if (t != "l2tp" && t != "pptp") {
3410
			$('.'+t).show();
3411
		}
3412
	}
3413

    
3414
	function show_reset_settings(reset_type) {
3415
		if (reset_type == 'preset') {
3416
			$('.pppoepreset').show();
3417
			$('.pppoecustom').hide();
3418
		} else if (reset_type == 'custom') {
3419
			$('.pppoecustom').show();
3420
			$('.pppoepreset').hide();
3421
		} else {
3422
			$('.pppoecustom').hide();
3423
			$('.pppoepreset').hide();
3424
		}
3425
	}
3426

    
3427
	function update_track6_prefix() {
3428
		var iface = $("#track6-interface").val();
3429
		if (iface == null) {
3430
			return;
3431
		}
3432

    
3433
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3434
		if (track6_prefix_ids == null) {
3435
			return;
3436
		}
3437

    
3438
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3439
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3440
	}
3441

    
3442
	// Create the new gateway from the data entered in the modal pop-up
3443
	function hide_add_gatewaysave() {
3444
		var iface = $('#if').val();
3445
		name = $('#name').val();
3446
		var descr = $('#gatewaydescr').val();
3447
		gatewayip = $('#gatewayip').val();
3448

    
3449
		var defaultgw = '';
3450
		if ($('#defaultgw').is(':checked')) {
3451
			defaultgw = '&defaultgw=on';
3452
		}
3453

    
3454
		var url = "system_gateways_edit.php";
3455
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3456
		$.ajax(
3457
			url,
3458
			{
3459
				type: 'post',
3460
				data: pars,
3461
				error: report_failure,
3462
				complete: save_callback
3463
			});
3464
		}
3465

    
3466
	function save_callback(response) {
3467
		if (response) {
3468
			var gwtext = escape(name) + " - " + gatewayip;
3469
			addOption($('#gateway'), gwtext, name);
3470
		} else {
3471
			report_failure();
3472
		}
3473

    
3474
		$("#newgateway").modal('hide');
3475
	}
3476

    
3477
	function report_failure(request, textStatus, errorThrown) {
3478
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3479
			alert(request.responseText);
3480
		} else {
3481
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3482
		}
3483

    
3484
		$("#newgateway").modal('hide');
3485
	}
3486

    
3487
	function addOption(selectbox, text, value)
3488
	{
3489
		var optn = document.createElement("OPTION");
3490
		optn.text = text;
3491
		optn.value = value;
3492
		selectbox.append(optn);
3493
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3494
	}
3495

    
3496
	function hide_add_gatewaysave_v6() {
3497

    
3498
		var iface = $('#if').val();
3499
		name = $('#name6').val();
3500
		var descr = $('#gatewaydescr6').val();
3501
		gatewayip = $('#gatewayip6').val();
3502
		var defaultgw = '';
3503
		if ($('#defaultgw6').is(':checked')) {
3504
			defaultgw = '&defaultgw=on';
3505
		}
3506
		var url_v6 = "system_gateways_edit.php";
3507
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3508
		$.ajax(
3509
			url_v6,
3510
			{
3511
				type: 'post',
3512
				data: pars_v6,
3513
				error: report_failure_v6,
3514
				success: save_callback_v6
3515
			});
3516
	}
3517

    
3518

    
3519
	function addOption_v6(selectbox, text, value)
3520
	{
3521
		var optn = document.createElement("OPTION");
3522
		optn.text = text;
3523
		optn.value = value;
3524
		selectbox.append(optn);
3525
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3526
	}
3527

    
3528
	function report_failure_v6(request, textStatus, errorThrown) {
3529
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3530
			alert(request.responseText);
3531
		} else {
3532
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3533
		}
3534

    
3535
		$("#newgateway6").modal('hide');
3536
	}
3537

    
3538
	function save_callback_v6(response_v6) {
3539
		if (response_v6) {
3540

    
3541
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3542
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3543
		} else {
3544
			report_failure_v6();
3545
		}
3546

    
3547
		$("#newgateway6").modal('hide');
3548
	}
3549

    
3550
	function country_list() {
3551

    
3552
		$('#country').children().remove();
3553
		$('#provider_list').children().remove();
3554
		$('#providerplan').children().remove();
3555
		$.ajax("getserviceproviders.php",{
3556
			success: function(response) {
3557

    
3558
				var responseTextArr = response.split("\n");
3559
				responseTextArr.sort();
3560

    
3561
				responseTextArr.forEach( function(value) {
3562
					country = value.split(":");
3563
					$('#country').append($('<option>', {
3564
						value: country[1],
3565
						text : country[0]
3566
					}));
3567
				});
3568
			}
3569
		});
3570
	}
3571

    
3572
	function providers_list() {
3573
		$('#provider_list').children().remove();
3574
		$('#providerplan').children().remove();
3575
		$.ajax("getserviceproviders.php",{
3576
			type: 'post',
3577
			data: {country : $('#country').val()},
3578
			success: function(response) {
3579
				var responseTextArr = response.split("\n");
3580
				responseTextArr.sort();
3581
				responseTextArr.forEach( function(value) {
3582
					$('#provider_list').append($('<option>', {
3583
							value: value,
3584
							text : value
3585
					}));
3586
				});
3587
			}
3588
		});
3589
	}
3590

    
3591
	function providerplan_list() {
3592
		$('#providerplan').children().remove();
3593
		$.ajax("getserviceproviders.php",{
3594
			type: 'post',
3595
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3596
			success: function(response) {
3597
				var responseTextArr = response.split("\n");
3598
				responseTextArr.sort();
3599

    
3600
				$('#providerplan').append($('<option>', {
3601
					value: '',
3602
					text : ''
3603
				}));
3604

    
3605
				responseTextArr.forEach( function(value) {
3606
					if (value != "") {
3607
						providerplan = value.split(":");
3608

    
3609
						$('#providerplan').append($('<option>', {
3610
							value: providerplan[1],
3611
							text : providerplan[0] + " - " + providerplan[1]
3612
						}));
3613
					}
3614
				});
3615
			}
3616
		});
3617
	}
3618

    
3619
	function prefill_provider() {
3620
		$.ajax("getserviceproviders.php",{
3621
			type: 'post',
3622
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3623
			success: function(data, textStatus, response) {
3624
				var xmldoc = response.responseXML;
3625
				var provider = xmldoc.getElementsByTagName('connection')[0];
3626
				$('#ppp_username').val('');
3627
				$('#ppp_password').val('');
3628
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3629
					$('#phone').val('#777');
3630
					$('#apn').val('');
3631
				} else {
3632
					$('#phone').val('*99#');
3633
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3634
				}
3635
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3636
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3637
				$('#ppp_username').val(ppp_username);
3638
				$('#ppp_password').val(ppp_password);
3639
			}
3640
		});
3641
	}
3642

    
3643
	function show_dhcp6adv() {
3644
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3645
		var adv = $('#dhcp6adv').prop('checked');
3646

    
3647
		hideCheckbox('dhcp6usev4iface', ovr);
3648
		hideCheckbox('dhcp6prefixonly', ovr);
3649
		hideInput('dhcp6-ia-pd-len', ovr);
3650
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3651
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3652

    
3653
		hideClass('dhcp6advanced', !adv || ovr);
3654
	}
3655

    
3656
	function setDHCPoptions() {
3657
		var adv = $('#dhcpadv').prop('checked');
3658
		var ovr = $('#dhcpovr').prop('checked');
3659

    
3660
		if(ovr) {
3661
			hideInput('dhcphostname', true);
3662
			hideIpAddress('alias-address', true);
3663
			hideInput('dhcprejectfrom', true);
3664
			hideInput('adv_dhcp_config_file_override_path', false);
3665
			hideClass('dhcpadvanced', true);
3666
		} else {
3667
			hideInput('dhcphostname', false);
3668
			hideIpAddress('alias-address', false);
3669
			hideInput('dhcprejectfrom', false);
3670
			hideInput('adv_dhcp_config_file_override_path', true);
3671
			hideClass('dhcpadvanced', !adv);
3672
		}
3673
	}
3674

    
3675
	// ---------- On initial page load ------------------------------------------------------------
3676

    
3677
	updateType($('#type').val());
3678
	updateTypeSix($('#type6').val());
3679
	show_reset_settings($('#pppoe-reset-type').val());
3680
	$("#add").prop('type' ,'button');
3681
	$("#cnx").prop('type' ,'button');
3682
	$("#addgw").prop('type' ,'button');
3683
	$("#add6").prop('type' ,'button');
3684
	$("#cnx6").prop('type' ,'button');
3685
	$("#addgw6").prop('type' ,'button');
3686
	hideClass('dhcp6advanced', true);
3687
	hideClass('dhcpadvanced', true);
3688
	show_dhcp6adv();
3689
	setDHCPoptions()
3690

    
3691
	// ---------- Click checkbox handlers ---------------------------------------------------------
3692

    
3693
   $('#type').on('change', function() {
3694
		updateType( this.value );
3695
	});
3696

    
3697
	$('#type6').on('change', function() {
3698
		updateTypeSix( this.value );
3699
	});
3700

    
3701
	$('#pppoe-reset-type').on('change', function() {
3702
		show_reset_settings( this.value );
3703
	});
3704

    
3705
	$("#add").click(function() {
3706
		hide_add_gatewaysave();
3707
	});
3708

    
3709
	$("#cnx").click(function() {
3710
		$("#newgateway").modal('hide');
3711
	});
3712

    
3713
	$("#add6").click(function() {
3714
		hide_add_gatewaysave_v6();
3715
	});
3716

    
3717
	$("#cnx6").click(function() {
3718
		$("#newgateway6").modal('hide');
3719
	});
3720

    
3721
	$('#country').on('change', function() {
3722
		providers_list();
3723
	});
3724

    
3725
	$('#provider_list').on('change', function() {
3726
		providerplan_list();
3727
	});
3728

    
3729
	$('#providerplan').on('change', function() {
3730
		prefill_provider();
3731
	});
3732

    
3733
	$('#dhcpadv, #dhcpovr').click(function () {
3734
		setDHCPoptions();
3735
	});
3736

    
3737
	$('#dhcp6adv').click(function () {
3738
		show_dhcp6adv();
3739
	});
3740

    
3741
	$('#adv_dhcp6_config_file_override').click(function () {
3742
		show_dhcp6adv();
3743
	});
3744

    
3745
	// DHCP preset actions
3746
	// Set presets from value of radio buttons
3747
	function setPresets(val) {
3748
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3749
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3750
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3751
		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']);?>");
3752
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3753
	}
3754

    
3755
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3756
		$('#adv_dhcp_pt_timeout').val(timeout);
3757
		$('#adv_dhcp_pt_retry').val(retry);
3758
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3759
		$('#adv_dhcp_pt_reboot').val(reboot);
3760
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3761
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3762
	}
3763

    
3764
	// Set preset buttons on page load
3765
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3766
	if(sv == "")
3767
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3768

    
3769
	// Set preset from value
3770
	setPresets(sv);
3771

    
3772
	// On click . .
3773
	$('[id=adv_dhcp_pt_values]').click(function () {
3774
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3775
	});
3776
});
3777
//]]>
3778
</script>
3779

    
3780
<?php include("foot.inc");
(82-82/234)