Project

General

Profile

Download (141 KB) Statistics
| Branch: | Tag: | Revision:
1 8a9edda5 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * interfaces.php
4 9da2cf1c Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2006 Daniel S. Haischt
10
 * All rights reserved.
11 fd9ebcd5 Stephen Beaver
 *
12 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15 fd9ebcd5 Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19 fd9ebcd5 Stephen Beaver
 *
20 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
21 fd9ebcd5 Stephen Beaver
 *
22 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27 fd9ebcd5 Stephen Beaver
 */
28 5b237745 Scott Ullrich
29 6b07c15a Matthew Grooms
##|+PRIV
30 01eb687d Ermal Luçi
##|*IDENT=page-interfaces
31 5230f468 jim-p
##|*NAME=Interfaces: WAN
32 998552f8 Ermal Luçi
##|*DESCR=Allow access to the 'Interfaces' page.
33 01eb687d Ermal Luçi
##|*MATCH=interfaces.php*
34 6b07c15a Matthew Grooms
##|-PRIV
35
36 f81cfcc9 jim-p
require_once("guiconfig.inc");
37
require_once("ipsec.inc");
38
require_once("functions.inc");
39
require_once("captiveportal.inc");
40
require_once("filter.inc");
41
require_once("shaper.inc");
42
require_once("rrd.inc");
43
require_once("vpn.inc");
44 1fb064e8 Erik Fonnesbeck
require_once("xmlparse_attr.inc");
45 bc68ed41 Viktor G
require_once("util.inc");
46 199d8121 Ermal Luçi
47 c6c398c6 jim-p
function remove_bad_chars($string) {
48
	return preg_replace('/[^a-z_0-9]/i', '', $string);
49
}
50
51 6dee9957 Stephen Beaver
define("ANTENNAS", false);
52 ae4c4bac Stephen Beaver
53 5eabad3d Phil Davis
if (isset($_POST['referer'])) {
54 68933ba7 Stephen Beaver
	$referer = $_POST['referer'];
55 5eabad3d Phil Davis
} else {
56 68933ba7 Stephen Beaver
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
57 5eabad3d Phil Davis
}
58 62424bdb Renato Botelho
59 94556105 Scott Ullrich
// Get configured interface list
60 f593f80b Phil Davis
$ifdescrs = get_configured_interface_with_descr(true);
61 94556105 Scott Ullrich
62 dd18038e Ermal
$if = "wan";
63 c946d721 Steve Beaver
64 1caf2209 Phil Davis
if ($_REQUEST['if']) {
65 68933ba7 Stephen Beaver
	$if = $_REQUEST['if'];
66 1caf2209 Phil Davis
}
67 dd18038e Ermal
68
if (empty($ifdescrs[$if])) {
69 68933ba7 Stephen Beaver
	header("Location: interfaces.php");
70
	exit;
71 9ff9a1c7 Seth Mos
}
72 6b07c15a Matthew Grooms
73 58af5941 Scott Ullrich
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
74
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
75
define("CRON_DAILY_PATTERN", "0 0 * * *");
76
define("CRON_HOURLY_PATTERN", "0 * * * *");
77 dc711694 Scott Ullrich
78 1caf2209 Phil Davis
if (!is_array($pconfig)) {
79 68933ba7 Stephen Beaver
	$pconfig = array();
80 1caf2209 Phil Davis
}
81 89c7a9c8 Ermal
82 c6c398c6 jim-p
init_config_arr(array('ppps', 'ppp'));
83 d85ba87f gnhb
$a_ppps = &$config['ppps']['ppp'];
84 58af5941 Scott Ullrich
85 c6c398c6 jim-p
init_config_arr(array('gateways', 'gateway_item'));
86 d173230c Seth Mos
$a_gateways = &$config['gateways']['gateway_item'];
87
88 58a185ae marjohn56
$interfaces = get_configured_interface_with_descr();
89 f3f98e97 Phil Davis
/* Interfaces which have addresses configured elsewhere and should not be
90 cc240e32 jim-p
 * configured here. See https://redmine.pfsense.org/issues/8687 */
91 992335fc Viktor G
$no_address_interfaces = array("ovpn", "ipsec", "gif", "gre", "l2tps");
92 cc240e32 jim-p
$show_address_controls = true;
93
$realifname = get_real_interface($if);
94
foreach ($no_address_interfaces as $ifbl) {
95
	if (substr($realifname, 0, strlen($ifbl)) == $ifbl) {
96
		$show_address_controls = false;
97
	}
98
}
99
100 c6c398c6 jim-p
init_config_arr(array('interfaces', $if));
101 f1f60c92 Ermal Luçi
$wancfg = &$config['interfaces'][$if];
102 ee5c01b5 Seth Mos
$old_wancfg = $wancfg;
103 e12ad49f Renato Botelho
$old_wancfg['realif'] = get_real_interface($if);
104
$old_ppps = $a_ppps;
105 564599fa Stephen Beaver
106 dd18038e Ermal
// Populate page descr if it does not exist.
107 1caf2209 Phil Davis
if ($if == "wan" && !$wancfg['descr']) {
108 68933ba7 Stephen Beaver
	$wancfg['descr'] = "WAN";
109 1caf2209 Phil Davis
} else if ($if == "lan" && !$wancfg['descr']) {
110 68933ba7 Stephen Beaver
	$wancfg['descr'] = "LAN";
111 1caf2209 Phil Davis
}
112 dd18038e Ermal
113 c4642eb1 Ermal LUÇI
/* NOTE: The code here is used to set the $pppid for the curious */
114 efe80217 jim-p
$pppid = null;
115
foreach ($a_ppps as $pid => $ppp) {
116 68933ba7 Stephen Beaver
	if ($wancfg['if'] == $ppp['if']) {
117 efe80217 jim-p
		$pppid = $pid;
118 68933ba7 Stephen Beaver
		break;
119
	}
120 30ade846 gnhb
}
121
122 c4b60a9a Colin Fleming
$type_disabled = (substr($wancfg['if'], 0, 3) == 'gre') ? 'disabled' : '';
123 f3d88511 Renato Botelho
124 1d7e1d6c gnhb
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
125 68933ba7 Stephen Beaver
	$pconfig['pppid'] = $pppid;
126
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
127
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
128
	if ($a_ppps[$pppid]['type'] == "ppp") {
129
		$pconfig['ppp_username'] = $a_ppps[$pppid]['username'];
130
		$pconfig['ppp_password'] = base64_decode($a_ppps[$pppid]['password']);
131
132
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
133
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
134 71465708 Viktor G
	} elseif ($a_ppps[$pppid]['type'] == "pppoe") {
135 68933ba7 Stephen Beaver
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
136
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
137
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
138 71465708 Viktor G
		$pconfig['hostuniq'] = $a_ppps[$pppid]['hostuniq'];
139 68933ba7 Stephen Beaver
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
140
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
141
142
		/* ================================================ */
143
		/* = force a connection reset at a specific time? = */
144
		/* ================================================ */
145
146
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
147
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
148
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
149
			if ($itemhash) {
150
				$cronitem = $itemhash['ITEM'];
151
			}
152
			if (isset($cronitem)) {
153
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
154
			} else {
155
				$resetTime = NULL;
156
			}
157
			//log_error("ResetTime:".$resetTime);
158
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
159
				if ($cronitem) {
160
					$pconfig['pppoe_pr_custom'] = true;
161
					$pconfig['pppoe_resetminute'] = $cronitem['minute'];
162
					$pconfig['pppoe_resethour'] = $cronitem['hour'];
163
					if ($cronitem['mday'] != "*" && $cronitem['month'] != "*") {
164
						$pconfig['pppoe_resetdate'] = "{$cronitem['month']}/{$cronitem['mday']}/" . date("Y");
165
					}
166
				}
167
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
168
				$pconfig['pppoe_pr_preset'] = true;
169
				switch ($resetTime) {
170
					case CRON_MONTHLY_PATTERN:
171
						$pconfig['pppoe_monthly'] = true;
172
						break;
173
					case CRON_WEEKLY_PATTERN:
174
						$pconfig['pppoe_weekly'] = true;
175
						break;
176
					case CRON_DAILY_PATTERN:
177
						$pconfig['pppoe_daily'] = true;
178
						break;
179
					case CRON_HOURLY_PATTERN:
180
						$pconfig['pppoe_hourly'] = true;
181
						break;
182
				}
183
			}
184
		} // End force pppoe reset at specific time
185
		// End if type == pppoe
186
	} else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp") {
187
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
188
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
189 8e267d3b Viktor G
		if (($a_ppps[$pppid]['type'] == 'l2tp') && isset($a_ppps[$pppid]['secret'])) {
190
			$pconfig['l2tp_secret'] = base64_decode($a_ppps[$pppid]['secret']);
191
		}
192 66fd7b47 Phil Davis
		$pconfig['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
193 68933ba7 Stephen Beaver
		$pconfig['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
194
		$pconfig['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
195
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
196
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
197
	}
198 8256f324 gnhb
} else {
199 68933ba7 Stephen Beaver
	$pconfig['ptpid'] = interfaces_ptpid_next();
200
	$pppid = count($a_ppps);
201 d85ba87f gnhb
}
202 564599fa Stephen Beaver
203 5b237745 Scott Ullrich
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
204 bc40d758 Seth Mos
$pconfig['alias-address'] = $wancfg['alias-address'];
205
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
206 57c83fd6 jim-p
$pconfig['dhcprejectfrom'] = $wancfg['dhcprejectfrom'];
207 f4dd8b4c N0YB
208
$pconfig['adv_dhcp_pt_timeout'] = $wancfg['adv_dhcp_pt_timeout'];
209
$pconfig['adv_dhcp_pt_retry'] = $wancfg['adv_dhcp_pt_retry'];
210
$pconfig['adv_dhcp_pt_select_timeout'] = $wancfg['adv_dhcp_pt_select_timeout'];
211
$pconfig['adv_dhcp_pt_reboot'] = $wancfg['adv_dhcp_pt_reboot'];
212
$pconfig['adv_dhcp_pt_backoff_cutoff'] = $wancfg['adv_dhcp_pt_backoff_cutoff'];
213
$pconfig['adv_dhcp_pt_initial_interval'] = $wancfg['adv_dhcp_pt_initial_interval'];
214
215
$pconfig['adv_dhcp_pt_values'] = $wancfg['adv_dhcp_pt_values'];
216
217
$pconfig['adv_dhcp_send_options'] = $wancfg['adv_dhcp_send_options'];
218
$pconfig['adv_dhcp_request_options'] = $wancfg['adv_dhcp_request_options'];
219
$pconfig['adv_dhcp_required_options'] = $wancfg['adv_dhcp_required_options'];
220
$pconfig['adv_dhcp_option_modifiers'] = $wancfg['adv_dhcp_option_modifiers'];
221
222
$pconfig['adv_dhcp_config_advanced'] = $wancfg['adv_dhcp_config_advanced'];
223
$pconfig['adv_dhcp_config_file_override'] = $wancfg['adv_dhcp_config_file_override'];
224
$pconfig['adv_dhcp_config_file_override_path'] = $wancfg['adv_dhcp_config_file_override_path'];
225
226
$pconfig['adv_dhcp6_interface_statement_send_options'] = $wancfg['adv_dhcp6_interface_statement_send_options'];
227
$pconfig['adv_dhcp6_interface_statement_request_options'] = $wancfg['adv_dhcp6_interface_statement_request_options'];
228
$pconfig['adv_dhcp6_interface_statement_information_only_enable'] = $wancfg['adv_dhcp6_interface_statement_information_only_enable'];
229
$pconfig['adv_dhcp6_interface_statement_script'] = $wancfg['adv_dhcp6_interface_statement_script'];
230
231
$pconfig['adv_dhcp6_id_assoc_statement_address_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_address_enable'];
232
$pconfig['adv_dhcp6_id_assoc_statement_address'] = $wancfg['adv_dhcp6_id_assoc_statement_address'];
233
$pconfig['adv_dhcp6_id_assoc_statement_address_id'] = $wancfg['adv_dhcp6_id_assoc_statement_address_id'];
234
$pconfig['adv_dhcp6_id_assoc_statement_address_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_pltime'];
235
$pconfig['adv_dhcp6_id_assoc_statement_address_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_address_vltime'];
236
237
$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'];
238
$pconfig['adv_dhcp6_id_assoc_statement_prefix'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix'];
239
$pconfig['adv_dhcp6_id_assoc_statement_prefix_id'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_id'];
240
$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'];
241
$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'];
242
243
$pconfig['adv_dhcp6_prefix_interface_statement_sla_id'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_id'];
244
$pconfig['adv_dhcp6_prefix_interface_statement_sla_len'] = $wancfg['adv_dhcp6_prefix_interface_statement_sla_len'];
245 58a185ae marjohn56
$pconfig['adv_dhcp6_prefix_selected_interface'] = $wancfg['adv_dhcp6_prefix_selected_interface'];
246 f4dd8b4c N0YB
247
$pconfig['adv_dhcp6_authentication_statement_authname'] = $wancfg['adv_dhcp6_authentication_statement_authname'];
248
$pconfig['adv_dhcp6_authentication_statement_protocol'] = $wancfg['adv_dhcp6_authentication_statement_protocol'];
249
$pconfig['adv_dhcp6_authentication_statement_algorithm'] = $wancfg['adv_dhcp6_authentication_statement_algorithm'];
250
$pconfig['adv_dhcp6_authentication_statement_rdm'] = $wancfg['adv_dhcp6_authentication_statement_rdm'];
251
252
$pconfig['adv_dhcp6_key_info_statement_keyname'] = $wancfg['adv_dhcp6_key_info_statement_keyname'];
253
$pconfig['adv_dhcp6_key_info_statement_realm'] = $wancfg['adv_dhcp6_key_info_statement_realm'];
254
$pconfig['adv_dhcp6_key_info_statement_keyid'] = $wancfg['adv_dhcp6_key_info_statement_keyid'];
255
$pconfig['adv_dhcp6_key_info_statement_secret'] = $wancfg['adv_dhcp6_key_info_statement_secret'];
256
$pconfig['adv_dhcp6_key_info_statement_expire'] = $wancfg['adv_dhcp6_key_info_statement_expire'];
257
258
$pconfig['adv_dhcp6_config_advanced'] = $wancfg['adv_dhcp6_config_advanced'];
259
$pconfig['adv_dhcp6_config_file_override'] = $wancfg['adv_dhcp6_config_file_override'];
260
$pconfig['adv_dhcp6_config_file_override_path'] = $wancfg['adv_dhcp6_config_file_override_path'];
261
262 e4d40f41 gnhb
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
263 f1f60c92 Ermal Luçi
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
264 6a688547 Ermal
$pconfig['enable'] = isset($wancfg['enable']);
265 f1f60c92 Ermal Luçi
266 1caf2209 Phil Davis
switch ($wancfg['ipaddr']) {
267 68933ba7 Stephen Beaver
	case "dhcp":
268
		$pconfig['type'] = "dhcp";
269 62ed56dc Luiz Souza
		$pconfig['dhcpvlanenable'] = isset($wancfg['dhcpvlanenable']);
270
		$pconfig['dhcpcvpt'] = $wancfg['dhcpcvpt'];
271 68933ba7 Stephen Beaver
		break;
272
	case "pppoe":
273
	case "pptp":
274
	case "l2tp":
275
	case "ppp":
276
		$pconfig['type'] = $wancfg['ipaddr'];
277
		break;
278
	default:
279
		if (is_ipaddrv4($wancfg['ipaddr'])) {
280
			$pconfig['type'] = "staticv4";
281
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
282
			$pconfig['subnet'] = $wancfg['subnet'];
283
			$pconfig['gateway'] = $wancfg['gateway'];
284 7957389b Viktor G
		} elseif (in_array(remove_ifindex($wancfg['if']), array("ppp", "pppoe", "pptp", "l2tp"))) {
285
			$pconfig['type'] = remove_ifindex($wancfg['if']);
286 68933ba7 Stephen Beaver
		} else {
287
			$pconfig['type'] = "none";
288
		}
289
		break;
290 9ff9a1c7 Seth Mos
}
291 5b237745 Scott Ullrich
292 1caf2209 Phil Davis
switch ($wancfg['ipaddrv6']) {
293 68933ba7 Stephen Beaver
	case "slaac":
294
		$pconfig['type6'] = "slaac";
295 9210d0aa Viktor Gurov
		$pconfig['slaacusev4iface'] = isset($wancfg['slaacusev4iface']);
296 68933ba7 Stephen Beaver
		break;
297
	case "dhcp6":
298
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
299
		if (!isset($wancfg['dhcp6-ia-pd-len'])) {
300
			$wancfg['dhcp6-ia-pd-len'] = "none";
301
		}
302
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
303
		$pconfig['dhcp6-ia-pd-send-hint'] = isset($wancfg['dhcp6-ia-pd-send-hint']);
304
		$pconfig['type6'] = "dhcp6";
305
		$pconfig['dhcp6prefixonly'] = isset($wancfg['dhcp6prefixonly']);
306
		$pconfig['dhcp6usev4iface'] = isset($wancfg['dhcp6usev4iface']);
307 8c661bc8 marjohn56
		$pconfig['dhcp6withoutra'] = isset($wancfg['dhcp6withoutra']);
308 6b8680a7 marjohn56
		$pconfig['dhcp6vlanenable'] = isset($wancfg['dhcp6vlanenable']);
309
		$pconfig['dhcp6cvpt'] = $wancfg['dhcp6cvpt'];
310 68933ba7 Stephen Beaver
		break;
311
	case "6to4":
312
		$pconfig['type6'] = "6to4";
313
		break;
314
	case "track6":
315
		$pconfig['type6'] = "track6";
316
		$pconfig['track6-interface'] = $wancfg['track6-interface'];
317
		if ($wancfg['track6-prefix-id'] == "") {
318
			$pconfig['track6-prefix-id'] = 0;
319
		} else {
320
			$pconfig['track6-prefix-id'] = $wancfg['track6-prefix-id'];
321
		}
322
		$pconfig['track6-prefix-id--hex'] = sprintf("%x", $pconfig['track6-prefix-id']);
323
		break;
324
	case "6rd":
325
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
326
		if ($wancfg['prefix-6rd-v4plen'] == "") {
327
			$wancfg['prefix-6rd-v4plen'] = "0";
328
		}
329
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
330
		$pconfig['type6'] = "6rd";
331
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
332
		break;
333
	default:
334
		if (is_ipaddrv6($wancfg['ipaddrv6'])) {
335
			$pconfig['type6'] = "staticv6";
336 b7331383 marjohn56
			$pconfig['ipv6usev4iface'] = isset($wancfg['ipv6usev4iface']);
337 68933ba7 Stephen Beaver
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
338
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
339
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
340
		} else {
341
			$pconfig['type6'] = "none";
342
		}
343
		break;
344 47593ac6 Seth Mos
}
345
346 5b237745 Scott Ullrich
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
347 ff1955ee Bill Marquette
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
348 5b237745 Scott Ullrich
$pconfig['spoofmac'] = $wancfg['spoofmac'];
349
$pconfig['mtu'] = $wancfg['mtu'];
350 4cea5cf8 Ermal
$pconfig['mss'] = $wancfg['mss'];
351 5b237745 Scott Ullrich
352
/* Wireless interface? */
353 b7f01f59 Bill Marquette
if (isset($wancfg['wireless'])) {
354 68933ba7 Stephen Beaver
	/* Sync first to be sure it displays the actual settings that will be used */
355
	interface_sync_wireless_clones($wancfg, false);
356
	/* Get wireless modes */
357
	$wlanif = get_real_interface($if);
358
	if (!does_interface_exist($wlanif)) {
359
		interface_wireless_clone($wlanif, $wancfg);
360
	}
361
	$wlanbaseif = interface_get_wireless_base($wancfg['if']);
362
	preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split);
363
	$wl_modes = get_wireless_modes($if);
364 91fd7459 Viktor G
	$wl_ht_modes = get_wireless_ht_modes($if);
365
	$wl_ht_list = get_wireless_ht_list($if);
366 68933ba7 Stephen Beaver
	$wl_chaninfo = get_wireless_channel_info($if);
367
	$wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2];
368
	$wl_sysctl = get_sysctl(
369
		array(
370
			"{$wl_sysctl_prefix}.diversity",
371
			"{$wl_sysctl_prefix}.txantenna",
372
			"{$wl_sysctl_prefix}.rxantenna",
373
			"{$wl_sysctl_prefix}.slottime",
374
			"{$wl_sysctl_prefix}.acktimeout",
375
			"{$wl_sysctl_prefix}.ctstimeout"));
376
	$wl_regdomain_xml_attr = array();
377
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
378
	$wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd'];
379
	$wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd'];
380
	$wl_countries = &$wl_regdomain_xml['country-codes']['country'];
381
	$wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country'];
382
	$pconfig['persistcommonwireless'] = isset($config['wireless']['interfaces'][$wlanbaseif]);
383
	$pconfig['standard'] = $wancfg['wireless']['standard'];
384
	$pconfig['mode'] = $wancfg['wireless']['mode'];
385
	$pconfig['protmode'] = $wancfg['wireless']['protmode'];
386
	$pconfig['ssid'] = $wancfg['wireless']['ssid'];
387
	$pconfig['channel'] = $wancfg['wireless']['channel'];
388 91fd7459 Viktor G
	$pconfig['channel_width'] = $wancfg['wireless']['channel_width'];
389 68933ba7 Stephen Beaver
	$pconfig['txpower'] = $wancfg['wireless']['txpower'];
390
	$pconfig['diversity'] = $wancfg['wireless']['diversity'];
391
	$pconfig['txantenna'] = $wancfg['wireless']['txantenna'];
392
	$pconfig['rxantenna'] = $wancfg['wireless']['rxantenna'];
393
	$pconfig['distance'] = $wancfg['wireless']['distance'];
394
	$pconfig['regdomain'] = $wancfg['wireless']['regdomain'];
395
	$pconfig['regcountry'] = $wancfg['wireless']['regcountry'];
396
	$pconfig['reglocation'] = $wancfg['wireless']['reglocation'];
397
	$pconfig['wme_enable'] = isset($wancfg['wireless']['wme']['enable']);
398
	if (isset($wancfg['wireless']['puren']['enable'])) {
399
		$pconfig['puremode'] = '11n';
400
	} else if (isset($wancfg['wireless']['pureg']['enable'])) {
401
		$pconfig['puremode'] = '11g';
402
	} else {
403
		$pconfig['puremode'] = 'any';
404
	}
405
	$pconfig['apbridge_enable'] = isset($wancfg['wireless']['apbridge']['enable']);
406
	$pconfig['authmode'] = $wancfg['wireless']['authmode'];
407
	$pconfig['hidessid_enable'] = isset($wancfg['wireless']['hidessid']['enable']);
408
	$pconfig['auth_server_addr'] = $wancfg['wireless']['auth_server_addr'];
409
	$pconfig['auth_server_port'] = $wancfg['wireless']['auth_server_port'];
410
	$pconfig['auth_server_shared_secret'] = $wancfg['wireless']['auth_server_shared_secret'];
411
	$pconfig['auth_server_addr2'] = $wancfg['wireless']['auth_server_addr2'];
412
	$pconfig['auth_server_port2'] = $wancfg['wireless']['auth_server_port2'];
413
	$pconfig['auth_server_shared_secret2'] = $wancfg['wireless']['auth_server_shared_secret2'];
414
	if (is_array($wancfg['wireless']['wpa'])) {
415
		$pconfig['debug_mode'] = $wancfg['wireless']['wpa']['debug_mode'];
416
		$pconfig['macaddr_acl'] = $wancfg['wireless']['wpa']['macaddr_acl'];
417
		$pconfig['mac_acl_enable'] = isset($wancfg['wireless']['wpa']['mac_acl_enable']);
418
		$pconfig['wpa_mode'] = $wancfg['wireless']['wpa']['wpa_mode'];
419
		$pconfig['wpa_key_mgmt'] = $wancfg['wireless']['wpa']['wpa_key_mgmt'];
420
		$pconfig['wpa_pairwise'] = $wancfg['wireless']['wpa']['wpa_pairwise'];
421
		$pconfig['wpa_group_rekey'] = $wancfg['wireless']['wpa']['wpa_group_rekey'];
422
		$pconfig['wpa_gmk_rekey'] = $wancfg['wireless']['wpa']['wpa_gmk_rekey'];
423
		$pconfig['wpa_strict_rekey'] = isset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
424
		$pconfig['passphrase'] = $wancfg['wireless']['wpa']['passphrase'];
425
		$pconfig['ieee8021x'] = isset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
426
		$pconfig['rsn_preauth'] = isset($wancfg['wireless']['wpa']['rsn_preauth']);
427
		$pconfig['ext_wpa_sw'] = $wancfg['wireless']['wpa']['ext_wpa_sw'];
428
		$pconfig['wpa_enable'] = isset($wancfg['wireless']['wpa']['enable']);
429 5f120301 Viktor G
		$pconfig['wpa_eap_client_mode'] = $wancfg['wireless']['wpa']['wpa_eap_client_mode'];
430
		$pconfig['wpa_eap_inner_auth'] = $wancfg['wireless']['wpa']['wpa_eap_inner_auth'];
431
		$pconfig['wpa_eap_inner_id'] = $wancfg['wireless']['wpa']['wpa_eap_inner_id'];
432
		$pconfig['wpa_eap_inner_password'] = base64_decode($wancfg['wireless']['wpa']['wpa_eap_inner_password']);
433
		$pconfig['wpa_eap_cert'] = $wancfg['wireless']['wpa']['wpa_eap_cert'];
434
		$pconfig['wpa_eap_ca'] = $wancfg['wireless']['wpa']['wpa_eap_ca'];
435 68933ba7 Stephen Beaver
	}
436
437
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
438
439 5b237745 Scott Ullrich
}
440
441 44c42356 Phil Davis
$changes_applied = false;
442
443 43e255d2 Ermal Luçi
if ($_POST['apply']) {
444 68933ba7 Stephen Beaver
	unset($input_errors);
445
	if (!is_subsystem_dirty('interfaces')) {
446 eaa948d6 NOYB
		$input_errors[] = gettext("The settings have already been applied!");
447 68933ba7 Stephen Beaver
	} else {
448 44c42356 Phil Davis
		$retval = 0;
449 68933ba7 Stephen Beaver
		unlink_if_exists("{$g['tmp_path']}/config.cache");
450
		clear_subsystem_dirty('interfaces');
451
452 c6d22ee1 Viktor G
		$vlan_redo = array();
453 68933ba7 Stephen Beaver
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
454
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
455
			foreach ($toapplylist as $ifapply => $ifcfgo) {
456 9bb98111 Viktor G
				$realif = get_real_interface($ifapply);
457
				$ifmtu = get_interface_mtu($realif);
458 2d5c75fa Reid Linnemann
				if (config_path_enabled("interfaces/{$ifapply}")) {
459 68933ba7 Stephen Beaver
					interface_bring_down($ifapply, false, $ifcfgo);
460
					interface_configure($ifapply, true);
461 2d5c75fa Reid Linnemann
					if (config_get_path("interfaces/{$ifapply}/ipaddrv6") == "track6") {
462 3a8a9028 Chris Buechler
						/* call interface_track6_configure with linkup true so
463
						   IPv6 IPs are added back. dhcp6c needs a HUP. Can't
464
						   just call interface_configure with linkup true as
465 7e653b50 Stephen Beaver
						   that skips bridge membership addition.
466 3a8a9028 Chris Buechler
						*/
467 2d5c75fa Reid Linnemann
						$wancfg = config_get_path("interfaces/{$ifapply}");
468 3a8a9028 Chris Buechler
						interface_track6_configure($ifapply, $wancfg, true);
469
					}
470 68933ba7 Stephen Beaver
				} else {
471
					interface_bring_down($ifapply, true, $ifcfgo);
472
				}
473 318714cb Viktor G
				restart_interface_services($ifapply, $ifcfg['ipaddrv6']);
474 2d5c75fa Reid Linnemann
				$mtu = config_get_path("interfaces/{$ifapply}/mtu");
475 9bb98111 Viktor G
				if (interface_has_clones($realif) &&
476 2d5c75fa Reid Linnemann
				    ($mtu && ($mtu != $ifmtu)) ||
477
				    (!$mtu && (get_interface_default_mtu() != $ifmtu))) { 
478 9bb98111 Viktor G
					$vlan_redo[] = $realif;
479
				}
480 68933ba7 Stephen Beaver
			}
481
		}
482 c9f69485 Luiz Souza
483
		/*
484 69ffb456 Viktor G
                 * If the parent interface has changed MTU above, the VLANs needs to be
485
                 * redone.
486 c9f69485 Luiz Souza
		 */
487 c6d22ee1 Viktor G
		if (!empty($vlan_redo)) {
488
			foreach ($vlan_redo as $vlredo) {
489 be732dba Viktor G
				interfaces_vlan_configure_mtu($vlredo);
490 c6d22ee1 Viktor G
			}
491 c9f69485 Luiz Souza
		}
492
493 68933ba7 Stephen Beaver
		/* sync filter configuration */
494
		setup_gateways_monitor();
495
496
		clear_subsystem_dirty('interfaces');
497
498 44c42356 Phil Davis
		$retval |= filter_configure();
499 68933ba7 Stephen Beaver
500
		enable_rrd_graphing();
501
502 44c42356 Phil Davis
		$changes_applied = true;
503
504 68933ba7 Stephen Beaver
		if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) {
505
			clear_subsystem_dirty('staticroutes');
506
		}
507 fd3af9eb Viktor G
508 bc68ed41 Viktor G
		send_event("service reload packages");
509 68933ba7 Stephen Beaver
	}
510
	@unlink("{$g['tmp_path']}/.interfaces.apply");
511 c946d721 Steve Beaver
} else if ($_POST['save']) {
512 270c4607 Scott Ullrich
513 68933ba7 Stephen Beaver
	unset($input_errors);
514
	$pconfig = $_POST;
515
516 b6f6210a jim-p
	if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
517 68933ba7 Stephen Beaver
		$pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
518
	} else {
519
		$pconfig['track6-prefix-id'] = 0;
520
	}
521
522
	/* filter out spaces from descriptions */
523
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
524
525
	/* okay first of all, cause we are just hiding the PPPoE HTML
526
	 * fields related to PPPoE resets, we are going to unset $_POST
527
	 * vars, if the reset feature should not be used. Otherwise the
528
	 * data validation procedure below, may trigger a false error
529
	 * message.
530
	 */
531
	if (empty($_POST['pppoe-reset-type'])) {
532
		unset($_POST['pppoe_pr_type']);
533
		unset($_POST['pppoe_resethour']);
534
		unset($_POST['pppoe_resetminute']);
535
		unset($_POST['pppoe_resetdate']);
536
		unset($_POST['pppoe_pr_preset_val']);
537
	}
538 f57a3d90 Phil Davis
539
	/* input validation */
540
	$reqdfields = explode(" ", "descr");
541
	$reqdfieldsn = array(gettext("Description"));
542 b07adc11 Phil Davis
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
543 f57a3d90 Phil Davis
544
	if (!$input_errors) {
545
		/* description unique? */
546
		foreach ($ifdescrs as $ifent => $ifdescr) {
547 b101627a Phil Davis
			if ($if != $ifent && (strcasecmp($ifdescr, $_POST['descr']) == 0)) {
548 f57a3d90 Phil Davis
				$input_errors[] = gettext("An interface with the specified description already exists.");
549
				break;
550
			}
551 68933ba7 Stephen Beaver
		}
552 f8bf3fe8 Phil Davis
553 f57a3d90 Phil Davis
		/* Is the description already used as an alias name? */
554 2d5c75fa Reid Linnemann
		foreach (config_get_path('aliases/alias', []) as $alias) {
555
			if (strcasecmp($alias['name'], $_POST['descr']) == 0) {
556
				$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."), $_POST['descr']);
557 f8bf3fe8 Phil Davis
			}
558
		}
559
560 f57a3d90 Phil Davis
		/* Is the description already used as an interface group name? */
561 2d5c75fa Reid Linnemann
		foreach (config_get_path('ifgroups/ifgroupentry', []) as $ifgroupentry) {
562
			if (strcasecmp($ifgroupentry['ifname'], $_POST['descr']) == 0) {
563
				$input_errors[] = sprintf(gettext("Sorry, an interface group with the name %s already exists."), $_POST['descr']);
564 b824f18c Renato Botelho
			}
565
		}
566
567 f57a3d90 Phil Davis
		if (is_numeric($_POST['descr'])) {
568
			$input_errors[] = gettext("The interface description cannot contain only numbers.");
569
		}
570 c9d93b62 Phil Davis
571 cec267cb Viktor G
		if ((strlen(trim($_POST['descr'])) > 25) && ((substr($realifname, 0, 4) == 'ovpn') ||
572 281dede0 Renato Botelho do Couto
		    (substr($realifname, 0, 5) == 'ipsec'))) {
573
			$input_errors[] = gettext("The OpenVPN and VTI interface description must be less than 26 characters long.");
574 cec267cb Viktor G
		}
575
576
		if ((strlen(trim($_POST['descr'])) > 22) && ((substr($realifname, 0, 3) == 'gif') ||
577
		    (substr($realifname, 0, 3) == 'gre'))) {
578
			$input_errors[] = gettext("The GIF and GRE interface description must be less than 23 characters long.");
579
		}
580
581 c9d93b62 Phil Davis
		/*
582
		 * Packages (e.g. tinc) create interface groups, reserve this
583
		 * namespace pkg_ for them.
584
		 * One namespace is shared by Interfaces, Interface Groups and Aliases.
585
		 */
586
		if (substr($_POST['descr'], 0, 4) == 'pkg_') {
587
			$input_errors[] = gettext("The interface description cannot start with pkg_");
588
		}
589 68933ba7 Stephen Beaver
	}
590 f57a3d90 Phil Davis
591 2d113b12 Renato Botelho
	if ($_POST['blockbogons'] == "yes" &&
592 2d5c75fa Reid Linnemann
	    config_path_enabled('system','ipv6allow') &&
593
	    (config_get_path('system/maximumtableentries', 0) <
594 2d113b12 Renato Botelho
	     $g['minimumtableentries_bogonsv6'])) {
595
		$input_errors[] = sprintf(gettext(
596
		    "In order to block bogon networks the Firewall Maximum Table Entries value in System / Advanced / Firewall must be increased at least to %s."),
597
		    $g['minimumtableentries_bogonsv6']);
598
	}
599
600 2d5c75fa Reid Linnemann
	if (config_path_enabled("dhcpd/{$if}")) {
601 403dad2a Renato Botelho
		if (!preg_match("/^staticv4/", $_POST['type'])) {
602
			$input_errors[] = gettext("The DHCP Server is active " .
603
			    "on this interface and it can be used only with " .
604
			    "a static IP configuration. Please disable the " .
605
			    "DHCP Server service on this interface first, " .
606
			    "then change the interface configuration.");
607
		} elseif (!empty($_POST['subnet']) && $_POST['subnet'] >= 31) {
608
			$input_errors[] = gettext("The DHCP Server is active " .
609
			    "on this interface and it can be used only with " .
610
			    "IPv4 subnet < 31. Please disable the " .
611
			    "DHCP Server service on this interface first, " .
612
			    "then change the interface configuration.");
613
		}
614 68933ba7 Stephen Beaver
	}
615 91cd1741 Viktor G
	if (isset($config['dhcpdv6']) && ($_POST['type6'] != "staticv6" && $_POST['type6'] != "track6")) {
616 2d5c75fa Reid Linnemann
		if (config_path_enabled("dhcpdv6/{$if}")) {
617 91cd1741 Viktor G
			$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only " .
618
			    "with a static IPv6 configuration. Please disable the DHCPv6 Server service on this " .
619
			    "interface first, then change the interface configuration.");
620
		}
621 2d5c75fa Reid Linnemann
		if (config_get_path("dhcpdv6/{$if}/ramode", "disabled") != "disabled") {
622 91cd1741 Viktor G
			$input_errors[] = gettext("The Router Advertisements Server is active on this interface and it can " .
623
			    "be used only with a static IPv6 configuration. Please disable the Router Advertisements " .
624
			    "Server service on this interface first, then change the interface configuration.");
625
		}
626 68933ba7 Stephen Beaver
	}
627
628
	switch (strtolower($_POST['type'])) {
629
		case "staticv4":
630
			$reqdfields = explode(" ", "ipaddr subnet gateway");
631
			$reqdfieldsn = array(gettext("IPv4 address"), gettext("Subnet bit count"), gettext("Gateway"));
632
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
633
			break;
634
		case "none":
635 2d5c75fa Reid Linnemann
			foreach (config_get_path('virtualip/vip', []) as $vip) {
636
				if (is_ipaddrv4($vip['subnet']) && $vip['interface'] == $if) {
637
					$input_errors[] = gettext("This interface is referenced by IPv4 VIPs. Please delete those before setting the interface to 'none' configuration.");
638 68933ba7 Stephen Beaver
				}
639
			}
640
			break;
641
		case "ppp":
642
			$reqdfields = explode(" ", "port phone");
643
			$reqdfieldsn = array(gettext("Modem Port"), gettext("Phone Number"));
644
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
645
			break;
646
		case "pppoe":
647
			if ($_POST['pppoe_dialondemand']) {
648
				$reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
649
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"), gettext("Dial on demand"), gettext("Idle timeout value"));
650
			} else {
651
				$reqdfields = explode(" ", "pppoe_username pppoe_password");
652
				$reqdfieldsn = array(gettext("PPPoE username"), gettext("PPPoE password"));
653
			}
654
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
655
			break;
656
		case "pptp":
657
			if ($_POST['pptp_dialondemand']) {
658 66fd7b47 Phil Davis
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0 pptp_dialondemand pptp_idletimeout");
659 68933ba7 Stephen Beaver
				$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"));
660
			} else {
661 ca28c12c Phil Davis
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local0 pptp_subnet0 pptp_remote0");
662 68933ba7 Stephen Beaver
				$reqdfieldsn = array(gettext("PPTP username"), gettext("PPTP password"), gettext("PPTP local IP address"), gettext("PPTP subnet"), gettext("PPTP remote IP address"));
663
			}
664
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
665
			break;
666
		case "l2tp":
667
			if ($_POST['pptp_dialondemand']) {
668 66fd7b47 Phil Davis
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0 pptp_dialondemand pptp_idletimeout");
669 68933ba7 Stephen Beaver
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"), gettext("Dial on demand"), gettext("Idle timeout value"));
670
			} else {
671 66fd7b47 Phil Davis
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote0");
672 68933ba7 Stephen Beaver
				$reqdfieldsn = array(gettext("L2TP username"), gettext("L2TP password"), gettext("L2TP remote IP address"));
673
			}
674
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
675
			break;
676
	}
677
	switch (strtolower($_POST['type6'])) {
678
		case "staticv6":
679
			$reqdfields = explode(" ", "ipaddrv6 subnetv6 gatewayv6");
680
			$reqdfieldsn = array(gettext("IPv6 address"), gettext("Subnet bit count"), gettext("Gateway"));
681
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
682
			break;
683
		case "none":
684 2d5c75fa Reid Linnemann
			foreach (config_get_path('virtualip/vip', []) as $vip) {
685
				if (is_ipaddrv6($vip['subnet']) && $vip['interface'] == $if) {
686
					$input_errors[] = gettext("This interface is referenced by IPv6 VIPs. Please delete those before setting the interface to 'none' configuration.");
687 68933ba7 Stephen Beaver
				}
688
			}
689
			break;
690
		case "dhcp6":
691
			if (in_array($wancfg['ipaddrv6'], array())) {
692 e4517c3c jim-p
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
693 68933ba7 Stephen Beaver
			}
694
			if ($_POST['dhcp6-ia-pd-send-hint'] && strtolower($_POST['dhcp6-ia-pd-len']) == 'none') {
695
				$input_errors[] = gettext('DHCPv6 Prefix Delegation size must be provided when Send IPv6 prefix hint flag is checked');
696
			}
697 522e3f91 jim-p
			if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_id']) &&
698
			    !is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
699
				$input_errors[] = gettext('DHCPv6 advanced id-assoc na ID value must be empty or an integer.');
700
			}
701
			if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_id']) &&
702
			    !is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
703
				$input_errors[] = gettext('DHCPv6 advanced id-assoc pd ID value must be empty or an integer.');
704
			}
705
			if (!empty($_POST['adv_dhcp6_prefix_interface_statement_sla_id']) &&
706
			    !is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
707
				$input_errors[] = gettext('DHCPv6 advanced Prefix Interface sla-id value must be empty or an integer.');
708
			}
709
			if (!empty($_POST['adv_dhcp6_prefix_interface_statement_sla_len']) &&
710
			    !is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
711
				$input_errors[] = gettext('DHCPv6 advanced Prefix Interface sla-len value must be empty or an integer.');
712
			}
713 68933ba7 Stephen Beaver
			break;
714
		case "6rd":
715
			foreach ($ifdescrs as $ifent => $ifdescr) {
716 2d5c75fa Reid Linnemann
				if ($if != $ifent && (config_get_path("interfaces/{$ifent}/ipaddrv6") == $_POST['type6'])) {
717
					if (config_get_path("interfaces/{$ifent}/prefix-6rd") == $_POST['prefix-6rd']) {
718 e4517c3c jim-p
						$input_errors[] = gettext("Only one interface can be configured within a single 6rd prefix.");
719 68933ba7 Stephen Beaver
						break;
720
					}
721
				}
722
			}
723 b8cfee9d Viktor G
			if (!is_subnetv6($_POST['prefix-6rd'])) {
724
				$input_errors[] = gettext("6RD Prefix must be a valid IPv6 prefix.");
725
			}
726 2239959d Chris Buechler
			if (!is_ipaddrv4($_POST['gateway-6rd'])) {
727 1a9ec5cc Phil Davis
				$input_errors[] = gettext("6RD Border Relay must be an IPv4 address.");
728 3c596efc Chris Buechler
			}
729 68933ba7 Stephen Beaver
			if (in_array($wancfg['ipaddrv6'], array())) {
730 e4517c3c jim-p
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
731 68933ba7 Stephen Beaver
			}
732
			break;
733
		case "6to4":
734
			foreach ($ifdescrs as $ifent => $ifdescr) {
735 2d5c75fa Reid Linnemann
				if ($if != $ifent && (config_get_path("interfaces/{$ifent}/ipaddrv6") == $_POST['type6'])) {
736 eaa948d6 NOYB
					$input_errors[] = sprintf(gettext("Only one interface can be configured as 6to4."), $_POST['type6']);
737 68933ba7 Stephen Beaver
					break;
738
				}
739
			}
740
			if (in_array($wancfg['ipaddrv6'], array())) {
741 e4517c3c jim-p
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
742 68933ba7 Stephen Beaver
			}
743
			break;
744
		case "track6":
745
			/* needs to check if $track6-prefix-id is used on another interface */
746
			if (in_array($wancfg['ipaddrv6'], array())) {
747 e4517c3c jim-p
				$input_errors[] = sprintf(gettext("The interface must be reassigned to configure as %s."), $_POST['type6']);
748 68933ba7 Stephen Beaver
			}
749
750 f09d4db4 Renato Botelho
			if (empty($_POST['track6-interface'])) {
751 eaa948d6 NOYB
				$input_errors[] = gettext("A valid interface to track must be selected.");
752 f09d4db4 Renato Botelho
			}
753
754 1b5fbae4 Stephen Jones
			if ($_POST['track6-prefix-id--hex'] != "" && !ctype_xdigit($_POST['track6-prefix-id--hex'])) {
755 eaa948d6 NOYB
				$input_errors[] = gettext("A valid hexadecimal number must be entered for the IPv6 prefix ID.");
756 68933ba7 Stephen Beaver
			} else {
757
				$track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16);
758
				if ($track6_prefix_id < 0 || $track6_prefix_id > $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) {
759 e4517c3c jim-p
					$input_errors[] = gettext("The specified IPv6 Prefix ID is out of range.") .
760 68933ba7 Stephen Beaver
						" ({$_POST['track6-interface']}) - (0) - (" . sprintf('%x', $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) . ")";
761
				} else {
762
					foreach ($ifdescrs as $ifent => $ifdescr) {
763
						if ($if == $ifent) {
764
							continue;
765
						}
766 123efede Reid Linnemann
						if (config_get_path("interfaces/{$ifent}/ipaddrv6") == 'track6' &&
767
						    config_get_path("interfaces/{$ifent}/track6-interface") == $_POST['track6-interface'] &&
768
						    config_get_path("interfaces/{$ifent}/track6-prefix-id") == $track6_prefix_id) {
769 68933ba7 Stephen Beaver
							$input_errors[] = sprintf(gettext("This track6 prefix ID is already being used in %s."), $ifdescr);
770
						}
771
					}
772
				}
773
			}
774
			break;
775
	}
776
777
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
778
	$staticroutes = get_staticroutes(true);
779
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
780 8c6190e8 Phil Davis
	if (($_POST['type'] == 'staticv4') && $_POST['ipaddr']) {
781 68933ba7 Stephen Beaver
		if (!is_ipaddrv4($_POST['ipaddr'])) {
782
			$input_errors[] = gettext("A valid IPv4 address must be specified.");
783
		} else {
784
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddr'], $if, true, true, $_POST['subnet']);
785
			if (count($where_ipaddr_configured)) {
786
				$subnet_conflict_text = sprintf(gettext("IPv4 address %s is being used by or overlaps with:"), $_POST['ipaddr'] . "/" . $_POST['subnet']);
787
				foreach ($where_ipaddr_configured as $subnet_conflict) {
788
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
789
				}
790
				$input_errors[] = $subnet_conflict_text;
791
			}
792
793
			/* Do not accept network or broadcast address, except if subnet is 31 or 32 */
794
			if ($_POST['subnet'] < 31) {
795
				if ($_POST['ipaddr'] == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
796
					$input_errors[] = gettext("This IPv4 address is the network address and cannot be used");
797
				} else if ($_POST['ipaddr'] == gen_subnet_max($_POST['ipaddr'], $_POST['subnet'])) {
798
					$input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used");
799
				}
800
			}
801
802
			foreach ($staticroutes as $route_subnet) {
803
				list($network, $subnet) = explode("/", $route_subnet);
804
				if ($_POST['subnet'] == $subnet && $network == gen_subnet($_POST['ipaddr'], $_POST['subnet'])) {
805
					$input_errors[] = gettext("This IPv4 address conflicts with a Static Route.");
806
					break;
807
				}
808
				unset($network, $subnet);
809
			}
810
		}
811
	}
812 d1630d95 Luiz Souza
	if (($_POST['type6'] == 'staticv6') && $_POST['ipaddrv6']) {
813 5af93827 Steve Beaver
		$_POST['ipaddrv6'] = addrtolower($_POST['ipaddrv6']);
814
815 68933ba7 Stephen Beaver
		if (!is_ipaddrv6($_POST['ipaddrv6'])) {
816
			$input_errors[] = gettext("A valid IPv6 address must be specified.");
817
		} else {
818 352f8085 Chris Buechler
			if (ip_in_subnet($_POST['ipaddrv6'], "fe80::/10")) {
819
				$input_errors[] = gettext("IPv6 link local addresses cannot be configured as an interface IP.");
820
			}
821 68933ba7 Stephen Beaver
			$where_ipaddr_configured = where_is_ipaddr_configured($_POST['ipaddrv6'], $if, true, true, $_POST['subnetv6']);
822
			if (count($where_ipaddr_configured)) {
823
				$subnet_conflict_text = sprintf(gettext("IPv6 address %s is being used by or overlaps with:"), $_POST['ipaddrv6'] . "/" . $_POST['subnetv6']);
824
				foreach ($where_ipaddr_configured as $subnet_conflict) {
825
					$subnet_conflict_text .= " " . convert_friendly_interface_to_friendly_descr($subnet_conflict['if']) . " (" . $subnet_conflict['ip_or_subnet'] . ")";
826
				}
827
				$input_errors[] = $subnet_conflict_text;
828
			}
829
830
			foreach ($staticroutes as $route_subnet) {
831
				list($network, $subnet) = explode("/", $route_subnet);
832
				if ($_POST['subnetv6'] == $subnet && $network == gen_subnetv6($_POST['ipaddrv6'], $_POST['subnetv6'])) {
833
					$input_errors[] = gettext("This IPv6 address conflicts with a Static Route.");
834
					break;
835
				}
836
				unset($network, $subnet);
837
			}
838
		}
839
	}
840
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
841
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
842
	}
843
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6']))) {
844
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
845
	}
846
	if (($_POST['alias-address'] && !is_ipaddrv4($_POST['alias-address']))) {
847
		$input_errors[] = gettext("A valid alias IP address must be specified.");
848
	}
849
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
850
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
851
	}
852 392a7045 lukehamburg
	if ($_POST['dhcprejectfrom'] && !validate_ipv4_list($_POST['dhcprejectfrom'])) {
853
		$input_errors[] = gettext("An invalid IP address was detected in the 'Reject leases from' field.");
854 68933ba7 Stephen Beaver
	}
855 f1bb5c7f Phil Davis
856
	// Only check the IPv4 gateway already exists if it is not "none" and it is not a gateway that the user is adding
857
	if (($_POST['gateway'] != "none") && (!$_POST['gatewayip4'] || ($_POST['gateway'] != $_POST['gatewayname4']))) {
858 68933ba7 Stephen Beaver
		$match = false;
859
		foreach ($a_gateways as $gateway) {
860
			if (in_array($_POST['gateway'], $gateway)) {
861
				$match = true;
862
			}
863
		}
864 f1bb5c7f Phil Davis
		if (!$match) {
865
			$input_errors[] = gettext("A valid IPv4 gateway must be specified.");
866
		}
867
	}
868
	// Only check the IPv6 gateway already exists if it is not "none" and it is not a gateway that the user is adding
869
	if (($_POST['gatewayv6'] != "none") && (!$_POST['gatewayip6'] || ($_POST['gatewayv6'] != $_POST['gatewayname6']))) {
870
		$match = false;
871 68933ba7 Stephen Beaver
		foreach ($a_gateways as $gateway) {
872
			if (in_array($_POST['gatewayv6'], $gateway)) {
873
				$match = true;
874
			}
875
		}
876
		if (!$match) {
877 f1bb5c7f Phil Davis
			$input_errors[] = gettext("A valid IPv6 gateway must be specified.");
878 68933ba7 Stephen Beaver
		}
879
	}
880 dac4cd09 Steve Beaver
881 71465708 Viktor G
	if ($_POST['provider'] && strpos($_POST['provider'], "\"")) {
882 dac4cd09 Steve Beaver
		$input_errors[] = gettext("The service name may not contain quote characters.");
883 68933ba7 Stephen Beaver
	}
884 71465708 Viktor G
	if ($_POST['hostuniq'] && !preg_match('/^[a-zA-Z0-9]+$/i', $_POST['hostuniq'])) {
885
		$input_errors[] = gettext("The Host-Uniq value can only be hexadecimal or letters and numbers.");
886
	}
887 68933ba7 Stephen Beaver
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
888
		$input_errors[] = gettext("The idle timeout value must be an integer.");
889
	}
890
	if ($_POST['pppoe_resethour'] != "" && !is_numericint($_POST['pppoe_resethour']) &&
891 aa82505e Phil Davis
	    $_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
892
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
893 68933ba7 Stephen Beaver
	}
894
	if ($_POST['pppoe_resetminute'] != "" && !is_numericint($_POST['pppoe_resetminute']) &&
895 aa82505e Phil Davis
	    $_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) {
896
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
897 68933ba7 Stephen Beaver
	}
898
	if ($_POST['pppoe_resetdate'] != "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
899
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
900
	}
901 66fd7b47 Phil Davis
	if (($_POST['pptp_local0'] && !is_ipaddrv4($_POST['pptp_local0']))) {
902 68933ba7 Stephen Beaver
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
903
	}
904 66fd7b47 Phil Davis
	if (($_POST['pptp_subnet0'] && !is_numeric($_POST['pptp_subnet0']))) {
905 68933ba7 Stephen Beaver
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
906
	}
907 8d89682e Phil Davis
	if (($_POST['pptp_remote0'] && !is_ipaddrv4($_POST['pptp_remote0']) && !is_hostname($_POST['pptp_remote0']))) {
908 68933ba7 Stephen Beaver
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
909
	}
910
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
911
		$input_errors[] = gettext("The idle timeout value must be an integer.");
912
	}
913
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
914
		$input_errors[] = gettext("A valid MAC address must be specified.");
915
	}
916
	if ($_POST['mtu']) {
917
		if (!is_numericint($_POST['mtu'])) {
918
			$input_errors[] = "MTU must be an integer.";
919
		}
920
		if (substr($wancfg['if'], 0, 3) == 'gif') {
921
			$min_mtu = 1280;
922
			$max_mtu = 8192;
923 4fa69727 Viktor G
		} elseif (($_POST['ipaddrv6'] == '6rd') || ($_POST['ipaddrv6'] == '6to4')) {
924
			$min_mtu = 1300;
925
			$max_mtu = 9000;
926 68933ba7 Stephen Beaver
		} else {
927
			$min_mtu = 576;
928
			$max_mtu = 9000;
929
		}
930
931
		if ($_POST['mtu'] < $min_mtu || $_POST['mtu'] > $max_mtu) {
932
			$input_errors[] = sprintf(gettext("The MTU must be between %d and %d bytes."), $min_mtu, $max_mtu);
933
		}
934
935
		unset($min_mtu, $max_mtu);
936
937 12bcf7e9 Luiz Souza
		if (interface_is_vlan($wancfg['if']) != NULL) {
938 68933ba7 Stephen Beaver
			$realhwif_array = get_parent_interface($wancfg['if']);
939
			// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
940
			$parent_realhwif = $realhwif_array[0];
941
			$parent_if = convert_real_interface_to_friendly_interface_name($parent_realhwif);
942 4a3a45c4 Luiz Otavio O Souza
			$mtu = 0;
943 2d5c75fa Reid Linnemann
			if (!empty($parent_if) && !(config_get_path("interfaces/{$parent_if}/mtu")))
944
				$mtu = intval(config_get_path("interfaces/{$parent_if}/mtu"));
945 4a3a45c4 Luiz Otavio O Souza
			if ($mtu == 0)
946
				$mtu = get_interface_mtu($parent_realhwif);
947
			if ($_POST['mtu'] > $mtu)
948
				$input_errors[] = gettext("The MTU of a VLAN cannot be greater than that of its parent interface.");
949 68933ba7 Stephen Beaver
		} else {
950
			foreach ($config['interfaces'] as $idx => $ifdata) {
951 12bcf7e9 Luiz Souza
				if (($idx == $if) || interface_is_vlan($ifdata['if']) == NULL) {
952 68933ba7 Stephen Beaver
					continue;
953
				}
954
955
				$realhwif_array = get_parent_interface($ifdata['if']);
956
				// Need code to handle MLPPP if we ever use $realhwif for MLPPP handling
957
				$parent_realhwif = $realhwif_array[0];
958
959
				if ($parent_realhwif != $wancfg['if']) {
960
					continue;
961
				}
962
963
				if (isset($ifdata['mtu']) && $ifdata['mtu'] > $_POST['mtu']) {
964 4a3a45c4 Luiz Otavio O Souza
					$input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a larger value."), $ifdata['descr']);
965 68933ba7 Stephen Beaver
				}
966
			}
967
		}
968
	}
969
	if ($_POST['mss'] != '') {
970
		if (!is_numericint($_POST['mss']) || ($_POST['mss'] < 576 || $_POST['mss'] > 65535)) {
971
			$input_errors[] = gettext("The MSS must be an integer between 576 and 65535 bytes.");
972
		}
973
	}
974
	/* Wireless interface? */
975
	if (isset($wancfg['wireless'])) {
976
		$reqdfields = array("mode");
977
		$reqdfieldsn = array(gettext("Mode"));
978
		if ($_POST['mode'] == 'hostap') {
979
			$reqdfields[] = "ssid";
980
			$reqdfieldsn[] = gettext("SSID");
981
			if (isset($_POST['channel']) && $_POST['channel'] == "0") {
982
				// auto channel with hostap is broken, prevent this for now.
983
				$input_errors[] = gettext("A specific channel, not auto, must be selected for Access Point mode.");
984
			}
985
		}
986 91fd7459 Viktor G
		if (!stristr($_POST['standard'], '11n') && ($_POST['channel_width'] != "0")) {
987
			$input_errors[] = gettext("Channel width selection is only supported by 802.11n standards.");
988
		}
989 68933ba7 Stephen Beaver
		if (stristr($_POST['standard'], '11n')) {
990
			if (!($_POST['wme_enable'])) {
991
				$input_errors[] = gettext("802.11n standards require enabling WME.");
992
			}
993 91fd7459 Viktor G
			if (($_POST['channel_width'] != "0") && ($_POST['channel'] != "0") &&
994
			    is_array($wl_ht_list[$_POST['standard']][$_POST['channel']]) &&
995
			    !empty($wl_ht_list[$_POST['standard']][$_POST['channel']]) &&
996
			    !in_array($_POST['channel_width'], $wl_ht_list[$_POST['standard']][$_POST['channel']])) {
997
				$input_errors[] = sprintf(gettext("Unable to use %s channel width with channel %s."), strtoupper($_POST['channel_width']), $_POST['channel']);
998
			}
999 68933ba7 Stephen Beaver
		}
1000
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
1001
		check_wireless_mode();
1002
		if (isset($_POST['wpa_group_rekey']) && (!is_numericint($_POST['wpa_group_rekey']) || $_POST['wpa_group_rekey'] < 1 || $_POST['wpa_group_rekey'] > 9999)) {
1003
			$input_errors[] = gettext("Key Rotation must be an integer between 1 and 9999.");
1004
		}
1005
		if (isset($_POST['wpa_gmk_rekey']) && (!is_numericint($_POST['wpa_gmk_rekey']) || $_POST['wpa_gmk_rekey'] < 1 || $_POST['wpa_gmk_rekey'] > 9999)) {
1006
			$input_errors[] = gettext("Master Key Regeneration must be an integer between 1 and 9999.");
1007
		}
1008
		if (isset($_POST['wpa_group_rekey']) && isset($_POST['wpa_gmk_rekey'])) {
1009
			if ($_POST['wpa_group_rekey'] > $_POST['wpa_gmk_rekey']) {
1010
				$input_errors[] = gettext("Master Key Regeneration must be greater than Key Rotation.");
1011
			}
1012
		}
1013
		if (!empty($_POST['auth_server_addr'])) {
1014
			if (!is_domain($_POST['auth_server_addr']) && !is_ipaddr($_POST['auth_server_addr'])) {
1015
				$input_errors[] = gettext("802.1X Authentication Server must be an IP or hostname.");
1016
			}
1017
		}
1018
		if (!empty($_POST['auth_server_addr2'])) {
1019
			if (!is_domain($_POST['auth_server_addr2']) && !is_ipaddr($_POST['auth_server_addr2'])) {
1020
				$input_errors[] = gettext("Secondary 802.1X Authentication Server must be an IP or hostname.");
1021
			}
1022
		}
1023
		if (!empty($_POST['auth_server_port'])) {
1024
			if (!is_port($_POST['auth_server_port'])) {
1025
				$input_errors[] = gettext("802.1X Authentication Server Port must be a valid port number (1-65535).");
1026
			}
1027
		}
1028
		if (!empty($_POST['auth_server_port2'])) {
1029
			if (!is_port($_POST['auth_server_port2'])) {
1030
				$input_errors[] = gettext("Secondary 802.1X Authentication Server Port must be a valid port number (1-65535).");
1031
			}
1032
		}
1033
		if (isset($_POST['channel']) && !is_numericint($_POST['channel'])) {
1034
			if (!is_numericint($_POST['channel'])) {
1035
				$input_errors[] = gettext("Invalid channel specified.");
1036
			} else {
1037
				if ($_POST['channel'] > 255 || $_POST['channel'] < 0) {
1038
					$input_errors[] = gettext("Channel must be between 0-255.");
1039
				}
1040
			}
1041
		}
1042
		if (!empty($_POST['distance']) && !is_numericint($_POST['distance'])) {
1043
			$input_errors[] = gettext("Distance must be an integer.");
1044
		}
1045
		if (isset($_POST['standard']) && (stristr($_POST['standard'], '11na') || stristr($_POST['standard'], '11a'))) {
1046
			if ($_POST['channel'] != 0 && $_POST['channel'] < 15) {
1047
				$input_errors[] = gettext("Channel selected is not valid for 802.11a or 802.11na.");
1048
			}
1049
		}
1050
		if (isset($_POST['standard']) && ($_POST['standard'] == "11b" || $_POST['standard'] == "11g")) {
1051
			if ($_POST['channel'] > 14) {
1052
				$input_errors[] = gettext("Channel selected is not valid for 802.11b or 802.11g.");
1053
			}
1054
		}
1055
		if (!empty($_POST['protmode']) && !in_array($_POST['protmode'], array("off", "cts", "rtscts"))) {
1056
			$input_errors[] = gettext("Invalid option chosen for OFDM Protection Mode");
1057
		}
1058
1059
		if ($_POST['passphrase']) {
1060
			$passlen = strlen($_POST['passphrase']);
1061
			if ($passlen < 8 || $passlen > 63) {
1062
				$input_errors[] = gettext("The WPA passphrase must be between 8 and 63 characters long.");
1063
			}
1064
		}
1065
1066
		if ($_POST['wpa_enable'] == "yes") {
1067
			if (empty($_POST['passphrase']) && stristr($_POST['wpa_key_mgmt'], "WPA-PSK")) {
1068
				$input_errors[] = gettext("A WPA Passphrase must be specified when WPA PSK is enabled.");
1069
			}
1070 5f120301 Viktor G
			if (($_POST['mode'] == 'bss') & ($_POST['wpa_key_mgmt'] == "WPA-EAP") &&
1071
			    ($_POST['wpa_eap_client_mode'] != 'tls')) {
1072
				if (empty($_POST['wpa_eap_inner_id'])) {
1073
					$input_errors[] = gettext("An Inner Authentication Identity must be specified " .
1074
					    "when PEAP/TTLS authentication method is selected.");
1075
				}
1076
				if (empty($_POST['wpa_eap_inner_password'])) {
1077
					$input_errors[] = gettext("An Inner Authentication Passphrase must be specified " .
1078
					    "when PEAP/TTLS authentication method is selected.");
1079
				}
1080
			}
1081 68933ba7 Stephen Beaver
		}
1082
	}
1083 c8b10b4c Stephen Beaver
1084
	if ($_POST['ppp_password'] != $_POST['ppp_password_confirm']) {
1085
		$input_errors[] = gettext("PPP Password and confirmed password must match!");
1086
	}
1087
1088 6fb95fa2 heper
	if ($_POST['pppoe_password'] != $_POST['pppoe_password_confirm']) {
1089 c8b10b4c Stephen Beaver
		$input_errors[] = gettext("PPPoE Password and confirmed password must match!");
1090
	}
1091
1092
	if ($_POST['pptp_password'] != $_POST['pptp_password_confirm']) {
1093
		$input_errors[] = gettext("PTPP Password and confirmed password must match!");
1094
	}
1095
1096 f1bb5c7f Phil Davis
	if ($_POST['gatewayip4']) {
1097
		// The user wants to add an IPv4 gateway - validate the settings
1098
		$gateway_settings4 = array();
1099
1100
		$gateway_settings4['name'] = $_POST['gatewayname4'];
1101
		$gateway_settings4['interface'] = $_POST['if'];
1102
		$gateway_settings4['gateway'] = $_POST['gatewayip4'];
1103
		$gateway_settings4['descr'] = $_POST['gatewaydescr4'];
1104
		$gateway_settings4['defaultgw'] = $_POST['defaultgw4'];
1105 264f4423 PiBa-NL
		$gateway_settings4['ipprotocol'] = 'inet';
1106 f1bb5c7f Phil Davis
		$gw_input_errors = validate_gateway($gateway_settings4, '', $_POST['ipaddr'], $_POST['subnet']);
1107
		foreach ($gw_input_errors as $input_error_text) {
1108
			$input_errors[] = $input_error_text;
1109
		}
1110
	}
1111
1112
	if ($_POST['gatewayip6']) {
1113
		// The user wants to add an IPv6 gateway - validate the settings
1114
		$gateway_settings6 = array();
1115
1116
		$gateway_settings6['name'] = $_POST['gatewayname6'];
1117
		$gateway_settings6['interface'] = $_POST['if'];
1118
		$gateway_settings6['gateway'] = $_POST['gatewayip6'];
1119
		$gateway_settings6['descr'] = $_POST['gatewaydescr6'];
1120
		$gateway_settings6['defaultgw'] = $_POST['defaultgw6'];
1121 264f4423 PiBa-NL
		$gateway_settings6['ipprotocol'] = 'inet6';
1122 f1bb5c7f Phil Davis
		$gw_input_errors = validate_gateway($gateway_settings6, '', $_POST['ipaddrv6'], $_POST['subnetv6']);
1123
		foreach ($gw_input_errors as $input_error_text) {
1124
			$input_errors[] = $input_error_text;
1125
		}
1126
	}
1127
1128 68933ba7 Stephen Beaver
	if (!$input_errors) {
1129 66fd7b47 Phil Davis
		// These 3 fields can be a list of multiple data items when used for MLPPP.
1130
		// The UI in this code only processes the first of the list, so save the data here then we can preserve any other entries.
1131
		$poriginal['pptp_localip'] = explode(",", $a_ppps[$pppid]['localip']);
1132
		$poriginal['pptp_subnet'] = explode(",", $a_ppps[$pppid]['subnet']);
1133
		$poriginal['pptp_remote'] = explode(",", $a_ppps[$pppid]['gateway']);
1134
1135 68933ba7 Stephen Beaver
		if ($wancfg['ipaddr'] != $_POST['type']) {
1136
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1137
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
1138
				unset($a_ppps[$pppid]);
1139
			} else if ($wancfg['ipaddr'] == "dhcp") {
1140
				kill_dhclient_process($wancfg['if']);
1141
			}
1142 dd3d48af Viktor G
			if (($wancfg['ipaddrv6'] == "dhcp6") && ($_POST['type6'] != "dhcp6")) {
1143
				interface_dhcpv6_configure($if, $wancfg, true);
1144 68933ba7 Stephen Beaver
			}
1145
		}
1146
		$ppp = array();
1147
		if ($wancfg['ipaddr'] != "ppp") {
1148
			unset($wancfg['ipaddr']);
1149
		}
1150
		if ($wancfg['ipaddrv6'] != "ppp") {
1151
			unset($wancfg['ipaddrv6']);
1152
		}
1153
		unset($wancfg['subnet']);
1154
		unset($wancfg['gateway']);
1155
		unset($wancfg['subnetv6']);
1156
		unset($wancfg['gatewayv6']);
1157
		unset($wancfg['dhcphostname']);
1158
		unset($wancfg['dhcprejectfrom']);
1159
		unset($wancfg['dhcp6-duid']);
1160
		unset($wancfg['dhcp6-ia-pd-len']);
1161
		unset($wancfg['dhcp6-ia-pd-send-hint']);
1162
		unset($wancfg['dhcp6prefixonly']);
1163
		unset($wancfg['dhcp6usev4iface']);
1164 9210d0aa Viktor Gurov
		unset($wancfg['slaacusev4iface']);
1165 b7331383 marjohn56
		unset($wancfg['ipv6usev4iface']);
1166 68933ba7 Stephen Beaver
		unset($wancfg['track6-interface']);
1167
		unset($wancfg['track6-prefix-id']);
1168 8c661bc8 marjohn56
		unset($wancfg['dhcp6withoutra']);
1169 6b8680a7 marjohn56
		unset($wancfg['dhcp6vlanenable']);
1170
		unset($wancfg['dhcp6cvpt']);
1171 68933ba7 Stephen Beaver
		unset($wancfg['prefix-6rd']);
1172
		unset($wancfg['prefix-6rd-v4plen']);
1173
		unset($wancfg['gateway-6rd']);
1174
1175 62ed56dc Luiz Souza
		unset($wancfg['dhcpvlanenable']);
1176
		unset($wancfg['dhcpcvpt']);
1177
1178 68933ba7 Stephen Beaver
		unset($wancfg['adv_dhcp_pt_timeout']);
1179
		unset($wancfg['adv_dhcp_pt_retry']);
1180
		unset($wancfg['adv_dhcp_pt_select_timeout']);
1181
		unset($wancfg['adv_dhcp_pt_reboot']);
1182
		unset($wancfg['adv_dhcp_pt_backoff_cutoff']);
1183
		unset($wancfg['adv_dhcp_pt_initial_interval']);
1184
1185
		unset($wancfg['adv_dhcp_pt_values']);
1186
1187
		unset($wancfg['adv_dhcp_send_options']);
1188
		unset($wancfg['adv_dhcp_request_options']);
1189
		unset($wancfg['adv_dhcp_required_options']);
1190
		unset($wancfg['adv_dhcp_option_modifiers']);
1191
1192
		unset($wancfg['adv_dhcp_config_advanced']);
1193
		unset($wancfg['adv_dhcp_config_file_override']);
1194
		unset($wancfg['adv_dhcp_config_file_override_path']);
1195
1196
		unset($wancfg['adv_dhcp6_interface_statement_send_options']);
1197
		unset($wancfg['adv_dhcp6_interface_statement_request_options']);
1198
		unset($wancfg['adv_dhcp6_interface_statement_information_only_enable']);
1199
		unset($wancfg['adv_dhcp6_interface_statement_script']);
1200
1201
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_enable']);
1202
		unset($wancfg['adv_dhcp6_id_assoc_statement_address']);
1203
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_id']);
1204
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_pltime']);
1205
		unset($wancfg['adv_dhcp6_id_assoc_statement_address_vltime']);
1206
1207
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_enable']);
1208
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix']);
1209
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_id']);
1210
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime']);
1211
		unset($wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime']);
1212
1213
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_id']);
1214
		unset($wancfg['adv_dhcp6_prefix_interface_statement_sla_len']);
1215 58a185ae marjohn56
		unset($wancfg['adv_dhcp6_prefix_selected_interface']);
1216 68933ba7 Stephen Beaver
1217
		unset($wancfg['adv_dhcp6_authentication_statement_authname']);
1218
		unset($wancfg['adv_dhcp6_authentication_statement_protocol']);
1219
		unset($wancfg['adv_dhcp6_authentication_statement_algorithm']);
1220
		unset($wancfg['adv_dhcp6_authentication_statement_rdm']);
1221
1222
		unset($wancfg['adv_dhcp6_key_info_statement_keyname']);
1223
		unset($wancfg['adv_dhcp6_key_info_statement_realm']);
1224
		unset($wancfg['adv_dhcp6_key_info_statement_keyid']);
1225
		unset($wancfg['adv_dhcp6_key_info_statement_secret']);
1226
		unset($wancfg['adv_dhcp6_key_info_statement_expire']);
1227
1228
		unset($wancfg['adv_dhcp6_config_advanced']);
1229
		unset($wancfg['adv_dhcp6_config_file_override']);
1230
		unset($wancfg['adv_dhcp6_config_file_override_path']);
1231
1232
		unset($wancfg['pppoe_password']);
1233
		unset($wancfg['pptp_username']);
1234
		unset($wancfg['pptp_password']);
1235 8e267d3b Viktor G
		unset($wancfg['l2tp_secret']);
1236 68933ba7 Stephen Beaver
		unset($wancfg['provider']);
1237 71465708 Viktor G
		unset($wancfg['hostuniq']);
1238 68933ba7 Stephen Beaver
		unset($wancfg['ondemand']);
1239
		unset($wancfg['timeout']);
1240
		if (empty($wancfg['pppoe']['pppoe-reset-type'])) {
1241
			unset($wancfg['pppoe']['pppoe-reset-type']);
1242
		}
1243
		unset($wancfg['local']);
1244
1245
		unset($wancfg['remote']);
1246
		if (is_array($a_ppps[$pppid]) && in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
1247
			if ($wancfg['ipaddr'] != 'ppp') {
1248
				unset($a_ppps[$pppid]['apn']);
1249
				unset($a_ppps[$pppid]['phone']);
1250
				unset($a_ppps[$pppid]['provider']);
1251
				unset($a_ppps[$pppid]['ondemand']);
1252
			}
1253
			if (in_array($wancfg['ipaddr'], array("pppoe", "pptp", "l2tp"))) {
1254
				unset($a_ppps[$pppid]['localip']);
1255
				unset($a_ppps[$pppid]['subnet']);
1256
				unset($a_ppps[$pppid]['gateway']);
1257
			}
1258
			if ($wancfg['ipaddr'] != 'pppoe') {
1259
				unset($a_ppps[$pppid]['pppoe-reset-type']);
1260 71465708 Viktor G
				unset($a_ppps[$pppid]['hostuniq']);
1261 68933ba7 Stephen Beaver
			}
1262
			if ($wancfg['type'] != $_POST['type']) {
1263
				unset($a_ppps[$pppid]['idletimeout']);
1264
			}
1265
		}
1266
1267
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
1268
		$wancfg['enable'] = $_POST['enable'] == "yes" ? true : false;
1269
1270
		/* let return_gateways_array() do the magic on dynamic interfaces for us */
1271
		switch ($_POST['type']) {
1272
			case "staticv4":
1273
				$wancfg['ipaddr'] = $_POST['ipaddr'];
1274
				$wancfg['subnet'] = $_POST['subnet'];
1275
				if ($_POST['gateway'] != "none") {
1276
					$wancfg['gateway'] = $_POST['gateway'];
1277
				}
1278
				break;
1279
			case "dhcp":
1280
				$wancfg['ipaddr'] = "dhcp";
1281
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
1282
				$wancfg['alias-address'] = $_POST['alias-address'];
1283
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
1284
				$wancfg['dhcprejectfrom'] = $_POST['dhcprejectfrom'];
1285
1286
				$wancfg['adv_dhcp_pt_timeout'] = $_POST['adv_dhcp_pt_timeout'];
1287
				$wancfg['adv_dhcp_pt_retry'] = $_POST['adv_dhcp_pt_retry'];
1288
				$wancfg['adv_dhcp_pt_select_timeout'] = $_POST['adv_dhcp_pt_select_timeout'];
1289
				$wancfg['adv_dhcp_pt_reboot'] = $_POST['adv_dhcp_pt_reboot'];
1290
				$wancfg['adv_dhcp_pt_backoff_cutoff'] = $_POST['adv_dhcp_pt_backoff_cutoff'];
1291
				$wancfg['adv_dhcp_pt_initial_interval'] = $_POST['adv_dhcp_pt_initial_interval'];
1292
1293
				$wancfg['adv_dhcp_pt_values'] = $_POST['adv_dhcp_pt_values'];
1294
1295
				$wancfg['adv_dhcp_send_options'] = $_POST['adv_dhcp_send_options'];
1296
				$wancfg['adv_dhcp_request_options'] = $_POST['adv_dhcp_request_options'];
1297
				$wancfg['adv_dhcp_required_options'] = $_POST['adv_dhcp_required_options'];
1298
				$wancfg['adv_dhcp_option_modifiers'] = $_POST['adv_dhcp_option_modifiers'];
1299
1300
				$wancfg['adv_dhcp_config_advanced'] = $_POST['adv_dhcp_config_advanced'];
1301
				$wancfg['adv_dhcp_config_file_override'] = $_POST['adv_dhcp_config_file_override'];
1302
				$wancfg['adv_dhcp_config_file_override_path'] = $_POST['adv_dhcp_config_file_override_path'];
1303
1304
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
1305
				if ($gateway_item) {
1306
					$a_gateways[] = $gateway_item;
1307
				}
1308 62ed56dc Luiz Souza
				if ($_POST['dhcpvlanenable'] == "yes") {
1309
					$wancfg['dhcpvlanenable'] = true;
1310
				}
1311
				if (!empty($_POST['dhcpcvpt'])) {
1312
					$wancfg['dhcpcvpt'] = $_POST['dhcpcvpt'];
1313
				} else {
1314
					unset($wancfg['dhcpcvpt']);
1315
				}
1316 68933ba7 Stephen Beaver
				break;
1317
			case "ppp":
1318
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1319
				$a_ppps[$pppid]['type'] = $_POST['type'];
1320
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1321
				$a_ppps[$pppid]['ports'] = $_POST['port'];
1322
				$a_ppps[$pppid]['username'] = $_POST['ppp_username'];
1323 76d6d925 Stephen Beaver
				if ($_POST['ppp_password'] != DMYPWD) {
1324
					$a_ppps[$pppid]['password'] = base64_encode($_POST['ppp_password']);
1325
				}
1326 68933ba7 Stephen Beaver
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
1327
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
1328
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
1329
				$wancfg['ipaddr'] = $_POST['type'];
1330
				break;
1331
1332
			case "pppoe":
1333
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1334
				$a_ppps[$pppid]['type'] = $_POST['type'];
1335
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1336 6a9435a6 Viktor G
				if (isset($_POST['ppp_port'])) {
1337
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1338
				} else {
1339
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1340
				}
1341 68933ba7 Stephen Beaver
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
1342 76d6d925 Stephen Beaver
				if ($_POST['pppoe_password'] != DMYPWD) {
1343
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
1344
				}
1345 68933ba7 Stephen Beaver
				if (!empty($_POST['provider'])) {
1346
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
1347
				} else {
1348
					$a_ppps[$pppid]['provider'] = true;
1349
				}
1350 71465708 Viktor G
				if (!empty($_POST['hostuniq'])) {
1351
					$a_ppps[$pppid]['hostuniq'] = strtolower($_POST['hostuniq']);
1352
				} else {
1353
					$a_ppps[$pppid]['hostuniq'] = true;
1354
				}
1355 68933ba7 Stephen Beaver
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
1356
				if (!empty($_POST['pppoe_idletimeout'])) {
1357
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
1358
				} else {
1359
					unset($a_ppps[$pppid]['idletimeout']);
1360
				}
1361
1362
				if (!empty($_POST['pppoe-reset-type'])) {
1363
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
1364
				} else {
1365
					unset($a_ppps[$pppid]['pppoe-reset-type']);
1366
				}
1367
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1368
				$wancfg['ipaddr'] = $_POST['type'];
1369
				if ($gateway_item) {
1370
					$a_gateways[] = $gateway_item;
1371
				}
1372
1373
				break;
1374
			case "pptp":
1375
			case "l2tp":
1376
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
1377
				$a_ppps[$pppid]['type'] = $_POST['type'];
1378
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
1379 6a9435a6 Viktor G
				if (isset($_POST['ppp_port'])) {
1380
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
1381
				} else {
1382
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
1383
				}
1384 68933ba7 Stephen Beaver
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
1385 76d6d925 Stephen Beaver
				if ($_POST['pptp_password'] != DMYPWD) {
1386
					$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
1387
				}
1388 8e267d3b Viktor G
				if (($_POST['type'] == 'l2tp') && (!empty($_POST['l2tp_secret']))) {
1389
					$a_ppps[$pppid]['secret'] = base64_encode($_POST['l2tp_secret']);
1390
				} else {
1391
					unset($a_ppps[$pppid]['secret']);
1392
				}
1393 66fd7b47 Phil Davis
				// Replace the first (0) entry with the posted data. Preserve any other entries that might be there.
1394
				$poriginal['pptp_localip'][0] = $_POST['pptp_local0'];
1395
				$a_ppps[$pppid]['localip'] = implode(',', $poriginal['pptp_localip']);
1396
				$poriginal['pptp_subnet'][0] = $_POST['pptp_subnet0'];
1397
				$a_ppps[$pppid]['subnet'] = implode(',', $poriginal['pptp_subnet']);
1398
				$poriginal['pptp_remote'][0] = $_POST['pptp_remote0'];
1399
				$a_ppps[$pppid]['gateway'] = implode(',', $poriginal['pptp_remote']);
1400 68933ba7 Stephen Beaver
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
1401
				if (!empty($_POST['pptp_idletimeout'])) {
1402
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
1403
				} else {
1404
					unset($a_ppps[$pppid]['idletimeout']);
1405
				}
1406
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
1407
				$wancfg['ipaddr'] = $_POST['type'];
1408
				if ($gateway_item) {
1409
					$a_gateways[] = $gateway_item;
1410
				}
1411
				break;
1412
			case "none":
1413
				break;
1414
		}
1415
		switch ($_POST['type6']) {
1416
			case "staticv6":
1417
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
1418
				$wancfg['subnetv6'] = $_POST['subnetv6'];
1419 b7331383 marjohn56
				if ($_POST['ipv6usev4iface'] == "yes") {
1420
					$wancfg['ipv6usev4iface'] = true;
1421
				}
1422 68933ba7 Stephen Beaver
				if ($_POST['gatewayv6'] != "none") {
1423
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
1424
				}
1425
				break;
1426
			case "slaac":
1427
				$wancfg['ipaddrv6'] = "slaac";
1428 9210d0aa Viktor Gurov
				if ($_POST['slaacusev4iface'] == "yes") {
1429
					$wancfg['slaacusev4iface'] = true;
1430 c9b49393 Viktor Gurov
				}
1431 68933ba7 Stephen Beaver
				break;
1432
			case "dhcp6":
1433
				$wancfg['ipaddrv6'] = "dhcp6";
1434
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
1435
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
1436
				if ($_POST['dhcp6-ia-pd-send-hint'] == "yes") {
1437
					$wancfg['dhcp6-ia-pd-send-hint'] = true;
1438
				}
1439
				if ($_POST['dhcp6prefixonly'] == "yes") {
1440
					$wancfg['dhcp6prefixonly'] = true;
1441
				}
1442
				if ($_POST['dhcp6usev4iface'] == "yes") {
1443
					$wancfg['dhcp6usev4iface'] = true;
1444
				}
1445 8c661bc8 marjohn56
				if ($_POST['dhcp6withoutra'] == "yes") {
1446
					$wancfg['dhcp6withoutra'] = true;
1447
				}
1448 6b8680a7 marjohn56
				if ($_POST['dhcp6vlanenable'] == "yes") {
1449
					$wancfg['dhcp6vlanenable'] = true;
1450
				}
1451
				if (!empty($_POST['dhcp6cvpt'])) {
1452
					$wancfg['dhcp6cvpt'] = $_POST['dhcp6cvpt'];
1453
				} else {
1454
					unset($wancfg['dhcp6cvpt']);
1455
				}
1456
1457 68933ba7 Stephen Beaver
				if (!empty($_POST['adv_dhcp6_interface_statement_send_options'])) {
1458
					$wancfg['adv_dhcp6_interface_statement_send_options'] = $_POST['adv_dhcp6_interface_statement_send_options'];
1459
				}
1460
				if (!empty($_POST['adv_dhcp6_interface_statement_request_options'])) {
1461
					$wancfg['adv_dhcp6_interface_statement_request_options'] = $_POST['adv_dhcp6_interface_statement_request_options'];
1462
				}
1463
				if (isset($_POST['adv_dhcp6_interface_statement_information_only_enable'])) {
1464
					$wancfg['adv_dhcp6_interface_statement_information_only_enable'] = $_POST['adv_dhcp6_interface_statement_information_only_enable'];
1465
				}
1466
				if (!empty($_POST['adv_dhcp6_interface_statement_script'])) {
1467
					$wancfg['adv_dhcp6_interface_statement_script'] = $_POST['adv_dhcp6_interface_statement_script'];
1468
				}
1469
1470
				if (isset($_POST['adv_dhcp6_id_assoc_statement_address_enable'])) {
1471
					$wancfg['adv_dhcp6_id_assoc_statement_address_enable'] = $_POST['adv_dhcp6_id_assoc_statement_address_enable'];
1472
				}
1473
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address'])) {
1474
					$wancfg['adv_dhcp6_id_assoc_statement_address'] = $_POST['adv_dhcp6_id_assoc_statement_address'];
1475
				}
1476
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_address_id'])) {
1477
					$wancfg['adv_dhcp6_id_assoc_statement_address_id'] = $_POST['adv_dhcp6_id_assoc_statement_address_id'];
1478
				}
1479
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_pltime'])) {
1480
					$wancfg['adv_dhcp6_id_assoc_statement_address_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_pltime'];
1481
				}
1482
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_address_vltime'])) {
1483
					$wancfg['adv_dhcp6_id_assoc_statement_address_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_address_vltime'];
1484
				}
1485
1486
				if (isset($_POST['adv_dhcp6_id_assoc_statement_prefix_enable'])) {
1487
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_enable'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_enable'];
1488
				}
1489
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix'])) {
1490
					$wancfg['adv_dhcp6_id_assoc_statement_prefix'] = $_POST['adv_dhcp6_id_assoc_statement_prefix'];
1491
				}
1492
				if (is_numericint($_POST['adv_dhcp6_id_assoc_statement_prefix_id'])) {
1493
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_id'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_id'];
1494
				}
1495
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'])) {
1496
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_pltime'];
1497
				}
1498
				if (!empty($_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'])) {
1499
					$wancfg['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $_POST['adv_dhcp6_id_assoc_statement_prefix_vltime'];
1500
				}
1501
1502
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_id'])) {
1503
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_id'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_id'];
1504
				}
1505
				if (is_numericint($_POST['adv_dhcp6_prefix_interface_statement_sla_len'])) {
1506
					$wancfg['adv_dhcp6_prefix_interface_statement_sla_len'] = $_POST['adv_dhcp6_prefix_interface_statement_sla_len'];
1507
				}
1508 58a185ae marjohn56
				if (!empty($_POST['adv_dhcp6_prefix_selected_interface'])) {
1509
					$wancfg['adv_dhcp6_prefix_selected_interface'] = $_POST['adv_dhcp6_prefix_selected_interface'];
1510
				}
1511 68933ba7 Stephen Beaver
				if (!empty($_POST['adv_dhcp6_authentication_statement_authname'])) {
1512
					$wancfg['adv_dhcp6_authentication_statement_authname'] = $_POST['adv_dhcp6_authentication_statement_authname'];
1513
				}
1514
				if (!empty($_POST['adv_dhcp6_authentication_statement_protocol'])) {
1515
					$wancfg['adv_dhcp6_authentication_statement_protocol'] = $_POST['adv_dhcp6_authentication_statement_protocol'];
1516
				}
1517
				if (!empty($_POST['adv_dhcp6_authentication_statement_algorithm'])) {
1518
					$wancfg['adv_dhcp6_authentication_statement_algorithm'] = $_POST['adv_dhcp6_authentication_statement_algorithm'];
1519
				}
1520
				if (!empty($_POST['adv_dhcp6_authentication_statement_rdm'])) {
1521
					$wancfg['adv_dhcp6_authentication_statement_rdm'] = $_POST['adv_dhcp6_authentication_statement_rdm'];
1522
				}
1523
1524
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyname'])) {
1525
					$wancfg['adv_dhcp6_key_info_statement_keyname'] = $_POST['adv_dhcp6_key_info_statement_keyname'];
1526
				}
1527
				if (!empty($_POST['adv_dhcp6_key_info_statement_realm'])) {
1528
					$wancfg['adv_dhcp6_key_info_statement_realm'] = $_POST['adv_dhcp6_key_info_statement_realm'];
1529
				}
1530
				if (!empty($_POST['adv_dhcp6_key_info_statement_keyid'])) {
1531
					$wancfg['adv_dhcp6_key_info_statement_keyid'] = $_POST['adv_dhcp6_key_info_statement_keyid'];
1532
				}
1533
				if (!empty($_POST['adv_dhcp6_key_info_statement_secret'])) {
1534
					$wancfg['adv_dhcp6_key_info_statement_secret'] = $_POST['adv_dhcp6_key_info_statement_secret'];
1535
				}
1536
				if (!empty($_POST['adv_dhcp6_key_info_statement_expire'])) {
1537
					$wancfg['adv_dhcp6_key_info_statement_expire'] = $_POST['adv_dhcp6_key_info_statement_expire'];
1538
				}
1539
1540
				if (!empty($_POST['adv_dhcp6_config_advanced'])) {
1541
					$wancfg['adv_dhcp6_config_advanced'] = $_POST['adv_dhcp6_config_advanced'];
1542
				}
1543
				if (!empty($_POST['adv_dhcp6_config_file_override'])) {
1544
					$wancfg['adv_dhcp6_config_file_override'] = $_POST['adv_dhcp6_config_file_override'];
1545
				}
1546
				if (!empty($_POST['adv_dhcp6_config_file_override_path'])) {
1547
					$wancfg['adv_dhcp6_config_file_override_path'] = $_POST['adv_dhcp6_config_file_override_path'];
1548
				}
1549
1550
				if ($gateway_item) {
1551
					$a_gateways[] = $gateway_item;
1552
				}
1553
				break;
1554
			case "6rd":
1555
				$wancfg['ipaddrv6'] = "6rd";
1556
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
1557
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
1558
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
1559
				if ($gateway_item) {
1560
					$a_gateways[] = $gateway_item;
1561
				}
1562
				break;
1563
			case "6to4":
1564
				$wancfg['ipaddrv6'] = "6to4";
1565
				break;
1566
			case "track6":
1567
				$wancfg['ipaddrv6'] = "track6";
1568
				$wancfg['track6-interface'] = $_POST['track6-interface'];
1569
				if ($_POST['track6-prefix-id--hex'] === "") {
1570
					$wancfg['track6-prefix-id'] = 0;
1571 b6f6210a jim-p
				} else if (ctype_xdigit($_POST['track6-prefix-id--hex'])) {
1572 68933ba7 Stephen Beaver
					$wancfg['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16);
1573
				} else {
1574
					$wancfg['track6-prefix-id'] = 0;
1575
				}
1576
				break;
1577
			case "none":
1578
				break;
1579
		}
1580
		handle_pppoe_reset($_POST);
1581
1582
		if ($_POST['blockpriv'] == "yes") {
1583
			$wancfg['blockpriv'] = true;
1584
		} else {
1585
			unset($wancfg['blockpriv']);
1586
		}
1587
		if ($_POST['blockbogons'] == "yes") {
1588
			$wancfg['blockbogons'] = true;
1589
		} else {
1590
			unset($wancfg['blockbogons']);
1591
		}
1592
		$wancfg['spoofmac'] = $_POST['spoofmac'];
1593
		if (empty($_POST['mtu'])) {
1594
			unset($wancfg['mtu']);
1595
		} else {
1596
			$wancfg['mtu'] = $_POST['mtu'];
1597
		}
1598
		if (empty($_POST['mss'])) {
1599
			unset($wancfg['mss']);
1600
		} else {
1601
			$wancfg['mss'] = $_POST['mss'];
1602
		}
1603
		if (empty($_POST['mediaopt'])) {
1604
			unset($wancfg['media']);
1605
			unset($wancfg['mediaopt']);
1606
		} else {
1607
			$mediaopts = explode(' ', $_POST['mediaopt']);
1608
			if ($mediaopts[0] != '') {
1609
				$wancfg['media'] = $mediaopts[0];
1610
			}
1611
			if ($mediaopts[1] != '') {
1612
				$wancfg['mediaopt'] = $mediaopts[1];
1613
			} else {
1614
				unset($wancfg['mediaopt']);
1615
			}
1616
		}
1617
		if (isset($wancfg['wireless'])) {
1618
			handle_wireless_post();
1619
		}
1620
1621 e85ae672 Renato Botelho do Couto
		write_config("Interfaces settings changed");
1622 68933ba7 Stephen Beaver
1623 f1bb5c7f Phil Davis
		if ($_POST['gatewayip4']) {
1624
			save_gateway($gateway_settings4);
1625
		}
1626
1627
		if ($_POST['gatewayip6']) {
1628
			save_gateway($gateway_settings6);
1629
		}
1630
1631 68933ba7 Stephen Beaver
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
1632
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
1633
		} else {
1634
			$toapplylist = array();
1635
		}
1636
		$toapplylist[$if]['ifcfg'] = $old_wancfg;
1637
		$toapplylist[$if]['ppps'] = $old_ppps;
1638
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
1639
1640
		mark_subsystem_dirty('interfaces');
1641
1642
		/* regenerate cron settings/crontab file */
1643
		configure_cron();
1644
1645
		header("Location: interfaces.php?if={$if}");
1646
		exit;
1647
	}
1648 c0948c6c Renato Botelho
1649 6a9435a6 Viktor G
	/* keep port value, see https://redmine.pfsense.org/issues/12498 */
1650
	if (!empty($_POST['ppp_port'])) {
1651
		$pconfig['port'] = $_POST['ppp_port'];
1652
	}
1653
1654 4401107f Steve Beaver
} // end if ($_POST['save'])
1655 270c4607 Scott Ullrich
1656 25a6411a Scott Ullrich
function handle_wireless_post() {
1657 2d5c75fa Reid Linnemann
	global $_POST, $config, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
1658 68933ba7 Stephen Beaver
	if (!is_array($wancfg['wireless'])) {
1659
		$wancfg['wireless'] = array();
1660
	}
1661
	$wancfg['wireless']['standard'] = $_POST['standard'];
1662
	$wancfg['wireless']['mode'] = $_POST['mode'];
1663
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
1664
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
1665
	$wancfg['wireless']['channel'] = $_POST['channel'];
1666 91fd7459 Viktor G
	$wancfg['wireless']['channel_width'] = $_POST['channel_width'];
1667 68933ba7 Stephen Beaver
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
1668
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
1669
	$wancfg['wireless']['distance'] = $_POST['distance'];
1670
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
1671
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
1672
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
1673
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
1674
		foreach ($wl_countries_attr as $wl_country) {
1675
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
1676
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
1677
				break;
1678
			}
1679
		}
1680
	}
1681
	if (!is_array($wancfg['wireless']['wpa'])) {
1682
		$wancfg['wireless']['wpa'] = array();
1683
	}
1684
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
1685
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
1686
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
1687
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
1688
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
1689
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
1690
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
1691
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
1692 5f120301 Viktor G
	$wancfg['wireless']['wpa']['wpa_eap_client_mode'] = $_POST['wpa_eap_client_mode'];
1693
	$wancfg['wireless']['wpa']['wpa_eap_inner_auth'] = $_POST['wpa_eap_inner_auth'];
1694
	$wancfg['wireless']['wpa']['wpa_eap_inner_id'] = $_POST['wpa_eap_inner_id'];
1695
	$wancfg['wireless']['wpa']['wpa_eap_inner_password'] = base64_encode($_POST['wpa_eap_inner_password']);
1696
	$wancfg['wireless']['wpa']['wpa_eap_cert'] = $_POST['wpa_eap_cert'];
1697
	$wancfg['wireless']['wpa']['wpa_eap_ca'] = $_POST['wpa_eap_ca'];
1698 68933ba7 Stephen Beaver
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
1699
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
1700
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
1701
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
1702
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
1703
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
1704
1705
	if ($_POST['persistcommonwireless'] == "yes") {
1706
		if (!is_array($config['wireless'])) {
1707 721fafba Christian McDonald
			config_set_path('wireless', array());
1708 68933ba7 Stephen Beaver
		}
1709 2d5c75fa Reid Linnemann
		if (!is_array(config_get_path('wireless/interfaces'))) {
1710 721fafba Christian McDonald
			config_set_path('wireless/interfaces', array());
1711 68933ba7 Stephen Beaver
		}
1712
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif])) {
1713
			$config['wireless']['interfaces'][$wlanbaseif] = array();
1714
		}
1715
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif])) {
1716 7e3ea4a8 Christian McDonald
		config_del_path("wireless/interfaces/{$wlanbaseif}");
1717 68933ba7 Stephen Beaver
	}
1718
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity'])) {
1719
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
1720
	} else if (isset($wancfg['wireless']['diversity'])) {
1721
		unset($wancfg['wireless']['diversity']);
1722
	}
1723
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna'])) {
1724
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
1725
	} else if (isset($wancfg['wireless']['txantenna'])) {
1726
		unset($wancfg['wireless']['txantenna']);
1727
	}
1728
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna'])) {
1729
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
1730
	} else if (isset($wancfg['wireless']['rxantenna'])) {
1731
		unset($wancfg['wireless']['rxantenna']);
1732
	}
1733
	if ($_POST['hidessid_enable'] == "yes") {
1734
		$wancfg['wireless']['hidessid']['enable'] = true;
1735
	} else if (isset($wancfg['wireless']['hidessid']['enable'])) {
1736
		unset($wancfg['wireless']['hidessid']['enable']);
1737
	}
1738
	if ($_POST['mac_acl_enable'] == "yes") {
1739
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
1740
	} else if (isset($wancfg['wireless']['wpa']['mac_acl_enable'])) {
1741
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
1742
	}
1743
	if ($_POST['rsn_preauth'] == "yes") {
1744
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
1745
	} else {
1746
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
1747
	}
1748
	if ($_POST['ieee8021x'] == "yes") {
1749
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
1750
	} else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable'])) {
1751
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
1752
	}
1753
	if ($_POST['wpa_strict_rekey'] == "yes") {
1754
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
1755
	} else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey'])) {
1756
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
1757
	}
1758
	if ($_POST['debug_mode'] == "yes") {
1759
		$wancfg['wireless']['wpa']['debug_mode'] = true;
1760
	} else if (isset($wancfg['wireless']['wpa']['debug_mode'])) {
1761
		sunset($wancfg['wireless']['wpa']['debug_mode']);
1762
	}
1763
	if ($_POST['wpa_enable'] == "yes") {
1764
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
1765
	} else if (isset($wancfg['wireless']['wpa']['enable'])) {
1766
		unset($wancfg['wireless']['wpa']['enable']);
1767
	}
1768
1769
	if ($_POST['wme_enable'] == "yes") {
1770
		if (!is_array($wancfg['wireless']['wme'])) {
1771
			$wancfg['wireless']['wme'] = array();
1772
		}
1773
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
1774
	} else if (isset($wancfg['wireless']['wme']['enable'])) {
1775
		unset($wancfg['wireless']['wme']['enable']);
1776
	}
1777
	if ($_POST['puremode'] == "11g") {
1778
		if (!is_array($wancfg['wireless']['pureg'])) {
1779
			$wancfg['wireless']['pureg'] = array();
1780
		}
1781
		$wancfg['wireless']['pureg']['enable'] = true;
1782
	} else if ($_POST['puremode'] == "11n") {
1783
		if (!is_array($wancfg['wireless']['puren'])) {
1784
			$wancfg['wireless']['puren'] = array();
1785
		}
1786
		$wancfg['wireless']['puren']['enable'] = true;
1787
	} else {
1788
		if (isset($wancfg['wireless']['pureg'])) {
1789
			unset($wancfg['wireless']['pureg']);
1790
		}
1791
		if (isset($wancfg['wireless']['puren'])) {
1792
			unset($wancfg['wireless']['puren']);
1793
		}
1794
	}
1795
	if ($_POST['apbridge_enable'] == "yes") {
1796
		if (!is_array($wancfg['wireless']['apbridge'])) {
1797
			$wancfg['wireless']['apbridge'] = array();
1798
		}
1799
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1800
	} else if (isset($wancfg['wireless']['apbridge']['enable'])) {
1801
		unset($wancfg['wireless']['apbridge']['enable']);
1802
	}
1803
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1804
		if (!is_array($wancfg['wireless']['turbo'])) {
1805
			$wancfg['wireless']['turbo'] = array();
1806
		}
1807
		$wancfg['wireless']['turbo']['enable'] = true;
1808
	} else if (isset($wancfg['wireless']['turbo']['enable'])) {
1809
		unset($wancfg['wireless']['turbo']['enable']);
1810
	}
1811
1812
	interface_sync_wireless_clones($wancfg, true);
1813 5b237745 Scott Ullrich
}
1814 7f43ca88 Scott Ullrich
1815 597330aa Erik Fonnesbeck
function check_wireless_mode() {
1816 68933ba7 Stephen Beaver
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1817
1818
	if ($wancfg['wireless']['mode'] == $_POST['mode']) {
1819
		return;
1820
	}
1821
1822
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) {
1823
		$clone_count = 1;
1824
	} else {
1825
		$clone_count = 0;
1826
	}
1827
1828 2d5c75fa Reid Linnemann
	foreach (config_get_path('wireless/clone', []) as $clone) {
1829
		if ($clone['if'] == $wlanbaseif) {
1830 68933ba7 Stephen Beaver
				$clone_count++;
1831
		}
1832
	}
1833
1834
	if ($clone_count > 1) {
1835
		$old_wireless_mode = $wancfg['wireless']['mode'];
1836
		$wancfg['wireless']['mode'] = $_POST['mode'];
1837
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1838 e4517c3c jim-p
			$input_errors[] = sprintf(gettext("Unable to change mode to %s. The maximum number of wireless clones supported in this mode may have been reached."), $wlan_modes[$wancfg['wireless']['mode']]);
1839 68933ba7 Stephen Beaver
		} else {
1840 414aa359 Renato Botelho
			pfSense_interface_destroy("{$wlanif}_");
1841 68933ba7 Stephen Beaver
		}
1842
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1843
	}
1844 597330aa Erik Fonnesbeck
}
1845
1846 509ca889 Evgeny Yurchenko
// Find all possible media options for the interface
1847
$mediaopts_list = array();
1848 2d5c75fa Reid Linnemann
$intrealname = config_get_path("interfaces/{$if}/if");
1849 281dede0 Renato Botelho do Couto
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1850
foreach ($mediaopts as $mediaopt) {
1851
	preg_match("/media (.*)/", $mediaopt, $matches);
1852
	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)) {
1853
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1854
		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1855
	} else {
1856
		// there is only media like "media 1000baseT"
1857
		array_push($mediaopts_list, $matches[1]);
1858 68933ba7 Stephen Beaver
	}
1859 509ca889 Evgeny Yurchenko
}
1860
1861 cc240e32 jim-p
$pgtitle = array(gettext("Interfaces"), "{$wancfg['descr']} ({$realifname})");
1862 b32dd0a6 jim-p
$shortcut_section = "interfaces";
1863 af1e2031 jim-p
1864 7957389b Viktor G
$types4 = array("ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP"));
1865
1866
if (!in_array($pconfig['type'], array("ppp", "pppoe", "pptp", "l2tp")) ||
1867
   !array_key_exists($a_ppps[$pppid]['ports'], get_configured_interface_list_by_realif())) { 
1868
	$types4 = array_merge(array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP")), $types4);
1869
}
1870
1871 feb88a14 smos
$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"));
1872 7f43ca88 Scott Ullrich
1873 ae4c4bac Stephen Beaver
// Get the MAC address
1874 f1bb5c7f Phil Davis
$defgatewayname4 = $wancfg['descr'] . "GW";
1875
$defgatewayname6 = $wancfg['descr'] . "GWv6";
1876 ae4c4bac Stephen Beaver
1877
function build_mediaopts_list() {
1878 68933ba7 Stephen Beaver
	global $mediaopts_list;
1879 a0509b13 Stephen Beaver
1880 0fc3de67 Phil Davis
	$list = [""	 =>	 gettext("Default (no preference, typically autoselect)"),
1881
			 " " =>	 gettext("------- Media Supported by this interface -------")
1882 68933ba7 Stephen Beaver
			];
1883 a0509b13 Stephen Beaver
1884 68933ba7 Stephen Beaver
	foreach ($mediaopts_list as $mediaopt) {
1885
		$list[$mediaopt] = $mediaopt;
1886
	}
1887 a0509b13 Stephen Beaver
1888 68933ba7 Stephen Beaver
	return($list);
1889 ae4c4bac Stephen Beaver
}
1890 9978e156 gnhb
1891 ae4c4bac Stephen Beaver
function build_gateway_list() {
1892 9f3f4276 Stephen Beaver
	global $a_gateways, $if;
1893 a0509b13 Stephen Beaver
1894 0fc3de67 Phil Davis
	$list = array("none" => gettext("None"));
1895 68933ba7 Stephen Beaver
	foreach ($a_gateways as $gateway) {
1896 b767ea71 jim-p
		if (empty($gateway)) {
1897
			continue;
1898
		}
1899 68933ba7 Stephen Beaver
		if (($gateway['interface'] == $if) && (is_ipaddrv4($gateway['gateway']))) {
1900
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1901
		}
1902
	}
1903 a0509b13 Stephen Beaver
1904 68933ba7 Stephen Beaver
	return($list);
1905 ae4c4bac Stephen Beaver
}
1906 1caf2209 Phil Davis
1907 9f3f4276 Stephen Beaver
function build_gatewayv6_list() {
1908
	global $a_gateways, $if;
1909
1910 0fc3de67 Phil Davis
	$list = array("none" => gettext("None"));
1911 9f3f4276 Stephen Beaver
	foreach ($a_gateways as $gateway) {
1912 b767ea71 jim-p
		if (empty($gateway)) {
1913
			continue;
1914
		}
1915 9f3f4276 Stephen Beaver
		if (($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1916
			$list[$gateway['name']] = $gateway['name'] . " - " . $gateway['gateway'];
1917
		}
1918
	}
1919
1920
	return($list);
1921
}
1922
1923 ae4c4bac Stephen Beaver
include("head.inc");
1924 4634cb48 Ermal Luçi
1925 aa82505e Phil Davis
if ($input_errors) {
1926 68933ba7 Stephen Beaver
	print_input_errors($input_errors);
1927 aa82505e Phil Davis
}
1928 a0509b13 Stephen Beaver
1929 aa82505e Phil Davis
if (is_subsystem_dirty('interfaces')) {
1930 3b3a95e5 Phil Davis
	print_apply_box(sprintf(gettext("The %s configuration has been changed."), $wancfg['descr']) . "<br />" .
1931 e4517c3c jim-p
					gettext("The changes must be applied to take effect.") . "<br />" .
1932 f4bed461 k-paulius
					gettext("Don't forget to adjust the DHCP Server range if needed after applying."));
1933 aa82505e Phil Davis
}
1934 a0509b13 Stephen Beaver
1935 44c42356 Phil Davis
if ($changes_applied) {
1936
	print_apply_result_box($retval);
1937 aa82505e Phil Davis
}
1938 ae4c4bac Stephen Beaver
1939 8f58b51b jim-p
$form = new Form();
1940 ae4c4bac Stephen Beaver
1941 5f88f964 k-paulius
$section = new Form_Section('General Configuration');
1942 ae4c4bac Stephen Beaver
1943
$section->addInput(new Form_Checkbox(
1944 68933ba7 Stephen Beaver
	'enable',
1945
	'Enable',
1946
	'Enable interface',
1947
	$pconfig['enable'],
1948
	'yes'
1949 ae4c4bac Stephen Beaver
));
1950
1951
$section->addInput(new Form_Input(
1952 68933ba7 Stephen Beaver
	'descr',
1953 1095b204 Phil Davis
	'*Description',
1954 68933ba7 Stephen Beaver
	'text',
1955
	$pconfig['descr']
1956 ae4c4bac Stephen Beaver
))->setHelp('Enter a description (name) for the interface here.');
1957
1958 cc240e32 jim-p
if ($show_address_controls) {
1959
	$section->addInput(new Form_Select(
1960
		'type',
1961
		'IPv4 Configuration Type',
1962
		$pconfig['type'],
1963
		$types4
1964
	));
1965
	$section->addInput(new Form_Select(
1966
		'type6',
1967
		'IPv6 Configuration Type',
1968
		$pconfig['type6'],
1969
		$types6
1970
	));
1971
} else {
1972
	$section->addInput(new Form_StaticText(
1973
		'IPv4/IPv6 Configuration',
1974
		"This interface type does not support manual address configuration on this page. "
1975
	));
1976 ee12dd78 Peter Feichtinger
	$form->addGlobal(new Form_Input(
1977 cc240e32 jim-p
		'type',
1978
		null,
1979
		'hidden',
1980
		'none'
1981
	));
1982 ee12dd78 Peter Feichtinger
	$form->addGlobal(new Form_Input(
1983 cc240e32 jim-p
		'type6',
1984
		null,
1985
		'hidden',
1986
		'none'
1987
	));
1988
}
1989 ae4c4bac Stephen Beaver
1990 a628e8ca Viktor G
if (!is_pseudo_interface($intrealname, true)) {
1991
	$macaddress = new Form_Input(
1992
		'spoofmac',
1993
		'MAC Address',
1994
		'text',
1995
		$pconfig['spoofmac'],
1996
		['placeholder' => 'xx:xx:xx:xx:xx:xx']
1997
	);
1998
1999
	if (interface_is_vlan($realifname)) {
2000
		$macaddress->setDisabled();
2001
		$macaddress->setHelp('The MAC address of a VLAN interface must be ' .
2002
		    'set on its parent interface');
2003
	} else {
2004
		$macaddress->setHelp('This field can be used to modify ("spoof") the ' .
2005
		    'MAC address of this interface.%sEnter a MAC address in the ' .
2006
		    'following format: xx:xx:xx:xx:xx:xx or leave blank.', '<br />');
2007
	}
2008 ae4c4bac Stephen Beaver
2009 a628e8ca Viktor G
	$section->addInput($macaddress);
2010
}
2011 ae4c4bac Stephen Beaver
2012 692b5e02 Stephen Beaver
$section->addInput(new Form_Input(
2013
	'mtu',
2014
	'MTU',
2015
	'number',
2016
	$pconfig['mtu']
2017 eaa948d6 NOYB
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
2018 692b5e02 Stephen Beaver
			'This is typically 1500 bytes but can vary in some circumstances.');
2019 ae4c4bac Stephen Beaver
2020
$section->addInput(new Form_Input(
2021 68933ba7 Stephen Beaver
	'mss',
2022
	'MSS',
2023
	'number',
2024
	$pconfig['mss']
2025 1d378c4e Viktor G
))->setHelp('If a value is entered in this field, then MSS clamping for TCP connections to the value entered above ' .
2026
	    'minus 40 for IPv4 (TCP/IPv4 header size) and minus 60 for IPv6 (TCP/IPv6 header size) will be in effect.');
2027 ae4c4bac Stephen Beaver
2028
if (count($mediaopts_list) > 0) {
2029 68933ba7 Stephen Beaver
	$section->addInput(new Form_Select(
2030
		'mediaopt',
2031
		'Speed and Duplex',
2032 2d5c75fa Reid Linnemann
		rtrim(config_get_path("interfaces/{$if}/media", "") . ' ' . config_get_path("interfaces/{$if}/mediaopt"), ""),
2033
		build_mediaopts_list() 
2034 4d0c9c59 Phil Davis
	))->setHelp('Explicitly set speed and duplex mode for this interface.%s' .
2035
				'WARNING: MUST be set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.', '<br />');
2036 ae4c4bac Stephen Beaver
}
2037 a0509b13 Stephen Beaver
2038 ae4c4bac Stephen Beaver
$form->add($section);
2039
2040 5f88f964 k-paulius
$section = new Form_Section('Static IPv4 Configuration');
2041 3375f236 Stephen Beaver
$section->addClass('staticv4');
2042 ae4c4bac Stephen Beaver
2043
$section->addInput(new Form_IpAddress(
2044 68933ba7 Stephen Beaver
	'ipaddr',
2045 1095b204 Phil Davis
	'*IPv4 Address',
2046 41fc88ec Phil Davis
	$pconfig['ipaddr'],
2047
	'V4'
2048 ae4c4bac Stephen Beaver
))->addMask('subnet', $pconfig['subnet'], 32);
2049
2050
$group = new Form_Group('IPv4 Upstream gateway');
2051
2052
$group->add(new Form_Select(
2053 68933ba7 Stephen Beaver
	'gateway',
2054
	'IPv4 Upstream Gateway',
2055
	$pconfig['gateway'],
2056
	build_gateway_list()
2057 ae4c4bac Stephen Beaver
));
2058
2059
$group->add(new Form_Button(
2060 dfafd8c2 Phil Davis
	'addgw4',
2061 faab522f Renato Botelho
	'Add a new gateway',
2062 2e7fa7ca jim-p
	null,
2063
	'fa-plus'
2064 dfafd8c2 Phil Davis
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway4')->setAttribute('data-toggle', 'modal');
2065 aeeda8b4 Stephen Beaver
2066 4d0c9c59 Phil Davis
$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.%1$s' .
2067 d6bc49df Brett Keller
				'On local area network interfaces the upstream gateway should be "none".%1$s' .
2068
				'Selecting an upstream gateway causes the firewall to treat this interface as a %2$sWAN type interface%4$s.%1$s' .
2069
				'Gateways can be managed by %3$sclicking here%4$s.', '<br />', '<a target="_blank" href="https://docs.netgate.com/pfsense/en/latest/interfaces/wanvslan.html">', '<a target="_blank" href="system_gateways.php">', '</a>');
2070 ae4c4bac Stephen Beaver
2071
$section->add($group);
2072
2073 aeeda8b4 Stephen Beaver
$form->add($section);
2074 ae4c4bac Stephen Beaver
2075 c9b49393 Viktor Gurov
$section = new Form_Section('SLAAC IPv6 Configuration');
2076
$section->addClass('slaac');
2077
2078
$section->addInput(new Form_Checkbox(
2079 9210d0aa Viktor Gurov
	'slaacusev4iface',
2080 c9b49393 Viktor Gurov
	'Use IPv4 connectivity as parent interface',
2081
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2082 9210d0aa Viktor Gurov
	$pconfig['slaacusev4iface']
2083 c9b49393 Viktor Gurov
));
2084
2085
$form->add($section);
2086
2087 5f88f964 k-paulius
$section = new Form_Section('Static IPv6 Configuration');
2088 3375f236 Stephen Beaver
$section->addClass('staticv6');
2089 ae4c4bac Stephen Beaver
2090
$section->addInput(new Form_IpAddress(
2091 68933ba7 Stephen Beaver
	'ipaddrv6',
2092 1095b204 Phil Davis
	'*IPv6 address',
2093 41fc88ec Phil Davis
	$pconfig['ipaddrv6'],
2094
	'V6'
2095 241111d7 Stephen Beaver
))->addMask('subnetv6', $pconfig['subnetv6'], 128);
2096 ae4c4bac Stephen Beaver
2097 b7331383 marjohn56
$section->addInput(new Form_Checkbox(
2098
	'ipv6usev4iface',
2099
	'Use IPv4 connectivity as parent interface',
2100 3e86fa99 marjohn56
	'IPv6 will use the IPv4 connectivity link (PPPoE)',
2101 b7331383 marjohn56
	$pconfig['ipv6usev4iface']
2102
));
2103
2104 ae4c4bac Stephen Beaver
$group = new Form_Group('IPv6 Upstream gateway');
2105
2106
$group->add(new Form_Select(
2107 68933ba7 Stephen Beaver
	'gatewayv6',
2108 2288d860 Stephen Beaver
	'IPv6 Upstream Gateway',
2109 9f3f4276 Stephen Beaver
	$pconfig['gatewayv6'],
2110
	build_gatewayv6_list()
2111 ae4c4bac Stephen Beaver
));
2112
2113
$group->add(new Form_Button(
2114 68933ba7 Stephen Beaver
	'addgw6',
2115 faab522f Renato Botelho
	'Add a new gateway',
2116 2e7fa7ca jim-p
	null,
2117
	'fa-plus'
2118 347c0214 Phil Davis
))->setAttribute('type','button')->addClass('btn-success')->setAttribute('data-target', '#newgateway6')->setAttribute('data-toggle', 'modal');
2119 ae4c4bac Stephen Beaver
2120 4d0c9c59 Phil Davis
$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.%s' .
2121
				'On local LANs the upstream gateway should be "none". ', '<br />');
2122 a0509b13 Stephen Beaver
2123 8b5aac9f Stephen Beaver
$section->add($group);
2124
$form->add($section);
2125 ae4c4bac Stephen Beaver
2126 8b5aac9f Stephen Beaver
// Add new gateway modal pop-up for IPv6
2127 5f88f964 k-paulius
$modal = new Modal('New IPv6 Gateway', 'newgateway6', 'large');
2128 8b5aac9f Stephen Beaver
2129
$modal->addInput(new Form_Checkbox(
2130 68933ba7 Stephen Beaver
	'defaultgw6',
2131
	'Default',
2132
	'Default gateway',
2133 e8113404 Phil Davis
	isset($gateway_settings6['defaultgw']) ? $gateway_settings6['defaultgw'] : ($if == "wan" || $if == "WAN")
2134 ae4c4bac Stephen Beaver
));
2135
2136 8b5aac9f Stephen Beaver
$modal->addInput(new Form_Input(
2137 dfafd8c2 Phil Davis
	'gatewayname6',
2138 68933ba7 Stephen Beaver
	'Gateway name',
2139
	'text',
2140 e8113404 Phil Davis
	($gateway_settings6['name'] == "") ? $defgatewayname6 : $gateway_settings6['name']
2141 8b5aac9f Stephen Beaver
));
2142 ae4c4bac Stephen Beaver
2143 8b5aac9f Stephen Beaver
$modal->addInput(new Form_IpAddress(
2144 68933ba7 Stephen Beaver
	'gatewayip6',
2145 4dda3174 Stephen Beaver
	'Gateway IPv6',
2146 e8113404 Phil Davis
	$gateway_settings6['gateway'],
2147 41fc88ec Phil Davis
	'V6'
2148 8b5aac9f Stephen Beaver
));
2149 ae4c4bac Stephen Beaver
2150 8b5aac9f Stephen Beaver
$modal->addInput(new Form_Input(
2151 68933ba7 Stephen Beaver
	'gatewaydescr6',
2152
	'Description',
2153 e8113404 Phil Davis
	'text',
2154
	$gateway_settings6['descr']
2155 8b5aac9f Stephen Beaver
));
2156 ae4c4bac Stephen Beaver
2157 8b5aac9f Stephen Beaver
$btnaddgw6 = new Form_Button(
2158 68933ba7 Stephen Beaver
	'add6',
2159 faab522f Renato Botelho
	'Add',
2160 2e7fa7ca jim-p
	null,
2161
	'fa-plus'
2162 8b5aac9f Stephen Beaver
);
2163 ae4c4bac Stephen Beaver
2164 347c0214 Phil Davis
$btnaddgw6->setAttribute('type','button')->addClass('btn-success');
2165 ae4c4bac Stephen Beaver
2166 8b5aac9f Stephen Beaver
$btncnxgw6 = new Form_Button(
2167 68933ba7 Stephen Beaver
	'cnx6',
2168 faab522f Renato Botelho
	'Cancel',
2169 2e7fa7ca jim-p
	null,
2170
	'fa-undo'
2171 8b5aac9f Stephen Beaver
);
2172
2173 347c0214 Phil Davis
$btncnxgw6->setAttribute('type','button')->addClass('btn-warning');
2174 8b5aac9f Stephen Beaver
2175
$modal->addInput(new Form_StaticText(
2176 68933ba7 Stephen Beaver
	null,
2177
	$btnaddgw6 . $btncnxgw6
2178 8b5aac9f Stephen Beaver
));
2179
2180
$form->add($modal);
2181 ae4c4bac Stephen Beaver
2182
// ==== DHCP client configuration =============================
2183
2184 5f88f964 k-paulius
$section = new Form_Section('DHCP Client Configuration');
2185 3375f236 Stephen Beaver
$section->addClass('dhcp');
2186 ae4c4bac Stephen Beaver
2187 34ab580d Stephen Beaver
$group = new Form_Group('Options');
2188
2189
$group->add(new Form_Checkbox(
2190 0c5916ce NOYB
	'adv_dhcp_config_advanced',
2191 34ab580d Stephen Beaver
	null,
2192 79a1a27f NOYB
	'Advanced Configuration',
2193 0c5916ce NOYB
	$pconfig['adv_dhcp_config_advanced']
2194 79a1a27f NOYB
))->setHelp('Use advanced DHCP configuration options.');
2195 34ab580d Stephen Beaver
2196
$group->add(new Form_Checkbox(
2197 0c5916ce NOYB
	'adv_dhcp_config_file_override',
2198 34ab580d Stephen Beaver
	null,
2199 79a1a27f NOYB
	'Configuration Override',
2200 0c5916ce NOYB
	$pconfig['adv_dhcp_config_file_override']
2201 79a1a27f NOYB
))->setHelp('Override the configuration from this file.');
2202 34ab580d Stephen Beaver
2203
$section->add($group);
2204
2205 ae4c4bac Stephen Beaver
$section->addInput(new Form_Input(
2206 68933ba7 Stephen Beaver
	'dhcphostname',
2207
	'Hostname',
2208
	'text',
2209
	$pconfig['dhcphostname']
2210 ae4c4bac Stephen Beaver
))->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).');
2211
2212
$section->addInput(new Form_IpAddress(
2213 68933ba7 Stephen Beaver
	'alias-address',
2214
	'Alias IPv4 address',
2215 41fc88ec Phil Davis
	$pconfig['alias-address'],
2216
	'V4'
2217 ae4c4bac Stephen Beaver
))->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.');
2218
2219
$section->addInput(new Form_Input(
2220 68933ba7 Stephen Beaver
	'dhcprejectfrom',
2221
	'Reject leases from',
2222
	'text',
2223
	$pconfig['dhcprejectfrom']
2224 392a7045 lukehamburg
))->setHelp('To have the DHCP client reject offers from specific DHCP servers, enter their IP addresses here ' .
2225
			'(separate multiple entries with a comma). ' .
2226 3c36d8ce jim-p
			'This is useful for rejecting leases from cable modems that offer private IP addresses when they lose upstream sync.');
2227 ae4c4bac Stephen Beaver
2228 62ed56dc Luiz Souza
if (interface_is_vlan($wancfg['if']) != NULL) {
2229
2230
	$group = new Form_Group('DHCP VLAN Priority');
2231
	$group->add(new Form_Checkbox(
2232
		'dhcpvlanenable',
2233
		null,
2234
		'Enable dhcpclient VLAN Priority tagging',
2235
		$pconfig['dhcpvlanenable']
2236
	))->setHelp('Normally off unless specifically required by the ISP.');
2237
2238
	$group->add(new Form_Select(
2239
		'dhcpcvpt',
2240
		'VLAN Prio',
2241
		$pconfig['dhcpcvpt'],
2242
		$vlanprio
2243
	))->setHelp('Choose 802.1p priority to set.');
2244
2245
	$section->add($group);
2246
}
2247
2248 ae4c4bac Stephen Beaver
$group = new Form_Group('Protocol timing');
2249 34ab580d Stephen Beaver
$group->addClass('dhcpadvanced');
2250 f0e84135 Danilo-Z
$group->setHelp('The values in these fields are DHCP protocol timings used when requesting a lease.%1$s' .
2251
				'See %2$shere%3$s for more information.', '<br />', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#PROTOCOL_TIMING">', '</a>');
2252 ae4c4bac Stephen Beaver
2253
$group->add(new Form_Input(
2254 68933ba7 Stephen Beaver
	'adv_dhcp_pt_timeout',
2255
	null,
2256
	'number',
2257
	$pconfig['adv_dhcp_pt_timeout']
2258 ae4c4bac Stephen Beaver
))->setHelp('Timeout');
2259
2260
$group->add(new Form_Input(
2261 68933ba7 Stephen Beaver
	'adv_dhcp_pt_retry',
2262
	null,
2263
	'number',
2264
	$pconfig['adv_dhcp_pt_retry']
2265 ae4c4bac Stephen Beaver
))->setHelp('Retry');
2266
2267
$group->add(new Form_Input(
2268 68933ba7 Stephen Beaver
	'adv_dhcp_pt_select_timeout',
2269
	null,
2270
	'number',
2271 a2239232 NOYB
	$pconfig['adv_dhcp_pt_select_timeout'],
2272
	['min' => 0]
2273 ae4c4bac Stephen Beaver
))->setHelp('Select timeout');
2274
2275
$group->add(new Form_Input(
2276 68933ba7 Stephen Beaver
	'adv_dhcp_pt_reboot',
2277
	null,
2278
	'number',
2279
	$pconfig['adv_dhcp_pt_reboot']
2280 ae4c4bac Stephen Beaver
))->setHelp('Reboot');
2281
2282
$group->add(new Form_Input(
2283 68933ba7 Stephen Beaver
	'adv_dhcp_pt_backoff_cutoff',
2284
	null,
2285
	'number',
2286
	$pconfig['adv_dhcp_pt_backoff_cutoff']
2287 ae4c4bac Stephen Beaver
))->setHelp('Backoff cutoff');
2288
2289
$group->add(new Form_Input(
2290 68933ba7 Stephen Beaver
	'adv_dhcp_pt_initial_interval',
2291
	null,
2292
	'number',
2293
	$pconfig['adv_dhcp_pt_initial_interval']
2294 ae4c4bac Stephen Beaver
))->setHelp('Initial interval');
2295
2296
$section->add($group);
2297
2298
$group = new Form_Group('Presets');
2299 34ab580d Stephen Beaver
$group->addClass('dhcpadvanced');
2300 ae4c4bac Stephen Beaver
2301
$group->add(new Form_Checkbox(
2302 68933ba7 Stephen Beaver
	'adv_dhcp_pt_values',
2303
	null,
2304
	'FreeBSD default',
2305
	null,
2306
	'DHCP'
2307 ae4c4bac Stephen Beaver
))->displayAsRadio();
2308
2309
$group->add(new Form_Checkbox(
2310 68933ba7 Stephen Beaver
	'adv_dhcp_pt_values',
2311
	null,
2312
	'Clear',
2313
	null,
2314
	'Clear'
2315 ae4c4bac Stephen Beaver
))->displayAsRadio();
2316
2317
$group->add(new Form_Checkbox(
2318 68933ba7 Stephen Beaver
	'adv_dhcp_pt_values',
2319
	null,
2320
	'pfSense Default',
2321
	null,
2322
	'pfSense'
2323 ae4c4bac Stephen Beaver
))->displayAsRadio();
2324
2325
$group->add(new Form_Checkbox(
2326 68933ba7 Stephen Beaver
	'adv_dhcp_pt_values',
2327
	null,
2328
	'Saved Cfg',
2329
	null,
2330
	'SavedCfg'
2331 ae4c4bac Stephen Beaver
))->displayAsRadio();
2332
2333
$section->add($group);
2334
2335 34ab580d Stephen Beaver
$section->addInput(new Form_Input(
2336
	'adv_dhcp_config_file_override_path',
2337 79a1a27f NOYB
	'Configuration File Override',
2338 34ab580d Stephen Beaver
	'text',
2339
	$pconfig['adv_dhcp_config_file_override_path']
2340 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2341
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s'.
2342
			'Where C is U(pper) or L(ower) Case, and D is ":-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2343
			'Some ISPs may require certain options be or not be sent.', '<br />');
2344 34ab580d Stephen Beaver
2345 ae4c4bac Stephen Beaver
$form->add($section);
2346
2347
$section = new Form_Section('Lease Requirements and Requests');
2348 34ab580d Stephen Beaver
$section->addClass('dhcpadvanced');
2349 ae4c4bac Stephen Beaver
2350
$section->addInput(new Form_Input(
2351 68933ba7 Stephen Beaver
	'adv_dhcp_send_options',
2352
	'Send options',
2353
	'text',
2354
	$pconfig['adv_dhcp_send_options']
2355 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('The values in this field are DHCP options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2356
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2357
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2358
			'Some ISPs may require certain options be or not be sent.', '<br />');
2359 ae4c4bac Stephen Beaver
2360
$section->addInput(new Form_Input(
2361 68933ba7 Stephen Beaver
	'adv_dhcp_request_options',
2362
	'Request options',
2363
	'text',
2364
	$pconfig['adv_dhcp_request_options']
2365 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('The values in this field are DHCP option 55 to be sent when requesting a DHCP lease.  [option [, ...]] %1$s' .
2366
			'Some ISPs may require certain options be or not be requested.', '<br />');
2367 68933ba7 Stephen Beaver
2368
$section->addInput(new Form_Input(
2369 0683ff17 NOYB
	'adv_dhcp_required_options',
2370 583b40ee Phil Davis
	'Require options',
2371 68933ba7 Stephen Beaver
	'text',
2372 0683ff17 NOYB
	$pconfig['adv_dhcp_required_options']
2373 79a1a27f NOYB
))->setWidth(9)->sethelp('The values in this field are DHCP options required by the client when requesting a DHCP lease.	 [option [, ...]]');
2374 ae4c4bac Stephen Beaver
2375
$section->addInput(new Form_Input(
2376 68933ba7 Stephen Beaver
	'adv_dhcp_option_modifiers',
2377
	'Option modifiers',
2378
	'text',
2379
	$pconfig['adv_dhcp_option_modifiers']
2380 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('The values in this field are DHCP option modifiers applied to the obtained DHCP lease.	 [modifier option declaration [, ...]] %1$s' .
2381
			'modifiers: (default, supersede, prepend, append) %1$s' .
2382
			'See %2$shere%3$s more information', '<br />', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhclient.conf&sektion=5#LEASE_REQUIREMENTS_AND_REQUESTS">', '</a>');
2383 ae4c4bac Stephen Beaver
2384
$form->add($section);
2385
2386
// DHCP6 client config
2387
2388 5f88f964 k-paulius
$section = new Form_Section('DHCP6 Client Configuration');
2389 3375f236 Stephen Beaver
$section->addClass('dhcp6');
2390
2391 79a1a27f NOYB
$group = new Form_Group('Options');
2392
2393
$group->add(new Form_Checkbox(
2394 7361f6c2 Stephen Beaver
	'adv_dhcp6_config_advanced',
2395 79a1a27f NOYB
	null,
2396
	'Advanced Configuration',
2397 0c5916ce NOYB
	$pconfig['adv_dhcp6_config_advanced']
2398 79a1a27f NOYB
))->setHelp('Use advanced DHCPv6 configuration options.');
2399 309e8f8f Stephen Beaver
2400 79a1a27f NOYB
$group->add(new Form_Checkbox(
2401 68933ba7 Stephen Beaver
	'adv_dhcp6_config_file_override',
2402 79a1a27f NOYB
	null,
2403
	'Configuration Override',
2404 0c5916ce NOYB
	$pconfig['adv_dhcp6_config_file_override']
2405 79a1a27f NOYB
))->setHelp('Override the configuration from this file.');
2406
2407
$section->add($group);
2408 309e8f8f Stephen Beaver
2409 ae4c4bac Stephen Beaver
$section->addInput(new Form_Checkbox(
2410 68933ba7 Stephen Beaver
	'dhcp6usev4iface',
2411
	'Use IPv4 connectivity as parent interface',
2412
	'Request a IPv6 prefix/information through the IPv4 connectivity link',
2413
	$pconfig['dhcp6usev4iface']
2414 ae4c4bac Stephen Beaver
));
2415
2416
$section->addInput(new Form_Checkbox(
2417 68933ba7 Stephen Beaver
	'dhcp6prefixonly',
2418
	'Request only an IPv6 prefix',
2419
	'Only request an IPv6 prefix, do not request an IPv6 address',
2420
	$pconfig['dhcp6prefixonly']
2421 ae4c4bac Stephen Beaver
));
2422
2423
$section->addInput(new Form_Select(
2424 68933ba7 Stephen Beaver
	'dhcp6-ia-pd-len',
2425
	'DHCPv6 Prefix Delegation size',
2426
	$pconfig['dhcp6-ia-pd-len'],
2427 51dc008b Andreas Bleischwitz
	array("none" => "None", 16 => "48", 15 => "49", 14 => "50", 13 => "51", 12 => "52", 11 => "53", 10 => "54", 9 => "55", 8 => "56", 7 => "57", 6 => "58", 5 => "59", 4 => "60", 3 => "61", 2 => "62", 1 => "63", 0 => "64")
2428 a0509b13 Stephen Beaver
))->setHelp('The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP.');
2429 ae4c4bac Stephen Beaver
2430
$section->addInput(new Form_Checkbox(
2431 68933ba7 Stephen Beaver
	'dhcp6-ia-pd-send-hint',
2432
	'Send IPv6 prefix hint',
2433
	'Send an IPv6 prefix hint to indicate the desired prefix size for delegation',
2434
	$pconfig['dhcp6-ia-pd-send-hint']
2435 ae4c4bac Stephen Beaver
));
2436
2437 8c661bc8 marjohn56
$section->addInput(new Form_Checkbox(
2438
	'dhcp6withoutra',
2439
	'Do not wait for a RA',
2440
	'Required by some ISPs, especially those not using PPPoE',
2441
	$pconfig['dhcp6withoutra']
2442
));
2443 6b8680a7 marjohn56
2444 966835f8 Luiz Souza
if (interface_is_vlan($wancfg['if']) != NULL) {
2445
	$group = new Form_Group('DHCP6 VLAN Priority');
2446
2447
	$group->add(new Form_Checkbox(
2448
		'dhcp6vlanenable',
2449
		null,
2450
		'Enable dhcp6c VLAN Priority tagging',
2451
		$pconfig['dhcp6vlanenable']
2452
	))->setHelp('Normally off unless specifically required by the ISP.');
2453
2454
	$group->add(new Form_Select(
2455
		'dhcp6cvpt',
2456
		'VLAN Prio',
2457
		$pconfig['dhcp6cvpt'],
2458
		$vlanprio
2459
	))->setHelp('Choose 802.1p priority to set.');
2460
2461
	$section->add($group);
2462
}
2463 6b8680a7 marjohn56
2464 309e8f8f Stephen Beaver
$section->addInput(new Form_Input(
2465 68933ba7 Stephen Beaver
	'adv_dhcp6_config_file_override_path',
2466
	'Configuration File Override',
2467
	'text',
2468
	$pconfig['adv_dhcp6_config_file_override_path']
2469 4d0c9c59 Phil Davis
))->setWidth(9)->setHelp('The value in this field is the full absolute path to a DHCP client configuration file.	 [/[dirname/[.../]]filename[.ext]] %1$s' .
2470
			'Value Substitutions in Config File: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2471
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2472
			'Some ISPs may require certain options be or not be sent.', '<br />');
2473 309e8f8f Stephen Beaver
2474 ae4c4bac Stephen Beaver
$form->add($section);
2475
2476
// DHCP6 client config - Advanced
2477
2478 5f88f964 k-paulius
$section = new Form_Section('Advanced DHCP6 Client Configuration');
2479 309e8f8f Stephen Beaver
$section->addClass('dhcp6advanced');
2480 3375f236 Stephen Beaver
2481 ae4c4bac Stephen Beaver
$section->addInput(new Form_Checkbox(
2482 68933ba7 Stephen Beaver
	'adv_dhcp6_interface_statement_information_only_enable',
2483
	'Information only',
2484 79a1a27f NOYB
	'Exchange Information Only',
2485 03911305 Stephen Beaver
	$pconfig['adv_dhcp6_interface_statement_information_only_enable'],
2486
	'Selected'
2487 79a1a27f NOYB
))->setHelp('Only exchange informational configuration parameters with servers.');
2488 ae4c4bac Stephen Beaver
2489
$section->addInput(new Form_Input(
2490 68933ba7 Stephen Beaver
	'adv_dhcp6_interface_statement_send_options',
2491
	'Send options',
2492
	'text',
2493
	$pconfig['adv_dhcp6_interface_statement_send_options']
2494 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('DHCP send options to be sent when requesting a DHCP lease.	 [option declaration [, ...]] %1$s' .
2495
			'Value Substitutions: {interface}, {hostname}, {mac_addr_asciiCD}, {mac_addr_hexCD} %1$s' .
2496
			'Where C is U(pper) or L(ower) Case, and D is " :-." Delimiter (space, colon, hyphen, or period) (omitted for none).%1$s' .
2497
			'Some DHCP services may require certain options be or not be sent.', '<br />');
2498 ae4c4bac Stephen Beaver
2499
$section->addInput(new Form_Input(
2500 68933ba7 Stephen Beaver
	'adv_dhcp6_interface_statement_request_options',
2501
	'Request Options',
2502
	'text',
2503
	$pconfig['adv_dhcp6_interface_statement_request_options']
2504 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('DHCP request options to be sent when requesting a DHCP lease.	[option [, ...]] %1$s' .
2505
			'Some DHCP services may require certain options be or not be requested.', '<br />');
2506 a0509b13 Stephen Beaver
2507 ae4c4bac Stephen Beaver
$section->addInput(new Form_Input(
2508 68933ba7 Stephen Beaver
	'adv_dhcp6_interface_statement_script',
2509
	'Scripts',
2510
	'text',
2511
	$pconfig['adv_dhcp6_interface_statement_script']
2512 4d0c9c59 Phil Davis
))->setWidth(9)->sethelp('Absolute path to a script invoked on certain conditions including when a reply message is received.%1$s' .
2513
			'[/[dirname/[.../]]filename[.ext]].', '<br />');
2514 a0509b13 Stephen Beaver
2515 ae4c4bac Stephen Beaver
$group = new Form_Group('Identity Association Statement');
2516
2517
$group->add(new Form_Checkbox(
2518 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_address_enable',
2519
	null,
2520
	'Non-Temporary Address Allocation',
2521 03911305 Stephen Beaver
	$pconfig['adv_dhcp6_id_assoc_statement_address_enable'],
2522
	'Selected'
2523 ae4c4bac Stephen Beaver
));
2524 a0509b13 Stephen Beaver
2525 ae4c4bac Stephen Beaver
$group->add(new Form_Input(
2526 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_address_id',
2527
	null,
2528
	'text',
2529
	$pconfig['adv_dhcp6_id_assoc_statement_address_id']
2530 ae4c4bac Stephen Beaver
))->sethelp('id-assoc na ID');
2531
2532
$group->add(new Form_IpAddress(
2533 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_address',
2534
	null,
2535 41fc88ec Phil Davis
	$pconfig['adv_dhcp6_id_assoc_statement_address'],
2536
	'V6'
2537 ae4c4bac Stephen Beaver
))->sethelp('IPv6 address');
2538
2539
$group->add(new Form_Input(
2540 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_address_pltime',
2541
	null,
2542
	'text',
2543
	$pconfig['adv_dhcp6_id_assoc_statement_address_pltime']
2544 ae4c4bac Stephen Beaver
))->sethelp('pltime');
2545
2546
$group->add(new Form_Input(
2547 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_address_vltime',
2548
	null,
2549
	'text',
2550
	$pconfig['adv_dhcp6_id_assoc_statement_address_vltime']
2551 ae4c4bac Stephen Beaver
))->sethelp('vltime');
2552
2553
$section->add($group);
2554
2555 a0509b13 Stephen Beaver
// Prefix delegation
2556 ae4c4bac Stephen Beaver
$group = new Form_Group('');
2557
2558
$group->add(new Form_Checkbox(
2559 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_prefix_enable',
2560
	null,
2561
	'Prefix Delegation ',
2562 03911305 Stephen Beaver
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_enable'],
2563
	'Selected'
2564 ae4c4bac Stephen Beaver
));
2565 a0509b13 Stephen Beaver
2566 ae4c4bac Stephen Beaver
$group->add(new Form_Input(
2567 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_prefix_id',
2568
	null,
2569
	'text',
2570
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_id']
2571 ae4c4bac Stephen Beaver
))->sethelp('id-assoc pd ID');
2572
2573
$group->add(new Form_IpAddress(
2574 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_prefix',
2575
	null,
2576 41fc88ec Phil Davis
	$pconfig['adv_dhcp6_id_assoc_statement_prefix'],
2577
	'V6'
2578 ae4c4bac Stephen Beaver
))->sethelp('IPv6 prefix');
2579
2580
$group->add(new Form_Input(
2581 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_prefix_pltime',
2582
	null,
2583
	'text',
2584
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']
2585 ae4c4bac Stephen Beaver
))->sethelp('pltime');
2586
2587
$group->add(new Form_Input(
2588 68933ba7 Stephen Beaver
	'adv_dhcp6_id_assoc_statement_prefix_vltime',
2589
	null,
2590
	'text',
2591
	$pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']
2592 ae4c4bac Stephen Beaver
))->sethelp('vltime');
2593
2594
$section->add($group);
2595
2596
$group = new Form_Group('Prefix interface statement');
2597
2598
$group->add(new Form_Input(
2599 68933ba7 Stephen Beaver
	'adv_dhcp6_prefix_interface_statement_sla_id',
2600
	null,
2601
	'text',
2602
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_id']
2603 ae4c4bac Stephen Beaver
))->sethelp('Prefix Interface sla-id');
2604
2605
$group->add(new Form_Input(
2606 68933ba7 Stephen Beaver
	'adv_dhcp6_prefix_interface_statement_sla_len',
2607
	null,
2608
	'text',
2609
	$pconfig['adv_dhcp6_prefix_interface_statement_sla_len']
2610 ae4c4bac Stephen Beaver
))->sethelp('sla-len');
2611
2612
$section->add($group);
2613
2614 58a185ae marjohn56
$group = new Form_Group('Select prefix interface');
2615
$section->addInput(new Form_Select(
2616
	'adv_dhcp6_prefix_selected_interface',
2617
	'Prefix Interface',
2618
	$pconfig['adv_dhcp6_prefix_selected_interface'],
2619
	$interfaces
2620
))->setHelp('Select the interface on which to apply the prefix delegation.');
2621
2622 ae4c4bac Stephen Beaver
$group = new Form_Group('Authentication statement');
2623
2624
$group->add(new Form_Input(
2625 68933ba7 Stephen Beaver
	'adv_dhcp6_authentication_statement_authname',
2626
	null,
2627
	'text',
2628
	$pconfig['adv_dhcp6_authentication_statement_authname']
2629 ae4c4bac Stephen Beaver
))->sethelp('Authname');
2630
2631
$group->add(new Form_Input(
2632 68933ba7 Stephen Beaver
	'adv_dhcp6_authentication_statement_protocol',
2633
	null,
2634
	'text',
2635
	$pconfig['adv_dhcp6_authentication_statement_protocol']
2636 ae4c4bac Stephen Beaver
))->sethelp('Protocol');
2637
2638
$group->add(new Form_Input(
2639 68933ba7 Stephen Beaver
	'adv_dhcp6_authentication_statement_algorithm',
2640
	null,
2641
	'text',
2642
	$pconfig['adv_dhcp6_authentication_statement_algorithm']
2643 ae4c4bac Stephen Beaver
))->sethelp('Algorithm');
2644
2645
$group->add(new Form_Input(
2646 68933ba7 Stephen Beaver
	'adv_dhcp6_authentication_statement_rdm',
2647
	null,
2648
	'text',
2649
	$pconfig['adv_dhcp6_authentication_statement_rdm']
2650 ae4c4bac Stephen Beaver
))->sethelp('RDM');
2651
2652
$section->add($group);
2653
2654
$group = new Form_Group('Keyinfo statement');
2655
2656
$group->add(new Form_Input(
2657 68933ba7 Stephen Beaver
	'adv_dhcp6_key_info_statement_keyname',
2658
	null,
2659
	'text',
2660
	$pconfig['adv_dhcp6_key_info_statement_keyname']
2661 ae4c4bac Stephen Beaver
))->sethelp('Keyname');
2662
2663
$group->add(new Form_Input(
2664 68933ba7 Stephen Beaver
	'adv_dhcp6_key_info_statement_realm',
2665
	null,
2666
	'text',
2667
	$pconfig['adv_dhcp6_key_info_statement_realm']
2668 ae4c4bac Stephen Beaver
))->sethelp('Realm');
2669
2670
$section->add($group);
2671
2672
$group = new Form_Group('');
2673
2674
$group->add(new Form_Input(
2675 68933ba7 Stephen Beaver
	'adv_dhcp6_key_info_statement_keyid',
2676
	null,
2677
	'text',
2678
	$pconfig['adv_dhcp6_key_info_statement_keyid']
2679 ae4c4bac Stephen Beaver
))->sethelp('KeyID');
2680
2681
$group->add(new Form_Input(
2682 68933ba7 Stephen Beaver
	'adv_dhcp6_key_info_statement_secret',
2683
	null,
2684
	'text',
2685
	$pconfig['adv_dhcp6_key_info_statement_secret']
2686 ae4c4bac Stephen Beaver
))->sethelp('Secret');
2687
2688
$group->add(new Form_Input(
2689 68933ba7 Stephen Beaver
	'adv_dhcp6_key_info_statement_expire',
2690
	null,
2691
	'text',
2692
	$pconfig['adv_dhcp6_key_info_statement_expire']
2693 ae4c4bac Stephen Beaver
))->sethelp('Expire');
2694
2695 b3875714 jim-p
$group->setHelp('See %1$shere%2$s more information', '<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=dhcp6c.conf&sektion=5&apropos=0&manpath=FreeBSD+11.0-RELEASE+and+Ports#Interface_statement">', '</a>');
2696 79a1a27f NOYB
2697 ae4c4bac Stephen Beaver
$section->add($group);
2698
2699
$form->add($section);
2700
2701
$section = new Form_Section('6RD Configuration');
2702 c0c25504 Stephen Beaver
$section->addClass('_6rd');
2703 ae4c4bac Stephen Beaver
2704
$section->addInput(new Form_Input(
2705 68933ba7 Stephen Beaver
	'prefix-6rd',
2706
	'6RD Prefix',
2707
	'text',
2708
	$pconfig['prefix-6rd']
2709 eaa948d6 NOYB
))->sethelp('6RD IPv6 prefix assigned by the ISP. e.g. "2001:db8::/32"');
2710 ae4c4bac Stephen Beaver
2711
$section->addInput(new Form_Input(
2712 68933ba7 Stephen Beaver
	'gateway-6rd',
2713 1095b204 Phil Davis
	'*6RD Border relay',
2714 68933ba7 Stephen Beaver
	'text',
2715
	$pconfig['gateway-6rd']
2716 eaa948d6 NOYB
))->sethelp('6RD IPv4 gateway address assigned by the ISP');
2717 ae4c4bac Stephen Beaver
2718
$section->addInput(new Form_Select(
2719 68933ba7 Stephen Beaver
	'prefix-6rd-v4plen',
2720 6bb806c6 Chris Buechler
	'6RD IPv4 Prefix length',
2721 68933ba7 Stephen Beaver
	$pconfig['prefix-6rd-v4plen'],
2722
	array_combine(range(0, 32), range(0, 32))
2723 ab9b8aad NOYB
))->setHelp('6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means embed the entire IPv4 address in the 6RD prefix.');
2724 ae4c4bac Stephen Beaver
2725
$form->add($section);
2726
2727
// Track IPv6 ointerface section
2728
$section = new Form_Section('Track IPv6 Interface');
2729 3375f236 Stephen Beaver
$section->addClass('track6');
2730 ae4c4bac Stephen Beaver
2731
function build_ipv6interface_list() {
2732 5a41b18c Renato Botelho
	global $config, $form;
2733 9abccff3 Stephen Beaver
2734 68933ba7 Stephen Beaver
	$list = array('' => '');
2735
2736 f593f80b Phil Davis
	$interfaces = get_configured_interface_with_descr(true);
2737 68933ba7 Stephen Beaver
	$dynv6ifs = array();
2738
2739
	foreach ($interfaces as $iface => $ifacename) {
2740 2d5c75fa Reid Linnemann
		switch (config_get_path("interfaces/{$iface}/ipaddrv6")) {
2741 68933ba7 Stephen Beaver
			case "6to4":
2742
			case "6rd":
2743
			case "dhcp6":
2744
				$dynv6ifs[$iface] = array(
2745
					'name' => $ifacename,
2746 2456ecc9 jim-p
					'ipv6_num_prefix_ids' => pow(2, (int) calculate_ipv6_delegation_length($iface)) - 1
2747 68933ba7 Stephen Beaver
				);
2748
				break;
2749
			default:
2750 86ec819a jim-p
				continue 2;
2751 68933ba7 Stephen Beaver
		}
2752
	}
2753
2754
	foreach ($dynv6ifs as $iface => $ifacedata) {
2755
		$list[$iface] = $ifacedata['name'];
2756
2757 ee12dd78 Peter Feichtinger
		$form->addGlobal(new Form_Input(
2758 68933ba7 Stephen Beaver
			'ipv6-num-prefix-ids-' . $iface,
2759
			null,
2760
			'hidden',
2761
			$ifacedata['ipv6_num_prefix_ids']
2762
		));
2763
	}
2764
2765
	return($list);
2766 ae4c4bac Stephen Beaver
}
2767 c0948c6c Renato Botelho
2768 ae4c4bac Stephen Beaver
$section->addInput(new Form_Select(
2769 68933ba7 Stephen Beaver
	'track6-interface',
2770 1095b204 Phil Davis
	'*IPv6 Interface',
2771 68933ba7 Stephen Beaver
	$pconfig['track6-interface'],
2772
	build_ipv6interface_list()
2773 a6a344d8 NOYB
))->setHelp('Selects the dynamic IPv6 WAN interface to track for configuration.');
2774 c0948c6c Renato Botelho
2775 ae4c4bac Stephen Beaver
if ($pconfig['track6-prefix-id'] == "") {
2776 68933ba7 Stephen Beaver
	$pconfig['track6-prefix-id'] = 0;
2777 ae4c4bac Stephen Beaver
}
2778 3a906378 gnhb
2779 ae4c4bac Stephen Beaver
$section->addInput(new Form_Input(
2780 1ee6d09a Phil Davis
	'track6-prefix-id--hex',
2781 68933ba7 Stephen Beaver
	'IPv6 Prefix ID',
2782
	'text',
2783
	sprintf("%x", $pconfig['track6-prefix-id'])
2784 4d0c9c59 Phil Davis
))->setHelp('(%1$shexadecimal%2$s from 0 to %3$s) 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.', '<b>', '</b>', '<span id="track6-prefix-id-range"></span>');
2785 a0509b13 Stephen Beaver
2786 ee12dd78 Peter Feichtinger
$form->addGlobal(new Form_Input(
2787 1ee6d09a Phil Davis
	'track6-prefix-id-max',
2788 68933ba7 Stephen Beaver
	null,
2789
	'hidden',
2790
	0
2791 aeeda8b4 Stephen Beaver
));
2792 a9929d56 Stephen Beaver
2793 ae4c4bac Stephen Beaver
$form->add($section);
2794
2795
/// PPP section
2796
2797
$section = new Form_Section('PPP Configuration');
2798 3375f236 Stephen Beaver
$section->addClass('ppp');
2799 ae4c4bac Stephen Beaver
2800
$section->addInput(new Form_Select(
2801 68933ba7 Stephen Beaver
	'country',
2802
	'Country',
2803
	$pconfig['country'],
2804
	[]
2805 ae4c4bac Stephen Beaver
));
2806
2807
$section->addInput(new Form_Select(
2808 68933ba7 Stephen Beaver
	'provider_list',
2809
	'Provider',
2810
	$pconfig['provider_list'],
2811
	[]
2812 ae4c4bac Stephen Beaver
));
2813
2814
$section->addInput(new Form_Select(
2815 68933ba7 Stephen Beaver
	'providerplan',
2816
	'Plan',
2817
	$pconfig['providerplan'],
2818
	[]
2819 eaa948d6 NOYB
))->setHelp('Select to fill in service provider data.');
2820 ae4c4bac Stephen Beaver
2821
$section->addInput(new Form_Input(
2822 68933ba7 Stephen Beaver
	'ppp_username',
2823
	'Username',
2824
	'text',
2825 659a8a26 jim-p
	$pconfig['ppp_username'],
2826
	['autocomplete' => 'new-password']
2827 ae4c4bac Stephen Beaver
));
2828
2829 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
2830 68933ba7 Stephen Beaver
	'ppp_password',
2831
	'Password',
2832
	'password',
2833
	$pconfig['ppp_password']
2834 ae4c4bac Stephen Beaver
));
2835
2836 309e8f8f Stephen Beaver
$section->addInput(new Form_Input(
2837 68933ba7 Stephen Beaver
	'phone',
2838 1095b204 Phil Davis
	'*Phone number',
2839 68933ba7 Stephen Beaver
	'text',
2840
	$pconfig['phone']
2841 a6a344d8 NOYB
))->setHelp('Typically *99# for GSM networks and #777 for CDMA networks.');
2842 986fd3d9 Renato Botelho
2843 ae4c4bac Stephen Beaver
$section->addInput(new Form_Input(
2844 68933ba7 Stephen Beaver
	'apn',
2845
	'Access Point Name',
2846
	'text',
2847
	$pconfig['apn']
2848 ae4c4bac Stephen Beaver
));
2849
2850 309e8f8f Stephen Beaver
2851 ae4c4bac Stephen Beaver
function build_port_list() {
2852 68933ba7 Stephen Beaver
	$list = array("" => "None");
2853 a0509b13 Stephen Beaver
2854 68933ba7 Stephen Beaver
	$portlist = glob("/dev/cua*");
2855
	$modems	  = glob("/dev/modem*");
2856
	$portlist = array_merge($portlist, $modems);
2857 ae4c4bac Stephen Beaver
2858 68933ba7 Stephen Beaver
	foreach ($portlist as $port) {
2859
		if (preg_match("/\.(lock|init)$/", $port)) {
2860
			continue;
2861
		}
2862 ae4c4bac Stephen Beaver
2863 68933ba7 Stephen Beaver
	$list[trim($port)] = $port;
2864
	}
2865 a0509b13 Stephen Beaver
2866 68933ba7 Stephen Beaver
	return($list);
2867 a0509b13 Stephen Beaver
}
2868 309e8f8f Stephen Beaver
2869 ae4c4bac Stephen Beaver
$section->addInput(new Form_Select(
2870 68933ba7 Stephen Beaver
	'port',
2871 1095b204 Phil Davis
	"*Modem port",
2872 68933ba7 Stephen Beaver
	$pconfig['port'],
2873
	build_port_list()
2874 ae4c4bac Stephen Beaver
));
2875 a0509b13 Stephen Beaver
2876 309e8f8f Stephen Beaver
$section->addInput(new Form_Button(
2877 68933ba7 Stephen Beaver
	'btnadvppp',
2878 faab522f Renato Botelho
	'Advanced PPP',
2879 827a3812 jim-p
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
2880
	'fa-cog'
2881 a6a344d8 NOYB
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Create a new PPP configuration.');
2882 a0509b13 Stephen Beaver
2883 ae4c4bac Stephen Beaver
$form->add($section);
2884
2885
// PPPoE configuration
2886
$section = new Form_Section('PPPoE Configuration');
2887 3375f236 Stephen Beaver
$section->addClass('pppoe');
2888 ae4c4bac Stephen Beaver
2889
$section->addInput(new Form_Input(
2890 68933ba7 Stephen Beaver
	'pppoe_username',
2891 32a85c63 Phil Davis
	'*Username',
2892 68933ba7 Stephen Beaver
	'text',
2893 659a8a26 jim-p
	$pconfig['pppoe_username'],
2894
	['autocomplete' => 'new-password']
2895 ae4c4bac Stephen Beaver
));
2896
2897 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
2898 68933ba7 Stephen Beaver
	'pppoe_password',
2899 32a85c63 Phil Davis
	'*Password',
2900 68933ba7 Stephen Beaver
	'password',
2901
	$pconfig['pppoe_password']
2902 ae4c4bac Stephen Beaver
));
2903
2904
$section->addInput(new Form_Input(
2905 68933ba7 Stephen Beaver
	'provider',
2906
	'Service name',
2907
	'text',
2908
	$pconfig['provider']
2909 a6a344d8 NOYB
))->setHelp('This field can usually be left empty.');
2910 ae4c4bac Stephen Beaver
2911 71465708 Viktor G
$section->addInput(new Form_Input(
2912
	'hostuniq',
2913
	'Host-Uniq',
2914
	'text',
2915
	$pconfig['hostuniq']
2916
))->setHelp('A unique host tag value for this PPPoE client. Leave blank unless a value is required by the service provider.');
2917
2918 ae4c4bac Stephen Beaver
$section->addInput(new Form_Checkbox(
2919 68933ba7 Stephen Beaver
	'pppoe_dialondemand',
2920
	'Dial on demand',
2921
	'Enable Dial-On-Demand mode ',
2922
	$pconfig['pppoe_dialondemand'],
2923
	'enable'
2924 ae4c4bac Stephen Beaver
));
2925
2926
$section->addInput(new Form_Input(
2927 68933ba7 Stephen Beaver
	'pppoe_idletimeout',
2928
	'Idle timeout',
2929
	'number',
2930
	$pconfig['pppoe_idletimeout'],
2931 6e78a06f BBcan177
	['min' => 0]
2932 ae4c4bac Stephen Beaver
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
2933 68933ba7 Stephen Beaver
			'An idle timeout of zero disables this feature.');
2934 ae4c4bac Stephen Beaver
2935 eaf7cb2a Stephen Beaver
$section->addInput(new Form_Select(
2936 68933ba7 Stephen Beaver
	'pppoe-reset-type',
2937
	'Periodic reset',
2938
	$pconfig['pppoe-reset-type'],
2939 6e8892c5 Stephen Beaver
	['' => gettext('Disabled'), 'custom' => gettext('Custom'), 'preset' => gettext('Pre-set')]
2940 a6a344d8 NOYB
))->setHelp('Select a reset timing type.');
2941 eaf7cb2a Stephen Beaver
2942 635f649d Stephen Beaver
$group = new Form_Group('Custom reset');
2943 aeeda8b4 Stephen Beaver
$group->addClass('pppoecustom');
2944 eaf7cb2a Stephen Beaver
2945
$group->add(new Form_Input(
2946 68933ba7 Stephen Beaver
	'pppoe_resethour',
2947
	null,
2948
	'number',
2949 b381fa76 jim-p
	(strlen($pconfig['pppoe_resethour']) > 0) ? $pconfig['pppoe_resethour'] : "0",
2950 6e78a06f BBcan177
	['min' => 0, 'max' => 23]
2951 b381fa76 jim-p
))->setHelp('Hour (0-23), blank for * (every)');
2952 eaf7cb2a Stephen Beaver
2953
$group->add(new Form_Input(
2954 68933ba7 Stephen Beaver
	'pppoe_resetminute',
2955
	null,
2956
	'number',
2957 b381fa76 jim-p
	(strlen($pconfig['pppoe_resetminute']) > 0) ? $pconfig['pppoe_resetminute'] : "0",
2958 6e78a06f BBcan177
	['min' => 0, 'max' => 59]
2959 b381fa76 jim-p
))->setHelp('Minute (0-59), blank for * (every)');
2960 eaf7cb2a Stephen Beaver
2961
$group->add(new Form_Input(
2962 68933ba7 Stephen Beaver
	'pppoe_resetdate',
2963
	null,
2964
	'text',
2965
	$pconfig['pppoe_resetdate']
2966 eaf7cb2a Stephen Beaver
))->setHelp('Specific date (mm/dd/yyyy)');
2967
2968 eaa948d6 NOYB
$group->setHelp('Leave the date field empty, for the reset to be executed each day at the time specified by the minutes and hour fields');
2969 eaf7cb2a Stephen Beaver
2970
$section->add($group);
2971
2972
$group = new Form_MultiCheckboxGroup('cron based reset');
2973 7957389b Viktor G
$group->addClass('pppoepreset');
2974 eaf7cb2a Stephen Beaver
2975
$group->add(new Form_MultiCheckbox(
2976 68933ba7 Stephen Beaver
	'pppoe_pr_preset_val',
2977
	null,
2978
	'Reset at each month ("0 0 1 * *")',
2979
	$pconfig['pppoe_monthly'],
2980
	'monthly'
2981 eaf7cb2a Stephen Beaver
))->displayAsRadio();
2982
2983
$group->add(new Form_MultiCheckbox(
2984 68933ba7 Stephen Beaver
	'pppoe_pr_preset_val',
2985
	null,
2986
	'Reset at each week ("0 0 * * 0")',
2987
	$pconfig['pppoe_weekly'],
2988
	'weekly'
2989 eaf7cb2a Stephen Beaver
))->displayAsRadio();
2990
2991
$group->add(new Form_MultiCheckbox(
2992 68933ba7 Stephen Beaver
	'pppoe_pr_preset_val',
2993
	null,
2994
	'Reset at each day ("0 0 * * *")',
2995
	$pconfig['pppoe_daily'],
2996
	'daily'
2997 eaf7cb2a Stephen Beaver
))->displayAsRadio();
2998
2999
$group->add(new Form_MultiCheckbox(
3000 68933ba7 Stephen Beaver
	'pppoe_pr_preset_val',
3001
	null,
3002
	'Reset at each hour ("0 * * * *")',
3003
	$pconfig['pppoe_hourly'],
3004
	'hourly'
3005 eaf7cb2a Stephen Beaver
))->displayAsRadio();
3006
3007
$section->add($group);
3008
3009 827a3812 jim-p
$section->addInput(new Form_Button(
3010
	'btnadvppp',
3011 faab522f Renato Botelho
	'Advanced and MLPPP',
3012 827a3812 jim-p
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3013
	'fa-cog'
3014 347c0214 Phil Davis
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('Click for additional PPPoE configuration options. Save first if changes have been made.');
3015 eaf7cb2a Stephen Beaver
3016
$form->add($section);
3017
3018
// PPTP & L2TP Configuration section
3019 aeeda8b4 Stephen Beaver
$section = new Form_Section('PPTP/L2TP Configuration');
3020 3375f236 Stephen Beaver
$section->addClass('pptp');
3021 eaf7cb2a Stephen Beaver
3022
$section->addInput(new Form_Input(
3023 68933ba7 Stephen Beaver
	'pptp_username',
3024 1095b204 Phil Davis
	'*Username',
3025 68933ba7 Stephen Beaver
	'text',
3026 659a8a26 jim-p
	$pconfig['pptp_username'],
3027
	['autocomplete' => 'new-password']
3028 eaf7cb2a Stephen Beaver
));
3029
3030 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
3031 68933ba7 Stephen Beaver
	'pptp_password',
3032 1095b204 Phil Davis
	'*Password',
3033 68933ba7 Stephen Beaver
	'password',
3034
	$pconfig['pptp_password']
3035 eaf7cb2a Stephen Beaver
));
3036
3037 8e267d3b Viktor G
$group = new Form_Group('Shared Secret');
3038
3039
$group->add(new Form_Input(
3040
	'l2tp_secret',
3041
	'*Secret',
3042
	'password',
3043
	$pconfig['l2tp_secret']
3044
))->setHelp('L2TP tunnel Shared Secret. Used to authenticate tunnel connection and encrypt ' .
3045 9623ec5b Viktor G
	    'important control packet contents. (Optional)');
3046 8e267d3b Viktor G
3047
$group->addClass('l2tp_secret');
3048
$section->add($group);
3049
3050 eaf7cb2a Stephen Beaver
$section->addInput(new Form_IpAddress(
3051 66fd7b47 Phil Davis
	'pptp_local0',
3052 1095b204 Phil Davis
	'*Local IP address',
3053 7e38cc2c Viktor G
	$_POST['pptp_local0'] ? $_POST['pptp_local0'] : $pconfig['pptp_localip'][0],
3054 41fc88ec Phil Davis
	'V4'
3055 7e38cc2c Viktor G
))->addMask('pptp_subnet0', $_POST['pptp_subnet0'] ? $_POST['pptp_subnet0'] : $pconfig['pptp_subnet'][0]);
3056 eaf7cb2a Stephen Beaver
3057 4890b6ec Phil Davis
$section->addInput(new Form_IpAddress(
3058 66fd7b47 Phil Davis
	'pptp_remote0',
3059 1095b204 Phil Davis
	'*Remote IP address',
3060 7e38cc2c Viktor G
	$_POST['pptp_remote0'] ? $_POST['pptp_remote0'] : $pconfig['pptp_remote'][0],
3061 4890b6ec Phil Davis
	'HOSTV4'
3062 eaf7cb2a Stephen Beaver
));
3063
3064
$section->addInput(new Form_Checkbox(
3065 68933ba7 Stephen Beaver
	'pptp_dialondemand',
3066
	'Dial on demand',
3067
	'Enable Dial-On-Demand mode ',
3068
	$pconfig['pptp_dialondemand'],
3069
	'enable'
3070 eaa948d6 NOYB
))->setHelp('This option causes the interface to operate in dial-on-demand mode, allowing it to be a virtual full time connection. ' .
3071 68933ba7 Stephen Beaver
			'The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.');
3072 eaf7cb2a Stephen Beaver
3073
$section->addInput(new Form_Input(
3074 68933ba7 Stephen Beaver
	'pptp_idletimeout',
3075
	'Idle timeout (seconds)',
3076
	'number',
3077
	$pconfig['pptp_idletimeout'],
3078 6e78a06f BBcan177
	['min' => 0]
3079 eaf7cb2a Stephen Beaver
))->setHelp('If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. ' .
3080 68933ba7 Stephen Beaver
			'An idle timeout of zero disables this feature.');
3081 a0509b13 Stephen Beaver
3082 827a3812 jim-p
if (isset($pconfig['pptp_localip'][1]) || isset($pconfig['pptp_subnet'][1]) || isset($pconfig['pptp_remote'][1])) {
3083
	$mlppp_text = gettext("There are additional Local and Remote IP addresses defined for MLPPP.") . "<br />";
3084 eaf7cb2a Stephen Beaver
} else {
3085 827a3812 jim-p
	$mlppp_text = "";
3086 eaf7cb2a Stephen Beaver
}
3087
3088 827a3812 jim-p
$section->addInput(new Form_Button(
3089
	'btnadvppp',
3090 faab522f Renato Botelho
	'Advanced and MLPPP',
3091 827a3812 jim-p
	isset($pconfig['pppid']) ? 'interfaces_ppps_edit.php?id=' . htmlspecialchars($pconfig['pppid']) : 'interfaces_ppps_edit.php',
3092
	'fa-cog'
3093 4d0c9c59 Phil Davis
))->setAttribute('type','button')->addClass('btn-info')->setAttribute('id')->setHelp('%sClick for additional PPTP and L2TP configuration options. Save first if changes have been made.', $mlppp_text);
3094 827a3812 jim-p
3095 ae4c4bac Stephen Beaver
$form->add($section);
3096 eaf7cb2a Stephen Beaver
3097
// Wireless interface
3098 a0509b13 Stephen Beaver
if (isset($wancfg['wireless'])) {
3099
3100 5f88f964 k-paulius
	$section = new Form_Section('Common Wireless Configuration - Settings apply to all wireless networks on ' . $wlanbaseif . '.');
3101 68933ba7 Stephen Beaver
3102
	$section->addInput(new Form_Checkbox(
3103
		'persistcommonwireless',
3104
		'Persist common settings',
3105
		'Preserve common wireless configuration through interface deletions and reassignments.',
3106
		$pconfig['persistcommonwireless'],
3107
		'yes'
3108
	));
3109
3110
	$mode_list = ['auto' => 'Auto'];
3111
3112
	if (is_array($wl_modes)) {
3113
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3114
			$mode_list[$wl_standard] = '802.' . $wl_standard;
3115
		}
3116
	}
3117
3118 aa82505e Phil Davis
	if (count($mode_list) == 1) {
3119 68933ba7 Stephen Beaver
		$mode_list[''] = '';
3120 aa82505e Phil Davis
	}
3121 68933ba7 Stephen Beaver
3122
	$section->addInput(new Form_Select(
3123
		'standard',
3124
		'Standard',
3125
		($pconfig['standard'] == "") ? "11ng":$pconfig['standard'],
3126
		$mode_list
3127
	));
3128
3129
	if (isset($wl_modes['11g'])) {
3130
		$section->addInput(new Form_Select(
3131
			'protmode',
3132
			'802.11g OFDM Protection Mode',
3133
			$pconfig['protmode'],
3134 0fc3de67 Phil Davis
			['off' => gettext('Off'), 'cts' => gettext('CTS to self'), 'rtscts' => gettext('RTS and CTS')]
3135 68933ba7 Stephen Beaver
		))->setHelp('For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.');
3136 aa82505e Phil Davis
	} else {
3137 ee12dd78 Peter Feichtinger
		$form->addGlobal(new Form_Input(
3138 68933ba7 Stephen Beaver
			'protmode',
3139
			null,
3140
			'hidden',
3141
			'off'
3142
		));
3143
	}
3144
3145 0fc3de67 Phil Davis
	$mode_list = ['0' => gettext('Auto')];
3146 68933ba7 Stephen Beaver
3147
	if (is_array($wl_modes)) {
3148
		foreach ($wl_modes as $wl_standard => $wl_channels) {
3149
			if ($wl_standard == "11g") {
3150
				$wl_standard = "11b/g";
3151
			} else if ($wl_standard == "11ng") {
3152
				$wl_standard = "11b/g/n";
3153
			} else if ($wl_standard == "11na") {
3154
				$wl_standard = "11a/n";
3155
			}
3156
3157
			foreach ($wl_channels as $wl_channel) {
3158
				if (isset($wl_chaninfo[$wl_channel])) {
3159 91fd7459 Viktor G
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel;
3160 68933ba7 Stephen Beaver
				} else {
3161 91fd7459 Viktor G
					$mode_list[$wl_channel] = $wl_standard . ' - ' . $wl_channel . ' (' . $wl_chaninfo[$wl_channel][1] . ' @ ' . $wl_chaninfo[$wl_channel][2] . ' / ' . $wl_chaninfo[$wl_channel][3] . ')';
3162 68933ba7 Stephen Beaver
				}
3163
			}
3164
		}
3165
	}
3166
3167
	$section->addInput(new Form_Select(
3168
		'channel',
3169
		'Channel',
3170
		$pconfig['channel'],
3171
		$mode_list
3172 4d0c9c59 Phil Davis
	))->setHelp('Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain) %1$s' .
3173
				'Not all channels may be supported by some cards.  Auto may override the wireless standard selected above.', '<br />');
3174 68933ba7 Stephen Beaver
3175 91fd7459 Viktor G
	$section->addInput(new Form_Select(
3176
		'channel_width',
3177
		'Channel width',
3178
		$pconfig['channel_width'],
3179
		$wl_ht_modes
3180
	))->setHelp('Channel width for 802.11n mode. Not all cards may support channel width changing.');
3181
3182 725f987f Stephen Beaver
	if (ANTENNAS) {
3183
		if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3184
			$group = new Form_Group('Antenna Settings');
3185
3186
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])) {
3187
				$group->add(new Form_Select(
3188
					'diversity',
3189
					null,
3190
					(isset($pconfig['diversity'])) ? $pconfig['diversity']:'',
3191 0fc3de67 Phil Davis
					['' => gettext('Default'), '0' => gettext('Off'), '1' => gettext('On')]
3192 725f987f Stephen Beaver
				))->setHelp('Diversity');
3193
			}
3194 68933ba7 Stephen Beaver
3195 725f987f Stephen Beaver
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])) {
3196
				$group->add(new Form_Select(
3197
					'txantenna',
3198
					null,
3199
					(isset($pconfig['txantenna'])) ? $pconfig['txantenna']:'',
3200 0fc3de67 Phil Davis
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3201 725f987f Stephen Beaver
				))->setHelp('Transmit antenna');
3202
			}
3203 68933ba7 Stephen Beaver
3204 725f987f Stephen Beaver
			if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])) {
3205
				$group->add(new Form_Select(
3206
					'rxantenna',
3207
					null,
3208
					(isset($pconfig['rxantenna'])) ? $pconfig['rxantenna']:'',
3209 0fc3de67 Phil Davis
					['' => gettext('Default'), '0' => gettext('Auto'), '1' => gettext('#1'), '2' => gettext('#2')]
3210 725f987f Stephen Beaver
				))->setHelp('Receive antenna');
3211
			}
3212 68933ba7 Stephen Beaver
3213 725f987f Stephen Beaver
			$group->setHelp('Note: The antenna numbers do not always match up with the labels on the card.');
3214 68933ba7 Stephen Beaver
3215 725f987f Stephen Beaver
			$section->add($group);
3216
		}
3217 68933ba7 Stephen Beaver
	}
3218
3219
	if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])) {
3220
			$section->addInput(new Form_Input(
3221
				'distance',
3222
				'Distance setting (meters)',
3223
				'test',
3224
				$pconfig['distance']
3225
			))->setHelp('This field can be used to tune ACK/CTS timers to fit the distance between AP and Client');
3226
	}
3227
3228
	$form->add($section);
3229
3230
	// Regulatory settings
3231 5f88f964 k-paulius
	$section = new Form_Section('Regulatory Settings');
3232 68933ba7 Stephen Beaver
3233
	$domain_list = array("" => 'Default');
3234
3235
	if (is_array($wl_regdomains)) {
3236
		foreach ($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
3237
			$domain_list[$wl_regdomains_attr[$wl_regdomain_key]['ID']] = $wl_regdomain['name'];
3238
		}
3239
	}
3240
3241
	$section->addInput(new Form_Select(
3242
		'regdomain',
3243
		'Regulatory domain',
3244
		$pconfig['regdomain'],
3245
		$domain_list
3246
	))->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');
3247
3248
	$country_list = array('' => 'Default');
3249
3250
	if (is_array($wl_countries)) {
3251
		foreach ($wl_countries as $wl_country_key => $wl_country) {
3252
			$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']);
3253
		}
3254
	}
3255
3256
	$section->addInput(new Form_Select(
3257
		'regcountry',
3258
		'Country',
3259
		$pconfig['regcountry'],
3260
		$country_list
3261
	))->setHelp('Any country setting other than "Default" will override the regulatory domain setting');
3262
3263
	$section->addInput(new Form_Select(
3264
		'reglocation',
3265
		'Location',
3266
		$pconfig['reglocation'],
3267 0fc3de67 Phil Davis
		['' => gettext('Default'), 'indoor' => gettext('Indoor'), 'outdoor' => gettext('Outdoor'), 'anywhere' => gettext('Anywhere')]
3268 68933ba7 Stephen Beaver
	))->setHelp('These settings may affect which channels are available and the maximum transmit power allowed on those channels. ' .
3269 4d0c9c59 Phil Davis
				'Using the correct settings to comply with local regulatory requirements is recommended.%1$s' .
3270 68933ba7 Stephen Beaver
				'All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  ' .
3271
				'Some of the regulatory domains or country codes may not be allowed by some cards.	' .
3272 4d0c9c59 Phil Davis
				'These settings may not be able to add additional channels that are not already supported.', '<br />');
3273 68933ba7 Stephen Beaver
3274
	$form->add($section);
3275
3276 5f88f964 k-paulius
	$section = new Form_Section('Network-Specific Wireless Configuration');
3277 68933ba7 Stephen Beaver
3278
	$section->addInput(new Form_Select(
3279
		'mode',
3280
		'Mode',
3281
		$pconfig['mode'],
3282 0fc3de67 Phil Davis
		['bss' => gettext('Infrastructure (BSS)'), 'adhoc' => gettext('Ad-hoc (IBSS)'), 'hostap' => gettext('Access Point')]
3283 68933ba7 Stephen Beaver
	));
3284
3285
	$section->addInput(new Form_Input(
3286
		'ssid',
3287
		'SSID',
3288
		'text',
3289
		$pconfig['ssid']
3290
	));
3291
3292
	if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])) {
3293
		$section->addInput(new Form_Select(
3294
			'puremode',
3295
			'Minimum wireless standard',
3296
			$pconfig['puremode'],
3297 0fc3de67 Phil Davis
			['any' => gettext('Any'), '11g' => gettext('802.11g'), '11n' => gettext('802.11n')]
3298 68933ba7 Stephen Beaver
		))->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)');
3299
	} elseif (isset($wl_modes['11g'])) {
3300
		$section->addInput(new Form_Checkbox(
3301
			'puremode',
3302
			'802.11g only',
3303 109ebe80 Stephen Beaver
			null,
3304 68933ba7 Stephen Beaver
			$pconfig['puremode'],
3305
			'11g'
3306
		))->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)');
3307
	}
3308
3309
	$section->addInput(new Form_Checkbox(
3310
		'apbridge_enable',
3311
		'Allow intra-BSS communication',
3312
		'Allow packets to pass between wireless clients directly when operating as an access point',
3313
		$pconfig['apbridge_enable'],
3314
		'yes'
3315 11439ca3 jim-p
	))->setHelp('Provides extra security by isolating clients so they cannot directly communicate with one another');
3316 68933ba7 Stephen Beaver
3317
	$section->addInput(new Form_Checkbox(
3318
		'wme_enable',
3319
		'Enable WME',
3320
		'Force the card to use WME (wireless QoS)',
3321
		$pconfig['wme_enable'],
3322
		'yes'
3323
	));
3324
3325
	$section->addInput(new Form_Checkbox(
3326
		'hidessid_enable',
3327
		'Hide SSID',
3328 11439ca3 jim-p
		'Disable broadcasting of the SSID for this network (This may cause problems for some clients, and the SSID may still be discovered by other means.)',
3329 68933ba7 Stephen Beaver
		$pconfig['hidessid_enable'],
3330
		'yes'
3331
	));
3332
3333
	$form->add($section);
3334
3335
	// WPA Section
3336
	$section = new Form_Section('WPA');
3337
3338
	$section->addInput(new Form_Checkbox(
3339
		'wpa_enable',
3340
		'Enable',
3341
		'Enable WPA',
3342
		$pconfig['wpa_enable'],
3343
		'yes'
3344
	));
3345
3346
	$section->addInput(new Form_Select(
3347
		'wpa_mode',
3348
		'WPA mode',
3349
		(isset($pconfig['wpa_mode'])) ? $pconfig['wpa_mode']: '2',
3350 0fc3de67 Phil Davis
		['1' => gettext('WPA'), '2' => gettext('WPA2'), '3' => gettext('Both')]
3351 68933ba7 Stephen Beaver
	));
3352
3353 5f120301 Viktor G
	$section->addInput(new Form_Select(
3354
		'wpa_pairwise',
3355
		'WPA Pairwise',
3356
		(isset($pconfig['wpa_pairwise'])) ? $pconfig['wpa_pairwise']:'CCMP',
3357
		['CCMP TKIP' => gettext('Both'), 'CCMP' => gettext('AES (recommended)'), 'TKIP' => gettext('TKIP')]
3358
	));
3359
3360 68933ba7 Stephen Beaver
	$section->addInput(new Form_Select(
3361
		'wpa_key_mgmt',
3362
		'WPA Key Management Mode',
3363
		$pconfig['wpa_key_mgmt'],
3364 0fc3de67 Phil Davis
		['WPA-PSK' => gettext('Pre-Shared Key'), 'WPA-EAP' => gettext('Extensible Authentication Protocol'), 'WPA-PSK WPA-EAP' => gettext('Both')]
3365 68933ba7 Stephen Beaver
	));
3366
3367 5f120301 Viktor G
	$section->addInput(new Form_Input(
3368
		'passphrase',
3369
		'WPA Pre-Shared Key',
3370
		'text',
3371
		$pconfig['passphrase']
3372
	))->setHelp('WPA Passphrase must be between 8 and 63 characters long');
3373
3374 68933ba7 Stephen Beaver
	$section->addInput(new Form_Select(
3375 5f120301 Viktor G
		'wpa_eap_client_mode',
3376
		'EAP Client Mode',
3377
		$pconfig['wpa_eap_client_mode'],
3378
		['PEAP' => 'PEAP', 'TLS' => 'TLS', 'TTLS' => 'TTLS']
3379
	));
3380
3381
	$section->addInput(new Form_Select(
3382
		'wpa_eap_ca',
3383
		'Certificate Authority',
3384
		$pconfig['wpa_eap_ca'],
3385
		cert_build_list('ca', 'HTTPS')
3386
	));
3387
3388
	$section->addInput(new Form_Select(
3389
		'wpa_eap_inner_auth',
3390
		'Inner Authentication Method',
3391
		$pconfig['wpa_eap_inner_auth'],
3392 296c5881 Viktor G
		['MSCHAPV2' => gettext('MSCHAPv2'), 'MD5' => gettext('MD5'), 'PAP' => gettext('PAP')]
3393 5f120301 Viktor G
	));
3394
3395
	$section->addInput(new Form_Input(
3396
		'wpa_eap_inner_id',
3397
		'*Inner Authentication Identity',
3398
		'text',
3399
		$pconfig['wpa_eap_inner_id']
3400
	));
3401
3402
	$section->addInput(new Form_Input(
3403
		'wpa_eap_inner_password',
3404
		'*Inner Authentication Passphrase',
3405
		'text',
3406
		$pconfig['wpa_eap_inner_password']
3407
	));
3408
3409
	$section->addInput(new Form_Select(
3410
		'wpa_eap_cert',
3411
		'TLS/TTLS Client Certificate',
3412
		$pconfig['wpa_eap_cert'],
3413
		cert_build_list('cert', 'HTTPS')
3414 68933ba7 Stephen Beaver
	));
3415
3416
	$section->addInput(new Form_Input(
3417
		'wpa_group_rekey',
3418 11439ca3 jim-p
		'Group Key Rotation',
3419 68933ba7 Stephen Beaver
		'number',
3420
		$pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60",
3421
		['min' => '1', 'max' => 9999]
3422 11439ca3 jim-p
	))->setHelp('Time between group rekey events, specified in seconds. Allowed values are 1-9999. Must be shorter than Master Key Regeneration time');
3423 68933ba7 Stephen Beaver
3424
	$section->addInput(new Form_Input(
3425
		'wpa_gmk_rekey',
3426 11439ca3 jim-p
		'Group Master Key Regeneration',
3427 68933ba7 Stephen Beaver
		'number',
3428
		$pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600",
3429
		['min' => '1', 'max' => 9999]
3430 11439ca3 jim-p
	))->setHelp('Time between GMK rekey events, specified in seconds. Allowed values are 1-9999. Must be longer than Group Key Rotation time');
3431 68933ba7 Stephen Beaver
3432
	$section->addInput(new Form_Checkbox(
3433
		'wpa_strict_rekey',
3434
		'Strict Key Regeneration',
3435
		'Force the AP to rekey whenever a client disassociates',
3436
		$pconfig['wpa_strict_rekey'],
3437
		'yes'
3438
	));
3439
3440 d65e45d3 Stephen Beaver
	$form->add($section);
3441
3442 5f88f964 k-paulius
	$section = new Form_Section('802.1x RADIUS Options');
3443 5f120301 Viktor G
	$section->addClass('ieee8021x_group');
3444 d65e45d3 Stephen Beaver
3445 68933ba7 Stephen Beaver
	$section->addInput(new Form_Checkbox(
3446
		'ieee8021x',
3447
		'IEEE802.1X',
3448
		'Enable 802.1X authentication',
3449
		$pconfig['ieee8021x'],
3450
		'yes'
3451 5f120301 Viktor G
	));
3452 68933ba7 Stephen Beaver
3453
	$group = new Form_Group('Primary 802.1X server');
3454
3455
	$group->add(new Form_IpAddress(
3456
		'auth_server_addr',
3457
		'IP Address',
3458
		$pconfig['auth_server_addr']
3459 11439ca3 jim-p
	))->setHelp('IP address of the RADIUS server');
3460 68933ba7 Stephen Beaver
3461
	$group->add(new Form_Input(
3462
		'auth_server_port',
3463
		'Port',
3464
		'number',
3465
		$pconfig['auth_server_port']
3466 11439ca3 jim-p
	))->setHelp('Server auth port. Default is 1812');
3467 68933ba7 Stephen Beaver
3468
	$group->add(new Form_Input(
3469
		'auth_server_shared_secret',
3470 11439ca3 jim-p
		'Shared Secret',
3471 1b2527f2 jim-p
		'text',
3472 68933ba7 Stephen Beaver
		$pconfig['auth_server_shared_secret']
3473 11439ca3 jim-p
	))->setHelp('RADIUS Shared secret for this firewall');
3474 68933ba7 Stephen Beaver
3475
	$section->add($group);
3476
3477
	$group = new Form_Group('Secondary 802.1X server');
3478
3479
	$group->add(new Form_IpAddress(
3480
		'auth_server_addr2',
3481
		'IP Address',
3482
		$pconfig['auth_server_addr2']
3483 11439ca3 jim-p
	))->setHelp('IP address of the RADIUS server');
3484 68933ba7 Stephen Beaver
3485
	$group->add(new Form_Input(
3486
		'auth_server_port2',
3487
		'Port',
3488
		'number',
3489
		$pconfig['auth_server_port2']
3490 11439ca3 jim-p
	))->setHelp('Server auth port. Default is 1812');
3491 68933ba7 Stephen Beaver
3492
	$group->add(new Form_Input(
3493
		'auth_server_shared_secret2',
3494 11439ca3 jim-p
		'Shared Secret',
3495 1b2527f2 jim-p
		'text',
3496 68933ba7 Stephen Beaver
		$pconfig['auth_server_shared_secret2']
3497 11439ca3 jim-p
	))->setHelp('RADIUS Shared secret for this firewall');
3498 68933ba7 Stephen Beaver
3499
	$section->add($group);
3500
3501
	$section->addInput(new Form_Checkbox(
3502
		'rsn_preauth',
3503
		'Authentication Roaming Preauth',
3504
		null,
3505
		$pconfig['rsn_preauth'],
3506
		'yes'
3507 5f120301 Viktor G
	))->setHelp('Pre-authentication to speed up roaming between access points.');
3508 68933ba7 Stephen Beaver
3509
	$form->add($section);
3510 a0509b13 Stephen Beaver
}
3511
3512 3cf65ce0 NOYB
$section = new Form_Section('Reserved Networks');
3513 a0509b13 Stephen Beaver
3514
$section->addInput(new Form_Checkbox(
3515 68933ba7 Stephen Beaver
	'blockpriv',
3516 eaa948d6 NOYB
	'Block private networks and loopback addresses',
3517 68933ba7 Stephen Beaver
	'',
3518
	$pconfig['blockpriv'],
3519
	'yes'
3520 a0509b13 Stephen Beaver
))->setHelp('Blocks traffic from IP addresses that are reserved for private networks per RFC 1918 (10/8, 172.16/12, 192.168/16) ' .
3521 eaa948d6 NOYB
			'and unique local addresses per RFC 4193 (fc00::/7) as well as loopback addresses (127/8). This option should ' .
3522
			'generally be turned on, unless this network interface resides in such a private address space, too.');
3523 68933ba7 Stephen Beaver
3524 aa82505e Phil Davis
$section->addInput(new Form_Checkbox(
3525 68933ba7 Stephen Beaver
	'blockbogons',
3526
	'Block bogon networks',
3527
	'',
3528
	$pconfig['blockbogons'],
3529
	'yes'
3530 a0509b13 Stephen Beaver
))->setHelp('Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should ' .
3531 4d0c9c59 Phil Davis
			'never appear in the Internet routing table, and so should not appear as the source address in any packets received.%1$s' .
3532 d16ea02a jim-p
			'This option should only be used on external interfaces (WANs), it is not necessary on local interfaces and it can potentially block required local traffic.%1$s' .
3533 7dfb18da Joseph Reeves
			'Note: The update frequency can be changed under System > Advanced, Firewall & NAT settings.', '<br />');
3534 eaf7cb2a Stephen Beaver
3535
$form->add($section);
3536 a0509b13 Stephen Beaver
3537
$form->addGlobal(new Form_Input(
3538 68933ba7 Stephen Beaver
	'if',
3539
	null,
3540
	'hidden',
3541
	$if
3542 a0509b13 Stephen Beaver
));
3543
3544 6a9435a6 Viktor G
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
3545
	$form->addGlobal(new Form_Input(
3546
		'ppp_port',
3547
		null,
3548
		'hidden',
3549
		$pconfig['port']
3550
	));
3551
}
3552
3553 a0509b13 Stephen Beaver
$form->addGlobal(new Form_Input(
3554 68933ba7 Stephen Beaver
	'ptpid',
3555
	null,
3556
	'hidden',
3557
	$pconfig['ptpid']
3558 a0509b13 Stephen Beaver
));
3559
3560 564599fa Stephen Beaver
3561
// Add new gateway modal pop-up
3562 dfafd8c2 Phil Davis
$modal = new Modal('New IPv4 Gateway', 'newgateway4', 'large');
3563 564599fa Stephen Beaver
3564
$modal->addInput(new Form_Checkbox(
3565 dfafd8c2 Phil Davis
	'defaultgw4',
3566 564599fa Stephen Beaver
	'Default',
3567
	'Default gateway',
3568 e8113404 Phil Davis
	isset($gateway_settings4['defaultgw']) ? $gateway_settings4['defaultgw'] : ($if == "wan" || $if == "WAN")
3569 564599fa Stephen Beaver
));
3570
3571
$modal->addInput(new Form_Input(
3572 dfafd8c2 Phil Davis
	'gatewayname4',
3573 564599fa Stephen Beaver
	'Gateway name',
3574
	'text',
3575 e8113404 Phil Davis
	($gateway_settings4['name'] == "") ? $defgatewayname4 : $gateway_settings4['name']
3576 564599fa Stephen Beaver
));
3577
3578
$modal->addInput(new Form_IpAddress(
3579 dfafd8c2 Phil Davis
	'gatewayip4',
3580 564599fa Stephen Beaver
	'Gateway IPv4',
3581 e8113404 Phil Davis
	$gateway_settings4['gateway'],
3582 41fc88ec Phil Davis
	'V4'
3583 564599fa Stephen Beaver
));
3584
3585
$modal->addInput(new Form_Input(
3586 dfafd8c2 Phil Davis
	'gatewaydescr4',
3587 564599fa Stephen Beaver
	'Description',
3588 e8113404 Phil Davis
	'text',
3589
	$gateway_settings4['descr']
3590 564599fa Stephen Beaver
));
3591
3592 dfafd8c2 Phil Davis
$btnaddgw4 = new Form_Button(
3593
	'add4',
3594 faab522f Renato Botelho
	'Add',
3595 2e7fa7ca jim-p
	null,
3596
	'fa-plus'
3597 564599fa Stephen Beaver
);
3598
3599 dfafd8c2 Phil Davis
$btnaddgw4->setAttribute('type','button')->addClass('btn-success');
3600 564599fa Stephen Beaver
3601 dfafd8c2 Phil Davis
$btncnxgw4 = new Form_Button(
3602
	'cnx4',
3603 faab522f Renato Botelho
	'Cancel',
3604 2e7fa7ca jim-p
	null,
3605
	'fa-undo'
3606 564599fa Stephen Beaver
);
3607
3608 dfafd8c2 Phil Davis
$btncnxgw4->setAttribute('type','button')->addClass('btn-warning');
3609 564599fa Stephen Beaver
3610
$modal->addInput(new Form_StaticText(
3611
	null,
3612 dfafd8c2 Phil Davis
	$btnaddgw4 . $btncnxgw4
3613 564599fa Stephen Beaver
));
3614
3615
$form->add($modal);
3616
3617 ae4c4bac Stephen Beaver
print($form);
3618
?>
3619 a0509b13 Stephen Beaver
3620 ae4c4bac Stephen Beaver
<script type="text/javascript">
3621 309e8f8f Stephen Beaver
//<![CDATA[
3622 aa82505e Phil Davis
events.push(function() {
3623 68933ba7 Stephen Beaver
	function updateType(t) {
3624 564599fa Stephen Beaver
3625 68933ba7 Stephen Beaver
		switch (t) {
3626
			case "none": {
3627 34ab580d Stephen Beaver
				$('.dhcpadvanced, .staticv4, .dhcp, .pppoe, .pptp, .ppp').hide();
3628 68933ba7 Stephen Beaver
				break;
3629
			}
3630
			case "staticv4": {
3631 2ed5fb61 Phil Davis
				$('.dhcpadvanced, .none, .dhcp').hide();
3632 564599fa Stephen Beaver
				$('.pppoe, .pptp, .ppp').hide();
3633 68933ba7 Stephen Beaver
				break;
3634
			}
3635
			case "dhcp": {
3636 564599fa Stephen Beaver
				$('.dhcpadvanced, .none').hide();
3637
				$('.staticv4').hide();	// MYSTERY: This line makes the page very slow to load, but why? There is nothing special
3638
										//			about the staticv4 class
3639
				$('.pppoe, .pptp, .ppp').hide();
3640 68933ba7 Stephen Beaver
				break;
3641
			}
3642
			case "ppp": {
3643 34ab580d Stephen Beaver
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .pppoe').hide();
3644 68933ba7 Stephen Beaver
				country_list();
3645
				break;
3646
			}
3647
			case "pppoe": {
3648 34ab580d Stephen Beaver
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pptp, .ppp').hide();
3649 68933ba7 Stephen Beaver
				break;
3650
			}
3651 8e267d3b Viktor G
			case "l2tp": {
3652 34ab580d Stephen Beaver
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp').hide();
3653 8e267d3b Viktor G
				$('.pptp, .l2tp_secret').show();
3654
				break;
3655
			}
3656
			case "pptp": {
3657
				$('.dhcpadvanced, .none, .staticv4, .dhcp, .pppoe, .ppp, .l2tp_secret').hide();
3658 68933ba7 Stephen Beaver
				$('.pptp').show();
3659
				break;
3660
			}
3661
		}
3662
3663
		if (t != "l2tp" && t != "pptp") {
3664
			$('.'+t).show();
3665
		}
3666
	}
3667
3668
	function updateTypeSix(t) {
3669 aa82505e Phil Davis
		if (!isNaN(t[0])) {
3670 68933ba7 Stephen Beaver
			t = '_' + t;
3671 aa82505e Phil Davis
		}
3672 68933ba7 Stephen Beaver
3673
		switch (t) {
3674
			case "none": {
3675 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .staticv6, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3676 68933ba7 Stephen Beaver
				break;
3677
			}
3678
			case "staticv6": {
3679 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .dhcp6, ._6rd, ._6to4, .track6, .slaac').hide();
3680 68933ba7 Stephen Beaver
				break;
3681
			}
3682
			case "slaac": {
3683 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .dhcp6').hide();
3684 68933ba7 Stephen Beaver
				break;
3685
			}
3686
			case "dhcp6": {
3687 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .staticv6, ._6rd, ._6to4, .track6, .slaac').hide();
3688 68933ba7 Stephen Beaver
				break;
3689
			}
3690 ea125f70 Chris Buechler
			case "_6rd": {
3691 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6to4, .track6, .slaac').hide();
3692 68933ba7 Stephen Beaver
				break;
3693
			}
3694
			case "_6to4": {
3695 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, .track6, .slaac').hide();
3696 68933ba7 Stephen Beaver
				break;
3697
			}
3698
			case "track6": {
3699 c0c25504 Stephen Beaver
				$('.dhcp6advanced, .none, .dhcp6, .staticv6, ._6rd, ._6to4, .slaac').hide();
3700 68933ba7 Stephen Beaver
				update_track6_prefix();
3701
				break;
3702
			}
3703
		}
3704
3705
		if (t != "l2tp" && t != "pptp") {
3706
			$('.'+t).show();
3707
		}
3708
	}
3709
3710
	function show_reset_settings(reset_type) {
3711
		if (reset_type == 'preset') {
3712
			$('.pppoepreset').show();
3713
			$('.pppoecustom').hide();
3714
		} else if (reset_type == 'custom') {
3715
			$('.pppoecustom').show();
3716
			$('.pppoepreset').hide();
3717
		} else {
3718
			$('.pppoecustom').hide();
3719
			$('.pppoepreset').hide();
3720
		}
3721
	}
3722
3723
	function update_track6_prefix() {
3724
		var iface = $("#track6-interface").val();
3725
		if (iface == null) {
3726
			return;
3727
		}
3728
3729
		var track6_prefix_ids = $('#ipv6-num-prefix-ids-' + iface).val();
3730
		if (track6_prefix_ids == null) {
3731
			return;
3732
		}
3733
3734
		track6_prefix_ids = parseInt(track6_prefix_ids).toString(16);
3735 4d0c9c59 Phil Davis
		$('#track6-prefix-id-range').html(track6_prefix_ids);
3736 68933ba7 Stephen Beaver
	}
3737
3738 e8113404 Phil Davis
	function addOption_v4() {
3739
		var gwtext_v4 = escape($("#gatewayname4").val()) + " - " + $("#gatewayip4").val();
3740
		addSelectboxOption($('#gateway'), gwtext_v4, $("#gatewayname4").val());
3741 68933ba7 Stephen Beaver
	}
3742
3743 e8113404 Phil Davis
	function addOption_v6() {
3744
		var gwtext_v6 = escape($("#gatewayname6").val()) + " - " + $("#gatewayip6").val();
3745 b4538739 Phil Davis
		addSelectboxOption($('#gatewayv6'), gwtext_v6, $("#gatewayname6").val());
3746 68933ba7 Stephen Beaver
	}
3747
3748 e8113404 Phil Davis
	function addSelectboxOption(selectbox, text, value) {
3749 68933ba7 Stephen Beaver
		var optn = document.createElement("OPTION");
3750
		optn.text = text;
3751
		optn.value = value;
3752
		selectbox.append(optn);
3753
		selectbox.prop('selectedIndex', selectbox.children().length - 1);
3754
	}
3755
3756
	function country_list() {
3757
		$('#country').children().remove();
3758
		$('#provider_list').children().remove();
3759
		$('#providerplan').children().remove();
3760
		$.ajax("getserviceproviders.php",{
3761
			success: function(response) {
3762
3763
				var responseTextArr = response.split("\n");
3764
				responseTextArr.sort();
3765
3766
				responseTextArr.forEach( function(value) {
3767
					country = value.split(":");
3768
					$('#country').append($('<option>', {
3769
						value: country[1],
3770
						text : country[0]
3771
					}));
3772
				});
3773
			}
3774
		});
3775
	}
3776
3777
	function providers_list() {
3778
		$('#provider_list').children().remove();
3779
		$('#providerplan').children().remove();
3780
		$.ajax("getserviceproviders.php",{
3781
			type: 'post',
3782
			data: {country : $('#country').val()},
3783
			success: function(response) {
3784
				var responseTextArr = response.split("\n");
3785
				responseTextArr.sort();
3786
				responseTextArr.forEach( function(value) {
3787
					$('#provider_list').append($('<option>', {
3788
							value: value,
3789
							text : value
3790
					}));
3791
				});
3792
			}
3793
		});
3794
	}
3795
3796
	function providerplan_list() {
3797
		$('#providerplan').children().remove();
3798
		$.ajax("getserviceproviders.php",{
3799
			type: 'post',
3800
			data: {country : $('#country').val(), provider : $('#provider_list').val()},
3801
			success: function(response) {
3802
				var responseTextArr = response.split("\n");
3803
				responseTextArr.sort();
3804
3805
				$('#providerplan').append($('<option>', {
3806
					value: '',
3807
					text : ''
3808
				}));
3809
3810
				responseTextArr.forEach( function(value) {
3811
					if (value != "") {
3812
						providerplan = value.split(":");
3813
3814
						$('#providerplan').append($('<option>', {
3815
							value: providerplan[1],
3816
							text : providerplan[0] + " - " + providerplan[1]
3817
						}));
3818
					}
3819
				});
3820
			}
3821
		});
3822
	}
3823
3824
	function prefill_provider() {
3825
		$.ajax("getserviceproviders.php",{
3826
			type: 'post',
3827
			data: {country : $('#country').val(), provider : $('#provider_list').val(), plan : $('#providerplan').val()},
3828
			success: function(data, textStatus, response) {
3829
				var xmldoc = response.responseXML;
3830
				var provider = xmldoc.getElementsByTagName('connection')[0];
3831
				$('#ppp_username').val('');
3832
				$('#ppp_password').val('');
3833
				if (provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
3834
					$('#phone').val('#777');
3835
					$('#apn').val('');
3836
				} else {
3837
					$('#phone').val('*99#');
3838
					$('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
3839
				}
3840
				ppp_username = provider.getElementsByTagName('ppp_username')[0].firstChild.data;
3841
				ppp_password = provider.getElementsByTagName('ppp_password')[0].firstChild.data;
3842
				$('#ppp_username').val(ppp_username);
3843
				$('#ppp_password').val(ppp_password);
3844
			}
3845
		});
3846
	}
3847
3848
	function show_dhcp6adv() {
3849
		var ovr = $('#adv_dhcp6_config_file_override').prop('checked');
3850 7361f6c2 Stephen Beaver
		var adv = $('#adv_dhcp6_config_advanced').prop('checked');
3851 68933ba7 Stephen Beaver
3852
		hideCheckbox('dhcp6usev4iface', ovr);
3853
		hideCheckbox('dhcp6prefixonly', ovr);
3854
		hideInput('dhcp6-ia-pd-len', ovr);
3855
		hideCheckbox('dhcp6-ia-pd-send-hint', ovr);
3856
		hideInput('adv_dhcp6_config_file_override_path', !ovr);
3857
3858
		hideClass('dhcp6advanced', !adv || ovr);
3859
	}
3860
3861 34ab580d Stephen Beaver
	function setDHCPoptions() {
3862 0c5916ce NOYB
		var adv = $('#adv_dhcp_config_advanced').prop('checked');
3863
		var ovr = $('#adv_dhcp_config_file_override').prop('checked');
3864 34ab580d Stephen Beaver
3865 aa82505e Phil Davis
		if (ovr) {
3866 34ab580d Stephen Beaver
			hideInput('dhcphostname', true);
3867
			hideIpAddress('alias-address', true);
3868
			hideInput('dhcprejectfrom', true);
3869
			hideInput('adv_dhcp_config_file_override_path', false);
3870
			hideClass('dhcpadvanced', true);
3871
		} else {
3872
			hideInput('dhcphostname', false);
3873
			hideIpAddress('alias-address', false);
3874
			hideInput('dhcprejectfrom', false);
3875
			hideInput('adv_dhcp_config_file_override_path', true);
3876
			hideClass('dhcpadvanced', !adv);
3877
		}
3878
	}
3879
3880 564599fa Stephen Beaver
	// DHCP preset actions
3881
	// Set presets from value of radio buttons
3882
	function setPresets(val) {
3883
		// timeout, retry, select-timeout, reboot, backoff-cutoff, initial-interval
3884
		if (val == "DHCP")		setPresetsnow("60", "300", "0", "10", "120", "10");
3885
		if (val == "pfSense")	setPresetsnow("60", "15", "0", "", "", "1");
3886
		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']);?>");
3887
		if (val == "Clear")		setPresetsnow("", "", "", "", "", "");
3888
	}
3889
3890
	function setPresetsnow(timeout, retry, selecttimeout, reboot, backoffcutoff, initialinterval) {
3891
		$('#adv_dhcp_pt_timeout').val(timeout);
3892
		$('#adv_dhcp_pt_retry').val(retry);
3893
		$('#adv_dhcp_pt_select_timeout').val(selecttimeout);
3894
		$('#adv_dhcp_pt_reboot').val(reboot);
3895
		$('#adv_dhcp_pt_backoff_cutoff').val(backoffcutoff);
3896
		$('#adv_dhcp_pt_initial_interval').val(initialinterval);
3897
	}
3898
3899 fb572e81 Phil Davis
	function setPPPoEDialOnDemandItems() {
3900 32a85c63 Phil Davis
		setRequired('pppoe_idletimeout', $('#pppoe_dialondemand').prop('checked'));
3901
	}
3902
3903 fb572e81 Phil Davis
	function setPPTPDialOnDemandItems() {
3904
		setRequired('pptp_idletimeout', $('#pptp_dialondemand').prop('checked'));
3905
	}
3906
3907 5f120301 Viktor G
	function show_wpaoptions() {
3908
		var wpa = !($('#wpa_enable').prop('checked'));
3909
3910
		hideInput('passphrase', wpa);
3911
		hideInput('wpa_mode', wpa);
3912
		hideInput('wpa_key_mgmt', wpa);
3913
		hideInput('wpa_pairwise', wpa);
3914
		hideCheckbox('wpa_strict_rekey', wpa);
3915
		hideClass('ieee8021x_group', true);
3916
		if ($('#mode').val() == 'hostap') {
3917
			hideInput('wpa_group_rekey', wpa);
3918
			hideInput('wpa_gmk_rekey', wpa);
3919
			hideCheckbox('wpa_strict_rekey', wpa);
3920
		} else {
3921
			hideInput('wpa_group_rekey', true);
3922
			hideInput('wpa_gmk_rekey', true);
3923
			hideCheckbox('wpa_strict_rekey', true);
3924
		}
3925
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3926
	}
3927
3928
	function updatewifistandard(s) {
3929
		switch (s) {
3930
			case "auto": {
3931
				hideInput('protmode', false);
3932
				hideInput('channel_width', false);
3933
				break;
3934
			}
3935
			case "11b": {
3936
				hideInput('protmode', true);
3937
				hideInput('channel_width', true);
3938
				break;
3939
			}
3940
			case "11g": {
3941
				hideInput('protmode', false);
3942
				hideInput('channel_width', true);
3943
				break;
3944
			}
3945
			case "11ng": {
3946
				hideInput('protmode', false);
3947
				hideInput('channel_width', false);
3948
				break;
3949
			}
3950
			case "11a": {
3951
				hideInput('protmode', true);
3952
				hideInput('channel_width', true);
3953
				break;
3954
			}
3955
			case "11na": {
3956
				hideInput('protmode', true);
3957
				hideInput('channel_width', false);
3958
				break;
3959
			}
3960
			default: {
3961
				break;
3962
			}
3963
		}
3964
	}
3965
3966
	function updatewifimode(m) {
3967
		switch (m) {
3968
			case "adhoc": {
3969
				hideInput('puremode', true);
3970
				hideCheckbox('apbridge_enable', true);
3971
				hideCheckbox('hidessid_enable', false);
3972
				break;
3973
			}
3974
			case "hostap": {
3975
				hideInput('puremode', false);
3976
				hideCheckbox('apbridge_enable', false);
3977
				hideCheckbox('hidessid_enable', false);
3978
				break;
3979
			}
3980
			default: {
3981
				hideInput('puremode', true);
3982
				hideCheckbox('apbridge_enable', true);
3983
				hideCheckbox('hidessid_enable', true);
3984
				break;
3985
			}
3986
		}
3987
		show_wpaoptions();
3988 f9d9d77e Viktor G
		updateeapclientmode($('#wpa_eap_client_mode').val());
3989
		updatewpakeymgmt($('#wpa_key_mgmt').val());
3990 5f120301 Viktor G
	}
3991
3992
	function updateeapclientmode(m) {
3993 f9d9d77e Viktor G
		if ($('#mode').val() == 'bss') {
3994
			var wpa = !($('#wpa_enable').prop('checked'));
3995
		} else {
3996
			var wpa = true;
3997
		}
3998 5f120301 Viktor G
		switch (m) {
3999 c7839f15 Viktor G
			case "PEAP": {
4000 5f120301 Viktor G
				hideInput('wpa_eap_cert', true);
4001
				hideInput('wpa_eap_inner_auth', wpa);
4002
				hideInput('wpa_eap_inner_id', wpa);
4003
				hideInput('wpa_eap_inner_password', wpa);
4004
				break;
4005
			}
4006 c7839f15 Viktor G
			case "TLS": {
4007 5f120301 Viktor G
				hideInput('wpa_eap_cert', wpa);
4008
				hideInput('wpa_eap_inner_auth', true);
4009
				hideInput('wpa_eap_inner_id', true);
4010
				hideInput('wpa_eap_inner_password', true);
4011
				break;
4012
			}
4013 c7839f15 Viktor G
			case "TTLS": {
4014 5f120301 Viktor G
				hideInput('wpa_eap_cert', wpa);
4015
				hideInput('wpa_eap_inner_auth', wpa);
4016
				hideInput('wpa_eap_inner_id', wpa);
4017
				hideInput('wpa_eap_inner_password', wpa);
4018
				break;
4019
			}
4020
			default: {
4021
				break;
4022
			}
4023
		}
4024
	}
4025
4026
	function updatewpakeymgmt(m) {
4027 f9d9d77e Viktor G
		hideInput('passphrase', false);
4028
		hideInput('wpa_eap_client_mode', true);
4029
		hideInput('wpa_eap_ca', true);
4030
		hideInput('wpa_eap_cert', true);
4031
		hideInput('wpa_eap_inner_auth', true);
4032
		hideInput('wpa_eap_inner_id', true);
4033
		hideInput('wpa_eap_inner_password', true);
4034
		hideClass('ieee8021x_group', true);
4035
		if (m == "WPA-EAP") {
4036 5f120301 Viktor G
			hideInput('passphrase', true);
4037 f9d9d77e Viktor G
			if ($('#mode').val() == 'bss') {
4038
				hideInput('wpa_eap_client_mode', false);
4039
				hideInput('wpa_eap_ca', false);
4040
				updateeapclientmode($('#wpa_eap_client_mode').val());
4041
			} else if ($('#mode').val() == 'hostap') {
4042
				hideClass('ieee8021x_group', false);
4043
			}
4044
		} else if (m != "WPA-PSK") {
4045
			hideInput('passphrase', false);
4046
			if ($('#mode').val() == 'bss') {
4047
				hideInput('wpa_eap_client_mode', false);
4048
				hideInput('wpa_eap_ca', false);
4049
				hideInput('wpa_eap_cert', false);
4050
				hideInput('wpa_eap_inner_auth', false);
4051
				hideInput('wpa_eap_inner_id', false);
4052
				hideInput('wpa_eap_inner_password', false);
4053
			} else if ($('#mode').val() == 'hostap') {
4054
				hideClass('ieee8021x_group', false);
4055
			}
4056 5f120301 Viktor G
		}
4057
	}
4058
4059 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
4060
4061 68933ba7 Stephen Beaver
	updateType($('#type').val());
4062
	updateTypeSix($('#type6').val());
4063
	show_reset_settings($('#pppoe-reset-type').val());
4064
	hideClass('dhcp6advanced', true);
4065 34ab580d Stephen Beaver
	hideClass('dhcpadvanced', true);
4066 68933ba7 Stephen Beaver
	show_dhcp6adv();
4067 32a85c63 Phil Davis
	setDHCPoptions();
4068 fb572e81 Phil Davis
	setPPPoEDialOnDemandItems();
4069
	setPPTPDialOnDemandItems();
4070 5f120301 Viktor G
	show_wpaoptions();
4071
	updatewifistandard($('#standard').val());
4072
	updatewifimode($('#mode').val());
4073 68933ba7 Stephen Beaver
4074 564599fa Stephen Beaver
	// Set preset buttons on page load
4075
	var sv = "<?=htmlspecialchars($pconfig['adv_dhcp_pt_values']);?>";
4076 aa82505e Phil Davis
	if (sv == "") {
4077 564599fa Stephen Beaver
		$("input[name=adv_dhcp_pt_values][value='SavedCfg']").prop('checked', true);
4078 b4f03056 NOYB
	} else {
4079
		$("input[name=adv_dhcp_pt_values][value="+sv+"]").prop('checked', true);
4080 aa82505e Phil Davis
	}
4081 564599fa Stephen Beaver
4082
	// Set preset from value
4083
	setPresets(sv);
4084 aa82505e Phil Davis
4085 e8113404 Phil Davis
	// If the user wants to add a gateway, then add that to the gateway selection
4086
	if ($("#gatewayip4").val() != '') {
4087
		addOption_v4();
4088
	}
4089
	if ($("#gatewayip6").val() != '') {
4090
		addOption_v6();
4091
	}
4092
4093 eef93144 Jared Dillard
	// ---------- Click checkbox handlers ---------------------------------------------------------
4094 9abccff3 Stephen Beaver
4095 564599fa Stephen Beaver
	$('#type').on('change', function() {
4096 aa82505e Phil Davis
		updateType(this.value);
4097 68933ba7 Stephen Beaver
	});
4098 3375f236 Stephen Beaver
4099 34ab580d Stephen Beaver
	$('#type6').on('change', function() {
4100 aa82505e Phil Davis
		updateTypeSix(this.value);
4101 68933ba7 Stephen Beaver
	});
4102 3375f236 Stephen Beaver
4103 5f120301 Viktor G
	$('#standard').on('change', function() {
4104
		updatewifistandard(this.value);
4105
	});
4106
4107
	$('#mode').on('change', function() {
4108
		updatewifimode(this.value);
4109
	});
4110
4111
	$('#wpa_key_mgmt').on('change', function() {
4112
		updatewpakeymgmt(this.value);
4113
	});
4114
4115
	$('#wpa_eap_client_mode').on('change', function() {
4116
		updateeapclientmode(this.value);
4117
	});
4118
4119 1ee6d09a Phil Davis
	$('#track6-interface').on('change', function() {
4120
		update_track6_prefix();
4121
	});
4122
4123 34ab580d Stephen Beaver
	$('#pppoe-reset-type').on('change', function() {
4124 aa82505e Phil Davis
		show_reset_settings(this.value);
4125 68933ba7 Stephen Beaver
	});
4126
4127 dfafd8c2 Phil Davis
	$("#add4").click(function() {
4128 e8113404 Phil Davis
		addOption_v4();
4129 f1bb5c7f Phil Davis
		$("#newgateway4").modal('hide');
4130 68933ba7 Stephen Beaver
	});
4131
4132 dfafd8c2 Phil Davis
	$("#cnx4").click(function() {
4133 f1bb5c7f Phil Davis
		$("#gatewayname4").val('<?=$defgatewayname4;?>');
4134
		$("#gatewayip4").val('');
4135
		$("#gatewaydescr4").val('');
4136 e8113404 Phil Davis
		$("#defaultgw4").prop("checked", false);
4137 dfafd8c2 Phil Davis
		$("#newgateway4").modal('hide');
4138 68933ba7 Stephen Beaver
	});
4139
4140
	$("#add6").click(function() {
4141 e8113404 Phil Davis
		addOption_v6();
4142 f1bb5c7f Phil Davis
		$("#newgateway6").modal('hide');
4143 68933ba7 Stephen Beaver
	});
4144
4145
	$("#cnx6").click(function() {
4146 f1bb5c7f Phil Davis
		$("#gatewayname6").val('<?=$defgatewayname6;?>');
4147
		$("#gatewayip6").val('');
4148
		$("#gatewaydescr6").val('');
4149 e8113404 Phil Davis
		$("#defaultgw6").prop("checked", false);
4150 68933ba7 Stephen Beaver
		$("#newgateway6").modal('hide');
4151
	});
4152
4153
	$('#country').on('change', function() {
4154
		providers_list();
4155
	});
4156
4157
	$('#provider_list').on('change', function() {
4158
		providerplan_list();
4159
	});
4160
4161
	$('#providerplan').on('change', function() {
4162
		prefill_provider();
4163
	});
4164
4165 0c5916ce NOYB
	$('#adv_dhcp_config_advanced, #adv_dhcp_config_file_override').click(function () {
4166 34ab580d Stephen Beaver
		setDHCPoptions();
4167
	});
4168
4169 7361f6c2 Stephen Beaver
	$('#adv_dhcp6_config_advanced').click(function () {
4170 68933ba7 Stephen Beaver
		show_dhcp6adv();
4171
	});
4172
4173
	$('#adv_dhcp6_config_file_override').click(function () {
4174
		show_dhcp6adv();
4175
	});
4176
4177
	// On click . .
4178 32a85c63 Phil Davis
	$('#pppoe_dialondemand').click(function () {
4179 fb572e81 Phil Davis
		setPPPoEDialOnDemandItems();
4180
	});
4181
4182
	$('#pptp_dialondemand').click(function () {
4183
		setPPTPDialOnDemandItems();
4184 32a85c63 Phil Davis
	});
4185
4186 b4f03056 NOYB
	$('[name=adv_dhcp_pt_values]').click(function () {
4187 68933ba7 Stephen Beaver
	   setPresets($('input[name=adv_dhcp_pt_values]:checked').val());
4188
	});
4189 564599fa Stephen Beaver
4190 5f120301 Viktor G
	$('#wpa_enable').click(function () {
4191
		show_wpaoptions();
4192
	});
4193
4194 d85d82b7 Stephen Beaver
	$('#pppoe_resetdate').datepicker();
4195
4196 aeeda8b4 Stephen Beaver
});
4197
//]]>
4198
</script>
4199 ae4c4bac Stephen Beaver
4200 241111d7 Stephen Beaver
<?php include("foot.inc");