Project

General

Profile

Download (11.5 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-2024 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
$pconfig['remoteip'] = config_get_path('l2tp/radius/remoteip');
35
$pconfig['localip'] = config_get_path('l2tp/radius/localip');
36
$pconfig['l2tp_subnet'] = config_get_path('l2tp/radius/l2tp_subnet');
37
$pconfig['mode'] = config_get_path('l2tp/radius/mode');
38
$pconfig['interface'] = config_get_path('l2tp/radius/interface');
39
$pconfig['l2tp_dns1'] = config_get_path('l2tp/radius/dns1');
40
$pconfig['l2tp_dns2'] = config_get_path('l2tp/radius/dns2');
41
$pconfig['mtu'] = config_get_path('l2tp/radius/mtu');
42
$pconfig['radiusenable'] = config_path_enabled('l2tp/radius');
43
$pconfig['radacct_enable'] = config_path_enabled('l2tp/accounting');
44
$pconfig['radiusserver'] = config_get_path('l2tp/radius/radius')['server'];
45
$pconfig['radiussecret'] = config_get_path('l2tp/radius/radius')['secret'];
46
$pconfig['radiusissueips'] = config_path_enabled('l2tp/radiusissueips');
47
$pconfig['n_l2tp_units'] = config_get_path('l2tp/radius/n_l2tp_units');
48
$pconfig['paporchap'] = config_get_path('l2tp/radius/paporchap');
49
$pconfig['secret'] = config_get_path('l2tp/radius/secret');
50

    
51
if ($_POST['save']) {
52

    
53
	unset($input_errors);
54
	$pconfig = $_POST;
55

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

    
69
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
70

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

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

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

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

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

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

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

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

    
145
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
146

    
147

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

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

    
164
		if ($_POST['mtu'] == "") {
165
			if (isset($l2tpcfg['mtu'])) {
166
				unset($l2tpcfg['mtu']);
167
			}
168
		} else {
169
			$l2tpcfg['mtu'] = $_POST['mtu'];
170
		}
171

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

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

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

    
190
		config_set_path('l2tp', $l2tpcfg);
191
		write_config(gettext("L2TP VPN configuration changed."));
192

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

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

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

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

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

    
217
$form = new Form();
218

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
$section->addInput(new Form_Input(
303
	'mtu',
304
	'VPN MTU',
305
	'number',
306
	$pconfig['mtu']
307
))->setHelp('If this field is blank, the adapter\'s default MTU will be used. ' .
308
			'This is typically 1500 bytes but can vary in some circumstances.');
309

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

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

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

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

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

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

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

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

    
351
print($form);
352
?>
353
<div class="infoblock blockopen">
354
<?php
355
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
356
?>
357
</div>
358

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

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

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

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

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

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

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

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

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

    
395
<?php include("foot.inc")?>
(225-225/232)