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

    
142
		config_lock();
143
		$retval = vpn_l2tp_configure();
144
		config_unlock();
145

    
146
		$savemsg = get_std_save_message($retval);
147

    
148
		/* if ajax is calling, give them an update message */
149
		if(isAjax())
150
			print_info_box_np($savemsg);
151
	}
152
}
153

    
154
include("head.inc");
155
?>
156

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

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

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

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

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

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

    
413
<script type="text/javascript">
414
	enable_change(false);
415
</script>
416

    
417
<?php include("fend.inc"); ?>
418
</body>
419
</html>
(193-193/206)