Project

General

Profile

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

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

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

    
81
define("ANTENNAS", false);
82

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
450
}
451

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

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

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

    
481
		clear_subsystem_dirty('interfaces');
482

    
483
		filter_configure();
484

    
485
		enable_rrd_graphing();
486

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

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

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

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

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

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

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

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

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

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

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

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

    
828
		unset($min_mtu, $max_mtu);
829

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1395
		conf_mount_ro();
1396
		write_config();
1397

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

    
1407
		mark_subsystem_dirty('interfaces');
1408

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

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

    
1416
} // end if ($_POST)
1417

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

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

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

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

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

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

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

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

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

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

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

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

    
1624
$closehead = false;
1625

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

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

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

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

    
1642
	return($list);
1643
}
1644

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

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

    
1655
	return($list);
1656
}
1657

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

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

    
1668
	return($list);
1669
}
1670

    
1671
include("head.inc");
1672

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

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

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

    
1683

    
1684
require_once('classes/Form.class.php');
1685
require_once('classes/Modal.class.php');
1686

    
1687
$form = new Form(new Form_Button(
1688
	'Submit',
1689
	gettext("Save")
1690
));
1691

    
1692
$section = new Form_Section('General configuration');
1693

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

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

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

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

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

    
1731
$btnmymac = new Form_Button(
1732
	'btnmymac',
1733
	'Copy My MAC'
1734
	);
1735

    
1736
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1737

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

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

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

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

    
1771
$form->add($section);
1772

    
1773
$section = new Form_Section('Static IPv4 configuration');
1774
$section->addClass('staticv4');
1775

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

    
1782
$group = new Form_Group('IPv4 Upstream gateway');
1783

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

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

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

    
1800
$section->add($group);
1801

    
1802
$form->add($section);
1803

    
1804
$section = new Form_Section('Static IPv6 configuration');
1805
$section->addClass('staticv6');
1806

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

    
1813
$group = new Form_Group('IPv6 Upstream gateway');
1814

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

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

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

    
1830
$section->add($group);
1831
$form->add($section);
1832

    
1833
// Add new gateway modal pop-up for IPv6
1834
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1835

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

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

    
1850
$modal->addInput(new Form_IpAddress(
1851
	'gatewayip6',
1852
	'Gateway IPv6',
1853
	null
1854
));
1855

    
1856
$modal->addInput(new Form_Input(
1857
	'gatewaydescr6',
1858
	'Description',
1859
	'text'
1860
));
1861

    
1862
$btnaddgw6 = new Form_Button(
1863
	'add6',
1864
	'Add'
1865
);
1866

    
1867
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1868

    
1869
$btncnxgw6 = new Form_Button(
1870
	'cnx6',
1871
	'Cancel'
1872
);
1873

    
1874
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1875

    
1876
$modal->addInput(new Form_StaticText(
1877
	null,
1878
	$btnaddgw6 . $btncnxgw6
1879
));
1880

    
1881
$form->add($modal);
1882

    
1883
// ==== DHCP client configuration =============================
1884

    
1885
$section = new Form_Section('DHCP client configuration');
1886
$section->addClass('dhcp');
1887

    
1888
$group = new Form_Group('Options');
1889

    
1890
$group->add(new Form_Checkbox(
1891
	'dhcpadv',
1892
	null,
1893
	'Show DHCP advanced options',
1894
	false
1895
));
1896

    
1897
$group->add(new Form_Checkbox(
1898
	'dhcpovr',
1899
	null,
1900
	'Config file override',
1901
	false
1902
));
1903

    
1904
$section->add($group);
1905

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

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

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

    
1927
$group = new Form_Group('Protocol timing');
1928
$group->addClass('dhcpadvanced');
1929

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

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

    
1944
$group->add(new Form_Input(
1945
	'adv_dhcp_pt_select_timeout',
1946
	null,
1947
	'number',
1948
	$pconfig['adv_dhcp_pt_select_timeout']
1949
))->setHelp('Select timeout');
1950

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

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

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

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

    
1974
$group = new Form_Group('Presets');
1975
$group->addClass('dhcpadvanced');
1976

    
1977
$group->add(new Form_Checkbox(
1978
	'adv_dhcp_pt_values',
1979
	null,
1980
	'FreeBSD default',
1981
	null,
1982
	'DHCP'
1983
))->displayAsRadio();
1984

    
1985
$group->add(new Form_Checkbox(
1986
	'adv_dhcp_pt_values',
1987
	null,
1988
	'Clear',
1989
	null,
1990
	'Clear'
1991
))->displayAsRadio();
1992

    
1993
$group->add(new Form_Checkbox(
1994
	'adv_dhcp_pt_values',
1995
	null,
1996
	'pfSense Default',
1997
	null,
1998
	'pfSense'
1999
))->displayAsRadio();
2000

    
2001
$group->add(new Form_Checkbox(
2002
	'adv_dhcp_pt_values',
2003
	null,
2004
	'Saved Cfg',
2005
	null,
2006
	'SavedCfg'
2007
))->displayAsRadio();
2008

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

    
2012
$section->add($group);
2013

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

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

    
2026
$section = new Form_Section('Lease Requirements and Requests');
2027
$section->addClass('dhcpadvanced');
2028

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

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

    
2047
$section->addInput(new Form_Input(
2048
	'adv_dhcp_require_options',
2049
	'Request options',
2050
	'text',
2051
	$pconfig['adv_dhcp_require_options']
2052
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2053

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

    
2062
$form->add($section);
2063

    
2064
// DHCP6 client config
2065

    
2066
$section = new Form_Section('DHCP6 client configuration');
2067
$section->addClass('dhcp6');
2068

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

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

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

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

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

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

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

    
2121
$form->add($section);
2122

    
2123
// DHCP6 client config - Advanced
2124

    
2125
$section = new Form_Section('Advanced DHCP6 client configuration');
2126
$section->addClass('dhcp6advanced');
2127

    
2128
$section->addInput(new Form_Checkbox(
2129
	'adv_dhcp6_interface_statement_information_only_enable',
2130
	'Information only',
2131
	null,
2132
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2133
));
2134

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

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

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

    
2161
$group = new Form_Group('Identity Association Statement');
2162

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

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

    
2177
$group->add(new Form_IpAddress(
2178
	'adv_dhcp6_id_assoc_statement_address',
2179
	null,
2180
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2181
))->sethelp('IPv6 address');
2182

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

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

    
2197
$section->add($group);
2198

    
2199
// Prefix delegation
2200
$group = new Form_Group('');
2201

    
2202
$group->add(new Form_Checkbox(
2203
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2204
	null,
2205
	'Prefix Delegation ',
2206
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2207
));
2208

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

    
2216
$group->add(new Form_IpAddress(
2217
	'adv_dhcp6_id_assoc_statement_prefix',
2218
	null,
2219
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2220
))->sethelp('IPv6 prefix');
2221

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

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

    
2236
$section->add($group);
2237

    
2238
$group = new Form_Group('Prefix interface statement');
2239

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

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

    
2254
$section->add($group);
2255

    
2256
$group = new Form_Group('Authentication statement');
2257

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

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

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

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

    
2286
$section->add($group);
2287

    
2288
$group = new Form_Group('Keyinfo statement');
2289

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

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

    
2304
$section->add($group);
2305

    
2306
$group = new Form_Group('');
2307

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

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

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

    
2329
$section->add($group);
2330

    
2331
$form->add($section);
2332

    
2333
$section = new Form_Section('6RD Configuration');
2334
$section->addClass('_6rd');
2335

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

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

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

    
2357
$form->add($section);
2358

    
2359
// Track IPv6 ointerface section
2360
$section = new Form_Section('Track IPv6 Interface');
2361
$section->addClass('track6');
2362

    
2363
function build_ipv6interface_list() {
2364
	global $config, $section;
2365

    
2366
	$list = array('' => '');
2367

    
2368
	$interfaces = get_configured_interface_with_descr(false, true);
2369
	$dynv6ifs = array();
2370

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

    
2386
	foreach ($dynv6ifs as $iface => $ifacedata) {
2387
		$list[$iface] = $ifacedata['name'];
2388

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

    
2397
	return($list);
2398
}
2399

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

    
2407
if ($pconfig['track6-prefix-id'] == "") {
2408
	$pconfig['track6-prefix-id'] = 0;
2409
}
2410

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

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

    
2425
$form->add($section);
2426

    
2427
/// PPP section
2428

    
2429
$section = new Form_Section('PPP Configuration');
2430
$section->addClass('ppp');
2431

    
2432
$section->addInput(new Form_Select(
2433
	'country',
2434
	'Country',
2435
	$pconfig['country'],
2436
	[]
2437
));
2438

    
2439
$section->addInput(new Form_Select(
2440
	'provider_list',
2441
	'Provider',
2442
	$pconfig['provider_list'],
2443
	[]
2444
));
2445

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

    
2453
$section->addInput(new Form_Input(
2454
	'ppp_username',
2455
	'Username',
2456
	'text',
2457
	$pconfig['ppp_username']
2458
));
2459

    
2460
$section->addInput(new Form_Input(
2461
	'ppp_password',
2462
	'Password',
2463
	'password',
2464
	$pconfig['ppp_password']
2465
));
2466

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

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

    
2481

    
2482
function build_port_list() {
2483
	$list = array("" => "None");
2484

    
2485
	$portlist = glob("/dev/cua*");
2486
	$modems	  = glob("/dev/modem*");
2487
	$portlist = array_merge($portlist, $modems);
2488

    
2489
	foreach ($portlist as $port) {
2490
		if (preg_match("/\.(lock|init)$/", $port)) {
2491
			continue;
2492
		}
2493

    
2494
	$list[trim($port)] = $port;
2495
	}
2496

    
2497
	return($list);
2498
}
2499

    
2500
$section->addInput(new Form_Select(
2501
	'port',
2502
	"Modem port",
2503
	$pconfig['port'],
2504
	build_port_list()
2505
));
2506

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

    
2513
$form->add($section);
2514

    
2515
// PPPoE configuration
2516
$section = new Form_Section('PPPoE Configuration');
2517
$section->addClass('pppoe');
2518

    
2519
$section->addInput(new Form_Input(
2520
	'pppoe_username',
2521
	'Username',
2522
	'text',
2523
	$pconfig['pppoe_username']
2524
));
2525

    
2526
$section->addInput(new Form_Input(
2527
	'pppoe_password',
2528
	'Password',
2529
	'password',
2530
	$pconfig['pppoe_password']
2531
));
2532

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

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

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

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

    
2564
$group = new Form_Group('Custom reset');
2565
$group->addClass('pppoecustom');
2566

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

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

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

    
2591
$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');
2592

    
2593
$section->add($group);
2594

    
2595
$group = new Form_MultiCheckboxGroup('cron based reset');
2596
$group->addClass('pppoepreset');
2597

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

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

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

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

    
2630
$section->add($group);
2631

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

    
2644
$form->add($section);
2645

    
2646
// PPTP & L2TP Configuration section
2647
$section = new Form_Section('PPTP/L2TP Configuration');
2648
$section->addClass('pptp');
2649

    
2650
$section->addInput(new Form_Input(
2651
	'pptp_username',
2652
	'Username',
2653
	'text',
2654
	$pconfig['pptp_username']
2655
));
2656

    
2657
$section->addInput(new Form_Input(
2658
	'pptp_password',
2659
	'Password',
2660
	'password',
2661
	$pconfig['pptp_password']
2662
));
2663

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

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

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

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

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

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

    
2712
$form->add($section);
2713

    
2714
// Wireless interface
2715
if (isset($wancfg['wireless'])) {
2716

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

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

    
2727
	$mode_list = ['auto' => 'Auto'];
2728

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

    
2735
	if (count($mode_list) == 1)
2736
		$mode_list[''] = '';
2737

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

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

    
2763
	$mode_list = ['0' => 'Auto'];
2764

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

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

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

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

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

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

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

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

    
2826
			$section->add($group);
2827
		}
2828
	}
2829

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

    
2839
	$form->add($section);
2840

    
2841
	// Regulatory settings
2842
	$section = new Form_Section('Regulatory settings');
2843

    
2844
	$domain_list = array("" => 'Default');
2845

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

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

    
2859
	$country_list = array('' => 'Default');
2860

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

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

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

    
2885
	$form->add($section);
2886

    
2887
	$section = new Form_Section('Network-specific wireless configuration');
2888

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

    
2896
	$section->addInput(new Form_Input(
2897
		'ssid',
2898
		'SSID',
2899
		'text',
2900
		$pconfig['ssid']
2901
	));
2902

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

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

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

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

    
2944
	$form->add($section);
2945

    
2946
	// WPA Section
2947
	$section = new Form_Section('WPA');
2948

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

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

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

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

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

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

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

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

    
3009
	$form->add($section);
3010

    
3011
	$section = new Form_Section('802.1x RADIUS options');
3012

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

    
3021
	$group = new Form_Group('Primary 802.1X server');
3022

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

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

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

    
3043
	$section->add($group);
3044

    
3045
	$group = new Form_Group('Secondary 802.1X server');
3046

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

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

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

    
3067
	$section->add($group);
3068

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

    
3077
	$form->add($section);
3078
}
3079

    
3080
$section = new Form_Section('Private networks');
3081

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

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

    
3102
$form->add($section);
3103

    
3104
$form->addGlobal(new Form_Input(
3105
	'if',
3106
	null,
3107
	'hidden',
3108
	$if
3109
));
3110

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

    
3120
$form->addGlobal(new Form_Input(
3121
	'ptpid',
3122
	null,
3123
	'hidden',
3124
	$pconfig['ptpid']
3125
));
3126

    
3127

    
3128
// Add new gateway modal pop-up
3129
$modal = new Modal('New gateway', 'newgateway', 'large');
3130

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

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

    
3145
$modal->addInput(new Form_IpAddress(
3146
	'gatewayip',
3147
	'Gateway IPv4',
3148
	null
3149
));
3150

    
3151
$modal->addInput(new Form_Input(
3152
	'gatewaydescr',
3153
	'Description',
3154
	'text'
3155
));
3156

    
3157
$btnaddgw = new Form_Button(
3158
	'add',
3159
	'Add'
3160
);
3161

    
3162
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3163

    
3164
$btncnxgw = new Form_Button(
3165
	'cnx',
3166
	'Cancel'
3167
);
3168

    
3169
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3170

    
3171
$modal->addInput(new Form_StaticText(
3172
	null,
3173
	$btnaddgw . $btncnxgw
3174
));
3175

    
3176
$form->add($modal);
3177

    
3178
print($form);
3179
?>
3180

    
3181
<script type="text/javascript">
3182
//<![CDATA[
3183
events.push(function(){
3184
	function updateType(t) {
3185

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

    
3220
		if (t != "l2tp" && t != "pptp") {
3221
			$('.'+t).show();
3222
		}
3223
	}
3224

    
3225
	function updateTypeSix(t) {
3226
		if (!isNaN(t[0]))
3227
			t = '_' + t;
3228

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

    
3261
		if (t != "l2tp" && t != "pptp") {
3262
			$('.'+t).show();
3263
		}
3264
	}
3265

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

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

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

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

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

    
3301
		var defaultgw = '';
3302
		if ($('#defaultgw').is(':checked')) {
3303
			defaultgw = '&defaultgw=on';
3304
		}
3305

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

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

    
3326
		$("#newgateway").modal('hide');
3327
	}
3328

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

    
3336
		$("#newgateway").modal('hide');
3337
	}
3338

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

    
3348
	function hide_add_gatewaysave_v6() {
3349

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

    
3370

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

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

    
3387
		$("#newgateway6").modal('hide');
3388
	}
3389

    
3390
	function save_callback_v6(response_v6) {
3391
		if (response_v6) {
3392

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

    
3399
		$("#newgateway6").modal('hide');
3400
	}
3401

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

    
3409
				var responseTextArr = response.split("\n");
3410
				responseTextArr.sort();
3411

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

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

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

    
3451
				$('#providerplan').append($('<option>', {
3452
					value: '',
3453
					text : ''
3454
				}));
3455

    
3456
				responseTextArr.forEach( function(value) {
3457
					if (value != "") {
3458
						providerplan = value.split(":");
3459

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

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

    
3494
	function show_dhcp6adv() {
3495
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3496
		var adv = $('#dhcp6adv').prop('checked');
3497

    
3498
		hideCheckbox('dhcp6usev4iface', ovr);
3499
		hideCheckbox('dhcp6prefixonly', ovr);
3500
		hideInput('dhcp6-ia-pd-len', ovr);
3501
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3502
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3503

    
3504
		hideClass('dhcp6advanced', !adv || ovr);
3505
	}
3506

    
3507
	function setDHCPoptions() {
3508
		var adv = $('#dhcpadv').prop('checked');
3509
		var ovr = $('#dhcpovr').prop('checked');
3510

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

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

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

    
3545
	// ---------- On initial page load ------------------------------------------------------------
3546

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

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

    
3566
	// Set preset from value
3567
	setPresets(sv);
3568
	
3569
	// ---------- Click checkbox handlers ---------------------------------------------------------
3570

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

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

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

    
3583
	$("#add").click(function() {
3584
		hide_add_gatewaysave();
3585
	});
3586

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

    
3591
	$("#add6").click(function() {
3592
		hide_add_gatewaysave_v6();
3593
	});
3594

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

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

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

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

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

    
3615
	$('#dhcp6adv').click(function () {
3616
		show_dhcp6adv();
3617
	});
3618

    
3619
	$('#adv_dhcp6_config_file_override').click(function () {
3620
		show_dhcp6adv();
3621
	});
3622

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

    
3628
});
3629
//]]>
3630
</script>
3631

    
3632
<?php include("foot.inc");
(82-82/230)