Project

General

Profile

Download (11.3 KB) Statistics
| Branch: | Tag: | Revision:
1 5656fe23 Ermal Lu?i
<?php
2
/*
3 aaec5634 Renato Botelho
 * vpn_l2tp.php
4 b9043cdc Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8 b9043cdc Stephen Beaver
 *
9 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11 b9043cdc Stephen Beaver
 *
12 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14 b9043cdc Stephen Beaver
 *
15 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19 b9043cdc Stephen Beaver
 *
20 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24 b9043cdc Stephen Beaver
 *
25 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29 b9043cdc Stephen Beaver
 *
30 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33 b9043cdc Stephen Beaver
 *
34 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36 b9043cdc Stephen Beaver
 *
37 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39 b9043cdc Stephen Beaver
 *
40 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 b9043cdc Stephen Beaver
 */
53 5656fe23 Ermal Lu?i
54 047cb829 Ermal Lu?i
##|+PRIV
55
##|*IDENT=page-vpn-vpnl2tp
56 9599211d jim-p
##|*NAME=VPN: L2TP
57
##|*DESCR=Allow access to the 'VPN: L2TP' page.
58 047cb829 Ermal Lu?i
##|*MATCH=vpn_l2tp.php*
59
##|-PRIV
60
61 aceaf18c Phil Davis
require_once("guiconfig.inc");
62 483e6de8 Scott Ullrich
require_once("vpn.inc");
63 5656fe23 Ermal Lu?i
64
if (!is_array($config['l2tp']['radius'])) {
65
	$config['l2tp']['radius'] = array();
66
}
67
$l2tpcfg = &$config['l2tp'];
68
69
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
70
$pconfig['localip'] = $l2tpcfg['localip'];
71 a56120f2 Ermal Lu?i
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
72 5656fe23 Ermal Lu?i
$pconfig['mode'] = $l2tpcfg['mode'];
73
$pconfig['interface'] = $l2tpcfg['interface'];
74 c8cc0c1c smos
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
75
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
76 5656fe23 Ermal Lu?i
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
77
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
78
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
79
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
80 74509a47 Phil Davis
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
81 5656fe23 Ermal Lu?i
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
82
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
83 40de0b13 Ermal Lu?i
$pconfig['secret'] = $l2tpcfg['secret'];
84 5656fe23 Ermal Lu?i
85
if ($_POST) {
86
87
	unset($input_errors);
88
	$pconfig = $_POST;
89
90
	/* input validation */
91
	if ($_POST['mode'] == "server") {
92
		$reqdfields = explode(" ", "localip remoteip");
93 6c07db48 Phil Davis
		$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
94 5656fe23 Ermal Lu?i
95
		if ($_POST['radiusenable']) {
96
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
97
			$reqdfieldsn = array_merge($reqdfieldsn,
98 a3e00d53 Phil Davis
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
99 5656fe23 Ermal Lu?i
		}
100
101 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
102 5656fe23 Ermal Lu?i
103
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
104
			$input_errors[] = gettext("A valid server address must be specified.");
105
		}
106 0a0b17d9 Renato Botelho
		if (is_ipaddr_configured($_POST['localip'])) {
107
			$input_errors[] = gettext("'Server address' parameter should NOT be set to any IP address currently in use on this firewall.");
108
		}
109 a56120f2 Ermal Lu?i
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
110 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid remote start address must be specified.");
111
		}
112
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
113
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
114
		}
115
116 c8b10b4c Stephen Beaver
		if ($_POST['secret'] != $_POST['secret_confirm']) {
117
			$input_errors[] = gettext("Secret and confirmation must match");
118
		}
119
120
		if ($_POST['radiussecret'] != $_POST['radiussecret_confirm']) {
121 dbd00a12 Phil Davis
			$input_errors[] = gettext("RADIUS secret and confirmation must match");
122 c8b10b4c Stephen Beaver
		}
123
124 be513209 Renato Botelho
		if (!is_numericint($_POST['n_l2tp_units']) || $_POST['n_l2tp_units'] > 255) {
125
			$input_errors[] = gettext("Number of L2TP users must be between 1 and 255");
126
		}
127
128 5656fe23 Ermal Lu?i
		if (!$input_errors) {
129 a56120f2 Ermal Lu?i
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
130 ddf82c16 Renato Botelho
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
131 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
132
			}
133 a55e9c70 Ermal Lu?i
			if ($_POST['localip'] == get_interface_ip("lan")) {
134 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
135
			}
136
		}
137
	}
138
139
	if (!$input_errors) {
140
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
141
		$l2tpcfg['localip'] = $_POST['localip'];
142 a56120f2 Ermal Lu?i
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
143 5656fe23 Ermal Lu?i
		$l2tpcfg['mode'] = $_POST['mode'];
144
		$l2tpcfg['interface'] = $_POST['interface'];
145
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
146
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
147 76d6d925 Stephen Beaver
		if ($_POST['radiussecret'] != DMYPWD) {
148
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
149
		}
150
151
		if ($_POST['secret'] != DMYPWD) {
152
			$l2tpcfg['secret'] = $_POST['secret'];
153
		}
154
155 5656fe23 Ermal Lu?i
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
156
157 c8cc0c1c smos
158
		if ($_POST['l2tp_dns1'] == "") {
159 6c07db48 Phil Davis
			if (isset($l2tpcfg['dns1'])) {
160 c8cc0c1c smos
				unset($l2tpcfg['dns1']);
161 a3e00d53 Phil Davis
			}
162 6c07db48 Phil Davis
		} else {
163
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
164
		}
165 c8cc0c1c smos
166 6c07db48 Phil Davis
		if ($_POST['l2tp_dns2'] == "") {
167
			if (isset($l2tpcfg['dns2'])) {
168
				unset($l2tpcfg['dns2']);
169 a3e00d53 Phil Davis
			}
170 6c07db48 Phil Davis
		} else {
171
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
172
		}
173 c8cc0c1c smos
174 a3e00d53 Phil Davis
		if ($_POST['radiusenable'] == "yes") {
175 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['enable'] = true;
176 a3e00d53 Phil Davis
		} else {
177 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['enable']);
178 a3e00d53 Phil Davis
		}
179 5656fe23 Ermal Lu?i
180 a3e00d53 Phil Davis
		if ($_POST['radacct_enable'] == "yes") {
181 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['accounting'] = true;
182 a3e00d53 Phil Davis
		} else {
183 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['accounting']);
184 a3e00d53 Phil Davis
		}
185 5656fe23 Ermal Lu?i
186 a3e00d53 Phil Davis
		if ($_POST['radiusissueips'] == "yes") {
187 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['radiusissueips'] = true;
188 a3e00d53 Phil Davis
		} else {
189 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['radiusissueips']);
190 a3e00d53 Phil Davis
		}
191 5656fe23 Ermal Lu?i
192
		write_config();
193
194
		$retval = 0;
195
		$retval = vpn_l2tp_configure();
196
		$savemsg = get_std_save_message($retval);
197
198
		/* if ajax is calling, give them an update message */
199 a3e00d53 Phil Davis
		if (isAjax()) {
200 3b3a95e5 Phil Davis
			print_info_box($savemsg, 'success');
201 a3e00d53 Phil Davis
		}
202 5656fe23 Ermal Lu?i
	}
203
}
204
205 ea62cbe7 Stephen Beaver
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
206
$shortcut_section = "l2tps";
207 5656fe23 Ermal Lu?i
include("head.inc");
208
209 c86c14dc Phil Davis
if ($input_errors) {
210 ea62cbe7 Stephen Beaver
	print_input_errors($input_errors);
211 c86c14dc Phil Davis
}
212 5656fe23 Ermal Lu?i
213 c86c14dc Phil Davis
if ($savemsg) {
214 f78bbe16 Phil Davis
	print_info_box($savemsg, 'success');
215 c86c14dc Phil Davis
}
216 61144c9b Sander van Leeuwen
217
$tab_array = array();
218 ea62cbe7 Stephen Beaver
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
219
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
220 748cbea6 Sander van Leeuwen
display_top_tabs($tab_array);
221 61144c9b Sander van Leeuwen
222 8f58b51b jim-p
$form = new Form();
223 ea62cbe7 Stephen Beaver
224
$section = new Form_Section("Enable L2TP");
225
226
$section->addInput(new Form_Checkbox(
227
	'mode',
228
	'Enable',
229 160d285a jim-p
	'Enable L2TP server',
230 ea62cbe7 Stephen Beaver
	($pconfig['mode'] == "server"),
231
	'server'
232
));
233
234
$form->add($section);
235
236
$iflist = array();
237 61144c9b Sander van Leeuwen
$interfaces = get_configured_interface_with_descr();
238 ea62cbe7 Stephen Beaver
foreach ($interfaces as $iface => $ifacename) {
239
	$iflist[$iface] = $ifacename;
240
}
241 61144c9b Sander van Leeuwen
242 ea62cbe7 Stephen Beaver
$section = new Form_Section("Configuration");
243
$section->addClass('toggle-l2tp-enable');
244
245
$section->addInput(new Form_Select(
246
	'interface',
247
	'Interface',
248
	$pconfig['interface'],
249
	$iflist
250
));
251
252
$section->addInput(new Form_Input(
253
	'localip',
254
	'Server address',
255
	'text',
256
	$pconfig['localip']
257
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
258
			'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
259
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
260
261
$section->addInput(new Form_IpAddress(
262
	'remoteip',
263
	'Remote address range',
264
	$pconfig['remoteip']
265
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
266
  ->setHelp('Specify the starting address for the client IP address subnet.');
267
268 be513209 Renato Botelho
$section->addInput(new Form_Select(
269 ea62cbe7 Stephen Beaver
	'n_l2tp_units',
270
	'Number of L2TP users',
271
	$pconfig['n_l2tp_units'],
272 be513209 Renato Botelho
	array_combine(range(1, 255, 1), range(1, 255, 1))
273 ea62cbe7 Stephen Beaver
));
274
275 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
276 ea62cbe7 Stephen Beaver
	'secret',
277
	'Secret',
278
	'password',
279
	$pconfig['secret']
280
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
281
282
$section->addInput(new Form_Select(
283
	'paporchap',
284
	'Authentication type',
285
	$pconfig['paporchap'],
286
	array(
287
		'chap' => 'CHAP',
288
		'chap-msv2' => 'MS-CHAPv2',
289
		'pap' => 'PAP'
290
		)
291
))->setHelp('Specifies the protocol to use for authentication.');
292
293
$section->addInput(new Form_Input(
294
	'l2tp_dns1',
295 f0b7a730 jim-p
	'Primary L2TP DNS server',
296 ea62cbe7 Stephen Beaver
	'text',
297
	$pconfig['l2tp_dns1']
298
));
299
300
$section->addInput(new Form_Input(
301
	'l2tp_dns2',
302 f0b7a730 jim-p
	'Secondary L2TP DNS server',
303 ea62cbe7 Stephen Beaver
	'text',
304
	$pconfig['l2tp_dns2']
305
));
306
307
$form->add($section);
308
309
$section = new Form_Section("RADIUS");
310
$section->addClass('toggle-l2tp-enable');
311
312
$section->addInput(new Form_Checkbox(
313
	'radiusenable',
314
	'Enable',
315
	'Use a RADIUS server for authentication',
316
	$pconfig['radiusenable']
317
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
318
319
$section->addInput(new Form_Checkbox(
320
	'radacct_enable',
321
	'Accounting',
322
	'Enable RADIUS accounting',
323
	$pconfig['radacct_enable']
324
))->setHelp('Sends accounting packets to the RADIUS server.');
325
326
$section->addInput(new Form_IpAddress(
327
	'radiusserver',
328
	'Server',
329
	$pconfig['radiusserver']
330
))->setHelp('Enter the IP address of the RADIUS server.');
331
332 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
333 ea62cbe7 Stephen Beaver
	'radiussecret',
334
	'Secret',
335
	'password',
336
	$pconfig['radiussecret']
337
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
338
339
$section->addInput(new Form_Checkbox(
340
	'radiusissueips',
341
	'RADIUS issued IPs',
342
	'Issue IP Addresses via RADIUS server.',
343
	$pconfig['radiusissueips']
344
));
345
346
$form->add($section);
347
348
print($form);
349 c4a7740d Sander van Leeuwen
?>
350 60362560 Phil Davis
<div class="infoblock blockopen">
351
<?php
352 8545adde k-paulius
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
353 60362560 Phil Davis
?>
354
</div>
355 61144c9b Sander van Leeuwen
356 8fd9052f Colin Fleming
<script type="text/javascript">
357 d28502be Colin Fleming
//<![CDATA[
358 c86c14dc Phil Davis
events.push(function() {
359 ea62cbe7 Stephen Beaver
360
	function setL2TP () {
361
		hide = ! $('#mode').prop('checked');
362
363
		hideClass('toggle-l2tp-enable', hide);
364
	}
365
366
	function setRADIUS () {
367
		hide = ! $('#radiusenable').prop('checked');
368
369
		hideCheckbox('radacct_enable', hide);
370
		hideInput('radiusserver', hide);
371
		hideInput('radiussecret', hide);
372
		hideCheckbox('radiusissueips', hide);
373
	}
374
375
	// on-click
376
	$('#mode').click(function () {
377
		setL2TP();
378
	});
379
380
	$('#radiusenable').click(function () {
381
		setRADIUS();
382
	});
383
384
	// on-page-load
385
	setRADIUS();
386
	setL2TP();
387
388
});
389 d28502be Colin Fleming
//]]>
390 5656fe23 Ermal Lu?i
</script>
391
392 3fac0afc Jose Luis Duran
<?php include("foot.inc")?>