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. Interfaces cannot have the same name as an alias."), $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

    
544
	/* Is the description already used as an alias name? */
545
	if (is_array($config['aliases']['alias'])) {
546
		foreach ($config['aliases']['alias'] as $alias) {
547
			if ($alias['name'] == $_POST['descr']) {
548
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
549
			}
550
		}
551
	}
552

    
553
	if (is_numeric($_POST['descr'])) {
554
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
555
	}
556
	/* input validation */
557
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
558
		$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.");
559
	}
560
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
561
		$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.");
562
	}
563

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

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

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

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

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

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

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

    
834
		unset($min_mtu, $max_mtu);
835

    
836
		if (stristr($wancfg['if'], "_vlan")) {
837
			$realhwif_array = get_parent_interface($wancfg['if']);
838
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
839
			$parent_realhwif = $realhwif_array[0];
840
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
841
			if (!empty($parent_if) && !empty($config['interfaces'][$parent_if]['mtu'])) {
842
				if ($_POST['mtu'] > intval($config['interfaces'][$parent_if]['mtu'])) {
843
					$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
844
				}
845
			}
846
		} else {
847
			foreach ($config['interfaces'] as $idx => $ifdata) {
848
				if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
849
					continue;
850
				}
851

    
852
				$realhwif_array = get_parent_interface($ifdata['if']);
853
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
854
				$parent_realhwif = $realhwif_array[0];
855

    
856
				if ($parent_realhwif != $wancfg['if']) {
857
					continue;
858
				}
859

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

    
947
		if ($_POST['passphrase']) {
948
			$passlen = strlen($_POST['passphrase']);
949
			if ($passlen < 8 || $passlen > 63) {
950
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
951
			}
952
		}
953

    
954
		if ($_POST['wpa_enable'] == "yes") {
955
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
956
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
957
			}
958
		}
959
	}
960

    
961
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
962
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
963
	}
964

    
965
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
966
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
967
	}
968

    
969
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
970
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
971
	}
972

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

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

    
1018
		unset($wancfg['adv_dhcp_pt_timeout']);
1019
		unset($wancfg['adv_dhcp_pt_retry']);
1020
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1021
		unset($wancfg['adv_dhcp_pt_reboot']);
1022
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1023
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1024

    
1025
		unset($wancfg['adv_dhcp_pt_values']);
1026

    
1027
		unset($wancfg['adv_dhcp_send_options']);
1028
		unset($wancfg['adv_dhcp_request_options']);
1029
		unset($wancfg['adv_dhcp_required_options']);
1030
		unset($wancfg['adv_dhcp_option_modifiers']);
1031

    
1032
		unset($wancfg['adv_dhcp_config_advanced']);
1033
		unset($wancfg['adv_dhcp_config_file_override']);
1034
		unset($wancfg['adv_dhcp_config_file_override_path']);
1035

    
1036
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1037
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1038
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1039
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1040

    
1041
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1042
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1043
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1044
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1045
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1046

    
1047
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1048
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1049
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1050
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1051
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1052

    
1053
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1054
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1055

    
1056
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1057
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1058
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1059
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1060

    
1061
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1062
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1063
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1064
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1065
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1066

    
1067
		unset($wancfg['adv_dhcp6_config_advanced']);
1068
		unset($wancfg['adv_dhcp6_config_file_override']);
1069
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1070

    
1071
		unset($wancfg['pppoe_password']);
1072
		unset($wancfg['pptp_username']);
1073
		unset($wancfg['pptp_password']);
1074
		unset($wancfg['provider']);
1075
		unset($wancfg['ondemand']);
1076
		unset($wancfg['timeout']);
1077
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1078
			unset($wancfg['pppoe']['pppoe-reset-type']);
1079
		}
1080
		unset($wancfg['local']);
1081

    
1082
		unset($wancfg['remote']);
1083
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1084
			if ($wancfg['ipaddr'] != 'ppp') {
1085
				unset($a_ppps[$pppid]['apn']);
1086
				unset($a_ppps[$pppid]['phone']);
1087
				unset($a_ppps[$pppid]['provider']);
1088
				unset($a_ppps[$pppid]['ondemand']);
1089
			}
1090
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1091
				unset($a_ppps[$pppid]['localip']);
1092
				unset($a_ppps[$pppid]['subnet']);
1093
				unset($a_ppps[$pppid]['gateway']);
1094
			}
1095
			if ($wancfg['ipaddr'] != 'pppoe') {
1096
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1097
			}
1098
			if ($wancfg['type'] != $_POST['type']) {
1099
				unset($a_ppps[$pppid]['idletimeout']);
1100
			}
1101
		}
1102

    
1103
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1104
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1105

    
1106
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1107
		switch ($_POST['type']) {
1108
			case "staticv4":
1109
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1110
				$wancfg['subnet'] = $_POST['subnet'];
1111
				if ($_POST['gateway'] != "none") {
1112
					$wancfg['gateway'] = $_POST['gateway'];
1113
				}
1114
				break;
1115
			case "dhcp":
1116
				$wancfg['ipaddr'] = "dhcp";
1117
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1118
				$wancfg['alias-address'] = $_POST['alias-address'];
1119
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1120
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1121

    
1122
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1123
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1124
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1125
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1126
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1127
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1128

    
1129
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1130

    
1131
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1132
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1133
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1134
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1135

    
1136
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1137
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1138
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1139

    
1140
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1141
				if ($gateway_item) {
1142
					$a_gateways[] = $gateway_item;
1143
				}
1144
				break;
1145
			case "ppp":
1146
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1147
				$a_ppps[$pppid]['type'] = $_POST['type'];
1148
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1149
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1150
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1151
				if ($_POST['ppp_password'] != DMYPWD) {
1152
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1153
				}
1154
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1155
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1156
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1157
				$wancfg['ipaddr'] = $_POST['type'];
1158
				break;
1159

    
1160
			case "pppoe":
1161
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1162
				$a_ppps[$pppid]['type'] = $_POST['type'];
1163
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1164
				if (isset($_POST['ppp_port'])) {
1165
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1166
				} else {
1167
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1168
				}
1169
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1170
				if ($_POST['pppoe_password'] != DMYPWD) {
1171
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1172
				}
1173
				if (!empty($_POST['provider'])) {
1174
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1175
				} else {
1176
					$a_ppps[$pppid]['provider'] = true;
1177
				}
1178
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1179
				if (!empty($_POST['pppoe_idletimeout'])) {
1180
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1181
				} else {
1182
					unset($a_ppps[$pppid]['idletimeout']);
1183
				}
1184

    
1185
				if (!empty($_POST['pppoe-reset-type'])) {
1186
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1187
				} else {
1188
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1189
				}
1190
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1191
				$wancfg['ipaddr'] = $_POST['type'];
1192
				if ($gateway_item) {
1193
					$a_gateways[] = $gateway_item;
1194
				}
1195

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

    
1258
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1259
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1260
				}
1261
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1262
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1263
				}
1264
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1265
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1266
				}
1267
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1268
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1269
				}
1270

    
1271
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1272
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1273
				}
1274
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1275
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1276
				}
1277
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1278
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1279
				}
1280
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1281
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1282
				}
1283
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1284
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1285
				}
1286

    
1287
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1288
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1289
				}
1290
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1291
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1292
				}
1293
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1294
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1295
				}
1296
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1297
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1298
				}
1299
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1300
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1301
				}
1302

    
1303
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1304
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1305
				}
1306
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1307
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1308
				}
1309

    
1310
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1311
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1312
				}
1313
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1314
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1315
				}
1316
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1317
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1318
				}
1319
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1320
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1321
				}
1322

    
1323
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1324
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1325
				}
1326
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1327
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1328
				}
1329
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1330
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1331
				}
1332
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1333
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1334
				}
1335
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1336
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1337
				}
1338

    
1339
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1340
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1341
				}
1342
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1343
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1344
				}
1345
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1346
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1347
				}
1348

    
1349
				if ($gateway_item) {
1350
					$a_gateways[] = $gateway_item;
1351
				}
1352
				break;
1353
			case "6rd":
1354
				$wancfg['ipaddrv6'] = "6rd";
1355
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1356
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1357
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1358
				if ($gateway_item) {
1359
					$a_gateways[] = $gateway_item;
1360
				}
1361
				break;
1362
			case "6to4":
1363
				$wancfg['ipaddrv6'] = "6to4";
1364
				break;
1365
			case "track6":
1366
				$wancfg['ipaddrv6'] = "track6";
1367
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1368
				if ($_POST['track6-prefix-id--hex'] === "") {
1369
					$wancfg['track6-prefix-id'] = 0;
1370
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1371
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1372
				} else {
1373
					$wancfg['track6-prefix-id'] = 0;
1374
				}
1375
				break;
1376
			case "none":
1377
				break;
1378
		}
1379
		handle_pppoe_reset($_POST);
1380

    
1381
		if ($_POST['blockpriv'] == "yes") {
1382
			$wancfg['blockpriv'] = true;
1383
		} else {
1384
			unset($wancfg['blockpriv']);
1385
		}
1386
		if ($_POST['blockbogons'] == "yes") {
1387
			$wancfg['blockbogons'] = true;
1388
		} else {
1389
			unset($wancfg['blockbogons']);
1390
		}
1391
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1392
		if (empty($_POST['mtu'])) {
1393
			unset($wancfg['mtu']);
1394
		} else {
1395
			$wancfg['mtu'] = $_POST['mtu'];
1396
		}
1397
		if (empty($_POST['mss'])) {
1398
			unset($wancfg['mss']);
1399
		} else {
1400
			$wancfg['mss'] = $_POST['mss'];
1401
		}
1402
		if (empty($_POST['mediaopt'])) {
1403
			unset($wancfg['media']);
1404
			unset($wancfg['mediaopt']);
1405
		} else {
1406
			$mediaopts = explode(' ', $_POST['mediaopt']);
1407
			if ($mediaopts[0] != '') {
1408
				$wancfg['media'] = $mediaopts[0];
1409
			}
1410
			if ($mediaopts[1] != '') {
1411
				$wancfg['mediaopt'] = $mediaopts[1];
1412
			} else {
1413
				unset($wancfg['mediaopt']);
1414
			}
1415
		}
1416
		if (isset($wancfg['wireless'])) {
1417
			handle_wireless_post();
1418
		}
1419

    
1420
		conf_mount_ro();
1421
		write_config();
1422

    
1423
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1424
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1425
		} else {
1426
			$toapplylist = array();
1427
		}
1428
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1429
		$toapplylist[$if]['ppps'] = $old_ppps;
1430
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1431

    
1432
		mark_subsystem_dirty('interfaces');
1433

    
1434
		/* regenerate cron settings/crontab file */
1435
		configure_cron();
1436

    
1437
		header("Location: interfaces.php?if={$if}");
1438
		exit;
1439
	}
1440

    
1441
} // end if ($_POST)
1442

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

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

    
1549
	if ($_POST['wme_enable'] == "yes") {
1550
		if (!is_array($wancfg['wireless']['wme'])) {
1551
			$wancfg['wireless']['wme'] = array();
1552
		}
1553
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1554
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1555
		unset($wancfg['wireless']['wme']['enable']);
1556
	}
1557
	if ($_POST['puremode'] == "11g") {
1558
		if (!is_array($wancfg['wireless']['pureg'])) {
1559
			$wancfg['wireless']['pureg'] = array();
1560
		}
1561
		$wancfg['wireless']['pureg']['enable'] = true;
1562
	} else if ($_POST['puremode'] == "11n") {
1563
		if (!is_array($wancfg['wireless']['puren'])) {
1564
			$wancfg['wireless']['puren'] = array();
1565
		}
1566
		$wancfg['wireless']['puren']['enable'] = true;
1567
	} else {
1568
		if (isset($wancfg['wireless']['pureg'])) {
1569
			unset($wancfg['wireless']['pureg']);
1570
		}
1571
		if (isset($wancfg['wireless']['puren'])) {
1572
			unset($wancfg['wireless']['puren']);
1573
		}
1574
	}
1575
	if ($_POST['apbridge_enable'] == "yes") {
1576
		if (!is_array($wancfg['wireless']['apbridge'])) {
1577
			$wancfg['wireless']['apbridge'] = array();
1578
		}
1579
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1580
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1581
		unset($wancfg['wireless']['apbridge']['enable']);
1582
	}
1583
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1584
		if (!is_array($wancfg['wireless']['turbo'])) {
1585
			$wancfg['wireless']['turbo'] = array();
1586
		}
1587
		$wancfg['wireless']['turbo']['enable'] = true;
1588
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1589
		unset($wancfg['wireless']['turbo']['enable']);
1590
	}
1591

    
1592
	interface_sync_wireless_clones($wancfg, true);
1593
}
1594

    
1595
function check_wireless_mode() {
1596
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1597

    
1598
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1599
		return;
1600
	}
1601

    
1602
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1603
		$clone_count = 1;
1604
	} else {
1605
		$clone_count = 0;
1606
	}
1607

    
1608
	if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) {
1609
		foreach ($config['wireless']['clone'] as $clone) {
1610
			if ($clone['if'] == $wlanbaseif) {
1611
				$clone_count++;
1612
			}
1613
		}
1614
	}
1615

    
1616
	if ($clone_count > 1) {
1617
		$old_wireless_mode = $wancfg['wireless']['mode'];
1618
		$wancfg['wireless']['mode'] = $_POST['mode'];
1619
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1620
			$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']]);
1621
		} else {
1622
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1623
		}
1624
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1625
	}
1626
}
1627

    
1628
// Find all possible media options for the interface
1629
$mediaopts_list = array();
1630
$intrealname = $config['interfaces'][$if]['if'];
1631
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1632
foreach ($mediaopts as $mediaopt) {
1633
	preg_match("/media (.*)/", $mediaopt, $matches);
1634
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1635
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1636
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1637
	} else {
1638
		// there is only media like "media 1000baseT"
1639
		array_push($mediaopts_list, $matches[1]);
1640
	}
1641
}
1642

    
1643
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1644
$shortcut_section = "interfaces";
1645

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

    
1649
// Get the MAC address
1650
$ip = $_SERVER['REMOTE_ADDR'];
1651
$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d" " -f4`;
1652
$mymac = str_replace("\n", "", $mymac);
1653

    
1654
function build_mediaopts_list() {
1655
	global $mediaopts_list;
1656

    
1657
	$list = [""	 =>	 "Default (no preference, typically autoselect)",
1658
			 " " =>	 "------- Media Supported by this interface -------"
1659
			];
1660

    
1661
	foreach ($mediaopts_list as $mediaopt) {
1662
		$list[$mediaopt] = $mediaopt;
1663
	}
1664

    
1665
	return($list);
1666
}
1667

    
1668
function build_gateway_list() {
1669
	global $a_gateways, $if;
1670

    
1671
	$list = array("none" => "None");
1672
	foreach ($a_gateways as $gateway) {
1673
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1674
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1675
		}
1676
	}
1677

    
1678
	return($list);
1679
}
1680

    
1681
function build_gatewayv6_list() {
1682
	global $a_gateways, $if;
1683

    
1684
	$list = array("none" => "None");
1685
	foreach ($a_gateways as $gateway) {
1686
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1687
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1688
		}
1689
	}
1690

    
1691
	return($list);
1692
}
1693

    
1694
include("head.inc");
1695

    
1696
if ($input_errors) {
1697
	print_input_errors($input_errors);
1698
}
1699

    
1700
if (is_subsystem_dirty('interfaces')) {
1701
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1702
					  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."));
1703
}
1704

    
1705
if ($savemsg) {
1706
	print_info_box($savemsg, 'success');
1707
}
1708

    
1709

    
1710
$form = new Form(new Form_Button(
1711
	'Submit',
1712
	gettext("Save")
1713
));
1714

    
1715
$section = new Form_Section('General configuration');
1716

    
1717
$section->addInput(new Form_Checkbox(
1718
	'enable',
1719
	'Enable',
1720
	'Enable interface',
1721
	$pconfig['enable'],
1722
	'yes'
1723
));
1724

    
1725
$section->addInput(new Form_Input(
1726
	'descr',
1727
	'Description',
1728
	'text',
1729
	$pconfig['descr']
1730
))->setHelp('Enter a description (name) for the interface here.');
1731

    
1732
$section->addInput(new Form_Select(
1733
	'type',
1734
	'IPv4 Configuration Type',
1735
	$pconfig['type'],
1736
	$types4
1737
));
1738

    
1739
$section->addInput(new Form_Select(
1740
	'type6',
1741
	'IPv6 Configuration Type',
1742
	$pconfig['type6'],
1743
	$types6
1744
));
1745

    
1746
$macaddress = new Form_Input(
1747
	'spoofmac',
1748
	'MAC Address',
1749
	'text',
1750
	$pconfig['spoofmac'],
1751
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1752
);
1753

    
1754
$btnmymac = new Form_Button(
1755
	'btnmymac',
1756
	'Copy My MAC'
1757
	);
1758

    
1759
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1760

    
1761
$group = new Form_Group('MAC controls');
1762
$group->add($macaddress);
1763
// $group->add($btnmymac);
1764
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1765
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1766
$section->add($group);
1767

    
1768
$section->addInput(new Form_Input(
1769
	'mtu',
1770
	'MTU',
1771
	'number',
1772
	$pconfig['mtu']
1773
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1774
			'This is typically 1500 bytes but can vary in some circumstances.');
1775

    
1776
$section->addInput(new Form_Input(
1777
	'mss',
1778
	'MSS',
1779
	'number',
1780
	$pconfig['mss']
1781
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1782
			'header size) will be in effect.');
1783

    
1784
if (count($mediaopts_list) > 0) {
1785
	$section->addInput(new Form_Select(
1786
		'mediaopt',
1787
		'Speed and Duplex',
1788
		rtrim($mediaopt_from_config),
1789
		build_mediaopts_list()
1790
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1791
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1792
}
1793

    
1794
$form->add($section);
1795

    
1796
$section = new Form_Section('Static IPv4 configuration');
1797
$section->addClass('staticv4');
1798

    
1799
$section->addInput(new Form_IpAddress(
1800
	'ipaddr',
1801
	'IPv4 Address',
1802
	$pconfig['ipaddr']
1803
))->addMask('subnet', $pconfig['subnet'], 32);
1804

    
1805
$group = new Form_Group('IPv4 Upstream gateway');
1806

    
1807
$group->add(new Form_Select(
1808
	'gateway',
1809
	'IPv4 Upstream Gateway',
1810
	$pconfig['gateway'],
1811
	build_gateway_list()
1812
));
1813

    
1814
$group->add(new Form_Button(
1815
	'addgw',
1816
	'Add a new gateway'
1817
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1818

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

    
1823
$section->add($group);
1824

    
1825
$form->add($section);
1826

    
1827
$section = new Form_Section('Static IPv6 configuration');
1828
$section->addClass('staticv6');
1829

    
1830
$section->addInput(new Form_IpAddress(
1831
	'ipaddrv6',
1832
	'IPv6 address',
1833
	$pconfig['ipaddrv6']
1834
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1835

    
1836
$group = new Form_Group('IPv6 Upstream gateway');
1837

    
1838
$group->add(new Form_Select(
1839
	'gatewayv6',
1840
	'IPv6 Upstream Gateway',
1841
	$pconfig['gatewayv6'],
1842
	build_gatewayv6_list()
1843
));
1844

    
1845
$group->add(new Form_Button(
1846
	'addgw6',
1847
	'Add a new gateway'
1848
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1849

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

    
1853
$section->add($group);
1854
$form->add($section);
1855

    
1856
// Add new gateway modal pop-up for IPv6
1857
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1858

    
1859
$modal->addInput(new Form_Checkbox(
1860
	'defaultgw6',
1861
	'Default',
1862
	'Default gateway',
1863
	($if == "wan" || $if == "WAN")
1864
));
1865

    
1866
$modal->addInput(new Form_Input(
1867
	'name6',
1868
	'Gateway name',
1869
	'text',
1870
	$wancfg['descr'] . "GWv6"
1871
));
1872

    
1873
$modal->addInput(new Form_IpAddress(
1874
	'gatewayip6',
1875
	'Gateway IPv6',
1876
	null
1877
));
1878

    
1879
$modal->addInput(new Form_Input(
1880
	'gatewaydescr6',
1881
	'Description',
1882
	'text'
1883
));
1884

    
1885
$btnaddgw6 = new Form_Button(
1886
	'add6',
1887
	'Add'
1888
);
1889

    
1890
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1891

    
1892
$btncnxgw6 = new Form_Button(
1893
	'cnx6',
1894
	'Cancel'
1895
);
1896

    
1897
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1898

    
1899
$modal->addInput(new Form_StaticText(
1900
	null,
1901
	$btnaddgw6 . $btncnxgw6
1902
));
1903

    
1904
$form->add($modal);
1905

    
1906
// ==== DHCP client configuration =============================
1907

    
1908
$section = new Form_Section('DHCP client configuration');
1909
$section->addClass('dhcp');
1910

    
1911
$group = new Form_Group('Options');
1912

    
1913
$group->add(new Form_Checkbox(
1914
	'dhcpadv',
1915
	null,
1916
	'Show DHCP advanced options',
1917
	false
1918
));
1919

    
1920
$group->add(new Form_Checkbox(
1921
	'dhcpovr',
1922
	null,
1923
	'Config file override',
1924
	false
1925
));
1926

    
1927
$section->add($group);
1928

    
1929
$section->addInput(new Form_Input(
1930
	'dhcphostname',
1931
	'Hostname',
1932
	'text',
1933
	$pconfig['dhcphostname']
1934
))->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).');
1935

    
1936
$section->addInput(new Form_IpAddress(
1937
	'alias-address',
1938
	'Alias IPv4 address',
1939
	$pconfig['alias-address']
1940
))->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.');
1941

    
1942
$section->addInput(new Form_Input(
1943
	'dhcprejectfrom',
1944
	'Reject leases from',
1945
	'text',
1946
	$pconfig['dhcprejectfrom']
1947
))->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. ' .
1948
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1949

    
1950
$group = new Form_Group('Protocol timing');
1951
$group->addClass('dhcpadvanced');
1952

    
1953
$group->add(new Form_Input(
1954
	'adv_dhcp_pt_timeout',
1955
	null,
1956
	'number',
1957
	$pconfig['adv_dhcp_pt_timeout']
1958
))->setHelp('Timeout');
1959

    
1960
$group->add(new Form_Input(
1961
	'adv_dhcp_pt_retry',
1962
	null,
1963
	'number',
1964
	$pconfig['adv_dhcp_pt_retry']
1965
))->setHelp('Retry');
1966

    
1967
$group->add(new Form_Input(
1968
	'adv_dhcp_pt_select_timeout',
1969
	null,
1970
	'number',
1971
	$pconfig['adv_dhcp_pt_select_timeout'],
1972
	['min' => 0]
1973
))->setHelp('Select timeout');
1974

    
1975
$group->add(new Form_Input(
1976
	'adv_dhcp_pt_reboot',
1977
	null,
1978
	'number',
1979
	$pconfig['adv_dhcp_pt_reboot']
1980
))->setHelp('Reboot');
1981

    
1982
$group->add(new Form_Input(
1983
	'adv_dhcp_pt_backoff_cutoff',
1984
	null,
1985
	'number',
1986
	$pconfig['adv_dhcp_pt_backoff_cutoff']
1987
))->setHelp('Backoff cutoff');
1988

    
1989
$group->add(new Form_Input(
1990
	'adv_dhcp_pt_initial_interval',
1991
	null,
1992
	'number',
1993
	$pconfig['adv_dhcp_pt_initial_interval']
1994
))->setHelp('Initial interval');
1995

    
1996
$section->add($group);
1997

    
1998
$group = new Form_Group('Presets');
1999
$group->addClass('dhcpadvanced');
2000

    
2001
$group->add(new Form_Checkbox(
2002
	'adv_dhcp_pt_values',
2003
	null,
2004
	'FreeBSD default',
2005
	null,
2006
	'DHCP'
2007
))->displayAsRadio();
2008

    
2009
$group->add(new Form_Checkbox(
2010
	'adv_dhcp_pt_values',
2011
	null,
2012
	'Clear',
2013
	null,
2014
	'Clear'
2015
))->displayAsRadio();
2016

    
2017
$group->add(new Form_Checkbox(
2018
	'adv_dhcp_pt_values',
2019
	null,
2020
	'pfSense Default',
2021
	null,
2022
	'pfSense'
2023
))->displayAsRadio();
2024

    
2025
$group->add(new Form_Checkbox(
2026
	'adv_dhcp_pt_values',
2027
	null,
2028
	'Saved Cfg',
2029
	null,
2030
	'SavedCfg'
2031
))->displayAsRadio();
2032

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

    
2036
$section->add($group);
2037

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

    
2048
$form->add($section);
2049

    
2050
$section = new Form_Section('Lease Requirements and Requests');
2051
$section->addClass('dhcpadvanced');
2052

    
2053
$section->addInput(new Form_Input(
2054
	'adv_dhcp_send_options',
2055
	'Send options',
2056
	'text',
2057
	$pconfig['adv_dhcp_send_options']
2058
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2059
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2060
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2061
			'Some ISPs may require certain options be or not be sent.');
2062

    
2063
$section->addInput(new Form_Input(
2064
	'adv_dhcp_request_options',
2065
	'Request options',
2066
	'text',
2067
	$pconfig['adv_dhcp_request_options']
2068
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2069
			'Some ISPs may require certain options be or not be requested.');
2070

    
2071
$section->addInput(new Form_Input(
2072
	'adv_dhcp_required_options',
2073
	'Require options',
2074
	'text',
2075
	$pconfig['adv_dhcp_required_options']
2076
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2077

    
2078
$section->addInput(new Form_Input(
2079
	'adv_dhcp_option_modifiers',
2080
	'Option modifiers',
2081
	'text',
2082
	$pconfig['adv_dhcp_option_modifiers']
2083
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2084
			'modifiers: (default, supersede, prepend, append)');
2085

    
2086
$form->add($section);
2087

    
2088
// DHCP6 client config
2089

    
2090
$section = new Form_Section('DHCP6 client configuration');
2091
$section->addClass('dhcp6');
2092

    
2093
$section->addInput(new Form_Checkbox(
2094
	'adv_dhcp6_config_advanced',
2095
	'Advanced',
2096
	'Show DHCPv6 advanced options',
2097
	$pconfig['adv_dhcp6_config_advanced'],
2098
	'Selected'
2099
));
2100

    
2101
$section->addInput(new Form_Checkbox(
2102
	'adv_dhcp6_config_file_override',
2103
	'Config file override',
2104
	'Override the configuration from this file',
2105
	$pconfig['adv_dhcp6_config_file_override'],
2106
	'Selected'
2107
));
2108

    
2109
$section->addInput(new Form_Checkbox(
2110
	'dhcp6usev4iface',
2111
	'Use IPv4 connectivity as parent interface',
2112
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2113
	$pconfig['dhcp6usev4iface']
2114
));
2115

    
2116
$section->addInput(new Form_Checkbox(
2117
	'dhcp6prefixonly',
2118
	'Request only an IPv6 prefix',
2119
	'Only request an IPv6 prefix, do not request an IPv6 address',
2120
	$pconfig['dhcp6prefixonly']
2121
));
2122

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

    
2130
$section->addInput(new Form_Checkbox(
2131
	'dhcp6-ia-pd-send-hint',
2132
	'Send IPv6 prefix hint',
2133
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2134
	$pconfig['dhcp6-ia-pd-send-hint']
2135
));
2136

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

    
2147
$form->add($section);
2148

    
2149
// DHCP6 client config - Advanced
2150

    
2151
$section = new Form_Section('Advanced DHCP6 client configuration');
2152
$section->addClass('dhcp6advanced');
2153

    
2154
$section->addInput(new Form_Checkbox(
2155
	'adv_dhcp6_interface_statement_information_only_enable',
2156
	'Information only',
2157
	null,
2158
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2159
	'Selected'
2160
));
2161

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

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

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

    
2188
$group = new Form_Group('Identity Association Statement');
2189

    
2190
$group->add(new Form_Checkbox(
2191
	'adv_dhcp6_id_assoc_statement_address_enable',
2192
	null,
2193
	'Non-Temporary Address Allocation',
2194
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2195
	'Selected'
2196
));
2197

    
2198
$group->add(new Form_Input(
2199
	'adv_dhcp6_id_assoc_statement_address_id',
2200
	null,
2201
	'text',
2202
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2203
))->sethelp('id-assoc na ID');
2204

    
2205
$group->add(new Form_IpAddress(
2206
	'adv_dhcp6_id_assoc_statement_address',
2207
	null,
2208
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2209
))->sethelp('IPv6 address');
2210

    
2211
$group->add(new Form_Input(
2212
	'adv_dhcp6_id_assoc_statement_address_pltime',
2213
	null,
2214
	'text',
2215
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2216
))->sethelp('pltime');
2217

    
2218
$group->add(new Form_Input(
2219
	'adv_dhcp6_id_assoc_statement_address_vltime',
2220
	null,
2221
	'text',
2222
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2223
))->sethelp('vltime');
2224

    
2225
$section->add($group);
2226

    
2227
// Prefix delegation
2228
$group = new Form_Group('');
2229

    
2230
$group->add(new Form_Checkbox(
2231
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2232
	null,
2233
	'Prefix Delegation ',
2234
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2235
	'Selected'
2236
));
2237

    
2238
$group->add(new Form_Input(
2239
	'adv_dhcp6_id_assoc_statement_prefix_id',
2240
	null,
2241
	'text',
2242
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2243
))->sethelp('id-assoc pd ID');
2244

    
2245
$group->add(new Form_IpAddress(
2246
	'adv_dhcp6_id_assoc_statement_prefix',
2247
	null,
2248
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2249
))->sethelp('IPv6 prefix');
2250

    
2251
$group->add(new Form_Input(
2252
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2253
	null,
2254
	'text',
2255
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2256
))->sethelp('pltime');
2257

    
2258
$group->add(new Form_Input(
2259
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2260
	null,
2261
	'text',
2262
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2263
))->sethelp('vltime');
2264

    
2265
$section->add($group);
2266

    
2267
$group = new Form_Group('Prefix interface statement');
2268

    
2269
$group->add(new Form_Input(
2270
	'adv_dhcp6_prefix_interface_statement_sla_id',
2271
	null,
2272
	'text',
2273
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2274
))->sethelp('Prefix Interface sla-id');
2275

    
2276
$group->add(new Form_Input(
2277
	'adv_dhcp6_prefix_interface_statement_sla_len',
2278
	null,
2279
	'text',
2280
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2281
))->sethelp('sla-len');
2282

    
2283
$section->add($group);
2284

    
2285
$group = new Form_Group('Authentication statement');
2286

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

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

    
2301
$group->add(new Form_Input(
2302
	'adv_dhcp6_authentication_statement_algorithm',
2303
	null,
2304
	'text',
2305
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2306
))->sethelp('Algorithm');
2307

    
2308
$group->add(new Form_Input(
2309
	'adv_dhcp6_authentication_statement_rdm',
2310
	null,
2311
	'text',
2312
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2313
))->sethelp('RDM');
2314

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

    
2317
$group = new Form_Group('Keyinfo statement');
2318

    
2319
$group->add(new Form_Input(
2320
	'adv_dhcp6_key_info_statement_keyname',
2321
	null,
2322
	'text',
2323
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2324
))->sethelp('Keyname');
2325

    
2326
$group->add(new Form_Input(
2327
	'adv_dhcp6_key_info_statement_realm',
2328
	null,
2329
	'text',
2330
	$pconfig['adv_dhcp6_key_info_statement_realm']
2331
))->sethelp('Realm');
2332

    
2333
$section->add($group);
2334

    
2335
$group = new Form_Group('');
2336

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

    
2344
$group->add(new Form_Input(
2345
	'adv_dhcp6_key_info_statement_secret',
2346
	null,
2347
	'text',
2348
	$pconfig['adv_dhcp6_key_info_statement_secret']
2349
))->sethelp('Secret');
2350

    
2351
$group->add(new Form_Input(
2352
	'adv_dhcp6_key_info_statement_expire',
2353
	null,
2354
	'text',
2355
	$pconfig['adv_dhcp6_key_info_statement_expire']
2356
))->sethelp('Expire');
2357

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

    
2360
$form->add($section);
2361

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

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

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

    
2379
$section->addInput(new Form_Select(
2380
	'prefix-6rd-v4plen',
2381
	'6RD IPv4 Prefix length',
2382
	$pconfig['prefix-6rd-v4plen'],
2383
	array_combine(range(0, 32), range(0, 32))
2384
))->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.');
2385

    
2386
$form->add($section);
2387

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

    
2392
function build_ipv6interface_list() {
2393
	global $config, $section;
2394

    
2395
	$list = array('' => '');
2396

    
2397
	$interfaces = get_configured_interface_with_descr(false, true);
2398
	$dynv6ifs = array();
2399

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

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

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

    
2426
	return($list);
2427
}
2428

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

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

    
2440
$section->addInput(new Form_Input(
2441
	'track6-prefix-id--hex' . $iface,
2442
	'IPv6 Prefix ID',
2443
	'text',
2444
	sprintf("%x", $pconfig['track6-prefix-id'])
2445
))->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.');
2446

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

    
2454
$form->add($section);
2455

    
2456
/// PPP section
2457

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

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

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

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

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

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

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

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

    
2510

    
2511
function build_port_list() {
2512
	$list = array("" => "None");
2513

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

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

    
2523
	$list[trim($port)] = $port;
2524
	}
2525

    
2526
	return($list);
2527
}
2528

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

    
2536
$section->addInput(new Form_Button(
2537
	'btnadvppp',
2538
	'Advanced PPP',
2539
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2540
))->setHelp('Create a new PPP configuration');
2541

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

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

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

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

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

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

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

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

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

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

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

    
2612
// ToDo: Need a date-picker here
2613
$group->add(new Form_Input(
2614
	'pppoe_resetdate',
2615
	null,
2616
	'text',
2617
	$pconfig['pppoe_resetdate']
2618
))->setHelp('Specific date (mm/dd/yyyy)');
2619

    
2620
$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');
2621

    
2622
$section->add($group);
2623

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

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

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

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

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

    
2659
$section->add($group);
2660

    
2661
if (isset($pconfig['pppid'])) {
2662
	$section->addInput(new Form_StaticText(
2663
		'Advanced and MLPPP',
2664
		'<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>'
2665
	));
2666
} else {
2667
	$section->addInput(new Form_StaticText(
2668
		'Advanced and MLPPP',
2669
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2670
	));
2671
}
2672

    
2673
$form->add($section);
2674

    
2675
// PPTP & L2TP Configuration section
2676
$section = new Form_Section('PPTP/L2TP Configuration');
2677
$section->addClass('pptp');
2678

    
2679
$section->addInput(new Form_Input(
2680
	'pptp_username',
2681
	'Username',
2682
	'text',
2683
	$pconfig['pptp_username']
2684
));
2685

    
2686
$section->addPassword(new Form_Input(
2687
	'pptp_password',
2688
	'Password',
2689
	'password',
2690
	$pconfig['pptp_password']
2691
));
2692

    
2693
$section->addInput(new Form_IpAddress(
2694
	'pptp_local0',
2695
	'Local IP address',
2696
	$pconfig['pptp_localip'][0]
2697
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2698

    
2699
$section->addInput(new Form_IpAddress(
2700
	'pptp_remote0',
2701
	'Remote IP address',
2702
	$pconfig['pptp_remote'][0]
2703
));
2704

    
2705
$section->addInput(new Form_Checkbox(
2706
	'pptp_dialondemand',
2707
	'Dial on demand',
2708
	'Enable Dial-On-Demand mode ',
2709
	$pconfig['pptp_dialondemand'],
2710
	'enable'
2711
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2712
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2713

    
2714
$section->addInput(new Form_Input(
2715
	'pptp_idletimeout',
2716
	'Idle timeout (seconds)',
2717
	'number',
2718
	$pconfig['pptp_idletimeout'],
2719
	[min => 0]
2720
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2721
			'An idle timeout of zero disables this feature.');
2722

    
2723
if (isset($pconfig['pppid'])) {
2724
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2725
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2726
	} else {
2727
		$mlppp_text = "";
2728
	}
2729

    
2730
	$section->addInput(new Form_StaticText(
2731
		'Advanced and MLPPP',
2732
		$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>'
2733
	));
2734
} else {
2735
	$section->addInput(new Form_StaticText(
2736
		'Advanced and MLPPP',
2737
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2738
	));
2739
}
2740

    
2741
$form->add($section);
2742

    
2743
// Wireless interface
2744
if (isset($wancfg['wireless'])) {
2745

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

    
2748
	$section->addInput(new Form_Checkbox(
2749
		'persistcommonwireless',
2750
		'Persist common settings',
2751
		'Preserve common wireless configuration through interface deletions and reassignments.',
2752
		$pconfig['persistcommonwireless'],
2753
		'yes'
2754
	));
2755

    
2756
	$mode_list = ['auto' => 'Auto'];
2757

    
2758
	if (is_array($wl_modes)) {
2759
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2760
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2761
		}
2762
	}
2763

    
2764
	if (count($mode_list) == 1) {
2765
		$mode_list[''] = '';
2766
	}
2767

    
2768
	$section->addInput(new Form_Select(
2769
		'standard',
2770
		'Standard',
2771
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2772
		$mode_list
2773
	));
2774

    
2775
	if (isset($wl_modes['11g'])) {
2776
		$section->addInput(new Form_Select(
2777
			'protmode',
2778
			'802.11g OFDM Protection Mode',
2779
			$pconfig['protmode'],
2780
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2781
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2782
	} else {
2783
		$section->addInput(new Form_Input(
2784
			'protmode',
2785
			null,
2786
			'hidden',
2787
			'off'
2788
		));
2789
	}
2790

    
2791
	$mode_list = ['0' => 'Auto'];
2792

    
2793
	if (is_array($wl_modes)) {
2794
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2795
			if ($wl_standard == "11g") {
2796
				$wl_standard = "11b/g";
2797
			} else if ($wl_standard == "11ng") {
2798
				$wl_standard = "11b/g/n";
2799
			} else if ($wl_standard == "11na") {
2800
				$wl_standard = "11a/n";
2801
			}
2802

    
2803
			foreach ($wl_channels as $wl_channel) {
2804
				if (isset($wl_chaninfo[$wl_channel])) {
2805
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2806
				} else {
2807
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2808
				}
2809
			}
2810
		}
2811
	}
2812

    
2813
	$section->addInput(new Form_Select(
2814
		'channel',
2815
		'Channel',
2816
		$pconfig['channel'],
2817
		$mode_list
2818
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2819
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2820

    
2821
	if (ANTENNAS) {
2822
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2823
			$group = new Form_Group('Antenna Settings');
2824

    
2825
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2826
				$group->add(new Form_Select(
2827
					'diversity',
2828
					null,
2829
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2830
					['' => 'Default', '0' => 'Off', '1' => 'On']
2831
				))->setHelp('Diversity');
2832
			}
2833

    
2834
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2835
				$group->add(new Form_Select(
2836
					'txantenna',
2837
					null,
2838
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2839
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2840
				))->setHelp('Transmit antenna');
2841
			}
2842

    
2843
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2844
				$group->add(new Form_Select(
2845
					'rxantenna',
2846
					null,
2847
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2848
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2849
				))->setHelp('Receive antenna');
2850
			}
2851

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

    
2854
			$section->add($group);
2855
		}
2856
	}
2857

    
2858
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2859
			$section->addInput(new Form_Input(
2860
				'distance',
2861
				'Distance setting (meters)',
2862
				'test',
2863
				$pconfig['distance']
2864
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2865
	}
2866

    
2867
	$form->add($section);
2868

    
2869
	// Regulatory settings
2870
	$section = new Form_Section('Regulatory settings');
2871

    
2872
	$domain_list = array("" => 'Default');
2873

    
2874
	if (is_array($wl_regdomains)) {
2875
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2876
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2877
		}
2878
	}
2879

    
2880
	$section->addInput(new Form_Select(
2881
		'regdomain',
2882
		'Regulatory domain',
2883
		$pconfig['regdomain'],
2884
		$domain_list
2885
	))->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');
2886

    
2887
	$country_list = array('' => 'Default');
2888

    
2889
	if (is_array($wl_countries)) {
2890
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2891
			$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']);
2892
		}
2893
	}
2894

    
2895
	$section->addInput(new Form_Select(
2896
		'regcountry',
2897
		'Country',
2898
		$pconfig['regcountry'],
2899
		$country_list
2900
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2901

    
2902
	$section->addInput(new Form_Select(
2903
		'reglocation',
2904
		'Location',
2905
		$pconfig['reglocation'],
2906
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2907
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2908
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2909
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2910
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2911
				'These settings may not be able to add additional channels that are not already supported.');
2912

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

    
2915
	$section = new Form_Section('Network-specific wireless configuration');
2916

    
2917
	$section->addInput(new Form_Select(
2918
		'mode',
2919
		'Mode',
2920
		$pconfig['mode'],
2921
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
2922
	));
2923

    
2924
	$section->addInput(new Form_Input(
2925
		'ssid',
2926
		'SSID',
2927
		'text',
2928
		$pconfig['ssid']
2929
	));
2930

    
2931
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2932
		$section->addInput(new Form_Select(
2933
			'puremode',
2934
			'Minimum wireless standard',
2935
			$pconfig['puremode'],
2936
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
2937
		))->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)');
2938
	} elseif (isset($wl_modes['11g'])) {
2939
		$section->addInput(new Form_Checkbox(
2940
			'puremode',
2941
			'802.11g only',
2942
			null,
2943
			$pconfig['puremode'],
2944
			'11g'
2945
		))->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)');
2946
	}
2947

    
2948
	$section->addInput(new Form_Checkbox(
2949
		'apbridge_enable',
2950
		'Allow intra-BSS communication',
2951
		'Allow packets to pass between wireless clients directly when operating as an access point',
2952
		$pconfig['apbridge_enable'],
2953
		'yes'
2954
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2955

    
2956
	$section->addInput(new Form_Checkbox(
2957
		'wme_enable',
2958
		'Enable WME',
2959
		'Force the card to use WME (wireless QoS)',
2960
		$pconfig['wme_enable'],
2961
		'yes'
2962
	));
2963

    
2964
	$section->addInput(new Form_Checkbox(
2965
		'hidessid_enable',
2966
		'Hide SSID',
2967
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2968
		$pconfig['hidessid_enable'],
2969
		'yes'
2970
	));
2971

    
2972
	$form->add($section);
2973

    
2974
	// WPA Section
2975
	$section = new Form_Section('WPA');
2976

    
2977
	$section->addInput(new Form_Checkbox(
2978
		'wpa_enable',
2979
		'Enable',
2980
		'Enable WPA',
2981
		$pconfig['wpa_enable'],
2982
		'yes'
2983
	));
2984

    
2985
	$section->addInput(new Form_Input(
2986
		'passphrase',
2987
		'WPA Pre-Shared Key',
2988
		'text',
2989
		$pconfig['passphrase']
2990
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2991

    
2992
	$section->addInput(new Form_Select(
2993
		'wpa_mode',
2994
		'WPA mode',
2995
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2996
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
2997
	));
2998

    
2999
	$section->addInput(new Form_Select(
3000
		'wpa_key_mgmt',
3001
		'WPA Key Management Mode',
3002
		$pconfig['wpa_key_mgmt'],
3003
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
3004
	));
3005

    
3006
	$section->addInput(new Form_Select(
3007
		'wpa_pairwise',
3008
		'WPA Pairwise',
3009
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3010
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3011
	));
3012

    
3013
	$section->addInput(new Form_Input(
3014
		'wpa_group_rekey',
3015
		'WPA Pre-Shared Key',
3016
		'number',
3017
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3018
		['min' => '1', 'max' => 9999]
3019
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3020

    
3021
	$section->addInput(new Form_Input(
3022
		'wpa_gmk_rekey',
3023
		'Master Key Regeneration',
3024
		'number',
3025
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3026
		['min' => '1', 'max' => 9999]
3027
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3028

    
3029
	$section->addInput(new Form_Checkbox(
3030
		'wpa_strict_rekey',
3031
		'Strict Key Regeneration',
3032
		'Force the AP to rekey whenever a client disassociates',
3033
		$pconfig['wpa_strict_rekey'],
3034
		'yes'
3035
	));
3036

    
3037
	$form->add($section);
3038

    
3039
	$section = new Form_Section('802.1x RADIUS options');
3040

    
3041
	$section->addInput(new Form_Checkbox(
3042
		'ieee8021x',
3043
		'IEEE802.1X',
3044
		'Enable 802.1X authentication',
3045
		$pconfig['ieee8021x'],
3046
		'yes'
3047
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3048

    
3049
	$group = new Form_Group('Primary 802.1X server');
3050

    
3051
	$group->add(new Form_IpAddress(
3052
		'auth_server_addr',
3053
		'IP Address',
3054
		$pconfig['auth_server_addr']
3055
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3056

    
3057
	$group->add(new Form_Input(
3058
		'auth_server_port',
3059
		'Port',
3060
		'number',
3061
		$pconfig['auth_server_port']
3062
	))->setHelp('Server port. Leave blank for the default port 1812');
3063

    
3064
	$group->add(new Form_Input(
3065
		'auth_server_shared_secret',
3066
		'Shared secret',
3067
		'number',
3068
		$pconfig['auth_server_shared_secret']
3069
	))->setHelp('Shared secret');
3070

    
3071
	$section->add($group);
3072

    
3073
	$group = new Form_Group('Secondary 802.1X server');
3074

    
3075
	$group->add(new Form_IpAddress(
3076
		'auth_server_addr2',
3077
		'IP Address',
3078
		$pconfig['auth_server_addr2']
3079
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3080

    
3081
	$group->add(new Form_Input(
3082
		'auth_server_port2',
3083
		'Port',
3084
		'number',
3085
		$pconfig['auth_server_port2']
3086
	))->setHelp('Server port. Leave blank for the default port 1812');
3087

    
3088
	$group->add(new Form_Input(
3089
		'auth_server_shared_secret2',
3090
		'Shared secret',
3091
		'number',
3092
		$pconfig['auth_server_shared_secret2']
3093
	))->setHelp('Shared secret');
3094

    
3095
	$section->add($group);
3096

    
3097
	$section->addInput(new Form_Checkbox(
3098
		'rsn_preauth',
3099
		'Authentication Roaming Preauth',
3100
		null,
3101
		$pconfig['rsn_preauth'],
3102
		'yes'
3103
	));
3104

    
3105
	$form->add($section);
3106
}
3107

    
3108
$section = new Form_Section('Private networks');
3109

    
3110
$section->addInput(new Form_Checkbox(
3111
	'blockpriv',
3112
	'Block private networks',
3113
	'',
3114
	$pconfig['blockpriv'],
3115
	'yes'
3116
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3117
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3118
			'lies in such a private address space, too.');
3119

    
3120
$section->addInput(new Form_Checkbox(
3121
	'blockbogons',
3122
	'Block bogon networks',
3123
	'',
3124
	$pconfig['blockbogons'],
3125
	'yes'
3126
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3127
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3128
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3129

    
3130
$form->add($section);
3131

    
3132
$form->addGlobal(new Form_Input(
3133
	'if',
3134
	null,
3135
	'hidden',
3136
	$if
3137
));
3138

    
3139
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3140
	$form->addGlobal(new Form_Input(
3141
		'ppp_port',
3142
		null,
3143
		'hidden',
3144
		$pconfig['port']
3145
	));
3146
}
3147

    
3148
$form->addGlobal(new Form_Input(
3149
	'ptpid',
3150
	null,
3151
	'hidden',
3152
	$pconfig['ptpid']
3153
));
3154

    
3155

    
3156
// Add new gateway modal pop-up
3157
$modal = new Modal('New gateway', 'newgateway', 'large');
3158

    
3159
$modal->addInput(new Form_Checkbox(
3160
	'defaultgw',
3161
	'Default',
3162
	'Default gateway',
3163
	($if == "wan" || $if == "WAN")
3164
));
3165

    
3166
$modal->addInput(new Form_Input(
3167
	'name',
3168
	'Gateway name',
3169
	'text',
3170
	$wancfg['descr'] . "GW"
3171
));
3172

    
3173
$modal->addInput(new Form_IpAddress(
3174
	'gatewayip',
3175
	'Gateway IPv4',
3176
	null
3177
));
3178

    
3179
$modal->addInput(new Form_Input(
3180
	'gatewaydescr',
3181
	'Description',
3182
	'text'
3183
));
3184

    
3185
$btnaddgw = new Form_Button(
3186
	'add',
3187
	'Add'
3188
);
3189

    
3190
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3191

    
3192
$btncnxgw = new Form_Button(
3193
	'cnx',
3194
	'Cancel'
3195
);
3196

    
3197
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3198

    
3199
$modal->addInput(new Form_StaticText(
3200
	null,
3201
	$btnaddgw . $btncnxgw
3202
));
3203

    
3204
$form->add($modal);
3205

    
3206
print($form);
3207
?>
3208

    
3209
<script type="text/javascript">
3210
//<![CDATA[
3211
events.push(function() {
3212
	function updateType(t) {
3213

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

    
3248
		if (t != "l2tp" && t != "pptp") {
3249
			$('.'+t).show();
3250
		}
3251
	}
3252

    
3253
	function updateTypeSix(t) {
3254
		if (!isNaN(t[0])) {
3255
			t = '_' + t;
3256
		}
3257

    
3258
		switch (t) {
3259
			case "none": {
3260
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3261
				break;
3262
			}
3263
			case "staticv6": {
3264
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3265
				break;
3266
			}
3267
			case "slaac": {
3268
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3269
				break;
3270
			}
3271
			case "dhcp6": {
3272
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3273
				break;
3274
			}
3275
			case "6rd_": {
3276
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3277
				break;
3278
			}
3279
			case "_6to4": {
3280
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3281
				break;
3282
			}
3283
			case "track6": {
3284
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3285
				update_track6_prefix();
3286
				break;
3287
			}
3288
		}
3289

    
3290
		if (t != "l2tp" && t != "pptp") {
3291
			$('.'+t).show();
3292
		}
3293
	}
3294

    
3295
	function show_reset_settings(reset_type) {
3296
		if (reset_type == 'preset') {
3297
			$('.pppoepreset').show();
3298
			$('.pppoecustom').hide();
3299
		} else if (reset_type == 'custom') {
3300
			$('.pppoecustom').show();
3301
			$('.pppoepreset').hide();
3302
		} else {
3303
			$('.pppoecustom').hide();
3304
			$('.pppoepreset').hide();
3305
		}
3306
	}
3307

    
3308
	function update_track6_prefix() {
3309
		var iface = $("#track6-interface").val();
3310
		if (iface == null) {
3311
			return;
3312
		}
3313

    
3314
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3315
		if (track6_prefix_ids == null) {
3316
			return;
3317
		}
3318

    
3319
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3320
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3321
	}
3322

    
3323
	// Create the new gateway from the data entered in the modal pop-up
3324
	function hide_add_gatewaysave() {
3325
		var iface = $('#if').val();
3326
		name = $('#name').val();
3327
		var descr = $('#gatewaydescr').val();
3328
		gatewayip = $('#gatewayip').val();
3329

    
3330
		var defaultgw = '';
3331
		if ($('#defaultgw').is(':checked')) {
3332
			defaultgw = '&defaultgw=on';
3333
		}
3334

    
3335
		var url = "system_gateways_edit.php";
3336
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3337
		$.ajax(
3338
			url,
3339
			{
3340
				type: 'post',
3341
				data: pars,
3342
				error: report_failure,
3343
				complete: save_callback
3344
			});
3345
		}
3346

    
3347
	function save_callback(response) {
3348
		if (response) {
3349
			var gwtext = escape(name) + " - " + gatewayip;
3350
			addOption($('#gateway'), gwtext, name);
3351
		} else {
3352
			report_failure();
3353
		}
3354

    
3355
		$("#newgateway").modal('hide');
3356
	}
3357

    
3358
	function report_failure(request, textStatus, errorThrown) {
3359
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3360
			alert(request.responseText);
3361
		} else {
3362
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3363
		}
3364

    
3365
		$("#newgateway").modal('hide');
3366
	}
3367

    
3368
	function addOption(selectbox, text, value) {
3369
		var optn = document.createElement("OPTION");
3370
		optn.text = text;
3371
		optn.value = value;
3372
		selectbox.append(optn);
3373
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3374
	}
3375

    
3376
	function hide_add_gatewaysave_v6() {
3377

    
3378
		var iface = $('#if').val();
3379
		name = $('#name6').val();
3380
		var descr = $('#gatewaydescr6').val();
3381
		gatewayip = $('#gatewayip6').val();
3382
		var defaultgw = '';
3383
		if ($('#defaultgw6').is(':checked')) {
3384
			defaultgw = '&defaultgw=on';
3385
		}
3386
		var url_v6 = "system_gateways_edit.php";
3387
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3388
		$.ajax(
3389
			url_v6,
3390
			{
3391
				type: 'post',
3392
				data: pars_v6,
3393
				error: report_failure_v6,
3394
				success: save_callback_v6
3395
			});
3396
	}
3397

    
3398

    
3399
	function addOption_v6(selectbox, text, value) {
3400
		var optn = document.createElement("OPTION");
3401
		optn.text = text;
3402
		optn.value = value;
3403
		selectbox.append(optn);
3404
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3405
	}
3406

    
3407
	function report_failure_v6(request, textStatus, errorThrown) {
3408
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3409
			alert(request.responseText);
3410
		} else {
3411
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3412
		}
3413

    
3414
		$("#newgateway6").modal('hide');
3415
	}
3416

    
3417
	function save_callback_v6(response_v6) {
3418
		if (response_v6) {
3419

    
3420
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3421
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3422
		} else {
3423
			report_failure_v6();
3424
		}
3425

    
3426
		$("#newgateway6").modal('hide');
3427
	}
3428

    
3429
	function country_list() {
3430
		$('#country').children().remove();
3431
		$('#provider_list').children().remove();
3432
		$('#providerplan').children().remove();
3433
		$.ajax("getserviceproviders.php",{
3434
			success: function(response) {
3435

    
3436
				var responseTextArr = response.split("\n");
3437
				responseTextArr.sort();
3438

    
3439
				responseTextArr.forEach( function(value) {
3440
					country = value.split(":");
3441
					$('#country').append($('<option>', {
3442
						value: country[1],
3443
						text : country[0]
3444
					}));
3445
				});
3446
			}
3447
		});
3448
	}
3449

    
3450
	function providers_list() {
3451
		$('#provider_list').children().remove();
3452
		$('#providerplan').children().remove();
3453
		$.ajax("getserviceproviders.php",{
3454
			type: 'post',
3455
			data: {country : $('#country').val()},
3456
			success: function(response) {
3457
				var responseTextArr = response.split("\n");
3458
				responseTextArr.sort();
3459
				responseTextArr.forEach( function(value) {
3460
					$('#provider_list').append($('<option>', {
3461
							value: value,
3462
							text : value
3463
					}));
3464
				});
3465
			}
3466
		});
3467
	}
3468

    
3469
	function providerplan_list() {
3470
		$('#providerplan').children().remove();
3471
		$.ajax("getserviceproviders.php",{
3472
			type: 'post',
3473
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3474
			success: function(response) {
3475
				var responseTextArr = response.split("\n");
3476
				responseTextArr.sort();
3477

    
3478
				$('#providerplan').append($('<option>', {
3479
					value: '',
3480
					text : ''
3481
				}));
3482

    
3483
				responseTextArr.forEach( function(value) {
3484
					if (value != "") {
3485
						providerplan = value.split(":");
3486

    
3487
						$('#providerplan').append($('<option>', {
3488
							value: providerplan[1],
3489
							text : providerplan[0] + " - " + providerplan[1]
3490
						}));
3491
					}
3492
				});
3493
			}
3494
		});
3495
	}
3496

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

    
3521
	function show_dhcp6adv() {
3522
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3523
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3524

    
3525
		hideCheckbox('dhcp6usev4iface', ovr);
3526
		hideCheckbox('dhcp6prefixonly', ovr);
3527
		hideInput('dhcp6-ia-pd-len', ovr);
3528
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3529
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3530

    
3531
		hideClass('dhcp6advanced', !adv || ovr);
3532
	}
3533

    
3534
	function setDHCPoptions() {
3535
		var adv = $('#dhcpadv').prop('checked');
3536
		var ovr = $('#dhcpovr').prop('checked');
3537

    
3538
		if (ovr) {
3539
			hideInput('dhcphostname', true);
3540
			hideIpAddress('alias-address', true);
3541
			hideInput('dhcprejectfrom', true);
3542
			hideInput('adv_dhcp_config_file_override_path', false);
3543
			hideClass('dhcpadvanced', true);
3544
		} else {
3545
			hideInput('dhcphostname', false);
3546
			hideIpAddress('alias-address', false);
3547
			hideInput('dhcprejectfrom', false);
3548
			hideInput('adv_dhcp_config_file_override_path', true);
3549
			hideClass('dhcpadvanced', !adv);
3550
		}
3551
	}
3552

    
3553
	// DHCP preset actions
3554
	// Set presets from value of radio buttons
3555
	function setPresets(val) {
3556
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3557
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3558
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3559
		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']);?>");
3560
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3561
	}
3562

    
3563
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3564
		$('#adv_dhcp_pt_timeout').val(timeout);
3565
		$('#adv_dhcp_pt_retry').val(retry);
3566
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3567
		$('#adv_dhcp_pt_reboot').val(reboot);
3568
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3569
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3570
	}
3571

    
3572
	// ---------- On initial page load ------------------------------------------------------------
3573

    
3574
	updateType($('#type').val());
3575
	updateTypeSix($('#type6').val());
3576
	show_reset_settings($('#pppoe-reset-type').val());
3577
	$("#add").prop('type', 'button');
3578
	$("#cnx").prop('type', 'button');
3579
	$("#addgw").prop('type', 'button');
3580
	$("#add6").prop('type', 'button');
3581
	$("#cnx6").prop('type', 'button');
3582
	$("#addgw6").prop('type', 'button');
3583
	hideClass('dhcp6advanced', true);
3584
	hideClass('dhcpadvanced', true);
3585
	show_dhcp6adv();
3586
	setDHCPoptions()
3587

    
3588
	// Set preset buttons on page load
3589
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3590
	if (sv == "") {
3591
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3592
	} else {
3593
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3594
	}
3595

    
3596
	// Set preset from value
3597
	setPresets(sv);
3598

    
3599
	// ---------- Click checkbox handlers ---------------------------------------------------------
3600

    
3601
	$('#type').on('change', function() {
3602
		updateType(this.value);
3603
	});
3604

    
3605
	$('#type6').on('change', function() {
3606
		updateTypeSix(this.value);
3607
	});
3608

    
3609
	$('#pppoe-reset-type').on('change', function() {
3610
		show_reset_settings(this.value);
3611
	});
3612

    
3613
	$("#add").click(function() {
3614
		hide_add_gatewaysave();
3615
	});
3616

    
3617
	$("#cnx").click(function() {
3618
		$("#newgateway").modal('hide');
3619
	});
3620

    
3621
	$("#add6").click(function() {
3622
		hide_add_gatewaysave_v6();
3623
	});
3624

    
3625
	$("#cnx6").click(function() {
3626
		$("#newgateway6").modal('hide');
3627
	});
3628

    
3629
	$('#country').on('change', function() {
3630
		providers_list();
3631
	});
3632

    
3633
	$('#provider_list').on('change', function() {
3634
		providerplan_list();
3635
	});
3636

    
3637
	$('#providerplan').on('change', function() {
3638
		prefill_provider();
3639
	});
3640

    
3641
	$('#dhcpadv, #dhcpovr').click(function () {
3642
		setDHCPoptions();
3643
	});
3644

    
3645
	$('#adv_dhcp6_config_advanced').click(function () {
3646
		show_dhcp6adv();
3647
	});
3648

    
3649
	$('#adv_dhcp6_config_file_override').click(function () {
3650
		show_dhcp6adv();
3651
	});
3652

    
3653
	// On click . .
3654
	$('[name=adv_dhcp_pt_values]').click(function () {
3655
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3656
	});
3657

    
3658
});
3659
//]]>
3660
</script>
3661

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