Project

General

Profile

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

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

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

    
77
define("ANTENNAS", false);
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
446
}
447

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

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

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

    
477
		clear_subsystem_dirty('interfaces');
478

    
479
		filter_configure();
480

    
481
		enable_rrd_graphing();
482

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

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

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

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

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

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

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

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

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

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

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

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

    
824
		unset($min_mtu, $max_mtu);
825

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1391
		conf_mount_ro();
1392
		write_config();
1393

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

    
1403
		mark_subsystem_dirty('interfaces');
1404

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

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

    
1412
} // end if ($_POST)
1413

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

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

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

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

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

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

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

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

    
1587
	if ($clone_count > 1) {
1588
		$old_wireless_mode = $wancfg['wireless']['mode'];
1589
		$wancfg['wireless']['mode'] = $_POST['mode'];
1590
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1591
			$input_errors[] = sprintf(gettext("Unable to change mode to %s.	 You may already have the maximum number of wireless clones supported in this mode."), $wlan_modes[$wancfg['wireless']['mode']]);
1592
		} else {
1593
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1594
		}
1595
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1596
	}
1597
}
1598

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

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

    
1617
$types4 = array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP"), "ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP"));
1618
$types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), "dhcp6" => gettext("DHCP6"), "slaac" => gettext("SLAAC"), "6rd" => gettext("6rd Tunnel"), "6to4" => gettext("6to4 Tunnel"), "track6" => gettext("Track Interface"));
1619

    
1620
$closehead = false;
1621

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

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

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

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

    
1638
	return($list);
1639
}
1640

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

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

    
1651
	return($list);
1652
}
1653

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

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

    
1664
	return($list);
1665
}
1666

    
1667
include("head.inc");
1668

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

    
1673
if (is_subsystem_dirty('interfaces')) {
1674
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1675
					  gettext("You must apply the changes in order for them to take effect. Don't forget to adjust the DHCP Server range if needed after applying."));
1676
}
1677

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

    
1682

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1792
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.' . '<br />' .
1793
				'On local LANs the upstream gateway should be "none".' .
1794
				gettext('You can manage gateways by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>');
1795

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

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

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

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

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

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

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

    
1823
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.' . '<br />' .
1824
				'On local LANs the upstream gateway should be "none". ');
1825

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1902
$section->addInput(new Form_Input(
1903
	'dhcphostname',
1904
	'Hostname',
1905
	'text',
1906
	$pconfig['dhcphostname']
1907
))->setHelp('The value in this field is sent as the DHCP client identifier and hostname when requesting a DHCP lease. Some ISPs may require this (for client identification).');
1908

    
1909
$section->addInput(new Form_IpAddress(
1910
	'alias-address',
1911
	'Alias IPv4 address',
1912
	$pconfig['alias-address']
1913
))->addMask('alias-subnet', $pconfig['alias-subnet'], 32)->setHelp('The value in this field is used as a fixed alias IPv4 address by the DHCP client.');
1914

    
1915
$section->addInput(new Form_Input(
1916
	'dhcprejectfrom',
1917
	'Reject leases from',
1918
	'text',
1919
	$pconfig['dhcprejectfrom']
1920
))->setHelp('If there is a certain upstream DHCP server that should be ignored, place the IP address or subnet of the DHCP server to be ignored here. ' .
1921
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1922

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2060
// DHCP6 client config
2061

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

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

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

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

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

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

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

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

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

    
2119
// DHCP6 client config - Advanced
2120

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2393
	return($list);
2394
}
2395

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

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

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

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

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

    
2423
/// PPP section
2424

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

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

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

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

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

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

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

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

    
2477

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

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

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

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

    
2493
	return($list);
2494
}
2495

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2731
	if (count($mode_list) == 1) {
2732
		$mode_list[''] = '';
2733
	}
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
	} else {
2750
		$section->addInput(new Form_Input(
2751
			'protmode',
2752
			null,
2753
			'hidden',
2754
			'off'
2755
		));
2756
	}
2757

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3122

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

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

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

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

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

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

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

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

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

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

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

    
3173
print($form);
3174
?>
3175

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3343
	function hide_add_gatewaysave_v6() {
3344

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

    
3365

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3539
	// ---------- On initial page load ------------------------------------------------------------
3540

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

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

    
3561
	// Set preset from value
3562
	setPresets(sv);
3563

    
3564
	// ---------- Click checkbox handlers ---------------------------------------------------------
3565

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

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

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

    
3578
	$("#add").click(function() {
3579
		hide_add_gatewaysave();
3580
	});
3581

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

    
3586
	$("#add6").click(function() {
3587
		hide_add_gatewaysave_v6();
3588
	});
3589

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

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

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

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

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

    
3610
	$('#dhcp6adv').click(function () {
3611
		show_dhcp6adv();
3612
	});
3613

    
3614
	$('#adv_dhcp6_config_file_override').click(function () {
3615
		show_dhcp6adv();
3616
	});
3617

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

    
3623
});
3624
//]]>
3625
</script>
3626

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