Project

General

Profile

Download (18.1 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	vpn_ipsec_mobile.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	
6 e2411886 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7 5b237745 Scott Ullrich
	All rights reserved.
8
	
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11
	
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14
	
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18
	
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31
require("guiconfig.inc");
32
33
if (!is_array($config['ipsec']['mobileclients'])) {
34
	$config['ipsec']['mobileclients'] = array();
35
}
36
$a_ipsec = &$config['ipsec']['mobileclients'];
37
38
if (count($a_ipsec) == 0) {
39
	/* defaults */
40
	$pconfig['p1mode'] = "aggressive";
41
	$pconfig['p1myidentt'] = "myaddress";
42
	$pconfig['p1ealgo'] = "3des";
43
	$pconfig['p1halgo'] = "sha1";
44
	$pconfig['p1dhgroup'] = "2";
45 e2411886 Scott Ullrich
	$pconfig['p1authentication_method'] = "pre_shared_key";
46 5b237745 Scott Ullrich
	$pconfig['p2proto'] = "esp";
47
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael");
48
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
49
	$pconfig['p2pfsgroup'] = "0";
50
} else {
51
	$pconfig['enable'] = isset($a_ipsec['enable']);
52 e4298413 Scott Ullrich
	$pconfig['natt'] = isset($a_ipsec['natt']);
53 5b237745 Scott Ullrich
	$pconfig['p1mode'] = $a_ipsec['p1']['mode'];
54
		
55
	if (isset($a_ipsec['p1']['myident']['myaddress']))
56
		$pconfig['p1myidentt'] = 'myaddress';
57
	else if (isset($a_ipsec['p1']['myident']['address'])) {
58
		$pconfig['p1myidentt'] = 'address';
59
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['address'];
60
	} else if (isset($a_ipsec['p1']['myident']['fqdn'])) {
61
		$pconfig['p1myidentt'] = 'fqdn';
62
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['fqdn'];
63
	} else if (isset($a_ipsec['p1']['myident']['ufqdn'])) {
64
		$pconfig['p1myidentt'] = 'user_fqdn';
65
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['ufqdn'];
66
 	}
67
	
68
	$pconfig['p1ealgo'] = $a_ipsec['p1']['encryption-algorithm'];
69
	$pconfig['p1halgo'] = $a_ipsec['p1']['hash-algorithm'];
70
	$pconfig['p1dhgroup'] = $a_ipsec['p1']['dhgroup'];
71
	$pconfig['p1lifetime'] = $a_ipsec['p1']['lifetime'];
72 e2411886 Scott Ullrich
	$pconfig['p1authentication_method'] = $a_ipsec['p1']['authentication_method'];
73
	$pconfig['p1cert'] = base64_decode($a_ipsec['p1']['cert']);
74
	$pconfig['p1privatekey'] = base64_decode($a_ipsec['p1']['private-key']);
75 5b237745 Scott Ullrich
	$pconfig['p2proto'] = $a_ipsec['p2']['protocol'];
76
	$pconfig['p2ealgos'] = $a_ipsec['p2']['encryption-algorithm-option'];
77
	$pconfig['p2halgos'] = $a_ipsec['p2']['hash-algorithm-option'];
78
	$pconfig['p2pfsgroup'] = $a_ipsec['p2']['pfsgroup'];
79
	$pconfig['p2lifetime'] = $a_ipsec['p2']['lifetime'];
80
}
81
82
if ($_POST) {
83
	unset($input_errors);
84
	$pconfig = $_POST;
85
86
	/* input validation */
87
	$reqdfields = explode(" ", "p2ealgos p2halgos");
88
	$reqdfieldsn = explode(",", "P2 Encryption Algorithms,P2 Hash Algorithms");
89
	
90
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
91
	
92 e2411886 Scott Ullrich
	if ($_POST['p1authentication_method']== "rsasig") {
93
		if (!strstr($_POST['p1cert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1cert'], "END CERTIFICATE"))
94
			$input_errors[] = "This certificate does not appear to be valid.";
95
		if (!strstr($_POST['p1privatekey'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['p1privatekey'], "END RSA PRIVATE KEY"))
96
			$input_errors[] = "This key does not appear to be valid.";	
97
	}
98
	
99 5b237745 Scott Ullrich
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
100
		$input_errors[] = "The P1 lifetime must be an integer.";
101
	}
102
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
103
		$input_errors[] = "The P2 lifetime must be an integer.";
104
	}
105
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
106
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
107
	}
108
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
109
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
110
	}
111
	if ($_POST['p1myidentt'] == "user_fqdn") {
112
		$ufqdn = explode("@",$_POST['p1myident']);
113
		if (!is_domain($ufqdn[1])) 
114
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
115
	}
116
	
117
	if ($_POST['p1myidentt'] == "myaddress")
118
		$_POST['p1myident'] = "";
119
120
	if (!$input_errors) {
121
		$ipsecent = array();
122
		$ipsecent['enable'] = $_POST['enable'] ? true : false;
123
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
124 e4298413 Scott Ullrich
		$ipsecent['natt'] = $_POST['natt'] ? true : false;
125 5b237745 Scott Ullrich
		
126
		$ipsecent['p1']['myident'] = array();
127
		switch ($_POST['p1myidentt']) {
128
			case 'myaddress':
129
				$ipsecent['p1']['myident']['myaddress'] = true;
130
				break;
131
			case 'address':
132
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
133
				break;
134
			case 'fqdn':
135
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
136
				break;
137
			case 'user_fqdn':
138
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
139
				break;
140
		}
141
		
142
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
143
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
144
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
145
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
146 e2411886 Scott Ullrich
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
147
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
148
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
149 5b237745 Scott Ullrich
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
150
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
151
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
152
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
153
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
154
		
155
		$a_ipsec = $ipsecent;
156
		
157
		write_config();
158
		touch($d_ipsecconfdirty_path);
159
		
160
		header("Location: vpn_ipsec_mobile.php");
161
		exit;
162
	}
163
}
164 422f27c0 Scott Ullrich
165 d88c6a9f Scott Ullrich
$pgtitle = array("VPN","IPsec","Mobile");
166 4df96eff Scott Ullrich
include("head.inc");
167
168
?>
169 422f27c0 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
170 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
171 e2411886 Scott Ullrich
<script language="JavaScript">
172
<!--
173
function methodsel_change() {
174
	switch (document.iform.p1authentication_method.selectedIndex) {
175
		case 1:	/* rsa */
176
			document.iform.p1privatekey.disabled = 0;
177
			document.iform.p1cert.disabled = 0;
178
			break;
179
		default: /* pre-shared */
180
			document.iform.p1privatekey.disabled = 1;
181
			document.iform.p1cert.disabled = 1;
182
			break;
183
	}
184
}
185
//-->
186
</script>
187 5b237745 Scott Ullrich
<form action="vpn_ipsec.php" method="post">
188
<?php if ($input_errors) print_input_errors($input_errors); ?>
189
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
190
<?php print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
191
<?php endif; ?>
192
</form>
193
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
194
<table width="100%" border="0" cellpadding="0" cellspacing="0">
195 e2411886 Scott Ullrich
  <tr><td class="tabnavtbl">
196 323d040b Scott Ullrich
<?php
197
	$tab_array = array();
198
	$tab_array[0] = array("Tunnels", false, "vpn_ipsec.php");
199
	$tab_array[1] = array("Mobile clients", true, "vpn_ipsec_mobile.php");
200
	$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
201
	$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
202
	display_top_tabs($tab_array);
203
?>
204 5b237745 Scott Ullrich
  </td></tr>
205
  <tr> 
206 0f10aee4 Bill Marquette
    <td>
207
	 <div id="mainarea">
208
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
209 5b237745 Scott Ullrich
			  <tr> 
210
                        <td width="22%" valign="top">&nbsp;</td>
211
                        <td width="78%"> 
212
                    <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
213
                    <strong>Allow mobile clients</strong></td>
214 e4298413 Scott Ullrich
                </tr>
215
				<tr> 
216
                  <td width="22%" valign="top">&nbsp;</td>
217
                  <td width="78%"> 
218
                    <input name="natt" type="checkbox" id="natt" value="yes" <?php if ($pconfig['natt']) echo "checked"; ?>>
219
                    <strong>Enable NAT Traversal (NAT-T)</strong><br>
220
                    <span class="vexpl">Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed,
221
                    	which can help with clients that are behind restrictive firewalls.</span></td>
222 5b237745 Scott Ullrich
                </tr>
223
                <tr> 
224
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal 
225
                    (Authentication)</td>
226
                </tr>
227
                <tr> 
228
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
229 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
230 b5c78501 Seth Mos
					<select name="p1mode" class="formselect">
231 5b237745 Scott Ullrich
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
232
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>> 
233
                      <?=htmlspecialchars($mode);?>
234
                      </option>
235
                      <?php endforeach; ?>
236
                    </select> <br> <span class="vexpl">Aggressive is faster, but 
237
                    less secure.</span></td>
238
                </tr>
239
                <tr> 
240
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
241 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
242 b5c78501 Seth Mos
					<select name="p1myidentt" class="formselect">
243 5b237745 Scott Ullrich
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
244
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>> 
245
                      <?=htmlspecialchars($modename);?>
246
                      </option>
247
                      <?php endforeach; ?>
248 b5c78501 Seth Mos
                    </select> <input name="p1myident" type="text" class="formfld unknown" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>"> 
249 5b237745 Scott Ullrich
                  </td>
250
                </tr>
251
                <tr> 
252
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
253 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
254 b5c78501 Seth Mos
					<select name="p1ealgo" class="formselect">
255 5b237745 Scott Ullrich
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
256
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>> 
257
                      <?=htmlspecialchars($algoname);?>
258
                      </option>
259
                      <?php endforeach; ?>
260
                    </select> <br> <span class="vexpl">Must match the setting 
261
                    chosen on the remote side. </span></td>
262
                </tr>
263
                <tr> 
264
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
265 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
266 b5c78501 Seth Mos
					<select name="p1halgo" class="formselect">
267 5b237745 Scott Ullrich
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
268
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>> 
269
                      <?=htmlspecialchars($algoname);?>
270
                      </option>
271
                      <?php endforeach; ?>
272
                    </select> <br> <span class="vexpl">Must match the setting 
273
                    chosen on the remote side. </span></td>
274
                </tr>
275
                <tr> 
276
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
277 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
278 b5c78501 Seth Mos
					<select name="p1dhgroup" class="formselect">
279 5b237745 Scott Ullrich
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
280
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>> 
281
                      <?=htmlspecialchars($keygroup);?>
282
                      </option>
283
                      <?php endforeach; ?>
284
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
285
                    bit, 5 = 1536 bit</em><br>
286
                    Must match the setting chosen on the remote side. </span></td>
287
                </tr>
288
                <tr> 
289
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
290 e2411886 Scott Ullrich
                        <td width="78%" class="vtable"> 
291 b5c78501 Seth Mos
                    <input name="p1lifetime" type="text" class="formfld unknown" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
292 5b237745 Scott Ullrich
                    seconds</td>
293
                </tr>
294 e2411886 Scott Ullrich
                <tr> 
295
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
296
                  <td width="78%" class="vtable">
297 b5c78501 Seth Mos
					<select name="p1authentication_method" class="formselect" onChange="methodsel_change()">
298 e2411886 Scott Ullrich
                      <?php foreach ($p1_authentication_methods as $method => $methodname): ?>
299
                      <option value="<?=$method;?>" <?php if ($method == $pconfig['p1authentication_method']) echo "selected"; ?>> 
300
                      <?=htmlspecialchars($methodname);?>
301
                      </option>
302
                      <?php endforeach; ?>
303
                    </select> <br> <span class="vexpl">Must match the setting 
304
                    chosen on the remote side. </span></td>
305
                </tr>
306
                <tr> 
307
                  <td width="22%" valign="top" class="vncellreq">Certificate</td>
308
                  <td width="78%" class="vtable"> 
309
                    <textarea name="p1cert" cols="65" rows="7" id="p1cert" class="formpre"><?=htmlspecialchars($pconfig['p1cert']);?></textarea>
310
                    <br> 
311
                    Paste a certificate in X.509 PEM format here.</td>
312
                </tr>
313
                <tr> 
314
                  <td width="22%" valign="top" class="vncellreq">Key</td>
315
                  <td width="78%" class="vtable"> 
316
                    <textarea name="p1privatekey" cols="65" rows="7" id="p1privatekey" class="formpre"><?=htmlspecialchars($pconfig['p1privatekey']);?></textarea>
317
                    <br> 
318
                    Paste an RSA private key in PEM format here.</td>
319
                </tr>
320 5b237745 Scott Ullrich
                <tr> 
321
                  <td colspan="2" class="list" height="12"></td>
322
                </tr>
323
                <tr> 
324
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal 
325
                    (SA/Key Exchange)</td>
326
                </tr>
327
                <tr> 
328
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
329 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
330 b5c78501 Seth Mos
					<select name="p2proto" class="formselect">
331 5b237745 Scott Ullrich
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
332
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>> 
333
                      <?=htmlspecialchars($protoname);?>
334
                      </option>
335
                      <?php endforeach; ?>
336
                    </select> <br> <span class="vexpl">ESP is encryption, AH is 
337
                    authentication only </span></td>
338
                </tr>
339
                <tr> 
340
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
341 e2411886 Scott Ullrich
                        <td width="78%" class="vtable"> 
342 5b237745 Scott Ullrich
                          <?php foreach ($p2_ealgos as $algo => $algoname): ?>
343
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>> 
344
                    <?=htmlspecialchars($algoname);?>
345
                    <br> 
346
                    <?php endforeach; ?>
347
                    <br>
348
                    Hint: use 3DES for best compatibility or if you have a hardware 
349
                    crypto accelerator card. Blowfish is usually the fastest in 
350
                    software encryption. </td>
351
                </tr>
352
                <tr> 
353
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
354 e2411886 Scott Ullrich
                        <td width="78%" class="vtable"> 
355 5b237745 Scott Ullrich
                          <?php foreach ($p2_halgos as $algo => $algoname): ?>
356
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>> 
357
                    <?=htmlspecialchars($algoname);?>
358
                    <br> 
359
                    <?php endforeach; ?>
360
                  </td>
361
                </tr>
362
                <tr> 
363
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
364 e2411886 Scott Ullrich
                        <td width="78%" class="vtable">
365 b5c78501 Seth Mos
					<select name="p2pfsgroup" class="formselect">
366 5b237745 Scott Ullrich
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
367
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>> 
368
                      <?=htmlspecialchars($keygroupname);?>
369
                      </option>
370
                      <?php endforeach; ?>
371
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
372
                    bit, 5 = 1536 bit</em></span></td>
373
                </tr>
374
                <tr> 
375
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
376 e2411886 Scott Ullrich
                        <td width="78%" class="vtable"> 
377 b5c78501 Seth Mos
                    <input name="p2lifetime" type="text" class="formfld unknown" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
378 5b237745 Scott Ullrich
                    seconds</td>
379
                </tr>
380
                <tr> 
381
                  <td width="22%" valign="top">&nbsp;</td>
382
                  <td width="78%"> 
383
                    <input name="Submit" type="submit" class="formbtn" value="Save">
384
                  </td>
385
                </tr>
386
              </table>
387 0f10aee4 Bill Marquette
	  </div>
388
	 </td>
389
	</tr>
390
</table>
391 5b237745 Scott Ullrich
</form>
392 e2411886 Scott Ullrich
<script language="JavaScript">
393
<!--
394
methodsel_change();
395
//-->
396
</script>
397 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
398 323d040b Scott Ullrich
</body>
399
</html>