Project

General

Profile

Download (10.2 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-2018 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
init_config_arr(array('l2tp', 'radius'));
33
$l2tpcfg = &$config['l2tp'];
34

    
35
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
36
$pconfig['localip'] = $l2tpcfg['localip'];
37
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
38
$pconfig['mode'] = $l2tpcfg['mode'];
39
$pconfig['interface'] = $l2tpcfg['interface'];
40
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
41
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
42
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
43
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
44
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
45
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
46
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
47
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
48
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
49
$pconfig['secret'] = $l2tpcfg['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 remoteip");
59
		$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
60

    
61
		if ($_POST['radiusenable']) {
62
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
63
			$reqdfieldsn = array_merge($reqdfieldsn,
64
				array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
65
		}
66

    
67
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
68

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

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

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

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

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

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

    
114
	}
115

    
116
	if (!$input_errors) {
117
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
118
		$l2tpcfg['localip'] = $_POST['localip'];
119
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
120
		$l2tpcfg['mode'] = $_POST['mode'];
121
		$l2tpcfg['interface'] = $_POST['interface'];
122
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
123
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
124
		if ($_POST['radiussecret'] != DMYPWD) {
125
			$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
126
		}
127

    
128
		if ($_POST['secret'] != DMYPWD) {
129
			$l2tpcfg['secret'] = $_POST['secret'];
130
		}
131

    
132
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
133

    
134

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

    
143
		if ($_POST['l2tp_dns2'] == "") {
144
			if (isset($l2tpcfg['dns2'])) {
145
				unset($l2tpcfg['dns2']);
146
			}
147
		} else {
148
			$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
149
		}
150

    
151
		if ($_POST['radiusenable'] == "yes") {
152
			$l2tpcfg['radius']['enable'] = true;
153
		} else {
154
			unset($l2tpcfg['radius']['enable']);
155
		}
156

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

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

    
169
		write_config(gettext("L2TP VPN configuration changed."));
170

    
171
		$changes_applied = true;
172
		$retval = 0;
173
		$retval |= vpn_l2tp_configure();
174
	}
175
}
176

    
177
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
178
$pglinks = array("", "@self", "@self");
179
$shortcut_section = "l2tps";
180
include("head.inc");
181

    
182
if ($input_errors) {
183
	print_input_errors($input_errors);
184
}
185

    
186
if ($changes_applied) {
187
	print_apply_result_box($retval);
188
}
189

    
190
$tab_array = array();
191
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
192
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
193
display_top_tabs($tab_array);
194

    
195
$form = new Form();
196

    
197
$section = new Form_Section("Enable L2TP");
198

    
199
$section->addInput(new Form_Checkbox(
200
	'mode',
201
	'Enable',
202
	'Enable L2TP server',
203
	($pconfig['mode'] == "server"),
204
	'server'
205
));
206

    
207
$form->add($section);
208

    
209
$iflist = array();
210
$interfaces = get_configured_interface_with_descr();
211
foreach ($interfaces as $iface => $ifacename) {
212
	$iflist[$iface] = $ifacename;
213
}
214

    
215
$section = new Form_Section("Configuration");
216
$section->addClass('toggle-l2tp-enable');
217

    
218
$section->addInput(new Form_Select(
219
	'interface',
220
	'*Interface',
221
	$pconfig['interface'],
222
	$iflist
223
));
224

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

    
234
$section->addInput(new Form_IpAddress(
235
        'remoteip',
236
        '*Remote address range',
237
        $pconfig['remoteip']
238
))->addMask('l2tp_subnet', $pconfig['l2tp_subnet'])
239
  ->setHelp('Specify the starting address for the client IP address subnet.');
240

    
241
$section->addInput(new Form_Select(
242
	'n_l2tp_units',
243
	'*Number of L2TP users',
244
	$pconfig['n_l2tp_units'],
245
	array_combine(range(1, 255, 1), range(1, 255, 1))
246
));
247

    
248
$section->addPassword(new Form_Input(
249
	'secret',
250
	'Secret',
251
	'password',
252
	$pconfig['secret']
253
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
254

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

    
266
$section->addInput(new Form_Input(
267
	'l2tp_dns1',
268
	'Primary L2TP DNS server',
269
	'text',
270
	$pconfig['l2tp_dns1']
271
));
272

    
273
$section->addInput(new Form_Input(
274
	'l2tp_dns2',
275
	'Secondary L2TP DNS server',
276
	'text',
277
	$pconfig['l2tp_dns2']
278
));
279

    
280
$form->add($section);
281

    
282
$section = new Form_Section("RADIUS");
283
$section->addClass('toggle-l2tp-enable');
284

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

    
292
$section->addInput(new Form_Checkbox(
293
	'radacct_enable',
294
	'Accounting',
295
	'Enable RADIUS accounting',
296
	$pconfig['radacct_enable']
297
))->setHelp('Sends accounting packets to the RADIUS server.');
298

    
299
$section->addInput(new Form_IpAddress(
300
	'radiusserver',
301
	'*Server',
302
	$pconfig['radiusserver']
303
))->setHelp('Enter the IP address of the RADIUS server.');
304

    
305
$section->addPassword(new Form_Input(
306
	'radiussecret',
307
	'*Secret',
308
	'password',
309
	$pconfig['radiussecret']
310
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
311

    
312
$section->addInput(new Form_Checkbox(
313
	'radiusissueips',
314
	'RADIUS issued IPs',
315
	'Issue IP Addresses via RADIUS server.',
316
	$pconfig['radiusissueips']
317
));
318

    
319
$form->add($section);
320

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

    
329
<script type="text/javascript">
330
//<![CDATA[
331
events.push(function() {
332

    
333
	function setL2TP () {
334
		hide = ! $('#mode').prop('checked');
335

    
336
		hideClass('toggle-l2tp-enable', hide);
337
	}
338

    
339
	function setRADIUS () {
340
		hide = ! $('#radiusenable').prop('checked');
341

    
342
		hideCheckbox('radacct_enable', hide);
343
		hideInput('radiusserver', hide);
344
		hideInput('radiussecret', hide);
345
		hideCheckbox('radiusissueips', hide);
346
	}
347

    
348
	// on-click
349
	$('#mode').click(function () {
350
		setL2TP();
351
	});
352

    
353
	$('#radiusenable').click(function () {
354
		setRADIUS();
355
	});
356

    
357
	// on-page-load
358
	setRADIUS();
359
	setL2TP();
360

    
361
});
362
//]]>
363
</script>
364

    
365
<?php include("foot.inc")?>
(227-227/234)