Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	vpn_pptp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

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

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

    
50
if ($_POST) {
51

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

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

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

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

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

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

    
143
?>
144

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

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

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

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