Project

General

Profile

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

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

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

    
76
define("ANTENNAS", false);
77

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
440
}
441

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

    
450
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
451
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
452
			foreach ($toapplylist as $ifapply => $ifcfgo) {
453
				if (isset($config['interfaces'][$ifapply]['enable'])) {
454
					interface_bring_down($ifapply, false, $ifcfgo);
455
					interface_configure($ifapply, true);
456
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
457
						/* call interface_track6_configure with linkup true so
458
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
459
						   just call interface_configure with linkup true as
460
						   that skips bridge membership addition.
461
						*/
462
						$wancfg = $config['interfaces'][$ifapply];
463
						interface_track6_configure($ifapply, $wancfg, true);
464
					}
465
				} else {
466
					interface_bring_down($ifapply, true, $ifcfgo);
467
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
468
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
469
						services_dhcpd_configure();
470
					}
471
				}
472
			}
473
		}
474
		/* restart snmp so that it binds to correct address */
475
		services_snmpd_configure();
476

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

    
480
		clear_subsystem_dirty('interfaces');
481

    
482
		filter_configure();
483

    
484
		enable_rrd_graphing();
485

    
486
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
487
			clear_subsystem_dirty('staticroutes');
488
		}
489
	}
490
	@unlink("{$g['tmp_path']}/.interfaces.apply");
491
	header("Location: interfaces.php?if={$if}");
492
	exit;
493
} else if ($_POST) {
494

    
495
	unset($input_errors);
496
	$pconfig = $_POST;
497

    
498
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
499
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
500
	} else {
501
		$pconfig['track6-prefix-id'] = 0;
502
	}
503
	conf_mount_rw();
504

    
505
	/* filter out spaces from descriptions */
506
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
507

    
508
	/* okay first of all, cause we are just hiding the PPPoE HTML
509
	 * fields related to PPPoE resets, we are going to unset $_POST
510
	 * vars, if the reset feature should not be used. Otherwise the
511
	 * data validation procedure below, may trigger a false error
512
	 * message.
513
	 */
514
	if (empty($_POST['pppoe-reset-type'])) {
515
		unset($_POST['pppoe_pr_type']);
516
		unset($_POST['pppoe_resethour']);
517
		unset($_POST['pppoe_resetminute']);
518
		unset($_POST['pppoe_resetdate']);
519
		unset($_POST['pppoe_pr_preset_val']);
520
	}
521
	/* input validation */
522
	$reqdfields = explode(" ", "descr");
523
	$reqdfieldsn = array(gettext("Description"));
524
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
525

    
526
	if (!$input_errors) {
527
		/* description unique? */
528
		foreach ($ifdescrs as $ifent => $ifdescr) {
529
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
530
				$input_errors[] = gettext("An interface with the specified description already exists.");
531
				break;
532
			}
533
		}
534

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

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

    
553
		if (is_numeric($_POST['descr'])) {
554
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
555
		}
556

    
557
		/*
558
		 * Packages (e.g. tinc) create interface groups, reserve this
559
		 * namespace pkg_ for them.
560
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
561
		 */
562
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
563
			$input_errors[] = gettext("The interface description cannot start with pkg_");
564
		}
565
	}
566

    
567
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
568
		if (!preg_match("/^staticv4/", $_POST['type'])) {
569
			$input_errors[] = gettext("The DHCP Server is active " .
570
			    "on this interface and it can be used only with " .
571
			    "a static IP configuration. Please disable the " .
572
			    "DHCP Server service on this interface first, " .
573
			    "then change the interface configuration.");
574
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
575
			$input_errors[] = gettext("The DHCP Server is active " .
576
			    "on this interface and it can be used only with " .
577
			    "IPv4 subnet < 31. Please disable the " .
578
			    "DHCP Server service on this interface first, " .
579
			    "then change the interface configuration.");
580
		}
581
	}
582
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
583
		$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.");
584
	}
585

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

    
693
			if (empty($_POST['track6-interface'])) {
694
				$input_errors[] = gettext("A valid interface to track must be selected.");
695
			}
696

    
697
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
698
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
699
			} else {
700
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
701
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
702
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
703
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
704
				} else {
705
					foreach ($ifdescrs as $ifent => $ifdescr) {
706
						if ($if == $ifent) {
707
							continue;
708
						}
709
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
710
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
711
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
712
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
713
						}
714
					}
715
				}
716
			}
717
			break;
718
	}
719

    
720
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
721
	$staticroutes = get_staticroutes(true);
722
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
723
	if ($_POST['ipaddr']) {
724
		if (!is_ipaddrv4($_POST['ipaddr'])) {
725
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
726
		} else {
727
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
728
			if (count($where_ipaddr_configured)) {
729
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
730
				foreach ($where_ipaddr_configured as $subnet_conflict) {
731
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
732
				}
733
				$input_errors[] = $subnet_conflict_text;
734
			}
735

    
736
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
737
			if ($_POST['subnet'] < 31) {
738
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
739
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
740
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
741
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
742
				}
743
			}
744

    
745
			foreach ($staticroutes as $route_subnet) {
746
				list($network, $subnet) = explode("/", $route_subnet);
747
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
748
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
749
					break;
750
				}
751
				unset($network, $subnet);
752
			}
753
		}
754
	}
755
	if ($_POST['ipaddrv6']) {
756
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
757

    
758
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
759
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
760
		} else {
761
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
762
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
763
			}
764
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
765
			if (count($where_ipaddr_configured)) {
766
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
767
				foreach ($where_ipaddr_configured as $subnet_conflict) {
768
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
769
				}
770
				$input_errors[] = $subnet_conflict_text;
771
			}
772

    
773
			foreach ($staticroutes as $route_subnet) {
774
				list($network, $subnet) = explode("/", $route_subnet);
775
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
776
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
777
					break;
778
				}
779
				unset($network, $subnet);
780
			}
781
		}
782
	}
783
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
784
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
785
	}
786
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
787
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
788
	}
789
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
790
		$input_errors[] = gettext("A valid alias IP address must be specified.");
791
	}
792
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
793
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
794
	}
795
	if ($_POST['dhcprejectfrom'] && !is_ipaddrv4($_POST['dhcprejectfrom'])) {
796
		$input_errors[] = gettext("A valid alias IP address must be specified to reject DHCP Leases from.");
797
	}
798
	if (($_POST['gateway'] != "none") || ($_POST['gatewayv6'] != "none")) {
799
		$match = false;
800
		foreach ($a_gateways as $gateway) {
801
			if (in_array($_POST['gateway'], $gateway)) {
802
				$match = true;
803
			}
804
		}
805
		foreach ($a_gateways as $gateway) {
806
			if (in_array($_POST['gatewayv6'], $gateway)) {
807
				$match = true;
808
			}
809
		}
810
		if (!$match) {
811
			$input_errors[] = gettext("A valid gateway must be specified.");
812
		}
813
	}
814
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
815
		$input_errors[] = gettext("The service name contains invalid characters.");
816
	}
817
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
818
		$input_errors[] = gettext("The idle timeout value must be an integer.");
819
	}
820
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
821
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
822
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
823
	}
824
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
825
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
826
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
827
	}
828
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
829
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
830
	}
831
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
832
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
833
	}
834
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
835
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
836
	}
837
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
838
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
839
	}
840
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
841
		$input_errors[] = gettext("The idle timeout value must be an integer.");
842
	}
843
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
844
		$input_errors[] = gettext("A valid MAC address must be specified.");
845
	}
846
	if ($_POST['mtu']) {
847
		if (!is_numericint($_POST['mtu'])) {
848
			$input_errors[] = "MTU must be an integer.";
849
		}
850
		if (substr($wancfg['if'], 0, 3) == 'gif') {
851
			$min_mtu = 1280;
852
			$max_mtu = 8192;
853
		} else {
854
			$min_mtu = 576;
855
			$max_mtu = 9000;
856
		}
857

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

    
862
		unset($min_mtu, $max_mtu);
863

    
864
		if (stristr($wancfg['if'], "_vlan")) {
865
			$realhwif_array = get_parent_interface($wancfg['if']);
866
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
867
			$parent_realhwif = $realhwif_array[0];
868
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
869
			$mtu = 0;
870
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
871
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
872
			if ($mtu == 0)
873
				$mtu = get_interface_mtu($parent_realhwif);
874
			if ($_POST['mtu'] > $mtu)
875
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
876
		} else {
877
			foreach ($config['interfaces'] as $idx => $ifdata) {
878
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
879
					continue;
880
				}
881

    
882
				$realhwif_array = get_parent_interface($ifdata['if']);
883
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
884
				$parent_realhwif = $realhwif_array[0];
885

    
886
				if ($parent_realhwif != $wancfg['if']) {
887
					continue;
888
				}
889

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

    
977
		if ($_POST['passphrase']) {
978
			$passlen = strlen($_POST['passphrase']);
979
			if ($passlen < 8 || $passlen > 63) {
980
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
981
			}
982
		}
983

    
984
		if ($_POST['wpa_enable'] == "yes") {
985
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
986
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
987
			}
988
		}
989
	}
990

    
991
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
992
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
993
	}
994

    
995
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
996
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
997
	}
998

    
999
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1000
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1001
	}
1002

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

    
1010
		if ($wancfg['ipaddr'] != $_POST['type']) {
1011
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1012
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1013
				unset($a_ppps[$pppid]);
1014
			} else if ($wancfg['ipaddr'] == "dhcp") {
1015
				kill_dhclient_process($wancfg['if']);
1016
			}
1017
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1018
				$pid = find_dhcp6c_process($wancfg['if']);
1019
				if ($pid) {
1020
					posix_kill($pid, SIGTERM);
1021
				}
1022
			}
1023
		}
1024
		$ppp = array();
1025
		if ($wancfg['ipaddr'] != "ppp") {
1026
			unset($wancfg['ipaddr']);
1027
		}
1028
		if ($wancfg['ipaddrv6'] != "ppp") {
1029
			unset($wancfg['ipaddrv6']);
1030
		}
1031
		unset($wancfg['subnet']);
1032
		unset($wancfg['gateway']);
1033
		unset($wancfg['subnetv6']);
1034
		unset($wancfg['gatewayv6']);
1035
		unset($wancfg['dhcphostname']);
1036
		unset($wancfg['dhcprejectfrom']);
1037
		unset($wancfg['dhcp6-duid']);
1038
		unset($wancfg['dhcp6-ia-pd-len']);
1039
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1040
		unset($wancfg['dhcp6prefixonly']);
1041
		unset($wancfg['dhcp6usev4iface']);
1042
		unset($wancfg['dhcp6debug']);
1043
		unset($wancfg['track6-interface']);
1044
		unset($wancfg['track6-prefix-id']);
1045
		unset($wancfg['dhcp6withoutra']);
1046
		unset($wancfg['dhcp6norelease']);
1047
		unset($wancfg['prefix-6rd']);
1048
		unset($wancfg['prefix-6rd-v4plen']);
1049
		unset($wancfg['gateway-6rd']);
1050

    
1051
		unset($wancfg['adv_dhcp_pt_timeout']);
1052
		unset($wancfg['adv_dhcp_pt_retry']);
1053
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1054
		unset($wancfg['adv_dhcp_pt_reboot']);
1055
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1056
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1057

    
1058
		unset($wancfg['adv_dhcp_pt_values']);
1059

    
1060
		unset($wancfg['adv_dhcp_send_options']);
1061
		unset($wancfg['adv_dhcp_request_options']);
1062
		unset($wancfg['adv_dhcp_required_options']);
1063
		unset($wancfg['adv_dhcp_option_modifiers']);
1064

    
1065
		unset($wancfg['adv_dhcp_config_advanced']);
1066
		unset($wancfg['adv_dhcp_config_file_override']);
1067
		unset($wancfg['adv_dhcp_config_file_override_path']);
1068

    
1069
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1070
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1071
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1072
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1073

    
1074
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1075
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1076
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1077
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1078
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1079

    
1080
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1081
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1082
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1083
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1084
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1085

    
1086
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1087
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1088

    
1089
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1090
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1091
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1092
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1093

    
1094
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1095
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1096
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1097
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1098
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1099

    
1100
		unset($wancfg['adv_dhcp6_config_advanced']);
1101
		unset($wancfg['adv_dhcp6_config_file_override']);
1102
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1103

    
1104
		unset($wancfg['pppoe_password']);
1105
		unset($wancfg['pptp_username']);
1106
		unset($wancfg['pptp_password']);
1107
		unset($wancfg['provider']);
1108
		unset($wancfg['ondemand']);
1109
		unset($wancfg['timeout']);
1110
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1111
			unset($wancfg['pppoe']['pppoe-reset-type']);
1112
		}
1113
		unset($wancfg['local']);
1114

    
1115
		unset($wancfg['remote']);
1116
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1117
			if ($wancfg['ipaddr'] != 'ppp') {
1118
				unset($a_ppps[$pppid]['apn']);
1119
				unset($a_ppps[$pppid]['phone']);
1120
				unset($a_ppps[$pppid]['provider']);
1121
				unset($a_ppps[$pppid]['ondemand']);
1122
			}
1123
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1124
				unset($a_ppps[$pppid]['localip']);
1125
				unset($a_ppps[$pppid]['subnet']);
1126
				unset($a_ppps[$pppid]['gateway']);
1127
			}
1128
			if ($wancfg['ipaddr'] != 'pppoe') {
1129
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1130
			}
1131
			if ($wancfg['type'] != $_POST['type']) {
1132
				unset($a_ppps[$pppid]['idletimeout']);
1133
			}
1134
		}
1135

    
1136
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1137
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1138

    
1139
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1140
		switch ($_POST['type']) {
1141
			case "staticv4":
1142
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1143
				$wancfg['subnet'] = $_POST['subnet'];
1144
				if ($_POST['gateway'] != "none") {
1145
					$wancfg['gateway'] = $_POST['gateway'];
1146
				}
1147
				break;
1148
			case "dhcp":
1149
				$wancfg['ipaddr'] = "dhcp";
1150
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1151
				$wancfg['alias-address'] = $_POST['alias-address'];
1152
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1153
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1154

    
1155
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1156
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1157
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1158
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1159
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1160
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1161

    
1162
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1163

    
1164
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1165
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1166
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1167
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1168

    
1169
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1170
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1171
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1172

    
1173
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1174
				if ($gateway_item) {
1175
					$a_gateways[] = $gateway_item;
1176
				}
1177
				break;
1178
			case "ppp":
1179
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1180
				$a_ppps[$pppid]['type'] = $_POST['type'];
1181
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1182
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1183
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1184
				if ($_POST['ppp_password'] != DMYPWD) {
1185
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1186
				}
1187
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1188
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1189
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1190
				$wancfg['ipaddr'] = $_POST['type'];
1191
				break;
1192

    
1193
			case "pppoe":
1194
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1195
				$a_ppps[$pppid]['type'] = $_POST['type'];
1196
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1197
				if (isset($_POST['ppp_port'])) {
1198
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1199
				} else {
1200
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1201
				}
1202
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1203
				if ($_POST['pppoe_password'] != DMYPWD) {
1204
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1205
				}
1206
				if (!empty($_POST['provider'])) {
1207
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1208
				} else {
1209
					$a_ppps[$pppid]['provider'] = true;
1210
				}
1211
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1212
				if (!empty($_POST['pppoe_idletimeout'])) {
1213
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1214
				} else {
1215
					unset($a_ppps[$pppid]['idletimeout']);
1216
				}
1217

    
1218
				if (!empty($_POST['pppoe-reset-type'])) {
1219
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1220
				} else {
1221
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1222
				}
1223
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1224
				$wancfg['ipaddr'] = $_POST['type'];
1225
				if ($gateway_item) {
1226
					$a_gateways[] = $gateway_item;
1227
				}
1228

    
1229
				break;
1230
			case "pptp":
1231
			case "l2tp":
1232
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1233
				$a_ppps[$pppid]['type'] = $_POST['type'];
1234
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1235
				if (isset($_POST['ppp_port'])) {
1236
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1237
				} else {
1238
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1239
				}
1240
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1241
				if ($_POST['pptp_password'] != DMYPWD) {
1242
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1243
				}
1244
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1245
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1246
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1247
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1248
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1249
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1250
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1251
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1252
				if (!empty($_POST['pptp_idletimeout'])) {
1253
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1254
				} else {
1255
					unset($a_ppps[$pppid]['idletimeout']);
1256
				}
1257
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1258
				$wancfg['ipaddr'] = $_POST['type'];
1259
				if ($gateway_item) {
1260
					$a_gateways[] = $gateway_item;
1261
				}
1262
				break;
1263
			case "none":
1264
				break;
1265
		}
1266
		switch ($_POST['type6']) {
1267
			case "staticv6":
1268
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1269
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1270
				if ($_POST['gatewayv6'] != "none") {
1271
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1272
				}
1273
				break;
1274
			case "slaac":
1275
				$wancfg['ipaddrv6'] = "slaac";
1276
				break;
1277
			case "dhcp6":
1278
				$wancfg['ipaddrv6'] = "dhcp6";
1279
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1280
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1281
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1282
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1283
				}
1284
				if ($_POST['dhcp6prefixonly'] == "yes") {
1285
					$wancfg['dhcp6prefixonly'] = true;
1286
				}
1287
				if ($_POST['dhcp6usev4iface'] == "yes") {
1288
					$wancfg['dhcp6usev4iface'] = true;
1289
				}
1290
				if ($_POST['dhcp6debug'] == "yes") {
1291
					$wancfg['dhcp6debug'] = true;
1292
				}
1293

    
1294
				if ($_POST['dhcp6withoutra'] == "yes") {
1295
					$wancfg['dhcp6withoutra'] = true;
1296
				}
1297
				if ($_POST['dhcp6norelease'] == "yes") {
1298
					$wancfg['dhcp6norelease'] = true;
1299
				}
1300
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1301
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1304
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1305
				}
1306
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1307
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1310
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1311
				}
1312

    
1313
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1314
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1317
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1318
				}
1319
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1320
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1323
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1326
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1327
				}
1328

    
1329
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1330
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1333
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1334
				}
1335
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1336
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1337
				}
1338
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1339
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1340
				}
1341
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1342
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1343
				}
1344

    
1345
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1346
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1347
				}
1348
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1349
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1350
				}
1351

    
1352
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1353
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1354
				}
1355
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1356
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1357
				}
1358
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1359
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1360
				}
1361
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1362
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1363
				}
1364

    
1365
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1366
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1367
				}
1368
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1369
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1370
				}
1371
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1372
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1373
				}
1374
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1375
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1376
				}
1377
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1378
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1379
				}
1380

    
1381
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1382
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1383
				}
1384
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1385
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1386
				}
1387
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1388
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1389
				}
1390

    
1391
				if ($gateway_item) {
1392
					$a_gateways[] = $gateway_item;
1393
				}
1394
				break;
1395
			case "6rd":
1396
				$wancfg['ipaddrv6'] = "6rd";
1397
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1398
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1399
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1400
				if ($gateway_item) {
1401
					$a_gateways[] = $gateway_item;
1402
				}
1403
				break;
1404
			case "6to4":
1405
				$wancfg['ipaddrv6'] = "6to4";
1406
				break;
1407
			case "track6":
1408
				$wancfg['ipaddrv6'] = "track6";
1409
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1410
				if ($_POST['track6-prefix-id--hex'] === "") {
1411
					$wancfg['track6-prefix-id'] = 0;
1412
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1413
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1414
				} else {
1415
					$wancfg['track6-prefix-id'] = 0;
1416
				}
1417
				break;
1418
			case "none":
1419
				break;
1420
		}
1421
		handle_pppoe_reset($_POST);
1422

    
1423
		if ($_POST['blockpriv'] == "yes") {
1424
			$wancfg['blockpriv'] = true;
1425
		} else {
1426
			unset($wancfg['blockpriv']);
1427
		}
1428
		if ($_POST['blockbogons'] == "yes") {
1429
			$wancfg['blockbogons'] = true;
1430
		} else {
1431
			unset($wancfg['blockbogons']);
1432
		}
1433
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1434
		if (empty($_POST['mtu'])) {
1435
			unset($wancfg['mtu']);
1436
		} else {
1437
			$wancfg['mtu'] = $_POST['mtu'];
1438
		}
1439
		if (empty($_POST['mss'])) {
1440
			unset($wancfg['mss']);
1441
		} else {
1442
			$wancfg['mss'] = $_POST['mss'];
1443
		}
1444
		if (empty($_POST['mediaopt'])) {
1445
			unset($wancfg['media']);
1446
			unset($wancfg['mediaopt']);
1447
		} else {
1448
			$mediaopts = explode(' ', $_POST['mediaopt']);
1449
			if ($mediaopts[0] != '') {
1450
				$wancfg['media'] = $mediaopts[0];
1451
			}
1452
			if ($mediaopts[1] != '') {
1453
				$wancfg['mediaopt'] = $mediaopts[1];
1454
			} else {
1455
				unset($wancfg['mediaopt']);
1456
			}
1457
		}
1458
		if (isset($wancfg['wireless'])) {
1459
			handle_wireless_post();
1460
		}
1461

    
1462
		conf_mount_ro();
1463
		write_config();
1464

    
1465
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1466
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1467
		} else {
1468
			$toapplylist = array();
1469
		}
1470
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1471
		$toapplylist[$if]['ppps'] = $old_ppps;
1472
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1473

    
1474
		mark_subsystem_dirty('interfaces');
1475

    
1476
		/* regenerate cron settings/crontab file */
1477
		configure_cron();
1478

    
1479
		header("Location: interfaces.php?if={$if}");
1480
		exit;
1481
	}
1482

    
1483
} // end if ($_POST)
1484

    
1485
function handle_wireless_post() {
1486
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1487
	if (!is_array($wancfg['wireless'])) {
1488
		$wancfg['wireless'] = array();
1489
	}
1490
	$wancfg['wireless']['standard'] = $_POST['standard'];
1491
	$wancfg['wireless']['mode'] = $_POST['mode'];
1492
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1493
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1494
	$wancfg['wireless']['channel'] = $_POST['channel'];
1495
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1496
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1497
	$wancfg['wireless']['distance'] = $_POST['distance'];
1498
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1499
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1500
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1501
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1502
		foreach ($wl_countries_attr as $wl_country) {
1503
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1504
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1505
				break;
1506
			}
1507
		}
1508
	}
1509
	if (!is_array($wancfg['wireless']['wpa'])) {
1510
		$wancfg['wireless']['wpa'] = array();
1511
	}
1512
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1513
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1514
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1515
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1516
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1517
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1518
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1519
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1520
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1521
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1522
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1523
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1524
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1525
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1526

    
1527
	if ($_POST['persistcommonwireless'] == "yes") {
1528
		if (!is_array($config['wireless'])) {
1529
			$config['wireless'] = array();
1530
		}
1531
		if (!is_array($config['wireless']['interfaces'])) {
1532
			$config['wireless']['interfaces'] = array();
1533
		}
1534
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1535
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1536
		}
1537
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1538
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1539
	}
1540
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1541
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1542
	} else if (isset($wancfg['wireless']['diversity'])) {
1543
		unset($wancfg['wireless']['diversity']);
1544
	}
1545
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1546
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1547
	} else if (isset($wancfg['wireless']['txantenna'])) {
1548
		unset($wancfg['wireless']['txantenna']);
1549
	}
1550
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1551
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1552
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1553
		unset($wancfg['wireless']['rxantenna']);
1554
	}
1555
	if ($_POST['hidessid_enable'] == "yes") {
1556
		$wancfg['wireless']['hidessid']['enable'] = true;
1557
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1558
		unset($wancfg['wireless']['hidessid']['enable']);
1559
	}
1560
	if ($_POST['mac_acl_enable'] == "yes") {
1561
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1562
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1563
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1564
	}
1565
	if ($_POST['rsn_preauth'] == "yes") {
1566
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1567
	} else {
1568
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1569
	}
1570
	if ($_POST['ieee8021x'] == "yes") {
1571
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1572
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1573
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1574
	}
1575
	if ($_POST['wpa_strict_rekey'] == "yes") {
1576
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1577
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1578
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1579
	}
1580
	if ($_POST['debug_mode'] == "yes") {
1581
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1582
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1583
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1584
	}
1585
	if ($_POST['wpa_enable'] == "yes") {
1586
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1587
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1588
		unset($wancfg['wireless']['wpa']['enable']);
1589
	}
1590

    
1591
	if ($_POST['wme_enable'] == "yes") {
1592
		if (!is_array($wancfg['wireless']['wme'])) {
1593
			$wancfg['wireless']['wme'] = array();
1594
		}
1595
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1596
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1597
		unset($wancfg['wireless']['wme']['enable']);
1598
	}
1599
	if ($_POST['puremode'] == "11g") {
1600
		if (!is_array($wancfg['wireless']['pureg'])) {
1601
			$wancfg['wireless']['pureg'] = array();
1602
		}
1603
		$wancfg['wireless']['pureg']['enable'] = true;
1604
	} else if ($_POST['puremode'] == "11n") {
1605
		if (!is_array($wancfg['wireless']['puren'])) {
1606
			$wancfg['wireless']['puren'] = array();
1607
		}
1608
		$wancfg['wireless']['puren']['enable'] = true;
1609
	} else {
1610
		if (isset($wancfg['wireless']['pureg'])) {
1611
			unset($wancfg['wireless']['pureg']);
1612
		}
1613
		if (isset($wancfg['wireless']['puren'])) {
1614
			unset($wancfg['wireless']['puren']);
1615
		}
1616
	}
1617
	if ($_POST['apbridge_enable'] == "yes") {
1618
		if (!is_array($wancfg['wireless']['apbridge'])) {
1619
			$wancfg['wireless']['apbridge'] = array();
1620
		}
1621
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1622
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1623
		unset($wancfg['wireless']['apbridge']['enable']);
1624
	}
1625
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1626
		if (!is_array($wancfg['wireless']['turbo'])) {
1627
			$wancfg['wireless']['turbo'] = array();
1628
		}
1629
		$wancfg['wireless']['turbo']['enable'] = true;
1630
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1631
		unset($wancfg['wireless']['turbo']['enable']);
1632
	}
1633

    
1634
	interface_sync_wireless_clones($wancfg, true);
1635
}
1636

    
1637
function check_wireless_mode() {
1638
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1639

    
1640
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1641
		return;
1642
	}
1643

    
1644
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1645
		$clone_count = 1;
1646
	} else {
1647
		$clone_count = 0;
1648
	}
1649

    
1650
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1651
		foreach ($config['wireless']['clone'] as $clone) {
1652
			if ($clone['if'] == $wlanbaseif) {
1653
				$clone_count++;
1654
			}
1655
		}
1656
	}
1657

    
1658
	if ($clone_count > 1) {
1659
		$old_wireless_mode = $wancfg['wireless']['mode'];
1660
		$wancfg['wireless']['mode'] = $_POST['mode'];
1661
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1662
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."), $wlan_modes[$wancfg['wireless']['mode']]);
1663
		} else {
1664
			pfSense_interface_destroy("{$wlanif}_");
1665
		}
1666
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1667
	}
1668
}
1669

    
1670
// Find all possible media options for the interface
1671
$mediaopts_list = array();
1672
$intrealname = $config['interfaces'][$if]['if'];
1673
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1674
foreach ($mediaopts as $mediaopt) {
1675
	preg_match("/media (.*)/", $mediaopt, $matches);
1676
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1677
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1678
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1679
	} else {
1680
		// there is only media like "media 1000baseT"
1681
		array_push($mediaopts_list, $matches[1]);
1682
	}
1683
}
1684

    
1685
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1686
$shortcut_section = "interfaces";
1687

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

    
1691
// Get the MAC address
1692
$ip = $_SERVER['REMOTE_ADDR'];
1693
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1694
$mymac = str_replace("\n", "", $mymac);
1695

    
1696
function build_mediaopts_list() {
1697
	global $mediaopts_list;
1698

    
1699
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1700
			 " " =>	 gettext("------- Media Supported by this interface -------")
1701
			];
1702

    
1703
	foreach ($mediaopts_list as $mediaopt) {
1704
		$list[$mediaopt] = $mediaopt;
1705
	}
1706

    
1707
	return($list);
1708
}
1709

    
1710
function build_gateway_list() {
1711
	global $a_gateways, $if;
1712

    
1713
	$list = array("none" => gettext("None"));
1714
	foreach ($a_gateways as $gateway) {
1715
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1716
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1717
		}
1718
	}
1719

    
1720
	return($list);
1721
}
1722

    
1723
function build_gatewayv6_list() {
1724
	global $a_gateways, $if;
1725

    
1726
	$list = array("none" => gettext("None"));
1727
	foreach ($a_gateways as $gateway) {
1728
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1729
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1730
		}
1731
	}
1732

    
1733
	return($list);
1734
}
1735

    
1736
include("head.inc");
1737

    
1738
if ($input_errors) {
1739
	print_input_errors($input_errors);
1740
}
1741

    
1742
if (is_subsystem_dirty('interfaces')) {
1743
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1744
					gettext("The changes must be applied to take effect.") . "<br />" .
1745
					gettext("Don't forget to adjust the DHCP Server range if needed after applying."));
1746
}
1747

    
1748
if ($savemsg) {
1749
	print_info_box($savemsg, 'success');
1750
}
1751

    
1752

    
1753
$form = new Form();
1754

    
1755
$section = new Form_Section('General Configuration');
1756

    
1757
$section->addInput(new Form_Checkbox(
1758
	'enable',
1759
	'Enable',
1760
	'Enable interface',
1761
	$pconfig['enable'],
1762
	'yes'
1763
));
1764

    
1765
$section->addInput(new Form_Input(
1766
	'descr',
1767
	'*Description',
1768
	'text',
1769
	$pconfig['descr']
1770
))->setHelp('Enter a description (name) for the interface here.');
1771

    
1772
$section->addInput(new Form_Select(
1773
	'type',
1774
	'IPv4 Configuration Type',
1775
	$pconfig['type'],
1776
	$types4
1777
));
1778

    
1779
$section->addInput(new Form_Select(
1780
	'type6',
1781
	'IPv6 Configuration Type',
1782
	$pconfig['type6'],
1783
	$types6
1784
));
1785

    
1786
$macaddress = new Form_Input(
1787
	'spoofmac',
1788
	'MAC Address',
1789
	'text',
1790
	$pconfig['spoofmac'],
1791
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1792
);
1793

    
1794
$btnmymac = new Form_Button(
1795
	'btnmymac',
1796
	'Copy My MAC',
1797
	null,
1798
	'fa-clone'
1799
	);
1800

    
1801
$btnmymac->setAttribute('type','button')->addClass('btn-success btn-sm');
1802

    
1803
$group = new Form_Group('MAC Address');
1804
$group->add($macaddress);
1805
// $group->add($btnmymac);
1806
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1807
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.');
1808
$section->add($group);
1809

    
1810
$section->addInput(new Form_Input(
1811
	'mtu',
1812
	'MTU',
1813
	'number',
1814
	$pconfig['mtu']
1815
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1816
			'This is typically 1500 bytes but can vary in some circumstances.');
1817

    
1818
$section->addInput(new Form_Input(
1819
	'mss',
1820
	'MSS',
1821
	'number',
1822
	$pconfig['mss']
1823
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1824
			'header size) will be in effect.');
1825

    
1826
if (count($mediaopts_list) > 0) {
1827
	$section->addInput(new Form_Select(
1828
		'mediaopt',
1829
		'Speed and Duplex',
1830
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1831
		build_mediaopts_list()
1832
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1833
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1834
}
1835

    
1836
$form->add($section);
1837

    
1838
$section = new Form_Section('Static IPv4 Configuration');
1839
$section->addClass('staticv4');
1840

    
1841
$section->addInput(new Form_IpAddress(
1842
	'ipaddr',
1843
	'*IPv4 Address',
1844
	$pconfig['ipaddr'],
1845
	'V4'
1846
))->addMask('subnet', $pconfig['subnet'], 32);
1847

    
1848
$group = new Form_Group('IPv4 Upstream gateway');
1849

    
1850
$group->add(new Form_Select(
1851
	'gateway',
1852
	'IPv4 Upstream Gateway',
1853
	$pconfig['gateway'],
1854
	build_gateway_list()
1855
));
1856

    
1857
$group->add(new Form_Button(
1858
	'addgw',
1859
	'Add a new gateway',
1860
	null,
1861
	'fa-plus'
1862
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1863

    
1864
$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 />' .
1865
				'On local area network interfaces the upstream gateway should be "none". ' .
1866
				gettext('Gateways can be managed by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>.');
1867

    
1868
$section->add($group);
1869

    
1870
$form->add($section);
1871

    
1872
$section = new Form_Section('Static IPv6 Configuration');
1873
$section->addClass('staticv6');
1874

    
1875
$section->addInput(new Form_IpAddress(
1876
	'ipaddrv6',
1877
	'*IPv6 address',
1878
	$pconfig['ipaddrv6'],
1879
	'V6'
1880
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1881

    
1882
$group = new Form_Group('IPv6 Upstream gateway');
1883

    
1884
$group->add(new Form_Select(
1885
	'gatewayv6',
1886
	'IPv6 Upstream Gateway',
1887
	$pconfig['gatewayv6'],
1888
	build_gatewayv6_list()
1889
));
1890

    
1891
$group->add(new Form_Button(
1892
	'addgw6',
1893
	'Add a new gateway',
1894
	null,
1895
	'fa-plus'
1896
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1897

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

    
1901
$section->add($group);
1902
$form->add($section);
1903

    
1904
// Add new gateway modal pop-up for IPv6
1905
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1906

    
1907
$modal->addInput(new Form_Checkbox(
1908
	'defaultgw6',
1909
	'Default',
1910
	'Default gateway',
1911
	($if == "wan" || $if == "WAN")
1912
));
1913

    
1914
$modal->addInput(new Form_Input(
1915
	'name6',
1916
	'Gateway name',
1917
	'text',
1918
	$wancfg['descr'] . "GWv6"
1919
));
1920

    
1921
$modal->addInput(new Form_IpAddress(
1922
	'gatewayip6',
1923
	'Gateway IPv6',
1924
	null,
1925
	'V6'
1926
));
1927

    
1928
$modal->addInput(new Form_Input(
1929
	'gatewaydescr6',
1930
	'Description',
1931
	'text'
1932
));
1933

    
1934
$btnaddgw6 = new Form_Button(
1935
	'add6',
1936
	'Add',
1937
	null,
1938
	'fa-plus'
1939
);
1940

    
1941
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1942

    
1943
$btncnxgw6 = new Form_Button(
1944
	'cnx6',
1945
	'Cancel',
1946
	null,
1947
	'fa-undo'
1948
);
1949

    
1950
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1951

    
1952
$modal->addInput(new Form_StaticText(
1953
	null,
1954
	$btnaddgw6 . $btncnxgw6
1955
));
1956

    
1957
$form->add($modal);
1958

    
1959
// ==== DHCP client configuration =============================
1960

    
1961
$section = new Form_Section('DHCP Client Configuration');
1962
$section->addClass('dhcp');
1963

    
1964
$group = new Form_Group('Options');
1965

    
1966
$group->add(new Form_Checkbox(
1967
	'adv_dhcp_config_advanced',
1968
	null,
1969
	'Advanced Configuration',
1970
	$pconfig['adv_dhcp_config_advanced']
1971
))->setHelp('Use advanced DHCP configuration options.');
1972

    
1973
$group->add(new Form_Checkbox(
1974
	'adv_dhcp_config_file_override',
1975
	null,
1976
	'Configuration Override',
1977
	$pconfig['adv_dhcp_config_file_override']
1978
))->setHelp('Override the configuration from this file.');
1979

    
1980
$section->add($group);
1981

    
1982
$section->addInput(new Form_Input(
1983
	'dhcphostname',
1984
	'Hostname',
1985
	'text',
1986
	$pconfig['dhcphostname']
1987
))->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).');
1988

    
1989
$section->addInput(new Form_IpAddress(
1990
	'alias-address',
1991
	'Alias IPv4 address',
1992
	$pconfig['alias-address'],
1993
	'V4'
1994
))->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.');
1995

    
1996
$section->addInput(new Form_Input(
1997
	'dhcprejectfrom',
1998
	'Reject leases from',
1999
	'text',
2000
	$pconfig['dhcprejectfrom']
2001
))->setHelp('To make the DHCP client reject leases from an undesirable DHCP server, place the IP address of the DHCP server here. ' .
2002
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2003

    
2004
$group = new Form_Group('Protocol timing');
2005
$group->addClass('dhcpadvanced');
2006

    
2007
$group->add(new Form_Input(
2008
	'adv_dhcp_pt_timeout',
2009
	null,
2010
	'number',
2011
	$pconfig['adv_dhcp_pt_timeout']
2012
))->setHelp('Timeout');
2013

    
2014
$group->add(new Form_Input(
2015
	'adv_dhcp_pt_retry',
2016
	null,
2017
	'number',
2018
	$pconfig['adv_dhcp_pt_retry']
2019
))->setHelp('Retry');
2020

    
2021
$group->add(new Form_Input(
2022
	'adv_dhcp_pt_select_timeout',
2023
	null,
2024
	'number',
2025
	$pconfig['adv_dhcp_pt_select_timeout'],
2026
	['min' => 0]
2027
))->setHelp('Select timeout');
2028

    
2029
$group->add(new Form_Input(
2030
	'adv_dhcp_pt_reboot',
2031
	null,
2032
	'number',
2033
	$pconfig['adv_dhcp_pt_reboot']
2034
))->setHelp('Reboot');
2035

    
2036
$group->add(new Form_Input(
2037
	'adv_dhcp_pt_backoff_cutoff',
2038
	null,
2039
	'number',
2040
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2041
))->setHelp('Backoff cutoff');
2042

    
2043
$group->add(new Form_Input(
2044
	'adv_dhcp_pt_initial_interval',
2045
	null,
2046
	'number',
2047
	$pconfig['adv_dhcp_pt_initial_interval']
2048
))->setHelp('Initial interval');
2049

    
2050
$section->add($group);
2051

    
2052
$group = new Form_Group('Presets');
2053
$group->addClass('dhcpadvanced');
2054

    
2055
$group->add(new Form_Checkbox(
2056
	'adv_dhcp_pt_values',
2057
	null,
2058
	'FreeBSD default',
2059
	null,
2060
	'DHCP'
2061
))->displayAsRadio();
2062

    
2063
$group->add(new Form_Checkbox(
2064
	'adv_dhcp_pt_values',
2065
	null,
2066
	'Clear',
2067
	null,
2068
	'Clear'
2069
))->displayAsRadio();
2070

    
2071
$group->add(new Form_Checkbox(
2072
	'adv_dhcp_pt_values',
2073
	null,
2074
	'pfSense Default',
2075
	null,
2076
	'pfSense'
2077
))->displayAsRadio();
2078

    
2079
$group->add(new Form_Checkbox(
2080
	'adv_dhcp_pt_values',
2081
	null,
2082
	'Saved Cfg',
2083
	null,
2084
	'SavedCfg'
2085
))->displayAsRadio();
2086

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

    
2090
$section->add($group);
2091

    
2092
$section->addInput(new Form_Input(
2093
	'adv_dhcp_config_file_override_path',
2094
	'Configuration File Override',
2095
	'text',
2096
	$pconfig['adv_dhcp_config_file_override_path']
2097
))->setWidth(9)->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2098
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2099
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2100
			'Some ISPs may require certain options be or not be sent.');
2101

    
2102
$form->add($section);
2103

    
2104
$section = new Form_Section('Lease Requirements and Requests');
2105
$section->addClass('dhcpadvanced');
2106

    
2107
$section->addInput(new Form_Input(
2108
	'adv_dhcp_send_options',
2109
	'Send options',
2110
	'text',
2111
	$pconfig['adv_dhcp_send_options']
2112
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2113
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2114
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2115
			'Some ISPs may require certain options be or not be sent.');
2116

    
2117
$section->addInput(new Form_Input(
2118
	'adv_dhcp_request_options',
2119
	'Request options',
2120
	'text',
2121
	$pconfig['adv_dhcp_request_options']
2122
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2123
			'Some ISPs may require certain options be or not be requested.');
2124

    
2125
$section->addInput(new Form_Input(
2126
	'adv_dhcp_required_options',
2127
	'Require options',
2128
	'text',
2129
	$pconfig['adv_dhcp_required_options']
2130
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2131

    
2132
$section->addInput(new Form_Input(
2133
	'adv_dhcp_option_modifiers',
2134
	'Option modifiers',
2135
	'text',
2136
	$pconfig['adv_dhcp_option_modifiers']
2137
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2138
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2139
			'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">' . 'See here more information' . '</a>');
2140

    
2141
$form->add($section);
2142

    
2143
// DHCP6 client config
2144

    
2145
$section = new Form_Section('DHCP6 Client Configuration');
2146
$section->addClass('dhcp6');
2147

    
2148
$group = new Form_Group('Options');
2149

    
2150
$group->add(new Form_Checkbox(
2151
	'adv_dhcp6_config_advanced',
2152
	null,
2153
	'Advanced Configuration',
2154
	$pconfig['adv_dhcp6_config_advanced']
2155
))->setHelp('Use advanced DHCPv6 configuration options.');
2156

    
2157
$group->add(new Form_Checkbox(
2158
	'adv_dhcp6_config_file_override',
2159
	null,
2160
	'Configuration Override',
2161
	$pconfig['adv_dhcp6_config_file_override']
2162
))->setHelp('Override the configuration from this file.');
2163

    
2164
$section->add($group);
2165

    
2166
$section->addInput(new Form_Checkbox(
2167
	'dhcp6usev4iface',
2168
	'Use IPv4 connectivity as parent interface',
2169
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2170
	$pconfig['dhcp6usev4iface']
2171
));
2172

    
2173
$section->addInput(new Form_Checkbox(
2174
	'dhcp6prefixonly',
2175
	'Request only an IPv6 prefix',
2176
	'Only request an IPv6 prefix, do not request an IPv6 address',
2177
	$pconfig['dhcp6prefixonly']
2178
));
2179

    
2180
$section->addInput(new Form_Select(
2181
	'dhcp6-ia-pd-len',
2182
	'DHCPv6 Prefix Delegation size',
2183
	$pconfig['dhcp6-ia-pd-len'],
2184
	array("none" => "None", 16 => "48", 12 => "52", 8 => "56", 5 => "59", 4 => "60", 3 => "61",  2 => "62", 1 => "63", 0 => "64")
2185
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2186

    
2187
$section->addInput(new Form_Checkbox(
2188
	'dhcp6-ia-pd-send-hint',
2189
	'Send IPv6 prefix hint',
2190
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2191
	$pconfig['dhcp6-ia-pd-send-hint']
2192
));
2193

    
2194
$section->addInput(new Form_Checkbox(
2195
	'dhcp6debug',
2196
	'Debug',
2197
	'Start DHCP6 client in debug mode',
2198
	$pconfig['dhcp6debug']
2199
));
2200

    
2201
$section->addInput(new Form_Checkbox(
2202
	'dhcp6withoutra',
2203
	'Do not wait for a RA',
2204
	'Required by some ISPs, especially those not using PPPoE',
2205
	$pconfig['dhcp6withoutra']
2206
));
2207
$section->addInput(new Form_Checkbox(
2208
	'dhcp6norelease',
2209
	'Do not allow PD/Address release',
2210
	'dhcp6c will send a release to the ISP on exit, some ISPs then release the allocated address or prefix. This option prevents that signal ever being sent',
2211
	$pconfig['dhcp6norelease']
2212
));
2213
$section->addInput(new Form_Input(
2214
	'adv_dhcp6_config_file_override_path',
2215
	'Configuration File Override',
2216
	'text',
2217
	$pconfig['adv_dhcp6_config_file_override_path']
2218
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2219
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2220
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2221
			'Some ISPs may require certain options be or not be sent.');
2222

    
2223
$form->add($section);
2224

    
2225
// DHCP6 client config - Advanced
2226

    
2227
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2228
$section->addClass('dhcp6advanced');
2229

    
2230
$section->addInput(new Form_Checkbox(
2231
	'adv_dhcp6_interface_statement_information_only_enable',
2232
	'Information only',
2233
	'Exchange Information Only',
2234
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2235
	'Selected'
2236
))->setHelp('Only exchange informational configuration parameters with servers.');
2237

    
2238
$section->addInput(new Form_Input(
2239
	'adv_dhcp6_interface_statement_send_options',
2240
	'Send options',
2241
	'text',
2242
	$pconfig['adv_dhcp6_interface_statement_send_options']
2243
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2244
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2245
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2246
			'Some DHCP services may require certain options be or not be sent.');
2247

    
2248
$section->addInput(new Form_Input(
2249
	'adv_dhcp6_interface_statement_request_options',
2250
	'Request Options',
2251
	'text',
2252
	$pconfig['adv_dhcp6_interface_statement_request_options']
2253
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2254
			'Some DHCP services may require certain options be or not be requested.');
2255

    
2256
$section->addInput(new Form_Input(
2257
	'adv_dhcp6_interface_statement_script',
2258
	'Scripts',
2259
	'text',
2260
	$pconfig['adv_dhcp6_interface_statement_script']
2261
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2262
			'[/[dirname/[.../]]filename[.ext]].');
2263

    
2264
$group = new Form_Group('Identity Association Statement');
2265

    
2266
$group->add(new Form_Checkbox(
2267
	'adv_dhcp6_id_assoc_statement_address_enable',
2268
	null,
2269
	'Non-Temporary Address Allocation',
2270
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2271
	'Selected'
2272
));
2273

    
2274
$group->add(new Form_Input(
2275
	'adv_dhcp6_id_assoc_statement_address_id',
2276
	null,
2277
	'text',
2278
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2279
))->sethelp('id-assoc na ID');
2280

    
2281
$group->add(new Form_IpAddress(
2282
	'adv_dhcp6_id_assoc_statement_address',
2283
	null,
2284
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2285
	'V6'
2286
))->sethelp('IPv6 address');
2287

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

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

    
2302
$section->add($group);
2303

    
2304
// Prefix delegation
2305
$group = new Form_Group('');
2306

    
2307
$group->add(new Form_Checkbox(
2308
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2309
	null,
2310
	'Prefix Delegation ',
2311
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2312
	'Selected'
2313
));
2314

    
2315
$group->add(new Form_Input(
2316
	'adv_dhcp6_id_assoc_statement_prefix_id',
2317
	null,
2318
	'text',
2319
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2320
))->sethelp('id-assoc pd ID');
2321

    
2322
$group->add(new Form_IpAddress(
2323
	'adv_dhcp6_id_assoc_statement_prefix',
2324
	null,
2325
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2326
	'V6'
2327
))->sethelp('IPv6 prefix');
2328

    
2329
$group->add(new Form_Input(
2330
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2331
	null,
2332
	'text',
2333
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2334
))->sethelp('pltime');
2335

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

    
2343
$section->add($group);
2344

    
2345
$group = new Form_Group('Prefix interface statement');
2346

    
2347
$group->add(new Form_Input(
2348
	'adv_dhcp6_prefix_interface_statement_sla_id',
2349
	null,
2350
	'text',
2351
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2352
))->sethelp('Prefix Interface sla-id');
2353

    
2354
$group->add(new Form_Input(
2355
	'adv_dhcp6_prefix_interface_statement_sla_len',
2356
	null,
2357
	'text',
2358
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2359
))->sethelp('sla-len');
2360

    
2361
$section->add($group);
2362

    
2363
$group = new Form_Group('Authentication statement');
2364

    
2365
$group->add(new Form_Input(
2366
	'adv_dhcp6_authentication_statement_authname',
2367
	null,
2368
	'text',
2369
	$pconfig['adv_dhcp6_authentication_statement_authname']
2370
))->sethelp('Authname');
2371

    
2372
$group->add(new Form_Input(
2373
	'adv_dhcp6_authentication_statement_protocol',
2374
	null,
2375
	'text',
2376
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2377
))->sethelp('Protocol');
2378

    
2379
$group->add(new Form_Input(
2380
	'adv_dhcp6_authentication_statement_algorithm',
2381
	null,
2382
	'text',
2383
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2384
))->sethelp('Algorithm');
2385

    
2386
$group->add(new Form_Input(
2387
	'adv_dhcp6_authentication_statement_rdm',
2388
	null,
2389
	'text',
2390
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2391
))->sethelp('RDM');
2392

    
2393
$section->add($group);
2394

    
2395
$group = new Form_Group('Keyinfo statement');
2396

    
2397
$group->add(new Form_Input(
2398
	'adv_dhcp6_key_info_statement_keyname',
2399
	null,
2400
	'text',
2401
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2402
))->sethelp('Keyname');
2403

    
2404
$group->add(new Form_Input(
2405
	'adv_dhcp6_key_info_statement_realm',
2406
	null,
2407
	'text',
2408
	$pconfig['adv_dhcp6_key_info_statement_realm']
2409
))->sethelp('Realm');
2410

    
2411
$section->add($group);
2412

    
2413
$group = new Form_Group('');
2414

    
2415
$group->add(new Form_Input(
2416
	'adv_dhcp6_key_info_statement_keyid',
2417
	null,
2418
	'text',
2419
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2420
))->sethelp('KeyID');
2421

    
2422
$group->add(new Form_Input(
2423
	'adv_dhcp6_key_info_statement_secret',
2424
	null,
2425
	'text',
2426
	$pconfig['adv_dhcp6_key_info_statement_secret']
2427
))->sethelp('Secret');
2428

    
2429
$group->add(new Form_Input(
2430
	'adv_dhcp6_key_info_statement_expire',
2431
	null,
2432
	'text',
2433
	$pconfig['adv_dhcp6_key_info_statement_expire']
2434
))->sethelp('Expire');
2435

    
2436
$group->setHelp('<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhcp6c.conf&sektion=5&apropos=0&manpath=FreeBSD+10.1-RELEASE+and+Ports#Interface_statement">' . 'See here more information' . '</a>');
2437

    
2438
$section->add($group);
2439

    
2440
$form->add($section);
2441

    
2442
$section = new Form_Section('6RD Configuration');
2443
$section->addClass('_6rd');
2444

    
2445
$section->addInput(new Form_Input(
2446
	'prefix-6rd',
2447
	'6RD Prefix',
2448
	'text',
2449
	$pconfig['prefix-6rd']
2450
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2451

    
2452
$section->addInput(new Form_Input(
2453
	'gateway-6rd',
2454
	'*6RD Border relay',
2455
	'text',
2456
	$pconfig['gateway-6rd']
2457
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2458

    
2459
$section->addInput(new Form_Select(
2460
	'prefix-6rd-v4plen',
2461
	'6RD IPv4 Prefix length',
2462
	$pconfig['prefix-6rd-v4plen'],
2463
	array_combine(range(0, 32), range(0, 32))
2464
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2465

    
2466
$form->add($section);
2467

    
2468
// Track IPv6 ointerface section
2469
$section = new Form_Section('Track IPv6 Interface');
2470
$section->addClass('track6');
2471

    
2472
function build_ipv6interface_list() {
2473
	global $config, $section;
2474

    
2475
	$list = array('' => '');
2476

    
2477
	$interfaces = get_configured_interface_with_descr(false, true);
2478
	$dynv6ifs = array();
2479

    
2480
	foreach ($interfaces as $iface => $ifacename) {
2481
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2482
			case "6to4":
2483
			case "6rd":
2484
			case "dhcp6":
2485
				$dynv6ifs[$iface] = array(
2486
					'name' => $ifacename,
2487
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2488
				);
2489
				break;
2490
			default:
2491
				continue;
2492
		}
2493
	}
2494

    
2495
	foreach ($dynv6ifs as $iface => $ifacedata) {
2496
		$list[$iface] = $ifacedata['name'];
2497

    
2498
		$section->addInput(new Form_Input(
2499
			'ipv6-num-prefix-ids-' . $iface,
2500
			null,
2501
			'hidden',
2502
			$ifacedata['ipv6_num_prefix_ids']
2503
		));
2504
	}
2505

    
2506
	return($list);
2507
}
2508

    
2509
$section->addInput(new Form_Select(
2510
	'track6-interface',
2511
	'*IPv6 Interface',
2512
	$pconfig['track6-interface'],
2513
	build_ipv6interface_list()
2514
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2515

    
2516
if ($pconfig['track6-prefix-id'] == "") {
2517
	$pconfig['track6-prefix-id'] = 0;
2518
}
2519

    
2520
$section->addInput(new Form_Input(
2521
	'track6-prefix-id--hex',
2522
	'IPv6 Prefix ID',
2523
	'text',
2524
	sprintf("%x", $pconfig['track6-prefix-id'])
2525
))->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.');
2526

    
2527
$section->addInput(new Form_Input(
2528
	'track6-prefix-id-max',
2529
	null,
2530
	'hidden',
2531
	0
2532
));
2533

    
2534
$form->add($section);
2535

    
2536
/// PPP section
2537

    
2538
$section = new Form_Section('PPP Configuration');
2539
$section->addClass('ppp');
2540

    
2541
$section->addInput(new Form_Select(
2542
	'country',
2543
	'Country',
2544
	$pconfig['country'],
2545
	[]
2546
));
2547

    
2548
$section->addInput(new Form_Select(
2549
	'provider_list',
2550
	'Provider',
2551
	$pconfig['provider_list'],
2552
	[]
2553
));
2554

    
2555
$section->addInput(new Form_Select(
2556
	'providerplan',
2557
	'Plan',
2558
	$pconfig['providerplan'],
2559
	[]
2560
))->setHelp('Select to fill in service provider data.');
2561

    
2562
$section->addInput(new Form_Input(
2563
	'ppp_username',
2564
	'Username',
2565
	'text',
2566
	$pconfig['ppp_username']
2567
));
2568

    
2569
$section->addPassword(new Form_Input(
2570
	'ppp_password',
2571
	'Password',
2572
	'password',
2573
	$pconfig['ppp_password']
2574
));
2575

    
2576
$section->addInput(new Form_Input(
2577
	'phone',
2578
	'*Phone number',
2579
	'text',
2580
	$pconfig['phone']
2581
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2582

    
2583
$section->addInput(new Form_Input(
2584
	'apn',
2585
	'Access Point Name',
2586
	'text',
2587
	$pconfig['apn']
2588
));
2589

    
2590

    
2591
function build_port_list() {
2592
	$list = array("" => "None");
2593

    
2594
	$portlist = glob("/dev/cua*");
2595
	$modems	  = glob("/dev/modem*");
2596
	$portlist = array_merge($portlist, $modems);
2597

    
2598
	foreach ($portlist as $port) {
2599
		if (preg_match("/\.(lock|init)$/", $port)) {
2600
			continue;
2601
		}
2602

    
2603
	$list[trim($port)] = $port;
2604
	}
2605

    
2606
	return($list);
2607
}
2608

    
2609
$section->addInput(new Form_Select(
2610
	'port',
2611
	"*Modem port",
2612
	$pconfig['port'],
2613
	build_port_list()
2614
));
2615

    
2616
$section->addInput(new Form_Button(
2617
	'btnadvppp',
2618
	'Advanced PPP',
2619
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2620
	'fa-cog'
2621
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2622

    
2623
$form->add($section);
2624

    
2625
// PPPoE configuration
2626
$section = new Form_Section('PPPoE Configuration');
2627
$section->addClass('pppoe');
2628

    
2629
$section->addInput(new Form_Input(
2630
	'pppoe_username',
2631
	'*Username',
2632
	'text',
2633
	$pconfig['pppoe_username']
2634
));
2635

    
2636
$section->addPassword(new Form_Input(
2637
	'pppoe_password',
2638
	'*Password',
2639
	'password',
2640
	$pconfig['pppoe_password']
2641
));
2642

    
2643
$section->addInput(new Form_Input(
2644
	'provider',
2645
	'Service name',
2646
	'text',
2647
	$pconfig['provider']
2648
))->setHelp('This field can usually be left empty.');
2649

    
2650
$section->addInput(new Form_Checkbox(
2651
	'pppoe_dialondemand',
2652
	'Dial on demand',
2653
	'Enable Dial-On-Demand mode ',
2654
	$pconfig['pppoe_dialondemand'],
2655
	'enable'
2656
));
2657

    
2658
$section->addInput(new Form_Input(
2659
	'pppoe_idletimeout',
2660
	'Idle timeout',
2661
	'number',
2662
	$pconfig['pppoe_idletimeout'],
2663
	['min' => 0]
2664
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2665
			'An idle timeout of zero disables this feature.');
2666

    
2667
$section->addInput(new Form_Select(
2668
	'pppoe-reset-type',
2669
	'Periodic reset',
2670
	$pconfig['pppoe-reset-type'],
2671
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2672
))->setHelp('Select a reset timing type.');
2673

    
2674
$group = new Form_Group('Custom reset');
2675
$group->addClass('pppoecustom');
2676

    
2677
$group->add(new Form_Input(
2678
	'pppoe_resethour',
2679
	null,
2680
	'number',
2681
	$pconfig['pppoe_resethour'],
2682
	['min' => 0, 'max' => 23]
2683
))->setHelp('Hour (0-23)');
2684

    
2685
$group->add(new Form_Input(
2686
	'pppoe_resetminute',
2687
	null,
2688
	'number',
2689
	$pconfig['pppoe_resetminute'],
2690
	['min' => 0, 'max' => 59]
2691
))->setHelp('Minutes (0-59)');
2692

    
2693
$group->add(new Form_Input(
2694
	'pppoe_resetdate',
2695
	null,
2696
	'text',
2697
	$pconfig['pppoe_resetdate']
2698
))->setHelp('Specific date (mm/dd/yyyy)');
2699

    
2700
$group->setHelp('Leave the date field empty, for the reset to be executed each day at the time specified by the minutes and hour fields');
2701

    
2702
$section->add($group);
2703

    
2704
$group = new Form_MultiCheckboxGroup('cron based reset');
2705
$group->addClass('pppoepreset');
2706

    
2707
$group->add(new Form_MultiCheckbox(
2708
	'pppoe_pr_preset_val',
2709
	null,
2710
	'Reset at each month ("0 0 1 * *")',
2711
	$pconfig['pppoe_monthly'],
2712
	'monthly'
2713
))->displayAsRadio();
2714

    
2715
$group->add(new Form_MultiCheckbox(
2716
	'pppoe_pr_preset_val',
2717
	null,
2718
	'Reset at each week ("0 0 * * 0")',
2719
	$pconfig['pppoe_weekly'],
2720
	'weekly'
2721
))->displayAsRadio();
2722

    
2723
$group->add(new Form_MultiCheckbox(
2724
	'pppoe_pr_preset_val',
2725
	null,
2726
	'Reset at each day ("0 0 * * *")',
2727
	$pconfig['pppoe_daily'],
2728
	'daily'
2729
))->displayAsRadio();
2730

    
2731
$group->add(new Form_MultiCheckbox(
2732
	'pppoe_pr_preset_val',
2733
	null,
2734
	'Reset at each hour ("0 * * * *")',
2735
	$pconfig['pppoe_hourly'],
2736
	'hourly'
2737
))->displayAsRadio();
2738

    
2739
$section->add($group);
2740

    
2741
$section->addInput(new Form_Button(
2742
	'btnadvppp',
2743
	'Advanced and MLPPP',
2744
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2745
	'fa-cog'
2746
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2747

    
2748
$form->add($section);
2749

    
2750
// PPTP & L2TP Configuration section
2751
$section = new Form_Section('PPTP/L2TP Configuration');
2752
$section->addClass('pptp');
2753

    
2754
$section->addInput(new Form_Input(
2755
	'pptp_username',
2756
	'*Username',
2757
	'text',
2758
	$pconfig['pptp_username']
2759
));
2760

    
2761
$section->addPassword(new Form_Input(
2762
	'pptp_password',
2763
	'*Password',
2764
	'password',
2765
	$pconfig['pptp_password']
2766
));
2767

    
2768
$section->addInput(new Form_IpAddress(
2769
	'pptp_local0',
2770
	'*Local IP address',
2771
	$pconfig['pptp_localip'][0],
2772
	'V4'
2773
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2774

    
2775
$section->addInput(new Form_IpAddress(
2776
	'pptp_remote0',
2777
	'*Remote IP address',
2778
	$pconfig['pptp_remote'][0],
2779
	'HOSTV4'
2780
));
2781

    
2782
$section->addInput(new Form_Checkbox(
2783
	'pptp_dialondemand',
2784
	'Dial on demand',
2785
	'Enable Dial-On-Demand mode ',
2786
	$pconfig['pptp_dialondemand'],
2787
	'enable'
2788
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2789
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2790

    
2791
$section->addInput(new Form_Input(
2792
	'pptp_idletimeout',
2793
	'Idle timeout (seconds)',
2794
	'number',
2795
	$pconfig['pptp_idletimeout'],
2796
	['min' => 0]
2797
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2798
			'An idle timeout of zero disables this feature.');
2799

    
2800
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2801
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2802
} else {
2803
	$mlppp_text = "";
2804
}
2805

    
2806
$section->addInput(new Form_Button(
2807
	'btnadvppp',
2808
	'Advanced and MLPPP',
2809
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2810
	'fa-cog'
2811
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp($mlppp_text . 'Click for additional PPTP and L2TP configuration options. Save first if changes have been made.');
2812

    
2813
$form->add($section);
2814

    
2815
// Wireless interface
2816
if (isset($wancfg['wireless'])) {
2817

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

    
2820
	$section->addInput(new Form_Checkbox(
2821
		'persistcommonwireless',
2822
		'Persist common settings',
2823
		'Preserve common wireless configuration through interface deletions and reassignments.',
2824
		$pconfig['persistcommonwireless'],
2825
		'yes'
2826
	));
2827

    
2828
	$mode_list = ['auto' => 'Auto'];
2829

    
2830
	if (is_array($wl_modes)) {
2831
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2832
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2833
		}
2834
	}
2835

    
2836
	if (count($mode_list) == 1) {
2837
		$mode_list[''] = '';
2838
	}
2839

    
2840
	$section->addInput(new Form_Select(
2841
		'standard',
2842
		'Standard',
2843
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2844
		$mode_list
2845
	));
2846

    
2847
	if (isset($wl_modes['11g'])) {
2848
		$section->addInput(new Form_Select(
2849
			'protmode',
2850
			'802.11g OFDM Protection Mode',
2851
			$pconfig['protmode'],
2852
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2853
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2854
	} else {
2855
		$section->addInput(new Form_Input(
2856
			'protmode',
2857
			null,
2858
			'hidden',
2859
			'off'
2860
		));
2861
	}
2862

    
2863
	$mode_list = ['0' => gettext('Auto')];
2864

    
2865
	if (is_array($wl_modes)) {
2866
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2867
			if ($wl_standard == "11g") {
2868
				$wl_standard = "11b/g";
2869
			} else if ($wl_standard == "11ng") {
2870
				$wl_standard = "11b/g/n";
2871
			} else if ($wl_standard == "11na") {
2872
				$wl_standard = "11a/n";
2873
			}
2874

    
2875
			foreach ($wl_channels as $wl_channel) {
2876
				if (isset($wl_chaninfo[$wl_channel])) {
2877
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2878
				} else {
2879
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2880
				}
2881
			}
2882
		}
2883
	}
2884

    
2885
	$section->addInput(new Form_Select(
2886
		'channel',
2887
		'Channel',
2888
		$pconfig['channel'],
2889
		$mode_list
2890
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2891
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2892

    
2893
	if (ANTENNAS) {
2894
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2895
			$group = new Form_Group('Antenna Settings');
2896

    
2897
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2898
				$group->add(new Form_Select(
2899
					'diversity',
2900
					null,
2901
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2902
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2903
				))->setHelp('Diversity');
2904
			}
2905

    
2906
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2907
				$group->add(new Form_Select(
2908
					'txantenna',
2909
					null,
2910
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2911
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2912
				))->setHelp('Transmit antenna');
2913
			}
2914

    
2915
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2916
				$group->add(new Form_Select(
2917
					'rxantenna',
2918
					null,
2919
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2920
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2921
				))->setHelp('Receive antenna');
2922
			}
2923

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

    
2926
			$section->add($group);
2927
		}
2928
	}
2929

    
2930
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2931
			$section->addInput(new Form_Input(
2932
				'distance',
2933
				'Distance setting (meters)',
2934
				'test',
2935
				$pconfig['distance']
2936
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2937
	}
2938

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

    
2941
	// Regulatory settings
2942
	$section = new Form_Section('Regulatory Settings');
2943

    
2944
	$domain_list = array("" => 'Default');
2945

    
2946
	if (is_array($wl_regdomains)) {
2947
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2948
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2949
		}
2950
	}
2951

    
2952
	$section->addInput(new Form_Select(
2953
		'regdomain',
2954
		'Regulatory domain',
2955
		$pconfig['regdomain'],
2956
		$domain_list
2957
	))->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');
2958

    
2959
	$country_list = array('' => 'Default');
2960

    
2961
	if (is_array($wl_countries)) {
2962
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2963
			$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']);
2964
		}
2965
	}
2966

    
2967
	$section->addInput(new Form_Select(
2968
		'regcountry',
2969
		'Country',
2970
		$pconfig['regcountry'],
2971
		$country_list
2972
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2973

    
2974
	$section->addInput(new Form_Select(
2975
		'reglocation',
2976
		'Location',
2977
		$pconfig['reglocation'],
2978
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
2979
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2980
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2981
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2982
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2983
				'These settings may not be able to add additional channels that are not already supported.');
2984

    
2985
	$form->add($section);
2986

    
2987
	$section = new Form_Section('Network-Specific Wireless Configuration');
2988

    
2989
	$section->addInput(new Form_Select(
2990
		'mode',
2991
		'Mode',
2992
		$pconfig['mode'],
2993
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2994
	));
2995

    
2996
	$section->addInput(new Form_Input(
2997
		'ssid',
2998
		'SSID',
2999
		'text',
3000
		$pconfig['ssid']
3001
	));
3002

    
3003
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3004
		$section->addInput(new Form_Select(
3005
			'puremode',
3006
			'Minimum wireless standard',
3007
			$pconfig['puremode'],
3008
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3009
		))->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)');
3010
	} elseif (isset($wl_modes['11g'])) {
3011
		$section->addInput(new Form_Checkbox(
3012
			'puremode',
3013
			'802.11g only',
3014
			null,
3015
			$pconfig['puremode'],
3016
			'11g'
3017
		))->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)');
3018
	}
3019

    
3020
	$section->addInput(new Form_Checkbox(
3021
		'apbridge_enable',
3022
		'Allow intra-BSS communication',
3023
		'Allow packets to pass between wireless clients directly when operating as an access point',
3024
		$pconfig['apbridge_enable'],
3025
		'yes'
3026
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3027

    
3028
	$section->addInput(new Form_Checkbox(
3029
		'wme_enable',
3030
		'Enable WME',
3031
		'Force the card to use WME (wireless QoS)',
3032
		$pconfig['wme_enable'],
3033
		'yes'
3034
	));
3035

    
3036
	$section->addInput(new Form_Checkbox(
3037
		'hidessid_enable',
3038
		'Hide SSID',
3039
		'Disable broadcasting of the SSID for this network (This may cause problems for some clients, and the SSID may still be discovered by other means.)',
3040
		$pconfig['hidessid_enable'],
3041
		'yes'
3042
	));
3043

    
3044
	$form->add($section);
3045

    
3046
	// WPA Section
3047
	$section = new Form_Section('WPA');
3048

    
3049
	$section->addInput(new Form_Checkbox(
3050
		'wpa_enable',
3051
		'Enable',
3052
		'Enable WPA',
3053
		$pconfig['wpa_enable'],
3054
		'yes'
3055
	));
3056

    
3057
	$section->addInput(new Form_Input(
3058
		'passphrase',
3059
		'WPA Pre-Shared Key',
3060
		'text',
3061
		$pconfig['passphrase']
3062
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3063

    
3064
	$section->addInput(new Form_Select(
3065
		'wpa_mode',
3066
		'WPA mode',
3067
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3068
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3069
	));
3070

    
3071
	$section->addInput(new Form_Select(
3072
		'wpa_key_mgmt',
3073
		'WPA Key Management Mode',
3074
		$pconfig['wpa_key_mgmt'],
3075
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3076
	));
3077

    
3078
	$section->addInput(new Form_Select(
3079
		'wpa_pairwise',
3080
		'WPA Pairwise',
3081
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3082
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3083
	));
3084

    
3085
	$section->addInput(new Form_Input(
3086
		'wpa_group_rekey',
3087
		'Group Key Rotation',
3088
		'number',
3089
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3090
		['min' => '1', 'max' => 9999]
3091
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3092

    
3093
	$section->addInput(new Form_Input(
3094
		'wpa_gmk_rekey',
3095
		'Group Master Key Regeneration',
3096
		'number',
3097
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3098
		['min' => '1', 'max' => 9999]
3099
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3100

    
3101
	$section->addInput(new Form_Checkbox(
3102
		'wpa_strict_rekey',
3103
		'Strict Key Regeneration',
3104
		'Force the AP to rekey whenever a client disassociates',
3105
		$pconfig['wpa_strict_rekey'],
3106
		'yes'
3107
	));
3108

    
3109
	$form->add($section);
3110

    
3111
	$section = new Form_Section('802.1x RADIUS Options');
3112

    
3113
	$section->addInput(new Form_Checkbox(
3114
		'ieee8021x',
3115
		'IEEE802.1X',
3116
		'Enable 802.1X authentication',
3117
		$pconfig['ieee8021x'],
3118
		'yes'
3119
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3120

    
3121
	$group = new Form_Group('Primary 802.1X server');
3122

    
3123
	$group->add(new Form_IpAddress(
3124
		'auth_server_addr',
3125
		'IP Address',
3126
		$pconfig['auth_server_addr']
3127
	))->setHelp('IP address of the RADIUS server');
3128

    
3129
	$group->add(new Form_Input(
3130
		'auth_server_port',
3131
		'Port',
3132
		'number',
3133
		$pconfig['auth_server_port']
3134
	))->setHelp('Server auth port. Default is 1812');
3135

    
3136
	$group->add(new Form_Input(
3137
		'auth_server_shared_secret',
3138
		'Shared Secret',
3139
		'text',
3140
		$pconfig['auth_server_shared_secret']
3141
	))->setHelp('RADIUS Shared secret for this firewall');
3142

    
3143
	$section->add($group);
3144

    
3145
	$group = new Form_Group('Secondary 802.1X server');
3146

    
3147
	$group->add(new Form_IpAddress(
3148
		'auth_server_addr2',
3149
		'IP Address',
3150
		$pconfig['auth_server_addr2']
3151
	))->setHelp('IP address of the RADIUS server');
3152

    
3153
	$group->add(new Form_Input(
3154
		'auth_server_port2',
3155
		'Port',
3156
		'number',
3157
		$pconfig['auth_server_port2']
3158
	))->setHelp('Server auth port. Default is 1812');
3159

    
3160
	$group->add(new Form_Input(
3161
		'auth_server_shared_secret2',
3162
		'Shared Secret',
3163
		'text',
3164
		$pconfig['auth_server_shared_secret2']
3165
	))->setHelp('RADIUS Shared secret for this firewall');
3166

    
3167
	$section->add($group);
3168

    
3169
	$section->addInput(new Form_Checkbox(
3170
		'rsn_preauth',
3171
		'Authentication Roaming Preauth',
3172
		null,
3173
		$pconfig['rsn_preauth'],
3174
		'yes'
3175
	));
3176

    
3177
	$form->add($section);
3178
}
3179

    
3180
$section = new Form_Section('Reserved Networks');
3181

    
3182
$section->addInput(new Form_Checkbox(
3183
	'blockpriv',
3184
	'Block private networks and loopback addresses',
3185
	'',
3186
	$pconfig['blockpriv'],
3187
	'yes'
3188
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3189
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3190
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3191

    
3192
$section->addInput(new Form_Checkbox(
3193
	'blockbogons',
3194
	'Block bogon networks',
3195
	'',
3196
	$pconfig['blockbogons'],
3197
	'yes'
3198
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3199
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.' . '<br />' .
3200
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.');
3201

    
3202
$form->add($section);
3203

    
3204
$form->addGlobal(new Form_Input(
3205
	'if',
3206
	null,
3207
	'hidden',
3208
	$if
3209
));
3210

    
3211
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3212
	$form->addGlobal(new Form_Input(
3213
		'ppp_port',
3214
		null,
3215
		'hidden',
3216
		$pconfig['port']
3217
	));
3218
}
3219

    
3220
$form->addGlobal(new Form_Input(
3221
	'ptpid',
3222
	null,
3223
	'hidden',
3224
	$pconfig['ptpid']
3225
));
3226

    
3227

    
3228
// Add new gateway modal pop-up
3229
$modal = new Modal('New Gateway', 'newgateway', 'large');
3230

    
3231
$modal->addInput(new Form_Checkbox(
3232
	'defaultgw',
3233
	'Default',
3234
	'Default gateway',
3235
	($if == "wan" || $if == "WAN")
3236
));
3237

    
3238
$modal->addInput(new Form_Input(
3239
	'name',
3240
	'Gateway name',
3241
	'text',
3242
	$wancfg['descr'] . "GW"
3243
));
3244

    
3245
$modal->addInput(new Form_IpAddress(
3246
	'gatewayip',
3247
	'Gateway IPv4',
3248
	null,
3249
	'V4'
3250
));
3251

    
3252
$modal->addInput(new Form_Input(
3253
	'gatewaydescr',
3254
	'Description',
3255
	'text'
3256
));
3257

    
3258
$btnaddgw = new Form_Button(
3259
	'add',
3260
	'Add',
3261
	null,
3262
	'fa-plus'
3263
);
3264

    
3265
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3266

    
3267
$btncnxgw = new Form_Button(
3268
	'cnx',
3269
	'Cancel',
3270
	null,
3271
	'fa-undo'
3272
);
3273

    
3274
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3275

    
3276
$modal->addInput(new Form_StaticText(
3277
	null,
3278
	$btnaddgw . $btncnxgw
3279
));
3280

    
3281
$form->add($modal);
3282

    
3283
print($form);
3284
?>
3285

    
3286
<script type="text/javascript">
3287
//<![CDATA[
3288
events.push(function() {
3289
	function updateType(t) {
3290

    
3291
		switch (t) {
3292
			case "none": {
3293
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3294
				break;
3295
			}
3296
			case "staticv4": {
3297
				$('.dhcpadvanced, .none, .dhcp').hide();
3298
				$('.pppoe, .pptp, .ppp').hide();
3299
				break;
3300
			}
3301
			case "dhcp": {
3302
				$('.dhcpadvanced, .none').hide();
3303
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3304
										//			about the staticv4 class
3305
				$('.pppoe, .pptp, .ppp').hide();
3306
				break;
3307
			}
3308
			case "ppp": {
3309
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3310
				country_list();
3311
				break;
3312
			}
3313
			case "pppoe": {
3314
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3315
				break;
3316
			}
3317
			case "l2tp":
3318
			case "pptp": {
3319
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3320
				$('.pptp').show();
3321
				break;
3322
			}
3323
		}
3324

    
3325
		if (t != "l2tp" && t != "pptp") {
3326
			$('.'+t).show();
3327
		}
3328
	}
3329

    
3330
	function updateTypeSix(t) {
3331
		if (!isNaN(t[0])) {
3332
			t = '_' + t;
3333
		}
3334

    
3335
		switch (t) {
3336
			case "none": {
3337
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3338
				break;
3339
			}
3340
			case "staticv6": {
3341
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3342
				break;
3343
			}
3344
			case "slaac": {
3345
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3346
				break;
3347
			}
3348
			case "dhcp6": {
3349
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3350
				break;
3351
			}
3352
			case "_6rd": {
3353
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3354
				break;
3355
			}
3356
			case "_6to4": {
3357
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3358
				break;
3359
			}
3360
			case "track6": {
3361
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3362
				update_track6_prefix();
3363
				break;
3364
			}
3365
		}
3366

    
3367
		if (t != "l2tp" && t != "pptp") {
3368
			$('.'+t).show();
3369
		}
3370
	}
3371

    
3372
	function show_reset_settings(reset_type) {
3373
		if (reset_type == 'preset') {
3374
			$('.pppoepreset').show();
3375
			$('.pppoecustom').hide();
3376
		} else if (reset_type == 'custom') {
3377
			$('.pppoecustom').show();
3378
			$('.pppoepreset').hide();
3379
		} else {
3380
			$('.pppoecustom').hide();
3381
			$('.pppoepreset').hide();
3382
		}
3383
	}
3384

    
3385
	function update_track6_prefix() {
3386
		var iface = $("#track6-interface").val();
3387
		if (iface == null) {
3388
			return;
3389
		}
3390

    
3391
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3392
		if (track6_prefix_ids == null) {
3393
			return;
3394
		}
3395

    
3396
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3397
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3398
	}
3399

    
3400
	// Create the new gateway from the data entered in the modal pop-up
3401
	function hide_add_gatewaysave() {
3402
		var iface = $('#if').val();
3403
		name = $('#name').val();
3404
		var descr = $('#gatewaydescr').val();
3405
		gatewayip = $('#gatewayip').val();
3406

    
3407
		var defaultgw = '';
3408
		if ($('#defaultgw').is(':checked')) {
3409
			defaultgw = '&defaultgw=on';
3410
		}
3411

    
3412
		var url = "system_gateways_edit.php";
3413
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3414
		$.ajax(
3415
			url,
3416
			{
3417
				type: 'post',
3418
				data: pars,
3419
				error: report_failure,
3420
				complete: save_callback
3421
			});
3422
		}
3423

    
3424
	function save_callback(response) {
3425
		if (response) {
3426
			var gwtext = escape(name) + " - " + gatewayip;
3427
			addOption($('#gateway'), gwtext, name);
3428
		} else {
3429
			report_failure();
3430
		}
3431

    
3432
		$("#newgateway").modal('hide');
3433
	}
3434

    
3435
	function report_failure(request, textStatus, errorThrown) {
3436
		contenttype = ";"+request.getResponseHeader("Content-Type")+";";
3437
		if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
3438
			alert(request.responseText);
3439
		} else {
3440
			alert("The IPv4 gateway could not be created.");
3441
		}
3442

    
3443
		$("#newgateway").modal('hide');
3444
	}
3445

    
3446
	function addOption(selectbox, text, value) {
3447
		var optn = document.createElement("OPTION");
3448
		optn.text = text;
3449
		optn.value = value;
3450
		selectbox.append(optn);
3451
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3452
	}
3453

    
3454
	function hide_add_gatewaysave_v6() {
3455

    
3456
		var iface = $('#if').val();
3457
		name = $('#name6').val();
3458
		var descr = $('#gatewaydescr6').val();
3459
		gatewayip = $('#gatewayip6').val();
3460
		var defaultgw = '';
3461
		if ($('#defaultgw6').is(':checked')) {
3462
			defaultgw = '&defaultgw=on';
3463
		}
3464
		var url_v6 = "system_gateways_edit.php";
3465
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3466
		$.ajax(
3467
			url_v6,
3468
			{
3469
				type: 'post',
3470
				data: pars_v6,
3471
				error: report_failure_v6,
3472
				success: save_callback_v6
3473
			});
3474
	}
3475

    
3476

    
3477
	function addOption_v6(selectbox, text, value) {
3478
		var optn = document.createElement("OPTION");
3479
		optn.text = text;
3480
		optn.value = value;
3481
		selectbox.append(optn);
3482
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3483
	}
3484

    
3485
	function report_failure_v6(request, textStatus, errorThrown) {
3486
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3487
			alert(request.responseText);
3488
		} else {
3489
			alert("The IPv6 gateway could not be created.");
3490
		}
3491

    
3492
		$("#newgateway6").modal('hide');
3493
	}
3494

    
3495
	function save_callback_v6(response_v6) {
3496
		if (response_v6) {
3497

    
3498
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3499
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3500
		} else {
3501
			report_failure_v6();
3502
		}
3503

    
3504
		$("#newgateway6").modal('hide');
3505
	}
3506

    
3507
	function country_list() {
3508
		$('#country').children().remove();
3509
		$('#provider_list').children().remove();
3510
		$('#providerplan').children().remove();
3511
		$.ajax("getserviceproviders.php",{
3512
			success: function(response) {
3513

    
3514
				var responseTextArr = response.split("\n");
3515
				responseTextArr.sort();
3516

    
3517
				responseTextArr.forEach( function(value) {
3518
					country = value.split(":");
3519
					$('#country').append($('<option>', {
3520
						value: country[1],
3521
						text : country[0]
3522
					}));
3523
				});
3524
			}
3525
		});
3526
	}
3527

    
3528
	function providers_list() {
3529
		$('#provider_list').children().remove();
3530
		$('#providerplan').children().remove();
3531
		$.ajax("getserviceproviders.php",{
3532
			type: 'post',
3533
			data: {country : $('#country').val()},
3534
			success: function(response) {
3535
				var responseTextArr = response.split("\n");
3536
				responseTextArr.sort();
3537
				responseTextArr.forEach( function(value) {
3538
					$('#provider_list').append($('<option>', {
3539
							value: value,
3540
							text : value
3541
					}));
3542
				});
3543
			}
3544
		});
3545
	}
3546

    
3547
	function providerplan_list() {
3548
		$('#providerplan').children().remove();
3549
		$.ajax("getserviceproviders.php",{
3550
			type: 'post',
3551
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3552
			success: function(response) {
3553
				var responseTextArr = response.split("\n");
3554
				responseTextArr.sort();
3555

    
3556
				$('#providerplan').append($('<option>', {
3557
					value: '',
3558
					text : ''
3559
				}));
3560

    
3561
				responseTextArr.forEach( function(value) {
3562
					if (value != "") {
3563
						providerplan = value.split(":");
3564

    
3565
						$('#providerplan').append($('<option>', {
3566
							value: providerplan[1],
3567
							text : providerplan[0] + " - " + providerplan[1]
3568
						}));
3569
					}
3570
				});
3571
			}
3572
		});
3573
	}
3574

    
3575
	function prefill_provider() {
3576
		$.ajax("getserviceproviders.php",{
3577
			type: 'post',
3578
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3579
			success: function(data, textStatus, response) {
3580
				var xmldoc = response.responseXML;
3581
				var provider = xmldoc.getElementsByTagName('connection')[0];
3582
				$('#ppp_username').val('');
3583
				$('#ppp_password').val('');
3584
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3585
					$('#phone').val('#777');
3586
					$('#apn').val('');
3587
				} else {
3588
					$('#phone').val('*99#');
3589
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3590
				}
3591
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3592
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3593
				$('#ppp_username').val(ppp_username);
3594
				$('#ppp_password').val(ppp_password);
3595
			}
3596
		});
3597
	}
3598

    
3599
	function show_dhcp6adv() {
3600
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3601
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3602

    
3603
		hideCheckbox('dhcp6usev4iface', ovr);
3604
		hideCheckbox('dhcp6prefixonly', ovr);
3605
		hideInput('dhcp6-ia-pd-len', ovr);
3606
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3607
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3608

    
3609
		hideClass('dhcp6advanced', !adv || ovr);
3610
	}
3611

    
3612
	function setDHCPoptions() {
3613
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3614
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3615

    
3616
		if (ovr) {
3617
			hideInput('dhcphostname', true);
3618
			hideIpAddress('alias-address', true);
3619
			hideInput('dhcprejectfrom', true);
3620
			hideInput('adv_dhcp_config_file_override_path', false);
3621
			hideClass('dhcpadvanced', true);
3622
		} else {
3623
			hideInput('dhcphostname', false);
3624
			hideIpAddress('alias-address', false);
3625
			hideInput('dhcprejectfrom', false);
3626
			hideInput('adv_dhcp_config_file_override_path', true);
3627
			hideClass('dhcpadvanced', !adv);
3628
		}
3629
	}
3630

    
3631
	// DHCP preset actions
3632
	// Set presets from value of radio buttons
3633
	function setPresets(val) {
3634
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3635
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3636
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3637
		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']);?>");
3638
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3639
	}
3640

    
3641
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3642
		$('#adv_dhcp_pt_timeout').val(timeout);
3643
		$('#adv_dhcp_pt_retry').val(retry);
3644
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3645
		$('#adv_dhcp_pt_reboot').val(reboot);
3646
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3647
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3648
	}
3649

    
3650
	function setDialOnDemandItems() {
3651
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3652
	}
3653

    
3654
	// ---------- On initial page load ------------------------------------------------------------
3655

    
3656
	updateType($('#type').val());
3657
	updateTypeSix($('#type6').val());
3658
	show_reset_settings($('#pppoe-reset-type').val());
3659
	hideClass('dhcp6advanced', true);
3660
	hideClass('dhcpadvanced', true);
3661
	show_dhcp6adv();
3662
	setDHCPoptions();
3663
	setDialOnDemandItems();
3664

    
3665
	// Set preset buttons on page load
3666
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3667
	if (sv == "") {
3668
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3669
	} else {
3670
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3671
	}
3672

    
3673
	// Set preset from value
3674
	setPresets(sv);
3675

    
3676
	// ---------- Click checkbox handlers ---------------------------------------------------------
3677

    
3678
	$('#type').on('change', function() {
3679
		updateType(this.value);
3680
	});
3681

    
3682
	$('#type6').on('change', function() {
3683
		updateTypeSix(this.value);
3684
	});
3685

    
3686
	$('#track6-interface').on('change', function() {
3687
		update_track6_prefix();
3688
	});
3689

    
3690
	$('#pppoe-reset-type').on('change', function() {
3691
		show_reset_settings(this.value);
3692
	});
3693

    
3694
	$("#add").click(function() {
3695
		hide_add_gatewaysave();
3696
	});
3697

    
3698
	$("#cnx").click(function() {
3699
		$("#newgateway").modal('hide');
3700
	});
3701

    
3702
	$("#add6").click(function() {
3703
		hide_add_gatewaysave_v6();
3704
	});
3705

    
3706
	$("#cnx6").click(function() {
3707
		$("#newgateway6").modal('hide');
3708
	});
3709

    
3710
	$('#country').on('change', function() {
3711
		providers_list();
3712
	});
3713

    
3714
	$('#provider_list').on('change', function() {
3715
		providerplan_list();
3716
	});
3717

    
3718
	$('#providerplan').on('change', function() {
3719
		prefill_provider();
3720
	});
3721

    
3722
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3723
		setDHCPoptions();
3724
	});
3725

    
3726
	$('#adv_dhcp6_config_advanced').click(function () {
3727
		show_dhcp6adv();
3728
	});
3729

    
3730
	$('#adv_dhcp6_config_file_override').click(function () {
3731
		show_dhcp6adv();
3732
	});
3733

    
3734
	// On click . .
3735
	$('#pppoe_dialondemand').click(function () {
3736
		setDialOnDemandItems();
3737
	});
3738

    
3739
	$('[name=adv_dhcp_pt_values]').click(function () {
3740
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3741
	});
3742

    
3743
	$('#pppoe_resetdate').datepicker();
3744

    
3745
});
3746
//]]>
3747
</script>
3748

    
3749
<?php include("foot.inc");
(66-66/225)