Project

General

Profile

Download (11.3 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
##|+PRIV
25
##|*IDENT=page-vpn-vpnl2tp
26
##|*NAME=VPN: L2TP
27
##|*DESCR=Allow access to the 'VPN: L2TP' page.
28
##|*MATCH=vpn_l2tp.php*
29
##|-PRIV
30

    
31
require_once("guiconfig.inc");
32
require_once("vpn.inc");
33

    
34
init_config_arr(array('l2tp', 'radius'));
35
$l2tpcfg = &$config['l2tp'];
36

    
37
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
38
$pconfig['localip'] = $l2tpcfg['localip'];
39
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
40
$pconfig['mode'] = $l2tpcfg['mode'];
41
$pconfig['interface'] = $l2tpcfg['interface'];
42
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
43
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
44
$pconfig['mtu'] = $l2tpcfg['mtu'];
45
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
46
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
47
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
48
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
49
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
50
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
51
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
52
$pconfig['secret'] = $l2tpcfg['secret'];
53

    
54
if ($_POST['save']) {
55

    
56
	unset($input_errors);
57
	$pconfig = $_POST;
58

    
59
	/* input validation */
60
	if ($_POST['mode'] == "server") {
61
		$reqdfields = explode(" ", "localip");
62
		$reqdfieldsn = array(gettext("Server address"));
63
		if (!$_POST['radiusenable'] || !$_POST['radiusissueips']) {
64
			$reqdfields = array_merge($reqdfields, explode(" ", "remoteip"));
65
			$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Remote start address")));
66
		} elseif ($_POST['radiusenable']) {
67
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
68
			$reqdfieldsn = array_merge($reqdfieldsn,
69
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
70
		}
71

    
72
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
73

    
74
		if (($_POST['localip'] && !is_ipaddrv4($_POST['localip']))) {
75
			$input_errors[] = gettext("A valid server address must be specified.");
76
		}
77
		if (is_ipaddr_configured($_POST['localip'])) {
78
			$input_errors[] = gettext("'Server address' parameter should NOT be set to any IP address currently in use on this firewall.");
79
		}
80
		if ($_POST['l2tp_subnet'] && !is_ipaddrv4($_POST['remoteip']) &&
81
		    (!$_POST['radiusenable'] || !$_POST['radiusissueips'])) {
82
			$input_errors[] = gettext("A valid remote start address must be specified.");
83
		}
84
		if (($_POST['radiusserver'] && !is_ipaddrv4($_POST['radiusserver']))) {
85
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
86
		}
87

    
88
		if ($_POST['secret'] != $_POST['secret_confirm']) {
89
			$input_errors[] = gettext("Secret and confirmation must match");
90
		}
91

    
92
		if ($_POST['radiussecret'] != $_POST['radiussecret_confirm']) {
93
			$input_errors[] = gettext("RADIUS secret and confirmation must match");
94
		}
95

    
96
		if (!is_numericint($_POST['n_l2tp_units']) || $_POST['n_l2tp_units'] > 255) {
97
			$input_errors[] = gettext("Number of L2TP users must be between 1 and 255");
98
		}
99

    
100
		if (!$input_errors) {
101
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
102
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
103
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
104
			}
105
			if ($_POST['localip'] == get_interface_ip("lan")) {
106
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
107
			}
108
		}
109

    
110
		if (!empty($_POST['l2tp_dns1']) && !is_ipaddrv4(trim($_POST['l2tp_dns1']))) {
111
			$input_errors[] = gettext("The field 'Primary L2TP DNS Server' must contain a valid IPv4 address.");
112
		}
113
		if (!empty($_POST['l2tp_dns2']) && !is_ipaddrv4(trim($_POST['l2tp_dns2']))) {
114
			$input_errors[] = gettext("The field 'Secondary L2TP DNS Server' must contain a valid IPv4 address.");
115
		}
116
		if (!empty($_POST['l2tp_dns2']) && empty($_POST['l2tp_dns1'])) {
117
			$input_errors[] = gettext("The Secondary L2TP DNS Server cannot be set when the Primary L2TP DNS Server is empty.");
118
		}
119
		if ($_POST['mtu']) {
120
			if (!is_numericint($_POST['mtu'])) {
121
				$input_errors[] = "MTU must be an integer.";
122
			}
123
			$min_mtu = 576;
124
			$max_mtu = 9000;
125
			if (($_POST['mtu'] < $min_mtu) || ($_POST['mtu'] > $max_mtu)) {
126
				$input_errors[] = sprintf(gettext("The MTU must be between %d and %d bytes."), $min_mtu, $max_mtu);
127
			}
128
		}
129
	}
130

    
131
	if (!$input_errors) {
132
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
133
		$l2tpcfg['localip'] = $_POST['localip'];
134
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
135
		$l2tpcfg['mode'] = $_POST['mode'];
136
		$l2tpcfg['interface'] = $_POST['interface'];
137
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
138
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
139
		if ($_POST['radiussecret'] != DMYPWD) {
140
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
141
		}
142

    
143
		if ($_POST['secret'] != DMYPWD) {
144
			$l2tpcfg['secret'] = $_POST['secret'];
145
		}
146

    
147
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
148

    
149

    
150
		if ($_POST['l2tp_dns1'] == "") {
151
			if (isset($l2tpcfg['dns1'])) {
152
				unset($l2tpcfg['dns1']);
153
			}
154
		} else {
155
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
156
		}
157

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

    
166
		if ($_POST['mtu'] == "") {
167
			if (isset($l2tpcfg['mtu'])) {
168
				unset($l2tpcfg['mtu']);
169
			}
170
		} else {
171
			$l2tpcfg['mtu'] = $_POST['mtu'];
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(gettext("L2TP VPN configuration changed."));
193

    
194
		$changes_applied = true;
195
		$retval = 0;
196
		$retval |= vpn_l2tp_configure();
197
	}
198
}
199

    
200
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
201
$pglinks = array("", "@self", "@self");
202
$shortcut_section = "l2tps";
203
include("head.inc");
204

    
205
if ($input_errors) {
206
	print_input_errors($input_errors);
207
}
208

    
209
if ($changes_applied) {
210
	print_apply_result_box($retval);
211
}
212

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

    
218
$form = new Form();
219

    
220
$section = new Form_Section("Enable L2TP");
221

    
222
$section->addInput(new Form_Checkbox(
223
	'mode',
224
	'Enable',
225
	'Enable L2TP server',
226
	($pconfig['mode'] == "server"),
227
	'server'
228
));
229

    
230
$form->add($section);
231

    
232
$iflist = array();
233
$interfaces = get_configured_interface_with_descr();
234
foreach ($interfaces as $iface => $ifacename) {
235
	$iflist[$iface] = $ifacename;
236
}
237

    
238
$section = new Form_Section("Configuration");
239
$section->addClass('toggle-l2tp-enable');
240

    
241
$section->addInput(new Form_Select(
242
	'interface',
243
	'*Interface',
244
	$pconfig['interface'],
245
	$iflist
246
));
247

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

    
257
$section->addInput(new Form_IpAddress(
258
        'remoteip',
259
        '*Remote address range',
260
        $pconfig['remoteip']
261
))->addMask('l2tp_subnet', $pconfig['l2tp_subnet'], 32)->setWidth(5)
262
  ->setHelp('Specify the starting address for the client IP address subnet.');
263

    
264
$section->addInput(new Form_Select(
265
	'n_l2tp_units',
266
	'*Number of L2TP users',
267
	$pconfig['n_l2tp_units'],
268
	array_combine(range(1, 255, 1), range(1, 255, 1))
269
));
270

    
271
$section->addPassword(new Form_Input(
272
	'secret',
273
	'Secret',
274
	'password',
275
	$pconfig['secret']
276
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
277

    
278
$section->addInput(new Form_Select(
279
	'paporchap',
280
	'*Authentication type',
281
	$pconfig['paporchap'],
282
	array(
283
		'chap' => 'CHAP',
284
		'chap-msv2' => 'MS-CHAPv2',
285
		'pap' => 'PAP'
286
		)
287
))->setHelp('Specifies the protocol to use for authentication.');
288

    
289
$section->addInput(new Form_Input(
290
	'l2tp_dns1',
291
	'Primary L2TP DNS server',
292
	'text',
293
	$pconfig['l2tp_dns1']
294
));
295

    
296
$section->addInput(new Form_Input(
297
	'l2tp_dns2',
298
	'Secondary L2TP DNS server',
299
	'text',
300
	$pconfig['l2tp_dns2']
301
));
302

    
303
$section->addInput(new Form_Input(
304
	'mtu',
305
	'VPN MTU',
306
	'number',
307
	$pconfig['mtu']
308
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
309
			'This is typically 1500 bytes but can vary in some circumstances.');
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->addPassword(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
<div class="infoblock blockopen">
355
<?php
356
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
357
?>
358
</div>
359

    
360
<script type="text/javascript">
361
//<![CDATA[
362
events.push(function() {
363

    
364
	function setL2TP () {
365
		hide = ! $('#mode').prop('checked');
366

    
367
		hideClass('toggle-l2tp-enable', hide);
368
	}
369

    
370
	function setRADIUS () {
371
		hide = ! $('#radiusenable').prop('checked');
372

    
373
		hideCheckbox('radacct_enable', hide);
374
		hideInput('radiusserver', hide);
375
		hideInput('radiussecret', hide);
376
		hideCheckbox('radiusissueips', hide);
377
	}
378

    
379
	// on-click
380
	$('#mode').click(function () {
381
		setL2TP();
382
	});
383

    
384
	$('#radiusenable').click(function () {
385
		setRADIUS();
386
	});
387

    
388
	// on-page-load
389
	setRADIUS();
390
	setL2TP();
391

    
392
});
393
//]]>
394
</script>
395

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