Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5656fe23 Ermal Lu?i
<?php
2
/*
3 c5d81585 Renato Botelho
 * vpn_l2tp.php
4 b9043cdc 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
 * All rights reserved.
10 b9043cdc Stephen Beaver
 *
11 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14 b9043cdc Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 b9043cdc Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22 b9043cdc Stephen Beaver
 */
23 5656fe23 Ermal Lu?i
24 047cb829 Ermal Lu?i
##|+PRIV
25
##|*IDENT=page-vpn-vpnl2tp
26 9599211d jim-p
##|*NAME=VPN: L2TP
27
##|*DESCR=Allow access to the 'VPN: L2TP' page.
28 047cb829 Ermal Lu?i
##|*MATCH=vpn_l2tp.php*
29
##|-PRIV
30
31 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
32 483e6de8 Scott Ullrich
require_once("vpn.inc");
33 5656fe23 Ermal Lu?i
34 c6c398c6 jim-p
init_config_arr(array('l2tp', 'radius'));
35 5656fe23 Ermal Lu?i
$l2tpcfg = &$config['l2tp'];
36
37
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
38
$pconfig['localip'] = $l2tpcfg['localip'];
39 a56120f2 Ermal Lu?i
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
40 5656fe23 Ermal Lu?i
$pconfig['mode'] = $l2tpcfg['mode'];
41
$pconfig['interface'] = $l2tpcfg['interface'];
42 c8cc0c1c smos
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
43
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
44 5656fe23 Ermal Lu?i
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
45
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
46
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
47
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
48 9a9b0007 Phil Davis
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
49 5656fe23 Ermal Lu?i
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
50
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
51 40de0b13 Ermal Lu?i
$pconfig['secret'] = $l2tpcfg['secret'];
52 5656fe23 Ermal Lu?i
53 84450372 Steve Beaver
if ($_POST['save']) {
54 5656fe23 Ermal Lu?i
55
	unset($input_errors);
56
	$pconfig = $_POST;
57
58
	/* input validation */
59
	if ($_POST['mode'] == "server") {
60 ad1a6de3 Viktor Gurov
		$reqdfields = explode(" ", "localip");
61
		$reqdfieldsn = array(gettext("Server address"));
62
		if (!$_POST['radiusenable'] || !$_POST['radiusissueips']) {
63
			$reqdfields = array_merge($reqdfields, explode(" ", "remoteip"));
64
			$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Remote start address")));
65
		} elseif ($_POST['radiusenable']) {
66 5656fe23 Ermal Lu?i
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
67
			$reqdfieldsn = array_merge($reqdfieldsn,
68 a3e00d53 Phil Davis
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
69 5656fe23 Ermal Lu?i
		}
70
71 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
72 5656fe23 Ermal Lu?i
73 ad1a6de3 Viktor Gurov
		if (($_POST['localip'] && !is_ipaddrv4($_POST['localip']))) {
74 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid server address must be specified.");
75
		}
76 0a0b17d9 Renato Botelho
		if (is_ipaddr_configured($_POST['localip'])) {
77
			$input_errors[] = gettext("'Server address' parameter should NOT be set to any IP address currently in use on this firewall.");
78
		}
79 ad1a6de3 Viktor Gurov
		if ($_POST['l2tp_subnet'] && !is_ipaddrv4($_POST['remoteip']) &&
80
		    (!$_POST['radiusenable'] || !$_POST['radiusissueips'])) {
81 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid remote start address must be specified.");
82
		}
83 ad1a6de3 Viktor Gurov
		if (($_POST['radiusserver'] && !is_ipaddrv4($_POST['radiusserver']))) {
84 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
85
		}
86
87 c8b10b4c Stephen Beaver
		if ($_POST['secret'] != $_POST['secret_confirm']) {
88
			$input_errors[] = gettext("Secret and confirmation must match");
89
		}
90
91
		if ($_POST['radiussecret'] != $_POST['radiussecret_confirm']) {
92 dbd00a12 Phil Davis
			$input_errors[] = gettext("RADIUS secret and confirmation must match");
93 c8b10b4c Stephen Beaver
		}
94
95 be513209 Renato Botelho
		if (!is_numericint($_POST['n_l2tp_units']) || $_POST['n_l2tp_units'] > 255) {
96
			$input_errors[] = gettext("Number of L2TP users must be between 1 and 255");
97
		}
98
99 5656fe23 Ermal Lu?i
		if (!$input_errors) {
100 a56120f2 Ermal Lu?i
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
101 ddf82c16 Renato Botelho
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
102 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
103
			}
104 a55e9c70 Ermal Lu?i
			if ($_POST['localip'] == get_interface_ip("lan")) {
105 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
106
			}
107
		}
108 11a3e413 jim-p
109
		if (!empty($_POST['l2tp_dns1']) && !is_ipaddrv4(trim($_POST['l2tp_dns1']))) {
110
			$input_errors[] = gettext("The field 'Primary L2TP DNS Server' must contain a valid IPv4 address.");
111
		}
112
		if (!empty($_POST['l2tp_dns2']) && !is_ipaddrv4(trim($_POST['l2tp_dns2']))) {
113
			$input_errors[] = gettext("The field 'Secondary L2TP DNS Server' must contain a valid IPv4 address.");
114
		}
115
		if (!empty($_POST['l2tp_dns2']) && empty($_POST['l2tp_dns1'])) {
116
			$input_errors[] = gettext("The Secondary L2TP DNS Server cannot be set when the Primary L2TP DNS Server is empty.");
117
		}
118
119 5656fe23 Ermal Lu?i
	}
120
121
	if (!$input_errors) {
122
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
123
		$l2tpcfg['localip'] = $_POST['localip'];
124 a56120f2 Ermal Lu?i
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
125 5656fe23 Ermal Lu?i
		$l2tpcfg['mode'] = $_POST['mode'];
126
		$l2tpcfg['interface'] = $_POST['interface'];
127
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
128
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
129 76d6d925 Stephen Beaver
		if ($_POST['radiussecret'] != DMYPWD) {
130
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
131
		}
132
133
		if ($_POST['secret'] != DMYPWD) {
134
			$l2tpcfg['secret'] = $_POST['secret'];
135
		}
136
137 5656fe23 Ermal Lu?i
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
138
139 c8cc0c1c smos
140
		if ($_POST['l2tp_dns1'] == "") {
141 6c07db48 Phil Davis
			if (isset($l2tpcfg['dns1'])) {
142 c8cc0c1c smos
				unset($l2tpcfg['dns1']);
143 a3e00d53 Phil Davis
			}
144 6c07db48 Phil Davis
		} else {
145
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
146
		}
147 c8cc0c1c smos
148 6c07db48 Phil Davis
		if ($_POST['l2tp_dns2'] == "") {
149
			if (isset($l2tpcfg['dns2'])) {
150
				unset($l2tpcfg['dns2']);
151 a3e00d53 Phil Davis
			}
152 6c07db48 Phil Davis
		} else {
153
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
154
		}
155 c8cc0c1c smos
156 a3e00d53 Phil Davis
		if ($_POST['radiusenable'] == "yes") {
157 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['enable'] = true;
158 a3e00d53 Phil Davis
		} else {
159 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['enable']);
160 a3e00d53 Phil Davis
		}
161 5656fe23 Ermal Lu?i
162 a3e00d53 Phil Davis
		if ($_POST['radacct_enable'] == "yes") {
163 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['accounting'] = true;
164 a3e00d53 Phil Davis
		} else {
165 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['accounting']);
166 a3e00d53 Phil Davis
		}
167 5656fe23 Ermal Lu?i
168 a3e00d53 Phil Davis
		if ($_POST['radiusissueips'] == "yes") {
169 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['radiusissueips'] = true;
170 a3e00d53 Phil Davis
		} else {
171 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['radiusissueips']);
172 a3e00d53 Phil Davis
		}
173 5656fe23 Ermal Lu?i
174 1eab8134 doktornotor
		write_config(gettext("L2TP VPN configuration changed."));
175 5656fe23 Ermal Lu?i
176 44c42356 Phil Davis
		$changes_applied = true;
177 5656fe23 Ermal Lu?i
		$retval = 0;
178 44c42356 Phil Davis
		$retval |= vpn_l2tp_configure();
179 5656fe23 Ermal Lu?i
	}
180
}
181
182 ea62cbe7 Stephen Beaver
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
183 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
184 ea62cbe7 Stephen Beaver
$shortcut_section = "l2tps";
185 5656fe23 Ermal Lu?i
include("head.inc");
186
187 c86c14dc Phil Davis
if ($input_errors) {
188 ea62cbe7 Stephen Beaver
	print_input_errors($input_errors);
189 c86c14dc Phil Davis
}
190 5656fe23 Ermal Lu?i
191 44c42356 Phil Davis
if ($changes_applied) {
192
	print_apply_result_box($retval);
193 c86c14dc Phil Davis
}
194 61144c9b Sander van Leeuwen
195
$tab_array = array();
196 ea62cbe7 Stephen Beaver
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
197
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
198 748cbea6 Sander van Leeuwen
display_top_tabs($tab_array);
199 61144c9b Sander van Leeuwen
200 8f58b51b jim-p
$form = new Form();
201 ea62cbe7 Stephen Beaver
202
$section = new Form_Section("Enable L2TP");
203
204
$section->addInput(new Form_Checkbox(
205
	'mode',
206
	'Enable',
207 f680e46c jim-p
	'Enable L2TP server',
208 ea62cbe7 Stephen Beaver
	($pconfig['mode'] == "server"),
209
	'server'
210
));
211
212
$form->add($section);
213
214
$iflist = array();
215 61144c9b Sander van Leeuwen
$interfaces = get_configured_interface_with_descr();
216 ea62cbe7 Stephen Beaver
foreach ($interfaces as $iface => $ifacename) {
217
	$iflist[$iface] = $ifacename;
218
}
219 61144c9b Sander van Leeuwen
220 ea62cbe7 Stephen Beaver
$section = new Form_Section("Configuration");
221
$section->addClass('toggle-l2tp-enable');
222
223
$section->addInput(new Form_Select(
224
	'interface',
225 1bbdab13 Phil Davis
	'*Interface',
226 ea62cbe7 Stephen Beaver
	$pconfig['interface'],
227
	$iflist
228
));
229
230
$section->addInput(new Form_Input(
231
	'localip',
232 1bbdab13 Phil Davis
	'*Server address',
233 ea62cbe7 Stephen Beaver
	'text',
234
	$pconfig['localip']
235 3e142087 Phil Davis
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". %1$s' .
236
			'Typically this is set to an unused IP just outside of the client range.%1$s%1$s' .
237
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.', '<br />');
238 ea62cbe7 Stephen Beaver
239 8a78fdc0 Steve Beaver
$section->addInput(new Form_IpAddress(
240 7c150530 Steve Beaver
        'remoteip',
241
        '*Remote address range',
242
        $pconfig['remoteip']
243 ad1a6de3 Viktor Gurov
))->addMask('l2tp_subnet', $pconfig['l2tp_subnet'], 32)->setWidth(5)
244 8a78fdc0 Steve Beaver
  ->setHelp('Specify the starting address for the client IP address subnet.');
245 7c150530 Steve Beaver
246 be513209 Renato Botelho
$section->addInput(new Form_Select(
247 ea62cbe7 Stephen Beaver
	'n_l2tp_units',
248 1bbdab13 Phil Davis
	'*Number of L2TP users',
249 ea62cbe7 Stephen Beaver
	$pconfig['n_l2tp_units'],
250 be513209 Renato Botelho
	array_combine(range(1, 255, 1), range(1, 255, 1))
251 ea62cbe7 Stephen Beaver
));
252
253 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
254 ea62cbe7 Stephen Beaver
	'secret',
255
	'Secret',
256
	'password',
257
	$pconfig['secret']
258
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
259
260
$section->addInput(new Form_Select(
261
	'paporchap',
262 1bbdab13 Phil Davis
	'*Authentication type',
263 ea62cbe7 Stephen Beaver
	$pconfig['paporchap'],
264
	array(
265
		'chap' => 'CHAP',
266
		'chap-msv2' => 'MS-CHAPv2',
267
		'pap' => 'PAP'
268
		)
269
))->setHelp('Specifies the protocol to use for authentication.');
270
271
$section->addInput(new Form_Input(
272
	'l2tp_dns1',
273 f06b86ca jim-p
	'Primary L2TP DNS server',
274 ea62cbe7 Stephen Beaver
	'text',
275
	$pconfig['l2tp_dns1']
276
));
277
278
$section->addInput(new Form_Input(
279
	'l2tp_dns2',
280 f06b86ca jim-p
	'Secondary L2TP DNS server',
281 ea62cbe7 Stephen Beaver
	'text',
282
	$pconfig['l2tp_dns2']
283
));
284
285
$form->add($section);
286
287
$section = new Form_Section("RADIUS");
288
$section->addClass('toggle-l2tp-enable');
289
290
$section->addInput(new Form_Checkbox(
291
	'radiusenable',
292
	'Enable',
293
	'Use a RADIUS server for authentication',
294
	$pconfig['radiusenable']
295
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
296
297
$section->addInput(new Form_Checkbox(
298
	'radacct_enable',
299
	'Accounting',
300
	'Enable RADIUS accounting',
301
	$pconfig['radacct_enable']
302
))->setHelp('Sends accounting packets to the RADIUS server.');
303
304
$section->addInput(new Form_IpAddress(
305
	'radiusserver',
306 1bbdab13 Phil Davis
	'*Server',
307 ea62cbe7 Stephen Beaver
	$pconfig['radiusserver']
308
))->setHelp('Enter the IP address of the RADIUS server.');
309
310 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
311 ea62cbe7 Stephen Beaver
	'radiussecret',
312 1bbdab13 Phil Davis
	'*Secret',
313 ea62cbe7 Stephen Beaver
	'password',
314
	$pconfig['radiussecret']
315
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
316
317
$section->addInput(new Form_Checkbox(
318
	'radiusissueips',
319
	'RADIUS issued IPs',
320
	'Issue IP Addresses via RADIUS server.',
321
	$pconfig['radiusissueips']
322
));
323
324
$form->add($section);
325
326
print($form);
327 c4a7740d Sander van Leeuwen
?>
328 60362560 Phil Davis
<div class="infoblock blockopen">
329
<?php
330 8545adde k-paulius
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
331 60362560 Phil Davis
?>
332
</div>
333 61144c9b Sander van Leeuwen
334 8fd9052f Colin Fleming
<script type="text/javascript">
335 d28502be Colin Fleming
//<![CDATA[
336 c86c14dc Phil Davis
events.push(function() {
337 ea62cbe7 Stephen Beaver
338
	function setL2TP () {
339
		hide = ! $('#mode').prop('checked');
340
341
		hideClass('toggle-l2tp-enable', hide);
342
	}
343
344
	function setRADIUS () {
345
		hide = ! $('#radiusenable').prop('checked');
346
347
		hideCheckbox('radacct_enable', hide);
348
		hideInput('radiusserver', hide);
349
		hideInput('radiussecret', hide);
350
		hideCheckbox('radiusissueips', hide);
351
	}
352
353
	// on-click
354
	$('#mode').click(function () {
355
		setL2TP();
356
	});
357
358
	$('#radiusenable').click(function () {
359
		setRADIUS();
360
	});
361
362
	// on-page-load
363
	setRADIUS();
364
	setL2TP();
365
366
});
367 d28502be Colin Fleming
//]]>
368 5656fe23 Ermal Lu?i
</script>
369
370 3fac0afc Jose Luis Duran
<?php include("foot.inc")?>