Project

General

Profile

Download (126 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
$interfaces = get_configured_interface_with_descr();
125
$wancfg = &$config['interfaces'][$if];
126
$old_wancfg = $wancfg;
127
$old_wancfg['realif'] = get_real_interface($if);
128
$old_ppps = $a_ppps;
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
261
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
262
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
263
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
264

    
265
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
266
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
267
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
268
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
269

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

    
276
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
277
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
278
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
279

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

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

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

    
359
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
360
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
361
$pconfig['spoofmac'] = $wancfg['spoofmac'];
362
$pconfig['mtu'] = $wancfg['mtu'];
363
$pconfig['mss'] = $wancfg['mss'];
364

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

    
441
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
442

    
443
}
444

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

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

    
480
		/* sync filter configuration */
481
		setup_gateways_monitor();
482

    
483
		clear_subsystem_dirty('interfaces');
484

    
485
		filter_configure();
486

    
487
		enable_rrd_graphing();
488

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

    
498
	unset($input_errors);
499
	$pconfig = $_POST;
500

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

    
508
	/* filter out spaces from descriptions */
509
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
510

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
865
		unset($min_mtu, $max_mtu);
866

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

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

    
889
				if ($parent_realhwif != $wancfg['if']) {
890
					continue;
891
				}
892

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

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

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

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

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

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

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

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

    
1055
		unset($wancfg['adv_dhcp_pt_timeout']);
1056
		unset($wancfg['adv_dhcp_pt_retry']);
1057
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1058
		unset($wancfg['adv_dhcp_pt_reboot']);
1059
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1060
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1061

    
1062
		unset($wancfg['adv_dhcp_pt_values']);
1063

    
1064
		unset($wancfg['adv_dhcp_send_options']);
1065
		unset($wancfg['adv_dhcp_request_options']);
1066
		unset($wancfg['adv_dhcp_required_options']);
1067
		unset($wancfg['adv_dhcp_option_modifiers']);
1068

    
1069
		unset($wancfg['adv_dhcp_config_advanced']);
1070
		unset($wancfg['adv_dhcp_config_file_override']);
1071
		unset($wancfg['adv_dhcp_config_file_override_path']);
1072

    
1073
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1074
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1075
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1076
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1077

    
1078
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1079
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1080
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1081
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1082
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1083

    
1084
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1085
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1086
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1087
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1088
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1089

    
1090
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1091
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1092
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1093

    
1094
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1095
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1096
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1097
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1098

    
1099
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1100
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1101
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1102
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1103
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1104

    
1105
		unset($wancfg['adv_dhcp6_config_advanced']);
1106
		unset($wancfg['adv_dhcp6_config_file_override']);
1107
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1108

    
1109
		unset($wancfg['pppoe_password']);
1110
		unset($wancfg['pptp_username']);
1111
		unset($wancfg['pptp_password']);
1112
		unset($wancfg['provider']);
1113
		unset($wancfg['ondemand']);
1114
		unset($wancfg['timeout']);
1115
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1116
			unset($wancfg['pppoe']['pppoe-reset-type']);
1117
		}
1118
		unset($wancfg['local']);
1119

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

    
1141
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1142
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1143

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

    
1160
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1161
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1162
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1163
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1164
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1165
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1166

    
1167
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1168

    
1169
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1170
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1171
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1172
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1173

    
1174
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1175
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1176
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1177

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

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

    
1223
				if (!empty($_POST['pppoe-reset-type'])) {
1224
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1225
				} else {
1226
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1227
				}
1228
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1229
				$wancfg['ipaddr'] = $_POST['type'];
1230
				if ($gateway_item) {
1231
					$a_gateways[] = $gateway_item;
1232
				}
1233

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

    
1302
				if ($_POST['dhcp6withoutra'] == "yes") {
1303
					$wancfg['dhcp6withoutra'] = true;
1304
				}
1305
				if ($_POST['dhcp6norelease'] == "yes") {
1306
					$wancfg['dhcp6norelease'] = true;
1307
				}
1308
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1309
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1310
				}
1311
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1312
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1313
				}
1314
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1315
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1316
				}
1317
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1318
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1319
				}
1320

    
1321
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1322
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1323
				}
1324
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1325
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1326
				}
1327
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1328
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1329
				}
1330
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1331
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1332
				}
1333
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1334
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1335
				}
1336

    
1337
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1338
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1339
				}
1340
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1341
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1342
				}
1343
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1344
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1345
				}
1346
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1347
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1348
				}
1349
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1350
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1351
				}
1352

    
1353
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1354
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1355
				}
1356
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1357
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1358
				}
1359
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1360
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1361
				}
1362
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1363
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1364
				}
1365
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1366
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1367
				}
1368
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1369
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1370
				}
1371
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1372
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1373
				}
1374

    
1375
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1376
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1377
				}
1378
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1379
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1380
				}
1381
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1382
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1383
				}
1384
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1385
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1386
				}
1387
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1388
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1389
				}
1390

    
1391
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1392
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1395
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1396
				}
1397
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1398
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1399
				}
1400

    
1401
				if ($gateway_item) {
1402
					$a_gateways[] = $gateway_item;
1403
				}
1404
				break;
1405
			case "6rd":
1406
				$wancfg['ipaddrv6'] = "6rd";
1407
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1408
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1409
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1410
				if ($gateway_item) {
1411
					$a_gateways[] = $gateway_item;
1412
				}
1413
				break;
1414
			case "6to4":
1415
				$wancfg['ipaddrv6'] = "6to4";
1416
				break;
1417
			case "track6":
1418
				$wancfg['ipaddrv6'] = "track6";
1419
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1420
				if ($_POST['track6-prefix-id--hex'] === "") {
1421
					$wancfg['track6-prefix-id'] = 0;
1422
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1423
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1424
				} else {
1425
					$wancfg['track6-prefix-id'] = 0;
1426
				}
1427
				break;
1428
			case "none":
1429
				break;
1430
		}
1431
		handle_pppoe_reset($_POST);
1432

    
1433
		if ($_POST['blockpriv'] == "yes") {
1434
			$wancfg['blockpriv'] = true;
1435
		} else {
1436
			unset($wancfg['blockpriv']);
1437
		}
1438
		if ($_POST['blockbogons'] == "yes") {
1439
			$wancfg['blockbogons'] = true;
1440
		} else {
1441
			unset($wancfg['blockbogons']);
1442
		}
1443
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1444
		if (empty($_POST['mtu'])) {
1445
			unset($wancfg['mtu']);
1446
		} else {
1447
			$wancfg['mtu'] = $_POST['mtu'];
1448
		}
1449
		if (empty($_POST['mss'])) {
1450
			unset($wancfg['mss']);
1451
		} else {
1452
			$wancfg['mss'] = $_POST['mss'];
1453
		}
1454
		if (empty($_POST['mediaopt'])) {
1455
			unset($wancfg['media']);
1456
			unset($wancfg['mediaopt']);
1457
		} else {
1458
			$mediaopts = explode(' ', $_POST['mediaopt']);
1459
			if ($mediaopts[0] != '') {
1460
				$wancfg['media'] = $mediaopts[0];
1461
			}
1462
			if ($mediaopts[1] != '') {
1463
				$wancfg['mediaopt'] = $mediaopts[1];
1464
			} else {
1465
				unset($wancfg['mediaopt']);
1466
			}
1467
		}
1468
		if (isset($wancfg['wireless'])) {
1469
			handle_wireless_post();
1470
		}
1471

    
1472
		conf_mount_ro();
1473
		write_config();
1474

    
1475
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1476
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1477
		} else {
1478
			$toapplylist = array();
1479
		}
1480
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1481
		$toapplylist[$if]['ppps'] = $old_ppps;
1482
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1483

    
1484
		mark_subsystem_dirty('interfaces');
1485

    
1486
		/* regenerate cron settings/crontab file */
1487
		configure_cron();
1488

    
1489
		header("Location: interfaces.php?if={$if}");
1490
		exit;
1491
	}
1492

    
1493
} // end if ($_POST)
1494

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

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

    
1601
	if ($_POST['wme_enable'] == "yes") {
1602
		if (!is_array($wancfg['wireless']['wme'])) {
1603
			$wancfg['wireless']['wme'] = array();
1604
		}
1605
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1606
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1607
		unset($wancfg['wireless']['wme']['enable']);
1608
	}
1609
	if ($_POST['puremode'] == "11g") {
1610
		if (!is_array($wancfg['wireless']['pureg'])) {
1611
			$wancfg['wireless']['pureg'] = array();
1612
		}
1613
		$wancfg['wireless']['pureg']['enable'] = true;
1614
	} else if ($_POST['puremode'] == "11n") {
1615
		if (!is_array($wancfg['wireless']['puren'])) {
1616
			$wancfg['wireless']['puren'] = array();
1617
		}
1618
		$wancfg['wireless']['puren']['enable'] = true;
1619
	} else {
1620
		if (isset($wancfg['wireless']['pureg'])) {
1621
			unset($wancfg['wireless']['pureg']);
1622
		}
1623
		if (isset($wancfg['wireless']['puren'])) {
1624
			unset($wancfg['wireless']['puren']);
1625
		}
1626
	}
1627
	if ($_POST['apbridge_enable'] == "yes") {
1628
		if (!is_array($wancfg['wireless']['apbridge'])) {
1629
			$wancfg['wireless']['apbridge'] = array();
1630
		}
1631
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1632
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1633
		unset($wancfg['wireless']['apbridge']['enable']);
1634
	}
1635
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1636
		if (!is_array($wancfg['wireless']['turbo'])) {
1637
			$wancfg['wireless']['turbo'] = array();
1638
		}
1639
		$wancfg['wireless']['turbo']['enable'] = true;
1640
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1641
		unset($wancfg['wireless']['turbo']['enable']);
1642
	}
1643

    
1644
	interface_sync_wireless_clones($wancfg, true);
1645
}
1646

    
1647
function check_wireless_mode() {
1648
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1649

    
1650
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1651
		return;
1652
	}
1653

    
1654
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1655
		$clone_count = 1;
1656
	} else {
1657
		$clone_count = 0;
1658
	}
1659

    
1660
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1661
		foreach ($config['wireless']['clone'] as $clone) {
1662
			if ($clone['if'] == $wlanbaseif) {
1663
				$clone_count++;
1664
			}
1665
		}
1666
	}
1667

    
1668
	if ($clone_count > 1) {
1669
		$old_wireless_mode = $wancfg['wireless']['mode'];
1670
		$wancfg['wireless']['mode'] = $_POST['mode'];
1671
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1672
			$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']]);
1673
		} else {
1674
			pfSense_interface_destroy("{$wlanif}_");
1675
		}
1676
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1677
	}
1678
}
1679

    
1680
// Find all possible media options for the interface
1681
$mediaopts_list = array();
1682
$intrealname = $config['interfaces'][$if]['if'];
1683
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1684
foreach ($mediaopts as $mediaopt) {
1685
	preg_match("/media (.*)/", $mediaopt, $matches);
1686
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1687
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1688
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1689
	} else {
1690
		// there is only media like "media 1000baseT"
1691
		array_push($mediaopts_list, $matches[1]);
1692
	}
1693
}
1694

    
1695
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1696
$shortcut_section = "interfaces";
1697

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

    
1701
// Get the MAC address
1702
$ip = $_SERVER['REMOTE_ADDR'];
1703
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1704
$mymac = str_replace("\n", "", $mymac);
1705

    
1706
function build_mediaopts_list() {
1707
	global $mediaopts_list;
1708

    
1709
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1710
			 " " =>	 gettext("------- Media Supported by this interface -------")
1711
			];
1712

    
1713
	foreach ($mediaopts_list as $mediaopt) {
1714
		$list[$mediaopt] = $mediaopt;
1715
	}
1716

    
1717
	return($list);
1718
}
1719

    
1720
function build_gateway_list() {
1721
	global $a_gateways, $if;
1722

    
1723
	$list = array("none" => gettext("None"));
1724
	foreach ($a_gateways as $gateway) {
1725
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1726
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1727
		}
1728
	}
1729

    
1730
	return($list);
1731
}
1732

    
1733
function build_gatewayv6_list() {
1734
	global $a_gateways, $if;
1735

    
1736
	$list = array("none" => gettext("None"));
1737
	foreach ($a_gateways as $gateway) {
1738
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1739
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1740
		}
1741
	}
1742

    
1743
	return($list);
1744
}
1745

    
1746
include("head.inc");
1747

    
1748
if ($input_errors) {
1749
	print_input_errors($input_errors);
1750
}
1751

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

    
1758
if ($savemsg) {
1759
	print_info_box($savemsg, 'success');
1760
}
1761

    
1762

    
1763
$form = new Form();
1764

    
1765
$section = new Form_Section('General Configuration');
1766

    
1767
$section->addInput(new Form_Checkbox(
1768
	'enable',
1769
	'Enable',
1770
	'Enable interface',
1771
	$pconfig['enable'],
1772
	'yes'
1773
));
1774

    
1775
$section->addInput(new Form_Input(
1776
	'descr',
1777
	'*Description',
1778
	'text',
1779
	$pconfig['descr']
1780
))->setHelp('Enter a description (name) for the interface here.');
1781

    
1782
$section->addInput(new Form_Select(
1783
	'type',
1784
	'IPv4 Configuration Type',
1785
	$pconfig['type'],
1786
	$types4
1787
));
1788

    
1789
$section->addInput(new Form_Select(
1790
	'type6',
1791
	'IPv6 Configuration Type',
1792
	$pconfig['type6'],
1793
	$types6
1794
));
1795

    
1796
$macaddress = new Form_Input(
1797
	'spoofmac',
1798
	'MAC Address',
1799
	'text',
1800
	$pconfig['spoofmac'],
1801
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1802
);
1803

    
1804
$btnmymac = new Form_Button(
1805
	'btnmymac',
1806
	'Copy My MAC',
1807
	null,
1808
	'fa-clone'
1809
	);
1810

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

    
1813
$group = new Form_Group('MAC Address');
1814
$group->add($macaddress);
1815
// $group->add($btnmymac);
1816
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1817
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.');
1818
$section->add($group);
1819

    
1820
$section->addInput(new Form_Input(
1821
	'mtu',
1822
	'MTU',
1823
	'number',
1824
	$pconfig['mtu']
1825
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1826
			'This is typically 1500 bytes but can vary in some circumstances.');
1827

    
1828
$section->addInput(new Form_Input(
1829
	'mss',
1830
	'MSS',
1831
	'number',
1832
	$pconfig['mss']
1833
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1834
			'header size) will be in effect.');
1835

    
1836
if (count($mediaopts_list) > 0) {
1837
	$section->addInput(new Form_Select(
1838
		'mediaopt',
1839
		'Speed and Duplex',
1840
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1841
		build_mediaopts_list()
1842
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1843
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1844
}
1845

    
1846
$form->add($section);
1847

    
1848
$section = new Form_Section('Static IPv4 Configuration');
1849
$section->addClass('staticv4');
1850

    
1851
$section->addInput(new Form_IpAddress(
1852
	'ipaddr',
1853
	'*IPv4 Address',
1854
	$pconfig['ipaddr'],
1855
	'V4'
1856
))->addMask('subnet', $pconfig['subnet'], 32);
1857

    
1858
$group = new Form_Group('IPv4 Upstream gateway');
1859

    
1860
$group->add(new Form_Select(
1861
	'gateway',
1862
	'IPv4 Upstream Gateway',
1863
	$pconfig['gateway'],
1864
	build_gateway_list()
1865
));
1866

    
1867
$group->add(new Form_Button(
1868
	'addgw',
1869
	'Add a new gateway',
1870
	null,
1871
	'fa-plus'
1872
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1873

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

    
1878
$section->add($group);
1879

    
1880
$form->add($section);
1881

    
1882
$section = new Form_Section('Static IPv6 Configuration');
1883
$section->addClass('staticv6');
1884

    
1885
$section->addInput(new Form_IpAddress(
1886
	'ipaddrv6',
1887
	'*IPv6 address',
1888
	$pconfig['ipaddrv6'],
1889
	'V6'
1890
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1891

    
1892
$section->addInput(new Form_Checkbox(
1893
	'ipv6usev4iface',
1894
	'Use IPv4 connectivity as parent interface',
1895
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1896
	$pconfig['ipv6usev4iface']
1897
));
1898

    
1899
$group = new Form_Group('IPv6 Upstream gateway');
1900

    
1901
$group->add(new Form_Select(
1902
	'gatewayv6',
1903
	'IPv6 Upstream Gateway',
1904
	$pconfig['gatewayv6'],
1905
	build_gatewayv6_list()
1906
));
1907

    
1908
$group->add(new Form_Button(
1909
	'addgw6',
1910
	'Add a new gateway',
1911
	null,
1912
	'fa-plus'
1913
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1914

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

    
1918
$section->add($group);
1919
$form->add($section);
1920

    
1921
// Add new gateway modal pop-up for IPv6
1922
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1923

    
1924
$modal->addInput(new Form_Checkbox(
1925
	'defaultgw6',
1926
	'Default',
1927
	'Default gateway',
1928
	($if == "wan" || $if == "WAN")
1929
));
1930

    
1931
$modal->addInput(new Form_Input(
1932
	'name6',
1933
	'Gateway name',
1934
	'text',
1935
	$wancfg['descr'] . "GWv6"
1936
));
1937

    
1938
$modal->addInput(new Form_IpAddress(
1939
	'gatewayip6',
1940
	'Gateway IPv6',
1941
	null,
1942
	'V6'
1943
));
1944

    
1945
$modal->addInput(new Form_Input(
1946
	'gatewaydescr6',
1947
	'Description',
1948
	'text'
1949
));
1950

    
1951
$btnaddgw6 = new Form_Button(
1952
	'add6',
1953
	'Add',
1954
	null,
1955
	'fa-plus'
1956
);
1957

    
1958
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1959

    
1960
$btncnxgw6 = new Form_Button(
1961
	'cnx6',
1962
	'Cancel',
1963
	null,
1964
	'fa-undo'
1965
);
1966

    
1967
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1968

    
1969
$modal->addInput(new Form_StaticText(
1970
	null,
1971
	$btnaddgw6 . $btncnxgw6
1972
));
1973

    
1974
$form->add($modal);
1975

    
1976
// ==== DHCP client configuration =============================
1977

    
1978
$section = new Form_Section('DHCP Client Configuration');
1979
$section->addClass('dhcp');
1980

    
1981
$group = new Form_Group('Options');
1982

    
1983
$group->add(new Form_Checkbox(
1984
	'adv_dhcp_config_advanced',
1985
	null,
1986
	'Advanced Configuration',
1987
	$pconfig['adv_dhcp_config_advanced']
1988
))->setHelp('Use advanced DHCP configuration options.');
1989

    
1990
$group->add(new Form_Checkbox(
1991
	'adv_dhcp_config_file_override',
1992
	null,
1993
	'Configuration Override',
1994
	$pconfig['adv_dhcp_config_file_override']
1995
))->setHelp('Override the configuration from this file.');
1996

    
1997
$section->add($group);
1998

    
1999
$section->addInput(new Form_Input(
2000
	'dhcphostname',
2001
	'Hostname',
2002
	'text',
2003
	$pconfig['dhcphostname']
2004
))->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).');
2005

    
2006
$section->addInput(new Form_IpAddress(
2007
	'alias-address',
2008
	'Alias IPv4 address',
2009
	$pconfig['alias-address'],
2010
	'V4'
2011
))->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.');
2012

    
2013
$section->addInput(new Form_Input(
2014
	'dhcprejectfrom',
2015
	'Reject leases from',
2016
	'text',
2017
	$pconfig['dhcprejectfrom']
2018
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2019
			'(separate multiple entries with a comma). ' .
2020
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2021

    
2022
$group = new Form_Group('Protocol timing');
2023
$group->addClass('dhcpadvanced');
2024

    
2025
$group->add(new Form_Input(
2026
	'adv_dhcp_pt_timeout',
2027
	null,
2028
	'number',
2029
	$pconfig['adv_dhcp_pt_timeout']
2030
))->setHelp('Timeout');
2031

    
2032
$group->add(new Form_Input(
2033
	'adv_dhcp_pt_retry',
2034
	null,
2035
	'number',
2036
	$pconfig['adv_dhcp_pt_retry']
2037
))->setHelp('Retry');
2038

    
2039
$group->add(new Form_Input(
2040
	'adv_dhcp_pt_select_timeout',
2041
	null,
2042
	'number',
2043
	$pconfig['adv_dhcp_pt_select_timeout'],
2044
	['min' => 0]
2045
))->setHelp('Select timeout');
2046

    
2047
$group->add(new Form_Input(
2048
	'adv_dhcp_pt_reboot',
2049
	null,
2050
	'number',
2051
	$pconfig['adv_dhcp_pt_reboot']
2052
))->setHelp('Reboot');
2053

    
2054
$group->add(new Form_Input(
2055
	'adv_dhcp_pt_backoff_cutoff',
2056
	null,
2057
	'number',
2058
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2059
))->setHelp('Backoff cutoff');
2060

    
2061
$group->add(new Form_Input(
2062
	'adv_dhcp_pt_initial_interval',
2063
	null,
2064
	'number',
2065
	$pconfig['adv_dhcp_pt_initial_interval']
2066
))->setHelp('Initial interval');
2067

    
2068
$section->add($group);
2069

    
2070
$group = new Form_Group('Presets');
2071
$group->addClass('dhcpadvanced');
2072

    
2073
$group->add(new Form_Checkbox(
2074
	'adv_dhcp_pt_values',
2075
	null,
2076
	'FreeBSD default',
2077
	null,
2078
	'DHCP'
2079
))->displayAsRadio();
2080

    
2081
$group->add(new Form_Checkbox(
2082
	'adv_dhcp_pt_values',
2083
	null,
2084
	'Clear',
2085
	null,
2086
	'Clear'
2087
))->displayAsRadio();
2088

    
2089
$group->add(new Form_Checkbox(
2090
	'adv_dhcp_pt_values',
2091
	null,
2092
	'pfSense Default',
2093
	null,
2094
	'pfSense'
2095
))->displayAsRadio();
2096

    
2097
$group->add(new Form_Checkbox(
2098
	'adv_dhcp_pt_values',
2099
	null,
2100
	'Saved Cfg',
2101
	null,
2102
	'SavedCfg'
2103
))->displayAsRadio();
2104

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

    
2108
$section->add($group);
2109

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

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

    
2122
$section = new Form_Section('Lease Requirements and Requests');
2123
$section->addClass('dhcpadvanced');
2124

    
2125
$section->addInput(new Form_Input(
2126
	'adv_dhcp_send_options',
2127
	'Send options',
2128
	'text',
2129
	$pconfig['adv_dhcp_send_options']
2130
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2131
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2132
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2133
			'Some ISPs may require certain options be or not be sent.');
2134

    
2135
$section->addInput(new Form_Input(
2136
	'adv_dhcp_request_options',
2137
	'Request options',
2138
	'text',
2139
	$pconfig['adv_dhcp_request_options']
2140
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2141
			'Some ISPs may require certain options be or not be requested.');
2142

    
2143
$section->addInput(new Form_Input(
2144
	'adv_dhcp_required_options',
2145
	'Require options',
2146
	'text',
2147
	$pconfig['adv_dhcp_required_options']
2148
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2149

    
2150
$section->addInput(new Form_Input(
2151
	'adv_dhcp_option_modifiers',
2152
	'Option modifiers',
2153
	'text',
2154
	$pconfig['adv_dhcp_option_modifiers']
2155
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2156
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2157
			'<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>');
2158

    
2159
$form->add($section);
2160

    
2161
// DHCP6 client config
2162

    
2163
$section = new Form_Section('DHCP6 Client Configuration');
2164
$section->addClass('dhcp6');
2165

    
2166
$group = new Form_Group('Options');
2167

    
2168
$group->add(new Form_Checkbox(
2169
	'adv_dhcp6_config_advanced',
2170
	null,
2171
	'Advanced Configuration',
2172
	$pconfig['adv_dhcp6_config_advanced']
2173
))->setHelp('Use advanced DHCPv6 configuration options.');
2174

    
2175
$group->add(new Form_Checkbox(
2176
	'adv_dhcp6_config_file_override',
2177
	null,
2178
	'Configuration Override',
2179
	$pconfig['adv_dhcp6_config_file_override']
2180
))->setHelp('Override the configuration from this file.');
2181

    
2182
$section->add($group);
2183

    
2184
$section->addInput(new Form_Checkbox(
2185
	'dhcp6usev4iface',
2186
	'Use IPv4 connectivity as parent interface',
2187
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2188
	$pconfig['dhcp6usev4iface']
2189
));
2190

    
2191
$section->addInput(new Form_Checkbox(
2192
	'dhcp6prefixonly',
2193
	'Request only an IPv6 prefix',
2194
	'Only request an IPv6 prefix, do not request an IPv6 address',
2195
	$pconfig['dhcp6prefixonly']
2196
));
2197

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

    
2205
$section->addInput(new Form_Checkbox(
2206
	'dhcp6-ia-pd-send-hint',
2207
	'Send IPv6 prefix hint',
2208
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2209
	$pconfig['dhcp6-ia-pd-send-hint']
2210
));
2211

    
2212
$section->addInput(new Form_Checkbox(
2213
	'dhcp6debug',
2214
	'Debug',
2215
	'Start DHCP6 client in debug mode',
2216
	$pconfig['dhcp6debug']
2217
));
2218

    
2219
$section->addInput(new Form_Checkbox(
2220
	'dhcp6withoutra',
2221
	'Do not wait for a RA',
2222
	'Required by some ISPs, especially those not using PPPoE',
2223
	$pconfig['dhcp6withoutra']
2224
));
2225
$section->addInput(new Form_Checkbox(
2226
	'dhcp6norelease',
2227
	'Do not allow PD/Address release',
2228
	'dhcp6c will send a release to the ISP on exit, some ISPs then release the allocated address or prefix. This option prevents that signal ever being sent',
2229
	$pconfig['dhcp6norelease']
2230
));
2231
$section->addInput(new Form_Input(
2232
	'adv_dhcp6_config_file_override_path',
2233
	'Configuration File Override',
2234
	'text',
2235
	$pconfig['adv_dhcp6_config_file_override_path']
2236
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2237
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2238
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2239
			'Some ISPs may require certain options be or not be sent.');
2240

    
2241
$form->add($section);
2242

    
2243
// DHCP6 client config - Advanced
2244

    
2245
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2246
$section->addClass('dhcp6advanced');
2247

    
2248
$section->addInput(new Form_Checkbox(
2249
	'adv_dhcp6_interface_statement_information_only_enable',
2250
	'Information only',
2251
	'Exchange Information Only',
2252
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2253
	'Selected'
2254
))->setHelp('Only exchange informational configuration parameters with servers.');
2255

    
2256
$section->addInput(new Form_Input(
2257
	'adv_dhcp6_interface_statement_send_options',
2258
	'Send options',
2259
	'text',
2260
	$pconfig['adv_dhcp6_interface_statement_send_options']
2261
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2262
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2263
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2264
			'Some DHCP services may require certain options be or not be sent.');
2265

    
2266
$section->addInput(new Form_Input(
2267
	'adv_dhcp6_interface_statement_request_options',
2268
	'Request Options',
2269
	'text',
2270
	$pconfig['adv_dhcp6_interface_statement_request_options']
2271
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2272
			'Some DHCP services may require certain options be or not be requested.');
2273

    
2274
$section->addInput(new Form_Input(
2275
	'adv_dhcp6_interface_statement_script',
2276
	'Scripts',
2277
	'text',
2278
	$pconfig['adv_dhcp6_interface_statement_script']
2279
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2280
			'[/[dirname/[.../]]filename[.ext]].');
2281

    
2282
$group = new Form_Group('Identity Association Statement');
2283

    
2284
$group->add(new Form_Checkbox(
2285
	'adv_dhcp6_id_assoc_statement_address_enable',
2286
	null,
2287
	'Non-Temporary Address Allocation',
2288
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2289
	'Selected'
2290
));
2291

    
2292
$group->add(new Form_Input(
2293
	'adv_dhcp6_id_assoc_statement_address_id',
2294
	null,
2295
	'text',
2296
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2297
))->sethelp('id-assoc na ID');
2298

    
2299
$group->add(new Form_IpAddress(
2300
	'adv_dhcp6_id_assoc_statement_address',
2301
	null,
2302
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2303
	'V6'
2304
))->sethelp('IPv6 address');
2305

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

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

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

    
2322
// Prefix delegation
2323
$group = new Form_Group('');
2324

    
2325
$group->add(new Form_Checkbox(
2326
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2327
	null,
2328
	'Prefix Delegation ',
2329
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2330
	'Selected'
2331
));
2332

    
2333
$group->add(new Form_Input(
2334
	'adv_dhcp6_id_assoc_statement_prefix_id',
2335
	null,
2336
	'text',
2337
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2338
))->sethelp('id-assoc pd ID');
2339

    
2340
$group->add(new Form_IpAddress(
2341
	'adv_dhcp6_id_assoc_statement_prefix',
2342
	null,
2343
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2344
	'V6'
2345
))->sethelp('IPv6 prefix');
2346

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

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

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

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

    
2365
$group->add(new Form_Input(
2366
	'adv_dhcp6_prefix_interface_statement_sla_id',
2367
	null,
2368
	'text',
2369
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2370
))->sethelp('Prefix Interface sla-id');
2371

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

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

    
2381
$group = new Form_Group('Select prefix interface');
2382
$section->addInput(new Form_Select(
2383
	'adv_dhcp6_prefix_selected_interface',
2384
	'Prefix Interface',
2385
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2386
	$interfaces
2387
))->setHelp('Select the interface on which to apply the prefix delegation.');
2388

    
2389
$group = new Form_Group('Authentication statement');
2390

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

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

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

    
2412
$group->add(new Form_Input(
2413
	'adv_dhcp6_authentication_statement_rdm',
2414
	null,
2415
	'text',
2416
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2417
))->sethelp('RDM');
2418

    
2419
$section->add($group);
2420

    
2421
$group = new Form_Group('Keyinfo statement');
2422

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

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

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

    
2439
$group = new Form_Group('');
2440

    
2441
$group->add(new Form_Input(
2442
	'adv_dhcp6_key_info_statement_keyid',
2443
	null,
2444
	'text',
2445
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2446
))->sethelp('KeyID');
2447

    
2448
$group->add(new Form_Input(
2449
	'adv_dhcp6_key_info_statement_secret',
2450
	null,
2451
	'text',
2452
	$pconfig['adv_dhcp6_key_info_statement_secret']
2453
))->sethelp('Secret');
2454

    
2455
$group->add(new Form_Input(
2456
	'adv_dhcp6_key_info_statement_expire',
2457
	null,
2458
	'text',
2459
	$pconfig['adv_dhcp6_key_info_statement_expire']
2460
))->sethelp('Expire');
2461

    
2462
$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>');
2463

    
2464
$section->add($group);
2465

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

    
2468
$section = new Form_Section('6RD Configuration');
2469
$section->addClass('_6rd');
2470

    
2471
$section->addInput(new Form_Input(
2472
	'prefix-6rd',
2473
	'6RD Prefix',
2474
	'text',
2475
	$pconfig['prefix-6rd']
2476
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2477

    
2478
$section->addInput(new Form_Input(
2479
	'gateway-6rd',
2480
	'*6RD Border relay',
2481
	'text',
2482
	$pconfig['gateway-6rd']
2483
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2484

    
2485
$section->addInput(new Form_Select(
2486
	'prefix-6rd-v4plen',
2487
	'6RD IPv4 Prefix length',
2488
	$pconfig['prefix-6rd-v4plen'],
2489
	array_combine(range(0, 32), range(0, 32))
2490
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2491

    
2492
$form->add($section);
2493

    
2494
// Track IPv6 ointerface section
2495
$section = new Form_Section('Track IPv6 Interface');
2496
$section->addClass('track6');
2497

    
2498
function build_ipv6interface_list() {
2499
	global $config, $section;
2500

    
2501
	$list = array('' => '');
2502

    
2503
	$interfaces = get_configured_interface_with_descr(false, true);
2504
	$dynv6ifs = array();
2505

    
2506
	foreach ($interfaces as $iface => $ifacename) {
2507
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2508
			case "6to4":
2509
			case "6rd":
2510
			case "dhcp6":
2511
				$dynv6ifs[$iface] = array(
2512
					'name' => $ifacename,
2513
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2514
				);
2515
				break;
2516
			default:
2517
				continue;
2518
		}
2519
	}
2520

    
2521
	foreach ($dynv6ifs as $iface => $ifacedata) {
2522
		$list[$iface] = $ifacedata['name'];
2523

    
2524
		$section->addInput(new Form_Input(
2525
			'ipv6-num-prefix-ids-' . $iface,
2526
			null,
2527
			'hidden',
2528
			$ifacedata['ipv6_num_prefix_ids']
2529
		));
2530
	}
2531

    
2532
	return($list);
2533
}
2534

    
2535
$section->addInput(new Form_Select(
2536
	'track6-interface',
2537
	'*IPv6 Interface',
2538
	$pconfig['track6-interface'],
2539
	build_ipv6interface_list()
2540
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2541

    
2542
if ($pconfig['track6-prefix-id'] == "") {
2543
	$pconfig['track6-prefix-id'] = 0;
2544
}
2545

    
2546
$section->addInput(new Form_Input(
2547
	'track6-prefix-id--hex',
2548
	'IPv6 Prefix ID',
2549
	'text',
2550
	sprintf("%x", $pconfig['track6-prefix-id'])
2551
))->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.');
2552

    
2553
$section->addInput(new Form_Input(
2554
	'track6-prefix-id-max',
2555
	null,
2556
	'hidden',
2557
	0
2558
));
2559

    
2560
$form->add($section);
2561

    
2562
/// PPP section
2563

    
2564
$section = new Form_Section('PPP Configuration');
2565
$section->addClass('ppp');
2566

    
2567
$section->addInput(new Form_Select(
2568
	'country',
2569
	'Country',
2570
	$pconfig['country'],
2571
	[]
2572
));
2573

    
2574
$section->addInput(new Form_Select(
2575
	'provider_list',
2576
	'Provider',
2577
	$pconfig['provider_list'],
2578
	[]
2579
));
2580

    
2581
$section->addInput(new Form_Select(
2582
	'providerplan',
2583
	'Plan',
2584
	$pconfig['providerplan'],
2585
	[]
2586
))->setHelp('Select to fill in service provider data.');
2587

    
2588
$section->addInput(new Form_Input(
2589
	'ppp_username',
2590
	'Username',
2591
	'text',
2592
	$pconfig['ppp_username']
2593
));
2594

    
2595
$section->addPassword(new Form_Input(
2596
	'ppp_password',
2597
	'Password',
2598
	'password',
2599
	$pconfig['ppp_password']
2600
));
2601

    
2602
$section->addInput(new Form_Input(
2603
	'phone',
2604
	'*Phone number',
2605
	'text',
2606
	$pconfig['phone']
2607
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2608

    
2609
$section->addInput(new Form_Input(
2610
	'apn',
2611
	'Access Point Name',
2612
	'text',
2613
	$pconfig['apn']
2614
));
2615

    
2616

    
2617
function build_port_list() {
2618
	$list = array("" => "None");
2619

    
2620
	$portlist = glob("/dev/cua*");
2621
	$modems	  = glob("/dev/modem*");
2622
	$portlist = array_merge($portlist, $modems);
2623

    
2624
	foreach ($portlist as $port) {
2625
		if (preg_match("/\.(lock|init)$/", $port)) {
2626
			continue;
2627
		}
2628

    
2629
	$list[trim($port)] = $port;
2630
	}
2631

    
2632
	return($list);
2633
}
2634

    
2635
$section->addInput(new Form_Select(
2636
	'port',
2637
	"*Modem port",
2638
	$pconfig['port'],
2639
	build_port_list()
2640
));
2641

    
2642
$section->addInput(new Form_Button(
2643
	'btnadvppp',
2644
	'Advanced PPP',
2645
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2646
	'fa-cog'
2647
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2648

    
2649
$form->add($section);
2650

    
2651
// PPPoE configuration
2652
$section = new Form_Section('PPPoE Configuration');
2653
$section->addClass('pppoe');
2654

    
2655
$section->addInput(new Form_Input(
2656
	'pppoe_username',
2657
	'*Username',
2658
	'text',
2659
	$pconfig['pppoe_username']
2660
));
2661

    
2662
$section->addPassword(new Form_Input(
2663
	'pppoe_password',
2664
	'*Password',
2665
	'password',
2666
	$pconfig['pppoe_password']
2667
));
2668

    
2669
$section->addInput(new Form_Input(
2670
	'provider',
2671
	'Service name',
2672
	'text',
2673
	$pconfig['provider']
2674
))->setHelp('This field can usually be left empty.');
2675

    
2676
$section->addInput(new Form_Checkbox(
2677
	'pppoe_dialondemand',
2678
	'Dial on demand',
2679
	'Enable Dial-On-Demand mode ',
2680
	$pconfig['pppoe_dialondemand'],
2681
	'enable'
2682
));
2683

    
2684
$section->addInput(new Form_Input(
2685
	'pppoe_idletimeout',
2686
	'Idle timeout',
2687
	'number',
2688
	$pconfig['pppoe_idletimeout'],
2689
	['min' => 0]
2690
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2691
			'An idle timeout of zero disables this feature.');
2692

    
2693
$section->addInput(new Form_Select(
2694
	'pppoe-reset-type',
2695
	'Periodic reset',
2696
	$pconfig['pppoe-reset-type'],
2697
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2698
))->setHelp('Select a reset timing type.');
2699

    
2700
$group = new Form_Group('Custom reset');
2701
$group->addClass('pppoecustom');
2702

    
2703
$group->add(new Form_Input(
2704
	'pppoe_resethour',
2705
	null,
2706
	'number',
2707
	$pconfig['pppoe_resethour'],
2708
	['min' => 0, 'max' => 23]
2709
))->setHelp('Hour (0-23)');
2710

    
2711
$group->add(new Form_Input(
2712
	'pppoe_resetminute',
2713
	null,
2714
	'number',
2715
	$pconfig['pppoe_resetminute'],
2716
	['min' => 0, 'max' => 59]
2717
))->setHelp('Minutes (0-59)');
2718

    
2719
$group->add(new Form_Input(
2720
	'pppoe_resetdate',
2721
	null,
2722
	'text',
2723
	$pconfig['pppoe_resetdate']
2724
))->setHelp('Specific date (mm/dd/yyyy)');
2725

    
2726
$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');
2727

    
2728
$section->add($group);
2729

    
2730
$group = new Form_MultiCheckboxGroup('cron based reset');
2731
$group->addClass('pppoepreset');
2732

    
2733
$group->add(new Form_MultiCheckbox(
2734
	'pppoe_pr_preset_val',
2735
	null,
2736
	'Reset at each month ("0 0 1 * *")',
2737
	$pconfig['pppoe_monthly'],
2738
	'monthly'
2739
))->displayAsRadio();
2740

    
2741
$group->add(new Form_MultiCheckbox(
2742
	'pppoe_pr_preset_val',
2743
	null,
2744
	'Reset at each week ("0 0 * * 0")',
2745
	$pconfig['pppoe_weekly'],
2746
	'weekly'
2747
))->displayAsRadio();
2748

    
2749
$group->add(new Form_MultiCheckbox(
2750
	'pppoe_pr_preset_val',
2751
	null,
2752
	'Reset at each day ("0 0 * * *")',
2753
	$pconfig['pppoe_daily'],
2754
	'daily'
2755
))->displayAsRadio();
2756

    
2757
$group->add(new Form_MultiCheckbox(
2758
	'pppoe_pr_preset_val',
2759
	null,
2760
	'Reset at each hour ("0 * * * *")',
2761
	$pconfig['pppoe_hourly'],
2762
	'hourly'
2763
))->displayAsRadio();
2764

    
2765
$section->add($group);
2766

    
2767
$section->addInput(new Form_Button(
2768
	'btnadvppp',
2769
	'Advanced and MLPPP',
2770
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2771
	'fa-cog'
2772
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2773

    
2774
$form->add($section);
2775

    
2776
// PPTP & L2TP Configuration section
2777
$section = new Form_Section('PPTP/L2TP Configuration');
2778
$section->addClass('pptp');
2779

    
2780
$section->addInput(new Form_Input(
2781
	'pptp_username',
2782
	'*Username',
2783
	'text',
2784
	$pconfig['pptp_username']
2785
));
2786

    
2787
$section->addPassword(new Form_Input(
2788
	'pptp_password',
2789
	'*Password',
2790
	'password',
2791
	$pconfig['pptp_password']
2792
));
2793

    
2794
$section->addInput(new Form_IpAddress(
2795
	'pptp_local0',
2796
	'*Local IP address',
2797
	$pconfig['pptp_localip'][0],
2798
	'V4'
2799
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2800

    
2801
$section->addInput(new Form_IpAddress(
2802
	'pptp_remote0',
2803
	'*Remote IP address',
2804
	$pconfig['pptp_remote'][0],
2805
	'HOSTV4'
2806
));
2807

    
2808
$section->addInput(new Form_Checkbox(
2809
	'pptp_dialondemand',
2810
	'Dial on demand',
2811
	'Enable Dial-On-Demand mode ',
2812
	$pconfig['pptp_dialondemand'],
2813
	'enable'
2814
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2815
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2816

    
2817
$section->addInput(new Form_Input(
2818
	'pptp_idletimeout',
2819
	'Idle timeout (seconds)',
2820
	'number',
2821
	$pconfig['pptp_idletimeout'],
2822
	['min' => 0]
2823
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2824
			'An idle timeout of zero disables this feature.');
2825

    
2826
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2827
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2828
} else {
2829
	$mlppp_text = "";
2830
}
2831

    
2832
$section->addInput(new Form_Button(
2833
	'btnadvppp',
2834
	'Advanced and MLPPP',
2835
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2836
	'fa-cog'
2837
))->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.');
2838

    
2839
$form->add($section);
2840

    
2841
// Wireless interface
2842
if (isset($wancfg['wireless'])) {
2843

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

    
2846
	$section->addInput(new Form_Checkbox(
2847
		'persistcommonwireless',
2848
		'Persist common settings',
2849
		'Preserve common wireless configuration through interface deletions and reassignments.',
2850
		$pconfig['persistcommonwireless'],
2851
		'yes'
2852
	));
2853

    
2854
	$mode_list = ['auto' => 'Auto'];
2855

    
2856
	if (is_array($wl_modes)) {
2857
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2858
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2859
		}
2860
	}
2861

    
2862
	if (count($mode_list) == 1) {
2863
		$mode_list[''] = '';
2864
	}
2865

    
2866
	$section->addInput(new Form_Select(
2867
		'standard',
2868
		'Standard',
2869
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2870
		$mode_list
2871
	));
2872

    
2873
	if (isset($wl_modes['11g'])) {
2874
		$section->addInput(new Form_Select(
2875
			'protmode',
2876
			'802.11g OFDM Protection Mode',
2877
			$pconfig['protmode'],
2878
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2879
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2880
	} else {
2881
		$section->addInput(new Form_Input(
2882
			'protmode',
2883
			null,
2884
			'hidden',
2885
			'off'
2886
		));
2887
	}
2888

    
2889
	$mode_list = ['0' => gettext('Auto')];
2890

    
2891
	if (is_array($wl_modes)) {
2892
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2893
			if ($wl_standard == "11g") {
2894
				$wl_standard = "11b/g";
2895
			} else if ($wl_standard == "11ng") {
2896
				$wl_standard = "11b/g/n";
2897
			} else if ($wl_standard == "11na") {
2898
				$wl_standard = "11a/n";
2899
			}
2900

    
2901
			foreach ($wl_channels as $wl_channel) {
2902
				if (isset($wl_chaninfo[$wl_channel])) {
2903
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2904
				} else {
2905
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2906
				}
2907
			}
2908
		}
2909
	}
2910

    
2911
	$section->addInput(new Form_Select(
2912
		'channel',
2913
		'Channel',
2914
		$pconfig['channel'],
2915
		$mode_list
2916
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2917
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2918

    
2919
	if (ANTENNAS) {
2920
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2921
			$group = new Form_Group('Antenna Settings');
2922

    
2923
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2924
				$group->add(new Form_Select(
2925
					'diversity',
2926
					null,
2927
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2928
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2929
				))->setHelp('Diversity');
2930
			}
2931

    
2932
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2933
				$group->add(new Form_Select(
2934
					'txantenna',
2935
					null,
2936
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2937
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2938
				))->setHelp('Transmit antenna');
2939
			}
2940

    
2941
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2942
				$group->add(new Form_Select(
2943
					'rxantenna',
2944
					null,
2945
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2946
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2947
				))->setHelp('Receive antenna');
2948
			}
2949

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

    
2952
			$section->add($group);
2953
		}
2954
	}
2955

    
2956
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2957
			$section->addInput(new Form_Input(
2958
				'distance',
2959
				'Distance setting (meters)',
2960
				'test',
2961
				$pconfig['distance']
2962
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2963
	}
2964

    
2965
	$form->add($section);
2966

    
2967
	// Regulatory settings
2968
	$section = new Form_Section('Regulatory Settings');
2969

    
2970
	$domain_list = array("" => 'Default');
2971

    
2972
	if (is_array($wl_regdomains)) {
2973
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2974
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2975
		}
2976
	}
2977

    
2978
	$section->addInput(new Form_Select(
2979
		'regdomain',
2980
		'Regulatory domain',
2981
		$pconfig['regdomain'],
2982
		$domain_list
2983
	))->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');
2984

    
2985
	$country_list = array('' => 'Default');
2986

    
2987
	if (is_array($wl_countries)) {
2988
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2989
			$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']);
2990
		}
2991
	}
2992

    
2993
	$section->addInput(new Form_Select(
2994
		'regcountry',
2995
		'Country',
2996
		$pconfig['regcountry'],
2997
		$country_list
2998
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2999

    
3000
	$section->addInput(new Form_Select(
3001
		'reglocation',
3002
		'Location',
3003
		$pconfig['reglocation'],
3004
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
3005
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3006
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
3007
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3008
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3009
				'These settings may not be able to add additional channels that are not already supported.');
3010

    
3011
	$form->add($section);
3012

    
3013
	$section = new Form_Section('Network-Specific Wireless Configuration');
3014

    
3015
	$section->addInput(new Form_Select(
3016
		'mode',
3017
		'Mode',
3018
		$pconfig['mode'],
3019
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3020
	));
3021

    
3022
	$section->addInput(new Form_Input(
3023
		'ssid',
3024
		'SSID',
3025
		'text',
3026
		$pconfig['ssid']
3027
	));
3028

    
3029
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3030
		$section->addInput(new Form_Select(
3031
			'puremode',
3032
			'Minimum wireless standard',
3033
			$pconfig['puremode'],
3034
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3035
		))->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)');
3036
	} elseif (isset($wl_modes['11g'])) {
3037
		$section->addInput(new Form_Checkbox(
3038
			'puremode',
3039
			'802.11g only',
3040
			null,
3041
			$pconfig['puremode'],
3042
			'11g'
3043
		))->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)');
3044
	}
3045

    
3046
	$section->addInput(new Form_Checkbox(
3047
		'apbridge_enable',
3048
		'Allow intra-BSS communication',
3049
		'Allow packets to pass between wireless clients directly when operating as an access point',
3050
		$pconfig['apbridge_enable'],
3051
		'yes'
3052
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3053

    
3054
	$section->addInput(new Form_Checkbox(
3055
		'wme_enable',
3056
		'Enable WME',
3057
		'Force the card to use WME (wireless QoS)',
3058
		$pconfig['wme_enable'],
3059
		'yes'
3060
	));
3061

    
3062
	$section->addInput(new Form_Checkbox(
3063
		'hidessid_enable',
3064
		'Hide SSID',
3065
		'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.)',
3066
		$pconfig['hidessid_enable'],
3067
		'yes'
3068
	));
3069

    
3070
	$form->add($section);
3071

    
3072
	// WPA Section
3073
	$section = new Form_Section('WPA');
3074

    
3075
	$section->addInput(new Form_Checkbox(
3076
		'wpa_enable',
3077
		'Enable',
3078
		'Enable WPA',
3079
		$pconfig['wpa_enable'],
3080
		'yes'
3081
	));
3082

    
3083
	$section->addInput(new Form_Input(
3084
		'passphrase',
3085
		'WPA Pre-Shared Key',
3086
		'text',
3087
		$pconfig['passphrase']
3088
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3089

    
3090
	$section->addInput(new Form_Select(
3091
		'wpa_mode',
3092
		'WPA mode',
3093
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3094
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3095
	));
3096

    
3097
	$section->addInput(new Form_Select(
3098
		'wpa_key_mgmt',
3099
		'WPA Key Management Mode',
3100
		$pconfig['wpa_key_mgmt'],
3101
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3102
	));
3103

    
3104
	$section->addInput(new Form_Select(
3105
		'wpa_pairwise',
3106
		'WPA Pairwise',
3107
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3108
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3109
	));
3110

    
3111
	$section->addInput(new Form_Input(
3112
		'wpa_group_rekey',
3113
		'Group Key Rotation',
3114
		'number',
3115
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3116
		['min' => '1', 'max' => 9999]
3117
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3118

    
3119
	$section->addInput(new Form_Input(
3120
		'wpa_gmk_rekey',
3121
		'Group Master Key Regeneration',
3122
		'number',
3123
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3124
		['min' => '1', 'max' => 9999]
3125
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3126

    
3127
	$section->addInput(new Form_Checkbox(
3128
		'wpa_strict_rekey',
3129
		'Strict Key Regeneration',
3130
		'Force the AP to rekey whenever a client disassociates',
3131
		$pconfig['wpa_strict_rekey'],
3132
		'yes'
3133
	));
3134

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

    
3137
	$section = new Form_Section('802.1x RADIUS Options');
3138

    
3139
	$section->addInput(new Form_Checkbox(
3140
		'ieee8021x',
3141
		'IEEE802.1X',
3142
		'Enable 802.1X authentication',
3143
		$pconfig['ieee8021x'],
3144
		'yes'
3145
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3146

    
3147
	$group = new Form_Group('Primary 802.1X server');
3148

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

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

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

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

    
3171
	$group = new Form_Group('Secondary 802.1X server');
3172

    
3173
	$group->add(new Form_IpAddress(
3174
		'auth_server_addr2',
3175
		'IP Address',
3176
		$pconfig['auth_server_addr2']
3177
	))->setHelp('IP address of the RADIUS server');
3178

    
3179
	$group->add(new Form_Input(
3180
		'auth_server_port2',
3181
		'Port',
3182
		'number',
3183
		$pconfig['auth_server_port2']
3184
	))->setHelp('Server auth port. Default is 1812');
3185

    
3186
	$group->add(new Form_Input(
3187
		'auth_server_shared_secret2',
3188
		'Shared Secret',
3189
		'text',
3190
		$pconfig['auth_server_shared_secret2']
3191
	))->setHelp('RADIUS Shared secret for this firewall');
3192

    
3193
	$section->add($group);
3194

    
3195
	$section->addInput(new Form_Checkbox(
3196
		'rsn_preauth',
3197
		'Authentication Roaming Preauth',
3198
		null,
3199
		$pconfig['rsn_preauth'],
3200
		'yes'
3201
	));
3202

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

    
3206
$section = new Form_Section('Reserved Networks');
3207

    
3208
$section->addInput(new Form_Checkbox(
3209
	'blockpriv',
3210
	'Block private networks and loopback addresses',
3211
	'',
3212
	$pconfig['blockpriv'],
3213
	'yes'
3214
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3215
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3216
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3217

    
3218
$section->addInput(new Form_Checkbox(
3219
	'blockbogons',
3220
	'Block bogon networks',
3221
	'',
3222
	$pconfig['blockbogons'],
3223
	'yes'
3224
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3225
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.' . '<br />' .
3226
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.');
3227

    
3228
$form->add($section);
3229

    
3230
$form->addGlobal(new Form_Input(
3231
	'if',
3232
	null,
3233
	'hidden',
3234
	$if
3235
));
3236

    
3237
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3238
	$form->addGlobal(new Form_Input(
3239
		'ppp_port',
3240
		null,
3241
		'hidden',
3242
		$pconfig['port']
3243
	));
3244
}
3245

    
3246
$form->addGlobal(new Form_Input(
3247
	'ptpid',
3248
	null,
3249
	'hidden',
3250
	$pconfig['ptpid']
3251
));
3252

    
3253

    
3254
// Add new gateway modal pop-up
3255
$modal = new Modal('New Gateway', 'newgateway', 'large');
3256

    
3257
$modal->addInput(new Form_Checkbox(
3258
	'defaultgw',
3259
	'Default',
3260
	'Default gateway',
3261
	($if == "wan" || $if == "WAN")
3262
));
3263

    
3264
$modal->addInput(new Form_Input(
3265
	'name',
3266
	'Gateway name',
3267
	'text',
3268
	$wancfg['descr'] . "GW"
3269
));
3270

    
3271
$modal->addInput(new Form_IpAddress(
3272
	'gatewayip',
3273
	'Gateway IPv4',
3274
	null,
3275
	'V4'
3276
));
3277

    
3278
$modal->addInput(new Form_Input(
3279
	'gatewaydescr',
3280
	'Description',
3281
	'text'
3282
));
3283

    
3284
$btnaddgw = new Form_Button(
3285
	'add',
3286
	'Add',
3287
	null,
3288
	'fa-plus'
3289
);
3290

    
3291
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3292

    
3293
$btncnxgw = new Form_Button(
3294
	'cnx',
3295
	'Cancel',
3296
	null,
3297
	'fa-undo'
3298
);
3299

    
3300
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3301

    
3302
$modal->addInput(new Form_StaticText(
3303
	null,
3304
	$btnaddgw . $btncnxgw
3305
));
3306

    
3307
$form->add($modal);
3308

    
3309
print($form);
3310
?>
3311

    
3312
<script type="text/javascript">
3313
//<![CDATA[
3314
events.push(function() {
3315
	function updateType(t) {
3316

    
3317
		switch (t) {
3318
			case "none": {
3319
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3320
				break;
3321
			}
3322
			case "staticv4": {
3323
				$('.dhcpadvanced, .none, .dhcp').hide();
3324
				$('.pppoe, .pptp, .ppp').hide();
3325
				break;
3326
			}
3327
			case "dhcp": {
3328
				$('.dhcpadvanced, .none').hide();
3329
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3330
										//			about the staticv4 class
3331
				$('.pppoe, .pptp, .ppp').hide();
3332
				break;
3333
			}
3334
			case "ppp": {
3335
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3336
				country_list();
3337
				break;
3338
			}
3339
			case "pppoe": {
3340
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3341
				break;
3342
			}
3343
			case "l2tp":
3344
			case "pptp": {
3345
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3346
				$('.pptp').show();
3347
				break;
3348
			}
3349
		}
3350

    
3351
		if (t != "l2tp" && t != "pptp") {
3352
			$('.'+t).show();
3353
		}
3354
	}
3355

    
3356
	function updateTypeSix(t) {
3357
		if (!isNaN(t[0])) {
3358
			t = '_' + t;
3359
		}
3360

    
3361
		switch (t) {
3362
			case "none": {
3363
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3364
				break;
3365
			}
3366
			case "staticv6": {
3367
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3368
				break;
3369
			}
3370
			case "slaac": {
3371
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3372
				break;
3373
			}
3374
			case "dhcp6": {
3375
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3376
				break;
3377
			}
3378
			case "_6rd": {
3379
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3380
				break;
3381
			}
3382
			case "_6to4": {
3383
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3384
				break;
3385
			}
3386
			case "track6": {
3387
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3388
				update_track6_prefix();
3389
				break;
3390
			}
3391
		}
3392

    
3393
		if (t != "l2tp" && t != "pptp") {
3394
			$('.'+t).show();
3395
		}
3396
	}
3397

    
3398
	function show_reset_settings(reset_type) {
3399
		if (reset_type == 'preset') {
3400
			$('.pppoepreset').show();
3401
			$('.pppoecustom').hide();
3402
		} else if (reset_type == 'custom') {
3403
			$('.pppoecustom').show();
3404
			$('.pppoepreset').hide();
3405
		} else {
3406
			$('.pppoecustom').hide();
3407
			$('.pppoepreset').hide();
3408
		}
3409
	}
3410

    
3411
	function update_track6_prefix() {
3412
		var iface = $("#track6-interface").val();
3413
		if (iface == null) {
3414
			return;
3415
		}
3416

    
3417
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3418
		if (track6_prefix_ids == null) {
3419
			return;
3420
		}
3421

    
3422
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3423
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3424
	}
3425

    
3426
	// Create the new gateway from the data entered in the modal pop-up
3427
	function hide_add_gatewaysave() {
3428
		var iface = $('#if').val();
3429
		name = $('#name').val();
3430
		var descr = $('#gatewaydescr').val();
3431
		gatewayip = $('#gatewayip').val();
3432

    
3433
		var defaultgw = '';
3434
		if ($('#defaultgw').is(':checked')) {
3435
			defaultgw = '&defaultgw=on';
3436
		}
3437

    
3438
		var url = "system_gateways_edit.php";
3439
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3440
		$.ajax(
3441
			url,
3442
			{
3443
				type: 'post',
3444
				data: pars,
3445
				error: report_failure,
3446
				complete: save_callback
3447
			});
3448
		}
3449

    
3450
	function save_callback(response) {
3451
		if (response) {
3452
			var gwtext = escape(name) + " - " + gatewayip;
3453
			addOption($('#gateway'), gwtext, name);
3454
		} else {
3455
			report_failure();
3456
		}
3457

    
3458
		$("#newgateway").modal('hide');
3459
	}
3460

    
3461
	function report_failure(request, textStatus, errorThrown) {
3462
		contenttype = ";"+request.getResponseHeader("Content-Type")+";";
3463
		if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
3464
			alert(request.responseText);
3465
		} else {
3466
			alert("The IPv4 gateway could not be created.");
3467
		}
3468

    
3469
		$("#newgateway").modal('hide');
3470
	}
3471

    
3472
	function addOption(selectbox, text, value) {
3473
		var optn = document.createElement("OPTION");
3474
		optn.text = text;
3475
		optn.value = value;
3476
		selectbox.append(optn);
3477
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3478
	}
3479

    
3480
	function hide_add_gatewaysave_v6() {
3481

    
3482
		var iface = $('#if').val();
3483
		name = $('#name6').val();
3484
		var descr = $('#gatewaydescr6').val();
3485
		gatewayip = $('#gatewayip6').val();
3486
		var defaultgw = '';
3487
		if ($('#defaultgw6').is(':checked')) {
3488
			defaultgw = '&defaultgw=on';
3489
		}
3490
		var url_v6 = "system_gateways_edit.php";
3491
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3492
		$.ajax(
3493
			url_v6,
3494
			{
3495
				type: 'post',
3496
				data: pars_v6,
3497
				error: report_failure_v6,
3498
				success: save_callback_v6
3499
			});
3500
	}
3501

    
3502

    
3503
	function addOption_v6(selectbox, text, value) {
3504
		var optn = document.createElement("OPTION");
3505
		optn.text = text;
3506
		optn.value = value;
3507
		selectbox.append(optn);
3508
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3509
	}
3510

    
3511
	function report_failure_v6(request, textStatus, errorThrown) {
3512
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3513
			alert(request.responseText);
3514
		} else {
3515
			alert("The IPv6 gateway could not be created.");
3516
		}
3517

    
3518
		$("#newgateway6").modal('hide');
3519
	}
3520

    
3521
	function save_callback_v6(response_v6) {
3522
		if (response_v6) {
3523

    
3524
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3525
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3526
		} else {
3527
			report_failure_v6();
3528
		}
3529

    
3530
		$("#newgateway6").modal('hide');
3531
	}
3532

    
3533
	function country_list() {
3534
		$('#country').children().remove();
3535
		$('#provider_list').children().remove();
3536
		$('#providerplan').children().remove();
3537
		$.ajax("getserviceproviders.php",{
3538
			success: function(response) {
3539

    
3540
				var responseTextArr = response.split("\n");
3541
				responseTextArr.sort();
3542

    
3543
				responseTextArr.forEach( function(value) {
3544
					country = value.split(":");
3545
					$('#country').append($('<option>', {
3546
						value: country[1],
3547
						text : country[0]
3548
					}));
3549
				});
3550
			}
3551
		});
3552
	}
3553

    
3554
	function providers_list() {
3555
		$('#provider_list').children().remove();
3556
		$('#providerplan').children().remove();
3557
		$.ajax("getserviceproviders.php",{
3558
			type: 'post',
3559
			data: {country : $('#country').val()},
3560
			success: function(response) {
3561
				var responseTextArr = response.split("\n");
3562
				responseTextArr.sort();
3563
				responseTextArr.forEach( function(value) {
3564
					$('#provider_list').append($('<option>', {
3565
							value: value,
3566
							text : value
3567
					}));
3568
				});
3569
			}
3570
		});
3571
	}
3572

    
3573
	function providerplan_list() {
3574
		$('#providerplan').children().remove();
3575
		$.ajax("getserviceproviders.php",{
3576
			type: 'post',
3577
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3578
			success: function(response) {
3579
				var responseTextArr = response.split("\n");
3580
				responseTextArr.sort();
3581

    
3582
				$('#providerplan').append($('<option>', {
3583
					value: '',
3584
					text : ''
3585
				}));
3586

    
3587
				responseTextArr.forEach( function(value) {
3588
					if (value != "") {
3589
						providerplan = value.split(":");
3590

    
3591
						$('#providerplan').append($('<option>', {
3592
							value: providerplan[1],
3593
							text : providerplan[0] + " - " + providerplan[1]
3594
						}));
3595
					}
3596
				});
3597
			}
3598
		});
3599
	}
3600

    
3601
	function prefill_provider() {
3602
		$.ajax("getserviceproviders.php",{
3603
			type: 'post',
3604
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3605
			success: function(data, textStatus, response) {
3606
				var xmldoc = response.responseXML;
3607
				var provider = xmldoc.getElementsByTagName('connection')[0];
3608
				$('#ppp_username').val('');
3609
				$('#ppp_password').val('');
3610
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3611
					$('#phone').val('#777');
3612
					$('#apn').val('');
3613
				} else {
3614
					$('#phone').val('*99#');
3615
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3616
				}
3617
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3618
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3619
				$('#ppp_username').val(ppp_username);
3620
				$('#ppp_password').val(ppp_password);
3621
			}
3622
		});
3623
	}
3624

    
3625
	function show_dhcp6adv() {
3626
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3627
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3628

    
3629
		hideCheckbox('dhcp6usev4iface', ovr);
3630
		hideCheckbox('dhcp6prefixonly', ovr);
3631
		hideInput('dhcp6-ia-pd-len', ovr);
3632
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3633
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3634

    
3635
		hideClass('dhcp6advanced', !adv || ovr);
3636
	}
3637

    
3638
	function setDHCPoptions() {
3639
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3640
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3641

    
3642
		if (ovr) {
3643
			hideInput('dhcphostname', true);
3644
			hideIpAddress('alias-address', true);
3645
			hideInput('dhcprejectfrom', true);
3646
			hideInput('adv_dhcp_config_file_override_path', false);
3647
			hideClass('dhcpadvanced', true);
3648
		} else {
3649
			hideInput('dhcphostname', false);
3650
			hideIpAddress('alias-address', false);
3651
			hideInput('dhcprejectfrom', false);
3652
			hideInput('adv_dhcp_config_file_override_path', true);
3653
			hideClass('dhcpadvanced', !adv);
3654
		}
3655
	}
3656

    
3657
	// DHCP preset actions
3658
	// Set presets from value of radio buttons
3659
	function setPresets(val) {
3660
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3661
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3662
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3663
		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']);?>");
3664
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3665
	}
3666

    
3667
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3668
		$('#adv_dhcp_pt_timeout').val(timeout);
3669
		$('#adv_dhcp_pt_retry').val(retry);
3670
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3671
		$('#adv_dhcp_pt_reboot').val(reboot);
3672
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3673
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3674
	}
3675

    
3676
	function setDialOnDemandItems() {
3677
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3678
	}
3679

    
3680
	// ---------- On initial page load ------------------------------------------------------------
3681

    
3682
	updateType($('#type').val());
3683
	updateTypeSix($('#type6').val());
3684
	show_reset_settings($('#pppoe-reset-type').val());
3685
	hideClass('dhcp6advanced', true);
3686
	hideClass('dhcpadvanced', true);
3687
	show_dhcp6adv();
3688
	setDHCPoptions();
3689
	setDialOnDemandItems();
3690

    
3691
	// Set preset buttons on page load
3692
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3693
	if (sv == "") {
3694
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3695
	} else {
3696
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3697
	}
3698

    
3699
	// Set preset from value
3700
	setPresets(sv);
3701

    
3702
	// ---------- Click checkbox handlers ---------------------------------------------------------
3703

    
3704
	$('#type').on('change', function() {
3705
		updateType(this.value);
3706
	});
3707

    
3708
	$('#type6').on('change', function() {
3709
		updateTypeSix(this.value);
3710
	});
3711

    
3712
	$('#track6-interface').on('change', function() {
3713
		update_track6_prefix();
3714
	});
3715

    
3716
	$('#pppoe-reset-type').on('change', function() {
3717
		show_reset_settings(this.value);
3718
	});
3719

    
3720
	$("#add").click(function() {
3721
		hide_add_gatewaysave();
3722
	});
3723

    
3724
	$("#cnx").click(function() {
3725
		$("#newgateway").modal('hide');
3726
	});
3727

    
3728
	$("#add6").click(function() {
3729
		hide_add_gatewaysave_v6();
3730
	});
3731

    
3732
	$("#cnx6").click(function() {
3733
		$("#newgateway6").modal('hide');
3734
	});
3735

    
3736
	$('#country').on('change', function() {
3737
		providers_list();
3738
	});
3739

    
3740
	$('#provider_list').on('change', function() {
3741
		providerplan_list();
3742
	});
3743

    
3744
	$('#providerplan').on('change', function() {
3745
		prefill_provider();
3746
	});
3747

    
3748
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3749
		setDHCPoptions();
3750
	});
3751

    
3752
	$('#adv_dhcp6_config_advanced').click(function () {
3753
		show_dhcp6adv();
3754
	});
3755

    
3756
	$('#adv_dhcp6_config_file_override').click(function () {
3757
		show_dhcp6adv();
3758
	});
3759

    
3760
	// On click . .
3761
	$('#pppoe_dialondemand').click(function () {
3762
		setDialOnDemandItems();
3763
	});
3764

    
3765
	$('[name=adv_dhcp_pt_values]').click(function () {
3766
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3767
	});
3768

    
3769
	$('#pppoe_resetdate').datepicker();
3770

    
3771
});
3772
//]]>
3773
</script>
3774

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