Project

General

Profile

Download (19.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
##|+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
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("L2TP"));
39
$shortcut_section = "l2tps";
40

    
41
require("guiconfig.inc");
42
require_once("vpn.inc");
43

    
44
if (!is_array($config['l2tp']['radius'])) {
45
	$config['l2tp']['radius'] = array();
46
}
47
$l2tpcfg = &$config['l2tp'];
48

    
49
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
50
$pconfig['localip'] = $l2tpcfg['localip'];
51
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
52
$pconfig['mode'] = $l2tpcfg['mode'];
53
$pconfig['interface'] = $l2tpcfg['interface'];
54
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
55
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
56
$pconfig['wins'] = $l2tpcfg['wins'];
57
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
58
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
59
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
60
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
61
$pconfig['radiusissueips'] = $l2tpcfg['radius']['radiusissueips'];
62
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
63
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
64
$pconfig['secret'] = $l2tpcfg['secret'];
65

    
66
if ($_POST) {
67

    
68
	unset($input_errors);
69
	$pconfig = $_POST;
70

    
71
	/* input validation */
72
	if ($_POST['mode'] == "server") {
73
		$reqdfields = explode(" ", "localip remoteip");
74
		$reqdfieldsn = array(gettext("Server address"),gettext("Remote start address"));
75

    
76
		if ($_POST['radiusenable']) {
77
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
78
			$reqdfieldsn = array_merge($reqdfieldsn,
79
				array(gettext("RADIUS server address"),gettext("RADIUS shared secret")));
80
		}
81

    
82
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83

    
84
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
85
			$input_errors[] = gettext("A valid server address must be specified.");
86
		}
87
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
88
			$input_errors[] = gettext("A valid remote start address must be specified.");
89
		}
90
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
91
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
92
		}
93

    
94
		/* if this is an AJAX caller then handle via JSON */
95
		if(isAjax() && is_array($input_errors)) {
96
			input_errors2Ajax($input_errors);
97
			exit;
98
		}
99

    
100
		if (!$input_errors) {
101
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
102
			$subnet_start = ip2ulong($_POST['remoteip']);
103
			$subnet_end = ip2ulong($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
104

    
105
			if ((ip2ulong($_POST['localip']) >= $subnet_start) &&
106
			    (ip2ulong($_POST['localip']) <= $subnet_end)) {
107
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
108
			}
109
			if ($_POST['localip'] == get_interface_ip("lan")) {
110
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
111
			}
112
		}
113
	}
114

    
115
	/* if this is an AJAX caller then handle via JSON */
116
	if(isAjax() && is_array($input_errors)) {
117
		input_errors2Ajax($input_errors);
118
		exit;
119
	}
120

    
121
	if (!$input_errors) {
122
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
123
		$l2tpcfg['localip'] = $_POST['localip'];
124
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
125
		$l2tpcfg['mode'] = $_POST['mode'];
126
		$l2tpcfg['interface'] = $_POST['interface'];
127
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
128

    
129
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
130
		$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
131
		$l2tpcfg['secret'] = $_POST['secret'];
132

    
133
		if($_POST['wins'])
134
			$l2tpcfg['wins'] = $_POST['wins'];
135
		else
136
			unset($l2tpcfg['wins']);
137

    
138
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
139

    
140

    
141
		if ($_POST['l2tp_dns1'] == "") {
142
			if (isset($l2tpcfg['dns1']))
143
				unset($l2tpcfg['dns1']);
144
			} else
145
				$l2tpcfg['dns1'] = $_POST['l2tp_dns1'];
146

    
147
			if ($_POST['l2tp_dns2'] == "") {
148
				if (isset($l2tpcfg['dns2']))
149
					unset($l2tpcfg['dns2']);
150
			} else
151
				$l2tpcfg['dns2'] = $_POST['l2tp_dns2'];
152

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

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

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

    
168
		write_config();
169

    
170
		$retval = 0;
171
		$retval = vpn_l2tp_configure();
172
		$savemsg = get_std_save_message($retval);
173

    
174
		/* if ajax is calling, give them an update message */
175
		if(isAjax())
176
			print_info_box_np($savemsg);
177
	}
178
}
179

    
180
include("head.inc");
181
?>
182

    
183
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
184
<?php include("fbegin.inc"); ?>
185

    
186
<script type="text/javascript">
187
<!--
188
function get_radio_value(obj)
189
{
190
	for (i = 0; i < obj.length; i++) {
191
		if (obj[i].checked)
192
			return obj[i].value;
193
	}
194
	return null;
195
}
196

    
197
function enable_change(enable_over) {
198
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
199
		document.iform.remoteip.disabled = 0;
200
		document.iform.localip.disabled = 0;
201
		document.iform.l2tp_subnet.disabled = 0;
202
		document.iform.radiusenable.disabled = 0;
203
		document.iform.radiusissueips.disabled = 0;
204
		document.iform.paporchap.disabled = 0;
205
		document.iform.interface.disabled = 0;
206
		document.iform.n_l2tp_units.disabled = 0;
207
		document.iform.secret.disabled = 0;
208
		document.iform.l2tp_dns1.disabled = 0;
209
		document.iform.l2tp_dns2.disabled = 0;
210
    /* fix colors */
211
		document.iform.remoteip.style.backgroundColor = '#FFFFFF';
212
		document.iform.localip.style.backgroundColor = '#FFFFFF';
213
		document.iform.l2tp_subnet.style.backgroundColor = '#FFFFFF';
214
		document.iform.radiusenable.style.backgroundColor = '#FFFFFF';
215
		document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
216
		document.iform.paporchap.style.backgroundColor = '#FFFFFF';
217
		document.iform.interface.style.backgroundColor = '#FFFFFF';
218
		document.iform.n_l2tp_units.style.backgroundColor = '#FFFFFF';
219
		document.iform.secret.style.backgroundColor = '#FFFFFF';
220
		if (document.iform.radiusenable.checked || enable_over) {
221
			document.iform.radacct_enable.disabled = 0;
222
			document.iform.radiusserver.disabled = 0;
223
			document.iform.radiussecret.disabled = 0;
224
			document.iform.radiusissueips.disabled = 0;
225
      /* fix colors */
226
			document.iform.radacct_enable.style.backgroundColor = '#FFFFFF';
227
			document.iform.radiusserver.style.backgroundColor = '#FFFFFF';
228
			document.iform.radiussecret.style.backgroundColor = '#FFFFFF';
229
			document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
230
		} else {
231
			document.iform.radacct_enable.disabled = 1;
232
			document.iform.radiusserver.disabled = 1;
233
			document.iform.radiussecret.disabled = 1;
234
			document.iform.radiusissueips.disabled = 1;
235
      /* fix colors */
236
			document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
237
			document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
238
			document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
239
			document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
240
		}
241
	} else {
242
		document.iform.interface.disabled = 1;
243
		document.iform.n_l2tp_units.disabled = 1;
244
		document.iform.l2tp_subnet.disabled = 1;
245
		document.iform.l2tp_dns1.disabled = 1;
246
		document.iform.l2tp_dns2.disabled = 1;
247
		document.iform.paporchap.disabled = 1;
248
		document.iform.remoteip.disabled = 1;
249
		document.iform.localip.disabled = 1;
250
		document.iform.radiusenable.disabled = 1;
251
		document.iform.radacct_enable.disabled = 1;
252
		document.iform.radiusserver.disabled = 1;
253
		document.iform.radiussecret.disabled = 1;
254
		document.iform.radiusissueips.disabled = 1;
255
		document.iform.secret.disabled = 1;
256
    /* fix colors */
257
		document.iform.interface.style.backgroundColor = '#D4D0C8';
258
		document.iform.n_l2tp_units.style.backgroundColor = '#D4D0C8';
259
		document.iform.l2tp_subnet.style.backgroundColor = '#D4D0C8';
260
		document.iform.paporchap.style.backgroundColor = '#D4D0C8';
261
		document.iform.remoteip.style.backgroundColor = '#D4D0C8';
262
		document.iform.localip.style.backgroundColor = '#D4D0C8';
263
		document.iform.radiusenable.style.backgroundColor = '#D4D0C8';
264
		document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
265
		document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
266
		document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
267
		document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
268
		document.iform.secret.style.backgroundColor = '#D4D0C8';
269
	}
270
}
271
//-->
272
</script>
273
<form action="vpn_l2tp.php" method="post" name="iform" id="iform">
274
<?php if ($input_errors) print_input_errors($input_errors); ?>
275
<?php if ($savemsg) print_info_box($savemsg); ?>
276
<div id="inputerrors"></div>
277
<table width="100%" border="0" cellpadding="0" cellspacing="0">
278
  <tr><td class="tabnavtbl">
279
<?php
280
	$tab_array = array();
281
	$tab_array[0] = array(gettext("Configuration"), true, "vpn_l2tp.php");
282
	$tab_array[1] = array(gettext("Users"), false, "vpn_l2tp_users.php");
283
	display_top_tabs($tab_array);
284
?>
285
  </td></tr>
286
  <tr>
287
    <td>
288
	<div id="mainarea">
289
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
290
                <tr>
291
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
292
                  <td width="78%" class="vtable">
293
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
294
			<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked=\"checked\"";?> />
295
                    <?=gettext("Off"); ?></td>
296
		</tr>
297
                <tr>
298
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
299
                  <td width="78%" class="vtable">
300
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked=\"checked\""; ?> />
301
                    <?=gettext("Enable L2TP server"); ?></td>
302
		</tr>
303

    
304
                <tr>
305
                  <td width="22%" valign="top" class="vncell"><b><?=gettext("Interface");?></b></td>
306
                  <td width="78%" valign="top" class="vtable">
307

    
308
			<select name="interface" class="formselect" id="interface">
309
			  <?php
310
				$interfaces = get_configured_interface_with_descr();
311
				foreach ($interfaces as $iface => $ifacename):
312
			  ?>
313
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
314
			  <?=htmlspecialchars($ifacename);?>
315
			  </option>
316
			  <?php endforeach; ?>
317
			</select> <br />
318

    
319
		  </td>
320
                </tr>
321
                <tr>
322
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Server Address");?></td>
323
                  <td width="78%" class="vtable">
324
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld unknown" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>" />
325
			<br/>
326
			<?=gettext("Enter the IP address the L2TP server should give to clients for use as their \"gateway\""); ?>.
327
			<br/>
328
			<?=gettext("Typically this is set to an unused IP just outside of the client range"); ?>.
329
			<br/>
330
			<br/>
331
			<?=gettext("NOTE: This should NOT be set to any IP address currently in use on this firewall"); ?>.</td>
332
                </tr>
333
                <tr>
334
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Remote Address Range");?></td>
335
                  <td width="78%" class="vtable">
336
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld unknown" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>" />
337
                    <br />
338
                    <?=gettext("Specify the starting address for the client IP address subnet.");?><br />
339
                    </td>
340
                </tr>
341
                <tr>
342
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet Mask"); ?></td>
343
                  <td width="78%" class="vtable">
344
                    <select id="l2tp_subnet" name="l2tp_subnet">
345
                    <?php
346
                     for($x=0; $x<33; $x++) {
347
                        if($x == $pconfig['l2tp_subnet'])
348
                                $SELECTED = " SELECTED";
349
                        else
350
                                $SELECTED = "";
351
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
352
                     }
353
                    ?>
354
                    </select>
355
                    <br><?=gettext("Hint:"); ?> 24 <?=gettext("is"); ?> 255.255.255.0
356
                  </td>
357
                </tr>
358
                <tr>
359
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Number of L2TP users"); ?></td>
360
                  <td width="78%" class="vtable">
361
                    <select id="n_l2tp_units" name="n_l2tp_units">
362
                    <?php
363
                     for($x=0; $x<255; $x++) {
364
                        if($x == $pconfig['n_l2tp_units'])
365
                                $SELECTED = " SELECTED";
366
                        else
367
                                $SELECTED = "";
368
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
369
                     }
370
                    ?>
371
                    </select>
372
                    <br><?=gettext("Hint:"); ?> 10 <?=gettext("is ten L2TP clients"); ?>
373
                  </td>
374
                </tr>
375
		<tr>
376
                  <td width="22%" valign="top" class="vncell"><?=gettext("Secret");?></td>
377
                  <td width="78%" class="vtable">
378
			<input type="password" name="secret" id="secret" class="formfld pwd" value="<? echo htmlspecialchars($pconfig['secret']); ?>">
379
                    <br />
380
                    <?=gettext("Specify optional secret shared between peers. Required on some devices/setups.");?><br />
381
                    </td>
382
                </tr>
383
                <tr>
384
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication Type");?></td>
385
                  <td width="78%" class="vtable">
386
                    <?=$mandfldhtml;?><select name="paporchap" id="paporchap">
387
			<option value='chap'<?php if($pconfig['paporchap'] == "chap") echo " SELECTED"; ?>><?=gettext("CHAP"); ?></option>
388
			<option value='pap'<?php if($pconfig['paporchap'] == "pap") echo " SELECTED"; ?>><?=gettext("PAP"); ?></option>
389
		    </select>
390
                    <br />
391
                    <?=gettext("Specifies which protocol to use for authentication.");?><br />
392
                    </td>
393
                </tr>
394
		<tr>
395
		  <td width="22%" valign="top" class="vncell"><?=gettext("L2TP DNS Servers"); ?></td>
396
		  <td width="78%" class="vtable">
397
		    <?=$mandfldhtml;?><input name="l2tp_dns1" type="text" class="formfld unknown" id="l2tp_dns1" size="20" value="<?=htmlspecialchars($pconfig['l2tp_dns1']);?>">
398
		   	<br>
399
				<input name="l2tp_dns2" type="text" class="formfld unknown" id="l2tp_dns2" size="20" value="<?=htmlspecialchars($pconfig['l2tp_dns2']);?>">
400
			<br>
401
		   <?=gettext("primary and secondary DNS servers assigned to L2TP clients"); ?><br>
402
		  </td>
403
		</tr>
404
		<tr>
405
		  <td width="22%" valign="top" class="vncell"><?=gettext("WINS Server"); ?></td>
406
		  <td width="78%" valign="top" class="vtable">
407
		      <input name="wins" class="formfld unknown" id="wins" size="20" value="<?=htmlspecialchars($pconfig['wins']);?>">
408
		  </td>
409
		</tr>
410
                <tr>
411
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS"); ?></td>
412
                  <td width="78%" class="vtable">
413
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked=\"checked\""; ?> />
414
                      <strong> <?=gettext("Use a RADIUS server for authentication");?><br /></strong>
415
                      <?=gettext("When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.");?><br />
416
                      <br />
417
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked=\"checked\""; ?> />
418
                      <strong><?=gettext("Enable RADIUS accounting");?></strong><br />
419
                      <?=gettext("Sends accounting packets to the RADIUS server.");?></td>
420
                </tr>
421
                <tr>
422
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS Server");?></td>
423
                  <td width="78%" class="vtable">
424
                      <input name="radiusserver" type="text" class="formfld unknown" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>" />
425
                      <br />
426
                      <?=gettext("Enter the IP address of the RADIUS server.");?></td>
427
                </tr>
428
                <tr>
429
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS Shared Secret");?></td>
430
                  <td width="78%" valign="top" class="vtable">
431
                      <input name="radiussecret" type="password" class="formfld pwd" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>" />
432
                      <br />
433
                      <?=gettext("Enter the shared secret that will be used to authenticate to the RADIUS server.");?></td>
434
                </tr>
435
                <tr>
436
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS Issued IP's");?></td>
437
                  <td width="78%" valign="top" class="vtable">
438
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if(isset($pconfig['radiusissueips'])) echo " checked=\"checked\""; ?> />
439
                      <br />
440
                      <?=gettext("Issue IP Addresses via RADIUS server.");?>
441
                  </td>
442
                </tr>
443
                <tr>
444
                  <td width="22%" valign="top">&nbsp;</td>
445
                  <td width="78%">
446
                    <input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)" />
447
                  </td>
448
                </tr>
449
                <tr>
450
                  <td colspan="2">
451
			<span class="vexpl">
452
				<strong class="red"><?=gettext("Note:");?></strong><br />
453
				<?=gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients!");?>
454
			</span>
455
                  </td>
456
                </tr>
457
              </table>
458
	   </div>
459
	 </td>
460
	</tr>
461
</table>
462
</form>
463

    
464
<script type="text/javascript">
465
	enable_change(false);
466
</script>
467

    
468
<?php include("fend.inc"); ?>
469
</body>
470
</html>
(236-236/248)