Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5656fe23 Ermal Lu?i
<?php
2
/*
3 c5d81585 Renato Botelho
 * vpn_l2tp.php
4 b9043cdc Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 b9043cdc Stephen Beaver
 *
9 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12 b9043cdc Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
14 b9043cdc Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20 b9043cdc Stephen Beaver
 */
21 5656fe23 Ermal Lu?i
22 047cb829 Ermal Lu?i
##|+PRIV
23
##|*IDENT=page-vpn-vpnl2tp
24 9599211d jim-p
##|*NAME=VPN: L2TP
25
##|*DESCR=Allow access to the 'VPN: L2TP' page.
26 047cb829 Ermal Lu?i
##|*MATCH=vpn_l2tp.php*
27
##|-PRIV
28
29 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
30 483e6de8 Scott Ullrich
require_once("vpn.inc");
31 5656fe23 Ermal Lu?i
32
if (!is_array($config['l2tp']['radius'])) {
33
	$config['l2tp']['radius'] = array();
34
}
35
$l2tpcfg = &$config['l2tp'];
36
37
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
38
$pconfig['localip'] = $l2tpcfg['localip'];
39 a56120f2 Ermal Lu?i
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
40 5656fe23 Ermal Lu?i
$pconfig['mode'] = $l2tpcfg['mode'];
41
$pconfig['interface'] = $l2tpcfg['interface'];
42 c8cc0c1c smos
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
43
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
44 5656fe23 Ermal Lu?i
$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 9a9b0007 Phil Davis
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
49 5656fe23 Ermal Lu?i
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
50
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
51 40de0b13 Ermal Lu?i
$pconfig['secret'] = $l2tpcfg['secret'];
52 5656fe23 Ermal Lu?i
53 84450372 Steve Beaver
if ($_POST['save']) {
54 5656fe23 Ermal Lu?i
55
	unset($input_errors);
56
	$pconfig = $_POST;
57
58
	/* input validation */
59
	if ($_POST['mode'] == "server") {
60
		$reqdfields = explode(" ", "localip remoteip");
61 6c07db48 Phil Davis
		$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
62 5656fe23 Ermal Lu?i
63
		if ($_POST['radiusenable']) {
64
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
65
			$reqdfieldsn = array_merge($reqdfieldsn,
66 a3e00d53 Phil Davis
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
67 5656fe23 Ermal Lu?i
		}
68
69 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
70 5656fe23 Ermal Lu?i
71
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
72
			$input_errors[] = gettext("A valid server address must be specified.");
73
		}
74 0a0b17d9 Renato Botelho
		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 a56120f2 Ermal Lu?i
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
78 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid remote start address must be specified.");
79
		}
80
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
81
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
82
		}
83
84 c8b10b4c Stephen Beaver
		if ($_POST['secret'] != $_POST['secret_confirm']) {
85
			$input_errors[] = gettext("Secret and confirmation must match");
86
		}
87
88
		if ($_POST['radiussecret'] != $_POST['radiussecret_confirm']) {
89 dbd00a12 Phil Davis
			$input_errors[] = gettext("RADIUS secret and confirmation must match");
90 c8b10b4c Stephen Beaver
		}
91
92 be513209 Renato Botelho
		if (!is_numericint($_POST['n_l2tp_units']) || $_POST['n_l2tp_units'] > 255) {
93
			$input_errors[] = gettext("Number of L2TP users must be between 1 and 255");
94
		}
95
96 5656fe23 Ermal Lu?i
		if (!$input_errors) {
97 a56120f2 Ermal Lu?i
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
98 ddf82c16 Renato Botelho
			if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
99 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
100
			}
101 a55e9c70 Ermal Lu?i
			if ($_POST['localip'] == get_interface_ip("lan")) {
102 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
103
			}
104
		}
105 11a3e413 jim-p
106
		if (!empty($_POST['l2tp_dns1']) && !is_ipaddrv4(trim($_POST['l2tp_dns1']))) {
107
			$input_errors[] = gettext("The field 'Primary L2TP DNS Server' must contain a valid IPv4 address.");
108
		}
109
		if (!empty($_POST['l2tp_dns2']) && !is_ipaddrv4(trim($_POST['l2tp_dns2']))) {
110
			$input_errors[] = gettext("The field 'Secondary L2TP DNS Server' must contain a valid IPv4 address.");
111
		}
112
		if (!empty($_POST['l2tp_dns2']) && empty($_POST['l2tp_dns1'])) {
113
			$input_errors[] = gettext("The Secondary L2TP DNS Server cannot be set when the Primary L2TP DNS Server is empty.");
114
		}
115
116 5656fe23 Ermal Lu?i
	}
117
118
	if (!$input_errors) {
119
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
120
		$l2tpcfg['localip'] = $_POST['localip'];
121 a56120f2 Ermal Lu?i
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
122 5656fe23 Ermal Lu?i
		$l2tpcfg['mode'] = $_POST['mode'];
123
		$l2tpcfg['interface'] = $_POST['interface'];
124
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
125
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
126 76d6d925 Stephen Beaver
		if ($_POST['radiussecret'] != DMYPWD) {
127
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
128
		}
129
130
		if ($_POST['secret'] != DMYPWD) {
131
			$l2tpcfg['secret'] = $_POST['secret'];
132
		}
133
134 5656fe23 Ermal Lu?i
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
135
136 c8cc0c1c smos
137
		if ($_POST['l2tp_dns1'] == "") {
138 6c07db48 Phil Davis
			if (isset($l2tpcfg['dns1'])) {
139 c8cc0c1c smos
				unset($l2tpcfg['dns1']);
140 a3e00d53 Phil Davis
			}
141 6c07db48 Phil Davis
		} else {
142
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
143
		}
144 c8cc0c1c smos
145 6c07db48 Phil Davis
		if ($_POST['l2tp_dns2'] == "") {
146
			if (isset($l2tpcfg['dns2'])) {
147
				unset($l2tpcfg['dns2']);
148 a3e00d53 Phil Davis
			}
149 6c07db48 Phil Davis
		} else {
150
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
151
		}
152 c8cc0c1c smos
153 a3e00d53 Phil Davis
		if ($_POST['radiusenable'] == "yes") {
154 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['enable'] = true;
155 a3e00d53 Phil Davis
		} else {
156 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['enable']);
157 a3e00d53 Phil Davis
		}
158 5656fe23 Ermal Lu?i
159 a3e00d53 Phil Davis
		if ($_POST['radacct_enable'] == "yes") {
160 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['accounting'] = true;
161 a3e00d53 Phil Davis
		} else {
162 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['accounting']);
163 a3e00d53 Phil Davis
		}
164 5656fe23 Ermal Lu?i
165 a3e00d53 Phil Davis
		if ($_POST['radiusissueips'] == "yes") {
166 5656fe23 Ermal Lu?i
			$l2tpcfg['radius']['radiusissueips'] = true;
167 a3e00d53 Phil Davis
		} else {
168 5656fe23 Ermal Lu?i
			unset($l2tpcfg['radius']['radiusissueips']);
169 a3e00d53 Phil Davis
		}
170 5656fe23 Ermal Lu?i
171 1eab8134 doktornotor
		write_config(gettext("L2TP VPN configuration changed."));
172 5656fe23 Ermal Lu?i
173 44c42356 Phil Davis
		$changes_applied = true;
174 5656fe23 Ermal Lu?i
		$retval = 0;
175 44c42356 Phil Davis
		$retval |= vpn_l2tp_configure();
176 5656fe23 Ermal Lu?i
	}
177
}
178
179 ea62cbe7 Stephen Beaver
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
180 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
181 ea62cbe7 Stephen Beaver
$shortcut_section = "l2tps";
182 5656fe23 Ermal Lu?i
include("head.inc");
183
184 c86c14dc Phil Davis
if ($input_errors) {
185 ea62cbe7 Stephen Beaver
	print_input_errors($input_errors);
186 c86c14dc Phil Davis
}
187 5656fe23 Ermal Lu?i
188 44c42356 Phil Davis
if ($changes_applied) {
189
	print_apply_result_box($retval);
190 c86c14dc Phil Davis
}
191 61144c9b Sander van Leeuwen
192
$tab_array = array();
193 ea62cbe7 Stephen Beaver
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
194
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
195 748cbea6 Sander van Leeuwen
display_top_tabs($tab_array);
196 61144c9b Sander van Leeuwen
197 8f58b51b jim-p
$form = new Form();
198 ea62cbe7 Stephen Beaver
199
$section = new Form_Section("Enable L2TP");
200
201
$section->addInput(new Form_Checkbox(
202
	'mode',
203
	'Enable',
204 f680e46c jim-p
	'Enable L2TP server',
205 ea62cbe7 Stephen Beaver
	($pconfig['mode'] == "server"),
206
	'server'
207
));
208
209
$form->add($section);
210
211
$iflist = array();
212 61144c9b Sander van Leeuwen
$interfaces = get_configured_interface_with_descr();
213 ea62cbe7 Stephen Beaver
foreach ($interfaces as $iface => $ifacename) {
214
	$iflist[$iface] = $ifacename;
215
}
216 61144c9b Sander van Leeuwen
217 ea62cbe7 Stephen Beaver
$section = new Form_Section("Configuration");
218
$section->addClass('toggle-l2tp-enable');
219
220
$section->addInput(new Form_Select(
221
	'interface',
222 1bbdab13 Phil Davis
	'*Interface',
223 ea62cbe7 Stephen Beaver
	$pconfig['interface'],
224
	$iflist
225
));
226
227
$section->addInput(new Form_Input(
228
	'localip',
229 1bbdab13 Phil Davis
	'*Server address',
230 ea62cbe7 Stephen Beaver
	'text',
231
	$pconfig['localip']
232 3e142087 Phil Davis
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". %1$s' .
233
			'Typically this is set to an unused IP just outside of the client range.%1$s%1$s' .
234
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.', '<br />');
235 ea62cbe7 Stephen Beaver
236
$section->addInput(new Form_IpAddress(
237
	'remoteip',
238 1bbdab13 Phil Davis
	'*Remote address range',
239 ea62cbe7 Stephen Beaver
	$pconfig['remoteip']
240
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
241
  ->setHelp('Specify the starting address for the client IP address subnet.');
242
243 be513209 Renato Botelho
$section->addInput(new Form_Select(
244 ea62cbe7 Stephen Beaver
	'n_l2tp_units',
245 1bbdab13 Phil Davis
	'*Number of L2TP users',
246 ea62cbe7 Stephen Beaver
	$pconfig['n_l2tp_units'],
247 be513209 Renato Botelho
	array_combine(range(1, 255, 1), range(1, 255, 1))
248 ea62cbe7 Stephen Beaver
));
249
250 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
251 ea62cbe7 Stephen Beaver
	'secret',
252
	'Secret',
253
	'password',
254
	$pconfig['secret']
255
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
256
257
$section->addInput(new Form_Select(
258
	'paporchap',
259 1bbdab13 Phil Davis
	'*Authentication type',
260 ea62cbe7 Stephen Beaver
	$pconfig['paporchap'],
261
	array(
262
		'chap' => 'CHAP',
263
		'chap-msv2' => 'MS-CHAPv2',
264
		'pap' => 'PAP'
265
		)
266
))->setHelp('Specifies the protocol to use for authentication.');
267
268
$section->addInput(new Form_Input(
269
	'l2tp_dns1',
270 f06b86ca jim-p
	'Primary L2TP DNS server',
271 ea62cbe7 Stephen Beaver
	'text',
272
	$pconfig['l2tp_dns1']
273
));
274
275
$section->addInput(new Form_Input(
276
	'l2tp_dns2',
277 f06b86ca jim-p
	'Secondary L2TP DNS server',
278 ea62cbe7 Stephen Beaver
	'text',
279
	$pconfig['l2tp_dns2']
280
));
281
282
$form->add($section);
283
284
$section = new Form_Section("RADIUS");
285
$section->addClass('toggle-l2tp-enable');
286
287
$section->addInput(new Form_Checkbox(
288
	'radiusenable',
289
	'Enable',
290
	'Use a RADIUS server for authentication',
291
	$pconfig['radiusenable']
292
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
293
294
$section->addInput(new Form_Checkbox(
295
	'radacct_enable',
296
	'Accounting',
297
	'Enable RADIUS accounting',
298
	$pconfig['radacct_enable']
299
))->setHelp('Sends accounting packets to the RADIUS server.');
300
301
$section->addInput(new Form_IpAddress(
302
	'radiusserver',
303 1bbdab13 Phil Davis
	'*Server',
304 ea62cbe7 Stephen Beaver
	$pconfig['radiusserver']
305
))->setHelp('Enter the IP address of the RADIUS server.');
306
307 c8b10b4c Stephen Beaver
$section->addPassword(new Form_Input(
308 ea62cbe7 Stephen Beaver
	'radiussecret',
309 1bbdab13 Phil Davis
	'*Secret',
310 ea62cbe7 Stephen Beaver
	'password',
311
	$pconfig['radiussecret']
312
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
313
314
$section->addInput(new Form_Checkbox(
315
	'radiusissueips',
316
	'RADIUS issued IPs',
317
	'Issue IP Addresses via RADIUS server.',
318
	$pconfig['radiusissueips']
319
));
320
321
$form->add($section);
322
323
print($form);
324 c4a7740d Sander van Leeuwen
?>
325 60362560 Phil Davis
<div class="infoblock blockopen">
326
<?php
327 8545adde k-paulius
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
328 60362560 Phil Davis
?>
329
</div>
330 61144c9b Sander van Leeuwen
331 8fd9052f Colin Fleming
<script type="text/javascript">
332 d28502be Colin Fleming
//<![CDATA[
333 c86c14dc Phil Davis
events.push(function() {
334 ea62cbe7 Stephen Beaver
335
	function setL2TP () {
336
		hide = ! $('#mode').prop('checked');
337
338
		hideClass('toggle-l2tp-enable', hide);
339
	}
340
341
	function setRADIUS () {
342
		hide = ! $('#radiusenable').prop('checked');
343
344
		hideCheckbox('radacct_enable', hide);
345
		hideInput('radiusserver', hide);
346
		hideInput('radiussecret', hide);
347
		hideCheckbox('radiusissueips', hide);
348
	}
349
350
	// on-click
351
	$('#mode').click(function () {
352
		setL2TP();
353
	});
354
355
	$('#radiusenable').click(function () {
356
		setRADIUS();
357
	});
358
359
	// on-page-load
360
	setRADIUS();
361
	setL2TP();
362
363
});
364 d28502be Colin Fleming
//]]>
365 5656fe23 Ermal Lu?i
</script>
366
367 3fac0afc Jose Luis Duran
<?php include("foot.inc")?>