Project

General

Profile

Download (9.69 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-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * 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
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * 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
 */
21

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

    
29
require_once("guiconfig.inc");
30
require_once("vpn.inc");
31

    
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
$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) {
54

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

    
58
	/* input validation */
59
	if ($_POST['mode'] == "server") {
60
		$reqdfields = explode(" ", "localip remoteip");
61
		$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
62

    
63
		if ($_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_ipaddr($_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_ipaddr($_POST['remoteip']))) {
78
			$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
		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
			$input_errors[] = gettext("RADIUS secret and confirmation must match");
90
		}
91

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

    
107
	if (!$input_errors) {
108
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
109
		$l2tpcfg['localip'] = $_POST['localip'];
110
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
111
		$l2tpcfg['mode'] = $_POST['mode'];
112
		$l2tpcfg['interface'] = $_POST['interface'];
113
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
114
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
115
		if ($_POST['radiussecret'] != DMYPWD) {
116
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
117
		}
118

    
119
		if ($_POST['secret'] != DMYPWD) {
120
			$l2tpcfg['secret'] = $_POST['secret'];
121
		}
122

    
123
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
124

    
125

    
126
		if ($_POST['l2tp_dns1'] == "") {
127
			if (isset($l2tpcfg['dns1'])) {
128
				unset($l2tpcfg['dns1']);
129
			}
130
		} else {
131
			$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
132
		}
133

    
134
		if ($_POST['l2tp_dns2'] == "") {
135
			if (isset($l2tpcfg['dns2'])) {
136
				unset($l2tpcfg['dns2']);
137
			}
138
		} else {
139
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
140
		}
141

    
142
		if ($_POST['radiusenable'] == "yes") {
143
			$l2tpcfg['radius']['enable'] = true;
144
		} else {
145
			unset($l2tpcfg['radius']['enable']);
146
		}
147

    
148
		if ($_POST['radacct_enable'] == "yes") {
149
			$l2tpcfg['radius']['accounting'] = true;
150
		} else {
151
			unset($l2tpcfg['radius']['accounting']);
152
		}
153

    
154
		if ($_POST['radiusissueips'] == "yes") {
155
			$l2tpcfg['radius']['radiusissueips'] = true;
156
		} else {
157
			unset($l2tpcfg['radius']['radiusissueips']);
158
		}
159

    
160
		write_config();
161

    
162
		$retval = 0;
163
		$retval = vpn_l2tp_configure();
164
		$savemsg = get_std_save_message($retval);
165

    
166
		/* if ajax is calling, give them an update message */
167
		if (isAjax()) {
168
			print_info_box($savemsg, 'success');
169
		}
170
	}
171
}
172

    
173
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
174
$shortcut_section = "l2tps";
175
include("head.inc");
176

    
177
if ($input_errors) {
178
	print_input_errors($input_errors);
179
}
180

    
181
if ($savemsg) {
182
	print_info_box($savemsg, 'success');
183
}
184

    
185
$tab_array = array();
186
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
187
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
188
display_top_tabs($tab_array);
189

    
190
$form = new Form();
191

    
192
$section = new Form_Section("Enable L2TP");
193

    
194
$section->addInput(new Form_Checkbox(
195
	'mode',
196
	'Enable',
197
	'Enable L2TP server',
198
	($pconfig['mode'] == "server"),
199
	'server'
200
));
201

    
202
$form->add($section);
203

    
204
$iflist = array();
205
$interfaces = get_configured_interface_with_descr();
206
foreach ($interfaces as $iface => $ifacename) {
207
	$iflist[$iface] = $ifacename;
208
}
209

    
210
$section = new Form_Section("Configuration");
211
$section->addClass('toggle-l2tp-enable');
212

    
213
$section->addInput(new Form_Select(
214
	'interface',
215
	'Interface',
216
	$pconfig['interface'],
217
	$iflist
218
));
219

    
220
$section->addInput(new Form_Input(
221
	'localip',
222
	'Server address',
223
	'text',
224
	$pconfig['localip']
225
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
226
			'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
227
			'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
228

    
229
$section->addInput(new Form_IpAddress(
230
	'remoteip',
231
	'Remote address range',
232
	$pconfig['remoteip']
233
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
234
  ->setHelp('Specify the starting address for the client IP address subnet.');
235

    
236
$section->addInput(new Form_Select(
237
	'n_l2tp_units',
238
	'Number of L2TP users',
239
	$pconfig['n_l2tp_units'],
240
	array_combine(range(1, 255, 1), range(1, 255, 1))
241
));
242

    
243
$section->addPassword(new Form_Input(
244
	'secret',
245
	'Secret',
246
	'password',
247
	$pconfig['secret']
248
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
249

    
250
$section->addInput(new Form_Select(
251
	'paporchap',
252
	'Authentication type',
253
	$pconfig['paporchap'],
254
	array(
255
		'chap' => 'CHAP',
256
		'chap-msv2' => 'MS-CHAPv2',
257
		'pap' => 'PAP'
258
		)
259
))->setHelp('Specifies the protocol to use for authentication.');
260

    
261
$section->addInput(new Form_Input(
262
	'l2tp_dns1',
263
	'Primary L2TP DNS server',
264
	'text',
265
	$pconfig['l2tp_dns1']
266
));
267

    
268
$section->addInput(new Form_Input(
269
	'l2tp_dns2',
270
	'Secondary L2TP DNS server',
271
	'text',
272
	$pconfig['l2tp_dns2']
273
));
274

    
275
$form->add($section);
276

    
277
$section = new Form_Section("RADIUS");
278
$section->addClass('toggle-l2tp-enable');
279

    
280
$section->addInput(new Form_Checkbox(
281
	'radiusenable',
282
	'Enable',
283
	'Use a RADIUS server for authentication',
284
	$pconfig['radiusenable']
285
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
286

    
287
$section->addInput(new Form_Checkbox(
288
	'radacct_enable',
289
	'Accounting',
290
	'Enable RADIUS accounting',
291
	$pconfig['radacct_enable']
292
))->setHelp('Sends accounting packets to the RADIUS server.');
293

    
294
$section->addInput(new Form_IpAddress(
295
	'radiusserver',
296
	'Server',
297
	$pconfig['radiusserver']
298
))->setHelp('Enter the IP address of the RADIUS server.');
299

    
300
$section->addPassword(new Form_Input(
301
	'radiussecret',
302
	'Secret',
303
	'password',
304
	$pconfig['radiussecret']
305
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
306

    
307
$section->addInput(new Form_Checkbox(
308
	'radiusissueips',
309
	'RADIUS issued IPs',
310
	'Issue IP Addresses via RADIUS server.',
311
	$pconfig['radiusissueips']
312
));
313

    
314
$form->add($section);
315

    
316
print($form);
317
?>
318
<div class="infoblock blockopen">
319
<?php
320
	print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
321
?>
322
</div>
323

    
324
<script type="text/javascript">
325
//<![CDATA[
326
events.push(function() {
327

    
328
	function setL2TP () {
329
		hide = ! $('#mode').prop('checked');
330

    
331
		hideClass('toggle-l2tp-enable', hide);
332
	}
333

    
334
	function setRADIUS () {
335
		hide = ! $('#radiusenable').prop('checked');
336

    
337
		hideCheckbox('radacct_enable', hide);
338
		hideInput('radiusserver', hide);
339
		hideInput('radiussecret', hide);
340
		hideCheckbox('radiusissueips', hide);
341
	}
342

    
343
	// on-click
344
	$('#mode').click(function () {
345
		setL2TP();
346
	});
347

    
348
	$('#radiusenable').click(function () {
349
		setRADIUS();
350
	});
351

    
352
	// on-page-load
353
	setRADIUS();
354
	setL2TP();
355

    
356
});
357
//]]>
358
</script>
359

    
360
<?php include("foot.inc")?>
(218-218/225)