Project

General

Profile

Download (13.4 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['req128'] = $_POST['req128'] ? true : false;
109
		$pptpcfg['radius']['enable'] = $_POST['radiusenable'] ? true : false;
110
		$pptpcfg['radius']['accounting'] = $_POST['radacct_enable'] ? true : false;
111
		$pptpcfg['radius']['server'] = $_POST['radiusserver'];
112
		$pptpcfg['radius']['secret'] = $_POST['radiussecret'];
113
			
114
		write_config();
115
		
116
		$retval = 0;
117
		
118
		config_lock();
119
		$retval = vpn_pptpd_configure();
120
		config_unlock();
121
		
122
		$savemsg = get_std_save_message($retval);
123
	}
124
}
125

    
126
$pgtitle = "VPN PPTP";
127
include("head.inc");
128

    
129
?>
130

    
131
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
132
<?php include("fbegin.inc"); ?>
133
<p class="pgtitle"><?=$pgtitle?></p>
134
<script language="JavaScript">
135
<!--
136
function get_radio_value(obj)
137
{
138
	for (i = 0; i < obj.length; i++) {
139
		if (obj[i].checked)
140
			return obj[i].value;
141
	}
142
	return null;
143
}
144

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

    
275
                </tr>
276
                <tr> 
277
                  <td width="22%" valign="top" class="vncell">WINS Server</td>
278
                  <td width="78%" valign="top" class="vtable">
279
                      <input name="wins" class="formfld" id="wins" size="20" value="<?=htmlspecialchars($pconfig['wins']);?>">
280
                  </td>
281
                </tr>
282

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