Project

General

Profile

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