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
|
$changes_applied = true;
|
163
|
$retval = 0;
|
164
|
$retval |= vpn_l2tp_configure();
|
165
|
}
|
166
|
}
|
167
|
|
168
|
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("Configuration"));
|
169
|
$pglinks = array("", "@self", "@self");
|
170
|
$shortcut_section = "l2tps";
|
171
|
include("head.inc");
|
172
|
|
173
|
if ($input_errors) {
|
174
|
print_input_errors($input_errors);
|
175
|
}
|
176
|
|
177
|
if ($changes_applied) {
|
178
|
print_apply_result_box($retval);
|
179
|
}
|
180
|
|
181
|
$tab_array = array();
|
182
|
$tab_array[] = array(gettext("Configuration"), true, "vpn_l2tp.php");
|
183
|
$tab_array[] = array(gettext("Users"), false, "vpn_l2tp_users.php");
|
184
|
display_top_tabs($tab_array);
|
185
|
|
186
|
$form = new Form();
|
187
|
|
188
|
$section = new Form_Section("Enable L2TP");
|
189
|
|
190
|
$section->addInput(new Form_Checkbox(
|
191
|
'mode',
|
192
|
'Enable',
|
193
|
'Enable L2TP server',
|
194
|
($pconfig['mode'] == "server"),
|
195
|
'server'
|
196
|
));
|
197
|
|
198
|
$form->add($section);
|
199
|
|
200
|
$iflist = array();
|
201
|
$interfaces = get_configured_interface_with_descr();
|
202
|
foreach ($interfaces as $iface => $ifacename) {
|
203
|
$iflist[$iface] = $ifacename;
|
204
|
}
|
205
|
|
206
|
$section = new Form_Section("Configuration");
|
207
|
$section->addClass('toggle-l2tp-enable');
|
208
|
|
209
|
$section->addInput(new Form_Select(
|
210
|
'interface',
|
211
|
'*Interface',
|
212
|
$pconfig['interface'],
|
213
|
$iflist
|
214
|
));
|
215
|
|
216
|
$section->addInput(new Form_Input(
|
217
|
'localip',
|
218
|
'*Server address',
|
219
|
'text',
|
220
|
$pconfig['localip']
|
221
|
))->setHelp('Enter the IP address the L2TP server should give to clients for use as their "gateway". ' . '<br />' .
|
222
|
'Typically this is set to an unused IP just outside of the client range.' . '<br /><br />' .
|
223
|
'NOTE: This should NOT be set to any IP address currently in use on this firewall.');
|
224
|
|
225
|
$section->addInput(new Form_IpAddress(
|
226
|
'remoteip',
|
227
|
'*Remote address range',
|
228
|
$pconfig['remoteip']
|
229
|
))->addMask(l2tp_subnet, $pconfig['l2tp_subnet'])
|
230
|
->setHelp('Specify the starting address for the client IP address subnet.');
|
231
|
|
232
|
$section->addInput(new Form_Select(
|
233
|
'n_l2tp_units',
|
234
|
'*Number of L2TP users',
|
235
|
$pconfig['n_l2tp_units'],
|
236
|
array_combine(range(1, 255, 1), range(1, 255, 1))
|
237
|
));
|
238
|
|
239
|
$section->addPassword(new Form_Input(
|
240
|
'secret',
|
241
|
'Secret',
|
242
|
'password',
|
243
|
$pconfig['secret']
|
244
|
))->setHelp('Specify optional secret shared between peers. Required on some devices/setups.');
|
245
|
|
246
|
$section->addInput(new Form_Select(
|
247
|
'paporchap',
|
248
|
'*Authentication type',
|
249
|
$pconfig['paporchap'],
|
250
|
array(
|
251
|
'chap' => 'CHAP',
|
252
|
'chap-msv2' => 'MS-CHAPv2',
|
253
|
'pap' => 'PAP'
|
254
|
)
|
255
|
))->setHelp('Specifies the protocol to use for authentication.');
|
256
|
|
257
|
$section->addInput(new Form_Input(
|
258
|
'l2tp_dns1',
|
259
|
'Primary L2TP DNS server',
|
260
|
'text',
|
261
|
$pconfig['l2tp_dns1']
|
262
|
));
|
263
|
|
264
|
$section->addInput(new Form_Input(
|
265
|
'l2tp_dns2',
|
266
|
'Secondary L2TP DNS server',
|
267
|
'text',
|
268
|
$pconfig['l2tp_dns2']
|
269
|
));
|
270
|
|
271
|
$form->add($section);
|
272
|
|
273
|
$section = new Form_Section("RADIUS");
|
274
|
$section->addClass('toggle-l2tp-enable');
|
275
|
|
276
|
$section->addInput(new Form_Checkbox(
|
277
|
'radiusenable',
|
278
|
'Enable',
|
279
|
'Use a RADIUS server for authentication',
|
280
|
$pconfig['radiusenable']
|
281
|
))->setHelp('When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.');
|
282
|
|
283
|
$section->addInput(new Form_Checkbox(
|
284
|
'radacct_enable',
|
285
|
'Accounting',
|
286
|
'Enable RADIUS accounting',
|
287
|
$pconfig['radacct_enable']
|
288
|
))->setHelp('Sends accounting packets to the RADIUS server.');
|
289
|
|
290
|
$section->addInput(new Form_IpAddress(
|
291
|
'radiusserver',
|
292
|
'*Server',
|
293
|
$pconfig['radiusserver']
|
294
|
))->setHelp('Enter the IP address of the RADIUS server.');
|
295
|
|
296
|
$section->addPassword(new Form_Input(
|
297
|
'radiussecret',
|
298
|
'*Secret',
|
299
|
'password',
|
300
|
$pconfig['radiussecret']
|
301
|
))->setHelp('Enter the shared secret that will be used to authenticate to the RADIUS server.');
|
302
|
|
303
|
$section->addInput(new Form_Checkbox(
|
304
|
'radiusissueips',
|
305
|
'RADIUS issued IPs',
|
306
|
'Issue IP Addresses via RADIUS server.',
|
307
|
$pconfig['radiusissueips']
|
308
|
));
|
309
|
|
310
|
$form->add($section);
|
311
|
|
312
|
print($form);
|
313
|
?>
|
314
|
<div class="infoblock blockopen">
|
315
|
<?php
|
316
|
print_info_box(gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients."), 'info', false);
|
317
|
?>
|
318
|
</div>
|
319
|
|
320
|
<script type="text/javascript">
|
321
|
//<![CDATA[
|
322
|
events.push(function() {
|
323
|
|
324
|
function setL2TP () {
|
325
|
hide = ! $('#mode').prop('checked');
|
326
|
|
327
|
hideClass('toggle-l2tp-enable', hide);
|
328
|
}
|
329
|
|
330
|
function setRADIUS () {
|
331
|
hide = ! $('#radiusenable').prop('checked');
|
332
|
|
333
|
hideCheckbox('radacct_enable', hide);
|
334
|
hideInput('radiusserver', hide);
|
335
|
hideInput('radiussecret', hide);
|
336
|
hideCheckbox('radiusissueips', hide);
|
337
|
}
|
338
|
|
339
|
// on-click
|
340
|
$('#mode').click(function () {
|
341
|
setL2TP();
|
342
|
});
|
343
|
|
344
|
$('#radiusenable').click(function () {
|
345
|
setRADIUS();
|
346
|
});
|
347
|
|
348
|
// on-page-load
|
349
|
setRADIUS();
|
350
|
setL2TP();
|
351
|
|
352
|
});
|
353
|
//]]>
|
354
|
</script>
|
355
|
|
356
|
<?php include("foot.inc")?>
|