Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_pptp.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
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
require("guiconfig.inc");
32

    
33
if (!is_array($config['pptpd']['radius'])) {
34
	$config['pptpd']['radius'] = array();
35
}
36
$pptpcfg = &$config['pptpd'];
37

    
38
$pconfig['remoteip'] = $pptpcfg['remoteip'];
39
$pconfig['localip'] = $pptpcfg['localip'];
40
$pconfig['redir'] = $pptpcfg['redir'];
41
$pconfig['mode'] = $pptpcfg['mode'];
42
$pconfig['wins'] = $pptpcfg['wins'];
43
$pconfig['req128'] = isset($pptpcfg['req128']);
44
$pconfig['radiusenable'] = isset($pptpcfg['radius']['enable']);
45
$pconfig['radacct_enable'] = isset($pptpcfg['radius']['accounting']);
46
$pconfig['radiusserver'] = $pptpcfg['radius']['server'];
47
$pconfig['radiussecret'] = $pptpcfg['radius']['secret'];
48

    
49
if ($_POST) {
50

    
51
	unset($input_errors);
52
	$pconfig = $_POST;
53

    
54
	/* input validation */
55
	if ($_POST['mode'] == "server") {
56
		$reqdfields = explode(" ", "localip remoteip");
57
		$reqdfieldsn = explode(",", "Server address,Remote start address");
58
		
59
		if ($_POST['radiusenable']) {
60
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
61
			$reqdfieldsn = array_merge($reqdfieldsn, 
62
				explode(",", "RADIUS server address,RADIUS shared secret"));
63
		}
64
		
65
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
66
		
67
		if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) {
68
			$input_errors[] = "A valid server address must be specified.";
69
		}
70
		if (($_POST['subnet'] && !is_ipaddr($_POST['remoteip']))) {
71
			$input_errors[] = "A valid remote start address must be specified.";
72
		}
73
		if (($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver']))) {
74
			$input_errors[] = "A valid RADIUS server address must be specified.";
75
		}
76
		
77
		if (!$input_errors) {	
78
			$_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $g['pptp_subnet']);
79
			$subnet_start = ip2long($_POST['remoteip']);
80
			$subnet_end = ip2long($_POST['remoteip']) + $g['n_pptp_units'] - 1;
81
						
82
			if ((ip2long($_POST['localip']) >= $subnet_start) && 
83
			    (ip2long($_POST['localip']) <= $subnet_end)) {
84
				$input_errors[] = "The specified server address lies in the remote subnet.";	
85
			}
86
			if ($_POST['localip'] == $config['interfaces']['lan']['ipaddr']) {
87
				$input_errors[] = "The specified server address is equal to the LAN interface address.";	
88
			}
89
		}
90
	} else if ($_POST['mode'] == "redir") {
91
		$reqdfields = explode(" ", "redir");
92
		$reqdfieldsn = explode(",", "PPTP redirection target address");
93
		
94
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95
		
96
		if (($_POST['redir'] && !is_ipaddr($_POST['redir']))) {
97
			$input_errors[] = "A valid target address must be specified.";
98
		}
99
	} else {
100
		/* turning pptp off, lets dump any custom rules */
101
		$rules = &$config['filter']['rule'];
102
		for($x=0; $x<count($rules); $x++) {
103
			if($rules[$x]['interface'] == "pptp") { 
104
				unset($rules[$x]);
105
			}
106
		}
107
		unset($config['pptpd']['mode']);
108
		write_config();
109
	}
110

    
111
	if (!$input_errors) {
112
		$pptpcfg['remoteip'] = $_POST['remoteip'];
113
		$pptpcfg['redir'] = $_POST['redir'];
114
		$pptpcfg['localip'] = $_POST['localip'];
115
		$pptpcfg['mode'] = $_POST['mode'];
116
		$pptpcfg['wins'] = $_POST['wins'];
117
		$pptpcfg['radius']['server'] = $_POST['radiusserver'];
118
		$pptpcfg['radius']['secret'] = $_POST['radiussecret'];
119

    
120
		if($_POST['req128'] == "yes") 
121
			$pptpcfg['req128'] = true;
122
		else
123
			unset($pptpcfg['req128']);
124

    
125
		if($_POST['radiusenable'] == "yes") 
126
			$pptpcfg['radius']['enable'] = true;
127
		else 
128
			unset($pptpcfg['radius']['enable']);
129
			
130
		if($_POST['radacct_enable'] == "yes") 
131
			$pptpcfg['radius']['accounting'] = true;
132
		else 
133
			unset($pptpcfg['radius']['accounting']);
134
		
135
		write_config();
136
		
137
		$retval = 0;
138
		
139
		config_lock();
140
		$retval = vpn_setup();
141
		config_unlock();
142
		
143
		$savemsg = get_std_save_message($retval);
144
		
145
		filter_configure();
146
	}
147
}
148

    
149
$pgtitle = "VPN PPTP";
150
include("head.inc");
151

    
152
?>
153

    
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155
<?php include("fbegin.inc"); ?>
156
<p class="pgtitle"><?=$pgtitle?></p>
157
<script language="JavaScript">
158
<!--
159
function get_radio_value(obj)
160
{
161
	for (i = 0; i < obj.length; i++) {
162
		if (obj[i].checked)
163
			return obj[i].value;
164
	}
165
	return null;
166
}
167

    
168
function enable_change(enable_over) {
169
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
170
		document.iform.remoteip.disabled = 0;
171
		document.iform.localip.disabled = 0;
172
		document.iform.req128.disabled = 0;
173
		document.iform.radiusenable.disabled = 0;
174
		document.iform.wins.disabled = 0;
175
		
176
		if (document.iform.radiusenable.checked || enable_over) {
177
			document.iform.radacct_enable.disabled = 0;
178
			document.iform.radiusserver.disabled = 0;
179
			document.iform.radiussecret.disabled = 0;
180
		} else {
181
			document.iform.radacct_enable.disabled = 1;
182
			document.iform.radiusserver.disabled = 1;
183
			document.iform.radiussecret.disabled = 1;
184
		}
185
	} else {
186
		document.iform.remoteip.disabled = 1;
187
		document.iform.localip.disabled = 1;
188
		document.iform.req128.disabled = 1;
189
		document.iform.radiusenable.disabled = 1;
190
		document.iform.radacct_enable.disabled = 1;
191
		document.iform.radiusserver.disabled = 1;
192
		document.iform.radiussecret.disabled = 1;
193
		document.iform.wins.disabled = 1;
194
	}
195
	if ((get_radio_value(document.iform.mode) == "redir") || enable_over) {
196
		document.iform.redir.disabled = 0;
197
	} else {
198
		document.iform.redir.disabled = 1;
199
	}
200
}
201
//-->
202
</script>
203
<form action="vpn_pptp.php" method="post" name="iform" id="iform">
204
<?php if ($input_errors) print_input_errors($input_errors); ?>
205
<?php if ($savemsg) print_info_box($savemsg); ?>
206
<table width="100%" border="0" cellpadding="0" cellspacing="0">
207
  <tr><td class="tabnavtbl">
208
<?php
209
	$tab_array = array();
210
	$tab_array[0] = array("Configuration", true, "vpn_pptp.php");
211
	$tab_array[1] = array("Users", false, "vpn_pptp_users.php");
212
	display_top_tabs($tab_array);
213
?>  
214
  </td></tr>
215
  <tr> 
216
    <td>
217
<div id="mainarea">
218
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
219
                <tr> 
220
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
221
                  <td width="78%" class="vtable"> 
222
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
223
				  	<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked";?>>
224
                    Off</td>
225
                <tr> 
226
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
227
                  <td width="78%" class="vtable">
228
<input type="radio" name="mode" value="redir" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "redir") echo "checked"; ?>>
229
                    Redirect incoming PPTP connections to:</td>
230
                <tr> 
231
                  <td width="22%" valign="top" class="vncellreq">PPTP redirection</td>
232
                  <td width="78%" class="vtable"> 
233
                    <?=$mandfldhtml;?><input name="redir" type="text" class="formfld" id="redir" size="20" value="<?=htmlspecialchars($pconfig['redir']);?>"> 
234
                    <br>
235
                    Enter the IP address of a host which will accept incoming 
236
                    PPTP connections.</td>
237
                <tr> 
238
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
239
                  <td width="78%" class="vtable">
240
<input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
241
                    Enable PPTP server</td>
242
                <tr> 
243
                  <td width="22%" valign="top" class="vncellreq">Max. concurrent 
244
                    connections</td>
245
                  <td width="78%" class="vtable"> 
246
                    <?=$g['n_pptp_units'];?>
247
                  </td>
248
                <tr> 
249
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
250
                  <td width="78%" class="vtable"> 
251
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
252
                    <br>
253
                    Enter the IP address the PPTP server should use on its side 
254
                    for all clients.</td>
255
                </tr>
256
                <tr> 
257
                  <td width="22%" valign="top" class="vncellreq">Remote address 
258
                    range</td>
259
                  <td width="78%" class="vtable"> 
260
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
261
                    / 
262
                    <?=$g['pptp_subnet'];?>
263
                    <br>
264
                    Specify the starting address for the client IP address subnet.<br>
265
                    The PPTP server will assign 
266
                    <?=$g['n_pptp_units'];?>
267
                    addresses, starting at the address entered above, to clients.</td>
268
                </tr>
269
                <tr> 
270
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
271
                  <td width="78%" class="vtable"> 
272
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
273
                      <strong>Use a RADIUS server for authentication<br>
274
                      </strong>When set, all users will be authenticated using 
275
                      the RADIUS server specified below. The local user database 
276
                      will not be used.<br>
277
                      <br>
278
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
279
                      <strong>Enable RADIUS accounting <br>
280
                      </strong>Sends accounting packets to the RADIUS server.</td>
281
                </tr>
282
                <tr> 
283
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
284
                  <td width="78%" class="vtable">
285
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
286
                      <br>
287
                      Enter the IP address of the RADIUS server.</td>
288
                </tr>
289
                <tr> 
290
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
291
                  <td width="78%" valign="top" class="vtable">
292
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
293
                      <br>
294
                      Enter the shared secret that will be used to authenticate 
295
                      to the RADIUS server.</td>
296
                </tr>
297

    
298
                </tr>
299
                <tr> 
300
                  <td width="22%" valign="top" class="vncell">WINS Server</td>
301
                  <td width="78%" valign="top" class="vtable">
302
                      <input name="wins" class="formfld" id="wins" size="20" value="<?=htmlspecialchars($pconfig['wins']);?>">
303
                  </td>
304
                </tr>
305

    
306
                <tr> 
307
                  <td height="16" colspan="2" valign="top"></td>
308
                </tr>
309
                <tr> 
310
                  <td width="22%" valign="middle">&nbsp;</td>
311
                  <td width="78%" class="vtable"> 
312
                    <input name="req128" type="checkbox" id="req128" value="yes" <?php if ($pconfig['req128']) echo "checked"; ?>> 
313
                    <strong>Require 128-bit encryption</strong><br>
314
                    When set, 128-bit encryption will be accepted. Otherwise, 
315
                    40-bit and 56-bit encryption will be accepted, too. Note that 
316
                    encryption will always be forced on PPTP connections (i.e. 
317
                    unencrypted connections will not be accepted).</td>
318
                </tr>
319
                <tr> 
320
                  <td width="22%" valign="top">&nbsp;</td>
321
                  <td width="78%"> 
322
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
323
                  </td>
324
                </tr>
325
                <tr> 
326
                  <td width="22%" valign="top">&nbsp;</td>
327
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
328
                    </strong></span>don't forget to <a href="firewall_rules.php?if=pptp">add a firewall rule</a> to permit 
329
                    traffic from PPTP clients!</span></td>
330
                </tr>
331
              </table>
332
</div>
333
			</td>
334
	</tr>
335
</table>
336
</form>
337
<script language="JavaScript">
338
<!--
339
enable_change(false);
340
//-->
341
</script>
342
<?php include("fend.inc"); ?>
343
</body>
344
</html>
(160-160/164)