Project

General

Profile

Download (13.1 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-2004 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['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['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
			
112
		write_config();
113
		
114
		$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
?>
124
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
125
<html><head>
126
<title><?=gentitle("VPN: PPTP");?></title>
127
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
128
<link href="gui.css" rel="stylesheet" type="text/css">
129
<script language="JavaScript">
130
<!--
131
function get_radio_value(obj)
132
{
133
	for (i = 0; i < obj.length; i++) {
134
		if (obj[i].checked)
135
			return obj[i].value;
136
	}
137
	return null;
138
}
139

    
140
function enable_change(enable_over) {
141
	if ((get_radio_value(document.iform.mode) == "server") || enable_over) {
142
		document.iform.remoteip.disabled = 0;
143
		document.iform.localip.disabled = 0;
144
		document.iform.req128.disabled = 0;
145
		document.iform.radiusenable.disabled = 0;
146
		
147
		if (document.iform.radiusenable.checked || enable_over) {
148
			document.iform.radacct_enable.disabled = 0;
149
			document.iform.radiusserver.disabled = 0;
150
			document.iform.radiussecret.disabled = 0;
151
		} else {
152
			document.iform.radacct_enable.disabled = 1;
153
			document.iform.radiusserver.disabled = 1;
154
			document.iform.radiussecret.disabled = 1;
155
		}
156
	} else {
157
		document.iform.remoteip.disabled = 1;
158
		document.iform.localip.disabled = 1;
159
		document.iform.req128.disabled = 1;
160
		document.iform.radiusenable.disabled = 1;
161
		document.iform.radacct_enable.disabled = 1;
162
		document.iform.radiusserver.disabled = 1;
163
		document.iform.radiussecret.disabled = 1;
164
	}
165
	if ((get_radio_value(document.iform.mode) == "redir") || enable_over) {
166
		document.iform.redir.disabled = 0;
167
	} else {
168
		document.iform.redir.disabled = 1;
169
	}
170
}
171
//-->
172
</script>
173
</head>
174

    
175
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
176
<?php include("fbegin.inc"); ?>
177
<p class="pgtitle">VPN: PPTP</p>
178
<form action="vpn_pptp.php" method="post" name="iform" id="iform">
179
<?php if ($input_errors) print_input_errors($input_errors); ?>
180
<?php if ($savemsg) print_info_box($savemsg); ?>
181
<table width="100%" border="0" cellpadding="0" cellspacing="0">
182
  <tr><td>
183
  <ul id="tabnav">
184
    <li class="tabact">Configuration</li>
185
    <li class="tabinact"><a href="vpn_pptp_users.php">Users</a></li>
186
  </ul>
187
  </td></tr>
188
  <tr> 
189
    <td class="tabcont">
190
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
191
                <tr> 
192
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
193
                  <td width="78%" class="vtable"> 
194
                    <input name="mode" type="radio" onclick="enable_change(false)" value="off"
195
				  	<?php if (($pconfig['mode'] != "server") && ($pconfig['mode'] != "redir")) echo "checked";?>>
196
                    Off</td>
197
                <tr> 
198
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
199
                  <td width="78%" class="vtable">
200
<input type="radio" name="mode" value="redir" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "redir") echo "checked"; ?>>
201
                    Redirect incoming PPTP connections to:</td>
202
                <tr> 
203
                  <td width="22%" valign="top" class="vncellreq">PPTP redirection</td>
204
                  <td width="78%" class="vtable"> 
205
                    <input name="redir" type="text" class="formfld" id="redir" size="20" value="<?=htmlspecialchars($pconfig['redir']);?>"> 
206
                    <br>
207
                    Enter the IP address of a host which will accept incoming 
208
                    PPTP connections.</td>
209
                <tr> 
210
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
211
                  <td width="78%" class="vtable">
212
<input type="radio" name="mode" value="server" onclick="enable_change(false)" <?php if ($pconfig['mode'] == "server") echo "checked"; ?>>
213
                    Enable PPTP server</td>
214
                <tr> 
215
                  <td width="22%" valign="top" class="vncellreq">Max. concurrent 
216
                    connections</td>
217
                  <td width="78%" class="vtable"> 
218
                    <?=$g['n_pptp_units'];?>
219
                  </td>
220
                <tr> 
221
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
222
                  <td width="78%" class="vtable"> 
223
                    <input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
224
                    <br>
225
                    Enter the IP address the PPTP server should use on its side 
226
                    for all clients.</td>
227
                </tr>
228
                <tr> 
229
                  <td width="22%" valign="top" class="vncellreq">Remote address 
230
                    range</td>
231
                  <td width="78%" class="vtable"> 
232
                    <input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
233
                    / 
234
                    <?=$g['pptp_subnet'];?>
235
                    <br>
236
                    Specify the starting address for the client IP address subnet.<br>
237
                    The PPTP server will assign 
238
                    <?=$g['n_pptp_units'];?>
239
                    addresses, starting at the address entered above, to clients.</td>
240
                </tr>
241
                <tr> 
242
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
243
                  <td width="78%" class="vtable"> 
244
                    <p> 
245
                      <input name="radiusenable" type="checkbox" id="radiusenable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radiusenable'] == "yes") echo "checked"; ?>>
246
                      <strong>Use a RADIUS server for authentication<br>
247
                      </strong>When set, all users will be authenticated using 
248
                      the RADIUS server specified below. The local user database 
249
                      will not be used.<br>
250
                      <br>
251
                      <input name="radacct_enable" type="checkbox" id="radacct_enable" onclick="enable_change(false)" value="yes" <?php if ($pconfig['radacct_enable'] == "yes") echo "checked"; ?>>
252
                      <strong>Enable RADIUS accounting <br>
253
                      </strong>Sends accounting packets to the RADIUS server. </p></td>
254
                </tr>
255
                <tr> 
256
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
257
                  <td width="78%" class="vtable"> 
258
                    <p> 
259
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
260
                      <br>
261
                      Enter the IP address of the RADIUS server.</p></td>
262
                </tr>
263
                <tr> 
264
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
265
                  <td width="78%" valign="top" class="vtable"> 
266
                    <p> 
267
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
268
                      <br>
269
                      Enter the shared secret that will be used to authenticate 
270
                      to the RADIUS server.</p></td>
271
                </tr>
272
                <tr> 
273
                  <td height="16" colspan="2" valign="top"></td>
274
                </tr>
275
                <tr> 
276
                  <td width="22%" valign="middle">&nbsp;</td>
277
                  <td width="78%" class="vtable"> 
278
                    <input name="req128" type="checkbox" id="req128" value="yes" <?php if ($pconfig['req128'] == "yes") echo "checked"; ?>> 
279
                    <strong>Require 128-bit encryption</strong><br>
280
                    When set, 128-bit encryption will be accepted. Otherwise, 
281
                    40-bit and 56-bit encryption will be accepted, too. Note that 
282
                    encryption will always be forced on PPTP connections (i.e. 
283
                    unencrypted connections will not be accepted).</td>
284
                </tr>
285
                <tr> 
286
                  <td width="22%" valign="top">&nbsp;</td>
287
                  <td width="78%"> 
288
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
289
                  </td>
290
                </tr>
291
                <tr> 
292
                  <td width="22%" valign="top">&nbsp;</td>
293
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
294
                    </strong></span>don't forget to add a firewall rule to permit 
295
                    traffic from PPTP clients!</span></td>
296
                </tr>
297
              </table>
298
			</td>
299
	</tr>
300
</table>
301
</form>
302
<script language="JavaScript">
303
<!--
304
enable_change(false);
305
//-->
306
</script>
307
<?php include("fend.inc"); ?>
308
</body>
309
</html>
(96-96/99)