Project

General

Profile

Download (11.8 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("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
			$subnet_start = ip2ulong($_POST['remoteip']);
139
			$subnet_end = ip2ulong($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
140

    
141
			if ((ip2ulong($_POST['localip']) >= $subnet_start) &&
142
			    (ip2ulong($_POST['localip']) <= $subnet_end)) {
143
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
144
			}
145
			if ($_POST['localip'] == get_interface_ip("lan")) {
146
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
147
			}
148
		}
149
	}
150

    
151
	/* if this is an AJAX caller then handle via JSON */
152
	if (isAjax() && is_array($input_errors)) {
153
		input_errors2Ajax($input_errors);
154
		exit;
155
	}
156

    
157
	if (!$input_errors) {
158
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
159
		$l2tpcfg['localip'] = $_POST['localip'];
160
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
161
		$l2tpcfg['mode'] = $_POST['mode'];
162
		$l2tpcfg['interface'] = $_POST['interface'];
163
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
164
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
165
		if ($_POST['radiussecret'] != DMYPWD) {
166
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
167
		}
168

    
169
		if ($_POST['secret'] != DMYPWD) {
170
			$l2tpcfg['secret'] = $_POST['secret'];
171
		}
172

    
173
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
174

    
175

    
176
		if ($_POST['l2tp_dns1'] == "") {
177
			if (isset($l2tpcfg['dns1'])) {
178
				unset($l2tpcfg['dns1']);
179
			}
180
		} else {
181
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
182
		}
183

    
184
		if ($_POST['l2tp_dns2'] == "") {
185
			if (isset($l2tpcfg['dns2'])) {
186
				unset($l2tpcfg['dns2']);
187
			}
188
		} else {
189
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
190
		}
191

    
192
		if ($_POST['radiusenable'] == "yes") {
193
			$l2tpcfg['radius']['enable'] = true;
194
		} else {
195
			unset($l2tpcfg['radius']['enable']);
196
		}
197

    
198
		if ($_POST['radacct_enable'] == "yes") {
199
			$l2tpcfg['radius']['accounting'] = true;
200
		} else {
201
			unset($l2tpcfg['radius']['accounting']);
202
		}
203

    
204
		if ($_POST['radiusissueips'] == "yes") {
205
			$l2tpcfg['radius']['radiusissueips'] = true;
206
		} else {
207
			unset($l2tpcfg['radius']['radiusissueips']);
208
		}
209

    
210
		write_config();
211

    
212
		$retval = 0;
213
		$retval = vpn_l2tp_configure();
214
		$savemsg = get_std_save_message($retval);
215

    
216
		/* if ajax is calling, give them an update message */
217
		if (isAjax()) {
218
			print_info_box_np($savemsg);
219
		}
220
	}
221
}
222

    
223
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
224
$shortcut_section = "l2tps";
225
include("head.inc");
226

    
227
if ($input_errors) {
228
	print_input_errors($input_errors);
229
}
230

    
231
if ($savemsg) {
232
	print_info_box($savemsg);
233
}
234

    
235
$tab_array = array();
236
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
237
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
238
display_top_tabs($tab_array);
239

    
240
$form = new Form(new Form_Button(
241
	'Submit',
242
	gettext("Save")
243
));
244

    
245
$section = new Form_Section("Enable L2TP");
246

    
247
$section->addInput(new Form_Checkbox(
248
	'mode',
249
	'Enable',
250
	'Enable LT2P server',
251
	($pconfig['mode'] == "server"),
252
	'server'
253
));
254

    
255
$form->add($section);
256

    
257
$iflist = array();
258
$interfaces = get_configured_interface_with_descr();
259
foreach ($interfaces as $iface => $ifacename) {
260
	$iflist[$iface] = $ifacename;
261
}
262

    
263
$section = new Form_Section("Configuration");
264
$section->addClass('toggle-l2tp-enable');
265

    
266
$section->addInput(new Form_Select(
267
	'interface',
268
	'Interface',
269
	$pconfig['interface'],
270
	$iflist
271
));
272

    
273
$section->addInput(new Form_Input(
274
	'localip',
275
	'Server address',
276
	'text',
277
	$pconfig['localip']
278
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
279
			'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
280
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
281

    
282
$section->addInput(new Form_IpAddress(
283
	'remoteip',
284
	'Remote address range',
285
	$pconfig['remoteip']
286
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
287
  ->setHelp('Specify the starting address for the client IP address subnet.');
288

    
289
$section->addInput(new Form_Select(
290
	'n_l2tp_units',
291
	'Number of L2TP users',
292
	$pconfig['n_l2tp_units'],
293
	array_combine(range(1, 255, 1), range(1, 255, 1))
294
));
295

    
296
$section->addPassword(new Form_Input(
297
	'secret',
298
	'Secret',
299
	'password',
300
	$pconfig['secret']
301
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
302

    
303
$section->addInput(new Form_Select(
304
	'paporchap',
305
	'Authentication type',
306
	$pconfig['paporchap'],
307
	array(
308
		'chap' => 'CHAP',
309
		'chap-msv2' => 'MS-CHAPv2',
310
		'pap' => 'PAP'
311
		)
312
))->setHelp('Specifies the protocol to use for authentication.');
313

    
314
$section->addInput(new Form_Input(
315
	'l2tp_dns1',
316
	'Primary L2TM DNS server',
317
	'text',
318
	$pconfig['l2tp_dns1']
319
));
320

    
321
$section->addInput(new Form_Input(
322
	'l2tp_dns2',
323
	'Secondary L2TM DNS server',
324
	'text',
325
	$pconfig['l2tp_dns2']
326
));
327

    
328
$form->add($section);
329

    
330
$section = new Form_Section("RADIUS");
331
$section->addClass('toggle-l2tp-enable');
332

    
333
$section->addInput(new Form_Checkbox(
334
	'radiusenable',
335
	'Enable',
336
	'Use a RADIUS server for authentication',
337
	$pconfig['radiusenable']
338
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
339

    
340
$section->addInput(new Form_Checkbox(
341
	'radacct_enable',
342
	'Accounting',
343
	'Enable RADIUS accounting',
344
	$pconfig['radacct_enable']
345
))->setHelp('Sends accounting packets to the RADIUS server.');
346

    
347
$section->addInput(new Form_IpAddress(
348
	'radiusserver',
349
	'Server',
350
	$pconfig['radiusserver']
351
))->setHelp('Enter the IP address of the RADIUS server.');
352

    
353
$section->addPassword(new Form_Input(
354
	'radiussecret',
355
	'Secret',
356
	'password',
357
	$pconfig['radiussecret']
358
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
359

    
360
$section->addInput(new Form_Checkbox(
361
	'radiusissueips',
362
	'RADIUS issued IPs',
363
	'Issue IP Addresses via RADIUS server.',
364
	$pconfig['radiusissueips']
365
));
366

    
367
$form->add($section);
368

    
369
print($form);
370

    
371
print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients!"), 'info');
372
?>
373

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

    
378
	function setL2TP () {
379
		hide = ! $('#mode').prop('checked');
380

    
381
		hideClass('toggle-l2tp-enable', hide);
382
	}
383

    
384
	function setRADIUS () {
385
		hide = ! $('#radiusenable').prop('checked');
386

    
387
		hideCheckbox('radacct_enable', hide);
388
		hideInput('radiusserver', hide);
389
		hideInput('radiussecret', hide);
390
		hideCheckbox('radiusissueips', hide);
391
	}
392

    
393
	// on-click
394
	$('#mode').click(function () {
395
		setL2TP();
396
	});
397

    
398
	$('#radiusenable').click(function () {
399
		setRADIUS();
400
	});
401

    
402
	// on-page-load
403
	setRADIUS();
404
	setL2TP();
405

    
406
});
407
//]]>
408
</script>
409

    
410
<?php include("foot.inc")?>
(222-222/229)