Project

General

Profile

Download (128 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 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(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'])) {
88
	$config['gateways'] = array();
89
}
90

    
91
if (!is_array($config['gateways']['gateway_item'])) {
92
	$config['gateways']['gateway_item'] = array();
93
}
94

    
95
$a_gateways = &$config['gateways']['gateway_item'];
96

    
97
$interfaces = get_configured_interface_with_descr();
98
/* Interfaces which have addresses configired elsewhere and should not be
99
 * configured here. See https://redmine.pfsense.org/issues/8687 */
100
$no_address_interfaces = array("ovpn", "ipsec", "gif", "gre");
101
$show_address_controls = true;
102
$realifname = get_real_interface($if);
103
foreach ($no_address_interfaces as $ifbl) {
104
	if (substr($realifname, 0, strlen($ifbl)) == $ifbl) {
105
		$show_address_controls = false;
106
	}
107
}
108

    
109
$wancfg = &$config['interfaces'][$if];
110
$old_wancfg = $wancfg;
111
$old_wancfg['realif'] = get_real_interface($if);
112
$old_ppps = $a_ppps;
113

    
114
// Populate page descr if it does not exist.
115
if ($if == "wan" && !$wancfg['descr']) {
116
	$wancfg['descr'] = "WAN";
117
} else if ($if == "lan" && !$wancfg['descr']) {
118
	$wancfg['descr'] = "LAN";
119
}
120

    
121
/* NOTE: The code here is used to set the $pppid for the curious */
122
foreach ($a_ppps as $pppid => $ppp) {
123
	if ($wancfg['if'] == $ppp['if']) {
124
		break;
125
	}
126
}
127

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

    
130
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
131
	$pconfig['pppid'] = $pppid;
132
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
133
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
134
	if ($a_ppps[$pppid]['type'] == "ppp") {
135
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
136
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
137

    
138
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
139
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
140
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
141
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
142
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
143
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
144
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
145
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
146

    
147
		/* ================================================ */
148
		/* = force a connection reset at a specific time? = */
149
		/* ================================================ */
150

    
151
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
152
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
153
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
154
			if ($itemhash) {
155
				$cronitem = $itemhash['ITEM'];
156
			}
157
			if (isset($cronitem)) {
158
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
159
			} else {
160
				$resetTime = NULL;
161
			}
162
			//log_error("ResetTime:".$resetTime);
163
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
164
				if ($cronitem) {
165
					$pconfig['pppoe_pr_custom'] = true;
166
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
167
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
168
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
169
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
170
					}
171
				}
172
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
173
				$pconfig['pppoe_pr_preset'] = true;
174
				switch ($resetTime) {
175
					case CRON_MONTHLY_PATTERN:
176
						$pconfig['pppoe_monthly'] = true;
177
						break;
178
					case CRON_WEEKLY_PATTERN:
179
						$pconfig['pppoe_weekly'] = true;
180
						break;
181
					case CRON_DAILY_PATTERN:
182
						$pconfig['pppoe_daily'] = true;
183
						break;
184
					case CRON_HOURLY_PATTERN:
185
						$pconfig['pppoe_hourly'] = true;
186
						break;
187
				}
188
			}
189
		} // End force pppoe reset at specific time
190
		// End if type == pppoe
191
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
192
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
193
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
194
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
195
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
196
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
197
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
198
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
199
	}
200
} else {
201
	$pconfig['ptpid'] = interfaces_ptpid_next();
202
	$pppid = count($a_ppps);
203
}
204

    
205
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
206
$pconfig['alias-address'] = $wancfg['alias-address'];
207
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
208
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
209

    
210
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
211
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
212
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
213
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
214
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
215
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
216

    
217
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
218

    
219
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
220
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
221
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
222
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
223

    
224
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
225
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
226
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
227

    
228
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
229
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
230
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
231
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
232

    
233
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
234
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
235
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
236
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
237
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
238

    
239
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
240
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
241
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
242
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
243
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
244

    
245
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
246
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
247
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
248

    
249
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
250
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
251
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
252
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
253

    
254
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
255
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
256
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
257
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
258
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
259

    
260
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
261
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
262
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
263

    
264
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
265
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
266
$pconfig['enable'] = isset($wancfg['enable']);
267

    
268
switch ($wancfg['ipaddr']) {
269
	case "dhcp":
270
		$pconfig['type'] = "dhcp";
271
		$pconfig['dhcpvlanenable'] = isset($wancfg['dhcpvlanenable']);
272
		$pconfig['dhcpcvpt'] = $wancfg['dhcpcvpt'];
273
		break;
274
	case "pppoe":
275
	case "pptp":
276
	case "l2tp":
277
	case "ppp":
278
		$pconfig['type'] = $wancfg['ipaddr'];
279
		break;
280
	default:
281
		if (is_ipaddrv4($wancfg['ipaddr'])) {
282
			$pconfig['type'] = "staticv4";
283
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
284
			$pconfig['subnet'] = $wancfg['subnet'];
285
			$pconfig['gateway'] = $wancfg['gateway'];
286
		} else {
287
			$pconfig['type'] = "none";
288
		}
289
		break;
290
}
291

    
292
switch ($wancfg['ipaddrv6']) {
293
	case "slaac":
294
		$pconfig['type6'] = "slaac";
295
		break;
296
	case "dhcp6":
297
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
298
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
299
			$wancfg['dhcp6-ia-pd-len'] = "none";
300
		}
301
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
302
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
303
		$pconfig['type6'] = "dhcp6";
304
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
305
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
306
		$pconfig['dhcp6debug'] = isset($wancfg['dhcp6debug']);
307
		$pconfig['dhcp6withoutra'] = isset($wancfg['dhcp6withoutra']);
308
		$pconfig['dhcp6norelease'] = isset($wancfg['dhcp6norelease']);
309
		$pconfig['dhcp6vlanenable'] = isset($wancfg['dhcp6vlanenable']);
310
		$pconfig['dhcp6cvpt'] = $wancfg['dhcp6cvpt'];
311
		break;
312
	case "6to4":
313
		$pconfig['type6'] = "6to4";
314
		break;
315
	case "track6":
316
		$pconfig['type6'] = "track6";
317
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
318
		if ($wancfg['track6-prefix-id'] == "") {
319
			$pconfig['track6-prefix-id'] = 0;
320
		} else {
321
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
322
		}
323
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
324
		break;
325
	case "6rd":
326
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
327
		if ($wancfg['prefix-6rd-v4plen'] == "") {
328
			$wancfg['prefix-6rd-v4plen'] = "0";
329
		}
330
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
331
		$pconfig['type6'] = "6rd";
332
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
333
		break;
334
	default:
335
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
336
			$pconfig['type6'] = "staticv6";
337
			$pconfig['ipv6usev4iface'] = isset($wancfg['ipv6usev4iface']);
338
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
339
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
340
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
341
		} else {
342
			$pconfig['type6'] = "none";
343
		}
344
		break;
345
}
346

    
347
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
348
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
349
$pconfig['spoofmac'] = $wancfg['spoofmac'];
350
$pconfig['mtu'] = $wancfg['mtu'];
351
$pconfig['mss'] = $wancfg['mss'];
352

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

    
429
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
430

    
431
}
432

    
433
$changes_applied = false;
434

    
435
if ($_POST['apply']) {
436
	unset($input_errors);
437
	if (!is_subsystem_dirty('interfaces')) {
438
		$input_errors[] = gettext("The settings have already been applied!");
439
	} else {
440
		$retval = 0;
441
		unlink_if_exists("{$g['tmp_path']}/config.cache");
442
		clear_subsystem_dirty('interfaces');
443

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

    
471
		/* sync filter configuration */
472
		setup_gateways_monitor();
473

    
474
		clear_subsystem_dirty('interfaces');
475

    
476
		$retval |= filter_configure();
477

    
478
		enable_rrd_graphing();
479

    
480
		$changes_applied = true;
481

    
482
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
483
			clear_subsystem_dirty('staticroutes');
484
		}
485
	}
486
	@unlink("{$g['tmp_path']}/.interfaces.apply");
487
} else if ($_POST['save']) {
488

    
489
	unset($input_errors);
490
	$pconfig = $_POST;
491

    
492
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
493
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
494
	} else {
495
		$pconfig['track6-prefix-id'] = 0;
496
	}
497

    
498
	/* filter out spaces from descriptions */
499
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
500

    
501
	/* okay first of all, cause we are just hiding the PPPoE HTML
502
	 * fields related to PPPoE resets, we are going to unset $_POST
503
	 * vars, if the reset feature should not be used. Otherwise the
504
	 * data validation procedure below, may trigger a false error
505
	 * message.
506
	 */
507
	if (empty($_POST['pppoe-reset-type'])) {
508
		unset($_POST['pppoe_pr_type']);
509
		unset($_POST['pppoe_resethour']);
510
		unset($_POST['pppoe_resetminute']);
511
		unset($_POST['pppoe_resetdate']);
512
		unset($_POST['pppoe_pr_preset_val']);
513
	}
514

    
515
	/* input validation */
516
	$reqdfields = explode(" ", "descr");
517
	$reqdfieldsn = array(gettext("Description"));
518
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
519

    
520
	if (!$input_errors) {
521
		/* description unique? */
522
		foreach ($ifdescrs as $ifent => $ifdescr) {
523
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
524
				$input_errors[] = gettext("An interface with the specified description already exists.");
525
				break;
526
			}
527
		}
528

    
529
		/* Is the description already used as an alias name? */
530
		if (is_array($config['aliases']['alias'])) {
531
			foreach ($config['aliases']['alias'] as $alias) {
532
				if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
533
					$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
534
				}
535
			}
536
		}
537

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

    
547
		if (is_numeric($_POST['descr'])) {
548
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
549
		}
550

    
551
		/*
552
		 * Packages (e.g. tinc) create interface groups, reserve this
553
		 * namespace pkg_ for them.
554
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
555
		 */
556
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
557
			$input_errors[] = gettext("The interface description cannot start with pkg_");
558
		}
559
	}
560

    
561
	if ($_POST['blockbogons'] == "yes" &&
562
	    isset($config['system']['ipv6allow']) &&
563
	    (!isset($config['system']['maximumtableentries']) ||
564
	     $config['system']['maximumtableentries'] <
565
	     $g['minimumtableentries_bogonsv6'])) {
566
		$input_errors[] = sprintf(gettext(
567
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
568
		    $g['minimumtableentries_bogonsv6']);
569
	}
570

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

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

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

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

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

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

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

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

    
777
			foreach ($staticroutes as $route_subnet) {
778
				list($network, $subnet) = explode("/", $route_subnet);
779
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
780
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
781
					break;
782
				}
783
				unset($network, $subnet);
784
			}
785
		}
786
	}
787
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
788
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
789
	}
790
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
791
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
792
	}
793
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
794
		$input_errors[] = gettext("A valid alias IP address must be specified.");
795
	}
796
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
797
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
798
	}
799
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
800
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
801
	}
802

    
803
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
804
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
805
		$match = false;
806
		foreach ($a_gateways as $gateway) {
807
			if (in_array($_POST['gateway'], $gateway)) {
808
				$match = true;
809
			}
810
		}
811
		if (!$match) {
812
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
813
		}
814
	}
815
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
816
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
817
		$match = false;
818
		foreach ($a_gateways as $gateway) {
819
			if (in_array($_POST['gatewayv6'], $gateway)) {
820
				$match = true;
821
			}
822
		}
823
		if (!$match) {
824
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
825
		}
826
	}
827
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
828
		$input_errors[] = gettext("The service name contains invalid characters.");
829
	}
830
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
831
		$input_errors[] = gettext("The idle timeout value must be an integer.");
832
	}
833
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
834
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
835
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
836
	}
837
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
838
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
839
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
840
	}
841
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
842
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
843
	}
844
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
845
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
846
	}
847
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
848
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
849
	}
850
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
851
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
852
	}
853
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
854
		$input_errors[] = gettext("The idle timeout value must be an integer.");
855
	}
856
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
857
		$input_errors[] = gettext("A valid MAC address must be specified.");
858
	}
859
	if ($_POST['mtu']) {
860
		if (!is_numericint($_POST['mtu'])) {
861
			$input_errors[] = "MTU must be an integer.";
862
		}
863
		if (substr($wancfg['if'], 0, 3) == 'gif') {
864
			$min_mtu = 1280;
865
			$max_mtu = 8192;
866
		} else {
867
			$min_mtu = 576;
868
			$max_mtu = 9000;
869
		}
870

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

    
875
		unset($min_mtu, $max_mtu);
876

    
877
		if (interface_is_vlan($wancfg['if']) != NULL) {
878
			$realhwif_array = get_parent_interface($wancfg['if']);
879
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
880
			$parent_realhwif = $realhwif_array[0];
881
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
882
			$mtu = 0;
883
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
884
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
885
			if ($mtu == 0)
886
				$mtu = get_interface_mtu($parent_realhwif);
887
			if ($_POST['mtu'] > $mtu)
888
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
889
		} else {
890
			foreach ($config['interfaces'] as $idx => $ifdata) {
891
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
892
					continue;
893
				}
894

    
895
				$realhwif_array = get_parent_interface($ifdata['if']);
896
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
897
				$parent_realhwif = $realhwif_array[0];
898

    
899
				if ($parent_realhwif != $wancfg['if']) {
900
					continue;
901
				}
902

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

    
990
		if ($_POST['passphrase']) {
991
			$passlen = strlen($_POST['passphrase']);
992
			if ($passlen < 8 || $passlen > 63) {
993
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
994
			}
995
		}
996

    
997
		if ($_POST['wpa_enable'] == "yes") {
998
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
999
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1000
			}
1001
		}
1002
	}
1003

    
1004
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1005
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1006
	}
1007

    
1008
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1009
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1010
	}
1011

    
1012
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1013
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1014
	}
1015

    
1016
	if ($_POST['gatewayip4']) {
1017
		// The user wants to add an IPv4 gateway - validate the settings
1018
		$gateway_settings4 = array();
1019

    
1020
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1021
		$gateway_settings4['interface'] = $_POST['if'];
1022
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1023
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1024
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1025
		$gateway_settings4['ipprotocol'] = 'inet';
1026
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1027
		foreach ($gw_input_errors as $input_error_text) {
1028
			$input_errors[] = $input_error_text;
1029
		}
1030
	}
1031

    
1032
	if ($_POST['gatewayip6']) {
1033
		// The user wants to add an IPv6 gateway - validate the settings
1034
		$gateway_settings6 = array();
1035

    
1036
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1037
		$gateway_settings6['interface'] = $_POST['if'];
1038
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1039
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1040
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1041
		$gateway_settings6['ipprotocol'] = 'inet6';
1042
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1043
		foreach ($gw_input_errors as $input_error_text) {
1044
			$input_errors[] = $input_error_text;
1045
		}
1046
	}
1047

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

    
1055
		if ($wancfg['ipaddr'] != $_POST['type']) {
1056
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1057
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1058
				unset($a_ppps[$pppid]);
1059
			} else if ($wancfg['ipaddr'] == "dhcp") {
1060
				kill_dhclient_process($wancfg['if']);
1061
			}
1062
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1063
				kill_dhcp6client_process($wancfg['if'],true);
1064
			}
1065
		}
1066
		$ppp = array();
1067
		if ($wancfg['ipaddr'] != "ppp") {
1068
			unset($wancfg['ipaddr']);
1069
		}
1070
		if ($wancfg['ipaddrv6'] != "ppp") {
1071
			unset($wancfg['ipaddrv6']);
1072
		}
1073
		unset($wancfg['subnet']);
1074
		unset($wancfg['gateway']);
1075
		unset($wancfg['subnetv6']);
1076
		unset($wancfg['gatewayv6']);
1077
		unset($wancfg['dhcphostname']);
1078
		unset($wancfg['dhcprejectfrom']);
1079
		unset($wancfg['dhcp6-duid']);
1080
		unset($wancfg['dhcp6-ia-pd-len']);
1081
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1082
		unset($wancfg['dhcp6prefixonly']);
1083
		unset($wancfg['dhcp6usev4iface']);
1084
		unset($wancfg['ipv6usev4iface']);
1085
		unset($wancfg['dhcp6debug']);
1086
		unset($wancfg['track6-interface']);
1087
		unset($wancfg['track6-prefix-id']);
1088
		unset($wancfg['dhcp6withoutra']);
1089
		unset($wancfg['dhcp6norelease']);
1090
		unset($wancfg['dhcp6vlanenable']);
1091
		unset($wancfg['dhcp6cvpt']);
1092
		unset($wancfg['prefix-6rd']);
1093
		unset($wancfg['prefix-6rd-v4plen']);
1094
		unset($wancfg['gateway-6rd']);
1095

    
1096
		unset($wancfg['dhcpvlanenable']);
1097
		unset($wancfg['dhcpcvpt']);
1098

    
1099
		unset($wancfg['adv_dhcp_pt_timeout']);
1100
		unset($wancfg['adv_dhcp_pt_retry']);
1101
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1102
		unset($wancfg['adv_dhcp_pt_reboot']);
1103
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1104
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1105

    
1106
		unset($wancfg['adv_dhcp_pt_values']);
1107

    
1108
		unset($wancfg['adv_dhcp_send_options']);
1109
		unset($wancfg['adv_dhcp_request_options']);
1110
		unset($wancfg['adv_dhcp_required_options']);
1111
		unset($wancfg['adv_dhcp_option_modifiers']);
1112

    
1113
		unset($wancfg['adv_dhcp_config_advanced']);
1114
		unset($wancfg['adv_dhcp_config_file_override']);
1115
		unset($wancfg['adv_dhcp_config_file_override_path']);
1116

    
1117
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1118
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1119
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1120
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1121

    
1122
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1123
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1124
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1125
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1126
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1127

    
1128
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1129
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1130
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1131
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1132
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1133

    
1134
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1135
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1136
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1137

    
1138
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1139
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1140
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1141
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1142

    
1143
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1144
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1145
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1146
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1147
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1148

    
1149
		unset($wancfg['adv_dhcp6_config_advanced']);
1150
		unset($wancfg['adv_dhcp6_config_file_override']);
1151
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1152

    
1153
		unset($wancfg['pppoe_password']);
1154
		unset($wancfg['pptp_username']);
1155
		unset($wancfg['pptp_password']);
1156
		unset($wancfg['provider']);
1157
		unset($wancfg['ondemand']);
1158
		unset($wancfg['timeout']);
1159
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1160
			unset($wancfg['pppoe']['pppoe-reset-type']);
1161
		}
1162
		unset($wancfg['local']);
1163

    
1164
		unset($wancfg['remote']);
1165
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1166
			if ($wancfg['ipaddr'] != 'ppp') {
1167
				unset($a_ppps[$pppid]['apn']);
1168
				unset($a_ppps[$pppid]['phone']);
1169
				unset($a_ppps[$pppid]['provider']);
1170
				unset($a_ppps[$pppid]['ondemand']);
1171
			}
1172
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1173
				unset($a_ppps[$pppid]['localip']);
1174
				unset($a_ppps[$pppid]['subnet']);
1175
				unset($a_ppps[$pppid]['gateway']);
1176
			}
1177
			if ($wancfg['ipaddr'] != 'pppoe') {
1178
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1179
			}
1180
			if ($wancfg['type'] != $_POST['type']) {
1181
				unset($a_ppps[$pppid]['idletimeout']);
1182
			}
1183
		}
1184

    
1185
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1186
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1187

    
1188
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1189
		switch ($_POST['type']) {
1190
			case "staticv4":
1191
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1192
				$wancfg['subnet'] = $_POST['subnet'];
1193
				if ($_POST['gateway'] != "none") {
1194
					$wancfg['gateway'] = $_POST['gateway'];
1195
				}
1196
				break;
1197
			case "dhcp":
1198
				$wancfg['ipaddr'] = "dhcp";
1199
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1200
				$wancfg['alias-address'] = $_POST['alias-address'];
1201
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1202
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1203

    
1204
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1205
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1206
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1207
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1208
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1209
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1210

    
1211
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1212

    
1213
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1214
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1215
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1216
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1217

    
1218
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1219
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1220
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1221

    
1222
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1223
				if ($gateway_item) {
1224
					$a_gateways[] = $gateway_item;
1225
				}
1226
				if ($_POST['dhcpvlanenable'] == "yes") {
1227
					$wancfg['dhcpvlanenable'] = true;
1228
				}
1229
				if (!empty($_POST['dhcpcvpt'])) {
1230
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1231
				} else {
1232
					unset($wancfg['dhcpcvpt']);
1233
				}
1234
				break;
1235
			case "ppp":
1236
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1237
				$a_ppps[$pppid]['type'] = $_POST['type'];
1238
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1239
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1240
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1241
				if ($_POST['ppp_password'] != DMYPWD) {
1242
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1243
				}
1244
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1245
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1246
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1247
				$wancfg['ipaddr'] = $_POST['type'];
1248
				break;
1249

    
1250
			case "pppoe":
1251
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1252
				$a_ppps[$pppid]['type'] = $_POST['type'];
1253
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1254
				if (isset($_POST['ppp_port'])) {
1255
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1256
				} else {
1257
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1258
				}
1259
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1260
				if ($_POST['pppoe_password'] != DMYPWD) {
1261
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1262
				}
1263
				if (!empty($_POST['provider'])) {
1264
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1265
				} else {
1266
					$a_ppps[$pppid]['provider'] = true;
1267
				}
1268
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1269
				if (!empty($_POST['pppoe_idletimeout'])) {
1270
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1271
				} else {
1272
					unset($a_ppps[$pppid]['idletimeout']);
1273
				}
1274

    
1275
				if (!empty($_POST['pppoe-reset-type'])) {
1276
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1277
				} else {
1278
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1279
				}
1280
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1281
				$wancfg['ipaddr'] = $_POST['type'];
1282
				if ($gateway_item) {
1283
					$a_gateways[] = $gateway_item;
1284
				}
1285

    
1286
				break;
1287
			case "pptp":
1288
			case "l2tp":
1289
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1290
				$a_ppps[$pppid]['type'] = $_POST['type'];
1291
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1292
				if (isset($_POST['ppp_port'])) {
1293
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1294
				} else {
1295
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1296
				}
1297
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1298
				if ($_POST['pptp_password'] != DMYPWD) {
1299
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1300
				}
1301
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1302
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1303
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1304
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1305
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1306
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1307
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1308
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1309
				if (!empty($_POST['pptp_idletimeout'])) {
1310
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1311
				} else {
1312
					unset($a_ppps[$pppid]['idletimeout']);
1313
				}
1314
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1315
				$wancfg['ipaddr'] = $_POST['type'];
1316
				if ($gateway_item) {
1317
					$a_gateways[] = $gateway_item;
1318
				}
1319
				break;
1320
			case "none":
1321
				break;
1322
		}
1323
		switch ($_POST['type6']) {
1324
			case "staticv6":
1325
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1326
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1327
				if ($_POST['ipv6usev4iface'] == "yes") {
1328
					$wancfg['ipv6usev4iface'] = true;
1329
				}
1330
				if ($_POST['gatewayv6'] != "none") {
1331
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1332
				}
1333
				break;
1334
			case "slaac":
1335
				$wancfg['ipaddrv6'] = "slaac";
1336
				break;
1337
			case "dhcp6":
1338
				$wancfg['ipaddrv6'] = "dhcp6";
1339
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1340
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1341
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1342
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1343
				}
1344
				if ($_POST['dhcp6prefixonly'] == "yes") {
1345
					$wancfg['dhcp6prefixonly'] = true;
1346
				}
1347
				if ($_POST['dhcp6usev4iface'] == "yes") {
1348
					$wancfg['dhcp6usev4iface'] = true;
1349
				}
1350
				if ($_POST['dhcp6debug'] == "yes") {
1351
					$wancfg['dhcp6debug'] = true;
1352
				}
1353

    
1354
				if ($_POST['dhcp6withoutra'] == "yes") {
1355
					$wancfg['dhcp6withoutra'] = true;
1356
				}
1357
				if ($_POST['dhcp6norelease'] == "yes") {
1358
					$wancfg['dhcp6norelease'] = true;
1359
				}
1360
				if ($_POST['dhcp6vlanenable'] == "yes") {
1361
					$wancfg['dhcp6vlanenable'] = true;
1362
				}
1363
				if (!empty($_POST['dhcp6cvpt'])) {
1364
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1365
				} else {
1366
					unset($wancfg['dhcp6cvpt']);
1367
				}
1368

    
1369
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1370
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1371
				}
1372
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1373
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1374
				}
1375
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1376
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1377
				}
1378
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1379
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1380
				}
1381

    
1382
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1383
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1384
				}
1385
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1386
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1387
				}
1388
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1389
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1390
				}
1391
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1392
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1395
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1396
				}
1397

    
1398
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1399
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1400
				}
1401
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1402
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1403
				}
1404
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1405
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1406
				}
1407
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1408
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1409
				}
1410
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1411
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1412
				}
1413

    
1414
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1415
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1416
				}
1417
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1418
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1419
				}
1420
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1421
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1422
				}
1423
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1424
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1425
				}
1426
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1427
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1428
				}
1429
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1430
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1431
				}
1432
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1433
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1434
				}
1435

    
1436
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1437
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1438
				}
1439
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1440
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1441
				}
1442
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1443
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1444
				}
1445
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1446
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1447
				}
1448
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1449
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1450
				}
1451

    
1452
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1453
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1454
				}
1455
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1456
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1457
				}
1458
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1459
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1460
				}
1461

    
1462
				if ($gateway_item) {
1463
					$a_gateways[] = $gateway_item;
1464
				}
1465
				break;
1466
			case "6rd":
1467
				$wancfg['ipaddrv6'] = "6rd";
1468
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1469
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1470
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1471
				if ($gateway_item) {
1472
					$a_gateways[] = $gateway_item;
1473
				}
1474
				break;
1475
			case "6to4":
1476
				$wancfg['ipaddrv6'] = "6to4";
1477
				break;
1478
			case "track6":
1479
				$wancfg['ipaddrv6'] = "track6";
1480
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1481
				if ($_POST['track6-prefix-id--hex'] === "") {
1482
					$wancfg['track6-prefix-id'] = 0;
1483
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1484
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1485
				} else {
1486
					$wancfg['track6-prefix-id'] = 0;
1487
				}
1488
				break;
1489
			case "none":
1490
				break;
1491
		}
1492
		handle_pppoe_reset($_POST);
1493

    
1494
		if ($_POST['blockpriv'] == "yes") {
1495
			$wancfg['blockpriv'] = true;
1496
		} else {
1497
			unset($wancfg['blockpriv']);
1498
		}
1499
		if ($_POST['blockbogons'] == "yes") {
1500
			$wancfg['blockbogons'] = true;
1501
		} else {
1502
			unset($wancfg['blockbogons']);
1503
		}
1504
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1505
		if (empty($_POST['mtu'])) {
1506
			unset($wancfg['mtu']);
1507
		} else {
1508
			$wancfg['mtu'] = $_POST['mtu'];
1509
		}
1510
		if (empty($_POST['mss'])) {
1511
			unset($wancfg['mss']);
1512
		} else {
1513
			$wancfg['mss'] = $_POST['mss'];
1514
		}
1515
		if (empty($_POST['mediaopt'])) {
1516
			unset($wancfg['media']);
1517
			unset($wancfg['mediaopt']);
1518
		} else {
1519
			$mediaopts = explode(' ', $_POST['mediaopt']);
1520
			if ($mediaopts[0] != '') {
1521
				$wancfg['media'] = $mediaopts[0];
1522
			}
1523
			if ($mediaopts[1] != '') {
1524
				$wancfg['mediaopt'] = $mediaopts[1];
1525
			} else {
1526
				unset($wancfg['mediaopt']);
1527
			}
1528
		}
1529
		if (isset($wancfg['wireless'])) {
1530
			handle_wireless_post();
1531
		}
1532

    
1533
		write_config();
1534

    
1535
		if ($_POST['gatewayip4']) {
1536
			save_gateway($gateway_settings4);
1537
		}
1538

    
1539
		if ($_POST['gatewayip6']) {
1540
			save_gateway($gateway_settings6);
1541
		}
1542

    
1543
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1544
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1545
		} else {
1546
			$toapplylist = array();
1547
		}
1548
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1549
		$toapplylist[$if]['ppps'] = $old_ppps;
1550
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1551

    
1552
		mark_subsystem_dirty('interfaces');
1553

    
1554
		/* regenerate cron settings/crontab file */
1555
		configure_cron();
1556

    
1557
		header("Location: interfaces.php?if={$if}");
1558
		exit;
1559
	}
1560

    
1561
} // end if ($_POST['save'])
1562

    
1563
function handle_wireless_post() {
1564
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1565
	if (!is_array($wancfg['wireless'])) {
1566
		$wancfg['wireless'] = array();
1567
	}
1568
	$wancfg['wireless']['standard'] = $_POST['standard'];
1569
	$wancfg['wireless']['mode'] = $_POST['mode'];
1570
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1571
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1572
	$wancfg['wireless']['channel'] = $_POST['channel'];
1573
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1574
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1575
	$wancfg['wireless']['distance'] = $_POST['distance'];
1576
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1577
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1578
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1579
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1580
		foreach ($wl_countries_attr as $wl_country) {
1581
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1582
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1583
				break;
1584
			}
1585
		}
1586
	}
1587
	if (!is_array($wancfg['wireless']['wpa'])) {
1588
		$wancfg['wireless']['wpa'] = array();
1589
	}
1590
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1591
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1592
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1593
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1594
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1595
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1596
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1597
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1598
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1599
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1600
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1601
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1602
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1603
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1604

    
1605
	if ($_POST['persistcommonwireless'] == "yes") {
1606
		if (!is_array($config['wireless'])) {
1607
			$config['wireless'] = array();
1608
		}
1609
		if (!is_array($config['wireless']['interfaces'])) {
1610
			$config['wireless']['interfaces'] = array();
1611
		}
1612
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1613
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1614
		}
1615
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1616
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1617
	}
1618
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1619
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1620
	} else if (isset($wancfg['wireless']['diversity'])) {
1621
		unset($wancfg['wireless']['diversity']);
1622
	}
1623
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1624
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1625
	} else if (isset($wancfg['wireless']['txantenna'])) {
1626
		unset($wancfg['wireless']['txantenna']);
1627
	}
1628
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1629
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1630
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1631
		unset($wancfg['wireless']['rxantenna']);
1632
	}
1633
	if ($_POST['hidessid_enable'] == "yes") {
1634
		$wancfg['wireless']['hidessid']['enable'] = true;
1635
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1636
		unset($wancfg['wireless']['hidessid']['enable']);
1637
	}
1638
	if ($_POST['mac_acl_enable'] == "yes") {
1639
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1640
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1641
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1642
	}
1643
	if ($_POST['rsn_preauth'] == "yes") {
1644
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1645
	} else {
1646
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1647
	}
1648
	if ($_POST['ieee8021x'] == "yes") {
1649
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1650
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1651
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1652
	}
1653
	if ($_POST['wpa_strict_rekey'] == "yes") {
1654
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1655
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1656
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1657
	}
1658
	if ($_POST['debug_mode'] == "yes") {
1659
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1660
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1661
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1662
	}
1663
	if ($_POST['wpa_enable'] == "yes") {
1664
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1665
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1666
		unset($wancfg['wireless']['wpa']['enable']);
1667
	}
1668

    
1669
	if ($_POST['wme_enable'] == "yes") {
1670
		if (!is_array($wancfg['wireless']['wme'])) {
1671
			$wancfg['wireless']['wme'] = array();
1672
		}
1673
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1674
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1675
		unset($wancfg['wireless']['wme']['enable']);
1676
	}
1677
	if ($_POST['puremode'] == "11g") {
1678
		if (!is_array($wancfg['wireless']['pureg'])) {
1679
			$wancfg['wireless']['pureg'] = array();
1680
		}
1681
		$wancfg['wireless']['pureg']['enable'] = true;
1682
	} else if ($_POST['puremode'] == "11n") {
1683
		if (!is_array($wancfg['wireless']['puren'])) {
1684
			$wancfg['wireless']['puren'] = array();
1685
		}
1686
		$wancfg['wireless']['puren']['enable'] = true;
1687
	} else {
1688
		if (isset($wancfg['wireless']['pureg'])) {
1689
			unset($wancfg['wireless']['pureg']);
1690
		}
1691
		if (isset($wancfg['wireless']['puren'])) {
1692
			unset($wancfg['wireless']['puren']);
1693
		}
1694
	}
1695
	if ($_POST['apbridge_enable'] == "yes") {
1696
		if (!is_array($wancfg['wireless']['apbridge'])) {
1697
			$wancfg['wireless']['apbridge'] = array();
1698
		}
1699
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1700
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1701
		unset($wancfg['wireless']['apbridge']['enable']);
1702
	}
1703
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1704
		if (!is_array($wancfg['wireless']['turbo'])) {
1705
			$wancfg['wireless']['turbo'] = array();
1706
		}
1707
		$wancfg['wireless']['turbo']['enable'] = true;
1708
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1709
		unset($wancfg['wireless']['turbo']['enable']);
1710
	}
1711

    
1712
	interface_sync_wireless_clones($wancfg, true);
1713
}
1714

    
1715
function check_wireless_mode() {
1716
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1717

    
1718
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1719
		return;
1720
	}
1721

    
1722
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1723
		$clone_count = 1;
1724
	} else {
1725
		$clone_count = 0;
1726
	}
1727

    
1728
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1729
		foreach ($config['wireless']['clone'] as $clone) {
1730
			if ($clone['if'] == $wlanbaseif) {
1731
				$clone_count++;
1732
			}
1733
		}
1734
	}
1735

    
1736
	if ($clone_count > 1) {
1737
		$old_wireless_mode = $wancfg['wireless']['mode'];
1738
		$wancfg['wireless']['mode'] = $_POST['mode'];
1739
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1740
			$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']]);
1741
		} else {
1742
			pfSense_interface_destroy("{$wlanif}_");
1743
		}
1744
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1745
	}
1746
}
1747

    
1748
// Find all possible media options for the interface
1749
$mediaopts_list = array();
1750
$intrealname = $config['interfaces'][$if]['if'];
1751
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1752
foreach ($mediaopts as $mediaopt) {
1753
	preg_match("/media (.*)/", $mediaopt, $matches);
1754
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1755
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1756
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1757
	} else {
1758
		// there is only media like "media 1000baseT"
1759
		array_push($mediaopts_list, $matches[1]);
1760
	}
1761
}
1762

    
1763
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1764
$shortcut_section = "interfaces";
1765

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

    
1769
// Get the MAC address
1770
$ip = $_SERVER['REMOTE_ADDR'];
1771
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1772
$mymac = str_replace("\n", "", $mymac);
1773
$defgatewayname4 = $wancfg['descr'] . "GW";
1774
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1775

    
1776
function build_mediaopts_list() {
1777
	global $mediaopts_list;
1778

    
1779
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1780
			 " " =>	 gettext("------- Media Supported by this interface -------")
1781
			];
1782

    
1783
	foreach ($mediaopts_list as $mediaopt) {
1784
		$list[$mediaopt] = $mediaopt;
1785
	}
1786

    
1787
	return($list);
1788
}
1789

    
1790
function build_gateway_list() {
1791
	global $a_gateways, $if;
1792

    
1793
	$list = array("none" => gettext("None"));
1794
	foreach ($a_gateways as $gateway) {
1795
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1796
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1797
		}
1798
	}
1799

    
1800
	return($list);
1801
}
1802

    
1803
function build_gatewayv6_list() {
1804
	global $a_gateways, $if;
1805

    
1806
	$list = array("none" => gettext("None"));
1807
	foreach ($a_gateways as $gateway) {
1808
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1809
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1810
		}
1811
	}
1812

    
1813
	return($list);
1814
}
1815

    
1816
include("head.inc");
1817

    
1818
if ($input_errors) {
1819
	print_input_errors($input_errors);
1820
}
1821

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

    
1828
if ($changes_applied) {
1829
	print_apply_result_box($retval);
1830
}
1831

    
1832
$form = new Form();
1833

    
1834
$section = new Form_Section('General Configuration');
1835

    
1836
$section->addInput(new Form_Checkbox(
1837
	'enable',
1838
	'Enable',
1839
	'Enable interface',
1840
	$pconfig['enable'],
1841
	'yes'
1842
));
1843

    
1844
$section->addInput(new Form_Input(
1845
	'descr',
1846
	'*Description',
1847
	'text',
1848
	$pconfig['descr']
1849
))->setHelp('Enter a description (name) for the interface here.');
1850

    
1851
if ($show_address_controls) {
1852
	$section->addInput(new Form_Select(
1853
		'type',
1854
		'IPv4 Configuration Type',
1855
		$pconfig['type'],
1856
		$types4
1857
	));
1858
	$section->addInput(new Form_Select(
1859
		'type6',
1860
		'IPv6 Configuration Type',
1861
		$pconfig['type6'],
1862
		$types6
1863
	));
1864
} else {
1865
	$section->addInput(new Form_StaticText(
1866
		'IPv4/IPv6 Configuration',
1867
		"This interface type does not support manual address configuration on this page. "
1868
	));
1869
	$section->addInput(new Form_Input(
1870
		'type',
1871
		null,
1872
		'hidden',
1873
		'none'
1874
	));
1875
	$section->addInput(new Form_Input(
1876
		'type6',
1877
		null,
1878
		'hidden',
1879
		'none'
1880
	));
1881
}
1882

    
1883
$macaddress = new Form_Input(
1884
	'spoofmac',
1885
	'MAC Address',
1886
	'text',
1887
	$pconfig['spoofmac'],
1888
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1889
);
1890

    
1891
$btnmymac = new Form_Button(
1892
	'btnmymac',
1893
	'Copy My MAC',
1894
	null,
1895
	'fa-clone'
1896
	);
1897

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

    
1900
$group = new Form_Group('MAC Address');
1901
$group->add($macaddress);
1902
// $group->add($btnmymac);
1903
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1904
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1905
$section->add($group);
1906

    
1907
$section->addInput(new Form_Input(
1908
	'mtu',
1909
	'MTU',
1910
	'number',
1911
	$pconfig['mtu']
1912
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1913
			'This is typically 1500 bytes but can vary in some circumstances.');
1914

    
1915
$section->addInput(new Form_Input(
1916
	'mss',
1917
	'MSS',
1918
	'number',
1919
	$pconfig['mss']
1920
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1921
			'header size) will be in effect.');
1922

    
1923
if (count($mediaopts_list) > 0) {
1924
	$section->addInput(new Form_Select(
1925
		'mediaopt',
1926
		'Speed and Duplex',
1927
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1928
		build_mediaopts_list()
1929
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1930
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1931
}
1932

    
1933
$form->add($section);
1934

    
1935
$section = new Form_Section('Static IPv4 Configuration');
1936
$section->addClass('staticv4');
1937

    
1938
$section->addInput(new Form_IpAddress(
1939
	'ipaddr',
1940
	'*IPv4 Address',
1941
	$pconfig['ipaddr'],
1942
	'V4'
1943
))->addMask('subnet', $pconfig['subnet'], 32);
1944

    
1945
$group = new Form_Group('IPv4 Upstream gateway');
1946

    
1947
$group->add(new Form_Select(
1948
	'gateway',
1949
	'IPv4 Upstream Gateway',
1950
	$pconfig['gateway'],
1951
	build_gateway_list()
1952
));
1953

    
1954
$group->add(new Form_Button(
1955
	'addgw4',
1956
	'Add a new gateway',
1957
	null,
1958
	'fa-plus'
1959
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1960

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

    
1965
$section->add($group);
1966

    
1967
$form->add($section);
1968

    
1969
$section = new Form_Section('Static IPv6 Configuration');
1970
$section->addClass('staticv6');
1971

    
1972
$section->addInput(new Form_IpAddress(
1973
	'ipaddrv6',
1974
	'*IPv6 address',
1975
	$pconfig['ipaddrv6'],
1976
	'V6'
1977
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1978

    
1979
$section->addInput(new Form_Checkbox(
1980
	'ipv6usev4iface',
1981
	'Use IPv4 connectivity as parent interface',
1982
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1983
	$pconfig['ipv6usev4iface']
1984
));
1985

    
1986
$group = new Form_Group('IPv6 Upstream gateway');
1987

    
1988
$group->add(new Form_Select(
1989
	'gatewayv6',
1990
	'IPv6 Upstream Gateway',
1991
	$pconfig['gatewayv6'],
1992
	build_gatewayv6_list()
1993
));
1994

    
1995
$group->add(new Form_Button(
1996
	'addgw6',
1997
	'Add a new gateway',
1998
	null,
1999
	'fa-plus'
2000
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2001

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

    
2005
$section->add($group);
2006
$form->add($section);
2007

    
2008
// Add new gateway modal pop-up for IPv6
2009
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2010

    
2011
$modal->addInput(new Form_Checkbox(
2012
	'defaultgw6',
2013
	'Default',
2014
	'Default gateway',
2015
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2016
));
2017

    
2018
$modal->addInput(new Form_Input(
2019
	'gatewayname6',
2020
	'Gateway name',
2021
	'text',
2022
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2023
));
2024

    
2025
$modal->addInput(new Form_IpAddress(
2026
	'gatewayip6',
2027
	'Gateway IPv6',
2028
	$gateway_settings6['gateway'],
2029
	'V6'
2030
));
2031

    
2032
$modal->addInput(new Form_Input(
2033
	'gatewaydescr6',
2034
	'Description',
2035
	'text',
2036
	$gateway_settings6['descr']
2037
));
2038

    
2039
$btnaddgw6 = new Form_Button(
2040
	'add6',
2041
	'Add',
2042
	null,
2043
	'fa-plus'
2044
);
2045

    
2046
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2047

    
2048
$btncnxgw6 = new Form_Button(
2049
	'cnx6',
2050
	'Cancel',
2051
	null,
2052
	'fa-undo'
2053
);
2054

    
2055
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2056

    
2057
$modal->addInput(new Form_StaticText(
2058
	null,
2059
	$btnaddgw6 . $btncnxgw6
2060
));
2061

    
2062
$form->add($modal);
2063

    
2064
// ==== DHCP client configuration =============================
2065

    
2066
$section = new Form_Section('DHCP Client Configuration');
2067
$section->addClass('dhcp');
2068

    
2069
$group = new Form_Group('Options');
2070

    
2071
$group->add(new Form_Checkbox(
2072
	'adv_dhcp_config_advanced',
2073
	null,
2074
	'Advanced Configuration',
2075
	$pconfig['adv_dhcp_config_advanced']
2076
))->setHelp('Use advanced DHCP configuration options.');
2077

    
2078
$group->add(new Form_Checkbox(
2079
	'adv_dhcp_config_file_override',
2080
	null,
2081
	'Configuration Override',
2082
	$pconfig['adv_dhcp_config_file_override']
2083
))->setHelp('Override the configuration from this file.');
2084

    
2085
$section->add($group);
2086

    
2087
$section->addInput(new Form_Input(
2088
	'dhcphostname',
2089
	'Hostname',
2090
	'text',
2091
	$pconfig['dhcphostname']
2092
))->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).');
2093

    
2094
$section->addInput(new Form_IpAddress(
2095
	'alias-address',
2096
	'Alias IPv4 address',
2097
	$pconfig['alias-address'],
2098
	'V4'
2099
))->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.');
2100

    
2101
$section->addInput(new Form_Input(
2102
	'dhcprejectfrom',
2103
	'Reject leases from',
2104
	'text',
2105
	$pconfig['dhcprejectfrom']
2106
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2107
			'(separate multiple entries with a comma). ' .
2108
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2109

    
2110
if (interface_is_vlan($wancfg['if']) != NULL) {
2111

    
2112
	$group = new Form_Group('DHCP VLAN Priority');
2113
	$group->add(new Form_Checkbox(
2114
		'dhcpvlanenable',
2115
		null,
2116
		'Enable dhcpclient VLAN Priority tagging',
2117
		$pconfig['dhcpvlanenable']
2118
	))->setHelp('Normally off unless specifically required by the ISP.');
2119

    
2120
	$group->add(new Form_Select(
2121
		'dhcpcvpt',
2122
		'VLAN Prio',
2123
		$pconfig['dhcpcvpt'],
2124
		$vlanprio
2125
	))->setHelp('Choose 802.1p priority to set.');
2126

    
2127
	$section->add($group);
2128
}
2129

    
2130
$group = new Form_Group('Protocol timing');
2131
$group->addClass('dhcpadvanced');
2132

    
2133
$group->add(new Form_Input(
2134
	'adv_dhcp_pt_timeout',
2135
	null,
2136
	'number',
2137
	$pconfig['adv_dhcp_pt_timeout']
2138
))->setHelp('Timeout');
2139

    
2140
$group->add(new Form_Input(
2141
	'adv_dhcp_pt_retry',
2142
	null,
2143
	'number',
2144
	$pconfig['adv_dhcp_pt_retry']
2145
))->setHelp('Retry');
2146

    
2147
$group->add(new Form_Input(
2148
	'adv_dhcp_pt_select_timeout',
2149
	null,
2150
	'number',
2151
	$pconfig['adv_dhcp_pt_select_timeout'],
2152
	['min' => 0]
2153
))->setHelp('Select timeout');
2154

    
2155
$group->add(new Form_Input(
2156
	'adv_dhcp_pt_reboot',
2157
	null,
2158
	'number',
2159
	$pconfig['adv_dhcp_pt_reboot']
2160
))->setHelp('Reboot');
2161

    
2162
$group->add(new Form_Input(
2163
	'adv_dhcp_pt_backoff_cutoff',
2164
	null,
2165
	'number',
2166
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2167
))->setHelp('Backoff cutoff');
2168

    
2169
$group->add(new Form_Input(
2170
	'adv_dhcp_pt_initial_interval',
2171
	null,
2172
	'number',
2173
	$pconfig['adv_dhcp_pt_initial_interval']
2174
))->setHelp('Initial interval');
2175

    
2176
$section->add($group);
2177

    
2178
$group = new Form_Group('Presets');
2179
$group->addClass('dhcpadvanced');
2180

    
2181
$group->add(new Form_Checkbox(
2182
	'adv_dhcp_pt_values',
2183
	null,
2184
	'FreeBSD default',
2185
	null,
2186
	'DHCP'
2187
))->displayAsRadio();
2188

    
2189
$group->add(new Form_Checkbox(
2190
	'adv_dhcp_pt_values',
2191
	null,
2192
	'Clear',
2193
	null,
2194
	'Clear'
2195
))->displayAsRadio();
2196

    
2197
$group->add(new Form_Checkbox(
2198
	'adv_dhcp_pt_values',
2199
	null,
2200
	'pfSense Default',
2201
	null,
2202
	'pfSense'
2203
))->displayAsRadio();
2204

    
2205
$group->add(new Form_Checkbox(
2206
	'adv_dhcp_pt_values',
2207
	null,
2208
	'Saved Cfg',
2209
	null,
2210
	'SavedCfg'
2211
))->displayAsRadio();
2212

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

    
2216
$section->add($group);
2217

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

    
2228
$form->add($section);
2229

    
2230
$section = new Form_Section('Lease Requirements and Requests');
2231
$section->addClass('dhcpadvanced');
2232

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

    
2243
$section->addInput(new Form_Input(
2244
	'adv_dhcp_request_options',
2245
	'Request options',
2246
	'text',
2247
	$pconfig['adv_dhcp_request_options']
2248
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2249
			'Some ISPs may require certain options be or not be requested.', '<br />');
2250

    
2251
$section->addInput(new Form_Input(
2252
	'adv_dhcp_required_options',
2253
	'Require options',
2254
	'text',
2255
	$pconfig['adv_dhcp_required_options']
2256
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2257

    
2258
$section->addInput(new Form_Input(
2259
	'adv_dhcp_option_modifiers',
2260
	'Option modifiers',
2261
	'text',
2262
	$pconfig['adv_dhcp_option_modifiers']
2263
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2264
			'modifiers: (default, supersede, prepend, append) %1$s' .
2265
			'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>');
2266

    
2267
$form->add($section);
2268

    
2269
// DHCP6 client config
2270

    
2271
$section = new Form_Section('DHCP6 Client Configuration');
2272
$section->addClass('dhcp6');
2273

    
2274
$group = new Form_Group('Options');
2275

    
2276
$group->add(new Form_Checkbox(
2277
	'adv_dhcp6_config_advanced',
2278
	null,
2279
	'Advanced Configuration',
2280
	$pconfig['adv_dhcp6_config_advanced']
2281
))->setHelp('Use advanced DHCPv6 configuration options.');
2282

    
2283
$group->add(new Form_Checkbox(
2284
	'adv_dhcp6_config_file_override',
2285
	null,
2286
	'Configuration Override',
2287
	$pconfig['adv_dhcp6_config_file_override']
2288
))->setHelp('Override the configuration from this file.');
2289

    
2290
$section->add($group);
2291

    
2292
$section->addInput(new Form_Checkbox(
2293
	'dhcp6usev4iface',
2294
	'Use IPv4 connectivity as parent interface',
2295
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2296
	$pconfig['dhcp6usev4iface']
2297
));
2298

    
2299
$section->addInput(new Form_Checkbox(
2300
	'dhcp6prefixonly',
2301
	'Request only an IPv6 prefix',
2302
	'Only request an IPv6 prefix, do not request an IPv6 address',
2303
	$pconfig['dhcp6prefixonly']
2304
));
2305

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

    
2313
$section->addInput(new Form_Checkbox(
2314
	'dhcp6-ia-pd-send-hint',
2315
	'Send IPv6 prefix hint',
2316
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2317
	$pconfig['dhcp6-ia-pd-send-hint']
2318
));
2319

    
2320
$section->addInput(new Form_Checkbox(
2321
	'dhcp6debug',
2322
	'Debug',
2323
	'Start DHCP6 client in debug mode',
2324
	$pconfig['dhcp6debug']
2325
));
2326
$section->addInput(new Form_Checkbox(
2327
	'dhcp6withoutra',
2328
	'Do not wait for a RA',
2329
	'Required by some ISPs, especially those not using PPPoE',
2330
	$pconfig['dhcp6withoutra']
2331
));
2332
$section->addInput(new Form_Checkbox(
2333
	'dhcp6norelease',
2334
	'Do not allow PD/Address release',
2335
	'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',
2336
	$pconfig['dhcp6norelease']
2337
));
2338

    
2339
if (interface_is_vlan($wancfg['if']) != NULL) {
2340
	$group = new Form_Group('DHCP6 VLAN Priority');
2341

    
2342
	$group->add(new Form_Checkbox(
2343
		'dhcp6vlanenable',
2344
		null,
2345
		'Enable dhcp6c VLAN Priority tagging',
2346
		$pconfig['dhcp6vlanenable']
2347
	))->setHelp('Normally off unless specifically required by the ISP.');
2348

    
2349
	$group->add(new Form_Select(
2350
		'dhcp6cvpt',
2351
		'VLAN Prio',
2352
		$pconfig['dhcp6cvpt'],
2353
		$vlanprio
2354
	))->setHelp('Choose 802.1p priority to set.');
2355

    
2356
	$section->add($group);
2357
}
2358

    
2359
$section->addInput(new Form_Input(
2360
	'adv_dhcp6_config_file_override_path',
2361
	'Configuration File Override',
2362
	'text',
2363
	$pconfig['adv_dhcp6_config_file_override_path']
2364
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2365
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2366
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2367
			'Some ISPs may require certain options be or not be sent.', '<br />');
2368

    
2369
$form->add($section);
2370

    
2371
// DHCP6 client config - Advanced
2372

    
2373
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2374
$section->addClass('dhcp6advanced');
2375

    
2376
$section->addInput(new Form_Checkbox(
2377
	'adv_dhcp6_interface_statement_information_only_enable',
2378
	'Information only',
2379
	'Exchange Information Only',
2380
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2381
	'Selected'
2382
))->setHelp('Only exchange informational configuration parameters with servers.');
2383

    
2384
$section->addInput(new Form_Input(
2385
	'adv_dhcp6_interface_statement_send_options',
2386
	'Send options',
2387
	'text',
2388
	$pconfig['adv_dhcp6_interface_statement_send_options']
2389
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2390
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2391
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2392
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2393

    
2394
$section->addInput(new Form_Input(
2395
	'adv_dhcp6_interface_statement_request_options',
2396
	'Request Options',
2397
	'text',
2398
	$pconfig['adv_dhcp6_interface_statement_request_options']
2399
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2400
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2401

    
2402
$section->addInput(new Form_Input(
2403
	'adv_dhcp6_interface_statement_script',
2404
	'Scripts',
2405
	'text',
2406
	$pconfig['adv_dhcp6_interface_statement_script']
2407
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2408
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2409

    
2410
$group = new Form_Group('Identity Association Statement');
2411

    
2412
$group->add(new Form_Checkbox(
2413
	'adv_dhcp6_id_assoc_statement_address_enable',
2414
	null,
2415
	'Non-Temporary Address Allocation',
2416
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2417
	'Selected'
2418
));
2419

    
2420
$group->add(new Form_Input(
2421
	'adv_dhcp6_id_assoc_statement_address_id',
2422
	null,
2423
	'text',
2424
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2425
))->sethelp('id-assoc na ID');
2426

    
2427
$group->add(new Form_IpAddress(
2428
	'adv_dhcp6_id_assoc_statement_address',
2429
	null,
2430
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2431
	'V6'
2432
))->sethelp('IPv6 address');
2433

    
2434
$group->add(new Form_Input(
2435
	'adv_dhcp6_id_assoc_statement_address_pltime',
2436
	null,
2437
	'text',
2438
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2439
))->sethelp('pltime');
2440

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

    
2448
$section->add($group);
2449

    
2450
// Prefix delegation
2451
$group = new Form_Group('');
2452

    
2453
$group->add(new Form_Checkbox(
2454
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2455
	null,
2456
	'Prefix Delegation ',
2457
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2458
	'Selected'
2459
));
2460

    
2461
$group->add(new Form_Input(
2462
	'adv_dhcp6_id_assoc_statement_prefix_id',
2463
	null,
2464
	'text',
2465
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2466
))->sethelp('id-assoc pd ID');
2467

    
2468
$group->add(new Form_IpAddress(
2469
	'adv_dhcp6_id_assoc_statement_prefix',
2470
	null,
2471
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2472
	'V6'
2473
))->sethelp('IPv6 prefix');
2474

    
2475
$group->add(new Form_Input(
2476
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2477
	null,
2478
	'text',
2479
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2480
))->sethelp('pltime');
2481

    
2482
$group->add(new Form_Input(
2483
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2484
	null,
2485
	'text',
2486
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2487
))->sethelp('vltime');
2488

    
2489
$section->add($group);
2490

    
2491
$group = new Form_Group('Prefix interface statement');
2492

    
2493
$group->add(new Form_Input(
2494
	'adv_dhcp6_prefix_interface_statement_sla_id',
2495
	null,
2496
	'text',
2497
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2498
))->sethelp('Prefix Interface sla-id');
2499

    
2500
$group->add(new Form_Input(
2501
	'adv_dhcp6_prefix_interface_statement_sla_len',
2502
	null,
2503
	'text',
2504
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2505
))->sethelp('sla-len');
2506

    
2507
$section->add($group);
2508

    
2509
$group = new Form_Group('Select prefix interface');
2510
$section->addInput(new Form_Select(
2511
	'adv_dhcp6_prefix_selected_interface',
2512
	'Prefix Interface',
2513
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2514
	$interfaces
2515
))->setHelp('Select the interface on which to apply the prefix delegation.');
2516

    
2517
$group = new Form_Group('Authentication statement');
2518

    
2519
$group->add(new Form_Input(
2520
	'adv_dhcp6_authentication_statement_authname',
2521
	null,
2522
	'text',
2523
	$pconfig['adv_dhcp6_authentication_statement_authname']
2524
))->sethelp('Authname');
2525

    
2526
$group->add(new Form_Input(
2527
	'adv_dhcp6_authentication_statement_protocol',
2528
	null,
2529
	'text',
2530
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2531
))->sethelp('Protocol');
2532

    
2533
$group->add(new Form_Input(
2534
	'adv_dhcp6_authentication_statement_algorithm',
2535
	null,
2536
	'text',
2537
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2538
))->sethelp('Algorithm');
2539

    
2540
$group->add(new Form_Input(
2541
	'adv_dhcp6_authentication_statement_rdm',
2542
	null,
2543
	'text',
2544
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2545
))->sethelp('RDM');
2546

    
2547
$section->add($group);
2548

    
2549
$group = new Form_Group('Keyinfo statement');
2550

    
2551
$group->add(new Form_Input(
2552
	'adv_dhcp6_key_info_statement_keyname',
2553
	null,
2554
	'text',
2555
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2556
))->sethelp('Keyname');
2557

    
2558
$group->add(new Form_Input(
2559
	'adv_dhcp6_key_info_statement_realm',
2560
	null,
2561
	'text',
2562
	$pconfig['adv_dhcp6_key_info_statement_realm']
2563
))->sethelp('Realm');
2564

    
2565
$section->add($group);
2566

    
2567
$group = new Form_Group('');
2568

    
2569
$group->add(new Form_Input(
2570
	'adv_dhcp6_key_info_statement_keyid',
2571
	null,
2572
	'text',
2573
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2574
))->sethelp('KeyID');
2575

    
2576
$group->add(new Form_Input(
2577
	'adv_dhcp6_key_info_statement_secret',
2578
	null,
2579
	'text',
2580
	$pconfig['adv_dhcp6_key_info_statement_secret']
2581
))->sethelp('Secret');
2582

    
2583
$group->add(new Form_Input(
2584
	'adv_dhcp6_key_info_statement_expire',
2585
	null,
2586
	'text',
2587
	$pconfig['adv_dhcp6_key_info_statement_expire']
2588
))->sethelp('Expire');
2589

    
2590
$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+11.0-RELEASE+and+Ports#Interface_statement">', '</a>');
2591

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

    
2594
$form->add($section);
2595

    
2596
$section = new Form_Section('6RD Configuration');
2597
$section->addClass('_6rd');
2598

    
2599
$section->addInput(new Form_Input(
2600
	'prefix-6rd',
2601
	'6RD Prefix',
2602
	'text',
2603
	$pconfig['prefix-6rd']
2604
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2605

    
2606
$section->addInput(new Form_Input(
2607
	'gateway-6rd',
2608
	'*6RD Border relay',
2609
	'text',
2610
	$pconfig['gateway-6rd']
2611
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2612

    
2613
$section->addInput(new Form_Select(
2614
	'prefix-6rd-v4plen',
2615
	'6RD IPv4 Prefix length',
2616
	$pconfig['prefix-6rd-v4plen'],
2617
	array_combine(range(0, 32), range(0, 32))
2618
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2619

    
2620
$form->add($section);
2621

    
2622
// Track IPv6 ointerface section
2623
$section = new Form_Section('Track IPv6 Interface');
2624
$section->addClass('track6');
2625

    
2626
function build_ipv6interface_list() {
2627
	global $config, $section;
2628

    
2629
	$list = array('' => '');
2630

    
2631
	$interfaces = get_configured_interface_with_descr(true);
2632
	$dynv6ifs = array();
2633

    
2634
	foreach ($interfaces as $iface => $ifacename) {
2635
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2636
			case "6to4":
2637
			case "6rd":
2638
			case "dhcp6":
2639
				$dynv6ifs[$iface] = array(
2640
					'name' => $ifacename,
2641
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2642
				);
2643
				break;
2644
			default:
2645
				continue;
2646
		}
2647
	}
2648

    
2649
	foreach ($dynv6ifs as $iface => $ifacedata) {
2650
		$list[$iface] = $ifacedata['name'];
2651

    
2652
		$section->addInput(new Form_Input(
2653
			'ipv6-num-prefix-ids-' . $iface,
2654
			null,
2655
			'hidden',
2656
			$ifacedata['ipv6_num_prefix_ids']
2657
		));
2658
	}
2659

    
2660
	return($list);
2661
}
2662

    
2663
$section->addInput(new Form_Select(
2664
	'track6-interface',
2665
	'*IPv6 Interface',
2666
	$pconfig['track6-interface'],
2667
	build_ipv6interface_list()
2668
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2669

    
2670
if ($pconfig['track6-prefix-id'] == "") {
2671
	$pconfig['track6-prefix-id'] = 0;
2672
}
2673

    
2674
$section->addInput(new Form_Input(
2675
	'track6-prefix-id--hex',
2676
	'IPv6 Prefix ID',
2677
	'text',
2678
	sprintf("%x", $pconfig['track6-prefix-id'])
2679
))->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>');
2680

    
2681
$section->addInput(new Form_Input(
2682
	'track6-prefix-id-max',
2683
	null,
2684
	'hidden',
2685
	0
2686
));
2687

    
2688
$form->add($section);
2689

    
2690
/// PPP section
2691

    
2692
$section = new Form_Section('PPP Configuration');
2693
$section->addClass('ppp');
2694

    
2695
$section->addInput(new Form_Select(
2696
	'country',
2697
	'Country',
2698
	$pconfig['country'],
2699
	[]
2700
));
2701

    
2702
$section->addInput(new Form_Select(
2703
	'provider_list',
2704
	'Provider',
2705
	$pconfig['provider_list'],
2706
	[]
2707
));
2708

    
2709
$section->addInput(new Form_Select(
2710
	'providerplan',
2711
	'Plan',
2712
	$pconfig['providerplan'],
2713
	[]
2714
))->setHelp('Select to fill in service provider data.');
2715

    
2716
$section->addInput(new Form_Input(
2717
	'ppp_username',
2718
	'Username',
2719
	'text',
2720
	$pconfig['ppp_username']
2721
));
2722

    
2723
$section->addPassword(new Form_Input(
2724
	'ppp_password',
2725
	'Password',
2726
	'password',
2727
	$pconfig['ppp_password']
2728
));
2729

    
2730
$section->addInput(new Form_Input(
2731
	'phone',
2732
	'*Phone number',
2733
	'text',
2734
	$pconfig['phone']
2735
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2736

    
2737
$section->addInput(new Form_Input(
2738
	'apn',
2739
	'Access Point Name',
2740
	'text',
2741
	$pconfig['apn']
2742
));
2743

    
2744

    
2745
function build_port_list() {
2746
	$list = array("" => "None");
2747

    
2748
	$portlist = glob("/dev/cua*");
2749
	$modems	  = glob("/dev/modem*");
2750
	$portlist = array_merge($portlist, $modems);
2751

    
2752
	foreach ($portlist as $port) {
2753
		if (preg_match("/\.(lock|init)$/", $port)) {
2754
			continue;
2755
		}
2756

    
2757
	$list[trim($port)] = $port;
2758
	}
2759

    
2760
	return($list);
2761
}
2762

    
2763
$section->addInput(new Form_Select(
2764
	'port',
2765
	"*Modem port",
2766
	$pconfig['port'],
2767
	build_port_list()
2768
));
2769

    
2770
$section->addInput(new Form_Button(
2771
	'btnadvppp',
2772
	'Advanced PPP',
2773
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2774
	'fa-cog'
2775
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2776

    
2777
$form->add($section);
2778

    
2779
// PPPoE configuration
2780
$section = new Form_Section('PPPoE Configuration');
2781
$section->addClass('pppoe');
2782

    
2783
$section->addInput(new Form_Input(
2784
	'pppoe_username',
2785
	'*Username',
2786
	'text',
2787
	$pconfig['pppoe_username']
2788
));
2789

    
2790
$section->addPassword(new Form_Input(
2791
	'pppoe_password',
2792
	'*Password',
2793
	'password',
2794
	$pconfig['pppoe_password']
2795
));
2796

    
2797
$section->addInput(new Form_Input(
2798
	'provider',
2799
	'Service name',
2800
	'text',
2801
	$pconfig['provider']
2802
))->setHelp('This field can usually be left empty.');
2803

    
2804
$section->addInput(new Form_Checkbox(
2805
	'pppoe_dialondemand',
2806
	'Dial on demand',
2807
	'Enable Dial-On-Demand mode ',
2808
	$pconfig['pppoe_dialondemand'],
2809
	'enable'
2810
));
2811

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

    
2821
$section->addInput(new Form_Select(
2822
	'pppoe-reset-type',
2823
	'Periodic reset',
2824
	$pconfig['pppoe-reset-type'],
2825
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2826
))->setHelp('Select a reset timing type.');
2827

    
2828
$group = new Form_Group('Custom reset');
2829
$group->addClass('pppoecustom');
2830

    
2831
$group->add(new Form_Input(
2832
	'pppoe_resethour',
2833
	null,
2834
	'number',
2835
	$pconfig['pppoe_resethour'],
2836
	['min' => 0, 'max' => 23]
2837
))->setHelp('Hour (0-23)');
2838

    
2839
$group->add(new Form_Input(
2840
	'pppoe_resetminute',
2841
	null,
2842
	'number',
2843
	$pconfig['pppoe_resetminute'],
2844
	['min' => 0, 'max' => 59]
2845
))->setHelp('Minutes (0-59)');
2846

    
2847
$group->add(new Form_Input(
2848
	'pppoe_resetdate',
2849
	null,
2850
	'text',
2851
	$pconfig['pppoe_resetdate']
2852
))->setHelp('Specific date (mm/dd/yyyy)');
2853

    
2854
$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');
2855

    
2856
$section->add($group);
2857

    
2858
$group = new Form_MultiCheckboxGroup('cron based reset');
2859
$group->addClass('pppoepreset');
2860

    
2861
$group->add(new Form_MultiCheckbox(
2862
	'pppoe_pr_preset_val',
2863
	null,
2864
	'Reset at each month ("0 0 1 * *")',
2865
	$pconfig['pppoe_monthly'],
2866
	'monthly'
2867
))->displayAsRadio();
2868

    
2869
$group->add(new Form_MultiCheckbox(
2870
	'pppoe_pr_preset_val',
2871
	null,
2872
	'Reset at each week ("0 0 * * 0")',
2873
	$pconfig['pppoe_weekly'],
2874
	'weekly'
2875
))->displayAsRadio();
2876

    
2877
$group->add(new Form_MultiCheckbox(
2878
	'pppoe_pr_preset_val',
2879
	null,
2880
	'Reset at each day ("0 0 * * *")',
2881
	$pconfig['pppoe_daily'],
2882
	'daily'
2883
))->displayAsRadio();
2884

    
2885
$group->add(new Form_MultiCheckbox(
2886
	'pppoe_pr_preset_val',
2887
	null,
2888
	'Reset at each hour ("0 * * * *")',
2889
	$pconfig['pppoe_hourly'],
2890
	'hourly'
2891
))->displayAsRadio();
2892

    
2893
$section->add($group);
2894

    
2895
$section->addInput(new Form_Button(
2896
	'btnadvppp',
2897
	'Advanced and MLPPP',
2898
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2899
	'fa-cog'
2900
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2901

    
2902
$form->add($section);
2903

    
2904
// PPTP & L2TP Configuration section
2905
$section = new Form_Section('PPTP/L2TP Configuration');
2906
$section->addClass('pptp');
2907

    
2908
$section->addInput(new Form_Input(
2909
	'pptp_username',
2910
	'*Username',
2911
	'text',
2912
	$pconfig['pptp_username']
2913
));
2914

    
2915
$section->addPassword(new Form_Input(
2916
	'pptp_password',
2917
	'*Password',
2918
	'password',
2919
	$pconfig['pptp_password']
2920
));
2921

    
2922
$section->addInput(new Form_IpAddress(
2923
	'pptp_local0',
2924
	'*Local IP address',
2925
	$pconfig['pptp_localip'][0],
2926
	'V4'
2927
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2928

    
2929
$section->addInput(new Form_IpAddress(
2930
	'pptp_remote0',
2931
	'*Remote IP address',
2932
	$pconfig['pptp_remote'][0],
2933
	'HOSTV4'
2934
));
2935

    
2936
$section->addInput(new Form_Checkbox(
2937
	'pptp_dialondemand',
2938
	'Dial on demand',
2939
	'Enable Dial-On-Demand mode ',
2940
	$pconfig['pptp_dialondemand'],
2941
	'enable'
2942
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2943
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2944

    
2945
$section->addInput(new Form_Input(
2946
	'pptp_idletimeout',
2947
	'Idle timeout (seconds)',
2948
	'number',
2949
	$pconfig['pptp_idletimeout'],
2950
	['min' => 0]
2951
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2952
			'An idle timeout of zero disables this feature.');
2953

    
2954
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2955
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2956
} else {
2957
	$mlppp_text = "";
2958
}
2959

    
2960
$section->addInput(new Form_Button(
2961
	'btnadvppp',
2962
	'Advanced and MLPPP',
2963
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2964
	'fa-cog'
2965
))->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);
2966

    
2967
$form->add($section);
2968

    
2969
// Wireless interface
2970
if (isset($wancfg['wireless'])) {
2971

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

    
2974
	$section->addInput(new Form_Checkbox(
2975
		'persistcommonwireless',
2976
		'Persist common settings',
2977
		'Preserve common wireless configuration through interface deletions and reassignments.',
2978
		$pconfig['persistcommonwireless'],
2979
		'yes'
2980
	));
2981

    
2982
	$mode_list = ['auto' => 'Auto'];
2983

    
2984
	if (is_array($wl_modes)) {
2985
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2986
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2987
		}
2988
	}
2989

    
2990
	if (count($mode_list) == 1) {
2991
		$mode_list[''] = '';
2992
	}
2993

    
2994
	$section->addInput(new Form_Select(
2995
		'standard',
2996
		'Standard',
2997
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2998
		$mode_list
2999
	));
3000

    
3001
	if (isset($wl_modes['11g'])) {
3002
		$section->addInput(new Form_Select(
3003
			'protmode',
3004
			'802.11g OFDM Protection Mode',
3005
			$pconfig['protmode'],
3006
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3007
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3008
	} else {
3009
		$section->addInput(new Form_Input(
3010
			'protmode',
3011
			null,
3012
			'hidden',
3013
			'off'
3014
		));
3015
	}
3016

    
3017
	$mode_list = ['0' => gettext('Auto')];
3018

    
3019
	if (is_array($wl_modes)) {
3020
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3021
			if ($wl_standard == "11g") {
3022
				$wl_standard = "11b/g";
3023
			} else if ($wl_standard == "11ng") {
3024
				$wl_standard = "11b/g/n";
3025
			} else if ($wl_standard == "11na") {
3026
				$wl_standard = "11a/n";
3027
			}
3028

    
3029
			foreach ($wl_channels as $wl_channel) {
3030
				if (isset($wl_chaninfo[$wl_channel])) {
3031
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
3032
				} else {
3033
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3034
				}
3035
			}
3036
		}
3037
	}
3038

    
3039
	$section->addInput(new Form_Select(
3040
		'channel',
3041
		'Channel',
3042
		$pconfig['channel'],
3043
		$mode_list
3044
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3045
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3046

    
3047
	if (ANTENNAS) {
3048
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3049
			$group = new Form_Group('Antenna Settings');
3050

    
3051
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3052
				$group->add(new Form_Select(
3053
					'diversity',
3054
					null,
3055
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3056
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3057
				))->setHelp('Diversity');
3058
			}
3059

    
3060
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3061
				$group->add(new Form_Select(
3062
					'txantenna',
3063
					null,
3064
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3065
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3066
				))->setHelp('Transmit antenna');
3067
			}
3068

    
3069
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3070
				$group->add(new Form_Select(
3071
					'rxantenna',
3072
					null,
3073
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3074
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3075
				))->setHelp('Receive antenna');
3076
			}
3077

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

    
3080
			$section->add($group);
3081
		}
3082
	}
3083

    
3084
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3085
			$section->addInput(new Form_Input(
3086
				'distance',
3087
				'Distance setting (meters)',
3088
				'test',
3089
				$pconfig['distance']
3090
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3091
	}
3092

    
3093
	$form->add($section);
3094

    
3095
	// Regulatory settings
3096
	$section = new Form_Section('Regulatory Settings');
3097

    
3098
	$domain_list = array("" => 'Default');
3099

    
3100
	if (is_array($wl_regdomains)) {
3101
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3102
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3103
		}
3104
	}
3105

    
3106
	$section->addInput(new Form_Select(
3107
		'regdomain',
3108
		'Regulatory domain',
3109
		$pconfig['regdomain'],
3110
		$domain_list
3111
	))->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');
3112

    
3113
	$country_list = array('' => 'Default');
3114

    
3115
	if (is_array($wl_countries)) {
3116
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3117
			$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']);
3118
		}
3119
	}
3120

    
3121
	$section->addInput(new Form_Select(
3122
		'regcountry',
3123
		'Country',
3124
		$pconfig['regcountry'],
3125
		$country_list
3126
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3127

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

    
3139
	$form->add($section);
3140

    
3141
	$section = new Form_Section('Network-Specific Wireless Configuration');
3142

    
3143
	$section->addInput(new Form_Select(
3144
		'mode',
3145
		'Mode',
3146
		$pconfig['mode'],
3147
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3148
	));
3149

    
3150
	$section->addInput(new Form_Input(
3151
		'ssid',
3152
		'SSID',
3153
		'text',
3154
		$pconfig['ssid']
3155
	));
3156

    
3157
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3158
		$section->addInput(new Form_Select(
3159
			'puremode',
3160
			'Minimum wireless standard',
3161
			$pconfig['puremode'],
3162
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3163
		))->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)');
3164
	} elseif (isset($wl_modes['11g'])) {
3165
		$section->addInput(new Form_Checkbox(
3166
			'puremode',
3167
			'802.11g only',
3168
			null,
3169
			$pconfig['puremode'],
3170
			'11g'
3171
		))->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)');
3172
	}
3173

    
3174
	$section->addInput(new Form_Checkbox(
3175
		'apbridge_enable',
3176
		'Allow intra-BSS communication',
3177
		'Allow packets to pass between wireless clients directly when operating as an access point',
3178
		$pconfig['apbridge_enable'],
3179
		'yes'
3180
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3181

    
3182
	$section->addInput(new Form_Checkbox(
3183
		'wme_enable',
3184
		'Enable WME',
3185
		'Force the card to use WME (wireless QoS)',
3186
		$pconfig['wme_enable'],
3187
		'yes'
3188
	));
3189

    
3190
	$section->addInput(new Form_Checkbox(
3191
		'hidessid_enable',
3192
		'Hide SSID',
3193
		'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.)',
3194
		$pconfig['hidessid_enable'],
3195
		'yes'
3196
	));
3197

    
3198
	$form->add($section);
3199

    
3200
	// WPA Section
3201
	$section = new Form_Section('WPA');
3202

    
3203
	$section->addInput(new Form_Checkbox(
3204
		'wpa_enable',
3205
		'Enable',
3206
		'Enable WPA',
3207
		$pconfig['wpa_enable'],
3208
		'yes'
3209
	));
3210

    
3211
	$section->addInput(new Form_Input(
3212
		'passphrase',
3213
		'WPA Pre-Shared Key',
3214
		'text',
3215
		$pconfig['passphrase']
3216
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3217

    
3218
	$section->addInput(new Form_Select(
3219
		'wpa_mode',
3220
		'WPA mode',
3221
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3222
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3223
	));
3224

    
3225
	$section->addInput(new Form_Select(
3226
		'wpa_key_mgmt',
3227
		'WPA Key Management Mode',
3228
		$pconfig['wpa_key_mgmt'],
3229
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3230
	));
3231

    
3232
	$section->addInput(new Form_Select(
3233
		'wpa_pairwise',
3234
		'WPA Pairwise',
3235
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3236
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3237
	));
3238

    
3239
	$section->addInput(new Form_Input(
3240
		'wpa_group_rekey',
3241
		'Group Key Rotation',
3242
		'number',
3243
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3244
		['min' => '1', 'max' => 9999]
3245
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3246

    
3247
	$section->addInput(new Form_Input(
3248
		'wpa_gmk_rekey',
3249
		'Group Master Key Regeneration',
3250
		'number',
3251
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3252
		['min' => '1', 'max' => 9999]
3253
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3254

    
3255
	$section->addInput(new Form_Checkbox(
3256
		'wpa_strict_rekey',
3257
		'Strict Key Regeneration',
3258
		'Force the AP to rekey whenever a client disassociates',
3259
		$pconfig['wpa_strict_rekey'],
3260
		'yes'
3261
	));
3262

    
3263
	$form->add($section);
3264

    
3265
	$section = new Form_Section('802.1x RADIUS Options');
3266

    
3267
	$section->addInput(new Form_Checkbox(
3268
		'ieee8021x',
3269
		'IEEE802.1X',
3270
		'Enable 802.1X authentication',
3271
		$pconfig['ieee8021x'],
3272
		'yes'
3273
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3274

    
3275
	$group = new Form_Group('Primary 802.1X server');
3276

    
3277
	$group->add(new Form_IpAddress(
3278
		'auth_server_addr',
3279
		'IP Address',
3280
		$pconfig['auth_server_addr']
3281
	))->setHelp('IP address of the RADIUS server');
3282

    
3283
	$group->add(new Form_Input(
3284
		'auth_server_port',
3285
		'Port',
3286
		'number',
3287
		$pconfig['auth_server_port']
3288
	))->setHelp('Server auth port. Default is 1812');
3289

    
3290
	$group->add(new Form_Input(
3291
		'auth_server_shared_secret',
3292
		'Shared Secret',
3293
		'text',
3294
		$pconfig['auth_server_shared_secret']
3295
	))->setHelp('RADIUS Shared secret for this firewall');
3296

    
3297
	$section->add($group);
3298

    
3299
	$group = new Form_Group('Secondary 802.1X server');
3300

    
3301
	$group->add(new Form_IpAddress(
3302
		'auth_server_addr2',
3303
		'IP Address',
3304
		$pconfig['auth_server_addr2']
3305
	))->setHelp('IP address of the RADIUS server');
3306

    
3307
	$group->add(new Form_Input(
3308
		'auth_server_port2',
3309
		'Port',
3310
		'number',
3311
		$pconfig['auth_server_port2']
3312
	))->setHelp('Server auth port. Default is 1812');
3313

    
3314
	$group->add(new Form_Input(
3315
		'auth_server_shared_secret2',
3316
		'Shared Secret',
3317
		'text',
3318
		$pconfig['auth_server_shared_secret2']
3319
	))->setHelp('RADIUS Shared secret for this firewall');
3320

    
3321
	$section->add($group);
3322

    
3323
	$section->addInput(new Form_Checkbox(
3324
		'rsn_preauth',
3325
		'Authentication Roaming Preauth',
3326
		null,
3327
		$pconfig['rsn_preauth'],
3328
		'yes'
3329
	));
3330

    
3331
	$form->add($section);
3332
}
3333

    
3334
$section = new Form_Section('Reserved Networks');
3335

    
3336
$section->addInput(new Form_Checkbox(
3337
	'blockpriv',
3338
	'Block private networks and loopback addresses',
3339
	'',
3340
	$pconfig['blockpriv'],
3341
	'yes'
3342
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3343
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3344
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3345

    
3346
$section->addInput(new Form_Checkbox(
3347
	'blockbogons',
3348
	'Block bogon networks',
3349
	'',
3350
	$pconfig['blockbogons'],
3351
	'yes'
3352
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3353
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3354
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3355

    
3356
$form->add($section);
3357

    
3358
$form->addGlobal(new Form_Input(
3359
	'if',
3360
	null,
3361
	'hidden',
3362
	$if
3363
));
3364

    
3365
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3366
	$form->addGlobal(new Form_Input(
3367
		'ppp_port',
3368
		null,
3369
		'hidden',
3370
		$pconfig['port']
3371
	));
3372
}
3373

    
3374
$form->addGlobal(new Form_Input(
3375
	'ptpid',
3376
	null,
3377
	'hidden',
3378
	$pconfig['ptpid']
3379
));
3380

    
3381

    
3382
// Add new gateway modal pop-up
3383
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3384

    
3385
$modal->addInput(new Form_Checkbox(
3386
	'defaultgw4',
3387
	'Default',
3388
	'Default gateway',
3389
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3390
));
3391

    
3392
$modal->addInput(new Form_Input(
3393
	'gatewayname4',
3394
	'Gateway name',
3395
	'text',
3396
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3397
));
3398

    
3399
$modal->addInput(new Form_IpAddress(
3400
	'gatewayip4',
3401
	'Gateway IPv4',
3402
	$gateway_settings4['gateway'],
3403
	'V4'
3404
));
3405

    
3406
$modal->addInput(new Form_Input(
3407
	'gatewaydescr4',
3408
	'Description',
3409
	'text',
3410
	$gateway_settings4['descr']
3411
));
3412

    
3413
$btnaddgw4 = new Form_Button(
3414
	'add4',
3415
	'Add',
3416
	null,
3417
	'fa-plus'
3418
);
3419

    
3420
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3421

    
3422
$btncnxgw4 = new Form_Button(
3423
	'cnx4',
3424
	'Cancel',
3425
	null,
3426
	'fa-undo'
3427
);
3428

    
3429
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3430

    
3431
$modal->addInput(new Form_StaticText(
3432
	null,
3433
	$btnaddgw4 . $btncnxgw4
3434
));
3435

    
3436
$form->add($modal);
3437

    
3438
print($form);
3439
?>
3440

    
3441
<script type="text/javascript">
3442
//<![CDATA[
3443
events.push(function() {
3444
	function updateType(t) {
3445

    
3446
		switch (t) {
3447
			case "none": {
3448
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3449
				break;
3450
			}
3451
			case "staticv4": {
3452
				$('.dhcpadvanced, .none, .dhcp').hide();
3453
				$('.pppoe, .pptp, .ppp').hide();
3454
				break;
3455
			}
3456
			case "dhcp": {
3457
				$('.dhcpadvanced, .none').hide();
3458
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3459
										//			about the staticv4 class
3460
				$('.pppoe, .pptp, .ppp').hide();
3461
				break;
3462
			}
3463
			case "ppp": {
3464
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3465
				country_list();
3466
				break;
3467
			}
3468
			case "pppoe": {
3469
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3470
				break;
3471
			}
3472
			case "l2tp":
3473
			case "pptp": {
3474
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3475
				$('.pptp').show();
3476
				break;
3477
			}
3478
		}
3479

    
3480
		if (t != "l2tp" && t != "pptp") {
3481
			$('.'+t).show();
3482
		}
3483
	}
3484

    
3485
	function updateTypeSix(t) {
3486
		if (!isNaN(t[0])) {
3487
			t = '_' + t;
3488
		}
3489

    
3490
		switch (t) {
3491
			case "none": {
3492
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3493
				break;
3494
			}
3495
			case "staticv6": {
3496
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3497
				break;
3498
			}
3499
			case "slaac": {
3500
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3501
				break;
3502
			}
3503
			case "dhcp6": {
3504
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3505
				break;
3506
			}
3507
			case "_6rd": {
3508
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3509
				break;
3510
			}
3511
			case "_6to4": {
3512
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3513
				break;
3514
			}
3515
			case "track6": {
3516
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3517
				update_track6_prefix();
3518
				break;
3519
			}
3520
		}
3521

    
3522
		if (t != "l2tp" && t != "pptp") {
3523
			$('.'+t).show();
3524
		}
3525
	}
3526

    
3527
	function show_reset_settings(reset_type) {
3528
		if (reset_type == 'preset') {
3529
			$('.pppoepreset').show();
3530
			$('.pppoecustom').hide();
3531
		} else if (reset_type == 'custom') {
3532
			$('.pppoecustom').show();
3533
			$('.pppoepreset').hide();
3534
		} else {
3535
			$('.pppoecustom').hide();
3536
			$('.pppoepreset').hide();
3537
		}
3538
	}
3539

    
3540
	function update_track6_prefix() {
3541
		var iface = $("#track6-interface").val();
3542
		if (iface == null) {
3543
			return;
3544
		}
3545

    
3546
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3547
		if (track6_prefix_ids == null) {
3548
			return;
3549
		}
3550

    
3551
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3552
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3553
	}
3554

    
3555
	function addOption_v4() {
3556
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3557
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3558
	}
3559

    
3560
	function addOption_v6() {
3561
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3562
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3563
	}
3564

    
3565
	function addSelectboxOption(selectbox, text, value) {
3566
		var optn = document.createElement("OPTION");
3567
		optn.text = text;
3568
		optn.value = value;
3569
		selectbox.append(optn);
3570
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3571
	}
3572

    
3573
	function country_list() {
3574
		$('#country').children().remove();
3575
		$('#provider_list').children().remove();
3576
		$('#providerplan').children().remove();
3577
		$.ajax("getserviceproviders.php",{
3578
			success: function(response) {
3579

    
3580
				var responseTextArr = response.split("\n");
3581
				responseTextArr.sort();
3582

    
3583
				responseTextArr.forEach( function(value) {
3584
					country = value.split(":");
3585
					$('#country').append($('<option>', {
3586
						value: country[1],
3587
						text : country[0]
3588
					}));
3589
				});
3590
			}
3591
		});
3592
	}
3593

    
3594
	function providers_list() {
3595
		$('#provider_list').children().remove();
3596
		$('#providerplan').children().remove();
3597
		$.ajax("getserviceproviders.php",{
3598
			type: 'post',
3599
			data: {country : $('#country').val()},
3600
			success: function(response) {
3601
				var responseTextArr = response.split("\n");
3602
				responseTextArr.sort();
3603
				responseTextArr.forEach( function(value) {
3604
					$('#provider_list').append($('<option>', {
3605
							value: value,
3606
							text : value
3607
					}));
3608
				});
3609
			}
3610
		});
3611
	}
3612

    
3613
	function providerplan_list() {
3614
		$('#providerplan').children().remove();
3615
		$.ajax("getserviceproviders.php",{
3616
			type: 'post',
3617
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3618
			success: function(response) {
3619
				var responseTextArr = response.split("\n");
3620
				responseTextArr.sort();
3621

    
3622
				$('#providerplan').append($('<option>', {
3623
					value: '',
3624
					text : ''
3625
				}));
3626

    
3627
				responseTextArr.forEach( function(value) {
3628
					if (value != "") {
3629
						providerplan = value.split(":");
3630

    
3631
						$('#providerplan').append($('<option>', {
3632
							value: providerplan[1],
3633
							text : providerplan[0] + " - " + providerplan[1]
3634
						}));
3635
					}
3636
				});
3637
			}
3638
		});
3639
	}
3640

    
3641
	function prefill_provider() {
3642
		$.ajax("getserviceproviders.php",{
3643
			type: 'post',
3644
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3645
			success: function(data, textStatus, response) {
3646
				var xmldoc = response.responseXML;
3647
				var provider = xmldoc.getElementsByTagName('connection')[0];
3648
				$('#ppp_username').val('');
3649
				$('#ppp_password').val('');
3650
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3651
					$('#phone').val('#777');
3652
					$('#apn').val('');
3653
				} else {
3654
					$('#phone').val('*99#');
3655
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3656
				}
3657
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3658
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3659
				$('#ppp_username').val(ppp_username);
3660
				$('#ppp_password').val(ppp_password);
3661
			}
3662
		});
3663
	}
3664

    
3665
	function show_dhcp6adv() {
3666
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3667
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3668

    
3669
		hideCheckbox('dhcp6usev4iface', ovr);
3670
		hideCheckbox('dhcp6prefixonly', ovr);
3671
		hideInput('dhcp6-ia-pd-len', ovr);
3672
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3673
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3674

    
3675
		hideClass('dhcp6advanced', !adv || ovr);
3676
	}
3677

    
3678
	function setDHCPoptions() {
3679
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3680
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3681

    
3682
		if (ovr) {
3683
			hideInput('dhcphostname', true);
3684
			hideIpAddress('alias-address', true);
3685
			hideInput('dhcprejectfrom', true);
3686
			hideInput('adv_dhcp_config_file_override_path', false);
3687
			hideClass('dhcpadvanced', true);
3688
		} else {
3689
			hideInput('dhcphostname', false);
3690
			hideIpAddress('alias-address', false);
3691
			hideInput('dhcprejectfrom', false);
3692
			hideInput('adv_dhcp_config_file_override_path', true);
3693
			hideClass('dhcpadvanced', !adv);
3694
		}
3695
	}
3696

    
3697
	// DHCP preset actions
3698
	// Set presets from value of radio buttons
3699
	function setPresets(val) {
3700
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3701
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3702
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3703
		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']);?>");
3704
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3705
	}
3706

    
3707
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3708
		$('#adv_dhcp_pt_timeout').val(timeout);
3709
		$('#adv_dhcp_pt_retry').val(retry);
3710
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3711
		$('#adv_dhcp_pt_reboot').val(reboot);
3712
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3713
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3714
	}
3715

    
3716
	function setPPPoEDialOnDemandItems() {
3717
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3718
	}
3719

    
3720
	function setPPTPDialOnDemandItems() {
3721
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3722
	}
3723

    
3724
	// ---------- On initial page load ------------------------------------------------------------
3725

    
3726
	updateType($('#type').val());
3727
	updateTypeSix($('#type6').val());
3728
	show_reset_settings($('#pppoe-reset-type').val());
3729
	hideClass('dhcp6advanced', true);
3730
	hideClass('dhcpadvanced', true);
3731
	show_dhcp6adv();
3732
	setDHCPoptions();
3733
	setPPPoEDialOnDemandItems();
3734
	setPPTPDialOnDemandItems();
3735

    
3736
	// Set preset buttons on page load
3737
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3738
	if (sv == "") {
3739
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3740
	} else {
3741
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3742
	}
3743

    
3744
	// Set preset from value
3745
	setPresets(sv);
3746

    
3747
	// If the user wants to add a gateway, then add that to the gateway selection
3748
	if ($("#gatewayip4").val() != '') {
3749
		addOption_v4();
3750
	}
3751
	if ($("#gatewayip6").val() != '') {
3752
		addOption_v6();
3753
	}
3754

    
3755
	// ---------- Click checkbox handlers ---------------------------------------------------------
3756

    
3757
	$('#type').on('change', function() {
3758
		updateType(this.value);
3759
	});
3760

    
3761
	$('#type6').on('change', function() {
3762
		updateTypeSix(this.value);
3763
	});
3764

    
3765
	$('#track6-interface').on('change', function() {
3766
		update_track6_prefix();
3767
	});
3768

    
3769
	$('#pppoe-reset-type').on('change', function() {
3770
		show_reset_settings(this.value);
3771
	});
3772

    
3773
	$("#add4").click(function() {
3774
		addOption_v4();
3775
		$("#newgateway4").modal('hide');
3776
	});
3777

    
3778
	$("#cnx4").click(function() {
3779
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3780
		$("#gatewayip4").val('');
3781
		$("#gatewaydescr4").val('');
3782
		$("#defaultgw4").prop("checked", false);
3783
		$("#newgateway4").modal('hide');
3784
	});
3785

    
3786
	$("#add6").click(function() {
3787
		addOption_v6();
3788
		$("#newgateway6").modal('hide');
3789
	});
3790

    
3791
	$("#cnx6").click(function() {
3792
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3793
		$("#gatewayip6").val('');
3794
		$("#gatewaydescr6").val('');
3795
		$("#defaultgw6").prop("checked", false);
3796
		$("#newgateway6").modal('hide');
3797
	});
3798

    
3799
	$('#country').on('change', function() {
3800
		providers_list();
3801
	});
3802

    
3803
	$('#provider_list').on('change', function() {
3804
		providerplan_list();
3805
	});
3806

    
3807
	$('#providerplan').on('change', function() {
3808
		prefill_provider();
3809
	});
3810

    
3811
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3812
		setDHCPoptions();
3813
	});
3814

    
3815
	$('#adv_dhcp6_config_advanced').click(function () {
3816
		show_dhcp6adv();
3817
	});
3818

    
3819
	$('#adv_dhcp6_config_file_override').click(function () {
3820
		show_dhcp6adv();
3821
	});
3822

    
3823
	// On click . .
3824
	$('#pppoe_dialondemand').click(function () {
3825
		setPPPoEDialOnDemandItems();
3826
	});
3827

    
3828
	$('#pptp_dialondemand').click(function () {
3829
		setPPTPDialOnDemandItems();
3830
	});
3831

    
3832
	$('[name=adv_dhcp_pt_values]').click(function () {
3833
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3834
	});
3835

    
3836
	$('#pppoe_resetdate').datepicker();
3837

    
3838
});
3839
//]]>
3840
</script>
3841

    
3842
<?php include("foot.inc");
(71-71/234)