Project

General

Profile

Download (124 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
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
##|+PRIV
28
##|*IDENT=page-interfaces
29
##|*NAME=Interfaces: WAN
30
##|*DESCR=Allow access to the 'Interfaces' page.
31
##|*MATCH=interfaces.php*
32
##|-PRIV
33

    
34
require_once("guiconfig.inc");
35
require_once("ipsec.inc");
36
require_once("functions.inc");
37
require_once("captiveportal.inc");
38
require_once("filter.inc");
39
require_once("shaper.inc");
40
require_once("rrd.inc");
41
require_once("vpn.inc");
42
require_once("xmlparse_attr.inc");
43

    
44
define("ANTENNAS", false);
45

    
46
if (isset($_POST['referer'])) {
47
	$referer = $_POST['referer'];
48
} else {
49
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
50
}
51

    
52
// Get configured interface list
53
$ifdescrs = get_configured_interface_with_descr(false, true);
54

    
55
$if = "wan";
56

    
57
if ($_REQUEST['if']) {
58
	$if = $_REQUEST['if'];
59
}
60

    
61
if (empty($ifdescrs[$if])) {
62
	header("Location: interfaces.php");
63
	exit;
64
}
65

    
66
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
67
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
68
define("CRON_DAILY_PATTERN", "0 0 * * *");
69
define("CRON_HOURLY_PATTERN", "0 * * * *");
70

    
71
if (!is_array($pconfig)) {
72
	$pconfig = array();
73
}
74

    
75
if (!is_array($config['ppps'])) {
76
	$config['ppps'] = array();
77
}
78
if (!is_array($config['ppps']['ppp'])) {
79
	$config['ppps']['ppp'] = array();
80
}
81
$a_ppps = &$config['ppps']['ppp'];
82

    
83
function remove_bad_chars($string) {
84
	return preg_replace('/[^a-z_0-9]/i', '', $string);
85
}
86

    
87
if (!is_array($config['gateways']['gateway_item'])) {
88
	$config['gateways']['gateway_item'] = array();
89
}
90

    
91
$a_gateways = &$config['gateways']['gateway_item'];
92

    
93
$wancfg = &$config['interfaces'][$if];
94
$old_wancfg = $wancfg;
95
$old_wancfg['realif'] = get_real_interface($if);
96
$old_ppps = $a_ppps;
97

    
98
// Populate page descr if it does not exist.
99
if ($if == "wan" && !$wancfg['descr']) {
100
	$wancfg['descr'] = "WAN";
101
} else if ($if == "lan" && !$wancfg['descr']) {
102
	$wancfg['descr'] = "LAN";
103
}
104

    
105
/* NOTE: The code here is used to set the $pppid for the curious */
106
foreach ($a_ppps as $pppid => $ppp) {
107
	if ($wancfg['if'] == $ppp['if']) {
108
		break;
109
	}
110
}
111

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

    
114
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
115
	$pconfig['pppid'] = $pppid;
116
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
117
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
118
	if ($a_ppps[$pppid]['type'] == "ppp") {
119
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
120
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
121

    
122
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
123
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
124
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
125
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
126
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
127
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
128
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
129
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
130

    
131
		/* ================================================ */
132
		/* = force a connection reset at a specific time? = */
133
		/* ================================================ */
134

    
135
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
136
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
137
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
138
			if ($itemhash) {
139
				$cronitem = $itemhash['ITEM'];
140
			}
141
			if (isset($cronitem)) {
142
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
143
			} else {
144
				$resetTime = NULL;
145
			}
146
			//log_error("ResetTime:".$resetTime);
147
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
148
				if ($cronitem) {
149
					$pconfig['pppoe_pr_custom'] = true;
150
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
151
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
152
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
153
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
154
					}
155
				}
156
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
157
				$pconfig['pppoe_pr_preset'] = true;
158
				switch ($resetTime) {
159
					case CRON_MONTHLY_PATTERN:
160
						$pconfig['pppoe_monthly'] = true;
161
						break;
162
					case CRON_WEEKLY_PATTERN:
163
						$pconfig['pppoe_weekly'] = true;
164
						break;
165
					case CRON_DAILY_PATTERN:
166
						$pconfig['pppoe_daily'] = true;
167
						break;
168
					case CRON_HOURLY_PATTERN:
169
						$pconfig['pppoe_hourly'] = true;
170
						break;
171
				}
172
			}
173
		} // End force pppoe reset at specific time
174
		// End if type == pppoe
175
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
176
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
177
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
178
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
179
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
180
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
181
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
182
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
183
	}
184
} else {
185
	$pconfig['ptpid'] = interfaces_ptpid_next();
186
	$pppid = count($a_ppps);
187
}
188

    
189
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
190
$pconfig['alias-address'] = $wancfg['alias-address'];
191
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
192
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
193

    
194
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
195
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
196
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
197
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
198
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
199
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
200

    
201
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
202

    
203
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
204
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
205
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
206
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
207

    
208
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
209
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
210
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
211

    
212
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
213
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
214
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
215
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
216

    
217
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
218
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
219
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
220
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
221
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
222

    
223
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
224
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
225
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
226
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
227
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
228

    
229
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
230
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
231

    
232
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
233
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
234
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
235
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
236

    
237
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
238
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
239
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
240
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
241
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
242

    
243
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
244
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
245
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
246

    
247
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
248
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
249
$pconfig['enable'] = isset($wancfg['enable']);
250

    
251
switch ($wancfg['ipaddr']) {
252
	case "dhcp":
253
		$pconfig['type'] = "dhcp";
254
		break;
255
	case "pppoe":
256
	case "pptp":
257
	case "l2tp":
258
	case "ppp":
259
		$pconfig['type'] = $wancfg['ipaddr'];
260
		break;
261
	default:
262
		if (is_ipaddrv4($wancfg['ipaddr'])) {
263
			$pconfig['type'] = "staticv4";
264
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
265
			$pconfig['subnet'] = $wancfg['subnet'];
266
			$pconfig['gateway'] = $wancfg['gateway'];
267
		} else {
268
			$pconfig['type'] = "none";
269
		}
270
		break;
271
}
272

    
273
switch ($wancfg['ipaddrv6']) {
274
	case "slaac":
275
		$pconfig['type6'] = "slaac";
276
		break;
277
	case "dhcp6":
278
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
279
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
280
			$wancfg['dhcp6-ia-pd-len'] = "none";
281
		}
282
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
283
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
284
		$pconfig['type6'] = "dhcp6";
285
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
286
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
287
		$pconfig['dhcp6debug'] = isset($wancfg['dhcp6debug']);
288
		$pconfig['dhcp6withoutra'] = isset($wancfg['dhcp6withoutra']);
289
		$pconfig['dhcp6norelease'] = isset($wancfg['dhcp6norelease']);
290
		break;
291
	case "6to4":
292
		$pconfig['type6'] = "6to4";
293
		break;
294
	case "track6":
295
		$pconfig['type6'] = "track6";
296
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
297
		if ($wancfg['track6-prefix-id'] == "") {
298
			$pconfig['track6-prefix-id'] = 0;
299
		} else {
300
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
301
		}
302
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
303
		break;
304
	case "6rd":
305
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
306
		if ($wancfg['prefix-6rd-v4plen'] == "") {
307
			$wancfg['prefix-6rd-v4plen'] = "0";
308
		}
309
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
310
		$pconfig['type6'] = "6rd";
311
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
312
		break;
313
	default:
314
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
315
			$pconfig['type6'] = "staticv6";
316
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
317
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
318
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
319
		} else {
320
			$pconfig['type6'] = "none";
321
		}
322
		break;
323
}
324

    
325
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
326
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
327
$pconfig['spoofmac'] = $wancfg['spoofmac'];
328
$pconfig['mtu'] = $wancfg['mtu'];
329
$pconfig['mss'] = $wancfg['mss'];
330

    
331
/* Wireless interface? */
332
if (isset($wancfg['wireless'])) {
333
	/* Sync first to be sure it displays the actual settings that will be used */
334
	interface_sync_wireless_clones($wancfg, false);
335
	/* Get wireless modes */
336
	$wlanif = get_real_interface($if);
337
	if (!does_interface_exist($wlanif)) {
338
		interface_wireless_clone($wlanif, $wancfg);
339
	}
340
	$wlanbaseif = interface_get_wireless_base($wancfg['if']);
341
	preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split);
342
	$wl_modes = get_wireless_modes($if);
343
	$wl_chaninfo = get_wireless_channel_info($if);
344
	$wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2];
345
	$wl_sysctl = get_sysctl(
346
		array(
347
			"{$wl_sysctl_prefix}.diversity",
348
			"{$wl_sysctl_prefix}.txantenna",
349
			"{$wl_sysctl_prefix}.rxantenna",
350
			"{$wl_sysctl_prefix}.slottime",
351
			"{$wl_sysctl_prefix}.acktimeout",
352
			"{$wl_sysctl_prefix}.ctstimeout"));
353
	$wl_regdomain_xml_attr = array();
354
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
355
	$wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd'];
356
	$wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd'];
357
	$wl_countries = &$wl_regdomain_xml['country-codes']['country'];
358
	$wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country'];
359
	$pconfig['persistcommonwireless'] = isset($config['wireless']['interfaces'][$wlanbaseif]);
360
	$pconfig['standard'] = $wancfg['wireless']['standard'];
361
	$pconfig['mode'] = $wancfg['wireless']['mode'];
362
	$pconfig['protmode'] = $wancfg['wireless']['protmode'];
363
	$pconfig['ssid'] = $wancfg['wireless']['ssid'];
364
	$pconfig['channel'] = $wancfg['wireless']['channel'];
365
	$pconfig['txpower'] = $wancfg['wireless']['txpower'];
366
	$pconfig['diversity'] = $wancfg['wireless']['diversity'];
367
	$pconfig['txantenna'] = $wancfg['wireless']['txantenna'];
368
	$pconfig['rxantenna'] = $wancfg['wireless']['rxantenna'];
369
	$pconfig['distance'] = $wancfg['wireless']['distance'];
370
	$pconfig['regdomain'] = $wancfg['wireless']['regdomain'];
371
	$pconfig['regcountry'] = $wancfg['wireless']['regcountry'];
372
	$pconfig['reglocation'] = $wancfg['wireless']['reglocation'];
373
	$pconfig['wme_enable'] = isset($wancfg['wireless']['wme']['enable']);
374
	if (isset($wancfg['wireless']['puren']['enable'])) {
375
		$pconfig['puremode'] = '11n';
376
	} else if (isset($wancfg['wireless']['pureg']['enable'])) {
377
		$pconfig['puremode'] = '11g';
378
	} else {
379
		$pconfig['puremode'] = 'any';
380
	}
381
	$pconfig['apbridge_enable'] = isset($wancfg['wireless']['apbridge']['enable']);
382
	$pconfig['authmode'] = $wancfg['wireless']['authmode'];
383
	$pconfig['hidessid_enable'] = isset($wancfg['wireless']['hidessid']['enable']);
384
	$pconfig['auth_server_addr'] = $wancfg['wireless']['auth_server_addr'];
385
	$pconfig['auth_server_port'] = $wancfg['wireless']['auth_server_port'];
386
	$pconfig['auth_server_shared_secret'] = $wancfg['wireless']['auth_server_shared_secret'];
387
	$pconfig['auth_server_addr2'] = $wancfg['wireless']['auth_server_addr2'];
388
	$pconfig['auth_server_port2'] = $wancfg['wireless']['auth_server_port2'];
389
	$pconfig['auth_server_shared_secret2'] = $wancfg['wireless']['auth_server_shared_secret2'];
390
	if (is_array($wancfg['wireless']['wpa'])) {
391
		$pconfig['debug_mode'] = $wancfg['wireless']['wpa']['debug_mode'];
392
		$pconfig['macaddr_acl'] = $wancfg['wireless']['wpa']['macaddr_acl'];
393
		$pconfig['mac_acl_enable'] = isset($wancfg['wireless']['wpa']['mac_acl_enable']);
394
		$pconfig['wpa_mode'] = $wancfg['wireless']['wpa']['wpa_mode'];
395
		$pconfig['wpa_key_mgmt'] = $wancfg['wireless']['wpa']['wpa_key_mgmt'];
396
		$pconfig['wpa_pairwise'] = $wancfg['wireless']['wpa']['wpa_pairwise'];
397
		$pconfig['wpa_group_rekey'] = $wancfg['wireless']['wpa']['wpa_group_rekey'];
398
		$pconfig['wpa_gmk_rekey'] = $wancfg['wireless']['wpa']['wpa_gmk_rekey'];
399
		$pconfig['wpa_strict_rekey'] = isset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
400
		$pconfig['passphrase'] = $wancfg['wireless']['wpa']['passphrase'];
401
		$pconfig['ieee8021x'] = isset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
402
		$pconfig['rsn_preauth'] = isset($wancfg['wireless']['wpa']['rsn_preauth']);
403
		$pconfig['ext_wpa_sw'] = $wancfg['wireless']['wpa']['ext_wpa_sw'];
404
		$pconfig['wpa_enable'] = isset($wancfg['wireless']['wpa']['enable']);
405
	}
406

    
407
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
408

    
409
}
410

    
411
$changes_applied = false;
412

    
413
if ($_POST['apply']) {
414
	unset($input_errors);
415
	if (!is_subsystem_dirty('interfaces')) {
416
		$input_errors[] = gettext("The settings have already been applied!");
417
	} else {
418
		$retval = 0;
419
		unlink_if_exists("{$g['tmp_path']}/config.cache");
420
		clear_subsystem_dirty('interfaces');
421

    
422
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
423
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
424
			foreach ($toapplylist as $ifapply => $ifcfgo) {
425
				if (isset($config['interfaces'][$ifapply]['enable'])) {
426
					interface_bring_down($ifapply, false, $ifcfgo);
427
					interface_configure($ifapply, true);
428
					if ($config['interfaces'][$ifapply]['ipaddrv6'] == "track6") {
429
						/* call interface_track6_configure with linkup true so
430
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
431
						   just call interface_configure with linkup true as
432
						   that skips bridge membership addition.
433
						*/
434
						$wancfg = $config['interfaces'][$ifapply];
435
						interface_track6_configure($ifapply, $wancfg, true);
436
					}
437
				} else {
438
					interface_bring_down($ifapply, true, $ifcfgo);
439
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
440
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
441
						services_dhcpd_configure();
442
					}
443
				}
444
			}
445
		}
446
		/* restart snmp so that it binds to correct address */
447
		$retval |= services_snmpd_configure();
448

    
449
		/* sync filter configuration */
450
		setup_gateways_monitor();
451

    
452
		clear_subsystem_dirty('interfaces');
453

    
454
		$retval |= filter_configure();
455

    
456
		enable_rrd_graphing();
457

    
458
		$changes_applied = true;
459

    
460
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
461
			clear_subsystem_dirty('staticroutes');
462
		}
463
	}
464
	@unlink("{$g['tmp_path']}/.interfaces.apply");
465
} else if ($_POST['save']) {
466

    
467
	unset($input_errors);
468
	$pconfig = $_POST;
469

    
470
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
471
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
472
	} else {
473
		$pconfig['track6-prefix-id'] = 0;
474
	}
475

    
476
	/* filter out spaces from descriptions */
477
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
478

    
479
	/* okay first of all, cause we are just hiding the PPPoE HTML
480
	 * fields related to PPPoE resets, we are going to unset $_POST
481
	 * vars, if the reset feature should not be used. Otherwise the
482
	 * data validation procedure below, may trigger a false error
483
	 * message.
484
	 */
485
	if (empty($_POST['pppoe-reset-type'])) {
486
		unset($_POST['pppoe_pr_type']);
487
		unset($_POST['pppoe_resethour']);
488
		unset($_POST['pppoe_resetminute']);
489
		unset($_POST['pppoe_resetdate']);
490
		unset($_POST['pppoe_pr_preset_val']);
491
	}
492

    
493
	/* input validation */
494
	$reqdfields = explode(" ", "descr");
495
	$reqdfieldsn = array(gettext("Description"));
496
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
497

    
498
	if (!$input_errors) {
499
		/* description unique? */
500
		foreach ($ifdescrs as $ifent => $ifdescr) {
501
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
502
				$input_errors[] = gettext("An interface with the specified description already exists.");
503
				break;
504
			}
505
		}
506

    
507
		/* Is the description already used as an alias name? */
508
		if (is_array($config['aliases']['alias'])) {
509
			foreach ($config['aliases']['alias'] as $alias) {
510
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
511
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
512
				}
513
			}
514
		}
515

    
516
		/* Is the description already used as an interface group name? */
517
		if (is_array($config['ifgroups']['ifgroupentry'])) {
518
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
519
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
520
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
521
				}
522
			}
523
		}
524

    
525
		if (is_numeric($_POST['descr'])) {
526
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
527
		}
528

    
529
		/*
530
		 * Packages (e.g. tinc) create interface groups, reserve this
531
		 * namespace pkg_ for them.
532
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
533
		 */
534
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
535
			$input_errors[] = gettext("The interface description cannot start with pkg_");
536
		}
537
	}
538

    
539
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
540
		if (!preg_match("/^staticv4/", $_POST['type'])) {
541
			$input_errors[] = gettext("The DHCP Server is active " .
542
			    "on this interface and it can be used only with " .
543
			    "a static IP configuration. Please disable the " .
544
			    "DHCP Server service on this interface first, " .
545
			    "then change the interface configuration.");
546
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
547
			$input_errors[] = gettext("The DHCP Server is active " .
548
			    "on this interface and it can be used only with " .
549
			    "IPv4 subnet < 31. Please disable the " .
550
			    "DHCP Server service on this interface first, " .
551
			    "then change the interface configuration.");
552
		}
553
	}
554
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
555
		$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.");
556
	}
557

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

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

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

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

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

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

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

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

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

    
834
		unset($min_mtu, $max_mtu);
835

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

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

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

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

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

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

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

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

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

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

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

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

    
1030
		unset($wancfg['adv_dhcp_pt_values']);
1031

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

    
1037
		unset($wancfg['adv_dhcp_config_advanced']);
1038
		unset($wancfg['adv_dhcp_config_file_override']);
1039
		unset($wancfg['adv_dhcp_config_file_override_path']);
1040

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

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

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

    
1058
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1059
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1060

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

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

    
1072
		unset($wancfg['adv_dhcp6_config_advanced']);
1073
		unset($wancfg['adv_dhcp6_config_file_override']);
1074
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1075

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

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

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

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

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

    
1134
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1135

    
1136
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1137
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1138
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1139
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1140

    
1141
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1142
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1143
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1144

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

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

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

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

    
1266
				if ($_POST['dhcp6withoutra'] == "yes") {
1267
					$wancfg['dhcp6withoutra'] = true;
1268
				}
1269
				if ($_POST['dhcp6norelease'] == "yes") {
1270
					$wancfg['dhcp6norelease'] = true;
1271
				}
1272
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1273
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1274
				}
1275
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1276
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1277
				}
1278
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1279
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1280
				}
1281
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1282
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1283
				}
1284

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

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

    
1317
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1318
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1319
				}
1320
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1321
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1322
				}
1323

    
1324
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1325
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1326
				}
1327
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1328
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1329
				}
1330
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1331
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1332
				}
1333
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1334
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1335
				}
1336

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

    
1353
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1354
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1355
				}
1356
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1357
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1358
				}
1359
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1360
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1361
				}
1362

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

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

    
1434
		write_config();
1435

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

    
1445
		mark_subsystem_dirty('interfaces');
1446

    
1447
		/* regenerate cron settings/crontab file */
1448
		configure_cron();
1449

    
1450
		header("Location: interfaces.php?if={$if}");
1451
		exit;
1452
	}
1453

    
1454
} // end if ($_POST['save'])
1455

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

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

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

    
1605
	interface_sync_wireless_clones($wancfg, true);
1606
}
1607

    
1608
function check_wireless_mode() {
1609
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1610

    
1611
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1612
		return;
1613
	}
1614

    
1615
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1616
		$clone_count = 1;
1617
	} else {
1618
		$clone_count = 0;
1619
	}
1620

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

    
1629
	if ($clone_count > 1) {
1630
		$old_wireless_mode = $wancfg['wireless']['mode'];
1631
		$wancfg['wireless']['mode'] = $_POST['mode'];
1632
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1633
			$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']]);
1634
		} else {
1635
			pfSense_interface_destroy("{$wlanif}_");
1636
		}
1637
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1638
	}
1639
}
1640

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

    
1656
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1657
$shortcut_section = "interfaces";
1658

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

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

    
1667
function build_mediaopts_list() {
1668
	global $mediaopts_list;
1669

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

    
1674
	foreach ($mediaopts_list as $mediaopt) {
1675
		$list[$mediaopt] = $mediaopt;
1676
	}
1677

    
1678
	return($list);
1679
}
1680

    
1681
function build_gateway_list() {
1682
	global $a_gateways, $if;
1683

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

    
1691
	return($list);
1692
}
1693

    
1694
function build_gatewayv6_list() {
1695
	global $a_gateways, $if;
1696

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

    
1704
	return($list);
1705
}
1706

    
1707
include("head.inc");
1708

    
1709
if ($input_errors) {
1710
	print_input_errors($input_errors);
1711
}
1712

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

    
1719
if ($changes_applied) {
1720
	print_apply_result_box($retval);
1721
}
1722

    
1723
$form = new Form();
1724

    
1725
$section = new Form_Section('General Configuration');
1726

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

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

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

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

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

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

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

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

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

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

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

    
1806
$form->add($section);
1807

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

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

    
1818
$group = new Form_Group('IPv4 Upstream gateway');
1819

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

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

    
1834
$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.%1$s' .
1835
				'On local area network interfaces the upstream gateway should be "none". ' .
1836
				'Gateways can be managed by %2$sclicking here%3$s.', '<br />', '<a target="_blank" href="system_gateways.php">', '</a>');
1837

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

    
1840
$form->add($section);
1841

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

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

    
1852
$group = new Form_Group('IPv6 Upstream gateway');
1853

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

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

    
1868
$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.%s' .
1869
				'On local LANs the upstream gateway should be "none". ', '<br />');
1870

    
1871
$section->add($group);
1872
$form->add($section);
1873

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

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

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

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

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

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

    
1911
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1912

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

    
1920
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1921

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

    
1927
$form->add($modal);
1928

    
1929
// ==== DHCP client configuration =============================
1930

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

    
1934
$group = new Form_Group('Options');
1935

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

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

    
1950
$section->add($group);
1951

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

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

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

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

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

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

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

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

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

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

    
2020
$section->add($group);
2021

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

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

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

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

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

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

    
2060
$section->add($group);
2061

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

    
2072
$form->add($section);
2073

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

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

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

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

    
2102
$section->addInput(new Form_Input(
2103
	'adv_dhcp_option_modifiers',
2104
	'Option modifiers',
2105
	'text',
2106
	$pconfig['adv_dhcp_option_modifiers']
2107
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2108
			'modifiers: (default, supersede, prepend, append) %1$s' .
2109
			'See %2$shere%3$s more information', '<br />', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">', '</a>');
2110

    
2111
$form->add($section);
2112

    
2113
// DHCP6 client config
2114

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

    
2118
$group = new Form_Group('Options');
2119

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

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

    
2134
$section->add($group);
2135

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

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

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

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

    
2164
$section->addInput(new Form_Checkbox(
2165
	'dhcp6debug',
2166
	'Debug',
2167
	'Start DHCP6 client in debug mode',
2168
	$pconfig['dhcp6debug']
2169
));
2170
$section->addInput(new Form_Checkbox(
2171
	'dhcp6withoutra',
2172
	'Do not wait for a RA',
2173
	'Required by some ISPs, especially those not using PPPoE',
2174
	$pconfig['dhcp6withoutra']
2175
));
2176
$section->addInput(new Form_Checkbox(
2177
	'dhcp6norelease',
2178
	'Do not allow PD/Address release',
2179
	'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',
2180
	$pconfig['dhcp6norelease']
2181
));
2182
$section->addInput(new Form_Input(
2183
	'adv_dhcp6_config_file_override_path',
2184
	'Configuration File Override',
2185
	'text',
2186
	$pconfig['adv_dhcp6_config_file_override_path']
2187
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2188
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2189
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2190
			'Some ISPs may require certain options be or not be sent.', '<br />');
2191

    
2192
$form->add($section);
2193

    
2194
// DHCP6 client config - Advanced
2195

    
2196
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2197
$section->addClass('dhcp6advanced');
2198

    
2199
$section->addInput(new Form_Checkbox(
2200
	'adv_dhcp6_interface_statement_information_only_enable',
2201
	'Information only',
2202
	'Exchange Information Only',
2203
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2204
	'Selected'
2205
))->setHelp('Only exchange informational configuration parameters with servers.');
2206

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

    
2217
$section->addInput(new Form_Input(
2218
	'adv_dhcp6_interface_statement_request_options',
2219
	'Request Options',
2220
	'text',
2221
	$pconfig['adv_dhcp6_interface_statement_request_options']
2222
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2223
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2224

    
2225
$section->addInput(new Form_Input(
2226
	'adv_dhcp6_interface_statement_script',
2227
	'Scripts',
2228
	'text',
2229
	$pconfig['adv_dhcp6_interface_statement_script']
2230
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2231
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2232

    
2233
$group = new Form_Group('Identity Association Statement');
2234

    
2235
$group->add(new Form_Checkbox(
2236
	'adv_dhcp6_id_assoc_statement_address_enable',
2237
	null,
2238
	'Non-Temporary Address Allocation',
2239
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2240
	'Selected'
2241
));
2242

    
2243
$group->add(new Form_Input(
2244
	'adv_dhcp6_id_assoc_statement_address_id',
2245
	null,
2246
	'text',
2247
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2248
))->sethelp('id-assoc na ID');
2249

    
2250
$group->add(new Form_IpAddress(
2251
	'adv_dhcp6_id_assoc_statement_address',
2252
	null,
2253
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2254
	'V6'
2255
))->sethelp('IPv6 address');
2256

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

    
2264
$group->add(new Form_Input(
2265
	'adv_dhcp6_id_assoc_statement_address_vltime',
2266
	null,
2267
	'text',
2268
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2269
))->sethelp('vltime');
2270

    
2271
$section->add($group);
2272

    
2273
// Prefix delegation
2274
$group = new Form_Group('');
2275

    
2276
$group->add(new Form_Checkbox(
2277
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2278
	null,
2279
	'Prefix Delegation ',
2280
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2281
	'Selected'
2282
));
2283

    
2284
$group->add(new Form_Input(
2285
	'adv_dhcp6_id_assoc_statement_prefix_id',
2286
	null,
2287
	'text',
2288
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2289
))->sethelp('id-assoc pd ID');
2290

    
2291
$group->add(new Form_IpAddress(
2292
	'adv_dhcp6_id_assoc_statement_prefix',
2293
	null,
2294
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2295
	'V6'
2296
))->sethelp('IPv6 prefix');
2297

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

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

    
2312
$section->add($group);
2313

    
2314
$group = new Form_Group('Prefix interface statement');
2315

    
2316
$group->add(new Form_Input(
2317
	'adv_dhcp6_prefix_interface_statement_sla_id',
2318
	null,
2319
	'text',
2320
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2321
))->sethelp('Prefix Interface sla-id');
2322

    
2323
$group->add(new Form_Input(
2324
	'adv_dhcp6_prefix_interface_statement_sla_len',
2325
	null,
2326
	'text',
2327
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2328
))->sethelp('sla-len');
2329

    
2330
$section->add($group);
2331

    
2332
$group = new Form_Group('Authentication statement');
2333

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

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

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

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

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

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

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

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

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

    
2382
$group = new Form_Group('');
2383

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

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

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

    
2405
$group->setHelp('See %1$shere%2$s more information', '<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">', '</a>');
2406

    
2407
$section->add($group);
2408

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

    
2411
$section = new Form_Section('6RD Configuration');
2412
$section->addClass('_6rd');
2413

    
2414
$section->addInput(new Form_Input(
2415
	'prefix-6rd',
2416
	'6RD Prefix',
2417
	'text',
2418
	$pconfig['prefix-6rd']
2419
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2420

    
2421
$section->addInput(new Form_Input(
2422
	'gateway-6rd',
2423
	'*6RD Border relay',
2424
	'text',
2425
	$pconfig['gateway-6rd']
2426
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2427

    
2428
$section->addInput(new Form_Select(
2429
	'prefix-6rd-v4plen',
2430
	'6RD IPv4 Prefix length',
2431
	$pconfig['prefix-6rd-v4plen'],
2432
	array_combine(range(0, 32), range(0, 32))
2433
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2434

    
2435
$form->add($section);
2436

    
2437
// Track IPv6 ointerface section
2438
$section = new Form_Section('Track IPv6 Interface');
2439
$section->addClass('track6');
2440

    
2441
function build_ipv6interface_list() {
2442
	global $config, $section;
2443

    
2444
	$list = array('' => '');
2445

    
2446
	$interfaces = get_configured_interface_with_descr(false, true);
2447
	$dynv6ifs = array();
2448

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

    
2464
	foreach ($dynv6ifs as $iface => $ifacedata) {
2465
		$list[$iface] = $ifacedata['name'];
2466

    
2467
		$section->addInput(new Form_Input(
2468
			'ipv6-num-prefix-ids-' . $iface,
2469
			null,
2470
			'hidden',
2471
			$ifacedata['ipv6_num_prefix_ids']
2472
		));
2473
	}
2474

    
2475
	return($list);
2476
}
2477

    
2478
$section->addInput(new Form_Select(
2479
	'track6-interface',
2480
	'*IPv6 Interface',
2481
	$pconfig['track6-interface'],
2482
	build_ipv6interface_list()
2483
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2484

    
2485
if ($pconfig['track6-prefix-id'] == "") {
2486
	$pconfig['track6-prefix-id'] = 0;
2487
}
2488

    
2489
$section->addInput(new Form_Input(
2490
	'track6-prefix-id--hex',
2491
	'IPv6 Prefix ID',
2492
	'text',
2493
	sprintf("%x", $pconfig['track6-prefix-id'])
2494
))->setHelp('(%1$shexadecimal%2$s from 0 to %3$s) 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.', '<b>', '</b>', '<span id="track6-prefix-id-range"></span>');
2495

    
2496
$section->addInput(new Form_Input(
2497
	'track6-prefix-id-max',
2498
	null,
2499
	'hidden',
2500
	0
2501
));
2502

    
2503
$form->add($section);
2504

    
2505
/// PPP section
2506

    
2507
$section = new Form_Section('PPP Configuration');
2508
$section->addClass('ppp');
2509

    
2510
$section->addInput(new Form_Select(
2511
	'country',
2512
	'Country',
2513
	$pconfig['country'],
2514
	[]
2515
));
2516

    
2517
$section->addInput(new Form_Select(
2518
	'provider_list',
2519
	'Provider',
2520
	$pconfig['provider_list'],
2521
	[]
2522
));
2523

    
2524
$section->addInput(new Form_Select(
2525
	'providerplan',
2526
	'Plan',
2527
	$pconfig['providerplan'],
2528
	[]
2529
))->setHelp('Select to fill in service provider data.');
2530

    
2531
$section->addInput(new Form_Input(
2532
	'ppp_username',
2533
	'Username',
2534
	'text',
2535
	$pconfig['ppp_username']
2536
));
2537

    
2538
$section->addPassword(new Form_Input(
2539
	'ppp_password',
2540
	'Password',
2541
	'password',
2542
	$pconfig['ppp_password']
2543
));
2544

    
2545
$section->addInput(new Form_Input(
2546
	'phone',
2547
	'*Phone number',
2548
	'text',
2549
	$pconfig['phone']
2550
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2551

    
2552
$section->addInput(new Form_Input(
2553
	'apn',
2554
	'Access Point Name',
2555
	'text',
2556
	$pconfig['apn']
2557
));
2558

    
2559

    
2560
function build_port_list() {
2561
	$list = array("" => "None");
2562

    
2563
	$portlist = glob("/dev/cua*");
2564
	$modems	  = glob("/dev/modem*");
2565
	$portlist = array_merge($portlist, $modems);
2566

    
2567
	foreach ($portlist as $port) {
2568
		if (preg_match("/\.(lock|init)$/", $port)) {
2569
			continue;
2570
		}
2571

    
2572
	$list[trim($port)] = $port;
2573
	}
2574

    
2575
	return($list);
2576
}
2577

    
2578
$section->addInput(new Form_Select(
2579
	'port',
2580
	"*Modem port",
2581
	$pconfig['port'],
2582
	build_port_list()
2583
));
2584

    
2585
$section->addInput(new Form_Button(
2586
	'btnadvppp',
2587
	'Advanced PPP',
2588
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2589
	'fa-cog'
2590
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2591

    
2592
$form->add($section);
2593

    
2594
// PPPoE configuration
2595
$section = new Form_Section('PPPoE Configuration');
2596
$section->addClass('pppoe');
2597

    
2598
$section->addInput(new Form_Input(
2599
	'pppoe_username',
2600
	'*Username',
2601
	'text',
2602
	$pconfig['pppoe_username']
2603
));
2604

    
2605
$section->addPassword(new Form_Input(
2606
	'pppoe_password',
2607
	'*Password',
2608
	'password',
2609
	$pconfig['pppoe_password']
2610
));
2611

    
2612
$section->addInput(new Form_Input(
2613
	'provider',
2614
	'Service name',
2615
	'text',
2616
	$pconfig['provider']
2617
))->setHelp('This field can usually be left empty.');
2618

    
2619
$section->addInput(new Form_Checkbox(
2620
	'pppoe_dialondemand',
2621
	'Dial on demand',
2622
	'Enable Dial-On-Demand mode ',
2623
	$pconfig['pppoe_dialondemand'],
2624
	'enable'
2625
));
2626

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

    
2636
$section->addInput(new Form_Select(
2637
	'pppoe-reset-type',
2638
	'Periodic reset',
2639
	$pconfig['pppoe-reset-type'],
2640
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2641
))->setHelp('Select a reset timing type.');
2642

    
2643
$group = new Form_Group('Custom reset');
2644
$group->addClass('pppoecustom');
2645

    
2646
$group->add(new Form_Input(
2647
	'pppoe_resethour',
2648
	null,
2649
	'number',
2650
	$pconfig['pppoe_resethour'],
2651
	['min' => 0, 'max' => 23]
2652
))->setHelp('Hour (0-23)');
2653

    
2654
$group->add(new Form_Input(
2655
	'pppoe_resetminute',
2656
	null,
2657
	'number',
2658
	$pconfig['pppoe_resetminute'],
2659
	['min' => 0, 'max' => 59]
2660
))->setHelp('Minutes (0-59)');
2661

    
2662
$group->add(new Form_Input(
2663
	'pppoe_resetdate',
2664
	null,
2665
	'text',
2666
	$pconfig['pppoe_resetdate']
2667
))->setHelp('Specific date (mm/dd/yyyy)');
2668

    
2669
$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');
2670

    
2671
$section->add($group);
2672

    
2673
$group = new Form_MultiCheckboxGroup('cron based reset');
2674
$group->addClass('pppoepreset');
2675

    
2676
$group->add(new Form_MultiCheckbox(
2677
	'pppoe_pr_preset_val',
2678
	null,
2679
	'Reset at each month ("0 0 1 * *")',
2680
	$pconfig['pppoe_monthly'],
2681
	'monthly'
2682
))->displayAsRadio();
2683

    
2684
$group->add(new Form_MultiCheckbox(
2685
	'pppoe_pr_preset_val',
2686
	null,
2687
	'Reset at each week ("0 0 * * 0")',
2688
	$pconfig['pppoe_weekly'],
2689
	'weekly'
2690
))->displayAsRadio();
2691

    
2692
$group->add(new Form_MultiCheckbox(
2693
	'pppoe_pr_preset_val',
2694
	null,
2695
	'Reset at each day ("0 0 * * *")',
2696
	$pconfig['pppoe_daily'],
2697
	'daily'
2698
))->displayAsRadio();
2699

    
2700
$group->add(new Form_MultiCheckbox(
2701
	'pppoe_pr_preset_val',
2702
	null,
2703
	'Reset at each hour ("0 * * * *")',
2704
	$pconfig['pppoe_hourly'],
2705
	'hourly'
2706
))->displayAsRadio();
2707

    
2708
$section->add($group);
2709

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

    
2717
$form->add($section);
2718

    
2719
// PPTP & L2TP Configuration section
2720
$section = new Form_Section('PPTP/L2TP Configuration');
2721
$section->addClass('pptp');
2722

    
2723
$section->addInput(new Form_Input(
2724
	'pptp_username',
2725
	'*Username',
2726
	'text',
2727
	$pconfig['pptp_username']
2728
));
2729

    
2730
$section->addPassword(new Form_Input(
2731
	'pptp_password',
2732
	'*Password',
2733
	'password',
2734
	$pconfig['pptp_password']
2735
));
2736

    
2737
$section->addInput(new Form_IpAddress(
2738
	'pptp_local0',
2739
	'*Local IP address',
2740
	$pconfig['pptp_localip'][0],
2741
	'V4'
2742
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2743

    
2744
$section->addInput(new Form_IpAddress(
2745
	'pptp_remote0',
2746
	'*Remote IP address',
2747
	$pconfig['pptp_remote'][0],
2748
	'HOSTV4'
2749
));
2750

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

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

    
2769
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2770
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2771
} else {
2772
	$mlppp_text = "";
2773
}
2774

    
2775
$section->addInput(new Form_Button(
2776
	'btnadvppp',
2777
	'Advanced and MLPPP',
2778
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2779
	'fa-cog'
2780
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('%sClick for additional PPTP and L2TP configuration options. Save first if changes have been made.', $mlppp_text);
2781

    
2782
$form->add($section);
2783

    
2784
// Wireless interface
2785
if (isset($wancfg['wireless'])) {
2786

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

    
2789
	$section->addInput(new Form_Checkbox(
2790
		'persistcommonwireless',
2791
		'Persist common settings',
2792
		'Preserve common wireless configuration through interface deletions and reassignments.',
2793
		$pconfig['persistcommonwireless'],
2794
		'yes'
2795
	));
2796

    
2797
	$mode_list = ['auto' => 'Auto'];
2798

    
2799
	if (is_array($wl_modes)) {
2800
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2801
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2802
		}
2803
	}
2804

    
2805
	if (count($mode_list) == 1) {
2806
		$mode_list[''] = '';
2807
	}
2808

    
2809
	$section->addInput(new Form_Select(
2810
		'standard',
2811
		'Standard',
2812
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2813
		$mode_list
2814
	));
2815

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

    
2832
	$mode_list = ['0' => gettext('Auto')];
2833

    
2834
	if (is_array($wl_modes)) {
2835
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2836
			if ($wl_standard == "11g") {
2837
				$wl_standard = "11b/g";
2838
			} else if ($wl_standard == "11ng") {
2839
				$wl_standard = "11b/g/n";
2840
			} else if ($wl_standard == "11na") {
2841
				$wl_standard = "11a/n";
2842
			}
2843

    
2844
			foreach ($wl_channels as $wl_channel) {
2845
				if (isset($wl_chaninfo[$wl_channel])) {
2846
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2847
				} else {
2848
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2849
				}
2850
			}
2851
		}
2852
	}
2853

    
2854
	$section->addInput(new Form_Select(
2855
		'channel',
2856
		'Channel',
2857
		$pconfig['channel'],
2858
		$mode_list
2859
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2860
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2861

    
2862
	if (ANTENNAS) {
2863
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2864
			$group = new Form_Group('Antenna Settings');
2865

    
2866
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2867
				$group->add(new Form_Select(
2868
					'diversity',
2869
					null,
2870
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2871
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2872
				))->setHelp('Diversity');
2873
			}
2874

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

    
2884
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2885
				$group->add(new Form_Select(
2886
					'rxantenna',
2887
					null,
2888
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2889
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2890
				))->setHelp('Receive antenna');
2891
			}
2892

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

    
2895
			$section->add($group);
2896
		}
2897
	}
2898

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

    
2908
	$form->add($section);
2909

    
2910
	// Regulatory settings
2911
	$section = new Form_Section('Regulatory Settings');
2912

    
2913
	$domain_list = array("" => 'Default');
2914

    
2915
	if (is_array($wl_regdomains)) {
2916
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2917
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2918
		}
2919
	}
2920

    
2921
	$section->addInput(new Form_Select(
2922
		'regdomain',
2923
		'Regulatory domain',
2924
		$pconfig['regdomain'],
2925
		$domain_list
2926
	))->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');
2927

    
2928
	$country_list = array('' => 'Default');
2929

    
2930
	if (is_array($wl_countries)) {
2931
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2932
			$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']);
2933
		}
2934
	}
2935

    
2936
	$section->addInput(new Form_Select(
2937
		'regcountry',
2938
		'Country',
2939
		$pconfig['regcountry'],
2940
		$country_list
2941
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2942

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

    
2954
	$form->add($section);
2955

    
2956
	$section = new Form_Section('Network-Specific Wireless Configuration');
2957

    
2958
	$section->addInput(new Form_Select(
2959
		'mode',
2960
		'Mode',
2961
		$pconfig['mode'],
2962
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2963
	));
2964

    
2965
	$section->addInput(new Form_Input(
2966
		'ssid',
2967
		'SSID',
2968
		'text',
2969
		$pconfig['ssid']
2970
	));
2971

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

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

    
2997
	$section->addInput(new Form_Checkbox(
2998
		'wme_enable',
2999
		'Enable WME',
3000
		'Force the card to use WME (wireless QoS)',
3001
		$pconfig['wme_enable'],
3002
		'yes'
3003
	));
3004

    
3005
	$section->addInput(new Form_Checkbox(
3006
		'hidessid_enable',
3007
		'Hide SSID',
3008
		'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.)',
3009
		$pconfig['hidessid_enable'],
3010
		'yes'
3011
	));
3012

    
3013
	$form->add($section);
3014

    
3015
	// WPA Section
3016
	$section = new Form_Section('WPA');
3017

    
3018
	$section->addInput(new Form_Checkbox(
3019
		'wpa_enable',
3020
		'Enable',
3021
		'Enable WPA',
3022
		$pconfig['wpa_enable'],
3023
		'yes'
3024
	));
3025

    
3026
	$section->addInput(new Form_Input(
3027
		'passphrase',
3028
		'WPA Pre-Shared Key',
3029
		'text',
3030
		$pconfig['passphrase']
3031
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3032

    
3033
	$section->addInput(new Form_Select(
3034
		'wpa_mode',
3035
		'WPA mode',
3036
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3037
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3038
	));
3039

    
3040
	$section->addInput(new Form_Select(
3041
		'wpa_key_mgmt',
3042
		'WPA Key Management Mode',
3043
		$pconfig['wpa_key_mgmt'],
3044
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3045
	));
3046

    
3047
	$section->addInput(new Form_Select(
3048
		'wpa_pairwise',
3049
		'WPA Pairwise',
3050
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3051
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3052
	));
3053

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

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

    
3070
	$section->addInput(new Form_Checkbox(
3071
		'wpa_strict_rekey',
3072
		'Strict Key Regeneration',
3073
		'Force the AP to rekey whenever a client disassociates',
3074
		$pconfig['wpa_strict_rekey'],
3075
		'yes'
3076
	));
3077

    
3078
	$form->add($section);
3079

    
3080
	$section = new Form_Section('802.1x RADIUS Options');
3081

    
3082
	$section->addInput(new Form_Checkbox(
3083
		'ieee8021x',
3084
		'IEEE802.1X',
3085
		'Enable 802.1X authentication',
3086
		$pconfig['ieee8021x'],
3087
		'yes'
3088
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3089

    
3090
	$group = new Form_Group('Primary 802.1X server');
3091

    
3092
	$group->add(new Form_IpAddress(
3093
		'auth_server_addr',
3094
		'IP Address',
3095
		$pconfig['auth_server_addr']
3096
	))->setHelp('IP address of the RADIUS server');
3097

    
3098
	$group->add(new Form_Input(
3099
		'auth_server_port',
3100
		'Port',
3101
		'number',
3102
		$pconfig['auth_server_port']
3103
	))->setHelp('Server auth port. Default is 1812');
3104

    
3105
	$group->add(new Form_Input(
3106
		'auth_server_shared_secret',
3107
		'Shared Secret',
3108
		'text',
3109
		$pconfig['auth_server_shared_secret']
3110
	))->setHelp('RADIUS Shared secret for this firewall');
3111

    
3112
	$section->add($group);
3113

    
3114
	$group = new Form_Group('Secondary 802.1X server');
3115

    
3116
	$group->add(new Form_IpAddress(
3117
		'auth_server_addr2',
3118
		'IP Address',
3119
		$pconfig['auth_server_addr2']
3120
	))->setHelp('IP address of the RADIUS server');
3121

    
3122
	$group->add(new Form_Input(
3123
		'auth_server_port2',
3124
		'Port',
3125
		'number',
3126
		$pconfig['auth_server_port2']
3127
	))->setHelp('Server auth port. Default is 1812');
3128

    
3129
	$group->add(new Form_Input(
3130
		'auth_server_shared_secret2',
3131
		'Shared Secret',
3132
		'text',
3133
		$pconfig['auth_server_shared_secret2']
3134
	))->setHelp('RADIUS Shared secret for this firewall');
3135

    
3136
	$section->add($group);
3137

    
3138
	$section->addInput(new Form_Checkbox(
3139
		'rsn_preauth',
3140
		'Authentication Roaming Preauth',
3141
		null,
3142
		$pconfig['rsn_preauth'],
3143
		'yes'
3144
	));
3145

    
3146
	$form->add($section);
3147
}
3148

    
3149
$section = new Form_Section('Reserved Networks');
3150

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

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

    
3171
$form->add($section);
3172

    
3173
$form->addGlobal(new Form_Input(
3174
	'if',
3175
	null,
3176
	'hidden',
3177
	$if
3178
));
3179

    
3180
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3181
	$form->addGlobal(new Form_Input(
3182
		'ppp_port',
3183
		null,
3184
		'hidden',
3185
		$pconfig['port']
3186
	));
3187
}
3188

    
3189
$form->addGlobal(new Form_Input(
3190
	'ptpid',
3191
	null,
3192
	'hidden',
3193
	$pconfig['ptpid']
3194
));
3195

    
3196

    
3197
// Add new gateway modal pop-up
3198
$modal = new Modal('New Gateway', 'newgateway', 'large');
3199

    
3200
$modal->addInput(new Form_Checkbox(
3201
	'defaultgw',
3202
	'Default',
3203
	'Default gateway',
3204
	($if == "wan" || $if == "WAN")
3205
));
3206

    
3207
$modal->addInput(new Form_Input(
3208
	'name',
3209
	'Gateway name',
3210
	'text',
3211
	$wancfg['descr'] . "GW"
3212
));
3213

    
3214
$modal->addInput(new Form_IpAddress(
3215
	'gatewayip',
3216
	'Gateway IPv4',
3217
	null,
3218
	'V4'
3219
));
3220

    
3221
$modal->addInput(new Form_Input(
3222
	'gatewaydescr',
3223
	'Description',
3224
	'text'
3225
));
3226

    
3227
$btnaddgw = new Form_Button(
3228
	'add',
3229
	'Add',
3230
	null,
3231
	'fa-plus'
3232
);
3233

    
3234
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3235

    
3236
$btncnxgw = new Form_Button(
3237
	'cnx',
3238
	'Cancel',
3239
	null,
3240
	'fa-undo'
3241
);
3242

    
3243
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3244

    
3245
$modal->addInput(new Form_StaticText(
3246
	null,
3247
	$btnaddgw . $btncnxgw
3248
));
3249

    
3250
$form->add($modal);
3251

    
3252
print($form);
3253
?>
3254

    
3255
<script type="text/javascript">
3256
//<![CDATA[
3257
events.push(function() {
3258
	function updateType(t) {
3259

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

    
3294
		if (t != "l2tp" && t != "pptp") {
3295
			$('.'+t).show();
3296
		}
3297
	}
3298

    
3299
	function updateTypeSix(t) {
3300
		if (!isNaN(t[0])) {
3301
			t = '_' + t;
3302
		}
3303

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

    
3336
		if (t != "l2tp" && t != "pptp") {
3337
			$('.'+t).show();
3338
		}
3339
	}
3340

    
3341
	function show_reset_settings(reset_type) {
3342
		if (reset_type == 'preset') {
3343
			$('.pppoepreset').show();
3344
			$('.pppoecustom').hide();
3345
		} else if (reset_type == 'custom') {
3346
			$('.pppoecustom').show();
3347
			$('.pppoepreset').hide();
3348
		} else {
3349
			$('.pppoecustom').hide();
3350
			$('.pppoepreset').hide();
3351
		}
3352
	}
3353

    
3354
	function update_track6_prefix() {
3355
		var iface = $("#track6-interface").val();
3356
		if (iface == null) {
3357
			return;
3358
		}
3359

    
3360
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3361
		if (track6_prefix_ids == null) {
3362
			return;
3363
		}
3364

    
3365
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3366
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3367
	}
3368

    
3369
	// Create the new gateway from the data entered in the modal pop-up
3370
	function hide_add_gatewaysave() {
3371
		var iface = $('#if').val();
3372
		name = $('#name').val();
3373
		var descr = $('#gatewaydescr').val();
3374
		gatewayip = $('#gatewayip').val();
3375

    
3376
		var defaultgw = '';
3377
		if ($('#defaultgw').is(':checked')) {
3378
			defaultgw = '&defaultgw=on';
3379
		}
3380

    
3381
		var url = "system_gateways_edit.php";
3382
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3383
		$.ajax(
3384
			url,
3385
			{
3386
				type: 'post',
3387
				data: pars,
3388
				error: report_failure,
3389
				complete: save_callback
3390
			});
3391
		}
3392

    
3393
	function save_callback(response) {
3394
		if (response) {
3395
			var gwtext = escape(name) + " - " + gatewayip;
3396
			addOption($('#gateway'), gwtext, name);
3397
		} else {
3398
			report_failure();
3399
		}
3400

    
3401
		$("#newgateway").modal('hide');
3402
	}
3403

    
3404
	function report_failure(request, textStatus, errorThrown) {
3405
		contenttype = ";"+request.getResponseHeader("Content-Type")+";";
3406
		if (textStatus === "error" && contenttype.indexOf(";text/plain;") !== -1) {
3407
			alert(request.responseText);
3408
		} else {
3409
			alert("The IPv4 gateway could not be created.");
3410
		}
3411

    
3412
		$("#newgateway").modal('hide');
3413
	}
3414

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

    
3423
	function hide_add_gatewaysave_v6() {
3424

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

    
3445

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

    
3454
	function report_failure_v6(request, textStatus, errorThrown) {
3455
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3456
			alert(request.responseText);
3457
		} else {
3458
			alert("The IPv6 gateway could not be created.");
3459
		}
3460

    
3461
		$("#newgateway6").modal('hide');
3462
	}
3463

    
3464
	function save_callback_v6(response_v6) {
3465
		if (response_v6) {
3466

    
3467
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3468
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3469
		} else {
3470
			report_failure_v6();
3471
		}
3472

    
3473
		$("#newgateway6").modal('hide');
3474
	}
3475

    
3476
	function country_list() {
3477
		$('#country').children().remove();
3478
		$('#provider_list').children().remove();
3479
		$('#providerplan').children().remove();
3480
		$.ajax("getserviceproviders.php",{
3481
			success: function(response) {
3482

    
3483
				var responseTextArr = response.split("\n");
3484
				responseTextArr.sort();
3485

    
3486
				responseTextArr.forEach( function(value) {
3487
					country = value.split(":");
3488
					$('#country').append($('<option>', {
3489
						value: country[1],
3490
						text : country[0]
3491
					}));
3492
				});
3493
			}
3494
		});
3495
	}
3496

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

    
3516
	function providerplan_list() {
3517
		$('#providerplan').children().remove();
3518
		$.ajax("getserviceproviders.php",{
3519
			type: 'post',
3520
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3521
			success: function(response) {
3522
				var responseTextArr = response.split("\n");
3523
				responseTextArr.sort();
3524

    
3525
				$('#providerplan').append($('<option>', {
3526
					value: '',
3527
					text : ''
3528
				}));
3529

    
3530
				responseTextArr.forEach( function(value) {
3531
					if (value != "") {
3532
						providerplan = value.split(":");
3533

    
3534
						$('#providerplan').append($('<option>', {
3535
							value: providerplan[1],
3536
							text : providerplan[0] + " - " + providerplan[1]
3537
						}));
3538
					}
3539
				});
3540
			}
3541
		});
3542
	}
3543

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

    
3568
	function show_dhcp6adv() {
3569
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3570
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3571

    
3572
		hideCheckbox('dhcp6usev4iface', ovr);
3573
		hideCheckbox('dhcp6prefixonly', ovr);
3574
		hideInput('dhcp6-ia-pd-len', ovr);
3575
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3576
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3577

    
3578
		hideClass('dhcp6advanced', !adv || ovr);
3579
	}
3580

    
3581
	function setDHCPoptions() {
3582
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3583
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3584

    
3585
		if (ovr) {
3586
			hideInput('dhcphostname', true);
3587
			hideIpAddress('alias-address', true);
3588
			hideInput('dhcprejectfrom', true);
3589
			hideInput('adv_dhcp_config_file_override_path', false);
3590
			hideClass('dhcpadvanced', true);
3591
		} else {
3592
			hideInput('dhcphostname', false);
3593
			hideIpAddress('alias-address', false);
3594
			hideInput('dhcprejectfrom', false);
3595
			hideInput('adv_dhcp_config_file_override_path', true);
3596
			hideClass('dhcpadvanced', !adv);
3597
		}
3598
	}
3599

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

    
3610
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3611
		$('#adv_dhcp_pt_timeout').val(timeout);
3612
		$('#adv_dhcp_pt_retry').val(retry);
3613
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3614
		$('#adv_dhcp_pt_reboot').val(reboot);
3615
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3616
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3617
	}
3618

    
3619
	function setPPPoEDialOnDemandItems() {
3620
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3621
	}
3622

    
3623
	function setPPTPDialOnDemandItems() {
3624
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3625
	}
3626

    
3627
	// ---------- On initial page load ------------------------------------------------------------
3628

    
3629
	updateType($('#type').val());
3630
	updateTypeSix($('#type6').val());
3631
	show_reset_settings($('#pppoe-reset-type').val());
3632
	hideClass('dhcp6advanced', true);
3633
	hideClass('dhcpadvanced', true);
3634
	show_dhcp6adv();
3635
	setDHCPoptions();
3636
	setPPPoEDialOnDemandItems();
3637
	setPPTPDialOnDemandItems();
3638

    
3639
	// Set preset buttons on page load
3640
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3641
	if (sv == "") {
3642
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3643
	} else {
3644
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3645
	}
3646

    
3647
	// Set preset from value
3648
	setPresets(sv);
3649

    
3650
	// ---------- Click checkbox handlers ---------------------------------------------------------
3651

    
3652
	$('#type').on('change', function() {
3653
		updateType(this.value);
3654
	});
3655

    
3656
	$('#type6').on('change', function() {
3657
		updateTypeSix(this.value);
3658
	});
3659

    
3660
	$('#track6-interface').on('change', function() {
3661
		update_track6_prefix();
3662
	});
3663

    
3664
	$('#pppoe-reset-type').on('change', function() {
3665
		show_reset_settings(this.value);
3666
	});
3667

    
3668
	$("#add").click(function() {
3669
		hide_add_gatewaysave();
3670
	});
3671

    
3672
	$("#cnx").click(function() {
3673
		$("#newgateway").modal('hide');
3674
	});
3675

    
3676
	$("#add6").click(function() {
3677
		hide_add_gatewaysave_v6();
3678
	});
3679

    
3680
	$("#cnx6").click(function() {
3681
		$("#newgateway6").modal('hide');
3682
	});
3683

    
3684
	$('#country').on('change', function() {
3685
		providers_list();
3686
	});
3687

    
3688
	$('#provider_list').on('change', function() {
3689
		providerplan_list();
3690
	});
3691

    
3692
	$('#providerplan').on('change', function() {
3693
		prefill_provider();
3694
	});
3695

    
3696
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3697
		setDHCPoptions();
3698
	});
3699

    
3700
	$('#adv_dhcp6_config_advanced').click(function () {
3701
		show_dhcp6adv();
3702
	});
3703

    
3704
	$('#adv_dhcp6_config_file_override').click(function () {
3705
		show_dhcp6adv();
3706
	});
3707

    
3708
	// On click . .
3709
	$('#pppoe_dialondemand').click(function () {
3710
		setPPPoEDialOnDemandItems();
3711
	});
3712

    
3713
	$('#pptp_dialondemand').click(function () {
3714
		setPPTPDialOnDemandItems();
3715
	});
3716

    
3717
	$('[name=adv_dhcp_pt_values]').click(function () {
3718
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3719
	});
3720

    
3721
	$('#pppoe_resetdate').datepicker();
3722

    
3723
});
3724
//]]>
3725
</script>
3726

    
3727
<?php include("foot.inc");
(65-65/223)