Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
364
// print_r($pconfig);
365

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

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

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

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

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

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

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

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

    
499
		clear_subsystem_dirty('interfaces');
500

    
501
		filter_configure();
502

    
503
		enable_rrd_graphing();
504

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

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

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

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

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

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

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

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

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

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

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

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

    
846
		unset($min_mtu, $max_mtu);
847

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1461
		conf_mount_ro();
1462
		write_config();
1463

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

    
1473
		mark_subsystem_dirty('interfaces');
1474

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

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

    
1482
} // end if ($_POST)
1483

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1716
$closehead = false;
1717

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

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

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

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

    
1734
	return($list);
1735
}
1736

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

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

    
1747
	return($list);
1748
}
1749

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

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

    
1760
	return($list);
1761
}
1762

    
1763
include("head.inc");
1764

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

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

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

    
1775

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2025
// ==== DHCP client configuration =============================
2026

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2206
// DHCP6 client config
2207

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

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

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

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

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

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

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

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

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

    
2265
// DHCP6 client config - Advanced
2266

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2539
	return($list);
2540
}
2541

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

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

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

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

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

    
2569
/// PPP section
2570

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

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

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

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

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

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

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

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

    
2623

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

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

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

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

    
2639
	return($list);
2640
}
2641

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2843
	$section->addInput(new Form_StaticText(
2844
		'Advanced and MLPPP',
2845
		$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>'
2846
	));
2847
} else {
2848
	$section->addInput(new Form_StaticText(
2849
		'Advanced and MLPPP',
2850
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2851
	));
2852
}
2853

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3329
print($form);
3330
?>
3331

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3495
	function hide_add_gatewaysave_v6() {
3496

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

    
3517

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

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

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

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

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

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

    
3549
	function country_list() {
3550

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3674
	// ---------- On initial page load ------------------------------------------------------------
3675

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

    
3690
	// ---------- Click checkbox handlers ---------------------------------------------------------
3691

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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