Project

General

Profile

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

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

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

    
44
define("ANTENNAS", false);
45

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
407
}
408

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

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

    
444
		/* sync filter configuration */
445
		setup_gateways_monitor();
446

    
447
		clear_subsystem_dirty('interfaces');
448

    
449
		filter_configure();
450

    
451
		enable_rrd_graphing();
452

    
453
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
454
			clear_subsystem_dirty('staticroutes');
455
		}
456
	}
457
	@unlink("{$g['tmp_path']}/.interfaces.apply");
458
	header("Location: interfaces.php?if={$if}");
459
	exit;
460
} else if ($_POST) {
461

    
462
	unset($input_errors);
463
	$pconfig = $_POST;
464

    
465
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
466
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
467
	} else {
468
		$pconfig['track6-prefix-id'] = 0;
469
	}
470

    
471
	/* filter out spaces from descriptions */
472
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
473

    
474
	/* okay first of all, cause we are just hiding the PPPoE HTML
475
	 * fields related to PPPoE resets, we are going to unset $_POST
476
	 * vars, if the reset feature should not be used. Otherwise the
477
	 * data validation procedure below, may trigger a false error
478
	 * message.
479
	 */
480
	if (empty($_POST['pppoe-reset-type'])) {
481
		unset($_POST['pppoe_pr_type']);
482
		unset($_POST['pppoe_resethour']);
483
		unset($_POST['pppoe_resetminute']);
484
		unset($_POST['pppoe_resetdate']);
485
		unset($_POST['pppoe_pr_preset_val']);
486
	}
487
	/* description unique? */
488
	foreach ($ifdescrs as $ifent => $ifdescr) {
489
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
490
			$input_errors[] = gettext("An interface with the specified description already exists.");
491
			break;
492
		}
493
	}
494

    
495
	/* Is the description already used as an alias name? */
496
	if (is_array($config['aliases']['alias'])) {
497
		foreach ($config['aliases']['alias'] as $alias) {
498
			if ($alias['name'] == $_POST['descr']) {
499
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
500
			}
501
		}
502
	}
503

    
504
	/* Is the description already used as an interface group name? */
505
	if (is_array($config['ifgroups']['ifgroupentry'])) {
506
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
507
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
508
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
509
			}
510
		}
511
	}
512

    
513
	if (is_numeric($_POST['descr'])) {
514
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
515
	}
516
	/* input validation */
517
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
518
		$input_errors[] = gettext("The DHCP Server is active on this interface and it can be used only with a static IP configuration. Please disable the DHCP Server service on this interface first, then change the interface configuration.");
519
	}
520
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
521
		$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.");
522
	}
523

    
524
	switch (strtolower($_POST['type'])) {
525
		case "staticv4":
526
			$reqdfields = explode(" ", "ipaddr subnet gateway");
527
			$reqdfieldsn = array(gettext("IPv4 address"), gettext("Subnet bit count"), gettext("Gateway"));
528
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
529
			break;
530
		case "none":
531
			if (is_array($config['virtualip']['vip'])) {
532
				foreach ($config['virtualip']['vip'] as $vip) {
533
					if (is_ipaddrv4($vip['subnet']) && $vip['interface'] == $if) {
534
						$input_errors[] = gettext("This interface is referenced by IPv4 VIPs. Please delete those before setting the interface to 'none' configuration.");
535
					}
536
				}
537
			}
538
			break;
539
		case "ppp":
540
			$reqdfields = explode(" ", "port phone");
541
			$reqdfieldsn = array(gettext("Modem Port"), gettext("Phone Number"));
542
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
543
			break;
544
		case "pppoe":
545
			if ($_POST['pppoe_dialondemand']) {
546
				$reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
547
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"), gettext("Dial on demand"), gettext("Idle timeout value"));
548
			} else {
549
				$reqdfields = explode(" ", "pppoe_username pppoe_password");
550
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"));
551
			}
552
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
553
			break;
554
		case "pptp":
555
			if ($_POST['pptp_dialondemand']) {
556
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0 pptp_dialondemand pptp_idletimeout");
557
				$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"));
558
			} else {
559
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0");
560
				$reqdfieldsn = array(gettext("PPTP username"), gettext("PPTP password"), gettext("PPTP local IP address"), gettext("PPTP subnet"), gettext("PPTP remote IP address"));
561
			}
562
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
563
			break;
564
		case "l2tp":
565
			if ($_POST['pptp_dialondemand']) {
566
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0 pptp_dialondemand pptp_idletimeout");
567
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"), gettext("Dial on demand"), gettext("Idle timeout value"));
568
			} else {
569
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0");
570
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"));
571
			}
572
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
573
			break;
574
	}
575
	switch (strtolower($_POST['type6'])) {
576
		case "staticv6":
577
			$reqdfields = explode(" ", "ipaddrv6 subnetv6 gatewayv6");
578
			$reqdfieldsn = array(gettext("IPv6 address"), gettext("Subnet bit count"), gettext("Gateway"));
579
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
580
			break;
581
		case "none":
582
			if (is_array($config['virtualip']['vip'])) {
583
				foreach ($config['virtualip']['vip'] as $vip) {
584
					if (is_ipaddrv6($vip['subnet']) && $vip['interface'] == $if) {
585
						$input_errors[] = gettext("This interface is referenced by IPv6 VIPs. Please delete those before setting the interface to 'none' configuration.");
586
					}
587
				}
588
			}
589
			break;
590
		case "dhcp6":
591
			if (in_array($wancfg['ipaddrv6'], array())) {
592
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
593
			}
594
			if ($_POST['dhcp6-ia-pd-send-hint'] && strtolower($_POST['dhcp6-ia-pd-len']) == 'none') {
595
				$input_errors[] = gettext('DHCPv6 Prefix Delegation size must be provided when Send IPv6 prefix hint flag is checked');
596
			}
597
			break;
598
		case "6rd":
599
			foreach ($ifdescrs as $ifent => $ifdescr) {
600
				if ($if != $ifent && ($config[interfaces][$ifent]['ipaddrv6'] == $_POST['type6'])) {
601
					if ($config[interfaces][$ifent]['prefix-6rd'] == $_POST['prefix-6rd']) {
602
						$input_errors[] = gettext("Only one interface can be configured within a single 6rd prefix.");
603
						break;
604
					}
605
				}
606
			}
607
			if (!is_ipaddrv4($_POST['gateway-6rd'])) {
608
				$input_errors[] = gettext("6RD Border Gateway must be an IPv4 address.");
609
			}
610
			if (in_array($wancfg['ipaddrv6'], array())) {
611
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
612
			}
613
			break;
614
		case "6to4":
615
			foreach ($ifdescrs as $ifent => $ifdescr) {
616
				if ($if != $ifent && ($config[interfaces][$ifent]['ipaddrv6'] == $_POST['type6'])) {
617
					$input_errors[] = sprintf(gettext("Only one interface can be configured as 6to4."), $_POST['type6']);
618
					break;
619
				}
620
			}
621
			if (in_array($wancfg['ipaddrv6'], array())) {
622
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
623
			}
624
			break;
625
		case "track6":
626
			/* needs to check if $track6-prefix-id is used on another interface */
627
			if (in_array($wancfg['ipaddrv6'], array())) {
628
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
629
			}
630

    
631
			if (empty($_POST['track6-interface'])) {
632
				$input_errors[] = gettext("A valid interface to track must be selected.");
633
			}
634

    
635
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
636
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
637
			} else {
638
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
639
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
640
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
641
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
642
				} else {
643
					foreach ($ifdescrs as $ifent => $ifdescr) {
644
						if ($if == $ifent) {
645
							continue;
646
						}
647
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
648
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
649
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
650
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
651
						}
652
					}
653
				}
654
			}
655
			break;
656
	}
657

    
658
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
659
	$staticroutes = get_staticroutes(true);
660
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
661
	if ($_POST['ipaddr']) {
662
		if (!is_ipaddrv4($_POST['ipaddr'])) {
663
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
664
		} else {
665
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
666
			if (count($where_ipaddr_configured)) {
667
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
668
				foreach ($where_ipaddr_configured as $subnet_conflict) {
669
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
670
				}
671
				$input_errors[] = $subnet_conflict_text;
672
			}
673

    
674
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
675
			if ($_POST['subnet'] < 31) {
676
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
677
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
678
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
679
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
680
				}
681
			}
682

    
683
			foreach ($staticroutes as $route_subnet) {
684
				list($network, $subnet) = explode("/", $route_subnet);
685
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
686
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
687
					break;
688
				}
689
				unset($network, $subnet);
690
			}
691
		}
692
	}
693
	if ($_POST['ipaddrv6']) {
694
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
695
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
696
		} else {
697
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
698
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
699
			}
700
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
701
			if (count($where_ipaddr_configured)) {
702
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
703
				foreach ($where_ipaddr_configured as $subnet_conflict) {
704
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
705
				}
706
				$input_errors[] = $subnet_conflict_text;
707
			}
708

    
709
			foreach ($staticroutes as $route_subnet) {
710
				list($network, $subnet) = explode("/", $route_subnet);
711
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
712
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
713
					break;
714
				}
715
				unset($network, $subnet);
716
			}
717
		}
718
	}
719
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
720
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
721
	}
722
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
723
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
724
	}
725
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
726
		$input_errors[] = gettext("A valid alias IP address must be specified.");
727
	}
728
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
729
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
730
	}
731
	if ($_POST['dhcprejectfrom'] && !is_ipaddrv4($_POST['dhcprejectfrom'])) {
732
		$input_errors[] = gettext("A valid alias IP address must be specified to reject DHCP Leases from.");
733
	}
734
	if (($_POST['gateway'] != "none") || ($_POST['gatewayv6'] != "none")) {
735
		$match = false;
736
		foreach ($a_gateways as $gateway) {
737
			if (in_array($_POST['gateway'], $gateway)) {
738
				$match = true;
739
			}
740
		}
741
		foreach ($a_gateways as $gateway) {
742
			if (in_array($_POST['gatewayv6'], $gateway)) {
743
				$match = true;
744
			}
745
		}
746
		if (!$match) {
747
			$input_errors[] = gettext("A valid gateway must be specified.");
748
		}
749
	}
750
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
751
		$input_errors[] = gettext("The service name contains invalid characters.");
752
	}
753
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
754
		$input_errors[] = gettext("The idle timeout value must be an integer.");
755
	}
756
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
757
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
758
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
759
	}
760
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
761
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
762
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
763
	}
764
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
765
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
766
	}
767
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
768
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
769
	}
770
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
771
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
772
	}
773
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
774
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
775
	}
776
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
777
		$input_errors[] = gettext("The idle timeout value must be an integer.");
778
	}
779
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
780
		$input_errors[] = gettext("A valid MAC address must be specified.");
781
	}
782
	if ($_POST['mtu']) {
783
		if (!is_numericint($_POST['mtu'])) {
784
			$input_errors[] = "MTU must be an integer.";
785
		}
786
		if (substr($wancfg['if'], 0, 3) == 'gif') {
787
			$min_mtu = 1280;
788
			$max_mtu = 8192;
789
		} else {
790
			$min_mtu = 576;
791
			$max_mtu = 9000;
792
		}
793

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

    
798
		unset($min_mtu, $max_mtu);
799

    
800
		if (stristr($wancfg['if'], "_vlan")) {
801
			$realhwif_array = get_parent_interface($wancfg['if']);
802
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
803
			$parent_realhwif = $realhwif_array[0];
804
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
805
			$mtu = 0;
806
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu']))
807
				$mtu = intval($config['interfaces'][$parent_if]['mtu']);
808
			if ($mtu == 0)
809
				$mtu = get_interface_mtu($parent_realhwif);
810
			if ($_POST['mtu'] > $mtu)
811
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
812
		} else {
813
			foreach ($config['interfaces'] as $idx => $ifdata) {
814
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
815
					continue;
816
				}
817

    
818
				$realhwif_array = get_parent_interface($ifdata['if']);
819
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
820
				$parent_realhwif = $realhwif_array[0];
821

    
822
				if ($parent_realhwif != $wancfg['if']) {
823
					continue;
824
				}
825

    
826
				if (isset($ifdata['mtu']) && $ifdata['mtu'] > $_POST['mtu']) {
827
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), $ifdata['descr']);
828
				}
829
			}
830
		}
831
	}
832
	if ($_POST['mss'] != '') {
833
		if (!is_numericint($_POST['mss']) || ($_POST['mss'] < 576 || $_POST['mss'] > 65535)) {
834
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
835
		}
836
	}
837
	/* Wireless interface? */
838
	if (isset($wancfg['wireless'])) {
839
		$reqdfields = array("mode");
840
		$reqdfieldsn = array(gettext("Mode"));
841
		if ($_POST['mode'] == 'hostap') {
842
			$reqdfields[] = "ssid";
843
			$reqdfieldsn[] = gettext("SSID");
844
			if (isset($_POST['channel']) && $_POST['channel'] == "0") {
845
				// auto channel with hostap is broken, prevent this for now.
846
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
847
			}
848
		}
849
		if (stristr($_POST['standard'], '11n')) {
850
			if (!($_POST['wme_enable'])) {
851
				$input_errors[] = gettext("802.11n standards require enabling WME.");
852
			}
853
		}
854
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
855
		check_wireless_mode();
856
		if (isset($_POST['wpa_group_rekey']) && (!is_numericint($_POST['wpa_group_rekey']) || $_POST['wpa_group_rekey'] < 1 || $_POST['wpa_group_rekey'] > 9999)) {
857
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
858
		}
859
		if (isset($_POST['wpa_gmk_rekey']) && (!is_numericint($_POST['wpa_gmk_rekey']) || $_POST['wpa_gmk_rekey'] < 1 || $_POST['wpa_gmk_rekey'] > 9999)) {
860
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
861
		}
862
		if (isset($_POST['wpa_group_rekey']) && isset($_POST['wpa_gmk_rekey'])) {
863
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
864
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
865
			}
866
		}
867
		if (!empty($_POST['auth_server_addr'])) {
868
			if (!is_domain($_POST['auth_server_addr']) && !is_ipaddr($_POST['auth_server_addr'])) {
869
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
870
			}
871
		}
872
		if (!empty($_POST['auth_server_addr2'])) {
873
			if (!is_domain($_POST['auth_server_addr2']) && !is_ipaddr($_POST['auth_server_addr2'])) {
874
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
875
			}
876
		}
877
		if (!empty($_POST['auth_server_port'])) {
878
			if (!is_port($_POST['auth_server_port'])) {
879
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
880
			}
881
		}
882
		if (!empty($_POST['auth_server_port2'])) {
883
			if (!is_port($_POST['auth_server_port2'])) {
884
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
885
			}
886
		}
887
		if (isset($_POST['channel']) && !is_numericint($_POST['channel'])) {
888
			if (!is_numericint($_POST['channel'])) {
889
				$input_errors[] = gettext("Invalid channel specified.");
890
			} else {
891
				if ($_POST['channel'] > 255 || $_POST['channel'] < 0) {
892
					$input_errors[] = gettext("Channel must be between 0-255.");
893
				}
894
			}
895
		}
896
		if (!empty($_POST['distance']) && !is_numericint($_POST['distance'])) {
897
			$input_errors[] = gettext("Distance must be an integer.");
898
		}
899
		if (isset($_POST['standard']) && (stristr($_POST['standard'], '11na') || stristr($_POST['standard'], '11a'))) {
900
			if ($_POST['channel'] != 0 && $_POST['channel'] < 15) {
901
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
902
			}
903
		}
904
		if (isset($_POST['standard']) && ($_POST['standard'] == "11b" || $_POST['standard'] == "11g")) {
905
			if ($_POST['channel'] > 14) {
906
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
907
			}
908
		}
909
		if (!empty($_POST['protmode']) && !in_array($_POST['protmode'], array("off", "cts", "rtscts"))) {
910
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
911
		}
912

    
913
		if ($_POST['passphrase']) {
914
			$passlen = strlen($_POST['passphrase']);
915
			if ($passlen < 8 || $passlen > 63) {
916
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
917
			}
918
		}
919

    
920
		if ($_POST['wpa_enable'] == "yes") {
921
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
922
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
923
			}
924
		}
925
	}
926

    
927
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
928
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
929
	}
930

    
931
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
932
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
933
	}
934

    
935
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
936
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
937
	}
938

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

    
946
		if ($wancfg['ipaddr'] != $_POST['type']) {
947
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
948
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
949
				unset($a_ppps[$pppid]);
950
			} else if ($wancfg['ipaddr'] == "dhcp") {
951
				kill_dhclient_process($wancfg['if']);
952
			}
953
			if ($wancfg['ipaddrv6'] == "dhcp6") {
954
				$pid = find_dhcp6c_process($wancfg['if']);
955
				if ($pid) {
956
					posix_kill($pid, SIGTERM);
957
				}
958
			}
959
		}
960
		$ppp = array();
961
		if ($wancfg['ipaddr'] != "ppp") {
962
			unset($wancfg['ipaddr']);
963
		}
964
		if ($wancfg['ipaddrv6'] != "ppp") {
965
			unset($wancfg['ipaddrv6']);
966
		}
967
		unset($wancfg['subnet']);
968
		unset($wancfg['gateway']);
969
		unset($wancfg['subnetv6']);
970
		unset($wancfg['gatewayv6']);
971
		unset($wancfg['dhcphostname']);
972
		unset($wancfg['dhcprejectfrom']);
973
		unset($wancfg['dhcp6-duid']);
974
		unset($wancfg['dhcp6-ia-pd-len']);
975
		unset($wancfg['dhcp6-ia-pd-send-hint']);
976
		unset($wancfg['dhcp6prefixonly']);
977
		unset($wancfg['dhcp6usev4iface']);
978
		unset($wancfg['dhcp6debug']);
979
		unset($wancfg['track6-interface']);
980
		unset($wancfg['track6-prefix-id']);
981
		unset($wancfg['dhcp6withoutra']);
982
		unset($wancfg['prefix-6rd']);
983
		unset($wancfg['prefix-6rd-v4plen']);
984
		unset($wancfg['gateway-6rd']);
985

    
986
		unset($wancfg['adv_dhcp_pt_timeout']);
987
		unset($wancfg['adv_dhcp_pt_retry']);
988
		unset($wancfg['adv_dhcp_pt_select_timeout']);
989
		unset($wancfg['adv_dhcp_pt_reboot']);
990
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
991
		unset($wancfg['adv_dhcp_pt_initial_interval']);
992

    
993
		unset($wancfg['adv_dhcp_pt_values']);
994

    
995
		unset($wancfg['adv_dhcp_send_options']);
996
		unset($wancfg['adv_dhcp_request_options']);
997
		unset($wancfg['adv_dhcp_required_options']);
998
		unset($wancfg['adv_dhcp_option_modifiers']);
999

    
1000
		unset($wancfg['adv_dhcp_config_advanced']);
1001
		unset($wancfg['adv_dhcp_config_file_override']);
1002
		unset($wancfg['adv_dhcp_config_file_override_path']);
1003

    
1004
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1005
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1006
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1007
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1008

    
1009
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1010
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1011
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1012
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1013
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1014

    
1015
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1016
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1017
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1018
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1019
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1020

    
1021
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1022
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1023

    
1024
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1025
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1026
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1027
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1028

    
1029
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1030
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1031
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1032
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1033
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1034

    
1035
		unset($wancfg['adv_dhcp6_config_advanced']);
1036
		unset($wancfg['adv_dhcp6_config_file_override']);
1037
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1038

    
1039
		unset($wancfg['pppoe_password']);
1040
		unset($wancfg['pptp_username']);
1041
		unset($wancfg['pptp_password']);
1042
		unset($wancfg['provider']);
1043
		unset($wancfg['ondemand']);
1044
		unset($wancfg['timeout']);
1045
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1046
			unset($wancfg['pppoe']['pppoe-reset-type']);
1047
		}
1048
		unset($wancfg['local']);
1049

    
1050
		unset($wancfg['remote']);
1051
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1052
			if ($wancfg['ipaddr'] != 'ppp') {
1053
				unset($a_ppps[$pppid]['apn']);
1054
				unset($a_ppps[$pppid]['phone']);
1055
				unset($a_ppps[$pppid]['provider']);
1056
				unset($a_ppps[$pppid]['ondemand']);
1057
			}
1058
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1059
				unset($a_ppps[$pppid]['localip']);
1060
				unset($a_ppps[$pppid]['subnet']);
1061
				unset($a_ppps[$pppid]['gateway']);
1062
			}
1063
			if ($wancfg['ipaddr'] != 'pppoe') {
1064
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1065
			}
1066
			if ($wancfg['type'] != $_POST['type']) {
1067
				unset($a_ppps[$pppid]['idletimeout']);
1068
			}
1069
		}
1070

    
1071
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1072
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1073

    
1074
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1075
		switch ($_POST['type']) {
1076
			case "staticv4":
1077
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1078
				$wancfg['subnet'] = $_POST['subnet'];
1079
				if ($_POST['gateway'] != "none") {
1080
					$wancfg['gateway'] = $_POST['gateway'];
1081
				}
1082
				break;
1083
			case "dhcp":
1084
				$wancfg['ipaddr'] = "dhcp";
1085
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1086
				$wancfg['alias-address'] = $_POST['alias-address'];
1087
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1088
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1089

    
1090
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1091
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1092
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1093
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1094
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1095
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1096

    
1097
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1098

    
1099
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1100
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1101
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1102
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1103

    
1104
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1105
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1106
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1107

    
1108
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1109
				if ($gateway_item) {
1110
					$a_gateways[] = $gateway_item;
1111
				}
1112
				break;
1113
			case "ppp":
1114
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1115
				$a_ppps[$pppid]['type'] = $_POST['type'];
1116
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1117
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1118
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1119
				if ($_POST['ppp_password'] != DMYPWD) {
1120
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1121
				}
1122
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1123
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1124
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1125
				$wancfg['ipaddr'] = $_POST['type'];
1126
				break;
1127

    
1128
			case "pppoe":
1129
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1130
				$a_ppps[$pppid]['type'] = $_POST['type'];
1131
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1132
				if (isset($_POST['ppp_port'])) {
1133
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1134
				} else {
1135
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1136
				}
1137
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1138
				if ($_POST['pppoe_password'] != DMYPWD) {
1139
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1140
				}
1141
				if (!empty($_POST['provider'])) {
1142
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1143
				} else {
1144
					$a_ppps[$pppid]['provider'] = true;
1145
				}
1146
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1147
				if (!empty($_POST['pppoe_idletimeout'])) {
1148
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1149
				} else {
1150
					unset($a_ppps[$pppid]['idletimeout']);
1151
				}
1152

    
1153
				if (!empty($_POST['pppoe-reset-type'])) {
1154
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1155
				} else {
1156
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1157
				}
1158
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1159
				$wancfg['ipaddr'] = $_POST['type'];
1160
				if ($gateway_item) {
1161
					$a_gateways[] = $gateway_item;
1162
				}
1163

    
1164
				break;
1165
			case "pptp":
1166
			case "l2tp":
1167
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1168
				$a_ppps[$pppid]['type'] = $_POST['type'];
1169
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1170
				if (isset($_POST['ppp_port'])) {
1171
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1172
				} else {
1173
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1174
				}
1175
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1176
				if ($_POST['pptp_password'] != DMYPWD) {
1177
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1178
				}
1179
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1180
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1181
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1182
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1183
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1184
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1185
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1186
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1187
				if (!empty($_POST['pptp_idletimeout'])) {
1188
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1189
				} else {
1190
					unset($a_ppps[$pppid]['idletimeout']);
1191
				}
1192
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1193
				$wancfg['ipaddr'] = $_POST['type'];
1194
				if ($gateway_item) {
1195
					$a_gateways[] = $gateway_item;
1196
				}
1197
				break;
1198
			case "none":
1199
				break;
1200
		}
1201
		switch ($_POST['type6']) {
1202
			case "staticv6":
1203
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1204
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1205
				if ($_POST['gatewayv6'] != "none") {
1206
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1207
				}
1208
				break;
1209
			case "slaac":
1210
				$wancfg['ipaddrv6'] = "slaac";
1211
				break;
1212
			case "dhcp6":
1213
				$wancfg['ipaddrv6'] = "dhcp6";
1214
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1215
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1216
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1217
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1218
				}
1219
				if ($_POST['dhcp6prefixonly'] == "yes") {
1220
					$wancfg['dhcp6prefixonly'] = true;
1221
				}
1222
				if ($_POST['dhcp6usev4iface'] == "yes") {
1223
					$wancfg['dhcp6usev4iface'] = true;
1224
				}
1225
				if ($_POST['dhcp6debug'] == "yes") {
1226
					$wancfg['dhcp6debug'] = true;
1227
				}
1228

    
1229
				if ($_POST['dhcp6withoutra'] == "yes") {
1230
					$wancfg['dhcp6withoutra'] = true;
1231
				}
1232
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1233
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1234
				}
1235
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1236
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1237
				}
1238
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1239
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1240
				}
1241
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1242
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1243
				}
1244

    
1245
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1246
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1247
				}
1248
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1249
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1250
				}
1251
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1252
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1253
				}
1254
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1255
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1256
				}
1257
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1258
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1259
				}
1260

    
1261
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1262
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1263
				}
1264
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1265
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1266
				}
1267
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1268
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1269
				}
1270
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1271
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1272
				}
1273
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1274
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1275
				}
1276

    
1277
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1278
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1279
				}
1280
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1281
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1282
				}
1283

    
1284
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1285
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1286
				}
1287
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1288
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1289
				}
1290
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1291
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1292
				}
1293
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1294
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1295
				}
1296

    
1297
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1298
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1299
				}
1300
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1301
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1304
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1307
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1310
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1311
				}
1312

    
1313
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1314
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1317
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1320
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1321
				}
1322

    
1323
				if ($gateway_item) {
1324
					$a_gateways[] = $gateway_item;
1325
				}
1326
				break;
1327
			case "6rd":
1328
				$wancfg['ipaddrv6'] = "6rd";
1329
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1330
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1331
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1332
				if ($gateway_item) {
1333
					$a_gateways[] = $gateway_item;
1334
				}
1335
				break;
1336
			case "6to4":
1337
				$wancfg['ipaddrv6'] = "6to4";
1338
				break;
1339
			case "track6":
1340
				$wancfg['ipaddrv6'] = "track6";
1341
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1342
				if ($_POST['track6-prefix-id--hex'] === "") {
1343
					$wancfg['track6-prefix-id'] = 0;
1344
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1345
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1346
				} else {
1347
					$wancfg['track6-prefix-id'] = 0;
1348
				}
1349
				break;
1350
			case "none":
1351
				break;
1352
		}
1353
		handle_pppoe_reset($_POST);
1354

    
1355
		if ($_POST['blockpriv'] == "yes") {
1356
			$wancfg['blockpriv'] = true;
1357
		} else {
1358
			unset($wancfg['blockpriv']);
1359
		}
1360
		if ($_POST['blockbogons'] == "yes") {
1361
			$wancfg['blockbogons'] = true;
1362
		} else {
1363
			unset($wancfg['blockbogons']);
1364
		}
1365
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1366
		if (empty($_POST['mtu'])) {
1367
			unset($wancfg['mtu']);
1368
		} else {
1369
			$wancfg['mtu'] = $_POST['mtu'];
1370
		}
1371
		if (empty($_POST['mss'])) {
1372
			unset($wancfg['mss']);
1373
		} else {
1374
			$wancfg['mss'] = $_POST['mss'];
1375
		}
1376
		if (empty($_POST['mediaopt'])) {
1377
			unset($wancfg['media']);
1378
			unset($wancfg['mediaopt']);
1379
		} else {
1380
			$mediaopts = explode(' ', $_POST['mediaopt']);
1381
			if ($mediaopts[0] != '') {
1382
				$wancfg['media'] = $mediaopts[0];
1383
			}
1384
			if ($mediaopts[1] != '') {
1385
				$wancfg['mediaopt'] = $mediaopts[1];
1386
			} else {
1387
				unset($wancfg['mediaopt']);
1388
			}
1389
		}
1390
		if (isset($wancfg['wireless'])) {
1391
			handle_wireless_post();
1392
		}
1393

    
1394
		write_config();
1395

    
1396
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1397
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1398
		} else {
1399
			$toapplylist = array();
1400
		}
1401
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1402
		$toapplylist[$if]['ppps'] = $old_ppps;
1403
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1404

    
1405
		mark_subsystem_dirty('interfaces');
1406

    
1407
		/* regenerate cron settings/crontab file */
1408
		configure_cron();
1409

    
1410
		header("Location: interfaces.php?if={$if}");
1411
		exit;
1412
	}
1413

    
1414
} // end if ($_POST)
1415

    
1416
function handle_wireless_post() {
1417
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1418
	if (!is_array($wancfg['wireless'])) {
1419
		$wancfg['wireless'] = array();
1420
	}
1421
	$wancfg['wireless']['standard'] = $_POST['standard'];
1422
	$wancfg['wireless']['mode'] = $_POST['mode'];
1423
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1424
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1425
	$wancfg['wireless']['channel'] = $_POST['channel'];
1426
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1427
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1428
	$wancfg['wireless']['distance'] = $_POST['distance'];
1429
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1430
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1431
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1432
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1433
		foreach ($wl_countries_attr as $wl_country) {
1434
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1435
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1436
				break;
1437
			}
1438
		}
1439
	}
1440
	if (!is_array($wancfg['wireless']['wpa'])) {
1441
		$wancfg['wireless']['wpa'] = array();
1442
	}
1443
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1444
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1445
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1446
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1447
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1448
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1449
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1450
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1451
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1452
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1453
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1454
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1455
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1456
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1457

    
1458
	if ($_POST['persistcommonwireless'] == "yes") {
1459
		if (!is_array($config['wireless'])) {
1460
			$config['wireless'] = array();
1461
		}
1462
		if (!is_array($config['wireless']['interfaces'])) {
1463
			$config['wireless']['interfaces'] = array();
1464
		}
1465
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1466
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1467
		}
1468
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1469
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1470
	}
1471
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1472
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1473
	} else if (isset($wancfg['wireless']['diversity'])) {
1474
		unset($wancfg['wireless']['diversity']);
1475
	}
1476
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1477
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1478
	} else if (isset($wancfg['wireless']['txantenna'])) {
1479
		unset($wancfg['wireless']['txantenna']);
1480
	}
1481
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1482
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1483
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1484
		unset($wancfg['wireless']['rxantenna']);
1485
	}
1486
	if ($_POST['hidessid_enable'] == "yes") {
1487
		$wancfg['wireless']['hidessid']['enable'] = true;
1488
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1489
		unset($wancfg['wireless']['hidessid']['enable']);
1490
	}
1491
	if ($_POST['mac_acl_enable'] == "yes") {
1492
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1493
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1494
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1495
	}
1496
	if ($_POST['rsn_preauth'] == "yes") {
1497
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1498
	} else {
1499
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1500
	}
1501
	if ($_POST['ieee8021x'] == "yes") {
1502
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1503
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1504
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1505
	}
1506
	if ($_POST['wpa_strict_rekey'] == "yes") {
1507
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1508
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1509
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1510
	}
1511
	if ($_POST['debug_mode'] == "yes") {
1512
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1513
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1514
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1515
	}
1516
	if ($_POST['wpa_enable'] == "yes") {
1517
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1518
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1519
		unset($wancfg['wireless']['wpa']['enable']);
1520
	}
1521

    
1522
	if ($_POST['wme_enable'] == "yes") {
1523
		if (!is_array($wancfg['wireless']['wme'])) {
1524
			$wancfg['wireless']['wme'] = array();
1525
		}
1526
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1527
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1528
		unset($wancfg['wireless']['wme']['enable']);
1529
	}
1530
	if ($_POST['puremode'] == "11g") {
1531
		if (!is_array($wancfg['wireless']['pureg'])) {
1532
			$wancfg['wireless']['pureg'] = array();
1533
		}
1534
		$wancfg['wireless']['pureg']['enable'] = true;
1535
	} else if ($_POST['puremode'] == "11n") {
1536
		if (!is_array($wancfg['wireless']['puren'])) {
1537
			$wancfg['wireless']['puren'] = array();
1538
		}
1539
		$wancfg['wireless']['puren']['enable'] = true;
1540
	} else {
1541
		if (isset($wancfg['wireless']['pureg'])) {
1542
			unset($wancfg['wireless']['pureg']);
1543
		}
1544
		if (isset($wancfg['wireless']['puren'])) {
1545
			unset($wancfg['wireless']['puren']);
1546
		}
1547
	}
1548
	if ($_POST['apbridge_enable'] == "yes") {
1549
		if (!is_array($wancfg['wireless']['apbridge'])) {
1550
			$wancfg['wireless']['apbridge'] = array();
1551
		}
1552
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1553
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1554
		unset($wancfg['wireless']['apbridge']['enable']);
1555
	}
1556
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1557
		if (!is_array($wancfg['wireless']['turbo'])) {
1558
			$wancfg['wireless']['turbo'] = array();
1559
		}
1560
		$wancfg['wireless']['turbo']['enable'] = true;
1561
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1562
		unset($wancfg['wireless']['turbo']['enable']);
1563
	}
1564

    
1565
	interface_sync_wireless_clones($wancfg, true);
1566
}
1567

    
1568
function check_wireless_mode() {
1569
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1570

    
1571
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1572
		return;
1573
	}
1574

    
1575
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1576
		$clone_count = 1;
1577
	} else {
1578
		$clone_count = 0;
1579
	}
1580

    
1581
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1582
		foreach ($config['wireless']['clone'] as $clone) {
1583
			if ($clone['if'] == $wlanbaseif) {
1584
				$clone_count++;
1585
			}
1586
		}
1587
	}
1588

    
1589
	if ($clone_count > 1) {
1590
		$old_wireless_mode = $wancfg['wireless']['mode'];
1591
		$wancfg['wireless']['mode'] = $_POST['mode'];
1592
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1593
			$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']]);
1594
		} else {
1595
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1596
		}
1597
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1598
	}
1599
}
1600

    
1601
// Find all possible media options for the interface
1602
$mediaopts_list = array();
1603
$intrealname = $config['interfaces'][$if]['if'];
1604
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1605
foreach ($mediaopts as $mediaopt) {
1606
	preg_match("/media (.*)/", $mediaopt, $matches);
1607
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1608
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1609
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1610
	} else {
1611
		// there is only media like "media 1000baseT"
1612
		array_push($mediaopts_list, $matches[1]);
1613
	}
1614
}
1615

    
1616
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1617
$shortcut_section = "interfaces";
1618

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

    
1622
// Get the MAC address
1623
$ip = $_SERVER['REMOTE_ADDR'];
1624
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1625
$mymac = str_replace("\n", "", $mymac);
1626

    
1627
function build_mediaopts_list() {
1628
	global $mediaopts_list;
1629

    
1630
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1631
			 " " =>	 gettext("------- Media Supported by this interface -------")
1632
			];
1633

    
1634
	foreach ($mediaopts_list as $mediaopt) {
1635
		$list[$mediaopt] = $mediaopt;
1636
	}
1637

    
1638
	return($list);
1639
}
1640

    
1641
function build_gateway_list() {
1642
	global $a_gateways, $if;
1643

    
1644
	$list = array("none" => gettext("None"));
1645
	foreach ($a_gateways as $gateway) {
1646
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1647
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1648
		}
1649
	}
1650

    
1651
	return($list);
1652
}
1653

    
1654
function build_gatewayv6_list() {
1655
	global $a_gateways, $if;
1656

    
1657
	$list = array("none" => gettext("None"));
1658
	foreach ($a_gateways as $gateway) {
1659
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1660
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1661
		}
1662
	}
1663

    
1664
	return($list);
1665
}
1666

    
1667
include("head.inc");
1668

    
1669
if ($input_errors) {
1670
	print_input_errors($input_errors);
1671
}
1672

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

    
1679
if ($savemsg) {
1680
	print_info_box($savemsg, 'success');
1681
}
1682

    
1683

    
1684
$form = new Form();
1685

    
1686
$section = new Form_Section('General Configuration');
1687

    
1688
$section->addInput(new Form_Checkbox(
1689
	'enable',
1690
	'Enable',
1691
	'Enable interface',
1692
	$pconfig['enable'],
1693
	'yes'
1694
));
1695

    
1696
$section->addInput(new Form_Input(
1697
	'descr',
1698
	'Description',
1699
	'text',
1700
	$pconfig['descr']
1701
))->setHelp('Enter a description (name) for the interface here.');
1702

    
1703
$section->addInput(new Form_Select(
1704
	'type',
1705
	'IPv4 Configuration Type',
1706
	$pconfig['type'],
1707
	$types4
1708
));
1709

    
1710
$section->addInput(new Form_Select(
1711
	'type6',
1712
	'IPv6 Configuration Type',
1713
	$pconfig['type6'],
1714
	$types6
1715
));
1716

    
1717
$macaddress = new Form_Input(
1718
	'spoofmac',
1719
	'MAC Address',
1720
	'text',
1721
	$pconfig['spoofmac'],
1722
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1723
);
1724

    
1725
$btnmymac = new Form_Button(
1726
	'btnmymac',
1727
	'Copy My MAC',
1728
	null,
1729
	'fa-clone'
1730
	);
1731

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

    
1734
$group = new Form_Group('MAC Address');
1735
$group->add($macaddress);
1736
// $group->add($btnmymac);
1737
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1738
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.');
1739
$section->add($group);
1740

    
1741
$section->addInput(new Form_Input(
1742
	'mtu',
1743
	'MTU',
1744
	'number',
1745
	$pconfig['mtu']
1746
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
1747
			'This is typically 1500 bytes but can vary in some circumstances.');
1748

    
1749
$section->addInput(new Form_Input(
1750
	'mss',
1751
	'MSS',
1752
	'number',
1753
	$pconfig['mss']
1754
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1755
			'header size) will be in effect.');
1756

    
1757
if (count($mediaopts_list) > 0) {
1758
	$section->addInput(new Form_Select(
1759
		'mediaopt',
1760
		'Speed and Duplex',
1761
		rtrim($config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt']),
1762
		build_mediaopts_list()
1763
	))->setHelp('Explicitly set speed and duplex mode for this interface.' . '<br />' .
1764
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1765
}
1766

    
1767
$form->add($section);
1768

    
1769
$section = new Form_Section('Static IPv4 Configuration');
1770
$section->addClass('staticv4');
1771

    
1772
$section->addInput(new Form_IpAddress(
1773
	'ipaddr',
1774
	'IPv4 Address',
1775
	$pconfig['ipaddr']
1776
))->addMask('subnet', $pconfig['subnet'], 32);
1777

    
1778
$group = new Form_Group('IPv4 Upstream gateway');
1779

    
1780
$group->add(new Form_Select(
1781
	'gateway',
1782
	'IPv4 Upstream Gateway',
1783
	$pconfig['gateway'],
1784
	build_gateway_list()
1785
));
1786

    
1787
$group->add(new Form_Button(
1788
	'addgw',
1789
	'Add a new gateway',
1790
	null,
1791
	'fa-plus'
1792
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1793

    
1794
$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.' . '<br />' .
1795
				'On local area network interfaces the upstream gateway should be "none". ' .
1796
				gettext('Gateways can be managed by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>.');
1797

    
1798
$section->add($group);
1799

    
1800
$form->add($section);
1801

    
1802
$section = new Form_Section('Static IPv6 Configuration');
1803
$section->addClass('staticv6');
1804

    
1805
$section->addInput(new Form_IpAddress(
1806
	'ipaddrv6',
1807
	'IPv6 address',
1808
	$pconfig['ipaddrv6']
1809
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1810

    
1811
$group = new Form_Group('IPv6 Upstream gateway');
1812

    
1813
$group->add(new Form_Select(
1814
	'gatewayv6',
1815
	'IPv6 Upstream Gateway',
1816
	$pconfig['gatewayv6'],
1817
	build_gatewayv6_list()
1818
));
1819

    
1820
$group->add(new Form_Button(
1821
	'addgw6',
1822
	'Add a new gateway',
1823
	null,
1824
	'fa-plus'
1825
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1826

    
1827
$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.' . '<br />' .
1828
				'On local LANs the upstream gateway should be "none". ');
1829

    
1830
$section->add($group);
1831
$form->add($section);
1832

    
1833
// Add new gateway modal pop-up for IPv6
1834
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
1835

    
1836
$modal->addInput(new Form_Checkbox(
1837
	'defaultgw6',
1838
	'Default',
1839
	'Default gateway',
1840
	($if == "wan" || $if == "WAN")
1841
));
1842

    
1843
$modal->addInput(new Form_Input(
1844
	'name6',
1845
	'Gateway name',
1846
	'text',
1847
	$wancfg['descr'] . "GWv6"
1848
));
1849

    
1850
$modal->addInput(new Form_IpAddress(
1851
	'gatewayip6',
1852
	'Gateway IPv6',
1853
	null
1854
));
1855

    
1856
$modal->addInput(new Form_Input(
1857
	'gatewaydescr6',
1858
	'Description',
1859
	'text'
1860
));
1861

    
1862
$btnaddgw6 = new Form_Button(
1863
	'add6',
1864
	'Add',
1865
	null,
1866
	'fa-plus'
1867
);
1868

    
1869
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
1870

    
1871
$btncnxgw6 = new Form_Button(
1872
	'cnx6',
1873
	'Cancel',
1874
	null,
1875
	'fa-undo'
1876
);
1877

    
1878
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
1879

    
1880
$modal->addInput(new Form_StaticText(
1881
	null,
1882
	$btnaddgw6 . $btncnxgw6
1883
));
1884

    
1885
$form->add($modal);
1886

    
1887
// ==== DHCP client configuration =============================
1888

    
1889
$section = new Form_Section('DHCP Client Configuration');
1890
$section->addClass('dhcp');
1891

    
1892
$group = new Form_Group('Options');
1893

    
1894
$group->add(new Form_Checkbox(
1895
	'adv_dhcp_config_advanced',
1896
	null,
1897
	'Advanced Configuration',
1898
	$pconfig['adv_dhcp_config_advanced']
1899
))->setHelp('Use advanced DHCP configuration options.');
1900

    
1901
$group->add(new Form_Checkbox(
1902
	'adv_dhcp_config_file_override',
1903
	null,
1904
	'Configuration Override',
1905
	$pconfig['adv_dhcp_config_file_override']
1906
))->setHelp('Override the configuration from this file.');
1907

    
1908
$section->add($group);
1909

    
1910
$section->addInput(new Form_Input(
1911
	'dhcphostname',
1912
	'Hostname',
1913
	'text',
1914
	$pconfig['dhcphostname']
1915
))->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).');
1916

    
1917
$section->addInput(new Form_IpAddress(
1918
	'alias-address',
1919
	'Alias IPv4 address',
1920
	$pconfig['alias-address']
1921
))->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.');
1922

    
1923
$section->addInput(new Form_Input(
1924
	'dhcprejectfrom',
1925
	'Reject leases from',
1926
	'text',
1927
	$pconfig['dhcprejectfrom']
1928
))->setHelp('To make the DHCP client reject leases from an undesirable DHCP server, place the IP address of the DHCP server here. ' .
1929
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
1930

    
1931
$group = new Form_Group('Protocol timing');
1932
$group->addClass('dhcpadvanced');
1933

    
1934
$group->add(new Form_Input(
1935
	'adv_dhcp_pt_timeout',
1936
	null,
1937
	'number',
1938
	$pconfig['adv_dhcp_pt_timeout']
1939
))->setHelp('Timeout');
1940

    
1941
$group->add(new Form_Input(
1942
	'adv_dhcp_pt_retry',
1943
	null,
1944
	'number',
1945
	$pconfig['adv_dhcp_pt_retry']
1946
))->setHelp('Retry');
1947

    
1948
$group->add(new Form_Input(
1949
	'adv_dhcp_pt_select_timeout',
1950
	null,
1951
	'number',
1952
	$pconfig['adv_dhcp_pt_select_timeout'],
1953
	['min' => 0]
1954
))->setHelp('Select timeout');
1955

    
1956
$group->add(new Form_Input(
1957
	'adv_dhcp_pt_reboot',
1958
	null,
1959
	'number',
1960
	$pconfig['adv_dhcp_pt_reboot']
1961
))->setHelp('Reboot');
1962

    
1963
$group->add(new Form_Input(
1964
	'adv_dhcp_pt_backoff_cutoff',
1965
	null,
1966
	'number',
1967
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1968
))->setHelp('Backoff cutoff');
1969

    
1970
$group->add(new Form_Input(
1971
	'adv_dhcp_pt_initial_interval',
1972
	null,
1973
	'number',
1974
	$pconfig['adv_dhcp_pt_initial_interval']
1975
))->setHelp('Initial interval');
1976

    
1977
$section->add($group);
1978

    
1979
$group = new Form_Group('Presets');
1980
$group->addClass('dhcpadvanced');
1981

    
1982
$group->add(new Form_Checkbox(
1983
	'adv_dhcp_pt_values',
1984
	null,
1985
	'FreeBSD default',
1986
	null,
1987
	'DHCP'
1988
))->displayAsRadio();
1989

    
1990
$group->add(new Form_Checkbox(
1991
	'adv_dhcp_pt_values',
1992
	null,
1993
	'Clear',
1994
	null,
1995
	'Clear'
1996
))->displayAsRadio();
1997

    
1998
$group->add(new Form_Checkbox(
1999
	'adv_dhcp_pt_values',
2000
	null,
2001
	'pfSense Default',
2002
	null,
2003
	'pfSense'
2004
))->displayAsRadio();
2005

    
2006
$group->add(new Form_Checkbox(
2007
	'adv_dhcp_pt_values',
2008
	null,
2009
	'Saved Cfg',
2010
	null,
2011
	'SavedCfg'
2012
))->displayAsRadio();
2013

    
2014
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.' . '<br />' .
2015
				'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#PROTOCOL_TIMING">' . 'See here more information' . '</a>');
2016

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

    
2019
$section->addInput(new Form_Input(
2020
	'adv_dhcp_config_file_override_path',
2021
	'Configuration File Override',
2022
	'text',
2023
	$pconfig['adv_dhcp_config_file_override_path']
2024
))->setWidth(9)->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2025
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2026
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2027
			'Some ISPs may require certain options be or not be sent.');
2028

    
2029
$form->add($section);
2030

    
2031
$section = new Form_Section('Lease Requirements and Requests');
2032
$section->addClass('dhcpadvanced');
2033

    
2034
$section->addInput(new Form_Input(
2035
	'adv_dhcp_send_options',
2036
	'Send options',
2037
	'text',
2038
	$pconfig['adv_dhcp_send_options']
2039
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2040
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2041
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2042
			'Some ISPs may require certain options be or not be sent.');
2043

    
2044
$section->addInput(new Form_Input(
2045
	'adv_dhcp_request_options',
2046
	'Request options',
2047
	'text',
2048
	$pconfig['adv_dhcp_request_options']
2049
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2050
			'Some ISPs may require certain options be or not be requested.');
2051

    
2052
$section->addInput(new Form_Input(
2053
	'adv_dhcp_required_options',
2054
	'Require options',
2055
	'text',
2056
	$pconfig['adv_dhcp_required_options']
2057
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2058

    
2059
$section->addInput(new Form_Input(
2060
	'adv_dhcp_option_modifiers',
2061
	'Option modifiers',
2062
	'text',
2063
	$pconfig['adv_dhcp_option_modifiers']
2064
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2065
			'modifiers: (default, supersede, prepend, append)' . '<br />' .
2066
			'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">' . 'See here more information' . '</a>');
2067

    
2068
$form->add($section);
2069

    
2070
// DHCP6 client config
2071

    
2072
$section = new Form_Section('DHCP6 Client Configuration');
2073
$section->addClass('dhcp6');
2074

    
2075
$group = new Form_Group('Options');
2076

    
2077
$group->add(new Form_Checkbox(
2078
	'adv_dhcp6_config_advanced',
2079
	null,
2080
	'Advanced Configuration',
2081
	$pconfig['adv_dhcp6_config_advanced']
2082
))->setHelp('Use advanced DHCPv6 configuration options.');
2083

    
2084
$group->add(new Form_Checkbox(
2085
	'adv_dhcp6_config_file_override',
2086
	null,
2087
	'Configuration Override',
2088
	$pconfig['adv_dhcp6_config_file_override']
2089
))->setHelp('Override the configuration from this file.');
2090

    
2091
$section->add($group);
2092

    
2093
$section->addInput(new Form_Checkbox(
2094
	'dhcp6usev4iface',
2095
	'Use IPv4 connectivity as parent interface',
2096
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2097
	$pconfig['dhcp6usev4iface']
2098
));
2099

    
2100
$section->addInput(new Form_Checkbox(
2101
	'dhcp6prefixonly',
2102
	'Request only an IPv6 prefix',
2103
	'Only request an IPv6 prefix, do not request an IPv6 address',
2104
	$pconfig['dhcp6prefixonly']
2105
));
2106

    
2107
$section->addInput(new Form_Select(
2108
	'dhcp6-ia-pd-len',
2109
	'DHCPv6 Prefix Delegation size',
2110
	$pconfig['dhcp6-ia-pd-len'],
2111
	array("none" => "None", 16 => "48", 12 => "52", 8 => "56", 4 => "60", 3 => "61",  2 => "62", 1 => "63", 0 => "64")
2112
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2113

    
2114
$section->addInput(new Form_Checkbox(
2115
	'dhcp6-ia-pd-send-hint',
2116
	'Send IPv6 prefix hint',
2117
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2118
	$pconfig['dhcp6-ia-pd-send-hint']
2119
));
2120

    
2121
$section->addInput(new Form_Checkbox(
2122
	'dhcp6debug',
2123
	'Debug',
2124
	'Start DHCP6 client in debug mode',
2125
	$pconfig['dhcp6debug']
2126
));
2127
$section->addInput(new Form_Checkbox(
2128
	'dhcp6withoutra',
2129
	'Do not wait for a RA',
2130
	'Required by some ISPs, especially those not using PPPoE',
2131
	$pconfig['dhcp6withoutra']
2132
));
2133
$section->addInput(new Form_Input(
2134
	'adv_dhcp6_config_file_override_path',
2135
	'Configuration File Override',
2136
	'text',
2137
	$pconfig['adv_dhcp6_config_file_override_path']
2138
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2139
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2140
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2141
			'Some ISPs may require certain options be or not be sent.');
2142

    
2143
$form->add($section);
2144

    
2145
// DHCP6 client config - Advanced
2146

    
2147
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2148
$section->addClass('dhcp6advanced');
2149

    
2150
$section->addInput(new Form_Checkbox(
2151
	'adv_dhcp6_interface_statement_information_only_enable',
2152
	'Information only',
2153
	'Exchange Information Only',
2154
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2155
	'Selected'
2156
))->setHelp('Only exchange informational configuration parameters with servers.');
2157

    
2158
$section->addInput(new Form_Input(
2159
	'adv_dhcp6_interface_statement_send_options',
2160
	'Send options',
2161
	'text',
2162
	$pconfig['adv_dhcp6_interface_statement_send_options']
2163
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2164
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2165
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2166
			'Some DHCP services may require certain options be or not be sent.');
2167

    
2168
$section->addInput(new Form_Input(
2169
	'adv_dhcp6_interface_statement_request_options',
2170
	'Request Options',
2171
	'text',
2172
	$pconfig['adv_dhcp6_interface_statement_request_options']
2173
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2174
			'Some DHCP services may require certain options be or not be requested.');
2175

    
2176
$section->addInput(new Form_Input(
2177
	'adv_dhcp6_interface_statement_script',
2178
	'Scripts',
2179
	'text',
2180
	$pconfig['adv_dhcp6_interface_statement_script']
2181
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2182
			'[/[dirname/[.../]]filename[.ext]].');
2183

    
2184
$group = new Form_Group('Identity Association Statement');
2185

    
2186
$group->add(new Form_Checkbox(
2187
	'adv_dhcp6_id_assoc_statement_address_enable',
2188
	null,
2189
	'Non-Temporary Address Allocation',
2190
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2191
	'Selected'
2192
));
2193

    
2194
$group->add(new Form_Input(
2195
	'adv_dhcp6_id_assoc_statement_address_id',
2196
	null,
2197
	'text',
2198
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2199
))->sethelp('id-assoc na ID');
2200

    
2201
$group->add(new Form_IpAddress(
2202
	'adv_dhcp6_id_assoc_statement_address',
2203
	null,
2204
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2205
))->sethelp('IPv6 address');
2206

    
2207
$group->add(new Form_Input(
2208
	'adv_dhcp6_id_assoc_statement_address_pltime',
2209
	null,
2210
	'text',
2211
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2212
))->sethelp('pltime');
2213

    
2214
$group->add(new Form_Input(
2215
	'adv_dhcp6_id_assoc_statement_address_vltime',
2216
	null,
2217
	'text',
2218
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2219
))->sethelp('vltime');
2220

    
2221
$section->add($group);
2222

    
2223
// Prefix delegation
2224
$group = new Form_Group('');
2225

    
2226
$group->add(new Form_Checkbox(
2227
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2228
	null,
2229
	'Prefix Delegation ',
2230
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2231
	'Selected'
2232
));
2233

    
2234
$group->add(new Form_Input(
2235
	'adv_dhcp6_id_assoc_statement_prefix_id',
2236
	null,
2237
	'text',
2238
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2239
))->sethelp('id-assoc pd ID');
2240

    
2241
$group->add(new Form_IpAddress(
2242
	'adv_dhcp6_id_assoc_statement_prefix',
2243
	null,
2244
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2245
))->sethelp('IPv6 prefix');
2246

    
2247
$group->add(new Form_Input(
2248
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2249
	null,
2250
	'text',
2251
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2252
))->sethelp('pltime');
2253

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

    
2261
$section->add($group);
2262

    
2263
$group = new Form_Group('Prefix interface statement');
2264

    
2265
$group->add(new Form_Input(
2266
	'adv_dhcp6_prefix_interface_statement_sla_id',
2267
	null,
2268
	'text',
2269
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2270
))->sethelp('Prefix Interface sla-id');
2271

    
2272
$group->add(new Form_Input(
2273
	'adv_dhcp6_prefix_interface_statement_sla_len',
2274
	null,
2275
	'text',
2276
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2277
))->sethelp('sla-len');
2278

    
2279
$section->add($group);
2280

    
2281
$group = new Form_Group('Authentication statement');
2282

    
2283
$group->add(new Form_Input(
2284
	'adv_dhcp6_authentication_statement_authname',
2285
	null,
2286
	'text',
2287
	$pconfig['adv_dhcp6_authentication_statement_authname']
2288
))->sethelp('Authname');
2289

    
2290
$group->add(new Form_Input(
2291
	'adv_dhcp6_authentication_statement_protocol',
2292
	null,
2293
	'text',
2294
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2295
))->sethelp('Protocol');
2296

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

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

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

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

    
2315
$group->add(new Form_Input(
2316
	'adv_dhcp6_key_info_statement_keyname',
2317
	null,
2318
	'text',
2319
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2320
))->sethelp('Keyname');
2321

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

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

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

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

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

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

    
2354
$group->setHelp('<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhcp6c.conf&sektion=5&apropos=0&manpath=FreeBSD+10.1-RELEASE+and+Ports#Interface_statement">' . 'See here more information' . '</a>');
2355

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

    
2358
$form->add($section);
2359

    
2360
$section = new Form_Section('6RD Configuration');
2361
$section->addClass('_6rd');
2362

    
2363
$section->addInput(new Form_Input(
2364
	'prefix-6rd',
2365
	'6RD Prefix',
2366
	'text',
2367
	$pconfig['prefix-6rd']
2368
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2369

    
2370
$section->addInput(new Form_Input(
2371
	'gateway-6rd',
2372
	'6RD Border relay',
2373
	'text',
2374
	$pconfig['gateway-6rd']
2375
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2376

    
2377
$section->addInput(new Form_Select(
2378
	'prefix-6rd-v4plen',
2379
	'6RD IPv4 Prefix length',
2380
	$pconfig['prefix-6rd-v4plen'],
2381
	array_combine(range(0, 32), range(0, 32))
2382
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2383

    
2384
$form->add($section);
2385

    
2386
// Track IPv6 ointerface section
2387
$section = new Form_Section('Track IPv6 Interface');
2388
$section->addClass('track6');
2389

    
2390
function build_ipv6interface_list() {
2391
	global $config, $section;
2392

    
2393
	$list = array('' => '');
2394

    
2395
	$interfaces = get_configured_interface_with_descr(false, true);
2396
	$dynv6ifs = array();
2397

    
2398
	foreach ($interfaces as $iface => $ifacename) {
2399
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2400
			case "6to4":
2401
			case "6rd":
2402
			case "dhcp6":
2403
				$dynv6ifs[$iface] = array(
2404
					'name' => $ifacename,
2405
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2406
				);
2407
				break;
2408
			default:
2409
				continue;
2410
		}
2411
	}
2412

    
2413
	foreach ($dynv6ifs as $iface => $ifacedata) {
2414
		$list[$iface] = $ifacedata['name'];
2415

    
2416
		$section->addInput(new Form_Input(
2417
			'ipv6-num-prefix-ids-' . $iface,
2418
			null,
2419
			'hidden',
2420
			$ifacedata['ipv6_num_prefix_ids']
2421
		));
2422
	}
2423

    
2424
	return($list);
2425
}
2426

    
2427
$section->addInput(new Form_Select(
2428
	'track6-interface',
2429
	'IPv6 Interface',
2430
	$pconfig['track6-interface'],
2431
	build_ipv6interface_list()
2432
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2433

    
2434
if ($pconfig['track6-prefix-id'] == "") {
2435
	$pconfig['track6-prefix-id'] = 0;
2436
}
2437

    
2438
$section->addInput(new Form_Input(
2439
	'track6-prefix-id--hex',
2440
	'IPv6 Prefix ID',
2441
	'text',
2442
	sprintf("%x", $pconfig['track6-prefix-id'])
2443
))->setHelp('<span id="track6-prefix-id-range"></span>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.');
2444

    
2445
$section->addInput(new Form_Input(
2446
	'track6-prefix-id-max',
2447
	null,
2448
	'hidden',
2449
	0
2450
));
2451

    
2452
$form->add($section);
2453

    
2454
/// PPP section
2455

    
2456
$section = new Form_Section('PPP Configuration');
2457
$section->addClass('ppp');
2458

    
2459
$section->addInput(new Form_Select(
2460
	'country',
2461
	'Country',
2462
	$pconfig['country'],
2463
	[]
2464
));
2465

    
2466
$section->addInput(new Form_Select(
2467
	'provider_list',
2468
	'Provider',
2469
	$pconfig['provider_list'],
2470
	[]
2471
));
2472

    
2473
$section->addInput(new Form_Select(
2474
	'providerplan',
2475
	'Plan',
2476
	$pconfig['providerplan'],
2477
	[]
2478
))->setHelp('Select to fill in service provider data.');
2479

    
2480
$section->addInput(new Form_Input(
2481
	'ppp_username',
2482
	'Username',
2483
	'text',
2484
	$pconfig['ppp_username']
2485
));
2486

    
2487
$section->addPassword(new Form_Input(
2488
	'ppp_password',
2489
	'Password',
2490
	'password',
2491
	$pconfig['ppp_password']
2492
));
2493

    
2494
$section->addInput(new Form_Input(
2495
	'phone',
2496
	'Phone number',
2497
	'text',
2498
	$pconfig['phone']
2499
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2500

    
2501
$section->addInput(new Form_Input(
2502
	'apn',
2503
	'Access Point Name',
2504
	'text',
2505
	$pconfig['apn']
2506
));
2507

    
2508

    
2509
function build_port_list() {
2510
	$list = array("" => "None");
2511

    
2512
	$portlist = glob("/dev/cua*");
2513
	$modems	  = glob("/dev/modem*");
2514
	$portlist = array_merge($portlist, $modems);
2515

    
2516
	foreach ($portlist as $port) {
2517
		if (preg_match("/\.(lock|init)$/", $port)) {
2518
			continue;
2519
		}
2520

    
2521
	$list[trim($port)] = $port;
2522
	}
2523

    
2524
	return($list);
2525
}
2526

    
2527
$section->addInput(new Form_Select(
2528
	'port',
2529
	"Modem port",
2530
	$pconfig['port'],
2531
	build_port_list()
2532
));
2533

    
2534
$section->addInput(new Form_Button(
2535
	'btnadvppp',
2536
	'Advanced PPP',
2537
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2538
	'fa-cog'
2539
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2540

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

    
2543
// PPPoE configuration
2544
$section = new Form_Section('PPPoE Configuration');
2545
$section->addClass('pppoe');
2546

    
2547
$section->addInput(new Form_Input(
2548
	'pppoe_username',
2549
	'Username',
2550
	'text',
2551
	$pconfig['pppoe_username']
2552
));
2553

    
2554
$section->addPassword(new Form_Input(
2555
	'pppoe_password',
2556
	'Password',
2557
	'password',
2558
	$pconfig['pppoe_password']
2559
));
2560

    
2561
$section->addInput(new Form_Input(
2562
	'provider',
2563
	'Service name',
2564
	'text',
2565
	$pconfig['provider']
2566
))->setHelp('This field can usually be left empty.');
2567

    
2568
$section->addInput(new Form_Checkbox(
2569
	'pppoe_dialondemand',
2570
	'Dial on demand',
2571
	'Enable Dial-On-Demand mode ',
2572
	$pconfig['pppoe_dialondemand'],
2573
	'enable'
2574
));
2575

    
2576
$section->addInput(new Form_Input(
2577
	'pppoe_idletimeout',
2578
	'Idle timeout',
2579
	'number',
2580
	$pconfig['pppoe_idletimeout'],
2581
	['min' => 0]
2582
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2583
			'An idle timeout of zero disables this feature.');
2584

    
2585
$section->addInput(new Form_Select(
2586
	'pppoe-reset-type',
2587
	'Periodic reset',
2588
	$pconfig['pppoe-reset-type'],
2589
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2590
))->setHelp('Select a reset timing type.');
2591

    
2592
$group = new Form_Group('Custom reset');
2593
$group->addClass('pppoecustom');
2594

    
2595
$group->add(new Form_Input(
2596
	'pppoe_resethour',
2597
	null,
2598
	'number',
2599
	$pconfig['pppoe_resethour'],
2600
	['min' => 0, 'max' => 23]
2601
))->setHelp('Hour (0-23)');
2602

    
2603
$group->add(new Form_Input(
2604
	'pppoe_resetminute',
2605
	null,
2606
	'number',
2607
	$pconfig['pppoe_resetminute'],
2608
	['min' => 0, 'max' => 59]
2609
))->setHelp('Minutes (0-59)');
2610

    
2611
$group->add(new Form_Input(
2612
	'pppoe_resetdate',
2613
	null,
2614
	'text',
2615
	$pconfig['pppoe_resetdate']
2616
))->setHelp('Specific date (mm/dd/yyyy)');
2617

    
2618
$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');
2619

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

    
2622
$group = new Form_MultiCheckboxGroup('cron based reset');
2623
$group->addClass('pppoepreset');
2624

    
2625
$group->add(new Form_MultiCheckbox(
2626
	'pppoe_pr_preset_val',
2627
	null,
2628
	'Reset at each month ("0 0 1 * *")',
2629
	$pconfig['pppoe_monthly'],
2630
	'monthly'
2631
))->displayAsRadio();
2632

    
2633
$group->add(new Form_MultiCheckbox(
2634
	'pppoe_pr_preset_val',
2635
	null,
2636
	'Reset at each week ("0 0 * * 0")',
2637
	$pconfig['pppoe_weekly'],
2638
	'weekly'
2639
))->displayAsRadio();
2640

    
2641
$group->add(new Form_MultiCheckbox(
2642
	'pppoe_pr_preset_val',
2643
	null,
2644
	'Reset at each day ("0 0 * * *")',
2645
	$pconfig['pppoe_daily'],
2646
	'daily'
2647
))->displayAsRadio();
2648

    
2649
$group->add(new Form_MultiCheckbox(
2650
	'pppoe_pr_preset_val',
2651
	null,
2652
	'Reset at each hour ("0 * * * *")',
2653
	$pconfig['pppoe_hourly'],
2654
	'hourly'
2655
))->displayAsRadio();
2656

    
2657
$section->add($group);
2658

    
2659
$section->addInput(new Form_Button(
2660
	'btnadvppp',
2661
	'Advanced and MLPPP',
2662
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2663
	'fa-cog'
2664
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
2665

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

    
2668
// PPTP & L2TP Configuration section
2669
$section = new Form_Section('PPTP/L2TP Configuration');
2670
$section->addClass('pptp');
2671

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

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

    
2686
$section->addInput(new Form_IpAddress(
2687
	'pptp_local0',
2688
	'Local IP address',
2689
	$pconfig['pptp_localip'][0]
2690
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2691

    
2692
$section->addInput(new Form_IpAddress(
2693
	'pptp_remote0',
2694
	'Remote IP address',
2695
	$pconfig['pptp_remote'][0]
2696
));
2697

    
2698
$section->addInput(new Form_Checkbox(
2699
	'pptp_dialondemand',
2700
	'Dial on demand',
2701
	'Enable Dial-On-Demand mode ',
2702
	$pconfig['pptp_dialondemand'],
2703
	'enable'
2704
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
2705
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2706

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

    
2716
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2717
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2718
} else {
2719
	$mlppp_text = "";
2720
}
2721

    
2722
$section->addInput(new Form_Button(
2723
	'btnadvppp',
2724
	'Advanced and MLPPP',
2725
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2726
	'fa-cog'
2727
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp($mlppp_text . 'Click for additional PPTP and L2TP configuration options. Save first if changes have been made.');
2728

    
2729
$form->add($section);
2730

    
2731
// Wireless interface
2732
if (isset($wancfg['wireless'])) {
2733

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

    
2736
	$section->addInput(new Form_Checkbox(
2737
		'persistcommonwireless',
2738
		'Persist common settings',
2739
		'Preserve common wireless configuration through interface deletions and reassignments.',
2740
		$pconfig['persistcommonwireless'],
2741
		'yes'
2742
	));
2743

    
2744
	$mode_list = ['auto' => 'Auto'];
2745

    
2746
	if (is_array($wl_modes)) {
2747
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2748
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2749
		}
2750
	}
2751

    
2752
	if (count($mode_list) == 1) {
2753
		$mode_list[''] = '';
2754
	}
2755

    
2756
	$section->addInput(new Form_Select(
2757
		'standard',
2758
		'Standard',
2759
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2760
		$mode_list
2761
	));
2762

    
2763
	if (isset($wl_modes['11g'])) {
2764
		$section->addInput(new Form_Select(
2765
			'protmode',
2766
			'802.11g OFDM Protection Mode',
2767
			$pconfig['protmode'],
2768
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
2769
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2770
	} else {
2771
		$section->addInput(new Form_Input(
2772
			'protmode',
2773
			null,
2774
			'hidden',
2775
			'off'
2776
		));
2777
	}
2778

    
2779
	$mode_list = ['0' => gettext('Auto')];
2780

    
2781
	if (is_array($wl_modes)) {
2782
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2783
			if ($wl_standard == "11g") {
2784
				$wl_standard = "11b/g";
2785
			} else if ($wl_standard == "11ng") {
2786
				$wl_standard = "11b/g/n";
2787
			} else if ($wl_standard == "11na") {
2788
				$wl_standard = "11a/n";
2789
			}
2790

    
2791
			foreach ($wl_channels as $wl_channel) {
2792
				if (isset($wl_chaninfo[$wl_channel])) {
2793
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2794
				} else {
2795
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2796
				}
2797
			}
2798
		}
2799
	}
2800

    
2801
	$section->addInput(new Form_Select(
2802
		'channel',
2803
		'Channel',
2804
		$pconfig['channel'],
2805
		$mode_list
2806
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2807
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.');
2808

    
2809
	if (ANTENNAS) {
2810
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2811
			$group = new Form_Group('Antenna Settings');
2812

    
2813
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2814
				$group->add(new Form_Select(
2815
					'diversity',
2816
					null,
2817
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2818
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
2819
				))->setHelp('Diversity');
2820
			}
2821

    
2822
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2823
				$group->add(new Form_Select(
2824
					'txantenna',
2825
					null,
2826
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2827
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2828
				))->setHelp('Transmit antenna');
2829
			}
2830

    
2831
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2832
				$group->add(new Form_Select(
2833
					'rxantenna',
2834
					null,
2835
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2836
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
2837
				))->setHelp('Receive antenna');
2838
			}
2839

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

    
2842
			$section->add($group);
2843
		}
2844
	}
2845

    
2846
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2847
			$section->addInput(new Form_Input(
2848
				'distance',
2849
				'Distance setting (meters)',
2850
				'test',
2851
				$pconfig['distance']
2852
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2853
	}
2854

    
2855
	$form->add($section);
2856

    
2857
	// Regulatory settings
2858
	$section = new Form_Section('Regulatory Settings');
2859

    
2860
	$domain_list = array("" => 'Default');
2861

    
2862
	if (is_array($wl_regdomains)) {
2863
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2864
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2865
		}
2866
	}
2867

    
2868
	$section->addInput(new Form_Select(
2869
		'regdomain',
2870
		'Regulatory domain',
2871
		$pconfig['regdomain'],
2872
		$domain_list
2873
	))->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');
2874

    
2875
	$country_list = array('' => 'Default');
2876

    
2877
	if (is_array($wl_countries)) {
2878
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2879
			$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']);
2880
		}
2881
	}
2882

    
2883
	$section->addInput(new Form_Select(
2884
		'regcountry',
2885
		'Country',
2886
		$pconfig['regcountry'],
2887
		$country_list
2888
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2889

    
2890
	$section->addInput(new Form_Select(
2891
		'reglocation',
2892
		'Location',
2893
		$pconfig['reglocation'],
2894
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
2895
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2896
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2897
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2898
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2899
				'These settings may not be able to add additional channels that are not already supported.');
2900

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

    
2903
	$section = new Form_Section('Network-Specific Wireless Configuration');
2904

    
2905
	$section->addInput(new Form_Select(
2906
		'mode',
2907
		'Mode',
2908
		$pconfig['mode'],
2909
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
2910
	));
2911

    
2912
	$section->addInput(new Form_Input(
2913
		'ssid',
2914
		'SSID',
2915
		'text',
2916
		$pconfig['ssid']
2917
	));
2918

    
2919
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2920
		$section->addInput(new Form_Select(
2921
			'puremode',
2922
			'Minimum wireless standard',
2923
			$pconfig['puremode'],
2924
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
2925
		))->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)');
2926
	} elseif (isset($wl_modes['11g'])) {
2927
		$section->addInput(new Form_Checkbox(
2928
			'puremode',
2929
			'802.11g only',
2930
			null,
2931
			$pconfig['puremode'],
2932
			'11g'
2933
		))->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)');
2934
	}
2935

    
2936
	$section->addInput(new Form_Checkbox(
2937
		'apbridge_enable',
2938
		'Allow intra-BSS communication',
2939
		'Allow packets to pass between wireless clients directly when operating as an access point',
2940
		$pconfig['apbridge_enable'],
2941
		'yes'
2942
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
2943

    
2944
	$section->addInput(new Form_Checkbox(
2945
		'wme_enable',
2946
		'Enable WME',
2947
		'Force the card to use WME (wireless QoS)',
2948
		$pconfig['wme_enable'],
2949
		'yes'
2950
	));
2951

    
2952
	$section->addInput(new Form_Checkbox(
2953
		'hidessid_enable',
2954
		'Hide SSID',
2955
		'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.)',
2956
		$pconfig['hidessid_enable'],
2957
		'yes'
2958
	));
2959

    
2960
	$form->add($section);
2961

    
2962
	// WPA Section
2963
	$section = new Form_Section('WPA');
2964

    
2965
	$section->addInput(new Form_Checkbox(
2966
		'wpa_enable',
2967
		'Enable',
2968
		'Enable WPA',
2969
		$pconfig['wpa_enable'],
2970
		'yes'
2971
	));
2972

    
2973
	$section->addInput(new Form_Input(
2974
		'passphrase',
2975
		'WPA Pre-Shared Key',
2976
		'text',
2977
		$pconfig['passphrase']
2978
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2979

    
2980
	$section->addInput(new Form_Select(
2981
		'wpa_mode',
2982
		'WPA mode',
2983
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2984
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
2985
	));
2986

    
2987
	$section->addInput(new Form_Select(
2988
		'wpa_key_mgmt',
2989
		'WPA Key Management Mode',
2990
		$pconfig['wpa_key_mgmt'],
2991
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
2992
	));
2993

    
2994
	$section->addInput(new Form_Select(
2995
		'wpa_pairwise',
2996
		'WPA Pairwise',
2997
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
2998
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
2999
	));
3000

    
3001
	$section->addInput(new Form_Input(
3002
		'wpa_group_rekey',
3003
		'Group Key Rotation',
3004
		'number',
3005
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3006
		['min' => '1', 'max' => 9999]
3007
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3008

    
3009
	$section->addInput(new Form_Input(
3010
		'wpa_gmk_rekey',
3011
		'Group Master Key Regeneration',
3012
		'number',
3013
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3014
		['min' => '1', 'max' => 9999]
3015
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3016

    
3017
	$section->addInput(new Form_Checkbox(
3018
		'wpa_strict_rekey',
3019
		'Strict Key Regeneration',
3020
		'Force the AP to rekey whenever a client disassociates',
3021
		$pconfig['wpa_strict_rekey'],
3022
		'yes'
3023
	));
3024

    
3025
	$form->add($section);
3026

    
3027
	$section = new Form_Section('802.1x RADIUS Options');
3028

    
3029
	$section->addInput(new Form_Checkbox(
3030
		'ieee8021x',
3031
		'IEEE802.1X',
3032
		'Enable 802.1X authentication',
3033
		$pconfig['ieee8021x'],
3034
		'yes'
3035
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3036

    
3037
	$group = new Form_Group('Primary 802.1X server');
3038

    
3039
	$group->add(new Form_IpAddress(
3040
		'auth_server_addr',
3041
		'IP Address',
3042
		$pconfig['auth_server_addr']
3043
	))->setHelp('IP address of the RADIUS server');
3044

    
3045
	$group->add(new Form_Input(
3046
		'auth_server_port',
3047
		'Port',
3048
		'number',
3049
		$pconfig['auth_server_port']
3050
	))->setHelp('Server auth port. Default is 1812');
3051

    
3052
	$group->add(new Form_Input(
3053
		'auth_server_shared_secret',
3054
		'Shared Secret',
3055
		'text',
3056
		$pconfig['auth_server_shared_secret']
3057
	))->setHelp('RADIUS Shared secret for this firewall');
3058

    
3059
	$section->add($group);
3060

    
3061
	$group = new Form_Group('Secondary 802.1X server');
3062

    
3063
	$group->add(new Form_IpAddress(
3064
		'auth_server_addr2',
3065
		'IP Address',
3066
		$pconfig['auth_server_addr2']
3067
	))->setHelp('IP address of the RADIUS server');
3068

    
3069
	$group->add(new Form_Input(
3070
		'auth_server_port2',
3071
		'Port',
3072
		'number',
3073
		$pconfig['auth_server_port2']
3074
	))->setHelp('Server auth port. Default is 1812');
3075

    
3076
	$group->add(new Form_Input(
3077
		'auth_server_shared_secret2',
3078
		'Shared Secret',
3079
		'text',
3080
		$pconfig['auth_server_shared_secret2']
3081
	))->setHelp('RADIUS Shared secret for this firewall');
3082

    
3083
	$section->add($group);
3084

    
3085
	$section->addInput(new Form_Checkbox(
3086
		'rsn_preauth',
3087
		'Authentication Roaming Preauth',
3088
		null,
3089
		$pconfig['rsn_preauth'],
3090
		'yes'
3091
	));
3092

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

    
3096
$section = new Form_Section('Reserved Networks');
3097

    
3098
$section->addInput(new Form_Checkbox(
3099
	'blockpriv',
3100
	'Block private networks and loopback addresses',
3101
	'',
3102
	$pconfig['blockpriv'],
3103
	'yes'
3104
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3105
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3106
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3107

    
3108
$section->addInput(new Form_Checkbox(
3109
	'blockbogons',
3110
	'Block bogon networks',
3111
	'',
3112
	$pconfig['blockbogons'],
3113
	'yes'
3114
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3115
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.' . '<br />' .
3116
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings.');
3117

    
3118
$form->add($section);
3119

    
3120
$form->addGlobal(new Form_Input(
3121
	'if',
3122
	null,
3123
	'hidden',
3124
	$if
3125
));
3126

    
3127
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3128
	$form->addGlobal(new Form_Input(
3129
		'ppp_port',
3130
		null,
3131
		'hidden',
3132
		$pconfig['port']
3133
	));
3134
}
3135

    
3136
$form->addGlobal(new Form_Input(
3137
	'ptpid',
3138
	null,
3139
	'hidden',
3140
	$pconfig['ptpid']
3141
));
3142

    
3143

    
3144
// Add new gateway modal pop-up
3145
$modal = new Modal('New Gateway', 'newgateway', 'large');
3146

    
3147
$modal->addInput(new Form_Checkbox(
3148
	'defaultgw',
3149
	'Default',
3150
	'Default gateway',
3151
	($if == "wan" || $if == "WAN")
3152
));
3153

    
3154
$modal->addInput(new Form_Input(
3155
	'name',
3156
	'Gateway name',
3157
	'text',
3158
	$wancfg['descr'] . "GW"
3159
));
3160

    
3161
$modal->addInput(new Form_IpAddress(
3162
	'gatewayip',
3163
	'Gateway IPv4',
3164
	null
3165
));
3166

    
3167
$modal->addInput(new Form_Input(
3168
	'gatewaydescr',
3169
	'Description',
3170
	'text'
3171
));
3172

    
3173
$btnaddgw = new Form_Button(
3174
	'add',
3175
	'Add',
3176
	null,
3177
	'fa-plus'
3178
);
3179

    
3180
$btnaddgw->setAttribute('type','button')->addClass('btn-success');
3181

    
3182
$btncnxgw = new Form_Button(
3183
	'cnx',
3184
	'Cancel',
3185
	null,
3186
	'fa-undo'
3187
);
3188

    
3189
$btncnxgw->setAttribute('type','button')->addClass('btn-warning');
3190

    
3191
$modal->addInput(new Form_StaticText(
3192
	null,
3193
	$btnaddgw . $btncnxgw
3194
));
3195

    
3196
$form->add($modal);
3197

    
3198
print($form);
3199
?>
3200

    
3201
<script type="text/javascript">
3202
//<![CDATA[
3203
events.push(function() {
3204
	function updateType(t) {
3205

    
3206
		switch (t) {
3207
			case "none": {
3208
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3209
				break;
3210
			}
3211
			case "staticv4": {
3212
				$('.dhcpadvanced, .none, .dhcp').hide();
3213
				$('.pppoe, .pptp, .ppp').hide();
3214
				break;
3215
			}
3216
			case "dhcp": {
3217
				$('.dhcpadvanced, .none').hide();
3218
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3219
										//			about the staticv4 class
3220
				$('.pppoe, .pptp, .ppp').hide();
3221
				break;
3222
			}
3223
			case "ppp": {
3224
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3225
				country_list();
3226
				break;
3227
			}
3228
			case "pppoe": {
3229
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3230
				break;
3231
			}
3232
			case "l2tp":
3233
			case "pptp": {
3234
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3235
				$('.pptp').show();
3236
				break;
3237
			}
3238
		}
3239

    
3240
		if (t != "l2tp" && t != "pptp") {
3241
			$('.'+t).show();
3242
		}
3243
	}
3244

    
3245
	function updateTypeSix(t) {
3246
		if (!isNaN(t[0])) {
3247
			t = '_' + t;
3248
		}
3249

    
3250
		switch (t) {
3251
			case "none": {
3252
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3253
				break;
3254
			}
3255
			case "staticv6": {
3256
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3257
				break;
3258
			}
3259
			case "slaac": {
3260
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3261
				break;
3262
			}
3263
			case "dhcp6": {
3264
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3265
				break;
3266
			}
3267
			case "_6rd": {
3268
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3269
				break;
3270
			}
3271
			case "_6to4": {
3272
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3273
				break;
3274
			}
3275
			case "track6": {
3276
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3277
				update_track6_prefix();
3278
				break;
3279
			}
3280
		}
3281

    
3282
		if (t != "l2tp" && t != "pptp") {
3283
			$('.'+t).show();
3284
		}
3285
	}
3286

    
3287
	function show_reset_settings(reset_type) {
3288
		if (reset_type == 'preset') {
3289
			$('.pppoepreset').show();
3290
			$('.pppoecustom').hide();
3291
		} else if (reset_type == 'custom') {
3292
			$('.pppoecustom').show();
3293
			$('.pppoepreset').hide();
3294
		} else {
3295
			$('.pppoecustom').hide();
3296
			$('.pppoepreset').hide();
3297
		}
3298
	}
3299

    
3300
	function update_track6_prefix() {
3301
		var iface = $("#track6-interface").val();
3302
		if (iface == null) {
3303
			return;
3304
		}
3305

    
3306
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3307
		if (track6_prefix_ids == null) {
3308
			return;
3309
		}
3310

    
3311
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3312
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3313
	}
3314

    
3315
	// Create the new gateway from the data entered in the modal pop-up
3316
	function hide_add_gatewaysave() {
3317
		var iface = $('#if').val();
3318
		name = $('#name').val();
3319
		var descr = $('#gatewaydescr').val();
3320
		gatewayip = $('#gatewayip').val();
3321

    
3322
		var defaultgw = '';
3323
		if ($('#defaultgw').is(':checked')) {
3324
			defaultgw = '&defaultgw=on';
3325
		}
3326

    
3327
		var url = "system_gateways_edit.php";
3328
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3329
		$.ajax(
3330
			url,
3331
			{
3332
				type: 'post',
3333
				data: pars,
3334
				error: report_failure,
3335
				complete: save_callback
3336
			});
3337
		}
3338

    
3339
	function save_callback(response) {
3340
		if (response) {
3341
			var gwtext = escape(name) + " - " + gatewayip;
3342
			addOption($('#gateway'), gwtext, name);
3343
		} else {
3344
			report_failure();
3345
		}
3346

    
3347
		$("#newgateway").modal('hide');
3348
	}
3349

    
3350
	function report_failure(request, textStatus, errorThrown) {
3351
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3352
			alert(request.responseText);
3353
		} else {
3354
			alert("The IPv4 gateway could not be created.");
3355
		}
3356

    
3357
		$("#newgateway").modal('hide');
3358
	}
3359

    
3360
	function addOption(selectbox, text, value) {
3361
		var optn = document.createElement("OPTION");
3362
		optn.text = text;
3363
		optn.value = value;
3364
		selectbox.append(optn);
3365
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3366
	}
3367

    
3368
	function hide_add_gatewaysave_v6() {
3369

    
3370
		var iface = $('#if').val();
3371
		name = $('#name6').val();
3372
		var descr = $('#gatewaydescr6').val();
3373
		gatewayip = $('#gatewayip6').val();
3374
		var defaultgw = '';
3375
		if ($('#defaultgw6').is(':checked')) {
3376
			defaultgw = '&defaultgw=on';
3377
		}
3378
		var url_v6 = "system_gateways_edit.php";
3379
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3380
		$.ajax(
3381
			url_v6,
3382
			{
3383
				type: 'post',
3384
				data: pars_v6,
3385
				error: report_failure_v6,
3386
				success: save_callback_v6
3387
			});
3388
	}
3389

    
3390

    
3391
	function addOption_v6(selectbox, text, value) {
3392
		var optn = document.createElement("OPTION");
3393
		optn.text = text;
3394
		optn.value = value;
3395
		selectbox.append(optn);
3396
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3397
	}
3398

    
3399
	function report_failure_v6(request, textStatus, errorThrown) {
3400
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3401
			alert(request.responseText);
3402
		} else {
3403
			alert("The IPv6 gateway could not be created.");
3404
		}
3405

    
3406
		$("#newgateway6").modal('hide');
3407
	}
3408

    
3409
	function save_callback_v6(response_v6) {
3410
		if (response_v6) {
3411

    
3412
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3413
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3414
		} else {
3415
			report_failure_v6();
3416
		}
3417

    
3418
		$("#newgateway6").modal('hide');
3419
	}
3420

    
3421
	function country_list() {
3422
		$('#country').children().remove();
3423
		$('#provider_list').children().remove();
3424
		$('#providerplan').children().remove();
3425
		$.ajax("getserviceproviders.php",{
3426
			success: function(response) {
3427

    
3428
				var responseTextArr = response.split("\n");
3429
				responseTextArr.sort();
3430

    
3431
				responseTextArr.forEach( function(value) {
3432
					country = value.split(":");
3433
					$('#country').append($('<option>', {
3434
						value: country[1],
3435
						text : country[0]
3436
					}));
3437
				});
3438
			}
3439
		});
3440
	}
3441

    
3442
	function providers_list() {
3443
		$('#provider_list').children().remove();
3444
		$('#providerplan').children().remove();
3445
		$.ajax("getserviceproviders.php",{
3446
			type: 'post',
3447
			data: {country : $('#country').val()},
3448
			success: function(response) {
3449
				var responseTextArr = response.split("\n");
3450
				responseTextArr.sort();
3451
				responseTextArr.forEach( function(value) {
3452
					$('#provider_list').append($('<option>', {
3453
							value: value,
3454
							text : value
3455
					}));
3456
				});
3457
			}
3458
		});
3459
	}
3460

    
3461
	function providerplan_list() {
3462
		$('#providerplan').children().remove();
3463
		$.ajax("getserviceproviders.php",{
3464
			type: 'post',
3465
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3466
			success: function(response) {
3467
				var responseTextArr = response.split("\n");
3468
				responseTextArr.sort();
3469

    
3470
				$('#providerplan').append($('<option>', {
3471
					value: '',
3472
					text : ''
3473
				}));
3474

    
3475
				responseTextArr.forEach( function(value) {
3476
					if (value != "") {
3477
						providerplan = value.split(":");
3478

    
3479
						$('#providerplan').append($('<option>', {
3480
							value: providerplan[1],
3481
							text : providerplan[0] + " - " + providerplan[1]
3482
						}));
3483
					}
3484
				});
3485
			}
3486
		});
3487
	}
3488

    
3489
	function prefill_provider() {
3490
		$.ajax("getserviceproviders.php",{
3491
			type: 'post',
3492
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3493
			success: function(data, textStatus, response) {
3494
				var xmldoc = response.responseXML;
3495
				var provider = xmldoc.getElementsByTagName('connection')[0];
3496
				$('#ppp_username').val('');
3497
				$('#ppp_password').val('');
3498
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3499
					$('#phone').val('#777');
3500
					$('#apn').val('');
3501
				} else {
3502
					$('#phone').val('*99#');
3503
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3504
				}
3505
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3506
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3507
				$('#ppp_username').val(ppp_username);
3508
				$('#ppp_password').val(ppp_password);
3509
			}
3510
		});
3511
	}
3512

    
3513
	function show_dhcp6adv() {
3514
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3515
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3516

    
3517
		hideCheckbox('dhcp6usev4iface', ovr);
3518
		hideCheckbox('dhcp6prefixonly', ovr);
3519
		hideInput('dhcp6-ia-pd-len', ovr);
3520
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3521
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3522

    
3523
		hideClass('dhcp6advanced', !adv || ovr);
3524
	}
3525

    
3526
	function setDHCPoptions() {
3527
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3528
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3529

    
3530
		if (ovr) {
3531
			hideInput('dhcphostname', true);
3532
			hideIpAddress('alias-address', true);
3533
			hideInput('dhcprejectfrom', true);
3534
			hideInput('adv_dhcp_config_file_override_path', false);
3535
			hideClass('dhcpadvanced', true);
3536
		} else {
3537
			hideInput('dhcphostname', false);
3538
			hideIpAddress('alias-address', false);
3539
			hideInput('dhcprejectfrom', false);
3540
			hideInput('adv_dhcp_config_file_override_path', true);
3541
			hideClass('dhcpadvanced', !adv);
3542
		}
3543
	}
3544

    
3545
	// DHCP preset actions
3546
	// Set presets from value of radio buttons
3547
	function setPresets(val) {
3548
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3549
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3550
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3551
		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']);?>");
3552
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3553
	}
3554

    
3555
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3556
		$('#adv_dhcp_pt_timeout').val(timeout);
3557
		$('#adv_dhcp_pt_retry').val(retry);
3558
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3559
		$('#adv_dhcp_pt_reboot').val(reboot);
3560
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3561
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3562
	}
3563

    
3564
	// ---------- On initial page load ------------------------------------------------------------
3565

    
3566
	updateType($('#type').val());
3567
	updateTypeSix($('#type6').val());
3568
	show_reset_settings($('#pppoe-reset-type').val());
3569
	hideClass('dhcp6advanced', true);
3570
	hideClass('dhcpadvanced', true);
3571
	show_dhcp6adv();
3572
	setDHCPoptions()
3573

    
3574
	// Set preset buttons on page load
3575
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3576
	if (sv == "") {
3577
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3578
	} else {
3579
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3580
	}
3581

    
3582
	// Set preset from value
3583
	setPresets(sv);
3584

    
3585
	// ---------- Click checkbox handlers ---------------------------------------------------------
3586

    
3587
	$('#type').on('change', function() {
3588
		updateType(this.value);
3589
	});
3590

    
3591
	$('#type6').on('change', function() {
3592
		updateTypeSix(this.value);
3593
	});
3594

    
3595
	$('#track6-interface').on('change', function() {
3596
		update_track6_prefix();
3597
	});
3598

    
3599
	$('#pppoe-reset-type').on('change', function() {
3600
		show_reset_settings(this.value);
3601
	});
3602

    
3603
	$("#add").click(function() {
3604
		hide_add_gatewaysave();
3605
	});
3606

    
3607
	$("#cnx").click(function() {
3608
		$("#newgateway").modal('hide');
3609
	});
3610

    
3611
	$("#add6").click(function() {
3612
		hide_add_gatewaysave_v6();
3613
	});
3614

    
3615
	$("#cnx6").click(function() {
3616
		$("#newgateway6").modal('hide');
3617
	});
3618

    
3619
	$('#country').on('change', function() {
3620
		providers_list();
3621
	});
3622

    
3623
	$('#provider_list').on('change', function() {
3624
		providerplan_list();
3625
	});
3626

    
3627
	$('#providerplan').on('change', function() {
3628
		prefill_provider();
3629
	});
3630

    
3631
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
3632
		setDHCPoptions();
3633
	});
3634

    
3635
	$('#adv_dhcp6_config_advanced').click(function () {
3636
		show_dhcp6adv();
3637
	});
3638

    
3639
	$('#adv_dhcp6_config_file_override').click(function () {
3640
		show_dhcp6adv();
3641
	});
3642

    
3643
	// On click . .
3644
	$('[name=adv_dhcp_pt_values]').click(function () {
3645
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3646
	});
3647

    
3648
	$('#pppoe_resetdate').datepicker();
3649

    
3650
});
3651
//]]>
3652
</script>
3653

    
3654
<?php include("foot.inc");
(67-67/225)