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
	}
100

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

    
110
		if($_POST['req128'] == "yes") 
111
			$pptpcfg['req128'] = true;
112
		else
113
			unset($pptpcfg['req128']);
114

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

    
139
$pgtitle = "VPN PPTP";
140
include("head.inc");
141

    
142
?>
143

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

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

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

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