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
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
61
	pfSense_MODULE: interfaces
62
*/
63

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

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

    
81
define("ANTENNAS", false);
82

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

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

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

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

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

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

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

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

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

    
127
$a_gateways = &$config['gateways']['gateway_item'];
128

    
129
$wancfg = &$config['interfaces'][$if];
130
$old_wancfg = $wancfg;
131
$old_wancfg['realif'] = get_real_interface($if);
132
$old_ppps = $a_ppps;
133

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

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

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

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

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

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

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

    
225
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
226
$pconfig['alias-address'] = $wancfg['alias-address'];
227
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
228
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
229

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
450
}
451

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

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

    
478
		/* sync filter configuration */
479
		setup_gateways_monitor();
480

    
481
		clear_subsystem_dirty('interfaces');
482

    
483
		filter_configure();
484

    
485
		enable_rrd_graphing();
486

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

    
514
	unset($input_errors);
515
	$pconfig = $_POST;
516

    
517
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
518
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
519
	} else {
520
		$pconfig['track6-prefix-id'] = 0;
521
	}
522
	conf_mount_rw();
523

    
524
	/* filter out spaces from descriptions */
525
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
526

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

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

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

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

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

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

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

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

    
828
		unset($min_mtu, $max_mtu);
829

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

    
846
				$realhwif_array = get_parent_interface($ifdata['if']);
847
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
848
				$parent_realhwif = $realhwif_array[0];
849

    
850
				if ($parent_realhwif != $wancfg['if']) {
851
					continue;
852
				}
853

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

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

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

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

    
999
		unset($wancfg['adv_dhcp_pt_timeout']);
1000
		unset($wancfg['adv_dhcp_pt_retry']);
1001
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1002
		unset($wancfg['adv_dhcp_pt_reboot']);
1003
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1004
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1005

    
1006
		unset($wancfg['adv_dhcp_pt_values']);
1007

    
1008
		unset($wancfg['adv_dhcp_send_options']);
1009
		unset($wancfg['adv_dhcp_request_options']);
1010
		unset($wancfg['adv_dhcp_required_options']);
1011
		unset($wancfg['adv_dhcp_option_modifiers']);
1012

    
1013
		unset($wancfg['adv_dhcp_config_advanced']);
1014
		unset($wancfg['adv_dhcp_config_file_override']);
1015
		unset($wancfg['adv_dhcp_config_file_override_path']);
1016

    
1017
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1018
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1019
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1020
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1021

    
1022
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1023
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1024
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1025
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1026
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1027

    
1028
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1029
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1030
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1031
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1032
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1033

    
1034
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1035
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1036

    
1037
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1038
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1039
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1040
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1041

    
1042
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1043
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1044
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1045
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1046
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1047

    
1048
		unset($wancfg['adv_dhcp6_config_advanced']);
1049
		unset($wancfg['adv_dhcp6_config_file_override']);
1050
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1051

    
1052
		unset($wancfg['pppoe_password']);
1053
		unset($wancfg['pptp_username']);
1054
		unset($wancfg['pptp_password']);
1055
		unset($wancfg['provider']);
1056
		unset($wancfg['ondemand']);
1057
		unset($wancfg['timeout']);
1058
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1059
			unset($wancfg['pppoe']['pppoe-reset-type']);
1060
		}
1061
		unset($wancfg['local']);
1062

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

    
1084
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1085
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1086

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

    
1103
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1104
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1105
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1106
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1107
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1108
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1109

    
1110
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1111

    
1112
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1113
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1114
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1115
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1116

    
1117
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1118
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1119
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1120

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

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

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

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

    
1233
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1234
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1235
				}
1236
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1237
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1238
				}
1239
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1240
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1241
				}
1242
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1243
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1244
				}
1245

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

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

    
1278
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1279
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1280
				}
1281
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1282
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1283
				}
1284

    
1285
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1286
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1287
				}
1288
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1289
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1290
				}
1291
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1292
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1293
				}
1294
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1295
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1296
				}
1297

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

    
1314
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1315
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1316
				}
1317
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1318
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1319
				}
1320
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1321
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1322
				}
1323

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

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

    
1395
		conf_mount_ro();
1396
		write_config();
1397

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

    
1407
		mark_subsystem_dirty('interfaces');
1408

    
1409
		/* regenerate cron settings/crontab file */
1410
		configure_cron();
1411

    
1412
		header("Location: interfaces.php?if={$if}");
1413
		exit;
1414
	}
1415

    
1416
} // end if ($_POST)
1417

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

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

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

    
1567
	interface_sync_wireless_clones($wancfg, true);
1568
}
1569

    
1570
function check_wireless_mode() {
1571
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1572

    
1573
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1574
		return;
1575
	}
1576

    
1577
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1578
		$clone_count = 1;
1579
	} else {
1580
		$clone_count = 0;
1581
	}
1582

    
1583
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1584
		foreach ($config['wireless']['clone'] as $clone) {
1585
			if ($clone['if'] == $wlanbaseif) {
1586
				$clone_count++;
1587
			}
1588
		}
1589
	}
1590

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

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

    
1618
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1619
$shortcut_section = "interfaces";
1620

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

    
1624
$closehead = false;
1625

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

    
1631
function build_mediaopts_list() {
1632
	global $mediaopts_list;
1633

    
1634
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1635
			 " " =>	 "------- Media Supported by this interface -------"
1636
			];
1637

    
1638
	foreach ($mediaopts_list as $mediaopt) {
1639
		$list[$mediaopt] = $mediaopt;
1640
	}
1641

    
1642
	return($list);
1643
}
1644

    
1645
function build_gateway_list() {
1646
	global $a_gateways, $if;
1647

    
1648
	$list = array("none" => "None");
1649
	foreach ($a_gateways as $gateway) {
1650
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1651
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1652
		}
1653
	}
1654

    
1655
	return($list);
1656
}
1657

    
1658
function build_gatewayv6_list() {
1659
	global $a_gateways, $if;
1660

    
1661
	$list = array("none" => "None");
1662
	foreach ($a_gateways as $gateway) {
1663
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1664
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1665
		}
1666
	}
1667

    
1668
	return($list);
1669
}
1670

    
1671
include("head.inc");
1672

    
1673
if ($input_errors)
1674
	print_input_errors($input_errors);
1675

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

    
1680
if ($savemsg)
1681
	print_info_box($savemsg, 'success');
1682

    
1683

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1880
// ==== DHCP client configuration =============================
1881

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

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

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

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

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

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

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

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

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

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

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

    
1941
$group->add(new Form_Input(
1942
	'adv_dhcp_pt_select_timeout',
1943
	null,
1944
	'number',
1945
	$pconfig['adv_dhcp_pt_select_timeout']
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
	'Option modifiers',
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_require_options',
2046
	'Request options',
2047
	'text',
2048
	$pconfig['adv_dhcp_require_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
	$section->addInput(new Form_Select(
2736
		'standard',
2737
		'Standard',
2738
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2739
		$mode_list
2740
	));
2741

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3124

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

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

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

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

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

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

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

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

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

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

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

    
3175
print($form);
3176
?>
3177

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

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

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

    
3222
	function updateTypeSix(t) {
3223
		if (!isNaN(t[0]))
3224
			t = '_' + t;
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
	{
3338
		var optn = document.createElement("OPTION");
3339
		optn.text = text;
3340
		optn.value = value;
3341
		selectbox.append(optn);
3342
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3343
	}
3344

    
3345
	function hide_add_gatewaysave_v6() {
3346

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

    
3367

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

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

    
3384
		$("#newgateway6").modal('hide');
3385
	}
3386

    
3387
	function save_callback_v6(response_v6) {
3388
		if (response_v6) {
3389

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

    
3396
		$("#newgateway6").modal('hide');
3397
	}
3398

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

    
3406
				var responseTextArr = response.split("\n");
3407
				responseTextArr.sort();
3408

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

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

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

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

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

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

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

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

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

    
3501
		hideClass('dhcp6advanced', !adv || ovr);
3502
	}
3503

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

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

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

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

    
3542
	// ---------- On initial page load ------------------------------------------------------------
3543

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

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

    
3563
	// Set preset from value
3564
	setPresets(sv);
3565
	
3566
	// ---------- Click checkbox handlers ---------------------------------------------------------
3567

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3629
<?php include("foot.inc");
(80-80/228)