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
		filter_configure();
125
	}
126
}
127

    
128
$pgtitle = "VPN PPTP";
129
include("head.inc");
130

    
131
?>
132

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

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

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

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