Project

General

Profile

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