Project

General

Profile

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

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

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

    
77
define("ANTENNAS", false);
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
362
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
363
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
364
$pconfig['spoofmac'] = $wancfg['spoofmac'];
365
$pconfig['mtu'] = $wancfg['mtu'];
366
$pconfig['mss'] = $wancfg['mss'];
367

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

    
444
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
445

    
446
}
447

    
448
if ($_POST['apply']) {
449
	unset($input_errors);
450
	if (!is_subsystem_dirty('interfaces')) {
451
		$input_errors[] = gettext("You have already applied your settings!");
452
	} else {
453
		unlink_if_exists("{$g['tmp_path']}/config.cache");
454
		clear_subsystem_dirty('interfaces');
455

    
456
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
457
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
458
			foreach ($toapplylist as $ifapply => $ifcfgo) {
459
				if (isset($config['interfaces'][$ifapply]['enable'])) {
460
					interface_bring_down($ifapply, false, $ifcfgo);
461
					interface_configure($ifapply, true);
462
				} else {
463
					interface_bring_down($ifapply, true, $ifcfgo);
464
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
465
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
466
						services_dhcpd_configure();
467
					}
468
				}
469
			}
470
		}
471
		/* restart snmp so that it binds to correct address */
472
		services_snmpd_configure();
473

    
474
		/* sync filter configuration */
475
		setup_gateways_monitor();
476

    
477
		clear_subsystem_dirty('interfaces');
478

    
479
		filter_configure();
480

    
481
		enable_rrd_graphing();
482

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

    
510
	unset($input_errors);
511
	$pconfig = $_POST;
512

    
513
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
514
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
515
	} else {
516
		$pconfig['track6-prefix-id'] = 0;
517
	}
518
	conf_mount_rw();
519

    
520
	/* filter out spaces from descriptions */
521
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
522

    
523
	/* okay first of all, cause we are just hiding the PPPoE HTML
524
	 * fields related to PPPoE resets, we are going to unset $_POST
525
	 * vars, if the reset feature should not be used. Otherwise the
526
	 * data validation procedure below, may trigger a false error
527
	 * message.
528
	 */
529
	if (empty($_POST['pppoe-reset-type'])) {
530
		unset($_POST['pppoe_pr_type']);
531
		unset($_POST['pppoe_resethour']);
532
		unset($_POST['pppoe_resetminute']);
533
		unset($_POST['pppoe_resetdate']);
534
		unset($_POST['pppoe_pr_preset_val']);
535
	}
536
	/* description unique? */
537
	foreach ($ifdescrs as $ifent => $ifdescr) {
538
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
539
			$input_errors[] = gettext("An interface with the specified description already exists.");
540
			break;
541
		}
542
	}
543
	if (is_numeric($_POST['descr'])) {
544
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
545
	}
546
	/* input validation */
547
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
548
		$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.");
549
	}
550
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
551
		$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.");
552
	}
553

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

    
661
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
662
				$input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID.");
663
			} else {
664
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
665
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
666
					$input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range.") .
667
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
668
				} else {
669
					foreach ($ifdescrs as $ifent => $ifdescr) {
670
						if ($if == $ifent) {
671
							continue;
672
						}
673
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
674
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
675
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
676
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
677
						}
678
					}
679
				}
680
			}
681
			break;
682
	}
683

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

    
700
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
701
			if ($_POST['subnet'] < 31) {
702
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
703
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
704
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
705
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
706
				}
707
			}
708

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

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

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

    
824
		unset($min_mtu, $max_mtu);
825

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

    
842
				$realhwif_array = get_parent_interface($ifdata['if']);
843
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
844
				$parent_realhwif = $realhwif_array[0];
845

    
846
				if ($parent_realhwif != $wancfg['if']) {
847
					continue;
848
				}
849

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

    
937
		if ($_POST['passphrase']) {
938
			$passlen = strlen($_POST['passphrase']);
939
			if ($passlen < 8 || $passlen > 63) {
940
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
941
			}
942
		}
943

    
944
		if ($_POST['wpa_enable'] == "yes") {
945
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
946
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
947
			}
948
		}
949
	}
950
	if (!$input_errors) {
951
		// These 3 fields can be a list of multiple data items when used for MLPPP.
952
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
953
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
954
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
955
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
956

    
957
		if ($wancfg['ipaddr'] != $_POST['type']) {
958
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
959
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
960
				unset($a_ppps[$pppid]);
961
			} else if ($wancfg['ipaddr'] == "dhcp") {
962
				kill_dhclient_process($wancfg['if']);
963
			}
964
			if ($wancfg['ipaddrv6'] == "dhcp6") {
965
				$pid = find_dhcp6c_process($wancfg['if']);
966
				if ($pid) {
967
					posix_kill($pid, SIGTERM);
968
				}
969
			}
970
		}
971
		$ppp = array();
972
		if ($wancfg['ipaddr'] != "ppp") {
973
			unset($wancfg['ipaddr']);
974
		}
975
		if ($wancfg['ipaddrv6'] != "ppp") {
976
			unset($wancfg['ipaddrv6']);
977
		}
978
		unset($wancfg['subnet']);
979
		unset($wancfg['gateway']);
980
		unset($wancfg['subnetv6']);
981
		unset($wancfg['gatewayv6']);
982
		unset($wancfg['dhcphostname']);
983
		unset($wancfg['dhcprejectfrom']);
984
		unset($wancfg['dhcp6-duid']);
985
		unset($wancfg['dhcp6-ia-pd-len']);
986
		unset($wancfg['dhcp6-ia-pd-send-hint']);
987
		unset($wancfg['dhcp6prefixonly']);
988
		unset($wancfg['dhcp6usev4iface']);
989
		unset($wancfg['track6-interface']);
990
		unset($wancfg['track6-prefix-id']);
991
		unset($wancfg['prefix-6rd']);
992
		unset($wancfg['prefix-6rd-v4plen']);
993
		unset($wancfg['gateway-6rd']);
994

    
995
		unset($wancfg['adv_dhcp_pt_timeout']);
996
		unset($wancfg['adv_dhcp_pt_retry']);
997
		unset($wancfg['adv_dhcp_pt_select_timeout']);
998
		unset($wancfg['adv_dhcp_pt_reboot']);
999
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1000
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1001

    
1002
		unset($wancfg['adv_dhcp_pt_values']);
1003

    
1004
		unset($wancfg['adv_dhcp_send_options']);
1005
		unset($wancfg['adv_dhcp_request_options']);
1006
		unset($wancfg['adv_dhcp_required_options']);
1007
		unset($wancfg['adv_dhcp_option_modifiers']);
1008

    
1009
		unset($wancfg['adv_dhcp_config_advanced']);
1010
		unset($wancfg['adv_dhcp_config_file_override']);
1011
		unset($wancfg['adv_dhcp_config_file_override_path']);
1012

    
1013
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1014
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1015
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1016
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1017

    
1018
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1019
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1020
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1021
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1022
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1023

    
1024
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1025
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1026
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1027
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1028
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1029

    
1030
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1031
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1032

    
1033
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1034
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1035
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1036
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1037

    
1038
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1039
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1040
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1041
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1042
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1043

    
1044
		unset($wancfg['adv_dhcp6_config_advanced']);
1045
		unset($wancfg['adv_dhcp6_config_file_override']);
1046
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1047

    
1048
		unset($wancfg['pppoe_password']);
1049
		unset($wancfg['pptp_username']);
1050
		unset($wancfg['pptp_password']);
1051
		unset($wancfg['provider']);
1052
		unset($wancfg['ondemand']);
1053
		unset($wancfg['timeout']);
1054
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1055
			unset($wancfg['pppoe']['pppoe-reset-type']);
1056
		}
1057
		unset($wancfg['local']);
1058

    
1059
		unset($wancfg['remote']);
1060
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1061
			if ($wancfg['ipaddr'] != 'ppp') {
1062
				unset($a_ppps[$pppid]['apn']);
1063
				unset($a_ppps[$pppid]['phone']);
1064
				unset($a_ppps[$pppid]['provider']);
1065
				unset($a_ppps[$pppid]['ondemand']);
1066
			}
1067
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1068
				unset($a_ppps[$pppid]['localip']);
1069
				unset($a_ppps[$pppid]['subnet']);
1070
				unset($a_ppps[$pppid]['gateway']);
1071
			}
1072
			if ($wancfg['ipaddr'] != 'pppoe') {
1073
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1074
			}
1075
			if ($wancfg['type'] != $_POST['type']) {
1076
				unset($a_ppps[$pppid]['idletimeout']);
1077
			}
1078
		}
1079

    
1080
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1081
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1082

    
1083
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1084
		switch ($_POST['type']) {
1085
			case "staticv4":
1086
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1087
				$wancfg['subnet'] = $_POST['subnet'];
1088
				if ($_POST['gateway'] != "none") {
1089
					$wancfg['gateway'] = $_POST['gateway'];
1090
				}
1091
				break;
1092
			case "dhcp":
1093
				$wancfg['ipaddr'] = "dhcp";
1094
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1095
				$wancfg['alias-address'] = $_POST['alias-address'];
1096
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1097
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1098

    
1099
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1100
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1101
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1102
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1103
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1104
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1105

    
1106
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1107

    
1108
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1109
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1110
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1111
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1112

    
1113
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1114
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1115
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1116

    
1117
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1118
				if ($gateway_item) {
1119
					$a_gateways[] = $gateway_item;
1120
				}
1121
				break;
1122
			case "ppp":
1123
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1124
				$a_ppps[$pppid]['type'] = $_POST['type'];
1125
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1126
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1127
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1128
				$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1129
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1130
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1131
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1132
				$wancfg['ipaddr'] = $_POST['type'];
1133
				break;
1134

    
1135
			case "pppoe":
1136
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1137
				$a_ppps[$pppid]['type'] = $_POST['type'];
1138
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1139
				if (isset($_POST['ppp_port'])) {
1140
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1141
				} else {
1142
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1143
				}
1144
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1145
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1146
				if (!empty($_POST['provider'])) {
1147
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1148
				} else {
1149
					$a_ppps[$pppid]['provider'] = true;
1150
				}
1151
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1152
				if (!empty($_POST['pppoe_idletimeout'])) {
1153
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1154
				} else {
1155
					unset($a_ppps[$pppid]['idletimeout']);
1156
				}
1157

    
1158
				if (!empty($_POST['pppoe-reset-type'])) {
1159
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1160
				} else {
1161
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1162
				}
1163
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1164
				$wancfg['ipaddr'] = $_POST['type'];
1165
				if ($gateway_item) {
1166
					$a_gateways[] = $gateway_item;
1167
				}
1168

    
1169
				break;
1170
			case "pptp":
1171
			case "l2tp":
1172
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1173
				$a_ppps[$pppid]['type'] = $_POST['type'];
1174
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1175
				if (isset($_POST['ppp_port'])) {
1176
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1177
				} else {
1178
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1179
				}
1180
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1181
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1182
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1183
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1184
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1185
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1186
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1187
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1188
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1189
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1190
				if (!empty($_POST['pptp_idletimeout'])) {
1191
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1192
				} else {
1193
					unset($a_ppps[$pppid]['idletimeout']);
1194
				}
1195
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1196
				$wancfg['ipaddr'] = $_POST['type'];
1197
				if ($gateway_item) {
1198
					$a_gateways[] = $gateway_item;
1199
				}
1200
				break;
1201
			case "none":
1202
				break;
1203
		}
1204
		switch ($_POST['type6']) {
1205
			case "staticv6":
1206
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1207
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1208
				if ($_POST['gatewayv6'] != "none") {
1209
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1210
				}
1211
				break;
1212
			case "slaac":
1213
				$wancfg['ipaddrv6'] = "slaac";
1214
				break;
1215
			case "dhcp6":
1216
				$wancfg['ipaddrv6'] = "dhcp6";
1217
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1218
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1219
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1220
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1221
				}
1222
				if ($_POST['dhcp6prefixonly'] == "yes") {
1223
					$wancfg['dhcp6prefixonly'] = true;
1224
				}
1225
				if ($_POST['dhcp6usev4iface'] == "yes") {
1226
					$wancfg['dhcp6usev4iface'] = true;
1227
				}
1228

    
1229
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1230
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1231
				}
1232
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1233
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1234
				}
1235
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1236
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1237
				}
1238
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1239
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1240
				}
1241

    
1242
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1243
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1244
				}
1245
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1246
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1247
				}
1248
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1249
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1250
				}
1251
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1252
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1253
				}
1254
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1255
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1256
				}
1257

    
1258
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1259
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1260
				}
1261
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1262
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1263
				}
1264
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1265
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1266
				}
1267
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1268
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1269
				}
1270
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1271
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1272
				}
1273

    
1274
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1275
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1276
				}
1277
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1278
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1279
				}
1280

    
1281
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1282
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1283
				}
1284
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1285
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1286
				}
1287
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1288
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1289
				}
1290
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1291
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1292
				}
1293

    
1294
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1295
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1296
				}
1297
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1298
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1299
				}
1300
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1301
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1304
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1307
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1308
				}
1309

    
1310
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1311
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1312
				}
1313
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1314
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1317
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1318
				}
1319

    
1320
				if ($gateway_item) {
1321
					$a_gateways[] = $gateway_item;
1322
				}
1323
				break;
1324
			case "6rd":
1325
				$wancfg['ipaddrv6'] = "6rd";
1326
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1327
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1328
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1329
				if ($gateway_item) {
1330
					$a_gateways[] = $gateway_item;
1331
				}
1332
				break;
1333
			case "6to4":
1334
				$wancfg['ipaddrv6'] = "6to4";
1335
				break;
1336
			case "track6":
1337
				$wancfg['ipaddrv6'] = "track6";
1338
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1339
				if ($_POST['track6-prefix-id--hex'] === "") {
1340
					$wancfg['track6-prefix-id'] = 0;
1341
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1342
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1343
				} else {
1344
					$wancfg['track6-prefix-id'] = 0;
1345
				}
1346
				break;
1347
			case "none":
1348
				break;
1349
		}
1350
		handle_pppoe_reset($_POST);
1351

    
1352
		if ($_POST['blockpriv'] == "yes") {
1353
			$wancfg['blockpriv'] = true;
1354
		} else {
1355
			unset($wancfg['blockpriv']);
1356
		}
1357
		if ($_POST['blockbogons'] == "yes") {
1358
			$wancfg['blockbogons'] = true;
1359
		} else {
1360
			unset($wancfg['blockbogons']);
1361
		}
1362
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1363
		if (empty($_POST['mtu'])) {
1364
			unset($wancfg['mtu']);
1365
		} else {
1366
			$wancfg['mtu'] = $_POST['mtu'];
1367
		}
1368
		if (empty($_POST['mss'])) {
1369
			unset($wancfg['mss']);
1370
		} else {
1371
			$wancfg['mss'] = $_POST['mss'];
1372
		}
1373
		if (empty($_POST['mediaopt'])) {
1374
			unset($wancfg['media']);
1375
			unset($wancfg['mediaopt']);
1376
		} else {
1377
			$mediaopts = explode(' ', $_POST['mediaopt']);
1378
			if ($mediaopts[0] != '') {
1379
				$wancfg['media'] = $mediaopts[0];
1380
			}
1381
			if ($mediaopts[1] != '') {
1382
				$wancfg['mediaopt'] = $mediaopts[1];
1383
			} else {
1384
				unset($wancfg['mediaopt']);
1385
			}
1386
		}
1387
		if (isset($wancfg['wireless'])) {
1388
			handle_wireless_post();
1389
		}
1390

    
1391
		conf_mount_ro();
1392
		write_config();
1393

    
1394
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1395
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1396
		} else {
1397
			$toapplylist = array();
1398
		}
1399
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1400
		$toapplylist[$if]['ppps'] = $old_ppps;
1401
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1402

    
1403
		mark_subsystem_dirty('interfaces');
1404

    
1405
		/* regenerate cron settings/crontab file */
1406
		configure_cron();
1407

    
1408
		header("Location: interfaces.php?if={$if}");
1409
		exit;
1410
	}
1411

    
1412
} // end if ($_POST)
1413

    
1414
function handle_wireless_post() {
1415
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1416
	if (!is_array($wancfg['wireless'])) {
1417
		$wancfg['wireless'] = array();
1418
	}
1419
	$wancfg['wireless']['standard'] = $_POST['standard'];
1420
	$wancfg['wireless']['mode'] = $_POST['mode'];
1421
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1422
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1423
	$wancfg['wireless']['channel'] = $_POST['channel'];
1424
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1425
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1426
	$wancfg['wireless']['distance'] = $_POST['distance'];
1427
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1428
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1429
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1430
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1431
		foreach ($wl_countries_attr as $wl_country) {
1432
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1433
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1434
				break;
1435
			}
1436
		}
1437
	}
1438
	if (!is_array($wancfg['wireless']['wpa'])) {
1439
		$wancfg['wireless']['wpa'] = array();
1440
	}
1441
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1442
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1443
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1444
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1445
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1446
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1447
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1448
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1449
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1450
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1451
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1452
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1453
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1454
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1455

    
1456
	if ($_POST['persistcommonwireless'] == "yes") {
1457
		if (!is_array($config['wireless'])) {
1458
			$config['wireless'] = array();
1459
		}
1460
		if (!is_array($config['wireless']['interfaces'])) {
1461
			$config['wireless']['interfaces'] = array();
1462
		}
1463
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1464
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1465
		}
1466
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1467
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1468
	}
1469
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1470
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1471
	} else if (isset($wancfg['wireless']['diversity'])) {
1472
		unset($wancfg['wireless']['diversity']);
1473
	}
1474
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1475
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1476
	} else if (isset($wancfg['wireless']['txantenna'])) {
1477
		unset($wancfg['wireless']['txantenna']);
1478
	}
1479
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1480
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1481
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1482
		unset($wancfg['wireless']['rxantenna']);
1483
	}
1484
	if ($_POST['hidessid_enable'] == "yes") {
1485
		$wancfg['wireless']['hidessid']['enable'] = true;
1486
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1487
		unset($wancfg['wireless']['hidessid']['enable']);
1488
	}
1489
	if ($_POST['mac_acl_enable'] == "yes") {
1490
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1491
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1492
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1493
	}
1494
	if ($_POST['rsn_preauth'] == "yes") {
1495
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1496
	} else {
1497
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1498
	}
1499
	if ($_POST['ieee8021x'] == "yes") {
1500
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1501
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1502
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1503
	}
1504
	if ($_POST['wpa_strict_rekey'] == "yes") {
1505
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1506
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1507
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1508
	}
1509
	if ($_POST['debug_mode'] == "yes") {
1510
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1511
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1512
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1513
	}
1514
	if ($_POST['wpa_enable'] == "yes") {
1515
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1516
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1517
		unset($wancfg['wireless']['wpa']['enable']);
1518
	}
1519

    
1520
	if ($_POST['wme_enable'] == "yes") {
1521
		if (!is_array($wancfg['wireless']['wme'])) {
1522
			$wancfg['wireless']['wme'] = array();
1523
		}
1524
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1525
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1526
		unset($wancfg['wireless']['wme']['enable']);
1527
	}
1528
	if ($_POST['puremode'] == "11g") {
1529
		if (!is_array($wancfg['wireless']['pureg'])) {
1530
			$wancfg['wireless']['pureg'] = array();
1531
		}
1532
		$wancfg['wireless']['pureg']['enable'] = true;
1533
	} else if ($_POST['puremode'] == "11n") {
1534
		if (!is_array($wancfg['wireless']['puren'])) {
1535
			$wancfg['wireless']['puren'] = array();
1536
		}
1537
		$wancfg['wireless']['puren']['enable'] = true;
1538
	} else {
1539
		if (isset($wancfg['wireless']['pureg'])) {
1540
			unset($wancfg['wireless']['pureg']);
1541
		}
1542
		if (isset($wancfg['wireless']['puren'])) {
1543
			unset($wancfg['wireless']['puren']);
1544
		}
1545
	}
1546
	if ($_POST['apbridge_enable'] == "yes") {
1547
		if (!is_array($wancfg['wireless']['apbridge'])) {
1548
			$wancfg['wireless']['apbridge'] = array();
1549
		}
1550
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1551
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1552
		unset($wancfg['wireless']['apbridge']['enable']);
1553
	}
1554
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1555
		if (!is_array($wancfg['wireless']['turbo'])) {
1556
			$wancfg['wireless']['turbo'] = array();
1557
		}
1558
		$wancfg['wireless']['turbo']['enable'] = true;
1559
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1560
		unset($wancfg['wireless']['turbo']['enable']);
1561
	}
1562

    
1563
	interface_sync_wireless_clones($wancfg, true);
1564
}
1565

    
1566
function check_wireless_mode() {
1567
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1568

    
1569
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1570
		return;
1571
	}
1572

    
1573
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1574
		$clone_count = 1;
1575
	} else {
1576
		$clone_count = 0;
1577
	}
1578

    
1579
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1580
		foreach ($config['wireless']['clone'] as $clone) {
1581
			if ($clone['if'] == $wlanbaseif) {
1582
				$clone_count++;
1583
			}
1584
		}
1585
	}
1586

    
1587
	if ($clone_count > 1) {
1588
		$old_wireless_mode = $wancfg['wireless']['mode'];
1589
		$wancfg['wireless']['mode'] = $_POST['mode'];
1590
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1591
			$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']]);
1592
		} else {
1593
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1594
		}
1595
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1596
	}
1597
}
1598

    
1599
// Find all possible media options for the interface
1600
$mediaopts_list = array();
1601
$intrealname = $config['interfaces'][$if]['if'];
1602
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1603
foreach ($mediaopts as $mediaopt) {
1604
	preg_match("/media (.*)/", $mediaopt, $matches);
1605
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1606
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1607
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1608
	} else {
1609
		// there is only media like "media 1000baseT"
1610
		array_push($mediaopts_list, $matches[1]);
1611
	}
1612
}
1613

    
1614
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1615
$shortcut_section = "interfaces";
1616

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

    
1620
$closehead = false;
1621

    
1622
// Get the MAC address
1623
$ip = $_SERVER['REMOTE_ADDR'];
1624
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1625
$mymac = str_replace("\n", "", $mymac);
1626

    
1627
function build_mediaopts_list() {
1628
	global $mediaopts_list;
1629

    
1630
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1631
			 " " =>	 "------- Media Supported by this interface -------"
1632
			];
1633

    
1634
	foreach ($mediaopts_list as $mediaopt) {
1635
		$list[$mediaopt] = $mediaopt;
1636
	}
1637

    
1638
	return($list);
1639
}
1640

    
1641
function build_gateway_list() {
1642
	global $a_gateways, $if;
1643

    
1644
	$list = array("none" => "None");
1645
	foreach ($a_gateways as $gateway) {
1646
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1647
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1648
		}
1649
	}
1650

    
1651
	return($list);
1652
}
1653

    
1654
function build_gatewayv6_list() {
1655
	global $a_gateways, $if;
1656

    
1657
	$list = array("none" => "None");
1658
	foreach ($a_gateways as $gateway) {
1659
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1660
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1661
		}
1662
	}
1663

    
1664
	return($list);
1665
}
1666

    
1667
include("head.inc");
1668

    
1669
if ($input_errors) {
1670
	print_input_errors($input_errors);
1671
}
1672

    
1673
if (is_subsystem_dirty('interfaces')) {
1674
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1675
					  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."));
1676
}
1677

    
1678
if ($savemsg) {
1679
	print_info_box($savemsg, 'success');
1680
}
1681

    
1682

    
1683
$form = new Form(new Form_Button(
1684
	'Submit',
1685
	gettext("Save")
1686
));
1687

    
1688
$section = new Form_Section('General configuration');
1689

    
1690
$section->addInput(new Form_Checkbox(
1691
	'enable',
1692
	'Enable',
1693
	'Enable interface',
1694
	$pconfig['enable'],
1695
	'yes'
1696
));
1697

    
1698
$section->addInput(new Form_Input(
1699
	'descr',
1700
	'Description',
1701
	'text',
1702
	$pconfig['descr']
1703
))->setHelp('Enter a description (name) for the interface here.');
1704

    
1705
$section->addInput(new Form_Select(
1706
	'type',
1707
	'IPv4 Configuration Type',
1708
	$pconfig['type'],
1709
	$types4
1710
));
1711

    
1712
$section->addInput(new Form_Select(
1713
	'type6',
1714
	'IPv6 Configuration Type',
1715
	$pconfig['type6'],
1716
	$types6
1717
));
1718

    
1719
$macaddress = new Form_Input(
1720
	'spoofmac',
1721
	'MAC Address',
1722
	'text',
1723
	$pconfig['spoofmac'],
1724
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1725
);
1726

    
1727
$btnmymac = new Form_Button(
1728
	'btnmymac',
1729
	'Copy My MAC'
1730
	);
1731

    
1732
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1733

    
1734
$group = new Form_Group('MAC controls');
1735
$group->add($macaddress);
1736
// $group->add($btnmymac);
1737
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1738
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1739
$section->add($group);
1740

    
1741
$section->addInput(new Form_Input(
1742
	'mtu',
1743
	'MTU',
1744
	'number',
1745
	$pconfig['mtu']
1746
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1747
			'This is typically 1500 bytes but can vary in some circumstances.');
1748

    
1749
$section->addInput(new Form_Input(
1750
	'mss',
1751
	'MSS',
1752
	'number',
1753
	$pconfig['mss']
1754
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1755
			'header size) will be in effect.');
1756

    
1757
if (count($mediaopts_list) > 0) {
1758
	$section->addInput(new Form_Select(
1759
		'mediaopt',
1760
		'Speed and Duplex',
1761
		rtrim($mediaopt_from_config),
1762
		build_mediaopts_list()
1763
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1764
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1765
}
1766

    
1767
$form->add($section);
1768

    
1769
$section = new Form_Section('Static IPv4 configuration');
1770
$section->addClass('staticv4');
1771

    
1772
$section->addInput(new Form_IpAddress(
1773
	'ipaddr',
1774
	'IPv4 Address',
1775
	$pconfig['ipaddr']
1776
))->addMask('subnet', $pconfig['subnet'], 32);
1777

    
1778
$group = new Form_Group('IPv4 Upstream gateway');
1779

    
1780
$group->add(new Form_Select(
1781
	'gateway',
1782
	'IPv4 Upstream Gateway',
1783
	$pconfig['gateway'],
1784
	build_gateway_list()
1785
));
1786

    
1787
$group->add(new Form_Button(
1788
	'addgw',
1789
	'Add a new gateway'
1790
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1791

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

    
1796
$section->add($group);
1797

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

    
1800
$section = new Form_Section('Static IPv6 configuration');
1801
$section->addClass('staticv6');
1802

    
1803
$section->addInput(new Form_IpAddress(
1804
	'ipaddrv6',
1805
	'IPv6 address',
1806
	$pconfig['ipaddrv6']
1807
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1808

    
1809
$group = new Form_Group('IPv6 Upstream gateway');
1810

    
1811
$group->add(new Form_Select(
1812
	'gatewayv6',
1813
	'IPv6 Upstream Gateway',
1814
	$pconfig['gatewayv6'],
1815
	build_gatewayv6_list()
1816
));
1817

    
1818
$group->add(new Form_Button(
1819
	'addgw6',
1820
	'Add a new gateway'
1821
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1822

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

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

    
1829
// Add new gateway modal pop-up for IPv6
1830
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1831

    
1832
$modal->addInput(new Form_Checkbox(
1833
	'defaultgw6',
1834
	'Default',
1835
	'Default gateway',
1836
	($if == "wan" || $if == "WAN")
1837
));
1838

    
1839
$modal->addInput(new Form_Input(
1840
	'name6',
1841
	'Gateway name',
1842
	'text',
1843
	$wancfg['descr'] . "GWv6"
1844
));
1845

    
1846
$modal->addInput(new Form_IpAddress(
1847
	'gatewayip6',
1848
	'Gateway IPv6',
1849
	null
1850
));
1851

    
1852
$modal->addInput(new Form_Input(
1853
	'gatewaydescr6',
1854
	'Description',
1855
	'text'
1856
));
1857

    
1858
$btnaddgw6 = new Form_Button(
1859
	'add6',
1860
	'Add'
1861
);
1862

    
1863
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1864

    
1865
$btncnxgw6 = new Form_Button(
1866
	'cnx6',
1867
	'Cancel'
1868
);
1869

    
1870
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1871

    
1872
$modal->addInput(new Form_StaticText(
1873
	null,
1874
	$btnaddgw6 . $btncnxgw6
1875
));
1876

    
1877
$form->add($modal);
1878

    
1879
// ==== DHCP client configuration =============================
1880

    
1881
$section = new Form_Section('DHCP client configuration');
1882
$section->addClass('dhcp');
1883

    
1884
$group = new Form_Group('Options');
1885

    
1886
$group->add(new Form_Checkbox(
1887
	'dhcpadv',
1888
	null,
1889
	'Show DHCP advanced options',
1890
	false
1891
));
1892

    
1893
$group->add(new Form_Checkbox(
1894
	'dhcpovr',
1895
	null,
1896
	'Config file override',
1897
	false
1898
));
1899

    
1900
$section->add($group);
1901

    
1902
$section->addInput(new Form_Input(
1903
	'dhcphostname',
1904
	'Hostname',
1905
	'text',
1906
	$pconfig['dhcphostname']
1907
))->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).');
1908

    
1909
$section->addInput(new Form_IpAddress(
1910
	'alias-address',
1911
	'Alias IPv4 address',
1912
	$pconfig['alias-address']
1913
))->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.');
1914

    
1915
$section->addInput(new Form_Input(
1916
	'dhcprejectfrom',
1917
	'Reject leases from',
1918
	'text',
1919
	$pconfig['dhcprejectfrom']
1920
))->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. ' .
1921
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1922

    
1923
$group = new Form_Group('Protocol timing');
1924
$group->addClass('dhcpadvanced');
1925

    
1926
$group->add(new Form_Input(
1927
	'adv_dhcp_pt_timeout',
1928
	null,
1929
	'number',
1930
	$pconfig['adv_dhcp_pt_timeout']
1931
))->setHelp('Timeout');
1932

    
1933
$group->add(new Form_Input(
1934
	'adv_dhcp_pt_retry',
1935
	null,
1936
	'number',
1937
	$pconfig['adv_dhcp_pt_retry']
1938
))->setHelp('Retry');
1939

    
1940
$group->add(new Form_Input(
1941
	'adv_dhcp_pt_select_timeout',
1942
	null,
1943
	'number',
1944
	$pconfig['adv_dhcp_pt_select_timeout'],
1945
	['min' => 0]
1946
))->setHelp('Select timeout');
1947

    
1948
$group->add(new Form_Input(
1949
	'adv_dhcp_pt_reboot',
1950
	null,
1951
	'number',
1952
	$pconfig['adv_dhcp_pt_reboot']
1953
))->setHelp('Reboot');
1954

    
1955
$group->add(new Form_Input(
1956
	'adv_dhcp_pt_backoff_cutoff',
1957
	null,
1958
	'number',
1959
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1960
))->setHelp('Backoff cutoff');
1961

    
1962
$group->add(new Form_Input(
1963
	'adv_dhcp_pt_initial_interval',
1964
	null,
1965
	'number',
1966
	$pconfig['adv_dhcp_pt_initial_interval']
1967
))->setHelp('Initial interval');
1968

    
1969
$section->add($group);
1970

    
1971
$group = new Form_Group('Presets');
1972
$group->addClass('dhcpadvanced');
1973

    
1974
$group->add(new Form_Checkbox(
1975
	'adv_dhcp_pt_values',
1976
	null,
1977
	'FreeBSD default',
1978
	null,
1979
	'DHCP'
1980
))->displayAsRadio();
1981

    
1982
$group->add(new Form_Checkbox(
1983
	'adv_dhcp_pt_values',
1984
	null,
1985
	'Clear',
1986
	null,
1987
	'Clear'
1988
))->displayAsRadio();
1989

    
1990
$group->add(new Form_Checkbox(
1991
	'adv_dhcp_pt_values',
1992
	null,
1993
	'pfSense Default',
1994
	null,
1995
	'pfSense'
1996
))->displayAsRadio();
1997

    
1998
$group->add(new Form_Checkbox(
1999
	'adv_dhcp_pt_values',
2000
	null,
2001
	'Saved Cfg',
2002
	null,
2003
	'SavedCfg'
2004
))->displayAsRadio();
2005

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

    
2009
$section->add($group);
2010

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

    
2021
$form->add($section);
2022

    
2023
$section = new Form_Section('Lease Requirements and Requests');
2024
$section->addClass('dhcpadvanced');
2025

    
2026
$section->addInput(new Form_Input(
2027
	'adv_dhcp_send_options',
2028
	'Send options',
2029
	'text',
2030
	$pconfig['adv_dhcp_send_options']
2031
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2032
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2033
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2034
			'Some ISPs may require certain options be or not be sent.');
2035

    
2036
$section->addInput(new Form_Input(
2037
	'adv_dhcp_request_options',
2038
	'Request options',
2039
	'text',
2040
	$pconfig['adv_dhcp_request_options']
2041
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2042
			'Some ISPs may require certain options be or not be requested.');
2043

    
2044
$section->addInput(new Form_Input(
2045
	'adv_dhcp_required_options',
2046
	'Require options',
2047
	'text',
2048
	$pconfig['adv_dhcp_required_options']
2049
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2050

    
2051
$section->addInput(new Form_Input(
2052
	'adv_dhcp_option_modifiers',
2053
	'Option modifiers',
2054
	'text',
2055
	$pconfig['adv_dhcp_option_modifiers']
2056
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2057
			'modifiers: (default, supersede, prepend, append)');
2058

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

    
2061
// DHCP6 client config
2062

    
2063
$section = new Form_Section('DHCP6 client configuration');
2064
$section->addClass('dhcp6');
2065

    
2066
$section->addInput(new Form_Checkbox(
2067
	'dhcp6adv',
2068
	'Advanced',
2069
	'Show DHCPv6 advanced options',
2070
	$pconfig['adv_dhcp6_config_advanced']
2071
));
2072

    
2073
$section->addInput(new Form_Checkbox(
2074
	'adv_dhcp6_config_file_override',
2075
	'Config file override',
2076
	'Override the configuration from this file',
2077
	$pconfig['adv_dhcp6_config_file_override']
2078
));
2079

    
2080
$section->addInput(new Form_Checkbox(
2081
	'dhcp6usev4iface',
2082
	'Use IPv4 connectivity as parent interface',
2083
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2084
	$pconfig['dhcp6usev4iface']
2085
));
2086

    
2087
$section->addInput(new Form_Checkbox(
2088
	'dhcp6prefixonly',
2089
	'Request only an IPv6 prefix',
2090
	'Only request an IPv6 prefix, do not request an IPv6 address',
2091
	$pconfig['dhcp6prefixonly']
2092
));
2093

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

    
2101
$section->addInput(new Form_Checkbox(
2102
	'dhcp6-ia-pd-send-hint',
2103
	'Send IPv6 prefix hint',
2104
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2105
	$pconfig['dhcp6-ia-pd-send-hint']
2106
));
2107

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

    
2118
$form->add($section);
2119

    
2120
// DHCP6 client config - Advanced
2121

    
2122
$section = new Form_Section('Advanced DHCP6 client configuration');
2123
$section->addClass('dhcp6advanced');
2124

    
2125
$section->addInput(new Form_Checkbox(
2126
	'adv_dhcp6_interface_statement_information_only_enable',
2127
	'Information only',
2128
	null,
2129
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2130
));
2131

    
2132
$section->addInput(new Form_Input(
2133
	'adv_dhcp6_interface_statement_send_options',
2134
	'Send options',
2135
	'text',
2136
	$pconfig['adv_dhcp6_interface_statement_send_options']
2137
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2138
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2139
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2140
			'Some DHCP services may require certain options be or not be sent.');
2141

    
2142
$section->addInput(new Form_Input(
2143
	'adv_dhcp6_interface_statement_request_options',
2144
	'Request Options',
2145
	'text',
2146
	$pconfig['adv_dhcp6_interface_statement_request_options']
2147
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2148
			'Some DHCP services may require certain options be or not be requested.');
2149

    
2150
$section->addInput(new Form_Input(
2151
	'adv_dhcp6_interface_statement_script',
2152
	'Scripts',
2153
	'text',
2154
	$pconfig['adv_dhcp6_interface_statement_script']
2155
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2156
			'[/[dirname/[.../]]filename[.ext]].');
2157

    
2158
$group = new Form_Group('Identity Association Statement');
2159

    
2160
$group->add(new Form_Checkbox(
2161
	'adv_dhcp6_id_assoc_statement_address_enable',
2162
	null,
2163
	'Non-Temporary Address Allocation',
2164
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2165
));
2166

    
2167
$group->add(new Form_Input(
2168
	'adv_dhcp6_id_assoc_statement_address_id',
2169
	null,
2170
	'text',
2171
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2172
))->sethelp('id-assoc na ID');
2173

    
2174
$group->add(new Form_IpAddress(
2175
	'adv_dhcp6_id_assoc_statement_address',
2176
	null,
2177
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2178
))->sethelp('IPv6 address');
2179

    
2180
$group->add(new Form_Input(
2181
	'adv_dhcp6_id_assoc_statement_address_pltime',
2182
	null,
2183
	'text',
2184
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2185
))->sethelp('pltime');
2186

    
2187
$group->add(new Form_Input(
2188
	'adv_dhcp6_id_assoc_statement_address_vltime',
2189
	null,
2190
	'text',
2191
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2192
))->sethelp('vltime');
2193

    
2194
$section->add($group);
2195

    
2196
// Prefix delegation
2197
$group = new Form_Group('');
2198

    
2199
$group->add(new Form_Checkbox(
2200
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2201
	null,
2202
	'Prefix Delegation ',
2203
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2204
));
2205

    
2206
$group->add(new Form_Input(
2207
	'adv_dhcp6_id_assoc_statement_prefix_id',
2208
	null,
2209
	'text',
2210
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2211
))->sethelp('id-assoc pd ID');
2212

    
2213
$group->add(new Form_IpAddress(
2214
	'adv_dhcp6_id_assoc_statement_prefix',
2215
	null,
2216
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2217
))->sethelp('IPv6 prefix');
2218

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

    
2226
$group->add(new Form_Input(
2227
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2228
	null,
2229
	'text',
2230
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2231
))->sethelp('vltime');
2232

    
2233
$section->add($group);
2234

    
2235
$group = new Form_Group('Prefix interface statement');
2236

    
2237
$group->add(new Form_Input(
2238
	'adv_dhcp6_prefix_interface_statement_sla_id',
2239
	null,
2240
	'text',
2241
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2242
))->sethelp('Prefix Interface sla-id');
2243

    
2244
$group->add(new Form_Input(
2245
	'adv_dhcp6_prefix_interface_statement_sla_len',
2246
	null,
2247
	'text',
2248
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2249
))->sethelp('sla-len');
2250

    
2251
$section->add($group);
2252

    
2253
$group = new Form_Group('Authentication statement');
2254

    
2255
$group->add(new Form_Input(
2256
	'adv_dhcp6_authentication_statement_authname',
2257
	null,
2258
	'text',
2259
	$pconfig['adv_dhcp6_authentication_statement_authname']
2260
))->sethelp('Authname');
2261

    
2262
$group->add(new Form_Input(
2263
	'adv_dhcp6_authentication_statement_protocol',
2264
	null,
2265
	'text',
2266
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2267
))->sethelp('Protocol');
2268

    
2269
$group->add(new Form_Input(
2270
	'adv_dhcp6_authentication_statement_algorithm',
2271
	null,
2272
	'text',
2273
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2274
))->sethelp('Algorithm');
2275

    
2276
$group->add(new Form_Input(
2277
	'adv_dhcp6_authentication_statement_rdm',
2278
	null,
2279
	'text',
2280
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2281
))->sethelp('RDM');
2282

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

    
2285
$group = new Form_Group('Keyinfo statement');
2286

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

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

    
2301
$section->add($group);
2302

    
2303
$group = new Form_Group('');
2304

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

    
2312
$group->add(new Form_Input(
2313
	'adv_dhcp6_key_info_statement_secret',
2314
	null,
2315
	'text',
2316
	$pconfig['adv_dhcp6_key_info_statement_secret']
2317
))->sethelp('Secret');
2318

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

    
2326
$section->add($group);
2327

    
2328
$form->add($section);
2329

    
2330
$section = new Form_Section('6RD Configuration');
2331
$section->addClass('_6rd');
2332

    
2333
$section->addInput(new Form_Input(
2334
	'prefix-6rd',
2335
	'6RD Prefix',
2336
	'text',
2337
	$pconfig['prefix-6rd']
2338
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2339

    
2340
$section->addInput(new Form_Input(
2341
	'gateway-6rd',
2342
	'6RD Border relay',
2343
	'text',
2344
	$pconfig['gateway-6rd']
2345
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2346

    
2347
$section->addInput(new Form_Select(
2348
	'prefix-6rd-v4plen',
2349
	'6RD IPv4 Prefix length',
2350
	$pconfig['prefix-6rd-v4plen'],
2351
	array_combine(range(0, 32), range(0, 32))
2352
))->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.');
2353

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

    
2356
// Track IPv6 ointerface section
2357
$section = new Form_Section('Track IPv6 Interface');
2358
$section->addClass('track6');
2359

    
2360
function build_ipv6interface_list() {
2361
	global $config, $section;
2362

    
2363
	$list = array('' => '');
2364

    
2365
	$interfaces = get_configured_interface_with_descr(false, true);
2366
	$dynv6ifs = array();
2367

    
2368
	foreach ($interfaces as $iface => $ifacename) {
2369
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2370
			case "6to4":
2371
			case "6rd":
2372
			case "dhcp6":
2373
				$dynv6ifs[$iface] = array(
2374
					'name' => $ifacename,
2375
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2376
				);
2377
				break;
2378
			default:
2379
				continue;
2380
		}
2381
	}
2382

    
2383
	foreach ($dynv6ifs as $iface => $ifacedata) {
2384
		$list[$iface] = $ifacedata['name'];
2385

    
2386
		$section->addInput(new Form_Input(
2387
			'ipv6-num-prefix-ids-' . $iface,
2388
			null,
2389
			'hidden',
2390
			$ifacedata['ipv6_num_prefix_ids']
2391
		));
2392
	}
2393

    
2394
	return($list);
2395
}
2396

    
2397
$section->addInput(new Form_Select(
2398
	'track6-interface',
2399
	'IPv6 Interface',
2400
	$pconfig['track6-interface'],
2401
	build_ipv6interface_list()
2402
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2403

    
2404
if ($pconfig['track6-prefix-id'] == "") {
2405
	$pconfig['track6-prefix-id'] = 0;
2406
}
2407

    
2408
$section->addInput(new Form_Input(
2409
	'track6-prefix-id--hex' . $iface,
2410
	'IPv6 Prefix ID',
2411
	'text',
2412
	sprintf("%x", $pconfig['track6-prefix-id'])
2413
))->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.');
2414

    
2415
$section->addInput(new Form_Input(
2416
	'track6-prefix-id-max' . $iface,
2417
	null,
2418
	'hidden',
2419
	0
2420
));
2421

    
2422
$form->add($section);
2423

    
2424
/// PPP section
2425

    
2426
$section = new Form_Section('PPP Configuration');
2427
$section->addClass('ppp');
2428

    
2429
$section->addInput(new Form_Select(
2430
	'country',
2431
	'Country',
2432
	$pconfig['country'],
2433
	[]
2434
));
2435

    
2436
$section->addInput(new Form_Select(
2437
	'provider_list',
2438
	'Provider',
2439
	$pconfig['provider_list'],
2440
	[]
2441
));
2442

    
2443
$section->addInput(new Form_Select(
2444
	'providerplan',
2445
	'Plan',
2446
	$pconfig['providerplan'],
2447
	[]
2448
))->setHelp('Select to fill in data for your service provider.');
2449

    
2450
$section->addInput(new Form_Input(
2451
	'ppp_username',
2452
	'Username',
2453
	'text',
2454
	$pconfig['ppp_username']
2455
));
2456

    
2457
$section->addInput(new Form_Input(
2458
	'ppp_password',
2459
	'Password',
2460
	'password',
2461
	$pconfig['ppp_password']
2462
));
2463

    
2464
$section->addInput(new Form_Input(
2465
	'phone',
2466
	'Phone number',
2467
	'text',
2468
	$pconfig['phone']
2469
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2470

    
2471
$section->addInput(new Form_Input(
2472
	'apn',
2473
	'Access Point Name',
2474
	'text',
2475
	$pconfig['apn']
2476
));
2477

    
2478

    
2479
function build_port_list() {
2480
	$list = array("" => "None");
2481

    
2482
	$portlist = glob("/dev/cua*");
2483
	$modems	  = glob("/dev/modem*");
2484
	$portlist = array_merge($portlist, $modems);
2485

    
2486
	foreach ($portlist as $port) {
2487
		if (preg_match("/\.(lock|init)$/", $port)) {
2488
			continue;
2489
		}
2490

    
2491
	$list[trim($port)] = $port;
2492
	}
2493

    
2494
	return($list);
2495
}
2496

    
2497
$section->addInput(new Form_Select(
2498
	'port',
2499
	"Modem port",
2500
	$pconfig['port'],
2501
	build_port_list()
2502
));
2503

    
2504
$section->addInput(new Form_Button(
2505
	'btnadvppp',
2506
	'Advanced PPP',
2507
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2508
))->setHelp('Create a new PPP configuration');
2509

    
2510
$form->add($section);
2511

    
2512
// PPPoE configuration
2513
$section = new Form_Section('PPPoE Configuration');
2514
$section->addClass('pppoe');
2515

    
2516
$section->addInput(new Form_Input(
2517
	'pppoe_username',
2518
	'Username',
2519
	'text',
2520
	$pconfig['pppoe_username']
2521
));
2522

    
2523
$section->addInput(new Form_Input(
2524
	'pppoe_password',
2525
	'Password',
2526
	'password',
2527
	$pconfig['pppoe_password']
2528
));
2529

    
2530
$section->addInput(new Form_Input(
2531
	'provider',
2532
	'Service name',
2533
	'text',
2534
	$pconfig['provider']
2535
))->setHelp('This field can usually be left empty');
2536

    
2537
$section->addInput(new Form_Checkbox(
2538
	'pppoe_dialondemand',
2539
	'Dial on demand',
2540
	'Enable Dial-On-Demand mode ',
2541
	$pconfig['pppoe_dialondemand'],
2542
	'enable'
2543
));
2544

    
2545
$section->addInput(new Form_Input(
2546
	'pppoe_idletimeout',
2547
	'Idle timeout',
2548
	'number',
2549
	$pconfig['pppoe_idletimeout'],
2550
	[min => 0]
2551
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2552
			'An idle timeout of zero disables this feature.');
2553

    
2554
$section->addInput(new Form_Select(
2555
	'pppoe-reset-type',
2556
	'Periodic reset',
2557
	$pconfig['pppoe-reset-type'],
2558
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2559
))->setHelp('Select a reset timing type');
2560

    
2561
$group = new Form_Group('Custom reset');
2562
$group->addClass('pppoecustom');
2563

    
2564
$group->add(new Form_Input(
2565
	'pppoe_resethour',
2566
	null,
2567
	'number',
2568
	$pconfig['pppoe_resethour'],
2569
	[min => 0, max => 23]
2570
))->setHelp('Hour (0-23)');
2571

    
2572
$group->add(new Form_Input(
2573
	'pppoe_resetminute',
2574
	null,
2575
	'number',
2576
	$pconfig['pppoe_resetminute'],
2577
	[min => 0, max => 59]
2578
))->setHelp('Minutes (0-59)');
2579

    
2580
// ToDo: Need a date-picker here
2581
$group->add(new Form_Input(
2582
	'pppoe_resetdate',
2583
	null,
2584
	'text',
2585
	$pconfig['pppoe_resetdate']
2586
))->setHelp('Specific date (mm/dd/yyyy)');
2587

    
2588
$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');
2589

    
2590
$section->add($group);
2591

    
2592
$group = new Form_MultiCheckboxGroup('cron based reset');
2593
$group->addClass('pppoepreset');
2594

    
2595
$group->add(new Form_MultiCheckbox(
2596
	'pppoe_pr_preset_val',
2597
	null,
2598
	'Reset at each month ("0 0 1 * *")',
2599
	$pconfig['pppoe_monthly'],
2600
	'monthly'
2601
))->displayAsRadio();
2602

    
2603
$group->add(new Form_MultiCheckbox(
2604
	'pppoe_pr_preset_val',
2605
	null,
2606
	'Reset at each week ("0 0 * * 0")',
2607
	$pconfig['pppoe_weekly'],
2608
	'weekly'
2609
))->displayAsRadio();
2610

    
2611
$group->add(new Form_MultiCheckbox(
2612
	'pppoe_pr_preset_val',
2613
	null,
2614
	'Reset at each day ("0 0 * * *")',
2615
	$pconfig['pppoe_daily'],
2616
	'daily'
2617
))->displayAsRadio();
2618

    
2619
$group->add(new Form_MultiCheckbox(
2620
	'pppoe_pr_preset_val',
2621
	null,
2622
	'Reset at each hour ("0 * * * *")',
2623
	$pconfig['pppoe_hourly'],
2624
	'hourly'
2625
))->displayAsRadio();
2626

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

    
2629
if (isset($pconfig['pppid'])) {
2630
	$section->addInput(new Form_StaticText(
2631
		'Advanced and MLPPP',
2632
		'<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>'
2633
	));
2634
} else {
2635
	$section->addInput(new Form_StaticText(
2636
		'Advanced and MLPPP',
2637
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2638
	));
2639
}
2640

    
2641
$form->add($section);
2642

    
2643
// PPTP & L2TP Configuration section
2644
$section = new Form_Section('PPTP/L2TP Configuration');
2645
$section->addClass('pptp');
2646

    
2647
$section->addInput(new Form_Input(
2648
	'pptp_username',
2649
	'Username',
2650
	'text',
2651
	$pconfig['pptp_username']
2652
));
2653

    
2654
$section->addInput(new Form_Input(
2655
	'pptp_password',
2656
	'Password',
2657
	'password',
2658
	$pconfig['pptp_password']
2659
));
2660

    
2661
$section->addInput(new Form_IpAddress(
2662
	'pptp_local0',
2663
	'Local IP address',
2664
	$pconfig['pptp_localip'][0]
2665
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2666

    
2667
$section->addInput(new Form_IpAddress(
2668
	'pptp_remote0',
2669
	'Remote IP address',
2670
	$pconfig['pptp_remote'][0]
2671
));
2672

    
2673
$section->addInput(new Form_Checkbox(
2674
	'pptp_dialondemand',
2675
	'Dial on demand',
2676
	'Enable Dial-On-Demand mode ',
2677
	$pconfig['pptp_dialondemand'],
2678
	'enable'
2679
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2680
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2681

    
2682
$section->addInput(new Form_Input(
2683
	'pptp_idletimeout',
2684
	'Idle timeout (seconds)',
2685
	'number',
2686
	$pconfig['pptp_idletimeout'],
2687
	[min => 0]
2688
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2689
			'An idle timeout of zero disables this feature.');
2690

    
2691
if (isset($pconfig['pppid'])) {
2692
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2693
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2694
	} else {
2695
		$mlppp_text = "";
2696
	}
2697

    
2698
	$section->addInput(new Form_StaticText(
2699
		'Advanced and MLPPP',
2700
		$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>'
2701
	));
2702
} else {
2703
	$section->addInput(new Form_StaticText(
2704
		'Advanced and MLPPP',
2705
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2706
	));
2707
}
2708

    
2709
$form->add($section);
2710

    
2711
// Wireless interface
2712
if (isset($wancfg['wireless'])) {
2713

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

    
2716
	$section->addInput(new Form_Checkbox(
2717
		'persistcommonwireless',
2718
		'Persist common settings',
2719
		'Preserve common wireless configuration through interface deletions and reassignments.',
2720
		$pconfig['persistcommonwireless'],
2721
		'yes'
2722
	));
2723

    
2724
	$mode_list = ['auto' => 'Auto'];
2725

    
2726
	if (is_array($wl_modes)) {
2727
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2728
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2729
		}
2730
	}
2731

    
2732
	if (count($mode_list) == 1) {
2733
		$mode_list[''] = '';
2734
	}
2735

    
2736
	$section->addInput(new Form_Select(
2737
		'standard',
2738
		'Standard',
2739
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2740
		$mode_list
2741
	));
2742

    
2743
	if (isset($wl_modes['11g'])) {
2744
		$section->addInput(new Form_Select(
2745
			'protmode',
2746
			'802.11g OFDM Protection Mode',
2747
			$pconfig['protmode'],
2748
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2749
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2750
	} else {
2751
		$section->addInput(new Form_Input(
2752
			'protmode',
2753
			null,
2754
			'hidden',
2755
			'off'
2756
		));
2757
	}
2758

    
2759
	$mode_list = ['0' => 'Auto'];
2760

    
2761
	if (is_array($wl_modes)) {
2762
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2763
			if ($wl_standard == "11g") {
2764
				$wl_standard = "11b/g";
2765
			} else if ($wl_standard == "11ng") {
2766
				$wl_standard = "11b/g/n";
2767
			} else if ($wl_standard == "11na") {
2768
				$wl_standard = "11a/n";
2769
			}
2770

    
2771
			foreach ($wl_channels as $wl_channel) {
2772
				if (isset($wl_chaninfo[$wl_channel])) {
2773
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2774
				} else {
2775
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2776
				}
2777
			}
2778
		}
2779
	}
2780

    
2781
	$section->addInput(new Form_Select(
2782
		'channel',
2783
		'Channel',
2784
		$pconfig['channel'],
2785
		$mode_list
2786
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2787
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2788

    
2789
	if (ANTENNAS) {
2790
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2791
			$group = new Form_Group('Antenna Settings');
2792

    
2793
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2794
				$group->add(new Form_Select(
2795
					'diversity',
2796
					null,
2797
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2798
					['' => 'Default', '0' => 'Off', '1' => 'On']
2799
				))->setHelp('Diversity');
2800
			}
2801

    
2802
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2803
				$group->add(new Form_Select(
2804
					'txantenna',
2805
					null,
2806
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2807
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2808
				))->setHelp('Transmit antenna');
2809
			}
2810

    
2811
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2812
				$group->add(new Form_Select(
2813
					'rxantenna',
2814
					null,
2815
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2816
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2817
				))->setHelp('Receive antenna');
2818
			}
2819

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

    
2822
			$section->add($group);
2823
		}
2824
	}
2825

    
2826
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2827
			$section->addInput(new Form_Input(
2828
				'distance',
2829
				'Distance setting (meters)',
2830
				'test',
2831
				$pconfig['distance']
2832
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2833
	}
2834

    
2835
	$form->add($section);
2836

    
2837
	// Regulatory settings
2838
	$section = new Form_Section('Regulatory settings');
2839

    
2840
	$domain_list = array("" => 'Default');
2841

    
2842
	if (is_array($wl_regdomains)) {
2843
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2844
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2845
		}
2846
	}
2847

    
2848
	$section->addInput(new Form_Select(
2849
		'regdomain',
2850
		'Regulatory domain',
2851
		$pconfig['regdomain'],
2852
		$domain_list
2853
	))->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');
2854

    
2855
	$country_list = array('' => 'Default');
2856

    
2857
	if (is_array($wl_countries)) {
2858
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2859
			$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']);
2860
		}
2861
	}
2862

    
2863
	$section->addInput(new Form_Select(
2864
		'regcountry',
2865
		'Country',
2866
		$pconfig['regcountry'],
2867
		$country_list
2868
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2869

    
2870
	$section->addInput(new Form_Select(
2871
		'reglocation',
2872
		'Location',
2873
		$pconfig['reglocation'],
2874
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2875
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2876
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2877
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2878
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2879
				'These settings may not be able to add additional channels that are not already supported.');
2880

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

    
2883
	$section = new Form_Section('Network-specific wireless configuration');
2884

    
2885
	$section->addInput(new Form_Select(
2886
		'mode',
2887
		'Mode',
2888
		$pconfig['mode'],
2889
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
2890
	));
2891

    
2892
	$section->addInput(new Form_Input(
2893
		'ssid',
2894
		'SSID',
2895
		'text',
2896
		$pconfig['ssid']
2897
	));
2898

    
2899
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2900
		$section->addInput(new Form_Select(
2901
			'puremode',
2902
			'Minimum wireless standard',
2903
			$pconfig['puremode'],
2904
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
2905
		))->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)');
2906
	} elseif (isset($wl_modes['11g'])) {
2907
		$section->addInput(new Form_Checkbox(
2908
			'puremode',
2909
			'802.11g only',
2910
			null,
2911
			$pconfig['puremode'],
2912
			'11g'
2913
		))->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)');
2914
	}
2915

    
2916
	$section->addInput(new Form_Checkbox(
2917
		'apbridge_enable',
2918
		'Allow intra-BSS communication',
2919
		'Allow packets to pass between wireless clients directly when operating as an access point',
2920
		$pconfig['apbridge_enable'],
2921
		'yes'
2922
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2923

    
2924
	$section->addInput(new Form_Checkbox(
2925
		'wme_enable',
2926
		'Enable WME',
2927
		'Force the card to use WME (wireless QoS)',
2928
		$pconfig['wme_enable'],
2929
		'yes'
2930
	));
2931

    
2932
	$section->addInput(new Form_Checkbox(
2933
		'hidessid_enable',
2934
		'Hide SSID',
2935
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2936
		$pconfig['hidessid_enable'],
2937
		'yes'
2938
	));
2939

    
2940
	$form->add($section);
2941

    
2942
	// WPA Section
2943
	$section = new Form_Section('WPA');
2944

    
2945
	$section->addInput(new Form_Checkbox(
2946
		'wpa_enable',
2947
		'Enable',
2948
		'Enable WPA',
2949
		$pconfig['wpa_enable'],
2950
		'yes'
2951
	));
2952

    
2953
	$section->addInput(new Form_Input(
2954
		'passphrase',
2955
		'WPA Pre-Shared Key',
2956
		'text',
2957
		$pconfig['passphrase']
2958
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2959

    
2960
	$section->addInput(new Form_Select(
2961
		'wpa_mode',
2962
		'WPA mode',
2963
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2964
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
2965
	));
2966

    
2967
	$section->addInput(new Form_Select(
2968
		'wpa_key_mgmt',
2969
		'WPA Key Management Mode',
2970
		$pconfig['wpa_key_mgmt'],
2971
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
2972
	));
2973

    
2974
	$section->addInput(new Form_Select(
2975
		'wpa_pairwise',
2976
		'WPA Pairwise',
2977
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
2978
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
2979
	));
2980

    
2981
	$section->addInput(new Form_Input(
2982
		'wpa_group_rekey',
2983
		'WPA Pre-Shared Key',
2984
		'number',
2985
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
2986
		['min' => '1', 'max' => 9999]
2987
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
2988

    
2989
	$section->addInput(new Form_Input(
2990
		'wpa_gmk_rekey',
2991
		'Master Key Regeneration',
2992
		'number',
2993
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
2994
		['min' => '1', 'max' => 9999]
2995
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
2996

    
2997
	$section->addInput(new Form_Checkbox(
2998
		'wpa_strict_rekey',
2999
		'Strict Key Regeneration',
3000
		'Force the AP to rekey whenever a client disassociates',
3001
		$pconfig['wpa_strict_rekey'],
3002
		'yes'
3003
	));
3004

    
3005
	$form->add($section);
3006

    
3007
	$section = new Form_Section('802.1x RADIUS options');
3008

    
3009
	$section->addInput(new Form_Checkbox(
3010
		'ieee8021x',
3011
		'IEEE802.1X',
3012
		'Enable 802.1X authentication',
3013
		$pconfig['ieee8021x'],
3014
		'yes'
3015
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3016

    
3017
	$group = new Form_Group('Primary 802.1X server');
3018

    
3019
	$group->add(new Form_IpAddress(
3020
		'auth_server_addr',
3021
		'IP Address',
3022
		$pconfig['auth_server_addr']
3023
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3024

    
3025
	$group->add(new Form_Input(
3026
		'auth_server_port',
3027
		'Port',
3028
		'number',
3029
		$pconfig['auth_server_port']
3030
	))->setHelp('Server port. Leave blank for the default port 1812');
3031

    
3032
	$group->add(new Form_Input(
3033
		'auth_server_shared_secret',
3034
		'Shared secret',
3035
		'number',
3036
		$pconfig['auth_server_shared_secret']
3037
	))->setHelp('Shared secret');
3038

    
3039
	$section->add($group);
3040

    
3041
	$group = new Form_Group('Secondary 802.1X server');
3042

    
3043
	$group->add(new Form_IpAddress(
3044
		'auth_server_addr2',
3045
		'IP Address',
3046
		$pconfig['auth_server_addr2']
3047
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3048

    
3049
	$group->add(new Form_Input(
3050
		'auth_server_port2',
3051
		'Port',
3052
		'number',
3053
		$pconfig['auth_server_port2']
3054
	))->setHelp('Server port. Leave blank for the default port 1812');
3055

    
3056
	$group->add(new Form_Input(
3057
		'auth_server_shared_secret2',
3058
		'Shared secret',
3059
		'number',
3060
		$pconfig['auth_server_shared_secret2']
3061
	))->setHelp('Shared secret');
3062

    
3063
	$section->add($group);
3064

    
3065
	$section->addInput(new Form_Checkbox(
3066
		'rsn_preauth',
3067
		'Authentication Roaming Preauth',
3068
		null,
3069
		$pconfig['rsn_preauth'],
3070
		'yes'
3071
	));
3072

    
3073
	$form->add($section);
3074
}
3075

    
3076
$section = new Form_Section('Private networks');
3077

    
3078
$section->addInput(new Form_Checkbox(
3079
	'blockpriv',
3080
	'Block private networks',
3081
	'',
3082
	$pconfig['blockpriv'],
3083
	'yes'
3084
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3085
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3086
			'lies in such a private address space, too.');
3087

    
3088
$section->addInput(new Form_Checkbox(
3089
	'blockbogons',
3090
	'Block bogon networks',
3091
	'',
3092
	$pconfig['blockbogons'],
3093
	'yes'
3094
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3095
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3096
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3097

    
3098
$form->add($section);
3099

    
3100
$form->addGlobal(new Form_Input(
3101
	'if',
3102
	null,
3103
	'hidden',
3104
	$if
3105
));
3106

    
3107
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3108
	$form->addGlobal(new Form_Input(
3109
		'ppp_port',
3110
		null,
3111
		'hidden',
3112
		$pconfig['port']
3113
	));
3114
}
3115

    
3116
$form->addGlobal(new Form_Input(
3117
	'ptpid',
3118
	null,
3119
	'hidden',
3120
	$pconfig['ptpid']
3121
));
3122

    
3123

    
3124
// Add new gateway modal pop-up
3125
$modal = new Modal('New gateway', 'newgateway', 'large');
3126

    
3127
$modal->addInput(new Form_Checkbox(
3128
	'defaultgw',
3129
	'Default',
3130
	'Default gateway',
3131
	($if == "wan" || $if == "WAN")
3132
));
3133

    
3134
$modal->addInput(new Form_Input(
3135
	'name',
3136
	'Gateway name',
3137
	'text',
3138
	$wancfg['descr'] . "GW"
3139
));
3140

    
3141
$modal->addInput(new Form_IpAddress(
3142
	'gatewayip',
3143
	'Gateway IPv4',
3144
	null
3145
));
3146

    
3147
$modal->addInput(new Form_Input(
3148
	'gatewaydescr',
3149
	'Description',
3150
	'text'
3151
));
3152

    
3153
$btnaddgw = new Form_Button(
3154
	'add',
3155
	'Add'
3156
);
3157

    
3158
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3159

    
3160
$btncnxgw = new Form_Button(
3161
	'cnx',
3162
	'Cancel'
3163
);
3164

    
3165
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3166

    
3167
$modal->addInput(new Form_StaticText(
3168
	null,
3169
	$btnaddgw . $btncnxgw
3170
));
3171

    
3172
$form->add($modal);
3173

    
3174
print($form);
3175
?>
3176

    
3177
<script type="text/javascript">
3178
//<![CDATA[
3179
events.push(function() {
3180
	function updateType(t) {
3181

    
3182
		switch (t) {
3183
			case "none": {
3184
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3185
				break;
3186
			}
3187
			case "staticv4": {
3188
				$('.dhcpadvanced, .none, .dhcp').hide();
3189
				$('.pppoe, .pptp, .ppp').hide();
3190
				break;
3191
			}
3192
			case "dhcp": {
3193
				$('.dhcpadvanced, .none').hide();
3194
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3195
										//			about the staticv4 class
3196
				$('.pppoe, .pptp, .ppp').hide();
3197
				break;
3198
			}
3199
			case "ppp": {
3200
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3201
				country_list();
3202
				break;
3203
			}
3204
			case "pppoe": {
3205
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3206
				break;
3207
			}
3208
			case "l2tp":
3209
			case "pptp": {
3210
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3211
				$('.pptp').show();
3212
				break;
3213
			}
3214
		}
3215

    
3216
		if (t != "l2tp" && t != "pptp") {
3217
			$('.'+t).show();
3218
		}
3219
	}
3220

    
3221
	function updateTypeSix(t) {
3222
		if (!isNaN(t[0])) {
3223
			t = '_' + t;
3224
		}
3225

    
3226
		switch (t) {
3227
			case "none": {
3228
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3229
				break;
3230
			}
3231
			case "staticv6": {
3232
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3233
				break;
3234
			}
3235
			case "slaac": {
3236
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3237
				break;
3238
			}
3239
			case "dhcp6": {
3240
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3241
				break;
3242
			}
3243
			case "6rd_": {
3244
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3245
				break;
3246
			}
3247
			case "_6to4": {
3248
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3249
				break;
3250
			}
3251
			case "track6": {
3252
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3253
				update_track6_prefix();
3254
				break;
3255
			}
3256
		}
3257

    
3258
		if (t != "l2tp" && t != "pptp") {
3259
			$('.'+t).show();
3260
		}
3261
	}
3262

    
3263
	function show_reset_settings(reset_type) {
3264
		if (reset_type == 'preset') {
3265
			$('.pppoepreset').show();
3266
			$('.pppoecustom').hide();
3267
		} else if (reset_type == 'custom') {
3268
			$('.pppoecustom').show();
3269
			$('.pppoepreset').hide();
3270
		} else {
3271
			$('.pppoecustom').hide();
3272
			$('.pppoepreset').hide();
3273
		}
3274
	}
3275

    
3276
	function update_track6_prefix() {
3277
		var iface = $("#track6-interface").val();
3278
		if (iface == null) {
3279
			return;
3280
		}
3281

    
3282
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3283
		if (track6_prefix_ids == null) {
3284
			return;
3285
		}
3286

    
3287
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3288
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3289
	}
3290

    
3291
	// Create the new gateway from the data entered in the modal pop-up
3292
	function hide_add_gatewaysave() {
3293
		var iface = $('#if').val();
3294
		name = $('#name').val();
3295
		var descr = $('#gatewaydescr').val();
3296
		gatewayip = $('#gatewayip').val();
3297

    
3298
		var defaultgw = '';
3299
		if ($('#defaultgw').is(':checked')) {
3300
			defaultgw = '&defaultgw=on';
3301
		}
3302

    
3303
		var url = "system_gateways_edit.php";
3304
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3305
		$.ajax(
3306
			url,
3307
			{
3308
				type: 'post',
3309
				data: pars,
3310
				error: report_failure,
3311
				complete: save_callback
3312
			});
3313
		}
3314

    
3315
	function save_callback(response) {
3316
		if (response) {
3317
			var gwtext = escape(name) + " - " + gatewayip;
3318
			addOption($('#gateway'), gwtext, name);
3319
		} else {
3320
			report_failure();
3321
		}
3322

    
3323
		$("#newgateway").modal('hide');
3324
	}
3325

    
3326
	function report_failure(request, textStatus, errorThrown) {
3327
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3328
			alert(request.responseText);
3329
		} else {
3330
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3331
		}
3332

    
3333
		$("#newgateway").modal('hide');
3334
	}
3335

    
3336
	function addOption(selectbox, text, value) {
3337
		var optn = document.createElement("OPTION");
3338
		optn.text = text;
3339
		optn.value = value;
3340
		selectbox.append(optn);
3341
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3342
	}
3343

    
3344
	function hide_add_gatewaysave_v6() {
3345

    
3346
		var iface = $('#if').val();
3347
		name = $('#name6').val();
3348
		var descr = $('#gatewaydescr6').val();
3349
		gatewayip = $('#gatewayip6').val();
3350
		var defaultgw = '';
3351
		if ($('#defaultgw6').is(':checked')) {
3352
			defaultgw = '&defaultgw=on';
3353
		}
3354
		var url_v6 = "system_gateways_edit.php";
3355
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3356
		$.ajax(
3357
			url_v6,
3358
			{
3359
				type: 'post',
3360
				data: pars_v6,
3361
				error: report_failure_v6,
3362
				success: save_callback_v6
3363
			});
3364
	}
3365

    
3366

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

    
3375
	function report_failure_v6(request, textStatus, errorThrown) {
3376
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3377
			alert(request.responseText);
3378
		} else {
3379
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3380
		}
3381

    
3382
		$("#newgateway6").modal('hide');
3383
	}
3384

    
3385
	function save_callback_v6(response_v6) {
3386
		if (response_v6) {
3387

    
3388
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3389
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3390
		} else {
3391
			report_failure_v6();
3392
		}
3393

    
3394
		$("#newgateway6").modal('hide');
3395
	}
3396

    
3397
	function country_list() {
3398
		$('#country').children().remove();
3399
		$('#provider_list').children().remove();
3400
		$('#providerplan').children().remove();
3401
		$.ajax("getserviceproviders.php",{
3402
			success: function(response) {
3403

    
3404
				var responseTextArr = response.split("\n");
3405
				responseTextArr.sort();
3406

    
3407
				responseTextArr.forEach( function(value) {
3408
					country = value.split(":");
3409
					$('#country').append($('<option>', {
3410
						value: country[1],
3411
						text : country[0]
3412
					}));
3413
				});
3414
			}
3415
		});
3416
	}
3417

    
3418
	function providers_list() {
3419
		$('#provider_list').children().remove();
3420
		$('#providerplan').children().remove();
3421
		$.ajax("getserviceproviders.php",{
3422
			type: 'post',
3423
			data: {country : $('#country').val()},
3424
			success: function(response) {
3425
				var responseTextArr = response.split("\n");
3426
				responseTextArr.sort();
3427
				responseTextArr.forEach( function(value) {
3428
					$('#provider_list').append($('<option>', {
3429
							value: value,
3430
							text : value
3431
					}));
3432
				});
3433
			}
3434
		});
3435
	}
3436

    
3437
	function providerplan_list() {
3438
		$('#providerplan').children().remove();
3439
		$.ajax("getserviceproviders.php",{
3440
			type: 'post',
3441
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3442
			success: function(response) {
3443
				var responseTextArr = response.split("\n");
3444
				responseTextArr.sort();
3445

    
3446
				$('#providerplan').append($('<option>', {
3447
					value: '',
3448
					text : ''
3449
				}));
3450

    
3451
				responseTextArr.forEach( function(value) {
3452
					if (value != "") {
3453
						providerplan = value.split(":");
3454

    
3455
						$('#providerplan').append($('<option>', {
3456
							value: providerplan[1],
3457
							text : providerplan[0] + " - " + providerplan[1]
3458
						}));
3459
					}
3460
				});
3461
			}
3462
		});
3463
	}
3464

    
3465
	function prefill_provider() {
3466
		$.ajax("getserviceproviders.php",{
3467
			type: 'post',
3468
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3469
			success: function(data, textStatus, response) {
3470
				var xmldoc = response.responseXML;
3471
				var provider = xmldoc.getElementsByTagName('connection')[0];
3472
				$('#ppp_username').val('');
3473
				$('#ppp_password').val('');
3474
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3475
					$('#phone').val('#777');
3476
					$('#apn').val('');
3477
				} else {
3478
					$('#phone').val('*99#');
3479
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3480
				}
3481
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3482
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3483
				$('#ppp_username').val(ppp_username);
3484
				$('#ppp_password').val(ppp_password);
3485
			}
3486
		});
3487
	}
3488

    
3489
	function show_dhcp6adv() {
3490
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3491
		var adv = $('#dhcp6adv').prop('checked');
3492

    
3493
		hideCheckbox('dhcp6usev4iface', ovr);
3494
		hideCheckbox('dhcp6prefixonly', ovr);
3495
		hideInput('dhcp6-ia-pd-len', ovr);
3496
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3497
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3498

    
3499
		hideClass('dhcp6advanced', !adv || ovr);
3500
	}
3501

    
3502
	function setDHCPoptions() {
3503
		var adv = $('#dhcpadv').prop('checked');
3504
		var ovr = $('#dhcpovr').prop('checked');
3505

    
3506
		if (ovr) {
3507
			hideInput('dhcphostname', true);
3508
			hideIpAddress('alias-address', true);
3509
			hideInput('dhcprejectfrom', true);
3510
			hideInput('adv_dhcp_config_file_override_path', false);
3511
			hideClass('dhcpadvanced', true);
3512
		} else {
3513
			hideInput('dhcphostname', false);
3514
			hideIpAddress('alias-address', false);
3515
			hideInput('dhcprejectfrom', false);
3516
			hideInput('adv_dhcp_config_file_override_path', true);
3517
			hideClass('dhcpadvanced', !adv);
3518
		}
3519
	}
3520

    
3521
	// DHCP preset actions
3522
	// Set presets from value of radio buttons
3523
	function setPresets(val) {
3524
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3525
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3526
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3527
		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']);?>");
3528
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3529
	}
3530

    
3531
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3532
		$('#adv_dhcp_pt_timeout').val(timeout);
3533
		$('#adv_dhcp_pt_retry').val(retry);
3534
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3535
		$('#adv_dhcp_pt_reboot').val(reboot);
3536
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3537
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3538
	}
3539

    
3540
	// ---------- On initial page load ------------------------------------------------------------
3541

    
3542
	updateType($('#type').val());
3543
	updateTypeSix($('#type6').val());
3544
	show_reset_settings($('#pppoe-reset-type').val());
3545
	$("#add").prop('type', 'button');
3546
	$("#cnx").prop('type', 'button');
3547
	$("#addgw").prop('type', 'button');
3548
	$("#add6").prop('type', 'button');
3549
	$("#cnx6").prop('type', 'button');
3550
	$("#addgw6").prop('type', 'button');
3551
	hideClass('dhcp6advanced', true);
3552
	hideClass('dhcpadvanced', true);
3553
	show_dhcp6adv();
3554
	setDHCPoptions()
3555

    
3556
	// Set preset buttons on page load
3557
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3558
	if (sv == "") {
3559
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3560
	} else {
3561
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3562
	}
3563

    
3564
	// Set preset from value
3565
	setPresets(sv);
3566

    
3567
	// ---------- Click checkbox handlers ---------------------------------------------------------
3568

    
3569
	$('#type').on('change', function() {
3570
		updateType(this.value);
3571
	});
3572

    
3573
	$('#type6').on('change', function() {
3574
		updateTypeSix(this.value);
3575
	});
3576

    
3577
	$('#pppoe-reset-type').on('change', function() {
3578
		show_reset_settings(this.value);
3579
	});
3580

    
3581
	$("#add").click(function() {
3582
		hide_add_gatewaysave();
3583
	});
3584

    
3585
	$("#cnx").click(function() {
3586
		$("#newgateway").modal('hide');
3587
	});
3588

    
3589
	$("#add6").click(function() {
3590
		hide_add_gatewaysave_v6();
3591
	});
3592

    
3593
	$("#cnx6").click(function() {
3594
		$("#newgateway6").modal('hide');
3595
	});
3596

    
3597
	$('#country').on('change', function() {
3598
		providers_list();
3599
	});
3600

    
3601
	$('#provider_list').on('change', function() {
3602
		providerplan_list();
3603
	});
3604

    
3605
	$('#providerplan').on('change', function() {
3606
		prefill_provider();
3607
	});
3608

    
3609
	$('#dhcpadv, #dhcpovr').click(function () {
3610
		setDHCPoptions();
3611
	});
3612

    
3613
	$('#dhcp6adv').click(function () {
3614
		show_dhcp6adv();
3615
	});
3616

    
3617
	$('#adv_dhcp6_config_file_override').click(function () {
3618
		show_dhcp6adv();
3619
	});
3620

    
3621
	// On click . .
3622
	$('[name=adv_dhcp_pt_values]').click(function () {
3623
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3624
	});
3625

    
3626
});
3627
//]]>
3628
</script>
3629

    
3630
<?php include("foot.inc");
(69-69/228)