Project

General

Profile

Download (124 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004-2008 Scott Ullrich
9
 *	Copyright (c) 2006 Daniel S. Haischt
10
 *	Copyright (c) 2008-2010 Ermal Luçi
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
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
61
	pfSense_MODULE: interfaces
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-interfaces
66
##|*NAME=Interfaces: WAN page
67
##|*DESCR=Allow access to the 'Interfaces' page.
68
##|*MATCH=interfaces.php*
69
##|-PRIV
70

    
71
require_once("guiconfig.inc");
72
require_once("ipsec.inc");
73
require_once("functions.inc");
74
require_once("captiveportal.inc");
75
require_once("filter.inc");
76
require_once("shaper.inc");
77
require_once("rrd.inc");
78
require_once("vpn.inc");
79
require_once("xmlparse_attr.inc");
80

    
81
define("ALLOWWEP", false);
82
define("ANTENNAS", false);
83

    
84
if (isset($_POST['referer'])) {
85
	$referer = $_POST['referer'];
86
} else {
87
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
88
}
89

    
90
// Get configured interface list
91
$ifdescrs = get_configured_interface_with_descr(false, true);
92

    
93
$if = "wan";
94
if ($_REQUEST['if']) {
95
	$if = $_REQUEST['if'];
96
}
97

    
98
if (empty($ifdescrs[$if])) {
99
	header("Location: interfaces.php");
100
	exit;
101
}
102

    
103
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
104
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
105
define("CRON_DAILY_PATTERN", "0 0 * * *");
106
define("CRON_HOURLY_PATTERN", "0 * * * *");
107

    
108
if (!is_array($pconfig)) {
109
	$pconfig = array();
110
}
111

    
112
if (!is_array($config['ppps'])) {
113
	$config['ppps'] = array();
114
}
115
if (!is_array($config['ppps']['ppp'])) {
116
	$config['ppps']['ppp'] = array();
117
}
118
$a_ppps = &$config['ppps']['ppp'];
119

    
120
function remove_bad_chars($string) {
121
	return preg_replace('/[^a-z_0-9]/i', '', $string);
122
}
123

    
124
if (!is_array($config['gateways']['gateway_item'])) {
125
	$config['gateways']['gateway_item'] = array();
126
}
127
$a_gateways = &$config['gateways']['gateway_item'];
128

    
129
$wancfg = &$config['interfaces'][$if];
130
$old_wancfg = $wancfg;
131
$old_wancfg['realif'] = get_real_interface($if);
132
$old_ppps = $a_ppps;
133
// Populate page descr if it does not exist.
134
if ($if == "wan" && !$wancfg['descr']) {
135
	$wancfg['descr'] = "WAN";
136
} else if ($if == "lan" && !$wancfg['descr']) {
137
	$wancfg['descr'] = "LAN";
138
}
139

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

    
147
$type_disabled = (substr($wancfg['if'], 0, 3) == 'gre') ? 'disabled="disabled"' : '';
148

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

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

    
166
		/* ================================================ */
167
		/* = force a connection reset at a specific time? = */
168
		/* ================================================ */
169

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

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

    
235
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
236

    
237
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
238
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
239
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
240
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
241

    
242
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
243
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
244
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
245

    
246
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
247
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
248
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
249
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
250

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

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

    
263
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
264
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
265

    
266
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
267
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
268
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
269
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
270

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

    
277
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
278
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
279
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
280

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

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

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

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

    
364
// print_r($pconfig);
365

    
366
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
367
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
368
$pconfig['spoofmac'] = $wancfg['spoofmac'];
369
$pconfig['mtu'] = $wancfg['mtu'];
370
$pconfig['mss'] = $wancfg['mss'];
371

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

    
449
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
450

    
451
	if(ALLOWWEP) {
452
		$pconfig['wep_enable'] = isset($wancfg['wireless']['wep']['enable']);
453

    
454
		if (is_array($wancfg['wireless']['wep']) && is_array($wancfg['wireless']['wep']['key'])) {
455
			$i = 1;
456
			foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
457
				$pconfig['key' . $i] = $wepkey['value'];
458
				if (isset($wepkey['txkey'])) {
459
					$pconfig['txkey'] = $i;
460
				}
461
				$i++;
462
			}
463
			if (!isset($wepkey['txkey'])) {
464
				$pconfig['txkey'] = 1;
465
			}
466
		}
467
	}
468
}
469

    
470
if ($_POST['apply']) {
471
	unset($input_errors);
472
	if (!is_subsystem_dirty('interfaces')) {
473
		$input_errors[] = gettext("You have already applied your settings!");
474
	} else {
475
		unlink_if_exists("{$g['tmp_path']}/config.cache");
476
		clear_subsystem_dirty('interfaces');
477

    
478
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
479
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
480
			foreach ($toapplylist as $ifapply => $ifcfgo) {
481
				if (isset($config['interfaces'][$ifapply]['enable'])) {
482
					interface_bring_down($ifapply, false, $ifcfgo);
483
					interface_configure($ifapply, true);
484
				} else {
485
					interface_bring_down($ifapply, true, $ifcfgo);
486
					if (isset($config['dhcpd'][$ifapply]['enable']) ||
487
						isset($config['dhcpdv6'][$ifapply]['enable'])) {
488
						services_dhcpd_configure();
489
					}
490
				}
491
			}
492
		}
493
		/* restart snmp so that it binds to correct address */
494
		services_snmpd_configure();
495

    
496
		/* sync filter configuration */
497
		setup_gateways_monitor();
498

    
499
		clear_subsystem_dirty('interfaces');
500

    
501
		filter_configure();
502

    
503
		enable_rrd_graphing();
504

    
505
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
506
			clear_subsystem_dirty('staticroutes');
507
		}
508
	}
509
	@unlink("{$g['tmp_path']}/.interfaces.apply");
510
	header("Location: interfaces.php?if={$if}");
511
	exit;
512
} else if ($_POST && $_POST['enable'] != "yes") {
513
	unset($wancfg['enable']);
514
	if (isset($wancfg['wireless'])) {
515
		interface_sync_wireless_clones($wancfg, false);
516
	}
517
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
518
	mark_subsystem_dirty('interfaces');
519
	if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
520
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
521
	} else {
522
		$toapplylist = array();
523
	}
524
	$toapplylist[$if]['ifcfg'] = $wancfg;
525
	$toapplylist[$if]['ppps'] = $a_ppps;
526
	/* we need to be able remove IP aliases for IPv6 */
527
	file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
528
	header("Location: interfaces.php?if={$if}");
529
	exit;
530
} else if ($_POST) {
531

    
532
	unset($input_errors);
533
	$pconfig = $_POST;
534

    
535
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
536
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
537
	} else {
538
		$pconfig['track6-prefix-id'] = 0;
539
	}
540
	conf_mount_rw();
541

    
542
	/* filter out spaces from descriptions */
543
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
544

    
545
	/* okay first of all, cause we are just hiding the PPPoE HTML
546
	 * fields related to PPPoE resets, we are going to unset $_POST
547
	 * vars, if the reset feature should not be used. Otherwise the
548
	 * data validation procedure below, may trigger a false error
549
	 * message.
550
	 */
551
	if (empty($_POST['pppoe-reset-type'])) {
552
		unset($_POST['pppoe_pr_type']);
553
		unset($_POST['pppoe_resethour']);
554
		unset($_POST['pppoe_resetminute']);
555
		unset($_POST['pppoe_resetdate']);
556
		unset($_POST['pppoe_pr_preset_val']);
557
	}
558
	/* description unique? */
559
	foreach ($ifdescrs as $ifent => $ifdescr) {
560
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
561
			$input_errors[] = gettext("An interface with the specified description already exists.");
562
			break;
563
		}
564
	}
565
	if (is_numeric($_POST['descr'])) {
566
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
567
	}
568
	/* input validation */
569
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
570
		$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.");
571
	}
572
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
573
		$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.");
574
	}
575

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

    
683
			if ($_POST['track6-prefix-id--hex'] != "" && !is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
684
				$input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID.");
685
			} else {
686
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
687
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
688
					$input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range.") .
689
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
690
				} else {
691
					foreach ($ifdescrs as $ifent => $ifdescr) {
692
						if ($if == $ifent) {
693
							continue;
694
						}
695
						if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' &&
696
							$config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] &&
697
							$config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) {
698
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
699
						}
700
					}
701
				}
702
			}
703
			break;
704
	}
705

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

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

    
731
			foreach ($staticroutes as $route_subnet) {
732
				list($network, $subnet) = explode("/", $route_subnet);
733
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
734
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
735
					break;
736
				}
737
				unset($network, $subnet);
738
			}
739
		}
740
	}
741
	if ($_POST['ipaddrv6']) {
742
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
743
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
744
		} else {
745
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
746
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
747
			}
748
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
749
			if (count($where_ipaddr_configured)) {
750
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
751
				foreach ($where_ipaddr_configured as $subnet_conflict) {
752
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
753
				}
754
				$input_errors[] = $subnet_conflict_text;
755
			}
756

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

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

    
846
		unset($min_mtu, $max_mtu);
847

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

    
864
				$realhwif_array = get_parent_interface($ifdata['if']);
865
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
866
				$parent_realhwif = $realhwif_array[0];
867

    
868
				if ($parent_realhwif != $wancfg['if']) {
869
					continue;
870
				}
871

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

    
959
		if(ALLOWWEP) {
960
			/* loop through keys and enforce size */
961
			for ($i = 1; $i <= 4; $i++) {
962
				if ($_POST['key' . $i]) {
963
					/* 64 bit */
964
					if (strlen($_POST['key' . $i]) == 5) {
965
						continue;
966
					}
967

    
968
					if (strlen($_POST['key' . $i]) == 10) {
969
						/* hex key */
970
						if (stristr($_POST['key' . $i], "0x") == false) {
971
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
972
						}
973
						continue;
974
					}
975

    
976
					if (strlen($_POST['key' . $i]) == 12) {
977
						/* hex key */
978
						if (stristr($_POST['key' . $i], "0x") == false) {
979
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
980
						}
981
						continue;
982
					}
983

    
984
					/* 128 bit */
985
					if (strlen($_POST['key' . $i]) == 13) {
986
						continue;
987
					}
988

    
989
					if (strlen($_POST['key' . $i]) == 26) {
990
						/* hex key */
991
						if (stristr($_POST['key' . $i], "0x") == false) {
992
							$_POST['key' . $i] = "0x" . $_POST['key' . $i];
993
						}
994
						continue;
995
					}
996

    
997
					if (strlen($_POST['key' . $i]) == 28) {
998
						continue;
999
					}
1000

    
1001
					$input_errors[] = gettext("Invalid WEP key. Enter a valid 40, 64, 104 or 128 bit WEP key.");
1002
					break;
1003
				}
1004
			}
1005
		}
1006

    
1007
		if ($_POST['passphrase']) {
1008
			$passlen = strlen($_POST['passphrase']);
1009
			if ($passlen < 8 || $passlen > 63) {
1010
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1011
			}
1012
		}
1013

    
1014
		if ($_POST['wpa_enable'] == "yes") {
1015
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1016
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1017
			}
1018
		}
1019
	}
1020
	if (!$input_errors) {
1021
		// These 3 fields can be a list of multiple data items when used for MLPPP.
1022
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
1023
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
1024
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
1025
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
1026

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1228
				if (!empty($_POST['pppoe-reset-type'])) {
1229
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1230
				} else {
1231
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1232
				}
1233
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1234
				$wancfg['ipaddr'] = $_POST['type'];
1235
				if ($gateway_item) {
1236
					$a_gateways[] = $gateway_item;
1237
				}
1238

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

    
1299
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1300
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1301
				}
1302
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1303
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1304
				}
1305
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1306
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1307
				}
1308
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1309
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1310
				}
1311

    
1312
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1313
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1314
				}
1315
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1316
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1317
				}
1318
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1319
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1320
				}
1321
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1322
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1323
				}
1324
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1325
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1326
				}
1327

    
1328
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1329
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1330
				}
1331
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1332
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1333
				}
1334
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1335
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1336
				}
1337
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1338
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1339
				}
1340
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1341
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1342
				}
1343

    
1344
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1345
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1346
				}
1347
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1348
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1349
				}
1350

    
1351
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1352
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1353
				}
1354
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1355
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1356
				}
1357
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1358
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1359
				}
1360
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1361
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1362
				}
1363

    
1364
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1365
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1366
				}
1367
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1368
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1369
				}
1370
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1371
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1372
				}
1373
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1374
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1375
				}
1376
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1377
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1378
				}
1379

    
1380
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1381
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1382
				}
1383
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1384
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1385
				}
1386
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1387
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1388
				}
1389

    
1390
				if ($gateway_item) {
1391
					$a_gateways[] = $gateway_item;
1392
				}
1393
				break;
1394
			case "6rd":
1395
				$wancfg['ipaddrv6'] = "6rd";
1396
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1397
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1398
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1399
				if ($gateway_item) {
1400
					$a_gateways[] = $gateway_item;
1401
				}
1402
				break;
1403
			case "6to4":
1404
				$wancfg['ipaddrv6'] = "6to4";
1405
				break;
1406
			case "track6":
1407
				$wancfg['ipaddrv6'] = "track6";
1408
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1409
				if ($_POST['track6-prefix-id--hex'] === "") {
1410
					$wancfg['track6-prefix-id'] = 0;
1411
				} else if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
1412
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1413
				} else {
1414
					$wancfg['track6-prefix-id'] = 0;
1415
				}
1416
				break;
1417
			case "none":
1418
				break;
1419
		}
1420
		handle_pppoe_reset($_POST);
1421

    
1422
		if ($_POST['blockpriv'] == "yes") {
1423
			$wancfg['blockpriv'] = true;
1424
		} else {
1425
			unset($wancfg['blockpriv']);
1426
		}
1427
		if ($_POST['blockbogons'] == "yes") {
1428
			$wancfg['blockbogons'] = true;
1429
		} else {
1430
			unset($wancfg['blockbogons']);
1431
		}
1432
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1433
		if (empty($_POST['mtu'])) {
1434
			unset($wancfg['mtu']);
1435
		} else {
1436
			$wancfg['mtu'] = $_POST['mtu'];
1437
		}
1438
		if (empty($_POST['mss'])) {
1439
			unset($wancfg['mss']);
1440
		} else {
1441
			$wancfg['mss'] = $_POST['mss'];
1442
		}
1443
		if (empty($_POST['mediaopt'])) {
1444
			unset($wancfg['media']);
1445
			unset($wancfg['mediaopt']);
1446
		} else {
1447
			$mediaopts = explode(' ', $_POST['mediaopt']);
1448
			if ($mediaopts[0] != '') {
1449
				$wancfg['media'] = $mediaopts[0];
1450
			}
1451
			if ($mediaopts[1] != '') {
1452
				$wancfg['mediaopt'] = $mediaopts[1];
1453
			} else {
1454
				unset($wancfg['mediaopt']);
1455
			}
1456
		}
1457
		if (isset($wancfg['wireless'])) {
1458
			handle_wireless_post();
1459
		}
1460

    
1461
		conf_mount_ro();
1462
		write_config();
1463

    
1464
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1465
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1466
		} else {
1467
			$toapplylist = array();
1468
		}
1469
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1470
		$toapplylist[$if]['ppps'] = $old_ppps;
1471
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1472

    
1473
		mark_subsystem_dirty('interfaces');
1474

    
1475
		/* regenerate cron settings/crontab file */
1476
		configure_cron();
1477

    
1478
		header("Location: interfaces.php?if={$if}");
1479
		exit;
1480
	}
1481

    
1482
} // end if ($_POST)
1483

    
1484
function handle_wireless_post() {
1485
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1486
	if (!is_array($wancfg['wireless'])) {
1487
		$wancfg['wireless'] = array();
1488
	}
1489
	$wancfg['wireless']['standard'] = $_POST['standard'];
1490
	$wancfg['wireless']['mode'] = $_POST['mode'];
1491
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1492
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1493
	$wancfg['wireless']['channel'] = $_POST['channel'];
1494
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1495
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1496
	$wancfg['wireless']['distance'] = $_POST['distance'];
1497
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1498
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1499
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1500
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1501
		foreach ($wl_countries_attr as $wl_country) {
1502
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1503
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1504
				break;
1505
			}
1506
		}
1507
	}
1508
	if (!is_array($wancfg['wireless']['wpa'])) {
1509
		$wancfg['wireless']['wpa'] = array();
1510
	}
1511
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1512
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
1513
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1514
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1515
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1516
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1517
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1518
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1519
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1520
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1521
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1522
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1523
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1524
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1525
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1526

    
1527
	if ($_POST['persistcommonwireless'] == "yes") {
1528
		if (!is_array($config['wireless'])) {
1529
			$config['wireless'] = array();
1530
		}
1531
		if (!is_array($config['wireless']['interfaces'])) {
1532
			$config['wireless']['interfaces'] = array();
1533
		}
1534
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1535
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1536
		}
1537
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1538
		unset($config['wireless']['interfaces'][$wlanbaseif]);
1539
	}
1540
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1541
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1542
	} else if (isset($wancfg['wireless']['diversity'])) {
1543
		unset($wancfg['wireless']['diversity']);
1544
	}
1545
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1546
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1547
	} else if (isset($wancfg['wireless']['txantenna'])) {
1548
		unset($wancfg['wireless']['txantenna']);
1549
	}
1550
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1551
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1552
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1553
		unset($wancfg['wireless']['rxantenna']);
1554
	}
1555
	if ($_POST['hidessid_enable'] == "yes") {
1556
		$wancfg['wireless']['hidessid']['enable'] = true;
1557
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1558
		unset($wancfg['wireless']['hidessid']['enable']);
1559
	}
1560
	if ($_POST['mac_acl_enable'] == "yes") {
1561
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1562
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1563
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1564
	}
1565
	if ($_POST['rsn_preauth'] == "yes") {
1566
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1567
	} else {
1568
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1569
	}
1570
	if ($_POST['ieee8021x'] == "yes") {
1571
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1572
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1573
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1574
	}
1575
	if ($_POST['wpa_strict_rekey'] == "yes") {
1576
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1577
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1578
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1579
	}
1580
	if ($_POST['debug_mode'] == "yes") {
1581
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1582
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1583
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1584
	}
1585
	if ($_POST['wpa_enable'] == "yes") {
1586
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1587
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1588
		unset($wancfg['wireless']['wpa']['enable']);
1589
	}
1590

    
1591
	if(ALLOWWEP) {
1592
		if ($_POST['wep_enable'] == "yes") {
1593
			if (!is_array($wancfg['wireless']['wep'])) {
1594
				$wancfg['wireless']['wep'] = array();
1595
			}
1596
			$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
1597
		} else if (isset($wancfg['wireless']['wep'])) {
1598
			unset($wancfg['wireless']['wep']);
1599
		}
1600
	}
1601

    
1602
	if ($_POST['wme_enable'] == "yes") {
1603
		if (!is_array($wancfg['wireless']['wme'])) {
1604
			$wancfg['wireless']['wme'] = array();
1605
		}
1606
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1607
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1608
		unset($wancfg['wireless']['wme']['enable']);
1609
	}
1610
	if ($_POST['puremode'] == "11g") {
1611
		if (!is_array($wancfg['wireless']['pureg'])) {
1612
			$wancfg['wireless']['pureg'] = array();
1613
		}
1614
		$wancfg['wireless']['pureg']['enable'] = true;
1615
	} else if ($_POST['puremode'] == "11n") {
1616
		if (!is_array($wancfg['wireless']['puren'])) {
1617
			$wancfg['wireless']['puren'] = array();
1618
		}
1619
		$wancfg['wireless']['puren']['enable'] = true;
1620
	} else {
1621
		if (isset($wancfg['wireless']['pureg'])) {
1622
			unset($wancfg['wireless']['pureg']);
1623
		}
1624
		if (isset($wancfg['wireless']['puren'])) {
1625
			unset($wancfg['wireless']['puren']);
1626
		}
1627
	}
1628
	if ($_POST['apbridge_enable'] == "yes") {
1629
		if (!is_array($wancfg['wireless']['apbridge'])) {
1630
			$wancfg['wireless']['apbridge'] = array();
1631
		}
1632
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1633
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1634
		unset($wancfg['wireless']['apbridge']['enable']);
1635
	}
1636
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1637
		if (!is_array($wancfg['wireless']['turbo'])) {
1638
			$wancfg['wireless']['turbo'] = array();
1639
		}
1640
		$wancfg['wireless']['turbo']['enable'] = true;
1641
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1642
		unset($wancfg['wireless']['turbo']['enable']);
1643
	}
1644

    
1645
	if(ALLOWWEP) {
1646
		$wancfg['wireless']['wep']['key'] = array();
1647
		for ($i = 1; $i <= 4; $i++) {
1648
			if ($_POST['key' . $i]) {
1649
				$newkey = array();
1650
				$newkey['value'] = $_POST['key' . $i];
1651
				if ($_POST['txkey'] == $i) {
1652
					$newkey['txkey'] = true;
1653
				}
1654
				$wancfg['wireless']['wep']['key'][] = $newkey;
1655
			}
1656
		}
1657
	}
1658

    
1659
	interface_sync_wireless_clones($wancfg, true);
1660
}
1661

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

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

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

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

    
1683
	if ($clone_count > 1) {
1684
		$old_wireless_mode = $wancfg['wireless']['mode'];
1685
		$wancfg['wireless']['mode'] = $_POST['mode'];
1686
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1687
			$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']]);
1688
		} else {
1689
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1690
		}
1691
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1692
	}
1693
}
1694

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

    
1710
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1711
$shortcut_section = "interfaces";
1712

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

    
1716
$closehead = false;
1717

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

    
1723
function build_mediaopts_list() {
1724
	global $mediaopts_list;
1725

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

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

    
1734
	return($list);
1735
}
1736

    
1737
function build_gateway_list() {
1738
	global $a_gateways;
1739

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

    
1747
	return($list);
1748
}
1749

    
1750
include("head.inc");
1751

    
1752
if ($input_errors)
1753
	print_input_errors($input_errors);
1754

    
1755
if (is_subsystem_dirty('interfaces'))
1756
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1757
					  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."));
1758

    
1759
if ($savemsg)
1760
	print_info_box($savemsg, 'success');
1761

    
1762

    
1763
require_once('classes/Form.class.php');
1764
require_once('classes/Modal.class.php');
1765

    
1766
$form = new Form(new Form_Button(
1767
	'Submit',
1768
	gettext("Save")
1769
));
1770

    
1771
$section = new Form_Section('General configuration');
1772

    
1773
$section->addInput(new Form_Checkbox(
1774
	'enable',
1775
	'Enable',
1776
	'Enable interface',
1777
	$pconfig['enable'],
1778
	'yes'
1779
));
1780

    
1781
$section->addInput(new Form_Input(
1782
	'descr',
1783
	'Description',
1784
	'text',
1785
	$pconfig['descr']
1786
))->setHelp('Enter a description (name) for the interface here.');
1787

    
1788
$section->addInput(new Form_Select(
1789
	'type',
1790
	'IPv4 Configuration Type',
1791
	$pconfig['type'],
1792
	$types4
1793
));
1794

    
1795
$section->addInput(new Form_Select(
1796
	'type6',
1797
	'IPv6 Configuration Type',
1798
	$pconfig['type6'],
1799
	$types6
1800
));
1801

    
1802
$macaddress = new Form_Input(
1803
	'mac',
1804
	'MAC Address',
1805
	'text',
1806
	$pconfig['mac'],
1807
	['placeholder' => 'xx:xx:xx:xx:xx:xx']
1808
);
1809

    
1810
$btnmymac = new Form_Button(
1811
	'btnmymac',
1812
	'Copy My MAC'
1813
	);
1814

    
1815
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1816

    
1817
$group = new Form_Group('MAC controls');
1818
$group->add($macaddress);
1819
// $group->add($btnmymac);
1820
$group->setHelp('This field can be used to modify ("spoof") the MAC address of this interface.' . '<br />' .
1821
				'Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank');
1822
$section->add($group);
1823

    
1824
$section->addInput(new Form_Input(
1825
	'mtu',
1826
	'MTU',
1827
	'number',
1828
	$pconfig['mtu']
1829
))->setHelp('If you leave this field blank, the adapter\'s default MTU will be used. ' .
1830
			'This is typically 1500 bytes but can vary in some circumstances.');
1831

    
1832
$section->addInput(new Form_Input(
1833
	'mss',
1834
	'MSS',
1835
	'number',
1836
	$pconfig['mss']
1837
))->setHelp('If you enter a value in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP ' .
1838
			'header size) will be in effect.');
1839

    
1840
if (count($mediaopts_list) > 0) {
1841
	$section->addInput(new Form_Select(
1842
		'mediaopt',
1843
		'Speed and Duplex',
1844
		rtrim($mediaopt_from_config),
1845
		build_mediaopts_list()
1846
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1847
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1848
}
1849

    
1850
$form->add($section);
1851

    
1852
$section = new Form_Section('Static IPv4 configuration');
1853
$section->addClass('staticv4');
1854

    
1855
$section->addInput(new Form_IpAddress(
1856
	'ipaddr',
1857
	'IPv4 Address',
1858
	$pconfig['ipaddr']
1859
))->addMask('subnet', $pconfig['subnet'], 32);
1860

    
1861
$group = new Form_Group('IPv4 Upstream gateway');
1862

    
1863
$group->add(new Form_Select(
1864
	'gateway',
1865
	'IPv4 Upstream Gateway',
1866
	$pconfig['gateway'],
1867
	build_gateway_list()
1868
));
1869

    
1870
$group->add(new Form_Button(
1871
	'addgw',
1872
	'Add a new gateway'
1873
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1874

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

    
1879
$section->add($group);
1880

    
1881
$form->add($section);
1882

    
1883
// Add new gateway modal pop-up
1884
$modal = new Modal('New gateway', 'newgateway', 'large');
1885

    
1886
$modal->addInput(new Form_Checkbox(
1887
	'defaultgw',
1888
	'Default',
1889
	'Default gateway',
1890
	($if == "wan" || $if == "WAN")
1891
));
1892

    
1893
$modal->addInput(new Form_Input(
1894
	'name',
1895
	'Gateway name',
1896
	'text',
1897
	$wancfg['descr'] . "GW"
1898
));
1899

    
1900
$modal->addInput(new Form_IpAddress(
1901
	'gatewayip',
1902
	'Gateway IPv4',
1903
	null
1904
));
1905

    
1906
$modal->addInput(new Form_Input(
1907
	'gatewaydescr',
1908
	'Description',
1909
	'text'
1910
));
1911

    
1912
$btnaddgw = new Form_Button(
1913
	'add',
1914
	'Add'
1915
);
1916

    
1917
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
1918

    
1919
$btncnxgw = new Form_Button(
1920
	'cnx',
1921
	'Cancel'
1922
);
1923

    
1924
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
1925

    
1926
$modal->addInput(new Form_StaticText(
1927
	null,
1928
	$btnaddgw . $btncnxgw
1929
));
1930

    
1931
$form->add($modal);
1932

    
1933
$section = new Form_Section('Static IPv6 configuration');
1934
$section->addClass('staticv6');
1935

    
1936
$section->addInput(new Form_IpAddress(
1937
	'ipaddrv6',
1938
	'IPv6 address',
1939
	$pconfig['ipaddrv6']
1940
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1941

    
1942
$group = new Form_Group('IPv6 Upstream gateway');
1943

    
1944
$group->add(new Form_Select(
1945
	'gatewayv6',
1946
	'IPv4 Upstream Gateway',
1947
	$pconfig['gateway'],
1948
	build_gateway_list()
1949
));
1950

    
1951
$group->add(new Form_Button(
1952
	'addgw6',
1953
	'Add a new gateway'
1954
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1955

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

    
1959
$section->add($group);
1960
$form->add($section);
1961

    
1962
// Add new gateway modal pop-up for IPv6
1963
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1964

    
1965
$modal->addInput(new Form_Checkbox(
1966
	'defaultgw6',
1967
	'Default',
1968
	'Default gateway',
1969
	($if == "wan" || $if == "WAN")
1970
));
1971

    
1972
$modal->addInput(new Form_Input(
1973
	'name6',
1974
	'Gateway name',
1975
	'text',
1976
	$wancfg['descr'] . "GW"
1977
));
1978

    
1979
$modal->addInput(new Form_IpAddress(
1980
	'gatewayip6',
1981
	'Gateway IPv4',
1982
	null
1983
));
1984

    
1985
$modal->addInput(new Form_Input(
1986
	'gatewaydescr6',
1987
	'Description',
1988
	'text'
1989
));
1990

    
1991
$btnaddgw6 = new Form_Button(
1992
	'add6',
1993
	'Add'
1994
);
1995

    
1996
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1997

    
1998
$btncnxgw6 = new Form_Button(
1999
	'cnx6',
2000
	'Cancel'
2001
);
2002

    
2003
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
2004

    
2005
$modal->addInput(new Form_StaticText(
2006
	null,
2007
	$btnaddgw6 . $btncnxgw6
2008
));
2009

    
2010
$form->add($modal);
2011

    
2012
// ==== DHCP client configuration =============================
2013

    
2014
$section = new Form_Section('DHCP client configuration');
2015
$section->addClass('dhcp');
2016

    
2017
$group = new Form_Group('Options');
2018

    
2019
$group->add(new Form_Checkbox(
2020
	'dhcpadv',
2021
	null,
2022
	'Show DHCP advanced options',
2023
	false
2024
));
2025

    
2026
$group->add(new Form_Checkbox(
2027
	'dhcpovr',
2028
	null,
2029
	'Config file override',
2030
	false
2031
));
2032

    
2033
$section->add($group);
2034

    
2035
$section->addInput(new Form_Input(
2036
	'dhcphostname',
2037
	'Hostname',
2038
	'text',
2039
	$pconfig['dhcphostname']
2040
))->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).');
2041

    
2042
$section->addInput(new Form_IpAddress(
2043
	'alias-address',
2044
	'Alias IPv4 address',
2045
	$pconfig['alias-address']
2046
))->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.');
2047

    
2048
$section->addInput(new Form_Input(
2049
	'dhcprejectfrom',
2050
	'Reject leases from',
2051
	'text',
2052
	$pconfig['dhcprejectfrom']
2053
))->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. ' .
2054
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
2055

    
2056
$group = new Form_Group('Protocol timing');
2057
$group->addClass('dhcpadvanced');
2058

    
2059
$group->add(new Form_Input(
2060
	'adv_dhcp_pt_timeout',
2061
	null,
2062
	'number',
2063
	$pconfig['adv_dhcp_pt_timeout']
2064
))->setHelp('Timeout');
2065

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

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

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

    
2087
$group->add(new Form_Input(
2088
	'adv_dhcp_pt_backoff_cutoff',
2089
	null,
2090
	'number',
2091
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2092
))->setHelp('Backoff cutoff');
2093

    
2094
$group->add(new Form_Input(
2095
	'adv_dhcp_pt_initial_interval',
2096
	null,
2097
	'number',
2098
	$pconfig['adv_dhcp_pt_initial_interval']
2099
))->setHelp('Initial interval');
2100

    
2101
$section->add($group);
2102

    
2103
$group = new Form_Group('Presets');
2104
$group->addClass('dhcpadvanced');
2105

    
2106
$group->add(new Form_Checkbox(
2107
	'adv_dhcp_pt_values',
2108
	null,
2109
	'FreeBSD default',
2110
	null,
2111
	'DHCP'
2112
))->displayAsRadio();
2113

    
2114
$group->add(new Form_Checkbox(
2115
	'adv_dhcp_pt_values',
2116
	null,
2117
	'Clear',
2118
	null,
2119
	'Clear'
2120
))->displayAsRadio();
2121

    
2122
$group->add(new Form_Checkbox(
2123
	'adv_dhcp_pt_values',
2124
	null,
2125
	'pfSense Default',
2126
	null,
2127
	'pfSense'
2128
))->displayAsRadio();
2129

    
2130
$group->add(new Form_Checkbox(
2131
	'adv_dhcp_pt_values',
2132
	null,
2133
	'Saved Cfg',
2134
	null,
2135
	'SavedCfg'
2136
))->displayAsRadio();
2137

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

    
2141
$section->add($group);
2142

    
2143
$section->addInput(new Form_Input(
2144
	'adv_dhcp_config_file_override_path',
2145
	'Option modifiers',
2146
	'text',
2147
	$pconfig['adv_dhcp_config_file_override_path']
2148
))->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]]' . '<br />' .
2149
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2150
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2151
			'Some ISPs may require certain options be or not be sent.');
2152

    
2153
$form->add($section);
2154

    
2155
$section = new Form_Section('Lease Requirements and Requests');
2156
$section->addClass('dhcpadvanced');
2157

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

    
2168
$section->addInput(new Form_Input(
2169
	'adv_dhcp_request_options',
2170
	'Request options',
2171
	'text',
2172
	$pconfig['adv_dhcp_request_options']
2173
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2174
			'Some ISPs may require certain options be or not be requested.');
2175

    
2176
$section->addInput(new Form_Input(
2177
	'adv_dhcp_require_options',
2178
	'Request options',
2179
	'text',
2180
	$pconfig['adv_dhcp_require_options']
2181
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2182

    
2183
$section->addInput(new Form_Input(
2184
	'adv_dhcp_option_modifiers',
2185
	'Option modifiers',
2186
	'text',
2187
	$pconfig['adv_dhcp_option_modifiers']
2188
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2189
			'modifiers: (default, supersede, prepend, append)');
2190

    
2191
$form->add($section);
2192

    
2193
// DHCP6 client config
2194

    
2195
$section = new Form_Section('DHCP6 client configuration');
2196
$section->addClass('dhcp6');
2197

    
2198
$section->addInput(new Form_Checkbox(
2199
	'dhcp6adv',
2200
	'Advanced',
2201
	'Show DHCPv6 advanced options',
2202
	$pconfig['adv_dhcp6_config_advanced']
2203
));
2204

    
2205
$section->addInput(new Form_Checkbox(
2206
	'adv_dhcp6_config_file_override',
2207
	'Config file override',
2208
	'Override the configuration from this file',
2209
	$pconfig['adv_dhcp6_config_file_override']
2210
));
2211

    
2212
$section->addInput(new Form_Checkbox(
2213
	'dhcp6usev4iface',
2214
	'Use IPv4 connectivity as parent interface',
2215
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2216
	$pconfig['dhcp6usev4iface']
2217
));
2218

    
2219
$section->addInput(new Form_Checkbox(
2220
	'dhcp6prefixonly',
2221
	'Request only an IPv6 prefix',
2222
	'Only request an IPv6 prefix, do not request an IPv6 address',
2223
	$pconfig['dhcp6prefixonly']
2224
));
2225

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

    
2233
$section->addInput(new Form_Checkbox(
2234
	'dhcp6-ia-pd-send-hint',
2235
	'Send IPv6 prefix hint',
2236
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2237
	$pconfig['dhcp6-ia-pd-send-hint']
2238
));
2239

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

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

    
2252
// DHCP6 client config - Advanced
2253

    
2254
$section = new Form_Section('Advanced DHCP6 client configuration');
2255
$section->addClass('dhcp6advanced');
2256

    
2257
$section->addInput(new Form_Checkbox(
2258
	'adv_dhcp6_interface_statement_information_only_enable',
2259
	'Information only',
2260
	null,
2261
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2262
));
2263

    
2264
$section->addInput(new Form_Input(
2265
	'adv_dhcp6_interface_statement_send_options',
2266
	'Send options',
2267
	'text',
2268
	$pconfig['adv_dhcp6_interface_statement_send_options']
2269
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2270
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2271
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2272
			'Some DHCP services may require certain options be or not be sent.');
2273

    
2274
$section->addInput(new Form_Input(
2275
	'adv_dhcp6_interface_statement_request_options',
2276
	'Request Options',
2277
	'text',
2278
	$pconfig['adv_dhcp6_interface_statement_request_options']
2279
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2280
			'Some DHCP services may require certain options be or not be requested.');
2281

    
2282
$section->addInput(new Form_Input(
2283
	'adv_dhcp6_interface_statement_script',
2284
	'Scripts',
2285
	'text',
2286
	$pconfig['adv_dhcp6_interface_statement_script']
2287
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2288
			'[/[dirname/[.../]]filename[.ext]].');
2289

    
2290
$group = new Form_Group('Identity Association Statement');
2291

    
2292
$group->add(new Form_Checkbox(
2293
	'adv_dhcp6_id_assoc_statement_address_enable',
2294
	null,
2295
	'Non-Temporary Address Allocation',
2296
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2297
));
2298

    
2299
$group->add(new Form_Input(
2300
	'adv_dhcp6_id_assoc_statement_address_id',
2301
	null,
2302
	'text',
2303
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2304
))->sethelp('id-assoc na ID');
2305

    
2306
$group->add(new Form_IpAddress(
2307
	'adv_dhcp6_id_assoc_statement_address',
2308
	null,
2309
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2310
))->sethelp('IPv6 address');
2311

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

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

    
2326
$section->add($group);
2327

    
2328
// Prefix delegation
2329
$group = new Form_Group('');
2330

    
2331
$group->add(new Form_Checkbox(
2332
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2333
	null,
2334
	'Prefix Delegation ',
2335
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2336
));
2337

    
2338
$group->add(new Form_Input(
2339
	'adv_dhcp6_id_assoc_statement_prefix_id',
2340
	null,
2341
	'text',
2342
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2343
))->sethelp('id-assoc pd ID');
2344

    
2345
$group->add(new Form_IpAddress(
2346
	'adv_dhcp6_id_assoc_statement_prefix',
2347
	null,
2348
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2349
))->sethelp('IPv6 prefix');
2350

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

    
2358
$group->add(new Form_Input(
2359
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2360
	null,
2361
	'text',
2362
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2363
))->sethelp('vltime');
2364

    
2365
$section->add($group);
2366

    
2367
$group = new Form_Group('Prefix interface statement');
2368

    
2369
$group->add(new Form_Input(
2370
	'adv_dhcp6_prefix_interface_statement_sla_id',
2371
	null,
2372
	'text',
2373
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2374
))->sethelp('Prefix Interface sla-id');
2375

    
2376
$group->add(new Form_Input(
2377
	'adv_dhcp6_prefix_interface_statement_sla_len',
2378
	null,
2379
	'text',
2380
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2381
))->sethelp('sla-len');
2382

    
2383
$section->add($group);
2384

    
2385
$group = new Form_Group('Authentication statement');
2386

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

    
2394
$group->add(new Form_Input(
2395
	'adv_dhcp6_authentication_statement_protocol',
2396
	null,
2397
	'text',
2398
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2399
))->sethelp('Protocol');
2400

    
2401
$group->add(new Form_Input(
2402
	'adv_dhcp6_authentication_statement_algorithm',
2403
	null,
2404
	'text',
2405
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2406
))->sethelp('Algorithm');
2407

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

    
2415
$section->add($group);
2416

    
2417
$group = new Form_Group('Keyinfo statement');
2418

    
2419
$group->add(new Form_Input(
2420
	'adv_dhcp6_key_info_statement_keyname',
2421
	null,
2422
	'text',
2423
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2424
))->sethelp('Keyname');
2425

    
2426
$group->add(new Form_Input(
2427
	'adv_dhcp6_key_info_statement_realm',
2428
	null,
2429
	'text',
2430
	$pconfig['adv_dhcp6_key_info_statement_realm']
2431
))->sethelp('Realm');
2432

    
2433
$section->add($group);
2434

    
2435
$group = new Form_Group('');
2436

    
2437
$group->add(new Form_Input(
2438
	'adv_dhcp6_key_info_statement_keyid',
2439
	null,
2440
	'text',
2441
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2442
))->sethelp('KeyID');
2443

    
2444
$group->add(new Form_Input(
2445
	'adv_dhcp6_key_info_statement_secret',
2446
	null,
2447
	'text',
2448
	$pconfig['adv_dhcp6_key_info_statement_secret']
2449
))->sethelp('Secret');
2450

    
2451
$group->add(new Form_Input(
2452
	'adv_dhcp6_key_info_statement_expire',
2453
	null,
2454
	'text',
2455
	$pconfig['adv_dhcp6_key_info_statement_expire']
2456
))->sethelp('Expire');
2457

    
2458
$section->add($group);
2459

    
2460
$form->add($section);
2461

    
2462
$section = new Form_Section('6RD Configuration');
2463
$section->addClass('_6rd');
2464

    
2465
$section->addInput(new Form_Input(
2466
	'prefix-6rd',
2467
	'6RD Prefix',
2468
	'text',
2469
	$pconfig['prefix-6rd']
2470
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2471

    
2472
$section->addInput(new Form_Input(
2473
	'gateway-6rd',
2474
	'6RD Border relay',
2475
	'text',
2476
	$pconfig['gateway-6rd']
2477
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2478

    
2479
$section->addInput(new Form_Select(
2480
	'prefix-6rd-v4plen',
2481
	'6RD IPv4 Prefix length',
2482
	$pconfig['prefix-6rd-v4plen'],
2483
	array_combine(range(0, 32), range(0, 32))
2484
))->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.');
2485

    
2486
$form->add($section);
2487

    
2488
// Track IPv6 ointerface section
2489
$section = new Form_Section('Track IPv6 Interface');
2490
$section->addClass('track6');
2491

    
2492
function build_ipv6interface_list() {
2493
	$list = array('' => '');
2494

    
2495
	$interfaces = get_configured_interface_with_descr(false, true);
2496
	$dynv6ifs = array();
2497

    
2498
	foreach ($interfaces as $iface => $ifacename) {
2499
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2500
			case "6to4":
2501
			case "6rd":
2502
			case "dhcp6":
2503
				$dynv6ifs[$iface] = array(
2504
					'name' => $ifacename,
2505
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2506
				);
2507
				break;
2508
			default:
2509
				continue;
2510
		}
2511
	}
2512

    
2513
	foreach ($dynv6ifs as $iface => $ifacedata) {
2514
		$list[$iface] = $ifacedata['name'];
2515

    
2516
		$section->addInput(new Form_Input(
2517
			'ipv6-num-prefix-ids-' . $iface,
2518
			null,
2519
			'hidden',
2520
			$ifacedata['ipv6_num_prefix_ids']
2521
		));
2522
	}
2523

    
2524
	return($list);
2525
}
2526

    
2527
$section->addInput(new Form_Select(
2528
	'track6-interface',
2529
	'IPv6 Interface',
2530
	$pconfig['track6-interface'],
2531
	build_ipv6interface_list()
2532
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2533

    
2534
if ($pconfig['track6-prefix-id'] == "") {
2535
	$pconfig['track6-prefix-id'] = 0;
2536
}
2537

    
2538
$section->addInput(new Form_Input(
2539
	'track6-prefix-id--hex' . $iface,
2540
	'IPv6 Prefix ID',
2541
	'text',
2542
	sprintf("%x", $pconfig['track6-prefix-id'])
2543
))->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.');
2544

    
2545
$section->addInput(new Form_Input(
2546
	'track6-prefix-id-max' . $iface,
2547
	null,
2548
	'hidden',
2549
	0
2550
));
2551

    
2552
$form->add($section);
2553

    
2554
/// PPP section
2555

    
2556
$section = new Form_Section('PPP Configuration');
2557
$section->addClass('ppp');
2558

    
2559
$section->addInput(new Form_Select(
2560
	'country',
2561
	'Country',
2562
	$pconfig['country'],
2563
	[]
2564
));
2565

    
2566
$section->addInput(new Form_Select(
2567
	'provider_list',
2568
	'Provider',
2569
	$pconfig['provider_list'],
2570
	[]
2571
));
2572

    
2573
$section->addInput(new Form_Select(
2574
	'providerplan',
2575
	'Plan',
2576
	$pconfig['providerplan'],
2577
	[]
2578
))->setHelp('Select to fill in data for your service provider.');
2579

    
2580
$section->addInput(new Form_Input(
2581
	'ppp_username',
2582
	'Username',
2583
	'text',
2584
	$pconfig['ppp_username']
2585
));
2586

    
2587
$section->addInput(new Form_Input(
2588
	'ppp_password',
2589
	'Password',
2590
	'password',
2591
	$pconfig['ppp_password']
2592
));
2593

    
2594
$section->addInput(new Form_Input(
2595
	'phone',
2596
	'Phone number',
2597
	'text',
2598
	$pconfig['phone']
2599
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2600

    
2601
$section->addInput(new Form_Input(
2602
	'apn',
2603
	'Access Point Name',
2604
	'text',
2605
	$pconfig['apn']
2606
));
2607

    
2608

    
2609
function build_port_list() {
2610
	$list = array("" => "None");
2611

    
2612
	$portlist = glob("/dev/cua*");
2613
	$modems	  = glob("/dev/modem*");
2614
	$portlist = array_merge($portlist, $modems);
2615

    
2616
	foreach ($portlist as $port) {
2617
		if (preg_match("/\.(lock|init)$/", $port)) {
2618
			continue;
2619
		}
2620

    
2621
	$list[trim($port)] = $port;
2622
	}
2623

    
2624
	return($list);
2625
}
2626

    
2627
$section->addInput(new Form_Select(
2628
	'port',
2629
	"Modem port",
2630
	$pconfig['port'],
2631
	build_port_list()
2632
));
2633

    
2634
$section->addInput(new Form_Button(
2635
	'btnadvppp',
2636
	'Advanced PPP',
2637
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2638
))->setHelp('Create a new PPP configuration');
2639

    
2640
$form->add($section);
2641

    
2642
// PPPoE configuration
2643
$section = new Form_Section('PPPoE Configuration');
2644
$section->addClass('pppoe');
2645

    
2646
$section->addInput(new Form_Input(
2647
	'pppoe_username',
2648
	'Username',
2649
	'text',
2650
	$pconfig['pppoe_username']
2651
));
2652

    
2653
$section->addInput(new Form_Input(
2654
	'pppoe_password',
2655
	'Password',
2656
	'password',
2657
	$pconfig['pppoe_password']
2658
));
2659

    
2660
$section->addInput(new Form_Input(
2661
	'provider',
2662
	'Service name',
2663
	'text',
2664
	$pconfig['provider']
2665
))->setHelp('This field can usually be left empty');
2666

    
2667
$section->addInput(new Form_Checkbox(
2668
	'pppoe_dialondemand',
2669
	'Dial on demand',
2670
	'Enable Dial-On-Demand mode ',
2671
	$pconfig['pppoe_dialondemand'],
2672
	'enable'
2673
));
2674

    
2675
$section->addInput(new Form_Input(
2676
	'pppoe_idletimeout',
2677
	'Idle timeout',
2678
	'number',
2679
	$pconfig['pppoe_idletimeout'],
2680
	[min => 0]
2681
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2682
			'An idle timeout of zero disables this feature.');
2683

    
2684
$section->addInput(new Form_Select(
2685
	'pppoe-reset-type',
2686
	'Periodic reset',
2687
	$pconfig['pppoe-reset-type'],
2688
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2689
))->setHelp('Select a reset timing type');
2690

    
2691
$group = new Form_Group('Custom reset');
2692
$group->addClass('pppoecustom');
2693

    
2694
$group->add(new Form_Input(
2695
	'pppoe_resethour',
2696
	null,
2697
	'number',
2698
	$pconfig['pppoe_resethour'],
2699
	[min => 0, max => 23]
2700
))->setHelp('Hour (0-23)');
2701

    
2702
$group->add(new Form_Input(
2703
	'pppoe_resetminute',
2704
	null,
2705
	'number',
2706
	$pconfig['pppoe_resetminute'],
2707
	[min => 0, max => 59]
2708
))->setHelp('Minutes (0-59)');
2709

    
2710
// ToDo: Need a date-picker here
2711
$group->add(new Form_Input(
2712
	'pppoe_resetdate',
2713
	null,
2714
	'text',
2715
	$pconfig['pppoe_resetdate']
2716
))->setHelp('Specific date (mm/dd/yyyy)');
2717

    
2718
$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');
2719

    
2720
$section->add($group);
2721

    
2722
$group = new Form_MultiCheckboxGroup('cron based reset');
2723
$group->addClass('pppoepreset');
2724

    
2725
$group->add(new Form_MultiCheckbox(
2726
	'pppoe_pr_preset_val',
2727
	null,
2728
	'Reset at each month ("0 0 1 * *")',
2729
	$pconfig['pppoe_monthly'],
2730
	'monthly'
2731
))->displayAsRadio();
2732

    
2733
$group->add(new Form_MultiCheckbox(
2734
	'pppoe_pr_preset_val',
2735
	null,
2736
	'Reset at each week ("0 0 * * 0")',
2737
	$pconfig['pppoe_weekly'],
2738
	'weekly'
2739
))->displayAsRadio();
2740

    
2741
$group->add(new Form_MultiCheckbox(
2742
	'pppoe_pr_preset_val',
2743
	null,
2744
	'Reset at each day ("0 0 * * *")',
2745
	$pconfig['pppoe_daily'],
2746
	'daily'
2747
))->displayAsRadio();
2748

    
2749
$group->add(new Form_MultiCheckbox(
2750
	'pppoe_pr_preset_val',
2751
	null,
2752
	'Reset at each hour ("0 * * * *")',
2753
	$pconfig['pppoe_hourly'],
2754
	'hourly'
2755
))->displayAsRadio();
2756

    
2757
$section->add($group);
2758

    
2759
if (isset($pconfig['pppid'])) {
2760
	$section->addInput(new Form_StaticText(
2761
		'Advanced and MLPPP',
2762
		'<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>'
2763
	));
2764
} else {
2765
	$section->addInput(new Form_StaticText(
2766
		'Advanced and MLPPP',
2767
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2768
	));
2769
}
2770

    
2771
$form->add($section);
2772

    
2773
// PPTP & L2TP Configuration section
2774
$section = new Form_Section('PPTP/L2TP Configuration');
2775
$section->addClass('pptp');
2776

    
2777
$section->addInput(new Form_Input(
2778
	'pptp_username',
2779
	'Username',
2780
	'text',
2781
	$pconfig['pptp_username']
2782
));
2783

    
2784
$section->addInput(new Form_Input(
2785
	'pptp_password',
2786
	'Password',
2787
	'password',
2788
	$pconfig['pptp_password']
2789
));
2790

    
2791
$section->addInput(new Form_IpAddress(
2792
	'pptp_local0',
2793
	'Local IP address',
2794
	$pconfig['pptp_localip'][0]
2795
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2796

    
2797
$section->addInput(new Form_IpAddress(
2798
	'pptp_remote0',
2799
	'Remote IP address',
2800
	$pconfig['pptp_remote'][0]
2801
));
2802

    
2803
$section->addInput(new Form_Checkbox(
2804
	'pptp_dialondemand',
2805
	'Dial on demand',
2806
	'Enable Dial-On-Demand mode ',
2807
	$pconfig['pptp_dialondemand'],
2808
	'enable'
2809
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2810
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2811

    
2812
$section->addInput(new Form_Input(
2813
	'pptp_idletimeout',
2814
	'Idle timeout (seconds)',
2815
	'number',
2816
	$pconfig['pptp_idletimeout'],
2817
	[min => 0]
2818
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2819
			'An idle timeout of zero disables this feature.');
2820

    
2821
if (isset($pconfig['pppid'])) {
2822
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2823
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2824
	} else {
2825
		$mlppp_text = "";
2826
	}
2827

    
2828
	$section->addInput(new Form_StaticText(
2829
		'Advanced and MLPPP',
2830
		$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>'
2831
	));
2832
} else {
2833
	$section->addInput(new Form_StaticText(
2834
		'Advanced and MLPPP',
2835
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2836
	));
2837
}
2838

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

    
2841
// Wireless interface
2842
if (isset($wancfg['wireless'])) {
2843

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

    
2846
	$section->addInput(new Form_Checkbox(
2847
		'persistcommonwireless',
2848
		'Persist common settings',
2849
		'Preserve common wireless configuration through interface deletions and reassignments.',
2850
		$pconfig['persistcommonwireless'],
2851
		'yes'
2852
	));
2853

    
2854
	$mode_list = ['auto' => 'Auto'];
2855

    
2856
	if (is_array($wl_modes)) {
2857
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2858
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2859
		}
2860
	}
2861

    
2862
	if (count($mode_list) == 1)
2863
		$mode_list[''] = '';
2864

    
2865
	$section->addInput(new Form_Select(
2866
		'standard',
2867
		'Standard',
2868
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2869
		$mode_list
2870
	));
2871

    
2872
	if (isset($wl_modes['11g'])) {
2873
		$section->addInput(new Form_Select(
2874
			'protmode',
2875
			'802.11g OFDM Protection Mode',
2876
			$pconfig['protmode'],
2877
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2878
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2879
	}
2880
	else
2881
	{
2882
		$section->addInput(new Form_Input(
2883
			'protmode',
2884
			null,
2885
			'hidden',
2886
			'off'
2887
		));
2888
	}
2889

    
2890
	$mode_list = ['0' => 'Auto'];
2891

    
2892
	if (is_array($wl_modes)) {
2893
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2894
			if ($wl_standard == "11g") {
2895
				$wl_standard = "11b/g";
2896
			} else if ($wl_standard == "11ng") {
2897
				$wl_standard = "11b/g/n";
2898
			} else if ($wl_standard == "11na") {
2899
				$wl_standard = "11a/n";
2900
			}
2901

    
2902
			foreach ($wl_channels as $wl_channel) {
2903
				if (isset($wl_chaninfo[$wl_channel])) {
2904
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2905
				} else {
2906
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2907
				}
2908
			}
2909
		}
2910
	}
2911

    
2912
	$section->addInput(new Form_Select(
2913
		'channel',
2914
		'Channel',
2915
		$pconfig['channel'],
2916
		$mode_list
2917
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2918
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2919

    
2920
	if (ANTENNAS) {
2921
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2922
			$group = new Form_Group('Antenna Settings');
2923

    
2924
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2925
				$group->add(new Form_Select(
2926
					'diversity',
2927
					null,
2928
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2929
					['' => 'Default', '0' => 'Off', '1' => 'On']
2930
				))->setHelp('Diversity');
2931
			}
2932

    
2933
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2934
				$group->add(new Form_Select(
2935
					'txantenna',
2936
					null,
2937
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2938
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2939
				))->setHelp('Transmit antenna');
2940
			}
2941

    
2942
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2943
				$group->add(new Form_Select(
2944
					'rxantenna',
2945
					null,
2946
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2947
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2948
				))->setHelp('Receive antenna');
2949
			}
2950

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

    
2953
			$section->add($group);
2954
		}
2955
	}
2956

    
2957
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2958
			$section->addInput(new Form_Input(
2959
				'distance',
2960
				'Distance setting (meters)',
2961
				'test',
2962
				$pconfig['distance']
2963
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2964
	}
2965

    
2966
	$form->add($section);
2967

    
2968
	// Regulatory settings
2969
	$section = new Form_Section('Regulatory settings');
2970

    
2971
	$domain_list = array("" => 'Default');
2972

    
2973
	if (is_array($wl_regdomains)) {
2974
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2975
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2976
		}
2977
	}
2978

    
2979
	$section->addInput(new Form_Select(
2980
		'regdomain',
2981
		'Regulatory domain',
2982
		$pconfig['regdomain'],
2983
		$domain_list
2984
	))->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');
2985

    
2986
	$country_list = array('' => 'Default');
2987

    
2988
	if (is_array($wl_countries)) {
2989
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2990
			$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']);
2991
		}
2992
	}
2993

    
2994
	$section->addInput(new Form_Select(
2995
		'regcountry',
2996
		'Country',
2997
		$pconfig['regcountry'],
2998
		$country_list
2999
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3000

    
3001
	$section->addInput(new Form_Select(
3002
		'reglocation',
3003
		'Location',
3004
		$pconfig['reglocation'],
3005
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
3006
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3007
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
3008
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3009
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3010
				'These settings may not be able to add additional channels that are not already supported.');
3011

    
3012
	$form->add($section);
3013

    
3014
	$section = new Form_Section('Network-specific wireless configuration');
3015

    
3016
	$section->addInput(new Form_Select(
3017
		'mode',
3018
		'Mode',
3019
		$pconfig['mode'],
3020
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
3021
	));
3022

    
3023
	$section->addInput(new Form_Input(
3024
		'ssid',
3025
		'SSID',
3026
		'text',
3027
		$pconfig['ssid']
3028
	));
3029

    
3030
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3031
		$section->addInput(new Form_Select(
3032
			'puremode',
3033
			'Minimum wireless standard',
3034
			$pconfig['puremode'],
3035
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
3036
		))->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)');
3037
	} elseif (isset($wl_modes['11g'])) {
3038
		$section->addInput(new Form_Checkbox(
3039
			'puremode',
3040
			'802.11g only',
3041
			null,
3042
			$pconfig['puremode'],
3043
			'11g'
3044
		))->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)');
3045
	}
3046

    
3047
	$section->addInput(new Form_Checkbox(
3048
		'apbridge_enable',
3049
		'Allow intra-BSS communication',
3050
		'Allow packets to pass between wireless clients directly when operating as an access point',
3051
		$pconfig['apbridge_enable'],
3052
		'yes'
3053
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
3054

    
3055
	$section->addInput(new Form_Checkbox(
3056
		'wme_enable',
3057
		'Enable WME',
3058
		'Force the card to use WME (wireless QoS)',
3059
		$pconfig['wme_enable'],
3060
		'yes'
3061
	));
3062

    
3063
	$section->addInput(new Form_Checkbox(
3064
		'hidessid_enable',
3065
		'Hide SSID',
3066
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
3067
		$pconfig['hidessid_enable'],
3068
		'yes'
3069
	));
3070

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

    
3073
	if(ALLOWWEP) {
3074
		// WEP Section
3075
		$section = new Form_Section('WEP');
3076

    
3077
		$section->addInput(new Form_Checkbox(
3078
			'wep_enable',
3079
			'Enable',
3080
			'Enable WEP',
3081
			$pconfig['wep_enable'],
3082
			'yes'
3083
		));
3084

    
3085
		for($idx=1; $idx <= 4; $idx++) {
3086
			$group = new Form_Group('Key' . $idx);
3087

    
3088
			$group->add(new Form_Input(
3089
				'key' . $idx,
3090
				null,
3091
				'text',
3092
				$pconfig['key' . $idx]
3093
			));
3094

    
3095
			$group->add(new Form_Checkbox(
3096
				'txkey',
3097
				null,
3098
				null,
3099
				$pconfig['txkey'],
3100
				$idx
3101
			))->displayAsRadio()->setHelp($idx == 4 ? 'Tx key':'');
3102

    
3103
			$section->add($group);
3104
		}
3105

    
3106
		$section->addInput(new Form_StaticText(
3107
			null,
3108
			'<span class="help-block">' .
3109
			gettext('40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by "0x"') . '<br />' .
3110
			gettext('104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by "0x"') .
3111
			'</span>'
3112
		));
3113

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

    
3117
	// WPA Section
3118
	$section = new Form_Section('WPA');
3119

    
3120
	$section->addInput(new Form_Checkbox(
3121
		'wpa_enable',
3122
		'Enable',
3123
		'Enable WPA',
3124
		$pconfig['wpa_enable'],
3125
		'yes'
3126
	));
3127

    
3128
	$section->addInput(new Form_Input(
3129
		'passphrase',
3130
		'WPA Pre-Shared Key',
3131
		'text',
3132
		$pconfig['passphrase']
3133
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3134

    
3135
	$section->addInput(new Form_Select(
3136
		'wpa_mode',
3137
		'WPA mode',
3138
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3139
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
3140
	));
3141

    
3142
	$section->addInput(new Form_Select(
3143
		'wpa_key_mgmt',
3144
		'WPA Key Management Mode',
3145
		$pconfig['wpa_key_mgmt'],
3146
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
3147
	));
3148

    
3149
	if(ALLOWWEP) {
3150
		$section->addInput(new Form_Select(
3151
			'auth_algs',
3152
			'Authentication',
3153
			$pconfig['auth_algs'],
3154
			['1' => 'Open System Authentication', '2' => 'Shared Key Authentication', '3' => 'Both']
3155
		))->setHelp('Shared Key Authentication requires WEP');
3156
	} else {
3157
		$section->addInput(new Form_Input(
3158
			'auth_algs',
3159
			null,
3160
			'hidden',
3161
			'1'
3162
		));;
3163
	}
3164

    
3165
	$section->addInput(new Form_Select(
3166
		'wpa_pairwise',
3167
		'WPA Pairwise',
3168
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3169
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3170
	));
3171

    
3172
	$section->addInput(new Form_Input(
3173
		'wpa_group_rekey',
3174
		'WPA Pre-Shared Key',
3175
		'number',
3176
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3177
		['min' => '1', 'max' => 9999]
3178
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3179

    
3180
	$section->addInput(new Form_Input(
3181
		'wpa_gmk_rekey',
3182
		'Master Key Regeneration',
3183
		'number',
3184
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3185
		['min' => '1', 'max' => 9999]
3186
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3187

    
3188
	$section->addInput(new Form_Checkbox(
3189
		'wpa_strict_rekey',
3190
		'Strict Key Regeneration',
3191
		'Force the AP to rekey whenever a client disassociates',
3192
		$pconfig['wpa_strict_rekey'],
3193
		'yes'
3194
	));
3195

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

    
3198
	$section = new Form_Section('802.1x RADIUS options');
3199

    
3200
	$section->addInput(new Form_Checkbox(
3201
		'ieee8021x',
3202
		'IEEE802.1X',
3203
		'Enable 802.1X authentication',
3204
		$pconfig['ieee8021x'],
3205
		'yes'
3206
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3207

    
3208
	$group = new Form_Group('Primary 802.1X server');
3209

    
3210
	$group->add(new Form_IpAddress(
3211
		'auth_server_addr',
3212
		'IP Address',
3213
		$pconfig['auth_server_addr']
3214
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3215

    
3216
	$group->add(new Form_Input(
3217
		'auth_server_port',
3218
		'Port',
3219
		'number',
3220
		$pconfig['auth_server_port']
3221
	))->setHelp('Server port. Leave blank for the default port 1812');
3222

    
3223
	$group->add(new Form_Input(
3224
		'auth_server_shared_secret',
3225
		'Shared secret',
3226
		'number',
3227
		$pconfig['auth_server_shared_secret']
3228
	))->setHelp('Shared secret');
3229

    
3230
	$section->add($group);
3231

    
3232
	$group = new Form_Group('Secondary 802.1X server');
3233

    
3234
	$group->add(new Form_IpAddress(
3235
		'auth_server_addr2',
3236
		'IP Address',
3237
		$pconfig['auth_server_addr2']
3238
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3239

    
3240
	$group->add(new Form_Input(
3241
		'auth_server_port2',
3242
		'Port',
3243
		'number',
3244
		$pconfig['auth_server_port2']
3245
	))->setHelp('Server port. Leave blank for the default port 1812');
3246

    
3247
	$group->add(new Form_Input(
3248
		'auth_server_shared_secret2',
3249
		'Shared secret',
3250
		'number',
3251
		$pconfig['auth_server_shared_secret2']
3252
	))->setHelp('Shared secret');
3253

    
3254
	$section->add($group);
3255

    
3256
	$section->addInput(new Form_Checkbox(
3257
		'rsn_preauth',
3258
		'Authentication Roaming Preauth',
3259
		null,
3260
		$pconfig['rsn_preauth'],
3261
		'yes'
3262
	));
3263

    
3264
	$form->add($section);
3265
}
3266

    
3267
$section = new Form_Section('Private networks');
3268

    
3269
$section->addInput(new Form_Checkbox(
3270
	'blockpriv',
3271
	'Block private networks',
3272
	'',
3273
	$pconfig['blockpriv'],
3274
	'yes'
3275
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3276
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3277
			'lies in such a private address space, too.');
3278

    
3279
	$section->addInput(new Form_Checkbox(
3280
	'blockbogons',
3281
	'Block bogon networks',
3282
	'',
3283
	$pconfig['blockbogons'],
3284
	'yes'
3285
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3286
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3287
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3288

    
3289
$form->add($section);
3290

    
3291
$form->addGlobal(new Form_Input(
3292
	'if',
3293
	null,
3294
	'hidden',
3295
	$if
3296
));
3297

    
3298
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3299
	$form->addGlobal(new Form_Input(
3300
		'ppp_port',
3301
		null,
3302
		'hidden',
3303
		$pconfig['port']
3304
	));
3305
}
3306

    
3307
$form->addGlobal(new Form_Input(
3308
	'ptpid',
3309
	null,
3310
	'hidden',
3311
	$pconfig['ptpid']
3312
));
3313

    
3314
print($form);
3315
?>
3316

    
3317
<script type="text/javascript">
3318
//<![CDATA[
3319
events.push(function(){
3320

    
3321
	function updateType(t) {
3322
		switch (t) {
3323
			case "none": {
3324
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3325
				break;
3326
			}
3327
			case "staticv4": {
3328
				$('.dhcpadvanced, .none, .dhcp, .pppoe, .pptp, .ppp').hide();
3329
				break;
3330
			}
3331
			case "dhcp": {
3332
				$('.dhcpadvanced, .none, .staticv4, .pppoe, .pptp, .ppp').hide();
3333
				break;
3334
			}
3335
			case "ppp": {
3336
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3337
				country_list();
3338
				break;
3339
			}
3340
			case "pppoe": {
3341
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3342
				break;
3343
			}
3344
			case "l2tp":
3345
			case "pptp": {
3346
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3347
				$('.pptp').show();
3348
				break;
3349
			}
3350
		}
3351

    
3352
		if (t != "l2tp" && t != "pptp") {
3353
			$('.'+t).show();
3354
		}
3355
	}
3356

    
3357
	function updateTypeSix(t) {
3358
		if (!isNaN(t[0]))
3359
			t = '_' + t;
3360

    
3361
		switch (t) {
3362
			case "none": {
3363
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3364
				break;
3365
			}
3366
			case "staticv6": {
3367
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3368
				break;
3369
			}
3370
			case "slaac": {
3371
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3372
				break;
3373
			}
3374
			case "dhcp6": {
3375
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3376
				break;
3377
			}
3378
			case "6rd_": {
3379
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3380
				break;
3381
			}
3382
			case "_6to4": {
3383
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3384
				break;
3385
			}
3386
			case "track6": {
3387
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3388
				update_track6_prefix();
3389
				break;
3390
			}
3391
		}
3392

    
3393
		if (t != "l2tp" && t != "pptp") {
3394
			$('.'+t).show();
3395
		}
3396
	}
3397

    
3398
	function show_reset_settings(reset_type) {
3399
		if (reset_type == 'preset') {
3400
			$('.pppoepreset').show();
3401
			$('.pppoecustom').hide();
3402
		} else if (reset_type == 'custom') {
3403
			$('.pppoecustom').show();
3404
			$('.pppoepreset').hide();
3405
		} else {
3406
			$('.pppoecustom').hide();
3407
			$('.pppoepreset').hide();
3408
		}
3409
	}
3410

    
3411
	function update_track6_prefix() {
3412
		var iface = $("#track6-interface").val();
3413
		if (iface == null) {
3414
			return;
3415
		}
3416

    
3417
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3418
		if (track6_prefix_ids == null) {
3419
			return;
3420
		}
3421

    
3422
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3423
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3424
	}
3425

    
3426
	// Create the new gateway from the data entered in the modal pop-up
3427
	function hide_add_gatewaysave() {
3428
		var iface = $('#if').val();
3429
		name = $('#name').val();
3430
		var descr = $('#gatewaydescr').val();
3431
		gatewayip = $('#gatewayip').val();
3432

    
3433
		var defaultgw = '';
3434
		if ($('#defaultgw').is(':checked')) {
3435
			defaultgw = '&defaultgw=on';
3436
		}
3437

    
3438
		var url = "system_gateways_edit.php";
3439
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3440
		$.ajax(
3441
			url,
3442
			{
3443
				type: 'post',
3444
				data: pars,
3445
				error: report_failure,
3446
				complete: save_callback
3447
			});
3448
		}
3449

    
3450
	function save_callback(response) {
3451
		if (response) {
3452
			var gwtext = escape(name) + " - " + gatewayip;
3453
			addOption($('#gateway'), gwtext, name);
3454
		} else {
3455
			report_failure();
3456
		}
3457

    
3458
		$("#newgateway").modal('hide');
3459
	}
3460

    
3461
	function report_failure(request, textStatus, errorThrown) {
3462
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3463
			alert(request.responseText);
3464
		} else {
3465
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3466
		}
3467

    
3468
		$("#newgateway").modal('hide');
3469
	}
3470

    
3471
	function addOption(selectbox, text, value)
3472
	{
3473
		var optn = document.createElement("OPTION");
3474
		optn.text = text;
3475
		optn.value = value;
3476
		selectbox.append(optn);
3477
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3478
	}
3479

    
3480
	function hide_add_gatewaysave_v6() {
3481

    
3482
		var iface = $('#if').val();
3483
		name = $('#namev6').val();
3484
		var descr = $('#gatewaydescrv6').val();
3485
		gatewayip = $('#gatewayipv6').val();
3486
		var defaultgw = '';
3487
		if ($('#defaultgwv6').is(':checked')) {
3488
			defaultgw = '&defaultgw=on';
3489
		}
3490
		var url_v6 = "system_gateways_edit.php";
3491
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3492
		$.ajax(
3493
			url_v6,
3494
			{
3495
				type: 'post',
3496
				data: pars_v6,
3497
				error: report_failure_v6,
3498
				success: save_callback_v6
3499
			});
3500
	}
3501

    
3502

    
3503
	function addOption_v6(selectbox, text, value)
3504
	{
3505
		var optn = document.createElement("OPTION");
3506
		optn.text = text;
3507
		optn.value = value;
3508
		selectbox.append(optn);
3509
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3510
	}
3511

    
3512
	function report_failure_v6(request, textStatus, errorThrown) {
3513
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3514
			alert(request.responseText);
3515
		} else {
3516
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3517
		}
3518

    
3519
		$("#newgateway6").modal('hide');
3520
	}
3521

    
3522
	function save_callback_v6(response_v6) {
3523
		if (response_v6) {
3524

    
3525
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3526
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3527
		} else {
3528
			report_failure_v6();
3529
		}
3530

    
3531
		$("#newgateway6").modal('hide');
3532
	}
3533

    
3534
	function country_list() {
3535

    
3536
		$('#country').children().remove();
3537
		$('#provider_list').children().remove();
3538
		$('#providerplan').children().remove();
3539
		$.ajax("getserviceproviders.php",{
3540
			success: function(response) {
3541

    
3542
				var responseTextArr = response.split("\n");
3543
				responseTextArr.sort();
3544

    
3545
				responseTextArr.forEach( function(value) {
3546
					country = value.split(":");
3547
					$('#country').append($('<option>', {
3548
						value: country[1],
3549
						text : country[0]
3550
					}));
3551
				});
3552
			}
3553
		});
3554
	}
3555

    
3556
	function providers_list() {
3557
		$('#provider_list').children().remove();
3558
		$('#providerplan').children().remove();
3559
		$.ajax("getserviceproviders.php",{
3560
			type: 'post',
3561
			data: {country : $('#country').val()},
3562
			success: function(response) {
3563
				var responseTextArr = response.split("\n");
3564
				responseTextArr.sort();
3565
				responseTextArr.forEach( function(value) {
3566
					$('#provider_list').append($('<option>', {
3567
							value: value,
3568
							text : value
3569
					}));
3570
				});
3571
			}
3572
		});
3573
	}
3574

    
3575
	function providerplan_list() {
3576
		$('#providerplan').children().remove();
3577
		$.ajax("getserviceproviders.php",{
3578
			type: 'post',
3579
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3580
			success: function(response) {
3581
				var responseTextArr = response.split("\n");
3582
				responseTextArr.sort();
3583

    
3584
				$('#providerplan').append($('<option>', {
3585
					value: '',
3586
					text : ''
3587
				}));
3588

    
3589
				responseTextArr.forEach( function(value) {
3590
					if (value != "") {
3591
						providerplan = value.split(":");
3592

    
3593
						$('#providerplan').append($('<option>', {
3594
							value: providerplan[1],
3595
							text : providerplan[0] + " - " + providerplan[1]
3596
						}));
3597
					}
3598
				});
3599
			}
3600
		});
3601
	}
3602

    
3603
	function prefill_provider() {
3604
		$.ajax("getserviceproviders.php",{
3605
			type: 'post',
3606
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3607
			success: function(data, textStatus, response) {
3608
				var xmldoc = response.responseXML;
3609
				var provider = xmldoc.getElementsByTagName('connection')[0];
3610
				$('#ppp_username').val('');
3611
				$('#ppp_password').val('');
3612
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3613
					$('#phone').val('#777');
3614
					$('#apn').val('');
3615
				} else {
3616
					$('#phone').val('*99#');
3617
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3618
				}
3619
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3620
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3621
				$('#ppp_username').val(ppp_username);
3622
				$('#ppp_password').val(ppp_password);
3623
			}
3624
		});
3625
	}
3626

    
3627
	// Hides all elements of the specified class. This will usually be a section
3628
	function hideClass(s_class, hide) {
3629
		if(hide)
3630
			$('.' + s_class).hide();
3631
		else
3632
			$('.' + s_class).show();
3633
	}
3634

    
3635
	// Hides the <div> in which the specified input element lives so that the input, its label and help text are hidden
3636
	function hideInput(id, hide) {
3637
		if(hide)
3638
			$('#' + id).parent().parent('div').addClass('hidden');
3639
		else
3640
			$('#' + id).parent().parent('div').removeClass('hidden');
3641
	}
3642

    
3643
	// Hides the <div> in which the specified IP address element lives so that the input, its label and help text are hidden
3644
	function hideIpAddress(id, hide) {
3645
		if(hide)
3646
			$('#' + id).parent().parent().parent('div').addClass('hidden');
3647
		else
3648
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
3649
	}
3650

    
3651
	// Hides the <div> in which the specified checkbox lives so that the checkbox, its label and help text are hidden
3652
	function hideCheckbox(id, hide) {
3653
		if(hide)
3654
			$('#' + id).parent().parent().parent('div').addClass('hidden');
3655
		else
3656
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
3657
	}
3658

    
3659
	function show_dhcp6adv() {
3660
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3661
		var adv = $('#dhcp6adv').prop('checked');
3662

    
3663
		hideCheckbox('dhcp6usev4iface', ovr);
3664
		hideCheckbox('dhcp6prefixonly', ovr);
3665
		hideInput('dhcp6-ia-pd-len', ovr);
3666
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3667
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3668

    
3669
		hideClass('dhcp6advanced', !adv || ovr);
3670
	}
3671

    
3672
	function setDHCPoptions() {
3673
		var adv = $('#dhcpadv').prop('checked');
3674
		var ovr = $('#dhcpovr').prop('checked');
3675

    
3676
		if(ovr) {
3677
			hideInput('dhcphostname', true);
3678
			hideIpAddress('alias-address', true);
3679
			hideInput('dhcprejectfrom', true);
3680
			hideInput('adv_dhcp_config_file_override_path', false);
3681
			hideClass('dhcpadvanced', true);
3682
		} else {
3683
			hideInput('dhcphostname', false);
3684
			hideIpAddress('alias-address', false);
3685
			hideInput('dhcprejectfrom', false);
3686
			hideInput('adv_dhcp_config_file_override_path', true);
3687
			hideClass('dhcpadvanced', !adv);
3688
		}
3689
	}
3690

    
3691
	// ---------- On initial page load ------------------------------------------------------------
3692

    
3693
	updateType($('#type').val());
3694
	updateTypeSix($('#type6').val());
3695
	show_reset_settings($('#pppoe-reset-type').val());
3696
	$("#add").prop('type' ,'button');
3697
	$("#cnx").prop('type' ,'button');
3698
	$("#addgw").prop('type' ,'button');
3699
	$("#add6").prop('type' ,'button');
3700
	$("#cnx6").prop('type' ,'button');
3701
	$("#addgw6").prop('type' ,'button');
3702
	hideClass('dhcp6advanced', true);
3703
	hideClass('dhcpadvanced', true);
3704
	show_dhcp6adv();
3705
	setDHCPoptions()
3706

    
3707
	// ---------- Click checkbox handlers ---------------------------------------------------------
3708
	
3709
   $('#type').on('change', function() {
3710
		updateType( this.value );
3711
	});
3712

    
3713
	$('#type6').on('change', function() {
3714
		updateTypeSix( this.value );
3715
	});
3716

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

    
3721
	$("#add").click(function() {
3722
		hide_add_gatewaysave();
3723
	});
3724

    
3725
	$("#cnx").click(function() {
3726
		$("#newgateway").modal('hide');
3727
	});
3728

    
3729
	$("#add6").click(function() {
3730
		hide_add_gatewaysave_v6();
3731
	});
3732

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

    
3737
	$('#country').on('change', function() {
3738
		providers_list();
3739
	});
3740

    
3741
	$('#provider_list').on('change', function() {
3742
		providerplan_list();
3743
	});
3744

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

    
3749
	$('#dhcpadv, #dhcpovr').click(function () {
3750
		setDHCPoptions();
3751
	});
3752

    
3753
	$('#dhcp6adv').click(function () {
3754
		show_dhcp6adv();
3755
	});
3756

    
3757
	$('#adv_dhcp6_config_file_override').click(function () {
3758
		show_dhcp6adv();
3759
	});
3760

    
3761
	// DHCP preset actions
3762
	// Set presets from value of radio buttons
3763
	function setPresets(val) {
3764
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3765
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3766
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3767
		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']);?>");
3768
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3769
	}
3770

    
3771
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3772
		$('#adv_dhcp_pt_timeout').val(timeout);
3773
		$('#adv_dhcp_pt_retry').val(retry);
3774
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3775
		$('#adv_dhcp_pt_reboot').val(reboot);
3776
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3777
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3778
	}
3779

    
3780
	// Set preset buttons on page load
3781
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3782
	if(sv == "")
3783
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3784

    
3785
	// Set preset from value
3786
	setPresets(sv);
3787

    
3788
	// On click . .
3789
	$('[id=adv_dhcp_pt_values]').click(function () {
3790
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3791
	});
3792
});
3793
//]]>
3794
</script>
3795

    
3796
<?php include("foot.inc");
(83-83/235)