Project

General

Profile

Download (123 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2006 Daniel S. Haischt
8
 * All rights reserved.
9
 *
10
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * 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
				kill_dhcp6client_process($wancfg['if'],true);
991
			}
992
		}
993
		$ppp = array();
994
		if ($wancfg['ipaddr'] != "ppp") {
995
			unset($wancfg['ipaddr']);
996
		}
997
		if ($wancfg['ipaddrv6'] != "ppp") {
998
			unset($wancfg['ipaddrv6']);
999
		}
1000
		unset($wancfg['subnet']);
1001
		unset($wancfg['gateway']);
1002
		unset($wancfg['subnetv6']);
1003
		unset($wancfg['gatewayv6']);
1004
		unset($wancfg['dhcphostname']);
1005
		unset($wancfg['dhcprejectfrom']);
1006
		unset($wancfg['dhcp6-duid']);
1007
		unset($wancfg['dhcp6-ia-pd-len']);
1008
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1009
		unset($wancfg['dhcp6prefixonly']);
1010
		unset($wancfg['dhcp6usev4iface']);
1011
		unset($wancfg['dhcp6debug']);
1012
		unset($wancfg['track6-interface']);
1013
		unset($wancfg['track6-prefix-id']);
1014
		unset($wancfg['dhcp6withoutra']);
1015
		unset($wancfg['dhcp6norelease']);
1016
		unset($wancfg['prefix-6rd']);
1017
		unset($wancfg['prefix-6rd-v4plen']);
1018
		unset($wancfg['gateway-6rd']);
1019

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1431
		write_config();
1432

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

    
1442
		mark_subsystem_dirty('interfaces');
1443

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

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

    
1451
} // end if ($_POST['save'])
1452

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

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

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

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

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

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

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

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

    
1626
	if ($clone_count > 1) {
1627
		$old_wireless_mode = $wancfg['wireless']['mode'];
1628
		$wancfg['wireless']['mode'] = $_POST['mode'];
1629
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1630
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."), $wlan_modes[$wancfg['wireless']['mode']]);
1631
		} else {
1632
			pfSense_interface_destroy("{$wlanif}_");
1633
		}
1634
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1635
	}
1636
}
1637

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

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

    
1656
$types4 = array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP"), "ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP"));
1657
$types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), "dhcp6" => gettext("DHCP6"), "slaac" => gettext("SLAAC"), "6rd" => gettext("6rd Tunnel"), "6to4" => gettext("6to4 Tunnel"), "track6" => gettext("Track Interface"));
1658

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

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

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

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

    
1675
	return($list);
1676
}
1677

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

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

    
1688
	return($list);
1689
}
1690

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

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

    
1701
	return($list);
1702
}
1703

    
1704
include("head.inc");
1705

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

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

    
1716
if ($changes_applied) {
1717
	print_apply_result_box($retval);
1718
}
1719

    
1720
$form = new Form();
1721

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1926
// ==== DHCP client configuration =============================
1927

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2054
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.%1$s' .
2055
				'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>');
2056

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

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

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

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

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

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

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

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

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

    
2110
// DHCP6 client config
2111

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

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

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

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

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

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

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

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

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

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

    
2189
$form->add($section);
2190

    
2191
// DHCP6 client config - Advanced
2192

    
2193
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2194
$section->addClass('dhcp6advanced');
2195

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

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

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

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

    
2230
$group = new Form_Group('Identity Association Statement');
2231

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

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

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

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

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

    
2268
$section->add($group);
2269

    
2270
// Prefix delegation
2271
$group = new Form_Group('');
2272

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

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

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

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

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

    
2309
$section->add($group);
2310

    
2311
$group = new Form_Group('Prefix interface statement');
2312

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

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

    
2327
$section->add($group);
2328

    
2329
$group = new Form_Group('Authentication statement');
2330

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

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

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

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

    
2359
$section->add($group);
2360

    
2361
$group = new Form_Group('Keyinfo statement');
2362

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

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

    
2377
$section->add($group);
2378

    
2379
$group = new Form_Group('');
2380

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

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

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

    
2402
$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>');
2403

    
2404
$section->add($group);
2405

    
2406
$form->add($section);
2407

    
2408
$section = new Form_Section('6RD Configuration');
2409
$section->addClass('_6rd');
2410

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

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

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

    
2432
$form->add($section);
2433

    
2434
// Track IPv6 ointerface section
2435
$section = new Form_Section('Track IPv6 Interface');
2436
$section->addClass('track6');
2437

    
2438
function build_ipv6interface_list() {
2439
	global $config, $section;
2440

    
2441
	$list = array('' => '');
2442

    
2443
	$interfaces = get_configured_interface_with_descr(false, true);
2444
	$dynv6ifs = array();
2445

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

    
2461
	foreach ($dynv6ifs as $iface => $ifacedata) {
2462
		$list[$iface] = $ifacedata['name'];
2463

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

    
2472
	return($list);
2473
}
2474

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

    
2482
if ($pconfig['track6-prefix-id'] == "") {
2483
	$pconfig['track6-prefix-id'] = 0;
2484
}
2485

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

    
2493
$section->addInput(new Form_Input(
2494
	'track6-prefix-id-max',
2495
	null,
2496
	'hidden',
2497
	0
2498
));
2499

    
2500
$form->add($section);
2501

    
2502
/// PPP section
2503

    
2504
$section = new Form_Section('PPP Configuration');
2505
$section->addClass('ppp');
2506

    
2507
$section->addInput(new Form_Select(
2508
	'country',
2509
	'Country',
2510
	$pconfig['country'],
2511
	[]
2512
));
2513

    
2514
$section->addInput(new Form_Select(
2515
	'provider_list',
2516
	'Provider',
2517
	$pconfig['provider_list'],
2518
	[]
2519
));
2520

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

    
2528
$section->addInput(new Form_Input(
2529
	'ppp_username',
2530
	'Username',
2531
	'text',
2532
	$pconfig['ppp_username']
2533
));
2534

    
2535
$section->addPassword(new Form_Input(
2536
	'ppp_password',
2537
	'Password',
2538
	'password',
2539
	$pconfig['ppp_password']
2540
));
2541

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

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

    
2556

    
2557
function build_port_list() {
2558
	$list = array("" => "None");
2559

    
2560
	$portlist = glob("/dev/cua*");
2561
	$modems	  = glob("/dev/modem*");
2562
	$portlist = array_merge($portlist, $modems);
2563

    
2564
	foreach ($portlist as $port) {
2565
		if (preg_match("/\.(lock|init)$/", $port)) {
2566
			continue;
2567
		}
2568

    
2569
	$list[trim($port)] = $port;
2570
	}
2571

    
2572
	return($list);
2573
}
2574

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

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

    
2589
$form->add($section);
2590

    
2591
// PPPoE configuration
2592
$section = new Form_Section('PPPoE Configuration');
2593
$section->addClass('pppoe');
2594

    
2595
$section->addInput(new Form_Input(
2596
	'pppoe_username',
2597
	'*Username',
2598
	'text',
2599
	$pconfig['pppoe_username']
2600
));
2601

    
2602
$section->addPassword(new Form_Input(
2603
	'pppoe_password',
2604
	'*Password',
2605
	'password',
2606
	$pconfig['pppoe_password']
2607
));
2608

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

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

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

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

    
2640
$group = new Form_Group('Custom reset');
2641
$group->addClass('pppoecustom');
2642

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

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

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

    
2666
$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');
2667

    
2668
$section->add($group);
2669

    
2670
$group = new Form_MultiCheckboxGroup('cron based reset');
2671
$group->addClass('pppoepreset');
2672

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

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

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

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

    
2705
$section->add($group);
2706

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

    
2714
$form->add($section);
2715

    
2716
// PPTP & L2TP Configuration section
2717
$section = new Form_Section('PPTP/L2TP Configuration');
2718
$section->addClass('pptp');
2719

    
2720
$section->addInput(new Form_Input(
2721
	'pptp_username',
2722
	'*Username',
2723
	'text',
2724
	$pconfig['pptp_username']
2725
));
2726

    
2727
$section->addPassword(new Form_Input(
2728
	'pptp_password',
2729
	'*Password',
2730
	'password',
2731
	$pconfig['pptp_password']
2732
));
2733

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

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

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

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

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

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

    
2779
$form->add($section);
2780

    
2781
// Wireless interface
2782
if (isset($wancfg['wireless'])) {
2783

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

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

    
2794
	$mode_list = ['auto' => 'Auto'];
2795

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

    
2802
	if (count($mode_list) == 1) {
2803
		$mode_list[''] = '';
2804
	}
2805

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

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

    
2829
	$mode_list = ['0' => gettext('Auto')];
2830

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

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

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

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

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

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

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

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

    
2892
			$section->add($group);
2893
		}
2894
	}
2895

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

    
2905
	$form->add($section);
2906

    
2907
	// Regulatory settings
2908
	$section = new Form_Section('Regulatory Settings');
2909

    
2910
	$domain_list = array("" => 'Default');
2911

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

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

    
2925
	$country_list = array('' => 'Default');
2926

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

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

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

    
2951
	$form->add($section);
2952

    
2953
	$section = new Form_Section('Network-Specific Wireless Configuration');
2954

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

    
2962
	$section->addInput(new Form_Input(
2963
		'ssid',
2964
		'SSID',
2965
		'text',
2966
		$pconfig['ssid']
2967
	));
2968

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

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

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

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

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

    
3012
	// WPA Section
3013
	$section = new Form_Section('WPA');
3014

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

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

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

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

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

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

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

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

    
3075
	$form->add($section);
3076

    
3077
	$section = new Form_Section('802.1x RADIUS Options');
3078

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

    
3087
	$group = new Form_Group('Primary 802.1X server');
3088

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

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

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

    
3109
	$section->add($group);
3110

    
3111
	$group = new Form_Group('Secondary 802.1X server');
3112

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

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

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

    
3133
	$section->add($group);
3134

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

    
3143
	$form->add($section);
3144
}
3145

    
3146
$section = new Form_Section('Reserved Networks');
3147

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

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

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

    
3170
$form->addGlobal(new Form_Input(
3171
	'if',
3172
	null,
3173
	'hidden',
3174
	$if
3175
));
3176

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

    
3186
$form->addGlobal(new Form_Input(
3187
	'ptpid',
3188
	null,
3189
	'hidden',
3190
	$pconfig['ptpid']
3191
));
3192

    
3193

    
3194
// Add new gateway modal pop-up
3195
$modal = new Modal('New Gateway', 'newgateway', 'large');
3196

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

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

    
3211
$modal->addInput(new Form_IpAddress(
3212
	'gatewayip',
3213
	'Gateway IPv4',
3214
	null,
3215
	'V4'
3216
));
3217

    
3218
$modal->addInput(new Form_Input(
3219
	'gatewaydescr',
3220
	'Description',
3221
	'text'
3222
));
3223

    
3224
$btnaddgw = new Form_Button(
3225
	'add',
3226
	'Add',
3227
	null,
3228
	'fa-plus'
3229
);
3230

    
3231
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3232

    
3233
$btncnxgw = new Form_Button(
3234
	'cnx',
3235
	'Cancel',
3236
	null,
3237
	'fa-undo'
3238
);
3239

    
3240
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3241

    
3242
$modal->addInput(new Form_StaticText(
3243
	null,
3244
	$btnaddgw . $btncnxgw
3245
));
3246

    
3247
$form->add($modal);
3248

    
3249
print($form);
3250
?>
3251

    
3252
<script type="text/javascript">
3253
//<![CDATA[
3254
events.push(function() {
3255
	function updateType(t) {
3256

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

    
3291
		if (t != "l2tp" && t != "pptp") {
3292
			$('.'+t).show();
3293
		}
3294
	}
3295

    
3296
	function updateTypeSix(t) {
3297
		if (!isNaN(t[0])) {
3298
			t = '_' + t;
3299
		}
3300

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

    
3333
		if (t != "l2tp" && t != "pptp") {
3334
			$('.'+t).show();
3335
		}
3336
	}
3337

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

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

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

    
3362
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3363
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3364
	}
3365

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

    
3373
		var defaultgw = '';
3374
		if ($('#defaultgw').is(':checked')) {
3375
			defaultgw = '&defaultgw=on';
3376
		}
3377

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

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

    
3398
		$("#newgateway").modal('hide');
3399
	}
3400

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

    
3409
		$("#newgateway").modal('hide');
3410
	}
3411

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

    
3420
	function hide_add_gatewaysave_v6() {
3421

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

    
3442

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

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

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

    
3461
	function save_callback_v6(response_v6) {
3462
		if (response_v6) {
3463

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

    
3470
		$("#newgateway6").modal('hide');
3471
	}
3472

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

    
3480
				var responseTextArr = response.split("\n");
3481
				responseTextArr.sort();
3482

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

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

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

    
3522
				$('#providerplan').append($('<option>', {
3523
					value: '',
3524
					text : ''
3525
				}));
3526

    
3527
				responseTextArr.forEach( function(value) {
3528
					if (value != "") {
3529
						providerplan = value.split(":");
3530

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

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

    
3565
	function show_dhcp6adv() {
3566
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3567
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3568

    
3569
		hideCheckbox('dhcp6usev4iface', ovr);
3570
		hideCheckbox('dhcp6prefixonly', ovr);
3571
		hideInput('dhcp6-ia-pd-len', ovr);
3572
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3573
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3574

    
3575
		hideClass('dhcp6advanced', !adv || ovr);
3576
	}
3577

    
3578
	function setDHCPoptions() {
3579
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3580
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3581

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

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

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

    
3616
	function setPPPoEDialOnDemandItems() {
3617
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3618
	}
3619

    
3620
	function setPPTPDialOnDemandItems() {
3621
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3622
	}
3623

    
3624
	// ---------- On initial page load ------------------------------------------------------------
3625

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

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

    
3644
	// Set preset from value
3645
	setPresets(sv);
3646

    
3647
	// ---------- Click checkbox handlers ---------------------------------------------------------
3648

    
3649
	$('#type').on('change', function() {
3650
		updateType(this.value);
3651
	});
3652

    
3653
	$('#type6').on('change', function() {
3654
		updateTypeSix(this.value);
3655
	});
3656

    
3657
	$('#track6-interface').on('change', function() {
3658
		update_track6_prefix();
3659
	});
3660

    
3661
	$('#pppoe-reset-type').on('change', function() {
3662
		show_reset_settings(this.value);
3663
	});
3664

    
3665
	$("#add").click(function() {
3666
		hide_add_gatewaysave();
3667
	});
3668

    
3669
	$("#cnx").click(function() {
3670
		$("#newgateway").modal('hide');
3671
	});
3672

    
3673
	$("#add6").click(function() {
3674
		hide_add_gatewaysave_v6();
3675
	});
3676

    
3677
	$("#cnx6").click(function() {
3678
		$("#newgateway6").modal('hide');
3679
	});
3680

    
3681
	$('#country').on('change', function() {
3682
		providers_list();
3683
	});
3684

    
3685
	$('#provider_list').on('change', function() {
3686
		providerplan_list();
3687
	});
3688

    
3689
	$('#providerplan').on('change', function() {
3690
		prefill_provider();
3691
	});
3692

    
3693
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3694
		setDHCPoptions();
3695
	});
3696

    
3697
	$('#adv_dhcp6_config_advanced').click(function () {
3698
		show_dhcp6adv();
3699
	});
3700

    
3701
	$('#adv_dhcp6_config_file_override').click(function () {
3702
		show_dhcp6adv();
3703
	});
3704

    
3705
	// On click . .
3706
	$('#pppoe_dialondemand').click(function () {
3707
		setPPPoEDialOnDemandItems();
3708
	});
3709

    
3710
	$('#pptp_dialondemand').click(function () {
3711
		setPPTPDialOnDemandItems();
3712
	});
3713

    
3714
	$('[name=adv_dhcp_pt_values]').click(function () {
3715
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3716
	});
3717

    
3718
	$('#pppoe_resetdate').datepicker();
3719

    
3720
});
3721
//]]>
3722
</script>
3723

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