Project

General

Profile

Download (12.9 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['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
$pgtitle = "VPN PPTP";
125
include("head.inc");
126

    
127
?>
128

    
129
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
130
<?php include("fbegin.inc"); ?>
131
<p class="pgtitle"><?=$pgtitle?></p>
132
<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
		
150
		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
  <tr><td class="tabnavtbl">
181
<?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
  </td></tr>
188
  <tr> 
189
    <td>
190
<div id="mainarea">
191
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
192
                <tr> 
193
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
194
                  <td width="78%" class="vtable"> 
195
                    <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
                <tr> 
199
                  <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
                <tr> 
204
                  <td width="22%" valign="top" class="vncellreq">PPTP redirection</td>
205
                  <td width="78%" class="vtable"> 
206
                    <?=$mandfldhtml;?><input name="redir" type="text" class="formfld" id="redir" size="20" value="<?=htmlspecialchars($pconfig['redir']);?>"> 
207
                    <br>
208
                    Enter the IP address of a host which will accept incoming 
209
                    PPTP connections.</td>
210
                <tr> 
211
                  <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
                <tr> 
216
                  <td width="22%" valign="top" class="vncellreq">Max. concurrent 
217
                    connections</td>
218
                  <td width="78%" class="vtable"> 
219
                    <?=$g['n_pptp_units'];?>
220
                  </td>
221
                <tr> 
222
                  <td width="22%" valign="top" class="vncellreq">Server address</td>
223
                  <td width="78%" class="vtable"> 
224
                    <?=$mandfldhtml;?><input name="localip" type="text" class="formfld" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>"> 
225
                    <br>
226
                    Enter the IP address the PPTP server should use on its side 
227
                    for all clients.</td>
228
                </tr>
229
                <tr> 
230
                  <td width="22%" valign="top" class="vncellreq">Remote address 
231
                    range</td>
232
                  <td width="78%" class="vtable"> 
233
                    <?=$mandfldhtml;?><input name="remoteip" type="text" class="formfld" id="remoteip" size="20" value="<?=htmlspecialchars($pconfig['remoteip']);?>">
234
                    / 
235
                    <?=$g['pptp_subnet'];?>
236
                    <br>
237
                    Specify the starting address for the client IP address subnet.<br>
238
                    The PPTP server will assign 
239
                    <?=$g['n_pptp_units'];?>
240
                    addresses, starting at the address entered above, to clients.</td>
241
                </tr>
242
                <tr> 
243
                  <td width="22%" valign="top" class="vncell">RADIUS</td>
244
                  <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
                      <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']) echo "checked"; ?>>
252
                      <strong>Enable RADIUS accounting <br>
253
                      </strong>Sends accounting packets to the RADIUS server.</td>
254
                </tr>
255
                <tr> 
256
                  <td width="22%" valign="top" class="vncell">RADIUS server </td>
257
                  <td width="78%" class="vtable">
258
                      <input name="radiusserver" type="text" class="formfld" id="radiusserver" size="20" value="<?=htmlspecialchars($pconfig['radiusserver']);?>">
259
                      <br>
260
                      Enter the IP address of the RADIUS server.</td>
261
                </tr>
262
                <tr> 
263
                  <td width="22%" valign="top" class="vncell">RADIUS shared secret</td>
264
                  <td width="78%" valign="top" class="vtable">
265
                      <input name="radiussecret" type="password" class="formfld" id="radiussecret" size="20" value="<?=htmlspecialchars($pconfig['radiussecret']);?>">
266
                      <br>
267
                      Enter the shared secret that will be used to authenticate 
268
                      to the RADIUS server.</td>
269
                </tr>
270
                <tr> 
271
                  <td height="16" colspan="2" valign="top"></td>
272
                </tr>
273
                <tr> 
274
                  <td width="22%" valign="middle">&nbsp;</td>
275
                  <td width="78%" class="vtable"> 
276
                    <input name="req128" type="checkbox" id="req128" value="yes" <?php if ($pconfig['req128']) echo "checked"; ?>> 
277
                    <strong>Require 128-bit encryption</strong><br>
278
                    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
                    unencrypted connections will not be accepted).</td>
282
                </tr>
283
                <tr> 
284
                  <td width="22%" valign="top">&nbsp;</td>
285
                  <td width="78%"> 
286
                    <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)"> 
287
                  </td>
288
                </tr>
289
                <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
              </table>
296
</div>
297
			</td>
298
	</tr>
299
</table>
300
</form>
301
<script language="JavaScript">
302
<!--
303
enable_change(false);
304
//-->
305
</script>
306
<?php include("fend.inc"); ?>
307
</body>
308
</html>
(124-124/128)