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
		break;
320
	case "6to4":
321
		$pconfig['type6'] = "6to4";
322
		break;
323
	case "track6":
324
		$pconfig['type6'] = "track6";
325
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
326
		if ($wancfg['track6-prefix-id'] == "") {
327
			$pconfig['track6-prefix-id'] = 0;
328
		} else {
329
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
330
		}
331
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
332
		break;
333
	case "6rd":
334
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
335
		if ($wancfg['prefix-6rd-v4plen'] == "") {
336
			$wancfg['prefix-6rd-v4plen'] = "0";
337
		}
338
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
339
		$pconfig['type6'] = "6rd";
340
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
341
		break;
342
	default:
343
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
344
			$pconfig['type6'] = "staticv6";
345
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
346
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
347
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
348
		} else {
349
			$pconfig['type6'] = "none";
350
		}
351
		break;
352
}
353

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

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

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

    
438
}
439

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

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

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

    
469
		clear_subsystem_dirty('interfaces');
470

    
471
		filter_configure();
472

    
473
		enable_rrd_graphing();
474

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

    
502
	unset($input_errors);
503
	$pconfig = $_POST;
504

    
505
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
506
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
507
	} else {
508
		$pconfig['track6-prefix-id'] = 0;
509
	}
510
	conf_mount_rw();
511

    
512
	/* filter out spaces from descriptions */
513
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
514

    
515
	/* okay first of all, cause we are just hiding the PPPoE HTML
516
	 * fields related to PPPoE resets, we are going to unset $_POST
517
	 * vars, if the reset feature should not be used. Otherwise the
518
	 * data validation procedure below, may trigger a false error
519
	 * message.
520
	 */
521
	if (empty($_POST['pppoe-reset-type'])) {
522
		unset($_POST['pppoe_pr_type']);
523
		unset($_POST['pppoe_resethour']);
524
		unset($_POST['pppoe_resetminute']);
525
		unset($_POST['pppoe_resetdate']);
526
		unset($_POST['pppoe_pr_preset_val']);
527
	}
528
	/* description unique? */
529
	foreach ($ifdescrs as $ifent => $ifdescr) {
530
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
531
			$input_errors[] = gettext("An interface with the specified description already exists.");
532
			break;
533
		}
534
	}
535

    
536
	/* Is the description already used as an alias name? */
537
	if (is_array($config['aliases']['alias'])) {
538
		foreach ($config['aliases']['alias'] as $alias) {
539
			if ($alias['name'] == $_POST['descr']) {
540
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
541
			}
542
		}
543
	}
544

    
545
	/* Is the description already used as an interface group name? */
546
	if (is_array($config['ifgroups']['ifgroupentry'])) {
547
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
548
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
549
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
550
			}
551
		}
552
	}
553

    
554
	if (is_numeric($_POST['descr'])) {
555
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
556
	}
557
	/* input validation */
558
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
559
		$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.");
560
	}
561
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
562
		$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.");
563
	}
564

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

    
672
			if (empty($_POST['track6-interface'])) {
673
				$input_errors[] = gettext("You have to select a valid interface to track.");
674
			}
675

    
676
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
677
				$input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID.");
678
			} else {
679
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
680
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
681
					$input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range.") .
682
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
683
				} else {
684
					foreach ($ifdescrs as $ifent => $ifdescr) {
685
						if ($if == $ifent) {
686
							continue;
687
						}
688
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
689
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
690
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
691
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
692
						}
693
					}
694
				}
695
			}
696
			break;
697
	}
698

    
699
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
700
	$staticroutes = get_staticroutes(true);
701
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
702
	if ($_POST['ipaddr']) {
703
		if (!is_ipaddrv4($_POST['ipaddr'])) {
704
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
705
		} else {
706
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
707
			if (count($where_ipaddr_configured)) {
708
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
709
				foreach ($where_ipaddr_configured as $subnet_conflict) {
710
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
711
				}
712
				$input_errors[] = $subnet_conflict_text;
713
			}
714

    
715
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
716
			if ($_POST['subnet'] < 31) {
717
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
718
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
719
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
720
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
721
				}
722
			}
723

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

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

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

    
839
		unset($min_mtu, $max_mtu);
840

    
841
		if (stristr($wancfg['if'], "_vlan")) {
842
			$realhwif_array = get_parent_interface($wancfg['if']);
843
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
844
			$parent_realhwif = $realhwif_array[0];
845
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
846
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu'])) {
847
				if ($_POST['mtu'] > intval($config['interfaces'][$parent_if]['mtu'])) {
848
					$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
849
				}
850
			}
851
		} else {
852
			foreach ($config['interfaces'] as $idx => $ifdata) {
853
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
854
					continue;
855
				}
856

    
857
				$realhwif_array = get_parent_interface($ifdata['if']);
858
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
859
				$parent_realhwif = $realhwif_array[0];
860

    
861
				if ($parent_realhwif != $wancfg['if']) {
862
					continue;
863
				}
864

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

    
952
		if ($_POST['passphrase']) {
953
			$passlen = strlen($_POST['passphrase']);
954
			if ($passlen < 8 || $passlen > 63) {
955
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
956
			}
957
		}
958

    
959
		if ($_POST['wpa_enable'] == "yes") {
960
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
961
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
962
			}
963
		}
964
	}
965

    
966
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
967
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
968
	}
969

    
970
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
971
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
972
	}
973

    
974
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
975
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
976
	}
977

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

    
985
		if ($wancfg['ipaddr'] != $_POST['type']) {
986
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
987
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
988
				unset($a_ppps[$pppid]);
989
			} else if ($wancfg['ipaddr'] == "dhcp") {
990
				kill_dhclient_process($wancfg['if']);
991
			}
992
			if ($wancfg['ipaddrv6'] == "dhcp6") {
993
				$pid = find_dhcp6c_process($wancfg['if']);
994
				if ($pid) {
995
					posix_kill($pid, SIGTERM);
996
				}
997
			}
998
		}
999
		$ppp = array();
1000
		if ($wancfg['ipaddr'] != "ppp") {
1001
			unset($wancfg['ipaddr']);
1002
		}
1003
		if ($wancfg['ipaddrv6'] != "ppp") {
1004
			unset($wancfg['ipaddrv6']);
1005
		}
1006
		unset($wancfg['subnet']);
1007
		unset($wancfg['gateway']);
1008
		unset($wancfg['subnetv6']);
1009
		unset($wancfg['gatewayv6']);
1010
		unset($wancfg['dhcphostname']);
1011
		unset($wancfg['dhcprejectfrom']);
1012
		unset($wancfg['dhcp6-duid']);
1013
		unset($wancfg['dhcp6-ia-pd-len']);
1014
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1015
		unset($wancfg['dhcp6prefixonly']);
1016
		unset($wancfg['dhcp6usev4iface']);
1017
		unset($wancfg['track6-interface']);
1018
		unset($wancfg['track6-prefix-id']);
1019
		unset($wancfg['prefix-6rd']);
1020
		unset($wancfg['prefix-6rd-v4plen']);
1021
		unset($wancfg['gateway-6rd']);
1022

    
1023
		unset($wancfg['adv_dhcp_pt_timeout']);
1024
		unset($wancfg['adv_dhcp_pt_retry']);
1025
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1026
		unset($wancfg['adv_dhcp_pt_reboot']);
1027
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1028
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1029

    
1030
		unset($wancfg['adv_dhcp_pt_values']);
1031

    
1032
		unset($wancfg['adv_dhcp_send_options']);
1033
		unset($wancfg['adv_dhcp_request_options']);
1034
		unset($wancfg['adv_dhcp_required_options']);
1035
		unset($wancfg['adv_dhcp_option_modifiers']);
1036

    
1037
		unset($wancfg['adv_dhcp_config_advanced']);
1038
		unset($wancfg['adv_dhcp_config_file_override']);
1039
		unset($wancfg['adv_dhcp_config_file_override_path']);
1040

    
1041
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1042
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1043
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1044
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1045

    
1046
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1047
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1048
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1049
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1050
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1051

    
1052
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1053
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1054
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1055
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1056
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1057

    
1058
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1059
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1060

    
1061
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1062
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1063
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1064
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1065

    
1066
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1067
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1068
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1069
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1070
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1071

    
1072
		unset($wancfg['adv_dhcp6_config_advanced']);
1073
		unset($wancfg['adv_dhcp6_config_file_override']);
1074
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1075

    
1076
		unset($wancfg['pppoe_password']);
1077
		unset($wancfg['pptp_username']);
1078
		unset($wancfg['pptp_password']);
1079
		unset($wancfg['provider']);
1080
		unset($wancfg['ondemand']);
1081
		unset($wancfg['timeout']);
1082
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1083
			unset($wancfg['pppoe']['pppoe-reset-type']);
1084
		}
1085
		unset($wancfg['local']);
1086

    
1087
		unset($wancfg['remote']);
1088
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1089
			if ($wancfg['ipaddr'] != 'ppp') {
1090
				unset($a_ppps[$pppid]['apn']);
1091
				unset($a_ppps[$pppid]['phone']);
1092
				unset($a_ppps[$pppid]['provider']);
1093
				unset($a_ppps[$pppid]['ondemand']);
1094
			}
1095
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1096
				unset($a_ppps[$pppid]['localip']);
1097
				unset($a_ppps[$pppid]['subnet']);
1098
				unset($a_ppps[$pppid]['gateway']);
1099
			}
1100
			if ($wancfg['ipaddr'] != 'pppoe') {
1101
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1102
			}
1103
			if ($wancfg['type'] != $_POST['type']) {
1104
				unset($a_ppps[$pppid]['idletimeout']);
1105
			}
1106
		}
1107

    
1108
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1109
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1110

    
1111
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1112
		switch ($_POST['type']) {
1113
			case "staticv4":
1114
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1115
				$wancfg['subnet'] = $_POST['subnet'];
1116
				if ($_POST['gateway'] != "none") {
1117
					$wancfg['gateway'] = $_POST['gateway'];
1118
				}
1119
				break;
1120
			case "dhcp":
1121
				$wancfg['ipaddr'] = "dhcp";
1122
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1123
				$wancfg['alias-address'] = $_POST['alias-address'];
1124
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1125
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1126

    
1127
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1128
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1129
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1130
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1131
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1132
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1133

    
1134
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1135

    
1136
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1137
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1138
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1139
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1140

    
1141
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1142
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1143
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1144

    
1145
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1146
				if ($gateway_item) {
1147
					$a_gateways[] = $gateway_item;
1148
				}
1149
				break;
1150
			case "ppp":
1151
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1152
				$a_ppps[$pppid]['type'] = $_POST['type'];
1153
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1154
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1155
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1156
				if ($_POST['ppp_password'] != DMYPWD) {
1157
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1158
				}
1159
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1160
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1161
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1162
				$wancfg['ipaddr'] = $_POST['type'];
1163
				break;
1164

    
1165
			case "pppoe":
1166
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1167
				$a_ppps[$pppid]['type'] = $_POST['type'];
1168
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1169
				if (isset($_POST['ppp_port'])) {
1170
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1171
				} else {
1172
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1173
				}
1174
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1175
				if ($_POST['pppoe_password'] != DMYPWD) {
1176
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1177
				}
1178
				if (!empty($_POST['provider'])) {
1179
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1180
				} else {
1181
					$a_ppps[$pppid]['provider'] = true;
1182
				}
1183
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1184
				if (!empty($_POST['pppoe_idletimeout'])) {
1185
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1186
				} else {
1187
					unset($a_ppps[$pppid]['idletimeout']);
1188
				}
1189

    
1190
				if (!empty($_POST['pppoe-reset-type'])) {
1191
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1192
				} else {
1193
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1194
				}
1195
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1196
				$wancfg['ipaddr'] = $_POST['type'];
1197
				if ($gateway_item) {
1198
					$a_gateways[] = $gateway_item;
1199
				}
1200

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

    
1263
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1264
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1265
				}
1266
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1267
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1268
				}
1269
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1270
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1271
				}
1272
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1273
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1274
				}
1275

    
1276
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1277
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1278
				}
1279
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1280
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1281
				}
1282
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1283
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1284
				}
1285
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1286
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1287
				}
1288
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1289
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1290
				}
1291

    
1292
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1293
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1294
				}
1295
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1296
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1297
				}
1298
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1299
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1300
				}
1301
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1302
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1303
				}
1304
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1305
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1306
				}
1307

    
1308
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1309
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1310
				}
1311
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1312
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1313
				}
1314

    
1315
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1316
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1317
				}
1318
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1319
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1320
				}
1321
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1322
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1323
				}
1324
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1325
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1326
				}
1327

    
1328
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1329
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1330
				}
1331
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1332
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1333
				}
1334
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1335
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1336
				}
1337
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1338
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1339
				}
1340
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1341
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1342
				}
1343

    
1344
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1345
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1346
				}
1347
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1348
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1349
				}
1350
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1351
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1352
				}
1353

    
1354
				if ($gateway_item) {
1355
					$a_gateways[] = $gateway_item;
1356
				}
1357
				break;
1358
			case "6rd":
1359
				$wancfg['ipaddrv6'] = "6rd";
1360
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1361
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1362
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1363
				if ($gateway_item) {
1364
					$a_gateways[] = $gateway_item;
1365
				}
1366
				break;
1367
			case "6to4":
1368
				$wancfg['ipaddrv6'] = "6to4";
1369
				break;
1370
			case "track6":
1371
				$wancfg['ipaddrv6'] = "track6";
1372
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1373
				if ($_POST['track6-prefix-id--hex'] === "") {
1374
					$wancfg['track6-prefix-id'] = 0;
1375
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1376
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1377
				} else {
1378
					$wancfg['track6-prefix-id'] = 0;
1379
				}
1380
				break;
1381
			case "none":
1382
				break;
1383
		}
1384
		handle_pppoe_reset($_POST);
1385

    
1386
		if ($_POST['blockpriv'] == "yes") {
1387
			$wancfg['blockpriv'] = true;
1388
		} else {
1389
			unset($wancfg['blockpriv']);
1390
		}
1391
		if ($_POST['blockbogons'] == "yes") {
1392
			$wancfg['blockbogons'] = true;
1393
		} else {
1394
			unset($wancfg['blockbogons']);
1395
		}
1396
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1397
		if (empty($_POST['mtu'])) {
1398
			unset($wancfg['mtu']);
1399
		} else {
1400
			$wancfg['mtu'] = $_POST['mtu'];
1401
		}
1402
		if (empty($_POST['mss'])) {
1403
			unset($wancfg['mss']);
1404
		} else {
1405
			$wancfg['mss'] = $_POST['mss'];
1406
		}
1407
		if (empty($_POST['mediaopt'])) {
1408
			unset($wancfg['media']);
1409
			unset($wancfg['mediaopt']);
1410
		} else {
1411
			$mediaopts = explode(' ', $_POST['mediaopt']);
1412
			if ($mediaopts[0] != '') {
1413
				$wancfg['media'] = $mediaopts[0];
1414
			}
1415
			if ($mediaopts[1] != '') {
1416
				$wancfg['mediaopt'] = $mediaopts[1];
1417
			} else {
1418
				unset($wancfg['mediaopt']);
1419
			}
1420
		}
1421
		if (isset($wancfg['wireless'])) {
1422
			handle_wireless_post();
1423
		}
1424

    
1425
		conf_mount_ro();
1426
		write_config();
1427

    
1428
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1429
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1430
		} else {
1431
			$toapplylist = array();
1432
		}
1433
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1434
		$toapplylist[$if]['ppps'] = $old_ppps;
1435
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1436

    
1437
		mark_subsystem_dirty('interfaces');
1438

    
1439
		/* regenerate cron settings/crontab file */
1440
		configure_cron();
1441

    
1442
		header("Location: interfaces.php?if={$if}");
1443
		exit;
1444
	}
1445

    
1446
} // end if ($_POST)
1447

    
1448
function handle_wireless_post() {
1449
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1450
	if (!is_array($wancfg['wireless'])) {
1451
		$wancfg['wireless'] = array();
1452
	}
1453
	$wancfg['wireless']['standard'] = $_POST['standard'];
1454
	$wancfg['wireless']['mode'] = $_POST['mode'];
1455
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1456
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1457
	$wancfg['wireless']['channel'] = $_POST['channel'];
1458
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1459
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1460
	$wancfg['wireless']['distance'] = $_POST['distance'];
1461
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1462
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1463
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1464
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1465
		foreach ($wl_countries_attr as $wl_country) {
1466
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1467
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1468
				break;
1469
			}
1470
		}
1471
	}
1472
	if (!is_array($wancfg['wireless']['wpa'])) {
1473
		$wancfg['wireless']['wpa'] = array();
1474
	}
1475
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1476
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1477
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1478
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1479
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1480
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1481
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1482
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1483
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1484
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1485
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1486
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1487
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1488
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1489

    
1490
	if ($_POST['persistcommonwireless'] == "yes") {
1491
		if (!is_array($config['wireless'])) {
1492
			$config['wireless'] = array();
1493
		}
1494
		if (!is_array($config['wireless']['interfaces'])) {
1495
			$config['wireless']['interfaces'] = array();
1496
		}
1497
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1498
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1499
		}
1500
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1501
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1502
	}
1503
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1504
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1505
	} else if (isset($wancfg['wireless']['diversity'])) {
1506
		unset($wancfg['wireless']['diversity']);
1507
	}
1508
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1509
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1510
	} else if (isset($wancfg['wireless']['txantenna'])) {
1511
		unset($wancfg['wireless']['txantenna']);
1512
	}
1513
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1514
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1515
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1516
		unset($wancfg['wireless']['rxantenna']);
1517
	}
1518
	if ($_POST['hidessid_enable'] == "yes") {
1519
		$wancfg['wireless']['hidessid']['enable'] = true;
1520
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1521
		unset($wancfg['wireless']['hidessid']['enable']);
1522
	}
1523
	if ($_POST['mac_acl_enable'] == "yes") {
1524
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1525
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1526
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1527
	}
1528
	if ($_POST['rsn_preauth'] == "yes") {
1529
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1530
	} else {
1531
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1532
	}
1533
	if ($_POST['ieee8021x'] == "yes") {
1534
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1535
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1536
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1537
	}
1538
	if ($_POST['wpa_strict_rekey'] == "yes") {
1539
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1540
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1541
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1542
	}
1543
	if ($_POST['debug_mode'] == "yes") {
1544
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1545
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1546
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1547
	}
1548
	if ($_POST['wpa_enable'] == "yes") {
1549
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1550
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1551
		unset($wancfg['wireless']['wpa']['enable']);
1552
	}
1553

    
1554
	if ($_POST['wme_enable'] == "yes") {
1555
		if (!is_array($wancfg['wireless']['wme'])) {
1556
			$wancfg['wireless']['wme'] = array();
1557
		}
1558
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1559
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1560
		unset($wancfg['wireless']['wme']['enable']);
1561
	}
1562
	if ($_POST['puremode'] == "11g") {
1563
		if (!is_array($wancfg['wireless']['pureg'])) {
1564
			$wancfg['wireless']['pureg'] = array();
1565
		}
1566
		$wancfg['wireless']['pureg']['enable'] = true;
1567
	} else if ($_POST['puremode'] == "11n") {
1568
		if (!is_array($wancfg['wireless']['puren'])) {
1569
			$wancfg['wireless']['puren'] = array();
1570
		}
1571
		$wancfg['wireless']['puren']['enable'] = true;
1572
	} else {
1573
		if (isset($wancfg['wireless']['pureg'])) {
1574
			unset($wancfg['wireless']['pureg']);
1575
		}
1576
		if (isset($wancfg['wireless']['puren'])) {
1577
			unset($wancfg['wireless']['puren']);
1578
		}
1579
	}
1580
	if ($_POST['apbridge_enable'] == "yes") {
1581
		if (!is_array($wancfg['wireless']['apbridge'])) {
1582
			$wancfg['wireless']['apbridge'] = array();
1583
		}
1584
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1585
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1586
		unset($wancfg['wireless']['apbridge']['enable']);
1587
	}
1588
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1589
		if (!is_array($wancfg['wireless']['turbo'])) {
1590
			$wancfg['wireless']['turbo'] = array();
1591
		}
1592
		$wancfg['wireless']['turbo']['enable'] = true;
1593
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1594
		unset($wancfg['wireless']['turbo']['enable']);
1595
	}
1596

    
1597
	interface_sync_wireless_clones($wancfg, true);
1598
}
1599

    
1600
function check_wireless_mode() {
1601
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1602

    
1603
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1604
		return;
1605
	}
1606

    
1607
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1608
		$clone_count = 1;
1609
	} else {
1610
		$clone_count = 0;
1611
	}
1612

    
1613
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1614
		foreach ($config['wireless']['clone'] as $clone) {
1615
			if ($clone['if'] == $wlanbaseif) {
1616
				$clone_count++;
1617
			}
1618
		}
1619
	}
1620

    
1621
	if ($clone_count > 1) {
1622
		$old_wireless_mode = $wancfg['wireless']['mode'];
1623
		$wancfg['wireless']['mode'] = $_POST['mode'];
1624
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1625
			$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']]);
1626
		} else {
1627
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1628
		}
1629
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1630
	}
1631
}
1632

    
1633
// Find all possible media options for the interface
1634
$mediaopts_list = array();
1635
$intrealname = $config['interfaces'][$if]['if'];
1636
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1637
foreach ($mediaopts as $mediaopt) {
1638
	preg_match("/media (.*)/", $mediaopt, $matches);
1639
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1640
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1641
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1642
	} else {
1643
		// there is only media like "media 1000baseT"
1644
		array_push($mediaopts_list, $matches[1]);
1645
	}
1646
}
1647

    
1648
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1649
$shortcut_section = "interfaces";
1650

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

    
1654
// Get the MAC address
1655
$ip = $_SERVER['REMOTE_ADDR'];
1656
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1657
$mymac = str_replace("\n", "", $mymac);
1658

    
1659
function build_mediaopts_list() {
1660
	global $mediaopts_list;
1661

    
1662
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1663
			 " " =>	 gettext("------- Media Supported by this interface -------")
1664
			];
1665

    
1666
	foreach ($mediaopts_list as $mediaopt) {
1667
		$list[$mediaopt] = $mediaopt;
1668
	}
1669

    
1670
	return($list);
1671
}
1672

    
1673
function build_gateway_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_ipaddrv4($gateway['gateway']))) {
1679
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1680
		}
1681
	}
1682

    
1683
	return($list);
1684
}
1685

    
1686
function build_gatewayv6_list() {
1687
	global $a_gateways, $if;
1688

    
1689
	$list = array("none" => gettext("None"));
1690
	foreach ($a_gateways as $gateway) {
1691
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1692
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1693
		}
1694
	}
1695

    
1696
	return($list);
1697
}
1698

    
1699
include("head.inc");
1700

    
1701
if ($input_errors) {
1702
	print_input_errors($input_errors);
1703
}
1704

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

    
1710
if ($savemsg) {
1711
	print_info_box($savemsg, 'success');
1712
}
1713

    
1714

    
1715
$form = new Form(new Form_Button(
1716
	'Submit',
1717
	gettext("Save")
1718
));
1719

    
1720
$section = new Form_Section('General configuration');
1721

    
1722
$section->addInput(new Form_Checkbox(
1723
	'enable',
1724
	'Enable',
1725
	'Enable interface',
1726
	$pconfig['enable'],
1727
	'yes'
1728
));
1729

    
1730
$section->addInput(new Form_Input(
1731
	'descr',
1732
	'Description',
1733
	'text',
1734
	$pconfig['descr']
1735
))->setHelp('Enter a description (name) for the interface here.');
1736

    
1737
$section->addInput(new Form_Select(
1738
	'type',
1739
	'IPv4 Configuration Type',
1740
	$pconfig['type'],
1741
	$types4
1742
));
1743

    
1744
$section->addInput(new Form_Select(
1745
	'type6',
1746
	'IPv6 Configuration Type',
1747
	$pconfig['type6'],
1748
	$types6
1749
));
1750

    
1751
$macaddress = new Form_Input(
1752
	'spoofmac',
1753
	'MAC Address',
1754
	'text',
1755
	$pconfig['spoofmac'],
1756
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1757
);
1758

    
1759
$btnmymac = new Form_Button(
1760
	'btnmymac',
1761
	'Copy My MAC'
1762
	);
1763

    
1764
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1765

    
1766
$group = new Form_Group('MAC controls');
1767
$group->add($macaddress);
1768
// $group->add($btnmymac);
1769
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1770
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1771
$section->add($group);
1772

    
1773
$section->addInput(new Form_Input(
1774
	'mtu',
1775
	'MTU',
1776
	'number',
1777
	$pconfig['mtu']
1778
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1779
			'This is typically 1500 bytes but can vary in some circumstances.');
1780

    
1781
$section->addInput(new Form_Input(
1782
	'mss',
1783
	'MSS',
1784
	'number',
1785
	$pconfig['mss']
1786
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1787
			'header size) will be in effect.');
1788

    
1789
if (count($mediaopts_list) > 0) {
1790
	$section->addInput(new Form_Select(
1791
		'mediaopt',
1792
		'Speed and Duplex',
1793
		rtrim($mediaopt_from_config),
1794
		build_mediaopts_list()
1795
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1796
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1797
}
1798

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

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

    
1804
$section->addInput(new Form_IpAddress(
1805
	'ipaddr',
1806
	'IPv4 Address',
1807
	$pconfig['ipaddr']
1808
))->addMask('subnet', $pconfig['subnet'], 32);
1809

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

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

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

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

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

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

    
1832
$section = new Form_Section('Static IPv6 configuration');
1833
$section->addClass('staticv6');
1834

    
1835
$section->addInput(new Form_IpAddress(
1836
	'ipaddrv6',
1837
	'IPv6 address',
1838
	$pconfig['ipaddrv6']
1839
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1840

    
1841
$group = new Form_Group('IPv6 Upstream gateway');
1842

    
1843
$group->add(new Form_Select(
1844
	'gatewayv6',
1845
	'IPv6 Upstream Gateway',
1846
	$pconfig['gatewayv6'],
1847
	build_gatewayv6_list()
1848
));
1849

    
1850
$group->add(new Form_Button(
1851
	'addgw6',
1852
	'Add a new gateway'
1853
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1854

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

    
1858
$section->add($group);
1859
$form->add($section);
1860

    
1861
// Add new gateway modal pop-up for IPv6
1862
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1863

    
1864
$modal->addInput(new Form_Checkbox(
1865
	'defaultgw6',
1866
	'Default',
1867
	'Default gateway',
1868
	($if == "wan" || $if == "WAN")
1869
));
1870

    
1871
$modal->addInput(new Form_Input(
1872
	'name6',
1873
	'Gateway name',
1874
	'text',
1875
	$wancfg['descr'] . "GWv6"
1876
));
1877

    
1878
$modal->addInput(new Form_IpAddress(
1879
	'gatewayip6',
1880
	'Gateway IPv6',
1881
	null
1882
));
1883

    
1884
$modal->addInput(new Form_Input(
1885
	'gatewaydescr6',
1886
	'Description',
1887
	'text'
1888
));
1889

    
1890
$btnaddgw6 = new Form_Button(
1891
	'add6',
1892
	'Add'
1893
);
1894

    
1895
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1896

    
1897
$btncnxgw6 = new Form_Button(
1898
	'cnx6',
1899
	'Cancel'
1900
);
1901

    
1902
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1903

    
1904
$modal->addInput(new Form_StaticText(
1905
	null,
1906
	$btnaddgw6 . $btncnxgw6
1907
));
1908

    
1909
$form->add($modal);
1910

    
1911
// ==== DHCP client configuration =============================
1912

    
1913
$section = new Form_Section('DHCP client configuration');
1914
$section->addClass('dhcp');
1915

    
1916
$group = new Form_Group('Options');
1917

    
1918
$group->add(new Form_Checkbox(
1919
	'dhcpadv',
1920
	null,
1921
	'Show DHCP advanced options',
1922
	false
1923
));
1924

    
1925
$group->add(new Form_Checkbox(
1926
	'dhcpovr',
1927
	null,
1928
	'Config file override',
1929
	false
1930
));
1931

    
1932
$section->add($group);
1933

    
1934
$section->addInput(new Form_Input(
1935
	'dhcphostname',
1936
	'Hostname',
1937
	'text',
1938
	$pconfig['dhcphostname']
1939
))->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).');
1940

    
1941
$section->addInput(new Form_IpAddress(
1942
	'alias-address',
1943
	'Alias IPv4 address',
1944
	$pconfig['alias-address']
1945
))->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.');
1946

    
1947
$section->addInput(new Form_Input(
1948
	'dhcprejectfrom',
1949
	'Reject leases from',
1950
	'text',
1951
	$pconfig['dhcprejectfrom']
1952
))->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. ' .
1953
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1954

    
1955
$group = new Form_Group('Protocol timing');
1956
$group->addClass('dhcpadvanced');
1957

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

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

    
1972
$group->add(new Form_Input(
1973
	'adv_dhcp_pt_select_timeout',
1974
	null,
1975
	'number',
1976
	$pconfig['adv_dhcp_pt_select_timeout'],
1977
	['min' => 0]
1978
))->setHelp('Select timeout');
1979

    
1980
$group->add(new Form_Input(
1981
	'adv_dhcp_pt_reboot',
1982
	null,
1983
	'number',
1984
	$pconfig['adv_dhcp_pt_reboot']
1985
))->setHelp('Reboot');
1986

    
1987
$group->add(new Form_Input(
1988
	'adv_dhcp_pt_backoff_cutoff',
1989
	null,
1990
	'number',
1991
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1992
))->setHelp('Backoff cutoff');
1993

    
1994
$group->add(new Form_Input(
1995
	'adv_dhcp_pt_initial_interval',
1996
	null,
1997
	'number',
1998
	$pconfig['adv_dhcp_pt_initial_interval']
1999
))->setHelp('Initial interval');
2000

    
2001
$section->add($group);
2002

    
2003
$group = new Form_Group('Presets');
2004
$group->addClass('dhcpadvanced');
2005

    
2006
$group->add(new Form_Checkbox(
2007
	'adv_dhcp_pt_values',
2008
	null,
2009
	'FreeBSD default',
2010
	null,
2011
	'DHCP'
2012
))->displayAsRadio();
2013

    
2014
$group->add(new Form_Checkbox(
2015
	'adv_dhcp_pt_values',
2016
	null,
2017
	'Clear',
2018
	null,
2019
	'Clear'
2020
))->displayAsRadio();
2021

    
2022
$group->add(new Form_Checkbox(
2023
	'adv_dhcp_pt_values',
2024
	null,
2025
	'pfSense Default',
2026
	null,
2027
	'pfSense'
2028
))->displayAsRadio();
2029

    
2030
$group->add(new Form_Checkbox(
2031
	'adv_dhcp_pt_values',
2032
	null,
2033
	'Saved Cfg',
2034
	null,
2035
	'SavedCfg'
2036
))->displayAsRadio();
2037

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

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

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

    
2053
$form->add($section);
2054

    
2055
$section = new Form_Section('Lease Requirements and Requests');
2056
$section->addClass('dhcpadvanced');
2057

    
2058
$section->addInput(new Form_Input(
2059
	'adv_dhcp_send_options',
2060
	'Send options',
2061
	'text',
2062
	$pconfig['adv_dhcp_send_options']
2063
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2064
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2065
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2066
			'Some ISPs may require certain options be or not be sent.');
2067

    
2068
$section->addInput(new Form_Input(
2069
	'adv_dhcp_request_options',
2070
	'Request options',
2071
	'text',
2072
	$pconfig['adv_dhcp_request_options']
2073
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2074
			'Some ISPs may require certain options be or not be requested.');
2075

    
2076
$section->addInput(new Form_Input(
2077
	'adv_dhcp_required_options',
2078
	'Require options',
2079
	'text',
2080
	$pconfig['adv_dhcp_required_options']
2081
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2082

    
2083
$section->addInput(new Form_Input(
2084
	'adv_dhcp_option_modifiers',
2085
	'Option modifiers',
2086
	'text',
2087
	$pconfig['adv_dhcp_option_modifiers']
2088
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2089
			'modifiers: (default, supersede, prepend, append)');
2090

    
2091
$form->add($section);
2092

    
2093
// DHCP6 client config
2094

    
2095
$section = new Form_Section('DHCP6 client configuration');
2096
$section->addClass('dhcp6');
2097

    
2098
$section->addInput(new Form_Checkbox(
2099
	'adv_dhcp6_config_advanced',
2100
	'Advanced',
2101
	'Show DHCPv6 advanced options',
2102
	$pconfig['adv_dhcp6_config_advanced'],
2103
	'Selected'
2104
));
2105

    
2106
$section->addInput(new Form_Checkbox(
2107
	'adv_dhcp6_config_file_override',
2108
	'Config file override',
2109
	'Override the configuration from this file',
2110
	$pconfig['adv_dhcp6_config_file_override'],
2111
	'Selected'
2112
));
2113

    
2114
$section->addInput(new Form_Checkbox(
2115
	'dhcp6usev4iface',
2116
	'Use IPv4 connectivity as parent interface',
2117
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2118
	$pconfig['dhcp6usev4iface']
2119
));
2120

    
2121
$section->addInput(new Form_Checkbox(
2122
	'dhcp6prefixonly',
2123
	'Request only an IPv6 prefix',
2124
	'Only request an IPv6 prefix, do not request an IPv6 address',
2125
	$pconfig['dhcp6prefixonly']
2126
));
2127

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

    
2135
$section->addInput(new Form_Checkbox(
2136
	'dhcp6-ia-pd-send-hint',
2137
	'Send IPv6 prefix hint',
2138
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2139
	$pconfig['dhcp6-ia-pd-send-hint']
2140
));
2141

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

    
2152
$form->add($section);
2153

    
2154
// DHCP6 client config - Advanced
2155

    
2156
$section = new Form_Section('Advanced DHCP6 client configuration');
2157
$section->addClass('dhcp6advanced');
2158

    
2159
$section->addInput(new Form_Checkbox(
2160
	'adv_dhcp6_interface_statement_information_only_enable',
2161
	'Information only',
2162
	null,
2163
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2164
	'Selected'
2165
));
2166

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

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

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

    
2193
$group = new Form_Group('Identity Association Statement');
2194

    
2195
$group->add(new Form_Checkbox(
2196
	'adv_dhcp6_id_assoc_statement_address_enable',
2197
	null,
2198
	'Non-Temporary Address Allocation',
2199
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2200
	'Selected'
2201
));
2202

    
2203
$group->add(new Form_Input(
2204
	'adv_dhcp6_id_assoc_statement_address_id',
2205
	null,
2206
	'text',
2207
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2208
))->sethelp('id-assoc na ID');
2209

    
2210
$group->add(new Form_IpAddress(
2211
	'adv_dhcp6_id_assoc_statement_address',
2212
	null,
2213
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2214
))->sethelp('IPv6 address');
2215

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

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

    
2230
$section->add($group);
2231

    
2232
// Prefix delegation
2233
$group = new Form_Group('');
2234

    
2235
$group->add(new Form_Checkbox(
2236
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2237
	null,
2238
	'Prefix Delegation ',
2239
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2240
	'Selected'
2241
));
2242

    
2243
$group->add(new Form_Input(
2244
	'adv_dhcp6_id_assoc_statement_prefix_id',
2245
	null,
2246
	'text',
2247
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2248
))->sethelp('id-assoc pd ID');
2249

    
2250
$group->add(new Form_IpAddress(
2251
	'adv_dhcp6_id_assoc_statement_prefix',
2252
	null,
2253
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2254
))->sethelp('IPv6 prefix');
2255

    
2256
$group->add(new Form_Input(
2257
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2258
	null,
2259
	'text',
2260
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2261
))->sethelp('pltime');
2262

    
2263
$group->add(new Form_Input(
2264
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2265
	null,
2266
	'text',
2267
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2268
))->sethelp('vltime');
2269

    
2270
$section->add($group);
2271

    
2272
$group = new Form_Group('Prefix interface statement');
2273

    
2274
$group->add(new Form_Input(
2275
	'adv_dhcp6_prefix_interface_statement_sla_id',
2276
	null,
2277
	'text',
2278
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2279
))->sethelp('Prefix Interface sla-id');
2280

    
2281
$group->add(new Form_Input(
2282
	'adv_dhcp6_prefix_interface_statement_sla_len',
2283
	null,
2284
	'text',
2285
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2286
))->sethelp('sla-len');
2287

    
2288
$section->add($group);
2289

    
2290
$group = new Form_Group('Authentication statement');
2291

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

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

    
2306
$group->add(new Form_Input(
2307
	'adv_dhcp6_authentication_statement_algorithm',
2308
	null,
2309
	'text',
2310
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2311
))->sethelp('Algorithm');
2312

    
2313
$group->add(new Form_Input(
2314
	'adv_dhcp6_authentication_statement_rdm',
2315
	null,
2316
	'text',
2317
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2318
))->sethelp('RDM');
2319

    
2320
$section->add($group);
2321

    
2322
$group = new Form_Group('Keyinfo statement');
2323

    
2324
$group->add(new Form_Input(
2325
	'adv_dhcp6_key_info_statement_keyname',
2326
	null,
2327
	'text',
2328
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2329
))->sethelp('Keyname');
2330

    
2331
$group->add(new Form_Input(
2332
	'adv_dhcp6_key_info_statement_realm',
2333
	null,
2334
	'text',
2335
	$pconfig['adv_dhcp6_key_info_statement_realm']
2336
))->sethelp('Realm');
2337

    
2338
$section->add($group);
2339

    
2340
$group = new Form_Group('');
2341

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

    
2349
$group->add(new Form_Input(
2350
	'adv_dhcp6_key_info_statement_secret',
2351
	null,
2352
	'text',
2353
	$pconfig['adv_dhcp6_key_info_statement_secret']
2354
))->sethelp('Secret');
2355

    
2356
$group->add(new Form_Input(
2357
	'adv_dhcp6_key_info_statement_expire',
2358
	null,
2359
	'text',
2360
	$pconfig['adv_dhcp6_key_info_statement_expire']
2361
))->sethelp('Expire');
2362

    
2363
$section->add($group);
2364

    
2365
$form->add($section);
2366

    
2367
$section = new Form_Section('6RD Configuration');
2368
$section->addClass('_6rd');
2369

    
2370
$section->addInput(new Form_Input(
2371
	'prefix-6rd',
2372
	'6RD Prefix',
2373
	'text',
2374
	$pconfig['prefix-6rd']
2375
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2376

    
2377
$section->addInput(new Form_Input(
2378
	'gateway-6rd',
2379
	'6RD Border relay',
2380
	'text',
2381
	$pconfig['gateway-6rd']
2382
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2383

    
2384
$section->addInput(new Form_Select(
2385
	'prefix-6rd-v4plen',
2386
	'6RD IPv4 Prefix length',
2387
	$pconfig['prefix-6rd-v4plen'],
2388
	array_combine(range(0, 32), range(0, 32))
2389
))->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.');
2390

    
2391
$form->add($section);
2392

    
2393
// Track IPv6 ointerface section
2394
$section = new Form_Section('Track IPv6 Interface');
2395
$section->addClass('track6');
2396

    
2397
function build_ipv6interface_list() {
2398
	global $config, $section;
2399

    
2400
	$list = array('' => '');
2401

    
2402
	$interfaces = get_configured_interface_with_descr(false, true);
2403
	$dynv6ifs = array();
2404

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

    
2420
	foreach ($dynv6ifs as $iface => $ifacedata) {
2421
		$list[$iface] = $ifacedata['name'];
2422

    
2423
		$section->addInput(new Form_Input(
2424
			'ipv6-num-prefix-ids-' . $iface,
2425
			null,
2426
			'hidden',
2427
			$ifacedata['ipv6_num_prefix_ids']
2428
		));
2429
	}
2430

    
2431
	return($list);
2432
}
2433

    
2434
$section->addInput(new Form_Select(
2435
	'track6-interface',
2436
	'IPv6 Interface',
2437
	$pconfig['track6-interface'],
2438
	build_ipv6interface_list()
2439
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2440

    
2441
if ($pconfig['track6-prefix-id'] == "") {
2442
	$pconfig['track6-prefix-id'] = 0;
2443
}
2444

    
2445
$section->addInput(new Form_Input(
2446
	'track6-prefix-id--hex' . $iface,
2447
	'IPv6 Prefix ID',
2448
	'text',
2449
	sprintf("%x", $pconfig['track6-prefix-id'])
2450
))->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.');
2451

    
2452
$section->addInput(new Form_Input(
2453
	'track6-prefix-id-max' . $iface,
2454
	null,
2455
	'hidden',
2456
	0
2457
));
2458

    
2459
$form->add($section);
2460

    
2461
/// PPP section
2462

    
2463
$section = new Form_Section('PPP Configuration');
2464
$section->addClass('ppp');
2465

    
2466
$section->addInput(new Form_Select(
2467
	'country',
2468
	'Country',
2469
	$pconfig['country'],
2470
	[]
2471
));
2472

    
2473
$section->addInput(new Form_Select(
2474
	'provider_list',
2475
	'Provider',
2476
	$pconfig['provider_list'],
2477
	[]
2478
));
2479

    
2480
$section->addInput(new Form_Select(
2481
	'providerplan',
2482
	'Plan',
2483
	$pconfig['providerplan'],
2484
	[]
2485
))->setHelp('Select to fill in data for your service provider.');
2486

    
2487
$section->addInput(new Form_Input(
2488
	'ppp_username',
2489
	'Username',
2490
	'text',
2491
	$pconfig['ppp_username']
2492
));
2493

    
2494
$section->addPassword(new Form_Input(
2495
	'ppp_password',
2496
	'Password',
2497
	'password',
2498
	$pconfig['ppp_password']
2499
));
2500

    
2501
$section->addInput(new Form_Input(
2502
	'phone',
2503
	'Phone number',
2504
	'text',
2505
	$pconfig['phone']
2506
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2507

    
2508
$section->addInput(new Form_Input(
2509
	'apn',
2510
	'Access Point Name',
2511
	'text',
2512
	$pconfig['apn']
2513
));
2514

    
2515

    
2516
function build_port_list() {
2517
	$list = array("" => "None");
2518

    
2519
	$portlist = glob("/dev/cua*");
2520
	$modems	  = glob("/dev/modem*");
2521
	$portlist = array_merge($portlist, $modems);
2522

    
2523
	foreach ($portlist as $port) {
2524
		if (preg_match("/\.(lock|init)$/", $port)) {
2525
			continue;
2526
		}
2527

    
2528
	$list[trim($port)] = $port;
2529
	}
2530

    
2531
	return($list);
2532
}
2533

    
2534
$section->addInput(new Form_Select(
2535
	'port',
2536
	"Modem port",
2537
	$pconfig['port'],
2538
	build_port_list()
2539
));
2540

    
2541
$section->addInput(new Form_Button(
2542
	'btnadvppp',
2543
	'Advanced PPP',
2544
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2545
))->setHelp('Create a new PPP configuration');
2546

    
2547
$form->add($section);
2548

    
2549
// PPPoE configuration
2550
$section = new Form_Section('PPPoE Configuration');
2551
$section->addClass('pppoe');
2552

    
2553
$section->addInput(new Form_Input(
2554
	'pppoe_username',
2555
	'Username',
2556
	'text',
2557
	$pconfig['pppoe_username']
2558
));
2559

    
2560
$section->addPassword(new Form_Input(
2561
	'pppoe_password',
2562
	'Password',
2563
	'password',
2564
	$pconfig['pppoe_password']
2565
));
2566

    
2567
$section->addInput(new Form_Input(
2568
	'provider',
2569
	'Service name',
2570
	'text',
2571
	$pconfig['provider']
2572
))->setHelp('This field can usually be left empty');
2573

    
2574
$section->addInput(new Form_Checkbox(
2575
	'pppoe_dialondemand',
2576
	'Dial on demand',
2577
	'Enable Dial-On-Demand mode ',
2578
	$pconfig['pppoe_dialondemand'],
2579
	'enable'
2580
));
2581

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

    
2591
$section->addInput(new Form_Select(
2592
	'pppoe-reset-type',
2593
	'Periodic reset',
2594
	$pconfig['pppoe-reset-type'],
2595
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2596
))->setHelp('Select a reset timing type');
2597

    
2598
$group = new Form_Group('Custom reset');
2599
$group->addClass('pppoecustom');
2600

    
2601
$group->add(new Form_Input(
2602
	'pppoe_resethour',
2603
	null,
2604
	'number',
2605
	$pconfig['pppoe_resethour'],
2606
	[min => 0, max => 23]
2607
))->setHelp('Hour (0-23)');
2608

    
2609
$group->add(new Form_Input(
2610
	'pppoe_resetminute',
2611
	null,
2612
	'number',
2613
	$pconfig['pppoe_resetminute'],
2614
	[min => 0, max => 59]
2615
))->setHelp('Minutes (0-59)');
2616

    
2617
// ToDo: Need a date-picker here
2618
$group->add(new Form_Input(
2619
	'pppoe_resetdate',
2620
	null,
2621
	'text',
2622
	$pconfig['pppoe_resetdate']
2623
))->setHelp('Specific date (mm/dd/yyyy)');
2624

    
2625
$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');
2626

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

    
2629
$group = new Form_MultiCheckboxGroup('cron based reset');
2630
$group->addClass('pppoepreset');
2631

    
2632
$group->add(new Form_MultiCheckbox(
2633
	'pppoe_pr_preset_val',
2634
	null,
2635
	'Reset at each month ("0 0 1 * *")',
2636
	$pconfig['pppoe_monthly'],
2637
	'monthly'
2638
))->displayAsRadio();
2639

    
2640
$group->add(new Form_MultiCheckbox(
2641
	'pppoe_pr_preset_val',
2642
	null,
2643
	'Reset at each week ("0 0 * * 0")',
2644
	$pconfig['pppoe_weekly'],
2645
	'weekly'
2646
))->displayAsRadio();
2647

    
2648
$group->add(new Form_MultiCheckbox(
2649
	'pppoe_pr_preset_val',
2650
	null,
2651
	'Reset at each day ("0 0 * * *")',
2652
	$pconfig['pppoe_daily'],
2653
	'daily'
2654
))->displayAsRadio();
2655

    
2656
$group->add(new Form_MultiCheckbox(
2657
	'pppoe_pr_preset_val',
2658
	null,
2659
	'Reset at each hour ("0 * * * *")',
2660
	$pconfig['pppoe_hourly'],
2661
	'hourly'
2662
))->displayAsRadio();
2663

    
2664
$section->add($group);
2665

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

    
2678
$form->add($section);
2679

    
2680
// PPTP & L2TP Configuration section
2681
$section = new Form_Section('PPTP/L2TP Configuration');
2682
$section->addClass('pptp');
2683

    
2684
$section->addInput(new Form_Input(
2685
	'pptp_username',
2686
	'Username',
2687
	'text',
2688
	$pconfig['pptp_username']
2689
));
2690

    
2691
$section->addPassword(new Form_Input(
2692
	'pptp_password',
2693
	'Password',
2694
	'password',
2695
	$pconfig['pptp_password']
2696
));
2697

    
2698
$section->addInput(new Form_IpAddress(
2699
	'pptp_local0',
2700
	'Local IP address',
2701
	$pconfig['pptp_localip'][0]
2702
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2703

    
2704
$section->addInput(new Form_IpAddress(
2705
	'pptp_remote0',
2706
	'Remote IP address',
2707
	$pconfig['pptp_remote'][0]
2708
));
2709

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

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

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

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

    
2746
$form->add($section);
2747

    
2748
// Wireless interface
2749
if (isset($wancfg['wireless'])) {
2750

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

    
2753
	$section->addInput(new Form_Checkbox(
2754
		'persistcommonwireless',
2755
		'Persist common settings',
2756
		'Preserve common wireless configuration through interface deletions and reassignments.',
2757
		$pconfig['persistcommonwireless'],
2758
		'yes'
2759
	));
2760

    
2761
	$mode_list = ['auto' => 'Auto'];
2762

    
2763
	if (is_array($wl_modes)) {
2764
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2765
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2766
		}
2767
	}
2768

    
2769
	if (count($mode_list) == 1) {
2770
		$mode_list[''] = '';
2771
	}
2772

    
2773
	$section->addInput(new Form_Select(
2774
		'standard',
2775
		'Standard',
2776
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2777
		$mode_list
2778
	));
2779

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

    
2796
	$mode_list = ['0' => gettext('Auto')];
2797

    
2798
	if (is_array($wl_modes)) {
2799
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2800
			if ($wl_standard == "11g") {
2801
				$wl_standard = "11b/g";
2802
			} else if ($wl_standard == "11ng") {
2803
				$wl_standard = "11b/g/n";
2804
			} else if ($wl_standard == "11na") {
2805
				$wl_standard = "11a/n";
2806
			}
2807

    
2808
			foreach ($wl_channels as $wl_channel) {
2809
				if (isset($wl_chaninfo[$wl_channel])) {
2810
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2811
				} else {
2812
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2813
				}
2814
			}
2815
		}
2816
	}
2817

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

    
2826
	if (ANTENNAS) {
2827
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2828
			$group = new Form_Group('Antenna Settings');
2829

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

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

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

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

    
2859
			$section->add($group);
2860
		}
2861
	}
2862

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

    
2872
	$form->add($section);
2873

    
2874
	// Regulatory settings
2875
	$section = new Form_Section('Regulatory settings');
2876

    
2877
	$domain_list = array("" => 'Default');
2878

    
2879
	if (is_array($wl_regdomains)) {
2880
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2881
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2882
		}
2883
	}
2884

    
2885
	$section->addInput(new Form_Select(
2886
		'regdomain',
2887
		'Regulatory domain',
2888
		$pconfig['regdomain'],
2889
		$domain_list
2890
	))->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');
2891

    
2892
	$country_list = array('' => 'Default');
2893

    
2894
	if (is_array($wl_countries)) {
2895
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2896
			$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']);
2897
		}
2898
	}
2899

    
2900
	$section->addInput(new Form_Select(
2901
		'regcountry',
2902
		'Country',
2903
		$pconfig['regcountry'],
2904
		$country_list
2905
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2906

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

    
2918
	$form->add($section);
2919

    
2920
	$section = new Form_Section('Network-specific wireless configuration');
2921

    
2922
	$section->addInput(new Form_Select(
2923
		'mode',
2924
		'Mode',
2925
		$pconfig['mode'],
2926
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2927
	));
2928

    
2929
	$section->addInput(new Form_Input(
2930
		'ssid',
2931
		'SSID',
2932
		'text',
2933
		$pconfig['ssid']
2934
	));
2935

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

    
2953
	$section->addInput(new Form_Checkbox(
2954
		'apbridge_enable',
2955
		'Allow intra-BSS communication',
2956
		'Allow packets to pass between wireless clients directly when operating as an access point',
2957
		$pconfig['apbridge_enable'],
2958
		'yes'
2959
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2960

    
2961
	$section->addInput(new Form_Checkbox(
2962
		'wme_enable',
2963
		'Enable WME',
2964
		'Force the card to use WME (wireless QoS)',
2965
		$pconfig['wme_enable'],
2966
		'yes'
2967
	));
2968

    
2969
	$section->addInput(new Form_Checkbox(
2970
		'hidessid_enable',
2971
		'Hide SSID',
2972
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2973
		$pconfig['hidessid_enable'],
2974
		'yes'
2975
	));
2976

    
2977
	$form->add($section);
2978

    
2979
	// WPA Section
2980
	$section = new Form_Section('WPA');
2981

    
2982
	$section->addInput(new Form_Checkbox(
2983
		'wpa_enable',
2984
		'Enable',
2985
		'Enable WPA',
2986
		$pconfig['wpa_enable'],
2987
		'yes'
2988
	));
2989

    
2990
	$section->addInput(new Form_Input(
2991
		'passphrase',
2992
		'WPA Pre-Shared Key',
2993
		'text',
2994
		$pconfig['passphrase']
2995
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2996

    
2997
	$section->addInput(new Form_Select(
2998
		'wpa_mode',
2999
		'WPA mode',
3000
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3001
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3002
	));
3003

    
3004
	$section->addInput(new Form_Select(
3005
		'wpa_key_mgmt',
3006
		'WPA Key Management Mode',
3007
		$pconfig['wpa_key_mgmt'],
3008
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3009
	));
3010

    
3011
	$section->addInput(new Form_Select(
3012
		'wpa_pairwise',
3013
		'WPA Pairwise',
3014
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3015
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3016
	));
3017

    
3018
	$section->addInput(new Form_Input(
3019
		'wpa_group_rekey',
3020
		'WPA Pre-Shared Key',
3021
		'number',
3022
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3023
		['min' => '1', 'max' => 9999]
3024
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3025

    
3026
	$section->addInput(new Form_Input(
3027
		'wpa_gmk_rekey',
3028
		'Master Key Regeneration',
3029
		'number',
3030
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3031
		['min' => '1', 'max' => 9999]
3032
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3033

    
3034
	$section->addInput(new Form_Checkbox(
3035
		'wpa_strict_rekey',
3036
		'Strict Key Regeneration',
3037
		'Force the AP to rekey whenever a client disassociates',
3038
		$pconfig['wpa_strict_rekey'],
3039
		'yes'
3040
	));
3041

    
3042
	$form->add($section);
3043

    
3044
	$section = new Form_Section('802.1x RADIUS options');
3045

    
3046
	$section->addInput(new Form_Checkbox(
3047
		'ieee8021x',
3048
		'IEEE802.1X',
3049
		'Enable 802.1X authentication',
3050
		$pconfig['ieee8021x'],
3051
		'yes'
3052
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3053

    
3054
	$group = new Form_Group('Primary 802.1X server');
3055

    
3056
	$group->add(new Form_IpAddress(
3057
		'auth_server_addr',
3058
		'IP Address',
3059
		$pconfig['auth_server_addr']
3060
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3061

    
3062
	$group->add(new Form_Input(
3063
		'auth_server_port',
3064
		'Port',
3065
		'number',
3066
		$pconfig['auth_server_port']
3067
	))->setHelp('Server port. Leave blank for the default port 1812');
3068

    
3069
	$group->add(new Form_Input(
3070
		'auth_server_shared_secret',
3071
		'Shared secret',
3072
		'number',
3073
		$pconfig['auth_server_shared_secret']
3074
	))->setHelp('Shared secret');
3075

    
3076
	$section->add($group);
3077

    
3078
	$group = new Form_Group('Secondary 802.1X server');
3079

    
3080
	$group->add(new Form_IpAddress(
3081
		'auth_server_addr2',
3082
		'IP Address',
3083
		$pconfig['auth_server_addr2']
3084
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3085

    
3086
	$group->add(new Form_Input(
3087
		'auth_server_port2',
3088
		'Port',
3089
		'number',
3090
		$pconfig['auth_server_port2']
3091
	))->setHelp('Server port. Leave blank for the default port 1812');
3092

    
3093
	$group->add(new Form_Input(
3094
		'auth_server_shared_secret2',
3095
		'Shared secret',
3096
		'number',
3097
		$pconfig['auth_server_shared_secret2']
3098
	))->setHelp('Shared secret');
3099

    
3100
	$section->add($group);
3101

    
3102
	$section->addInput(new Form_Checkbox(
3103
		'rsn_preauth',
3104
		'Authentication Roaming Preauth',
3105
		null,
3106
		$pconfig['rsn_preauth'],
3107
		'yes'
3108
	));
3109

    
3110
	$form->add($section);
3111
}
3112

    
3113
$section = new Form_Section('Private networks');
3114

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

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

    
3135
$form->add($section);
3136

    
3137
$form->addGlobal(new Form_Input(
3138
	'if',
3139
	null,
3140
	'hidden',
3141
	$if
3142
));
3143

    
3144
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3145
	$form->addGlobal(new Form_Input(
3146
		'ppp_port',
3147
		null,
3148
		'hidden',
3149
		$pconfig['port']
3150
	));
3151
}
3152

    
3153
$form->addGlobal(new Form_Input(
3154
	'ptpid',
3155
	null,
3156
	'hidden',
3157
	$pconfig['ptpid']
3158
));
3159

    
3160

    
3161
// Add new gateway modal pop-up
3162
$modal = new Modal('New gateway', 'newgateway', 'large');
3163

    
3164
$modal->addInput(new Form_Checkbox(
3165
	'defaultgw',
3166
	'Default',
3167
	'Default gateway',
3168
	($if == "wan" || $if == "WAN")
3169
));
3170

    
3171
$modal->addInput(new Form_Input(
3172
	'name',
3173
	'Gateway name',
3174
	'text',
3175
	$wancfg['descr'] . "GW"
3176
));
3177

    
3178
$modal->addInput(new Form_IpAddress(
3179
	'gatewayip',
3180
	'Gateway IPv4',
3181
	null
3182
));
3183

    
3184
$modal->addInput(new Form_Input(
3185
	'gatewaydescr',
3186
	'Description',
3187
	'text'
3188
));
3189

    
3190
$btnaddgw = new Form_Button(
3191
	'add',
3192
	'Add'
3193
);
3194

    
3195
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3196

    
3197
$btncnxgw = new Form_Button(
3198
	'cnx',
3199
	'Cancel'
3200
);
3201

    
3202
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3203

    
3204
$modal->addInput(new Form_StaticText(
3205
	null,
3206
	$btnaddgw . $btncnxgw
3207
));
3208

    
3209
$form->add($modal);
3210

    
3211
print($form);
3212
?>
3213

    
3214
<script type="text/javascript">
3215
//<![CDATA[
3216
events.push(function() {
3217
	function updateType(t) {
3218

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

    
3253
		if (t != "l2tp" && t != "pptp") {
3254
			$('.'+t).show();
3255
		}
3256
	}
3257

    
3258
	function updateTypeSix(t) {
3259
		if (!isNaN(t[0])) {
3260
			t = '_' + t;
3261
		}
3262

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

    
3295
		if (t != "l2tp" && t != "pptp") {
3296
			$('.'+t).show();
3297
		}
3298
	}
3299

    
3300
	function show_reset_settings(reset_type) {
3301
		if (reset_type == 'preset') {
3302
			$('.pppoepreset').show();
3303
			$('.pppoecustom').hide();
3304
		} else if (reset_type == 'custom') {
3305
			$('.pppoecustom').show();
3306
			$('.pppoepreset').hide();
3307
		} else {
3308
			$('.pppoecustom').hide();
3309
			$('.pppoepreset').hide();
3310
		}
3311
	}
3312

    
3313
	function update_track6_prefix() {
3314
		var iface = $("#track6-interface").val();
3315
		if (iface == null) {
3316
			return;
3317
		}
3318

    
3319
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3320
		if (track6_prefix_ids == null) {
3321
			return;
3322
		}
3323

    
3324
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3325
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3326
	}
3327

    
3328
	// Create the new gateway from the data entered in the modal pop-up
3329
	function hide_add_gatewaysave() {
3330
		var iface = $('#if').val();
3331
		name = $('#name').val();
3332
		var descr = $('#gatewaydescr').val();
3333
		gatewayip = $('#gatewayip').val();
3334

    
3335
		var defaultgw = '';
3336
		if ($('#defaultgw').is(':checked')) {
3337
			defaultgw = '&defaultgw=on';
3338
		}
3339

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

    
3352
	function save_callback(response) {
3353
		if (response) {
3354
			var gwtext = escape(name) + " - " + gatewayip;
3355
			addOption($('#gateway'), gwtext, name);
3356
		} else {
3357
			report_failure();
3358
		}
3359

    
3360
		$("#newgateway").modal('hide');
3361
	}
3362

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

    
3370
		$("#newgateway").modal('hide');
3371
	}
3372

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

    
3381
	function hide_add_gatewaysave_v6() {
3382

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

    
3403

    
3404
	function addOption_v6(selectbox, text, value) {
3405
		var optn = document.createElement("OPTION");
3406
		optn.text = text;
3407
		optn.value = value;
3408
		selectbox.append(optn);
3409
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3410
	}
3411

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

    
3419
		$("#newgateway6").modal('hide');
3420
	}
3421

    
3422
	function save_callback_v6(response_v6) {
3423
		if (response_v6) {
3424

    
3425
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3426
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3427
		} else {
3428
			report_failure_v6();
3429
		}
3430

    
3431
		$("#newgateway6").modal('hide');
3432
	}
3433

    
3434
	function country_list() {
3435
		$('#country').children().remove();
3436
		$('#provider_list').children().remove();
3437
		$('#providerplan').children().remove();
3438
		$.ajax("getserviceproviders.php",{
3439
			success: function(response) {
3440

    
3441
				var responseTextArr = response.split("\n");
3442
				responseTextArr.sort();
3443

    
3444
				responseTextArr.forEach( function(value) {
3445
					country = value.split(":");
3446
					$('#country').append($('<option>', {
3447
						value: country[1],
3448
						text : country[0]
3449
					}));
3450
				});
3451
			}
3452
		});
3453
	}
3454

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

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

    
3483
				$('#providerplan').append($('<option>', {
3484
					value: '',
3485
					text : ''
3486
				}));
3487

    
3488
				responseTextArr.forEach( function(value) {
3489
					if (value != "") {
3490
						providerplan = value.split(":");
3491

    
3492
						$('#providerplan').append($('<option>', {
3493
							value: providerplan[1],
3494
							text : providerplan[0] + " - " + providerplan[1]
3495
						}));
3496
					}
3497
				});
3498
			}
3499
		});
3500
	}
3501

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

    
3526
	function show_dhcp6adv() {
3527
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3528
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3529

    
3530
		hideCheckbox('dhcp6usev4iface', ovr);
3531
		hideCheckbox('dhcp6prefixonly', ovr);
3532
		hideInput('dhcp6-ia-pd-len', ovr);
3533
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3534
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3535

    
3536
		hideClass('dhcp6advanced', !adv || ovr);
3537
	}
3538

    
3539
	function setDHCPoptions() {
3540
		var adv = $('#dhcpadv').prop('checked');
3541
		var ovr = $('#dhcpovr').prop('checked');
3542

    
3543
		if (ovr) {
3544
			hideInput('dhcphostname', true);
3545
			hideIpAddress('alias-address', true);
3546
			hideInput('dhcprejectfrom', true);
3547
			hideInput('adv_dhcp_config_file_override_path', false);
3548
			hideClass('dhcpadvanced', true);
3549
		} else {
3550
			hideInput('dhcphostname', false);
3551
			hideIpAddress('alias-address', false);
3552
			hideInput('dhcprejectfrom', false);
3553
			hideInput('adv_dhcp_config_file_override_path', true);
3554
			hideClass('dhcpadvanced', !adv);
3555
		}
3556
	}
3557

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

    
3568
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3569
		$('#adv_dhcp_pt_timeout').val(timeout);
3570
		$('#adv_dhcp_pt_retry').val(retry);
3571
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3572
		$('#adv_dhcp_pt_reboot').val(reboot);
3573
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3574
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3575
	}
3576

    
3577
	// ---------- On initial page load ------------------------------------------------------------
3578

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

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

    
3601
	// Set preset from value
3602
	setPresets(sv);
3603

    
3604
	// ---------- Click checkbox handlers ---------------------------------------------------------
3605

    
3606
	$('#type').on('change', function() {
3607
		updateType(this.value);
3608
	});
3609

    
3610
	$('#type6').on('change', function() {
3611
		updateTypeSix(this.value);
3612
	});
3613

    
3614
	$('#pppoe-reset-type').on('change', function() {
3615
		show_reset_settings(this.value);
3616
	});
3617

    
3618
	$("#add").click(function() {
3619
		hide_add_gatewaysave();
3620
	});
3621

    
3622
	$("#cnx").click(function() {
3623
		$("#newgateway").modal('hide');
3624
	});
3625

    
3626
	$("#add6").click(function() {
3627
		hide_add_gatewaysave_v6();
3628
	});
3629

    
3630
	$("#cnx6").click(function() {
3631
		$("#newgateway6").modal('hide');
3632
	});
3633

    
3634
	$('#country').on('change', function() {
3635
		providers_list();
3636
	});
3637

    
3638
	$('#provider_list').on('change', function() {
3639
		providerplan_list();
3640
	});
3641

    
3642
	$('#providerplan').on('change', function() {
3643
		prefill_provider();
3644
	});
3645

    
3646
	$('#dhcpadv, #dhcpovr').click(function () {
3647
		setDHCPoptions();
3648
	});
3649

    
3650
	$('#adv_dhcp6_config_advanced').click(function () {
3651
		show_dhcp6adv();
3652
	});
3653

    
3654
	$('#adv_dhcp6_config_file_override').click(function () {
3655
		show_dhcp6adv();
3656
	});
3657

    
3658
	// On click . .
3659
	$('[name=adv_dhcp_pt_values]').click(function () {
3660
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3661
	});
3662

    
3663
});
3664
//]]>
3665
</script>
3666

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