Project

General

Profile

Download (124 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2006 Daniel S. Haischt
8
 * All rights reserved.
9
 *
10
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

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

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

    
44
define("ANTENNAS", false);
45

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

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

    
55
$if = "wan";
56
if ($_REQUEST['if']) {
57
	$if = $_REQUEST['if'];
58
}
59

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
408
}
409

    
410
$changes_applied = false;
411

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

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

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

    
451
		clear_subsystem_dirty('interfaces');
452

    
453
		$retval |= filter_configure();
454

    
455
		enable_rrd_graphing();
456

    
457
		$changes_applied = true;
458

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
833
		unset($min_mtu, $max_mtu);
834

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1433
		write_config();
1434

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

    
1444
		mark_subsystem_dirty('interfaces');
1445

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

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

    
1453
} // end if ($_POST)
1454

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1677
	return($list);
1678
}
1679

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

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

    
1690
	return($list);
1691
}
1692

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

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

    
1703
	return($list);
1704
}
1705

    
1706
include("head.inc");
1707

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

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

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

    
1722
$form = new Form();
1723

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1928
// ==== DHCP client configuration =============================
1929

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2112
// DHCP6 client config
2113

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

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

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

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

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

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

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

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

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

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

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

    
2193
// DHCP6 client config - Advanced
2194

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2404
$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>');
2405

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2474
	return($list);
2475
}
2476

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

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

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

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

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

    
2504
/// PPP section
2505

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

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

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

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

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

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

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

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

    
2558

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

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

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

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

    
2574
	return($list);
2575
}
2576

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3195

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

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

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

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

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

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

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

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

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

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

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

    
3251
print($form);
3252
?>
3253

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3422
	function hide_add_gatewaysave_v6() {
3423

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

    
3444

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3626
	// ---------- On initial page load ------------------------------------------------------------
3627

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

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

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

    
3649
	// ---------- Click checkbox handlers ---------------------------------------------------------
3650

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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