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
|
* Redistribution and use in source and binary forms, with or without
|
10
|
* modification, are permitted provided that the following conditions are met:
|
11
|
*
|
12
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13
|
* this list of conditions and the following disclaimer.
|
14
|
*
|
15
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
* notice, this list of conditions and the following disclaimer in
|
17
|
* the documentation and/or other materials provided with the
|
18
|
* distribution.
|
19
|
*
|
20
|
* 3. All advertising materials mentioning features or use of this software
|
21
|
* must display the following acknowledgment:
|
22
|
* "This product includes software developed by the pfSense Project
|
23
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
24
|
*
|
25
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26
|
* endorse or promote products derived from this software without
|
27
|
* prior written permission. For written permission, please contact
|
28
|
* coreteam@pfsense.org.
|
29
|
*
|
30
|
* 5. Products derived from this software may not be called "pfSense"
|
31
|
* nor may "pfSense" appear in their names without prior written
|
32
|
* permission of the Electric Sheep Fencing, LLC.
|
33
|
*
|
34
|
* 6. Redistributions of any form whatsoever must retain the following
|
35
|
* acknowledgment:
|
36
|
*
|
37
|
* "This product includes software developed by the pfSense Project
|
38
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39
|
*
|
40
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52
|
*/
|
53
|
|
54
|
##|+PRIV
|
55
|
##|*IDENT=page-vpn-vpnl2tp
|
56
|
##|*NAME=VPN: L2TP
|
57
|
##|*DESCR=Allow access to the 'VPN: L2TP' page.
|
58
|
##|*MATCH=vpn_l2tp.php*
|
59
|
##|-PRIV
|
60
|
|
61
|
require_once("guiconfig.inc");
|
62
|
require_once("vpn.inc");
|
63
|
|
64
|
if (!is_array($config['l2tp']['radius'])) {
|
65
|
$config['l2tp']['radius'] = array();
|
66
|
}
|
67
|
$l2tpcfg = &$config['l2tp'];
|
68
|
|
69
|
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
|
70
|
$pconfig['localip'] = $l2tpcfg['localip'];
|
71
|
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
|
72
|
$pconfig['mode'] = $l2tpcfg['mode'];
|
73
|
$pconfig['interface'] = $l2tpcfg['interface'];
|
74
|
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
|
75
|
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
|
76
|
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
|
77
|
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
|
78
|
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
|
79
|
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
|
80
|
$pconfig['radiusissueips'] = isset($l2tpcfg['radius']['radiusissueips']);
|
81
|
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
|
82
|
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
|
83
|
$pconfig['secret'] = $l2tpcfg['secret'];
|
84
|
|
85
|
if ($_POST) {
|
86
|
|
87
|
unset($input_errors);
|
88
|
$pconfig = $_POST;
|
89
|
|
90
|
/* input validation */
|
91
|
if ($_POST['mode'] == "server") {
|
92
|
$reqdfields = explode(" ", "localip remoteip");
|
93
|
$reqdfieldsn = array(gettext("Server address"), gettext("Remote start address"));
|
94
|
|
95
|
if ($_POST['radiusenable']) {
|
96
|
$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
|
97
|
$reqdfieldsn = array_merge($reqdfieldsn,
|
98
|
array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
|
99
|
}
|
100
|
|
101
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
102
|
|
103
|
if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
|
104
|
$input_errors[] = gettext("A valid server address must be specified.");
|
105
|
}
|
106
|
if (is_ipaddr_configured($_POST['localip'])) {
|
107
|
$input_errors[] = gettext("'Server address' parameter should NOT be set to any IP address currently in use on this firewall.");
|
108
|
}
|
109
|
if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
|
110
|
$input_errors[] = gettext("A valid remote start address must be specified.");
|
111
|
}
|
112
|
if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
|
113
|
$input_errors[] = gettext("A valid RADIUS server address must be specified.");
|
114
|
}
|
115
|
|
116
|
if ($_POST['secret'] != $_POST['secret_confirm']) {
|
117
|
$input_errors[] = gettext("Secret and confirmation must match");
|
118
|
}
|
119
|
|
120
|
if ($_POST['radiussecret'] != $_POST['radiussecret_confirm']) {
|
121
|
$input_errors[] = gettext("RADIUS secret and confirmation must match");
|
122
|
}
|
123
|
|
124
|
if (!is_numericint($_POST['n_l2tp_units']) || $_POST['n_l2tp_units'] > 255) {
|
125
|
$input_errors[] = gettext("Number of L2TP users must be between 1 and 255");
|
126
|
}
|
127
|
|
128
|
if (!$input_errors) {
|
129
|
$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
|
130
|
if (is_inrange_v4($_POST['localip'], $_POST['remoteip'], ip_after($_POST['remoteip'], $_POST['n_l2tp_units'] - 1))) {
|
131
|
$input_errors[] = gettext("The specified server address lies in the remote subnet.");
|
132
|
}
|
133
|
if ($_POST['localip'] == get_interface_ip("lan")) {
|
134
|
$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if (!$input_errors) {
|
140
|
$l2tpcfg['remoteip'] = $_POST['remoteip'];
|
141
|
$l2tpcfg['localip'] = $_POST['localip'];
|
142
|
$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
|
143
|
$l2tpcfg['mode'] = $_POST['mode'];
|
144
|
$l2tpcfg['interface'] = $_POST['interface'];
|
145
|
$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
|
146
|
$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
|
147
|
if ($_POST['radiussecret'] != DMYPWD) {
|
148
|
$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
|
149
|
}
|
150
|
|
151
|
if ($_POST['secret'] != DMYPWD) {
|
152
|
$l2tpcfg['secret'] = $_POST['secret'];
|
153
|
}
|
154
|
|
155
|
$l2tpcfg['paporchap'] = $_POST['paporchap'];
|
156
|
|
157
|
|
158
|
if ($_POST['l2tp_dns1'] == "") {
|
159
|
if (isset($l2tpcfg['dns1'])) {
|
160
|
unset($l2tpcfg['dns1']);
|
161
|
}
|
162
|
} else {
|
163
|
$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
|
164
|
}
|
165
|
|
166
|
if ($_POST['l2tp_dns2'] == "") {
|
167
|
if (isset($l2tpcfg['dns2'])) {
|
168
|
unset($l2tpcfg['dns2']);
|
169
|
}
|
170
|
} else {
|
171
|
$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
|
172
|
}
|
173
|
|
174
|
if ($_POST['radiusenable'] == "yes") {
|
175
|
$l2tpcfg['radius']['enable'] = true;
|
176
|
} else {
|
177
|
unset($l2tpcfg['radius']['enable']);
|
178
|
}
|
179
|
|
180
|
if ($_POST['radacct_enable'] == "yes") {
|
181
|
$l2tpcfg['radius']['accounting'] = true;
|
182
|
} else {
|
183
|
unset($l2tpcfg['radius']['accounting']);
|
184
|
}
|
185
|
|
186
|
if ($_POST['radiusissueips'] == "yes") {
|
187
|
$l2tpcfg['radius']['radiusissueips'] = true;
|
188
|
} else {
|
189
|
unset($l2tpcfg['radius']['radiusissueips']);
|
190
|
}
|
191
|
|
192
|
write_config();
|
193
|
|
194
|
$retval = 0;
|
195
|
$retval = vpn_l2tp_configure();
|
196
|
$savemsg = get_std_save_message($retval);
|
197
|
|
198
|
/* if ajax is calling, give them an update message */
|
199
|
if (isAjax()) {
|
200
|
print_info_box($savemsg, 'success');
|
201
|
}
|
202
|
}
|
203
|
}
|
204
|
|
205
|
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
|
206
|
$shortcut_section = "l2tps";
|
207
|
include("head.inc");
|
208
|
|
209
|
if ($input_errors) {
|
210
|
print_input_errors($input_errors);
|
211
|
}
|
212
|
|
213
|
if ($savemsg) {
|
214
|
print_info_box($savemsg, 'success');
|
215
|
}
|
216
|
|
217
|
$tab_array = array();
|
218
|
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
|
219
|
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
|
220
|
display_top_tabs($tab_array);
|
221
|
|
222
|
$form = new Form();
|
223
|
|
224
|
$section = new Form_Section("Enable L2TP");
|
225
|
|
226
|
$section->addInput(new Form_Checkbox(
|
227
|
'mode',
|
228
|
'Enable',
|
229
|
'Enable L2TP server',
|
230
|
($pconfig['mode'] == "server"),
|
231
|
'server'
|
232
|
));
|
233
|
|
234
|
$form->add($section);
|
235
|
|
236
|
$iflist = array();
|
237
|
$interfaces = get_configured_interface_with_descr();
|
238
|
foreach ($interfaces as $iface => $ifacename) {
|
239
|
$iflist[$iface] = $ifacename;
|
240
|
}
|
241
|
|
242
|
$section = new Form_Section("Configuration");
|
243
|
$section->addClass('toggle-l2tp-enable');
|
244
|
|
245
|
$section->addInput(new Form_Select(
|
246
|
'interface',
|
247
|
'Interface',
|
248
|
$pconfig['interface'],
|
249
|
$iflist
|
250
|
));
|
251
|
|
252
|
$section->addInput(new Form_Input(
|
253
|
'localip',
|
254
|
'Server address',
|
255
|
'text',
|
256
|
$pconfig['localip']
|
257
|
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
|
258
|
'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
|
259
|
'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
|
260
|
|
261
|
$section->addInput(new Form_IpAddress(
|
262
|
'remoteip',
|
263
|
'Remote address range',
|
264
|
$pconfig['remoteip']
|
265
|
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
|
266
|
->setHelp('Specify the starting address for the client IP address subnet.');
|
267
|
|
268
|
$section->addInput(new Form_Select(
|
269
|
'n_l2tp_units',
|
270
|
'Number of L2TP users',
|
271
|
$pconfig['n_l2tp_units'],
|
272
|
array_combine(range(1, 255, 1), range(1, 255, 1))
|
273
|
));
|
274
|
|
275
|
$section->addPassword(new Form_Input(
|
276
|
'secret',
|
277
|
'Secret',
|
278
|
'password',
|
279
|
$pconfig['secret']
|
280
|
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
|
281
|
|
282
|
$section->addInput(new Form_Select(
|
283
|
'paporchap',
|
284
|
'Authentication type',
|
285
|
$pconfig['paporchap'],
|
286
|
array(
|
287
|
'chap' => 'CHAP',
|
288
|
'chap-msv2' => 'MS-CHAPv2',
|
289
|
'pap' => 'PAP'
|
290
|
)
|
291
|
))->setHelp('Specifies the protocol to use for authentication.');
|
292
|
|
293
|
$section->addInput(new Form_Input(
|
294
|
'l2tp_dns1',
|
295
|
'Primary L2TP DNS server',
|
296
|
'text',
|
297
|
$pconfig['l2tp_dns1']
|
298
|
));
|
299
|
|
300
|
$section->addInput(new Form_Input(
|
301
|
'l2tp_dns2',
|
302
|
'Secondary L2TP DNS server',
|
303
|
'text',
|
304
|
$pconfig['l2tp_dns2']
|
305
|
));
|
306
|
|
307
|
$form->add($section);
|
308
|
|
309
|
$section = new Form_Section("RADIUS");
|
310
|
$section->addClass('toggle-l2tp-enable');
|
311
|
|
312
|
$section->addInput(new Form_Checkbox(
|
313
|
'radiusenable',
|
314
|
'Enable',
|
315
|
'Use a RADIUS server for authentication',
|
316
|
$pconfig['radiusenable']
|
317
|
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
|
318
|
|
319
|
$section->addInput(new Form_Checkbox(
|
320
|
'radacct_enable',
|
321
|
'Accounting',
|
322
|
'Enable RADIUS accounting',
|
323
|
$pconfig['radacct_enable']
|
324
|
))->setHelp('Sends accounting packets to the RADIUS server.');
|
325
|
|
326
|
$section->addInput(new Form_IpAddress(
|
327
|
'radiusserver',
|
328
|
'Server',
|
329
|
$pconfig['radiusserver']
|
330
|
))->setHelp('Enter the IP address of the RADIUS server.');
|
331
|
|
332
|
$section->addPassword(new Form_Input(
|
333
|
'radiussecret',
|
334
|
'Secret',
|
335
|
'password',
|
336
|
$pconfig['radiussecret']
|
337
|
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
|
338
|
|
339
|
$section->addInput(new Form_Checkbox(
|
340
|
'radiusissueips',
|
341
|
'RADIUS issued IPs',
|
342
|
'Issue IP Addresses via RADIUS server.',
|
343
|
$pconfig['radiusissueips']
|
344
|
));
|
345
|
|
346
|
$form->add($section);
|
347
|
|
348
|
print($form);
|
349
|
?>
|
350
|
<div class="infoblock blockopen">
|
351
|
<?php
|
352
|
print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
|
353
|
?>
|
354
|
</div>
|
355
|
|
356
|
<script type="text/javascript">
|
357
|
//<![CDATA[
|
358
|
events.push(function() {
|
359
|
|
360
|
function setL2TP () {
|
361
|
hide = ! $('#mode').prop('checked');
|
362
|
|
363
|
hideClass('toggle-l2tp-enable', hide);
|
364
|
}
|
365
|
|
366
|
function setRADIUS () {
|
367
|
hide = ! $('#radiusenable').prop('checked');
|
368
|
|
369
|
hideCheckbox('radacct_enable', hide);
|
370
|
hideInput('radiusserver', hide);
|
371
|
hideInput('radiussecret', hide);
|
372
|
hideCheckbox('radiusissueips', hide);
|
373
|
}
|
374
|
|
375
|
// on-click
|
376
|
$('#mode').click(function () {
|
377
|
setL2TP();
|
378
|
});
|
379
|
|
380
|
$('#radiusenable').click(function () {
|
381
|
setRADIUS();
|
382
|
});
|
383
|
|
384
|
// on-page-load
|
385
|
setRADIUS();
|
386
|
setL2TP();
|
387
|
|
388
|
});
|
389
|
//]]>
|
390
|
</script>
|
391
|
|
392
|
<?php include("foot.inc")?>
|