Project

General

Profile

Download (18 KB) Statistics
| Branch: | Tag: | Revision:
1 5656fe23 Ermal Lu?i
<?php
2
/*
3
	vpn_l2tp.php
4
	part of pfSense
5
6
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
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 the
17
	   documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31 047cb829 Ermal Lu?i
##|+PRIV
32
##|*IDENT=page-vpn-vpnl2tp
33
##|*NAME=VPN: VPN L2TP page
34
##|*DESCR=Allow access to the 'VPN: VPN L2TP' page.
35
##|*MATCH=vpn_l2tp.php*
36
##|-PRIV
37
38 5656fe23 Ermal Lu?i
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("L2TP"));
39
40
require("guiconfig.inc");
41 483e6de8 Scott Ullrich
require_once("vpn.inc");
42 5656fe23 Ermal Lu?i
43
if (!is_array($config['l2tp']['radius'])) {
44
	$config['l2tp']['radius'] = array();
45
}
46
$l2tpcfg = &$config['l2tp'];
47
48
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
49
$pconfig['localip'] = $l2tpcfg['localip'];
50 a56120f2 Ermal Lu?i
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
51 5656fe23 Ermal Lu?i
$pconfig['mode'] = $l2tpcfg['mode'];
52
$pconfig['interface'] = $l2tpcfg['interface'];
53
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
54
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
55
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
56
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
57
$pconfig['radiusissueips'] = $l2tpcfg['radius']['radiusissueips'];
58
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
59
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
60 40de0b13 Ermal Lu?i
$pconfig['secret'] = $l2tpcfg['secret'];
61 5656fe23 Ermal Lu?i
62
if ($_POST) {
63
64
	unset($input_errors);
65
	$pconfig = $_POST;
66
67
	/* input validation */
68
	if ($_POST['mode'] == "server") {
69
		$reqdfields = explode(" ", "localip remoteip");
70 346e6203 Rafael Lucas
		$reqdfieldsn = array(gettext("Server address"),gettext("Remote start address"));
71 5656fe23 Ermal Lu?i
72
		if ($_POST['radiusenable']) {
73
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
74
			$reqdfieldsn = array_merge($reqdfieldsn,
75 346e6203 Rafael Lucas
				array(gettext("RADIUS server address"),gettext("RADIUS shared secret")));
76 5656fe23 Ermal Lu?i
		}
77
78
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
79
80
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
81
			$input_errors[] = gettext("A valid server address must be specified.");
82
		}
83 a56120f2 Ermal Lu?i
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
84 5656fe23 Ermal Lu?i
			$input_errors[] = gettext("A valid remote start address must be specified.");
85
		}
86
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
87
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
88
		}
89
90
		/* if this is an AJAX caller then handle via JSON */
91
		if(isAjax() && is_array($input_errors)) {
92
			input_errors2Ajax($input_errors);
93
			exit;
94
		}
95
96
		if (!$input_errors) {
97 a56120f2 Ermal Lu?i
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
98 96033063 Erik Fonnesbeck
			$subnet_start = ip2ulong($_POST['remoteip']);
99
			$subnet_end = ip2ulong($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
100 5656fe23 Ermal Lu?i
101 96033063 Erik Fonnesbeck
			if ((ip2ulong($_POST['localip']) >= $subnet_start) &&
102
			    (ip2ulong($_POST['localip']) <= $subnet_end)) {
103 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
104
			}
105 a55e9c70 Ermal Lu?i
			if ($_POST['localip'] == get_interface_ip("lan")) {
106 5656fe23 Ermal Lu?i
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
107
			}
108
		}
109
	}
110
111
	/* if this is an AJAX caller then handle via JSON */
112
	if(isAjax() && is_array($input_errors)) {
113
		input_errors2Ajax($input_errors);
114
		exit;
115
	}
116
117
	if (!$input_errors) {
118
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
119
		$l2tpcfg['localip'] = $_POST['localip'];
120 a56120f2 Ermal Lu?i
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
121 5656fe23 Ermal Lu?i
		$l2tpcfg['mode'] = $_POST['mode'];
122
		$l2tpcfg['interface'] = $_POST['interface'];
123
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
124
125
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
126
		$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
127 40de0b13 Ermal Lu?i
		$l2tpcfg['secret'] = $_POST['secret'];
128 5656fe23 Ermal Lu?i
129
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
130
131
		if($_POST['radiusenable'] == "yes")
132
			$l2tpcfg['radius']['enable'] = true;
133
		else
134
			unset($l2tpcfg['radius']['enable']);
135
136
		if($_POST['radacct_enable'] == "yes")
137
			$l2tpcfg['radius']['accounting'] = true;
138
		else
139
			unset($l2tpcfg['radius']['accounting']);
140
141
		if($_POST['radiusissueips'] == "yes")
142
			$l2tpcfg['radius']['radiusissueips'] = true;
143
		else
144
			unset($l2tpcfg['radius']['radiusissueips']);
145
146
		write_config();
147
148
		$retval = 0;
149
		$retval = vpn_l2tp_configure();
150
		$savemsg = get_std_save_message($retval);
151
152
		/* if ajax is calling, give them an update message */
153
		if(isAjax())
154
			print_info_box_np($savemsg);
155
	}
156
}
157
158
include("head.inc");
159
?>
160
161
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
162
<?php include("fbegin.inc"); ?>
163
164
<script type="text/javascript">
165
<!--
166
function get_radio_value(obj)
167
{
168
	for (i = 0; i < obj.length; i++) {
169
		if (obj[i].checked)
170
			return obj[i].value;
171
	}
172
	return null;
173
}
174
175
function enable_change(enable_over) {
176
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
177
		document.iform.remoteip.disabled = 0;
178
		document.iform.localip.disabled = 0;
179 a56120f2 Ermal Lu?i
		document.iform.l2tp_subnet.disabled = 0;
180 5656fe23 Ermal Lu?i
		document.iform.radiusenable.disabled = 0;
181
		document.iform.radiusissueips.disabled = 0;
182
		document.iform.paporchap.disabled = 0;
183
		document.iform.interface.disabled = 0;
184
		document.iform.n_l2tp_units.disabled = 0;
185 40de0b13 Ermal Lu?i
		document.iform.secret.disabled = 0;
186 5656fe23 Ermal Lu?i
    /* fix colors */
187
		document.iform.remoteip.style.backgroundColor = '#FFFFFF';
188
		document.iform.localip.style.backgroundColor = '#FFFFFF';
189 a56120f2 Ermal Lu?i
		document.iform.l2tp_subnet.style.backgroundColor = '#FFFFFF';
190 5656fe23 Ermal Lu?i
		document.iform.radiusenable.style.backgroundColor = '#FFFFFF';
191
		document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
192
		document.iform.paporchap.style.backgroundColor = '#FFFFFF';
193
		document.iform.interface.style.backgroundColor = '#FFFFFF';
194
		document.iform.n_l2tp_units.style.backgroundColor = '#FFFFFF';
195 40de0b13 Ermal Lu?i
		document.iform.secret.style.backgroundColor = '#FFFFFF';
196 5656fe23 Ermal Lu?i
		if (document.iform.radiusenable.checked || enable_over) {
197
			document.iform.radacct_enable.disabled = 0;
198
			document.iform.radiusserver.disabled = 0;
199
			document.iform.radiussecret.disabled = 0;
200
			document.iform.radiusissueips.disabled = 0;
201
      /* fix colors */
202
			document.iform.radacct_enable.style.backgroundColor = '#FFFFFF';
203
			document.iform.radiusserver.style.backgroundColor = '#FFFFFF';
204
			document.iform.radiussecret.style.backgroundColor = '#FFFFFF';
205
			document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
206
		} else {
207
			document.iform.radacct_enable.disabled = 1;
208
			document.iform.radiusserver.disabled = 1;
209
			document.iform.radiussecret.disabled = 1;
210
			document.iform.radiusissueips.disabled = 1;
211
      /* fix colors */
212
			document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
213
			document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
214
			document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
215
			document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
216
		}
217
	} else {
218
		document.iform.interface.disabled = 1;
219
		document.iform.n_l2tp_units.disabled = 1;
220 a56120f2 Ermal Lu?i
		document.iform.l2tp_subnet.disabled = 1;
221 5656fe23 Ermal Lu?i
		document.iform.paporchap.disabled = 1;
222
		document.iform.remoteip.disabled = 1;
223
		document.iform.localip.disabled = 1;
224
		document.iform.radiusenable.disabled = 1;
225
		document.iform.radacct_enable.disabled = 1;
226
		document.iform.radiusserver.disabled = 1;
227
		document.iform.radiussecret.disabled = 1;
228
		document.iform.radiusissueips.disabled = 1;
229 40de0b13 Ermal Lu?i
		document.iform.secret.disabled = 1;
230 5656fe23 Ermal Lu?i
    /* fix colors */
231
		document.iform.interface.style.backgroundColor = '#D4D0C8';
232
		document.iform.n_l2tp_units.style.backgroundColor = '#D4D0C8';
233 a56120f2 Ermal Lu?i
		document.iform.l2tp_subnet.style.backgroundColor = '#D4D0C8';
234 5656fe23 Ermal Lu?i
		document.iform.paporchap.style.backgroundColor = '#D4D0C8';
235
		document.iform.remoteip.style.backgroundColor = '#D4D0C8';
236
		document.iform.localip.style.backgroundColor = '#D4D0C8';
237
		document.iform.radiusenable.style.backgroundColor = '#D4D0C8';
238
		document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
239
		document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
240
		document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
241
		document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
242 40de0b13 Ermal Lu?i
		document.iform.secret.style.backgroundColor = '#D4D0C8';
243 5656fe23 Ermal Lu?i
	}
244
}
245
//-->
246
</script>
247
<form action="vpn_l2tp.php" method="post" name="iform" id="iform">
248
<?php if ($input_errors) print_input_errors($input_errors); ?>
249
<?php if ($savemsg) print_info_box($savemsg); ?>
250
<div id="inputerrors"></div>
251
<table width="100%" border="0" cellpadding="0" cellspacing="0">
252
  <tr><td class="tabnavtbl">
253
<?php
254
	$tab_array = array();
255
	$tab_array[0] = array(gettext("Configuration"), true, "vpn_l2tp.php");
256
	$tab_array[1] = array(gettext("Users"), false, "vpn_l2tp_users.php");
257
	display_top_tabs($tab_array);
258
?>
259
  </td></tr>
260
  <tr>
261
    <td>
262
	<div id="mainarea">
263
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
264
                <tr>
265
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
266
                  <td width="78%" class="vtable">
267
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
268
			<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked=\"checked\"";?> />
269 adf32c24 Carlos Eduardo Ramos
                    <?=gettext("Off"); ?></td>
270 5656fe23 Ermal Lu?i
		</tr>
271
                <tr>
272
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
273
                  <td width="78%" class="vtable">
274
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked=\"checked\""; ?> />
275 adf32c24 Carlos Eduardo Ramos
                    <?=gettext("Enable l2tp server"); ?></td>
276 5656fe23 Ermal Lu?i
		</tr>
277
278
                <tr>
279
                  <td width="22%" valign="top" class="vncell"><b><?=gettext("Interface");?></b></td>
280
                  <td width="78%" valign="top" class="vtable">
281
282
			<select name="interface" class="formselect" id="interface">
283
			  <?php
284 6e8bd1b0 Seth Mos
				$interfaces = get_configured_interface_with_descr();
285 5656fe23 Ermal Lu?i
				foreach ($interfaces as $iface => $ifacename):
286
			  ?>
287
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
288
			  <?=htmlspecialchars($ifacename);?>
289
			  </option>
290
			  <?php endforeach; ?>
291
			</select> <br />
292
293
		  </td>
294
                </tr>
295
                <tr>
296
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Server address");?></td>
297
                  <td width="78%" class="vtable">
298
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld unknown" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>" />
299
                    <br />
300 221f5d17 Chris Buechler
                    <?=gettext("Enter the IP address the L2TP server should use on its side for all clients.");?></td>
301 5656fe23 Ermal Lu?i
                </tr>
302
                <tr>
303
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Remote address range");?></td>
304
                  <td width="78%" class="vtable">
305
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld unknown" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>" />
306
                    <br />
307
                    <?=gettext("Specify the starting address for the client IP address subnet.");?><br />
308
                    </td>
309
                </tr>
310 a56120f2 Ermal Lu?i
                <tr>
311 adf32c24 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet netmask"); ?></td>
312 a56120f2 Ermal Lu?i
                  <td width="78%" class="vtable">
313
                    <select id="l2tp_subnet" name="l2tp_subnet">
314
                    <?php
315
                     for($x=0; $x<33; $x++) {
316
                        if($x == $pconfig['l2tp_subnet'])
317
                                $SELECTED = " SELECTED";
318
                        else
319
                                $SELECTED = "";
320
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
321
                     }
322
                    ?>
323
                    </select>
324 ea53e38f Renato Botelho
                    <br><?=gettext("Hint:"); ?> 24 <?=gettext("is"); ?> 255.255.255.0
325 a56120f2 Ermal Lu?i
                  </td>
326
                </tr>
327 5656fe23 Ermal Lu?i
                <tr>
328 adf32c24 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Number of L2TP users"); ?></td>
329 5656fe23 Ermal Lu?i
                  <td width="78%" class="vtable">
330
                    <select id="n_l2tp_units" name="n_l2tp_units">
331
                    <?php
332
                     for($x=0; $x<255; $x++) {
333
                        if($x == $pconfig['n_l2tp_units'])
334
                                $SELECTED = " SELECTED";
335
                        else
336
                                $SELECTED = "";
337
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
338
                     }
339
                    ?>
340
                    </select>
341 ea53e38f Renato Botelho
                    <br><?=gettext("Hint:"); ?> 10 <?=gettext("is ten L2TP clients"); ?>
342 5656fe23 Ermal Lu?i
                  </td>
343
                </tr>
344 40de0b13 Ermal Lu?i
		<tr>
345
                  <td width="22%" valign="top" class="vncell"><?=gettext("Secret");?></td>
346
                  <td width="78%" class="vtable">
347
			<input type="password" name="secret" id="secret" class="formfld pwd" value="<? echo htmlspecialchars($pconfig['secret']); ?>">
348
                    <br />
349
                    <?=gettext("Specify optional secret shared between peers. Required on some devices/setups.");?><br />
350
                    </td>
351
                </tr>
352 5656fe23 Ermal Lu?i
                <tr>
353 8d6dd2e4 Chris Buechler
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption type");?></td>
354 5656fe23 Ermal Lu?i
                  <td width="78%" class="vtable">
355
                    <?=$mandfldhtml;?><select name="paporchap" id="paporchap">
356 adf32c24 Carlos Eduardo Ramos
			<option value='chap'<?php if($pconfig['paporchap'] == "chap") echo " SELECTED"; ?>><?=gettext("CHAP"); ?></option>
357
			<option value='pap'<?php if($pconfig['paporchap'] == "pap") echo " SELECTED"; ?>><?=gettext("PAP"); ?></option>
358 5656fe23 Ermal Lu?i
		    </select>
359
                    <br />
360
                    <?=gettext("Specifies which protocol to use for authentication.");?><br />
361
                    </td>
362
                </tr>
363
                <tr>
364 adf32c24 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS"); ?></td>
365 5656fe23 Ermal Lu?i
                  <td width="78%" class="vtable">
366
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked=\"checked\""; ?> />
367
                      <strong> <?=gettext("Use a RADIUS server for authentication");?><br /></strong>
368
                      <?=gettext("When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.");?><br />
369
                      <br />
370
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked=\"checked\""; ?> />
371
                      <strong><?=gettext("Enable RADIUS accounting");?></strong><br />
372
                      <?=gettext("Sends accounting packets to the RADIUS server.");?></td>
373
                </tr>
374
                <tr>
375
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS server");?></td>
376
                  <td width="78%" class="vtable">
377
                      <input name="radiusserver" type="text" class="formfld unknown" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>" />
378
                      <br />
379
                      <?=gettext("Enter the IP address of the RADIUS server.");?></td>
380
                </tr>
381
                <tr>
382
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS shared secret");?></td>
383
                  <td width="78%" valign="top" class="vtable">
384
                      <input name="radiussecret" type="password" class="formfld pwd" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>" />
385
                      <br />
386
                      <?=gettext("Enter the shared secret that will be used to authenticate to the RADIUS server.");?></td>
387
                </tr>
388
                <tr>
389
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS issued IP's");?></td>
390
                  <td width="78%" valign="top" class="vtable">
391
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if(isset($pconfig['radiusissueips'])) echo " checked=\"checked\""; ?> />
392
                      <br />
393
                      <?=gettext("Issue IP Addresses via RADIUS server.");?>
394
                  </td>
395
                </tr>
396
                <tr>
397
                  <td width="22%" valign="top">&nbsp;</td>
398
                  <td width="78%">
399 adf32c24 Carlos Eduardo Ramos
                    <input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)" />
400 5656fe23 Ermal Lu?i
                  </td>
401
                </tr>
402
                <tr>
403
                  <td colspan="2">
404
			<span class="vexpl">
405 ea53e38f Renato Botelho
				<strong class="red"><?=gettext("Note:");?></strong><br />
406 5656fe23 Ermal Lu?i
				<?=gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients!");?>
407
			</span>
408
                  </td>
409
                </tr>
410
              </table>
411
	   </div>
412
	 </td>
413
	</tr>
414
</table>
415
</form>
416
417
<script type="text/javascript">
418
	enable_change(false);
419
</script>
420
421
<?php include("fend.inc"); ?>
422
</body>
423
</html>