Project

General

Profile

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

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

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

    
44
define("ANTENNAS", false);
45

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

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

    
55
$if = "wan";
56

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
409
}
410

    
411
$changes_applied = false;
412

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

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

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

    
452
		clear_subsystem_dirty('interfaces');
453

    
454
		$retval |= filter_configure();
455

    
456
		enable_rrd_graphing();
457

    
458
		$changes_applied = true;
459

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
834
		unset($min_mtu, $max_mtu);
835

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1431
		write_config();
1432

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

    
1442
		mark_subsystem_dirty('interfaces');
1443

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1675
	return($list);
1676
}
1677

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

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

    
1688
	return($list);
1689
}
1690

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

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

    
1701
	return($list);
1702
}
1703

    
1704
include("head.inc");
1705

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

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

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

    
1720
$form = new Form();
1721

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1831
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.%1$s' .
1832
				'On local area network interfaces the upstream gateway should be "none". ' .
1833
				'Gateways can be managed by %2$sclicking here%3$s.', '<br />', '<a target="_blank" href="system_gateways.php">', '</a>');
1834

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

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

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

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

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

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

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

    
1865
$group->setHelp('If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the "Add" button.%s' .
1866
				'On local LANs the upstream gateway should be "none". ', '<br />');
1867

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1949
$section->addInput(new Form_Input(
1950
	'dhcphostname',
1951
	'Hostname',
1952
	'text',
1953
	$pconfig['dhcphostname']
1954
))->setHelp('The value in this field is sent as the DHCP client identifier and hostname when requesting a DHCP lease. Some ISPs may require this (for client identification).');
1955

    
1956
$section->addInput(new Form_IpAddress(
1957
	'alias-address',
1958
	'Alias IPv4 address',
1959
	$pconfig['alias-address'],
1960
	'V4'
1961
))->addMask('alias-subnet', $pconfig['alias-subnet'], 32)->setHelp('The value in this field is used as a fixed alias IPv4 address by the DHCP client.');
1962

    
1963
$section->addInput(new Form_Input(
1964
	'dhcprejectfrom',
1965
	'Reject leases from',
1966
	'text',
1967
	$pconfig['dhcprejectfrom']
1968
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
1969
			'(separate multiple entries with a comma). ' .
1970
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
1971

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2111
// DHCP6 client config
2112

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

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

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

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

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

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

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

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

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

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

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

    
2192
// DHCP6 client config - Advanced
2193

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2473
	return($list);
2474
}
2475

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

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

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

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

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

    
2503
/// PPP section
2504

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

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

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

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

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

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

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

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

    
2557

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

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

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

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

    
2573
	return($list);
2574
}
2575

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3194

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

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

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

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

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

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

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

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

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

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

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

    
3250
print($form);
3251
?>
3252

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3421
	function hide_add_gatewaysave_v6() {
3422

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

    
3443

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3625
	// ---------- On initial page load ------------------------------------------------------------
3626

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

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

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

    
3648
	// ---------- Click checkbox handlers ---------------------------------------------------------
3649

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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