Project

General

Profile

Download (19.5 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

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

    
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
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
51
$pconfig['mode'] = $l2tpcfg['mode'];
52
$pconfig['interface'] = $l2tpcfg['interface'];
53
$pconfig['l2tp_dns1'] = $l2tpcfg['dns1'];
54
$pconfig['l2tp_dns2'] = $l2tpcfg['dns2'];
55
$pconfig['wins'] = $l2tpcfg['wins'];
56
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
57
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
58
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
59
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
60
$pconfig['radiusissueips'] = $l2tpcfg['radius']['radiusissueips'];
61
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
62
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
63
$pconfig['secret'] = $l2tpcfg['secret'];
64

    
65
if ($_POST) {
66

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

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

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

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

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

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

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

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

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

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

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

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

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

    
139

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

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

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

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

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

    
167
		write_config();
168

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

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

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

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

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

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

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

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

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

    
458
<script type="text/javascript">
459
	enable_change(false);
460
</script>
461

    
462
<?php include("fend.inc"); ?>
463
</body>
464
</html>
(213-213/225)