Project

General

Profile

Download (11.2 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 this is an AJAX caller then handle via JSON */
119
		if (isAjax() && is_array($input_errors)) {
120
			input_errors2Ajax($input_errors);
121
			exit;
122
		}
123

    
124
		if (!$input_errors) {
125
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
126
			$subnet_start = ip2ulong($_POST['remoteip']);
127
			$subnet_end = ip2ulong($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
128

    
129
			if ((ip2ulong($_POST['localip']) >= $subnet_start) &&
130
				(ip2ulong($_POST['localip']) <= $subnet_end)) {
131
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
132
			}
133
			if ($_POST['localip'] == get_interface_ip("lan")) {
134
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
135
			}
136
		}
137
	}
138

    
139
	/* if this is an AJAX caller then handle via JSON */
140
	if (isAjax() && is_array($input_errors)) {
141
		input_errors2Ajax($input_errors);
142
		exit;
143
	}
144

    
145
	if (!$input_errors) {
146
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
147
		$l2tpcfg['localip'] = $_POST['localip'];
148
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
149
		$l2tpcfg['mode'] = $_POST['mode'];
150
		$l2tpcfg['interface'] = $_POST['interface'];
151
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
152
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
153
		$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
154
		$l2tpcfg['secret'] = $_POST['secret'];
155
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
156

    
157

    
158
		if ($_POST['l2tp_dns1'] == "") {
159
			if (isset($l2tpcfg['dns1'])) {
160
				unset($l2tpcfg['dns1']);
161
			}
162
		} else {
163
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
164
		}
165

    
166
		if ($_POST['l2tp_dns2'] == "") {
167
			if (isset($l2tpcfg['dns2'])) {
168
				unset($l2tpcfg['dns2']);
169
			}
170
		} else {
171
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
172
		}
173

    
174
		if ($_POST['radiusenable'] == "yes") {
175
			$l2tpcfg['radius']['enable'] = true;
176
		} else {
177
			unset($l2tpcfg['radius']['enable']);
178
		}
179

    
180
		if ($_POST['radacct_enable'] == "yes") {
181
			$l2tpcfg['radius']['accounting'] = true;
182
		} else {
183
			unset($l2tpcfg['radius']['accounting']);
184
		}
185

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

    
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
		if (isAjax()) {
200
			print_info_box_np($savemsg);
201
		}
202
	}
203
}
204

    
205
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
206
$shortcut_section = "l2tps";
207
include("head.inc");
208

    
209
if ($input_errors)
210
	print_input_errors($input_errors);
211

    
212
if ($savemsg)
213
	print_info_box($savemsg);
214

    
215
$tab_array = array();
216
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
217
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
218
display_top_tabs($tab_array);
219

    
220
$form = new Form(new Form_Button(
221
	'Submit',
222
	gettext("Save")
223
));
224

    
225
$section = new Form_Section("Enable L2TP");
226

    
227
$section->addInput(new Form_Checkbox(
228
	'mode',
229
	'Enable',
230
	'Enable LT2P server',
231
	($pconfig['mode'] == "server"),
232
	'server'
233
));
234

    
235
$form->add($section);
236

    
237
$iflist = array();
238
$interfaces = get_configured_interface_with_descr();
239
foreach ($interfaces as $iface => $ifacename) {
240
	$iflist[$iface] = $ifacename;
241
}
242

    
243
$section = new Form_Section("Configuration");
244
$section->addClass('toggle-l2tp-enable');
245

    
246
$section->addInput(new Form_Select(
247
	'interface',
248
	'Interface',
249
	$pconfig['interface'],
250
	$iflist
251
));
252

    
253
$section->addInput(new Form_Input(
254
	'localip',
255
	'Server address',
256
	'text',
257
	$pconfig['localip']
258
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
259
			'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
260
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
261

    
262
$section->addInput(new Form_IpAddress(
263
	'remoteip',
264
	'Remote address range',
265
	$pconfig['remoteip']
266
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
267
  ->setHelp('Specify the starting address for the client IP address subnet.');
268

    
269
$section->addInput(new Form_Input(
270
	'n_l2tp_units',
271
	'Number of L2TP users',
272
	'number',
273
	$pconfig['n_l2tp_units'],
274
	['min' => 0, 'max' => 255]
275
));
276

    
277
$section->addInput(new Form_Input(
278
	'secret',
279
	'Secret',
280
	'password',
281
	$pconfig['secret']
282
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
283

    
284
$section->addInput(new Form_Select(
285
	'paporchap',
286
	'Authentication type',
287
	$pconfig['paporchap'],
288
	array(
289
		'chap' => 'CHAP',
290
		'chap-msv2' => 'MS-CHAPv2',
291
		'pap' => 'PAP'
292
		)
293
))->setHelp('Specifies the protocol to use for authentication.');
294

    
295
$section->addInput(new Form_Input(
296
	'l2tp_dns1',
297
	'Primary L2TM DNS server',
298
	'text',
299
	$pconfig['l2tp_dns1']
300
));
301

    
302
$section->addInput(new Form_Input(
303
	'l2tp_dns2',
304
	'Secondary L2TM DNS server',
305
	'text',
306
	$pconfig['l2tp_dns2']
307
));
308

    
309
$form->add($section);
310

    
311
$section = new Form_Section("RADIUS");
312
$section->addClass('toggle-l2tp-enable');
313

    
314
$section->addInput(new Form_Checkbox(
315
	'radiusenable',
316
	'Enable',
317
	'Use a RADIUS server for authentication',
318
	$pconfig['radiusenable']
319
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
320

    
321
$section->addInput(new Form_Checkbox(
322
	'radacct_enable',
323
	'Accounting',
324
	'Enable RADIUS accounting',
325
	$pconfig['radacct_enable']
326
))->setHelp('Sends accounting packets to the RADIUS server.');
327

    
328
$section->addInput(new Form_IpAddress(
329
	'radiusserver',
330
	'Server',
331
	$pconfig['radiusserver']
332
))->setHelp('Enter the IP address of the RADIUS server.');
333

    
334
$section->addInput(new Form_Input(
335
	'radiussecret',
336
	'Secret',
337
	'password',
338
	$pconfig['radiussecret']
339
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
340

    
341
$section->addInput(new Form_Checkbox(
342
	'radiusissueips',
343
	'RADIUS issued IPs',
344
	'Issue IP Addresses via RADIUS server.',
345
	$pconfig['radiusissueips']
346
));
347

    
348
$form->add($section);
349

    
350
print($form);
351

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

    
355
<script type="text/javascript">
356
//<![CDATA[
357
events.push(function(){
358

    
359
	function setL2TP () {
360
		hide = ! $('#mode').prop('checked');
361

    
362
		hideClass('toggle-l2tp-enable', hide);
363
	}
364

    
365
	function setRADIUS () {
366
		hide = ! $('#radiusenable').prop('checked');
367

    
368
		hideCheckbox('radacct_enable', hide);
369
		hideInput('radiusserver', hide);
370
		hideInput('radiussecret', hide);
371
		hideCheckbox('radiusissueips', hide);
372
	}
373

    
374
	// on-click
375
	$('#mode').click(function () {
376
		setL2TP();
377
	});
378

    
379
	$('#radiusenable').click(function () {
380
		setRADIUS();
381
	});
382

    
383
	// on-page-load
384
	setRADIUS();
385
	setL2TP();
386

    
387
});
388
//]]>
389
</script>
390

    
391
<?php include("foot.inc")?>
(219-219/228)