Project

General

Profile

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

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

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

    
44
define("ANTENNAS", false);
45

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

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

    
55
$if = "wan";
56

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
134
		/* ================================================ */
135
		/* = force a connection reset at a specific time? = */
136
		/* ================================================ */
137

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

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

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

    
204
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
205

    
206
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
207
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
208
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
209
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
210

    
211
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
212
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
213
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
214

    
215
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
216
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
217
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
218
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
219

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

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

    
232
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
233
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
234
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
235

    
236
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
237
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
238
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
239
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
240

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

    
247
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
248
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
249
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
250

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

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

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

    
330
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
331
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
332
$pconfig['spoofmac'] = $wancfg['spoofmac'];
333
$pconfig['mtu'] = $wancfg['mtu'];
334
$pconfig['mss'] = $wancfg['mss'];
335

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

    
412
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
413

    
414
}
415

    
416
$changes_applied = false;
417

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

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

    
454
		/* sync filter configuration */
455
		setup_gateways_monitor();
456

    
457
		clear_subsystem_dirty('interfaces');
458

    
459
		$retval |= filter_configure();
460

    
461
		enable_rrd_graphing();
462

    
463
		$changes_applied = true;
464

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

    
472
	unset($input_errors);
473
	$pconfig = $_POST;
474

    
475
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
476
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
477
	} else {
478
		$pconfig['track6-prefix-id'] = 0;
479
	}
480

    
481
	/* filter out spaces from descriptions */
482
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
483

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

    
498
	/* input validation */
499
	$reqdfields = explode(" ", "descr");
500
	$reqdfieldsn = array(gettext("Description"));
501
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
502

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

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

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

    
530
		if (is_numeric($_POST['descr'])) {
531
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
532
		}
533

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

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

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

    
670
			if (empty($_POST['track6-interface'])) {
671
				$input_errors[] = gettext("A valid interface to track must be selected.");
672
			}
673

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

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

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

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

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

    
750
			foreach ($staticroutes as $route_subnet) {
751
				list($network, $subnet) = explode("/", $route_subnet);
752
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
753
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
754
					break;
755
				}
756
				unset($network, $subnet);
757
			}
758
		}
759
	}
760
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
761
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
762
	}
763
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
764
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
765
	}
766
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
767
		$input_errors[] = gettext("A valid alias IP address must be specified.");
768
	}
769
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
770
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
771
	}
772
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
773
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
774
	}
775

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

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

    
848
		unset($min_mtu, $max_mtu);
849

    
850
		if (interface_is_vlan($wancfg['if']) != NULL) {
851
			$realhwif_array = get_parent_interface($wancfg['if']);
852
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
853
			$parent_realhwif = $realhwif_array[0];
854
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
855
			$mtu = 0;
856
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
857
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
858
			if ($mtu == 0)
859
				$mtu = get_interface_mtu($parent_realhwif);
860
			if ($_POST['mtu'] > $mtu)
861
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
862
		} else {
863
			foreach ($config['interfaces'] as $idx => $ifdata) {
864
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
865
					continue;
866
				}
867

    
868
				$realhwif_array = get_parent_interface($ifdata['if']);
869
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
870
				$parent_realhwif = $realhwif_array[0];
871

    
872
				if ($parent_realhwif != $wancfg['if']) {
873
					continue;
874
				}
875

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

    
963
		if ($_POST['passphrase']) {
964
			$passlen = strlen($_POST['passphrase']);
965
			if ($passlen < 8 || $passlen > 63) {
966
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
967
			}
968
		}
969

    
970
		if ($_POST['wpa_enable'] == "yes") {
971
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
972
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
973
			}
974
		}
975
	}
976

    
977
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
978
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
979
	}
980

    
981
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
982
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
983
	}
984

    
985
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
986
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
987
	}
988

    
989
	if ($_POST['gatewayip4']) {
990
		// The user wants to add an IPv4 gateway - validate the settings
991
		$gateway_settings4 = array();
992

    
993
		$gateway_settings4['name'] = $_POST['gatewayname4'];
994
		$gateway_settings4['interface'] = $_POST['if'];
995
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
996
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
997
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
998
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
999
		foreach ($gw_input_errors as $input_error_text) {
1000
			$input_errors[] = $input_error_text;
1001
		}
1002
	}
1003

    
1004
	if ($_POST['gatewayip6']) {
1005
		// The user wants to add an IPv6 gateway - validate the settings
1006
		$gateway_settings6 = array();
1007

    
1008
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1009
		$gateway_settings6['interface'] = $_POST['if'];
1010
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1011
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1012
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1013
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1014
		foreach ($gw_input_errors as $input_error_text) {
1015
			$input_errors[] = $input_error_text;
1016
		}
1017
	}
1018

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

    
1026
		if ($wancfg['ipaddr'] != $_POST['type']) {
1027
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1028
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1029
				unset($a_ppps[$pppid]);
1030
			} else if ($wancfg['ipaddr'] == "dhcp") {
1031
				kill_dhclient_process($wancfg['if']);
1032
			}
1033
			if ($wancfg['ipaddrv6'] == "dhcp6") {
1034
				kill_dhcp6client_process($wancfg['if'],true);
1035
			}
1036
		}
1037
		$ppp = array();
1038
		if ($wancfg['ipaddr'] != "ppp") {
1039
			unset($wancfg['ipaddr']);
1040
		}
1041
		if ($wancfg['ipaddrv6'] != "ppp") {
1042
			unset($wancfg['ipaddrv6']);
1043
		}
1044
		unset($wancfg['subnet']);
1045
		unset($wancfg['gateway']);
1046
		unset($wancfg['subnetv6']);
1047
		unset($wancfg['gatewayv6']);
1048
		unset($wancfg['dhcphostname']);
1049
		unset($wancfg['dhcprejectfrom']);
1050
		unset($wancfg['dhcp6-duid']);
1051
		unset($wancfg['dhcp6-ia-pd-len']);
1052
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1053
		unset($wancfg['dhcp6prefixonly']);
1054
		unset($wancfg['dhcp6usev4iface']);
1055
		unset($wancfg['ipv6usev4iface']);
1056
		unset($wancfg['dhcp6debug']);
1057
		unset($wancfg['track6-interface']);
1058
		unset($wancfg['track6-prefix-id']);
1059
		unset($wancfg['dhcp6withoutra']);
1060
		unset($wancfg['dhcp6norelease']);
1061
		unset($wancfg['prefix-6rd']);
1062
		unset($wancfg['prefix-6rd-v4plen']);
1063
		unset($wancfg['gateway-6rd']);
1064

    
1065
		unset($wancfg['adv_dhcp_pt_timeout']);
1066
		unset($wancfg['adv_dhcp_pt_retry']);
1067
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1068
		unset($wancfg['adv_dhcp_pt_reboot']);
1069
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1070
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1071

    
1072
		unset($wancfg['adv_dhcp_pt_values']);
1073

    
1074
		unset($wancfg['adv_dhcp_send_options']);
1075
		unset($wancfg['adv_dhcp_request_options']);
1076
		unset($wancfg['adv_dhcp_required_options']);
1077
		unset($wancfg['adv_dhcp_option_modifiers']);
1078

    
1079
		unset($wancfg['adv_dhcp_config_advanced']);
1080
		unset($wancfg['adv_dhcp_config_file_override']);
1081
		unset($wancfg['adv_dhcp_config_file_override_path']);
1082

    
1083
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1084
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1085
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1086
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1087

    
1088
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1089
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1090
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1091
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1092
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1093

    
1094
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1095
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1096
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1097
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1098
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1099

    
1100
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1101
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1102
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1103

    
1104
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1105
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1106
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1107
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1108

    
1109
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1110
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1111
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1112
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1113
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1114

    
1115
		unset($wancfg['adv_dhcp6_config_advanced']);
1116
		unset($wancfg['adv_dhcp6_config_file_override']);
1117
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1118

    
1119
		unset($wancfg['pppoe_password']);
1120
		unset($wancfg['pptp_username']);
1121
		unset($wancfg['pptp_password']);
1122
		unset($wancfg['provider']);
1123
		unset($wancfg['ondemand']);
1124
		unset($wancfg['timeout']);
1125
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1126
			unset($wancfg['pppoe']['pppoe-reset-type']);
1127
		}
1128
		unset($wancfg['local']);
1129

    
1130
		unset($wancfg['remote']);
1131
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1132
			if ($wancfg['ipaddr'] != 'ppp') {
1133
				unset($a_ppps[$pppid]['apn']);
1134
				unset($a_ppps[$pppid]['phone']);
1135
				unset($a_ppps[$pppid]['provider']);
1136
				unset($a_ppps[$pppid]['ondemand']);
1137
			}
1138
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1139
				unset($a_ppps[$pppid]['localip']);
1140
				unset($a_ppps[$pppid]['subnet']);
1141
				unset($a_ppps[$pppid]['gateway']);
1142
			}
1143
			if ($wancfg['ipaddr'] != 'pppoe') {
1144
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1145
			}
1146
			if ($wancfg['type'] != $_POST['type']) {
1147
				unset($a_ppps[$pppid]['idletimeout']);
1148
			}
1149
		}
1150

    
1151
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1152
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1153

    
1154
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1155
		switch ($_POST['type']) {
1156
			case "staticv4":
1157
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1158
				$wancfg['subnet'] = $_POST['subnet'];
1159
				if ($_POST['gateway'] != "none") {
1160
					$wancfg['gateway'] = $_POST['gateway'];
1161
				}
1162
				break;
1163
			case "dhcp":
1164
				$wancfg['ipaddr'] = "dhcp";
1165
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1166
				$wancfg['alias-address'] = $_POST['alias-address'];
1167
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1168
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1169

    
1170
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1171
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1172
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1173
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1174
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1175
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1176

    
1177
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1178

    
1179
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1180
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1181
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1182
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1183

    
1184
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1185
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1186
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1187

    
1188
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1189
				if ($gateway_item) {
1190
					$a_gateways[] = $gateway_item;
1191
				}
1192
				break;
1193
			case "ppp":
1194
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1195
				$a_ppps[$pppid]['type'] = $_POST['type'];
1196
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1197
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1198
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1199
				if ($_POST['ppp_password'] != DMYPWD) {
1200
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1201
				}
1202
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1203
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1204
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1205
				$wancfg['ipaddr'] = $_POST['type'];
1206
				break;
1207

    
1208
			case "pppoe":
1209
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1210
				$a_ppps[$pppid]['type'] = $_POST['type'];
1211
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1212
				if (isset($_POST['ppp_port'])) {
1213
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1214
				} else {
1215
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1216
				}
1217
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1218
				if ($_POST['pppoe_password'] != DMYPWD) {
1219
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1220
				}
1221
				if (!empty($_POST['provider'])) {
1222
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1223
				} else {
1224
					$a_ppps[$pppid]['provider'] = true;
1225
				}
1226
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1227
				if (!empty($_POST['pppoe_idletimeout'])) {
1228
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1229
				} else {
1230
					unset($a_ppps[$pppid]['idletimeout']);
1231
				}
1232

    
1233
				if (!empty($_POST['pppoe-reset-type'])) {
1234
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1235
				} else {
1236
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1237
				}
1238
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1239
				$wancfg['ipaddr'] = $_POST['type'];
1240
				if ($gateway_item) {
1241
					$a_gateways[] = $gateway_item;
1242
				}
1243

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

    
1312
				if ($_POST['dhcp6withoutra'] == "yes") {
1313
					$wancfg['dhcp6withoutra'] = true;
1314
				}
1315
				if ($_POST['dhcp6norelease'] == "yes") {
1316
					$wancfg['dhcp6norelease'] = true;
1317
				}
1318
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1319
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1320
				}
1321
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1322
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1323
				}
1324
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1325
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1326
				}
1327
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1328
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1329
				}
1330

    
1331
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1332
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1333
				}
1334
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1335
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1336
				}
1337
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1338
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1339
				}
1340
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1341
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1342
				}
1343
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1344
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1345
				}
1346

    
1347
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1348
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1349
				}
1350
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1351
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1352
				}
1353
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1354
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1355
				}
1356
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1357
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1358
				}
1359
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1360
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1361
				}
1362

    
1363
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1364
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1365
				}
1366
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1367
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1368
				}
1369
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1370
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1371
				}
1372
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1373
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1374
				}
1375
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1376
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1377
				}
1378
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1379
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1380
				}
1381
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1382
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1383
				}
1384

    
1385
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1386
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1387
				}
1388
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1389
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1390
				}
1391
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1392
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1393
				}
1394
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1395
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1396
				}
1397
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1398
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1399
				}
1400

    
1401
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1402
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1403
				}
1404
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1405
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1406
				}
1407
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1408
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1409
				}
1410

    
1411
				if ($gateway_item) {
1412
					$a_gateways[] = $gateway_item;
1413
				}
1414
				break;
1415
			case "6rd":
1416
				$wancfg['ipaddrv6'] = "6rd";
1417
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1418
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1419
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1420
				if ($gateway_item) {
1421
					$a_gateways[] = $gateway_item;
1422
				}
1423
				break;
1424
			case "6to4":
1425
				$wancfg['ipaddrv6'] = "6to4";
1426
				break;
1427
			case "track6":
1428
				$wancfg['ipaddrv6'] = "track6";
1429
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1430
				if ($_POST['track6-prefix-id--hex'] === "") {
1431
					$wancfg['track6-prefix-id'] = 0;
1432
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1433
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1434
				} else {
1435
					$wancfg['track6-prefix-id'] = 0;
1436
				}
1437
				break;
1438
			case "none":
1439
				break;
1440
		}
1441
		handle_pppoe_reset($_POST);
1442

    
1443
		if ($_POST['blockpriv'] == "yes") {
1444
			$wancfg['blockpriv'] = true;
1445
		} else {
1446
			unset($wancfg['blockpriv']);
1447
		}
1448
		if ($_POST['blockbogons'] == "yes") {
1449
			$wancfg['blockbogons'] = true;
1450
		} else {
1451
			unset($wancfg['blockbogons']);
1452
		}
1453
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1454
		if (empty($_POST['mtu'])) {
1455
			unset($wancfg['mtu']);
1456
		} else {
1457
			$wancfg['mtu'] = $_POST['mtu'];
1458
		}
1459
		if (empty($_POST['mss'])) {
1460
			unset($wancfg['mss']);
1461
		} else {
1462
			$wancfg['mss'] = $_POST['mss'];
1463
		}
1464
		if (empty($_POST['mediaopt'])) {
1465
			unset($wancfg['media']);
1466
			unset($wancfg['mediaopt']);
1467
		} else {
1468
			$mediaopts = explode(' ', $_POST['mediaopt']);
1469
			if ($mediaopts[0] != '') {
1470
				$wancfg['media'] = $mediaopts[0];
1471
			}
1472
			if ($mediaopts[1] != '') {
1473
				$wancfg['mediaopt'] = $mediaopts[1];
1474
			} else {
1475
				unset($wancfg['mediaopt']);
1476
			}
1477
		}
1478
		if (isset($wancfg['wireless'])) {
1479
			handle_wireless_post();
1480
		}
1481

    
1482
		write_config();
1483

    
1484
		if ($_POST['gatewayip4']) {
1485
			save_gateway($gateway_settings4);
1486
		}
1487

    
1488
		if ($_POST['gatewayip6']) {
1489
			save_gateway($gateway_settings6);
1490
		}
1491

    
1492
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1493
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1494
		} else {
1495
			$toapplylist = array();
1496
		}
1497
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1498
		$toapplylist[$if]['ppps'] = $old_ppps;
1499
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1500

    
1501
		mark_subsystem_dirty('interfaces');
1502

    
1503
		/* regenerate cron settings/crontab file */
1504
		configure_cron();
1505

    
1506
		header("Location: interfaces.php?if={$if}");
1507
		exit;
1508
	}
1509

    
1510
} // end if ($_POST['save'])
1511

    
1512
function handle_wireless_post() {
1513
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1514
	if (!is_array($wancfg['wireless'])) {
1515
		$wancfg['wireless'] = array();
1516
	}
1517
	$wancfg['wireless']['standard'] = $_POST['standard'];
1518
	$wancfg['wireless']['mode'] = $_POST['mode'];
1519
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1520
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1521
	$wancfg['wireless']['channel'] = $_POST['channel'];
1522
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1523
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1524
	$wancfg['wireless']['distance'] = $_POST['distance'];
1525
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1526
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1527
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1528
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1529
		foreach ($wl_countries_attr as $wl_country) {
1530
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1531
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1532
				break;
1533
			}
1534
		}
1535
	}
1536
	if (!is_array($wancfg['wireless']['wpa'])) {
1537
		$wancfg['wireless']['wpa'] = array();
1538
	}
1539
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1540
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1541
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1542
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1543
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1544
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1545
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1546
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1547
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1548
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1549
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1550
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1551
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1552
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1553

    
1554
	if ($_POST['persistcommonwireless'] == "yes") {
1555
		if (!is_array($config['wireless'])) {
1556
			$config['wireless'] = array();
1557
		}
1558
		if (!is_array($config['wireless']['interfaces'])) {
1559
			$config['wireless']['interfaces'] = array();
1560
		}
1561
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1562
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1563
		}
1564
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1565
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1566
	}
1567
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1568
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1569
	} else if (isset($wancfg['wireless']['diversity'])) {
1570
		unset($wancfg['wireless']['diversity']);
1571
	}
1572
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1573
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1574
	} else if (isset($wancfg['wireless']['txantenna'])) {
1575
		unset($wancfg['wireless']['txantenna']);
1576
	}
1577
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1578
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1579
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1580
		unset($wancfg['wireless']['rxantenna']);
1581
	}
1582
	if ($_POST['hidessid_enable'] == "yes") {
1583
		$wancfg['wireless']['hidessid']['enable'] = true;
1584
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1585
		unset($wancfg['wireless']['hidessid']['enable']);
1586
	}
1587
	if ($_POST['mac_acl_enable'] == "yes") {
1588
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1589
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1590
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1591
	}
1592
	if ($_POST['rsn_preauth'] == "yes") {
1593
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1594
	} else {
1595
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1596
	}
1597
	if ($_POST['ieee8021x'] == "yes") {
1598
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1599
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1600
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1601
	}
1602
	if ($_POST['wpa_strict_rekey'] == "yes") {
1603
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1604
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1605
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1606
	}
1607
	if ($_POST['debug_mode'] == "yes") {
1608
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1609
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1610
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1611
	}
1612
	if ($_POST['wpa_enable'] == "yes") {
1613
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1614
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1615
		unset($wancfg['wireless']['wpa']['enable']);
1616
	}
1617

    
1618
	if ($_POST['wme_enable'] == "yes") {
1619
		if (!is_array($wancfg['wireless']['wme'])) {
1620
			$wancfg['wireless']['wme'] = array();
1621
		}
1622
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1623
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1624
		unset($wancfg['wireless']['wme']['enable']);
1625
	}
1626
	if ($_POST['puremode'] == "11g") {
1627
		if (!is_array($wancfg['wireless']['pureg'])) {
1628
			$wancfg['wireless']['pureg'] = array();
1629
		}
1630
		$wancfg['wireless']['pureg']['enable'] = true;
1631
	} else if ($_POST['puremode'] == "11n") {
1632
		if (!is_array($wancfg['wireless']['puren'])) {
1633
			$wancfg['wireless']['puren'] = array();
1634
		}
1635
		$wancfg['wireless']['puren']['enable'] = true;
1636
	} else {
1637
		if (isset($wancfg['wireless']['pureg'])) {
1638
			unset($wancfg['wireless']['pureg']);
1639
		}
1640
		if (isset($wancfg['wireless']['puren'])) {
1641
			unset($wancfg['wireless']['puren']);
1642
		}
1643
	}
1644
	if ($_POST['apbridge_enable'] == "yes") {
1645
		if (!is_array($wancfg['wireless']['apbridge'])) {
1646
			$wancfg['wireless']['apbridge'] = array();
1647
		}
1648
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1649
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1650
		unset($wancfg['wireless']['apbridge']['enable']);
1651
	}
1652
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1653
		if (!is_array($wancfg['wireless']['turbo'])) {
1654
			$wancfg['wireless']['turbo'] = array();
1655
		}
1656
		$wancfg['wireless']['turbo']['enable'] = true;
1657
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1658
		unset($wancfg['wireless']['turbo']['enable']);
1659
	}
1660

    
1661
	interface_sync_wireless_clones($wancfg, true);
1662
}
1663

    
1664
function check_wireless_mode() {
1665
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1666

    
1667
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1668
		return;
1669
	}
1670

    
1671
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1672
		$clone_count = 1;
1673
	} else {
1674
		$clone_count = 0;
1675
	}
1676

    
1677
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1678
		foreach ($config['wireless']['clone'] as $clone) {
1679
			if ($clone['if'] == $wlanbaseif) {
1680
				$clone_count++;
1681
			}
1682
		}
1683
	}
1684

    
1685
	if ($clone_count > 1) {
1686
		$old_wireless_mode = $wancfg['wireless']['mode'];
1687
		$wancfg['wireless']['mode'] = $_POST['mode'];
1688
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1689
			$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']]);
1690
		} else {
1691
			pfSense_interface_destroy("{$wlanif}_");
1692
		}
1693
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1694
	}
1695
}
1696

    
1697
// Find all possible media options for the interface
1698
$mediaopts_list = array();
1699
$intrealname = $config['interfaces'][$if]['if'];
1700
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1701
foreach ($mediaopts as $mediaopt) {
1702
	preg_match("/media (.*)/", $mediaopt, $matches);
1703
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1704
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1705
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1706
	} else {
1707
		// there is only media like "media 1000baseT"
1708
		array_push($mediaopts_list, $matches[1]);
1709
	}
1710
}
1711

    
1712
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1713
$shortcut_section = "interfaces";
1714

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

    
1718
// Get the MAC address
1719
$ip = $_SERVER['REMOTE_ADDR'];
1720
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1721
$mymac = str_replace("\n", "", $mymac);
1722
$defgatewayname4 = $wancfg['descr'] . "GW";
1723
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1724

    
1725
function build_mediaopts_list() {
1726
	global $mediaopts_list;
1727

    
1728
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1729
			 " " =>	 gettext("------- Media Supported by this interface -------")
1730
			];
1731

    
1732
	foreach ($mediaopts_list as $mediaopt) {
1733
		$list[$mediaopt] = $mediaopt;
1734
	}
1735

    
1736
	return($list);
1737
}
1738

    
1739
function build_gateway_list() {
1740
	global $a_gateways, $if;
1741

    
1742
	$list = array("none" => gettext("None"));
1743
	foreach ($a_gateways as $gateway) {
1744
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1745
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1746
		}
1747
	}
1748

    
1749
	return($list);
1750
}
1751

    
1752
function build_gatewayv6_list() {
1753
	global $a_gateways, $if;
1754

    
1755
	$list = array("none" => gettext("None"));
1756
	foreach ($a_gateways as $gateway) {
1757
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1758
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1759
		}
1760
	}
1761

    
1762
	return($list);
1763
}
1764

    
1765
include("head.inc");
1766

    
1767
if ($input_errors) {
1768
	print_input_errors($input_errors);
1769
}
1770

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

    
1777
if ($changes_applied) {
1778
	print_apply_result_box($retval);
1779
}
1780

    
1781
$form = new Form();
1782

    
1783
$section = new Form_Section('General Configuration');
1784

    
1785
$section->addInput(new Form_Checkbox(
1786
	'enable',
1787
	'Enable',
1788
	'Enable interface',
1789
	$pconfig['enable'],
1790
	'yes'
1791
));
1792

    
1793
$section->addInput(new Form_Input(
1794
	'descr',
1795
	'*Description',
1796
	'text',
1797
	$pconfig['descr']
1798
))->setHelp('Enter a description (name) for the interface here.');
1799

    
1800
$section->addInput(new Form_Select(
1801
	'type',
1802
	'IPv4 Configuration Type',
1803
	$pconfig['type'],
1804
	$types4
1805
));
1806

    
1807
$section->addInput(new Form_Select(
1808
	'type6',
1809
	'IPv6 Configuration Type',
1810
	$pconfig['type6'],
1811
	$types6
1812
));
1813

    
1814
$macaddress = new Form_Input(
1815
	'spoofmac',
1816
	'MAC Address',
1817
	'text',
1818
	$pconfig['spoofmac'],
1819
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1820
);
1821

    
1822
$btnmymac = new Form_Button(
1823
	'btnmymac',
1824
	'Copy My MAC',
1825
	null,
1826
	'fa-clone'
1827
	);
1828

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

    
1831
$group = new Form_Group('MAC Address');
1832
$group->add($macaddress);
1833
// $group->add($btnmymac);
1834
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.%s' .
1835
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
1836
$section->add($group);
1837

    
1838
$section->addInput(new Form_Input(
1839
	'mtu',
1840
	'MTU',
1841
	'number',
1842
	$pconfig['mtu']
1843
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1844
			'This is typically 1500 bytes but can vary in some circumstances.');
1845

    
1846
$section->addInput(new Form_Input(
1847
	'mss',
1848
	'MSS',
1849
	'number',
1850
	$pconfig['mss']
1851
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1852
			'header size) will be in effect.');
1853

    
1854
if (count($mediaopts_list) > 0) {
1855
	$section->addInput(new Form_Select(
1856
		'mediaopt',
1857
		'Speed and Duplex',
1858
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1859
		build_mediaopts_list()
1860
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
1861
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
1862
}
1863

    
1864
$form->add($section);
1865

    
1866
$section = new Form_Section('Static IPv4 Configuration');
1867
$section->addClass('staticv4');
1868

    
1869
$section->addInput(new Form_IpAddress(
1870
	'ipaddr',
1871
	'*IPv4 Address',
1872
	$pconfig['ipaddr'],
1873
	'V4'
1874
))->addMask('subnet', $pconfig['subnet'], 32);
1875

    
1876
$group = new Form_Group('IPv4 Upstream gateway');
1877

    
1878
$group->add(new Form_Select(
1879
	'gateway',
1880
	'IPv4 Upstream Gateway',
1881
	$pconfig['gateway'],
1882
	build_gateway_list()
1883
));
1884

    
1885
$group->add(new Form_Button(
1886
	'addgw4',
1887
	'Add a new gateway',
1888
	null,
1889
	'fa-plus'
1890
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
1891

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

    
1896
$section->add($group);
1897

    
1898
$form->add($section);
1899

    
1900
$section = new Form_Section('Static IPv6 Configuration');
1901
$section->addClass('staticv6');
1902

    
1903
$section->addInput(new Form_IpAddress(
1904
	'ipaddrv6',
1905
	'*IPv6 address',
1906
	$pconfig['ipaddrv6'],
1907
	'V6'
1908
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1909

    
1910
$section->addInput(new Form_Checkbox(
1911
	'ipv6usev4iface',
1912
	'Use IPv4 connectivity as parent interface',
1913
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
1914
	$pconfig['ipv6usev4iface']
1915
));
1916

    
1917
$group = new Form_Group('IPv6 Upstream gateway');
1918

    
1919
$group->add(new Form_Select(
1920
	'gatewayv6',
1921
	'IPv6 Upstream Gateway',
1922
	$pconfig['gatewayv6'],
1923
	build_gatewayv6_list()
1924
));
1925

    
1926
$group->add(new Form_Button(
1927
	'addgw6',
1928
	'Add a new gateway',
1929
	null,
1930
	'fa-plus'
1931
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1932

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

    
1936
$section->add($group);
1937
$form->add($section);
1938

    
1939
// Add new gateway modal pop-up for IPv6
1940
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1941

    
1942
$modal->addInput(new Form_Checkbox(
1943
	'defaultgw6',
1944
	'Default',
1945
	'Default gateway',
1946
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
1947
));
1948

    
1949
$modal->addInput(new Form_Input(
1950
	'gatewayname6',
1951
	'Gateway name',
1952
	'text',
1953
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
1954
));
1955

    
1956
$modal->addInput(new Form_IpAddress(
1957
	'gatewayip6',
1958
	'Gateway IPv6',
1959
	$gateway_settings6['gateway'],
1960
	'V6'
1961
));
1962

    
1963
$modal->addInput(new Form_Input(
1964
	'gatewaydescr6',
1965
	'Description',
1966
	'text',
1967
	$gateway_settings6['descr']
1968
));
1969

    
1970
$btnaddgw6 = new Form_Button(
1971
	'add6',
1972
	'Add',
1973
	null,
1974
	'fa-plus'
1975
);
1976

    
1977
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1978

    
1979
$btncnxgw6 = new Form_Button(
1980
	'cnx6',
1981
	'Cancel',
1982
	null,
1983
	'fa-undo'
1984
);
1985

    
1986
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1987

    
1988
$modal->addInput(new Form_StaticText(
1989
	null,
1990
	$btnaddgw6 . $btncnxgw6
1991
));
1992

    
1993
$form->add($modal);
1994

    
1995
// ==== DHCP client configuration =============================
1996

    
1997
$section = new Form_Section('DHCP Client Configuration');
1998
$section->addClass('dhcp');
1999

    
2000
$group = new Form_Group('Options');
2001

    
2002
$group->add(new Form_Checkbox(
2003
	'adv_dhcp_config_advanced',
2004
	null,
2005
	'Advanced Configuration',
2006
	$pconfig['adv_dhcp_config_advanced']
2007
))->setHelp('Use advanced DHCP configuration options.');
2008

    
2009
$group->add(new Form_Checkbox(
2010
	'adv_dhcp_config_file_override',
2011
	null,
2012
	'Configuration Override',
2013
	$pconfig['adv_dhcp_config_file_override']
2014
))->setHelp('Override the configuration from this file.');
2015

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

    
2018
$section->addInput(new Form_Input(
2019
	'dhcphostname',
2020
	'Hostname',
2021
	'text',
2022
	$pconfig['dhcphostname']
2023
))->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).');
2024

    
2025
$section->addInput(new Form_IpAddress(
2026
	'alias-address',
2027
	'Alias IPv4 address',
2028
	$pconfig['alias-address'],
2029
	'V4'
2030
))->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.');
2031

    
2032
$section->addInput(new Form_Input(
2033
	'dhcprejectfrom',
2034
	'Reject leases from',
2035
	'text',
2036
	$pconfig['dhcprejectfrom']
2037
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2038
			'(separate multiple entries with a comma). ' .
2039
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2040

    
2041
$group = new Form_Group('Protocol timing');
2042
$group->addClass('dhcpadvanced');
2043

    
2044
$group->add(new Form_Input(
2045
	'adv_dhcp_pt_timeout',
2046
	null,
2047
	'number',
2048
	$pconfig['adv_dhcp_pt_timeout']
2049
))->setHelp('Timeout');
2050

    
2051
$group->add(new Form_Input(
2052
	'adv_dhcp_pt_retry',
2053
	null,
2054
	'number',
2055
	$pconfig['adv_dhcp_pt_retry']
2056
))->setHelp('Retry');
2057

    
2058
$group->add(new Form_Input(
2059
	'adv_dhcp_pt_select_timeout',
2060
	null,
2061
	'number',
2062
	$pconfig['adv_dhcp_pt_select_timeout'],
2063
	['min' => 0]
2064
))->setHelp('Select timeout');
2065

    
2066
$group->add(new Form_Input(
2067
	'adv_dhcp_pt_reboot',
2068
	null,
2069
	'number',
2070
	$pconfig['adv_dhcp_pt_reboot']
2071
))->setHelp('Reboot');
2072

    
2073
$group->add(new Form_Input(
2074
	'adv_dhcp_pt_backoff_cutoff',
2075
	null,
2076
	'number',
2077
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2078
))->setHelp('Backoff cutoff');
2079

    
2080
$group->add(new Form_Input(
2081
	'adv_dhcp_pt_initial_interval',
2082
	null,
2083
	'number',
2084
	$pconfig['adv_dhcp_pt_initial_interval']
2085
))->setHelp('Initial interval');
2086

    
2087
$section->add($group);
2088

    
2089
$group = new Form_Group('Presets');
2090
$group->addClass('dhcpadvanced');
2091

    
2092
$group->add(new Form_Checkbox(
2093
	'adv_dhcp_pt_values',
2094
	null,
2095
	'FreeBSD default',
2096
	null,
2097
	'DHCP'
2098
))->displayAsRadio();
2099

    
2100
$group->add(new Form_Checkbox(
2101
	'adv_dhcp_pt_values',
2102
	null,
2103
	'Clear',
2104
	null,
2105
	'Clear'
2106
))->displayAsRadio();
2107

    
2108
$group->add(new Form_Checkbox(
2109
	'adv_dhcp_pt_values',
2110
	null,
2111
	'pfSense Default',
2112
	null,
2113
	'pfSense'
2114
))->displayAsRadio();
2115

    
2116
$group->add(new Form_Checkbox(
2117
	'adv_dhcp_pt_values',
2118
	null,
2119
	'Saved Cfg',
2120
	null,
2121
	'SavedCfg'
2122
))->displayAsRadio();
2123

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

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

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

    
2139
$form->add($section);
2140

    
2141
$section = new Form_Section('Lease Requirements and Requests');
2142
$section->addClass('dhcpadvanced');
2143

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

    
2154
$section->addInput(new Form_Input(
2155
	'adv_dhcp_request_options',
2156
	'Request options',
2157
	'text',
2158
	$pconfig['adv_dhcp_request_options']
2159
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2160
			'Some ISPs may require certain options be or not be requested.', '<br />');
2161

    
2162
$section->addInput(new Form_Input(
2163
	'adv_dhcp_required_options',
2164
	'Require options',
2165
	'text',
2166
	$pconfig['adv_dhcp_required_options']
2167
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2168

    
2169
$section->addInput(new Form_Input(
2170
	'adv_dhcp_option_modifiers',
2171
	'Option modifiers',
2172
	'text',
2173
	$pconfig['adv_dhcp_option_modifiers']
2174
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2175
			'modifiers: (default, supersede, prepend, append) %1$s' .
2176
			'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>');
2177

    
2178
$form->add($section);
2179

    
2180
// DHCP6 client config
2181

    
2182
$section = new Form_Section('DHCP6 Client Configuration');
2183
$section->addClass('dhcp6');
2184

    
2185
$group = new Form_Group('Options');
2186

    
2187
$group->add(new Form_Checkbox(
2188
	'adv_dhcp6_config_advanced',
2189
	null,
2190
	'Advanced Configuration',
2191
	$pconfig['adv_dhcp6_config_advanced']
2192
))->setHelp('Use advanced DHCPv6 configuration options.');
2193

    
2194
$group->add(new Form_Checkbox(
2195
	'adv_dhcp6_config_file_override',
2196
	null,
2197
	'Configuration Override',
2198
	$pconfig['adv_dhcp6_config_file_override']
2199
))->setHelp('Override the configuration from this file.');
2200

    
2201
$section->add($group);
2202

    
2203
$section->addInput(new Form_Checkbox(
2204
	'dhcp6usev4iface',
2205
	'Use IPv4 connectivity as parent interface',
2206
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2207
	$pconfig['dhcp6usev4iface']
2208
));
2209

    
2210
$section->addInput(new Form_Checkbox(
2211
	'dhcp6prefixonly',
2212
	'Request only an IPv6 prefix',
2213
	'Only request an IPv6 prefix, do not request an IPv6 address',
2214
	$pconfig['dhcp6prefixonly']
2215
));
2216

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

    
2224
$section->addInput(new Form_Checkbox(
2225
	'dhcp6-ia-pd-send-hint',
2226
	'Send IPv6 prefix hint',
2227
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2228
	$pconfig['dhcp6-ia-pd-send-hint']
2229
));
2230

    
2231
$section->addInput(new Form_Checkbox(
2232
	'dhcp6debug',
2233
	'Debug',
2234
	'Start DHCP6 client in debug mode',
2235
	$pconfig['dhcp6debug']
2236
));
2237
$section->addInput(new Form_Checkbox(
2238
	'dhcp6withoutra',
2239
	'Do not wait for a RA',
2240
	'Required by some ISPs, especially those not using PPPoE',
2241
	$pconfig['dhcp6withoutra']
2242
));
2243
$section->addInput(new Form_Checkbox(
2244
	'dhcp6norelease',
2245
	'Do not allow PD/Address release',
2246
	'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',
2247
	$pconfig['dhcp6norelease']
2248
));
2249
$section->addInput(new Form_Input(
2250
	'adv_dhcp6_config_file_override_path',
2251
	'Configuration File Override',
2252
	'text',
2253
	$pconfig['adv_dhcp6_config_file_override_path']
2254
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2255
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2256
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2257
			'Some ISPs may require certain options be or not be sent.', '<br />');
2258

    
2259
$form->add($section);
2260

    
2261
// DHCP6 client config - Advanced
2262

    
2263
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2264
$section->addClass('dhcp6advanced');
2265

    
2266
$section->addInput(new Form_Checkbox(
2267
	'adv_dhcp6_interface_statement_information_only_enable',
2268
	'Information only',
2269
	'Exchange Information Only',
2270
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2271
	'Selected'
2272
))->setHelp('Only exchange informational configuration parameters with servers.');
2273

    
2274
$section->addInput(new Form_Input(
2275
	'adv_dhcp6_interface_statement_send_options',
2276
	'Send options',
2277
	'text',
2278
	$pconfig['adv_dhcp6_interface_statement_send_options']
2279
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2280
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2281
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2282
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2283

    
2284
$section->addInput(new Form_Input(
2285
	'adv_dhcp6_interface_statement_request_options',
2286
	'Request Options',
2287
	'text',
2288
	$pconfig['adv_dhcp6_interface_statement_request_options']
2289
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2290
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2291

    
2292
$section->addInput(new Form_Input(
2293
	'adv_dhcp6_interface_statement_script',
2294
	'Scripts',
2295
	'text',
2296
	$pconfig['adv_dhcp6_interface_statement_script']
2297
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2298
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2299

    
2300
$group = new Form_Group('Identity Association Statement');
2301

    
2302
$group->add(new Form_Checkbox(
2303
	'adv_dhcp6_id_assoc_statement_address_enable',
2304
	null,
2305
	'Non-Temporary Address Allocation',
2306
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2307
	'Selected'
2308
));
2309

    
2310
$group->add(new Form_Input(
2311
	'adv_dhcp6_id_assoc_statement_address_id',
2312
	null,
2313
	'text',
2314
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2315
))->sethelp('id-assoc na ID');
2316

    
2317
$group->add(new Form_IpAddress(
2318
	'adv_dhcp6_id_assoc_statement_address',
2319
	null,
2320
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2321
	'V6'
2322
))->sethelp('IPv6 address');
2323

    
2324
$group->add(new Form_Input(
2325
	'adv_dhcp6_id_assoc_statement_address_pltime',
2326
	null,
2327
	'text',
2328
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2329
))->sethelp('pltime');
2330

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

    
2338
$section->add($group);
2339

    
2340
// Prefix delegation
2341
$group = new Form_Group('');
2342

    
2343
$group->add(new Form_Checkbox(
2344
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2345
	null,
2346
	'Prefix Delegation ',
2347
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2348
	'Selected'
2349
));
2350

    
2351
$group->add(new Form_Input(
2352
	'adv_dhcp6_id_assoc_statement_prefix_id',
2353
	null,
2354
	'text',
2355
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2356
))->sethelp('id-assoc pd ID');
2357

    
2358
$group->add(new Form_IpAddress(
2359
	'adv_dhcp6_id_assoc_statement_prefix',
2360
	null,
2361
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2362
	'V6'
2363
))->sethelp('IPv6 prefix');
2364

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

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

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

    
2381
$group = new Form_Group('Prefix interface statement');
2382

    
2383
$group->add(new Form_Input(
2384
	'adv_dhcp6_prefix_interface_statement_sla_id',
2385
	null,
2386
	'text',
2387
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2388
))->sethelp('Prefix Interface sla-id');
2389

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

    
2397
$section->add($group);
2398

    
2399
$group = new Form_Group('Select prefix interface');
2400
$section->addInput(new Form_Select(
2401
	'adv_dhcp6_prefix_selected_interface',
2402
	'Prefix Interface',
2403
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2404
	$interfaces
2405
))->setHelp('Select the interface on which to apply the prefix delegation.');
2406

    
2407
$group = new Form_Group('Authentication statement');
2408

    
2409
$group->add(new Form_Input(
2410
	'adv_dhcp6_authentication_statement_authname',
2411
	null,
2412
	'text',
2413
	$pconfig['adv_dhcp6_authentication_statement_authname']
2414
))->sethelp('Authname');
2415

    
2416
$group->add(new Form_Input(
2417
	'adv_dhcp6_authentication_statement_protocol',
2418
	null,
2419
	'text',
2420
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2421
))->sethelp('Protocol');
2422

    
2423
$group->add(new Form_Input(
2424
	'adv_dhcp6_authentication_statement_algorithm',
2425
	null,
2426
	'text',
2427
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2428
))->sethelp('Algorithm');
2429

    
2430
$group->add(new Form_Input(
2431
	'adv_dhcp6_authentication_statement_rdm',
2432
	null,
2433
	'text',
2434
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2435
))->sethelp('RDM');
2436

    
2437
$section->add($group);
2438

    
2439
$group = new Form_Group('Keyinfo statement');
2440

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

    
2448
$group->add(new Form_Input(
2449
	'adv_dhcp6_key_info_statement_realm',
2450
	null,
2451
	'text',
2452
	$pconfig['adv_dhcp6_key_info_statement_realm']
2453
))->sethelp('Realm');
2454

    
2455
$section->add($group);
2456

    
2457
$group = new Form_Group('');
2458

    
2459
$group->add(new Form_Input(
2460
	'adv_dhcp6_key_info_statement_keyid',
2461
	null,
2462
	'text',
2463
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2464
))->sethelp('KeyID');
2465

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

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

    
2480
$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>');
2481

    
2482
$section->add($group);
2483

    
2484
$form->add($section);
2485

    
2486
$section = new Form_Section('6RD Configuration');
2487
$section->addClass('_6rd');
2488

    
2489
$section->addInput(new Form_Input(
2490
	'prefix-6rd',
2491
	'6RD Prefix',
2492
	'text',
2493
	$pconfig['prefix-6rd']
2494
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2495

    
2496
$section->addInput(new Form_Input(
2497
	'gateway-6rd',
2498
	'*6RD Border relay',
2499
	'text',
2500
	$pconfig['gateway-6rd']
2501
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2502

    
2503
$section->addInput(new Form_Select(
2504
	'prefix-6rd-v4plen',
2505
	'6RD IPv4 Prefix length',
2506
	$pconfig['prefix-6rd-v4plen'],
2507
	array_combine(range(0, 32), range(0, 32))
2508
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2509

    
2510
$form->add($section);
2511

    
2512
// Track IPv6 ointerface section
2513
$section = new Form_Section('Track IPv6 Interface');
2514
$section->addClass('track6');
2515

    
2516
function build_ipv6interface_list() {
2517
	global $config, $section;
2518

    
2519
	$list = array('' => '');
2520

    
2521
	$interfaces = get_configured_interface_with_descr(true);
2522
	$dynv6ifs = array();
2523

    
2524
	foreach ($interfaces as $iface => $ifacename) {
2525
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2526
			case "6to4":
2527
			case "6rd":
2528
			case "dhcp6":
2529
				$dynv6ifs[$iface] = array(
2530
					'name' => $ifacename,
2531
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2532
				);
2533
				break;
2534
			default:
2535
				continue;
2536
		}
2537
	}
2538

    
2539
	foreach ($dynv6ifs as $iface => $ifacedata) {
2540
		$list[$iface] = $ifacedata['name'];
2541

    
2542
		$section->addInput(new Form_Input(
2543
			'ipv6-num-prefix-ids-' . $iface,
2544
			null,
2545
			'hidden',
2546
			$ifacedata['ipv6_num_prefix_ids']
2547
		));
2548
	}
2549

    
2550
	return($list);
2551
}
2552

    
2553
$section->addInput(new Form_Select(
2554
	'track6-interface',
2555
	'*IPv6 Interface',
2556
	$pconfig['track6-interface'],
2557
	build_ipv6interface_list()
2558
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2559

    
2560
if ($pconfig['track6-prefix-id'] == "") {
2561
	$pconfig['track6-prefix-id'] = 0;
2562
}
2563

    
2564
$section->addInput(new Form_Input(
2565
	'track6-prefix-id--hex',
2566
	'IPv6 Prefix ID',
2567
	'text',
2568
	sprintf("%x", $pconfig['track6-prefix-id'])
2569
))->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>');
2570

    
2571
$section->addInput(new Form_Input(
2572
	'track6-prefix-id-max',
2573
	null,
2574
	'hidden',
2575
	0
2576
));
2577

    
2578
$form->add($section);
2579

    
2580
/// PPP section
2581

    
2582
$section = new Form_Section('PPP Configuration');
2583
$section->addClass('ppp');
2584

    
2585
$section->addInput(new Form_Select(
2586
	'country',
2587
	'Country',
2588
	$pconfig['country'],
2589
	[]
2590
));
2591

    
2592
$section->addInput(new Form_Select(
2593
	'provider_list',
2594
	'Provider',
2595
	$pconfig['provider_list'],
2596
	[]
2597
));
2598

    
2599
$section->addInput(new Form_Select(
2600
	'providerplan',
2601
	'Plan',
2602
	$pconfig['providerplan'],
2603
	[]
2604
))->setHelp('Select to fill in service provider data.');
2605

    
2606
$section->addInput(new Form_Input(
2607
	'ppp_username',
2608
	'Username',
2609
	'text',
2610
	$pconfig['ppp_username']
2611
));
2612

    
2613
$section->addPassword(new Form_Input(
2614
	'ppp_password',
2615
	'Password',
2616
	'password',
2617
	$pconfig['ppp_password']
2618
));
2619

    
2620
$section->addInput(new Form_Input(
2621
	'phone',
2622
	'*Phone number',
2623
	'text',
2624
	$pconfig['phone']
2625
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2626

    
2627
$section->addInput(new Form_Input(
2628
	'apn',
2629
	'Access Point Name',
2630
	'text',
2631
	$pconfig['apn']
2632
));
2633

    
2634

    
2635
function build_port_list() {
2636
	$list = array("" => "None");
2637

    
2638
	$portlist = glob("/dev/cua*");
2639
	$modems	  = glob("/dev/modem*");
2640
	$portlist = array_merge($portlist, $modems);
2641

    
2642
	foreach ($portlist as $port) {
2643
		if (preg_match("/\.(lock|init)$/", $port)) {
2644
			continue;
2645
		}
2646

    
2647
	$list[trim($port)] = $port;
2648
	}
2649

    
2650
	return($list);
2651
}
2652

    
2653
$section->addInput(new Form_Select(
2654
	'port',
2655
	"*Modem port",
2656
	$pconfig['port'],
2657
	build_port_list()
2658
));
2659

    
2660
$section->addInput(new Form_Button(
2661
	'btnadvppp',
2662
	'Advanced PPP',
2663
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2664
	'fa-cog'
2665
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2666

    
2667
$form->add($section);
2668

    
2669
// PPPoE configuration
2670
$section = new Form_Section('PPPoE Configuration');
2671
$section->addClass('pppoe');
2672

    
2673
$section->addInput(new Form_Input(
2674
	'pppoe_username',
2675
	'*Username',
2676
	'text',
2677
	$pconfig['pppoe_username']
2678
));
2679

    
2680
$section->addPassword(new Form_Input(
2681
	'pppoe_password',
2682
	'*Password',
2683
	'password',
2684
	$pconfig['pppoe_password']
2685
));
2686

    
2687
$section->addInput(new Form_Input(
2688
	'provider',
2689
	'Service name',
2690
	'text',
2691
	$pconfig['provider']
2692
))->setHelp('This field can usually be left empty.');
2693

    
2694
$section->addInput(new Form_Checkbox(
2695
	'pppoe_dialondemand',
2696
	'Dial on demand',
2697
	'Enable Dial-On-Demand mode ',
2698
	$pconfig['pppoe_dialondemand'],
2699
	'enable'
2700
));
2701

    
2702
$section->addInput(new Form_Input(
2703
	'pppoe_idletimeout',
2704
	'Idle timeout',
2705
	'number',
2706
	$pconfig['pppoe_idletimeout'],
2707
	['min' => 0]
2708
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2709
			'An idle timeout of zero disables this feature.');
2710

    
2711
$section->addInput(new Form_Select(
2712
	'pppoe-reset-type',
2713
	'Periodic reset',
2714
	$pconfig['pppoe-reset-type'],
2715
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2716
))->setHelp('Select a reset timing type.');
2717

    
2718
$group = new Form_Group('Custom reset');
2719
$group->addClass('pppoecustom');
2720

    
2721
$group->add(new Form_Input(
2722
	'pppoe_resethour',
2723
	null,
2724
	'number',
2725
	$pconfig['pppoe_resethour'],
2726
	['min' => 0, 'max' => 23]
2727
))->setHelp('Hour (0-23)');
2728

    
2729
$group->add(new Form_Input(
2730
	'pppoe_resetminute',
2731
	null,
2732
	'number',
2733
	$pconfig['pppoe_resetminute'],
2734
	['min' => 0, 'max' => 59]
2735
))->setHelp('Minutes (0-59)');
2736

    
2737
$group->add(new Form_Input(
2738
	'pppoe_resetdate',
2739
	null,
2740
	'text',
2741
	$pconfig['pppoe_resetdate']
2742
))->setHelp('Specific date (mm/dd/yyyy)');
2743

    
2744
$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');
2745

    
2746
$section->add($group);
2747

    
2748
$group = new Form_MultiCheckboxGroup('cron based reset');
2749
$group->addClass('pppoepreset');
2750

    
2751
$group->add(new Form_MultiCheckbox(
2752
	'pppoe_pr_preset_val',
2753
	null,
2754
	'Reset at each month ("0 0 1 * *")',
2755
	$pconfig['pppoe_monthly'],
2756
	'monthly'
2757
))->displayAsRadio();
2758

    
2759
$group->add(new Form_MultiCheckbox(
2760
	'pppoe_pr_preset_val',
2761
	null,
2762
	'Reset at each week ("0 0 * * 0")',
2763
	$pconfig['pppoe_weekly'],
2764
	'weekly'
2765
))->displayAsRadio();
2766

    
2767
$group->add(new Form_MultiCheckbox(
2768
	'pppoe_pr_preset_val',
2769
	null,
2770
	'Reset at each day ("0 0 * * *")',
2771
	$pconfig['pppoe_daily'],
2772
	'daily'
2773
))->displayAsRadio();
2774

    
2775
$group->add(new Form_MultiCheckbox(
2776
	'pppoe_pr_preset_val',
2777
	null,
2778
	'Reset at each hour ("0 * * * *")',
2779
	$pconfig['pppoe_hourly'],
2780
	'hourly'
2781
))->displayAsRadio();
2782

    
2783
$section->add($group);
2784

    
2785
$section->addInput(new Form_Button(
2786
	'btnadvppp',
2787
	'Advanced and MLPPP',
2788
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2789
	'fa-cog'
2790
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2791

    
2792
$form->add($section);
2793

    
2794
// PPTP & L2TP Configuration section
2795
$section = new Form_Section('PPTP/L2TP Configuration');
2796
$section->addClass('pptp');
2797

    
2798
$section->addInput(new Form_Input(
2799
	'pptp_username',
2800
	'*Username',
2801
	'text',
2802
	$pconfig['pptp_username']
2803
));
2804

    
2805
$section->addPassword(new Form_Input(
2806
	'pptp_password',
2807
	'*Password',
2808
	'password',
2809
	$pconfig['pptp_password']
2810
));
2811

    
2812
$section->addInput(new Form_IpAddress(
2813
	'pptp_local0',
2814
	'*Local IP address',
2815
	$pconfig['pptp_localip'][0],
2816
	'V4'
2817
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2818

    
2819
$section->addInput(new Form_IpAddress(
2820
	'pptp_remote0',
2821
	'*Remote IP address',
2822
	$pconfig['pptp_remote'][0],
2823
	'HOSTV4'
2824
));
2825

    
2826
$section->addInput(new Form_Checkbox(
2827
	'pptp_dialondemand',
2828
	'Dial on demand',
2829
	'Enable Dial-On-Demand mode ',
2830
	$pconfig['pptp_dialondemand'],
2831
	'enable'
2832
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2833
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2834

    
2835
$section->addInput(new Form_Input(
2836
	'pptp_idletimeout',
2837
	'Idle timeout (seconds)',
2838
	'number',
2839
	$pconfig['pptp_idletimeout'],
2840
	['min' => 0]
2841
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2842
			'An idle timeout of zero disables this feature.');
2843

    
2844
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2845
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2846
} else {
2847
	$mlppp_text = "";
2848
}
2849

    
2850
$section->addInput(new Form_Button(
2851
	'btnadvppp',
2852
	'Advanced and MLPPP',
2853
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2854
	'fa-cog'
2855
))->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);
2856

    
2857
$form->add($section);
2858

    
2859
// Wireless interface
2860
if (isset($wancfg['wireless'])) {
2861

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

    
2864
	$section->addInput(new Form_Checkbox(
2865
		'persistcommonwireless',
2866
		'Persist common settings',
2867
		'Preserve common wireless configuration through interface deletions and reassignments.',
2868
		$pconfig['persistcommonwireless'],
2869
		'yes'
2870
	));
2871

    
2872
	$mode_list = ['auto' => 'Auto'];
2873

    
2874
	if (is_array($wl_modes)) {
2875
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2876
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2877
		}
2878
	}
2879

    
2880
	if (count($mode_list) == 1) {
2881
		$mode_list[''] = '';
2882
	}
2883

    
2884
	$section->addInput(new Form_Select(
2885
		'standard',
2886
		'Standard',
2887
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2888
		$mode_list
2889
	));
2890

    
2891
	if (isset($wl_modes['11g'])) {
2892
		$section->addInput(new Form_Select(
2893
			'protmode',
2894
			'802.11g OFDM Protection Mode',
2895
			$pconfig['protmode'],
2896
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2897
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2898
	} else {
2899
		$section->addInput(new Form_Input(
2900
			'protmode',
2901
			null,
2902
			'hidden',
2903
			'off'
2904
		));
2905
	}
2906

    
2907
	$mode_list = ['0' => gettext('Auto')];
2908

    
2909
	if (is_array($wl_modes)) {
2910
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2911
			if ($wl_standard == "11g") {
2912
				$wl_standard = "11b/g";
2913
			} else if ($wl_standard == "11ng") {
2914
				$wl_standard = "11b/g/n";
2915
			} else if ($wl_standard == "11na") {
2916
				$wl_standard = "11a/n";
2917
			}
2918

    
2919
			foreach ($wl_channels as $wl_channel) {
2920
				if (isset($wl_chaninfo[$wl_channel])) {
2921
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2922
				} else {
2923
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2924
				}
2925
			}
2926
		}
2927
	}
2928

    
2929
	$section->addInput(new Form_Select(
2930
		'channel',
2931
		'Channel',
2932
		$pconfig['channel'],
2933
		$mode_list
2934
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
2935
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
2936

    
2937
	if (ANTENNAS) {
2938
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2939
			$group = new Form_Group('Antenna Settings');
2940

    
2941
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2942
				$group->add(new Form_Select(
2943
					'diversity',
2944
					null,
2945
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2946
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2947
				))->setHelp('Diversity');
2948
			}
2949

    
2950
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2951
				$group->add(new Form_Select(
2952
					'txantenna',
2953
					null,
2954
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2955
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2956
				))->setHelp('Transmit antenna');
2957
			}
2958

    
2959
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2960
				$group->add(new Form_Select(
2961
					'rxantenna',
2962
					null,
2963
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2964
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2965
				))->setHelp('Receive antenna');
2966
			}
2967

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

    
2970
			$section->add($group);
2971
		}
2972
	}
2973

    
2974
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2975
			$section->addInput(new Form_Input(
2976
				'distance',
2977
				'Distance setting (meters)',
2978
				'test',
2979
				$pconfig['distance']
2980
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2981
	}
2982

    
2983
	$form->add($section);
2984

    
2985
	// Regulatory settings
2986
	$section = new Form_Section('Regulatory Settings');
2987

    
2988
	$domain_list = array("" => 'Default');
2989

    
2990
	if (is_array($wl_regdomains)) {
2991
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2992
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2993
		}
2994
	}
2995

    
2996
	$section->addInput(new Form_Select(
2997
		'regdomain',
2998
		'Regulatory domain',
2999
		$pconfig['regdomain'],
3000
		$domain_list
3001
	))->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');
3002

    
3003
	$country_list = array('' => 'Default');
3004

    
3005
	if (is_array($wl_countries)) {
3006
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3007
			$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']);
3008
		}
3009
	}
3010

    
3011
	$section->addInput(new Form_Select(
3012
		'regcountry',
3013
		'Country',
3014
		$pconfig['regcountry'],
3015
		$country_list
3016
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3017

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

    
3029
	$form->add($section);
3030

    
3031
	$section = new Form_Section('Network-Specific Wireless Configuration');
3032

    
3033
	$section->addInput(new Form_Select(
3034
		'mode',
3035
		'Mode',
3036
		$pconfig['mode'],
3037
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3038
	));
3039

    
3040
	$section->addInput(new Form_Input(
3041
		'ssid',
3042
		'SSID',
3043
		'text',
3044
		$pconfig['ssid']
3045
	));
3046

    
3047
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3048
		$section->addInput(new Form_Select(
3049
			'puremode',
3050
			'Minimum wireless standard',
3051
			$pconfig['puremode'],
3052
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3053
		))->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)');
3054
	} elseif (isset($wl_modes['11g'])) {
3055
		$section->addInput(new Form_Checkbox(
3056
			'puremode',
3057
			'802.11g only',
3058
			null,
3059
			$pconfig['puremode'],
3060
			'11g'
3061
		))->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)');
3062
	}
3063

    
3064
	$section->addInput(new Form_Checkbox(
3065
		'apbridge_enable',
3066
		'Allow intra-BSS communication',
3067
		'Allow packets to pass between wireless clients directly when operating as an access point',
3068
		$pconfig['apbridge_enable'],
3069
		'yes'
3070
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3071

    
3072
	$section->addInput(new Form_Checkbox(
3073
		'wme_enable',
3074
		'Enable WME',
3075
		'Force the card to use WME (wireless QoS)',
3076
		$pconfig['wme_enable'],
3077
		'yes'
3078
	));
3079

    
3080
	$section->addInput(new Form_Checkbox(
3081
		'hidessid_enable',
3082
		'Hide SSID',
3083
		'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.)',
3084
		$pconfig['hidessid_enable'],
3085
		'yes'
3086
	));
3087

    
3088
	$form->add($section);
3089

    
3090
	// WPA Section
3091
	$section = new Form_Section('WPA');
3092

    
3093
	$section->addInput(new Form_Checkbox(
3094
		'wpa_enable',
3095
		'Enable',
3096
		'Enable WPA',
3097
		$pconfig['wpa_enable'],
3098
		'yes'
3099
	));
3100

    
3101
	$section->addInput(new Form_Input(
3102
		'passphrase',
3103
		'WPA Pre-Shared Key',
3104
		'text',
3105
		$pconfig['passphrase']
3106
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3107

    
3108
	$section->addInput(new Form_Select(
3109
		'wpa_mode',
3110
		'WPA mode',
3111
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3112
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3113
	));
3114

    
3115
	$section->addInput(new Form_Select(
3116
		'wpa_key_mgmt',
3117
		'WPA Key Management Mode',
3118
		$pconfig['wpa_key_mgmt'],
3119
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3120
	));
3121

    
3122
	$section->addInput(new Form_Select(
3123
		'wpa_pairwise',
3124
		'WPA Pairwise',
3125
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3126
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3127
	));
3128

    
3129
	$section->addInput(new Form_Input(
3130
		'wpa_group_rekey',
3131
		'Group Key Rotation',
3132
		'number',
3133
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3134
		['min' => '1', 'max' => 9999]
3135
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3136

    
3137
	$section->addInput(new Form_Input(
3138
		'wpa_gmk_rekey',
3139
		'Group Master Key Regeneration',
3140
		'number',
3141
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3142
		['min' => '1', 'max' => 9999]
3143
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3144

    
3145
	$section->addInput(new Form_Checkbox(
3146
		'wpa_strict_rekey',
3147
		'Strict Key Regeneration',
3148
		'Force the AP to rekey whenever a client disassociates',
3149
		$pconfig['wpa_strict_rekey'],
3150
		'yes'
3151
	));
3152

    
3153
	$form->add($section);
3154

    
3155
	$section = new Form_Section('802.1x RADIUS Options');
3156

    
3157
	$section->addInput(new Form_Checkbox(
3158
		'ieee8021x',
3159
		'IEEE802.1X',
3160
		'Enable 802.1X authentication',
3161
		$pconfig['ieee8021x'],
3162
		'yes'
3163
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3164

    
3165
	$group = new Form_Group('Primary 802.1X server');
3166

    
3167
	$group->add(new Form_IpAddress(
3168
		'auth_server_addr',
3169
		'IP Address',
3170
		$pconfig['auth_server_addr']
3171
	))->setHelp('IP address of the RADIUS server');
3172

    
3173
	$group->add(new Form_Input(
3174
		'auth_server_port',
3175
		'Port',
3176
		'number',
3177
		$pconfig['auth_server_port']
3178
	))->setHelp('Server auth port. Default is 1812');
3179

    
3180
	$group->add(new Form_Input(
3181
		'auth_server_shared_secret',
3182
		'Shared Secret',
3183
		'text',
3184
		$pconfig['auth_server_shared_secret']
3185
	))->setHelp('RADIUS Shared secret for this firewall');
3186

    
3187
	$section->add($group);
3188

    
3189
	$group = new Form_Group('Secondary 802.1X server');
3190

    
3191
	$group->add(new Form_IpAddress(
3192
		'auth_server_addr2',
3193
		'IP Address',
3194
		$pconfig['auth_server_addr2']
3195
	))->setHelp('IP address of the RADIUS server');
3196

    
3197
	$group->add(new Form_Input(
3198
		'auth_server_port2',
3199
		'Port',
3200
		'number',
3201
		$pconfig['auth_server_port2']
3202
	))->setHelp('Server auth port. Default is 1812');
3203

    
3204
	$group->add(new Form_Input(
3205
		'auth_server_shared_secret2',
3206
		'Shared Secret',
3207
		'text',
3208
		$pconfig['auth_server_shared_secret2']
3209
	))->setHelp('RADIUS Shared secret for this firewall');
3210

    
3211
	$section->add($group);
3212

    
3213
	$section->addInput(new Form_Checkbox(
3214
		'rsn_preauth',
3215
		'Authentication Roaming Preauth',
3216
		null,
3217
		$pconfig['rsn_preauth'],
3218
		'yes'
3219
	));
3220

    
3221
	$form->add($section);
3222
}
3223

    
3224
$section = new Form_Section('Reserved Networks');
3225

    
3226
$section->addInput(new Form_Checkbox(
3227
	'blockpriv',
3228
	'Block private networks and loopback addresses',
3229
	'',
3230
	$pconfig['blockpriv'],
3231
	'yes'
3232
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3233
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3234
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3235

    
3236
$section->addInput(new Form_Checkbox(
3237
	'blockbogons',
3238
	'Block bogon networks',
3239
	'',
3240
	$pconfig['blockbogons'],
3241
	'yes'
3242
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3243
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3244
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.', '<br />');
3245

    
3246
$form->add($section);
3247

    
3248
$form->addGlobal(new Form_Input(
3249
	'if',
3250
	null,
3251
	'hidden',
3252
	$if
3253
));
3254

    
3255
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3256
	$form->addGlobal(new Form_Input(
3257
		'ppp_port',
3258
		null,
3259
		'hidden',
3260
		$pconfig['port']
3261
	));
3262
}
3263

    
3264
$form->addGlobal(new Form_Input(
3265
	'ptpid',
3266
	null,
3267
	'hidden',
3268
	$pconfig['ptpid']
3269
));
3270

    
3271

    
3272
// Add new gateway modal pop-up
3273
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3274

    
3275
$modal->addInput(new Form_Checkbox(
3276
	'defaultgw4',
3277
	'Default',
3278
	'Default gateway',
3279
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3280
));
3281

    
3282
$modal->addInput(new Form_Input(
3283
	'gatewayname4',
3284
	'Gateway name',
3285
	'text',
3286
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3287
));
3288

    
3289
$modal->addInput(new Form_IpAddress(
3290
	'gatewayip4',
3291
	'Gateway IPv4',
3292
	$gateway_settings4['gateway'],
3293
	'V4'
3294
));
3295

    
3296
$modal->addInput(new Form_Input(
3297
	'gatewaydescr4',
3298
	'Description',
3299
	'text',
3300
	$gateway_settings4['descr']
3301
));
3302

    
3303
$btnaddgw4 = new Form_Button(
3304
	'add4',
3305
	'Add',
3306
	null,
3307
	'fa-plus'
3308
);
3309

    
3310
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3311

    
3312
$btncnxgw4 = new Form_Button(
3313
	'cnx4',
3314
	'Cancel',
3315
	null,
3316
	'fa-undo'
3317
);
3318

    
3319
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3320

    
3321
$modal->addInput(new Form_StaticText(
3322
	null,
3323
	$btnaddgw4 . $btncnxgw4
3324
));
3325

    
3326
$form->add($modal);
3327

    
3328
print($form);
3329
?>
3330

    
3331
<script type="text/javascript">
3332
//<![CDATA[
3333
events.push(function() {
3334
	function updateType(t) {
3335

    
3336
		switch (t) {
3337
			case "none": {
3338
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3339
				break;
3340
			}
3341
			case "staticv4": {
3342
				$('.dhcpadvanced, .none, .dhcp').hide();
3343
				$('.pppoe, .pptp, .ppp').hide();
3344
				break;
3345
			}
3346
			case "dhcp": {
3347
				$('.dhcpadvanced, .none').hide();
3348
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3349
										//			about the staticv4 class
3350
				$('.pppoe, .pptp, .ppp').hide();
3351
				break;
3352
			}
3353
			case "ppp": {
3354
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3355
				country_list();
3356
				break;
3357
			}
3358
			case "pppoe": {
3359
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3360
				break;
3361
			}
3362
			case "l2tp":
3363
			case "pptp": {
3364
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3365
				$('.pptp').show();
3366
				break;
3367
			}
3368
		}
3369

    
3370
		if (t != "l2tp" && t != "pptp") {
3371
			$('.'+t).show();
3372
		}
3373
	}
3374

    
3375
	function updateTypeSix(t) {
3376
		if (!isNaN(t[0])) {
3377
			t = '_' + t;
3378
		}
3379

    
3380
		switch (t) {
3381
			case "none": {
3382
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3383
				break;
3384
			}
3385
			case "staticv6": {
3386
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3387
				break;
3388
			}
3389
			case "slaac": {
3390
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3391
				break;
3392
			}
3393
			case "dhcp6": {
3394
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3395
				break;
3396
			}
3397
			case "_6rd": {
3398
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3399
				break;
3400
			}
3401
			case "_6to4": {
3402
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3403
				break;
3404
			}
3405
			case "track6": {
3406
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3407
				update_track6_prefix();
3408
				break;
3409
			}
3410
		}
3411

    
3412
		if (t != "l2tp" && t != "pptp") {
3413
			$('.'+t).show();
3414
		}
3415
	}
3416

    
3417
	function show_reset_settings(reset_type) {
3418
		if (reset_type == 'preset') {
3419
			$('.pppoepreset').show();
3420
			$('.pppoecustom').hide();
3421
		} else if (reset_type == 'custom') {
3422
			$('.pppoecustom').show();
3423
			$('.pppoepreset').hide();
3424
		} else {
3425
			$('.pppoecustom').hide();
3426
			$('.pppoepreset').hide();
3427
		}
3428
	}
3429

    
3430
	function update_track6_prefix() {
3431
		var iface = $("#track6-interface").val();
3432
		if (iface == null) {
3433
			return;
3434
		}
3435

    
3436
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3437
		if (track6_prefix_ids == null) {
3438
			return;
3439
		}
3440

    
3441
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3442
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3443
	}
3444

    
3445
	function addOption_v4() {
3446
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3447
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3448
	}
3449

    
3450
	function addOption_v6() {
3451
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3452
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3453
	}
3454

    
3455
	function addSelectboxOption(selectbox, text, value) {
3456
		var optn = document.createElement("OPTION");
3457
		optn.text = text;
3458
		optn.value = value;
3459
		selectbox.append(optn);
3460
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3461
	}
3462

    
3463
	function country_list() {
3464
		$('#country').children().remove();
3465
		$('#provider_list').children().remove();
3466
		$('#providerplan').children().remove();
3467
		$.ajax("getserviceproviders.php",{
3468
			success: function(response) {
3469

    
3470
				var responseTextArr = response.split("\n");
3471
				responseTextArr.sort();
3472

    
3473
				responseTextArr.forEach( function(value) {
3474
					country = value.split(":");
3475
					$('#country').append($('<option>', {
3476
						value: country[1],
3477
						text : country[0]
3478
					}));
3479
				});
3480
			}
3481
		});
3482
	}
3483

    
3484
	function providers_list() {
3485
		$('#provider_list').children().remove();
3486
		$('#providerplan').children().remove();
3487
		$.ajax("getserviceproviders.php",{
3488
			type: 'post',
3489
			data: {country : $('#country').val()},
3490
			success: function(response) {
3491
				var responseTextArr = response.split("\n");
3492
				responseTextArr.sort();
3493
				responseTextArr.forEach( function(value) {
3494
					$('#provider_list').append($('<option>', {
3495
							value: value,
3496
							text : value
3497
					}));
3498
				});
3499
			}
3500
		});
3501
	}
3502

    
3503
	function providerplan_list() {
3504
		$('#providerplan').children().remove();
3505
		$.ajax("getserviceproviders.php",{
3506
			type: 'post',
3507
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3508
			success: function(response) {
3509
				var responseTextArr = response.split("\n");
3510
				responseTextArr.sort();
3511

    
3512
				$('#providerplan').append($('<option>', {
3513
					value: '',
3514
					text : ''
3515
				}));
3516

    
3517
				responseTextArr.forEach( function(value) {
3518
					if (value != "") {
3519
						providerplan = value.split(":");
3520

    
3521
						$('#providerplan').append($('<option>', {
3522
							value: providerplan[1],
3523
							text : providerplan[0] + " - " + providerplan[1]
3524
						}));
3525
					}
3526
				});
3527
			}
3528
		});
3529
	}
3530

    
3531
	function prefill_provider() {
3532
		$.ajax("getserviceproviders.php",{
3533
			type: 'post',
3534
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3535
			success: function(data, textStatus, response) {
3536
				var xmldoc = response.responseXML;
3537
				var provider = xmldoc.getElementsByTagName('connection')[0];
3538
				$('#ppp_username').val('');
3539
				$('#ppp_password').val('');
3540
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3541
					$('#phone').val('#777');
3542
					$('#apn').val('');
3543
				} else {
3544
					$('#phone').val('*99#');
3545
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3546
				}
3547
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3548
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3549
				$('#ppp_username').val(ppp_username);
3550
				$('#ppp_password').val(ppp_password);
3551
			}
3552
		});
3553
	}
3554

    
3555
	function show_dhcp6adv() {
3556
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3557
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3558

    
3559
		hideCheckbox('dhcp6usev4iface', ovr);
3560
		hideCheckbox('dhcp6prefixonly', ovr);
3561
		hideInput('dhcp6-ia-pd-len', ovr);
3562
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3563
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3564

    
3565
		hideClass('dhcp6advanced', !adv || ovr);
3566
	}
3567

    
3568
	function setDHCPoptions() {
3569
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3570
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3571

    
3572
		if (ovr) {
3573
			hideInput('dhcphostname', true);
3574
			hideIpAddress('alias-address', true);
3575
			hideInput('dhcprejectfrom', true);
3576
			hideInput('adv_dhcp_config_file_override_path', false);
3577
			hideClass('dhcpadvanced', true);
3578
		} else {
3579
			hideInput('dhcphostname', false);
3580
			hideIpAddress('alias-address', false);
3581
			hideInput('dhcprejectfrom', false);
3582
			hideInput('adv_dhcp_config_file_override_path', true);
3583
			hideClass('dhcpadvanced', !adv);
3584
		}
3585
	}
3586

    
3587
	// DHCP preset actions
3588
	// Set presets from value of radio buttons
3589
	function setPresets(val) {
3590
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3591
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3592
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3593
		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']);?>");
3594
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3595
	}
3596

    
3597
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3598
		$('#adv_dhcp_pt_timeout').val(timeout);
3599
		$('#adv_dhcp_pt_retry').val(retry);
3600
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3601
		$('#adv_dhcp_pt_reboot').val(reboot);
3602
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3603
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3604
	}
3605

    
3606
	function setPPPoEDialOnDemandItems() {
3607
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3608
	}
3609

    
3610
	function setPPTPDialOnDemandItems() {
3611
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3612
	}
3613

    
3614
	// ---------- On initial page load ------------------------------------------------------------
3615

    
3616
	updateType($('#type').val());
3617
	updateTypeSix($('#type6').val());
3618
	show_reset_settings($('#pppoe-reset-type').val());
3619
	hideClass('dhcp6advanced', true);
3620
	hideClass('dhcpadvanced', true);
3621
	show_dhcp6adv();
3622
	setDHCPoptions();
3623
	setPPPoEDialOnDemandItems();
3624
	setPPTPDialOnDemandItems();
3625

    
3626
	// Set preset buttons on page load
3627
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3628
	if (sv == "") {
3629
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3630
	} else {
3631
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3632
	}
3633

    
3634
	// Set preset from value
3635
	setPresets(sv);
3636

    
3637
	// If the user wants to add a gateway, then add that to the gateway selection
3638
	if ($("#gatewayip4").val() != '') {
3639
		addOption_v4();
3640
	}
3641
	if ($("#gatewayip6").val() != '') {
3642
		addOption_v6();
3643
	}
3644

    
3645
	// ---------- Click checkbox handlers ---------------------------------------------------------
3646

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

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

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

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

    
3663
	$("#add4").click(function() {
3664
		addOption_v4();
3665
		$("#newgateway4").modal('hide');
3666
	});
3667

    
3668
	$("#cnx4").click(function() {
3669
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
3670
		$("#gatewayip4").val('');
3671
		$("#gatewaydescr4").val('');
3672
		$("#defaultgw4").prop("checked", false);
3673
		$("#newgateway4").modal('hide');
3674
	});
3675

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

    
3681
	$("#cnx6").click(function() {
3682
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
3683
		$("#gatewayip6").val('');
3684
		$("#gatewaydescr6").val('');
3685
		$("#defaultgw6").prop("checked", false);
3686
		$("#newgateway6").modal('hide');
3687
	});
3688

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

    
3693
	$('#provider_list').on('change', function() {
3694
		providerplan_list();
3695
	});
3696

    
3697
	$('#providerplan').on('change', function() {
3698
		prefill_provider();
3699
	});
3700

    
3701
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3702
		setDHCPoptions();
3703
	});
3704

    
3705
	$('#adv_dhcp6_config_advanced').click(function () {
3706
		show_dhcp6adv();
3707
	});
3708

    
3709
	$('#adv_dhcp6_config_file_override').click(function () {
3710
		show_dhcp6adv();
3711
	});
3712

    
3713
	// On click . .
3714
	$('#pppoe_dialondemand').click(function () {
3715
		setPPPoEDialOnDemandItems();
3716
	});
3717

    
3718
	$('#pptp_dialondemand').click(function () {
3719
		setPPTPDialOnDemandItems();
3720
	});
3721

    
3722
	$('[name=adv_dhcp_pt_values]').click(function () {
3723
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3724
	});
3725

    
3726
	$('#pppoe_resetdate').datepicker();
3727

    
3728
});
3729
//]]>
3730
</script>
3731

    
3732
<?php include("foot.inc");
(71-71/230)