Project

General

Profile

Download (19.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_mobile.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7
	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
	$pconfig['p1authentication_method'] = "pre_shared_key";
46
	$pconfig['p2proto'] = "esp";
47
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael");
48
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
49
	$pconfig['p2pfsgroup'] = "0";
50
	$pconfig['dpddelay'] = "120";
51
} else {
52
	$pconfig['enable'] = isset($a_ipsec['enable']);
53
	$pconfig['natt'] = isset($a_ipsec['natt']);
54
	$pconfig['p1mode'] = $a_ipsec['p1']['mode'];
55
		
56
	if (isset($a_ipsec['p1']['myident']['myaddress']))
57
		$pconfig['p1myidentt'] = 'myaddress';
58
	else if (isset($a_ipsec['p1']['myident']['address'])) {
59
		$pconfig['p1myidentt'] = 'address';
60
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['address'];
61
	} else if (isset($a_ipsec['p1']['myident']['fqdn'])) {
62
		$pconfig['p1myidentt'] = 'fqdn';
63
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['fqdn'];
64
	} else if (isset($a_ipsec['p1']['myident']['ufqdn'])) {
65
		$pconfig['p1myidentt'] = 'user_fqdn';
66
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['ufqdn'];
67
 	}
68
	
69
	$pconfig['p1ealgo'] = $a_ipsec['p1']['encryption-algorithm'];
70
	$pconfig['p1halgo'] = $a_ipsec['p1']['hash-algorithm'];
71
	$pconfig['p1dhgroup'] = $a_ipsec['p1']['dhgroup'];
72
	$pconfig['p1lifetime'] = $a_ipsec['p1']['lifetime'];
73
	$pconfig['p1authentication_method'] = $a_ipsec['p1']['authentication_method'];
74
	$pconfig['p1cert'] = base64_decode($a_ipsec['p1']['cert']);
75
	$pconfig['p1privatekey'] = base64_decode($a_ipsec['p1']['private-key']);
76
	$pconfig['p2proto'] = $a_ipsec['p2']['protocol'];
77

    
78
	$pconfig['p2ealgos'] = $a_ipsec['p2']['encryption-algorithm-option'];
79
	$pconfig['p2halgos'] = $a_ipsec['p2']['hash-algorithm-option'];
80

    
81
	$pconfig['p2pfsgroup'] = $a_ipsec['p2']['pfsgroup'];
82
	$pconfig['p2lifetime'] = $a_ipsec['p2']['lifetime'];
83
	$pconfig['dpddelay'] = $a_ipsec['dpddelay'];
84
}
85

    
86
if ($_POST['apply']) {
87
		$retval = 0;
88
		$retval = vpn_ipsec_configure();
89
		$savemsg = get_std_save_message($retval);	
90
		unlink($d_ipsecconfdirty_path);
91
} else if($_POST)  {
92
	unset($input_errors);
93
	$pconfig = $_POST;
94

    
95
	/* input validation */
96
	$reqdfields = explode(" ", "p2ealgos p2halgos");
97
	$reqdfieldsn = explode(",", "P2 Encryption Algorithms,P2 Hash Algorithms");
98
	
99
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
100
	
101
	if ($_POST['p1authentication_method']== "rsasig") {
102
		if (!strstr($_POST['p1cert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1cert'], "END CERTIFICATE"))
103
			$input_errors[] = "This certificate does not appear to be valid.";
104
		if (!strstr($_POST['p1privatekey'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['p1privatekey'], "END RSA PRIVATE KEY"))
105
			$input_errors[] = "This key does not appear to be valid.";	
106
	}
107
	if (($_POST['dpddelay'] && !is_numeric($_POST['dpddelay']))) {
108
		$input_errors[] = "The DPD delay interval must be an integer.";
109
	}	
110
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
111
		$input_errors[] = "The P1 lifetime must be an integer.";
112
	}
113
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
114
		$input_errors[] = "The P2 lifetime must be an integer.";
115
	}
116
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
117
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
118
	}
119
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
120
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
121
	}
122
	if ($_POST['p1myidentt'] == "user_fqdn") {
123
		$ufqdn = explode("@",$_POST['p1myident']);
124
		if (!is_domain($ufqdn[1])) 
125
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
126
	}
127
	
128
	if ($_POST['p1myidentt'] == "myaddress")
129
		$_POST['p1myident'] = "";
130

    
131
	if (!$input_errors) {
132
		$ipsecent = array();
133
		$ipsecent['enable'] = $_POST['enable'] ? true : false;
134
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
135
		$ipsecent['natt'] = $_POST['natt'] ? true : false;
136
		
137
		$ipsecent['p1']['myident'] = array();
138
		switch ($_POST['p1myidentt']) {
139
			case 'myaddress':
140
				$ipsecent['p1']['myident']['myaddress'] = true;
141
				break;
142
			case 'address':
143
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
144
				break;
145
			case 'fqdn':
146
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
147
				break;
148
			case 'user_fqdn':
149
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
150
				break;
151
		}
152
		
153
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
154
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
155
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
156
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
157
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
158
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
159
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
160
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
161
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
162
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
163
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
164
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
165
		$ipsecent['dpddelay'] = $_POST['dpddelay'];
166
		
167
		$a_ipsec = $ipsecent;
168
		
169
		write_config();
170
		touch($d_ipsecconfdirty_path);
171
		
172
		header("Location: vpn_ipsec_mobile.php");
173
		exit;
174
	}
175
}
176

    
177
$pgtitle = "VPN: IPsec: Mobile";
178
include("head.inc");
179

    
180
?>
181
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
182
<?php include("fbegin.inc"); ?>
183
<p class="pgtitle"><?=$pgtitle?></p>
184
<script language="JavaScript">
185
<!--
186
function methodsel_change() {
187
	switch (document.iform.p1authentication_method.selectedIndex) {
188
		case 1:	/* rsa */
189
			document.iform.p1privatekey.disabled = 0;
190
			document.iform.p1cert.disabled = 0;
191
			break;
192
		default: /* pre-shared */
193
			document.iform.p1privatekey.disabled = 1;
194
			document.iform.p1cert.disabled = 1;
195
			break;
196
	}
197
}
198
//-->
199
</script>
200
<form action="vpn_ipsec_mobile.php" method="post">
201
<?php if ($savemsg) print_info_box($savemsg); ?>
202
<?php if ($input_errors) print_input_errors($input_errors); ?>
203
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
204
<?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>
205
<?php endif; ?>
206
</form>
207
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
208
<table width="100%" border="0" cellpadding="0" cellspacing="0">
209
  <tr><td class="tabnavtbl">
210
<?php
211
	$tab_array = array();
212
	$tab_array[0] = array("Tunnels", false, "vpn_ipsec.php");
213
	$tab_array[1] = array("Mobile clients", true, "vpn_ipsec_mobile.php");
214
	$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
215
	$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
216
	display_top_tabs($tab_array);
217
?>
218
  </td></tr>
219
  <tr> 
220
    <td>
221
	 <div id="mainarea">
222
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
223
			  <tr> 
224
                        <td width="22%" valign="top">&nbsp;</td>
225
                        <td width="78%"> 
226
                    <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
227
                    <strong>Allow mobile clients</strong></td>
228
                </tr>
229
                <tr> 
230
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal 
231
                    (Authentication)</td>
232
                </tr>
233
                <tr> 
234
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
235
                        <td width="78%" class="vtable">
236
					<select name="p1mode" class="formfld">
237
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
238
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>> 
239
                      <?=htmlspecialchars($mode);?>
240
                      </option>
241
                      <?php endforeach; ?>
242
                    </select> <br> <span class="vexpl">Aggressive is faster, but 
243
                    less secure.</span></td>
244
                </tr>
245
                <tr> 
246
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
247
                        <td width="78%" class="vtable">
248
					<select name="p1myidentt" class="formfld">
249
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
250
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>> 
251
                      <?=htmlspecialchars($modename);?>
252
                      </option>
253
                      <?php endforeach; ?>
254
                    </select> <input name="p1myident" type="text" class="formfld" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>"> 
255
                  </td>
256
                </tr>
257
                <tr> 
258
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
259
                        <td width="78%" class="vtable">
260
					<select name="p1ealgo" class="formfld">
261
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
262
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>> 
263
                      <?=htmlspecialchars($algoname);?>
264
                      </option>
265
                      <?php endforeach; ?>
266
                    </select> <br> <span class="vexpl">Must match the setting 
267
                    chosen on the remote side. </span></td>
268
                </tr>
269
                <tr> 
270
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
271
                        <td width="78%" class="vtable">
272
					<select name="p1halgo" class="formfld">
273
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
274
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>> 
275
                      <?=htmlspecialchars($algoname);?>
276
                      </option>
277
                      <?php endforeach; ?>
278
                    </select> <br> <span class="vexpl">Must match the setting 
279
                    chosen on the remote side. </span></td>
280
                </tr>
281
                <tr> 
282
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
283
                        <td width="78%" class="vtable">
284
					<select name="p1dhgroup" class="formfld">
285
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
286
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>> 
287
                      <?=htmlspecialchars($keygroup);?>
288
                      </option>
289
                      <?php endforeach; ?>
290
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
291
                    bit, 5 = 1536 bit</em><br>
292
                    Must match the setting chosen on the remote side. </span></td>
293
                </tr>
294
		<?php /*
295
                <tr>
296
                  <td width="22%" class="vncellreq" valign="top">NAT Traversal</td>
297
                  <td width="78%" class="vtable">
298
                    <input name="natt" type="checkbox" id="natt" value="yes" <?php if ($pconfig['natt']) echo "checked"; ?>>
299
                    Enable NAT Traversal (NAT-T)<br>
300
                    <span class="vexpl">Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed,
301
                        which can help with clients that are behind restrictive firewalls.</span></td>
302
                </tr>
303
		      */ ?>
304
                <tr>
305
                  <td width="22%" valign="top" class="vncell">DPD Interval</td>
306
                        <td width="78%" class="vtable">
307
                    <input name="dpddelay" type="text" class="formfld" id="dpddelay" size="3" value="<?=$pconfig['dpddelay'];?>">
308
                        <span class="vexpl">Dead Peer Detection interval in seconds.<br /> Leave this empty to only respond to DPD requests
309
                        and not send any requests.</td>
310
                </tr>
311

    
312
                <tr> 
313
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
314
                        <td width="78%" class="vtable"> 
315
                    <input name="p1lifetime" type="text" class="formfld" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
316
                    seconds</td>
317
                </tr>
318
                <tr> 
319
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
320
                  <td width="78%" class="vtable">
321
					<select name="p1authentication_method" class="formfld" onChange="methodsel_change()">
322
                      <?php foreach ($p1_authentication_methods as $method => $methodname): ?>
323
                      <option value="<?=$method;?>" <?php if ($method == $pconfig['p1authentication_method']) echo "selected"; ?>> 
324
                      <?=htmlspecialchars($methodname);?>
325
                      </option>
326
                      <?php endforeach; ?>
327
                    </select> <br> <span class="vexpl">Must match the setting 
328
                    chosen on the remote side. </span></td>
329
                </tr>
330
                <tr> 
331
                  <td width="22%" valign="top" class="vncellreq">Certificate</td>
332
                  <td width="78%" class="vtable"> 
333
                    <textarea name="p1cert" cols="65" rows="7" id="p1cert" class="formpre"><?=htmlspecialchars($pconfig['p1cert']);?></textarea>
334
                    <br> 
335
                    Paste a certificate in X.509 PEM format here.</td>
336
                </tr>
337
                <tr> 
338
                  <td width="22%" valign="top" class="vncellreq">Key</td>
339
                  <td width="78%" class="vtable"> 
340
                    <textarea name="p1privatekey" cols="65" rows="7" id="p1privatekey" class="formpre"><?=htmlspecialchars($pconfig['p1privatekey']);?></textarea>
341
                    <br> 
342
                    Paste an RSA private key in PEM format here.</td>
343
                </tr>
344
                <tr> 
345
                  <td colspan="2" class="list" height="12"></td>
346
                </tr>
347
                <tr> 
348
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal 
349
                    (SA/Key Exchange)</td>
350
                </tr>
351
                <tr> 
352
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
353
                        <td width="78%" class="vtable">
354
					<select name="p2proto" class="formfld">
355
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
356
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>> 
357
                      <?=htmlspecialchars($protoname);?>
358
                      </option>
359
                      <?php endforeach; ?>
360
                    </select> <br> <span class="vexpl">ESP is encryption, AH is 
361
                    authentication only </span></td>
362
                </tr>
363
                <tr> 
364
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
365
                        <td width="78%" class="vtable"> 
366
                          <?php foreach ($p2_ealgos as $algo => $algoname): ?>
367
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>> 
368
                    <?=htmlspecialchars($algoname);?>
369
                    <br> 
370
                    <?php endforeach; ?>
371
                    <br>
372
                    Hint: use 3DES for best compatibility or if you have a hardware 
373
                    crypto accelerator card. Blowfish is usually the fastest in 
374
                    software encryption. </td>
375
                </tr>
376
                <tr> 
377
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
378
                        <td width="78%" class="vtable"> 
379
                          <?php foreach ($p2_halgos as $algo => $algoname): ?>
380
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>> 
381
                    <?=htmlspecialchars($algoname);?>
382
                    <br> 
383
                    <?php endforeach; ?>
384
                  </td>
385
                </tr>
386
                <tr> 
387
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
388
                        <td width="78%" class="vtable">
389
					<select name="p2pfsgroup" class="formfld">
390
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
391
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>> 
392
                      <?=htmlspecialchars($keygroupname);?>
393
                      </option>
394
                      <?php endforeach; ?>
395
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
396
                    bit, 5 = 1536 bit</em></span></td>
397
                </tr>
398
                <tr> 
399
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
400
                        <td width="78%" class="vtable"> 
401
                    <input name="p2lifetime" type="text" class="formfld" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
402
                    seconds</td>
403
                </tr>
404
                <tr> 
405
                  <td width="22%" valign="top">&nbsp;</td>
406
                  <td width="78%"> 
407
                    <input name="Submit" type="submit" class="formbtn" value="Save">
408
                  </td>
409
                </tr>
410
              </table>
411
	  </div>
412
	 </td>
413
	</tr>
414
</table>
415
</form>
416
<script language="JavaScript">
417
<!--
418
methodsel_change();
419
//-->
420
</script>
421
<?php include("fend.inc"); ?>
422
</body>
423
</html>
(158-158/176)