Project

General

Profile

Download (122 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
switch ($wancfg['ipaddr']) {
284
	case "dhcp":
285
		$pconfig['type'] = "dhcp";
286
		break;
287
	case "pppoe":
288
	case "pptp":
289
	case "l2tp":
290
	case "ppp":
291
		$pconfig['type'] = $wancfg['ipaddr'];
292
		break;
293
	default:
294
		if (is_ipaddrv4($wancfg['ipaddr'])) {
295
			$pconfig['type'] = "staticv4";
296
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
297
			$pconfig['subnet'] = $wancfg['subnet'];
298
			$pconfig['gateway'] = $wancfg['gateway'];
299
		} else {
300
			$pconfig['type'] = "none";
301
		}
302
		break;
303
}
304

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

    
355
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
356
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
357
$pconfig['spoofmac'] = $wancfg['spoofmac'];
358
$pconfig['mtu'] = $wancfg['mtu'];
359
$pconfig['mss'] = $wancfg['mss'];
360

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

    
437
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
438

    
439
}
440

    
441
if ($_POST['apply']) {
442
	unset($input_errors);
443
	if (!is_subsystem_dirty('interfaces')) {
444
		$input_errors[] = gettext("You have already applied your settings!");
445
	} else {
446
		unlink_if_exists("{$g['tmp_path']}/config.cache");
447
		clear_subsystem_dirty('interfaces');
448

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

    
467
		/* sync filter configuration */
468
		setup_gateways_monitor();
469

    
470
		clear_subsystem_dirty('interfaces');
471

    
472
		filter_configure();
473

    
474
		enable_rrd_graphing();
475

    
476
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
477
			clear_subsystem_dirty('staticroutes');
478
		}
479
	}
480
	@unlink("{$g['tmp_path']}/.interfaces.apply");
481
	header("Location: interfaces.php?if={$if}");
482
	exit;
483
} else if ($_POST) {
484

    
485
	unset($input_errors);
486
	$pconfig = $_POST;
487

    
488
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
489
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
490
	} else {
491
		$pconfig['track6-prefix-id'] = 0;
492
	}
493
	conf_mount_rw();
494

    
495
	/* filter out spaces from descriptions */
496
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
497

    
498
	/* okay first of all, cause we are just hiding the PPPoE HTML
499
	 * fields related to PPPoE resets, we are going to unset $_POST
500
	 * vars, if the reset feature should not be used. Otherwise the
501
	 * data validation procedure below, may trigger a false error
502
	 * message.
503
	 */
504
	if (empty($_POST['pppoe-reset-type'])) {
505
		unset($_POST['pppoe_pr_type']);
506
		unset($_POST['pppoe_resethour']);
507
		unset($_POST['pppoe_resetminute']);
508
		unset($_POST['pppoe_resetdate']);
509
		unset($_POST['pppoe_pr_preset_val']);
510
	}
511
	/* description unique? */
512
	foreach ($ifdescrs as $ifent => $ifdescr) {
513
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
514
			$input_errors[] = gettext("An interface with the specified description already exists.");
515
			break;
516
		}
517
	}
518

    
519
	/* Is the description already used as an alias name? */
520
	if (is_array($config['aliases']['alias'])) {
521
		foreach ($config['aliases']['alias'] as $alias) {
522
			if ($alias['name'] == $_POST['descr']) {
523
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
524
			}
525
		}
526
	}
527

    
528
	/* Is the description already used as an interface group name? */
529
	if (is_array($config['ifgroups']['ifgroupentry'])) {
530
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
531
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
532
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
533
			}
534
		}
535
	}
536

    
537
	if (is_numeric($_POST['descr'])) {
538
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
539
	}
540
	/* input validation */
541
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
542
		$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.");
543
	}
544
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
545
		$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.");
546
	}
547

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

    
655
			if (empty($_POST['track6-interface'])) {
656
				$input_errors[] = gettext("You have to select a valid interface to track.");
657
			}
658

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

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

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

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

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

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

    
822
		unset($min_mtu, $max_mtu);
823

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1412
		conf_mount_ro();
1413
		write_config();
1414

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

    
1424
		mark_subsystem_dirty('interfaces');
1425

    
1426
		/* regenerate cron settings/crontab file */
1427
		configure_cron();
1428

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

    
1433
} // end if ($_POST)
1434

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

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

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

    
1584
	interface_sync_wireless_clones($wancfg, true);
1585
}
1586

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

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

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

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

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

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

    
1635
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1636
$shortcut_section = "interfaces";
1637

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

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

    
1646
function build_mediaopts_list() {
1647
	global $mediaopts_list;
1648

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

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

    
1657
	return($list);
1658
}
1659

    
1660
function build_gateway_list() {
1661
	global $a_gateways, $if;
1662

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

    
1670
	return($list);
1671
}
1672

    
1673
function build_gatewayv6_list() {
1674
	global $a_gateways, $if;
1675

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

    
1683
	return($list);
1684
}
1685

    
1686
include("head.inc");
1687

    
1688
if ($input_errors) {
1689
	print_input_errors($input_errors);
1690
}
1691

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

    
1698
if ($savemsg) {
1699
	print_info_box($savemsg, 'success');
1700
}
1701

    
1702

    
1703
$form = new Form(new Form_Button(
1704
	'Submit',
1705
	gettext("Save")
1706
));
1707

    
1708
$section = new Form_Section('General Configuration');
1709

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

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

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

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

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

    
1747
$btnmymac = new Form_Button(
1748
	'btnmymac',
1749
	'Copy My MAC'
1750
	);
1751

    
1752
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1753

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

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

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

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

    
1787
$form->add($section);
1788

    
1789
$section = new Form_Section('Static IPv4 Configuration');
1790
$section->addClass('staticv4');
1791

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

    
1798
$group = new Form_Group('IPv4 Upstream gateway');
1799

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

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

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

    
1816
$section->add($group);
1817

    
1818
$form->add($section);
1819

    
1820
$section = new Form_Section('Static IPv6 Configuration');
1821
$section->addClass('staticv6');
1822

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

    
1829
$group = new Form_Group('IPv6 Upstream gateway');
1830

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

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

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

    
1846
$section->add($group);
1847
$form->add($section);
1848

    
1849
// Add new gateway modal pop-up for IPv6
1850
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1851

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

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

    
1866
$modal->addInput(new Form_IpAddress(
1867
	'gatewayip6',
1868
	'Gateway IPv6',
1869
	null
1870
));
1871

    
1872
$modal->addInput(new Form_Input(
1873
	'gatewaydescr6',
1874
	'Description',
1875
	'text'
1876
));
1877

    
1878
$btnaddgw6 = new Form_Button(
1879
	'add6',
1880
	'Add'
1881
);
1882

    
1883
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1884

    
1885
$btncnxgw6 = new Form_Button(
1886
	'cnx6',
1887
	'Cancel'
1888
);
1889

    
1890
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1891

    
1892
$modal->addInput(new Form_StaticText(
1893
	null,
1894
	$btnaddgw6 . $btncnxgw6
1895
));
1896

    
1897
$form->add($modal);
1898

    
1899
// ==== DHCP client configuration =============================
1900

    
1901
$section = new Form_Section('DHCP Client Configuration');
1902
$section->addClass('dhcp');
1903

    
1904
$group = new Form_Group('Options');
1905

    
1906
$group->add(new Form_Checkbox(
1907
	'dhcpadv',
1908
	null,
1909
	'Show DHCP advanced options',
1910
	false
1911
));
1912

    
1913
$group->add(new Form_Checkbox(
1914
	'dhcpovr',
1915
	null,
1916
	'Config file override',
1917
	false
1918
));
1919

    
1920
$section->add($group);
1921

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

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

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

    
1943
$group = new Form_Group('Protocol timing');
1944
$group->addClass('dhcpadvanced');
1945

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

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

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

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

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

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

    
1989
$section->add($group);
1990

    
1991
$group = new Form_Group('Presets');
1992
$group->addClass('dhcpadvanced');
1993

    
1994
$group->add(new Form_Checkbox(
1995
	'adv_dhcp_pt_values',
1996
	null,
1997
	'FreeBSD default',
1998
	null,
1999
	'DHCP'
2000
))->displayAsRadio();
2001

    
2002
$group->add(new Form_Checkbox(
2003
	'adv_dhcp_pt_values',
2004
	null,
2005
	'Clear',
2006
	null,
2007
	'Clear'
2008
))->displayAsRadio();
2009

    
2010
$group->add(new Form_Checkbox(
2011
	'adv_dhcp_pt_values',
2012
	null,
2013
	'pfSense Default',
2014
	null,
2015
	'pfSense'
2016
))->displayAsRadio();
2017

    
2018
$group->add(new Form_Checkbox(
2019
	'adv_dhcp_pt_values',
2020
	null,
2021
	'Saved Cfg',
2022
	null,
2023
	'SavedCfg'
2024
))->displayAsRadio();
2025

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

    
2029
$section->add($group);
2030

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

    
2041
$form->add($section);
2042

    
2043
$section = new Form_Section('Lease Requirements and Requests');
2044
$section->addClass('dhcpadvanced');
2045

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

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

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

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

    
2079
$form->add($section);
2080

    
2081
// DHCP6 client config
2082

    
2083
$section = new Form_Section('DHCP6 Client Configuration');
2084
$section->addClass('dhcp6');
2085

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

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

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

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

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

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

    
2130
$section->addInput(new Form_Checkbox(
2131
	'dhcp6debug',
2132
	'Debug',
2133
	'Start DHCP6 client in debug mode',
2134
	$pconfig['dhcp6debug']
2135
));
2136

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

    
2147
$form->add($section);
2148

    
2149
// DHCP6 client config - Advanced
2150

    
2151
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2152
$section->addClass('dhcp6advanced');
2153

    
2154
$section->addInput(new Form_Checkbox(
2155
	'adv_dhcp6_interface_statement_information_only_enable',
2156
	'Information only',
2157
	null,
2158
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2159
	'Selected'
2160
));
2161

    
2162
$section->addInput(new Form_Input(
2163
	'adv_dhcp6_interface_statement_send_options',
2164
	'Send options',
2165
	'text',
2166
	$pconfig['adv_dhcp6_interface_statement_send_options']
2167
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2168
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2169
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2170
			'Some DHCP services may require certain options be or not be sent.');
2171

    
2172
$section->addInput(new Form_Input(
2173
	'adv_dhcp6_interface_statement_request_options',
2174
	'Request Options',
2175
	'text',
2176
	$pconfig['adv_dhcp6_interface_statement_request_options']
2177
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2178
			'Some DHCP services may require certain options be or not be requested.');
2179

    
2180
$section->addInput(new Form_Input(
2181
	'adv_dhcp6_interface_statement_script',
2182
	'Scripts',
2183
	'text',
2184
	$pconfig['adv_dhcp6_interface_statement_script']
2185
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2186
			'[/[dirname/[.../]]filename[.ext]].');
2187

    
2188
$group = new Form_Group('Identity Association Statement');
2189

    
2190
$group->add(new Form_Checkbox(
2191
	'adv_dhcp6_id_assoc_statement_address_enable',
2192
	null,
2193
	'Non-Temporary Address Allocation',
2194
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2195
	'Selected'
2196
));
2197

    
2198
$group->add(new Form_Input(
2199
	'adv_dhcp6_id_assoc_statement_address_id',
2200
	null,
2201
	'text',
2202
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2203
))->sethelp('id-assoc na ID');
2204

    
2205
$group->add(new Form_IpAddress(
2206
	'adv_dhcp6_id_assoc_statement_address',
2207
	null,
2208
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2209
))->sethelp('IPv6 address');
2210

    
2211
$group->add(new Form_Input(
2212
	'adv_dhcp6_id_assoc_statement_address_pltime',
2213
	null,
2214
	'text',
2215
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2216
))->sethelp('pltime');
2217

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

    
2225
$section->add($group);
2226

    
2227
// Prefix delegation
2228
$group = new Form_Group('');
2229

    
2230
$group->add(new Form_Checkbox(
2231
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2232
	null,
2233
	'Prefix Delegation ',
2234
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2235
	'Selected'
2236
));
2237

    
2238
$group->add(new Form_Input(
2239
	'adv_dhcp6_id_assoc_statement_prefix_id',
2240
	null,
2241
	'text',
2242
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2243
))->sethelp('id-assoc pd ID');
2244

    
2245
$group->add(new Form_IpAddress(
2246
	'adv_dhcp6_id_assoc_statement_prefix',
2247
	null,
2248
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2249
))->sethelp('IPv6 prefix');
2250

    
2251
$group->add(new Form_Input(
2252
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2253
	null,
2254
	'text',
2255
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2256
))->sethelp('pltime');
2257

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

    
2265
$section->add($group);
2266

    
2267
$group = new Form_Group('Prefix interface statement');
2268

    
2269
$group->add(new Form_Input(
2270
	'adv_dhcp6_prefix_interface_statement_sla_id',
2271
	null,
2272
	'text',
2273
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2274
))->sethelp('Prefix Interface sla-id');
2275

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

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

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

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

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

    
2301
$group->add(new Form_Input(
2302
	'adv_dhcp6_authentication_statement_algorithm',
2303
	null,
2304
	'text',
2305
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2306
))->sethelp('Algorithm');
2307

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

    
2315
$section->add($group);
2316

    
2317
$group = new Form_Group('Keyinfo statement');
2318

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

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

    
2333
$section->add($group);
2334

    
2335
$group = new Form_Group('');
2336

    
2337
$group->add(new Form_Input(
2338
	'adv_dhcp6_key_info_statement_keyid',
2339
	null,
2340
	'text',
2341
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2342
))->sethelp('KeyID');
2343

    
2344
$group->add(new Form_Input(
2345
	'adv_dhcp6_key_info_statement_secret',
2346
	null,
2347
	'text',
2348
	$pconfig['adv_dhcp6_key_info_statement_secret']
2349
))->sethelp('Secret');
2350

    
2351
$group->add(new Form_Input(
2352
	'adv_dhcp6_key_info_statement_expire',
2353
	null,
2354
	'text',
2355
	$pconfig['adv_dhcp6_key_info_statement_expire']
2356
))->sethelp('Expire');
2357

    
2358
$section->add($group);
2359

    
2360
$form->add($section);
2361

    
2362
$section = new Form_Section('6RD Configuration');
2363
$section->addClass('_6rd');
2364

    
2365
$section->addInput(new Form_Input(
2366
	'prefix-6rd',
2367
	'6RD Prefix',
2368
	'text',
2369
	$pconfig['prefix-6rd']
2370
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2371

    
2372
$section->addInput(new Form_Input(
2373
	'gateway-6rd',
2374
	'6RD Border relay',
2375
	'text',
2376
	$pconfig['gateway-6rd']
2377
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2378

    
2379
$section->addInput(new Form_Select(
2380
	'prefix-6rd-v4plen',
2381
	'6RD IPv4 Prefix length',
2382
	$pconfig['prefix-6rd-v4plen'],
2383
	array_combine(range(0, 32), range(0, 32))
2384
))->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.');
2385

    
2386
$form->add($section);
2387

    
2388
// Track IPv6 ointerface section
2389
$section = new Form_Section('Track IPv6 Interface');
2390
$section->addClass('track6');
2391

    
2392
function build_ipv6interface_list() {
2393
	global $config, $section;
2394

    
2395
	$list = array('' => '');
2396

    
2397
	$interfaces = get_configured_interface_with_descr(false, true);
2398
	$dynv6ifs = array();
2399

    
2400
	foreach ($interfaces as $iface => $ifacename) {
2401
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2402
			case "6to4":
2403
			case "6rd":
2404
			case "dhcp6":
2405
				$dynv6ifs[$iface] = array(
2406
					'name' => $ifacename,
2407
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2408
				);
2409
				break;
2410
			default:
2411
				continue;
2412
		}
2413
	}
2414

    
2415
	foreach ($dynv6ifs as $iface => $ifacedata) {
2416
		$list[$iface] = $ifacedata['name'];
2417

    
2418
		$section->addInput(new Form_Input(
2419
			'ipv6-num-prefix-ids-' . $iface,
2420
			null,
2421
			'hidden',
2422
			$ifacedata['ipv6_num_prefix_ids']
2423
		));
2424
	}
2425

    
2426
	return($list);
2427
}
2428

    
2429
$section->addInput(new Form_Select(
2430
	'track6-interface',
2431
	'IPv6 Interface',
2432
	$pconfig['track6-interface'],
2433
	build_ipv6interface_list()
2434
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2435

    
2436
if ($pconfig['track6-prefix-id'] == "") {
2437
	$pconfig['track6-prefix-id'] = 0;
2438
}
2439

    
2440
$section->addInput(new Form_Input(
2441
	'track6-prefix-id--hex' . $iface,
2442
	'IPv6 Prefix ID',
2443
	'text',
2444
	sprintf("%x", $pconfig['track6-prefix-id'])
2445
))->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.');
2446

    
2447
$section->addInput(new Form_Input(
2448
	'track6-prefix-id-max' . $iface,
2449
	null,
2450
	'hidden',
2451
	0
2452
));
2453

    
2454
$form->add($section);
2455

    
2456
/// PPP section
2457

    
2458
$section = new Form_Section('PPP Configuration');
2459
$section->addClass('ppp');
2460

    
2461
$section->addInput(new Form_Select(
2462
	'country',
2463
	'Country',
2464
	$pconfig['country'],
2465
	[]
2466
));
2467

    
2468
$section->addInput(new Form_Select(
2469
	'provider_list',
2470
	'Provider',
2471
	$pconfig['provider_list'],
2472
	[]
2473
));
2474

    
2475
$section->addInput(new Form_Select(
2476
	'providerplan',
2477
	'Plan',
2478
	$pconfig['providerplan'],
2479
	[]
2480
))->setHelp('Select to fill in data for your service provider.');
2481

    
2482
$section->addInput(new Form_Input(
2483
	'ppp_username',
2484
	'Username',
2485
	'text',
2486
	$pconfig['ppp_username']
2487
));
2488

    
2489
$section->addPassword(new Form_Input(
2490
	'ppp_password',
2491
	'Password',
2492
	'password',
2493
	$pconfig['ppp_password']
2494
));
2495

    
2496
$section->addInput(new Form_Input(
2497
	'phone',
2498
	'Phone number',
2499
	'text',
2500
	$pconfig['phone']
2501
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2502

    
2503
$section->addInput(new Form_Input(
2504
	'apn',
2505
	'Access Point Name',
2506
	'text',
2507
	$pconfig['apn']
2508
));
2509

    
2510

    
2511
function build_port_list() {
2512
	$list = array("" => "None");
2513

    
2514
	$portlist = glob("/dev/cua*");
2515
	$modems	  = glob("/dev/modem*");
2516
	$portlist = array_merge($portlist, $modems);
2517

    
2518
	foreach ($portlist as $port) {
2519
		if (preg_match("/\.(lock|init)$/", $port)) {
2520
			continue;
2521
		}
2522

    
2523
	$list[trim($port)] = $port;
2524
	}
2525

    
2526
	return($list);
2527
}
2528

    
2529
$section->addInput(new Form_Select(
2530
	'port',
2531
	"Modem port",
2532
	$pconfig['port'],
2533
	build_port_list()
2534
));
2535

    
2536
$section->addInput(new Form_Button(
2537
	'btnadvppp',
2538
	'Advanced PPP',
2539
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2540
))->setHelp('Create a new PPP configuration');
2541

    
2542
$form->add($section);
2543

    
2544
// PPPoE configuration
2545
$section = new Form_Section('PPPoE Configuration');
2546
$section->addClass('pppoe');
2547

    
2548
$section->addInput(new Form_Input(
2549
	'pppoe_username',
2550
	'Username',
2551
	'text',
2552
	$pconfig['pppoe_username']
2553
));
2554

    
2555
$section->addPassword(new Form_Input(
2556
	'pppoe_password',
2557
	'Password',
2558
	'password',
2559
	$pconfig['pppoe_password']
2560
));
2561

    
2562
$section->addInput(new Form_Input(
2563
	'provider',
2564
	'Service name',
2565
	'text',
2566
	$pconfig['provider']
2567
))->setHelp('This field can usually be left empty');
2568

    
2569
$section->addInput(new Form_Checkbox(
2570
	'pppoe_dialondemand',
2571
	'Dial on demand',
2572
	'Enable Dial-On-Demand mode ',
2573
	$pconfig['pppoe_dialondemand'],
2574
	'enable'
2575
));
2576

    
2577
$section->addInput(new Form_Input(
2578
	'pppoe_idletimeout',
2579
	'Idle timeout',
2580
	'number',
2581
	$pconfig['pppoe_idletimeout'],
2582
	[min => 0]
2583
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2584
			'An idle timeout of zero disables this feature.');
2585

    
2586
$section->addInput(new Form_Select(
2587
	'pppoe-reset-type',
2588
	'Periodic reset',
2589
	$pconfig['pppoe-reset-type'],
2590
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2591
))->setHelp('Select a reset timing type');
2592

    
2593
$group = new Form_Group('Custom reset');
2594
$group->addClass('pppoecustom');
2595

    
2596
$group->add(new Form_Input(
2597
	'pppoe_resethour',
2598
	null,
2599
	'number',
2600
	$pconfig['pppoe_resethour'],
2601
	[min => 0, max => 23]
2602
))->setHelp('Hour (0-23)');
2603

    
2604
$group->add(new Form_Input(
2605
	'pppoe_resetminute',
2606
	null,
2607
	'number',
2608
	$pconfig['pppoe_resetminute'],
2609
	[min => 0, max => 59]
2610
))->setHelp('Minutes (0-59)');
2611

    
2612
// ToDo: Need a date-picker here
2613
$group->add(new Form_Input(
2614
	'pppoe_resetdate',
2615
	null,
2616
	'text',
2617
	$pconfig['pppoe_resetdate']
2618
))->setHelp('Specific date (mm/dd/yyyy)');
2619

    
2620
$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');
2621

    
2622
$section->add($group);
2623

    
2624
$group = new Form_MultiCheckboxGroup('cron based reset');
2625
$group->addClass('pppoepreset');
2626

    
2627
$group->add(new Form_MultiCheckbox(
2628
	'pppoe_pr_preset_val',
2629
	null,
2630
	'Reset at each month ("0 0 1 * *")',
2631
	$pconfig['pppoe_monthly'],
2632
	'monthly'
2633
))->displayAsRadio();
2634

    
2635
$group->add(new Form_MultiCheckbox(
2636
	'pppoe_pr_preset_val',
2637
	null,
2638
	'Reset at each week ("0 0 * * 0")',
2639
	$pconfig['pppoe_weekly'],
2640
	'weekly'
2641
))->displayAsRadio();
2642

    
2643
$group->add(new Form_MultiCheckbox(
2644
	'pppoe_pr_preset_val',
2645
	null,
2646
	'Reset at each day ("0 0 * * *")',
2647
	$pconfig['pppoe_daily'],
2648
	'daily'
2649
))->displayAsRadio();
2650

    
2651
$group->add(new Form_MultiCheckbox(
2652
	'pppoe_pr_preset_val',
2653
	null,
2654
	'Reset at each hour ("0 * * * *")',
2655
	$pconfig['pppoe_hourly'],
2656
	'hourly'
2657
))->displayAsRadio();
2658

    
2659
$section->add($group);
2660

    
2661
if (isset($pconfig['pppid'])) {
2662
	$section->addInput(new Form_StaticText(
2663
		'Advanced and MLPPP',
2664
		'<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>'
2665
	));
2666
} else {
2667
	$section->addInput(new Form_StaticText(
2668
		'Advanced and MLPPP',
2669
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2670
	));
2671
}
2672

    
2673
$form->add($section);
2674

    
2675
// PPTP & L2TP Configuration section
2676
$section = new Form_Section('PPTP/L2TP Configuration');
2677
$section->addClass('pptp');
2678

    
2679
$section->addInput(new Form_Input(
2680
	'pptp_username',
2681
	'Username',
2682
	'text',
2683
	$pconfig['pptp_username']
2684
));
2685

    
2686
$section->addPassword(new Form_Input(
2687
	'pptp_password',
2688
	'Password',
2689
	'password',
2690
	$pconfig['pptp_password']
2691
));
2692

    
2693
$section->addInput(new Form_IpAddress(
2694
	'pptp_local0',
2695
	'Local IP address',
2696
	$pconfig['pptp_localip'][0]
2697
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2698

    
2699
$section->addInput(new Form_IpAddress(
2700
	'pptp_remote0',
2701
	'Remote IP address',
2702
	$pconfig['pptp_remote'][0]
2703
));
2704

    
2705
$section->addInput(new Form_Checkbox(
2706
	'pptp_dialondemand',
2707
	'Dial on demand',
2708
	'Enable Dial-On-Demand mode ',
2709
	$pconfig['pptp_dialondemand'],
2710
	'enable'
2711
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2712
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2713

    
2714
$section->addInput(new Form_Input(
2715
	'pptp_idletimeout',
2716
	'Idle timeout (seconds)',
2717
	'number',
2718
	$pconfig['pptp_idletimeout'],
2719
	[min => 0]
2720
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2721
			'An idle timeout of zero disables this feature.');
2722

    
2723
if (isset($pconfig['pppid'])) {
2724
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2725
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2726
	} else {
2727
		$mlppp_text = "";
2728
	}
2729

    
2730
	$section->addInput(new Form_StaticText(
2731
		'Advanced and MLPPP',
2732
		$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>'
2733
	));
2734
} else {
2735
	$section->addInput(new Form_StaticText(
2736
		'Advanced and MLPPP',
2737
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2738
	));
2739
}
2740

    
2741
$form->add($section);
2742

    
2743
// Wireless interface
2744
if (isset($wancfg['wireless'])) {
2745

    
2746
	$section = new Form_Section('Common Wireless Configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
2747

    
2748
	$section->addInput(new Form_Checkbox(
2749
		'persistcommonwireless',
2750
		'Persist common settings',
2751
		'Preserve common wireless configuration through interface deletions and reassignments.',
2752
		$pconfig['persistcommonwireless'],
2753
		'yes'
2754
	));
2755

    
2756
	$mode_list = ['auto' => 'Auto'];
2757

    
2758
	if (is_array($wl_modes)) {
2759
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2760
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2761
		}
2762
	}
2763

    
2764
	if (count($mode_list) == 1) {
2765
		$mode_list[''] = '';
2766
	}
2767

    
2768
	$section->addInput(new Form_Select(
2769
		'standard',
2770
		'Standard',
2771
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2772
		$mode_list
2773
	));
2774

    
2775
	if (isset($wl_modes['11g'])) {
2776
		$section->addInput(new Form_Select(
2777
			'protmode',
2778
			'802.11g OFDM Protection Mode',
2779
			$pconfig['protmode'],
2780
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2781
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2782
	} else {
2783
		$section->addInput(new Form_Input(
2784
			'protmode',
2785
			null,
2786
			'hidden',
2787
			'off'
2788
		));
2789
	}
2790

    
2791
	$mode_list = ['0' => gettext('Auto')];
2792

    
2793
	if (is_array($wl_modes)) {
2794
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2795
			if ($wl_standard == "11g") {
2796
				$wl_standard = "11b/g";
2797
			} else if ($wl_standard == "11ng") {
2798
				$wl_standard = "11b/g/n";
2799
			} else if ($wl_standard == "11na") {
2800
				$wl_standard = "11a/n";
2801
			}
2802

    
2803
			foreach ($wl_channels as $wl_channel) {
2804
				if (isset($wl_chaninfo[$wl_channel])) {
2805
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2806
				} else {
2807
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2808
				}
2809
			}
2810
		}
2811
	}
2812

    
2813
	$section->addInput(new Form_Select(
2814
		'channel',
2815
		'Channel',
2816
		$pconfig['channel'],
2817
		$mode_list
2818
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2819
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2820

    
2821
	if (ANTENNAS) {
2822
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2823
			$group = new Form_Group('Antenna Settings');
2824

    
2825
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2826
				$group->add(new Form_Select(
2827
					'diversity',
2828
					null,
2829
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2830
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2831
				))->setHelp('Diversity');
2832
			}
2833

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

    
2843
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2844
				$group->add(new Form_Select(
2845
					'rxantenna',
2846
					null,
2847
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2848
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2849
				))->setHelp('Receive antenna');
2850
			}
2851

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

    
2854
			$section->add($group);
2855
		}
2856
	}
2857

    
2858
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2859
			$section->addInput(new Form_Input(
2860
				'distance',
2861
				'Distance setting (meters)',
2862
				'test',
2863
				$pconfig['distance']
2864
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2865
	}
2866

    
2867
	$form->add($section);
2868

    
2869
	// Regulatory settings
2870
	$section = new Form_Section('Regulatory Settings');
2871

    
2872
	$domain_list = array("" => 'Default');
2873

    
2874
	if (is_array($wl_regdomains)) {
2875
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2876
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2877
		}
2878
	}
2879

    
2880
	$section->addInput(new Form_Select(
2881
		'regdomain',
2882
		'Regulatory domain',
2883
		$pconfig['regdomain'],
2884
		$domain_list
2885
	))->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');
2886

    
2887
	$country_list = array('' => 'Default');
2888

    
2889
	if (is_array($wl_countries)) {
2890
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2891
			$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']);
2892
		}
2893
	}
2894

    
2895
	$section->addInput(new Form_Select(
2896
		'regcountry',
2897
		'Country',
2898
		$pconfig['regcountry'],
2899
		$country_list
2900
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2901

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

    
2913
	$form->add($section);
2914

    
2915
	$section = new Form_Section('Network-Specific Wireless Configuration');
2916

    
2917
	$section->addInput(new Form_Select(
2918
		'mode',
2919
		'Mode',
2920
		$pconfig['mode'],
2921
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2922
	));
2923

    
2924
	$section->addInput(new Form_Input(
2925
		'ssid',
2926
		'SSID',
2927
		'text',
2928
		$pconfig['ssid']
2929
	));
2930

    
2931
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2932
		$section->addInput(new Form_Select(
2933
			'puremode',
2934
			'Minimum wireless standard',
2935
			$pconfig['puremode'],
2936
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2937
		))->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)');
2938
	} elseif (isset($wl_modes['11g'])) {
2939
		$section->addInput(new Form_Checkbox(
2940
			'puremode',
2941
			'802.11g only',
2942
			null,
2943
			$pconfig['puremode'],
2944
			'11g'
2945
		))->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)');
2946
	}
2947

    
2948
	$section->addInput(new Form_Checkbox(
2949
		'apbridge_enable',
2950
		'Allow intra-BSS communication',
2951
		'Allow packets to pass between wireless clients directly when operating as an access point',
2952
		$pconfig['apbridge_enable'],
2953
		'yes'
2954
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2955

    
2956
	$section->addInput(new Form_Checkbox(
2957
		'wme_enable',
2958
		'Enable WME',
2959
		'Force the card to use WME (wireless QoS)',
2960
		$pconfig['wme_enable'],
2961
		'yes'
2962
	));
2963

    
2964
	$section->addInput(new Form_Checkbox(
2965
		'hidessid_enable',
2966
		'Hide SSID',
2967
		'Disable broadcasting of the SSID for this network (This may cause problems for some clients, and the SSID may still be discovered by other means.)',
2968
		$pconfig['hidessid_enable'],
2969
		'yes'
2970
	));
2971

    
2972
	$form->add($section);
2973

    
2974
	// WPA Section
2975
	$section = new Form_Section('WPA');
2976

    
2977
	$section->addInput(new Form_Checkbox(
2978
		'wpa_enable',
2979
		'Enable',
2980
		'Enable WPA',
2981
		$pconfig['wpa_enable'],
2982
		'yes'
2983
	));
2984

    
2985
	$section->addInput(new Form_Input(
2986
		'passphrase',
2987
		'WPA Pre-Shared Key',
2988
		'text',
2989
		$pconfig['passphrase']
2990
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2991

    
2992
	$section->addInput(new Form_Select(
2993
		'wpa_mode',
2994
		'WPA mode',
2995
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2996
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
2997
	));
2998

    
2999
	$section->addInput(new Form_Select(
3000
		'wpa_key_mgmt',
3001
		'WPA Key Management Mode',
3002
		$pconfig['wpa_key_mgmt'],
3003
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3004
	));
3005

    
3006
	$section->addInput(new Form_Select(
3007
		'wpa_pairwise',
3008
		'WPA Pairwise',
3009
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3010
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3011
	));
3012

    
3013
	$section->addInput(new Form_Input(
3014
		'wpa_group_rekey',
3015
		'Group Key Rotation',
3016
		'number',
3017
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3018
		['min' => '1', 'max' => 9999]
3019
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3020

    
3021
	$section->addInput(new Form_Input(
3022
		'wpa_gmk_rekey',
3023
		'Group Master Key Regeneration',
3024
		'number',
3025
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3026
		['min' => '1', 'max' => 9999]
3027
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3028

    
3029
	$section->addInput(new Form_Checkbox(
3030
		'wpa_strict_rekey',
3031
		'Strict Key Regeneration',
3032
		'Force the AP to rekey whenever a client disassociates',
3033
		$pconfig['wpa_strict_rekey'],
3034
		'yes'
3035
	));
3036

    
3037
	$form->add($section);
3038

    
3039
	$section = new Form_Section('802.1x RADIUS Options');
3040

    
3041
	$section->addInput(new Form_Checkbox(
3042
		'ieee8021x',
3043
		'IEEE802.1X',
3044
		'Enable 802.1X authentication',
3045
		$pconfig['ieee8021x'],
3046
		'yes'
3047
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3048

    
3049
	$group = new Form_Group('Primary 802.1X server');
3050

    
3051
	$group->add(new Form_IpAddress(
3052
		'auth_server_addr',
3053
		'IP Address',
3054
		$pconfig['auth_server_addr']
3055
	))->setHelp('IP address of the RADIUS server');
3056

    
3057
	$group->add(new Form_Input(
3058
		'auth_server_port',
3059
		'Port',
3060
		'number',
3061
		$pconfig['auth_server_port']
3062
	))->setHelp('Server auth port. Default is 1812');
3063

    
3064
	$group->add(new Form_Input(
3065
		'auth_server_shared_secret',
3066
		'Shared Secret',
3067
		'number',
3068
		$pconfig['auth_server_shared_secret']
3069
	))->setHelp('RADIUS Shared secret for this firewall');
3070

    
3071
	$section->add($group);
3072

    
3073
	$group = new Form_Group('Secondary 802.1X server');
3074

    
3075
	$group->add(new Form_IpAddress(
3076
		'auth_server_addr2',
3077
		'IP Address',
3078
		$pconfig['auth_server_addr2']
3079
	))->setHelp('IP address of the RADIUS server');
3080

    
3081
	$group->add(new Form_Input(
3082
		'auth_server_port2',
3083
		'Port',
3084
		'number',
3085
		$pconfig['auth_server_port2']
3086
	))->setHelp('Server auth port. Default is 1812');
3087

    
3088
	$group->add(new Form_Input(
3089
		'auth_server_shared_secret2',
3090
		'Shared Secret',
3091
		'number',
3092
		$pconfig['auth_server_shared_secret2']
3093
	))->setHelp('RADIUS Shared secret for this firewall');
3094

    
3095
	$section->add($group);
3096

    
3097
	$section->addInput(new Form_Checkbox(
3098
		'rsn_preauth',
3099
		'Authentication Roaming Preauth',
3100
		null,
3101
		$pconfig['rsn_preauth'],
3102
		'yes'
3103
	));
3104

    
3105
	$form->add($section);
3106
}
3107

    
3108
$section = new Form_Section('Private Networks');
3109

    
3110
$section->addInput(new Form_Checkbox(
3111
	'blockpriv',
3112
	'Block private networks',
3113
	'',
3114
	$pconfig['blockpriv'],
3115
	'yes'
3116
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3117
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3118
			'lies in such a private address space, too.');
3119

    
3120
$section->addInput(new Form_Checkbox(
3121
	'blockbogons',
3122
	'Block bogon networks',
3123
	'',
3124
	$pconfig['blockbogons'],
3125
	'yes'
3126
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3127
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3128
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3129

    
3130
$form->add($section);
3131

    
3132
$form->addGlobal(new Form_Input(
3133
	'if',
3134
	null,
3135
	'hidden',
3136
	$if
3137
));
3138

    
3139
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3140
	$form->addGlobal(new Form_Input(
3141
		'ppp_port',
3142
		null,
3143
		'hidden',
3144
		$pconfig['port']
3145
	));
3146
}
3147

    
3148
$form->addGlobal(new Form_Input(
3149
	'ptpid',
3150
	null,
3151
	'hidden',
3152
	$pconfig['ptpid']
3153
));
3154

    
3155

    
3156
// Add new gateway modal pop-up
3157
$modal = new Modal('New Gateway', 'newgateway', 'large');
3158

    
3159
$modal->addInput(new Form_Checkbox(
3160
	'defaultgw',
3161
	'Default',
3162
	'Default gateway',
3163
	($if == "wan" || $if == "WAN")
3164
));
3165

    
3166
$modal->addInput(new Form_Input(
3167
	'name',
3168
	'Gateway name',
3169
	'text',
3170
	$wancfg['descr'] . "GW"
3171
));
3172

    
3173
$modal->addInput(new Form_IpAddress(
3174
	'gatewayip',
3175
	'Gateway IPv4',
3176
	null
3177
));
3178

    
3179
$modal->addInput(new Form_Input(
3180
	'gatewaydescr',
3181
	'Description',
3182
	'text'
3183
));
3184

    
3185
$btnaddgw = new Form_Button(
3186
	'add',
3187
	'Add'
3188
);
3189

    
3190
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3191

    
3192
$btncnxgw = new Form_Button(
3193
	'cnx',
3194
	'Cancel'
3195
);
3196

    
3197
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3198

    
3199
$modal->addInput(new Form_StaticText(
3200
	null,
3201
	$btnaddgw . $btncnxgw
3202
));
3203

    
3204
$form->add($modal);
3205

    
3206
print($form);
3207
?>
3208

    
3209
<script type="text/javascript">
3210
//<![CDATA[
3211
events.push(function() {
3212
	function updateType(t) {
3213

    
3214
		switch (t) {
3215
			case "none": {
3216
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3217
				break;
3218
			}
3219
			case "staticv4": {
3220
				$('.dhcpadvanced, .none, .dhcp').hide();
3221
				$('.pppoe, .pptp, .ppp').hide();
3222
				break;
3223
			}
3224
			case "dhcp": {
3225
				$('.dhcpadvanced, .none').hide();
3226
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3227
										//			about the staticv4 class
3228
				$('.pppoe, .pptp, .ppp').hide();
3229
				break;
3230
			}
3231
			case "ppp": {
3232
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3233
				country_list();
3234
				break;
3235
			}
3236
			case "pppoe": {
3237
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3238
				break;
3239
			}
3240
			case "l2tp":
3241
			case "pptp": {
3242
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3243
				$('.pptp').show();
3244
				break;
3245
			}
3246
		}
3247

    
3248
		if (t != "l2tp" && t != "pptp") {
3249
			$('.'+t).show();
3250
		}
3251
	}
3252

    
3253
	function updateTypeSix(t) {
3254
		if (!isNaN(t[0])) {
3255
			t = '_' + t;
3256
		}
3257

    
3258
		switch (t) {
3259
			case "none": {
3260
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3261
				break;
3262
			}
3263
			case "staticv6": {
3264
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3265
				break;
3266
			}
3267
			case "slaac": {
3268
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3269
				break;
3270
			}
3271
			case "dhcp6": {
3272
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3273
				break;
3274
			}
3275
			case "6rd_": {
3276
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3277
				break;
3278
			}
3279
			case "_6to4": {
3280
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3281
				break;
3282
			}
3283
			case "track6": {
3284
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3285
				update_track6_prefix();
3286
				break;
3287
			}
3288
		}
3289

    
3290
		if (t != "l2tp" && t != "pptp") {
3291
			$('.'+t).show();
3292
		}
3293
	}
3294

    
3295
	function show_reset_settings(reset_type) {
3296
		if (reset_type == 'preset') {
3297
			$('.pppoepreset').show();
3298
			$('.pppoecustom').hide();
3299
		} else if (reset_type == 'custom') {
3300
			$('.pppoecustom').show();
3301
			$('.pppoepreset').hide();
3302
		} else {
3303
			$('.pppoecustom').hide();
3304
			$('.pppoepreset').hide();
3305
		}
3306
	}
3307

    
3308
	function update_track6_prefix() {
3309
		var iface = $("#track6-interface").val();
3310
		if (iface == null) {
3311
			return;
3312
		}
3313

    
3314
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3315
		if (track6_prefix_ids == null) {
3316
			return;
3317
		}
3318

    
3319
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3320
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3321
	}
3322

    
3323
	// Create the new gateway from the data entered in the modal pop-up
3324
	function hide_add_gatewaysave() {
3325
		var iface = $('#if').val();
3326
		name = $('#name').val();
3327
		var descr = $('#gatewaydescr').val();
3328
		gatewayip = $('#gatewayip').val();
3329

    
3330
		var defaultgw = '';
3331
		if ($('#defaultgw').is(':checked')) {
3332
			defaultgw = '&defaultgw=on';
3333
		}
3334

    
3335
		var url = "system_gateways_edit.php";
3336
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3337
		$.ajax(
3338
			url,
3339
			{
3340
				type: 'post',
3341
				data: pars,
3342
				error: report_failure,
3343
				complete: save_callback
3344
			});
3345
		}
3346

    
3347
	function save_callback(response) {
3348
		if (response) {
3349
			var gwtext = escape(name) + " - " + gatewayip;
3350
			addOption($('#gateway'), gwtext, name);
3351
		} else {
3352
			report_failure();
3353
		}
3354

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

    
3358
	function report_failure(request, textStatus, errorThrown) {
3359
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3360
			alert(request.responseText);
3361
		} else {
3362
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3363
		}
3364

    
3365
		$("#newgateway").modal('hide');
3366
	}
3367

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

    
3376
	function hide_add_gatewaysave_v6() {
3377

    
3378
		var iface = $('#if').val();
3379
		name = $('#name6').val();
3380
		var descr = $('#gatewaydescr6').val();
3381
		gatewayip = $('#gatewayip6').val();
3382
		var defaultgw = '';
3383
		if ($('#defaultgw6').is(':checked')) {
3384
			defaultgw = '&defaultgw=on';
3385
		}
3386
		var url_v6 = "system_gateways_edit.php";
3387
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3388
		$.ajax(
3389
			url_v6,
3390
			{
3391
				type: 'post',
3392
				data: pars_v6,
3393
				error: report_failure_v6,
3394
				success: save_callback_v6
3395
			});
3396
	}
3397

    
3398

    
3399
	function addOption_v6(selectbox, text, value) {
3400
		var optn = document.createElement("OPTION");
3401
		optn.text = text;
3402
		optn.value = value;
3403
		selectbox.append(optn);
3404
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3405
	}
3406

    
3407
	function report_failure_v6(request, textStatus, errorThrown) {
3408
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3409
			alert(request.responseText);
3410
		} else {
3411
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3412
		}
3413

    
3414
		$("#newgateway6").modal('hide');
3415
	}
3416

    
3417
	function save_callback_v6(response_v6) {
3418
		if (response_v6) {
3419

    
3420
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3421
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3422
		} else {
3423
			report_failure_v6();
3424
		}
3425

    
3426
		$("#newgateway6").modal('hide');
3427
	}
3428

    
3429
	function country_list() {
3430
		$('#country').children().remove();
3431
		$('#provider_list').children().remove();
3432
		$('#providerplan').children().remove();
3433
		$.ajax("getserviceproviders.php",{
3434
			success: function(response) {
3435

    
3436
				var responseTextArr = response.split("\n");
3437
				responseTextArr.sort();
3438

    
3439
				responseTextArr.forEach( function(value) {
3440
					country = value.split(":");
3441
					$('#country').append($('<option>', {
3442
						value: country[1],
3443
						text : country[0]
3444
					}));
3445
				});
3446
			}
3447
		});
3448
	}
3449

    
3450
	function providers_list() {
3451
		$('#provider_list').children().remove();
3452
		$('#providerplan').children().remove();
3453
		$.ajax("getserviceproviders.php",{
3454
			type: 'post',
3455
			data: {country : $('#country').val()},
3456
			success: function(response) {
3457
				var responseTextArr = response.split("\n");
3458
				responseTextArr.sort();
3459
				responseTextArr.forEach( function(value) {
3460
					$('#provider_list').append($('<option>', {
3461
							value: value,
3462
							text : value
3463
					}));
3464
				});
3465
			}
3466
		});
3467
	}
3468

    
3469
	function providerplan_list() {
3470
		$('#providerplan').children().remove();
3471
		$.ajax("getserviceproviders.php",{
3472
			type: 'post',
3473
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3474
			success: function(response) {
3475
				var responseTextArr = response.split("\n");
3476
				responseTextArr.sort();
3477

    
3478
				$('#providerplan').append($('<option>', {
3479
					value: '',
3480
					text : ''
3481
				}));
3482

    
3483
				responseTextArr.forEach( function(value) {
3484
					if (value != "") {
3485
						providerplan = value.split(":");
3486

    
3487
						$('#providerplan').append($('<option>', {
3488
							value: providerplan[1],
3489
							text : providerplan[0] + " - " + providerplan[1]
3490
						}));
3491
					}
3492
				});
3493
			}
3494
		});
3495
	}
3496

    
3497
	function prefill_provider() {
3498
		$.ajax("getserviceproviders.php",{
3499
			type: 'post',
3500
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3501
			success: function(data, textStatus, response) {
3502
				var xmldoc = response.responseXML;
3503
				var provider = xmldoc.getElementsByTagName('connection')[0];
3504
				$('#ppp_username').val('');
3505
				$('#ppp_password').val('');
3506
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3507
					$('#phone').val('#777');
3508
					$('#apn').val('');
3509
				} else {
3510
					$('#phone').val('*99#');
3511
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3512
				}
3513
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3514
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3515
				$('#ppp_username').val(ppp_username);
3516
				$('#ppp_password').val(ppp_password);
3517
			}
3518
		});
3519
	}
3520

    
3521
	function show_dhcp6adv() {
3522
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3523
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3524

    
3525
		hideCheckbox('dhcp6usev4iface', ovr);
3526
		hideCheckbox('dhcp6prefixonly', ovr);
3527
		hideInput('dhcp6-ia-pd-len', ovr);
3528
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3529
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3530

    
3531
		hideClass('dhcp6advanced', !adv || ovr);
3532
	}
3533

    
3534
	function setDHCPoptions() {
3535
		var adv = $('#dhcpadv').prop('checked');
3536
		var ovr = $('#dhcpovr').prop('checked');
3537

    
3538
		if (ovr) {
3539
			hideInput('dhcphostname', true);
3540
			hideIpAddress('alias-address', true);
3541
			hideInput('dhcprejectfrom', true);
3542
			hideInput('adv_dhcp_config_file_override_path', false);
3543
			hideClass('dhcpadvanced', true);
3544
		} else {
3545
			hideInput('dhcphostname', false);
3546
			hideIpAddress('alias-address', false);
3547
			hideInput('dhcprejectfrom', false);
3548
			hideInput('adv_dhcp_config_file_override_path', true);
3549
			hideClass('dhcpadvanced', !adv);
3550
		}
3551
	}
3552

    
3553
	// DHCP preset actions
3554
	// Set presets from value of radio buttons
3555
	function setPresets(val) {
3556
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3557
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3558
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3559
		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']);?>");
3560
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3561
	}
3562

    
3563
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3564
		$('#adv_dhcp_pt_timeout').val(timeout);
3565
		$('#adv_dhcp_pt_retry').val(retry);
3566
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3567
		$('#adv_dhcp_pt_reboot').val(reboot);
3568
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3569
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3570
	}
3571

    
3572
	// ---------- On initial page load ------------------------------------------------------------
3573

    
3574
	updateType($('#type').val());
3575
	updateTypeSix($('#type6').val());
3576
	show_reset_settings($('#pppoe-reset-type').val());
3577
	$("#add").prop('type', 'button');
3578
	$("#cnx").prop('type', 'button');
3579
	$("#addgw").prop('type', 'button');
3580
	$("#add6").prop('type', 'button');
3581
	$("#cnx6").prop('type', 'button');
3582
	$("#addgw6").prop('type', 'button');
3583
	hideClass('dhcp6advanced', true);
3584
	hideClass('dhcpadvanced', true);
3585
	show_dhcp6adv();
3586
	setDHCPoptions()
3587

    
3588
	// Set preset buttons on page load
3589
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3590
	if (sv == "") {
3591
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3592
	} else {
3593
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3594
	}
3595

    
3596
	// Set preset from value
3597
	setPresets(sv);
3598

    
3599
	// ---------- Click checkbox handlers ---------------------------------------------------------
3600

    
3601
	$('#type').on('change', function() {
3602
		updateType(this.value);
3603
	});
3604

    
3605
	$('#type6').on('change', function() {
3606
		updateTypeSix(this.value);
3607
	});
3608

    
3609
	$('#pppoe-reset-type').on('change', function() {
3610
		show_reset_settings(this.value);
3611
	});
3612

    
3613
	$("#add").click(function() {
3614
		hide_add_gatewaysave();
3615
	});
3616

    
3617
	$("#cnx").click(function() {
3618
		$("#newgateway").modal('hide');
3619
	});
3620

    
3621
	$("#add6").click(function() {
3622
		hide_add_gatewaysave_v6();
3623
	});
3624

    
3625
	$("#cnx6").click(function() {
3626
		$("#newgateway6").modal('hide');
3627
	});
3628

    
3629
	$('#country').on('change', function() {
3630
		providers_list();
3631
	});
3632

    
3633
	$('#provider_list').on('change', function() {
3634
		providerplan_list();
3635
	});
3636

    
3637
	$('#providerplan').on('change', function() {
3638
		prefill_provider();
3639
	});
3640

    
3641
	$('#dhcpadv, #dhcpovr').click(function () {
3642
		setDHCPoptions();
3643
	});
3644

    
3645
	$('#adv_dhcp6_config_advanced').click(function () {
3646
		show_dhcp6adv();
3647
	});
3648

    
3649
	$('#adv_dhcp6_config_file_override').click(function () {
3650
		show_dhcp6adv();
3651
	});
3652

    
3653
	// On click . .
3654
	$('[name=adv_dhcp_pt_values]').click(function () {
3655
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3656
	});
3657

    
3658
});
3659
//]]>
3660
</script>
3661

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