Project

General

Profile

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

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

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

    
77
define("ANTENNAS", false);
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
446
}
447

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

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

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

    
477
		clear_subsystem_dirty('interfaces');
478

    
479
		filter_configure();
480

    
481
		enable_rrd_graphing();
482

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

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

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

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

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

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

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

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

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

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

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

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

    
824
		unset($min_mtu, $max_mtu);
825

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

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

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

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

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

    
944
		if ($_POST['wpa_enable'] == "yes") {
945
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
946
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
947
			}
948
		}
949
	}
950

    
951
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
952
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
953
	}
954

    
955
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
956
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
957
	}
958

    
959
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
960
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
961
	}
962

    
963
	if (!$input_errors) {
964
		// These 3 fields can be a list of multiple data items when used for MLPPP.
965
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
966
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
967
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
968
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
969

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

    
1008
		unset($wancfg['adv_dhcp_pt_timeout']);
1009
		unset($wancfg['adv_dhcp_pt_retry']);
1010
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1011
		unset($wancfg['adv_dhcp_pt_reboot']);
1012
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1013
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1014

    
1015
		unset($wancfg['adv_dhcp_pt_values']);
1016

    
1017
		unset($wancfg['adv_dhcp_send_options']);
1018
		unset($wancfg['adv_dhcp_request_options']);
1019
		unset($wancfg['adv_dhcp_required_options']);
1020
		unset($wancfg['adv_dhcp_option_modifiers']);
1021

    
1022
		unset($wancfg['adv_dhcp_config_advanced']);
1023
		unset($wancfg['adv_dhcp_config_file_override']);
1024
		unset($wancfg['adv_dhcp_config_file_override_path']);
1025

    
1026
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1027
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1028
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1029
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1030

    
1031
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1032
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1033
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1034
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1035
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1036

    
1037
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1038
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1039
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1040
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1041
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1042

    
1043
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1044
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1045

    
1046
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1047
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1048
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1049
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1050

    
1051
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1052
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1053
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1054
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1055
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1056

    
1057
		unset($wancfg['adv_dhcp6_config_advanced']);
1058
		unset($wancfg['adv_dhcp6_config_file_override']);
1059
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1060

    
1061
		unset($wancfg['pppoe_password']);
1062
		unset($wancfg['pptp_username']);
1063
		unset($wancfg['pptp_password']);
1064
		unset($wancfg['provider']);
1065
		unset($wancfg['ondemand']);
1066
		unset($wancfg['timeout']);
1067
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1068
			unset($wancfg['pppoe']['pppoe-reset-type']);
1069
		}
1070
		unset($wancfg['local']);
1071

    
1072
		unset($wancfg['remote']);
1073
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1074
			if ($wancfg['ipaddr'] != 'ppp') {
1075
				unset($a_ppps[$pppid]['apn']);
1076
				unset($a_ppps[$pppid]['phone']);
1077
				unset($a_ppps[$pppid]['provider']);
1078
				unset($a_ppps[$pppid]['ondemand']);
1079
			}
1080
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1081
				unset($a_ppps[$pppid]['localip']);
1082
				unset($a_ppps[$pppid]['subnet']);
1083
				unset($a_ppps[$pppid]['gateway']);
1084
			}
1085
			if ($wancfg['ipaddr'] != 'pppoe') {
1086
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1087
			}
1088
			if ($wancfg['type'] != $_POST['type']) {
1089
				unset($a_ppps[$pppid]['idletimeout']);
1090
			}
1091
		}
1092

    
1093
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1094
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1095

    
1096
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1097
		switch ($_POST['type']) {
1098
			case "staticv4":
1099
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1100
				$wancfg['subnet'] = $_POST['subnet'];
1101
				if ($_POST['gateway'] != "none") {
1102
					$wancfg['gateway'] = $_POST['gateway'];
1103
				}
1104
				break;
1105
			case "dhcp":
1106
				$wancfg['ipaddr'] = "dhcp";
1107
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1108
				$wancfg['alias-address'] = $_POST['alias-address'];
1109
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1110
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1111

    
1112
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1113
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1114
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1115
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1116
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1117
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1118

    
1119
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1120

    
1121
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1122
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1123
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1124
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1125

    
1126
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1127
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1128
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1129

    
1130
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1131
				if ($gateway_item) {
1132
					$a_gateways[] = $gateway_item;
1133
				}
1134
				break;
1135
			case "ppp":
1136
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1137
				$a_ppps[$pppid]['type'] = $_POST['type'];
1138
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1139
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1140
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1141
				if ($_POST['ppp_password'] != DMYPWD) {
1142
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1143
				}
1144
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1145
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1146
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1147
				$wancfg['ipaddr'] = $_POST['type'];
1148
				break;
1149

    
1150
			case "pppoe":
1151
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1152
				$a_ppps[$pppid]['type'] = $_POST['type'];
1153
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1154
				if (isset($_POST['ppp_port'])) {
1155
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1156
				} else {
1157
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1158
				}
1159
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1160
				if ($_POST['pppoe_password'] != DMYPWD) {
1161
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1162
				}
1163
				if (!empty($_POST['provider'])) {
1164
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1165
				} else {
1166
					$a_ppps[$pppid]['provider'] = true;
1167
				}
1168
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1169
				if (!empty($_POST['pppoe_idletimeout'])) {
1170
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1171
				} else {
1172
					unset($a_ppps[$pppid]['idletimeout']);
1173
				}
1174

    
1175
				if (!empty($_POST['pppoe-reset-type'])) {
1176
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1177
				} else {
1178
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1179
				}
1180
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1181
				$wancfg['ipaddr'] = $_POST['type'];
1182
				if ($gateway_item) {
1183
					$a_gateways[] = $gateway_item;
1184
				}
1185

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

    
1248
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1249
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1250
				}
1251
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1252
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1253
				}
1254
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1255
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1256
				}
1257
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1258
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1259
				}
1260

    
1261
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1262
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1263
				}
1264
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1265
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1266
				}
1267
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1268
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1269
				}
1270
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1271
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1272
				}
1273
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1274
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1275
				}
1276

    
1277
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1278
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1279
				}
1280
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1281
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1282
				}
1283
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1284
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1285
				}
1286
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1287
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1288
				}
1289
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1290
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1291
				}
1292

    
1293
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1294
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1295
				}
1296
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1297
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1298
				}
1299

    
1300
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1301
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1304
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1307
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1310
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1311
				}
1312

    
1313
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1314
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1317
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1320
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1323
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1326
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1327
				}
1328

    
1329
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1330
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1333
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1334
				}
1335
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1336
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1337
				}
1338

    
1339
				if ($gateway_item) {
1340
					$a_gateways[] = $gateway_item;
1341
				}
1342
				break;
1343
			case "6rd":
1344
				$wancfg['ipaddrv6'] = "6rd";
1345
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1346
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1347
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1348
				if ($gateway_item) {
1349
					$a_gateways[] = $gateway_item;
1350
				}
1351
				break;
1352
			case "6to4":
1353
				$wancfg['ipaddrv6'] = "6to4";
1354
				break;
1355
			case "track6":
1356
				$wancfg['ipaddrv6'] = "track6";
1357
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1358
				if ($_POST['track6-prefix-id--hex'] === "") {
1359
					$wancfg['track6-prefix-id'] = 0;
1360
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1361
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1362
				} else {
1363
					$wancfg['track6-prefix-id'] = 0;
1364
				}
1365
				break;
1366
			case "none":
1367
				break;
1368
		}
1369
		handle_pppoe_reset($_POST);
1370

    
1371
		if ($_POST['blockpriv'] == "yes") {
1372
			$wancfg['blockpriv'] = true;
1373
		} else {
1374
			unset($wancfg['blockpriv']);
1375
		}
1376
		if ($_POST['blockbogons'] == "yes") {
1377
			$wancfg['blockbogons'] = true;
1378
		} else {
1379
			unset($wancfg['blockbogons']);
1380
		}
1381
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1382
		if (empty($_POST['mtu'])) {
1383
			unset($wancfg['mtu']);
1384
		} else {
1385
			$wancfg['mtu'] = $_POST['mtu'];
1386
		}
1387
		if (empty($_POST['mss'])) {
1388
			unset($wancfg['mss']);
1389
		} else {
1390
			$wancfg['mss'] = $_POST['mss'];
1391
		}
1392
		if (empty($_POST['mediaopt'])) {
1393
			unset($wancfg['media']);
1394
			unset($wancfg['mediaopt']);
1395
		} else {
1396
			$mediaopts = explode(' ', $_POST['mediaopt']);
1397
			if ($mediaopts[0] != '') {
1398
				$wancfg['media'] = $mediaopts[0];
1399
			}
1400
			if ($mediaopts[1] != '') {
1401
				$wancfg['mediaopt'] = $mediaopts[1];
1402
			} else {
1403
				unset($wancfg['mediaopt']);
1404
			}
1405
		}
1406
		if (isset($wancfg['wireless'])) {
1407
			handle_wireless_post();
1408
		}
1409

    
1410
		conf_mount_ro();
1411
		write_config();
1412

    
1413
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1414
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1415
		} else {
1416
			$toapplylist = array();
1417
		}
1418
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1419
		$toapplylist[$if]['ppps'] = $old_ppps;
1420
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1421

    
1422
		mark_subsystem_dirty('interfaces');
1423

    
1424
		/* regenerate cron settings/crontab file */
1425
		configure_cron();
1426

    
1427
		header("Location: interfaces.php?if={$if}");
1428
		exit;
1429
	}
1430

    
1431
} // end if ($_POST)
1432

    
1433
function handle_wireless_post() {
1434
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1435
	if (!is_array($wancfg['wireless'])) {
1436
		$wancfg['wireless'] = array();
1437
	}
1438
	$wancfg['wireless']['standard'] = $_POST['standard'];
1439
	$wancfg['wireless']['mode'] = $_POST['mode'];
1440
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1441
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1442
	$wancfg['wireless']['channel'] = $_POST['channel'];
1443
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1444
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1445
	$wancfg['wireless']['distance'] = $_POST['distance'];
1446
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1447
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1448
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1449
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1450
		foreach ($wl_countries_attr as $wl_country) {
1451
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1452
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1453
				break;
1454
			}
1455
		}
1456
	}
1457
	if (!is_array($wancfg['wireless']['wpa'])) {
1458
		$wancfg['wireless']['wpa'] = array();
1459
	}
1460
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1461
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1462
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1463
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1464
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1465
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1466
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1467
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1468
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1469
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1470
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1471
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1472
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1473
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1474

    
1475
	if ($_POST['persistcommonwireless'] == "yes") {
1476
		if (!is_array($config['wireless'])) {
1477
			$config['wireless'] = array();
1478
		}
1479
		if (!is_array($config['wireless']['interfaces'])) {
1480
			$config['wireless']['interfaces'] = array();
1481
		}
1482
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1483
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1484
		}
1485
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1486
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1487
	}
1488
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1489
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1490
	} else if (isset($wancfg['wireless']['diversity'])) {
1491
		unset($wancfg['wireless']['diversity']);
1492
	}
1493
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1494
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1495
	} else if (isset($wancfg['wireless']['txantenna'])) {
1496
		unset($wancfg['wireless']['txantenna']);
1497
	}
1498
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1499
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1500
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1501
		unset($wancfg['wireless']['rxantenna']);
1502
	}
1503
	if ($_POST['hidessid_enable'] == "yes") {
1504
		$wancfg['wireless']['hidessid']['enable'] = true;
1505
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1506
		unset($wancfg['wireless']['hidessid']['enable']);
1507
	}
1508
	if ($_POST['mac_acl_enable'] == "yes") {
1509
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1510
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1511
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1512
	}
1513
	if ($_POST['rsn_preauth'] == "yes") {
1514
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1515
	} else {
1516
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1517
	}
1518
	if ($_POST['ieee8021x'] == "yes") {
1519
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1520
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1521
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1522
	}
1523
	if ($_POST['wpa_strict_rekey'] == "yes") {
1524
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1525
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1526
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1527
	}
1528
	if ($_POST['debug_mode'] == "yes") {
1529
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1530
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1531
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1532
	}
1533
	if ($_POST['wpa_enable'] == "yes") {
1534
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1535
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1536
		unset($wancfg['wireless']['wpa']['enable']);
1537
	}
1538

    
1539
	if ($_POST['wme_enable'] == "yes") {
1540
		if (!is_array($wancfg['wireless']['wme'])) {
1541
			$wancfg['wireless']['wme'] = array();
1542
		}
1543
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1544
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1545
		unset($wancfg['wireless']['wme']['enable']);
1546
	}
1547
	if ($_POST['puremode'] == "11g") {
1548
		if (!is_array($wancfg['wireless']['pureg'])) {
1549
			$wancfg['wireless']['pureg'] = array();
1550
		}
1551
		$wancfg['wireless']['pureg']['enable'] = true;
1552
	} else if ($_POST['puremode'] == "11n") {
1553
		if (!is_array($wancfg['wireless']['puren'])) {
1554
			$wancfg['wireless']['puren'] = array();
1555
		}
1556
		$wancfg['wireless']['puren']['enable'] = true;
1557
	} else {
1558
		if (isset($wancfg['wireless']['pureg'])) {
1559
			unset($wancfg['wireless']['pureg']);
1560
		}
1561
		if (isset($wancfg['wireless']['puren'])) {
1562
			unset($wancfg['wireless']['puren']);
1563
		}
1564
	}
1565
	if ($_POST['apbridge_enable'] == "yes") {
1566
		if (!is_array($wancfg['wireless']['apbridge'])) {
1567
			$wancfg['wireless']['apbridge'] = array();
1568
		}
1569
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1570
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1571
		unset($wancfg['wireless']['apbridge']['enable']);
1572
	}
1573
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1574
		if (!is_array($wancfg['wireless']['turbo'])) {
1575
			$wancfg['wireless']['turbo'] = array();
1576
		}
1577
		$wancfg['wireless']['turbo']['enable'] = true;
1578
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1579
		unset($wancfg['wireless']['turbo']['enable']);
1580
	}
1581

    
1582
	interface_sync_wireless_clones($wancfg, true);
1583
}
1584

    
1585
function check_wireless_mode() {
1586
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1587

    
1588
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1589
		return;
1590
	}
1591

    
1592
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1593
		$clone_count = 1;
1594
	} else {
1595
		$clone_count = 0;
1596
	}
1597

    
1598
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1599
		foreach ($config['wireless']['clone'] as $clone) {
1600
			if ($clone['if'] == $wlanbaseif) {
1601
				$clone_count++;
1602
			}
1603
		}
1604
	}
1605

    
1606
	if ($clone_count > 1) {
1607
		$old_wireless_mode = $wancfg['wireless']['mode'];
1608
		$wancfg['wireless']['mode'] = $_POST['mode'];
1609
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1610
			$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']]);
1611
		} else {
1612
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1613
		}
1614
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1615
	}
1616
}
1617

    
1618
// Find all possible media options for the interface
1619
$mediaopts_list = array();
1620
$intrealname = $config['interfaces'][$if]['if'];
1621
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1622
foreach ($mediaopts as $mediaopt) {
1623
	preg_match("/media (.*)/", $mediaopt, $matches);
1624
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1625
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1626
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1627
	} else {
1628
		// there is only media like "media 1000baseT"
1629
		array_push($mediaopts_list, $matches[1]);
1630
	}
1631
}
1632

    
1633
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1634
$shortcut_section = "interfaces";
1635

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

    
1639
// Get the MAC address
1640
$ip = $_SERVER['REMOTE_ADDR'];
1641
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1642
$mymac = str_replace("\n", "", $mymac);
1643

    
1644
function build_mediaopts_list() {
1645
	global $mediaopts_list;
1646

    
1647
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1648
			 " " =>	 "------- Media Supported by this interface -------"
1649
			];
1650

    
1651
	foreach ($mediaopts_list as $mediaopt) {
1652
		$list[$mediaopt] = $mediaopt;
1653
	}
1654

    
1655
	return($list);
1656
}
1657

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

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

    
1668
	return($list);
1669
}
1670

    
1671
function build_gatewayv6_list() {
1672
	global $a_gateways, $if;
1673

    
1674
	$list = array("none" => "None");
1675
	foreach ($a_gateways as $gateway) {
1676
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1677
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1678
		}
1679
	}
1680

    
1681
	return($list);
1682
}
1683

    
1684
include("head.inc");
1685

    
1686
if ($input_errors) {
1687
	print_input_errors($input_errors);
1688
}
1689

    
1690
if (is_subsystem_dirty('interfaces')) {
1691
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1692
					  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."));
1693
}
1694

    
1695
if ($savemsg) {
1696
	print_info_box($savemsg, 'success');
1697
}
1698

    
1699

    
1700
$form = new Form(new Form_Button(
1701
	'Submit',
1702
	gettext("Save")
1703
));
1704

    
1705
$section = new Form_Section('General configuration');
1706

    
1707
$section->addInput(new Form_Checkbox(
1708
	'enable',
1709
	'Enable',
1710
	'Enable interface',
1711
	$pconfig['enable'],
1712
	'yes'
1713
));
1714

    
1715
$section->addInput(new Form_Input(
1716
	'descr',
1717
	'Description',
1718
	'text',
1719
	$pconfig['descr']
1720
))->setHelp('Enter a description (name) for the interface here.');
1721

    
1722
$section->addInput(new Form_Select(
1723
	'type',
1724
	'IPv4 Configuration Type',
1725
	$pconfig['type'],
1726
	$types4
1727
));
1728

    
1729
$section->addInput(new Form_Select(
1730
	'type6',
1731
	'IPv6 Configuration Type',
1732
	$pconfig['type6'],
1733
	$types6
1734
));
1735

    
1736
$macaddress = new Form_Input(
1737
	'spoofmac',
1738
	'MAC Address',
1739
	'text',
1740
	$pconfig['spoofmac'],
1741
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1742
);
1743

    
1744
$btnmymac = new Form_Button(
1745
	'btnmymac',
1746
	'Copy My MAC'
1747
	);
1748

    
1749
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1750

    
1751
$group = new Form_Group('MAC controls');
1752
$group->add($macaddress);
1753
// $group->add($btnmymac);
1754
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1755
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1756
$section->add($group);
1757

    
1758
$section->addInput(new Form_Input(
1759
	'mtu',
1760
	'MTU',
1761
	'number',
1762
	$pconfig['mtu']
1763
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1764
			'This is typically 1500 bytes but can vary in some circumstances.');
1765

    
1766
$section->addInput(new Form_Input(
1767
	'mss',
1768
	'MSS',
1769
	'number',
1770
	$pconfig['mss']
1771
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1772
			'header size) will be in effect.');
1773

    
1774
if (count($mediaopts_list) > 0) {
1775
	$section->addInput(new Form_Select(
1776
		'mediaopt',
1777
		'Speed and Duplex',
1778
		rtrim($mediaopt_from_config),
1779
		build_mediaopts_list()
1780
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1781
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1782
}
1783

    
1784
$form->add($section);
1785

    
1786
$section = new Form_Section('Static IPv4 configuration');
1787
$section->addClass('staticv4');
1788

    
1789
$section->addInput(new Form_IpAddress(
1790
	'ipaddr',
1791
	'IPv4 Address',
1792
	$pconfig['ipaddr']
1793
))->addMask('subnet', $pconfig['subnet'], 32);
1794

    
1795
$group = new Form_Group('IPv4 Upstream gateway');
1796

    
1797
$group->add(new Form_Select(
1798
	'gateway',
1799
	'IPv4 Upstream Gateway',
1800
	$pconfig['gateway'],
1801
	build_gateway_list()
1802
));
1803

    
1804
$group->add(new Form_Button(
1805
	'addgw',
1806
	'Add a new gateway'
1807
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1808

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

    
1813
$section->add($group);
1814

    
1815
$form->add($section);
1816

    
1817
$section = new Form_Section('Static IPv6 configuration');
1818
$section->addClass('staticv6');
1819

    
1820
$section->addInput(new Form_IpAddress(
1821
	'ipaddrv6',
1822
	'IPv6 address',
1823
	$pconfig['ipaddrv6']
1824
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1825

    
1826
$group = new Form_Group('IPv6 Upstream gateway');
1827

    
1828
$group->add(new Form_Select(
1829
	'gatewayv6',
1830
	'IPv6 Upstream Gateway',
1831
	$pconfig['gatewayv6'],
1832
	build_gatewayv6_list()
1833
));
1834

    
1835
$group->add(new Form_Button(
1836
	'addgw6',
1837
	'Add a new gateway'
1838
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1839

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

    
1843
$section->add($group);
1844
$form->add($section);
1845

    
1846
// Add new gateway modal pop-up for IPv6
1847
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1848

    
1849
$modal->addInput(new Form_Checkbox(
1850
	'defaultgw6',
1851
	'Default',
1852
	'Default gateway',
1853
	($if == "wan" || $if == "WAN")
1854
));
1855

    
1856
$modal->addInput(new Form_Input(
1857
	'name6',
1858
	'Gateway name',
1859
	'text',
1860
	$wancfg['descr'] . "GWv6"
1861
));
1862

    
1863
$modal->addInput(new Form_IpAddress(
1864
	'gatewayip6',
1865
	'Gateway IPv6',
1866
	null
1867
));
1868

    
1869
$modal->addInput(new Form_Input(
1870
	'gatewaydescr6',
1871
	'Description',
1872
	'text'
1873
));
1874

    
1875
$btnaddgw6 = new Form_Button(
1876
	'add6',
1877
	'Add'
1878
);
1879

    
1880
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1881

    
1882
$btncnxgw6 = new Form_Button(
1883
	'cnx6',
1884
	'Cancel'
1885
);
1886

    
1887
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1888

    
1889
$modal->addInput(new Form_StaticText(
1890
	null,
1891
	$btnaddgw6 . $btncnxgw6
1892
));
1893

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

    
1896
// ==== DHCP client configuration =============================
1897

    
1898
$section = new Form_Section('DHCP client configuration');
1899
$section->addClass('dhcp');
1900

    
1901
$group = new Form_Group('Options');
1902

    
1903
$group->add(new Form_Checkbox(
1904
	'dhcpadv',
1905
	null,
1906
	'Show DHCP advanced options',
1907
	false
1908
));
1909

    
1910
$group->add(new Form_Checkbox(
1911
	'dhcpovr',
1912
	null,
1913
	'Config file override',
1914
	false
1915
));
1916

    
1917
$section->add($group);
1918

    
1919
$section->addInput(new Form_Input(
1920
	'dhcphostname',
1921
	'Hostname',
1922
	'text',
1923
	$pconfig['dhcphostname']
1924
))->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).');
1925

    
1926
$section->addInput(new Form_IpAddress(
1927
	'alias-address',
1928
	'Alias IPv4 address',
1929
	$pconfig['alias-address']
1930
))->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.');
1931

    
1932
$section->addInput(new Form_Input(
1933
	'dhcprejectfrom',
1934
	'Reject leases from',
1935
	'text',
1936
	$pconfig['dhcprejectfrom']
1937
))->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. ' .
1938
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1939

    
1940
$group = new Form_Group('Protocol timing');
1941
$group->addClass('dhcpadvanced');
1942

    
1943
$group->add(new Form_Input(
1944
	'adv_dhcp_pt_timeout',
1945
	null,
1946
	'number',
1947
	$pconfig['adv_dhcp_pt_timeout']
1948
))->setHelp('Timeout');
1949

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

    
1957
$group->add(new Form_Input(
1958
	'adv_dhcp_pt_select_timeout',
1959
	null,
1960
	'number',
1961
	$pconfig['adv_dhcp_pt_select_timeout'],
1962
	['min' => 0]
1963
))->setHelp('Select timeout');
1964

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

    
1972
$group->add(new Form_Input(
1973
	'adv_dhcp_pt_backoff_cutoff',
1974
	null,
1975
	'number',
1976
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1977
))->setHelp('Backoff cutoff');
1978

    
1979
$group->add(new Form_Input(
1980
	'adv_dhcp_pt_initial_interval',
1981
	null,
1982
	'number',
1983
	$pconfig['adv_dhcp_pt_initial_interval']
1984
))->setHelp('Initial interval');
1985

    
1986
$section->add($group);
1987

    
1988
$group = new Form_Group('Presets');
1989
$group->addClass('dhcpadvanced');
1990

    
1991
$group->add(new Form_Checkbox(
1992
	'adv_dhcp_pt_values',
1993
	null,
1994
	'FreeBSD default',
1995
	null,
1996
	'DHCP'
1997
))->displayAsRadio();
1998

    
1999
$group->add(new Form_Checkbox(
2000
	'adv_dhcp_pt_values',
2001
	null,
2002
	'Clear',
2003
	null,
2004
	'Clear'
2005
))->displayAsRadio();
2006

    
2007
$group->add(new Form_Checkbox(
2008
	'adv_dhcp_pt_values',
2009
	null,
2010
	'pfSense Default',
2011
	null,
2012
	'pfSense'
2013
))->displayAsRadio();
2014

    
2015
$group->add(new Form_Checkbox(
2016
	'adv_dhcp_pt_values',
2017
	null,
2018
	'Saved Cfg',
2019
	null,
2020
	'SavedCfg'
2021
))->displayAsRadio();
2022

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

    
2026
$section->add($group);
2027

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

    
2038
$form->add($section);
2039

    
2040
$section = new Form_Section('Lease Requirements and Requests');
2041
$section->addClass('dhcpadvanced');
2042

    
2043
$section->addInput(new Form_Input(
2044
	'adv_dhcp_send_options',
2045
	'Send options',
2046
	'text',
2047
	$pconfig['adv_dhcp_send_options']
2048
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2049
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2050
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2051
			'Some ISPs may require certain options be or not be sent.');
2052

    
2053
$section->addInput(new Form_Input(
2054
	'adv_dhcp_request_options',
2055
	'Request options',
2056
	'text',
2057
	$pconfig['adv_dhcp_request_options']
2058
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2059
			'Some ISPs may require certain options be or not be requested.');
2060

    
2061
$section->addInput(new Form_Input(
2062
	'adv_dhcp_required_options',
2063
	'Require options',
2064
	'text',
2065
	$pconfig['adv_dhcp_required_options']
2066
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2067

    
2068
$section->addInput(new Form_Input(
2069
	'adv_dhcp_option_modifiers',
2070
	'Option modifiers',
2071
	'text',
2072
	$pconfig['adv_dhcp_option_modifiers']
2073
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2074
			'modifiers: (default, supersede, prepend, append)');
2075

    
2076
$form->add($section);
2077

    
2078
// DHCP6 client config
2079

    
2080
$section = new Form_Section('DHCP6 client configuration');
2081
$section->addClass('dhcp6');
2082

    
2083
$section->addInput(new Form_Checkbox(
2084
	'adv_dhcp6_config_advanced',
2085
	'Advanced',
2086
	'Show DHCPv6 advanced options',
2087
	$pconfig['adv_dhcp6_config_advanced'],
2088
	'Selected'
2089
));
2090

    
2091
$section->addInput(new Form_Checkbox(
2092
	'adv_dhcp6_config_file_override',
2093
	'Config file override',
2094
	'Override the configuration from this file',
2095
	$pconfig['adv_dhcp6_config_file_override'],
2096
	'Selected'
2097
));
2098

    
2099
$section->addInput(new Form_Checkbox(
2100
	'dhcp6usev4iface',
2101
	'Use IPv4 connectivity as parent interface',
2102
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2103
	$pconfig['dhcp6usev4iface']
2104
));
2105

    
2106
$section->addInput(new Form_Checkbox(
2107
	'dhcp6prefixonly',
2108
	'Request only an IPv6 prefix',
2109
	'Only request an IPv6 prefix, do not request an IPv6 address',
2110
	$pconfig['dhcp6prefixonly']
2111
));
2112

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

    
2120
$section->addInput(new Form_Checkbox(
2121
	'dhcp6-ia-pd-send-hint',
2122
	'Send IPv6 prefix hint',
2123
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2124
	$pconfig['dhcp6-ia-pd-send-hint']
2125
));
2126

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

    
2137
$form->add($section);
2138

    
2139
// DHCP6 client config - Advanced
2140

    
2141
$section = new Form_Section('Advanced DHCP6 client configuration');
2142
$section->addClass('dhcp6advanced');
2143

    
2144
$section->addInput(new Form_Checkbox(
2145
	'adv_dhcp6_interface_statement_information_only_enable',
2146
	'Information only',
2147
	null,
2148
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2149
	'Selected'
2150
));
2151

    
2152
$section->addInput(new Form_Input(
2153
	'adv_dhcp6_interface_statement_send_options',
2154
	'Send options',
2155
	'text',
2156
	$pconfig['adv_dhcp6_interface_statement_send_options']
2157
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2158
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2159
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2160
			'Some DHCP services may require certain options be or not be sent.');
2161

    
2162
$section->addInput(new Form_Input(
2163
	'adv_dhcp6_interface_statement_request_options',
2164
	'Request Options',
2165
	'text',
2166
	$pconfig['adv_dhcp6_interface_statement_request_options']
2167
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2168
			'Some DHCP services may require certain options be or not be requested.');
2169

    
2170
$section->addInput(new Form_Input(
2171
	'adv_dhcp6_interface_statement_script',
2172
	'Scripts',
2173
	'text',
2174
	$pconfig['adv_dhcp6_interface_statement_script']
2175
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2176
			'[/[dirname/[.../]]filename[.ext]].');
2177

    
2178
$group = new Form_Group('Identity Association Statement');
2179

    
2180
$group->add(new Form_Checkbox(
2181
	'adv_dhcp6_id_assoc_statement_address_enable',
2182
	null,
2183
	'Non-Temporary Address Allocation',
2184
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2185
	'Selected'
2186
));
2187

    
2188
$group->add(new Form_Input(
2189
	'adv_dhcp6_id_assoc_statement_address_id',
2190
	null,
2191
	'text',
2192
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2193
))->sethelp('id-assoc na ID');
2194

    
2195
$group->add(new Form_IpAddress(
2196
	'adv_dhcp6_id_assoc_statement_address',
2197
	null,
2198
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2199
))->sethelp('IPv6 address');
2200

    
2201
$group->add(new Form_Input(
2202
	'adv_dhcp6_id_assoc_statement_address_pltime',
2203
	null,
2204
	'text',
2205
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2206
))->sethelp('pltime');
2207

    
2208
$group->add(new Form_Input(
2209
	'adv_dhcp6_id_assoc_statement_address_vltime',
2210
	null,
2211
	'text',
2212
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2213
))->sethelp('vltime');
2214

    
2215
$section->add($group);
2216

    
2217
// Prefix delegation
2218
$group = new Form_Group('');
2219

    
2220
$group->add(new Form_Checkbox(
2221
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2222
	null,
2223
	'Prefix Delegation ',
2224
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2225
	'Selected'
2226
));
2227

    
2228
$group->add(new Form_Input(
2229
	'adv_dhcp6_id_assoc_statement_prefix_id',
2230
	null,
2231
	'text',
2232
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2233
))->sethelp('id-assoc pd ID');
2234

    
2235
$group->add(new Form_IpAddress(
2236
	'adv_dhcp6_id_assoc_statement_prefix',
2237
	null,
2238
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2239
))->sethelp('IPv6 prefix');
2240

    
2241
$group->add(new Form_Input(
2242
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2243
	null,
2244
	'text',
2245
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2246
))->sethelp('pltime');
2247

    
2248
$group->add(new Form_Input(
2249
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2250
	null,
2251
	'text',
2252
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2253
))->sethelp('vltime');
2254

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

    
2257
$group = new Form_Group('Prefix interface statement');
2258

    
2259
$group->add(new Form_Input(
2260
	'adv_dhcp6_prefix_interface_statement_sla_id',
2261
	null,
2262
	'text',
2263
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2264
))->sethelp('Prefix Interface sla-id');
2265

    
2266
$group->add(new Form_Input(
2267
	'adv_dhcp6_prefix_interface_statement_sla_len',
2268
	null,
2269
	'text',
2270
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2271
))->sethelp('sla-len');
2272

    
2273
$section->add($group);
2274

    
2275
$group = new Form_Group('Authentication statement');
2276

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

    
2284
$group->add(new Form_Input(
2285
	'adv_dhcp6_authentication_statement_protocol',
2286
	null,
2287
	'text',
2288
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2289
))->sethelp('Protocol');
2290

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

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

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

    
2307
$group = new Form_Group('Keyinfo statement');
2308

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

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

    
2323
$section->add($group);
2324

    
2325
$group = new Form_Group('');
2326

    
2327
$group->add(new Form_Input(
2328
	'adv_dhcp6_key_info_statement_keyid',
2329
	null,
2330
	'text',
2331
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2332
))->sethelp('KeyID');
2333

    
2334
$group->add(new Form_Input(
2335
	'adv_dhcp6_key_info_statement_secret',
2336
	null,
2337
	'text',
2338
	$pconfig['adv_dhcp6_key_info_statement_secret']
2339
))->sethelp('Secret');
2340

    
2341
$group->add(new Form_Input(
2342
	'adv_dhcp6_key_info_statement_expire',
2343
	null,
2344
	'text',
2345
	$pconfig['adv_dhcp6_key_info_statement_expire']
2346
))->sethelp('Expire');
2347

    
2348
$section->add($group);
2349

    
2350
$form->add($section);
2351

    
2352
$section = new Form_Section('6RD Configuration');
2353
$section->addClass('_6rd');
2354

    
2355
$section->addInput(new Form_Input(
2356
	'prefix-6rd',
2357
	'6RD Prefix',
2358
	'text',
2359
	$pconfig['prefix-6rd']
2360
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2361

    
2362
$section->addInput(new Form_Input(
2363
	'gateway-6rd',
2364
	'6RD Border relay',
2365
	'text',
2366
	$pconfig['gateway-6rd']
2367
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2368

    
2369
$section->addInput(new Form_Select(
2370
	'prefix-6rd-v4plen',
2371
	'6RD IPv4 Prefix length',
2372
	$pconfig['prefix-6rd-v4plen'],
2373
	array_combine(range(0, 32), range(0, 32))
2374
))->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.');
2375

    
2376
$form->add($section);
2377

    
2378
// Track IPv6 ointerface section
2379
$section = new Form_Section('Track IPv6 Interface');
2380
$section->addClass('track6');
2381

    
2382
function build_ipv6interface_list() {
2383
	global $config, $section;
2384

    
2385
	$list = array('' => '');
2386

    
2387
	$interfaces = get_configured_interface_with_descr(false, true);
2388
	$dynv6ifs = array();
2389

    
2390
	foreach ($interfaces as $iface => $ifacename) {
2391
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2392
			case "6to4":
2393
			case "6rd":
2394
			case "dhcp6":
2395
				$dynv6ifs[$iface] = array(
2396
					'name' => $ifacename,
2397
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2398
				);
2399
				break;
2400
			default:
2401
				continue;
2402
		}
2403
	}
2404

    
2405
	foreach ($dynv6ifs as $iface => $ifacedata) {
2406
		$list[$iface] = $ifacedata['name'];
2407

    
2408
		$section->addInput(new Form_Input(
2409
			'ipv6-num-prefix-ids-' . $iface,
2410
			null,
2411
			'hidden',
2412
			$ifacedata['ipv6_num_prefix_ids']
2413
		));
2414
	}
2415

    
2416
	return($list);
2417
}
2418

    
2419
$section->addInput(new Form_Select(
2420
	'track6-interface',
2421
	'IPv6 Interface',
2422
	$pconfig['track6-interface'],
2423
	build_ipv6interface_list()
2424
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2425

    
2426
if ($pconfig['track6-prefix-id'] == "") {
2427
	$pconfig['track6-prefix-id'] = 0;
2428
}
2429

    
2430
$section->addInput(new Form_Input(
2431
	'track6-prefix-id--hex' . $iface,
2432
	'IPv6 Prefix ID',
2433
	'text',
2434
	sprintf("%x", $pconfig['track6-prefix-id'])
2435
))->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.');
2436

    
2437
$section->addInput(new Form_Input(
2438
	'track6-prefix-id-max' . $iface,
2439
	null,
2440
	'hidden',
2441
	0
2442
));
2443

    
2444
$form->add($section);
2445

    
2446
/// PPP section
2447

    
2448
$section = new Form_Section('PPP Configuration');
2449
$section->addClass('ppp');
2450

    
2451
$section->addInput(new Form_Select(
2452
	'country',
2453
	'Country',
2454
	$pconfig['country'],
2455
	[]
2456
));
2457

    
2458
$section->addInput(new Form_Select(
2459
	'provider_list',
2460
	'Provider',
2461
	$pconfig['provider_list'],
2462
	[]
2463
));
2464

    
2465
$section->addInput(new Form_Select(
2466
	'providerplan',
2467
	'Plan',
2468
	$pconfig['providerplan'],
2469
	[]
2470
))->setHelp('Select to fill in data for your service provider.');
2471

    
2472
$section->addInput(new Form_Input(
2473
	'ppp_username',
2474
	'Username',
2475
	'text',
2476
	$pconfig['ppp_username']
2477
));
2478

    
2479
$section->addPassword(new Form_Input(
2480
	'ppp_password',
2481
	'Password',
2482
	'password',
2483
	$pconfig['ppp_password']
2484
));
2485

    
2486
$section->addInput(new Form_Input(
2487
	'phone',
2488
	'Phone number',
2489
	'text',
2490
	$pconfig['phone']
2491
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2492

    
2493
$section->addInput(new Form_Input(
2494
	'apn',
2495
	'Access Point Name',
2496
	'text',
2497
	$pconfig['apn']
2498
));
2499

    
2500

    
2501
function build_port_list() {
2502
	$list = array("" => "None");
2503

    
2504
	$portlist = glob("/dev/cua*");
2505
	$modems	  = glob("/dev/modem*");
2506
	$portlist = array_merge($portlist, $modems);
2507

    
2508
	foreach ($portlist as $port) {
2509
		if (preg_match("/\.(lock|init)$/", $port)) {
2510
			continue;
2511
		}
2512

    
2513
	$list[trim($port)] = $port;
2514
	}
2515

    
2516
	return($list);
2517
}
2518

    
2519
$section->addInput(new Form_Select(
2520
	'port',
2521
	"Modem port",
2522
	$pconfig['port'],
2523
	build_port_list()
2524
));
2525

    
2526
$section->addInput(new Form_Button(
2527
	'btnadvppp',
2528
	'Advanced PPP',
2529
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2530
))->setHelp('Create a new PPP configuration');
2531

    
2532
$form->add($section);
2533

    
2534
// PPPoE configuration
2535
$section = new Form_Section('PPPoE Configuration');
2536
$section->addClass('pppoe');
2537

    
2538
$section->addInput(new Form_Input(
2539
	'pppoe_username',
2540
	'Username',
2541
	'text',
2542
	$pconfig['pppoe_username']
2543
));
2544

    
2545
$section->addPassword(new Form_Input(
2546
	'pppoe_password',
2547
	'Password',
2548
	'password',
2549
	$pconfig['pppoe_password']
2550
));
2551

    
2552
$section->addInput(new Form_Input(
2553
	'provider',
2554
	'Service name',
2555
	'text',
2556
	$pconfig['provider']
2557
))->setHelp('This field can usually be left empty');
2558

    
2559
$section->addInput(new Form_Checkbox(
2560
	'pppoe_dialondemand',
2561
	'Dial on demand',
2562
	'Enable Dial-On-Demand mode ',
2563
	$pconfig['pppoe_dialondemand'],
2564
	'enable'
2565
));
2566

    
2567
$section->addInput(new Form_Input(
2568
	'pppoe_idletimeout',
2569
	'Idle timeout',
2570
	'number',
2571
	$pconfig['pppoe_idletimeout'],
2572
	[min => 0]
2573
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2574
			'An idle timeout of zero disables this feature.');
2575

    
2576
$section->addInput(new Form_Select(
2577
	'pppoe-reset-type',
2578
	'Periodic reset',
2579
	$pconfig['pppoe-reset-type'],
2580
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2581
))->setHelp('Select a reset timing type');
2582

    
2583
$group = new Form_Group('Custom reset');
2584
$group->addClass('pppoecustom');
2585

    
2586
$group->add(new Form_Input(
2587
	'pppoe_resethour',
2588
	null,
2589
	'number',
2590
	$pconfig['pppoe_resethour'],
2591
	[min => 0, max => 23]
2592
))->setHelp('Hour (0-23)');
2593

    
2594
$group->add(new Form_Input(
2595
	'pppoe_resetminute',
2596
	null,
2597
	'number',
2598
	$pconfig['pppoe_resetminute'],
2599
	[min => 0, max => 59]
2600
))->setHelp('Minutes (0-59)');
2601

    
2602
// ToDo: Need a date-picker here
2603
$group->add(new Form_Input(
2604
	'pppoe_resetdate',
2605
	null,
2606
	'text',
2607
	$pconfig['pppoe_resetdate']
2608
))->setHelp('Specific date (mm/dd/yyyy)');
2609

    
2610
$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');
2611

    
2612
$section->add($group);
2613

    
2614
$group = new Form_MultiCheckboxGroup('cron based reset');
2615
$group->addClass('pppoepreset');
2616

    
2617
$group->add(new Form_MultiCheckbox(
2618
	'pppoe_pr_preset_val',
2619
	null,
2620
	'Reset at each month ("0 0 1 * *")',
2621
	$pconfig['pppoe_monthly'],
2622
	'monthly'
2623
))->displayAsRadio();
2624

    
2625
$group->add(new Form_MultiCheckbox(
2626
	'pppoe_pr_preset_val',
2627
	null,
2628
	'Reset at each week ("0 0 * * 0")',
2629
	$pconfig['pppoe_weekly'],
2630
	'weekly'
2631
))->displayAsRadio();
2632

    
2633
$group->add(new Form_MultiCheckbox(
2634
	'pppoe_pr_preset_val',
2635
	null,
2636
	'Reset at each day ("0 0 * * *")',
2637
	$pconfig['pppoe_daily'],
2638
	'daily'
2639
))->displayAsRadio();
2640

    
2641
$group->add(new Form_MultiCheckbox(
2642
	'pppoe_pr_preset_val',
2643
	null,
2644
	'Reset at each hour ("0 * * * *")',
2645
	$pconfig['pppoe_hourly'],
2646
	'hourly'
2647
))->displayAsRadio();
2648

    
2649
$section->add($group);
2650

    
2651
if (isset($pconfig['pppid'])) {
2652
	$section->addInput(new Form_StaticText(
2653
		'Advanced and MLPPP',
2654
		'<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>'
2655
	));
2656
} else {
2657
	$section->addInput(new Form_StaticText(
2658
		'Advanced and MLPPP',
2659
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2660
	));
2661
}
2662

    
2663
$form->add($section);
2664

    
2665
// PPTP & L2TP Configuration section
2666
$section = new Form_Section('PPTP/L2TP Configuration');
2667
$section->addClass('pptp');
2668

    
2669
$section->addInput(new Form_Input(
2670
	'pptp_username',
2671
	'Username',
2672
	'text',
2673
	$pconfig['pptp_username']
2674
));
2675

    
2676
$section->addPassword(new Form_Input(
2677
	'pptp_password',
2678
	'Password',
2679
	'password',
2680
	$pconfig['pptp_password']
2681
));
2682

    
2683
$section->addInput(new Form_IpAddress(
2684
	'pptp_local0',
2685
	'Local IP address',
2686
	$pconfig['pptp_localip'][0]
2687
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2688

    
2689
$section->addInput(new Form_IpAddress(
2690
	'pptp_remote0',
2691
	'Remote IP address',
2692
	$pconfig['pptp_remote'][0]
2693
));
2694

    
2695
$section->addInput(new Form_Checkbox(
2696
	'pptp_dialondemand',
2697
	'Dial on demand',
2698
	'Enable Dial-On-Demand mode ',
2699
	$pconfig['pptp_dialondemand'],
2700
	'enable'
2701
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2702
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2703

    
2704
$section->addInput(new Form_Input(
2705
	'pptp_idletimeout',
2706
	'Idle timeout (seconds)',
2707
	'number',
2708
	$pconfig['pptp_idletimeout'],
2709
	[min => 0]
2710
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2711
			'An idle timeout of zero disables this feature.');
2712

    
2713
if (isset($pconfig['pppid'])) {
2714
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2715
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2716
	} else {
2717
		$mlppp_text = "";
2718
	}
2719

    
2720
	$section->addInput(new Form_StaticText(
2721
		'Advanced and MLPPP',
2722
		$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>'
2723
	));
2724
} else {
2725
	$section->addInput(new Form_StaticText(
2726
		'Advanced and MLPPP',
2727
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2728
	));
2729
}
2730

    
2731
$form->add($section);
2732

    
2733
// Wireless interface
2734
if (isset($wancfg['wireless'])) {
2735

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

    
2738
	$section->addInput(new Form_Checkbox(
2739
		'persistcommonwireless',
2740
		'Persist common settings',
2741
		'Preserve common wireless configuration through interface deletions and reassignments.',
2742
		$pconfig['persistcommonwireless'],
2743
		'yes'
2744
	));
2745

    
2746
	$mode_list = ['auto' => 'Auto'];
2747

    
2748
	if (is_array($wl_modes)) {
2749
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2750
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2751
		}
2752
	}
2753

    
2754
	if (count($mode_list) == 1) {
2755
		$mode_list[''] = '';
2756
	}
2757

    
2758
	$section->addInput(new Form_Select(
2759
		'standard',
2760
		'Standard',
2761
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2762
		$mode_list
2763
	));
2764

    
2765
	if (isset($wl_modes['11g'])) {
2766
		$section->addInput(new Form_Select(
2767
			'protmode',
2768
			'802.11g OFDM Protection Mode',
2769
			$pconfig['protmode'],
2770
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2771
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2772
	} else {
2773
		$section->addInput(new Form_Input(
2774
			'protmode',
2775
			null,
2776
			'hidden',
2777
			'off'
2778
		));
2779
	}
2780

    
2781
	$mode_list = ['0' => 'Auto'];
2782

    
2783
	if (is_array($wl_modes)) {
2784
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2785
			if ($wl_standard == "11g") {
2786
				$wl_standard = "11b/g";
2787
			} else if ($wl_standard == "11ng") {
2788
				$wl_standard = "11b/g/n";
2789
			} else if ($wl_standard == "11na") {
2790
				$wl_standard = "11a/n";
2791
			}
2792

    
2793
			foreach ($wl_channels as $wl_channel) {
2794
				if (isset($wl_chaninfo[$wl_channel])) {
2795
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2796
				} else {
2797
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2798
				}
2799
			}
2800
		}
2801
	}
2802

    
2803
	$section->addInput(new Form_Select(
2804
		'channel',
2805
		'Channel',
2806
		$pconfig['channel'],
2807
		$mode_list
2808
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2809
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2810

    
2811
	if (ANTENNAS) {
2812
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2813
			$group = new Form_Group('Antenna Settings');
2814

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

    
2824
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2825
				$group->add(new Form_Select(
2826
					'txantenna',
2827
					null,
2828
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2829
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2830
				))->setHelp('Transmit antenna');
2831
			}
2832

    
2833
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2834
				$group->add(new Form_Select(
2835
					'rxantenna',
2836
					null,
2837
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2838
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2839
				))->setHelp('Receive antenna');
2840
			}
2841

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

    
2844
			$section->add($group);
2845
		}
2846
	}
2847

    
2848
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2849
			$section->addInput(new Form_Input(
2850
				'distance',
2851
				'Distance setting (meters)',
2852
				'test',
2853
				$pconfig['distance']
2854
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2855
	}
2856

    
2857
	$form->add($section);
2858

    
2859
	// Regulatory settings
2860
	$section = new Form_Section('Regulatory settings');
2861

    
2862
	$domain_list = array("" => 'Default');
2863

    
2864
	if (is_array($wl_regdomains)) {
2865
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2866
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2867
		}
2868
	}
2869

    
2870
	$section->addInput(new Form_Select(
2871
		'regdomain',
2872
		'Regulatory domain',
2873
		$pconfig['regdomain'],
2874
		$domain_list
2875
	))->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');
2876

    
2877
	$country_list = array('' => 'Default');
2878

    
2879
	if (is_array($wl_countries)) {
2880
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2881
			$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']);
2882
		}
2883
	}
2884

    
2885
	$section->addInput(new Form_Select(
2886
		'regcountry',
2887
		'Country',
2888
		$pconfig['regcountry'],
2889
		$country_list
2890
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2891

    
2892
	$section->addInput(new Form_Select(
2893
		'reglocation',
2894
		'Location',
2895
		$pconfig['reglocation'],
2896
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2897
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2898
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2899
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2900
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2901
				'These settings may not be able to add additional channels that are not already supported.');
2902

    
2903
	$form->add($section);
2904

    
2905
	$section = new Form_Section('Network-specific wireless configuration');
2906

    
2907
	$section->addInput(new Form_Select(
2908
		'mode',
2909
		'Mode',
2910
		$pconfig['mode'],
2911
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
2912
	));
2913

    
2914
	$section->addInput(new Form_Input(
2915
		'ssid',
2916
		'SSID',
2917
		'text',
2918
		$pconfig['ssid']
2919
	));
2920

    
2921
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2922
		$section->addInput(new Form_Select(
2923
			'puremode',
2924
			'Minimum wireless standard',
2925
			$pconfig['puremode'],
2926
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
2927
		))->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)');
2928
	} elseif (isset($wl_modes['11g'])) {
2929
		$section->addInput(new Form_Checkbox(
2930
			'puremode',
2931
			'802.11g only',
2932
			null,
2933
			$pconfig['puremode'],
2934
			'11g'
2935
		))->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)');
2936
	}
2937

    
2938
	$section->addInput(new Form_Checkbox(
2939
		'apbridge_enable',
2940
		'Allow intra-BSS communication',
2941
		'Allow packets to pass between wireless clients directly when operating as an access point',
2942
		$pconfig['apbridge_enable'],
2943
		'yes'
2944
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2945

    
2946
	$section->addInput(new Form_Checkbox(
2947
		'wme_enable',
2948
		'Enable WME',
2949
		'Force the card to use WME (wireless QoS)',
2950
		$pconfig['wme_enable'],
2951
		'yes'
2952
	));
2953

    
2954
	$section->addInput(new Form_Checkbox(
2955
		'hidessid_enable',
2956
		'Hide SSID',
2957
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2958
		$pconfig['hidessid_enable'],
2959
		'yes'
2960
	));
2961

    
2962
	$form->add($section);
2963

    
2964
	// WPA Section
2965
	$section = new Form_Section('WPA');
2966

    
2967
	$section->addInput(new Form_Checkbox(
2968
		'wpa_enable',
2969
		'Enable',
2970
		'Enable WPA',
2971
		$pconfig['wpa_enable'],
2972
		'yes'
2973
	));
2974

    
2975
	$section->addInput(new Form_Input(
2976
		'passphrase',
2977
		'WPA Pre-Shared Key',
2978
		'text',
2979
		$pconfig['passphrase']
2980
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2981

    
2982
	$section->addInput(new Form_Select(
2983
		'wpa_mode',
2984
		'WPA mode',
2985
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2986
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
2987
	));
2988

    
2989
	$section->addInput(new Form_Select(
2990
		'wpa_key_mgmt',
2991
		'WPA Key Management Mode',
2992
		$pconfig['wpa_key_mgmt'],
2993
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
2994
	));
2995

    
2996
	$section->addInput(new Form_Select(
2997
		'wpa_pairwise',
2998
		'WPA Pairwise',
2999
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3000
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3001
	));
3002

    
3003
	$section->addInput(new Form_Input(
3004
		'wpa_group_rekey',
3005
		'WPA Pre-Shared Key',
3006
		'number',
3007
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3008
		['min' => '1', 'max' => 9999]
3009
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3010

    
3011
	$section->addInput(new Form_Input(
3012
		'wpa_gmk_rekey',
3013
		'Master Key Regeneration',
3014
		'number',
3015
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3016
		['min' => '1', 'max' => 9999]
3017
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3018

    
3019
	$section->addInput(new Form_Checkbox(
3020
		'wpa_strict_rekey',
3021
		'Strict Key Regeneration',
3022
		'Force the AP to rekey whenever a client disassociates',
3023
		$pconfig['wpa_strict_rekey'],
3024
		'yes'
3025
	));
3026

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

    
3029
	$section = new Form_Section('802.1x RADIUS options');
3030

    
3031
	$section->addInput(new Form_Checkbox(
3032
		'ieee8021x',
3033
		'IEEE802.1X',
3034
		'Enable 802.1X authentication',
3035
		$pconfig['ieee8021x'],
3036
		'yes'
3037
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3038

    
3039
	$group = new Form_Group('Primary 802.1X server');
3040

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

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

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

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

    
3063
	$group = new Form_Group('Secondary 802.1X server');
3064

    
3065
	$group->add(new Form_IpAddress(
3066
		'auth_server_addr2',
3067
		'IP Address',
3068
		$pconfig['auth_server_addr2']
3069
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3070

    
3071
	$group->add(new Form_Input(
3072
		'auth_server_port2',
3073
		'Port',
3074
		'number',
3075
		$pconfig['auth_server_port2']
3076
	))->setHelp('Server port. Leave blank for the default port 1812');
3077

    
3078
	$group->add(new Form_Input(
3079
		'auth_server_shared_secret2',
3080
		'Shared secret',
3081
		'number',
3082
		$pconfig['auth_server_shared_secret2']
3083
	))->setHelp('Shared secret');
3084

    
3085
	$section->add($group);
3086

    
3087
	$section->addInput(new Form_Checkbox(
3088
		'rsn_preauth',
3089
		'Authentication Roaming Preauth',
3090
		null,
3091
		$pconfig['rsn_preauth'],
3092
		'yes'
3093
	));
3094

    
3095
	$form->add($section);
3096
}
3097

    
3098
$section = new Form_Section('Private networks');
3099

    
3100
$section->addInput(new Form_Checkbox(
3101
	'blockpriv',
3102
	'Block private networks',
3103
	'',
3104
	$pconfig['blockpriv'],
3105
	'yes'
3106
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3107
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3108
			'lies in such a private address space, too.');
3109

    
3110
$section->addInput(new Form_Checkbox(
3111
	'blockbogons',
3112
	'Block bogon networks',
3113
	'',
3114
	$pconfig['blockbogons'],
3115
	'yes'
3116
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3117
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3118
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3119

    
3120
$form->add($section);
3121

    
3122
$form->addGlobal(new Form_Input(
3123
	'if',
3124
	null,
3125
	'hidden',
3126
	$if
3127
));
3128

    
3129
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3130
	$form->addGlobal(new Form_Input(
3131
		'ppp_port',
3132
		null,
3133
		'hidden',
3134
		$pconfig['port']
3135
	));
3136
}
3137

    
3138
$form->addGlobal(new Form_Input(
3139
	'ptpid',
3140
	null,
3141
	'hidden',
3142
	$pconfig['ptpid']
3143
));
3144

    
3145

    
3146
// Add new gateway modal pop-up
3147
$modal = new Modal('New gateway', 'newgateway', 'large');
3148

    
3149
$modal->addInput(new Form_Checkbox(
3150
	'defaultgw',
3151
	'Default',
3152
	'Default gateway',
3153
	($if == "wan" || $if == "WAN")
3154
));
3155

    
3156
$modal->addInput(new Form_Input(
3157
	'name',
3158
	'Gateway name',
3159
	'text',
3160
	$wancfg['descr'] . "GW"
3161
));
3162

    
3163
$modal->addInput(new Form_IpAddress(
3164
	'gatewayip',
3165
	'Gateway IPv4',
3166
	null
3167
));
3168

    
3169
$modal->addInput(new Form_Input(
3170
	'gatewaydescr',
3171
	'Description',
3172
	'text'
3173
));
3174

    
3175
$btnaddgw = new Form_Button(
3176
	'add',
3177
	'Add'
3178
);
3179

    
3180
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3181

    
3182
$btncnxgw = new Form_Button(
3183
	'cnx',
3184
	'Cancel'
3185
);
3186

    
3187
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3188

    
3189
$modal->addInput(new Form_StaticText(
3190
	null,
3191
	$btnaddgw . $btncnxgw
3192
));
3193

    
3194
$form->add($modal);
3195

    
3196
print($form);
3197
?>
3198

    
3199
<script type="text/javascript">
3200
//<![CDATA[
3201
events.push(function() {
3202
	function updateType(t) {
3203

    
3204
		switch (t) {
3205
			case "none": {
3206
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3207
				break;
3208
			}
3209
			case "staticv4": {
3210
				$('.dhcpadvanced, .none, .dhcp').hide();
3211
				$('.pppoe, .pptp, .ppp').hide();
3212
				break;
3213
			}
3214
			case "dhcp": {
3215
				$('.dhcpadvanced, .none').hide();
3216
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3217
										//			about the staticv4 class
3218
				$('.pppoe, .pptp, .ppp').hide();
3219
				break;
3220
			}
3221
			case "ppp": {
3222
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3223
				country_list();
3224
				break;
3225
			}
3226
			case "pppoe": {
3227
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3228
				break;
3229
			}
3230
			case "l2tp":
3231
			case "pptp": {
3232
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3233
				$('.pptp').show();
3234
				break;
3235
			}
3236
		}
3237

    
3238
		if (t != "l2tp" && t != "pptp") {
3239
			$('.'+t).show();
3240
		}
3241
	}
3242

    
3243
	function updateTypeSix(t) {
3244
		if (!isNaN(t[0])) {
3245
			t = '_' + t;
3246
		}
3247

    
3248
		switch (t) {
3249
			case "none": {
3250
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3251
				break;
3252
			}
3253
			case "staticv6": {
3254
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3255
				break;
3256
			}
3257
			case "slaac": {
3258
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3259
				break;
3260
			}
3261
			case "dhcp6": {
3262
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3263
				break;
3264
			}
3265
			case "6rd_": {
3266
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3267
				break;
3268
			}
3269
			case "_6to4": {
3270
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3271
				break;
3272
			}
3273
			case "track6": {
3274
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3275
				update_track6_prefix();
3276
				break;
3277
			}
3278
		}
3279

    
3280
		if (t != "l2tp" && t != "pptp") {
3281
			$('.'+t).show();
3282
		}
3283
	}
3284

    
3285
	function show_reset_settings(reset_type) {
3286
		if (reset_type == 'preset') {
3287
			$('.pppoepreset').show();
3288
			$('.pppoecustom').hide();
3289
		} else if (reset_type == 'custom') {
3290
			$('.pppoecustom').show();
3291
			$('.pppoepreset').hide();
3292
		} else {
3293
			$('.pppoecustom').hide();
3294
			$('.pppoepreset').hide();
3295
		}
3296
	}
3297

    
3298
	function update_track6_prefix() {
3299
		var iface = $("#track6-interface").val();
3300
		if (iface == null) {
3301
			return;
3302
		}
3303

    
3304
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3305
		if (track6_prefix_ids == null) {
3306
			return;
3307
		}
3308

    
3309
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3310
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3311
	}
3312

    
3313
	// Create the new gateway from the data entered in the modal pop-up
3314
	function hide_add_gatewaysave() {
3315
		var iface = $('#if').val();
3316
		name = $('#name').val();
3317
		var descr = $('#gatewaydescr').val();
3318
		gatewayip = $('#gatewayip').val();
3319

    
3320
		var defaultgw = '';
3321
		if ($('#defaultgw').is(':checked')) {
3322
			defaultgw = '&defaultgw=on';
3323
		}
3324

    
3325
		var url = "system_gateways_edit.php";
3326
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3327
		$.ajax(
3328
			url,
3329
			{
3330
				type: 'post',
3331
				data: pars,
3332
				error: report_failure,
3333
				complete: save_callback
3334
			});
3335
		}
3336

    
3337
	function save_callback(response) {
3338
		if (response) {
3339
			var gwtext = escape(name) + " - " + gatewayip;
3340
			addOption($('#gateway'), gwtext, name);
3341
		} else {
3342
			report_failure();
3343
		}
3344

    
3345
		$("#newgateway").modal('hide');
3346
	}
3347

    
3348
	function report_failure(request, textStatus, errorThrown) {
3349
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3350
			alert(request.responseText);
3351
		} else {
3352
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3353
		}
3354

    
3355
		$("#newgateway").modal('hide');
3356
	}
3357

    
3358
	function addOption(selectbox, text, value) {
3359
		var optn = document.createElement("OPTION");
3360
		optn.text = text;
3361
		optn.value = value;
3362
		selectbox.append(optn);
3363
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3364
	}
3365

    
3366
	function hide_add_gatewaysave_v6() {
3367

    
3368
		var iface = $('#if').val();
3369
		name = $('#name6').val();
3370
		var descr = $('#gatewaydescr6').val();
3371
		gatewayip = $('#gatewayip6').val();
3372
		var defaultgw = '';
3373
		if ($('#defaultgw6').is(':checked')) {
3374
			defaultgw = '&defaultgw=on';
3375
		}
3376
		var url_v6 = "system_gateways_edit.php";
3377
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3378
		$.ajax(
3379
			url_v6,
3380
			{
3381
				type: 'post',
3382
				data: pars_v6,
3383
				error: report_failure_v6,
3384
				success: save_callback_v6
3385
			});
3386
	}
3387

    
3388

    
3389
	function addOption_v6(selectbox, text, value) {
3390
		var optn = document.createElement("OPTION");
3391
		optn.text = text;
3392
		optn.value = value;
3393
		selectbox.append(optn);
3394
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3395
	}
3396

    
3397
	function report_failure_v6(request, textStatus, errorThrown) {
3398
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3399
			alert(request.responseText);
3400
		} else {
3401
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3402
		}
3403

    
3404
		$("#newgateway6").modal('hide');
3405
	}
3406

    
3407
	function save_callback_v6(response_v6) {
3408
		if (response_v6) {
3409

    
3410
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3411
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3412
		} else {
3413
			report_failure_v6();
3414
		}
3415

    
3416
		$("#newgateway6").modal('hide');
3417
	}
3418

    
3419
	function country_list() {
3420
		$('#country').children().remove();
3421
		$('#provider_list').children().remove();
3422
		$('#providerplan').children().remove();
3423
		$.ajax("getserviceproviders.php",{
3424
			success: function(response) {
3425

    
3426
				var responseTextArr = response.split("\n");
3427
				responseTextArr.sort();
3428

    
3429
				responseTextArr.forEach( function(value) {
3430
					country = value.split(":");
3431
					$('#country').append($('<option>', {
3432
						value: country[1],
3433
						text : country[0]
3434
					}));
3435
				});
3436
			}
3437
		});
3438
	}
3439

    
3440
	function providers_list() {
3441
		$('#provider_list').children().remove();
3442
		$('#providerplan').children().remove();
3443
		$.ajax("getserviceproviders.php",{
3444
			type: 'post',
3445
			data: {country : $('#country').val()},
3446
			success: function(response) {
3447
				var responseTextArr = response.split("\n");
3448
				responseTextArr.sort();
3449
				responseTextArr.forEach( function(value) {
3450
					$('#provider_list').append($('<option>', {
3451
							value: value,
3452
							text : value
3453
					}));
3454
				});
3455
			}
3456
		});
3457
	}
3458

    
3459
	function providerplan_list() {
3460
		$('#providerplan').children().remove();
3461
		$.ajax("getserviceproviders.php",{
3462
			type: 'post',
3463
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3464
			success: function(response) {
3465
				var responseTextArr = response.split("\n");
3466
				responseTextArr.sort();
3467

    
3468
				$('#providerplan').append($('<option>', {
3469
					value: '',
3470
					text : ''
3471
				}));
3472

    
3473
				responseTextArr.forEach( function(value) {
3474
					if (value != "") {
3475
						providerplan = value.split(":");
3476

    
3477
						$('#providerplan').append($('<option>', {
3478
							value: providerplan[1],
3479
							text : providerplan[0] + " - " + providerplan[1]
3480
						}));
3481
					}
3482
				});
3483
			}
3484
		});
3485
	}
3486

    
3487
	function prefill_provider() {
3488
		$.ajax("getserviceproviders.php",{
3489
			type: 'post',
3490
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3491
			success: function(data, textStatus, response) {
3492
				var xmldoc = response.responseXML;
3493
				var provider = xmldoc.getElementsByTagName('connection')[0];
3494
				$('#ppp_username').val('');
3495
				$('#ppp_password').val('');
3496
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3497
					$('#phone').val('#777');
3498
					$('#apn').val('');
3499
				} else {
3500
					$('#phone').val('*99#');
3501
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3502
				}
3503
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3504
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3505
				$('#ppp_username').val(ppp_username);
3506
				$('#ppp_password').val(ppp_password);
3507
			}
3508
		});
3509
	}
3510

    
3511
	function show_dhcp6adv() {
3512
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3513
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3514

    
3515
		hideCheckbox('dhcp6usev4iface', ovr);
3516
		hideCheckbox('dhcp6prefixonly', ovr);
3517
		hideInput('dhcp6-ia-pd-len', ovr);
3518
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3519
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3520

    
3521
		hideClass('dhcp6advanced', !adv || ovr);
3522
	}
3523

    
3524
	function setDHCPoptions() {
3525
		var adv = $('#dhcpadv').prop('checked');
3526
		var ovr = $('#dhcpovr').prop('checked');
3527

    
3528
		if (ovr) {
3529
			hideInput('dhcphostname', true);
3530
			hideIpAddress('alias-address', true);
3531
			hideInput('dhcprejectfrom', true);
3532
			hideInput('adv_dhcp_config_file_override_path', false);
3533
			hideClass('dhcpadvanced', true);
3534
		} else {
3535
			hideInput('dhcphostname', false);
3536
			hideIpAddress('alias-address', false);
3537
			hideInput('dhcprejectfrom', false);
3538
			hideInput('adv_dhcp_config_file_override_path', true);
3539
			hideClass('dhcpadvanced', !adv);
3540
		}
3541
	}
3542

    
3543
	// DHCP preset actions
3544
	// Set presets from value of radio buttons
3545
	function setPresets(val) {
3546
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3547
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3548
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3549
		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']);?>");
3550
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3551
	}
3552

    
3553
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3554
		$('#adv_dhcp_pt_timeout').val(timeout);
3555
		$('#adv_dhcp_pt_retry').val(retry);
3556
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3557
		$('#adv_dhcp_pt_reboot').val(reboot);
3558
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3559
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3560
	}
3561

    
3562
	// ---------- On initial page load ------------------------------------------------------------
3563

    
3564
	updateType($('#type').val());
3565
	updateTypeSix($('#type6').val());
3566
	show_reset_settings($('#pppoe-reset-type').val());
3567
	$("#add").prop('type', 'button');
3568
	$("#cnx").prop('type', 'button');
3569
	$("#addgw").prop('type', 'button');
3570
	$("#add6").prop('type', 'button');
3571
	$("#cnx6").prop('type', 'button');
3572
	$("#addgw6").prop('type', 'button');
3573
	hideClass('dhcp6advanced', true);
3574
	hideClass('dhcpadvanced', true);
3575
	show_dhcp6adv();
3576
	setDHCPoptions()
3577

    
3578
	// Set preset buttons on page load
3579
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3580
	if (sv == "") {
3581
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3582
	} else {
3583
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3584
	}
3585

    
3586
	// Set preset from value
3587
	setPresets(sv);
3588

    
3589
	// ---------- Click checkbox handlers ---------------------------------------------------------
3590

    
3591
	$('#type').on('change', function() {
3592
		updateType(this.value);
3593
	});
3594

    
3595
	$('#type6').on('change', function() {
3596
		updateTypeSix(this.value);
3597
	});
3598

    
3599
	$('#pppoe-reset-type').on('change', function() {
3600
		show_reset_settings(this.value);
3601
	});
3602

    
3603
	$("#add").click(function() {
3604
		hide_add_gatewaysave();
3605
	});
3606

    
3607
	$("#cnx").click(function() {
3608
		$("#newgateway").modal('hide');
3609
	});
3610

    
3611
	$("#add6").click(function() {
3612
		hide_add_gatewaysave_v6();
3613
	});
3614

    
3615
	$("#cnx6").click(function() {
3616
		$("#newgateway6").modal('hide');
3617
	});
3618

    
3619
	$('#country').on('change', function() {
3620
		providers_list();
3621
	});
3622

    
3623
	$('#provider_list').on('change', function() {
3624
		providerplan_list();
3625
	});
3626

    
3627
	$('#providerplan').on('change', function() {
3628
		prefill_provider();
3629
	});
3630

    
3631
	$('#dhcpadv, #dhcpovr').click(function () {
3632
		setDHCPoptions();
3633
	});
3634

    
3635
	$('#adv_dhcp6_config_advanced').click(function () {
3636
		show_dhcp6adv();
3637
	});
3638

    
3639
	$('#adv_dhcp6_config_file_override').click(function () {
3640
		show_dhcp6adv();
3641
	});
3642

    
3643
	// On click . .
3644
	$('[name=adv_dhcp_pt_values]').click(function () {
3645
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3646
	});
3647

    
3648
});
3649
//]]>
3650
</script>
3651

    
3652
<?php include("foot.inc");
(69-69/229)