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['type'] == 'staticv4') && $_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['type'] == 'staticv6') && $_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'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
796
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
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 have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2002
			'(separate multiple entries with a comma). ' .
2003
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2004

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2133
$section->addInput(new Form_Input(
2134
	'adv_dhcp_option_modifiers',
2135
	'Option modifiers',
2136
	'text',
2137
	$pconfig['adv_dhcp_option_modifiers']
2138
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2139
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2140
			'<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>');
2141

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

    
2144
// DHCP6 client config
2145

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

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

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

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

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

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

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

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

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

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

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

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

    
2226
// DHCP6 client config - Advanced
2227

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2437
$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>');
2438

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2507
	return($list);
2508
}
2509

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

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

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

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

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

    
2537
/// PPP section
2538

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

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

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

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

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

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

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

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

    
2591

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

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

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

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

    
2607
	return($list);
2608
}
2609

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2701
$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');
2702

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2807
$section->addInput(new Form_Button(
2808
	'btnadvppp',
2809
	'Advanced and MLPPP',
2810
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2811
	'fa-cog'
2812
))->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.');
2813

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3037
	$section->addInput(new Form_Checkbox(
3038
		'hidessid_enable',
3039
		'Hide SSID',
3040
		'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.)',
3041
		$pconfig['hidessid_enable'],
3042
		'yes'
3043
	));
3044

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3228

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

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

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

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

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

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

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

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

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

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

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

    
3284
print($form);
3285
?>
3286

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3455
	function hide_add_gatewaysave_v6() {
3456

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

    
3477

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3655
	// ---------- On initial page load ------------------------------------------------------------
3656

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

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

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

    
3677
	// ---------- Click checkbox handlers ---------------------------------------------------------
3678

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3750
<?php include("foot.inc");
(71-71/233)