Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_l2tp.php
4
*/
5
/* ====================================================================
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

    
56
##|+PRIV
57
##|*IDENT=page-vpn-vpnl2tp
58
##|*NAME=VPN: L2TP
59
##|*DESCR=Allow access to the 'VPN: L2TP' page.
60
##|*MATCH=vpn_l2tp.php*
61
##|-PRIV
62

    
63
require("guiconfig.inc");
64
require_once("vpn.inc");
65

    
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
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
74
$pconfig['mode'] = $l2tpcfg['mode'];
75
$pconfig['interface'] = $l2tpcfg['interface'];
76
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
77
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
78
$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
$pconfig['secret'] = $l2tpcfg['secret'];
86

    
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
		$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
96

    
97
		if ($_POST['radiusenable']) {
98
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
99
			$reqdfieldsn = array_merge($reqdfieldsn,
100
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
101
		}
102

    
103
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
104

    
105
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
106
			$input_errors[] = gettext("A valid server address must be specified.");
107
		}
108
		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
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
112
			$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
		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("RADIUS secret and confirmation must match");
124
		}
125

    
126
		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
		/* if this is an AJAX caller then handle via JSON */
131
		if (isAjax() && is_array($input_errors)) {
132
			input_errors2Ajax($input_errors);
133
			exit;
134
		}
135

    
136
		if (!$input_errors) {
137
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
138
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
139
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
140
			}
141
			if ($_POST['localip'] == get_interface_ip("lan")) {
142
				$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
	if (isAjax() && is_array($input_errors)) {
149
		input_errors2Ajax($input_errors);
150
		exit;
151
	}
152

    
153
	if (!$input_errors) {
154
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
155
		$l2tpcfg['localip'] = $_POST['localip'];
156
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
157
		$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
		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
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
170

    
171

    
172
		if ($_POST['l2tp_dns1'] == "") {
173
			if (isset($l2tpcfg['dns1'])) {
174
				unset($l2tpcfg['dns1']);
175
			}
176
		} else {
177
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
178
		}
179

    
180
		if ($_POST['l2tp_dns2'] == "") {
181
			if (isset($l2tpcfg['dns2'])) {
182
				unset($l2tpcfg['dns2']);
183
			}
184
		} else {
185
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
186
		}
187

    
188
		if ($_POST['radiusenable'] == "yes") {
189
			$l2tpcfg['radius']['enable'] = true;
190
		} else {
191
			unset($l2tpcfg['radius']['enable']);
192
		}
193

    
194
		if ($_POST['radacct_enable'] == "yes") {
195
			$l2tpcfg['radius']['accounting'] = true;
196
		} else {
197
			unset($l2tpcfg['radius']['accounting']);
198
		}
199

    
200
		if ($_POST['radiusissueips'] == "yes") {
201
			$l2tpcfg['radius']['radiusissueips'] = true;
202
		} else {
203
			unset($l2tpcfg['radius']['radiusissueips']);
204
		}
205

    
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
		if (isAjax()) {
214
			print_info_box($savemsg, 'success');
215
		}
216
	}
217
}
218

    
219
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
220
$shortcut_section = "l2tps";
221
include("head.inc");
222

    
223
if ($input_errors) {
224
	print_input_errors($input_errors);
225
}
226

    
227
if ($savemsg) {
228
	print_info_box($savemsg, 'success');
229
}
230

    
231
$tab_array = array();
232
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
233
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
234
display_top_tabs($tab_array);
235

    
236
$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
$interfaces = get_configured_interface_with_descr();
255
foreach ($interfaces as $iface => $ifacename) {
256
	$iflist[$iface] = $ifacename;
257
}
258

    
259
$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
$section->addInput(new Form_Select(
286
	'n_l2tp_units',
287
	'Number of L2TP users',
288
	$pconfig['n_l2tp_units'],
289
	array_combine(range(1, 255, 1), range(1, 255, 1))
290
));
291

    
292
$section->addPassword(new Form_Input(
293
	'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
$section->addPassword(new Form_Input(
350
	'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
?>
367
<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

    
373
<script type="text/javascript">
374
//<![CDATA[
375
events.push(function() {
376

    
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
//]]>
407
</script>
408

    
409
<?php include("foot.inc")?>
(220-220/227)