Project

General

Profile

Download (11.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * vpn_l2tp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 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
 *
20
 * 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
 *
25
 * 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
 *
30
 * 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
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * 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
 */
53

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

    
61
require_once("guiconfig.inc");
62
require_once("vpn.inc");
63

    
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
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
72
$pconfig['mode'] = $l2tpcfg['mode'];
73
$pconfig['interface'] = $l2tpcfg['interface'];
74
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
75
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
76
$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
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
81
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
82
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
83
$pconfig['secret'] = $l2tpcfg['secret'];
84

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

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

    
101
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
102

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

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

    
134
		if (!$input_errors) {
135
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
136
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
137
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
138
			}
139
			if ($_POST['localip'] == get_interface_ip("lan")) {
140
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
141
			}
142
		}
143
	}
144

    
145
	/* if this is an AJAX caller then handle via JSON */
146
	if (isAjax() && is_array($input_errors)) {
147
		input_errors2Ajax($input_errors);
148
		exit;
149
	}
150

    
151
	if (!$input_errors) {
152
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
153
		$l2tpcfg['localip'] = $_POST['localip'];
154
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
155
		$l2tpcfg['mode'] = $_POST['mode'];
156
		$l2tpcfg['interface'] = $_POST['interface'];
157
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
158
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
159
		if ($_POST['radiussecret'] != DMYPWD) {
160
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
161
		}
162

    
163
		if ($_POST['secret'] != DMYPWD) {
164
			$l2tpcfg['secret'] = $_POST['secret'];
165
		}
166

    
167
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
168

    
169

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

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

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

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

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

    
204
		write_config();
205

    
206
		$retval = 0;
207
		$retval = vpn_l2tp_configure();
208
		$savemsg = get_std_save_message($retval);
209

    
210
		/* if ajax is calling, give them an update message */
211
		if (isAjax()) {
212
			print_info_box($savemsg, 'success');
213
		}
214
	}
215
}
216

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

    
221
if ($input_errors) {
222
	print_input_errors($input_errors);
223
}
224

    
225
if ($savemsg) {
226
	print_info_box($savemsg, 'success');
227
}
228

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

    
234
$form = new Form();
235

    
236
$section = new Form_Section("Enable L2TP");
237

    
238
$section->addInput(new Form_Checkbox(
239
	'mode',
240
	'Enable',
241
	'Enable L2TP server',
242
	($pconfig['mode'] == "server"),
243
	'server'
244
));
245

    
246
$form->add($section);
247

    
248
$iflist = array();
249
$interfaces = get_configured_interface_with_descr();
250
foreach ($interfaces as $iface => $ifacename) {
251
	$iflist[$iface] = $ifacename;
252
}
253

    
254
$section = new Form_Section("Configuration");
255
$section->addClass('toggle-l2tp-enable');
256

    
257
$section->addInput(new Form_Select(
258
	'interface',
259
	'Interface',
260
	$pconfig['interface'],
261
	$iflist
262
));
263

    
264
$section->addInput(new Form_Input(
265
	'localip',
266
	'Server address',
267
	'text',
268
	$pconfig['localip']
269
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
270
			'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
271
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
272

    
273
$section->addInput(new Form_IpAddress(
274
	'remoteip',
275
	'Remote address range',
276
	$pconfig['remoteip']
277
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
278
  ->setHelp('Specify the starting address for the client IP address subnet.');
279

    
280
$section->addInput(new Form_Select(
281
	'n_l2tp_units',
282
	'Number of L2TP users',
283
	$pconfig['n_l2tp_units'],
284
	array_combine(range(1, 255, 1), range(1, 255, 1))
285
));
286

    
287
$section->addPassword(new Form_Input(
288
	'secret',
289
	'Secret',
290
	'password',
291
	$pconfig['secret']
292
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
293

    
294
$section->addInput(new Form_Select(
295
	'paporchap',
296
	'Authentication type',
297
	$pconfig['paporchap'],
298
	array(
299
		'chap' => 'CHAP',
300
		'chap-msv2' => 'MS-CHAPv2',
301
		'pap' => 'PAP'
302
		)
303
))->setHelp('Specifies the protocol to use for authentication.');
304

    
305
$section->addInput(new Form_Input(
306
	'l2tp_dns1',
307
	'Primary L2TP DNS server',
308
	'text',
309
	$pconfig['l2tp_dns1']
310
));
311

    
312
$section->addInput(new Form_Input(
313
	'l2tp_dns2',
314
	'Secondary L2TP DNS server',
315
	'text',
316
	$pconfig['l2tp_dns2']
317
));
318

    
319
$form->add($section);
320

    
321
$section = new Form_Section("RADIUS");
322
$section->addClass('toggle-l2tp-enable');
323

    
324
$section->addInput(new Form_Checkbox(
325
	'radiusenable',
326
	'Enable',
327
	'Use a RADIUS server for authentication',
328
	$pconfig['radiusenable']
329
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
330

    
331
$section->addInput(new Form_Checkbox(
332
	'radacct_enable',
333
	'Accounting',
334
	'Enable RADIUS accounting',
335
	$pconfig['radacct_enable']
336
))->setHelp('Sends accounting packets to the RADIUS server.');
337

    
338
$section->addInput(new Form_IpAddress(
339
	'radiusserver',
340
	'Server',
341
	$pconfig['radiusserver']
342
))->setHelp('Enter the IP address of the RADIUS server.');
343

    
344
$section->addPassword(new Form_Input(
345
	'radiussecret',
346
	'Secret',
347
	'password',
348
	$pconfig['radiussecret']
349
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
350

    
351
$section->addInput(new Form_Checkbox(
352
	'radiusissueips',
353
	'RADIUS issued IPs',
354
	'Issue IP Addresses via RADIUS server.',
355
	$pconfig['radiusissueips']
356
));
357

    
358
$form->add($section);
359

    
360
print($form);
361
?>
362
<div class="infoblock blockopen">
363
<?php
364
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
365
?>
366
</div>
367

    
368
<script type="text/javascript">
369
//<![CDATA[
370
events.push(function() {
371

    
372
	function setL2TP () {
373
		hide = ! $('#mode').prop('checked');
374

    
375
		hideClass('toggle-l2tp-enable', hide);
376
	}
377

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

    
381
		hideCheckbox('radacct_enable', hide);
382
		hideInput('radiusserver', hide);
383
		hideInput('radiussecret', hide);
384
		hideCheckbox('radiusissueips', hide);
385
	}
386

    
387
	// on-click
388
	$('#mode').click(function () {
389
		setL2TP();
390
	});
391

    
392
	$('#radiusenable').click(function () {
393
		setRADIUS();
394
	});
395

    
396
	// on-page-load
397
	setRADIUS();
398
	setL2TP();
399

    
400
});
401
//]]>
402
</script>
403

    
404
<?php include("foot.inc")?>
(218-218/225)