Project

General

Profile

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

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

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

    
77
define("ANTENNAS", false);
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
283
switch ($wancfg['ipaddr']) {
284
	case "dhcp":
285
		$pconfig['type'] = "dhcp";
286
		break;
287
	case "pppoe":
288
	case "pptp":
289
	case "l2tp":
290
	case "ppp":
291
		$pconfig['type'] = $wancfg['ipaddr'];
292
		break;
293
	default:
294
		if (is_ipaddrv4($wancfg['ipaddr'])) {
295
			$pconfig['type'] = "staticv4";
296
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
297
			$pconfig['subnet'] = $wancfg['subnet'];
298
			$pconfig['gateway'] = $wancfg['gateway'];
299
		} else {
300
			$pconfig['type'] = "none";
301
		}
302
		break;
303
}
304

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

    
355
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
356
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
357
$pconfig['spoofmac'] = $wancfg['spoofmac'];
358
$pconfig['mtu'] = $wancfg['mtu'];
359
$pconfig['mss'] = $wancfg['mss'];
360

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

    
437
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
438

    
439
}
440

    
441
if ($_POST['apply']) {
442
	unset($input_errors);
443
	if (!is_subsystem_dirty('interfaces')) {
444
		$input_errors[] = gettext("You have already applied your settings!");
445
	} else {
446
		unlink_if_exists("{$g['tmp_path']}/config.cache");
447
		clear_subsystem_dirty('interfaces');
448

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

    
467
		/* sync filter configuration */
468
		setup_gateways_monitor();
469

    
470
		clear_subsystem_dirty('interfaces');
471

    
472
		filter_configure();
473

    
474
		enable_rrd_graphing();
475

    
476
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
477
			clear_subsystem_dirty('staticroutes');
478
		}
479
	}
480
	@unlink("{$g['tmp_path']}/.interfaces.apply");
481
	header("Location: interfaces.php?if={$if}");
482
	exit;
483
} else if ($_POST) {
484

    
485
	unset($input_errors);
486
	$pconfig = $_POST;
487

    
488
	if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) {
489
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
490
	} else {
491
		$pconfig['track6-prefix-id'] = 0;
492
	}
493
	conf_mount_rw();
494

    
495
	/* filter out spaces from descriptions */
496
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
497

    
498
	/* okay first of all, cause we are just hiding the PPPoE HTML
499
	 * fields related to PPPoE resets, we are going to unset $_POST
500
	 * vars, if the reset feature should not be used. Otherwise the
501
	 * data validation procedure below, may trigger a false error
502
	 * message.
503
	 */
504
	if (empty($_POST['pppoe-reset-type'])) {
505
		unset($_POST['pppoe_pr_type']);
506
		unset($_POST['pppoe_resethour']);
507
		unset($_POST['pppoe_resetminute']);
508
		unset($_POST['pppoe_resetdate']);
509
		unset($_POST['pppoe_pr_preset_val']);
510
	}
511
	/* description unique? */
512
	foreach ($ifdescrs as $ifent => $ifdescr) {
513
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
514
			$input_errors[] = gettext("An interface with the specified description already exists.");
515
			break;
516
		}
517
	}
518

    
519
	/* Is the description already used as an alias name? */
520
	if (is_array($config['aliases']['alias'])) {
521
		foreach ($config['aliases']['alias'] as $alias) {
522
			if ($alias['name'] == $_POST['descr']) {
523
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
524
			}
525
		}
526
	}
527

    
528
	/* Is the description already used as an interface group name? */
529
	if (is_array($config['ifgroups']['ifgroupentry'])) {
530
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
531
			if ($ifgroupentry['ifname'] == $_POST['descr']) {
532
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $wancfg['descr']);
533
			}
534
		}
535
	}
536

    
537
	if (is_numeric($_POST['descr'])) {
538
		$input_errors[] = gettext("The interface description cannot contain only numbers.");
539
	}
540
	/* input validation */
541
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (!preg_match("/^staticv4/", $_POST['type']))) {
542
		$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.");
543
	}
544
	if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (!preg_match("/^staticv6/", $_POST['type6']))) {
545
		$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.");
546
	}
547

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

    
655
			if (empty($_POST['track6-interface'])) {
656
				$input_errors[] = gettext("You have to select a valid interface to track.");
657
			}
658

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

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

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

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

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

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

    
822
		unset($min_mtu, $max_mtu);
823

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1412
		conf_mount_ro();
1413
		write_config();
1414

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

    
1424
		mark_subsystem_dirty('interfaces');
1425

    
1426
		/* regenerate cron settings/crontab file */
1427
		configure_cron();
1428

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

    
1433
} // end if ($_POST)
1434

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

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

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

    
1584
	interface_sync_wireless_clones($wancfg, true);
1585
}
1586

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

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

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

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

    
1608
	if ($clone_count > 1) {
1609
		$old_wireless_mode = $wancfg['wireless']['mode'];
1610
		$wancfg['wireless']['mode'] = $_POST['mode'];
1611
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1612
			$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']]);
1613
		} else {
1614
			mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy");
1615
		}
1616
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1617
	}
1618
}
1619

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

    
1635
$pgtitle = array(gettext("Interfaces"), $wancfg['descr']);
1636
$shortcut_section = "interfaces";
1637

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

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

    
1646
function build_mediaopts_list() {
1647
	global $mediaopts_list;
1648

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

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

    
1657
	return($list);
1658
}
1659

    
1660
function build_gateway_list() {
1661
	global $a_gateways, $if;
1662

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

    
1670
	return($list);
1671
}
1672

    
1673
function build_gatewayv6_list() {
1674
	global $a_gateways, $if;
1675

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

    
1683
	return($list);
1684
}
1685

    
1686
include("head.inc");
1687

    
1688
if ($input_errors) {
1689
	print_input_errors($input_errors);
1690
}
1691

    
1692
if (is_subsystem_dirty('interfaces')) {
1693
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1694
					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."));
1695
}
1696

    
1697
if ($savemsg) {
1698
	print_info_box($savemsg, 'success');
1699
}
1700

    
1701

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

    
1707
$section = new Form_Section('General configuration');
1708

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

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

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

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

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

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

    
1751
$btnmymac->removeClass('btn-primary')->addClass('btn-success btn-sm');
1752

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

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

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

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

    
1786
$form->add($section);
1787

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

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

    
1797
$group = new Form_Group('IPv4 Upstream gateway');
1798

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

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

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

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

    
1817
$form->add($section);
1818

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

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

    
1828
$group = new Form_Group('IPv6 Upstream gateway');
1829

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

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

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

    
1845
$section->add($group);
1846
$form->add($section);
1847

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

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

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

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

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

    
1877
$btnaddgw6 = new Form_Button(
1878
	'add6',
1879
	'Add'
1880
);
1881

    
1882
$btnaddgw6->removeClass('btn-primary')->addClass('btn-success');
1883

    
1884
$btncnxgw6 = new Form_Button(
1885
	'cnx6',
1886
	'Cancel'
1887
);
1888

    
1889
$btncnxgw6->removeClass('btn-primary')->addClass('btn-default');
1890

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

    
1896
$form->add($modal);
1897

    
1898
// ==== DHCP client configuration =============================
1899

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

    
1903
$group = new Form_Group('Options');
1904

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

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

    
1919
$section->add($group);
1920

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

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

    
1934
$section->addInput(new Form_Input(
1935
	'dhcprejectfrom',
1936
	'Reject leases from',
1937
	'text',
1938
	$pconfig['dhcprejectfrom']
1939
))->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. ' .
1940
			'This is useful for rejecting leases from cable modems that offer private IPs when they lose upstream sync.');
1941

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

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

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

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

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

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

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

    
1988
$section->add($group);
1989

    
1990
$group = new Form_Group('Presets');
1991
$group->addClass('dhcpadvanced');
1992

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

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

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

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

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

    
2028
$section->add($group);
2029

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

    
2040
$form->add($section);
2041

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

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

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

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

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

    
2078
$form->add($section);
2079

    
2080
// DHCP6 client config
2081

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

    
2085
$section->addInput(new Form_Checkbox(
2086
	'adv_dhcp6_config_advanced',
2087
	'Advanced',
2088
	'Show DHCPv6 advanced options',
2089
	$pconfig['adv_dhcp6_config_advanced'],
2090
	'Selected'
2091
));
2092

    
2093
$section->addInput(new Form_Checkbox(
2094
	'adv_dhcp6_config_file_override',
2095
	'Config file override',
2096
	'Override the configuration from this file',
2097
	$pconfig['adv_dhcp6_config_file_override'],
2098
	'Selected'
2099
));
2100

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

    
2108
$section->addInput(new Form_Checkbox(
2109
	'dhcp6prefixonly',
2110
	'Request only an IPv6 prefix',
2111
	'Only request an IPv6 prefix, do not request an IPv6 address',
2112
	$pconfig['dhcp6prefixonly']
2113
));
2114

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

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

    
2129
$section->addInput(new Form_Checkbox(
2130
	'dhcp6debug',
2131
	'Debug',
2132
	'Start DHCP6 client in debug mode',
2133
	$pconfig['dhcp6debug']
2134
));
2135

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

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

    
2148
// DHCP6 client config - Advanced
2149

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2425
	return($list);
2426
}
2427

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

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

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

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

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

    
2455
/// PPP section
2456

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

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

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

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

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

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

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

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

    
2509

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

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

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

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

    
2525
	return($list);
2526
}
2527

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2790
	$mode_list = ['0' => gettext('Auto')];
2791

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3154

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

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

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

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

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

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

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

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

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

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

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

    
3205
print($form);
3206
?>
3207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3375
	function hide_add_gatewaysave_v6() {
3376

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

    
3397

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3571
	// ---------- On initial page load ------------------------------------------------------------
3572

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

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

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

    
3598
	// ---------- Click checkbox handlers ---------------------------------------------------------
3599

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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