Project

General

Profile

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

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

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

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

    
438
}
439

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

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

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

    
478
		clear_subsystem_dirty('interfaces');
479

    
480
		filter_configure();
481

    
482
		enable_rrd_graphing();
483

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

    
493
	unset($input_errors);
494
	$pconfig = $_POST;
495

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

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

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

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

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

    
545
	if (is_numeric($_POST['descr'])) {
546
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
547
	}
548
	/* input validation */
549
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
550
		$input_errors[] = gettext("The DHCP Server is active on this interface and it can be used only with a static IP configuration. Please disable the DHCP Server service on this interface first, then change the interface configuration.");
551
	}
552
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
553
		$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.");
554
	}
555

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

    
663
			if (empty($_POST['track6-interface'])) {
664
				$input_errors[] = gettext("A valid interface to track must be selected.");
665
			}
666

    
667
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
668
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
669
			} else {
670
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
671
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
672
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
673
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
674
				} else {
675
					foreach ($ifdescrs as $ifent => $ifdescr) {
676
						if ($if == $ifent) {
677
							continue;
678
						}
679
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
680
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
681
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
682
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
683
						}
684
					}
685
				}
686
			}
687
			break;
688
	}
689

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

    
706
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
707
			if ($_POST['subnet'] < 31) {
708
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
709
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
710
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
711
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
712
				}
713
			}
714

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

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

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

    
830
		unset($min_mtu, $max_mtu);
831

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

    
850
				$realhwif_array = get_parent_interface($ifdata['if']);
851
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
852
				$parent_realhwif = $realhwif_array[0];
853

    
854
				if ($parent_realhwif != $wancfg['if']) {
855
					continue;
856
				}
857

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

    
945
		if ($_POST['passphrase']) {
946
			$passlen = strlen($_POST['passphrase']);
947
			if ($passlen < 8 || $passlen > 63) {
948
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
949
			}
950
		}
951

    
952
		if ($_POST['wpa_enable'] == "yes") {
953
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
954
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
955
			}
956
		}
957
	}
958

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

    
963
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
964
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
965
	}
966

    
967
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
968
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
969
	}
970

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

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

    
1017
		unset($wancfg['adv_dhcp_pt_timeout']);
1018
		unset($wancfg['adv_dhcp_pt_retry']);
1019
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1020
		unset($wancfg['adv_dhcp_pt_reboot']);
1021
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1022
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1023

    
1024
		unset($wancfg['adv_dhcp_pt_values']);
1025

    
1026
		unset($wancfg['adv_dhcp_send_options']);
1027
		unset($wancfg['adv_dhcp_request_options']);
1028
		unset($wancfg['adv_dhcp_required_options']);
1029
		unset($wancfg['adv_dhcp_option_modifiers']);
1030

    
1031
		unset($wancfg['adv_dhcp_config_advanced']);
1032
		unset($wancfg['adv_dhcp_config_file_override']);
1033
		unset($wancfg['adv_dhcp_config_file_override_path']);
1034

    
1035
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1036
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1037
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1038
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1039

    
1040
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1041
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1042
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1043
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1044
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1045

    
1046
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1047
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1048
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1049
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1050
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1051

    
1052
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1053
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1054

    
1055
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1056
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1057
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1058
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1059

    
1060
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1061
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1062
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1063
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1064
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1065

    
1066
		unset($wancfg['adv_dhcp6_config_advanced']);
1067
		unset($wancfg['adv_dhcp6_config_file_override']);
1068
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1069

    
1070
		unset($wancfg['pppoe_password']);
1071
		unset($wancfg['pptp_username']);
1072
		unset($wancfg['pptp_password']);
1073
		unset($wancfg['provider']);
1074
		unset($wancfg['ondemand']);
1075
		unset($wancfg['timeout']);
1076
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1077
			unset($wancfg['pppoe']['pppoe-reset-type']);
1078
		}
1079
		unset($wancfg['local']);
1080

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

    
1102
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1103
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1104

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

    
1121
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1122
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1123
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1124
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1125
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1126
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1127

    
1128
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1129

    
1130
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1131
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1132
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1133
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1134

    
1135
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1136
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1137
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1138

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

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

    
1184
				if (!empty($_POST['pppoe-reset-type'])) {
1185
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1186
				} else {
1187
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1188
				}
1189
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1190
				$wancfg['ipaddr'] = $_POST['type'];
1191
				if ($gateway_item) {
1192
					$a_gateways[] = $gateway_item;
1193
				}
1194

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

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

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

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

    
1305
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1306
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1307
				}
1308
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1309
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1310
				}
1311

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

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

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

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

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

    
1422
		conf_mount_ro();
1423
		write_config();
1424

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

    
1434
		mark_subsystem_dirty('interfaces');
1435

    
1436
		/* regenerate cron settings/crontab file */
1437
		configure_cron();
1438

    
1439
		header("Location: interfaces.php?if={$if}");
1440
		exit;
1441
	}
1442

    
1443
} // end if ($_POST)
1444

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

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

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

    
1594
	interface_sync_wireless_clones($wancfg, true);
1595
}
1596

    
1597
function check_wireless_mode() {
1598
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1599

    
1600
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1601
		return;
1602
	}
1603

    
1604
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1605
		$clone_count = 1;
1606
	} else {
1607
		$clone_count = 0;
1608
	}
1609

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

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

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

    
1645
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1646
$shortcut_section = "interfaces";
1647

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

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

    
1656
function build_mediaopts_list() {
1657
	global $mediaopts_list;
1658

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

    
1663
	foreach ($mediaopts_list as $mediaopt) {
1664
		$list[$mediaopt] = $mediaopt;
1665
	}
1666

    
1667
	return($list);
1668
}
1669

    
1670
function build_gateway_list() {
1671
	global $a_gateways, $if;
1672

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

    
1680
	return($list);
1681
}
1682

    
1683
function build_gatewayv6_list() {
1684
	global $a_gateways, $if;
1685

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

    
1693
	return($list);
1694
}
1695

    
1696
include("head.inc");
1697

    
1698
if ($input_errors) {
1699
	print_input_errors($input_errors);
1700
}
1701

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

    
1708
if ($savemsg) {
1709
	print_info_box($savemsg, 'success');
1710
}
1711

    
1712

    
1713
$form = new Form();
1714

    
1715
$section = new Form_Section('General Configuration');
1716

    
1717
$section->addInput(new Form_Checkbox(
1718
	'enable',
1719
	'Enable',
1720
	'Enable interface',
1721
	$pconfig['enable'],
1722
	'yes'
1723
));
1724

    
1725
$section->addInput(new Form_Input(
1726
	'descr',
1727
	'Description',
1728
	'text',
1729
	$pconfig['descr']
1730
))->setHelp('Enter a description (name) for the interface here.');
1731

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

    
1739
$section->addInput(new Form_Select(
1740
	'type6',
1741
	'IPv6 Configuration Type',
1742
	$pconfig['type6'],
1743
	$types6
1744
));
1745

    
1746
$macaddress = new Form_Input(
1747
	'spoofmac',
1748
	'MAC Address',
1749
	'text',
1750
	$pconfig['spoofmac'],
1751
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1752
);
1753

    
1754
$btnmymac = new Form_Button(
1755
	'btnmymac',
1756
	'Copy My MAC',
1757
	null,
1758
	'fa-clone'
1759
	);
1760

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

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

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

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

    
1786
if (count($mediaopts_list) > 0) {
1787
	$section->addInput(new Form_Select(
1788
		'mediaopt',
1789
		'Speed and Duplex',
1790
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1791
		build_mediaopts_list()
1792
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1793
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1794
}
1795

    
1796
$form->add($section);
1797

    
1798
$section = new Form_Section('Static IPv4 Configuration');
1799
$section->addClass('staticv4');
1800

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

    
1807
$group = new Form_Group('IPv4 Upstream gateway');
1808

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

    
1816
$group->add(new Form_Button(
1817
	'addgw',
1818
	'Add a new gateway',
1819
	null,
1820
	'fa-plus'
1821
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1822

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

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

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

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

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

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

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

    
1849
$group->add(new Form_Button(
1850
	'addgw6',
1851
	'Add a new gateway',
1852
	null,
1853
	'fa-plus'
1854
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1855

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

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

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

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

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

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

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

    
1891
$btnaddgw6 = new Form_Button(
1892
	'add6',
1893
	'Add',
1894
	null,
1895
	'fa-plus'
1896
);
1897

    
1898
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1899

    
1900
$btncnxgw6 = new Form_Button(
1901
	'cnx6',
1902
	'Cancel',
1903
	null,
1904
	'fa-undo'
1905
);
1906

    
1907
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1908

    
1909
$modal->addInput(new Form_StaticText(
1910
	null,
1911
	$btnaddgw6 . $btncnxgw6
1912
));
1913

    
1914
$form->add($modal);
1915

    
1916
// ==== DHCP client configuration =============================
1917

    
1918
$section = new Form_Section('DHCP Client Configuration');
1919
$section->addClass('dhcp');
1920

    
1921
$group = new Form_Group('Options');
1922

    
1923
$group->add(new Form_Checkbox(
1924
	'adv_dhcp_config_advanced',
1925
	null,
1926
	'Advanced Configuration',
1927
	$pconfig['adv_dhcp_config_advanced']
1928
))->setHelp('Use advanced DHCP configuration options.');
1929

    
1930
$group->add(new Form_Checkbox(
1931
	'adv_dhcp_config_file_override',
1932
	null,
1933
	'Configuration Override',
1934
	$pconfig['adv_dhcp_config_file_override']
1935
))->setHelp('Override the configuration from this file.');
1936

    
1937
$section->add($group);
1938

    
1939
$section->addInput(new Form_Input(
1940
	'dhcphostname',
1941
	'Hostname',
1942
	'text',
1943
	$pconfig['dhcphostname']
1944
))->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).');
1945

    
1946
$section->addInput(new Form_IpAddress(
1947
	'alias-address',
1948
	'Alias IPv4 address',
1949
	$pconfig['alias-address']
1950
))->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.');
1951

    
1952
$section->addInput(new Form_Input(
1953
	'dhcprejectfrom',
1954
	'Reject leases from',
1955
	'text',
1956
	$pconfig['dhcprejectfrom']
1957
))->setHelp('If there is a certain upstream DHCP server that should be ignored, place the IP address or subnet of the DHCP server to be ignored here. ' .
1958
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1959

    
1960
$group = new Form_Group('Protocol timing');
1961
$group->addClass('dhcpadvanced');
1962

    
1963
$group->add(new Form_Input(
1964
	'adv_dhcp_pt_timeout',
1965
	null,
1966
	'number',
1967
	$pconfig['adv_dhcp_pt_timeout']
1968
))->setHelp('Timeout');
1969

    
1970
$group->add(new Form_Input(
1971
	'adv_dhcp_pt_retry',
1972
	null,
1973
	'number',
1974
	$pconfig['adv_dhcp_pt_retry']
1975
))->setHelp('Retry');
1976

    
1977
$group->add(new Form_Input(
1978
	'adv_dhcp_pt_select_timeout',
1979
	null,
1980
	'number',
1981
	$pconfig['adv_dhcp_pt_select_timeout'],
1982
	['min' => 0]
1983
))->setHelp('Select timeout');
1984

    
1985
$group->add(new Form_Input(
1986
	'adv_dhcp_pt_reboot',
1987
	null,
1988
	'number',
1989
	$pconfig['adv_dhcp_pt_reboot']
1990
))->setHelp('Reboot');
1991

    
1992
$group->add(new Form_Input(
1993
	'adv_dhcp_pt_backoff_cutoff',
1994
	null,
1995
	'number',
1996
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1997
))->setHelp('Backoff cutoff');
1998

    
1999
$group->add(new Form_Input(
2000
	'adv_dhcp_pt_initial_interval',
2001
	null,
2002
	'number',
2003
	$pconfig['adv_dhcp_pt_initial_interval']
2004
))->setHelp('Initial interval');
2005

    
2006
$section->add($group);
2007

    
2008
$group = new Form_Group('Presets');
2009
$group->addClass('dhcpadvanced');
2010

    
2011
$group->add(new Form_Checkbox(
2012
	'adv_dhcp_pt_values',
2013
	null,
2014
	'FreeBSD default',
2015
	null,
2016
	'DHCP'
2017
))->displayAsRadio();
2018

    
2019
$group->add(new Form_Checkbox(
2020
	'adv_dhcp_pt_values',
2021
	null,
2022
	'Clear',
2023
	null,
2024
	'Clear'
2025
))->displayAsRadio();
2026

    
2027
$group->add(new Form_Checkbox(
2028
	'adv_dhcp_pt_values',
2029
	null,
2030
	'pfSense Default',
2031
	null,
2032
	'pfSense'
2033
))->displayAsRadio();
2034

    
2035
$group->add(new Form_Checkbox(
2036
	'adv_dhcp_pt_values',
2037
	null,
2038
	'Saved Cfg',
2039
	null,
2040
	'SavedCfg'
2041
))->displayAsRadio();
2042

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

    
2046
$section->add($group);
2047

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

    
2058
$form->add($section);
2059

    
2060
$section = new Form_Section('Lease Requirements and Requests');
2061
$section->addClass('dhcpadvanced');
2062

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

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

    
2081
$section->addInput(new Form_Input(
2082
	'adv_dhcp_required_options',
2083
	'Require options',
2084
	'text',
2085
	$pconfig['adv_dhcp_required_options']
2086
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2087

    
2088
$section->addInput(new Form_Input(
2089
	'adv_dhcp_option_modifiers',
2090
	'Option modifiers',
2091
	'text',
2092
	$pconfig['adv_dhcp_option_modifiers']
2093
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2094
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2095
			'<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>');
2096

    
2097
$form->add($section);
2098

    
2099
// DHCP6 client config
2100

    
2101
$section = new Form_Section('DHCP6 Client Configuration');
2102
$section->addClass('dhcp6');
2103

    
2104
$group = new Form_Group('Options');
2105

    
2106
$group->add(new Form_Checkbox(
2107
	'adv_dhcp6_config_advanced',
2108
	null,
2109
	'Advanced Configuration',
2110
	$pconfig['adv_dhcp6_config_advanced']
2111
))->setHelp('Use advanced DHCPv6 configuration options.');
2112

    
2113
$group->add(new Form_Checkbox(
2114
	'adv_dhcp6_config_file_override',
2115
	null,
2116
	'Configuration Override',
2117
	$pconfig['adv_dhcp6_config_file_override']
2118
))->setHelp('Override the configuration from this file.');
2119

    
2120
$section->add($group);
2121

    
2122
$section->addInput(new Form_Checkbox(
2123
	'dhcp6usev4iface',
2124
	'Use IPv4 connectivity as parent interface',
2125
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2126
	$pconfig['dhcp6usev4iface']
2127
));
2128

    
2129
$section->addInput(new Form_Checkbox(
2130
	'dhcp6prefixonly',
2131
	'Request only an IPv6 prefix',
2132
	'Only request an IPv6 prefix, do not request an IPv6 address',
2133
	$pconfig['dhcp6prefixonly']
2134
));
2135

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

    
2143
$section->addInput(new Form_Checkbox(
2144
	'dhcp6-ia-pd-send-hint',
2145
	'Send IPv6 prefix hint',
2146
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2147
	$pconfig['dhcp6-ia-pd-send-hint']
2148
));
2149

    
2150
$section->addInput(new Form_Checkbox(
2151
	'dhcp6debug',
2152
	'Debug',
2153
	'Start DHCP6 client in debug mode',
2154
	$pconfig['dhcp6debug']
2155
));
2156

    
2157
$section->addInput(new Form_Input(
2158
	'adv_dhcp6_config_file_override_path',
2159
	'Configuration File Override',
2160
	'text',
2161
	$pconfig['adv_dhcp6_config_file_override_path']
2162
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2163
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2164
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2165
			'Some ISPs may require certain options be or not be sent.');
2166

    
2167
$form->add($section);
2168

    
2169
// DHCP6 client config - Advanced
2170

    
2171
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2172
$section->addClass('dhcp6advanced');
2173

    
2174
$section->addInput(new Form_Checkbox(
2175
	'adv_dhcp6_interface_statement_information_only_enable',
2176
	'Information only',
2177
	'Exchange Information Only',
2178
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2179
	'Selected'
2180
))->setHelp('Only exchange informational configuration parameters with servers.');
2181

    
2182
$section->addInput(new Form_Input(
2183
	'adv_dhcp6_interface_statement_send_options',
2184
	'Send options',
2185
	'text',
2186
	$pconfig['adv_dhcp6_interface_statement_send_options']
2187
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2188
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2189
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2190
			'Some DHCP services may require certain options be or not be sent.');
2191

    
2192
$section->addInput(new Form_Input(
2193
	'adv_dhcp6_interface_statement_request_options',
2194
	'Request Options',
2195
	'text',
2196
	$pconfig['adv_dhcp6_interface_statement_request_options']
2197
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2198
			'Some DHCP services may require certain options be or not be requested.');
2199

    
2200
$section->addInput(new Form_Input(
2201
	'adv_dhcp6_interface_statement_script',
2202
	'Scripts',
2203
	'text',
2204
	$pconfig['adv_dhcp6_interface_statement_script']
2205
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2206
			'[/[dirname/[.../]]filename[.ext]].');
2207

    
2208
$group = new Form_Group('Identity Association Statement');
2209

    
2210
$group->add(new Form_Checkbox(
2211
	'adv_dhcp6_id_assoc_statement_address_enable',
2212
	null,
2213
	'Non-Temporary Address Allocation',
2214
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2215
	'Selected'
2216
));
2217

    
2218
$group->add(new Form_Input(
2219
	'adv_dhcp6_id_assoc_statement_address_id',
2220
	null,
2221
	'text',
2222
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2223
))->sethelp('id-assoc na ID');
2224

    
2225
$group->add(new Form_IpAddress(
2226
	'adv_dhcp6_id_assoc_statement_address',
2227
	null,
2228
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2229
))->sethelp('IPv6 address');
2230

    
2231
$group->add(new Form_Input(
2232
	'adv_dhcp6_id_assoc_statement_address_pltime',
2233
	null,
2234
	'text',
2235
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2236
))->sethelp('pltime');
2237

    
2238
$group->add(new Form_Input(
2239
	'adv_dhcp6_id_assoc_statement_address_vltime',
2240
	null,
2241
	'text',
2242
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2243
))->sethelp('vltime');
2244

    
2245
$section->add($group);
2246

    
2247
// Prefix delegation
2248
$group = new Form_Group('');
2249

    
2250
$group->add(new Form_Checkbox(
2251
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2252
	null,
2253
	'Prefix Delegation ',
2254
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2255
	'Selected'
2256
));
2257

    
2258
$group->add(new Form_Input(
2259
	'adv_dhcp6_id_assoc_statement_prefix_id',
2260
	null,
2261
	'text',
2262
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2263
))->sethelp('id-assoc pd ID');
2264

    
2265
$group->add(new Form_IpAddress(
2266
	'adv_dhcp6_id_assoc_statement_prefix',
2267
	null,
2268
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2269
))->sethelp('IPv6 prefix');
2270

    
2271
$group->add(new Form_Input(
2272
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2273
	null,
2274
	'text',
2275
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2276
))->sethelp('pltime');
2277

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

    
2285
$section->add($group);
2286

    
2287
$group = new Form_Group('Prefix interface statement');
2288

    
2289
$group->add(new Form_Input(
2290
	'adv_dhcp6_prefix_interface_statement_sla_id',
2291
	null,
2292
	'text',
2293
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2294
))->sethelp('Prefix Interface sla-id');
2295

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

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

    
2305
$group = new Form_Group('Authentication statement');
2306

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

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

    
2321
$group->add(new Form_Input(
2322
	'adv_dhcp6_authentication_statement_algorithm',
2323
	null,
2324
	'text',
2325
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2326
))->sethelp('Algorithm');
2327

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

    
2335
$section->add($group);
2336

    
2337
$group = new Form_Group('Keyinfo statement');
2338

    
2339
$group->add(new Form_Input(
2340
	'adv_dhcp6_key_info_statement_keyname',
2341
	null,
2342
	'text',
2343
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2344
))->sethelp('Keyname');
2345

    
2346
$group->add(new Form_Input(
2347
	'adv_dhcp6_key_info_statement_realm',
2348
	null,
2349
	'text',
2350
	$pconfig['adv_dhcp6_key_info_statement_realm']
2351
))->sethelp('Realm');
2352

    
2353
$section->add($group);
2354

    
2355
$group = new Form_Group('');
2356

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

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

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

    
2378
$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>');
2379

    
2380
$section->add($group);
2381

    
2382
$form->add($section);
2383

    
2384
$section = new Form_Section('6RD Configuration');
2385
$section->addClass('_6rd');
2386

    
2387
$section->addInput(new Form_Input(
2388
	'prefix-6rd',
2389
	'6RD Prefix',
2390
	'text',
2391
	$pconfig['prefix-6rd']
2392
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2393

    
2394
$section->addInput(new Form_Input(
2395
	'gateway-6rd',
2396
	'6RD Border relay',
2397
	'text',
2398
	$pconfig['gateway-6rd']
2399
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2400

    
2401
$section->addInput(new Form_Select(
2402
	'prefix-6rd-v4plen',
2403
	'6RD IPv4 Prefix length',
2404
	$pconfig['prefix-6rd-v4plen'],
2405
	array_combine(range(0, 32), range(0, 32))
2406
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2407

    
2408
$form->add($section);
2409

    
2410
// Track IPv6 ointerface section
2411
$section = new Form_Section('Track IPv6 Interface');
2412
$section->addClass('track6');
2413

    
2414
function build_ipv6interface_list() {
2415
	global $config, $section;
2416

    
2417
	$list = array('' => '');
2418

    
2419
	$interfaces = get_configured_interface_with_descr(false, true);
2420
	$dynv6ifs = array();
2421

    
2422
	foreach ($interfaces as $iface => $ifacename) {
2423
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2424
			case "6to4":
2425
			case "6rd":
2426
			case "dhcp6":
2427
				$dynv6ifs[$iface] = array(
2428
					'name' => $ifacename,
2429
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2430
				);
2431
				break;
2432
			default:
2433
				continue;
2434
		}
2435
	}
2436

    
2437
	foreach ($dynv6ifs as $iface => $ifacedata) {
2438
		$list[$iface] = $ifacedata['name'];
2439

    
2440
		$section->addInput(new Form_Input(
2441
			'ipv6-num-prefix-ids-' . $iface,
2442
			null,
2443
			'hidden',
2444
			$ifacedata['ipv6_num_prefix_ids']
2445
		));
2446
	}
2447

    
2448
	return($list);
2449
}
2450

    
2451
$section->addInput(new Form_Select(
2452
	'track6-interface',
2453
	'IPv6 Interface',
2454
	$pconfig['track6-interface'],
2455
	build_ipv6interface_list()
2456
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2457

    
2458
if ($pconfig['track6-prefix-id'] == "") {
2459
	$pconfig['track6-prefix-id'] = 0;
2460
}
2461

    
2462
$section->addInput(new Form_Input(
2463
	'track6-prefix-id--hex',
2464
	'IPv6 Prefix ID',
2465
	'text',
2466
	sprintf("%x", $pconfig['track6-prefix-id'])
2467
))->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.');
2468

    
2469
$section->addInput(new Form_Input(
2470
	'track6-prefix-id-max',
2471
	null,
2472
	'hidden',
2473
	0
2474
));
2475

    
2476
$form->add($section);
2477

    
2478
/// PPP section
2479

    
2480
$section = new Form_Section('PPP Configuration');
2481
$section->addClass('ppp');
2482

    
2483
$section->addInput(new Form_Select(
2484
	'country',
2485
	'Country',
2486
	$pconfig['country'],
2487
	[]
2488
));
2489

    
2490
$section->addInput(new Form_Select(
2491
	'provider_list',
2492
	'Provider',
2493
	$pconfig['provider_list'],
2494
	[]
2495
));
2496

    
2497
$section->addInput(new Form_Select(
2498
	'providerplan',
2499
	'Plan',
2500
	$pconfig['providerplan'],
2501
	[]
2502
))->setHelp('Select to fill in service provider data.');
2503

    
2504
$section->addInput(new Form_Input(
2505
	'ppp_username',
2506
	'Username',
2507
	'text',
2508
	$pconfig['ppp_username']
2509
));
2510

    
2511
$section->addPassword(new Form_Input(
2512
	'ppp_password',
2513
	'Password',
2514
	'password',
2515
	$pconfig['ppp_password']
2516
));
2517

    
2518
$section->addInput(new Form_Input(
2519
	'phone',
2520
	'Phone number',
2521
	'text',
2522
	$pconfig['phone']
2523
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2524

    
2525
$section->addInput(new Form_Input(
2526
	'apn',
2527
	'Access Point Name',
2528
	'text',
2529
	$pconfig['apn']
2530
));
2531

    
2532

    
2533
function build_port_list() {
2534
	$list = array("" => "None");
2535

    
2536
	$portlist = glob("/dev/cua*");
2537
	$modems	  = glob("/dev/modem*");
2538
	$portlist = array_merge($portlist, $modems);
2539

    
2540
	foreach ($portlist as $port) {
2541
		if (preg_match("/\.(lock|init)$/", $port)) {
2542
			continue;
2543
		}
2544

    
2545
	$list[trim($port)] = $port;
2546
	}
2547

    
2548
	return($list);
2549
}
2550

    
2551
$section->addInput(new Form_Select(
2552
	'port',
2553
	"Modem port",
2554
	$pconfig['port'],
2555
	build_port_list()
2556
));
2557

    
2558
$section->addInput(new Form_Button(
2559
	'btnadvppp',
2560
	'Advanced PPP',
2561
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2562
	'fa-cog'
2563
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2564

    
2565
$form->add($section);
2566

    
2567
// PPPoE configuration
2568
$section = new Form_Section('PPPoE Configuration');
2569
$section->addClass('pppoe');
2570

    
2571
$section->addInput(new Form_Input(
2572
	'pppoe_username',
2573
	'Username',
2574
	'text',
2575
	$pconfig['pppoe_username']
2576
));
2577

    
2578
$section->addPassword(new Form_Input(
2579
	'pppoe_password',
2580
	'Password',
2581
	'password',
2582
	$pconfig['pppoe_password']
2583
));
2584

    
2585
$section->addInput(new Form_Input(
2586
	'provider',
2587
	'Service name',
2588
	'text',
2589
	$pconfig['provider']
2590
))->setHelp('This field can usually be left empty.');
2591

    
2592
$section->addInput(new Form_Checkbox(
2593
	'pppoe_dialondemand',
2594
	'Dial on demand',
2595
	'Enable Dial-On-Demand mode ',
2596
	$pconfig['pppoe_dialondemand'],
2597
	'enable'
2598
));
2599

    
2600
$section->addInput(new Form_Input(
2601
	'pppoe_idletimeout',
2602
	'Idle timeout',
2603
	'number',
2604
	$pconfig['pppoe_idletimeout'],
2605
	['min' => 0]
2606
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2607
			'An idle timeout of zero disables this feature.');
2608

    
2609
$section->addInput(new Form_Select(
2610
	'pppoe-reset-type',
2611
	'Periodic reset',
2612
	$pconfig['pppoe-reset-type'],
2613
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2614
))->setHelp('Select a reset timing type.');
2615

    
2616
$group = new Form_Group('Custom reset');
2617
$group->addClass('pppoecustom');
2618

    
2619
$group->add(new Form_Input(
2620
	'pppoe_resethour',
2621
	null,
2622
	'number',
2623
	$pconfig['pppoe_resethour'],
2624
	['min' => 0, 'max' => 23]
2625
))->setHelp('Hour (0-23)');
2626

    
2627
$group->add(new Form_Input(
2628
	'pppoe_resetminute',
2629
	null,
2630
	'number',
2631
	$pconfig['pppoe_resetminute'],
2632
	['min' => 0, 'max' => 59]
2633
))->setHelp('Minutes (0-59)');
2634

    
2635
$group->add(new Form_Input(
2636
	'pppoe_resetdate',
2637
	null,
2638
	'text',
2639
	$pconfig['pppoe_resetdate']
2640
))->setHelp('Specific date (mm/dd/yyyy)');
2641

    
2642
$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');
2643

    
2644
$section->add($group);
2645

    
2646
$group = new Form_MultiCheckboxGroup('cron based reset');
2647
$group->addClass('pppoepreset');
2648

    
2649
$group->add(new Form_MultiCheckbox(
2650
	'pppoe_pr_preset_val',
2651
	null,
2652
	'Reset at each month ("0 0 1 * *")',
2653
	$pconfig['pppoe_monthly'],
2654
	'monthly'
2655
))->displayAsRadio();
2656

    
2657
$group->add(new Form_MultiCheckbox(
2658
	'pppoe_pr_preset_val',
2659
	null,
2660
	'Reset at each week ("0 0 * * 0")',
2661
	$pconfig['pppoe_weekly'],
2662
	'weekly'
2663
))->displayAsRadio();
2664

    
2665
$group->add(new Form_MultiCheckbox(
2666
	'pppoe_pr_preset_val',
2667
	null,
2668
	'Reset at each day ("0 0 * * *")',
2669
	$pconfig['pppoe_daily'],
2670
	'daily'
2671
))->displayAsRadio();
2672

    
2673
$group->add(new Form_MultiCheckbox(
2674
	'pppoe_pr_preset_val',
2675
	null,
2676
	'Reset at each hour ("0 * * * *")',
2677
	$pconfig['pppoe_hourly'],
2678
	'hourly'
2679
))->displayAsRadio();
2680

    
2681
$section->add($group);
2682

    
2683
$section->addInput(new Form_Button(
2684
	'btnadvppp',
2685
	'Advanced and MLPPP',
2686
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2687
	'fa-cog'
2688
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2689

    
2690
$form->add($section);
2691

    
2692
// PPTP & L2TP Configuration section
2693
$section = new Form_Section('PPTP/L2TP Configuration');
2694
$section->addClass('pptp');
2695

    
2696
$section->addInput(new Form_Input(
2697
	'pptp_username',
2698
	'Username',
2699
	'text',
2700
	$pconfig['pptp_username']
2701
));
2702

    
2703
$section->addPassword(new Form_Input(
2704
	'pptp_password',
2705
	'Password',
2706
	'password',
2707
	$pconfig['pptp_password']
2708
));
2709

    
2710
$section->addInput(new Form_IpAddress(
2711
	'pptp_local0',
2712
	'Local IP address',
2713
	$pconfig['pptp_localip'][0]
2714
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2715

    
2716
$section->addInput(new Form_IpAddress(
2717
	'pptp_remote0',
2718
	'Remote IP address',
2719
	$pconfig['pptp_remote'][0]
2720
));
2721

    
2722
$section->addInput(new Form_Checkbox(
2723
	'pptp_dialondemand',
2724
	'Dial on demand',
2725
	'Enable Dial-On-Demand mode ',
2726
	$pconfig['pptp_dialondemand'],
2727
	'enable'
2728
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2729
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2730

    
2731
$section->addInput(new Form_Input(
2732
	'pptp_idletimeout',
2733
	'Idle timeout (seconds)',
2734
	'number',
2735
	$pconfig['pptp_idletimeout'],
2736
	['min' => 0]
2737
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2738
			'An idle timeout of zero disables this feature.');
2739

    
2740
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2741
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2742
} else {
2743
	$mlppp_text = "";
2744
}
2745

    
2746
$section->addInput(new Form_Button(
2747
	'btnadvppp',
2748
	'Advanced and MLPPP',
2749
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2750
	'fa-cog'
2751
))->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.');
2752

    
2753
$form->add($section);
2754

    
2755
// Wireless interface
2756
if (isset($wancfg['wireless'])) {
2757

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

    
2760
	$section->addInput(new Form_Checkbox(
2761
		'persistcommonwireless',
2762
		'Persist common settings',
2763
		'Preserve common wireless configuration through interface deletions and reassignments.',
2764
		$pconfig['persistcommonwireless'],
2765
		'yes'
2766
	));
2767

    
2768
	$mode_list = ['auto' => 'Auto'];
2769

    
2770
	if (is_array($wl_modes)) {
2771
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2772
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2773
		}
2774
	}
2775

    
2776
	if (count($mode_list) == 1) {
2777
		$mode_list[''] = '';
2778
	}
2779

    
2780
	$section->addInput(new Form_Select(
2781
		'standard',
2782
		'Standard',
2783
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2784
		$mode_list
2785
	));
2786

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

    
2803
	$mode_list = ['0' => gettext('Auto')];
2804

    
2805
	if (is_array($wl_modes)) {
2806
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2807
			if ($wl_standard == "11g") {
2808
				$wl_standard = "11b/g";
2809
			} else if ($wl_standard == "11ng") {
2810
				$wl_standard = "11b/g/n";
2811
			} else if ($wl_standard == "11na") {
2812
				$wl_standard = "11a/n";
2813
			}
2814

    
2815
			foreach ($wl_channels as $wl_channel) {
2816
				if (isset($wl_chaninfo[$wl_channel])) {
2817
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2818
				} else {
2819
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2820
				}
2821
			}
2822
		}
2823
	}
2824

    
2825
	$section->addInput(new Form_Select(
2826
		'channel',
2827
		'Channel',
2828
		$pconfig['channel'],
2829
		$mode_list
2830
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2831
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2832

    
2833
	if (ANTENNAS) {
2834
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2835
			$group = new Form_Group('Antenna Settings');
2836

    
2837
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2838
				$group->add(new Form_Select(
2839
					'diversity',
2840
					null,
2841
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2842
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2843
				))->setHelp('Diversity');
2844
			}
2845

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

    
2855
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2856
				$group->add(new Form_Select(
2857
					'rxantenna',
2858
					null,
2859
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2860
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2861
				))->setHelp('Receive antenna');
2862
			}
2863

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

    
2866
			$section->add($group);
2867
		}
2868
	}
2869

    
2870
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2871
			$section->addInput(new Form_Input(
2872
				'distance',
2873
				'Distance setting (meters)',
2874
				'test',
2875
				$pconfig['distance']
2876
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2877
	}
2878

    
2879
	$form->add($section);
2880

    
2881
	// Regulatory settings
2882
	$section = new Form_Section('Regulatory Settings');
2883

    
2884
	$domain_list = array("" => 'Default');
2885

    
2886
	if (is_array($wl_regdomains)) {
2887
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2888
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2889
		}
2890
	}
2891

    
2892
	$section->addInput(new Form_Select(
2893
		'regdomain',
2894
		'Regulatory domain',
2895
		$pconfig['regdomain'],
2896
		$domain_list
2897
	))->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');
2898

    
2899
	$country_list = array('' => 'Default');
2900

    
2901
	if (is_array($wl_countries)) {
2902
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2903
			$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']);
2904
		}
2905
	}
2906

    
2907
	$section->addInput(new Form_Select(
2908
		'regcountry',
2909
		'Country',
2910
		$pconfig['regcountry'],
2911
		$country_list
2912
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2913

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

    
2925
	$form->add($section);
2926

    
2927
	$section = new Form_Section('Network-Specific Wireless Configuration');
2928

    
2929
	$section->addInput(new Form_Select(
2930
		'mode',
2931
		'Mode',
2932
		$pconfig['mode'],
2933
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2934
	));
2935

    
2936
	$section->addInput(new Form_Input(
2937
		'ssid',
2938
		'SSID',
2939
		'text',
2940
		$pconfig['ssid']
2941
	));
2942

    
2943
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2944
		$section->addInput(new Form_Select(
2945
			'puremode',
2946
			'Minimum wireless standard',
2947
			$pconfig['puremode'],
2948
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2949
		))->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)');
2950
	} elseif (isset($wl_modes['11g'])) {
2951
		$section->addInput(new Form_Checkbox(
2952
			'puremode',
2953
			'802.11g only',
2954
			null,
2955
			$pconfig['puremode'],
2956
			'11g'
2957
		))->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)');
2958
	}
2959

    
2960
	$section->addInput(new Form_Checkbox(
2961
		'apbridge_enable',
2962
		'Allow intra-BSS communication',
2963
		'Allow packets to pass between wireless clients directly when operating as an access point',
2964
		$pconfig['apbridge_enable'],
2965
		'yes'
2966
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2967

    
2968
	$section->addInput(new Form_Checkbox(
2969
		'wme_enable',
2970
		'Enable WME',
2971
		'Force the card to use WME (wireless QoS)',
2972
		$pconfig['wme_enable'],
2973
		'yes'
2974
	));
2975

    
2976
	$section->addInput(new Form_Checkbox(
2977
		'hidessid_enable',
2978
		'Hide SSID',
2979
		'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.)',
2980
		$pconfig['hidessid_enable'],
2981
		'yes'
2982
	));
2983

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

    
2986
	// WPA Section
2987
	$section = new Form_Section('WPA');
2988

    
2989
	$section->addInput(new Form_Checkbox(
2990
		'wpa_enable',
2991
		'Enable',
2992
		'Enable WPA',
2993
		$pconfig['wpa_enable'],
2994
		'yes'
2995
	));
2996

    
2997
	$section->addInput(new Form_Input(
2998
		'passphrase',
2999
		'WPA Pre-Shared Key',
3000
		'text',
3001
		$pconfig['passphrase']
3002
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3003

    
3004
	$section->addInput(new Form_Select(
3005
		'wpa_mode',
3006
		'WPA mode',
3007
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3008
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3009
	));
3010

    
3011
	$section->addInput(new Form_Select(
3012
		'wpa_key_mgmt',
3013
		'WPA Key Management Mode',
3014
		$pconfig['wpa_key_mgmt'],
3015
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3016
	));
3017

    
3018
	$section->addInput(new Form_Select(
3019
		'wpa_pairwise',
3020
		'WPA Pairwise',
3021
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3022
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3023
	));
3024

    
3025
	$section->addInput(new Form_Input(
3026
		'wpa_group_rekey',
3027
		'Group Key Rotation',
3028
		'number',
3029
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3030
		['min' => '1', 'max' => 9999]
3031
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3032

    
3033
	$section->addInput(new Form_Input(
3034
		'wpa_gmk_rekey',
3035
		'Group Master Key Regeneration',
3036
		'number',
3037
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3038
		['min' => '1', 'max' => 9999]
3039
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3040

    
3041
	$section->addInput(new Form_Checkbox(
3042
		'wpa_strict_rekey',
3043
		'Strict Key Regeneration',
3044
		'Force the AP to rekey whenever a client disassociates',
3045
		$pconfig['wpa_strict_rekey'],
3046
		'yes'
3047
	));
3048

    
3049
	$form->add($section);
3050

    
3051
	$section = new Form_Section('802.1x RADIUS Options');
3052

    
3053
	$section->addInput(new Form_Checkbox(
3054
		'ieee8021x',
3055
		'IEEE802.1X',
3056
		'Enable 802.1X authentication',
3057
		$pconfig['ieee8021x'],
3058
		'yes'
3059
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3060

    
3061
	$group = new Form_Group('Primary 802.1X server');
3062

    
3063
	$group->add(new Form_IpAddress(
3064
		'auth_server_addr',
3065
		'IP Address',
3066
		$pconfig['auth_server_addr']
3067
	))->setHelp('IP address of the RADIUS server');
3068

    
3069
	$group->add(new Form_Input(
3070
		'auth_server_port',
3071
		'Port',
3072
		'number',
3073
		$pconfig['auth_server_port']
3074
	))->setHelp('Server auth port. Default is 1812');
3075

    
3076
	$group->add(new Form_Input(
3077
		'auth_server_shared_secret',
3078
		'Shared Secret',
3079
		'text',
3080
		$pconfig['auth_server_shared_secret']
3081
	))->setHelp('RADIUS Shared secret for this firewall');
3082

    
3083
	$section->add($group);
3084

    
3085
	$group = new Form_Group('Secondary 802.1X server');
3086

    
3087
	$group->add(new Form_IpAddress(
3088
		'auth_server_addr2',
3089
		'IP Address',
3090
		$pconfig['auth_server_addr2']
3091
	))->setHelp('IP address of the RADIUS server');
3092

    
3093
	$group->add(new Form_Input(
3094
		'auth_server_port2',
3095
		'Port',
3096
		'number',
3097
		$pconfig['auth_server_port2']
3098
	))->setHelp('Server auth port. Default is 1812');
3099

    
3100
	$group->add(new Form_Input(
3101
		'auth_server_shared_secret2',
3102
		'Shared Secret',
3103
		'text',
3104
		$pconfig['auth_server_shared_secret2']
3105
	))->setHelp('RADIUS Shared secret for this firewall');
3106

    
3107
	$section->add($group);
3108

    
3109
	$section->addInput(new Form_Checkbox(
3110
		'rsn_preauth',
3111
		'Authentication Roaming Preauth',
3112
		null,
3113
		$pconfig['rsn_preauth'],
3114
		'yes'
3115
	));
3116

    
3117
	$form->add($section);
3118
}
3119

    
3120
$section = new Form_Section('Reserved Networks');
3121

    
3122
$section->addInput(new Form_Checkbox(
3123
	'blockpriv',
3124
	'Block private networks and loopback addresses',
3125
	'',
3126
	$pconfig['blockpriv'],
3127
	'yes'
3128
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3129
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3130
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3131

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

    
3142
$form->add($section);
3143

    
3144
$form->addGlobal(new Form_Input(
3145
	'if',
3146
	null,
3147
	'hidden',
3148
	$if
3149
));
3150

    
3151
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3152
	$form->addGlobal(new Form_Input(
3153
		'ppp_port',
3154
		null,
3155
		'hidden',
3156
		$pconfig['port']
3157
	));
3158
}
3159

    
3160
$form->addGlobal(new Form_Input(
3161
	'ptpid',
3162
	null,
3163
	'hidden',
3164
	$pconfig['ptpid']
3165
));
3166

    
3167

    
3168
// Add new gateway modal pop-up
3169
$modal = new Modal('New Gateway', 'newgateway', 'large');
3170

    
3171
$modal->addInput(new Form_Checkbox(
3172
	'defaultgw',
3173
	'Default',
3174
	'Default gateway',
3175
	($if == "wan" || $if == "WAN")
3176
));
3177

    
3178
$modal->addInput(new Form_Input(
3179
	'name',
3180
	'Gateway name',
3181
	'text',
3182
	$wancfg['descr'] . "GW"
3183
));
3184

    
3185
$modal->addInput(new Form_IpAddress(
3186
	'gatewayip',
3187
	'Gateway IPv4',
3188
	null
3189
));
3190

    
3191
$modal->addInput(new Form_Input(
3192
	'gatewaydescr',
3193
	'Description',
3194
	'text'
3195
));
3196

    
3197
$btnaddgw = new Form_Button(
3198
	'add',
3199
	'Add',
3200
	null,
3201
	'fa-plus'
3202
);
3203

    
3204
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3205

    
3206
$btncnxgw = new Form_Button(
3207
	'cnx',
3208
	'Cancel',
3209
	null,
3210
	'fa-undo'
3211
);
3212

    
3213
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3214

    
3215
$modal->addInput(new Form_StaticText(
3216
	null,
3217
	$btnaddgw . $btncnxgw
3218
));
3219

    
3220
$form->add($modal);
3221

    
3222
print($form);
3223
?>
3224

    
3225
<script type="text/javascript">
3226
//<![CDATA[
3227
events.push(function() {
3228
	function updateType(t) {
3229

    
3230
		switch (t) {
3231
			case "none": {
3232
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3233
				break;
3234
			}
3235
			case "staticv4": {
3236
				$('.dhcpadvanced, .none, .dhcp').hide();
3237
				$('.pppoe, .pptp, .ppp').hide();
3238
				break;
3239
			}
3240
			case "dhcp": {
3241
				$('.dhcpadvanced, .none').hide();
3242
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3243
										//			about the staticv4 class
3244
				$('.pppoe, .pptp, .ppp').hide();
3245
				break;
3246
			}
3247
			case "ppp": {
3248
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3249
				country_list();
3250
				break;
3251
			}
3252
			case "pppoe": {
3253
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3254
				break;
3255
			}
3256
			case "l2tp":
3257
			case "pptp": {
3258
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3259
				$('.pptp').show();
3260
				break;
3261
			}
3262
		}
3263

    
3264
		if (t != "l2tp" && t != "pptp") {
3265
			$('.'+t).show();
3266
		}
3267
	}
3268

    
3269
	function updateTypeSix(t) {
3270
		if (!isNaN(t[0])) {
3271
			t = '_' + t;
3272
		}
3273

    
3274
		switch (t) {
3275
			case "none": {
3276
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3277
				break;
3278
			}
3279
			case "staticv6": {
3280
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3281
				break;
3282
			}
3283
			case "slaac": {
3284
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3285
				break;
3286
			}
3287
			case "dhcp6": {
3288
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3289
				break;
3290
			}
3291
			case "_6rd": {
3292
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3293
				break;
3294
			}
3295
			case "_6to4": {
3296
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3297
				break;
3298
			}
3299
			case "track6": {
3300
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3301
				update_track6_prefix();
3302
				break;
3303
			}
3304
		}
3305

    
3306
		if (t != "l2tp" && t != "pptp") {
3307
			$('.'+t).show();
3308
		}
3309
	}
3310

    
3311
	function show_reset_settings(reset_type) {
3312
		if (reset_type == 'preset') {
3313
			$('.pppoepreset').show();
3314
			$('.pppoecustom').hide();
3315
		} else if (reset_type == 'custom') {
3316
			$('.pppoecustom').show();
3317
			$('.pppoepreset').hide();
3318
		} else {
3319
			$('.pppoecustom').hide();
3320
			$('.pppoepreset').hide();
3321
		}
3322
	}
3323

    
3324
	function update_track6_prefix() {
3325
		var iface = $("#track6-interface").val();
3326
		if (iface == null) {
3327
			return;
3328
		}
3329

    
3330
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3331
		if (track6_prefix_ids == null) {
3332
			return;
3333
		}
3334

    
3335
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3336
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3337
	}
3338

    
3339
	// Create the new gateway from the data entered in the modal pop-up
3340
	function hide_add_gatewaysave() {
3341
		var iface = $('#if').val();
3342
		name = $('#name').val();
3343
		var descr = $('#gatewaydescr').val();
3344
		gatewayip = $('#gatewayip').val();
3345

    
3346
		var defaultgw = '';
3347
		if ($('#defaultgw').is(':checked')) {
3348
			defaultgw = '&defaultgw=on';
3349
		}
3350

    
3351
		var url = "system_gateways_edit.php";
3352
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3353
		$.ajax(
3354
			url,
3355
			{
3356
				type: 'post',
3357
				data: pars,
3358
				error: report_failure,
3359
				complete: save_callback
3360
			});
3361
		}
3362

    
3363
	function save_callback(response) {
3364
		if (response) {
3365
			var gwtext = escape(name) + " - " + gatewayip;
3366
			addOption($('#gateway'), gwtext, name);
3367
		} else {
3368
			report_failure();
3369
		}
3370

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

    
3374
	function report_failure(request, textStatus, errorThrown) {
3375
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3376
			alert(request.responseText);
3377
		} else {
3378
			alert("The IPv4 gateway could not be created.");
3379
		}
3380

    
3381
		$("#newgateway").modal('hide');
3382
	}
3383

    
3384
	function addOption(selectbox, text, value) {
3385
		var optn = document.createElement("OPTION");
3386
		optn.text = text;
3387
		optn.value = value;
3388
		selectbox.append(optn);
3389
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3390
	}
3391

    
3392
	function hide_add_gatewaysave_v6() {
3393

    
3394
		var iface = $('#if').val();
3395
		name = $('#name6').val();
3396
		var descr = $('#gatewaydescr6').val();
3397
		gatewayip = $('#gatewayip6').val();
3398
		var defaultgw = '';
3399
		if ($('#defaultgw6').is(':checked')) {
3400
			defaultgw = '&defaultgw=on';
3401
		}
3402
		var url_v6 = "system_gateways_edit.php";
3403
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3404
		$.ajax(
3405
			url_v6,
3406
			{
3407
				type: 'post',
3408
				data: pars_v6,
3409
				error: report_failure_v6,
3410
				success: save_callback_v6
3411
			});
3412
	}
3413

    
3414

    
3415
	function addOption_v6(selectbox, text, value) {
3416
		var optn = document.createElement("OPTION");
3417
		optn.text = text;
3418
		optn.value = value;
3419
		selectbox.append(optn);
3420
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3421
	}
3422

    
3423
	function report_failure_v6(request, textStatus, errorThrown) {
3424
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3425
			alert(request.responseText);
3426
		} else {
3427
			alert("The IPv6 gateway could not be created.");
3428
		}
3429

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

    
3433
	function save_callback_v6(response_v6) {
3434
		if (response_v6) {
3435

    
3436
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3437
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3438
		} else {
3439
			report_failure_v6();
3440
		}
3441

    
3442
		$("#newgateway6").modal('hide');
3443
	}
3444

    
3445
	function country_list() {
3446
		$('#country').children().remove();
3447
		$('#provider_list').children().remove();
3448
		$('#providerplan').children().remove();
3449
		$.ajax("getserviceproviders.php",{
3450
			success: function(response) {
3451

    
3452
				var responseTextArr = response.split("\n");
3453
				responseTextArr.sort();
3454

    
3455
				responseTextArr.forEach( function(value) {
3456
					country = value.split(":");
3457
					$('#country').append($('<option>', {
3458
						value: country[1],
3459
						text : country[0]
3460
					}));
3461
				});
3462
			}
3463
		});
3464
	}
3465

    
3466
	function providers_list() {
3467
		$('#provider_list').children().remove();
3468
		$('#providerplan').children().remove();
3469
		$.ajax("getserviceproviders.php",{
3470
			type: 'post',
3471
			data: {country : $('#country').val()},
3472
			success: function(response) {
3473
				var responseTextArr = response.split("\n");
3474
				responseTextArr.sort();
3475
				responseTextArr.forEach( function(value) {
3476
					$('#provider_list').append($('<option>', {
3477
							value: value,
3478
							text : value
3479
					}));
3480
				});
3481
			}
3482
		});
3483
	}
3484

    
3485
	function providerplan_list() {
3486
		$('#providerplan').children().remove();
3487
		$.ajax("getserviceproviders.php",{
3488
			type: 'post',
3489
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3490
			success: function(response) {
3491
				var responseTextArr = response.split("\n");
3492
				responseTextArr.sort();
3493

    
3494
				$('#providerplan').append($('<option>', {
3495
					value: '',
3496
					text : ''
3497
				}));
3498

    
3499
				responseTextArr.forEach( function(value) {
3500
					if (value != "") {
3501
						providerplan = value.split(":");
3502

    
3503
						$('#providerplan').append($('<option>', {
3504
							value: providerplan[1],
3505
							text : providerplan[0] + " - " + providerplan[1]
3506
						}));
3507
					}
3508
				});
3509
			}
3510
		});
3511
	}
3512

    
3513
	function prefill_provider() {
3514
		$.ajax("getserviceproviders.php",{
3515
			type: 'post',
3516
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3517
			success: function(data, textStatus, response) {
3518
				var xmldoc = response.responseXML;
3519
				var provider = xmldoc.getElementsByTagName('connection')[0];
3520
				$('#ppp_username').val('');
3521
				$('#ppp_password').val('');
3522
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3523
					$('#phone').val('#777');
3524
					$('#apn').val('');
3525
				} else {
3526
					$('#phone').val('*99#');
3527
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3528
				}
3529
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3530
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3531
				$('#ppp_username').val(ppp_username);
3532
				$('#ppp_password').val(ppp_password);
3533
			}
3534
		});
3535
	}
3536

    
3537
	function show_dhcp6adv() {
3538
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3539
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3540

    
3541
		hideCheckbox('dhcp6usev4iface', ovr);
3542
		hideCheckbox('dhcp6prefixonly', ovr);
3543
		hideInput('dhcp6-ia-pd-len', ovr);
3544
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3545
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3546

    
3547
		hideClass('dhcp6advanced', !adv || ovr);
3548
	}
3549

    
3550
	function setDHCPoptions() {
3551
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3552
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3553

    
3554
		if (ovr) {
3555
			hideInput('dhcphostname', true);
3556
			hideIpAddress('alias-address', true);
3557
			hideInput('dhcprejectfrom', true);
3558
			hideInput('adv_dhcp_config_file_override_path', false);
3559
			hideClass('dhcpadvanced', true);
3560
		} else {
3561
			hideInput('dhcphostname', false);
3562
			hideIpAddress('alias-address', false);
3563
			hideInput('dhcprejectfrom', false);
3564
			hideInput('adv_dhcp_config_file_override_path', true);
3565
			hideClass('dhcpadvanced', !adv);
3566
		}
3567
	}
3568

    
3569
	// DHCP preset actions
3570
	// Set presets from value of radio buttons
3571
	function setPresets(val) {
3572
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3573
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3574
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3575
		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']);?>");
3576
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3577
	}
3578

    
3579
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3580
		$('#adv_dhcp_pt_timeout').val(timeout);
3581
		$('#adv_dhcp_pt_retry').val(retry);
3582
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3583
		$('#adv_dhcp_pt_reboot').val(reboot);
3584
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3585
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3586
	}
3587

    
3588
	// ---------- On initial page load ------------------------------------------------------------
3589

    
3590
	updateType($('#type').val());
3591
	updateTypeSix($('#type6').val());
3592
	show_reset_settings($('#pppoe-reset-type').val());
3593
	hideClass('dhcp6advanced', true);
3594
	hideClass('dhcpadvanced', true);
3595
	show_dhcp6adv();
3596
	setDHCPoptions()
3597

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

    
3606
	// Set preset from value
3607
	setPresets(sv);
3608

    
3609
	// ---------- Click checkbox handlers ---------------------------------------------------------
3610

    
3611
	$('#type').on('change', function() {
3612
		updateType(this.value);
3613
	});
3614

    
3615
	$('#type6').on('change', function() {
3616
		updateTypeSix(this.value);
3617
	});
3618

    
3619
	$('#track6-interface').on('change', function() {
3620
		update_track6_prefix();
3621
	});
3622

    
3623
	$('#pppoe-reset-type').on('change', function() {
3624
		show_reset_settings(this.value);
3625
	});
3626

    
3627
	$("#add").click(function() {
3628
		hide_add_gatewaysave();
3629
	});
3630

    
3631
	$("#cnx").click(function() {
3632
		$("#newgateway").modal('hide');
3633
	});
3634

    
3635
	$("#add6").click(function() {
3636
		hide_add_gatewaysave_v6();
3637
	});
3638

    
3639
	$("#cnx6").click(function() {
3640
		$("#newgateway6").modal('hide');
3641
	});
3642

    
3643
	$('#country').on('change', function() {
3644
		providers_list();
3645
	});
3646

    
3647
	$('#provider_list').on('change', function() {
3648
		providerplan_list();
3649
	});
3650

    
3651
	$('#providerplan').on('change', function() {
3652
		prefill_provider();
3653
	});
3654

    
3655
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3656
		setDHCPoptions();
3657
	});
3658

    
3659
	$('#adv_dhcp6_config_advanced').click(function () {
3660
		show_dhcp6adv();
3661
	});
3662

    
3663
	$('#adv_dhcp6_config_file_override').click(function () {
3664
		show_dhcp6adv();
3665
	});
3666

    
3667
	// On click . .
3668
	$('[name=adv_dhcp_pt_values]').click(function () {
3669
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3670
	});
3671

    
3672
	$('#pppoe_resetdate').datepicker();
3673

    
3674
});
3675
//]]>
3676
</script>
3677

    
3678
<?php include("foot.inc");
(68-68/227)