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

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

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

    
76
define("ANTENNAS", false);
77

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
439
}
440

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

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

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

    
479
		clear_subsystem_dirty('interfaces');
480

    
481
		filter_configure();
482

    
483
		enable_rrd_graphing();
484

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

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

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

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

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

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

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

    
546
	if (is_numeric($_POST['descr'])) {
547
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
548
	}
549
	/* input validation */
550
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
551
		$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.");
552
	}
553
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
554
		$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.");
555
	}
556

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

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

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

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

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

    
716
			foreach ($staticroutes as $route_subnet) {
717
				list($network, $subnet) = explode("/", $route_subnet);
718
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
719
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
720
					break;
721
				}
722
				unset($network, $subnet);
723
			}
724
		}
725
	}
726
	if ($_POST['ipaddrv6']) {
727
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
728

    
729
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
730
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
731
		} else {
732
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
733
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
734
			}
735
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
736
			if (count($where_ipaddr_configured)) {
737
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
738
				foreach ($where_ipaddr_configured as $subnet_conflict) {
739
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
740
				}
741
				$input_errors[] = $subnet_conflict_text;
742
			}
743

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

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

    
833
		unset($min_mtu, $max_mtu);
834

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

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

    
857
				if ($parent_realhwif != $wancfg['if']) {
858
					continue;
859
				}
860

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

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

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

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

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

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

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

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

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

    
1028
		unset($wancfg['adv_dhcp_pt_values']);
1029

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

    
1035
		unset($wancfg['adv_dhcp_config_advanced']);
1036
		unset($wancfg['adv_dhcp_config_file_override']);
1037
		unset($wancfg['adv_dhcp_config_file_override_path']);
1038

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

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

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

    
1056
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1057
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1058

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

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

    
1070
		unset($wancfg['adv_dhcp6_config_advanced']);
1071
		unset($wancfg['adv_dhcp6_config_file_override']);
1072
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1073

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

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

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

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

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

    
1132
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1133

    
1134
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1135
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1136
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1137
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1138

    
1139
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1140
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1141
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1142

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

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

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

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

    
1264
				if ($_POST['dhcp6withoutra'] == "yes") {
1265
					$wancfg['dhcp6withoutra'] = true;
1266
				}
1267

    
1268
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1269
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1270
				}
1271
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1272
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1273
				}
1274
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1275
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1276
				}
1277
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1278
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1279
				}
1280

    
1281
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1282
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1283
				}
1284
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1285
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1286
				}
1287
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1288
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1289
				}
1290
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1291
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1292
				}
1293
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1294
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1295
				}
1296

    
1297
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1298
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1299
				}
1300
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1301
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1302
				}
1303
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1304
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1307
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1310
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1311
				}
1312

    
1313
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1314
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1315
				}
1316
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1317
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1318
				}
1319

    
1320
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1321
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1322
				}
1323
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1324
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1325
				}
1326
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1327
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1328
				}
1329
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1330
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1331
				}
1332

    
1333
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1334
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1335
				}
1336
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1337
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1338
				}
1339
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1340
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1341
				}
1342
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1343
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1344
				}
1345
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1346
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1347
				}
1348

    
1349
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1350
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1351
				}
1352
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1353
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1354
				}
1355
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1356
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1357
				}
1358

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

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

    
1430
		conf_mount_ro();
1431
		write_config();
1432

    
1433
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1434
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1435
		} else {
1436
			$toapplylist = array();
1437
		}
1438
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1439
		$toapplylist[$if]['ppps'] = $old_ppps;
1440
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1441

    
1442
		mark_subsystem_dirty('interfaces');
1443

    
1444
		/* regenerate cron settings/crontab file */
1445
		configure_cron();
1446

    
1447
		header("Location: interfaces.php?if={$if}");
1448
		exit;
1449
	}
1450

    
1451
} // end if ($_POST)
1452

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

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

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

    
1602
	interface_sync_wireless_clones($wancfg, true);
1603
}
1604

    
1605
function check_wireless_mode() {
1606
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1607

    
1608
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1609
		return;
1610
	}
1611

    
1612
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1613
		$clone_count = 1;
1614
	} else {
1615
		$clone_count = 0;
1616
	}
1617

    
1618
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1619
		foreach ($config['wireless']['clone'] as $clone) {
1620
			if ($clone['if'] == $wlanbaseif) {
1621
				$clone_count++;
1622
			}
1623
		}
1624
	}
1625

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

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

    
1653
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1654
$shortcut_section = "interfaces";
1655

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

    
1659
// Get the MAC address
1660
$ip = $_SERVER['REMOTE_ADDR'];
1661
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1662
$mymac = str_replace("\n", "", $mymac);
1663

    
1664
function build_mediaopts_list() {
1665
	global $mediaopts_list;
1666

    
1667
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1668
			 " " =>	 gettext("------- Media Supported by this interface -------")
1669
			];
1670

    
1671
	foreach ($mediaopts_list as $mediaopt) {
1672
		$list[$mediaopt] = $mediaopt;
1673
	}
1674

    
1675
	return($list);
1676
}
1677

    
1678
function build_gateway_list() {
1679
	global $a_gateways, $if;
1680

    
1681
	$list = array("none" => gettext("None"));
1682
	foreach ($a_gateways as $gateway) {
1683
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1684
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1685
		}
1686
	}
1687

    
1688
	return($list);
1689
}
1690

    
1691
function build_gatewayv6_list() {
1692
	global $a_gateways, $if;
1693

    
1694
	$list = array("none" => gettext("None"));
1695
	foreach ($a_gateways as $gateway) {
1696
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1697
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1698
		}
1699
	}
1700

    
1701
	return($list);
1702
}
1703

    
1704
include("head.inc");
1705

    
1706
if ($input_errors) {
1707
	print_input_errors($input_errors);
1708
}
1709

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

    
1716
if ($savemsg) {
1717
	print_info_box($savemsg, 'success');
1718
}
1719

    
1720

    
1721
$form = new Form();
1722

    
1723
$section = new Form_Section('General Configuration');
1724

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

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

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

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

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

    
1762
$btnmymac = new Form_Button(
1763
	'btnmymac',
1764
	'Copy My MAC',
1765
	null,
1766
	'fa-clone'
1767
	);
1768

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

    
1771
$group = new Form_Group('MAC Address');
1772
$group->add($macaddress);
1773
// $group->add($btnmymac);
1774
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1775
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.');
1776
$section->add($group);
1777

    
1778
$section->addInput(new Form_Input(
1779
	'mtu',
1780
	'MTU',
1781
	'number',
1782
	$pconfig['mtu']
1783
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1784
			'This is typically 1500 bytes but can vary in some circumstances.');
1785

    
1786
$section->addInput(new Form_Input(
1787
	'mss',
1788
	'MSS',
1789
	'number',
1790
	$pconfig['mss']
1791
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1792
			'header size) will be in effect.');
1793

    
1794
if (count($mediaopts_list) > 0) {
1795
	$section->addInput(new Form_Select(
1796
		'mediaopt',
1797
		'Speed and Duplex',
1798
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1799
		build_mediaopts_list()
1800
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1801
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1802
}
1803

    
1804
$form->add($section);
1805

    
1806
$section = new Form_Section('Static IPv4 Configuration');
1807
$section->addClass('staticv4');
1808

    
1809
$section->addInput(new Form_IpAddress(
1810
	'ipaddr',
1811
	'IPv4 Address',
1812
	$pconfig['ipaddr'],
1813
	'V4'
1814
))->addMask('subnet', $pconfig['subnet'], 32);
1815

    
1816
$group = new Form_Group('IPv4 Upstream gateway');
1817

    
1818
$group->add(new Form_Select(
1819
	'gateway',
1820
	'IPv4 Upstream Gateway',
1821
	$pconfig['gateway'],
1822
	build_gateway_list()
1823
));
1824

    
1825
$group->add(new Form_Button(
1826
	'addgw',
1827
	'Add a new gateway',
1828
	null,
1829
	'fa-plus'
1830
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1831

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

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

    
1838
$form->add($section);
1839

    
1840
$section = new Form_Section('Static IPv6 Configuration');
1841
$section->addClass('staticv6');
1842

    
1843
$section->addInput(new Form_IpAddress(
1844
	'ipaddrv6',
1845
	'IPv6 address',
1846
	$pconfig['ipaddrv6'],
1847
	'V6'
1848
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1849

    
1850
$group = new Form_Group('IPv6 Upstream gateway');
1851

    
1852
$group->add(new Form_Select(
1853
	'gatewayv6',
1854
	'IPv6 Upstream Gateway',
1855
	$pconfig['gatewayv6'],
1856
	build_gatewayv6_list()
1857
));
1858

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

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

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

    
1872
// Add new gateway modal pop-up for IPv6
1873
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1874

    
1875
$modal->addInput(new Form_Checkbox(
1876
	'defaultgw6',
1877
	'Default',
1878
	'Default gateway',
1879
	($if == "wan" || $if == "WAN")
1880
));
1881

    
1882
$modal->addInput(new Form_Input(
1883
	'name6',
1884
	'Gateway name',
1885
	'text',
1886
	$wancfg['descr'] . "GWv6"
1887
));
1888

    
1889
$modal->addInput(new Form_IpAddress(
1890
	'gatewayip6',
1891
	'Gateway IPv6',
1892
	null,
1893
	'V6'
1894
));
1895

    
1896
$modal->addInput(new Form_Input(
1897
	'gatewaydescr6',
1898
	'Description',
1899
	'text'
1900
));
1901

    
1902
$btnaddgw6 = new Form_Button(
1903
	'add6',
1904
	'Add',
1905
	null,
1906
	'fa-plus'
1907
);
1908

    
1909
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1910

    
1911
$btncnxgw6 = new Form_Button(
1912
	'cnx6',
1913
	'Cancel',
1914
	null,
1915
	'fa-undo'
1916
);
1917

    
1918
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1919

    
1920
$modal->addInput(new Form_StaticText(
1921
	null,
1922
	$btnaddgw6 . $btncnxgw6
1923
));
1924

    
1925
$form->add($modal);
1926

    
1927
// ==== DHCP client configuration =============================
1928

    
1929
$section = new Form_Section('DHCP Client Configuration');
1930
$section->addClass('dhcp');
1931

    
1932
$group = new Form_Group('Options');
1933

    
1934
$group->add(new Form_Checkbox(
1935
	'adv_dhcp_config_advanced',
1936
	null,
1937
	'Advanced Configuration',
1938
	$pconfig['adv_dhcp_config_advanced']
1939
))->setHelp('Use advanced DHCP configuration options.');
1940

    
1941
$group->add(new Form_Checkbox(
1942
	'adv_dhcp_config_file_override',
1943
	null,
1944
	'Configuration Override',
1945
	$pconfig['adv_dhcp_config_file_override']
1946
))->setHelp('Override the configuration from this file.');
1947

    
1948
$section->add($group);
1949

    
1950
$section->addInput(new Form_Input(
1951
	'dhcphostname',
1952
	'Hostname',
1953
	'text',
1954
	$pconfig['dhcphostname']
1955
))->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).');
1956

    
1957
$section->addInput(new Form_IpAddress(
1958
	'alias-address',
1959
	'Alias IPv4 address',
1960
	$pconfig['alias-address'],
1961
	'V4'
1962
))->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.');
1963

    
1964
$section->addInput(new Form_Input(
1965
	'dhcprejectfrom',
1966
	'Reject leases from',
1967
	'text',
1968
	$pconfig['dhcprejectfrom']
1969
))->setHelp('To make the DHCP client reject leases from an undesirable DHCP server, place the IP address of the DHCP server here. ' .
1970
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
1971

    
1972
$group = new Form_Group('Protocol timing');
1973
$group->addClass('dhcpadvanced');
1974

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

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

    
1989
$group->add(new Form_Input(
1990
	'adv_dhcp_pt_select_timeout',
1991
	null,
1992
	'number',
1993
	$pconfig['adv_dhcp_pt_select_timeout'],
1994
	['min' => 0]
1995
))->setHelp('Select timeout');
1996

    
1997
$group->add(new Form_Input(
1998
	'adv_dhcp_pt_reboot',
1999
	null,
2000
	'number',
2001
	$pconfig['adv_dhcp_pt_reboot']
2002
))->setHelp('Reboot');
2003

    
2004
$group->add(new Form_Input(
2005
	'adv_dhcp_pt_backoff_cutoff',
2006
	null,
2007
	'number',
2008
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2009
))->setHelp('Backoff cutoff');
2010

    
2011
$group->add(new Form_Input(
2012
	'adv_dhcp_pt_initial_interval',
2013
	null,
2014
	'number',
2015
	$pconfig['adv_dhcp_pt_initial_interval']
2016
))->setHelp('Initial interval');
2017

    
2018
$section->add($group);
2019

    
2020
$group = new Form_Group('Presets');
2021
$group->addClass('dhcpadvanced');
2022

    
2023
$group->add(new Form_Checkbox(
2024
	'adv_dhcp_pt_values',
2025
	null,
2026
	'FreeBSD default',
2027
	null,
2028
	'DHCP'
2029
))->displayAsRadio();
2030

    
2031
$group->add(new Form_Checkbox(
2032
	'adv_dhcp_pt_values',
2033
	null,
2034
	'Clear',
2035
	null,
2036
	'Clear'
2037
))->displayAsRadio();
2038

    
2039
$group->add(new Form_Checkbox(
2040
	'adv_dhcp_pt_values',
2041
	null,
2042
	'pfSense Default',
2043
	null,
2044
	'pfSense'
2045
))->displayAsRadio();
2046

    
2047
$group->add(new Form_Checkbox(
2048
	'adv_dhcp_pt_values',
2049
	null,
2050
	'Saved Cfg',
2051
	null,
2052
	'SavedCfg'
2053
))->displayAsRadio();
2054

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

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

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

    
2070
$form->add($section);
2071

    
2072
$section = new Form_Section('Lease Requirements and Requests');
2073
$section->addClass('dhcpadvanced');
2074

    
2075
$section->addInput(new Form_Input(
2076
	'adv_dhcp_send_options',
2077
	'Send options',
2078
	'text',
2079
	$pconfig['adv_dhcp_send_options']
2080
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2081
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2082
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2083
			'Some ISPs may require certain options be or not be sent.');
2084

    
2085
$section->addInput(new Form_Input(
2086
	'adv_dhcp_request_options',
2087
	'Request options',
2088
	'text',
2089
	$pconfig['adv_dhcp_request_options']
2090
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2091
			'Some ISPs may require certain options be or not be requested.');
2092

    
2093
$section->addInput(new Form_Input(
2094
	'adv_dhcp_required_options',
2095
	'Require options',
2096
	'text',
2097
	$pconfig['adv_dhcp_required_options']
2098
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2099

    
2100
$section->addInput(new Form_Input(
2101
	'adv_dhcp_option_modifiers',
2102
	'Option modifiers',
2103
	'text',
2104
	$pconfig['adv_dhcp_option_modifiers']
2105
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2106
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2107
			'<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>');
2108

    
2109
$form->add($section);
2110

    
2111
// DHCP6 client config
2112

    
2113
$section = new Form_Section('DHCP6 Client Configuration');
2114
$section->addClass('dhcp6');
2115

    
2116
$group = new Form_Group('Options');
2117

    
2118
$group->add(new Form_Checkbox(
2119
	'adv_dhcp6_config_advanced',
2120
	null,
2121
	'Advanced Configuration',
2122
	$pconfig['adv_dhcp6_config_advanced']
2123
))->setHelp('Use advanced DHCPv6 configuration options.');
2124

    
2125
$group->add(new Form_Checkbox(
2126
	'adv_dhcp6_config_file_override',
2127
	null,
2128
	'Configuration Override',
2129
	$pconfig['adv_dhcp6_config_file_override']
2130
))->setHelp('Override the configuration from this file.');
2131

    
2132
$section->add($group);
2133

    
2134
$section->addInput(new Form_Checkbox(
2135
	'dhcp6usev4iface',
2136
	'Use IPv4 connectivity as parent interface',
2137
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2138
	$pconfig['dhcp6usev4iface']
2139
));
2140

    
2141
$section->addInput(new Form_Checkbox(
2142
	'dhcp6prefixonly',
2143
	'Request only an IPv6 prefix',
2144
	'Only request an IPv6 prefix, do not request an IPv6 address',
2145
	$pconfig['dhcp6prefixonly']
2146
));
2147

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

    
2155
$section->addInput(new Form_Checkbox(
2156
	'dhcp6-ia-pd-send-hint',
2157
	'Send IPv6 prefix hint',
2158
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2159
	$pconfig['dhcp6-ia-pd-send-hint']
2160
));
2161

    
2162
$section->addInput(new Form_Checkbox(
2163
	'dhcp6debug',
2164
	'Debug',
2165
	'Start DHCP6 client in debug mode',
2166
	$pconfig['dhcp6debug']
2167
));
2168

    
2169
$section->addInput(new Form_Checkbox(
2170
	'dhcp6withoutra',
2171
	'Do not wait for a RA',
2172
	'Required by some ISPs, especially those not using PPPoE',
2173
	$pconfig['dhcp6withoutra']
2174
));
2175

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

    
2186
$form->add($section);
2187

    
2188
// DHCP6 client config - Advanced
2189

    
2190
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2191
$section->addClass('dhcp6advanced');
2192

    
2193
$section->addInput(new Form_Checkbox(
2194
	'adv_dhcp6_interface_statement_information_only_enable',
2195
	'Information only',
2196
	'Exchange Information Only',
2197
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2198
	'Selected'
2199
))->setHelp('Only exchange informational configuration parameters with servers.');
2200

    
2201
$section->addInput(new Form_Input(
2202
	'adv_dhcp6_interface_statement_send_options',
2203
	'Send options',
2204
	'text',
2205
	$pconfig['adv_dhcp6_interface_statement_send_options']
2206
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2207
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2208
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2209
			'Some DHCP services may require certain options be or not be sent.');
2210

    
2211
$section->addInput(new Form_Input(
2212
	'adv_dhcp6_interface_statement_request_options',
2213
	'Request Options',
2214
	'text',
2215
	$pconfig['adv_dhcp6_interface_statement_request_options']
2216
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2217
			'Some DHCP services may require certain options be or not be requested.');
2218

    
2219
$section->addInput(new Form_Input(
2220
	'adv_dhcp6_interface_statement_script',
2221
	'Scripts',
2222
	'text',
2223
	$pconfig['adv_dhcp6_interface_statement_script']
2224
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2225
			'[/[dirname/[.../]]filename[.ext]].');
2226

    
2227
$group = new Form_Group('Identity Association Statement');
2228

    
2229
$group->add(new Form_Checkbox(
2230
	'adv_dhcp6_id_assoc_statement_address_enable',
2231
	null,
2232
	'Non-Temporary Address Allocation',
2233
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2234
	'Selected'
2235
));
2236

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

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

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

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

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

    
2267
// Prefix delegation
2268
$group = new Form_Group('');
2269

    
2270
$group->add(new Form_Checkbox(
2271
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2272
	null,
2273
	'Prefix Delegation ',
2274
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2275
	'Selected'
2276
));
2277

    
2278
$group->add(new Form_Input(
2279
	'adv_dhcp6_id_assoc_statement_prefix_id',
2280
	null,
2281
	'text',
2282
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2283
))->sethelp('id-assoc pd ID');
2284

    
2285
$group->add(new Form_IpAddress(
2286
	'adv_dhcp6_id_assoc_statement_prefix',
2287
	null,
2288
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2289
	'V6'
2290
))->sethelp('IPv6 prefix');
2291

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

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

    
2306
$section->add($group);
2307

    
2308
$group = new Form_Group('Prefix interface statement');
2309

    
2310
$group->add(new Form_Input(
2311
	'adv_dhcp6_prefix_interface_statement_sla_id',
2312
	null,
2313
	'text',
2314
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2315
))->sethelp('Prefix Interface sla-id');
2316

    
2317
$group->add(new Form_Input(
2318
	'adv_dhcp6_prefix_interface_statement_sla_len',
2319
	null,
2320
	'text',
2321
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2322
))->sethelp('sla-len');
2323

    
2324
$section->add($group);
2325

    
2326
$group = new Form_Group('Authentication statement');
2327

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

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

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

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

    
2356
$section->add($group);
2357

    
2358
$group = new Form_Group('Keyinfo statement');
2359

    
2360
$group->add(new Form_Input(
2361
	'adv_dhcp6_key_info_statement_keyname',
2362
	null,
2363
	'text',
2364
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2365
))->sethelp('Keyname');
2366

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

    
2374
$section->add($group);
2375

    
2376
$group = new Form_Group('');
2377

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

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

    
2392
$group->add(new Form_Input(
2393
	'adv_dhcp6_key_info_statement_expire',
2394
	null,
2395
	'text',
2396
	$pconfig['adv_dhcp6_key_info_statement_expire']
2397
))->sethelp('Expire');
2398

    
2399
$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>');
2400

    
2401
$section->add($group);
2402

    
2403
$form->add($section);
2404

    
2405
$section = new Form_Section('6RD Configuration');
2406
$section->addClass('_6rd');
2407

    
2408
$section->addInput(new Form_Input(
2409
	'prefix-6rd',
2410
	'6RD Prefix',
2411
	'text',
2412
	$pconfig['prefix-6rd']
2413
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2414

    
2415
$section->addInput(new Form_Input(
2416
	'gateway-6rd',
2417
	'6RD Border relay',
2418
	'text',
2419
	$pconfig['gateway-6rd']
2420
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2421

    
2422
$section->addInput(new Form_Select(
2423
	'prefix-6rd-v4plen',
2424
	'6RD IPv4 Prefix length',
2425
	$pconfig['prefix-6rd-v4plen'],
2426
	array_combine(range(0, 32), range(0, 32))
2427
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2428

    
2429
$form->add($section);
2430

    
2431
// Track IPv6 ointerface section
2432
$section = new Form_Section('Track IPv6 Interface');
2433
$section->addClass('track6');
2434

    
2435
function build_ipv6interface_list() {
2436
	global $config, $section;
2437

    
2438
	$list = array('' => '');
2439

    
2440
	$interfaces = get_configured_interface_with_descr(false, true);
2441
	$dynv6ifs = array();
2442

    
2443
	foreach ($interfaces as $iface => $ifacename) {
2444
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2445
			case "6to4":
2446
			case "6rd":
2447
			case "dhcp6":
2448
				$dynv6ifs[$iface] = array(
2449
					'name' => $ifacename,
2450
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2451
				);
2452
				break;
2453
			default:
2454
				continue;
2455
		}
2456
	}
2457

    
2458
	foreach ($dynv6ifs as $iface => $ifacedata) {
2459
		$list[$iface] = $ifacedata['name'];
2460

    
2461
		$section->addInput(new Form_Input(
2462
			'ipv6-num-prefix-ids-' . $iface,
2463
			null,
2464
			'hidden',
2465
			$ifacedata['ipv6_num_prefix_ids']
2466
		));
2467
	}
2468

    
2469
	return($list);
2470
}
2471

    
2472
$section->addInput(new Form_Select(
2473
	'track6-interface',
2474
	'IPv6 Interface',
2475
	$pconfig['track6-interface'],
2476
	build_ipv6interface_list()
2477
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2478

    
2479
if ($pconfig['track6-prefix-id'] == "") {
2480
	$pconfig['track6-prefix-id'] = 0;
2481
}
2482

    
2483
$section->addInput(new Form_Input(
2484
	'track6-prefix-id--hex',
2485
	'IPv6 Prefix ID',
2486
	'text',
2487
	sprintf("%x", $pconfig['track6-prefix-id'])
2488
))->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.');
2489

    
2490
$section->addInput(new Form_Input(
2491
	'track6-prefix-id-max',
2492
	null,
2493
	'hidden',
2494
	0
2495
));
2496

    
2497
$form->add($section);
2498

    
2499
/// PPP section
2500

    
2501
$section = new Form_Section('PPP Configuration');
2502
$section->addClass('ppp');
2503

    
2504
$section->addInput(new Form_Select(
2505
	'country',
2506
	'Country',
2507
	$pconfig['country'],
2508
	[]
2509
));
2510

    
2511
$section->addInput(new Form_Select(
2512
	'provider_list',
2513
	'Provider',
2514
	$pconfig['provider_list'],
2515
	[]
2516
));
2517

    
2518
$section->addInput(new Form_Select(
2519
	'providerplan',
2520
	'Plan',
2521
	$pconfig['providerplan'],
2522
	[]
2523
))->setHelp('Select to fill in service provider data.');
2524

    
2525
$section->addInput(new Form_Input(
2526
	'ppp_username',
2527
	'Username',
2528
	'text',
2529
	$pconfig['ppp_username']
2530
));
2531

    
2532
$section->addPassword(new Form_Input(
2533
	'ppp_password',
2534
	'Password',
2535
	'password',
2536
	$pconfig['ppp_password']
2537
));
2538

    
2539
$section->addInput(new Form_Input(
2540
	'phone',
2541
	'Phone number',
2542
	'text',
2543
	$pconfig['phone']
2544
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2545

    
2546
$section->addInput(new Form_Input(
2547
	'apn',
2548
	'Access Point Name',
2549
	'text',
2550
	$pconfig['apn']
2551
));
2552

    
2553

    
2554
function build_port_list() {
2555
	$list = array("" => "None");
2556

    
2557
	$portlist = glob("/dev/cua*");
2558
	$modems	  = glob("/dev/modem*");
2559
	$portlist = array_merge($portlist, $modems);
2560

    
2561
	foreach ($portlist as $port) {
2562
		if (preg_match("/\.(lock|init)$/", $port)) {
2563
			continue;
2564
		}
2565

    
2566
	$list[trim($port)] = $port;
2567
	}
2568

    
2569
	return($list);
2570
}
2571

    
2572
$section->addInput(new Form_Select(
2573
	'port',
2574
	"Modem port",
2575
	$pconfig['port'],
2576
	build_port_list()
2577
));
2578

    
2579
$section->addInput(new Form_Button(
2580
	'btnadvppp',
2581
	'Advanced PPP',
2582
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2583
	'fa-cog'
2584
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2585

    
2586
$form->add($section);
2587

    
2588
// PPPoE configuration
2589
$section = new Form_Section('PPPoE Configuration');
2590
$section->addClass('pppoe');
2591

    
2592
$section->addInput(new Form_Input(
2593
	'pppoe_username',
2594
	'Username',
2595
	'text',
2596
	$pconfig['pppoe_username']
2597
));
2598

    
2599
$section->addPassword(new Form_Input(
2600
	'pppoe_password',
2601
	'Password',
2602
	'password',
2603
	$pconfig['pppoe_password']
2604
));
2605

    
2606
$section->addInput(new Form_Input(
2607
	'provider',
2608
	'Service name',
2609
	'text',
2610
	$pconfig['provider']
2611
))->setHelp('This field can usually be left empty.');
2612

    
2613
$section->addInput(new Form_Checkbox(
2614
	'pppoe_dialondemand',
2615
	'Dial on demand',
2616
	'Enable Dial-On-Demand mode ',
2617
	$pconfig['pppoe_dialondemand'],
2618
	'enable'
2619
));
2620

    
2621
$section->addInput(new Form_Input(
2622
	'pppoe_idletimeout',
2623
	'Idle timeout',
2624
	'number',
2625
	$pconfig['pppoe_idletimeout'],
2626
	['min' => 0]
2627
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2628
			'An idle timeout of zero disables this feature.');
2629

    
2630
$section->addInput(new Form_Select(
2631
	'pppoe-reset-type',
2632
	'Periodic reset',
2633
	$pconfig['pppoe-reset-type'],
2634
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2635
))->setHelp('Select a reset timing type.');
2636

    
2637
$group = new Form_Group('Custom reset');
2638
$group->addClass('pppoecustom');
2639

    
2640
$group->add(new Form_Input(
2641
	'pppoe_resethour',
2642
	null,
2643
	'number',
2644
	$pconfig['pppoe_resethour'],
2645
	['min' => 0, 'max' => 23]
2646
))->setHelp('Hour (0-23)');
2647

    
2648
$group->add(new Form_Input(
2649
	'pppoe_resetminute',
2650
	null,
2651
	'number',
2652
	$pconfig['pppoe_resetminute'],
2653
	['min' => 0, 'max' => 59]
2654
))->setHelp('Minutes (0-59)');
2655

    
2656
$group->add(new Form_Input(
2657
	'pppoe_resetdate',
2658
	null,
2659
	'text',
2660
	$pconfig['pppoe_resetdate']
2661
))->setHelp('Specific date (mm/dd/yyyy)');
2662

    
2663
$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');
2664

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

    
2667
$group = new Form_MultiCheckboxGroup('cron based reset');
2668
$group->addClass('pppoepreset');
2669

    
2670
$group->add(new Form_MultiCheckbox(
2671
	'pppoe_pr_preset_val',
2672
	null,
2673
	'Reset at each month ("0 0 1 * *")',
2674
	$pconfig['pppoe_monthly'],
2675
	'monthly'
2676
))->displayAsRadio();
2677

    
2678
$group->add(new Form_MultiCheckbox(
2679
	'pppoe_pr_preset_val',
2680
	null,
2681
	'Reset at each week ("0 0 * * 0")',
2682
	$pconfig['pppoe_weekly'],
2683
	'weekly'
2684
))->displayAsRadio();
2685

    
2686
$group->add(new Form_MultiCheckbox(
2687
	'pppoe_pr_preset_val',
2688
	null,
2689
	'Reset at each day ("0 0 * * *")',
2690
	$pconfig['pppoe_daily'],
2691
	'daily'
2692
))->displayAsRadio();
2693

    
2694
$group->add(new Form_MultiCheckbox(
2695
	'pppoe_pr_preset_val',
2696
	null,
2697
	'Reset at each hour ("0 * * * *")',
2698
	$pconfig['pppoe_hourly'],
2699
	'hourly'
2700
))->displayAsRadio();
2701

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

    
2704
$section->addInput(new Form_Button(
2705
	'btnadvppp',
2706
	'Advanced and MLPPP',
2707
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2708
	'fa-cog'
2709
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2710

    
2711
$form->add($section);
2712

    
2713
// PPTP & L2TP Configuration section
2714
$section = new Form_Section('PPTP/L2TP Configuration');
2715
$section->addClass('pptp');
2716

    
2717
$section->addInput(new Form_Input(
2718
	'pptp_username',
2719
	'Username',
2720
	'text',
2721
	$pconfig['pptp_username']
2722
));
2723

    
2724
$section->addPassword(new Form_Input(
2725
	'pptp_password',
2726
	'Password',
2727
	'password',
2728
	$pconfig['pptp_password']
2729
));
2730

    
2731
$section->addInput(new Form_IpAddress(
2732
	'pptp_local0',
2733
	'Local IP address',
2734
	$pconfig['pptp_localip'][0],
2735
	'V4'
2736
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2737

    
2738
$section->addInput(new Form_IpAddress(
2739
	'pptp_remote0',
2740
	'Remote IP address',
2741
	$pconfig['pptp_remote'][0],
2742
	'V4'
2743
));
2744

    
2745
$section->addInput(new Form_Checkbox(
2746
	'pptp_dialondemand',
2747
	'Dial on demand',
2748
	'Enable Dial-On-Demand mode ',
2749
	$pconfig['pptp_dialondemand'],
2750
	'enable'
2751
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2752
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2753

    
2754
$section->addInput(new Form_Input(
2755
	'pptp_idletimeout',
2756
	'Idle timeout (seconds)',
2757
	'number',
2758
	$pconfig['pptp_idletimeout'],
2759
	['min' => 0]
2760
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2761
			'An idle timeout of zero disables this feature.');
2762

    
2763
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2764
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2765
} else {
2766
	$mlppp_text = "";
2767
}
2768

    
2769
$section->addInput(new Form_Button(
2770
	'btnadvppp',
2771
	'Advanced and MLPPP',
2772
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2773
	'fa-cog'
2774
))->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.');
2775

    
2776
$form->add($section);
2777

    
2778
// Wireless interface
2779
if (isset($wancfg['wireless'])) {
2780

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

    
2783
	$section->addInput(new Form_Checkbox(
2784
		'persistcommonwireless',
2785
		'Persist common settings',
2786
		'Preserve common wireless configuration through interface deletions and reassignments.',
2787
		$pconfig['persistcommonwireless'],
2788
		'yes'
2789
	));
2790

    
2791
	$mode_list = ['auto' => 'Auto'];
2792

    
2793
	if (is_array($wl_modes)) {
2794
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2795
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2796
		}
2797
	}
2798

    
2799
	if (count($mode_list) == 1) {
2800
		$mode_list[''] = '';
2801
	}
2802

    
2803
	$section->addInput(new Form_Select(
2804
		'standard',
2805
		'Standard',
2806
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2807
		$mode_list
2808
	));
2809

    
2810
	if (isset($wl_modes['11g'])) {
2811
		$section->addInput(new Form_Select(
2812
			'protmode',
2813
			'802.11g OFDM Protection Mode',
2814
			$pconfig['protmode'],
2815
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2816
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2817
	} else {
2818
		$section->addInput(new Form_Input(
2819
			'protmode',
2820
			null,
2821
			'hidden',
2822
			'off'
2823
		));
2824
	}
2825

    
2826
	$mode_list = ['0' => gettext('Auto')];
2827

    
2828
	if (is_array($wl_modes)) {
2829
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2830
			if ($wl_standard == "11g") {
2831
				$wl_standard = "11b/g";
2832
			} else if ($wl_standard == "11ng") {
2833
				$wl_standard = "11b/g/n";
2834
			} else if ($wl_standard == "11na") {
2835
				$wl_standard = "11a/n";
2836
			}
2837

    
2838
			foreach ($wl_channels as $wl_channel) {
2839
				if (isset($wl_chaninfo[$wl_channel])) {
2840
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2841
				} else {
2842
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2843
				}
2844
			}
2845
		}
2846
	}
2847

    
2848
	$section->addInput(new Form_Select(
2849
		'channel',
2850
		'Channel',
2851
		$pconfig['channel'],
2852
		$mode_list
2853
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2854
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2855

    
2856
	if (ANTENNAS) {
2857
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2858
			$group = new Form_Group('Antenna Settings');
2859

    
2860
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2861
				$group->add(new Form_Select(
2862
					'diversity',
2863
					null,
2864
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2865
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2866
				))->setHelp('Diversity');
2867
			}
2868

    
2869
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2870
				$group->add(new Form_Select(
2871
					'txantenna',
2872
					null,
2873
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2874
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2875
				))->setHelp('Transmit antenna');
2876
			}
2877

    
2878
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2879
				$group->add(new Form_Select(
2880
					'rxantenna',
2881
					null,
2882
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2883
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2884
				))->setHelp('Receive antenna');
2885
			}
2886

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

    
2889
			$section->add($group);
2890
		}
2891
	}
2892

    
2893
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2894
			$section->addInput(new Form_Input(
2895
				'distance',
2896
				'Distance setting (meters)',
2897
				'test',
2898
				$pconfig['distance']
2899
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2900
	}
2901

    
2902
	$form->add($section);
2903

    
2904
	// Regulatory settings
2905
	$section = new Form_Section('Regulatory Settings');
2906

    
2907
	$domain_list = array("" => 'Default');
2908

    
2909
	if (is_array($wl_regdomains)) {
2910
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2911
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2912
		}
2913
	}
2914

    
2915
	$section->addInput(new Form_Select(
2916
		'regdomain',
2917
		'Regulatory domain',
2918
		$pconfig['regdomain'],
2919
		$domain_list
2920
	))->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');
2921

    
2922
	$country_list = array('' => 'Default');
2923

    
2924
	if (is_array($wl_countries)) {
2925
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2926
			$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']);
2927
		}
2928
	}
2929

    
2930
	$section->addInput(new Form_Select(
2931
		'regcountry',
2932
		'Country',
2933
		$pconfig['regcountry'],
2934
		$country_list
2935
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2936

    
2937
	$section->addInput(new Form_Select(
2938
		'reglocation',
2939
		'Location',
2940
		$pconfig['reglocation'],
2941
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
2942
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2943
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2944
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2945
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2946
				'These settings may not be able to add additional channels that are not already supported.');
2947

    
2948
	$form->add($section);
2949

    
2950
	$section = new Form_Section('Network-Specific Wireless Configuration');
2951

    
2952
	$section->addInput(new Form_Select(
2953
		'mode',
2954
		'Mode',
2955
		$pconfig['mode'],
2956
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2957
	));
2958

    
2959
	$section->addInput(new Form_Input(
2960
		'ssid',
2961
		'SSID',
2962
		'text',
2963
		$pconfig['ssid']
2964
	));
2965

    
2966
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2967
		$section->addInput(new Form_Select(
2968
			'puremode',
2969
			'Minimum wireless standard',
2970
			$pconfig['puremode'],
2971
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2972
		))->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)');
2973
	} elseif (isset($wl_modes['11g'])) {
2974
		$section->addInput(new Form_Checkbox(
2975
			'puremode',
2976
			'802.11g only',
2977
			null,
2978
			$pconfig['puremode'],
2979
			'11g'
2980
		))->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)');
2981
	}
2982

    
2983
	$section->addInput(new Form_Checkbox(
2984
		'apbridge_enable',
2985
		'Allow intra-BSS communication',
2986
		'Allow packets to pass between wireless clients directly when operating as an access point',
2987
		$pconfig['apbridge_enable'],
2988
		'yes'
2989
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2990

    
2991
	$section->addInput(new Form_Checkbox(
2992
		'wme_enable',
2993
		'Enable WME',
2994
		'Force the card to use WME (wireless QoS)',
2995
		$pconfig['wme_enable'],
2996
		'yes'
2997
	));
2998

    
2999
	$section->addInput(new Form_Checkbox(
3000
		'hidessid_enable',
3001
		'Hide SSID',
3002
		'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.)',
3003
		$pconfig['hidessid_enable'],
3004
		'yes'
3005
	));
3006

    
3007
	$form->add($section);
3008

    
3009
	// WPA Section
3010
	$section = new Form_Section('WPA');
3011

    
3012
	$section->addInput(new Form_Checkbox(
3013
		'wpa_enable',
3014
		'Enable',
3015
		'Enable WPA',
3016
		$pconfig['wpa_enable'],
3017
		'yes'
3018
	));
3019

    
3020
	$section->addInput(new Form_Input(
3021
		'passphrase',
3022
		'WPA Pre-Shared Key',
3023
		'text',
3024
		$pconfig['passphrase']
3025
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3026

    
3027
	$section->addInput(new Form_Select(
3028
		'wpa_mode',
3029
		'WPA mode',
3030
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3031
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3032
	));
3033

    
3034
	$section->addInput(new Form_Select(
3035
		'wpa_key_mgmt',
3036
		'WPA Key Management Mode',
3037
		$pconfig['wpa_key_mgmt'],
3038
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3039
	));
3040

    
3041
	$section->addInput(new Form_Select(
3042
		'wpa_pairwise',
3043
		'WPA Pairwise',
3044
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3045
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3046
	));
3047

    
3048
	$section->addInput(new Form_Input(
3049
		'wpa_group_rekey',
3050
		'Group Key Rotation',
3051
		'number',
3052
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3053
		['min' => '1', 'max' => 9999]
3054
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3055

    
3056
	$section->addInput(new Form_Input(
3057
		'wpa_gmk_rekey',
3058
		'Group Master Key Regeneration',
3059
		'number',
3060
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3061
		['min' => '1', 'max' => 9999]
3062
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3063

    
3064
	$section->addInput(new Form_Checkbox(
3065
		'wpa_strict_rekey',
3066
		'Strict Key Regeneration',
3067
		'Force the AP to rekey whenever a client disassociates',
3068
		$pconfig['wpa_strict_rekey'],
3069
		'yes'
3070
	));
3071

    
3072
	$form->add($section);
3073

    
3074
	$section = new Form_Section('802.1x RADIUS Options');
3075

    
3076
	$section->addInput(new Form_Checkbox(
3077
		'ieee8021x',
3078
		'IEEE802.1X',
3079
		'Enable 802.1X authentication',
3080
		$pconfig['ieee8021x'],
3081
		'yes'
3082
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3083

    
3084
	$group = new Form_Group('Primary 802.1X server');
3085

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

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

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

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

    
3108
	$group = new Form_Group('Secondary 802.1X server');
3109

    
3110
	$group->add(new Form_IpAddress(
3111
		'auth_server_addr2',
3112
		'IP Address',
3113
		$pconfig['auth_server_addr2']
3114
	))->setHelp('IP address of the RADIUS server');
3115

    
3116
	$group->add(new Form_Input(
3117
		'auth_server_port2',
3118
		'Port',
3119
		'number',
3120
		$pconfig['auth_server_port2']
3121
	))->setHelp('Server auth port. Default is 1812');
3122

    
3123
	$group->add(new Form_Input(
3124
		'auth_server_shared_secret2',
3125
		'Shared Secret',
3126
		'text',
3127
		$pconfig['auth_server_shared_secret2']
3128
	))->setHelp('RADIUS Shared secret for this firewall');
3129

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

    
3132
	$section->addInput(new Form_Checkbox(
3133
		'rsn_preauth',
3134
		'Authentication Roaming Preauth',
3135
		null,
3136
		$pconfig['rsn_preauth'],
3137
		'yes'
3138
	));
3139

    
3140
	$form->add($section);
3141
}
3142

    
3143
$section = new Form_Section('Reserved Networks');
3144

    
3145
$section->addInput(new Form_Checkbox(
3146
	'blockpriv',
3147
	'Block private networks and loopback addresses',
3148
	'',
3149
	$pconfig['blockpriv'],
3150
	'yes'
3151
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3152
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3153
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3154

    
3155
$section->addInput(new Form_Checkbox(
3156
	'blockbogons',
3157
	'Block bogon networks',
3158
	'',
3159
	$pconfig['blockbogons'],
3160
	'yes'
3161
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3162
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.' . '<br />' .
3163
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.');
3164

    
3165
$form->add($section);
3166

    
3167
$form->addGlobal(new Form_Input(
3168
	'if',
3169
	null,
3170
	'hidden',
3171
	$if
3172
));
3173

    
3174
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3175
	$form->addGlobal(new Form_Input(
3176
		'ppp_port',
3177
		null,
3178
		'hidden',
3179
		$pconfig['port']
3180
	));
3181
}
3182

    
3183
$form->addGlobal(new Form_Input(
3184
	'ptpid',
3185
	null,
3186
	'hidden',
3187
	$pconfig['ptpid']
3188
));
3189

    
3190

    
3191
// Add new gateway modal pop-up
3192
$modal = new Modal('New Gateway', 'newgateway', 'large');
3193

    
3194
$modal->addInput(new Form_Checkbox(
3195
	'defaultgw',
3196
	'Default',
3197
	'Default gateway',
3198
	($if == "wan" || $if == "WAN")
3199
));
3200

    
3201
$modal->addInput(new Form_Input(
3202
	'name',
3203
	'Gateway name',
3204
	'text',
3205
	$wancfg['descr'] . "GW"
3206
));
3207

    
3208
$modal->addInput(new Form_IpAddress(
3209
	'gatewayip',
3210
	'Gateway IPv4',
3211
	null,
3212
	'V4'
3213
));
3214

    
3215
$modal->addInput(new Form_Input(
3216
	'gatewaydescr',
3217
	'Description',
3218
	'text'
3219
));
3220

    
3221
$btnaddgw = new Form_Button(
3222
	'add',
3223
	'Add',
3224
	null,
3225
	'fa-plus'
3226
);
3227

    
3228
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3229

    
3230
$btncnxgw = new Form_Button(
3231
	'cnx',
3232
	'Cancel',
3233
	null,
3234
	'fa-undo'
3235
);
3236

    
3237
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3238

    
3239
$modal->addInput(new Form_StaticText(
3240
	null,
3241
	$btnaddgw . $btncnxgw
3242
));
3243

    
3244
$form->add($modal);
3245

    
3246
print($form);
3247
?>
3248

    
3249
<script type="text/javascript">
3250
//<![CDATA[
3251
events.push(function() {
3252
	function updateType(t) {
3253

    
3254
		switch (t) {
3255
			case "none": {
3256
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3257
				break;
3258
			}
3259
			case "staticv4": {
3260
				$('.dhcpadvanced, .none, .dhcp').hide();
3261
				$('.pppoe, .pptp, .ppp').hide();
3262
				break;
3263
			}
3264
			case "dhcp": {
3265
				$('.dhcpadvanced, .none').hide();
3266
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3267
										//			about the staticv4 class
3268
				$('.pppoe, .pptp, .ppp').hide();
3269
				break;
3270
			}
3271
			case "ppp": {
3272
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3273
				country_list();
3274
				break;
3275
			}
3276
			case "pppoe": {
3277
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3278
				break;
3279
			}
3280
			case "l2tp":
3281
			case "pptp": {
3282
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3283
				$('.pptp').show();
3284
				break;
3285
			}
3286
		}
3287

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

    
3293
	function updateTypeSix(t) {
3294
		if (!isNaN(t[0])) {
3295
			t = '_' + t;
3296
		}
3297

    
3298
		switch (t) {
3299
			case "none": {
3300
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3301
				break;
3302
			}
3303
			case "staticv6": {
3304
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3305
				break;
3306
			}
3307
			case "slaac": {
3308
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3309
				break;
3310
			}
3311
			case "dhcp6": {
3312
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3313
				break;
3314
			}
3315
			case "_6rd": {
3316
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3317
				break;
3318
			}
3319
			case "_6to4": {
3320
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3321
				break;
3322
			}
3323
			case "track6": {
3324
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3325
				update_track6_prefix();
3326
				break;
3327
			}
3328
		}
3329

    
3330
		if (t != "l2tp" && t != "pptp") {
3331
			$('.'+t).show();
3332
		}
3333
	}
3334

    
3335
	function show_reset_settings(reset_type) {
3336
		if (reset_type == 'preset') {
3337
			$('.pppoepreset').show();
3338
			$('.pppoecustom').hide();
3339
		} else if (reset_type == 'custom') {
3340
			$('.pppoecustom').show();
3341
			$('.pppoepreset').hide();
3342
		} else {
3343
			$('.pppoecustom').hide();
3344
			$('.pppoepreset').hide();
3345
		}
3346
	}
3347

    
3348
	function update_track6_prefix() {
3349
		var iface = $("#track6-interface").val();
3350
		if (iface == null) {
3351
			return;
3352
		}
3353

    
3354
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3355
		if (track6_prefix_ids == null) {
3356
			return;
3357
		}
3358

    
3359
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3360
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3361
	}
3362

    
3363
	// Create the new gateway from the data entered in the modal pop-up
3364
	function hide_add_gatewaysave() {
3365
		var iface = $('#if').val();
3366
		name = $('#name').val();
3367
		var descr = $('#gatewaydescr').val();
3368
		gatewayip = $('#gatewayip').val();
3369

    
3370
		var defaultgw = '';
3371
		if ($('#defaultgw').is(':checked')) {
3372
			defaultgw = '&defaultgw=on';
3373
		}
3374

    
3375
		var url = "system_gateways_edit.php";
3376
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3377
		$.ajax(
3378
			url,
3379
			{
3380
				type: 'post',
3381
				data: pars,
3382
				error: report_failure,
3383
				complete: save_callback
3384
			});
3385
		}
3386

    
3387
	function save_callback(response) {
3388
		if (response) {
3389
			var gwtext = escape(name) + " - " + gatewayip;
3390
			addOption($('#gateway'), gwtext, name);
3391
		} else {
3392
			report_failure();
3393
		}
3394

    
3395
		$("#newgateway").modal('hide');
3396
	}
3397

    
3398
	function report_failure(request, textStatus, errorThrown) {
3399
		contenttype = ";"+request.getResponseHeader("Content-Type")+";";
3400
		if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
3401
			alert(request.responseText);
3402
		} else {
3403
			alert("The IPv4 gateway could not be created.");
3404
		}
3405

    
3406
		$("#newgateway").modal('hide');
3407
	}
3408

    
3409
	function addOption(selectbox, text, value) {
3410
		var optn = document.createElement("OPTION");
3411
		optn.text = text;
3412
		optn.value = value;
3413
		selectbox.append(optn);
3414
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3415
	}
3416

    
3417
	function hide_add_gatewaysave_v6() {
3418

    
3419
		var iface = $('#if').val();
3420
		name = $('#name6').val();
3421
		var descr = $('#gatewaydescr6').val();
3422
		gatewayip = $('#gatewayip6').val();
3423
		var defaultgw = '';
3424
		if ($('#defaultgw6').is(':checked')) {
3425
			defaultgw = '&defaultgw=on';
3426
		}
3427
		var url_v6 = "system_gateways_edit.php";
3428
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3429
		$.ajax(
3430
			url_v6,
3431
			{
3432
				type: 'post',
3433
				data: pars_v6,
3434
				error: report_failure_v6,
3435
				success: save_callback_v6
3436
			});
3437
	}
3438

    
3439

    
3440
	function addOption_v6(selectbox, text, value) {
3441
		var optn = document.createElement("OPTION");
3442
		optn.text = text;
3443
		optn.value = value;
3444
		selectbox.append(optn);
3445
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3446
	}
3447

    
3448
	function report_failure_v6(request, textStatus, errorThrown) {
3449
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3450
			alert(request.responseText);
3451
		} else {
3452
			alert("The IPv6 gateway could not be created.");
3453
		}
3454

    
3455
		$("#newgateway6").modal('hide');
3456
	}
3457

    
3458
	function save_callback_v6(response_v6) {
3459
		if (response_v6) {
3460

    
3461
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3462
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3463
		} else {
3464
			report_failure_v6();
3465
		}
3466

    
3467
		$("#newgateway6").modal('hide');
3468
	}
3469

    
3470
	function country_list() {
3471
		$('#country').children().remove();
3472
		$('#provider_list').children().remove();
3473
		$('#providerplan').children().remove();
3474
		$.ajax("getserviceproviders.php",{
3475
			success: function(response) {
3476

    
3477
				var responseTextArr = response.split("\n");
3478
				responseTextArr.sort();
3479

    
3480
				responseTextArr.forEach( function(value) {
3481
					country = value.split(":");
3482
					$('#country').append($('<option>', {
3483
						value: country[1],
3484
						text : country[0]
3485
					}));
3486
				});
3487
			}
3488
		});
3489
	}
3490

    
3491
	function providers_list() {
3492
		$('#provider_list').children().remove();
3493
		$('#providerplan').children().remove();
3494
		$.ajax("getserviceproviders.php",{
3495
			type: 'post',
3496
			data: {country : $('#country').val()},
3497
			success: function(response) {
3498
				var responseTextArr = response.split("\n");
3499
				responseTextArr.sort();
3500
				responseTextArr.forEach( function(value) {
3501
					$('#provider_list').append($('<option>', {
3502
							value: value,
3503
							text : value
3504
					}));
3505
				});
3506
			}
3507
		});
3508
	}
3509

    
3510
	function providerplan_list() {
3511
		$('#providerplan').children().remove();
3512
		$.ajax("getserviceproviders.php",{
3513
			type: 'post',
3514
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3515
			success: function(response) {
3516
				var responseTextArr = response.split("\n");
3517
				responseTextArr.sort();
3518

    
3519
				$('#providerplan').append($('<option>', {
3520
					value: '',
3521
					text : ''
3522
				}));
3523

    
3524
				responseTextArr.forEach( function(value) {
3525
					if (value != "") {
3526
						providerplan = value.split(":");
3527

    
3528
						$('#providerplan').append($('<option>', {
3529
							value: providerplan[1],
3530
							text : providerplan[0] + " - " + providerplan[1]
3531
						}));
3532
					}
3533
				});
3534
			}
3535
		});
3536
	}
3537

    
3538
	function prefill_provider() {
3539
		$.ajax("getserviceproviders.php",{
3540
			type: 'post',
3541
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3542
			success: function(data, textStatus, response) {
3543
				var xmldoc = response.responseXML;
3544
				var provider = xmldoc.getElementsByTagName('connection')[0];
3545
				$('#ppp_username').val('');
3546
				$('#ppp_password').val('');
3547
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3548
					$('#phone').val('#777');
3549
					$('#apn').val('');
3550
				} else {
3551
					$('#phone').val('*99#');
3552
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3553
				}
3554
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3555
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3556
				$('#ppp_username').val(ppp_username);
3557
				$('#ppp_password').val(ppp_password);
3558
			}
3559
		});
3560
	}
3561

    
3562
	function show_dhcp6adv() {
3563
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3564
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3565

    
3566
		hideCheckbox('dhcp6usev4iface', ovr);
3567
		hideCheckbox('dhcp6prefixonly', ovr);
3568
		hideInput('dhcp6-ia-pd-len', ovr);
3569
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3570
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3571

    
3572
		hideClass('dhcp6advanced', !adv || ovr);
3573
	}
3574

    
3575
	function setDHCPoptions() {
3576
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3577
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3578

    
3579
		if (ovr) {
3580
			hideInput('dhcphostname', true);
3581
			hideIpAddress('alias-address', true);
3582
			hideInput('dhcprejectfrom', true);
3583
			hideInput('adv_dhcp_config_file_override_path', false);
3584
			hideClass('dhcpadvanced', true);
3585
		} else {
3586
			hideInput('dhcphostname', false);
3587
			hideIpAddress('alias-address', false);
3588
			hideInput('dhcprejectfrom', false);
3589
			hideInput('adv_dhcp_config_file_override_path', true);
3590
			hideClass('dhcpadvanced', !adv);
3591
		}
3592
	}
3593

    
3594
	// DHCP preset actions
3595
	// Set presets from value of radio buttons
3596
	function setPresets(val) {
3597
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3598
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3599
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3600
		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']);?>");
3601
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3602
	}
3603

    
3604
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3605
		$('#adv_dhcp_pt_timeout').val(timeout);
3606
		$('#adv_dhcp_pt_retry').val(retry);
3607
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3608
		$('#adv_dhcp_pt_reboot').val(reboot);
3609
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3610
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3611
	}
3612

    
3613
	// ---------- On initial page load ------------------------------------------------------------
3614

    
3615
	updateType($('#type').val());
3616
	updateTypeSix($('#type6').val());
3617
	show_reset_settings($('#pppoe-reset-type').val());
3618
	hideClass('dhcp6advanced', true);
3619
	hideClass('dhcpadvanced', true);
3620
	show_dhcp6adv();
3621
	setDHCPoptions()
3622

    
3623
	// Set preset buttons on page load
3624
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3625
	if (sv == "") {
3626
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3627
	} else {
3628
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3629
	}
3630

    
3631
	// Set preset from value
3632
	setPresets(sv);
3633

    
3634
	// ---------- Click checkbox handlers ---------------------------------------------------------
3635

    
3636
	$('#type').on('change', function() {
3637
		updateType(this.value);
3638
	});
3639

    
3640
	$('#type6').on('change', function() {
3641
		updateTypeSix(this.value);
3642
	});
3643

    
3644
	$('#track6-interface').on('change', function() {
3645
		update_track6_prefix();
3646
	});
3647

    
3648
	$('#pppoe-reset-type').on('change', function() {
3649
		show_reset_settings(this.value);
3650
	});
3651

    
3652
	$("#add").click(function() {
3653
		hide_add_gatewaysave();
3654
	});
3655

    
3656
	$("#cnx").click(function() {
3657
		$("#newgateway").modal('hide');
3658
	});
3659

    
3660
	$("#add6").click(function() {
3661
		hide_add_gatewaysave_v6();
3662
	});
3663

    
3664
	$("#cnx6").click(function() {
3665
		$("#newgateway6").modal('hide');
3666
	});
3667

    
3668
	$('#country').on('change', function() {
3669
		providers_list();
3670
	});
3671

    
3672
	$('#provider_list').on('change', function() {
3673
		providerplan_list();
3674
	});
3675

    
3676
	$('#providerplan').on('change', function() {
3677
		prefill_provider();
3678
	});
3679

    
3680
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3681
		setDHCPoptions();
3682
	});
3683

    
3684
	$('#adv_dhcp6_config_advanced').click(function () {
3685
		show_dhcp6adv();
3686
	});
3687

    
3688
	$('#adv_dhcp6_config_file_override').click(function () {
3689
		show_dhcp6adv();
3690
	});
3691

    
3692
	// On click . .
3693
	$('[name=adv_dhcp_pt_values]').click(function () {
3694
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3695
	});
3696

    
3697
	$('#pppoe_resetdate').datepicker();
3698

    
3699
});
3700
//]]>
3701
</script>
3702

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