Project

General

Profile

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

    
128
$a_gateways = &$config['gateways']['gateway_item'];
129

    
130
$wancfg = &$config['interfaces'][$if];
131
$old_wancfg = $wancfg;
132
$old_wancfg['realif'] = get_real_interface($if);
133
$old_ppps = $a_ppps;
134

    
135
// Populate page descr if it does not exist.
136
if ($if == "wan" && !$wancfg['descr']) {
137
	$wancfg['descr'] = "WAN";
138
} else if ($if == "lan" && !$wancfg['descr']) {
139
	$wancfg['descr'] = "LAN";
140
}
141

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

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

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

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

    
168
		/* ================================================ */
169
		/* = force a connection reset at a specific time? = */
170
		/* ================================================ */
171

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

    
226
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
227
$pconfig['alias-address'] = $wancfg['alias-address'];
228
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
229
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
230

    
231
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
232
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
233
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
234
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
235
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
236
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
237

    
238
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
239

    
240
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
241
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
242
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
243
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
244

    
245
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
246
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
247
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
248

    
249
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
250
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
251
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
252
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
253

    
254
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
255
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
256
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
257
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
258
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
259

    
260
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
261
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
262
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
263
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
264
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
265

    
266
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
267
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
268

    
269
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
270
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
271
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
272
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
273

    
274
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
275
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
276
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
277
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
278
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
279

    
280
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
281
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
282
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
283

    
284
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
285
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
286
$pconfig['enable'] = isset($wancfg['enable']);
287

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

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

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

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

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

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

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

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

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

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

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

    
500
		clear_subsystem_dirty('interfaces');
501

    
502
		filter_configure();
503

    
504
		enable_rrd_graphing();
505

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

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

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

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

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

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

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

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

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

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

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

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

    
847
		unset($min_mtu, $max_mtu);
848

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1462
		conf_mount_ro();
1463
		write_config();
1464

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

    
1474
		mark_subsystem_dirty('interfaces');
1475

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

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

    
1483
} // end if ($_POST)
1484

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1717
$closehead = false;
1718

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

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

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

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

    
1735
	return($list);
1736
}
1737

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

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

    
1748
	return($list);
1749
}
1750

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

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

    
1761
	return($list);
1762
}
1763

    
1764
include("head.inc");
1765

    
1766
if ($input_errors)
1767
	print_input_errors($input_errors);
1768

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

    
1773
if ($savemsg)
1774
	print_info_box($savemsg, 'success');
1775

    
1776

    
1777
require_once('classes/Form.class.php');
1778
require_once('classes/Modal.class.php');
1779

    
1780
$form = new Form(new Form_Button(
1781
	'Submit',
1782
	gettext("Save")
1783
));
1784

    
1785
$section = new Form_Section('General configuration');
1786

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

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

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

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

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

    
1824
$btnmymac = new Form_Button(
1825
	'btnmymac',
1826
	'Copy My MAC'
1827
	);
1828

    
1829
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1830

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

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

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

    
1854
if (count($mediaopts_list) > 0) {
1855
	$section->addInput(new Form_Select(
1856
		'mediaopt',
1857
		'Speed and Duplex',
1858
		rtrim($mediaopt_from_config),
1859
		build_mediaopts_list()
1860
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1861
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1862
}
1863

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

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

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

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

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

    
1884
$group->add(new Form_Button(
1885
	'addgw',
1886
	'Add a new gateway'
1887
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1888

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

    
1893
$section->add($group);
1894

    
1895
$form->add($section);
1896

    
1897
$section = new Form_Section('Static IPv6 configuration');
1898
$section->addClass('staticv6');
1899

    
1900
$section->addInput(new Form_IpAddress(
1901
	'ipaddrv6',
1902
	'IPv6 address',
1903
	$pconfig['ipaddrv6']
1904
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1905

    
1906
$group = new Form_Group('IPv6 Upstream gateway');
1907

    
1908
$group->add(new Form_Select(
1909
	'gatewayv6',
1910
	'IPv6 Upstream Gateway',
1911
	$pconfig['gatewayv6'],
1912
	build_gatewayv6_list()
1913
));
1914

    
1915
$group->add(new Form_Button(
1916
	'addgw6',
1917
	'Add a new gateway'
1918
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1919

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

    
1923
$section->add($group);
1924
$form->add($section);
1925

    
1926
// Add new gateway modal pop-up for IPv6
1927
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1928

    
1929
$modal->addInput(new Form_Checkbox(
1930
	'defaultgw6',
1931
	'Default',
1932
	'Default gateway',
1933
	($if == "wan" || $if == "WAN")
1934
));
1935

    
1936
$modal->addInput(new Form_Input(
1937
	'name6',
1938
	'Gateway name',
1939
	'text',
1940
	$wancfg['descr'] . "GWv6"
1941
));
1942

    
1943
$modal->addInput(new Form_IpAddress(
1944
	'gatewayip6',
1945
	'Gateway IPv6',
1946
	null
1947
));
1948

    
1949
$modal->addInput(new Form_Input(
1950
	'gatewaydescr6',
1951
	'Description',
1952
	'text'
1953
));
1954

    
1955
$btnaddgw6 = new Form_Button(
1956
	'add6',
1957
	'Add'
1958
);
1959

    
1960
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1961

    
1962
$btncnxgw6 = new Form_Button(
1963
	'cnx6',
1964
	'Cancel'
1965
);
1966

    
1967
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1968

    
1969
$modal->addInput(new Form_StaticText(
1970
	null,
1971
	$btnaddgw6 . $btncnxgw6
1972
));
1973

    
1974
$form->add($modal);
1975

    
1976
// ==== DHCP client configuration =============================
1977

    
1978
$section = new Form_Section('DHCP client configuration');
1979
$section->addClass('dhcp');
1980

    
1981
$group = new Form_Group('Options');
1982

    
1983
$group->add(new Form_Checkbox(
1984
	'dhcpadv',
1985
	null,
1986
	'Show DHCP advanced options',
1987
	false
1988
));
1989

    
1990
$group->add(new Form_Checkbox(
1991
	'dhcpovr',
1992
	null,
1993
	'Config file override',
1994
	false
1995
));
1996

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

    
1999
$section->addInput(new Form_Input(
2000
	'dhcphostname',
2001
	'Hostname',
2002
	'text',
2003
	$pconfig['dhcphostname']
2004
))->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).');
2005

    
2006
$section->addInput(new Form_IpAddress(
2007
	'alias-address',
2008
	'Alias IPv4 address',
2009
	$pconfig['alias-address']
2010
))->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.');
2011

    
2012
$section->addInput(new Form_Input(
2013
	'dhcprejectfrom',
2014
	'Reject leases from',
2015
	'text',
2016
	$pconfig['dhcprejectfrom']
2017
))->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. ' .
2018
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
2019

    
2020
$group = new Form_Group('Protocol timing');
2021
$group->addClass('dhcpadvanced');
2022

    
2023
$group->add(new Form_Input(
2024
	'adv_dhcp_pt_timeout',
2025
	null,
2026
	'number',
2027
	$pconfig['adv_dhcp_pt_timeout']
2028
))->setHelp('Timeout');
2029

    
2030
$group->add(new Form_Input(
2031
	'adv_dhcp_pt_retry',
2032
	null,
2033
	'number',
2034
	$pconfig['adv_dhcp_pt_retry']
2035
))->setHelp('Retry');
2036

    
2037
$group->add(new Form_Input(
2038
	'adv_dhcp_pt_select_timeout',
2039
	null,
2040
	'number',
2041
	$pconfig['adv_dhcp_pt_select_timeout']
2042
))->setHelp('Select timeout');
2043

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

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

    
2058
$group->add(new Form_Input(
2059
	'adv_dhcp_pt_initial_interval',
2060
	null,
2061
	'number',
2062
	$pconfig['adv_dhcp_pt_initial_interval']
2063
))->setHelp('Initial interval');
2064

    
2065
$section->add($group);
2066

    
2067
$group = new Form_Group('Presets');
2068
$group->addClass('dhcpadvanced');
2069

    
2070
$group->add(new Form_Checkbox(
2071
	'adv_dhcp_pt_values',
2072
	null,
2073
	'FreeBSD default',
2074
	null,
2075
	'DHCP'
2076
))->displayAsRadio();
2077

    
2078
$group->add(new Form_Checkbox(
2079
	'adv_dhcp_pt_values',
2080
	null,
2081
	'Clear',
2082
	null,
2083
	'Clear'
2084
))->displayAsRadio();
2085

    
2086
$group->add(new Form_Checkbox(
2087
	'adv_dhcp_pt_values',
2088
	null,
2089
	'pfSense Default',
2090
	null,
2091
	'pfSense'
2092
))->displayAsRadio();
2093

    
2094
$group->add(new Form_Checkbox(
2095
	'adv_dhcp_pt_values',
2096
	null,
2097
	'Saved Cfg',
2098
	null,
2099
	'SavedCfg'
2100
))->displayAsRadio();
2101

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

    
2105
$section->add($group);
2106

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

    
2117
$form->add($section);
2118

    
2119
$section = new Form_Section('Lease Requirements and Requests');
2120
$section->addClass('dhcpadvanced');
2121

    
2122
$section->addInput(new Form_Input(
2123
	'adv_dhcp_send_options',
2124
	'Send options',
2125
	'text',
2126
	$pconfig['adv_dhcp_send_options']
2127
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2128
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2129
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2130
			'Some ISPs may require certain options be or not be sent.');
2131

    
2132
$section->addInput(new Form_Input(
2133
	'adv_dhcp_request_options',
2134
	'Request options',
2135
	'text',
2136
	$pconfig['adv_dhcp_request_options']
2137
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2138
			'Some ISPs may require certain options be or not be requested.');
2139

    
2140
$section->addInput(new Form_Input(
2141
	'adv_dhcp_require_options',
2142
	'Request options',
2143
	'text',
2144
	$pconfig['adv_dhcp_require_options']
2145
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2146

    
2147
$section->addInput(new Form_Input(
2148
	'adv_dhcp_option_modifiers',
2149
	'Option modifiers',
2150
	'text',
2151
	$pconfig['adv_dhcp_option_modifiers']
2152
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2153
			'modifiers: (default, supersede, prepend, append)');
2154

    
2155
$form->add($section);
2156

    
2157
// DHCP6 client config
2158

    
2159
$section = new Form_Section('DHCP6 client configuration');
2160
$section->addClass('dhcp6');
2161

    
2162
$section->addInput(new Form_Checkbox(
2163
	'dhcp6adv',
2164
	'Advanced',
2165
	'Show DHCPv6 advanced options',
2166
	$pconfig['adv_dhcp6_config_advanced']
2167
));
2168

    
2169
$section->addInput(new Form_Checkbox(
2170
	'adv_dhcp6_config_file_override',
2171
	'Config file override',
2172
	'Override the configuration from this file',
2173
	$pconfig['adv_dhcp6_config_file_override']
2174
));
2175

    
2176
$section->addInput(new Form_Checkbox(
2177
	'dhcp6usev4iface',
2178
	'Use IPv4 connectivity as parent interface',
2179
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2180
	$pconfig['dhcp6usev4iface']
2181
));
2182

    
2183
$section->addInput(new Form_Checkbox(
2184
	'dhcp6prefixonly',
2185
	'Request only an IPv6 prefix',
2186
	'Only request an IPv6 prefix, do not request an IPv6 address',
2187
	$pconfig['dhcp6prefixonly']
2188
));
2189

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

    
2197
$section->addInput(new Form_Checkbox(
2198
	'dhcp6-ia-pd-send-hint',
2199
	'Send IPv6 prefix hint',
2200
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2201
	$pconfig['dhcp6-ia-pd-send-hint']
2202
));
2203

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

    
2214
$form->add($section);
2215

    
2216
// DHCP6 client config - Advanced
2217

    
2218
$section = new Form_Section('Advanced DHCP6 client configuration');
2219
$section->addClass('dhcp6advanced');
2220

    
2221
$section->addInput(new Form_Checkbox(
2222
	'adv_dhcp6_interface_statement_information_only_enable',
2223
	'Information only',
2224
	null,
2225
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2226
));
2227

    
2228
$section->addInput(new Form_Input(
2229
	'adv_dhcp6_interface_statement_send_options',
2230
	'Send options',
2231
	'text',
2232
	$pconfig['adv_dhcp6_interface_statement_send_options']
2233
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2234
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2235
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2236
			'Some DHCP services may require certain options be or not be sent.');
2237

    
2238
$section->addInput(new Form_Input(
2239
	'adv_dhcp6_interface_statement_request_options',
2240
	'Request Options',
2241
	'text',
2242
	$pconfig['adv_dhcp6_interface_statement_request_options']
2243
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2244
			'Some DHCP services may require certain options be or not be requested.');
2245

    
2246
$section->addInput(new Form_Input(
2247
	'adv_dhcp6_interface_statement_script',
2248
	'Scripts',
2249
	'text',
2250
	$pconfig['adv_dhcp6_interface_statement_script']
2251
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2252
			'[/[dirname/[.../]]filename[.ext]].');
2253

    
2254
$group = new Form_Group('Identity Association Statement');
2255

    
2256
$group->add(new Form_Checkbox(
2257
	'adv_dhcp6_id_assoc_statement_address_enable',
2258
	null,
2259
	'Non-Temporary Address Allocation',
2260
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2261
));
2262

    
2263
$group->add(new Form_Input(
2264
	'adv_dhcp6_id_assoc_statement_address_id',
2265
	null,
2266
	'text',
2267
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2268
))->sethelp('id-assoc na ID');
2269

    
2270
$group->add(new Form_IpAddress(
2271
	'adv_dhcp6_id_assoc_statement_address',
2272
	null,
2273
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2274
))->sethelp('IPv6 address');
2275

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

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

    
2290
$section->add($group);
2291

    
2292
// Prefix delegation
2293
$group = new Form_Group('');
2294

    
2295
$group->add(new Form_Checkbox(
2296
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2297
	null,
2298
	'Prefix Delegation ',
2299
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2300
));
2301

    
2302
$group->add(new Form_Input(
2303
	'adv_dhcp6_id_assoc_statement_prefix_id',
2304
	null,
2305
	'text',
2306
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2307
))->sethelp('id-assoc pd ID');
2308

    
2309
$group->add(new Form_IpAddress(
2310
	'adv_dhcp6_id_assoc_statement_prefix',
2311
	null,
2312
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2313
))->sethelp('IPv6 prefix');
2314

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

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

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

    
2331
$group = new Form_Group('Prefix interface statement');
2332

    
2333
$group->add(new Form_Input(
2334
	'adv_dhcp6_prefix_interface_statement_sla_id',
2335
	null,
2336
	'text',
2337
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2338
))->sethelp('Prefix Interface sla-id');
2339

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

    
2347
$section->add($group);
2348

    
2349
$group = new Form_Group('Authentication statement');
2350

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

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

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

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

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

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

    
2383
$group->add(new Form_Input(
2384
	'adv_dhcp6_key_info_statement_keyname',
2385
	null,
2386
	'text',
2387
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2388
))->sethelp('Keyname');
2389

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

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

    
2399
$group = new Form_Group('');
2400

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

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

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

    
2422
$section->add($group);
2423

    
2424
$form->add($section);
2425

    
2426
$section = new Form_Section('6RD Configuration');
2427
$section->addClass('_6rd');
2428

    
2429
$section->addInput(new Form_Input(
2430
	'prefix-6rd',
2431
	'6RD Prefix',
2432
	'text',
2433
	$pconfig['prefix-6rd']
2434
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2435

    
2436
$section->addInput(new Form_Input(
2437
	'gateway-6rd',
2438
	'6RD Border relay',
2439
	'text',
2440
	$pconfig['gateway-6rd']
2441
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2442

    
2443
$section->addInput(new Form_Select(
2444
	'prefix-6rd-v4plen',
2445
	'6RD IPv4 Prefix length',
2446
	$pconfig['prefix-6rd-v4plen'],
2447
	array_combine(range(0, 32), range(0, 32))
2448
))->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.');
2449

    
2450
$form->add($section);
2451

    
2452
// Track IPv6 ointerface section
2453
$section = new Form_Section('Track IPv6 Interface');
2454
$section->addClass('track6');
2455

    
2456
function build_ipv6interface_list() {
2457
	global $config, $section;
2458

    
2459
	$list = array('' => '');
2460

    
2461
	$interfaces = get_configured_interface_with_descr(false, true);
2462
	$dynv6ifs = array();
2463

    
2464
	foreach ($interfaces as $iface => $ifacename) {
2465
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2466
			case "6to4":
2467
			case "6rd":
2468
			case "dhcp6":
2469
				$dynv6ifs[$iface] = array(
2470
					'name' => $ifacename,
2471
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2472
				);
2473
				break;
2474
			default:
2475
				continue;
2476
		}
2477
	}
2478

    
2479
	foreach ($dynv6ifs as $iface => $ifacedata) {
2480
		$list[$iface] = $ifacedata['name'];
2481

    
2482
		$section->addInput(new Form_Input(
2483
			'ipv6-num-prefix-ids-' . $iface,
2484
			null,
2485
			'hidden',
2486
			$ifacedata['ipv6_num_prefix_ids']
2487
		));
2488
	}
2489

    
2490
	return($list);
2491
}
2492

    
2493
$section->addInput(new Form_Select(
2494
	'track6-interface',
2495
	'IPv6 Interface',
2496
	$pconfig['track6-interface'],
2497
	build_ipv6interface_list()
2498
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2499

    
2500
if ($pconfig['track6-prefix-id'] == "") {
2501
	$pconfig['track6-prefix-id'] = 0;
2502
}
2503

    
2504
$section->addInput(new Form_Input(
2505
	'track6-prefix-id--hex' . $iface,
2506
	'IPv6 Prefix ID',
2507
	'text',
2508
	sprintf("%x", $pconfig['track6-prefix-id'])
2509
))->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.');
2510

    
2511
$section->addInput(new Form_Input(
2512
	'track6-prefix-id-max' . $iface,
2513
	null,
2514
	'hidden',
2515
	0
2516
));
2517

    
2518
$form->add($section);
2519

    
2520
/// PPP section
2521

    
2522
$section = new Form_Section('PPP Configuration');
2523
$section->addClass('ppp');
2524

    
2525
$section->addInput(new Form_Select(
2526
	'country',
2527
	'Country',
2528
	$pconfig['country'],
2529
	[]
2530
));
2531

    
2532
$section->addInput(new Form_Select(
2533
	'provider_list',
2534
	'Provider',
2535
	$pconfig['provider_list'],
2536
	[]
2537
));
2538

    
2539
$section->addInput(new Form_Select(
2540
	'providerplan',
2541
	'Plan',
2542
	$pconfig['providerplan'],
2543
	[]
2544
))->setHelp('Select to fill in data for your service provider.');
2545

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

    
2553
$section->addInput(new Form_Input(
2554
	'ppp_password',
2555
	'Password',
2556
	'password',
2557
	$pconfig['ppp_password']
2558
));
2559

    
2560
$section->addInput(new Form_Input(
2561
	'phone',
2562
	'Phone number',
2563
	'text',
2564
	$pconfig['phone']
2565
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2566

    
2567
$section->addInput(new Form_Input(
2568
	'apn',
2569
	'Access Point Name',
2570
	'text',
2571
	$pconfig['apn']
2572
));
2573

    
2574

    
2575
function build_port_list() {
2576
	$list = array("" => "None");
2577

    
2578
	$portlist = glob("/dev/cua*");
2579
	$modems	  = glob("/dev/modem*");
2580
	$portlist = array_merge($portlist, $modems);
2581

    
2582
	foreach ($portlist as $port) {
2583
		if (preg_match("/\.(lock|init)$/", $port)) {
2584
			continue;
2585
		}
2586

    
2587
	$list[trim($port)] = $port;
2588
	}
2589

    
2590
	return($list);
2591
}
2592

    
2593
$section->addInput(new Form_Select(
2594
	'port',
2595
	"Modem port",
2596
	$pconfig['port'],
2597
	build_port_list()
2598
));
2599

    
2600
$section->addInput(new Form_Button(
2601
	'btnadvppp',
2602
	'Advanced PPP',
2603
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2604
))->setHelp('Create a new PPP configuration');
2605

    
2606
$form->add($section);
2607

    
2608
// PPPoE configuration
2609
$section = new Form_Section('PPPoE Configuration');
2610
$section->addClass('pppoe');
2611

    
2612
$section->addInput(new Form_Input(
2613
	'pppoe_username',
2614
	'Username',
2615
	'text',
2616
	$pconfig['pppoe_username']
2617
));
2618

    
2619
$section->addInput(new Form_Input(
2620
	'pppoe_password',
2621
	'Password',
2622
	'password',
2623
	$pconfig['pppoe_password']
2624
));
2625

    
2626
$section->addInput(new Form_Input(
2627
	'provider',
2628
	'Service name',
2629
	'text',
2630
	$pconfig['provider']
2631
))->setHelp('This field can usually be left empty');
2632

    
2633
$section->addInput(new Form_Checkbox(
2634
	'pppoe_dialondemand',
2635
	'Dial on demand',
2636
	'Enable Dial-On-Demand mode ',
2637
	$pconfig['pppoe_dialondemand'],
2638
	'enable'
2639
));
2640

    
2641
$section->addInput(new Form_Input(
2642
	'pppoe_idletimeout',
2643
	'Idle timeout',
2644
	'number',
2645
	$pconfig['pppoe_idletimeout'],
2646
	[min => 0]
2647
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2648
			'An idle timeout of zero disables this feature.');
2649

    
2650
$section->addInput(new Form_Select(
2651
	'pppoe-reset-type',
2652
	'Periodic reset',
2653
	$pconfig['pppoe-reset-type'],
2654
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2655
))->setHelp('Select a reset timing type');
2656

    
2657
$group = new Form_Group('Custom reset');
2658
$group->addClass('pppoecustom');
2659

    
2660
$group->add(new Form_Input(
2661
	'pppoe_resethour',
2662
	null,
2663
	'number',
2664
	$pconfig['pppoe_resethour'],
2665
	[min => 0, max => 23]
2666
))->setHelp('Hour (0-23)');
2667

    
2668
$group->add(new Form_Input(
2669
	'pppoe_resetminute',
2670
	null,
2671
	'number',
2672
	$pconfig['pppoe_resetminute'],
2673
	[min => 0, max => 59]
2674
))->setHelp('Minutes (0-59)');
2675

    
2676
// ToDo: Need a date-picker here
2677
$group->add(new Form_Input(
2678
	'pppoe_resetdate',
2679
	null,
2680
	'text',
2681
	$pconfig['pppoe_resetdate']
2682
))->setHelp('Specific date (mm/dd/yyyy)');
2683

    
2684
$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');
2685

    
2686
$section->add($group);
2687

    
2688
$group = new Form_MultiCheckboxGroup('cron based reset');
2689
$group->addClass('pppoepreset');
2690

    
2691
$group->add(new Form_MultiCheckbox(
2692
	'pppoe_pr_preset_val',
2693
	null,
2694
	'Reset at each month ("0 0 1 * *")',
2695
	$pconfig['pppoe_monthly'],
2696
	'monthly'
2697
))->displayAsRadio();
2698

    
2699
$group->add(new Form_MultiCheckbox(
2700
	'pppoe_pr_preset_val',
2701
	null,
2702
	'Reset at each week ("0 0 * * 0")',
2703
	$pconfig['pppoe_weekly'],
2704
	'weekly'
2705
))->displayAsRadio();
2706

    
2707
$group->add(new Form_MultiCheckbox(
2708
	'pppoe_pr_preset_val',
2709
	null,
2710
	'Reset at each day ("0 0 * * *")',
2711
	$pconfig['pppoe_daily'],
2712
	'daily'
2713
))->displayAsRadio();
2714

    
2715
$group->add(new Form_MultiCheckbox(
2716
	'pppoe_pr_preset_val',
2717
	null,
2718
	'Reset at each hour ("0 * * * *")',
2719
	$pconfig['pppoe_hourly'],
2720
	'hourly'
2721
))->displayAsRadio();
2722

    
2723
$section->add($group);
2724

    
2725
if (isset($pconfig['pppid'])) {
2726
	$section->addInput(new Form_StaticText(
2727
		'Advanced and MLPPP',
2728
		'<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>'
2729
	));
2730
} else {
2731
	$section->addInput(new Form_StaticText(
2732
		'Advanced and MLPPP',
2733
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2734
	));
2735
}
2736

    
2737
$form->add($section);
2738

    
2739
// PPTP & L2TP Configuration section
2740
$section = new Form_Section('PPTP/L2TP Configuration');
2741
$section->addClass('pptp');
2742

    
2743
$section->addInput(new Form_Input(
2744
	'pptp_username',
2745
	'Username',
2746
	'text',
2747
	$pconfig['pptp_username']
2748
));
2749

    
2750
$section->addInput(new Form_Input(
2751
	'pptp_password',
2752
	'Password',
2753
	'password',
2754
	$pconfig['pptp_password']
2755
));
2756

    
2757
$section->addInput(new Form_IpAddress(
2758
	'pptp_local0',
2759
	'Local IP address',
2760
	$pconfig['pptp_localip'][0]
2761
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2762

    
2763
$section->addInput(new Form_IpAddress(
2764
	'pptp_remote0',
2765
	'Remote IP address',
2766
	$pconfig['pptp_remote'][0]
2767
));
2768

    
2769
$section->addInput(new Form_Checkbox(
2770
	'pptp_dialondemand',
2771
	'Dial on demand',
2772
	'Enable Dial-On-Demand mode ',
2773
	$pconfig['pptp_dialondemand'],
2774
	'enable'
2775
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2776
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2777

    
2778
$section->addInput(new Form_Input(
2779
	'pptp_idletimeout',
2780
	'Idle timeout (seconds)',
2781
	'number',
2782
	$pconfig['pptp_idletimeout'],
2783
	[min => 0]
2784
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2785
			'An idle timeout of zero disables this feature.');
2786

    
2787
if (isset($pconfig['pppid'])) {
2788
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2789
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2790
	} else {
2791
		$mlppp_text = "";
2792
	}
2793

    
2794
	$section->addInput(new Form_StaticText(
2795
		'Advanced and MLPPP',
2796
		$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>'
2797
	));
2798
} else {
2799
	$section->addInput(new Form_StaticText(
2800
		'Advanced and MLPPP',
2801
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2802
	));
2803
}
2804

    
2805
$form->add($section);
2806

    
2807
// Wireless interface
2808
if (isset($wancfg['wireless'])) {
2809

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

    
2812
	$section->addInput(new Form_Checkbox(
2813
		'persistcommonwireless',
2814
		'Persist common settings',
2815
		'Preserve common wireless configuration through interface deletions and reassignments.',
2816
		$pconfig['persistcommonwireless'],
2817
		'yes'
2818
	));
2819

    
2820
	$mode_list = ['auto' => 'Auto'];
2821

    
2822
	if (is_array($wl_modes)) {
2823
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2824
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2825
		}
2826
	}
2827

    
2828
	if (count($mode_list) == 1)
2829
		$mode_list[''] = '';
2830

    
2831
	$section->addInput(new Form_Select(
2832
		'standard',
2833
		'Standard',
2834
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2835
		$mode_list
2836
	));
2837

    
2838
	if (isset($wl_modes['11g'])) {
2839
		$section->addInput(new Form_Select(
2840
			'protmode',
2841
			'802.11g OFDM Protection Mode',
2842
			$pconfig['protmode'],
2843
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2844
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2845
	}
2846
	else
2847
	{
2848
		$section->addInput(new Form_Input(
2849
			'protmode',
2850
			null,
2851
			'hidden',
2852
			'off'
2853
		));
2854
	}
2855

    
2856
	$mode_list = ['0' => 'Auto'];
2857

    
2858
	if (is_array($wl_modes)) {
2859
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2860
			if ($wl_standard == "11g") {
2861
				$wl_standard = "11b/g";
2862
			} else if ($wl_standard == "11ng") {
2863
				$wl_standard = "11b/g/n";
2864
			} else if ($wl_standard == "11na") {
2865
				$wl_standard = "11a/n";
2866
			}
2867

    
2868
			foreach ($wl_channels as $wl_channel) {
2869
				if (isset($wl_chaninfo[$wl_channel])) {
2870
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2871
				} else {
2872
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2873
				}
2874
			}
2875
		}
2876
	}
2877

    
2878
	$section->addInput(new Form_Select(
2879
		'channel',
2880
		'Channel',
2881
		$pconfig['channel'],
2882
		$mode_list
2883
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2884
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2885

    
2886
	if (ANTENNAS) {
2887
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2888
			$group = new Form_Group('Antenna Settings');
2889

    
2890
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2891
				$group->add(new Form_Select(
2892
					'diversity',
2893
					null,
2894
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2895
					['' => 'Default', '0' => 'Off', '1' => 'On']
2896
				))->setHelp('Diversity');
2897
			}
2898

    
2899
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2900
				$group->add(new Form_Select(
2901
					'txantenna',
2902
					null,
2903
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2904
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2905
				))->setHelp('Transmit antenna');
2906
			}
2907

    
2908
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2909
				$group->add(new Form_Select(
2910
					'rxantenna',
2911
					null,
2912
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2913
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2914
				))->setHelp('Receive antenna');
2915
			}
2916

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

    
2919
			$section->add($group);
2920
		}
2921
	}
2922

    
2923
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2924
			$section->addInput(new Form_Input(
2925
				'distance',
2926
				'Distance setting (meters)',
2927
				'test',
2928
				$pconfig['distance']
2929
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2930
	}
2931

    
2932
	$form->add($section);
2933

    
2934
	// Regulatory settings
2935
	$section = new Form_Section('Regulatory settings');
2936

    
2937
	$domain_list = array("" => 'Default');
2938

    
2939
	if (is_array($wl_regdomains)) {
2940
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2941
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2942
		}
2943
	}
2944

    
2945
	$section->addInput(new Form_Select(
2946
		'regdomain',
2947
		'Regulatory domain',
2948
		$pconfig['regdomain'],
2949
		$domain_list
2950
	))->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');
2951

    
2952
	$country_list = array('' => 'Default');
2953

    
2954
	if (is_array($wl_countries)) {
2955
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2956
			$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']);
2957
		}
2958
	}
2959

    
2960
	$section->addInput(new Form_Select(
2961
		'regcountry',
2962
		'Country',
2963
		$pconfig['regcountry'],
2964
		$country_list
2965
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2966

    
2967
	$section->addInput(new Form_Select(
2968
		'reglocation',
2969
		'Location',
2970
		$pconfig['reglocation'],
2971
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2972
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2973
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2974
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2975
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2976
				'These settings may not be able to add additional channels that are not already supported.');
2977

    
2978
	$form->add($section);
2979

    
2980
	$section = new Form_Section('Network-specific wireless configuration');
2981

    
2982
	$section->addInput(new Form_Select(
2983
		'mode',
2984
		'Mode',
2985
		$pconfig['mode'],
2986
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
2987
	));
2988

    
2989
	$section->addInput(new Form_Input(
2990
		'ssid',
2991
		'SSID',
2992
		'text',
2993
		$pconfig['ssid']
2994
	));
2995

    
2996
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2997
		$section->addInput(new Form_Select(
2998
			'puremode',
2999
			'Minimum wireless standard',
3000
			$pconfig['puremode'],
3001
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
3002
		))->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)');
3003
	} elseif (isset($wl_modes['11g'])) {
3004
		$section->addInput(new Form_Checkbox(
3005
			'puremode',
3006
			'802.11g only',
3007
			null,
3008
			$pconfig['puremode'],
3009
			'11g'
3010
		))->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)');
3011
	}
3012

    
3013
	$section->addInput(new Form_Checkbox(
3014
		'apbridge_enable',
3015
		'Allow intra-BSS communication',
3016
		'Allow packets to pass between wireless clients directly when operating as an access point',
3017
		$pconfig['apbridge_enable'],
3018
		'yes'
3019
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
3020

    
3021
	$section->addInput(new Form_Checkbox(
3022
		'wme_enable',
3023
		'Enable WME',
3024
		'Force the card to use WME (wireless QoS)',
3025
		$pconfig['wme_enable'],
3026
		'yes'
3027
	));
3028

    
3029
	$section->addInput(new Form_Checkbox(
3030
		'hidessid_enable',
3031
		'Hide SSID',
3032
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
3033
		$pconfig['hidessid_enable'],
3034
		'yes'
3035
	));
3036

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

    
3039
	if(ALLOWWEP) {
3040
		// WEP Section
3041
		$section = new Form_Section('WEP');
3042

    
3043
		$section->addInput(new Form_Checkbox(
3044
			'wep_enable',
3045
			'Enable',
3046
			'Enable WEP',
3047
			$pconfig['wep_enable'],
3048
			'yes'
3049
		));
3050

    
3051
		for($idx=1; $idx <= 4; $idx++) {
3052
			$group = new Form_Group('Key' . $idx);
3053

    
3054
			$group->add(new Form_Input(
3055
				'key' . $idx,
3056
				null,
3057
				'text',
3058
				$pconfig['key' . $idx]
3059
			));
3060

    
3061
			$group->add(new Form_Checkbox(
3062
				'txkey',
3063
				null,
3064
				null,
3065
				$pconfig['txkey'],
3066
				$idx
3067
			))->displayAsRadio()->setHelp($idx == 4 ? 'Tx key':'');
3068

    
3069
			$section->add($group);
3070
		}
3071

    
3072
		$section->addInput(new Form_StaticText(
3073
			null,
3074
			'<span class="help-block">' .
3075
			gettext('40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by "0x"') . '<br />' .
3076
			gettext('104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by "0x"') .
3077
			'</span>'
3078
		));
3079

    
3080
		$form->add($section);
3081
	}
3082

    
3083
	// WPA Section
3084
	$section = new Form_Section('WPA');
3085

    
3086
	$section->addInput(new Form_Checkbox(
3087
		'wpa_enable',
3088
		'Enable',
3089
		'Enable WPA',
3090
		$pconfig['wpa_enable'],
3091
		'yes'
3092
	));
3093

    
3094
	$section->addInput(new Form_Input(
3095
		'passphrase',
3096
		'WPA Pre-Shared Key',
3097
		'text',
3098
		$pconfig['passphrase']
3099
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3100

    
3101
	$section->addInput(new Form_Select(
3102
		'wpa_mode',
3103
		'WPA mode',
3104
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3105
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
3106
	));
3107

    
3108
	$section->addInput(new Form_Select(
3109
		'wpa_key_mgmt',
3110
		'WPA Key Management Mode',
3111
		$pconfig['wpa_key_mgmt'],
3112
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
3113
	));
3114

    
3115
	if(ALLOWWEP) {
3116
		$section->addInput(new Form_Select(
3117
			'auth_algs',
3118
			'Authentication',
3119
			$pconfig['auth_algs'],
3120
			['1' => 'Open System Authentication', '2' => 'Shared Key Authentication', '3' => 'Both']
3121
		))->setHelp('Shared Key Authentication requires WEP');
3122
	} else {
3123
		$section->addInput(new Form_Input(
3124
			'auth_algs',
3125
			null,
3126
			'hidden',
3127
			'1'
3128
		));;
3129
	}
3130

    
3131
	$section->addInput(new Form_Select(
3132
		'wpa_pairwise',
3133
		'WPA Pairwise',
3134
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3135
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
3136
	));
3137

    
3138
	$section->addInput(new Form_Input(
3139
		'wpa_group_rekey',
3140
		'WPA Pre-Shared Key',
3141
		'number',
3142
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3143
		['min' => '1', 'max' => 9999]
3144
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3145

    
3146
	$section->addInput(new Form_Input(
3147
		'wpa_gmk_rekey',
3148
		'Master Key Regeneration',
3149
		'number',
3150
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3151
		['min' => '1', 'max' => 9999]
3152
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
3153

    
3154
	$section->addInput(new Form_Checkbox(
3155
		'wpa_strict_rekey',
3156
		'Strict Key Regeneration',
3157
		'Force the AP to rekey whenever a client disassociates',
3158
		$pconfig['wpa_strict_rekey'],
3159
		'yes'
3160
	));
3161

    
3162
	$form->add($section);
3163

    
3164
	$section = new Form_Section('802.1x RADIUS options');
3165

    
3166
	$section->addInput(new Form_Checkbox(
3167
		'ieee8021x',
3168
		'IEEE802.1X',
3169
		'Enable 802.1X authentication',
3170
		$pconfig['ieee8021x'],
3171
		'yes'
3172
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3173

    
3174
	$group = new Form_Group('Primary 802.1X server');
3175

    
3176
	$group->add(new Form_IpAddress(
3177
		'auth_server_addr',
3178
		'IP Address',
3179
		$pconfig['auth_server_addr']
3180
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3181

    
3182
	$group->add(new Form_Input(
3183
		'auth_server_port',
3184
		'Port',
3185
		'number',
3186
		$pconfig['auth_server_port']
3187
	))->setHelp('Server port. Leave blank for the default port 1812');
3188

    
3189
	$group->add(new Form_Input(
3190
		'auth_server_shared_secret',
3191
		'Shared secret',
3192
		'number',
3193
		$pconfig['auth_server_shared_secret']
3194
	))->setHelp('Shared secret');
3195

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

    
3198
	$group = new Form_Group('Secondary 802.1X server');
3199

    
3200
	$group->add(new Form_IpAddress(
3201
		'auth_server_addr2',
3202
		'IP Address',
3203
		$pconfig['auth_server_addr2']
3204
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3205

    
3206
	$group->add(new Form_Input(
3207
		'auth_server_port2',
3208
		'Port',
3209
		'number',
3210
		$pconfig['auth_server_port2']
3211
	))->setHelp('Server port. Leave blank for the default port 1812');
3212

    
3213
	$group->add(new Form_Input(
3214
		'auth_server_shared_secret2',
3215
		'Shared secret',
3216
		'number',
3217
		$pconfig['auth_server_shared_secret2']
3218
	))->setHelp('Shared secret');
3219

    
3220
	$section->add($group);
3221

    
3222
	$section->addInput(new Form_Checkbox(
3223
		'rsn_preauth',
3224
		'Authentication Roaming Preauth',
3225
		null,
3226
		$pconfig['rsn_preauth'],
3227
		'yes'
3228
	));
3229

    
3230
	$form->add($section);
3231
}
3232

    
3233
$section = new Form_Section('Private networks');
3234

    
3235
$section->addInput(new Form_Checkbox(
3236
	'blockpriv',
3237
	'Block private networks',
3238
	'',
3239
	$pconfig['blockpriv'],
3240
	'yes'
3241
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3242
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3243
			'lies in such a private address space, too.');
3244

    
3245
	$section->addInput(new Form_Checkbox(
3246
	'blockbogons',
3247
	'Block bogon networks',
3248
	'',
3249
	$pconfig['blockbogons'],
3250
	'yes'
3251
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3252
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3253
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3254

    
3255
$form->add($section);
3256

    
3257
$form->addGlobal(new Form_Input(
3258
	'if',
3259
	null,
3260
	'hidden',
3261
	$if
3262
));
3263

    
3264
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3265
	$form->addGlobal(new Form_Input(
3266
		'ppp_port',
3267
		null,
3268
		'hidden',
3269
		$pconfig['port']
3270
	));
3271
}
3272

    
3273
$form->addGlobal(new Form_Input(
3274
	'ptpid',
3275
	null,
3276
	'hidden',
3277
	$pconfig['ptpid']
3278
));
3279

    
3280

    
3281
// Add new gateway modal pop-up
3282
$modal = new Modal('New gateway', 'newgateway', 'large');
3283

    
3284
$modal->addInput(new Form_Checkbox(
3285
	'defaultgw',
3286
	'Default',
3287
	'Default gateway',
3288
	($if == "wan" || $if == "WAN")
3289
));
3290

    
3291
$modal->addInput(new Form_Input(
3292
	'name',
3293
	'Gateway name',
3294
	'text',
3295
	$wancfg['descr'] . "GW"
3296
));
3297

    
3298
$modal->addInput(new Form_IpAddress(
3299
	'gatewayip',
3300
	'Gateway IPv4',
3301
	null
3302
));
3303

    
3304
$modal->addInput(new Form_Input(
3305
	'gatewaydescr',
3306
	'Description',
3307
	'text'
3308
));
3309

    
3310
$btnaddgw = new Form_Button(
3311
	'add',
3312
	'Add'
3313
);
3314

    
3315
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3316

    
3317
$btncnxgw = new Form_Button(
3318
	'cnx',
3319
	'Cancel'
3320
);
3321

    
3322
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3323

    
3324
$modal->addInput(new Form_StaticText(
3325
	null,
3326
	$btnaddgw . $btncnxgw
3327
));
3328

    
3329
$form->add($modal);
3330

    
3331
print($form);
3332
?>
3333

    
3334
<script type="text/javascript">
3335
//<![CDATA[
3336
events.push(function(){
3337
	function updateType(t) {
3338

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

    
3373
		if (t != "l2tp" && t != "pptp") {
3374
			$('.'+t).show();
3375
		}
3376
	}
3377

    
3378
	function updateTypeSix(t) {
3379
		if (!isNaN(t[0]))
3380
			t = '_' + t;
3381

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

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

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

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

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

    
3443
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3444
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3445
	}
3446

    
3447
	// Create the new gateway from the data entered in the modal pop-up
3448
	function hide_add_gatewaysave() {
3449
		var iface = $('#if').val();
3450
		name = $('#name').val();
3451
		var descr = $('#gatewaydescr').val();
3452
		gatewayip = $('#gatewayip').val();
3453

    
3454
		var defaultgw = '';
3455
		if ($('#defaultgw').is(':checked')) {
3456
			defaultgw = '&defaultgw=on';
3457
		}
3458

    
3459
		var url = "system_gateways_edit.php";
3460
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3461
		$.ajax(
3462
			url,
3463
			{
3464
				type: 'post',
3465
				data: pars,
3466
				error: report_failure,
3467
				complete: save_callback
3468
			});
3469
		}
3470

    
3471
	function save_callback(response) {
3472
		if (response) {
3473
			var gwtext = escape(name) + " - " + gatewayip;
3474
			addOption($('#gateway'), gwtext, name);
3475
		} else {
3476
			report_failure();
3477
		}
3478

    
3479
		$("#newgateway").modal('hide');
3480
	}
3481

    
3482
	function report_failure(request, textStatus, errorThrown) {
3483
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3484
			alert(request.responseText);
3485
		} else {
3486
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3487
		}
3488

    
3489
		$("#newgateway").modal('hide');
3490
	}
3491

    
3492
	function addOption(selectbox, text, value)
3493
	{
3494
		var optn = document.createElement("OPTION");
3495
		optn.text = text;
3496
		optn.value = value;
3497
		selectbox.append(optn);
3498
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3499
	}
3500

    
3501
	function hide_add_gatewaysave_v6() {
3502

    
3503
		var iface = $('#if').val();
3504
		name = $('#name6').val();
3505
		var descr = $('#gatewaydescr6').val();
3506
		gatewayip = $('#gatewayip6').val();
3507
		var defaultgw = '';
3508
		if ($('#defaultgw6').is(':checked')) {
3509
			defaultgw = '&defaultgw=on';
3510
		}
3511
		var url_v6 = "system_gateways_edit.php";
3512
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3513
		$.ajax(
3514
			url_v6,
3515
			{
3516
				type: 'post',
3517
				data: pars_v6,
3518
				error: report_failure_v6,
3519
				success: save_callback_v6
3520
			});
3521
	}
3522

    
3523

    
3524
	function addOption_v6(selectbox, text, value)
3525
	{
3526
		var optn = document.createElement("OPTION");
3527
		optn.text = text;
3528
		optn.value = value;
3529
		selectbox.append(optn);
3530
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3531
	}
3532

    
3533
	function report_failure_v6(request, textStatus, errorThrown) {
3534
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3535
			alert(request.responseText);
3536
		} else {
3537
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3538
		}
3539

    
3540
		$("#newgateway6").modal('hide');
3541
	}
3542

    
3543
	function save_callback_v6(response_v6) {
3544
		if (response_v6) {
3545

    
3546
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3547
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3548
		} else {
3549
			report_failure_v6();
3550
		}
3551

    
3552
		$("#newgateway6").modal('hide');
3553
	}
3554

    
3555
	function country_list() {
3556
		$('#country').children().remove();
3557
		$('#provider_list').children().remove();
3558
		$('#providerplan').children().remove();
3559
		$.ajax("getserviceproviders.php",{
3560
			success: function(response) {
3561

    
3562
				var responseTextArr = response.split("\n");
3563
				responseTextArr.sort();
3564

    
3565
				responseTextArr.forEach( function(value) {
3566
					country = value.split(":");
3567
					$('#country').append($('<option>', {
3568
						value: country[1],
3569
						text : country[0]
3570
					}));
3571
				});
3572
			}
3573
		});
3574
	}
3575

    
3576
	function providers_list() {
3577
		$('#provider_list').children().remove();
3578
		$('#providerplan').children().remove();
3579
		$.ajax("getserviceproviders.php",{
3580
			type: 'post',
3581
			data: {country : $('#country').val()},
3582
			success: function(response) {
3583
				var responseTextArr = response.split("\n");
3584
				responseTextArr.sort();
3585
				responseTextArr.forEach( function(value) {
3586
					$('#provider_list').append($('<option>', {
3587
							value: value,
3588
							text : value
3589
					}));
3590
				});
3591
			}
3592
		});
3593
	}
3594

    
3595
	function providerplan_list() {
3596
		$('#providerplan').children().remove();
3597
		$.ajax("getserviceproviders.php",{
3598
			type: 'post',
3599
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3600
			success: function(response) {
3601
				var responseTextArr = response.split("\n");
3602
				responseTextArr.sort();
3603

    
3604
				$('#providerplan').append($('<option>', {
3605
					value: '',
3606
					text : ''
3607
				}));
3608

    
3609
				responseTextArr.forEach( function(value) {
3610
					if (value != "") {
3611
						providerplan = value.split(":");
3612

    
3613
						$('#providerplan').append($('<option>', {
3614
							value: providerplan[1],
3615
							text : providerplan[0] + " - " + providerplan[1]
3616
						}));
3617
					}
3618
				});
3619
			}
3620
		});
3621
	}
3622

    
3623
	function prefill_provider() {
3624
		$.ajax("getserviceproviders.php",{
3625
			type: 'post',
3626
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3627
			success: function(data, textStatus, response) {
3628
				var xmldoc = response.responseXML;
3629
				var provider = xmldoc.getElementsByTagName('connection')[0];
3630
				$('#ppp_username').val('');
3631
				$('#ppp_password').val('');
3632
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3633
					$('#phone').val('#777');
3634
					$('#apn').val('');
3635
				} else {
3636
					$('#phone').val('*99#');
3637
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3638
				}
3639
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3640
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3641
				$('#ppp_username').val(ppp_username);
3642
				$('#ppp_password').val(ppp_password);
3643
			}
3644
		});
3645
	}
3646

    
3647
	function show_dhcp6adv() {
3648
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3649
		var adv = $('#dhcp6adv').prop('checked');
3650

    
3651
		hideCheckbox('dhcp6usev4iface', ovr);
3652
		hideCheckbox('dhcp6prefixonly', ovr);
3653
		hideInput('dhcp6-ia-pd-len', ovr);
3654
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3655
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3656

    
3657
		hideClass('dhcp6advanced', !adv || ovr);
3658
	}
3659

    
3660
	function setDHCPoptions() {
3661
		var adv = $('#dhcpadv').prop('checked');
3662
		var ovr = $('#dhcpovr').prop('checked');
3663

    
3664
		if(ovr) {
3665
			hideInput('dhcphostname', true);
3666
			hideIpAddress('alias-address', true);
3667
			hideInput('dhcprejectfrom', true);
3668
			hideInput('adv_dhcp_config_file_override_path', false);
3669
			hideClass('dhcpadvanced', true);
3670
		} else {
3671
			hideInput('dhcphostname', false);
3672
			hideIpAddress('alias-address', false);
3673
			hideInput('dhcprejectfrom', false);
3674
			hideInput('adv_dhcp_config_file_override_path', true);
3675
			hideClass('dhcpadvanced', !adv);
3676
		}
3677
	}
3678

    
3679
	// DHCP preset actions
3680
	// Set presets from value of radio buttons
3681
	function setPresets(val) {
3682
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3683
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3684
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3685
		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']);?>");
3686
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3687
	}
3688

    
3689
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3690
		$('#adv_dhcp_pt_timeout').val(timeout);
3691
		$('#adv_dhcp_pt_retry').val(retry);
3692
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3693
		$('#adv_dhcp_pt_reboot').val(reboot);
3694
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3695
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3696
	}
3697

    
3698
	// ---------- On initial page load ------------------------------------------------------------
3699

    
3700
	updateType($('#type').val());
3701
	updateTypeSix($('#type6').val());
3702
	show_reset_settings($('#pppoe-reset-type').val());
3703
	$("#add").prop('type' ,'button');
3704
	$("#cnx").prop('type' ,'button');
3705
	$("#addgw").prop('type' ,'button');
3706
	$("#add6").prop('type' ,'button');
3707
	$("#cnx6").prop('type' ,'button');
3708
	$("#addgw6").prop('type' ,'button');
3709
	hideClass('dhcp6advanced', true);
3710
	hideClass('dhcpadvanced', true);
3711
	show_dhcp6adv();
3712
	setDHCPoptions()
3713

    
3714
	// Set preset buttons on page load
3715
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3716
	if(sv == "")
3717
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3718

    
3719
	// Set preset from value
3720
	setPresets(sv);
3721
	
3722
	// ---------- Click checkbox handlers ---------------------------------------------------------
3723

    
3724
	$('#type').on('change', function() {
3725
		updateType( this.value );
3726
	});
3727

    
3728
	$('#type6').on('change', function() {
3729
		updateTypeSix( this.value );
3730
	});
3731

    
3732
	$('#pppoe-reset-type').on('change', function() {
3733
		show_reset_settings( this.value );
3734
	});
3735

    
3736
	$("#add").click(function() {
3737
		hide_add_gatewaysave();
3738
	});
3739

    
3740
	$("#cnx").click(function() {
3741
		$("#newgateway").modal('hide');
3742
	});
3743

    
3744
	$("#add6").click(function() {
3745
		hide_add_gatewaysave_v6();
3746
	});
3747

    
3748
	$("#cnx6").click(function() {
3749
		$("#newgateway6").modal('hide');
3750
	});
3751

    
3752
	$('#country').on('change', function() {
3753
		providers_list();
3754
	});
3755

    
3756
	$('#provider_list').on('change', function() {
3757
		providerplan_list();
3758
	});
3759

    
3760
	$('#providerplan').on('change', function() {
3761
		prefill_provider();
3762
	});
3763

    
3764
	$('#dhcpadv, #dhcpovr').click(function () {
3765
		setDHCPoptions();
3766
	});
3767

    
3768
	$('#dhcp6adv').click(function () {
3769
		show_dhcp6adv();
3770
	});
3771

    
3772
	$('#adv_dhcp6_config_file_override').click(function () {
3773
		show_dhcp6adv();
3774
	});
3775

    
3776
	// On click . .
3777
	$('[id=adv_dhcp_pt_values]').click(function () {
3778
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3779
	});
3780

    
3781
});
3782
//]]>
3783
</script>
3784

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