Project

General

Profile

Download (13.6 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
		unset($config['pptpd']['mode']);
101
		write_config();
102
	}
103

    
104
	if (!$input_errors) {
105
		$pptpcfg['remoteip'] = $_POST['remoteip'];
106
		$pptpcfg['redir'] = $_POST['redir'];
107
		$pptpcfg['localip'] = $_POST['localip'];
108
		$pptpcfg['mode'] = $_POST['mode'];
109
		$pptpcfg['wins'] = $_POST['wins'];
110
		$pptpcfg['radius']['server'] = $_POST['radiusserver'];
111
		$pptpcfg['radius']['secret'] = $_POST['radiussecret'];
112

    
113
		if($_POST['req128'] == "yes") 
114
			$pptpcfg['req128'] = true;
115
		else
116
			unset($pptpcfg['req128']);
117

    
118
		if($_POST['radiusenable'] == "yes") 
119
			$pptpcfg['radius']['enable'] = true;
120
		else 
121
			unset($pptpcfg['radius']['enable']);
122
			
123
		if($_POST['radacct_enable'] == "yes") 
124
			$pptpcfg['radius']['accounting'] = true;
125
		else 
126
			unset($pptpcfg['radius']['accounting']);
127
		
128
		write_config();
129
		
130
		$retval = 0;
131
		
132
		config_lock();
133
		$retval = vpn_setup();
134
		config_unlock();
135
		
136
		$savemsg = get_std_save_message($retval);
137
		
138
		filter_configure();
139
	}
140
}
141

    
142
$pgtitle = "VPN PPTP";
143
include("head.inc");
144

    
145
?>
146

    
147
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
148
<?php include("fbegin.inc"); ?>
149
<p class="pgtitle"><?=$pgtitle?></p>
150
<script language="JavaScript">
151
<!--
152
function get_radio_value(obj)
153
{
154
	for (i = 0; i < obj.length; i++) {
155
		if (obj[i].checked)
156
			return obj[i].value;
157
	}
158
	return null;
159
}
160

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

    
291
                </tr>
292
                <tr> 
293
                  <td width="22%" valign="top" class="vncell">WINS Server</td>
294
                  <td width="78%" valign="top" class="vtable">
295
                      <input name="wins" class="formfld" id="wins" size="20" value="<?=htmlspecialchars($pconfig['wins']);?>">
296
                  </td>
297
                </tr>
298

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