Project

General

Profile

Download (10.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-2020 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['radiusenable'] = isset($l2tpcfg['radius']['enable']);
45
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
46
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
47
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
48
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
49
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
50
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
51
$pconfig['secret'] = $l2tpcfg['secret'];
52

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

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

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

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

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

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

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

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

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

    
109
		if (!empty($_POST['l2tp_dns1']) && !is_ipaddrv4(trim($_POST['l2tp_dns1']))) {
110
			$input_errors[] = gettext("The field 'Primary L2TP DNS Server' must contain a valid IPv4 address.");
111
		}
112
		if (!empty($_POST['l2tp_dns2']) && !is_ipaddrv4(trim($_POST['l2tp_dns2']))) {
113
			$input_errors[] = gettext("The field 'Secondary L2TP DNS Server' must contain a valid IPv4 address.");
114
		}
115
		if (!empty($_POST['l2tp_dns2']) && empty($_POST['l2tp_dns1'])) {
116
			$input_errors[] = gettext("The Secondary L2TP DNS Server cannot be set when the Primary L2TP DNS Server is empty.");
117
		}
118

    
119
	}
120

    
121
	if (!$input_errors) {
122
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
123
		$l2tpcfg['localip'] = $_POST['localip'];
124
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
125
		$l2tpcfg['mode'] = $_POST['mode'];
126
		$l2tpcfg['interface'] = $_POST['interface'];
127
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
128
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
129
		if ($_POST['radiussecret'] != DMYPWD) {
130
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
131
		}
132

    
133
		if ($_POST['secret'] != DMYPWD) {
134
			$l2tpcfg['secret'] = $_POST['secret'];
135
		}
136

    
137
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
138

    
139

    
140
		if ($_POST['l2tp_dns1'] == "") {
141
			if (isset($l2tpcfg['dns1'])) {
142
				unset($l2tpcfg['dns1']);
143
			}
144
		} else {
145
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
146
		}
147

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

    
156
		if ($_POST['radiusenable'] == "yes") {
157
			$l2tpcfg['radius']['enable'] = true;
158
		} else {
159
			unset($l2tpcfg['radius']['enable']);
160
		}
161

    
162
		if ($_POST['radacct_enable'] == "yes") {
163
			$l2tpcfg['radius']['accounting'] = true;
164
		} else {
165
			unset($l2tpcfg['radius']['accounting']);
166
		}
167

    
168
		if ($_POST['radiusissueips'] == "yes") {
169
			$l2tpcfg['radius']['radiusissueips'] = true;
170
		} else {
171
			unset($l2tpcfg['radius']['radiusissueips']);
172
		}
173

    
174
		write_config(gettext("L2TP VPN configuration changed."));
175

    
176
		$changes_applied = true;
177
		$retval = 0;
178
		$retval |= vpn_l2tp_configure();
179
	}
180
}
181

    
182
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
183
$pglinks = array("", "@self", "@self");
184
$shortcut_section = "l2tps";
185
include("head.inc");
186

    
187
if ($input_errors) {
188
	print_input_errors($input_errors);
189
}
190

    
191
if ($changes_applied) {
192
	print_apply_result_box($retval);
193
}
194

    
195
$tab_array = array();
196
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
197
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
198
display_top_tabs($tab_array);
199

    
200
$form = new Form();
201

    
202
$section = new Form_Section("Enable L2TP");
203

    
204
$section->addInput(new Form_Checkbox(
205
	'mode',
206
	'Enable',
207
	'Enable L2TP server',
208
	($pconfig['mode'] == "server"),
209
	'server'
210
));
211

    
212
$form->add($section);
213

    
214
$iflist = array();
215
$interfaces = get_configured_interface_with_descr();
216
foreach ($interfaces as $iface => $ifacename) {
217
	$iflist[$iface] = $ifacename;
218
}
219

    
220
$section = new Form_Section("Configuration");
221
$section->addClass('toggle-l2tp-enable');
222

    
223
$section->addInput(new Form_Select(
224
	'interface',
225
	'*Interface',
226
	$pconfig['interface'],
227
	$iflist
228
));
229

    
230
$section->addInput(new Form_Input(
231
	'localip',
232
	'*Server address',
233
	'text',
234
	$pconfig['localip']
235
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". %1$s' .
236
			'Typically this is set to an unused IP just outside of the client range.%1$s%1$s' .
237
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.', '<br />');
238

    
239
$section->addInput(new Form_IpAddress(
240
        'remoteip',
241
        '*Remote address range',
242
        $pconfig['remoteip']
243
))->addMask('l2tp_subnet', $pconfig['l2tp_subnet'], 32)->setWidth(5)
244
  ->setHelp('Specify the starting address for the client IP address subnet.');
245

    
246
$section->addInput(new Form_Select(
247
	'n_l2tp_units',
248
	'*Number of L2TP users',
249
	$pconfig['n_l2tp_units'],
250
	array_combine(range(1, 255, 1), range(1, 255, 1))
251
));
252

    
253
$section->addPassword(new Form_Input(
254
	'secret',
255
	'Secret',
256
	'password',
257
	$pconfig['secret']
258
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
259

    
260
$section->addInput(new Form_Select(
261
	'paporchap',
262
	'*Authentication type',
263
	$pconfig['paporchap'],
264
	array(
265
		'chap' => 'CHAP',
266
		'chap-msv2' => 'MS-CHAPv2',
267
		'pap' => 'PAP'
268
		)
269
))->setHelp('Specifies the protocol to use for authentication.');
270

    
271
$section->addInput(new Form_Input(
272
	'l2tp_dns1',
273
	'Primary L2TP DNS server',
274
	'text',
275
	$pconfig['l2tp_dns1']
276
));
277

    
278
$section->addInput(new Form_Input(
279
	'l2tp_dns2',
280
	'Secondary L2TP DNS server',
281
	'text',
282
	$pconfig['l2tp_dns2']
283
));
284

    
285
$form->add($section);
286

    
287
$section = new Form_Section("RADIUS");
288
$section->addClass('toggle-l2tp-enable');
289

    
290
$section->addInput(new Form_Checkbox(
291
	'radiusenable',
292
	'Enable',
293
	'Use a RADIUS server for authentication',
294
	$pconfig['radiusenable']
295
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
296

    
297
$section->addInput(new Form_Checkbox(
298
	'radacct_enable',
299
	'Accounting',
300
	'Enable RADIUS accounting',
301
	$pconfig['radacct_enable']
302
))->setHelp('Sends accounting packets to the RADIUS server.');
303

    
304
$section->addInput(new Form_IpAddress(
305
	'radiusserver',
306
	'*Server',
307
	$pconfig['radiusserver']
308
))->setHelp('Enter the IP address of the RADIUS server.');
309

    
310
$section->addPassword(new Form_Input(
311
	'radiussecret',
312
	'*Secret',
313
	'password',
314
	$pconfig['radiussecret']
315
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
316

    
317
$section->addInput(new Form_Checkbox(
318
	'radiusissueips',
319
	'RADIUS issued IPs',
320
	'Issue IP Addresses via RADIUS server.',
321
	$pconfig['radiusissueips']
322
));
323

    
324
$form->add($section);
325

    
326
print($form);
327
?>
328
<div class="infoblock blockopen">
329
<?php
330
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
331
?>
332
</div>
333

    
334
<script type="text/javascript">
335
//<![CDATA[
336
events.push(function() {
337

    
338
	function setL2TP () {
339
		hide = ! $('#mode').prop('checked');
340

    
341
		hideClass('toggle-l2tp-enable', hide);
342
	}
343

    
344
	function setRADIUS () {
345
		hide = ! $('#radiusenable').prop('checked');
346

    
347
		hideCheckbox('radacct_enable', hide);
348
		hideInput('radiusserver', hide);
349
		hideInput('radiussecret', hide);
350
		hideCheckbox('radiusissueips', hide);
351
	}
352

    
353
	// on-click
354
	$('#mode').click(function () {
355
		setL2TP();
356
	});
357

    
358
	$('#radiusenable').click(function () {
359
		setRADIUS();
360
	});
361

    
362
	// on-page-load
363
	setRADIUS();
364
	setL2TP();
365

    
366
});
367
//]]>
368
</script>
369

    
370
<?php include("foot.inc")?>
(223-223/230)