Project

General

Profile

Download (121 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c) 2006 Daniel S. Haischt
8
 *
9
 *	Some or all of this file is based on the m0n0wall project which is
10
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14
 *
15
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *	  this list of conditions and the following disclaimer.
17
 *
18
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *	  notice, this list of conditions and the following disclaimer in
20
 *	  the documentation and/or other materials provided with the
21
 *	  distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *	  must display the following acknowledgment:
25
 *	  "This product includes software developed by the pfSense Project
26
 *	   for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *	   endorse or promote products derived from this software without
30
 *	   prior written permission. For written permission, please contact
31
 *	   coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *	  nor may "pfSense" appear in their names without prior written
35
 *	  permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *	  acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59

    
60
##|+PRIV
61
##|*IDENT=page-interfaces
62
##|*NAME=Interfaces: WAN
63
##|*DESCR=Allow access to the 'Interfaces' page.
64
##|*MATCH=interfaces.php*
65
##|-PRIV
66

    
67
require_once("guiconfig.inc");
68
require_once("ipsec.inc");
69
require_once("functions.inc");
70
require_once("captiveportal.inc");
71
require_once("filter.inc");
72
require_once("shaper.inc");
73
require_once("rrd.inc");
74
require_once("vpn.inc");
75
require_once("xmlparse_attr.inc");
76

    
77
define("ANTENNAS", false);
78

    
79
if (isset($_POST['referer'])) {
80
	$referer = $_POST['referer'];
81
} else {
82
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
83
}
84

    
85
// Get configured interface list
86
$ifdescrs = get_configured_interface_with_descr(false, true);
87

    
88
$if = "wan";
89
if ($_REQUEST['if']) {
90
	$if = $_REQUEST['if'];
91
}
92

    
93
if (empty($ifdescrs[$if])) {
94
	header("Location: interfaces.php");
95
	exit;
96
}
97

    
98
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
99
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
100
define("CRON_DAILY_PATTERN", "0 0 * * *");
101
define("CRON_HOURLY_PATTERN", "0 * * * *");
102

    
103
if (!is_array($pconfig)) {
104
	$pconfig = array();
105
}
106

    
107
if (!is_array($config['ppps'])) {
108
	$config['ppps'] = array();
109
}
110
if (!is_array($config['ppps']['ppp'])) {
111
	$config['ppps']['ppp'] = array();
112
}
113
$a_ppps = &$config['ppps']['ppp'];
114

    
115
function remove_bad_chars($string) {
116
	return preg_replace('/[^a-z_0-9]/i', '', $string);
117
}
118

    
119
if (!is_array($config['gateways']['gateway_item'])) {
120
	$config['gateways']['gateway_item'] = array();
121
}
122

    
123
$a_gateways = &$config['gateways']['gateway_item'];
124

    
125
$wancfg = &$config['interfaces'][$if];
126
$old_wancfg = $wancfg;
127
$old_wancfg['realif'] = get_real_interface($if);
128
$old_ppps = $a_ppps;
129

    
130
// Populate page descr if it does not exist.
131
if ($if == "wan" && !$wancfg['descr']) {
132
	$wancfg['descr'] = "WAN";
133
} else if ($if == "lan" && !$wancfg['descr']) {
134
	$wancfg['descr'] = "LAN";
135
}
136

    
137
/* NOTE: The code here is used to set the $pppid for the curious */
138
foreach ($a_ppps as $pppid => $ppp) {
139
	if ($wancfg['if'] == $ppp['if']) {
140
		break;
141
	}
142
}
143

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

    
146
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
147
	$pconfig['pppid'] = $pppid;
148
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
149
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
150
	if ($a_ppps[$pppid]['type'] == "ppp") {
151
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
152
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
153

    
154
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
155
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
156
	} else if ($a_ppps[$pppid]['type'] == "pppoe") {
157
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
158
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
159
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
160
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
161
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
162

    
163
		/* ================================================ */
164
		/* = force a connection reset at a specific time? = */
165
		/* ================================================ */
166

    
167
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
168
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
169
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
170
			if ($itemhash) {
171
				$cronitem = $itemhash['ITEM'];
172
			}
173
			if (isset($cronitem)) {
174
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
175
			} else {
176
				$resetTime = NULL;
177
			}
178
			//log_error("ResetTime:".$resetTime);
179
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
180
				if ($cronitem) {
181
					$pconfig['pppoe_pr_custom'] = true;
182
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
183
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
184
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
185
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
186
					}
187
				}
188
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
189
				$pconfig['pppoe_pr_preset'] = true;
190
				switch ($resetTime) {
191
					case CRON_MONTHLY_PATTERN:
192
						$pconfig['pppoe_monthly'] = true;
193
						break;
194
					case CRON_WEEKLY_PATTERN:
195
						$pconfig['pppoe_weekly'] = true;
196
						break;
197
					case CRON_DAILY_PATTERN:
198
						$pconfig['pppoe_daily'] = true;
199
						break;
200
					case CRON_HOURLY_PATTERN:
201
						$pconfig['pppoe_hourly'] = true;
202
						break;
203
				}
204
			}
205
		} // End force pppoe reset at specific time
206
		// End if type == pppoe
207
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
208
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
209
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
210
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
211
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
212
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
213
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
214
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
215
	}
216
} else {
217
	$pconfig['ptpid'] = interfaces_ptpid_next();
218
	$pppid = count($a_ppps);
219
}
220

    
221
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
222
$pconfig['alias-address'] = $wancfg['alias-address'];
223
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
224
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
225

    
226
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
227
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
228
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
229
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
230
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
231
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
232

    
233
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
234

    
235
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
236
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
237
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
238
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
239

    
240
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
241
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
242
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
243

    
244
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
245
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
246
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
247
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
248

    
249
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
250
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
251
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
252
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
253
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
254

    
255
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
256
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
257
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
258
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
259
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
260

    
261
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
262
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
263

    
264
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
265
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
266
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
267
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
268

    
269
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
270
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
271
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
272
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
273
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
274

    
275
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
276
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
277
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
278

    
279
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
280
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
281
$pconfig['enable'] = isset($wancfg['enable']);
282

    
283
if (is_array($config['aliases']['alias'])) {
284
	foreach ($config['aliases']['alias'] as $alias) {
285
		if ($alias['name'] == $wancfg['descr']) {
286
			$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $wancfg['descr']);
287
		}
288
	}
289
}
290

    
291
switch ($wancfg['ipaddr']) {
292
	case "dhcp":
293
		$pconfig['type'] = "dhcp";
294
		break;
295
	case "pppoe":
296
	case "pptp":
297
	case "l2tp":
298
	case "ppp":
299
		$pconfig['type'] = $wancfg['ipaddr'];
300
		break;
301
	default:
302
		if (is_ipaddrv4($wancfg['ipaddr'])) {
303
			$pconfig['type'] = "staticv4";
304
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
305
			$pconfig['subnet'] = $wancfg['subnet'];
306
			$pconfig['gateway'] = $wancfg['gateway'];
307
		} else {
308
			$pconfig['type'] = "none";
309
		}
310
		break;
311
}
312

    
313
switch ($wancfg['ipaddrv6']) {
314
	case "slaac":
315
		$pconfig['type6'] = "slaac";
316
		break;
317
	case "dhcp6":
318
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
319
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
320
			$wancfg['dhcp6-ia-pd-len'] = "none";
321
		}
322
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
323
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
324
		$pconfig['type6'] = "dhcp6";
325
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
326
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
327
		break;
328
	case "6to4":
329
		$pconfig['type6'] = "6to4";
330
		break;
331
	case "track6":
332
		$pconfig['type6'] = "track6";
333
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
334
		if ($wancfg['track6-prefix-id'] == "") {
335
			$pconfig['track6-prefix-id'] = 0;
336
		} else {
337
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
338
		}
339
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
340
		break;
341
	case "6rd":
342
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
343
		if ($wancfg['prefix-6rd-v4plen'] == "") {
344
			$wancfg['prefix-6rd-v4plen'] = "0";
345
		}
346
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
347
		$pconfig['type6'] = "6rd";
348
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
349
		break;
350
	default:
351
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
352
			$pconfig['type6'] = "staticv6";
353
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
354
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
355
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
356
		} else {
357
			$pconfig['type6'] = "none";
358
		}
359
		break;
360
}
361

    
362
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
363
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
364
$pconfig['spoofmac'] = $wancfg['spoofmac'];
365
$pconfig['mtu'] = $wancfg['mtu'];
366
$pconfig['mss'] = $wancfg['mss'];
367

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

    
444
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
445

    
446
}
447

    
448
if ($_POST['apply']) {
449
	unset($input_errors);
450
	if (!is_subsystem_dirty('interfaces')) {
451
		$input_errors[] = gettext("You have already applied your settings!");
452
	} else {
453
		unlink_if_exists("{$g['tmp_path']}/config.cache");
454
		clear_subsystem_dirty('interfaces');
455

    
456
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
457
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
458
			foreach ($toapplylist as $ifapply => $ifcfgo) {
459
				if (isset($config['interfaces'][$ifapply]['enable'])) {
460
					interface_bring_down($ifapply, false, $ifcfgo);
461
					interface_configure($ifapply, true);
462
				} else {
463
					interface_bring_down($ifapply, true, $ifcfgo);
464
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
465
					    isset($config['dhcpdv6'][$ifapply]['enable'])) {
466
						services_dhcpd_configure();
467
					}
468
				}
469
			}
470
		}
471
		/* restart snmp so that it binds to correct address */
472
		services_snmpd_configure();
473

    
474
		/* sync filter configuration */
475
		setup_gateways_monitor();
476

    
477
		clear_subsystem_dirty('interfaces');
478

    
479
		filter_configure();
480

    
481
		enable_rrd_graphing();
482

    
483
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
484
			clear_subsystem_dirty('staticroutes');
485
		}
486
	}
487
	@unlink("{$g['tmp_path']}/.interfaces.apply");
488
	header("Location: interfaces.php?if={$if}");
489
	exit;
490
} else if ($_POST && $_POST['enable'] != "yes") {
491
	unset($wancfg['enable']);
492
	if (isset($wancfg['wireless'])) {
493
		interface_sync_wireless_clones($wancfg, false);
494
	}
495
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
496
	mark_subsystem_dirty('interfaces');
497
	if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
498
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
499
	} else {
500
		$toapplylist = array();
501
	}
502
	$toapplylist[$if]['ifcfg'] = $wancfg;
503
	$toapplylist[$if]['ppps'] = $a_ppps;
504
	/* we need to be able remove IP aliases for IPv6 */
505
	file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
506
	header("Location: interfaces.php?if={$if}");
507
	exit;
508
} else if ($_POST) {
509

    
510
	unset($input_errors);
511
	$pconfig = $_POST;
512

    
513
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
514
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
515
	} else {
516
		$pconfig['track6-prefix-id'] = 0;
517
	}
518
	conf_mount_rw();
519

    
520
	/* filter out spaces from descriptions */
521
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
522

    
523
	/* okay first of all, cause we are just hiding the PPPoE HTML
524
	 * fields related to PPPoE resets, we are going to unset $_POST
525
	 * vars, if the reset feature should not be used. Otherwise the
526
	 * data validation procedure below, may trigger a false error
527
	 * message.
528
	 */
529
	if (empty($_POST['pppoe-reset-type'])) {
530
		unset($_POST['pppoe_pr_type']);
531
		unset($_POST['pppoe_resethour']);
532
		unset($_POST['pppoe_resetminute']);
533
		unset($_POST['pppoe_resetdate']);
534
		unset($_POST['pppoe_pr_preset_val']);
535
	}
536
	/* description unique? */
537
	foreach ($ifdescrs as $ifent => $ifdescr) {
538
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
539
			$input_errors[] = gettext("An interface with the specified description already exists.");
540
			break;
541
		}
542
	}
543
	if (is_numeric($_POST['descr'])) {
544
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
545
	}
546
	/* input validation */
547
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
548
		$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.");
549
	}
550
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
551
		$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.");
552
	}
553

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

    
661
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
662
				$input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID.");
663
			} else {
664
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
665
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
666
					$input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range.") .
667
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
668
				} else {
669
					foreach ($ifdescrs as $ifent => $ifdescr) {
670
						if ($if == $ifent) {
671
							continue;
672
						}
673
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
674
						    $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
675
						    $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
676
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
677
						}
678
					}
679
				}
680
			}
681
			break;
682
	}
683

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

    
700
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
701
			if ($_POST['subnet'] < 31) {
702
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
703
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
704
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
705
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
706
				}
707
			}
708

    
709
			foreach ($staticroutes as $route_subnet) {
710
				list($network, $subnet) = explode("/", $route_subnet);
711
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
712
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
713
					break;
714
				}
715
				unset($network, $subnet);
716
			}
717
		}
718
	}
719
	if ($_POST['ipaddrv6']) {
720
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
721
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
722
		} else {
723
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
724
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
725
			}
726
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
727
			if (count($where_ipaddr_configured)) {
728
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
729
				foreach ($where_ipaddr_configured as $subnet_conflict) {
730
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
731
				}
732
				$input_errors[] = $subnet_conflict_text;
733
			}
734

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

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

    
824
		unset($min_mtu, $max_mtu);
825

    
826
		if (stristr($wancfg['if'], "_vlan")) {
827
			$realhwif_array = get_parent_interface($wancfg['if']);
828
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
829
			$parent_realhwif = $realhwif_array[0];
830
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
831
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu'])) {
832
				if ($_POST['mtu'] > intval($config['interfaces'][$parent_if]['mtu'])) {
833
					$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
834
				}
835
			}
836
		} else {
837
			foreach ($config['interfaces'] as $idx => $ifdata) {
838
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
839
					continue;
840
				}
841

    
842
				$realhwif_array = get_parent_interface($ifdata['if']);
843
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
844
				$parent_realhwif = $realhwif_array[0];
845

    
846
				if ($parent_realhwif != $wancfg['if']) {
847
					continue;
848
				}
849

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

    
937
		if ($_POST['passphrase']) {
938
			$passlen = strlen($_POST['passphrase']);
939
			if ($passlen < 8 || $passlen > 63) {
940
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
941
			}
942
		}
943

    
944
		if ($_POST['wpa_enable'] == "yes") {
945
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
946
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
947
			}
948
		}
949
	}
950

    
951
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
952
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
953
	}
954

    
955
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
956
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
957
	}
958

    
959
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
960
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
961
	}
962

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

    
970
		if ($wancfg['ipaddr'] != $_POST['type']) {
971
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
972
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
973
				unset($a_ppps[$pppid]);
974
			} else if ($wancfg['ipaddr'] == "dhcp") {
975
				kill_dhclient_process($wancfg['if']);
976
			}
977
			if ($wancfg['ipaddrv6'] == "dhcp6") {
978
				$pid = find_dhcp6c_process($wancfg['if']);
979
				if ($pid) {
980
					posix_kill($pid, SIGTERM);
981
				}
982
			}
983
		}
984
		$ppp = array();
985
		if ($wancfg['ipaddr'] != "ppp") {
986
			unset($wancfg['ipaddr']);
987
		}
988
		if ($wancfg['ipaddrv6'] != "ppp") {
989
			unset($wancfg['ipaddrv6']);
990
		}
991
		unset($wancfg['subnet']);
992
		unset($wancfg['gateway']);
993
		unset($wancfg['subnetv6']);
994
		unset($wancfg['gatewayv6']);
995
		unset($wancfg['dhcphostname']);
996
		unset($wancfg['dhcprejectfrom']);
997
		unset($wancfg['dhcp6-duid']);
998
		unset($wancfg['dhcp6-ia-pd-len']);
999
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1000
		unset($wancfg['dhcp6prefixonly']);
1001
		unset($wancfg['dhcp6usev4iface']);
1002
		unset($wancfg['track6-interface']);
1003
		unset($wancfg['track6-prefix-id']);
1004
		unset($wancfg['prefix-6rd']);
1005
		unset($wancfg['prefix-6rd-v4plen']);
1006
		unset($wancfg['gateway-6rd']);
1007

    
1008
		unset($wancfg['adv_dhcp_pt_timeout']);
1009
		unset($wancfg['adv_dhcp_pt_retry']);
1010
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1011
		unset($wancfg['adv_dhcp_pt_reboot']);
1012
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1013
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1014

    
1015
		unset($wancfg['adv_dhcp_pt_values']);
1016

    
1017
		unset($wancfg['adv_dhcp_send_options']);
1018
		unset($wancfg['adv_dhcp_request_options']);
1019
		unset($wancfg['adv_dhcp_required_options']);
1020
		unset($wancfg['adv_dhcp_option_modifiers']);
1021

    
1022
		unset($wancfg['adv_dhcp_config_advanced']);
1023
		unset($wancfg['adv_dhcp_config_file_override']);
1024
		unset($wancfg['adv_dhcp_config_file_override_path']);
1025

    
1026
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1027
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1028
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1029
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1030

    
1031
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1032
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1033
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1034
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1035
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1036

    
1037
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1038
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1039
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1040
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1041
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1042

    
1043
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1044
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1045

    
1046
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1047
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1048
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1049
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1050

    
1051
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1052
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1053
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1054
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1055
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1056

    
1057
		unset($wancfg['adv_dhcp6_config_advanced']);
1058
		unset($wancfg['adv_dhcp6_config_file_override']);
1059
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1060

    
1061
		unset($wancfg['pppoe_password']);
1062
		unset($wancfg['pptp_username']);
1063
		unset($wancfg['pptp_password']);
1064
		unset($wancfg['provider']);
1065
		unset($wancfg['ondemand']);
1066
		unset($wancfg['timeout']);
1067
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1068
			unset($wancfg['pppoe']['pppoe-reset-type']);
1069
		}
1070
		unset($wancfg['local']);
1071

    
1072
		unset($wancfg['remote']);
1073
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1074
			if ($wancfg['ipaddr'] != 'ppp') {
1075
				unset($a_ppps[$pppid]['apn']);
1076
				unset($a_ppps[$pppid]['phone']);
1077
				unset($a_ppps[$pppid]['provider']);
1078
				unset($a_ppps[$pppid]['ondemand']);
1079
			}
1080
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1081
				unset($a_ppps[$pppid]['localip']);
1082
				unset($a_ppps[$pppid]['subnet']);
1083
				unset($a_ppps[$pppid]['gateway']);
1084
			}
1085
			if ($wancfg['ipaddr'] != 'pppoe') {
1086
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1087
			}
1088
			if ($wancfg['type'] != $_POST['type']) {
1089
				unset($a_ppps[$pppid]['idletimeout']);
1090
			}
1091
		}
1092

    
1093
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1094
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1095

    
1096
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1097
		switch ($_POST['type']) {
1098
			case "staticv4":
1099
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1100
				$wancfg['subnet'] = $_POST['subnet'];
1101
				if ($_POST['gateway'] != "none") {
1102
					$wancfg['gateway'] = $_POST['gateway'];
1103
				}
1104
				break;
1105
			case "dhcp":
1106
				$wancfg['ipaddr'] = "dhcp";
1107
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1108
				$wancfg['alias-address'] = $_POST['alias-address'];
1109
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1110
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1111

    
1112
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1113
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1114
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1115
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1116
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1117
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1118

    
1119
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1120

    
1121
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1122
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1123
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1124
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1125

    
1126
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1127
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1128
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1129

    
1130
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1131
				if ($gateway_item) {
1132
					$a_gateways[] = $gateway_item;
1133
				}
1134
				break;
1135
			case "ppp":
1136
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1137
				$a_ppps[$pppid]['type'] = $_POST['type'];
1138
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1139
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1140
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1141
				if ($_POST['ppp_password'] != DMYPWD) {
1142
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1143
				}
1144
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1145
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1146
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1147
				$wancfg['ipaddr'] = $_POST['type'];
1148
				break;
1149

    
1150
			case "pppoe":
1151
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1152
				$a_ppps[$pppid]['type'] = $_POST['type'];
1153
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1154
				if (isset($_POST['ppp_port'])) {
1155
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1156
				} else {
1157
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1158
				}
1159
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1160
				if ($_POST['pppoe_password'] != DMYPWD) {
1161
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1162
				}
1163
				if (!empty($_POST['provider'])) {
1164
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1165
				} else {
1166
					$a_ppps[$pppid]['provider'] = true;
1167
				}
1168
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1169
				if (!empty($_POST['pppoe_idletimeout'])) {
1170
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1171
				} else {
1172
					unset($a_ppps[$pppid]['idletimeout']);
1173
				}
1174

    
1175
				if (!empty($_POST['pppoe-reset-type'])) {
1176
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1177
				} else {
1178
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1179
				}
1180
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1181
				$wancfg['ipaddr'] = $_POST['type'];
1182
				if ($gateway_item) {
1183
					$a_gateways[] = $gateway_item;
1184
				}
1185

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

    
1248
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1249
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1250
				}
1251
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1252
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1253
				}
1254
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1255
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1256
				}
1257
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1258
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1259
				}
1260

    
1261
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1262
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1263
				}
1264
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1265
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1266
				}
1267
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1268
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1269
				}
1270
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1271
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1272
				}
1273
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1274
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1275
				}
1276

    
1277
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1278
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1279
				}
1280
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1281
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1282
				}
1283
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1284
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1285
				}
1286
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1287
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1288
				}
1289
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1290
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1291
				}
1292

    
1293
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1294
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1295
				}
1296
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1297
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1298
				}
1299

    
1300
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1301
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1302
				}
1303
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1304
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1305
				}
1306
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1307
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1308
				}
1309
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1310
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1311
				}
1312

    
1313
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1314
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1317
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1320
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1321
				}
1322
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1323
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1324
				}
1325
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1326
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1327
				}
1328

    
1329
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1330
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1333
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1334
				}
1335
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1336
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1337
				}
1338

    
1339
				if ($gateway_item) {
1340
					$a_gateways[] = $gateway_item;
1341
				}
1342
				break;
1343
			case "6rd":
1344
				$wancfg['ipaddrv6'] = "6rd";
1345
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1346
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1347
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1348
				if ($gateway_item) {
1349
					$a_gateways[] = $gateway_item;
1350
				}
1351
				break;
1352
			case "6to4":
1353
				$wancfg['ipaddrv6'] = "6to4";
1354
				break;
1355
			case "track6":
1356
				$wancfg['ipaddrv6'] = "track6";
1357
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1358
				if ($_POST['track6-prefix-id--hex'] === "") {
1359
					$wancfg['track6-prefix-id'] = 0;
1360
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1361
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1362
				} else {
1363
					$wancfg['track6-prefix-id'] = 0;
1364
				}
1365
				break;
1366
			case "none":
1367
				break;
1368
		}
1369
		handle_pppoe_reset($_POST);
1370

    
1371
		if ($_POST['blockpriv'] == "yes") {
1372
			$wancfg['blockpriv'] = true;
1373
		} else {
1374
			unset($wancfg['blockpriv']);
1375
		}
1376
		if ($_POST['blockbogons'] == "yes") {
1377
			$wancfg['blockbogons'] = true;
1378
		} else {
1379
			unset($wancfg['blockbogons']);
1380
		}
1381
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1382
		if (empty($_POST['mtu'])) {
1383
			unset($wancfg['mtu']);
1384
		} else {
1385
			$wancfg['mtu'] = $_POST['mtu'];
1386
		}
1387
		if (empty($_POST['mss'])) {
1388
			unset($wancfg['mss']);
1389
		} else {
1390
			$wancfg['mss'] = $_POST['mss'];
1391
		}
1392
		if (empty($_POST['mediaopt'])) {
1393
			unset($wancfg['media']);
1394
			unset($wancfg['mediaopt']);
1395
		} else {
1396
			$mediaopts = explode(' ', $_POST['mediaopt']);
1397
			if ($mediaopts[0] != '') {
1398
				$wancfg['media'] = $mediaopts[0];
1399
			}
1400
			if ($mediaopts[1] != '') {
1401
				$wancfg['mediaopt'] = $mediaopts[1];
1402
			} else {
1403
				unset($wancfg['mediaopt']);
1404
			}
1405
		}
1406
		if (isset($wancfg['wireless'])) {
1407
			handle_wireless_post();
1408
		}
1409

    
1410
		conf_mount_ro();
1411
		write_config();
1412

    
1413
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1414
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1415
		} else {
1416
			$toapplylist = array();
1417
		}
1418
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1419
		$toapplylist[$if]['ppps'] = $old_ppps;
1420
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1421

    
1422
		mark_subsystem_dirty('interfaces');
1423

    
1424
		/* regenerate cron settings/crontab file */
1425
		configure_cron();
1426

    
1427
		header("Location: interfaces.php?if={$if}");
1428
		exit;
1429
	}
1430

    
1431
} // end if ($_POST)
1432

    
1433
function handle_wireless_post() {
1434
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1435
	if (!is_array($wancfg['wireless'])) {
1436
		$wancfg['wireless'] = array();
1437
	}
1438
	$wancfg['wireless']['standard'] = $_POST['standard'];
1439
	$wancfg['wireless']['mode'] = $_POST['mode'];
1440
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1441
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1442
	$wancfg['wireless']['channel'] = $_POST['channel'];
1443
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1444
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1445
	$wancfg['wireless']['distance'] = $_POST['distance'];
1446
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1447
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1448
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1449
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1450
		foreach ($wl_countries_attr as $wl_country) {
1451
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1452
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1453
				break;
1454
			}
1455
		}
1456
	}
1457
	if (!is_array($wancfg['wireless']['wpa'])) {
1458
		$wancfg['wireless']['wpa'] = array();
1459
	}
1460
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1461
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1462
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1463
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1464
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1465
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1466
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1467
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1468
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1469
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1470
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1471
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1472
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1473
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1474

    
1475
	if ($_POST['persistcommonwireless'] == "yes") {
1476
		if (!is_array($config['wireless'])) {
1477
			$config['wireless'] = array();
1478
		}
1479
		if (!is_array($config['wireless']['interfaces'])) {
1480
			$config['wireless']['interfaces'] = array();
1481
		}
1482
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1483
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1484
		}
1485
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1486
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1487
	}
1488
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1489
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1490
	} else if (isset($wancfg['wireless']['diversity'])) {
1491
		unset($wancfg['wireless']['diversity']);
1492
	}
1493
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1494
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1495
	} else if (isset($wancfg['wireless']['txantenna'])) {
1496
		unset($wancfg['wireless']['txantenna']);
1497
	}
1498
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1499
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1500
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1501
		unset($wancfg['wireless']['rxantenna']);
1502
	}
1503
	if ($_POST['hidessid_enable'] == "yes") {
1504
		$wancfg['wireless']['hidessid']['enable'] = true;
1505
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1506
		unset($wancfg['wireless']['hidessid']['enable']);
1507
	}
1508
	if ($_POST['mac_acl_enable'] == "yes") {
1509
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1510
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1511
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1512
	}
1513
	if ($_POST['rsn_preauth'] == "yes") {
1514
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1515
	} else {
1516
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1517
	}
1518
	if ($_POST['ieee8021x'] == "yes") {
1519
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1520
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1521
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1522
	}
1523
	if ($_POST['wpa_strict_rekey'] == "yes") {
1524
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1525
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1526
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1527
	}
1528
	if ($_POST['debug_mode'] == "yes") {
1529
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1530
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1531
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1532
	}
1533
	if ($_POST['wpa_enable'] == "yes") {
1534
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1535
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1536
		unset($wancfg['wireless']['wpa']['enable']);
1537
	}
1538

    
1539
	if ($_POST['wme_enable'] == "yes") {
1540
		if (!is_array($wancfg['wireless']['wme'])) {
1541
			$wancfg['wireless']['wme'] = array();
1542
		}
1543
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1544
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1545
		unset($wancfg['wireless']['wme']['enable']);
1546
	}
1547
	if ($_POST['puremode'] == "11g") {
1548
		if (!is_array($wancfg['wireless']['pureg'])) {
1549
			$wancfg['wireless']['pureg'] = array();
1550
		}
1551
		$wancfg['wireless']['pureg']['enable'] = true;
1552
	} else if ($_POST['puremode'] == "11n") {
1553
		if (!is_array($wancfg['wireless']['puren'])) {
1554
			$wancfg['wireless']['puren'] = array();
1555
		}
1556
		$wancfg['wireless']['puren']['enable'] = true;
1557
	} else {
1558
		if (isset($wancfg['wireless']['pureg'])) {
1559
			unset($wancfg['wireless']['pureg']);
1560
		}
1561
		if (isset($wancfg['wireless']['puren'])) {
1562
			unset($wancfg['wireless']['puren']);
1563
		}
1564
	}
1565
	if ($_POST['apbridge_enable'] == "yes") {
1566
		if (!is_array($wancfg['wireless']['apbridge'])) {
1567
			$wancfg['wireless']['apbridge'] = array();
1568
		}
1569
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1570
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1571
		unset($wancfg['wireless']['apbridge']['enable']);
1572
	}
1573
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1574
		if (!is_array($wancfg['wireless']['turbo'])) {
1575
			$wancfg['wireless']['turbo'] = array();
1576
		}
1577
		$wancfg['wireless']['turbo']['enable'] = true;
1578
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1579
		unset($wancfg['wireless']['turbo']['enable']);
1580
	}
1581

    
1582
	interface_sync_wireless_clones($wancfg, true);
1583
}
1584

    
1585
function check_wireless_mode() {
1586
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1587

    
1588
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1589
		return;
1590
	}
1591

    
1592
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1593
		$clone_count = 1;
1594
	} else {
1595
		$clone_count = 0;
1596
	}
1597

    
1598
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1599
		foreach ($config['wireless']['clone'] as $clone) {
1600
			if ($clone['if'] == $wlanbaseif) {
1601
				$clone_count++;
1602
			}
1603
		}
1604
	}
1605

    
1606
	if ($clone_count > 1) {
1607
		$old_wireless_mode = $wancfg['wireless']['mode'];
1608
		$wancfg['wireless']['mode'] = $_POST['mode'];
1609
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1610
			$input_errors[] = sprintf(gettext("Unable to change mode to %s.	 You may already have the maximum number of wireless clones supported in this mode."), $wlan_modes[$wancfg['wireless']['mode']]);
1611
		} else {
1612
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1613
		}
1614
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1615
	}
1616
}
1617

    
1618
// Find all possible media options for the interface
1619
$mediaopts_list = array();
1620
$intrealname = $config['interfaces'][$if]['if'];
1621
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1622
foreach ($mediaopts as $mediaopt) {
1623
	preg_match("/media (.*)/", $mediaopt, $matches);
1624
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1625
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1626
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1627
	} else {
1628
		// there is only media like "media 1000baseT"
1629
		array_push($mediaopts_list, $matches[1]);
1630
	}
1631
}
1632

    
1633
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1634
$shortcut_section = "interfaces";
1635

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

    
1639
// Get the MAC address
1640
$ip = $_SERVER['REMOTE_ADDR'];
1641
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1642
$mymac = str_replace("\n", "", $mymac);
1643

    
1644
function build_mediaopts_list() {
1645
	global $mediaopts_list;
1646

    
1647
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1648
			 " " =>	 "------- Media Supported by this interface -------"
1649
			];
1650

    
1651
	foreach ($mediaopts_list as $mediaopt) {
1652
		$list[$mediaopt] = $mediaopt;
1653
	}
1654

    
1655
	return($list);
1656
}
1657

    
1658
function build_gateway_list() {
1659
	global $a_gateways, $if;
1660

    
1661
	$list = array("none" => "None");
1662
	foreach ($a_gateways as $gateway) {
1663
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1664
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1665
		}
1666
	}
1667

    
1668
	return($list);
1669
}
1670

    
1671
function build_gatewayv6_list() {
1672
	global $a_gateways, $if;
1673

    
1674
	$list = array("none" => "None");
1675
	foreach ($a_gateways as $gateway) {
1676
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1677
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1678
		}
1679
	}
1680

    
1681
	return($list);
1682
}
1683

    
1684
include("head.inc");
1685

    
1686
if ($input_errors) {
1687
	print_input_errors($input_errors);
1688
}
1689

    
1690
if (is_subsystem_dirty('interfaces')) {
1691
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1692
					  gettext("You must apply the changes in order for them to take effect. Don't forget to adjust the DHCP Server range if needed after applying."));
1693
}
1694

    
1695
if ($savemsg) {
1696
	print_info_box($savemsg, 'success');
1697
}
1698

    
1699

    
1700
$form = new Form(new Form_Button(
1701
	'Submit',
1702
	gettext("Save")
1703
));
1704

    
1705
$section = new Form_Section('General configuration');
1706

    
1707
$section->addInput(new Form_Checkbox(
1708
	'enable',
1709
	'Enable',
1710
	'Enable interface',
1711
	$pconfig['enable'],
1712
	'yes'
1713
));
1714

    
1715
$section->addInput(new Form_Input(
1716
	'descr',
1717
	'Description',
1718
	'text',
1719
	$pconfig['descr']
1720
))->setHelp('Enter a description (name) for the interface here.');
1721

    
1722
$section->addInput(new Form_Select(
1723
	'type',
1724
	'IPv4 Configuration Type',
1725
	$pconfig['type'],
1726
	$types4
1727
));
1728

    
1729
$section->addInput(new Form_Select(
1730
	'type6',
1731
	'IPv6 Configuration Type',
1732
	$pconfig['type6'],
1733
	$types6
1734
));
1735

    
1736
$macaddress = new Form_Input(
1737
	'spoofmac',
1738
	'MAC Address',
1739
	'text',
1740
	$pconfig['spoofmac'],
1741
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1742
);
1743

    
1744
$btnmymac = new Form_Button(
1745
	'btnmymac',
1746
	'Copy My MAC'
1747
	);
1748

    
1749
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1750

    
1751
$group = new Form_Group('MAC controls');
1752
$group->add($macaddress);
1753
// $group->add($btnmymac);
1754
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1755
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1756
$section->add($group);
1757

    
1758
$section->addInput(new Form_Input(
1759
	'mtu',
1760
	'MTU',
1761
	'number',
1762
	$pconfig['mtu']
1763
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1764
			'This is typically 1500 bytes but can vary in some circumstances.');
1765

    
1766
$section->addInput(new Form_Input(
1767
	'mss',
1768
	'MSS',
1769
	'number',
1770
	$pconfig['mss']
1771
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1772
			'header size) will be in effect.');
1773

    
1774
if (count($mediaopts_list) > 0) {
1775
	$section->addInput(new Form_Select(
1776
		'mediaopt',
1777
		'Speed and Duplex',
1778
		rtrim($mediaopt_from_config),
1779
		build_mediaopts_list()
1780
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1781
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1782
}
1783

    
1784
$form->add($section);
1785

    
1786
$section = new Form_Section('Static IPv4 configuration');
1787
$section->addClass('staticv4');
1788

    
1789
$section->addInput(new Form_IpAddress(
1790
	'ipaddr',
1791
	'IPv4 Address',
1792
	$pconfig['ipaddr']
1793
))->addMask('subnet', $pconfig['subnet'], 32);
1794

    
1795
$group = new Form_Group('IPv4 Upstream gateway');
1796

    
1797
$group->add(new Form_Select(
1798
	'gateway',
1799
	'IPv4 Upstream Gateway',
1800
	$pconfig['gateway'],
1801
	build_gateway_list()
1802
));
1803

    
1804
$group->add(new Form_Button(
1805
	'addgw',
1806
	'Add a new gateway'
1807
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1808

    
1809
$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 />' .
1810
				'On local LANs the upstream gateway should be "none".' .
1811
				gettext('You can manage gateways by ') . '<a target="_blank" href="system_gateways.php">' . gettext(" clicking here") . '</a>');
1812

    
1813
$section->add($group);
1814

    
1815
$form->add($section);
1816

    
1817
$section = new Form_Section('Static IPv6 configuration');
1818
$section->addClass('staticv6');
1819

    
1820
$section->addInput(new Form_IpAddress(
1821
	'ipaddrv6',
1822
	'IPv6 address',
1823
	$pconfig['ipaddrv6']
1824
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1825

    
1826
$group = new Form_Group('IPv6 Upstream gateway');
1827

    
1828
$group->add(new Form_Select(
1829
	'gatewayv6',
1830
	'IPv6 Upstream Gateway',
1831
	$pconfig['gatewayv6'],
1832
	build_gatewayv6_list()
1833
));
1834

    
1835
$group->add(new Form_Button(
1836
	'addgw6',
1837
	'Add a new gateway'
1838
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1839

    
1840
$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 />' .
1841
				'On local LANs the upstream gateway should be "none". ');
1842

    
1843
$section->add($group);
1844
$form->add($section);
1845

    
1846
// Add new gateway modal pop-up for IPv6
1847
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1848

    
1849
$modal->addInput(new Form_Checkbox(
1850
	'defaultgw6',
1851
	'Default',
1852
	'Default gateway',
1853
	($if == "wan" || $if == "WAN")
1854
));
1855

    
1856
$modal->addInput(new Form_Input(
1857
	'name6',
1858
	'Gateway name',
1859
	'text',
1860
	$wancfg['descr'] . "GWv6"
1861
));
1862

    
1863
$modal->addInput(new Form_IpAddress(
1864
	'gatewayip6',
1865
	'Gateway IPv6',
1866
	null
1867
));
1868

    
1869
$modal->addInput(new Form_Input(
1870
	'gatewaydescr6',
1871
	'Description',
1872
	'text'
1873
));
1874

    
1875
$btnaddgw6 = new Form_Button(
1876
	'add6',
1877
	'Add'
1878
);
1879

    
1880
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1881

    
1882
$btncnxgw6 = new Form_Button(
1883
	'cnx6',
1884
	'Cancel'
1885
);
1886

    
1887
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1888

    
1889
$modal->addInput(new Form_StaticText(
1890
	null,
1891
	$btnaddgw6 . $btncnxgw6
1892
));
1893

    
1894
$form->add($modal);
1895

    
1896
// ==== DHCP client configuration =============================
1897

    
1898
$section = new Form_Section('DHCP client configuration');
1899
$section->addClass('dhcp');
1900

    
1901
$group = new Form_Group('Options');
1902

    
1903
$group->add(new Form_Checkbox(
1904
	'dhcpadv',
1905
	null,
1906
	'Show DHCP advanced options',
1907
	false
1908
));
1909

    
1910
$group->add(new Form_Checkbox(
1911
	'dhcpovr',
1912
	null,
1913
	'Config file override',
1914
	false
1915
));
1916

    
1917
$section->add($group);
1918

    
1919
$section->addInput(new Form_Input(
1920
	'dhcphostname',
1921
	'Hostname',
1922
	'text',
1923
	$pconfig['dhcphostname']
1924
))->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).');
1925

    
1926
$section->addInput(new Form_IpAddress(
1927
	'alias-address',
1928
	'Alias IPv4 address',
1929
	$pconfig['alias-address']
1930
))->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.');
1931

    
1932
$section->addInput(new Form_Input(
1933
	'dhcprejectfrom',
1934
	'Reject leases from',
1935
	'text',
1936
	$pconfig['dhcprejectfrom']
1937
))->setHelp('If there is a certain upstream DHCP server that should be ignored, place the IP address or subnet of the DHCP server to be ignored here. ' .
1938
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1939

    
1940
$group = new Form_Group('Protocol timing');
1941
$group->addClass('dhcpadvanced');
1942

    
1943
$group->add(new Form_Input(
1944
	'adv_dhcp_pt_timeout',
1945
	null,
1946
	'number',
1947
	$pconfig['adv_dhcp_pt_timeout']
1948
))->setHelp('Timeout');
1949

    
1950
$group->add(new Form_Input(
1951
	'adv_dhcp_pt_retry',
1952
	null,
1953
	'number',
1954
	$pconfig['adv_dhcp_pt_retry']
1955
))->setHelp('Retry');
1956

    
1957
$group->add(new Form_Input(
1958
	'adv_dhcp_pt_select_timeout',
1959
	null,
1960
	'number',
1961
	$pconfig['adv_dhcp_pt_select_timeout'],
1962
	['min' => 0]
1963
))->setHelp('Select timeout');
1964

    
1965
$group->add(new Form_Input(
1966
	'adv_dhcp_pt_reboot',
1967
	null,
1968
	'number',
1969
	$pconfig['adv_dhcp_pt_reboot']
1970
))->setHelp('Reboot');
1971

    
1972
$group->add(new Form_Input(
1973
	'adv_dhcp_pt_backoff_cutoff',
1974
	null,
1975
	'number',
1976
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1977
))->setHelp('Backoff cutoff');
1978

    
1979
$group->add(new Form_Input(
1980
	'adv_dhcp_pt_initial_interval',
1981
	null,
1982
	'number',
1983
	$pconfig['adv_dhcp_pt_initial_interval']
1984
))->setHelp('Initial interval');
1985

    
1986
$section->add($group);
1987

    
1988
$group = new Form_Group('Presets');
1989
$group->addClass('dhcpadvanced');
1990

    
1991
$group->add(new Form_Checkbox(
1992
	'adv_dhcp_pt_values',
1993
	null,
1994
	'FreeBSD default',
1995
	null,
1996
	'DHCP'
1997
))->displayAsRadio();
1998

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

    
2007
$group->add(new Form_Checkbox(
2008
	'adv_dhcp_pt_values',
2009
	null,
2010
	'pfSense Default',
2011
	null,
2012
	'pfSense'
2013
))->displayAsRadio();
2014

    
2015
$group->add(new Form_Checkbox(
2016
	'adv_dhcp_pt_values',
2017
	null,
2018
	'Saved Cfg',
2019
	null,
2020
	'SavedCfg'
2021
))->displayAsRadio();
2022

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

    
2026
$section->add($group);
2027

    
2028
$section->addInput(new Form_Input(
2029
	'adv_dhcp_config_file_override_path',
2030
	'Config file override',
2031
	'text',
2032
	$pconfig['adv_dhcp_config_file_override_path']
2033
))->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2034
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2035
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2036
			'Some ISPs may require certain options be or not be sent.');
2037

    
2038
$form->add($section);
2039

    
2040
$section = new Form_Section('Lease Requirements and Requests');
2041
$section->addClass('dhcpadvanced');
2042

    
2043
$section->addInput(new Form_Input(
2044
	'adv_dhcp_send_options',
2045
	'Send options',
2046
	'text',
2047
	$pconfig['adv_dhcp_send_options']
2048
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2049
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2050
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2051
			'Some ISPs may require certain options be or not be sent.');
2052

    
2053
$section->addInput(new Form_Input(
2054
	'adv_dhcp_request_options',
2055
	'Request options',
2056
	'text',
2057
	$pconfig['adv_dhcp_request_options']
2058
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2059
			'Some ISPs may require certain options be or not be requested.');
2060

    
2061
$section->addInput(new Form_Input(
2062
	'adv_dhcp_required_options',
2063
	'Require options',
2064
	'text',
2065
	$pconfig['adv_dhcp_required_options']
2066
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2067

    
2068
$section->addInput(new Form_Input(
2069
	'adv_dhcp_option_modifiers',
2070
	'Option modifiers',
2071
	'text',
2072
	$pconfig['adv_dhcp_option_modifiers']
2073
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2074
			'modifiers: (default, supersede, prepend, append)');
2075

    
2076
$form->add($section);
2077

    
2078
// DHCP6 client config
2079

    
2080
$section = new Form_Section('DHCP6 client configuration');
2081
$section->addClass('dhcp6');
2082

    
2083
$section->addInput(new Form_Checkbox(
2084
	'dhcp6adv',
2085
	'Advanced',
2086
	'Show DHCPv6 advanced options',
2087
	$pconfig['adv_dhcp6_config_advanced']
2088
));
2089

    
2090
$section->addInput(new Form_Checkbox(
2091
	'adv_dhcp6_config_file_override',
2092
	'Config file override',
2093
	'Override the configuration from this file',
2094
	$pconfig['adv_dhcp6_config_file_override']
2095
));
2096

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

    
2104
$section->addInput(new Form_Checkbox(
2105
	'dhcp6prefixonly',
2106
	'Request only an IPv6 prefix',
2107
	'Only request an IPv6 prefix, do not request an IPv6 address',
2108
	$pconfig['dhcp6prefixonly']
2109
));
2110

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

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

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

    
2135
$form->add($section);
2136

    
2137
// DHCP6 client config - Advanced
2138

    
2139
$section = new Form_Section('Advanced DHCP6 client configuration');
2140
$section->addClass('dhcp6advanced');
2141

    
2142
$section->addInput(new Form_Checkbox(
2143
	'adv_dhcp6_interface_statement_information_only_enable',
2144
	'Information only',
2145
	null,
2146
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2147
));
2148

    
2149
$section->addInput(new Form_Input(
2150
	'adv_dhcp6_interface_statement_send_options',
2151
	'Send options',
2152
	'text',
2153
	$pconfig['adv_dhcp6_interface_statement_send_options']
2154
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2155
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2156
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2157
			'Some DHCP services may require certain options be or not be sent.');
2158

    
2159
$section->addInput(new Form_Input(
2160
	'adv_dhcp6_interface_statement_request_options',
2161
	'Request Options',
2162
	'text',
2163
	$pconfig['adv_dhcp6_interface_statement_request_options']
2164
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2165
			'Some DHCP services may require certain options be or not be requested.');
2166

    
2167
$section->addInput(new Form_Input(
2168
	'adv_dhcp6_interface_statement_script',
2169
	'Scripts',
2170
	'text',
2171
	$pconfig['adv_dhcp6_interface_statement_script']
2172
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2173
			'[/[dirname/[.../]]filename[.ext]].');
2174

    
2175
$group = new Form_Group('Identity Association Statement');
2176

    
2177
$group->add(new Form_Checkbox(
2178
	'adv_dhcp6_id_assoc_statement_address_enable',
2179
	null,
2180
	'Non-Temporary Address Allocation',
2181
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2182
));
2183

    
2184
$group->add(new Form_Input(
2185
	'adv_dhcp6_id_assoc_statement_address_id',
2186
	null,
2187
	'text',
2188
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2189
))->sethelp('id-assoc na ID');
2190

    
2191
$group->add(new Form_IpAddress(
2192
	'adv_dhcp6_id_assoc_statement_address',
2193
	null,
2194
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2195
))->sethelp('IPv6 address');
2196

    
2197
$group->add(new Form_Input(
2198
	'adv_dhcp6_id_assoc_statement_address_pltime',
2199
	null,
2200
	'text',
2201
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2202
))->sethelp('pltime');
2203

    
2204
$group->add(new Form_Input(
2205
	'adv_dhcp6_id_assoc_statement_address_vltime',
2206
	null,
2207
	'text',
2208
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2209
))->sethelp('vltime');
2210

    
2211
$section->add($group);
2212

    
2213
// Prefix delegation
2214
$group = new Form_Group('');
2215

    
2216
$group->add(new Form_Checkbox(
2217
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2218
	null,
2219
	'Prefix Delegation ',
2220
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2221
));
2222

    
2223
$group->add(new Form_Input(
2224
	'adv_dhcp6_id_assoc_statement_prefix_id',
2225
	null,
2226
	'text',
2227
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2228
))->sethelp('id-assoc pd ID');
2229

    
2230
$group->add(new Form_IpAddress(
2231
	'adv_dhcp6_id_assoc_statement_prefix',
2232
	null,
2233
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2234
))->sethelp('IPv6 prefix');
2235

    
2236
$group->add(new Form_Input(
2237
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2238
	null,
2239
	'text',
2240
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2241
))->sethelp('pltime');
2242

    
2243
$group->add(new Form_Input(
2244
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2245
	null,
2246
	'text',
2247
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2248
))->sethelp('vltime');
2249

    
2250
$section->add($group);
2251

    
2252
$group = new Form_Group('Prefix interface statement');
2253

    
2254
$group->add(new Form_Input(
2255
	'adv_dhcp6_prefix_interface_statement_sla_id',
2256
	null,
2257
	'text',
2258
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2259
))->sethelp('Prefix Interface sla-id');
2260

    
2261
$group->add(new Form_Input(
2262
	'adv_dhcp6_prefix_interface_statement_sla_len',
2263
	null,
2264
	'text',
2265
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2266
))->sethelp('sla-len');
2267

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

    
2270
$group = new Form_Group('Authentication statement');
2271

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

    
2279
$group->add(new Form_Input(
2280
	'adv_dhcp6_authentication_statement_protocol',
2281
	null,
2282
	'text',
2283
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2284
))->sethelp('Protocol');
2285

    
2286
$group->add(new Form_Input(
2287
	'adv_dhcp6_authentication_statement_algorithm',
2288
	null,
2289
	'text',
2290
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2291
))->sethelp('Algorithm');
2292

    
2293
$group->add(new Form_Input(
2294
	'adv_dhcp6_authentication_statement_rdm',
2295
	null,
2296
	'text',
2297
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2298
))->sethelp('RDM');
2299

    
2300
$section->add($group);
2301

    
2302
$group = new Form_Group('Keyinfo statement');
2303

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

    
2311
$group->add(new Form_Input(
2312
	'adv_dhcp6_key_info_statement_realm',
2313
	null,
2314
	'text',
2315
	$pconfig['adv_dhcp6_key_info_statement_realm']
2316
))->sethelp('Realm');
2317

    
2318
$section->add($group);
2319

    
2320
$group = new Form_Group('');
2321

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

    
2329
$group->add(new Form_Input(
2330
	'adv_dhcp6_key_info_statement_secret',
2331
	null,
2332
	'text',
2333
	$pconfig['adv_dhcp6_key_info_statement_secret']
2334
))->sethelp('Secret');
2335

    
2336
$group->add(new Form_Input(
2337
	'adv_dhcp6_key_info_statement_expire',
2338
	null,
2339
	'text',
2340
	$pconfig['adv_dhcp6_key_info_statement_expire']
2341
))->sethelp('Expire');
2342

    
2343
$section->add($group);
2344

    
2345
$form->add($section);
2346

    
2347
$section = new Form_Section('6RD Configuration');
2348
$section->addClass('_6rd');
2349

    
2350
$section->addInput(new Form_Input(
2351
	'prefix-6rd',
2352
	'6RD Prefix',
2353
	'text',
2354
	$pconfig['prefix-6rd']
2355
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2356

    
2357
$section->addInput(new Form_Input(
2358
	'gateway-6rd',
2359
	'6RD Border relay',
2360
	'text',
2361
	$pconfig['gateway-6rd']
2362
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2363

    
2364
$section->addInput(new Form_Select(
2365
	'prefix-6rd-v4plen',
2366
	'6RD IPv4 Prefix length',
2367
	$pconfig['prefix-6rd-v4plen'],
2368
	array_combine(range(0, 32), range(0, 32))
2369
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means we embed the entire IPv4 address in the 6RD prefix.');
2370

    
2371
$form->add($section);
2372

    
2373
// Track IPv6 ointerface section
2374
$section = new Form_Section('Track IPv6 Interface');
2375
$section->addClass('track6');
2376

    
2377
function build_ipv6interface_list() {
2378
	global $config, $section;
2379

    
2380
	$list = array('' => '');
2381

    
2382
	$interfaces = get_configured_interface_with_descr(false, true);
2383
	$dynv6ifs = array();
2384

    
2385
	foreach ($interfaces as $iface => $ifacename) {
2386
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2387
			case "6to4":
2388
			case "6rd":
2389
			case "dhcp6":
2390
				$dynv6ifs[$iface] = array(
2391
					'name' => $ifacename,
2392
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2393
				);
2394
				break;
2395
			default:
2396
				continue;
2397
		}
2398
	}
2399

    
2400
	foreach ($dynv6ifs as $iface => $ifacedata) {
2401
		$list[$iface] = $ifacedata['name'];
2402

    
2403
		$section->addInput(new Form_Input(
2404
			'ipv6-num-prefix-ids-' . $iface,
2405
			null,
2406
			'hidden',
2407
			$ifacedata['ipv6_num_prefix_ids']
2408
		));
2409
	}
2410

    
2411
	return($list);
2412
}
2413

    
2414
$section->addInput(new Form_Select(
2415
	'track6-interface',
2416
	'IPv6 Interface',
2417
	$pconfig['track6-interface'],
2418
	build_ipv6interface_list()
2419
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2420

    
2421
if ($pconfig['track6-prefix-id'] == "") {
2422
	$pconfig['track6-prefix-id'] = 0;
2423
}
2424

    
2425
$section->addInput(new Form_Input(
2426
	'track6-prefix-id--hex' . $iface,
2427
	'IPv6 Prefix ID',
2428
	'text',
2429
	sprintf("%x", $pconfig['track6-prefix-id'])
2430
))->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.');
2431

    
2432
$section->addInput(new Form_Input(
2433
	'track6-prefix-id-max' . $iface,
2434
	null,
2435
	'hidden',
2436
	0
2437
));
2438

    
2439
$form->add($section);
2440

    
2441
/// PPP section
2442

    
2443
$section = new Form_Section('PPP Configuration');
2444
$section->addClass('ppp');
2445

    
2446
$section->addInput(new Form_Select(
2447
	'country',
2448
	'Country',
2449
	$pconfig['country'],
2450
	[]
2451
));
2452

    
2453
$section->addInput(new Form_Select(
2454
	'provider_list',
2455
	'Provider',
2456
	$pconfig['provider_list'],
2457
	[]
2458
));
2459

    
2460
$section->addInput(new Form_Select(
2461
	'providerplan',
2462
	'Plan',
2463
	$pconfig['providerplan'],
2464
	[]
2465
))->setHelp('Select to fill in data for your service provider.');
2466

    
2467
$section->addInput(new Form_Input(
2468
	'ppp_username',
2469
	'Username',
2470
	'text',
2471
	$pconfig['ppp_username']
2472
));
2473

    
2474
$section->addPassword(new Form_Input(
2475
	'ppp_password',
2476
	'Password',
2477
	'password',
2478
	$pconfig['ppp_password']
2479
));
2480

    
2481
$section->addInput(new Form_Input(
2482
	'phone',
2483
	'Phone number',
2484
	'text',
2485
	$pconfig['phone']
2486
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2487

    
2488
$section->addInput(new Form_Input(
2489
	'apn',
2490
	'Access Point Name',
2491
	'text',
2492
	$pconfig['apn']
2493
));
2494

    
2495

    
2496
function build_port_list() {
2497
	$list = array("" => "None");
2498

    
2499
	$portlist = glob("/dev/cua*");
2500
	$modems	  = glob("/dev/modem*");
2501
	$portlist = array_merge($portlist, $modems);
2502

    
2503
	foreach ($portlist as $port) {
2504
		if (preg_match("/\.(lock|init)$/", $port)) {
2505
			continue;
2506
		}
2507

    
2508
	$list[trim($port)] = $port;
2509
	}
2510

    
2511
	return($list);
2512
}
2513

    
2514
$section->addInput(new Form_Select(
2515
	'port',
2516
	"Modem port",
2517
	$pconfig['port'],
2518
	build_port_list()
2519
));
2520

    
2521
$section->addInput(new Form_Button(
2522
	'btnadvppp',
2523
	'Advanced PPP',
2524
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2525
))->setHelp('Create a new PPP configuration');
2526

    
2527
$form->add($section);
2528

    
2529
// PPPoE configuration
2530
$section = new Form_Section('PPPoE Configuration');
2531
$section->addClass('pppoe');
2532

    
2533
$section->addInput(new Form_Input(
2534
	'pppoe_username',
2535
	'Username',
2536
	'text',
2537
	$pconfig['pppoe_username']
2538
));
2539

    
2540
$section->addPassword(new Form_Input(
2541
	'pppoe_password',
2542
	'Password',
2543
	'password',
2544
	$pconfig['pppoe_password']
2545
));
2546

    
2547
$section->addInput(new Form_Input(
2548
	'provider',
2549
	'Service name',
2550
	'text',
2551
	$pconfig['provider']
2552
))->setHelp('This field can usually be left empty');
2553

    
2554
$section->addInput(new Form_Checkbox(
2555
	'pppoe_dialondemand',
2556
	'Dial on demand',
2557
	'Enable Dial-On-Demand mode ',
2558
	$pconfig['pppoe_dialondemand'],
2559
	'enable'
2560
));
2561

    
2562
$section->addInput(new Form_Input(
2563
	'pppoe_idletimeout',
2564
	'Idle timeout',
2565
	'number',
2566
	$pconfig['pppoe_idletimeout'],
2567
	[min => 0]
2568
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2569
			'An idle timeout of zero disables this feature.');
2570

    
2571
$section->addInput(new Form_Select(
2572
	'pppoe-reset-type',
2573
	'Periodic reset',
2574
	$pconfig['pppoe-reset-type'],
2575
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2576
))->setHelp('Select a reset timing type');
2577

    
2578
$group = new Form_Group('Custom reset');
2579
$group->addClass('pppoecustom');
2580

    
2581
$group->add(new Form_Input(
2582
	'pppoe_resethour',
2583
	null,
2584
	'number',
2585
	$pconfig['pppoe_resethour'],
2586
	[min => 0, max => 23]
2587
))->setHelp('Hour (0-23)');
2588

    
2589
$group->add(new Form_Input(
2590
	'pppoe_resetminute',
2591
	null,
2592
	'number',
2593
	$pconfig['pppoe_resetminute'],
2594
	[min => 0, max => 59]
2595
))->setHelp('Minutes (0-59)');
2596

    
2597
// ToDo: Need a date-picker here
2598
$group->add(new Form_Input(
2599
	'pppoe_resetdate',
2600
	null,
2601
	'text',
2602
	$pconfig['pppoe_resetdate']
2603
))->setHelp('Specific date (mm/dd/yyyy)');
2604

    
2605
$group->setHelp('If you leave the date field empty, the reset will be executed each day at the time you specified using the minutes and hour field');
2606

    
2607
$section->add($group);
2608

    
2609
$group = new Form_MultiCheckboxGroup('cron based reset');
2610
$group->addClass('pppoepreset');
2611

    
2612
$group->add(new Form_MultiCheckbox(
2613
	'pppoe_pr_preset_val',
2614
	null,
2615
	'Reset at each month ("0 0 1 * *")',
2616
	$pconfig['pppoe_monthly'],
2617
	'monthly'
2618
))->displayAsRadio();
2619

    
2620
$group->add(new Form_MultiCheckbox(
2621
	'pppoe_pr_preset_val',
2622
	null,
2623
	'Reset at each week ("0 0 * * 0")',
2624
	$pconfig['pppoe_weekly'],
2625
	'weekly'
2626
))->displayAsRadio();
2627

    
2628
$group->add(new Form_MultiCheckbox(
2629
	'pppoe_pr_preset_val',
2630
	null,
2631
	'Reset at each day ("0 0 * * *")',
2632
	$pconfig['pppoe_daily'],
2633
	'daily'
2634
))->displayAsRadio();
2635

    
2636
$group->add(new Form_MultiCheckbox(
2637
	'pppoe_pr_preset_val',
2638
	null,
2639
	'Reset at each hour ("0 * * * *")',
2640
	$pconfig['pppoe_hourly'],
2641
	'hourly'
2642
))->displayAsRadio();
2643

    
2644
$section->add($group);
2645

    
2646
if (isset($pconfig['pppid'])) {
2647
	$section->addInput(new Form_StaticText(
2648
		'Advanced and MLPPP',
2649
		'<a href="/interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) . '" class="navlnk">Click here for additional PPPoE configuration options. Save first if you made changes.</a>'
2650
	));
2651
} else {
2652
	$section->addInput(new Form_StaticText(
2653
		'Advanced and MLPPP',
2654
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2655
	));
2656
}
2657

    
2658
$form->add($section);
2659

    
2660
// PPTP & L2TP Configuration section
2661
$section = new Form_Section('PPTP/L2TP Configuration');
2662
$section->addClass('pptp');
2663

    
2664
$section->addInput(new Form_Input(
2665
	'pptp_username',
2666
	'Username',
2667
	'text',
2668
	$pconfig['pptp_username']
2669
));
2670

    
2671
$section->addPassword(new Form_Input(
2672
	'pptp_password',
2673
	'Password',
2674
	'password',
2675
	$pconfig['pptp_password']
2676
));
2677

    
2678
$section->addInput(new Form_IpAddress(
2679
	'pptp_local0',
2680
	'Local IP address',
2681
	$pconfig['pptp_localip'][0]
2682
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2683

    
2684
$section->addInput(new Form_IpAddress(
2685
	'pptp_remote0',
2686
	'Remote IP address',
2687
	$pconfig['pptp_remote'][0]
2688
));
2689

    
2690
$section->addInput(new Form_Checkbox(
2691
	'pptp_dialondemand',
2692
	'Dial on demand',
2693
	'Enable Dial-On-Demand mode ',
2694
	$pconfig['pptp_dialondemand'],
2695
	'enable'
2696
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2697
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2698

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

    
2708
if (isset($pconfig['pppid'])) {
2709
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2710
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2711
	} else {
2712
		$mlppp_text = "";
2713
	}
2714

    
2715
	$section->addInput(new Form_StaticText(
2716
		'Advanced and MLPPP',
2717
		$mlppp_text . '<a href="/interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) . '" class="navlnk">Click here for additional PPTP and L2TP configuration options. Save first if you made changes.</a>'
2718
	));
2719
} else {
2720
	$section->addInput(new Form_StaticText(
2721
		'Advanced and MLPPP',
2722
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2723
	));
2724
}
2725

    
2726
$form->add($section);
2727

    
2728
// Wireless interface
2729
if (isset($wancfg['wireless'])) {
2730

    
2731
	$section = new Form_Section('Common wireless configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
2732

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

    
2741
	$mode_list = ['auto' => 'Auto'];
2742

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

    
2749
	if (count($mode_list) == 1) {
2750
		$mode_list[''] = '';
2751
	}
2752

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

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

    
2776
	$mode_list = ['0' => 'Auto'];
2777

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

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

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

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

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

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

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

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

    
2839
			$section->add($group);
2840
		}
2841
	}
2842

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

    
2852
	$form->add($section);
2853

    
2854
	// Regulatory settings
2855
	$section = new Form_Section('Regulatory settings');
2856

    
2857
	$domain_list = array("" => 'Default');
2858

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

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

    
2872
	$country_list = array('' => 'Default');
2873

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

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

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

    
2898
	$form->add($section);
2899

    
2900
	$section = new Form_Section('Network-specific wireless configuration');
2901

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

    
2909
	$section->addInput(new Form_Input(
2910
		'ssid',
2911
		'SSID',
2912
		'text',
2913
		$pconfig['ssid']
2914
	));
2915

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

    
2933
	$section->addInput(new Form_Checkbox(
2934
		'apbridge_enable',
2935
		'Allow intra-BSS communication',
2936
		'Allow packets to pass between wireless clients directly when operating as an access point',
2937
		$pconfig['apbridge_enable'],
2938
		'yes'
2939
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2940

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

    
2949
	$section->addInput(new Form_Checkbox(
2950
		'hidessid_enable',
2951
		'Hide SSID',
2952
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2953
		$pconfig['hidessid_enable'],
2954
		'yes'
2955
	));
2956

    
2957
	$form->add($section);
2958

    
2959
	// WPA Section
2960
	$section = new Form_Section('WPA');
2961

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

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

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

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

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

    
2998
	$section->addInput(new Form_Input(
2999
		'wpa_group_rekey',
3000
		'WPA Pre-Shared Key',
3001
		'number',
3002
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3003
		['min' => '1', 'max' => 9999]
3004
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3005

    
3006
	$section->addInput(new Form_Input(
3007
		'wpa_gmk_rekey',
3008
		'Master Key Regeneration',
3009
		'number',
3010
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3011
		['min' => '1', 'max' => 9999]
3012
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3013

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

    
3022
	$form->add($section);
3023

    
3024
	$section = new Form_Section('802.1x RADIUS options');
3025

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

    
3034
	$group = new Form_Group('Primary 802.1X server');
3035

    
3036
	$group->add(new Form_IpAddress(
3037
		'auth_server_addr',
3038
		'IP Address',
3039
		$pconfig['auth_server_addr']
3040
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3041

    
3042
	$group->add(new Form_Input(
3043
		'auth_server_port',
3044
		'Port',
3045
		'number',
3046
		$pconfig['auth_server_port']
3047
	))->setHelp('Server port. Leave blank for the default port 1812');
3048

    
3049
	$group->add(new Form_Input(
3050
		'auth_server_shared_secret',
3051
		'Shared secret',
3052
		'number',
3053
		$pconfig['auth_server_shared_secret']
3054
	))->setHelp('Shared secret');
3055

    
3056
	$section->add($group);
3057

    
3058
	$group = new Form_Group('Secondary 802.1X server');
3059

    
3060
	$group->add(new Form_IpAddress(
3061
		'auth_server_addr2',
3062
		'IP Address',
3063
		$pconfig['auth_server_addr2']
3064
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3065

    
3066
	$group->add(new Form_Input(
3067
		'auth_server_port2',
3068
		'Port',
3069
		'number',
3070
		$pconfig['auth_server_port2']
3071
	))->setHelp('Server port. Leave blank for the default port 1812');
3072

    
3073
	$group->add(new Form_Input(
3074
		'auth_server_shared_secret2',
3075
		'Shared secret',
3076
		'number',
3077
		$pconfig['auth_server_shared_secret2']
3078
	))->setHelp('Shared secret');
3079

    
3080
	$section->add($group);
3081

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

    
3090
	$form->add($section);
3091
}
3092

    
3093
$section = new Form_Section('Private networks');
3094

    
3095
$section->addInput(new Form_Checkbox(
3096
	'blockpriv',
3097
	'Block private networks',
3098
	'',
3099
	$pconfig['blockpriv'],
3100
	'yes'
3101
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3102
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3103
			'lies in such a private address space, too.');
3104

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

    
3115
$form->add($section);
3116

    
3117
$form->addGlobal(new Form_Input(
3118
	'if',
3119
	null,
3120
	'hidden',
3121
	$if
3122
));
3123

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

    
3133
$form->addGlobal(new Form_Input(
3134
	'ptpid',
3135
	null,
3136
	'hidden',
3137
	$pconfig['ptpid']
3138
));
3139

    
3140

    
3141
// Add new gateway modal pop-up
3142
$modal = new Modal('New gateway', 'newgateway', 'large');
3143

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

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

    
3158
$modal->addInput(new Form_IpAddress(
3159
	'gatewayip',
3160
	'Gateway IPv4',
3161
	null
3162
));
3163

    
3164
$modal->addInput(new Form_Input(
3165
	'gatewaydescr',
3166
	'Description',
3167
	'text'
3168
));
3169

    
3170
$btnaddgw = new Form_Button(
3171
	'add',
3172
	'Add'
3173
);
3174

    
3175
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3176

    
3177
$btncnxgw = new Form_Button(
3178
	'cnx',
3179
	'Cancel'
3180
);
3181

    
3182
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3183

    
3184
$modal->addInput(new Form_StaticText(
3185
	null,
3186
	$btnaddgw . $btncnxgw
3187
));
3188

    
3189
$form->add($modal);
3190

    
3191
print($form);
3192
?>
3193

    
3194
<script type="text/javascript">
3195
//<![CDATA[
3196
events.push(function() {
3197
	function updateType(t) {
3198

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

    
3233
		if (t != "l2tp" && t != "pptp") {
3234
			$('.'+t).show();
3235
		}
3236
	}
3237

    
3238
	function updateTypeSix(t) {
3239
		if (!isNaN(t[0])) {
3240
			t = '_' + t;
3241
		}
3242

    
3243
		switch (t) {
3244
			case "none": {
3245
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3246
				break;
3247
			}
3248
			case "staticv6": {
3249
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3250
				break;
3251
			}
3252
			case "slaac": {
3253
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3254
				break;
3255
			}
3256
			case "dhcp6": {
3257
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3258
				break;
3259
			}
3260
			case "6rd_": {
3261
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3262
				break;
3263
			}
3264
			case "_6to4": {
3265
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3266
				break;
3267
			}
3268
			case "track6": {
3269
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3270
				update_track6_prefix();
3271
				break;
3272
			}
3273
		}
3274

    
3275
		if (t != "l2tp" && t != "pptp") {
3276
			$('.'+t).show();
3277
		}
3278
	}
3279

    
3280
	function show_reset_settings(reset_type) {
3281
		if (reset_type == 'preset') {
3282
			$('.pppoepreset').show();
3283
			$('.pppoecustom').hide();
3284
		} else if (reset_type == 'custom') {
3285
			$('.pppoecustom').show();
3286
			$('.pppoepreset').hide();
3287
		} else {
3288
			$('.pppoecustom').hide();
3289
			$('.pppoepreset').hide();
3290
		}
3291
	}
3292

    
3293
	function update_track6_prefix() {
3294
		var iface = $("#track6-interface").val();
3295
		if (iface == null) {
3296
			return;
3297
		}
3298

    
3299
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3300
		if (track6_prefix_ids == null) {
3301
			return;
3302
		}
3303

    
3304
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3305
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3306
	}
3307

    
3308
	// Create the new gateway from the data entered in the modal pop-up
3309
	function hide_add_gatewaysave() {
3310
		var iface = $('#if').val();
3311
		name = $('#name').val();
3312
		var descr = $('#gatewaydescr').val();
3313
		gatewayip = $('#gatewayip').val();
3314

    
3315
		var defaultgw = '';
3316
		if ($('#defaultgw').is(':checked')) {
3317
			defaultgw = '&defaultgw=on';
3318
		}
3319

    
3320
		var url = "system_gateways_edit.php";
3321
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3322
		$.ajax(
3323
			url,
3324
			{
3325
				type: 'post',
3326
				data: pars,
3327
				error: report_failure,
3328
				complete: save_callback
3329
			});
3330
		}
3331

    
3332
	function save_callback(response) {
3333
		if (response) {
3334
			var gwtext = escape(name) + " - " + gatewayip;
3335
			addOption($('#gateway'), gwtext, name);
3336
		} else {
3337
			report_failure();
3338
		}
3339

    
3340
		$("#newgateway").modal('hide');
3341
	}
3342

    
3343
	function report_failure(request, textStatus, errorThrown) {
3344
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3345
			alert(request.responseText);
3346
		} else {
3347
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3348
		}
3349

    
3350
		$("#newgateway").modal('hide');
3351
	}
3352

    
3353
	function addOption(selectbox, text, value) {
3354
		var optn = document.createElement("OPTION");
3355
		optn.text = text;
3356
		optn.value = value;
3357
		selectbox.append(optn);
3358
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3359
	}
3360

    
3361
	function hide_add_gatewaysave_v6() {
3362

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

    
3383

    
3384
	function addOption_v6(selectbox, text, value) {
3385
		var optn = document.createElement("OPTION");
3386
		optn.text = text;
3387
		optn.value = value;
3388
		selectbox.append(optn);
3389
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3390
	}
3391

    
3392
	function report_failure_v6(request, textStatus, errorThrown) {
3393
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3394
			alert(request.responseText);
3395
		} else {
3396
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3397
		}
3398

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

    
3402
	function save_callback_v6(response_v6) {
3403
		if (response_v6) {
3404

    
3405
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3406
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3407
		} else {
3408
			report_failure_v6();
3409
		}
3410

    
3411
		$("#newgateway6").modal('hide');
3412
	}
3413

    
3414
	function country_list() {
3415
		$('#country').children().remove();
3416
		$('#provider_list').children().remove();
3417
		$('#providerplan').children().remove();
3418
		$.ajax("getserviceproviders.php",{
3419
			success: function(response) {
3420

    
3421
				var responseTextArr = response.split("\n");
3422
				responseTextArr.sort();
3423

    
3424
				responseTextArr.forEach( function(value) {
3425
					country = value.split(":");
3426
					$('#country').append($('<option>', {
3427
						value: country[1],
3428
						text : country[0]
3429
					}));
3430
				});
3431
			}
3432
		});
3433
	}
3434

    
3435
	function providers_list() {
3436
		$('#provider_list').children().remove();
3437
		$('#providerplan').children().remove();
3438
		$.ajax("getserviceproviders.php",{
3439
			type: 'post',
3440
			data: {country : $('#country').val()},
3441
			success: function(response) {
3442
				var responseTextArr = response.split("\n");
3443
				responseTextArr.sort();
3444
				responseTextArr.forEach( function(value) {
3445
					$('#provider_list').append($('<option>', {
3446
							value: value,
3447
							text : value
3448
					}));
3449
				});
3450
			}
3451
		});
3452
	}
3453

    
3454
	function providerplan_list() {
3455
		$('#providerplan').children().remove();
3456
		$.ajax("getserviceproviders.php",{
3457
			type: 'post',
3458
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3459
			success: function(response) {
3460
				var responseTextArr = response.split("\n");
3461
				responseTextArr.sort();
3462

    
3463
				$('#providerplan').append($('<option>', {
3464
					value: '',
3465
					text : ''
3466
				}));
3467

    
3468
				responseTextArr.forEach( function(value) {
3469
					if (value != "") {
3470
						providerplan = value.split(":");
3471

    
3472
						$('#providerplan').append($('<option>', {
3473
							value: providerplan[1],
3474
							text : providerplan[0] + " - " + providerplan[1]
3475
						}));
3476
					}
3477
				});
3478
			}
3479
		});
3480
	}
3481

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

    
3506
	function show_dhcp6adv() {
3507
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3508
		var adv = $('#dhcp6adv').prop('checked');
3509

    
3510
		hideCheckbox('dhcp6usev4iface', ovr);
3511
		hideCheckbox('dhcp6prefixonly', ovr);
3512
		hideInput('dhcp6-ia-pd-len', ovr);
3513
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3514
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3515

    
3516
		hideClass('dhcp6advanced', !adv || ovr);
3517
	}
3518

    
3519
	function setDHCPoptions() {
3520
		var adv = $('#dhcpadv').prop('checked');
3521
		var ovr = $('#dhcpovr').prop('checked');
3522

    
3523
		if (ovr) {
3524
			hideInput('dhcphostname', true);
3525
			hideIpAddress('alias-address', true);
3526
			hideInput('dhcprejectfrom', true);
3527
			hideInput('adv_dhcp_config_file_override_path', false);
3528
			hideClass('dhcpadvanced', true);
3529
		} else {
3530
			hideInput('dhcphostname', false);
3531
			hideIpAddress('alias-address', false);
3532
			hideInput('dhcprejectfrom', false);
3533
			hideInput('adv_dhcp_config_file_override_path', true);
3534
			hideClass('dhcpadvanced', !adv);
3535
		}
3536
	}
3537

    
3538
	// DHCP preset actions
3539
	// Set presets from value of radio buttons
3540
	function setPresets(val) {
3541
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3542
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3543
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3544
		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']);?>");
3545
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3546
	}
3547

    
3548
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3549
		$('#adv_dhcp_pt_timeout').val(timeout);
3550
		$('#adv_dhcp_pt_retry').val(retry);
3551
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3552
		$('#adv_dhcp_pt_reboot').val(reboot);
3553
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3554
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3555
	}
3556

    
3557
	// ---------- On initial page load ------------------------------------------------------------
3558

    
3559
	updateType($('#type').val());
3560
	updateTypeSix($('#type6').val());
3561
	show_reset_settings($('#pppoe-reset-type').val());
3562
	$("#add").prop('type', 'button');
3563
	$("#cnx").prop('type', 'button');
3564
	$("#addgw").prop('type', 'button');
3565
	$("#add6").prop('type', 'button');
3566
	$("#cnx6").prop('type', 'button');
3567
	$("#addgw6").prop('type', 'button');
3568
	hideClass('dhcp6advanced', true);
3569
	hideClass('dhcpadvanced', true);
3570
	show_dhcp6adv();
3571
	setDHCPoptions()
3572

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

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

    
3584
	// ---------- Click checkbox handlers ---------------------------------------------------------
3585

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

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

    
3594
	$('#pppoe-reset-type').on('change', function() {
3595
		show_reset_settings(this.value);
3596
	});
3597

    
3598
	$("#add").click(function() {
3599
		hide_add_gatewaysave();
3600
	});
3601

    
3602
	$("#cnx").click(function() {
3603
		$("#newgateway").modal('hide');
3604
	});
3605

    
3606
	$("#add6").click(function() {
3607
		hide_add_gatewaysave_v6();
3608
	});
3609

    
3610
	$("#cnx6").click(function() {
3611
		$("#newgateway6").modal('hide');
3612
	});
3613

    
3614
	$('#country').on('change', function() {
3615
		providers_list();
3616
	});
3617

    
3618
	$('#provider_list').on('change', function() {
3619
		providerplan_list();
3620
	});
3621

    
3622
	$('#providerplan').on('change', function() {
3623
		prefill_provider();
3624
	});
3625

    
3626
	$('#dhcpadv, #dhcpovr').click(function () {
3627
		setDHCPoptions();
3628
	});
3629

    
3630
	$('#dhcp6adv').click(function () {
3631
		show_dhcp6adv();
3632
	});
3633

    
3634
	$('#adv_dhcp6_config_file_override').click(function () {
3635
		show_dhcp6adv();
3636
	});
3637

    
3638
	// On click . .
3639
	$('[name=adv_dhcp_pt_values]').click(function () {
3640
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3641
	});
3642

    
3643
});
3644
//]]>
3645
</script>
3646

    
3647
<?php include("foot.inc");
(69-69/229)