Project

General

Profile

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