Project

General

Profile

Download (17.6 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
$pgtitle = array(gettext("VPN"), gettext("L2TP"), gettext("L2TP"));
32

    
33
require("guiconfig.inc");
34

    
35
if (!is_array($config['l2tp']['radius'])) {
36
	$config['l2tp']['radius'] = array();
37
}
38
$l2tpcfg = &$config['l2tp'];
39

    
40
$pconfig['remoteip'] = $l2tpcfg['remoteip'];
41
$pconfig['localip'] = $l2tpcfg['localip'];
42
$pconfig['l2tp_subnet'] = $l2tpcfg['l2tp_subnet'];
43
$pconfig['mode'] = $l2tpcfg['mode'];
44
$pconfig['interface'] = $l2tpcfg['interface'];
45
$pconfig['radiusenable'] = isset($l2tpcfg['radius']['enable']);
46
$pconfig['radacct_enable'] = isset($l2tpcfg['radius']['accounting']);
47
$pconfig['radiusserver'] = $l2tpcfg['radius']['server'];
48
$pconfig['radiussecret'] = $l2tpcfg['radius']['secret'];
49
$pconfig['radiusissueips'] = $l2tpcfg['radius']['radiusissueips'];
50
$pconfig['n_l2tp_units'] = $l2tpcfg['n_l2tp_units'];
51
$pconfig['paporchap'] = $l2tpcfg['paporchap'];
52
$pconfig['secret'] = $l2tpcfg['secret'];
53

    
54
if ($_POST) {
55

    
56
	unset($input_errors);
57
	$pconfig = $_POST;
58

    
59
	/* input validation */
60
	if ($_POST['mode'] == "server") {
61
		$reqdfields = explode(" ", "localip remoteip");
62
		$reqdfieldsn = explode(",", "Server address,Remote start address");
63

    
64
		if ($_POST['radiusenable']) {
65
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
66
			$reqdfieldsn = array_merge($reqdfieldsn,
67
				explode(",", "RADIUS server address,RADIUS shared secret"));
68
		}
69

    
70
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
71

    
72
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
73
			$input_errors[] = gettext("A valid server address must be specified.");
74
		}
75
		if (($_POST['l2tp_subnet'] && !is_ipaddr($_POST['remoteip']))) {
76
			$input_errors[] = gettext("A valid remote start address must be specified.");
77
		}
78
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
79
			$input_errors[] = gettext("A valid RADIUS server address must be specified.");
80
		}
81

    
82
		/* if this is an AJAX caller then handle via JSON */
83
		if(isAjax() && is_array($input_errors)) {
84
			input_errors2Ajax($input_errors);
85
			exit;
86
		}
87

    
88
		if (!$input_errors) {
89
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['l2tp_subnet']);
90
			$subnet_start = ip2long($_POST['remoteip']);
91
			$subnet_end = ip2long($_POST['remoteip']) + $_POST['n_l2tp_units'] - 1;
92

    
93
			if ((ip2long($_POST['localip']) >= $subnet_start) &&
94
			    (ip2long($_POST['localip']) <= $subnet_end)) {
95
				$input_errors[] = gettext("The specified server address lies in the remote subnet.");
96
			}
97
			if ($_POST['localip'] == get_interface_ip("lan")) {
98
				$input_errors[] = gettext("The specified server address is equal to the LAN interface address.");
99
			}
100
		}
101
	}
102

    
103
	/* if this is an AJAX caller then handle via JSON */
104
	if(isAjax() && is_array($input_errors)) {
105
		input_errors2Ajax($input_errors);
106
		exit;
107
	}
108

    
109
	if (!$input_errors) {
110
		$l2tpcfg['remoteip'] = $_POST['remoteip'];
111
		$l2tpcfg['localip'] = $_POST['localip'];
112
		$l2tpcfg['l2tp_subnet'] = $_POST['l2tp_subnet'];
113
		$l2tpcfg['mode'] = $_POST['mode'];
114
		$l2tpcfg['interface'] = $_POST['interface'];
115
		$l2tpcfg['n_l2tp_units'] = $_POST['n_l2tp_units'];
116

    
117
		$l2tpcfg['radius']['server'] = $_POST['radiusserver'];
118
		$l2tpcfg['radius']['secret'] = $_POST['radiussecret'];
119
		$l2tpcfg['secret'] = $_POST['secret'];
120

    
121
		$l2tpcfg['paporchap'] = $_POST['paporchap'];
122

    
123
		if($_POST['radiusenable'] == "yes")
124
			$l2tpcfg['radius']['enable'] = true;
125
		else
126
			unset($l2tpcfg['radius']['enable']);
127

    
128
		if($_POST['radacct_enable'] == "yes")
129
			$l2tpcfg['radius']['accounting'] = true;
130
		else
131
			unset($l2tpcfg['radius']['accounting']);
132

    
133
		if($_POST['radiusissueips'] == "yes")
134
			$l2tpcfg['radius']['radiusissueips'] = true;
135
		else
136
			unset($l2tpcfg['radius']['radiusissueips']);
137

    
138
		write_config();
139

    
140
		$retval = 0;
141
		$retval = vpn_l2tp_configure();
142
		$savemsg = get_std_save_message($retval);
143

    
144
		/* if ajax is calling, give them an update message */
145
		if(isAjax())
146
			print_info_box_np($savemsg);
147
	}
148
}
149

    
150
include("head.inc");
151
?>
152

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

    
156
<script type="text/javascript">
157
<!--
158
function get_radio_value(obj)
159
{
160
	for (i = 0; i < obj.length; i++) {
161
		if (obj[i].checked)
162
			return obj[i].value;
163
	}
164
	return null;
165
}
166

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

    
270
                <tr>
271
                  <td width="22%" valign="top" class="vncell"><b><?=gettext("Interface");?></b></td>
272
                  <td width="78%" valign="top" class="vtable">
273

    
274
			<select name="interface" class="formselect" id="interface">
275
			  <?php
276
				$interfaces = get_configured_interface_with_descr();
277
				foreach ($interfaces as $iface => $ifacename):
278
			  ?>
279
			  <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
280
			  <?=htmlspecialchars($ifacename);?>
281
			  </option>
282
			  <?php endforeach; ?>
283
			</select> <br />
284

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

    
409
<script type="text/javascript">
410
	enable_change(false);
411
</script>
412

    
413
<?php include("fend.inc"); ?>
414
</body>
415
</html>
(193-193/206)