Project

General

Profile

Download (127 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
$wancfg = &$config['interfaces'][$if];
99
$old_wancfg = $wancfg;
100
$old_wancfg['realif'] = get_real_interface($if);
101
$old_ppps = $a_ppps;
102

    
103
// Populate page descr if it does not exist.
104
if ($if == "wan" && !$wancfg['descr']) {
105
	$wancfg['descr'] = "WAN";
106
} else if ($if == "lan" && !$wancfg['descr']) {
107
	$wancfg['descr'] = "LAN";
108
}
109

    
110
/* NOTE: The code here is used to set the $pppid for the curious */
111
foreach ($a_ppps as $pppid => $ppp) {
112
	if ($wancfg['if'] == $ppp['if']) {
113
		break;
114
	}
115
}
116

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

    
119
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
120
	$pconfig['pppid'] = $pppid;
121
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
122
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
123
	if ($a_ppps[$pppid]['type'] == "ppp") {
124
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
125
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
126

    
127
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
128
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
129
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
130
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
131
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
132
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
133
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
134
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
135

    
136
		/* ================================================ */
137
		/* = force a connection reset at a specific time? = */
138
		/* ================================================ */
139

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

    
194
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
195
$pconfig['alias-address'] = $wancfg['alias-address'];
196
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
197
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
198

    
199
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
200
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
201
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
202
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
203
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
204
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
205

    
206
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
207

    
208
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
209
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
210
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
211
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
212

    
213
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
214
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
215
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
216

    
217
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
218
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
219
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
220
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
221

    
222
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
223
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
224
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
225
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
226
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
227

    
228
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
229
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
230
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
231
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
232
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
233

    
234
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
235
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
236
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
237

    
238
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
239
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
240
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
241
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
242

    
243
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
244
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
245
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
246
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
247
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
248

    
249
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
250
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
251
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
252

    
253
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
254
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
255
$pconfig['enable'] = isset($wancfg['enable']);
256

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

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

    
334
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
335
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
336
$pconfig['spoofmac'] = $wancfg['spoofmac'];
337
$pconfig['mtu'] = $wancfg['mtu'];
338
$pconfig['mss'] = $wancfg['mss'];
339

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

    
416
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
417

    
418
}
419

    
420
$changes_applied = false;
421

    
422
if ($_POST['apply']) {
423
	unset($input_errors);
424
	if (!is_subsystem_dirty('interfaces')) {
425
		$input_errors[] = gettext("The settings have already been applied!");
426
	} else {
427
		$retval = 0;
428
		unlink_if_exists("{$g['tmp_path']}/config.cache");
429
		clear_subsystem_dirty('interfaces');
430

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

    
458
		/* sync filter configuration */
459
		setup_gateways_monitor();
460

    
461
		clear_subsystem_dirty('interfaces');
462

    
463
		$retval |= filter_configure();
464

    
465
		enable_rrd_graphing();
466

    
467
		$changes_applied = true;
468

    
469
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
470
			clear_subsystem_dirty('staticroutes');
471
		}
472
	}
473
	@unlink("{$g['tmp_path']}/.interfaces.apply");
474
} else if ($_POST['save']) {
475

    
476
	unset($input_errors);
477
	$pconfig = $_POST;
478

    
479
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
480
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
481
	} else {
482
		$pconfig['track6-prefix-id'] = 0;
483
	}
484

    
485
	/* filter out spaces from descriptions */
486
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
487

    
488
	/* okay first of all, cause we are just hiding the PPPoE HTML
489
	 * fields related to PPPoE resets, we are going to unset $_POST
490
	 * vars, if the reset feature should not be used. Otherwise the
491
	 * data validation procedure below, may trigger a false error
492
	 * message.
493
	 */
494
	if (empty($_POST['pppoe-reset-type'])) {
495
		unset($_POST['pppoe_pr_type']);
496
		unset($_POST['pppoe_resethour']);
497
		unset($_POST['pppoe_resetminute']);
498
		unset($_POST['pppoe_resetdate']);
499
		unset($_POST['pppoe_pr_preset_val']);
500
	}
501

    
502
	/* input validation */
503
	$reqdfields = explode(" ", "descr");
504
	$reqdfieldsn = array(gettext("Description"));
505
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
506

    
507
	if (!$input_errors) {
508
		/* description unique? */
509
		foreach ($ifdescrs as $ifent => $ifdescr) {
510
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
511
				$input_errors[] = gettext("An interface with the specified description already exists.");
512
				break;
513
			}
514
		}
515

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

    
525
		/* Is the description already used as an interface group name? */
526
		if (is_array($config['ifgroups']['ifgroupentry'])) {
527
			foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
528
				if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
529
					$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
530
				}
531
			}
532
		}
533

    
534
		if (is_numeric($_POST['descr'])) {
535
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
536
		}
537

    
538
		/*
539
		 * Packages (e.g. tinc) create interface groups, reserve this
540
		 * namespace pkg_ for them.
541
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
542
		 */
543
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
544
			$input_errors[] = gettext("The interface description cannot start with pkg_");
545
		}
546
	}
547

    
548
	if ($_POST['blockbogons'] == "yes" &&
549
	    isset($config['system']['ipv6allow']) &&
550
	    (!isset($config['system']['maximumtableentries']) ||
551
	     $config['system']['maximumtableentries'] <
552
	     $g['minimumtableentries_bogonsv6'])) {
553
		$input_errors[] = sprintf(gettext(
554
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
555
		    $g['minimumtableentries_bogonsv6']);
556
	}
557

    
558
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable'])) {
559
		if (!preg_match("/^staticv4/", $_POST['type'])) {
560
			$input_errors[] = gettext("The DHCP Server is active " .
561
			    "on this interface and it can be used only with " .
562
			    "a static IP configuration. Please disable the " .
563
			    "DHCP Server service on this interface first, " .
564
			    "then change the interface configuration.");
565
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
566
			$input_errors[] = gettext("The DHCP Server is active " .
567
			    "on this interface and it can be used only with " .
568
			    "IPv4 subnet < 31. Please disable the " .
569
			    "DHCP Server service on this interface first, " .
570
			    "then change the interface configuration.");
571
		}
572
	}
573
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
574
		$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.");
575
	}
576

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

    
684
			if (empty($_POST['track6-interface'])) {
685
				$input_errors[] = gettext("A valid interface to track must be selected.");
686
			}
687

    
688
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
689
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
690
			} else {
691
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
692
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
693
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
694
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
695
				} else {
696
					foreach ($ifdescrs as $ifent => $ifdescr) {
697
						if ($if == $ifent) {
698
							continue;
699
						}
700
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
701
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
702
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
703
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
704
						}
705
					}
706
				}
707
			}
708
			break;
709
	}
710

    
711
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
712
	$staticroutes = get_staticroutes(true);
713
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
714
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
715
		if (!is_ipaddrv4($_POST['ipaddr'])) {
716
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
717
		} else {
718
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
719
			if (count($where_ipaddr_configured)) {
720
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
721
				foreach ($where_ipaddr_configured as $subnet_conflict) {
722
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
723
				}
724
				$input_errors[] = $subnet_conflict_text;
725
			}
726

    
727
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
728
			if ($_POST['subnet'] < 31) {
729
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
730
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
731
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
732
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
733
				}
734
			}
735

    
736
			foreach ($staticroutes as $route_subnet) {
737
				list($network, $subnet) = explode("/", $route_subnet);
738
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
739
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
740
					break;
741
				}
742
				unset($network, $subnet);
743
			}
744
		}
745
	}
746
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
747
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
748

    
749
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
750
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
751
		} else {
752
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
753
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
754
			}
755
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
756
			if (count($where_ipaddr_configured)) {
757
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
758
				foreach ($where_ipaddr_configured as $subnet_conflict) {
759
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
760
				}
761
				$input_errors[] = $subnet_conflict_text;
762
			}
763

    
764
			foreach ($staticroutes as $route_subnet) {
765
				list($network, $subnet) = explode("/", $route_subnet);
766
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
767
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
768
					break;
769
				}
770
				unset($network, $subnet);
771
			}
772
		}
773
	}
774
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
775
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
776
	}
777
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
778
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
779
	}
780
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
781
		$input_errors[] = gettext("A valid alias IP address must be specified.");
782
	}
783
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
784
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
785
	}
786
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
787
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
788
	}
789

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

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

    
862
		unset($min_mtu, $max_mtu);
863

    
864
		if (interface_is_vlan($wancfg['if']) != NULL) {
865
			$realhwif_array = get_parent_interface($wancfg['if']);
866
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
867
			$parent_realhwif = $realhwif_array[0];
868
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
869
			$mtu = 0;
870
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
871
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
872
			if ($mtu == 0)
873
				$mtu = get_interface_mtu($parent_realhwif);
874
			if ($_POST['mtu'] > $mtu)
875
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
876
		} else {
877
			foreach ($config['interfaces'] as $idx => $ifdata) {
878
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
879
					continue;
880
				}
881

    
882
				$realhwif_array = get_parent_interface($ifdata['if']);
883
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
884
				$parent_realhwif = $realhwif_array[0];
885

    
886
				if ($parent_realhwif != $wancfg['if']) {
887
					continue;
888
				}
889

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

    
977
		if ($_POST['passphrase']) {
978
			$passlen = strlen($_POST['passphrase']);
979
			if ($passlen < 8 || $passlen > 63) {
980
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
981
			}
982
		}
983

    
984
		if ($_POST['wpa_enable'] == "yes") {
985
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
986
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
987
			}
988
		}
989
	}
990

    
991
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
992
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
993
	}
994

    
995
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
996
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
997
	}
998

    
999
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1000
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1001
	}
1002

    
1003
	if ($_POST['gatewayip4']) {
1004
		// The user wants to add an IPv4 gateway - validate the settings
1005
		$gateway_settings4 = array();
1006

    
1007
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1008
		$gateway_settings4['interface'] = $_POST['if'];
1009
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1010
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1011
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1012
		$gateway_settings4['ipprotocol'] = 'inet';
1013
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1014
		foreach ($gw_input_errors as $input_error_text) {
1015
			$input_errors[] = $input_error_text;
1016
		}
1017
	}
1018

    
1019
	if ($_POST['gatewayip6']) {
1020
		// The user wants to add an IPv6 gateway - validate the settings
1021
		$gateway_settings6 = array();
1022

    
1023
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1024
		$gateway_settings6['interface'] = $_POST['if'];
1025
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1026
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1027
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1028
		$gateway_settings6['ipprotocol'] = 'inet6';
1029
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1030
		foreach ($gw_input_errors as $input_error_text) {
1031
			$input_errors[] = $input_error_text;
1032
		}
1033
	}
1034

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

    
1042
		if ($wancfg['ipaddr'] != $_POST['type']) {
1043
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1044
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1045
				unset($a_ppps[$pppid]);
1046
			} else if ($wancfg['ipaddr'] == "dhcp") {
1047
				kill_dhclient_process($wancfg['if']);
1048
			}
1049
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1050
				kill_dhcp6client_process($wancfg['if'],true);
1051
			}
1052
		}
1053
		$ppp = array();
1054
		if ($wancfg['ipaddr'] != "ppp") {
1055
			unset($wancfg['ipaddr']);
1056
		}
1057
		if ($wancfg['ipaddrv6'] != "ppp") {
1058
			unset($wancfg['ipaddrv6']);
1059
		}
1060
		unset($wancfg['subnet']);
1061
		unset($wancfg['gateway']);
1062
		unset($wancfg['subnetv6']);
1063
		unset($wancfg['gatewayv6']);
1064
		unset($wancfg['dhcphostname']);
1065
		unset($wancfg['dhcprejectfrom']);
1066
		unset($wancfg['dhcp6-duid']);
1067
		unset($wancfg['dhcp6-ia-pd-len']);
1068
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1069
		unset($wancfg['dhcp6prefixonly']);
1070
		unset($wancfg['dhcp6usev4iface']);
1071
		unset($wancfg['ipv6usev4iface']);
1072
		unset($wancfg['dhcp6debug']);
1073
		unset($wancfg['track6-interface']);
1074
		unset($wancfg['track6-prefix-id']);
1075
		unset($wancfg['dhcp6withoutra']);
1076
		unset($wancfg['dhcp6norelease']);
1077
		unset($wancfg['dhcp6vlanenable']);
1078
		unset($wancfg['dhcp6cvpt']);
1079
		unset($wancfg['prefix-6rd']);
1080
		unset($wancfg['prefix-6rd-v4plen']);
1081
		unset($wancfg['gateway-6rd']);
1082

    
1083
		unset($wancfg['adv_dhcp_pt_timeout']);
1084
		unset($wancfg['adv_dhcp_pt_retry']);
1085
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1086
		unset($wancfg['adv_dhcp_pt_reboot']);
1087
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1088
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1089

    
1090
		unset($wancfg['adv_dhcp_pt_values']);
1091

    
1092
		unset($wancfg['adv_dhcp_send_options']);
1093
		unset($wancfg['adv_dhcp_request_options']);
1094
		unset($wancfg['adv_dhcp_required_options']);
1095
		unset($wancfg['adv_dhcp_option_modifiers']);
1096

    
1097
		unset($wancfg['adv_dhcp_config_advanced']);
1098
		unset($wancfg['adv_dhcp_config_file_override']);
1099
		unset($wancfg['adv_dhcp_config_file_override_path']);
1100

    
1101
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1102
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1103
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1104
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1105

    
1106
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1107
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1108
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1109
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1110
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1111

    
1112
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1113
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1114
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1115
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1116
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1117

    
1118
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1119
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1120
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1121

    
1122
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1123
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1124
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1125
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1126

    
1127
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1128
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1129
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1130
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1131
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1132

    
1133
		unset($wancfg['adv_dhcp6_config_advanced']);
1134
		unset($wancfg['adv_dhcp6_config_file_override']);
1135
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1136

    
1137
		unset($wancfg['pppoe_password']);
1138
		unset($wancfg['pptp_username']);
1139
		unset($wancfg['pptp_password']);
1140
		unset($wancfg['provider']);
1141
		unset($wancfg['ondemand']);
1142
		unset($wancfg['timeout']);
1143
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1144
			unset($wancfg['pppoe']['pppoe-reset-type']);
1145
		}
1146
		unset($wancfg['local']);
1147

    
1148
		unset($wancfg['remote']);
1149
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1150
			if ($wancfg['ipaddr'] != 'ppp') {
1151
				unset($a_ppps[$pppid]['apn']);
1152
				unset($a_ppps[$pppid]['phone']);
1153
				unset($a_ppps[$pppid]['provider']);
1154
				unset($a_ppps[$pppid]['ondemand']);
1155
			}
1156
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1157
				unset($a_ppps[$pppid]['localip']);
1158
				unset($a_ppps[$pppid]['subnet']);
1159
				unset($a_ppps[$pppid]['gateway']);
1160
			}
1161
			if ($wancfg['ipaddr'] != 'pppoe') {
1162
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1163
			}
1164
			if ($wancfg['type'] != $_POST['type']) {
1165
				unset($a_ppps[$pppid]['idletimeout']);
1166
			}
1167
		}
1168

    
1169
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1170
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1171

    
1172
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1173
		switch ($_POST['type']) {
1174
			case "staticv4":
1175
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1176
				$wancfg['subnet'] = $_POST['subnet'];
1177
				if ($_POST['gateway'] != "none") {
1178
					$wancfg['gateway'] = $_POST['gateway'];
1179
				}
1180
				break;
1181
			case "dhcp":
1182
				$wancfg['ipaddr'] = "dhcp";
1183
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1184
				$wancfg['alias-address'] = $_POST['alias-address'];
1185
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1186
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1187

    
1188
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1189
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1190
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1191
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1192
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1193
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1194

    
1195
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1196

    
1197
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1198
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1199
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1200
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1201

    
1202
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1203
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1204
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1205

    
1206
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1207
				if ($gateway_item) {
1208
					$a_gateways[] = $gateway_item;
1209
				}
1210
				break;
1211
			case "ppp":
1212
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1213
				$a_ppps[$pppid]['type'] = $_POST['type'];
1214
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1215
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1216
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1217
				if ($_POST['ppp_password'] != DMYPWD) {
1218
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1219
				}
1220
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1221
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1222
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1223
				$wancfg['ipaddr'] = $_POST['type'];
1224
				break;
1225

    
1226
			case "pppoe":
1227
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1228
				$a_ppps[$pppid]['type'] = $_POST['type'];
1229
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1230
				if (isset($_POST['ppp_port'])) {
1231
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1232
				} else {
1233
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1234
				}
1235
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1236
				if ($_POST['pppoe_password'] != DMYPWD) {
1237
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1238
				}
1239
				if (!empty($_POST['provider'])) {
1240
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1241
				} else {
1242
					$a_ppps[$pppid]['provider'] = true;
1243
				}
1244
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1245
				if (!empty($_POST['pppoe_idletimeout'])) {
1246
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1247
				} else {
1248
					unset($a_ppps[$pppid]['idletimeout']);
1249
				}
1250

    
1251
				if (!empty($_POST['pppoe-reset-type'])) {
1252
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1253
				} else {
1254
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1255
				}
1256
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1257
				$wancfg['ipaddr'] = $_POST['type'];
1258
				if ($gateway_item) {
1259
					$a_gateways[] = $gateway_item;
1260
				}
1261

    
1262
				break;
1263
			case "pptp":
1264
			case "l2tp":
1265
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1266
				$a_ppps[$pppid]['type'] = $_POST['type'];
1267
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1268
				if (isset($_POST['ppp_port'])) {
1269
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1270
				} else {
1271
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1272
				}
1273
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1274
				if ($_POST['pptp_password'] != DMYPWD) {
1275
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1276
				}
1277
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1278
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1279
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1280
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1281
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1282
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1283
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1284
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1285
				if (!empty($_POST['pptp_idletimeout'])) {
1286
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1287
				} else {
1288
					unset($a_ppps[$pppid]['idletimeout']);
1289
				}
1290
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1291
				$wancfg['ipaddr'] = $_POST['type'];
1292
				if ($gateway_item) {
1293
					$a_gateways[] = $gateway_item;
1294
				}
1295
				break;
1296
			case "none":
1297
				break;
1298
		}
1299
		switch ($_POST['type6']) {
1300
			case "staticv6":
1301
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1302
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1303
				if ($_POST['ipv6usev4iface'] == "yes") {
1304
					$wancfg['ipv6usev4iface'] = true;
1305
				}
1306
				if ($_POST['gatewayv6'] != "none") {
1307
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1308
				}
1309
				break;
1310
			case "slaac":
1311
				$wancfg['ipaddrv6'] = "slaac";
1312
				break;
1313
			case "dhcp6":
1314
				$wancfg['ipaddrv6'] = "dhcp6";
1315
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1316
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1317
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1318
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1319
				}
1320
				if ($_POST['dhcp6prefixonly'] == "yes") {
1321
					$wancfg['dhcp6prefixonly'] = true;
1322
				}
1323
				if ($_POST['dhcp6usev4iface'] == "yes") {
1324
					$wancfg['dhcp6usev4iface'] = true;
1325
				}
1326
				if ($_POST['dhcp6debug'] == "yes") {
1327
					$wancfg['dhcp6debug'] = true;
1328
				}
1329

    
1330
				if ($_POST['dhcp6withoutra'] == "yes") {
1331
					$wancfg['dhcp6withoutra'] = true;
1332
				}
1333
				if ($_POST['dhcp6norelease'] == "yes") {
1334
					$wancfg['dhcp6norelease'] = true;
1335
				}
1336
				if ($_POST['dhcp6vlanenable'] == "yes") {
1337
					$wancfg['dhcp6vlanenable'] = true;
1338
				}
1339
				if (!empty($_POST['dhcp6cvpt'])) {
1340
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1341
				} else {
1342
					unset($wancfg['dhcp6cvpt']);
1343
				}
1344

    
1345
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1346
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1347
				}
1348
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1349
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1350
				}
1351
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1352
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1353
				}
1354
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1355
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1356
				}
1357

    
1358
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1359
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1360
				}
1361
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1362
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1363
				}
1364
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1365
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1366
				}
1367
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1368
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1369
				}
1370
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1371
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1372
				}
1373

    
1374
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1375
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1376
				}
1377
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1378
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1379
				}
1380
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1381
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1382
				}
1383
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1384
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1385
				}
1386
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1387
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1388
				}
1389

    
1390
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1391
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1392
				}
1393
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1394
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1395
				}
1396
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1397
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1398
				}
1399
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1400
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1401
				}
1402
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1403
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1404
				}
1405
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1406
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1407
				}
1408
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1409
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1410
				}
1411

    
1412
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1413
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1414
				}
1415
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1416
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1417
				}
1418
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1419
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1420
				}
1421
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1422
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1423
				}
1424
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1425
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1426
				}
1427

    
1428
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1429
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1430
				}
1431
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1432
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1433
				}
1434
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1435
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1436
				}
1437

    
1438
				if ($gateway_item) {
1439
					$a_gateways[] = $gateway_item;
1440
				}
1441
				break;
1442
			case "6rd":
1443
				$wancfg['ipaddrv6'] = "6rd";
1444
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1445
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1446
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1447
				if ($gateway_item) {
1448
					$a_gateways[] = $gateway_item;
1449
				}
1450
				break;
1451
			case "6to4":
1452
				$wancfg['ipaddrv6'] = "6to4";
1453
				break;
1454
			case "track6":
1455
				$wancfg['ipaddrv6'] = "track6";
1456
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1457
				if ($_POST['track6-prefix-id--hex'] === "") {
1458
					$wancfg['track6-prefix-id'] = 0;
1459
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1460
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1461
				} else {
1462
					$wancfg['track6-prefix-id'] = 0;
1463
				}
1464
				break;
1465
			case "none":
1466
				break;
1467
		}
1468
		handle_pppoe_reset($_POST);
1469

    
1470
		if ($_POST['blockpriv'] == "yes") {
1471
			$wancfg['blockpriv'] = true;
1472
		} else {
1473
			unset($wancfg['blockpriv']);
1474
		}
1475
		if ($_POST['blockbogons'] == "yes") {
1476
			$wancfg['blockbogons'] = true;
1477
		} else {
1478
			unset($wancfg['blockbogons']);
1479
		}
1480
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1481
		if (empty($_POST['mtu'])) {
1482
			unset($wancfg['mtu']);
1483
		} else {
1484
			$wancfg['mtu'] = $_POST['mtu'];
1485
		}
1486
		if (empty($_POST['mss'])) {
1487
			unset($wancfg['mss']);
1488
		} else {
1489
			$wancfg['mss'] = $_POST['mss'];
1490
		}
1491
		if (empty($_POST['mediaopt'])) {
1492
			unset($wancfg['media']);
1493
			unset($wancfg['mediaopt']);
1494
		} else {
1495
			$mediaopts = explode(' ', $_POST['mediaopt']);
1496
			if ($mediaopts[0] != '') {
1497
				$wancfg['media'] = $mediaopts[0];
1498
			}
1499
			if ($mediaopts[1] != '') {
1500
				$wancfg['mediaopt'] = $mediaopts[1];
1501
			} else {
1502
				unset($wancfg['mediaopt']);
1503
			}
1504
		}
1505
		if (isset($wancfg['wireless'])) {
1506
			handle_wireless_post();
1507
		}
1508

    
1509
		write_config();
1510

    
1511
		if ($_POST['gatewayip4']) {
1512
			save_gateway($gateway_settings4);
1513
		}
1514

    
1515
		if ($_POST['gatewayip6']) {
1516
			save_gateway($gateway_settings6);
1517
		}
1518

    
1519
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1520
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1521
		} else {
1522
			$toapplylist = array();
1523
		}
1524
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1525
		$toapplylist[$if]['ppps'] = $old_ppps;
1526
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1527

    
1528
		mark_subsystem_dirty('interfaces');
1529

    
1530
		/* regenerate cron settings/crontab file */
1531
		configure_cron();
1532

    
1533
		header("Location: interfaces.php?if={$if}");
1534
		exit;
1535
	}
1536

    
1537
} // end if ($_POST['save'])
1538

    
1539
function handle_wireless_post() {
1540
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1541
	if (!is_array($wancfg['wireless'])) {
1542
		$wancfg['wireless'] = array();
1543
	}
1544
	$wancfg['wireless']['standard'] = $_POST['standard'];
1545
	$wancfg['wireless']['mode'] = $_POST['mode'];
1546
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1547
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1548
	$wancfg['wireless']['channel'] = $_POST['channel'];
1549
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1550
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1551
	$wancfg['wireless']['distance'] = $_POST['distance'];
1552
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1553
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1554
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1555
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1556
		foreach ($wl_countries_attr as $wl_country) {
1557
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1558
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1559
				break;
1560
			}
1561
		}
1562
	}
1563
	if (!is_array($wancfg['wireless']['wpa'])) {
1564
		$wancfg['wireless']['wpa'] = array();
1565
	}
1566
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1567
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1568
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1569
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1570
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1571
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1572
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1573
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1574
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1575
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1576
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1577
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1578
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1579
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1580

    
1581
	if ($_POST['persistcommonwireless'] == "yes") {
1582
		if (!is_array($config['wireless'])) {
1583
			$config['wireless'] = array();
1584
		}
1585
		if (!is_array($config['wireless']['interfaces'])) {
1586
			$config['wireless']['interfaces'] = array();
1587
		}
1588
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1589
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1590
		}
1591
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1592
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1593
	}
1594
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1595
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1596
	} else if (isset($wancfg['wireless']['diversity'])) {
1597
		unset($wancfg['wireless']['diversity']);
1598
	}
1599
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1600
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1601
	} else if (isset($wancfg['wireless']['txantenna'])) {
1602
		unset($wancfg['wireless']['txantenna']);
1603
	}
1604
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1605
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1606
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1607
		unset($wancfg['wireless']['rxantenna']);
1608
	}
1609
	if ($_POST['hidessid_enable'] == "yes") {
1610
		$wancfg['wireless']['hidessid']['enable'] = true;
1611
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1612
		unset($wancfg['wireless']['hidessid']['enable']);
1613
	}
1614
	if ($_POST['mac_acl_enable'] == "yes") {
1615
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1616
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1617
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1618
	}
1619
	if ($_POST['rsn_preauth'] == "yes") {
1620
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1621
	} else {
1622
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1623
	}
1624
	if ($_POST['ieee8021x'] == "yes") {
1625
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1626
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1627
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1628
	}
1629
	if ($_POST['wpa_strict_rekey'] == "yes") {
1630
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1631
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1632
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1633
	}
1634
	if ($_POST['debug_mode'] == "yes") {
1635
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1636
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1637
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1638
	}
1639
	if ($_POST['wpa_enable'] == "yes") {
1640
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1641
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1642
		unset($wancfg['wireless']['wpa']['enable']);
1643
	}
1644

    
1645
	if ($_POST['wme_enable'] == "yes") {
1646
		if (!is_array($wancfg['wireless']['wme'])) {
1647
			$wancfg['wireless']['wme'] = array();
1648
		}
1649
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1650
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1651
		unset($wancfg['wireless']['wme']['enable']);
1652
	}
1653
	if ($_POST['puremode'] == "11g") {
1654
		if (!is_array($wancfg['wireless']['pureg'])) {
1655
			$wancfg['wireless']['pureg'] = array();
1656
		}
1657
		$wancfg['wireless']['pureg']['enable'] = true;
1658
	} else if ($_POST['puremode'] == "11n") {
1659
		if (!is_array($wancfg['wireless']['puren'])) {
1660
			$wancfg['wireless']['puren'] = array();
1661
		}
1662
		$wancfg['wireless']['puren']['enable'] = true;
1663
	} else {
1664
		if (isset($wancfg['wireless']['pureg'])) {
1665
			unset($wancfg['wireless']['pureg']);
1666
		}
1667
		if (isset($wancfg['wireless']['puren'])) {
1668
			unset($wancfg['wireless']['puren']);
1669
		}
1670
	}
1671
	if ($_POST['apbridge_enable'] == "yes") {
1672
		if (!is_array($wancfg['wireless']['apbridge'])) {
1673
			$wancfg['wireless']['apbridge'] = array();
1674
		}
1675
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1676
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1677
		unset($wancfg['wireless']['apbridge']['enable']);
1678
	}
1679
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1680
		if (!is_array($wancfg['wireless']['turbo'])) {
1681
			$wancfg['wireless']['turbo'] = array();
1682
		}
1683
		$wancfg['wireless']['turbo']['enable'] = true;
1684
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1685
		unset($wancfg['wireless']['turbo']['enable']);
1686
	}
1687

    
1688
	interface_sync_wireless_clones($wancfg, true);
1689
}
1690

    
1691
function check_wireless_mode() {
1692
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1693

    
1694
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1695
		return;
1696
	}
1697

    
1698
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1699
		$clone_count = 1;
1700
	} else {
1701
		$clone_count = 0;
1702
	}
1703

    
1704
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1705
		foreach ($config['wireless']['clone'] as $clone) {
1706
			if ($clone['if'] == $wlanbaseif) {
1707
				$clone_count++;
1708
			}
1709
		}
1710
	}
1711

    
1712
	if ($clone_count > 1) {
1713
		$old_wireless_mode = $wancfg['wireless']['mode'];
1714
		$wancfg['wireless']['mode'] = $_POST['mode'];
1715
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1716
			$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']]);
1717
		} else {
1718
			pfSense_interface_destroy("{$wlanif}_");
1719
		}
1720
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1721
	}
1722
}
1723

    
1724
// Find all possible media options for the interface
1725
$mediaopts_list = array();
1726
$intrealname = $config['interfaces'][$if]['if'];
1727
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1728
foreach ($mediaopts as $mediaopt) {
1729
	preg_match("/media (.*)/", $mediaopt, $matches);
1730
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1731
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1732
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1733
	} else {
1734
		// there is only media like "media 1000baseT"
1735
		array_push($mediaopts_list, $matches[1]);
1736
	}
1737
}
1738

    
1739
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1740
$shortcut_section = "interfaces";
1741

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

    
1745
// Get the MAC address
1746
$ip = $_SERVER['REMOTE_ADDR'];
1747
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1748
$mymac = str_replace("\n", "", $mymac);
1749
$defgatewayname4 = $wancfg['descr'] . "GW";
1750
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1751

    
1752
function build_mediaopts_list() {
1753
	global $mediaopts_list;
1754

    
1755
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1756
			 " " =>	 gettext("------- Media Supported by this interface -------")
1757
			];
1758

    
1759
	foreach ($mediaopts_list as $mediaopt) {
1760
		$list[$mediaopt] = $mediaopt;
1761
	}
1762

    
1763
	return($list);
1764
}
1765

    
1766
function build_gateway_list() {
1767
	global $a_gateways, $if;
1768

    
1769
	$list = array("none" => gettext("None"));
1770
	foreach ($a_gateways as $gateway) {
1771
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1772
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1773
		}
1774
	}
1775

    
1776
	return($list);
1777
}
1778

    
1779
function build_gatewayv6_list() {
1780
	global $a_gateways, $if;
1781

    
1782
	$list = array("none" => gettext("None"));
1783
	foreach ($a_gateways as $gateway) {
1784
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1785
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1786
		}
1787
	}
1788

    
1789
	return($list);
1790
}
1791

    
1792
include("head.inc");
1793

    
1794
if ($input_errors) {
1795
	print_input_errors($input_errors);
1796
}
1797

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

    
1804
if ($changes_applied) {
1805
	print_apply_result_box($retval);
1806
}
1807

    
1808
$form = new Form();
1809

    
1810
$section = new Form_Section('General Configuration');
1811

    
1812
$section->addInput(new Form_Checkbox(
1813
	'enable',
1814
	'Enable',
1815
	'Enable interface',
1816
	$pconfig['enable'],
1817
	'yes'
1818
));
1819

    
1820
$section->addInput(new Form_Input(
1821
	'descr',
1822
	'*Description',
1823
	'text',
1824
	$pconfig['descr']
1825
))->setHelp('Enter a description (name) for the interface here.');
1826

    
1827
$section->addInput(new Form_Select(
1828
	'type',
1829
	'IPv4 Configuration Type',
1830
	$pconfig['type'],
1831
	$types4
1832
));
1833

    
1834
$section->addInput(new Form_Select(
1835
	'type6',
1836
	'IPv6 Configuration Type',
1837
	$pconfig['type6'],
1838
	$types6
1839
));
1840

    
1841
$macaddress = new Form_Input(
1842
	'spoofmac',
1843
	'MAC Address',
1844
	'text',
1845
	$pconfig['spoofmac'],
1846
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1847
);
1848

    
1849
$btnmymac = new Form_Button(
1850
	'btnmymac',
1851
	'Copy My MAC',
1852
	null,
1853
	'fa-clone'
1854
	);
1855

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

    
1858
$group = new Form_Group('MAC Address');
1859
$group->add($macaddress);
1860
// $group->add($btnmymac);
1861
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1862
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1863
$section->add($group);
1864

    
1865
$section->addInput(new Form_Input(
1866
	'mtu',
1867
	'MTU',
1868
	'number',
1869
	$pconfig['mtu']
1870
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1871
			'This is typically 1500 bytes but can vary in some circumstances.');
1872

    
1873
$section->addInput(new Form_Input(
1874
	'mss',
1875
	'MSS',
1876
	'number',
1877
	$pconfig['mss']
1878
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1879
			'header size) will be in effect.');
1880

    
1881
if (count($mediaopts_list) > 0) {
1882
	$section->addInput(new Form_Select(
1883
		'mediaopt',
1884
		'Speed and Duplex',
1885
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1886
		build_mediaopts_list()
1887
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1888
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1889
}
1890

    
1891
$form->add($section);
1892

    
1893
$section = new Form_Section('Static IPv4 Configuration');
1894
$section->addClass('staticv4');
1895

    
1896
$section->addInput(new Form_IpAddress(
1897
	'ipaddr',
1898
	'*IPv4 Address',
1899
	$pconfig['ipaddr'],
1900
	'V4'
1901
))->addMask('subnet', $pconfig['subnet'], 32);
1902

    
1903
$group = new Form_Group('IPv4 Upstream gateway');
1904

    
1905
$group->add(new Form_Select(
1906
	'gateway',
1907
	'IPv4 Upstream Gateway',
1908
	$pconfig['gateway'],
1909
	build_gateway_list()
1910
));
1911

    
1912
$group->add(new Form_Button(
1913
	'addgw4',
1914
	'Add a new gateway',
1915
	null,
1916
	'fa-plus'
1917
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1918

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

    
1923
$section->add($group);
1924

    
1925
$form->add($section);
1926

    
1927
$section = new Form_Section('Static IPv6 Configuration');
1928
$section->addClass('staticv6');
1929

    
1930
$section->addInput(new Form_IpAddress(
1931
	'ipaddrv6',
1932
	'*IPv6 address',
1933
	$pconfig['ipaddrv6'],
1934
	'V6'
1935
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1936

    
1937
$section->addInput(new Form_Checkbox(
1938
	'ipv6usev4iface',
1939
	'Use IPv4 connectivity as parent interface',
1940
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1941
	$pconfig['ipv6usev4iface']
1942
));
1943

    
1944
$group = new Form_Group('IPv6 Upstream gateway');
1945

    
1946
$group->add(new Form_Select(
1947
	'gatewayv6',
1948
	'IPv6 Upstream Gateway',
1949
	$pconfig['gatewayv6'],
1950
	build_gatewayv6_list()
1951
));
1952

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

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

    
1963
$section->add($group);
1964
$form->add($section);
1965

    
1966
// Add new gateway modal pop-up for IPv6
1967
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1968

    
1969
$modal->addInput(new Form_Checkbox(
1970
	'defaultgw6',
1971
	'Default',
1972
	'Default gateway',
1973
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
1974
));
1975

    
1976
$modal->addInput(new Form_Input(
1977
	'gatewayname6',
1978
	'Gateway name',
1979
	'text',
1980
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
1981
));
1982

    
1983
$modal->addInput(new Form_IpAddress(
1984
	'gatewayip6',
1985
	'Gateway IPv6',
1986
	$gateway_settings6['gateway'],
1987
	'V6'
1988
));
1989

    
1990
$modal->addInput(new Form_Input(
1991
	'gatewaydescr6',
1992
	'Description',
1993
	'text',
1994
	$gateway_settings6['descr']
1995
));
1996

    
1997
$btnaddgw6 = new Form_Button(
1998
	'add6',
1999
	'Add',
2000
	null,
2001
	'fa-plus'
2002
);
2003

    
2004
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2005

    
2006
$btncnxgw6 = new Form_Button(
2007
	'cnx6',
2008
	'Cancel',
2009
	null,
2010
	'fa-undo'
2011
);
2012

    
2013
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2014

    
2015
$modal->addInput(new Form_StaticText(
2016
	null,
2017
	$btnaddgw6 . $btncnxgw6
2018
));
2019

    
2020
$form->add($modal);
2021

    
2022
// ==== DHCP client configuration =============================
2023

    
2024
$section = new Form_Section('DHCP Client Configuration');
2025
$section->addClass('dhcp');
2026

    
2027
$group = new Form_Group('Options');
2028

    
2029
$group->add(new Form_Checkbox(
2030
	'adv_dhcp_config_advanced',
2031
	null,
2032
	'Advanced Configuration',
2033
	$pconfig['adv_dhcp_config_advanced']
2034
))->setHelp('Use advanced DHCP configuration options.');
2035

    
2036
$group->add(new Form_Checkbox(
2037
	'adv_dhcp_config_file_override',
2038
	null,
2039
	'Configuration Override',
2040
	$pconfig['adv_dhcp_config_file_override']
2041
))->setHelp('Override the configuration from this file.');
2042

    
2043
$section->add($group);
2044

    
2045
$section->addInput(new Form_Input(
2046
	'dhcphostname',
2047
	'Hostname',
2048
	'text',
2049
	$pconfig['dhcphostname']
2050
))->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).');
2051

    
2052
$section->addInput(new Form_IpAddress(
2053
	'alias-address',
2054
	'Alias IPv4 address',
2055
	$pconfig['alias-address'],
2056
	'V4'
2057
))->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.');
2058

    
2059
$section->addInput(new Form_Input(
2060
	'dhcprejectfrom',
2061
	'Reject leases from',
2062
	'text',
2063
	$pconfig['dhcprejectfrom']
2064
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2065
			'(separate multiple entries with a comma). ' .
2066
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2067

    
2068
$group = new Form_Group('Protocol timing');
2069
$group->addClass('dhcpadvanced');
2070

    
2071
$group->add(new Form_Input(
2072
	'adv_dhcp_pt_timeout',
2073
	null,
2074
	'number',
2075
	$pconfig['adv_dhcp_pt_timeout']
2076
))->setHelp('Timeout');
2077

    
2078
$group->add(new Form_Input(
2079
	'adv_dhcp_pt_retry',
2080
	null,
2081
	'number',
2082
	$pconfig['adv_dhcp_pt_retry']
2083
))->setHelp('Retry');
2084

    
2085
$group->add(new Form_Input(
2086
	'adv_dhcp_pt_select_timeout',
2087
	null,
2088
	'number',
2089
	$pconfig['adv_dhcp_pt_select_timeout'],
2090
	['min' => 0]
2091
))->setHelp('Select timeout');
2092

    
2093
$group->add(new Form_Input(
2094
	'adv_dhcp_pt_reboot',
2095
	null,
2096
	'number',
2097
	$pconfig['adv_dhcp_pt_reboot']
2098
))->setHelp('Reboot');
2099

    
2100
$group->add(new Form_Input(
2101
	'adv_dhcp_pt_backoff_cutoff',
2102
	null,
2103
	'number',
2104
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2105
))->setHelp('Backoff cutoff');
2106

    
2107
$group->add(new Form_Input(
2108
	'adv_dhcp_pt_initial_interval',
2109
	null,
2110
	'number',
2111
	$pconfig['adv_dhcp_pt_initial_interval']
2112
))->setHelp('Initial interval');
2113

    
2114
$section->add($group);
2115

    
2116
$group = new Form_Group('Presets');
2117
$group->addClass('dhcpadvanced');
2118

    
2119
$group->add(new Form_Checkbox(
2120
	'adv_dhcp_pt_values',
2121
	null,
2122
	'FreeBSD default',
2123
	null,
2124
	'DHCP'
2125
))->displayAsRadio();
2126

    
2127
$group->add(new Form_Checkbox(
2128
	'adv_dhcp_pt_values',
2129
	null,
2130
	'Clear',
2131
	null,
2132
	'Clear'
2133
))->displayAsRadio();
2134

    
2135
$group->add(new Form_Checkbox(
2136
	'adv_dhcp_pt_values',
2137
	null,
2138
	'pfSense Default',
2139
	null,
2140
	'pfSense'
2141
))->displayAsRadio();
2142

    
2143
$group->add(new Form_Checkbox(
2144
	'adv_dhcp_pt_values',
2145
	null,
2146
	'Saved Cfg',
2147
	null,
2148
	'SavedCfg'
2149
))->displayAsRadio();
2150

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

    
2154
$section->add($group);
2155

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

    
2166
$form->add($section);
2167

    
2168
$section = new Form_Section('Lease Requirements and Requests');
2169
$section->addClass('dhcpadvanced');
2170

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

    
2181
$section->addInput(new Form_Input(
2182
	'adv_dhcp_request_options',
2183
	'Request options',
2184
	'text',
2185
	$pconfig['adv_dhcp_request_options']
2186
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2187
			'Some ISPs may require certain options be or not be requested.', '<br />');
2188

    
2189
$section->addInput(new Form_Input(
2190
	'adv_dhcp_required_options',
2191
	'Require options',
2192
	'text',
2193
	$pconfig['adv_dhcp_required_options']
2194
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2195

    
2196
$section->addInput(new Form_Input(
2197
	'adv_dhcp_option_modifiers',
2198
	'Option modifiers',
2199
	'text',
2200
	$pconfig['adv_dhcp_option_modifiers']
2201
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2202
			'modifiers: (default, supersede, prepend, append) %1$s' .
2203
			'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>');
2204

    
2205
$form->add($section);
2206

    
2207
// DHCP6 client config
2208

    
2209
$section = new Form_Section('DHCP6 Client Configuration');
2210
$section->addClass('dhcp6');
2211

    
2212
$group = new Form_Group('Options');
2213

    
2214
$group->add(new Form_Checkbox(
2215
	'adv_dhcp6_config_advanced',
2216
	null,
2217
	'Advanced Configuration',
2218
	$pconfig['adv_dhcp6_config_advanced']
2219
))->setHelp('Use advanced DHCPv6 configuration options.');
2220

    
2221
$group->add(new Form_Checkbox(
2222
	'adv_dhcp6_config_file_override',
2223
	null,
2224
	'Configuration Override',
2225
	$pconfig['adv_dhcp6_config_file_override']
2226
))->setHelp('Override the configuration from this file.');
2227

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

    
2230
$section->addInput(new Form_Checkbox(
2231
	'dhcp6usev4iface',
2232
	'Use IPv4 connectivity as parent interface',
2233
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2234
	$pconfig['dhcp6usev4iface']
2235
));
2236

    
2237
$section->addInput(new Form_Checkbox(
2238
	'dhcp6prefixonly',
2239
	'Request only an IPv6 prefix',
2240
	'Only request an IPv6 prefix, do not request an IPv6 address',
2241
	$pconfig['dhcp6prefixonly']
2242
));
2243

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

    
2251
$section->addInput(new Form_Checkbox(
2252
	'dhcp6-ia-pd-send-hint',
2253
	'Send IPv6 prefix hint',
2254
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2255
	$pconfig['dhcp6-ia-pd-send-hint']
2256
));
2257

    
2258
$section->addInput(new Form_Checkbox(
2259
	'dhcp6debug',
2260
	'Debug',
2261
	'Start DHCP6 client in debug mode',
2262
	$pconfig['dhcp6debug']
2263
));
2264
$section->addInput(new Form_Checkbox(
2265
	'dhcp6withoutra',
2266
	'Do not wait for a RA',
2267
	'Required by some ISPs, especially those not using PPPoE',
2268
	$pconfig['dhcp6withoutra']
2269
));
2270
$section->addInput(new Form_Checkbox(
2271
	'dhcp6norelease',
2272
	'Do not allow PD/Address release',
2273
	'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',
2274
	$pconfig['dhcp6norelease']
2275
));
2276

    
2277
$group = new Form_Group('DHCP6 VLAN Priority');
2278

    
2279
$vlanprio = array(
2280
	"bk" => "Background (BK, 0)",
2281
	"be" => "Best Effort (BE, 1)",
2282
	"ee" => "Excellent Effort (EE, 2)",
2283
	"ca" => "Critical Applications (CA, 3)",
2284
	"vi" => "Video (VI, 4)",
2285
	"vo" => "Voice (VO, 5)",
2286
	"ic" => "Internetwork Control (IC, 6)",
2287
	"nc" => "Network Control (NC, 7)");
2288

    
2289
$group->add(new Form_Checkbox(
2290
	'dhcp6vlanenable',
2291
	null,
2292
	'Enable dhcp6c VLAN Priority tagging',
2293
	$pconfig['dhcp6vlanenable']
2294
))->setHelp('Normally off unless specifically required by the ISP.');
2295

    
2296
$group->add(new Form_Select(
2297
	'dhcp6cvpt',
2298
	'VLAN Prio',
2299
	$pconfig['dhcp6cvpt'],
2300
	$vlanprio
2301
))->setHelp('Choose 802.1p priority to set.');
2302

    
2303
$section->add($group);
2304

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

    
2315
$form->add($section);
2316

    
2317
// DHCP6 client config - Advanced
2318

    
2319
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2320
$section->addClass('dhcp6advanced');
2321

    
2322
$section->addInput(new Form_Checkbox(
2323
	'adv_dhcp6_interface_statement_information_only_enable',
2324
	'Information only',
2325
	'Exchange Information Only',
2326
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2327
	'Selected'
2328
))->setHelp('Only exchange informational configuration parameters with servers.');
2329

    
2330
$section->addInput(new Form_Input(
2331
	'adv_dhcp6_interface_statement_send_options',
2332
	'Send options',
2333
	'text',
2334
	$pconfig['adv_dhcp6_interface_statement_send_options']
2335
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2336
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2337
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2338
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2339

    
2340
$section->addInput(new Form_Input(
2341
	'adv_dhcp6_interface_statement_request_options',
2342
	'Request Options',
2343
	'text',
2344
	$pconfig['adv_dhcp6_interface_statement_request_options']
2345
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2346
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2347

    
2348
$section->addInput(new Form_Input(
2349
	'adv_dhcp6_interface_statement_script',
2350
	'Scripts',
2351
	'text',
2352
	$pconfig['adv_dhcp6_interface_statement_script']
2353
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2354
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2355

    
2356
$group = new Form_Group('Identity Association Statement');
2357

    
2358
$group->add(new Form_Checkbox(
2359
	'adv_dhcp6_id_assoc_statement_address_enable',
2360
	null,
2361
	'Non-Temporary Address Allocation',
2362
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2363
	'Selected'
2364
));
2365

    
2366
$group->add(new Form_Input(
2367
	'adv_dhcp6_id_assoc_statement_address_id',
2368
	null,
2369
	'text',
2370
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2371
))->sethelp('id-assoc na ID');
2372

    
2373
$group->add(new Form_IpAddress(
2374
	'adv_dhcp6_id_assoc_statement_address',
2375
	null,
2376
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2377
	'V6'
2378
))->sethelp('IPv6 address');
2379

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

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

    
2394
$section->add($group);
2395

    
2396
// Prefix delegation
2397
$group = new Form_Group('');
2398

    
2399
$group->add(new Form_Checkbox(
2400
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2401
	null,
2402
	'Prefix Delegation ',
2403
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2404
	'Selected'
2405
));
2406

    
2407
$group->add(new Form_Input(
2408
	'adv_dhcp6_id_assoc_statement_prefix_id',
2409
	null,
2410
	'text',
2411
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2412
))->sethelp('id-assoc pd ID');
2413

    
2414
$group->add(new Form_IpAddress(
2415
	'adv_dhcp6_id_assoc_statement_prefix',
2416
	null,
2417
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2418
	'V6'
2419
))->sethelp('IPv6 prefix');
2420

    
2421
$group->add(new Form_Input(
2422
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2423
	null,
2424
	'text',
2425
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2426
))->sethelp('pltime');
2427

    
2428
$group->add(new Form_Input(
2429
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2430
	null,
2431
	'text',
2432
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2433
))->sethelp('vltime');
2434

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

    
2437
$group = new Form_Group('Prefix interface statement');
2438

    
2439
$group->add(new Form_Input(
2440
	'adv_dhcp6_prefix_interface_statement_sla_id',
2441
	null,
2442
	'text',
2443
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2444
))->sethelp('Prefix Interface sla-id');
2445

    
2446
$group->add(new Form_Input(
2447
	'adv_dhcp6_prefix_interface_statement_sla_len',
2448
	null,
2449
	'text',
2450
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2451
))->sethelp('sla-len');
2452

    
2453
$section->add($group);
2454

    
2455
$group = new Form_Group('Select prefix interface');
2456
$section->addInput(new Form_Select(
2457
	'adv_dhcp6_prefix_selected_interface',
2458
	'Prefix Interface',
2459
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2460
	$interfaces
2461
))->setHelp('Select the interface on which to apply the prefix delegation.');
2462

    
2463
$group = new Form_Group('Authentication statement');
2464

    
2465
$group->add(new Form_Input(
2466
	'adv_dhcp6_authentication_statement_authname',
2467
	null,
2468
	'text',
2469
	$pconfig['adv_dhcp6_authentication_statement_authname']
2470
))->sethelp('Authname');
2471

    
2472
$group->add(new Form_Input(
2473
	'adv_dhcp6_authentication_statement_protocol',
2474
	null,
2475
	'text',
2476
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2477
))->sethelp('Protocol');
2478

    
2479
$group->add(new Form_Input(
2480
	'adv_dhcp6_authentication_statement_algorithm',
2481
	null,
2482
	'text',
2483
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2484
))->sethelp('Algorithm');
2485

    
2486
$group->add(new Form_Input(
2487
	'adv_dhcp6_authentication_statement_rdm',
2488
	null,
2489
	'text',
2490
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2491
))->sethelp('RDM');
2492

    
2493
$section->add($group);
2494

    
2495
$group = new Form_Group('Keyinfo statement');
2496

    
2497
$group->add(new Form_Input(
2498
	'adv_dhcp6_key_info_statement_keyname',
2499
	null,
2500
	'text',
2501
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2502
))->sethelp('Keyname');
2503

    
2504
$group->add(new Form_Input(
2505
	'adv_dhcp6_key_info_statement_realm',
2506
	null,
2507
	'text',
2508
	$pconfig['adv_dhcp6_key_info_statement_realm']
2509
))->sethelp('Realm');
2510

    
2511
$section->add($group);
2512

    
2513
$group = new Form_Group('');
2514

    
2515
$group->add(new Form_Input(
2516
	'adv_dhcp6_key_info_statement_keyid',
2517
	null,
2518
	'text',
2519
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2520
))->sethelp('KeyID');
2521

    
2522
$group->add(new Form_Input(
2523
	'adv_dhcp6_key_info_statement_secret',
2524
	null,
2525
	'text',
2526
	$pconfig['adv_dhcp6_key_info_statement_secret']
2527
))->sethelp('Secret');
2528

    
2529
$group->add(new Form_Input(
2530
	'adv_dhcp6_key_info_statement_expire',
2531
	null,
2532
	'text',
2533
	$pconfig['adv_dhcp6_key_info_statement_expire']
2534
))->sethelp('Expire');
2535

    
2536
$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>');
2537

    
2538
$section->add($group);
2539

    
2540
$form->add($section);
2541

    
2542
$section = new Form_Section('6RD Configuration');
2543
$section->addClass('_6rd');
2544

    
2545
$section->addInput(new Form_Input(
2546
	'prefix-6rd',
2547
	'6RD Prefix',
2548
	'text',
2549
	$pconfig['prefix-6rd']
2550
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2551

    
2552
$section->addInput(new Form_Input(
2553
	'gateway-6rd',
2554
	'*6RD Border relay',
2555
	'text',
2556
	$pconfig['gateway-6rd']
2557
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2558

    
2559
$section->addInput(new Form_Select(
2560
	'prefix-6rd-v4plen',
2561
	'6RD IPv4 Prefix length',
2562
	$pconfig['prefix-6rd-v4plen'],
2563
	array_combine(range(0, 32), range(0, 32))
2564
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2565

    
2566
$form->add($section);
2567

    
2568
// Track IPv6 ointerface section
2569
$section = new Form_Section('Track IPv6 Interface');
2570
$section->addClass('track6');
2571

    
2572
function build_ipv6interface_list() {
2573
	global $config, $section;
2574

    
2575
	$list = array('' => '');
2576

    
2577
	$interfaces = get_configured_interface_with_descr(true);
2578
	$dynv6ifs = array();
2579

    
2580
	foreach ($interfaces as $iface => $ifacename) {
2581
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2582
			case "6to4":
2583
			case "6rd":
2584
			case "dhcp6":
2585
				$dynv6ifs[$iface] = array(
2586
					'name' => $ifacename,
2587
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2588
				);
2589
				break;
2590
			default:
2591
				continue;
2592
		}
2593
	}
2594

    
2595
	foreach ($dynv6ifs as $iface => $ifacedata) {
2596
		$list[$iface] = $ifacedata['name'];
2597

    
2598
		$section->addInput(new Form_Input(
2599
			'ipv6-num-prefix-ids-' . $iface,
2600
			null,
2601
			'hidden',
2602
			$ifacedata['ipv6_num_prefix_ids']
2603
		));
2604
	}
2605

    
2606
	return($list);
2607
}
2608

    
2609
$section->addInput(new Form_Select(
2610
	'track6-interface',
2611
	'*IPv6 Interface',
2612
	$pconfig['track6-interface'],
2613
	build_ipv6interface_list()
2614
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2615

    
2616
if ($pconfig['track6-prefix-id'] == "") {
2617
	$pconfig['track6-prefix-id'] = 0;
2618
}
2619

    
2620
$section->addInput(new Form_Input(
2621
	'track6-prefix-id--hex',
2622
	'IPv6 Prefix ID',
2623
	'text',
2624
	sprintf("%x", $pconfig['track6-prefix-id'])
2625
))->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>');
2626

    
2627
$section->addInput(new Form_Input(
2628
	'track6-prefix-id-max',
2629
	null,
2630
	'hidden',
2631
	0
2632
));
2633

    
2634
$form->add($section);
2635

    
2636
/// PPP section
2637

    
2638
$section = new Form_Section('PPP Configuration');
2639
$section->addClass('ppp');
2640

    
2641
$section->addInput(new Form_Select(
2642
	'country',
2643
	'Country',
2644
	$pconfig['country'],
2645
	[]
2646
));
2647

    
2648
$section->addInput(new Form_Select(
2649
	'provider_list',
2650
	'Provider',
2651
	$pconfig['provider_list'],
2652
	[]
2653
));
2654

    
2655
$section->addInput(new Form_Select(
2656
	'providerplan',
2657
	'Plan',
2658
	$pconfig['providerplan'],
2659
	[]
2660
))->setHelp('Select to fill in service provider data.');
2661

    
2662
$section->addInput(new Form_Input(
2663
	'ppp_username',
2664
	'Username',
2665
	'text',
2666
	$pconfig['ppp_username']
2667
));
2668

    
2669
$section->addPassword(new Form_Input(
2670
	'ppp_password',
2671
	'Password',
2672
	'password',
2673
	$pconfig['ppp_password']
2674
));
2675

    
2676
$section->addInput(new Form_Input(
2677
	'phone',
2678
	'*Phone number',
2679
	'text',
2680
	$pconfig['phone']
2681
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2682

    
2683
$section->addInput(new Form_Input(
2684
	'apn',
2685
	'Access Point Name',
2686
	'text',
2687
	$pconfig['apn']
2688
));
2689

    
2690

    
2691
function build_port_list() {
2692
	$list = array("" => "None");
2693

    
2694
	$portlist = glob("/dev/cua*");
2695
	$modems	  = glob("/dev/modem*");
2696
	$portlist = array_merge($portlist, $modems);
2697

    
2698
	foreach ($portlist as $port) {
2699
		if (preg_match("/\.(lock|init)$/", $port)) {
2700
			continue;
2701
		}
2702

    
2703
	$list[trim($port)] = $port;
2704
	}
2705

    
2706
	return($list);
2707
}
2708

    
2709
$section->addInput(new Form_Select(
2710
	'port',
2711
	"*Modem port",
2712
	$pconfig['port'],
2713
	build_port_list()
2714
));
2715

    
2716
$section->addInput(new Form_Button(
2717
	'btnadvppp',
2718
	'Advanced PPP',
2719
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2720
	'fa-cog'
2721
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2722

    
2723
$form->add($section);
2724

    
2725
// PPPoE configuration
2726
$section = new Form_Section('PPPoE Configuration');
2727
$section->addClass('pppoe');
2728

    
2729
$section->addInput(new Form_Input(
2730
	'pppoe_username',
2731
	'*Username',
2732
	'text',
2733
	$pconfig['pppoe_username']
2734
));
2735

    
2736
$section->addPassword(new Form_Input(
2737
	'pppoe_password',
2738
	'*Password',
2739
	'password',
2740
	$pconfig['pppoe_password']
2741
));
2742

    
2743
$section->addInput(new Form_Input(
2744
	'provider',
2745
	'Service name',
2746
	'text',
2747
	$pconfig['provider']
2748
))->setHelp('This field can usually be left empty.');
2749

    
2750
$section->addInput(new Form_Checkbox(
2751
	'pppoe_dialondemand',
2752
	'Dial on demand',
2753
	'Enable Dial-On-Demand mode ',
2754
	$pconfig['pppoe_dialondemand'],
2755
	'enable'
2756
));
2757

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

    
2767
$section->addInput(new Form_Select(
2768
	'pppoe-reset-type',
2769
	'Periodic reset',
2770
	$pconfig['pppoe-reset-type'],
2771
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2772
))->setHelp('Select a reset timing type.');
2773

    
2774
$group = new Form_Group('Custom reset');
2775
$group->addClass('pppoecustom');
2776

    
2777
$group->add(new Form_Input(
2778
	'pppoe_resethour',
2779
	null,
2780
	'number',
2781
	$pconfig['pppoe_resethour'],
2782
	['min' => 0, 'max' => 23]
2783
))->setHelp('Hour (0-23)');
2784

    
2785
$group->add(new Form_Input(
2786
	'pppoe_resetminute',
2787
	null,
2788
	'number',
2789
	$pconfig['pppoe_resetminute'],
2790
	['min' => 0, 'max' => 59]
2791
))->setHelp('Minutes (0-59)');
2792

    
2793
$group->add(new Form_Input(
2794
	'pppoe_resetdate',
2795
	null,
2796
	'text',
2797
	$pconfig['pppoe_resetdate']
2798
))->setHelp('Specific date (mm/dd/yyyy)');
2799

    
2800
$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');
2801

    
2802
$section->add($group);
2803

    
2804
$group = new Form_MultiCheckboxGroup('cron based reset');
2805
$group->addClass('pppoepreset');
2806

    
2807
$group->add(new Form_MultiCheckbox(
2808
	'pppoe_pr_preset_val',
2809
	null,
2810
	'Reset at each month ("0 0 1 * *")',
2811
	$pconfig['pppoe_monthly'],
2812
	'monthly'
2813
))->displayAsRadio();
2814

    
2815
$group->add(new Form_MultiCheckbox(
2816
	'pppoe_pr_preset_val',
2817
	null,
2818
	'Reset at each week ("0 0 * * 0")',
2819
	$pconfig['pppoe_weekly'],
2820
	'weekly'
2821
))->displayAsRadio();
2822

    
2823
$group->add(new Form_MultiCheckbox(
2824
	'pppoe_pr_preset_val',
2825
	null,
2826
	'Reset at each day ("0 0 * * *")',
2827
	$pconfig['pppoe_daily'],
2828
	'daily'
2829
))->displayAsRadio();
2830

    
2831
$group->add(new Form_MultiCheckbox(
2832
	'pppoe_pr_preset_val',
2833
	null,
2834
	'Reset at each hour ("0 * * * *")',
2835
	$pconfig['pppoe_hourly'],
2836
	'hourly'
2837
))->displayAsRadio();
2838

    
2839
$section->add($group);
2840

    
2841
$section->addInput(new Form_Button(
2842
	'btnadvppp',
2843
	'Advanced and MLPPP',
2844
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2845
	'fa-cog'
2846
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2847

    
2848
$form->add($section);
2849

    
2850
// PPTP & L2TP Configuration section
2851
$section = new Form_Section('PPTP/L2TP Configuration');
2852
$section->addClass('pptp');
2853

    
2854
$section->addInput(new Form_Input(
2855
	'pptp_username',
2856
	'*Username',
2857
	'text',
2858
	$pconfig['pptp_username']
2859
));
2860

    
2861
$section->addPassword(new Form_Input(
2862
	'pptp_password',
2863
	'*Password',
2864
	'password',
2865
	$pconfig['pptp_password']
2866
));
2867

    
2868
$section->addInput(new Form_IpAddress(
2869
	'pptp_local0',
2870
	'*Local IP address',
2871
	$pconfig['pptp_localip'][0],
2872
	'V4'
2873
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2874

    
2875
$section->addInput(new Form_IpAddress(
2876
	'pptp_remote0',
2877
	'*Remote IP address',
2878
	$pconfig['pptp_remote'][0],
2879
	'HOSTV4'
2880
));
2881

    
2882
$section->addInput(new Form_Checkbox(
2883
	'pptp_dialondemand',
2884
	'Dial on demand',
2885
	'Enable Dial-On-Demand mode ',
2886
	$pconfig['pptp_dialondemand'],
2887
	'enable'
2888
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2889
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2890

    
2891
$section->addInput(new Form_Input(
2892
	'pptp_idletimeout',
2893
	'Idle timeout (seconds)',
2894
	'number',
2895
	$pconfig['pptp_idletimeout'],
2896
	['min' => 0]
2897
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2898
			'An idle timeout of zero disables this feature.');
2899

    
2900
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2901
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2902
} else {
2903
	$mlppp_text = "";
2904
}
2905

    
2906
$section->addInput(new Form_Button(
2907
	'btnadvppp',
2908
	'Advanced and MLPPP',
2909
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2910
	'fa-cog'
2911
))->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);
2912

    
2913
$form->add($section);
2914

    
2915
// Wireless interface
2916
if (isset($wancfg['wireless'])) {
2917

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

    
2920
	$section->addInput(new Form_Checkbox(
2921
		'persistcommonwireless',
2922
		'Persist common settings',
2923
		'Preserve common wireless configuration through interface deletions and reassignments.',
2924
		$pconfig['persistcommonwireless'],
2925
		'yes'
2926
	));
2927

    
2928
	$mode_list = ['auto' => 'Auto'];
2929

    
2930
	if (is_array($wl_modes)) {
2931
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2932
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2933
		}
2934
	}
2935

    
2936
	if (count($mode_list) == 1) {
2937
		$mode_list[''] = '';
2938
	}
2939

    
2940
	$section->addInput(new Form_Select(
2941
		'standard',
2942
		'Standard',
2943
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2944
		$mode_list
2945
	));
2946

    
2947
	if (isset($wl_modes['11g'])) {
2948
		$section->addInput(new Form_Select(
2949
			'protmode',
2950
			'802.11g OFDM Protection Mode',
2951
			$pconfig['protmode'],
2952
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2953
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2954
	} else {
2955
		$section->addInput(new Form_Input(
2956
			'protmode',
2957
			null,
2958
			'hidden',
2959
			'off'
2960
		));
2961
	}
2962

    
2963
	$mode_list = ['0' => gettext('Auto')];
2964

    
2965
	if (is_array($wl_modes)) {
2966
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2967
			if ($wl_standard == "11g") {
2968
				$wl_standard = "11b/g";
2969
			} else if ($wl_standard == "11ng") {
2970
				$wl_standard = "11b/g/n";
2971
			} else if ($wl_standard == "11na") {
2972
				$wl_standard = "11a/n";
2973
			}
2974

    
2975
			foreach ($wl_channels as $wl_channel) {
2976
				if (isset($wl_chaninfo[$wl_channel])) {
2977
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2978
				} else {
2979
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2980
				}
2981
			}
2982
		}
2983
	}
2984

    
2985
	$section->addInput(new Form_Select(
2986
		'channel',
2987
		'Channel',
2988
		$pconfig['channel'],
2989
		$mode_list
2990
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2991
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2992

    
2993
	if (ANTENNAS) {
2994
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2995
			$group = new Form_Group('Antenna Settings');
2996

    
2997
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2998
				$group->add(new Form_Select(
2999
					'diversity',
3000
					null,
3001
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3002
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3003
				))->setHelp('Diversity');
3004
			}
3005

    
3006
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3007
				$group->add(new Form_Select(
3008
					'txantenna',
3009
					null,
3010
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3011
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3012
				))->setHelp('Transmit antenna');
3013
			}
3014

    
3015
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3016
				$group->add(new Form_Select(
3017
					'rxantenna',
3018
					null,
3019
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3020
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3021
				))->setHelp('Receive antenna');
3022
			}
3023

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

    
3026
			$section->add($group);
3027
		}
3028
	}
3029

    
3030
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3031
			$section->addInput(new Form_Input(
3032
				'distance',
3033
				'Distance setting (meters)',
3034
				'test',
3035
				$pconfig['distance']
3036
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3037
	}
3038

    
3039
	$form->add($section);
3040

    
3041
	// Regulatory settings
3042
	$section = new Form_Section('Regulatory Settings');
3043

    
3044
	$domain_list = array("" => 'Default');
3045

    
3046
	if (is_array($wl_regdomains)) {
3047
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3048
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3049
		}
3050
	}
3051

    
3052
	$section->addInput(new Form_Select(
3053
		'regdomain',
3054
		'Regulatory domain',
3055
		$pconfig['regdomain'],
3056
		$domain_list
3057
	))->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');
3058

    
3059
	$country_list = array('' => 'Default');
3060

    
3061
	if (is_array($wl_countries)) {
3062
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3063
			$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']);
3064
		}
3065
	}
3066

    
3067
	$section->addInput(new Form_Select(
3068
		'regcountry',
3069
		'Country',
3070
		$pconfig['regcountry'],
3071
		$country_list
3072
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3073

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

    
3085
	$form->add($section);
3086

    
3087
	$section = new Form_Section('Network-Specific Wireless Configuration');
3088

    
3089
	$section->addInput(new Form_Select(
3090
		'mode',
3091
		'Mode',
3092
		$pconfig['mode'],
3093
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3094
	));
3095

    
3096
	$section->addInput(new Form_Input(
3097
		'ssid',
3098
		'SSID',
3099
		'text',
3100
		$pconfig['ssid']
3101
	));
3102

    
3103
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3104
		$section->addInput(new Form_Select(
3105
			'puremode',
3106
			'Minimum wireless standard',
3107
			$pconfig['puremode'],
3108
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3109
		))->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)');
3110
	} elseif (isset($wl_modes['11g'])) {
3111
		$section->addInput(new Form_Checkbox(
3112
			'puremode',
3113
			'802.11g only',
3114
			null,
3115
			$pconfig['puremode'],
3116
			'11g'
3117
		))->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)');
3118
	}
3119

    
3120
	$section->addInput(new Form_Checkbox(
3121
		'apbridge_enable',
3122
		'Allow intra-BSS communication',
3123
		'Allow packets to pass between wireless clients directly when operating as an access point',
3124
		$pconfig['apbridge_enable'],
3125
		'yes'
3126
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3127

    
3128
	$section->addInput(new Form_Checkbox(
3129
		'wme_enable',
3130
		'Enable WME',
3131
		'Force the card to use WME (wireless QoS)',
3132
		$pconfig['wme_enable'],
3133
		'yes'
3134
	));
3135

    
3136
	$section->addInput(new Form_Checkbox(
3137
		'hidessid_enable',
3138
		'Hide SSID',
3139
		'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.)',
3140
		$pconfig['hidessid_enable'],
3141
		'yes'
3142
	));
3143

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

    
3146
	// WPA Section
3147
	$section = new Form_Section('WPA');
3148

    
3149
	$section->addInput(new Form_Checkbox(
3150
		'wpa_enable',
3151
		'Enable',
3152
		'Enable WPA',
3153
		$pconfig['wpa_enable'],
3154
		'yes'
3155
	));
3156

    
3157
	$section->addInput(new Form_Input(
3158
		'passphrase',
3159
		'WPA Pre-Shared Key',
3160
		'text',
3161
		$pconfig['passphrase']
3162
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3163

    
3164
	$section->addInput(new Form_Select(
3165
		'wpa_mode',
3166
		'WPA mode',
3167
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3168
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3169
	));
3170

    
3171
	$section->addInput(new Form_Select(
3172
		'wpa_key_mgmt',
3173
		'WPA Key Management Mode',
3174
		$pconfig['wpa_key_mgmt'],
3175
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3176
	));
3177

    
3178
	$section->addInput(new Form_Select(
3179
		'wpa_pairwise',
3180
		'WPA Pairwise',
3181
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3182
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3183
	));
3184

    
3185
	$section->addInput(new Form_Input(
3186
		'wpa_group_rekey',
3187
		'Group Key Rotation',
3188
		'number',
3189
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3190
		['min' => '1', 'max' => 9999]
3191
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3192

    
3193
	$section->addInput(new Form_Input(
3194
		'wpa_gmk_rekey',
3195
		'Group Master Key Regeneration',
3196
		'number',
3197
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3198
		['min' => '1', 'max' => 9999]
3199
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3200

    
3201
	$section->addInput(new Form_Checkbox(
3202
		'wpa_strict_rekey',
3203
		'Strict Key Regeneration',
3204
		'Force the AP to rekey whenever a client disassociates',
3205
		$pconfig['wpa_strict_rekey'],
3206
		'yes'
3207
	));
3208

    
3209
	$form->add($section);
3210

    
3211
	$section = new Form_Section('802.1x RADIUS Options');
3212

    
3213
	$section->addInput(new Form_Checkbox(
3214
		'ieee8021x',
3215
		'IEEE802.1X',
3216
		'Enable 802.1X authentication',
3217
		$pconfig['ieee8021x'],
3218
		'yes'
3219
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3220

    
3221
	$group = new Form_Group('Primary 802.1X server');
3222

    
3223
	$group->add(new Form_IpAddress(
3224
		'auth_server_addr',
3225
		'IP Address',
3226
		$pconfig['auth_server_addr']
3227
	))->setHelp('IP address of the RADIUS server');
3228

    
3229
	$group->add(new Form_Input(
3230
		'auth_server_port',
3231
		'Port',
3232
		'number',
3233
		$pconfig['auth_server_port']
3234
	))->setHelp('Server auth port. Default is 1812');
3235

    
3236
	$group->add(new Form_Input(
3237
		'auth_server_shared_secret',
3238
		'Shared Secret',
3239
		'text',
3240
		$pconfig['auth_server_shared_secret']
3241
	))->setHelp('RADIUS Shared secret for this firewall');
3242

    
3243
	$section->add($group);
3244

    
3245
	$group = new Form_Group('Secondary 802.1X server');
3246

    
3247
	$group->add(new Form_IpAddress(
3248
		'auth_server_addr2',
3249
		'IP Address',
3250
		$pconfig['auth_server_addr2']
3251
	))->setHelp('IP address of the RADIUS server');
3252

    
3253
	$group->add(new Form_Input(
3254
		'auth_server_port2',
3255
		'Port',
3256
		'number',
3257
		$pconfig['auth_server_port2']
3258
	))->setHelp('Server auth port. Default is 1812');
3259

    
3260
	$group->add(new Form_Input(
3261
		'auth_server_shared_secret2',
3262
		'Shared Secret',
3263
		'text',
3264
		$pconfig['auth_server_shared_secret2']
3265
	))->setHelp('RADIUS Shared secret for this firewall');
3266

    
3267
	$section->add($group);
3268

    
3269
	$section->addInput(new Form_Checkbox(
3270
		'rsn_preauth',
3271
		'Authentication Roaming Preauth',
3272
		null,
3273
		$pconfig['rsn_preauth'],
3274
		'yes'
3275
	));
3276

    
3277
	$form->add($section);
3278
}
3279

    
3280
$section = new Form_Section('Reserved Networks');
3281

    
3282
$section->addInput(new Form_Checkbox(
3283
	'blockpriv',
3284
	'Block private networks and loopback addresses',
3285
	'',
3286
	$pconfig['blockpriv'],
3287
	'yes'
3288
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3289
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3290
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3291

    
3292
$section->addInput(new Form_Checkbox(
3293
	'blockbogons',
3294
	'Block bogon networks',
3295
	'',
3296
	$pconfig['blockbogons'],
3297
	'yes'
3298
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3299
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3300
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3301

    
3302
$form->add($section);
3303

    
3304
$form->addGlobal(new Form_Input(
3305
	'if',
3306
	null,
3307
	'hidden',
3308
	$if
3309
));
3310

    
3311
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3312
	$form->addGlobal(new Form_Input(
3313
		'ppp_port',
3314
		null,
3315
		'hidden',
3316
		$pconfig['port']
3317
	));
3318
}
3319

    
3320
$form->addGlobal(new Form_Input(
3321
	'ptpid',
3322
	null,
3323
	'hidden',
3324
	$pconfig['ptpid']
3325
));
3326

    
3327

    
3328
// Add new gateway modal pop-up
3329
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3330

    
3331
$modal->addInput(new Form_Checkbox(
3332
	'defaultgw4',
3333
	'Default',
3334
	'Default gateway',
3335
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3336
));
3337

    
3338
$modal->addInput(new Form_Input(
3339
	'gatewayname4',
3340
	'Gateway name',
3341
	'text',
3342
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3343
));
3344

    
3345
$modal->addInput(new Form_IpAddress(
3346
	'gatewayip4',
3347
	'Gateway IPv4',
3348
	$gateway_settings4['gateway'],
3349
	'V4'
3350
));
3351

    
3352
$modal->addInput(new Form_Input(
3353
	'gatewaydescr4',
3354
	'Description',
3355
	'text',
3356
	$gateway_settings4['descr']
3357
));
3358

    
3359
$btnaddgw4 = new Form_Button(
3360
	'add4',
3361
	'Add',
3362
	null,
3363
	'fa-plus'
3364
);
3365

    
3366
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3367

    
3368
$btncnxgw4 = new Form_Button(
3369
	'cnx4',
3370
	'Cancel',
3371
	null,
3372
	'fa-undo'
3373
);
3374

    
3375
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3376

    
3377
$modal->addInput(new Form_StaticText(
3378
	null,
3379
	$btnaddgw4 . $btncnxgw4
3380
));
3381

    
3382
$form->add($modal);
3383

    
3384
print($form);
3385
?>
3386

    
3387
<script type="text/javascript">
3388
//<![CDATA[
3389
events.push(function() {
3390
	function updateType(t) {
3391

    
3392
		switch (t) {
3393
			case "none": {
3394
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3395
				break;
3396
			}
3397
			case "staticv4": {
3398
				$('.dhcpadvanced, .none, .dhcp').hide();
3399
				$('.pppoe, .pptp, .ppp').hide();
3400
				break;
3401
			}
3402
			case "dhcp": {
3403
				$('.dhcpadvanced, .none').hide();
3404
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3405
										//			about the staticv4 class
3406
				$('.pppoe, .pptp, .ppp').hide();
3407
				break;
3408
			}
3409
			case "ppp": {
3410
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3411
				country_list();
3412
				break;
3413
			}
3414
			case "pppoe": {
3415
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3416
				break;
3417
			}
3418
			case "l2tp":
3419
			case "pptp": {
3420
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3421
				$('.pptp').show();
3422
				break;
3423
			}
3424
		}
3425

    
3426
		if (t != "l2tp" && t != "pptp") {
3427
			$('.'+t).show();
3428
		}
3429
	}
3430

    
3431
	function updateTypeSix(t) {
3432
		if (!isNaN(t[0])) {
3433
			t = '_' + t;
3434
		}
3435

    
3436
		switch (t) {
3437
			case "none": {
3438
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3439
				break;
3440
			}
3441
			case "staticv6": {
3442
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3443
				break;
3444
			}
3445
			case "slaac": {
3446
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3447
				break;
3448
			}
3449
			case "dhcp6": {
3450
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3451
				break;
3452
			}
3453
			case "_6rd": {
3454
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3455
				break;
3456
			}
3457
			case "_6to4": {
3458
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3459
				break;
3460
			}
3461
			case "track6": {
3462
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3463
				update_track6_prefix();
3464
				break;
3465
			}
3466
		}
3467

    
3468
		if (t != "l2tp" && t != "pptp") {
3469
			$('.'+t).show();
3470
		}
3471
	}
3472

    
3473
	function show_reset_settings(reset_type) {
3474
		if (reset_type == 'preset') {
3475
			$('.pppoepreset').show();
3476
			$('.pppoecustom').hide();
3477
		} else if (reset_type == 'custom') {
3478
			$('.pppoecustom').show();
3479
			$('.pppoepreset').hide();
3480
		} else {
3481
			$('.pppoecustom').hide();
3482
			$('.pppoepreset').hide();
3483
		}
3484
	}
3485

    
3486
	function update_track6_prefix() {
3487
		var iface = $("#track6-interface").val();
3488
		if (iface == null) {
3489
			return;
3490
		}
3491

    
3492
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3493
		if (track6_prefix_ids == null) {
3494
			return;
3495
		}
3496

    
3497
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3498
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3499
	}
3500

    
3501
	function addOption_v4() {
3502
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3503
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3504
	}
3505

    
3506
	function addOption_v6() {
3507
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3508
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3509
	}
3510

    
3511
	function addSelectboxOption(selectbox, text, value) {
3512
		var optn = document.createElement("OPTION");
3513
		optn.text = text;
3514
		optn.value = value;
3515
		selectbox.append(optn);
3516
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3517
	}
3518

    
3519
	function country_list() {
3520
		$('#country').children().remove();
3521
		$('#provider_list').children().remove();
3522
		$('#providerplan').children().remove();
3523
		$.ajax("getserviceproviders.php",{
3524
			success: function(response) {
3525

    
3526
				var responseTextArr = response.split("\n");
3527
				responseTextArr.sort();
3528

    
3529
				responseTextArr.forEach( function(value) {
3530
					country = value.split(":");
3531
					$('#country').append($('<option>', {
3532
						value: country[1],
3533
						text : country[0]
3534
					}));
3535
				});
3536
			}
3537
		});
3538
	}
3539

    
3540
	function providers_list() {
3541
		$('#provider_list').children().remove();
3542
		$('#providerplan').children().remove();
3543
		$.ajax("getserviceproviders.php",{
3544
			type: 'post',
3545
			data: {country : $('#country').val()},
3546
			success: function(response) {
3547
				var responseTextArr = response.split("\n");
3548
				responseTextArr.sort();
3549
				responseTextArr.forEach( function(value) {
3550
					$('#provider_list').append($('<option>', {
3551
							value: value,
3552
							text : value
3553
					}));
3554
				});
3555
			}
3556
		});
3557
	}
3558

    
3559
	function providerplan_list() {
3560
		$('#providerplan').children().remove();
3561
		$.ajax("getserviceproviders.php",{
3562
			type: 'post',
3563
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3564
			success: function(response) {
3565
				var responseTextArr = response.split("\n");
3566
				responseTextArr.sort();
3567

    
3568
				$('#providerplan').append($('<option>', {
3569
					value: '',
3570
					text : ''
3571
				}));
3572

    
3573
				responseTextArr.forEach( function(value) {
3574
					if (value != "") {
3575
						providerplan = value.split(":");
3576

    
3577
						$('#providerplan').append($('<option>', {
3578
							value: providerplan[1],
3579
							text : providerplan[0] + " - " + providerplan[1]
3580
						}));
3581
					}
3582
				});
3583
			}
3584
		});
3585
	}
3586

    
3587
	function prefill_provider() {
3588
		$.ajax("getserviceproviders.php",{
3589
			type: 'post',
3590
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3591
			success: function(data, textStatus, response) {
3592
				var xmldoc = response.responseXML;
3593
				var provider = xmldoc.getElementsByTagName('connection')[0];
3594
				$('#ppp_username').val('');
3595
				$('#ppp_password').val('');
3596
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3597
					$('#phone').val('#777');
3598
					$('#apn').val('');
3599
				} else {
3600
					$('#phone').val('*99#');
3601
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3602
				}
3603
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3604
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3605
				$('#ppp_username').val(ppp_username);
3606
				$('#ppp_password').val(ppp_password);
3607
			}
3608
		});
3609
	}
3610

    
3611
	function show_dhcp6adv() {
3612
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3613
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3614

    
3615
		hideCheckbox('dhcp6usev4iface', ovr);
3616
		hideCheckbox('dhcp6prefixonly', ovr);
3617
		hideInput('dhcp6-ia-pd-len', ovr);
3618
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3619
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3620

    
3621
		hideClass('dhcp6advanced', !adv || ovr);
3622
	}
3623

    
3624
	function setDHCPoptions() {
3625
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3626
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3627

    
3628
		if (ovr) {
3629
			hideInput('dhcphostname', true);
3630
			hideIpAddress('alias-address', true);
3631
			hideInput('dhcprejectfrom', true);
3632
			hideInput('adv_dhcp_config_file_override_path', false);
3633
			hideClass('dhcpadvanced', true);
3634
		} else {
3635
			hideInput('dhcphostname', false);
3636
			hideIpAddress('alias-address', false);
3637
			hideInput('dhcprejectfrom', false);
3638
			hideInput('adv_dhcp_config_file_override_path', true);
3639
			hideClass('dhcpadvanced', !adv);
3640
		}
3641
	}
3642

    
3643
	// DHCP preset actions
3644
	// Set presets from value of radio buttons
3645
	function setPresets(val) {
3646
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3647
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3648
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3649
		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']);?>");
3650
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3651
	}
3652

    
3653
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3654
		$('#adv_dhcp_pt_timeout').val(timeout);
3655
		$('#adv_dhcp_pt_retry').val(retry);
3656
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3657
		$('#adv_dhcp_pt_reboot').val(reboot);
3658
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3659
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3660
	}
3661

    
3662
	function setPPPoEDialOnDemandItems() {
3663
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3664
	}
3665

    
3666
	function setPPTPDialOnDemandItems() {
3667
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3668
	}
3669

    
3670
	// ---------- On initial page load ------------------------------------------------------------
3671

    
3672
	updateType($('#type').val());
3673
	updateTypeSix($('#type6').val());
3674
	show_reset_settings($('#pppoe-reset-type').val());
3675
	hideClass('dhcp6advanced', true);
3676
	hideClass('dhcpadvanced', true);
3677
	show_dhcp6adv();
3678
	setDHCPoptions();
3679
	setPPPoEDialOnDemandItems();
3680
	setPPTPDialOnDemandItems();
3681

    
3682
	// Set preset buttons on page load
3683
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3684
	if (sv == "") {
3685
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3686
	} else {
3687
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3688
	}
3689

    
3690
	// Set preset from value
3691
	setPresets(sv);
3692

    
3693
	// If the user wants to add a gateway, then add that to the gateway selection
3694
	if ($("#gatewayip4").val() != '') {
3695
		addOption_v4();
3696
	}
3697
	if ($("#gatewayip6").val() != '') {
3698
		addOption_v6();
3699
	}
3700

    
3701
	// ---------- Click checkbox handlers ---------------------------------------------------------
3702

    
3703
	$('#type').on('change', function() {
3704
		updateType(this.value);
3705
	});
3706

    
3707
	$('#type6').on('change', function() {
3708
		updateTypeSix(this.value);
3709
	});
3710

    
3711
	$('#track6-interface').on('change', function() {
3712
		update_track6_prefix();
3713
	});
3714

    
3715
	$('#pppoe-reset-type').on('change', function() {
3716
		show_reset_settings(this.value);
3717
	});
3718

    
3719
	$("#add4").click(function() {
3720
		addOption_v4();
3721
		$("#newgateway4").modal('hide');
3722
	});
3723

    
3724
	$("#cnx4").click(function() {
3725
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3726
		$("#gatewayip4").val('');
3727
		$("#gatewaydescr4").val('');
3728
		$("#defaultgw4").prop("checked", false);
3729
		$("#newgateway4").modal('hide');
3730
	});
3731

    
3732
	$("#add6").click(function() {
3733
		addOption_v6();
3734
		$("#newgateway6").modal('hide');
3735
	});
3736

    
3737
	$("#cnx6").click(function() {
3738
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3739
		$("#gatewayip6").val('');
3740
		$("#gatewaydescr6").val('');
3741
		$("#defaultgw6").prop("checked", false);
3742
		$("#newgateway6").modal('hide');
3743
	});
3744

    
3745
	$('#country').on('change', function() {
3746
		providers_list();
3747
	});
3748

    
3749
	$('#provider_list').on('change', function() {
3750
		providerplan_list();
3751
	});
3752

    
3753
	$('#providerplan').on('change', function() {
3754
		prefill_provider();
3755
	});
3756

    
3757
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3758
		setDHCPoptions();
3759
	});
3760

    
3761
	$('#adv_dhcp6_config_advanced').click(function () {
3762
		show_dhcp6adv();
3763
	});
3764

    
3765
	$('#adv_dhcp6_config_file_override').click(function () {
3766
		show_dhcp6adv();
3767
	});
3768

    
3769
	// On click . .
3770
	$('#pppoe_dialondemand').click(function () {
3771
		setPPPoEDialOnDemandItems();
3772
	});
3773

    
3774
	$('#pptp_dialondemand').click(function () {
3775
		setPPTPDialOnDemandItems();
3776
	});
3777

    
3778
	$('[name=adv_dhcp_pt_values]').click(function () {
3779
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3780
	});
3781

    
3782
	$('#pppoe_resetdate').datepicker();
3783

    
3784
});
3785
//]]>
3786
</script>
3787

    
3788
<?php include("foot.inc");
(71-71/235)