Project

General

Profile

Download (17.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

    
40
require("guiconfig.inc");
41

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

    
47
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
48
$pconfig['localip'] = $l2tpcfg['localip'];
49
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
50
$pconfig['mode'] = $l2tpcfg['mode'];
51
$pconfig['interface'] = $l2tpcfg['interface'];
52
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
53
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
54
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
55
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
56
$pconfig['radiusissueips'] = $l2tpcfg['radius']['radiusissueips'];
57
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
58
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
59
$pconfig['secret'] = $l2tpcfg['secret'];
60

    
61
if ($_POST) {
62

    
63
	unset($input_errors);
64
	$pconfig = $_POST;
65

    
66
	/* input validation */
67
	if ($_POST['mode'] == "server") {
68
		$reqdfields = explode(" ", "localip remoteip");
69
		$reqdfieldsn = explode(",", "Server address,Remote start address");
70

    
71
		if ($_POST['radiusenable']) {
72
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
73
			$reqdfieldsn = array_merge($reqdfieldsn,
74
				explode(",", "RADIUS server address,RADIUS shared secret"));
75
		}
76

    
77
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
78

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

    
89
		/* if this is an AJAX caller then handle via JSON */
90
		if(isAjax() && is_array($input_errors)) {
91
			input_errors2Ajax($input_errors);
92
			exit;
93
		}
94

    
95
		if (!$input_errors) {
96
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
97
			$subnet_start = ip2long($_POST['remoteip']);
98
			$subnet_end = ip2long($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
99

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

    
110
	/* if this is an AJAX caller then handle via JSON */
111
	if(isAjax() && is_array($input_errors)) {
112
		input_errors2Ajax($input_errors);
113
		exit;
114
	}
115

    
116
	if (!$input_errors) {
117
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
118
		$l2tpcfg['localip'] = $_POST['localip'];
119
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
120
		$l2tpcfg['mode'] = $_POST['mode'];
121
		$l2tpcfg['interface'] = $_POST['interface'];
122
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
123

    
124
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
125
		$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
126
		$l2tpcfg['secret'] = $_POST['secret'];
127

    
128
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
129

    
130
		if($_POST['radiusenable'] == "yes")
131
			$l2tpcfg['radius']['enable'] = true;
132
		else
133
			unset($l2tpcfg['radius']['enable']);
134

    
135
		if($_POST['radacct_enable'] == "yes")
136
			$l2tpcfg['radius']['accounting'] = true;
137
		else
138
			unset($l2tpcfg['radius']['accounting']);
139

    
140
		if($_POST['radiusissueips'] == "yes")
141
			$l2tpcfg['radius']['radiusissueips'] = true;
142
		else
143
			unset($l2tpcfg['radius']['radiusissueips']);
144

    
145
		write_config();
146

    
147
		$retval = 0;
148
		$retval = vpn_l2tp_configure();
149
		$savemsg = get_std_save_message($retval);
150

    
151
		/* if ajax is calling, give them an update message */
152
		if(isAjax())
153
			print_info_box_np($savemsg);
154
	}
155
}
156

    
157
include("head.inc");
158
?>
159

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

    
163
<script type="text/javascript">
164
<!--
165
function get_radio_value(obj)
166
{
167
	for (i = 0; i < obj.length; i++) {
168
		if (obj[i].checked)
169
			return obj[i].value;
170
	}
171
	return null;
172
}
173

    
174
function enable_change(enable_over) {
175
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
176
		document.iform.remoteip.disabled = 0;
177
		document.iform.localip.disabled = 0;
178
		document.iform.l2tp_subnet.disabled = 0;
179
		document.iform.radiusenable.disabled = 0;
180
		document.iform.radiusissueips.disabled = 0;
181
		document.iform.paporchap.disabled = 0;
182
		document.iform.interface.disabled = 0;
183
		document.iform.n_l2tp_units.disabled = 0;
184
		document.iform.secret.disabled = 0;
185
    /* fix colors */
186
		document.iform.remoteip.style.backgroundColor = '#FFFFFF';
187
		document.iform.localip.style.backgroundColor = '#FFFFFF';
188
		document.iform.l2tp_subnet.style.backgroundColor = '#FFFFFF';
189
		document.iform.radiusenable.style.backgroundColor = '#FFFFFF';
190
		document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
191
		document.iform.paporchap.style.backgroundColor = '#FFFFFF';
192
		document.iform.interface.style.backgroundColor = '#FFFFFF';
193
		document.iform.n_l2tp_units.style.backgroundColor = '#FFFFFF';
194
		document.iform.secret.style.backgroundColor = '#FFFFFF';
195
		if (document.iform.radiusenable.checked || enable_over) {
196
			document.iform.radacct_enable.disabled = 0;
197
			document.iform.radiusserver.disabled = 0;
198
			document.iform.radiussecret.disabled = 0;
199
			document.iform.radiusissueips.disabled = 0;
200
      /* fix colors */
201
			document.iform.radacct_enable.style.backgroundColor = '#FFFFFF';
202
			document.iform.radiusserver.style.backgroundColor = '#FFFFFF';
203
			document.iform.radiussecret.style.backgroundColor = '#FFFFFF';
204
			document.iform.radiusissueips.style.backgroundColor = '#FFFFFF';
205
		} else {
206
			document.iform.radacct_enable.disabled = 1;
207
			document.iform.radiusserver.disabled = 1;
208
			document.iform.radiussecret.disabled = 1;
209
			document.iform.radiusissueips.disabled = 1;
210
      /* fix colors */
211
			document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
212
			document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
213
			document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
214
			document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
215
		}
216
	} else {
217
		document.iform.interface.disabled = 1;
218
		document.iform.n_l2tp_units.disabled = 1;
219
		document.iform.l2tp_subnet.disabled = 1;
220
		document.iform.paporchap.disabled = 1;
221
		document.iform.remoteip.disabled = 1;
222
		document.iform.localip.disabled = 1;
223
		document.iform.radiusenable.disabled = 1;
224
		document.iform.radacct_enable.disabled = 1;
225
		document.iform.radiusserver.disabled = 1;
226
		document.iform.radiussecret.disabled = 1;
227
		document.iform.radiusissueips.disabled = 1;
228
		document.iform.secret.disabled = 1;
229
    /* fix colors */
230
		document.iform.interface.style.backgroundColor = '#D4D0C8';
231
		document.iform.n_l2tp_units.style.backgroundColor = '#D4D0C8';
232
		document.iform.l2tp_subnet.style.backgroundColor = '#D4D0C8';
233
		document.iform.paporchap.style.backgroundColor = '#D4D0C8';
234
		document.iform.remoteip.style.backgroundColor = '#D4D0C8';
235
		document.iform.localip.style.backgroundColor = '#D4D0C8';
236
		document.iform.radiusenable.style.backgroundColor = '#D4D0C8';
237
		document.iform.radacct_enable.style.backgroundColor = '#D4D0C8';
238
		document.iform.radiusserver.style.backgroundColor = '#D4D0C8';
239
		document.iform.radiussecret.style.backgroundColor = '#D4D0C8';
240
		document.iform.radiusissueips.style.backgroundColor = '#D4D0C8';
241
		document.iform.secret.style.backgroundColor = '#D4D0C8';
242
	}
243
}
244
//-->
245
</script>
246
<form action="vpn_l2tp.php" method="post" name="iform" id="iform">
247
<?php if ($input_errors) print_input_errors($input_errors); ?>
248
<?php if ($savemsg) print_info_box($savemsg); ?>
249
<div id="inputerrors"></div>
250
<table width="100%" border="0" cellpadding="0" cellspacing="0">
251
  <tr><td class="tabnavtbl">
252
<?php
253
	$tab_array = array();
254
	$tab_array[0] = array(gettext("Configuration"), true, "vpn_l2tp.php");
255
	$tab_array[1] = array(gettext("Users"), false, "vpn_l2tp_users.php");
256
	display_top_tabs($tab_array);
257
?>
258
  </td></tr>
259
  <tr>
260
    <td>
261
	<div id="mainarea">
262
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
263
                <tr>
264
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
265
                  <td width="78%" class="vtable">
266
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
267
			<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked=\"checked\"";?> />
268
                    Off</td>
269
		</tr>
270
                <tr>
271
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
272
                  <td width="78%" class="vtable">
273
		    <input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked=\"checked\""; ?> />
274
                    Enable l2tp server</td>
275
		</tr>
276

    
277
                <tr>
278
                  <td width="22%" valign="top" class="vncell"><b><?=gettext("Interface");?></b></td>
279
                  <td width="78%" valign="top" class="vtable">
280

    
281
			<select name="interface" class="formselect" id="interface">
282
			  <?php
283
				$interfaces = get_configured_interface_with_descr();
284
				foreach ($interfaces as $iface => $ifacename):
285
			  ?>
286
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
287
			  <?=htmlspecialchars($ifacename);?>
288
			  </option>
289
			  <?php endforeach; ?>
290
			</select> <br />
291

    
292
		  </td>
293
                </tr>
294
                <tr>
295
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Server address");?></td>
296
                  <td width="78%" class="vtable">
297
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld unknown" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>" />
298
                    <br />
299
                    <?=gettext("Enter the IP address the l2tp server should use on its side for all clients.");?></td>
300
                </tr>
301
                <tr>
302
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Remote address range");?></td>
303
                  <td width="78%" class="vtable">
304
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld unknown" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>" />
305
                    <br />
306
                    <?=gettext("Specify the starting address for the client IP address subnet.");?><br />
307
                    </td>
308
                </tr>
309
                <tr>
310
                  <td width="22%" valign="top" class="vncellreq">Subnet netmask</td>
311
                  <td width="78%" class="vtable">
312
                    <select id="l2tp_subnet" name="l2tp_subnet">
313
                    <?php
314
                     for($x=0; $x<33; $x++) {
315
                        if($x == $pconfig['l2tp_subnet'])
316
                                $SELECTED = " SELECTED";
317
                        else
318
                                $SELECTED = "";
319
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
320
                     }
321
                    ?>
322
                    </select>
323
                    <br>Hint: 24 is 255.255.255.0
324
                  </td>
325
                </tr>
326
                <tr>
327
                  <td width="22%" valign="top" class="vncellreq">No. L2TP users</td>
328
                  <td width="78%" class="vtable">
329
                    <select id="n_l2tp_units" name="n_l2tp_units">
330
                    <?php
331
                     for($x=0; $x<255; $x++) {
332
                        if($x == $pconfig['n_l2tp_units'])
333
                                $SELECTED = " SELECTED";
334
                        else
335
                                $SELECTED = "";
336
                        echo "<option value=\"{$x}\"{$SELECTED}>{$x}</option>\n";
337
                     }
338
                    ?>
339
                    </select>
340
                    <br>Hint: 10 is TEN l2tp clients
341
                  </td>
342
                </tr>
343
		<tr>
344
                  <td width="22%" valign="top" class="vncell"><?=gettext("Secret");?></td>
345
                  <td width="78%" class="vtable">
346
			<input type="password" name="secret" id="secret" class="formfld pwd" value="<? echo htmlspecialchars($pconfig['secret']); ?>">
347
                    <br />
348
                    <?=gettext("Specify optional secret shared between peers. Required on some devices/setups.");?><br />
349
                    </td>
350
                </tr>
351
                <tr>
352
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Encyrption type");?></td>
353
                  <td width="78%" class="vtable">
354
                    <?=$mandfldhtml;?><select name="paporchap" id="paporchap">
355
			<option value='chap'<?php if($pconfig['paporchap'] == "chap") echo " SELECTED"; ?>>CHAP</option>
356
			<option value='pap'<?php if($pconfig['paporchap'] == "pap") echo " SELECTED"; ?>>PAP</option>
357
		    </select>
358
                    <br />
359
                    <?=gettext("Specifies which protocol to use for authentication.");?><br />
360
                    </td>
361
                </tr>
362
                <tr>
363
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
364
                  <td width="78%" class="vtable">
365
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked=\"checked\""; ?> />
366
                      <strong> <?=gettext("Use a RADIUS server for authentication");?><br /></strong>
367
                      <?=gettext("When set, all users will be authenticated using the RADIUS server specified below. The local user database will not be used.");?><br />
368
                      <br />
369
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked=\"checked\""; ?> />
370
                      <strong><?=gettext("Enable RADIUS accounting");?></strong><br />
371
                      <?=gettext("Sends accounting packets to the RADIUS server.");?></td>
372
                </tr>
373
                <tr>
374
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS server");?></td>
375
                  <td width="78%" class="vtable">
376
                      <input name="radiusserver" type="text" class="formfld unknown" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>" />
377
                      <br />
378
                      <?=gettext("Enter the IP address of the RADIUS server.");?></td>
379
                </tr>
380
                <tr>
381
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS shared secret");?></td>
382
                  <td width="78%" valign="top" class="vtable">
383
                      <input name="radiussecret" type="password" class="formfld pwd" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>" />
384
                      <br />
385
                      <?=gettext("Enter the shared secret that will be used to authenticate to the RADIUS server.");?></td>
386
                </tr>
387
                <tr>
388
                  <td width="22%" valign="top" class="vncell"><?=gettext("RADIUS issued IP's");?></td>
389
                  <td width="78%" valign="top" class="vtable">
390
                      <input name="radiusissueips" value="yes" type="checkbox" class="formfld" id="radiusissueips"<?php if(isset($pconfig['radiusissueips'])) echo " checked=\"checked\""; ?> />
391
                      <br />
392
                      <?=gettext("Issue IP Addresses via RADIUS server.");?>
393
                  </td>
394
                </tr>
395
                <tr>
396
                  <td width="22%" valign="top">&nbsp;</td>
397
                  <td width="78%">
398
                    <input id="submit" name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)" />
399
                  </td>
400
                </tr>
401
                <tr>
402
                  <td colspan="2">
403
			<span class="vexpl">
404
				<strong class="red"><?=gettext("Note");?>:</strong><br />
405
				<?=gettext("Don't forget to add a firewall rule to permit traffic from L2TP clients!");?>
406
			</span>
407
                  </td>
408
                </tr>
409
              </table>
410
	   </div>
411
	 </td>
412
	</tr>
413
</table>
414
</form>
415

    
416
<script type="text/javascript">
417
	enable_change(false);
418
</script>
419

    
420
<?php include("fend.inc"); ?>
421
</body>
422
</html>
(205-205/218)