Project

General

Profile

Download (12.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3
/*
4
	vpn_pptp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 e2411886 Scott Ullrich
	
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8 5b237745 Scott Ullrich
	All rights reserved.
9 e2411886 Scott Ullrich
	
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 e2411886 Scott Ullrich
	
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 e2411886 Scott Ullrich
	
16 5b237745 Scott Ullrich
	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 e2411886 Scott Ullrich
	
20 5b237745 Scott Ullrich
	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['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 e2411886 Scott Ullrich
		
59 5b237745 Scott Ullrich
		if ($_POST['radiusenable']) {
60
			$reqdfields = array_merge($reqdfields, explode(" ", "radiusserver radiussecret"));
61 e2411886 Scott Ullrich
			$reqdfieldsn = array_merge($reqdfieldsn, 
62 5b237745 Scott Ullrich
				explode(",", "RADIUS server address,RADIUS shared secret"));
63
		}
64 e2411886 Scott Ullrich
		
65 5b237745 Scott Ullrich
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
66 e2411886 Scott Ullrich
		
67 5b237745 Scott Ullrich
		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 e2411886 Scott Ullrich
		
77
		if (!$input_errors) {	
78 5b237745 Scott Ullrich
			$_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 e2411886 Scott Ullrich
						
82
			if ((ip2long($_POST['localip']) >= $subnet_start) && 
83 5b237745 Scott Ullrich
			    (ip2long($_POST['localip']) <= $subnet_end)) {
84 e2411886 Scott Ullrich
				$input_errors[] = "The specified server address lies in the remote subnet.";	
85 5b237745 Scott Ullrich
			}
86
			if ($_POST['localip'] == $config['interfaces']['lan']['ipaddr']) {
87 e2411886 Scott Ullrich
				$input_errors[] = "The specified server address is equal to the LAN interface address.";	
88 5b237745 Scott Ullrich
			}
89
		}
90
	} else if ($_POST['mode'] == "redir") {
91
		$reqdfields = explode(" ", "redir");
92
		$reqdfieldsn = explode(",", "PPTP redirection target address");
93 e2411886 Scott Ullrich
		
94 5b237745 Scott Ullrich
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95 e2411886 Scott Ullrich
		
96 5b237745 Scott Ullrich
		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['req128'] = $_POST['req128'] ? true : false;
107
		$pptpcfg['radius']['enable'] = $_POST['radiusenable'] ? true : false;
108
		$pptpcfg['radius']['accounting'] = $_POST['radacct_enable'] ? true : false;
109
		$pptpcfg['radius']['server'] = $_POST['radiusserver'];
110
		$pptpcfg['radius']['secret'] = $_POST['radiussecret'];
111 e2411886 Scott Ullrich
			
112 5b237745 Scott Ullrich
		write_config();
113 e2411886 Scott Ullrich
		
114 5b237745 Scott Ullrich
		$retval = 0;
115
		if (!file_exists($d_sysrebootreqd_path)) {
116
			config_lock();
117
			$retval = vpn_pptpd_configure();
118
			config_unlock();
119
		}
120
		$savemsg = get_std_save_message($retval);
121
	}
122
}
123 4df96eff Scott Ullrich
124 b128368a Bill Marquette
$pgtitle = "VPN PPTP";
125 4df96eff Scott Ullrich
include("head.inc");
126
127 5b237745 Scott Ullrich
?>
128 422f27c0 Scott Ullrich
129
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
130 e2411886 Scott Ullrich
<?php include("fbegin.inc"); ?>
131 b128368a Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
132 5b237745 Scott Ullrich
<script language="JavaScript">
133
<!--
134
function get_radio_value(obj)
135
{
136
	for (i = 0; i < obj.length; i++) {
137
		if (obj[i].checked)
138
			return obj[i].value;
139
	}
140
	return null;
141
}
142
143
function enable_change(enable_over) {
144
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
145
		document.iform.remoteip.disabled = 0;
146
		document.iform.localip.disabled = 0;
147
		document.iform.req128.disabled = 0;
148
		document.iform.radiusenable.disabled = 0;
149 e2411886 Scott Ullrich
		
150 5b237745 Scott Ullrich
		if (document.iform.radiusenable.checked || enable_over) {
151
			document.iform.radacct_enable.disabled = 0;
152
			document.iform.radiusserver.disabled = 0;
153
			document.iform.radiussecret.disabled = 0;
154
		} else {
155
			document.iform.radacct_enable.disabled = 1;
156
			document.iform.radiusserver.disabled = 1;
157
			document.iform.radiussecret.disabled = 1;
158
		}
159
	} else {
160
		document.iform.remoteip.disabled = 1;
161
		document.iform.localip.disabled = 1;
162
		document.iform.req128.disabled = 1;
163
		document.iform.radiusenable.disabled = 1;
164
		document.iform.radacct_enable.disabled = 1;
165
		document.iform.radiusserver.disabled = 1;
166
		document.iform.radiussecret.disabled = 1;
167
	}
168
	if ((get_radio_value(document.iform.mode) == "redir") || enable_over) {
169
		document.iform.redir.disabled = 0;
170
	} else {
171
		document.iform.redir.disabled = 1;
172
	}
173
}
174
//-->
175
</script>
176
<form action="vpn_pptp.php" method="post" name="iform" id="iform">
177
<?php if ($input_errors) print_input_errors($input_errors); ?>
178
<?php if ($savemsg) print_info_box($savemsg); ?>
179
<table width="100%" border="0" cellpadding="0" cellspacing="0">
180 e2411886 Scott Ullrich
  <tr><td class="tabnavtbl">
181 17982382 Scott Ullrich
<?php
182
	$tab_array = array();
183
	$tab_array[0] = array("Configuration", true, "vpn_pptp.php");
184
	$tab_array[1] = array("Users", false, "vpn_pptp_users.php");
185
	display_top_tabs($tab_array);
186
?>  
187 5b237745 Scott Ullrich
  </td></tr>
188 e2411886 Scott Ullrich
  <tr> 
189 96f8c1e2 Bill Marquette
    <td>
190
<div id="mainarea">
191
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
192 e2411886 Scott Ullrich
                <tr> 
193 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
194 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
195 5b237745 Scott Ullrich
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
196
				  	<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked";?>>
197
                    Off</td>
198 e2411886 Scott Ullrich
                <tr> 
199 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
200
                  <td width="78%" class="vtable">
201
<input type="radio" name="mode" value="redir" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "redir") echo "checked"; ?>>
202
                    Redirect incoming PPTP connections to:</td>
203 e2411886 Scott Ullrich
                <tr> 
204 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">PPTP redirection</td>
205 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
206
                    <?=$mandfldhtml;?><input name="redir" type="text" class="formfld" id="redir" size="20" value="<?=htmlspecialchars($pconfig['redir']);?>"> 
207 5b237745 Scott Ullrich
                    <br>
208 e2411886 Scott Ullrich
                    Enter the IP address of a host which will accept incoming 
209 5b237745 Scott Ullrich
                    PPTP connections.</td>
210 e2411886 Scott Ullrich
                <tr> 
211 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
212
                  <td width="78%" class="vtable">
213
<input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
214
                    Enable PPTP server</td>
215 e2411886 Scott Ullrich
                <tr> 
216
                  <td width="22%" valign="top" class="vncellreq">Max. concurrent 
217 5b237745 Scott Ullrich
                    connections</td>
218 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
219 5b237745 Scott Ullrich
                    <?=$g['n_pptp_units'];?>
220
                  </td>
221 e2411886 Scott Ullrich
                <tr> 
222 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
223 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
224
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
225 5b237745 Scott Ullrich
                    <br>
226 e2411886 Scott Ullrich
                    Enter the IP address the PPTP server should use on its side 
227 5b237745 Scott Ullrich
                    for all clients.</td>
228
                </tr>
229 e2411886 Scott Ullrich
                <tr> 
230
                  <td width="22%" valign="top" class="vncellreq">Remote address 
231 5b237745 Scott Ullrich
                    range</td>
232 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
233
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
234
                    / 
235 5b237745 Scott Ullrich
                    <?=$g['pptp_subnet'];?>
236
                    <br>
237
                    Specify the starting address for the client IP address subnet.<br>
238 e2411886 Scott Ullrich
                    The PPTP server will assign 
239 5b237745 Scott Ullrich
                    <?=$g['n_pptp_units'];?>
240
                    addresses, starting at the address entered above, to clients.</td>
241
                </tr>
242 e2411886 Scott Ullrich
                <tr> 
243 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
244 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
245
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable']) echo "checked"; ?>>
246 5b237745 Scott Ullrich
                      <strong>Use a RADIUS server for authentication<br>
247 e2411886 Scott Ullrich
                      </strong>When set, all users will be authenticated using 
248
                      the RADIUS server specified below. The local user database 
249 5b237745 Scott Ullrich
                      will not be used.<br>
250
                      <br>
251 e2411886 Scott Ullrich
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable']) echo "checked"; ?>>
252 5b237745 Scott Ullrich
                      <strong>Enable RADIUS accounting <br>
253 e2411886 Scott Ullrich
                      </strong>Sends accounting packets to the RADIUS server.</td>
254 5b237745 Scott Ullrich
                </tr>
255 e2411886 Scott Ullrich
                <tr> 
256 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
257 78cf56c6 Scott Ullrich
                  <td width="78%" class="vtable">
258 5b237745 Scott Ullrich
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
259
                      <br>
260 e2411886 Scott Ullrich
                      Enter the IP address of the RADIUS server.</td>
261 5b237745 Scott Ullrich
                </tr>
262 e2411886 Scott Ullrich
                <tr> 
263 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
264 78cf56c6 Scott Ullrich
                  <td width="78%" valign="top" class="vtable">
265 5b237745 Scott Ullrich
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
266
                      <br>
267 e2411886 Scott Ullrich
                      Enter the shared secret that will be used to authenticate 
268
                      to the RADIUS server.</td>
269 5b237745 Scott Ullrich
                </tr>
270 e2411886 Scott Ullrich
                <tr> 
271 5b237745 Scott Ullrich
                  <td height="16" colspan="2" valign="top"></td>
272
                </tr>
273 e2411886 Scott Ullrich
                <tr> 
274 5b237745 Scott Ullrich
                  <td width="22%" valign="middle">&nbsp;</td>
275 e2411886 Scott Ullrich
                  <td width="78%" class="vtable"> 
276
                    <input name="req128" type="checkbox" id="req128" value="yes" <?php if ($pconfig['req128']) echo "checked"; ?>> 
277 5b237745 Scott Ullrich
                    <strong>Require 128-bit encryption</strong><br>
278 e2411886 Scott Ullrich
                    When set, 128-bit encryption will be accepted. Otherwise, 
279
                    40-bit and 56-bit encryption will be accepted, too. Note that 
280
                    encryption will always be forced on PPTP connections (i.e. 
281 5b237745 Scott Ullrich
                    unencrypted connections will not be accepted).</td>
282
                </tr>
283 e2411886 Scott Ullrich
                <tr> 
284 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
285 e2411886 Scott Ullrich
                  <td width="78%"> 
286
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
287 5b237745 Scott Ullrich
                  </td>
288
                </tr>
289 e2411886 Scott Ullrich
                <tr> 
290
                  <td width="22%" valign="top">&nbsp;</td>
291
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
292
                    </strong></span>don't forget to add a firewall rule to permit 
293
                    traffic from PPTP clients!</span></td>
294
                </tr>
295 5b237745 Scott Ullrich
              </table>
296 96f8c1e2 Bill Marquette
</div>
297 e2411886 Scott Ullrich
			</td>
298 5b237745 Scott Ullrich
	</tr>
299
</table>
300
</form>
301
<script language="JavaScript">
302
<!--
303
enable_change(false);
304
//-->
305
</script>
306
<?php include("fend.inc"); ?>
307 9999b3aa Scott Ullrich
</body>
308
</html>