Project

General

Profile

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

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

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

    
77
define("ANTENNAS", false);
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
446
}
447

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

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

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

    
477
		clear_subsystem_dirty('interfaces');
478

    
479
		filter_configure();
480

    
481
		enable_rrd_graphing();
482

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

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

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

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

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

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

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

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

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

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

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

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

    
824
		unset($min_mtu, $max_mtu);
825

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

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

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

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

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

    
944
		if ($_POST['wpa_enable'] == "yes") {
945
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
946
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
947
			}
948
		}
949
	}
950
	if (!$input_errors) {
951
		// These 3 fields can be a list of multiple data items when used for MLPPP.
952
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
953
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
954
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
955
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
956

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

    
995
		unset($wancfg['adv_dhcp_pt_timeout']);
996
		unset($wancfg['adv_dhcp_pt_retry']);
997
		unset($wancfg['adv_dhcp_pt_select_timeout']);
998
		unset($wancfg['adv_dhcp_pt_reboot']);
999
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1000
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1001

    
1002
		unset($wancfg['adv_dhcp_pt_values']);
1003

    
1004
		unset($wancfg['adv_dhcp_send_options']);
1005
		unset($wancfg['adv_dhcp_request_options']);
1006
		unset($wancfg['adv_dhcp_required_options']);
1007
		unset($wancfg['adv_dhcp_option_modifiers']);
1008

    
1009
		unset($wancfg['adv_dhcp_config_advanced']);
1010
		unset($wancfg['adv_dhcp_config_file_override']);
1011
		unset($wancfg['adv_dhcp_config_file_override_path']);
1012

    
1013
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1014
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1015
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1016
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1017

    
1018
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1019
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1020
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1021
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1022
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1023

    
1024
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1025
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1026
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1027
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1028
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1029

    
1030
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1031
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1032

    
1033
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1034
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1035
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1036
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1037

    
1038
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1039
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1040
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1041
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1042
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1043

    
1044
		unset($wancfg['adv_dhcp6_config_advanced']);
1045
		unset($wancfg['adv_dhcp6_config_file_override']);
1046
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1047

    
1048
		unset($wancfg['pppoe_password']);
1049
		unset($wancfg['pptp_username']);
1050
		unset($wancfg['pptp_password']);
1051
		unset($wancfg['provider']);
1052
		unset($wancfg['ondemand']);
1053
		unset($wancfg['timeout']);
1054
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1055
			unset($wancfg['pppoe']['pppoe-reset-type']);
1056
		}
1057
		unset($wancfg['local']);
1058

    
1059
		unset($wancfg['remote']);
1060
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1061
			if ($wancfg['ipaddr'] != 'ppp') {
1062
				unset($a_ppps[$pppid]['apn']);
1063
				unset($a_ppps[$pppid]['phone']);
1064
				unset($a_ppps[$pppid]['provider']);
1065
				unset($a_ppps[$pppid]['ondemand']);
1066
			}
1067
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1068
				unset($a_ppps[$pppid]['localip']);
1069
				unset($a_ppps[$pppid]['subnet']);
1070
				unset($a_ppps[$pppid]['gateway']);
1071
			}
1072
			if ($wancfg['ipaddr'] != 'pppoe') {
1073
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1074
			}
1075
			if ($wancfg['type'] != $_POST['type']) {
1076
				unset($a_ppps[$pppid]['idletimeout']);
1077
			}
1078
		}
1079

    
1080
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1081
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1082

    
1083
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1084
		switch ($_POST['type']) {
1085
			case "staticv4":
1086
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1087
				$wancfg['subnet'] = $_POST['subnet'];
1088
				if ($_POST['gateway'] != "none") {
1089
					$wancfg['gateway'] = $_POST['gateway'];
1090
				}
1091
				break;
1092
			case "dhcp":
1093
				$wancfg['ipaddr'] = "dhcp";
1094
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1095
				$wancfg['alias-address'] = $_POST['alias-address'];
1096
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1097
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1098

    
1099
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1100
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1101
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1102
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1103
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1104
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1105

    
1106
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1107

    
1108
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1109
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1110
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1111
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1112

    
1113
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1114
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1115
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1116

    
1117
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1118
				if ($gateway_item) {
1119
					$a_gateways[] = $gateway_item;
1120
				}
1121
				break;
1122
			case "ppp":
1123
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1124
				$a_ppps[$pppid]['type'] = $_POST['type'];
1125
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1126
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1127
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1128
				$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1129
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1130
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1131
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1132
				$wancfg['ipaddr'] = $_POST['type'];
1133
				break;
1134

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

    
1158
				if (!empty($_POST['pppoe-reset-type'])) {
1159
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1160
				} else {
1161
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1162
				}
1163
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1164
				$wancfg['ipaddr'] = $_POST['type'];
1165
				if ($gateway_item) {
1166
					$a_gateways[] = $gateway_item;
1167
				}
1168

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

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

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

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

    
1274
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1275
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1276
				}
1277
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1278
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1279
				}
1280

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

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

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

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

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

    
1391
		conf_mount_ro();
1392
		write_config();
1393

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

    
1403
		mark_subsystem_dirty('interfaces');
1404

    
1405
		/* regenerate cron settings/crontab file */
1406
		configure_cron();
1407

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

    
1412
} // end if ($_POST)
1413

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

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

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

    
1563
	interface_sync_wireless_clones($wancfg, true);
1564
}
1565

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

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

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

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

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

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

    
1614
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1615
$shortcut_section = "interfaces";
1616

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

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

    
1625
function build_mediaopts_list() {
1626
	global $mediaopts_list;
1627

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

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

    
1636
	return($list);
1637
}
1638

    
1639
function build_gateway_list() {
1640
	global $a_gateways, $if;
1641

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

    
1649
	return($list);
1650
}
1651

    
1652
function build_gatewayv6_list() {
1653
	global $a_gateways, $if;
1654

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

    
1662
	return($list);
1663
}
1664

    
1665
include("head.inc");
1666

    
1667
if ($input_errors) {
1668
	print_input_errors($input_errors);
1669
}
1670

    
1671
if (is_subsystem_dirty('interfaces')) {
1672
	print_info_box_np(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1673
					  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."));
1674
}
1675

    
1676
if ($savemsg) {
1677
	print_info_box($savemsg, 'success');
1678
}
1679

    
1680

    
1681
$form = new Form(new Form_Button(
1682
	'Submit',
1683
	gettext("Save")
1684
));
1685

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

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

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

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

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

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

    
1725
$btnmymac = new Form_Button(
1726
	'btnmymac',
1727
	'Copy My MAC'
1728
	);
1729

    
1730
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1731

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

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

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

    
1755
if (count($mediaopts_list) > 0) {
1756
	$section->addInput(new Form_Select(
1757
		'mediaopt',
1758
		'Speed and Duplex',
1759
		rtrim($mediaopt_from_config),
1760
		build_mediaopts_list()
1761
	))->setHelp('Here you can explicitly set speed and duplex mode for this interface.' . '<br />' .
1762
				'WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.');
1763
}
1764

    
1765
$form->add($section);
1766

    
1767
$section = new Form_Section('Static IPv4 configuration');
1768
$section->addClass('staticv4');
1769

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

    
1776
$group = new Form_Group('IPv4 Upstream gateway');
1777

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

    
1785
$group->add(new Form_Button(
1786
	'addgw',
1787
	'Add a new gateway'
1788
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway')->setAttribute('data-toggle', 'modal');
1789

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

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

    
1796
$form->add($section);
1797

    
1798
$section = new Form_Section('Static IPv6 configuration');
1799
$section->addClass('staticv6');
1800

    
1801
$section->addInput(new Form_IpAddress(
1802
	'ipaddrv6',
1803
	'IPv6 address',
1804
	$pconfig['ipaddrv6']
1805
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
1806

    
1807
$group = new Form_Group('IPv6 Upstream gateway');
1808

    
1809
$group->add(new Form_Select(
1810
	'gatewayv6',
1811
	'IPv6 Upstream Gateway',
1812
	$pconfig['gatewayv6'],
1813
	build_gatewayv6_list()
1814
));
1815

    
1816
$group->add(new Form_Button(
1817
	'addgw6',
1818
	'Add a new gateway'
1819
))->removeClass('btn-primary')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
1820

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

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

    
1827
// Add new gateway modal pop-up for IPv6
1828
$modal = new Modal('New IPv6 gateway', 'newgateway6', 'large');
1829

    
1830
$modal->addInput(new Form_Checkbox(
1831
	'defaultgw6',
1832
	'Default',
1833
	'Default gateway',
1834
	($if == "wan" || $if == "WAN")
1835
));
1836

    
1837
$modal->addInput(new Form_Input(
1838
	'name6',
1839
	'Gateway name',
1840
	'text',
1841
	$wancfg['descr'] . "GWv6"
1842
));
1843

    
1844
$modal->addInput(new Form_IpAddress(
1845
	'gatewayip6',
1846
	'Gateway IPv6',
1847
	null
1848
));
1849

    
1850
$modal->addInput(new Form_Input(
1851
	'gatewaydescr6',
1852
	'Description',
1853
	'text'
1854
));
1855

    
1856
$btnaddgw6 = new Form_Button(
1857
	'add6',
1858
	'Add'
1859
);
1860

    
1861
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1862

    
1863
$btncnxgw6 = new Form_Button(
1864
	'cnx6',
1865
	'Cancel'
1866
);
1867

    
1868
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1869

    
1870
$modal->addInput(new Form_StaticText(
1871
	null,
1872
	$btnaddgw6 . $btncnxgw6
1873
));
1874

    
1875
$form->add($modal);
1876

    
1877
// ==== DHCP client configuration =============================
1878

    
1879
$section = new Form_Section('DHCP client configuration');
1880
$section->addClass('dhcp');
1881

    
1882
$group = new Form_Group('Options');
1883

    
1884
$group->add(new Form_Checkbox(
1885
	'dhcpadv',
1886
	null,
1887
	'Show DHCP advanced options',
1888
	false
1889
));
1890

    
1891
$group->add(new Form_Checkbox(
1892
	'dhcpovr',
1893
	null,
1894
	'Config file override',
1895
	false
1896
));
1897

    
1898
$section->add($group);
1899

    
1900
$section->addInput(new Form_Input(
1901
	'dhcphostname',
1902
	'Hostname',
1903
	'text',
1904
	$pconfig['dhcphostname']
1905
))->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).');
1906

    
1907
$section->addInput(new Form_IpAddress(
1908
	'alias-address',
1909
	'Alias IPv4 address',
1910
	$pconfig['alias-address']
1911
))->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.');
1912

    
1913
$section->addInput(new Form_Input(
1914
	'dhcprejectfrom',
1915
	'Reject leases from',
1916
	'text',
1917
	$pconfig['dhcprejectfrom']
1918
))->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. ' .
1919
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1920

    
1921
$group = new Form_Group('Protocol timing');
1922
$group->addClass('dhcpadvanced');
1923

    
1924
$group->add(new Form_Input(
1925
	'adv_dhcp_pt_timeout',
1926
	null,
1927
	'number',
1928
	$pconfig['adv_dhcp_pt_timeout']
1929
))->setHelp('Timeout');
1930

    
1931
$group->add(new Form_Input(
1932
	'adv_dhcp_pt_retry',
1933
	null,
1934
	'number',
1935
	$pconfig['adv_dhcp_pt_retry']
1936
))->setHelp('Retry');
1937

    
1938
$group->add(new Form_Input(
1939
	'adv_dhcp_pt_select_timeout',
1940
	null,
1941
	'number',
1942
	$pconfig['adv_dhcp_pt_select_timeout'],
1943
	['min' => 0]
1944
))->setHelp('Select timeout');
1945

    
1946
$group->add(new Form_Input(
1947
	'adv_dhcp_pt_reboot',
1948
	null,
1949
	'number',
1950
	$pconfig['adv_dhcp_pt_reboot']
1951
))->setHelp('Reboot');
1952

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

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

    
1967
$section->add($group);
1968

    
1969
$group = new Form_Group('Presets');
1970
$group->addClass('dhcpadvanced');
1971

    
1972
$group->add(new Form_Checkbox(
1973
	'adv_dhcp_pt_values',
1974
	null,
1975
	'FreeBSD default',
1976
	null,
1977
	'DHCP'
1978
))->displayAsRadio();
1979

    
1980
$group->add(new Form_Checkbox(
1981
	'adv_dhcp_pt_values',
1982
	null,
1983
	'Clear',
1984
	null,
1985
	'Clear'
1986
))->displayAsRadio();
1987

    
1988
$group->add(new Form_Checkbox(
1989
	'adv_dhcp_pt_values',
1990
	null,
1991
	'pfSense Default',
1992
	null,
1993
	'pfSense'
1994
))->displayAsRadio();
1995

    
1996
$group->add(new Form_Checkbox(
1997
	'adv_dhcp_pt_values',
1998
	null,
1999
	'Saved Cfg',
2000
	null,
2001
	'SavedCfg'
2002
))->displayAsRadio();
2003

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

    
2007
$section->add($group);
2008

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

    
2019
$form->add($section);
2020

    
2021
$section = new Form_Section('Lease Requirements and Requests');
2022
$section->addClass('dhcpadvanced');
2023

    
2024
$section->addInput(new Form_Input(
2025
	'adv_dhcp_send_options',
2026
	'Send options',
2027
	'text',
2028
	$pconfig['adv_dhcp_send_options']
2029
))->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2030
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2031
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2032
			'Some ISPs may require certain options be or not be sent.');
2033

    
2034
$section->addInput(new Form_Input(
2035
	'adv_dhcp_request_options',
2036
	'Request options',
2037
	'text',
2038
	$pconfig['adv_dhcp_request_options']
2039
))->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]]' . '<br />' .
2040
			'Some ISPs may require certain options be or not be requested.');
2041

    
2042
$section->addInput(new Form_Input(
2043
	'adv_dhcp_required_options',
2044
	'Require options',
2045
	'text',
2046
	$pconfig['adv_dhcp_required_options']
2047
))->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2048

    
2049
$section->addInput(new Form_Input(
2050
	'adv_dhcp_option_modifiers',
2051
	'Option modifiers',
2052
	'text',
2053
	$pconfig['adv_dhcp_option_modifiers']
2054
))->sethelp('The values in this field are DHCP option modifiers applied to obtained DHCP lease.	 [modifier option declaration [, ...]]' . '<br />' .
2055
			'modifiers: (default, supersede, prepend, append)');
2056

    
2057
$form->add($section);
2058

    
2059
// DHCP6 client config
2060

    
2061
$section = new Form_Section('DHCP6 client configuration');
2062
$section->addClass('dhcp6');
2063

    
2064
$section->addInput(new Form_Checkbox(
2065
	'dhcp6adv',
2066
	'Advanced',
2067
	'Show DHCPv6 advanced options',
2068
	$pconfig['adv_dhcp6_config_advanced']
2069
));
2070

    
2071
$section->addInput(new Form_Checkbox(
2072
	'adv_dhcp6_config_file_override',
2073
	'Config file override',
2074
	'Override the configuration from this file',
2075
	$pconfig['adv_dhcp6_config_file_override']
2076
));
2077

    
2078
$section->addInput(new Form_Checkbox(
2079
	'dhcp6usev4iface',
2080
	'Use IPv4 connectivity as parent interface',
2081
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2082
	$pconfig['dhcp6usev4iface']
2083
));
2084

    
2085
$section->addInput(new Form_Checkbox(
2086
	'dhcp6prefixonly',
2087
	'Request only an IPv6 prefix',
2088
	'Only request an IPv6 prefix, do not request an IPv6 address',
2089
	$pconfig['dhcp6prefixonly']
2090
));
2091

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

    
2099
$section->addInput(new Form_Checkbox(
2100
	'dhcp6-ia-pd-send-hint',
2101
	'Send IPv6 prefix hint',
2102
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2103
	$pconfig['dhcp6-ia-pd-send-hint']
2104
));
2105

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

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

    
2118
// DHCP6 client config - Advanced
2119

    
2120
$section = new Form_Section('Advanced DHCP6 client configuration');
2121
$section->addClass('dhcp6advanced');
2122

    
2123
$section->addInput(new Form_Checkbox(
2124
	'adv_dhcp6_interface_statement_information_only_enable',
2125
	'Information only',
2126
	null,
2127
	$pconfig['adv_dhcp6_interface_statement_information_only_enable']
2128
));
2129

    
2130
$section->addInput(new Form_Input(
2131
	'adv_dhcp6_interface_statement_send_options',
2132
	'Send options',
2133
	'text',
2134
	$pconfig['adv_dhcp6_interface_statement_send_options']
2135
))->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]]' . '<br />' .
2136
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD}' . '<br />' .
2137
			'Where C is U(pper) or L(ower) Case, and D is \" :-.\" Delimiter (space, colon, hyphen, or period) (omitted for none).' . '<br />' .
2138
			'Some DHCP services may require certain options be or not be sent.');
2139

    
2140
$section->addInput(new Form_Input(
2141
	'adv_dhcp6_interface_statement_request_options',
2142
	'Request Options',
2143
	'text',
2144
	$pconfig['adv_dhcp6_interface_statement_request_options']
2145
))->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]]' . '<br />' .
2146
			'Some DHCP services may require certain options be or not be requested.');
2147

    
2148
$section->addInput(new Form_Input(
2149
	'adv_dhcp6_interface_statement_script',
2150
	'Scripts',
2151
	'text',
2152
	$pconfig['adv_dhcp6_interface_statement_script']
2153
))->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.' . '<br />' .
2154
			'[/[dirname/[.../]]filename[.ext]].');
2155

    
2156
$group = new Form_Group('Identity Association Statement');
2157

    
2158
$group->add(new Form_Checkbox(
2159
	'adv_dhcp6_id_assoc_statement_address_enable',
2160
	null,
2161
	'Non-Temporary Address Allocation',
2162
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable']
2163
));
2164

    
2165
$group->add(new Form_Input(
2166
	'adv_dhcp6_id_assoc_statement_address_id',
2167
	null,
2168
	'text',
2169
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2170
))->sethelp('id-assoc na ID');
2171

    
2172
$group->add(new Form_IpAddress(
2173
	'adv_dhcp6_id_assoc_statement_address',
2174
	null,
2175
	$pconfig['adv_dhcp6_id_assoc_statement_address']
2176
))->sethelp('IPv6 address');
2177

    
2178
$group->add(new Form_Input(
2179
	'adv_dhcp6_id_assoc_statement_address_pltime',
2180
	null,
2181
	'text',
2182
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2183
))->sethelp('pltime');
2184

    
2185
$group->add(new Form_Input(
2186
	'adv_dhcp6_id_assoc_statement_address_vltime',
2187
	null,
2188
	'text',
2189
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2190
))->sethelp('vltime');
2191

    
2192
$section->add($group);
2193

    
2194
// Prefix delegation
2195
$group = new Form_Group('');
2196

    
2197
$group->add(new Form_Checkbox(
2198
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2199
	null,
2200
	'Prefix Delegation ',
2201
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']
2202
));
2203

    
2204
$group->add(new Form_Input(
2205
	'adv_dhcp6_id_assoc_statement_prefix_id',
2206
	null,
2207
	'text',
2208
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2209
))->sethelp('id-assoc pd ID');
2210

    
2211
$group->add(new Form_IpAddress(
2212
	'adv_dhcp6_id_assoc_statement_prefix',
2213
	null,
2214
	$pconfig['adv_dhcp6_id_assoc_statement_prefix']
2215
))->sethelp('IPv6 prefix');
2216

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

    
2224
$group->add(new Form_Input(
2225
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2226
	null,
2227
	'text',
2228
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2229
))->sethelp('vltime');
2230

    
2231
$section->add($group);
2232

    
2233
$group = new Form_Group('Prefix interface statement');
2234

    
2235
$group->add(new Form_Input(
2236
	'adv_dhcp6_prefix_interface_statement_sla_id',
2237
	null,
2238
	'text',
2239
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2240
))->sethelp('Prefix Interface sla-id');
2241

    
2242
$group->add(new Form_Input(
2243
	'adv_dhcp6_prefix_interface_statement_sla_len',
2244
	null,
2245
	'text',
2246
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2247
))->sethelp('sla-len');
2248

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

    
2251
$group = new Form_Group('Authentication statement');
2252

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

    
2260
$group->add(new Form_Input(
2261
	'adv_dhcp6_authentication_statement_protocol',
2262
	null,
2263
	'text',
2264
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2265
))->sethelp('Protocol');
2266

    
2267
$group->add(new Form_Input(
2268
	'adv_dhcp6_authentication_statement_algorithm',
2269
	null,
2270
	'text',
2271
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2272
))->sethelp('Algorithm');
2273

    
2274
$group->add(new Form_Input(
2275
	'adv_dhcp6_authentication_statement_rdm',
2276
	null,
2277
	'text',
2278
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2279
))->sethelp('RDM');
2280

    
2281
$section->add($group);
2282

    
2283
$group = new Form_Group('Keyinfo statement');
2284

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

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

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

    
2301
$group = new Form_Group('');
2302

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

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

    
2317
$group->add(new Form_Input(
2318
	'adv_dhcp6_key_info_statement_expire',
2319
	null,
2320
	'text',
2321
	$pconfig['adv_dhcp6_key_info_statement_expire']
2322
))->sethelp('Expire');
2323

    
2324
$section->add($group);
2325

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

    
2328
$section = new Form_Section('6RD Configuration');
2329
$section->addClass('_6rd');
2330

    
2331
$section->addInput(new Form_Input(
2332
	'prefix-6rd',
2333
	'6RD Prefix',
2334
	'text',
2335
	$pconfig['prefix-6rd']
2336
))->sethelp('6RD IPv6 prefix assigned by your ISP. e.g. "2001:db8::/32"');
2337

    
2338
$section->addInput(new Form_Input(
2339
	'gateway-6rd',
2340
	'6RD Border relay',
2341
	'text',
2342
	$pconfig['gateway-6rd']
2343
))->sethelp('6RD IPv4 gateway address assigned by your ISP');
2344

    
2345
$section->addInput(new Form_Select(
2346
	'prefix-6rd-v4plen',
2347
	'6RD IPv4 Prefix length',
2348
	$pconfig['prefix-6rd-v4plen'],
2349
	array_combine(range(0, 32), range(0, 32))
2350
))->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.');
2351

    
2352
$form->add($section);
2353

    
2354
// Track IPv6 ointerface section
2355
$section = new Form_Section('Track IPv6 Interface');
2356
$section->addClass('track6');
2357

    
2358
function build_ipv6interface_list() {
2359
	global $config, $section;
2360

    
2361
	$list = array('' => '');
2362

    
2363
	$interfaces = get_configured_interface_with_descr(false, true);
2364
	$dynv6ifs = array();
2365

    
2366
	foreach ($interfaces as $iface => $ifacename) {
2367
		switch ($config['interfaces'][$iface]['ipaddrv6']) {
2368
			case "6to4":
2369
			case "6rd":
2370
			case "dhcp6":
2371
				$dynv6ifs[$iface] = array(
2372
					'name' => $ifacename,
2373
					'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1
2374
				);
2375
				break;
2376
			default:
2377
				continue;
2378
		}
2379
	}
2380

    
2381
	foreach ($dynv6ifs as $iface => $ifacedata) {
2382
		$list[$iface] = $ifacedata['name'];
2383

    
2384
		$section->addInput(new Form_Input(
2385
			'ipv6-num-prefix-ids-' . $iface,
2386
			null,
2387
			'hidden',
2388
			$ifacedata['ipv6_num_prefix_ids']
2389
		));
2390
	}
2391

    
2392
	return($list);
2393
}
2394

    
2395
$section->addInput(new Form_Select(
2396
	'track6-interface',
2397
	'IPv6 Interface',
2398
	$pconfig['track6-interface'],
2399
	build_ipv6interface_list()
2400
))->setHelp('selects the dynamic IPv6 WAN interface to track for configuration');
2401

    
2402
if ($pconfig['track6-prefix-id'] == "") {
2403
	$pconfig['track6-prefix-id'] = 0;
2404
}
2405

    
2406
$section->addInput(new Form_Input(
2407
	'track6-prefix-id--hex' . $iface,
2408
	'IPv6 Prefix ID',
2409
	'text',
2410
	sprintf("%x", $pconfig['track6-prefix-id'])
2411
))->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.');
2412

    
2413
$section->addInput(new Form_Input(
2414
	'track6-prefix-id-max' . $iface,
2415
	null,
2416
	'hidden',
2417
	0
2418
));
2419

    
2420
$form->add($section);
2421

    
2422
/// PPP section
2423

    
2424
$section = new Form_Section('PPP Configuration');
2425
$section->addClass('ppp');
2426

    
2427
$section->addInput(new Form_Select(
2428
	'country',
2429
	'Country',
2430
	$pconfig['country'],
2431
	[]
2432
));
2433

    
2434
$section->addInput(new Form_Select(
2435
	'provider_list',
2436
	'Provider',
2437
	$pconfig['provider_list'],
2438
	[]
2439
));
2440

    
2441
$section->addInput(new Form_Select(
2442
	'providerplan',
2443
	'Plan',
2444
	$pconfig['providerplan'],
2445
	[]
2446
))->setHelp('Select to fill in data for your service provider.');
2447

    
2448
$section->addInput(new Form_Input(
2449
	'ppp_username',
2450
	'Username',
2451
	'text',
2452
	$pconfig['ppp_username']
2453
));
2454

    
2455
$section->addInput(new Form_Input(
2456
	'ppp_password',
2457
	'Password',
2458
	'password',
2459
	$pconfig['ppp_password']
2460
));
2461

    
2462
$section->addInput(new Form_Input(
2463
	'phone',
2464
	'Phone number',
2465
	'text',
2466
	$pconfig['phone']
2467
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks');
2468

    
2469
$section->addInput(new Form_Input(
2470
	'apn',
2471
	'Access Point Name',
2472
	'text',
2473
	$pconfig['apn']
2474
));
2475

    
2476

    
2477
function build_port_list() {
2478
	$list = array("" => "None");
2479

    
2480
	$portlist = glob("/dev/cua*");
2481
	$modems	  = glob("/dev/modem*");
2482
	$portlist = array_merge($portlist, $modems);
2483

    
2484
	foreach ($portlist as $port) {
2485
		if (preg_match("/\.(lock|init)$/", $port)) {
2486
			continue;
2487
		}
2488

    
2489
	$list[trim($port)] = $port;
2490
	}
2491

    
2492
	return($list);
2493
}
2494

    
2495
$section->addInput(new Form_Select(
2496
	'port',
2497
	"Modem port",
2498
	$pconfig['port'],
2499
	build_port_list()
2500
));
2501

    
2502
$section->addInput(new Form_Button(
2503
	'btnadvppp',
2504
	'Advanced PPP',
2505
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php'
2506
))->setHelp('Create a new PPP configuration');
2507

    
2508
$form->add($section);
2509

    
2510
// PPPoE configuration
2511
$section = new Form_Section('PPPoE Configuration');
2512
$section->addClass('pppoe');
2513

    
2514
$section->addInput(new Form_Input(
2515
	'pppoe_username',
2516
	'Username',
2517
	'text',
2518
	$pconfig['pppoe_username']
2519
));
2520

    
2521
$section->addInput(new Form_Input(
2522
	'pppoe_password',
2523
	'Password',
2524
	'password',
2525
	$pconfig['pppoe_password']
2526
));
2527

    
2528
$section->addInput(new Form_Input(
2529
	'provider',
2530
	'Service name',
2531
	'text',
2532
	$pconfig['provider']
2533
))->setHelp('This field can usually be left empty');
2534

    
2535
$section->addInput(new Form_Checkbox(
2536
	'pppoe_dialondemand',
2537
	'Dial on demand',
2538
	'Enable Dial-On-Demand mode ',
2539
	$pconfig['pppoe_dialondemand'],
2540
	'enable'
2541
));
2542

    
2543
$section->addInput(new Form_Input(
2544
	'pppoe_idletimeout',
2545
	'Idle timeout',
2546
	'number',
2547
	$pconfig['pppoe_idletimeout'],
2548
	[min => 0]
2549
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2550
			'An idle timeout of zero disables this feature.');
2551

    
2552
$section->addInput(new Form_Select(
2553
	'pppoe-reset-type',
2554
	'Periodic reset',
2555
	$pconfig['pppoe-reset-type'],
2556
	['' => 'Disabled', 'custom' => 'Custom', 'preset' => 'Pre-set']
2557
))->setHelp('Select a reset timing type');
2558

    
2559
$group = new Form_Group('Custom reset');
2560
$group->addClass('pppoecustom');
2561

    
2562
$group->add(new Form_Input(
2563
	'pppoe_resethour',
2564
	null,
2565
	'number',
2566
	$pconfig['pppoe_resethour'],
2567
	[min => 0, max => 23]
2568
))->setHelp('Hour (0-23)');
2569

    
2570
$group->add(new Form_Input(
2571
	'pppoe_resetminute',
2572
	null,
2573
	'number',
2574
	$pconfig['pppoe_resetminute'],
2575
	[min => 0, max => 59]
2576
))->setHelp('Minutes (0-59)');
2577

    
2578
// ToDo: Need a date-picker here
2579
$group->add(new Form_Input(
2580
	'pppoe_resetdate',
2581
	null,
2582
	'text',
2583
	$pconfig['pppoe_resetdate']
2584
))->setHelp('Specific date (mm/dd/yyyy)');
2585

    
2586
$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');
2587

    
2588
$section->add($group);
2589

    
2590
$group = new Form_MultiCheckboxGroup('cron based reset');
2591
$group->addClass('pppoepreset');
2592

    
2593
$group->add(new Form_MultiCheckbox(
2594
	'pppoe_pr_preset_val',
2595
	null,
2596
	'Reset at each month ("0 0 1 * *")',
2597
	$pconfig['pppoe_monthly'],
2598
	'monthly'
2599
))->displayAsRadio();
2600

    
2601
$group->add(new Form_MultiCheckbox(
2602
	'pppoe_pr_preset_val',
2603
	null,
2604
	'Reset at each week ("0 0 * * 0")',
2605
	$pconfig['pppoe_weekly'],
2606
	'weekly'
2607
))->displayAsRadio();
2608

    
2609
$group->add(new Form_MultiCheckbox(
2610
	'pppoe_pr_preset_val',
2611
	null,
2612
	'Reset at each day ("0 0 * * *")',
2613
	$pconfig['pppoe_daily'],
2614
	'daily'
2615
))->displayAsRadio();
2616

    
2617
$group->add(new Form_MultiCheckbox(
2618
	'pppoe_pr_preset_val',
2619
	null,
2620
	'Reset at each hour ("0 * * * *")',
2621
	$pconfig['pppoe_hourly'],
2622
	'hourly'
2623
))->displayAsRadio();
2624

    
2625
$section->add($group);
2626

    
2627
if (isset($pconfig['pppid'])) {
2628
	$section->addInput(new Form_StaticText(
2629
		'Advanced and MLPPP',
2630
		'<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>'
2631
	));
2632
} else {
2633
	$section->addInput(new Form_StaticText(
2634
		'Advanced and MLPPP',
2635
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPPoE configuration options and for MLPPP configuration.</a>'
2636
	));
2637
}
2638

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

    
2641
// PPTP & L2TP Configuration section
2642
$section = new Form_Section('PPTP/L2TP Configuration');
2643
$section->addClass('pptp');
2644

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

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

    
2659
$section->addInput(new Form_IpAddress(
2660
	'pptp_local0',
2661
	'Local IP address',
2662
	$pconfig['pptp_localip'][0]
2663
))->addMask('pptp_subnet0', $pconfig['pptp_subnet'][0]);
2664

    
2665
$section->addInput(new Form_IpAddress(
2666
	'pptp_remote0',
2667
	'Remote IP address',
2668
	$pconfig['pptp_remote'][0]
2669
));
2670

    
2671
$section->addInput(new Form_Checkbox(
2672
	'pptp_dialondemand',
2673
	'Dial on demand',
2674
	'Enable Dial-On-Demand mode ',
2675
	$pconfig['pptp_dialondemand'],
2676
	'enable'
2677
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. ' .
2678
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
2679

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

    
2689
if (isset($pconfig['pppid'])) {
2690
	if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
2691
		$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
2692
	} else {
2693
		$mlppp_text = "";
2694
	}
2695

    
2696
	$section->addInput(new Form_StaticText(
2697
		'Advanced and MLPPP',
2698
		$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>'
2699
	));
2700
} else {
2701
	$section->addInput(new Form_StaticText(
2702
		'Advanced and MLPPP',
2703
		'<a href="/interfaces_ppps_edit.php" class="navlnk">Click here for additional PPTP and L2TP configuration options.</a>'
2704
	));
2705
}
2706

    
2707
$form->add($section);
2708

    
2709
// Wireless interface
2710
if (isset($wancfg['wireless'])) {
2711

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

    
2714
	$section->addInput(new Form_Checkbox(
2715
		'persistcommonwireless',
2716
		'Persist common settings',
2717
		'Preserve common wireless configuration through interface deletions and reassignments.',
2718
		$pconfig['persistcommonwireless'],
2719
		'yes'
2720
	));
2721

    
2722
	$mode_list = ['auto' => 'Auto'];
2723

    
2724
	if (is_array($wl_modes)) {
2725
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2726
			$mode_list[$wl_standard] = '802.' . $wl_standard;
2727
		}
2728
	}
2729

    
2730
	if (count($mode_list) == 1) {
2731
		$mode_list[''] = '';
2732
	}
2733

    
2734
	$section->addInput(new Form_Select(
2735
		'standard',
2736
		'Standard',
2737
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
2738
		$mode_list
2739
	));
2740

    
2741
	if (isset($wl_modes['11g'])) {
2742
		$section->addInput(new Form_Select(
2743
			'protmode',
2744
			'802.11g OFDM Protection Mode',
2745
			$pconfig['protmode'],
2746
			['off' => 'Off', 'cts' => 'CTS to self', 'rtscts' => 'RTS and CTS']
2747
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
2748
	} else {
2749
		$section->addInput(new Form_Input(
2750
			'protmode',
2751
			null,
2752
			'hidden',
2753
			'off'
2754
		));
2755
	}
2756

    
2757
	$mode_list = ['0' => 'Auto'];
2758

    
2759
	if (is_array($wl_modes)) {
2760
		foreach ($wl_modes as $wl_standard => $wl_channels) {
2761
			if ($wl_standard == "11g") {
2762
				$wl_standard = "11b/g";
2763
			} else if ($wl_standard == "11ng") {
2764
				$wl_standard = "11b/g/n";
2765
			} else if ($wl_standard == "11na") {
2766
				$wl_standard = "11a/n";
2767
			}
2768

    
2769
			foreach ($wl_channels as $wl_channel) {
2770
				if (isset($wl_chaninfo[$wl_channel])) {
2771
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel;
2772
				} else {
2773
					$mode_list[ $wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
2774
				}
2775
			}
2776
		}
2777
	}
2778

    
2779
	$section->addInput(new Form_Select(
2780
		'channel',
2781
		'Channel',
2782
		$pconfig['channel'],
2783
		$mode_list
2784
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)' . '<br />' .
2785
				'Not all channels may be supported by your card.  Auto may override the wireless standard selected above.');
2786

    
2787
	if (ANTENNAS) {
2788
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2789
			$group = new Form_Group('Antenna Settings');
2790

    
2791
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
2792
				$group->add(new Form_Select(
2793
					'diversity',
2794
					null,
2795
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
2796
					['' => 'Default', '0' => 'Off', '1' => 'On']
2797
				))->setHelp('Diversity');
2798
			}
2799

    
2800
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
2801
				$group->add(new Form_Select(
2802
					'txantenna',
2803
					null,
2804
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
2805
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2806
				))->setHelp('Transmit antenna');
2807
			}
2808

    
2809
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
2810
				$group->add(new Form_Select(
2811
					'rxantenna',
2812
					null,
2813
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
2814
					['' => 'Default', '0' => 'Auto', '1' => '#1', '2' => '#2']
2815
				))->setHelp('Receive antenna');
2816
			}
2817

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

    
2820
			$section->add($group);
2821
		}
2822
	}
2823

    
2824
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
2825
			$section->addInput(new Form_Input(
2826
				'distance',
2827
				'Distance setting (meters)',
2828
				'test',
2829
				$pconfig['distance']
2830
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
2831
	}
2832

    
2833
	$form->add($section);
2834

    
2835
	// Regulatory settings
2836
	$section = new Form_Section('Regulatory settings');
2837

    
2838
	$domain_list = array("" => 'Default');
2839

    
2840
	if (is_array($wl_regdomains)) {
2841
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2842
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
2843
		}
2844
	}
2845

    
2846
	$section->addInput(new Form_Select(
2847
		'regdomain',
2848
		'Regulatory domain',
2849
		$pconfig['regdomain'],
2850
		$domain_list
2851
	))->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');
2852

    
2853
	$country_list = array('' => 'Default');
2854

    
2855
	if (is_array($wl_countries)) {
2856
		foreach ($wl_countries as $wl_country_key => $wl_country) {
2857
			$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']);
2858
		}
2859
	}
2860

    
2861
	$section->addInput(new Form_Select(
2862
		'regcountry',
2863
		'Country',
2864
		$pconfig['regcountry'],
2865
		$country_list
2866
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
2867

    
2868
	$section->addInput(new Form_Select(
2869
		'reglocation',
2870
		'Location',
2871
		$pconfig['reglocation'],
2872
		['' => 'Default', 'indoor' => 'Indoor', 'outdoor' => 'Outdoor', 'anywhere' => 'Anywhere']
2873
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
2874
				'Using the correct settings to comply with local regulatory requirements is recommended.' . '<br />' .
2875
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
2876
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
2877
				'These settings may not be able to add additional channels that are not already supported.');
2878

    
2879
	$form->add($section);
2880

    
2881
	$section = new Form_Section('Network-specific wireless configuration');
2882

    
2883
	$section->addInput(new Form_Select(
2884
		'mode',
2885
		'Mode',
2886
		$pconfig['mode'],
2887
		['bss' => 'Infrastructure (BSS)', 'adhoc' => 'Ad-hoc (IBSS)', 'hostap' => 'Access Point']
2888
	));
2889

    
2890
	$section->addInput(new Form_Input(
2891
		'ssid',
2892
		'SSID',
2893
		'text',
2894
		$pconfig['ssid']
2895
	));
2896

    
2897
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
2898
		$section->addInput(new Form_Select(
2899
			'puremode',
2900
			'Minimum wireless standard',
2901
			$pconfig['puremode'],
2902
			['any' => 'Any', '11g' => '802.11g', '11n' => '802.11n']
2903
		))->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)');
2904
	} elseif (isset($wl_modes['11g'])) {
2905
		$section->addInput(new Form_Checkbox(
2906
			'puremode',
2907
			'802.11g only',
2908
			null,
2909
			$pconfig['puremode'],
2910
			'11g'
2911
		))->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)');
2912
	}
2913

    
2914
	$section->addInput(new Form_Checkbox(
2915
		'apbridge_enable',
2916
		'Allow intra-BSS communication',
2917
		'Allow packets to pass between wireless clients directly when operating as an access point',
2918
		$pconfig['apbridge_enable'],
2919
		'yes'
2920
	))->setHelp('Disabling the internal bridging is useful when traffic is to be processed with packet filtering');
2921

    
2922
	$section->addInput(new Form_Checkbox(
2923
		'wme_enable',
2924
		'Enable WME',
2925
		'Force the card to use WME (wireless QoS)',
2926
		$pconfig['wme_enable'],
2927
		'yes'
2928
	));
2929

    
2930
	$section->addInput(new Form_Checkbox(
2931
		'hidessid_enable',
2932
		'Hide SSID',
2933
		'Force the card to NOT broadcast its SSID (This may cause problems for some clients)',
2934
		$pconfig['hidessid_enable'],
2935
		'yes'
2936
	));
2937

    
2938
	$form->add($section);
2939

    
2940
	// WPA Section
2941
	$section = new Form_Section('WPA');
2942

    
2943
	$section->addInput(new Form_Checkbox(
2944
		'wpa_enable',
2945
		'Enable',
2946
		'Enable WPA',
2947
		$pconfig['wpa_enable'],
2948
		'yes'
2949
	));
2950

    
2951
	$section->addInput(new Form_Input(
2952
		'passphrase',
2953
		'WPA Pre-Shared Key',
2954
		'text',
2955
		$pconfig['passphrase']
2956
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
2957

    
2958
	$section->addInput(new Form_Select(
2959
		'wpa_mode',
2960
		'WPA mode',
2961
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
2962
		['1' => 'WPA', '2' => 'WPA2', '3' => 'Both']
2963
	));
2964

    
2965
	$section->addInput(new Form_Select(
2966
		'wpa_key_mgmt',
2967
		'WPA Key Management Mode',
2968
		$pconfig['wpa_key_mgmt'],
2969
		['WPA-PSK' => 'Pre-Shared Key', 'WPA-EAP' => 'Extensible Authentication Protocol', 'WPA-PSK WPA-EAP' => 'Both']
2970
	));
2971

    
2972
	$section->addInput(new Form_Select(
2973
		'wpa_pairwise',
2974
		'WPA Pairwise',
2975
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
2976
		['CCMP TKIP' => 'Both', 'CCMP' => 'AES (recommended)', 'TKIP' => 'TKIP']
2977
	));
2978

    
2979
	$section->addInput(new Form_Input(
2980
		'wpa_group_rekey',
2981
		'WPA Pre-Shared Key',
2982
		'number',
2983
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
2984
		['min' => '1', 'max' => 9999]
2985
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
2986

    
2987
	$section->addInput(new Form_Input(
2988
		'wpa_gmk_rekey',
2989
		'Master Key Regeneration',
2990
		'number',
2991
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
2992
		['min' => '1', 'max' => 9999]
2993
	))->setHelp('Specified in seconds. Allowed values are 1-9999. Must be longer than Key Rotation time');
2994

    
2995
	$section->addInput(new Form_Checkbox(
2996
		'wpa_strict_rekey',
2997
		'Strict Key Regeneration',
2998
		'Force the AP to rekey whenever a client disassociates',
2999
		$pconfig['wpa_strict_rekey'],
3000
		'yes'
3001
	));
3002

    
3003
	$form->add($section);
3004

    
3005
	$section = new Form_Section('802.1x RADIUS options');
3006

    
3007
	$section->addInput(new Form_Checkbox(
3008
		'ieee8021x',
3009
		'IEEE802.1X',
3010
		'Enable 802.1X authentication',
3011
		$pconfig['ieee8021x'],
3012
		'yes'
3013
	))->setHelp('This option requires that the "Enable WPA box" is checked');
3014

    
3015
	$group = new Form_Group('Primary 802.1X server');
3016

    
3017
	$group->add(new Form_IpAddress(
3018
		'auth_server_addr',
3019
		'IP Address',
3020
		$pconfig['auth_server_addr']
3021
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3022

    
3023
	$group->add(new Form_Input(
3024
		'auth_server_port',
3025
		'Port',
3026
		'number',
3027
		$pconfig['auth_server_port']
3028
	))->setHelp('Server port. Leave blank for the default port 1812');
3029

    
3030
	$group->add(new Form_Input(
3031
		'auth_server_shared_secret',
3032
		'Shared secret',
3033
		'number',
3034
		$pconfig['auth_server_shared_secret']
3035
	))->setHelp('Shared secret');
3036

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

    
3039
	$group = new Form_Group('Secondary 802.1X server');
3040

    
3041
	$group->add(new Form_IpAddress(
3042
		'auth_server_addr2',
3043
		'IP Address',
3044
		$pconfig['auth_server_addr2']
3045
	))->setHelp('IP address.  (Commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)');
3046

    
3047
	$group->add(new Form_Input(
3048
		'auth_server_port2',
3049
		'Port',
3050
		'number',
3051
		$pconfig['auth_server_port2']
3052
	))->setHelp('Server port. Leave blank for the default port 1812');
3053

    
3054
	$group->add(new Form_Input(
3055
		'auth_server_shared_secret2',
3056
		'Shared secret',
3057
		'number',
3058
		$pconfig['auth_server_shared_secret2']
3059
	))->setHelp('Shared secret');
3060

    
3061
	$section->add($group);
3062

    
3063
	$section->addInput(new Form_Checkbox(
3064
		'rsn_preauth',
3065
		'Authentication Roaming Preauth',
3066
		null,
3067
		$pconfig['rsn_preauth'],
3068
		'yes'
3069
	));
3070

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

    
3074
$section = new Form_Section('Private networks');
3075

    
3076
$section->addInput(new Form_Checkbox(
3077
	'blockpriv',
3078
	'Block private networks',
3079
	'',
3080
	$pconfig['blockpriv'],
3081
	'yes'
3082
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3083
			' as well as loopback addresses (127/8). You should generally leave this option turned on, unless your WAN network ' .
3084
			'lies in such a private address space, too.');
3085

    
3086
$section->addInput(new Form_Checkbox(
3087
	'blockbogons',
3088
	'Block bogon networks',
3089
	'',
3090
	$pconfig['blockbogons'],
3091
	'yes'
3092
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3093
			'never appear in the Internet routing table, and so should not appear as the source address in any packets you receive.' . '<br />' .
3094
			'Note: The update frequency can be changed under System->Advanced Firewall/NAT settings');
3095

    
3096
$form->add($section);
3097

    
3098
$form->addGlobal(new Form_Input(
3099
	'if',
3100
	null,
3101
	'hidden',
3102
	$if
3103
));
3104

    
3105
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3106
	$form->addGlobal(new Form_Input(
3107
		'ppp_port',
3108
		null,
3109
		'hidden',
3110
		$pconfig['port']
3111
	));
3112
}
3113

    
3114
$form->addGlobal(new Form_Input(
3115
	'ptpid',
3116
	null,
3117
	'hidden',
3118
	$pconfig['ptpid']
3119
));
3120

    
3121

    
3122
// Add new gateway modal pop-up
3123
$modal = new Modal('New gateway', 'newgateway', 'large');
3124

    
3125
$modal->addInput(new Form_Checkbox(
3126
	'defaultgw',
3127
	'Default',
3128
	'Default gateway',
3129
	($if == "wan" || $if == "WAN")
3130
));
3131

    
3132
$modal->addInput(new Form_Input(
3133
	'name',
3134
	'Gateway name',
3135
	'text',
3136
	$wancfg['descr'] . "GW"
3137
));
3138

    
3139
$modal->addInput(new Form_IpAddress(
3140
	'gatewayip',
3141
	'Gateway IPv4',
3142
	null
3143
));
3144

    
3145
$modal->addInput(new Form_Input(
3146
	'gatewaydescr',
3147
	'Description',
3148
	'text'
3149
));
3150

    
3151
$btnaddgw = new Form_Button(
3152
	'add',
3153
	'Add'
3154
);
3155

    
3156
$btnaddgw->removeClass('btn-primary')->addClass('btn-success');
3157

    
3158
$btncnxgw = new Form_Button(
3159
	'cnx',
3160
	'Cancel'
3161
);
3162

    
3163
$btncnxgw->removeClass('btn-primary')->addClass('btn-default');
3164

    
3165
$modal->addInput(new Form_StaticText(
3166
	null,
3167
	$btnaddgw . $btncnxgw
3168
));
3169

    
3170
$form->add($modal);
3171

    
3172
print($form);
3173
?>
3174

    
3175
<script type="text/javascript">
3176
//<![CDATA[
3177
events.push(function() {
3178
	function updateType(t) {
3179

    
3180
		switch (t) {
3181
			case "none": {
3182
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3183
				break;
3184
			}
3185
			case "staticv4": {
3186
				$('.dhcpadvanced, .none, .dhcp').hide();
3187
				$('.pppoe, .pptp, .ppp').hide();
3188
				break;
3189
			}
3190
			case "dhcp": {
3191
				$('.dhcpadvanced, .none').hide();
3192
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3193
										//			about the staticv4 class
3194
				$('.pppoe, .pptp, .ppp').hide();
3195
				break;
3196
			}
3197
			case "ppp": {
3198
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3199
				country_list();
3200
				break;
3201
			}
3202
			case "pppoe": {
3203
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3204
				break;
3205
			}
3206
			case "l2tp":
3207
			case "pptp": {
3208
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3209
				$('.pptp').show();
3210
				break;
3211
			}
3212
		}
3213

    
3214
		if (t != "l2tp" && t != "pptp") {
3215
			$('.'+t).show();
3216
		}
3217
	}
3218

    
3219
	function updateTypeSix(t) {
3220
		if (!isNaN(t[0])) {
3221
			t = '_' + t;
3222
		}
3223

    
3224
		switch (t) {
3225
			case "none": {
3226
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3227
				break;
3228
			}
3229
			case "staticv6": {
3230
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3231
				break;
3232
			}
3233
			case "slaac": {
3234
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3235
				break;
3236
			}
3237
			case "dhcp6": {
3238
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3239
				break;
3240
			}
3241
			case "6rd_": {
3242
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3243
				break;
3244
			}
3245
			case "_6to4": {
3246
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3247
				break;
3248
			}
3249
			case "track6": {
3250
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3251
				update_track6_prefix();
3252
				break;
3253
			}
3254
		}
3255

    
3256
		if (t != "l2tp" && t != "pptp") {
3257
			$('.'+t).show();
3258
		}
3259
	}
3260

    
3261
	function show_reset_settings(reset_type) {
3262
		if (reset_type == 'preset') {
3263
			$('.pppoepreset').show();
3264
			$('.pppoecustom').hide();
3265
		} else if (reset_type == 'custom') {
3266
			$('.pppoecustom').show();
3267
			$('.pppoepreset').hide();
3268
		} else {
3269
			$('.pppoecustom').hide();
3270
			$('.pppoepreset').hide();
3271
		}
3272
	}
3273

    
3274
	function update_track6_prefix() {
3275
		var iface = $("#track6-interface").val();
3276
		if (iface == null) {
3277
			return;
3278
		}
3279

    
3280
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3281
		if (track6_prefix_ids == null) {
3282
			return;
3283
		}
3284

    
3285
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3286
		$('#track6-prefix-id-range').html('(<b>hexadecimal</b> from 0 to ' + track6_prefix_ids + ')');
3287
	}
3288

    
3289
	// Create the new gateway from the data entered in the modal pop-up
3290
	function hide_add_gatewaysave() {
3291
		var iface = $('#if').val();
3292
		name = $('#name').val();
3293
		var descr = $('#gatewaydescr').val();
3294
		gatewayip = $('#gatewayip').val();
3295

    
3296
		var defaultgw = '';
3297
		if ($('#defaultgw').is(':checked')) {
3298
			defaultgw = '&defaultgw=on';
3299
		}
3300

    
3301
		var url = "system_gateways_edit.php";
3302
		var pars = 'isAjax=true&ipprotocol=inet' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3303
		$.ajax(
3304
			url,
3305
			{
3306
				type: 'post',
3307
				data: pars,
3308
				error: report_failure,
3309
				complete: save_callback
3310
			});
3311
		}
3312

    
3313
	function save_callback(response) {
3314
		if (response) {
3315
			var gwtext = escape(name) + " - " + gatewayip;
3316
			addOption($('#gateway'), gwtext, name);
3317
		} else {
3318
			report_failure();
3319
		}
3320

    
3321
		$("#newgateway").modal('hide');
3322
	}
3323

    
3324
	function report_failure(request, textStatus, errorThrown) {
3325
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3326
			alert(request.responseText);
3327
		} else {
3328
			alert("Sorry, we could not create your IPv4 gateway at this time.");
3329
		}
3330

    
3331
		$("#newgateway").modal('hide');
3332
	}
3333

    
3334
	function addOption(selectbox, text, value) {
3335
		var optn = document.createElement("OPTION");
3336
		optn.text = text;
3337
		optn.value = value;
3338
		selectbox.append(optn);
3339
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3340
	}
3341

    
3342
	function hide_add_gatewaysave_v6() {
3343

    
3344
		var iface = $('#if').val();
3345
		name = $('#name6').val();
3346
		var descr = $('#gatewaydescr6').val();
3347
		gatewayip = $('#gatewayip6').val();
3348
		var defaultgw = '';
3349
		if ($('#defaultgw6').is(':checked')) {
3350
			defaultgw = '&defaultgw=on';
3351
		}
3352
		var url_v6 = "system_gateways_edit.php";
3353
		var pars_v6 = 'isAjax=true&ipprotocol=inet6' + defaultgw + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
3354
		$.ajax(
3355
			url_v6,
3356
			{
3357
				type: 'post',
3358
				data: pars_v6,
3359
				error: report_failure_v6,
3360
				success: save_callback_v6
3361
			});
3362
	}
3363

    
3364

    
3365
	function addOption_v6(selectbox, text, value) {
3366
		var optn = document.createElement("OPTION");
3367
		optn.text = text;
3368
		optn.value = value;
3369
		selectbox.append(optn);
3370
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3371
	}
3372

    
3373
	function report_failure_v6(request, textStatus, errorThrown) {
3374
		if (textStatus === "error" && request.getResponseHeader("Content-Type") === "text/plain") {
3375
			alert(request.responseText);
3376
		} else {
3377
			alert("Sorry, we could not create your IPv6 gateway at this time.");
3378
		}
3379

    
3380
		$("#newgateway6").modal('hide');
3381
	}
3382

    
3383
	function save_callback_v6(response_v6) {
3384
		if (response_v6) {
3385

    
3386
			var gwtext_v6 = escape(name) + " - " + gatewayip;
3387
			addOption_v6($('#gatewayv6'), gwtext_v6, name);
3388
		} else {
3389
			report_failure_v6();
3390
		}
3391

    
3392
		$("#newgateway6").modal('hide');
3393
	}
3394

    
3395
	function country_list() {
3396
		$('#country').children().remove();
3397
		$('#provider_list').children().remove();
3398
		$('#providerplan').children().remove();
3399
		$.ajax("getserviceproviders.php",{
3400
			success: function(response) {
3401

    
3402
				var responseTextArr = response.split("\n");
3403
				responseTextArr.sort();
3404

    
3405
				responseTextArr.forEach( function(value) {
3406
					country = value.split(":");
3407
					$('#country').append($('<option>', {
3408
						value: country[1],
3409
						text : country[0]
3410
					}));
3411
				});
3412
			}
3413
		});
3414
	}
3415

    
3416
	function providers_list() {
3417
		$('#provider_list').children().remove();
3418
		$('#providerplan').children().remove();
3419
		$.ajax("getserviceproviders.php",{
3420
			type: 'post',
3421
			data: {country : $('#country').val()},
3422
			success: function(response) {
3423
				var responseTextArr = response.split("\n");
3424
				responseTextArr.sort();
3425
				responseTextArr.forEach( function(value) {
3426
					$('#provider_list').append($('<option>', {
3427
							value: value,
3428
							text : value
3429
					}));
3430
				});
3431
			}
3432
		});
3433
	}
3434

    
3435
	function providerplan_list() {
3436
		$('#providerplan').children().remove();
3437
		$.ajax("getserviceproviders.php",{
3438
			type: 'post',
3439
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3440
			success: function(response) {
3441
				var responseTextArr = response.split("\n");
3442
				responseTextArr.sort();
3443

    
3444
				$('#providerplan').append($('<option>', {
3445
					value: '',
3446
					text : ''
3447
				}));
3448

    
3449
				responseTextArr.forEach( function(value) {
3450
					if (value != "") {
3451
						providerplan = value.split(":");
3452

    
3453
						$('#providerplan').append($('<option>', {
3454
							value: providerplan[1],
3455
							text : providerplan[0] + " - " + providerplan[1]
3456
						}));
3457
					}
3458
				});
3459
			}
3460
		});
3461
	}
3462

    
3463
	function prefill_provider() {
3464
		$.ajax("getserviceproviders.php",{
3465
			type: 'post',
3466
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3467
			success: function(data, textStatus, response) {
3468
				var xmldoc = response.responseXML;
3469
				var provider = xmldoc.getElementsByTagName('connection')[0];
3470
				$('#ppp_username').val('');
3471
				$('#ppp_password').val('');
3472
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3473
					$('#phone').val('#777');
3474
					$('#apn').val('');
3475
				} else {
3476
					$('#phone').val('*99#');
3477
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3478
				}
3479
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3480
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3481
				$('#ppp_username').val(ppp_username);
3482
				$('#ppp_password').val(ppp_password);
3483
			}
3484
		});
3485
	}
3486

    
3487
	function show_dhcp6adv() {
3488
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3489
		var adv = $('#dhcp6adv').prop('checked');
3490

    
3491
		hideCheckbox('dhcp6usev4iface', ovr);
3492
		hideCheckbox('dhcp6prefixonly', ovr);
3493
		hideInput('dhcp6-ia-pd-len', ovr);
3494
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3495
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3496

    
3497
		hideClass('dhcp6advanced', !adv || ovr);
3498
	}
3499

    
3500
	function setDHCPoptions() {
3501
		var adv = $('#dhcpadv').prop('checked');
3502
		var ovr = $('#dhcpovr').prop('checked');
3503

    
3504
		if (ovr) {
3505
			hideInput('dhcphostname', true);
3506
			hideIpAddress('alias-address', true);
3507
			hideInput('dhcprejectfrom', true);
3508
			hideInput('adv_dhcp_config_file_override_path', false);
3509
			hideClass('dhcpadvanced', true);
3510
		} else {
3511
			hideInput('dhcphostname', false);
3512
			hideIpAddress('alias-address', false);
3513
			hideInput('dhcprejectfrom', false);
3514
			hideInput('adv_dhcp_config_file_override_path', true);
3515
			hideClass('dhcpadvanced', !adv);
3516
		}
3517
	}
3518

    
3519
	// DHCP preset actions
3520
	// Set presets from value of radio buttons
3521
	function setPresets(val) {
3522
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3523
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3524
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3525
		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']);?>");
3526
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3527
	}
3528

    
3529
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3530
		$('#adv_dhcp_pt_timeout').val(timeout);
3531
		$('#adv_dhcp_pt_retry').val(retry);
3532
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3533
		$('#adv_dhcp_pt_reboot').val(reboot);
3534
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3535
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3536
	}
3537

    
3538
	// ---------- On initial page load ------------------------------------------------------------
3539

    
3540
	updateType($('#type').val());
3541
	updateTypeSix($('#type6').val());
3542
	show_reset_settings($('#pppoe-reset-type').val());
3543
	$("#add").prop('type', 'button');
3544
	$("#cnx").prop('type', 'button');
3545
	$("#addgw").prop('type', 'button');
3546
	$("#add6").prop('type', 'button');
3547
	$("#cnx6").prop('type', 'button');
3548
	$("#addgw6").prop('type', 'button');
3549
	hideClass('dhcp6advanced', true);
3550
	hideClass('dhcpadvanced', true);
3551
	show_dhcp6adv();
3552
	setDHCPoptions()
3553

    
3554
	// Set preset buttons on page load
3555
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
3556
	if (sv == "") {
3557
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
3558
	} else {
3559
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
3560
	}
3561

    
3562
	// Set preset from value
3563
	setPresets(sv);
3564

    
3565
	// ---------- Click checkbox handlers ---------------------------------------------------------
3566

    
3567
	$('#type').on('change', function() {
3568
		updateType(this.value);
3569
	});
3570

    
3571
	$('#type6').on('change', function() {
3572
		updateTypeSix(this.value);
3573
	});
3574

    
3575
	$('#pppoe-reset-type').on('change', function() {
3576
		show_reset_settings(this.value);
3577
	});
3578

    
3579
	$("#add").click(function() {
3580
		hide_add_gatewaysave();
3581
	});
3582

    
3583
	$("#cnx").click(function() {
3584
		$("#newgateway").modal('hide');
3585
	});
3586

    
3587
	$("#add6").click(function() {
3588
		hide_add_gatewaysave_v6();
3589
	});
3590

    
3591
	$("#cnx6").click(function() {
3592
		$("#newgateway6").modal('hide');
3593
	});
3594

    
3595
	$('#country').on('change', function() {
3596
		providers_list();
3597
	});
3598

    
3599
	$('#provider_list').on('change', function() {
3600
		providerplan_list();
3601
	});
3602

    
3603
	$('#providerplan').on('change', function() {
3604
		prefill_provider();
3605
	});
3606

    
3607
	$('#dhcpadv, #dhcpovr').click(function () {
3608
		setDHCPoptions();
3609
	});
3610

    
3611
	$('#dhcp6adv').click(function () {
3612
		show_dhcp6adv();
3613
	});
3614

    
3615
	$('#adv_dhcp6_config_file_override').click(function () {
3616
		show_dhcp6adv();
3617
	});
3618

    
3619
	// On click . .
3620
	$('[name=adv_dhcp_pt_values]').click(function () {
3621
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
3622
	});
3623

    
3624
});
3625
//]]>
3626
</script>
3627

    
3628
<?php include("foot.inc");
(69-69/228)