Project

General

Profile

Download (18.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
} else {
51
	$pconfig['enable'] = isset($a_ipsec['enable']);
52
	$pconfig['natt'] = isset($a_ipsec['natt']);
53
	$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
	$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
	$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
	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
	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
		$ipsecent['natt'] = $_POST['natt'] ? true : false;
125
		
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
		$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
		$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

    
165
$pgtitle = array("VPN","IPsec","Mobile");
166
include("head.inc");
167

    
168
?>
169
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
170
<?php include("fbegin.inc"); ?>
171
<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
<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
  <tr><td class="tabnavtbl">
196
<?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("CAs", false, "vpn_ipsec_ca.php");
201
	display_top_tabs($tab_array);
202
?>
203
  </td></tr>
204
  <tr> 
205
    <td>
206
	 <div id="mainarea">
207
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
208
			  <tr> 
209
                        <td width="22%" valign="top">&nbsp;</td>
210
                        <td width="78%"> 
211
                    <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
212
                    <strong>Allow mobile clients</strong></td>
213
                </tr>
214
				<tr> 
215
                  <td width="22%" valign="top">&nbsp;</td>
216
                  <td width="78%"> 
217
                    <input name="natt" type="checkbox" id="natt" value="yes" <?php if ($pconfig['natt']) echo "checked"; ?>>
218
                    <strong>Enable NAT Traversal (NAT-T)</strong><br>
219
                    <span class="vexpl">Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed,
220
                    	which can help with clients that are behind restrictive firewalls.</span></td>
221
                </tr>
222
                <tr> 
223
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal 
224
                    (Authentication)</td>
225
                </tr>
226
                <tr> 
227
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
228
                        <td width="78%" class="vtable">
229
					<select name="p1mode" class="formselect">
230
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
231
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>> 
232
                      <?=htmlspecialchars($mode);?>
233
                      </option>
234
                      <?php endforeach; ?>
235
                    </select> <br> <span class="vexpl">Aggressive is faster, but 
236
                    less secure.</span></td>
237
                </tr>
238
                <tr> 
239
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
240
                        <td width="78%" class="vtable">
241
					<select name="p1myidentt" class="formselect">
242
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
243
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>> 
244
                      <?=htmlspecialchars($modename);?>
245
                      </option>
246
                      <?php endforeach; ?>
247
                    </select> <input name="p1myident" type="text" class="formfld unknown" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>"> 
248
                  </td>
249
                </tr>
250
                <tr> 
251
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
252
                        <td width="78%" class="vtable">
253
					<select name="p1ealgo" class="formselect">
254
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
255
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>> 
256
                      <?=htmlspecialchars($algoname);?>
257
                      </option>
258
                      <?php endforeach; ?>
259
                    </select> <br> <span class="vexpl">Must match the setting 
260
                    chosen on the remote side. </span></td>
261
                </tr>
262
                <tr> 
263
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
264
                        <td width="78%" class="vtable">
265
					<select name="p1halgo" class="formselect">
266
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
267
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>> 
268
                      <?=htmlspecialchars($algoname);?>
269
                      </option>
270
                      <?php endforeach; ?>
271
                    </select> <br> <span class="vexpl">Must match the setting 
272
                    chosen on the remote side. </span></td>
273
                </tr>
274
                <tr> 
275
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
276
                        <td width="78%" class="vtable">
277
					<select name="p1dhgroup" class="formselect">
278
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
279
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>> 
280
                      <?=htmlspecialchars($keygroup);?>
281
                      </option>
282
                      <?php endforeach; ?>
283
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
284
                    bit, 5 = 1536 bit</em><br>
285
                    Must match the setting chosen on the remote side. </span></td>
286
                </tr>
287
                <tr> 
288
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
289
                        <td width="78%" class="vtable"> 
290
                    <input name="p1lifetime" type="text" class="formfld unknown" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
291
                    seconds</td>
292
                </tr>
293
                <tr> 
294
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
295
                  <td width="78%" class="vtable">
296
					<select name="p1authentication_method" class="formselect" onChange="methodsel_change()">
297
                      <?php foreach ($p1_authentication_methods as $method => $methodname): ?>
298
                      <option value="<?=$method;?>" <?php if ($method == $pconfig['p1authentication_method']) echo "selected"; ?>> 
299
                      <?=htmlspecialchars($methodname);?>
300
                      </option>
301
                      <?php endforeach; ?>
302
                    </select> <br> <span class="vexpl">Must match the setting 
303
                    chosen on the remote side. </span></td>
304
                </tr>
305
                <tr> 
306
                  <td width="22%" valign="top" class="vncellreq">Certificate</td>
307
                  <td width="78%" class="vtable"> 
308
                    <textarea name="p1cert" cols="65" rows="7" id="p1cert" class="formpre"><?=htmlspecialchars($pconfig['p1cert']);?></textarea>
309
                    <br> 
310
                    Paste a certificate in X.509 PEM format here.</td>
311
                </tr>
312
                <tr> 
313
                  <td width="22%" valign="top" class="vncellreq">Key</td>
314
                  <td width="78%" class="vtable"> 
315
                    <textarea name="p1privatekey" cols="65" rows="7" id="p1privatekey" class="formpre"><?=htmlspecialchars($pconfig['p1privatekey']);?></textarea>
316
                    <br> 
317
                    Paste an RSA private key in PEM format here.</td>
318
                </tr>
319
                <tr> 
320
                  <td colspan="2" class="list" height="12"></td>
321
                </tr>
322
                <tr> 
323
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal 
324
                    (SA/Key Exchange)</td>
325
                </tr>
326
                <tr> 
327
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
328
                        <td width="78%" class="vtable">
329
					<select name="p2proto" class="formselect">
330
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
331
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>> 
332
                      <?=htmlspecialchars($protoname);?>
333
                      </option>
334
                      <?php endforeach; ?>
335
                    </select> <br> <span class="vexpl">ESP is encryption, AH is 
336
                    authentication only </span></td>
337
                </tr>
338
                <tr> 
339
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
340
                        <td width="78%" class="vtable"> 
341
                          <?php foreach ($p2_ealgos as $algo => $algoname): ?>
342
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>> 
343
                    <?=htmlspecialchars($algoname);?>
344
                    <br> 
345
                    <?php endforeach; ?>
346
                    <br>
347
                    Hint: use 3DES for best compatibility or if you have a hardware 
348
                    crypto accelerator card. Blowfish is usually the fastest in 
349
                    software encryption. </td>
350
                </tr>
351
                <tr> 
352
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
353
                        <td width="78%" class="vtable"> 
354
                          <?php foreach ($p2_halgos as $algo => $algoname): ?>
355
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>> 
356
                    <?=htmlspecialchars($algoname);?>
357
                    <br> 
358
                    <?php endforeach; ?>
359
                  </td>
360
                </tr>
361
                <tr> 
362
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
363
                        <td width="78%" class="vtable">
364
					<select name="p2pfsgroup" class="formselect">
365
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
366
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>> 
367
                      <?=htmlspecialchars($keygroupname);?>
368
                      </option>
369
                      <?php endforeach; ?>
370
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
371
                    bit, 5 = 1536 bit</em></span></td>
372
                </tr>
373
                <tr> 
374
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
375
                        <td width="78%" class="vtable"> 
376
                    <input name="p2lifetime" type="text" class="formfld unknown" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
377
                    seconds</td>
378
                </tr>
379
                <tr> 
380
                  <td width="22%" valign="top">&nbsp;</td>
381
                  <td width="78%"> 
382
                    <input name="Submit" type="submit" class="formbtn" value="Save">
383
                  </td>
384
                </tr>
385
              </table>
386
	  </div>
387
	 </td>
388
	</tr>
389
</table>
390
</form>
391
<script language="JavaScript">
392
<!--
393
methodsel_change();
394
//-->
395
</script>
396
<?php include("fend.inc"); ?>
397
</body>
398
</html>
(174-174/197)