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

    
213
if ($savemsg) {
214
	print_info_box($savemsg);
215
}
216

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

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

    
227
$section = new Form_Section("Enable L2TP");
228

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

    
237
$form->add($section);
238

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

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

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

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

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

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

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

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

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

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

    
311
$form->add($section);
312

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

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

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

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

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

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

    
350
$form->add($section);
351

    
352
print($form);
353

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

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

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

    
364
		hideClass('toggle-l2tp-enable', hide);
365
	}
366

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

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

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

    
381
	$('#radiusenable').click(function () {
382
		setRADIUS();
383
	});
384

    
385
	// on-page-load
386
	setRADIUS();
387
	setL2TP();
388

    
389
});
390
//]]>
391
</script>
392

    
393
<?php include("foot.inc")?>
(221-221/228)