Project

General

Profile

Download (27.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_edit.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']['tunnel'])) {
34
	$config['ipsec']['tunnel'] = array();
35
}
36
$a_ipsec = &$config['ipsec']['tunnel'];
37

    
38
$specialsrcdst = explode(" ", "lan");
39

    
40
$id = $_GET['id'];
41
if (isset($_POST['id']))
42
	$id = $_POST['id'];
43
	
44
if (isset($id) && $a_ipsec[$id]) {
45
	$pconfig['disabled'] = isset($a_ipsec[$id]['disabled']);
46
	$pconfig['auto'] = isset($a_ipsec[$id]['auto']);
47

    
48
	if (!isset($a_ipsec[$id]['local-subnet']))
49
		$pconfig['localnet'] = "lan";
50
	else
51
		address_to_pconfig_vpn($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask']);
52
		
53
	if ($a_ipsec[$id]['interface'])
54
		$pconfig['interface'] = $a_ipsec[$id]['interface'];
55
	else
56
		$pconfig['interface'] = "wan";
57
		
58
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_ipsec[$id]['remote-subnet']);
59
	$pconfig['remotegw'] = $a_ipsec[$id]['remote-gateway'];
60
	$pconfig['p1mode'] = $a_ipsec[$id]['p1']['mode'];
61
	
62
	if (isset($a_ipsec[$id]['p1']['myident']['myaddress']))
63
		$pconfig['p1myidentt'] = 'myaddress';
64
	else if (isset($a_ipsec[$id]['p1']['myident']['address'])) {
65
		$pconfig['p1myidentt'] = 'address';
66
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['address'];
67
	} else if (isset($a_ipsec[$id]['p1']['myident']['fqdn'])) {
68
		$pconfig['p1myidentt'] = 'fqdn';
69
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['fqdn'];
70
	} else if (isset($a_ipsec[$id]['p1']['myident']['ufqdn'])) {
71
		$pconfig['p1myidentt'] = 'user_fqdn';
72
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['ufqdn'];
73
 	} else if (isset($a_ipsec[$id]['p1']['myident']['dyn_dns'])) {
74
		$pconfig['p1myidentt'] = 'dyn_dns';
75
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['dyn_dns'];
76
	}
77
	
78
	$pconfig['p1ealgo'] = $a_ipsec[$id]['p1']['encryption-algorithm'];
79
	$pconfig['p1halgo'] = $a_ipsec[$id]['p1']['hash-algorithm'];
80
	$pconfig['p1dhgroup'] = $a_ipsec[$id]['p1']['dhgroup'];
81
	$pconfig['p1lifetime'] = $a_ipsec[$id]['p1']['lifetime'];
82
	$pconfig['p1authentication_method'] = $a_ipsec[$id]['p1']['authentication_method'];
83
	$pconfig['p1pskey'] = $a_ipsec[$id]['p1']['pre-shared-key'];
84
	$pconfig['p1cert'] = base64_decode($a_ipsec[$id]['p1']['cert']);
85
	$pconfig['p1peercert'] = base64_decode($a_ipsec[$id]['p1']['peercert']);
86
	$pconfig['p1privatekey'] = base64_decode($a_ipsec[$id]['p1']['private-key']);
87
	$pconfig['p2proto'] = $a_ipsec[$id]['p2']['protocol'];
88
	$pconfig['p2ealgos'] = $a_ipsec[$id]['p2']['encryption-algorithm-option'];
89
	$pconfig['p2halgos'] = $a_ipsec[$id]['p2']['hash-algorithm-option'];
90
	$pconfig['p2pfsgroup'] = $a_ipsec[$id]['p2']['pfsgroup'];
91
	$pconfig['p2lifetime'] = $a_ipsec[$id]['p2']['lifetime'];
92
	$pconfig['descr'] = $a_ipsec[$id]['descr'];
93
	$pconfig['pinghost'] = $a_ipsec[$id]['pinghost'];
94
	
95
} else {
96
	/* defaults */
97
	$pconfig['interface'] = "wan";
98
	$pconfig['localnet'] = "lan";
99
	$pconfig['p1mode'] = "aggressive";
100
	$pconfig['p1myidentt'] = "myaddress";
101
	$pconfig['p1authentication_method'] = "pre_shared_key";
102
	$pconfig['p1ealgo'] = "3des";
103
	$pconfig['p1halgo'] = "sha1";
104
	$pconfig['p1dhgroup'] = "2";
105
	$pconfig['p2proto'] = "esp";
106
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael,rijndael 256");
107
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
108
	$pconfig['p2pfsgroup'] = "0";
109
	$pconfig['remotebits'] = 32;
110
}
111

    
112
if ($_POST) {
113
	if (is_specialnet($_POST['localnettype'])) {
114
		$_POST['localnet'] = $_POST['localnettype'];
115
		$_POST['localnetmask'] = 0;
116
	} else if ($_POST['localnettype'] == "single") {
117
		$_POST['localnetmask'] = 32;
118
	}
119
	
120
	unset($input_errors);
121
	$pconfig = $_POST;
122

    
123
	/* input validation */
124
	if ($_POST['p1authentication_method'] == "pre_shared_key") {
125
		$reqdfields = explode(" ", "localnet remotenet remotebits remotegw p1pskey p2ealgos p2halgos");
126
		$reqdfieldsn = explode(",", "Local network,Remote network,Remote network bits,Remote gateway,Pre-Shared Key,P2 Encryption Algorithms,P2 Hash Algorithms");
127
	}
128
	else {
129
		$reqdfields = explode(" ", "localnet remotenet remotebits remotegw p2ealgos p2halgos");
130
		$reqdfieldsn = explode(",", "Local network,Remote network,Remote network bits,Remote gateway,P2 Encryption Algorithms,P2 Hash Algorithms");	
131
		if (!strstr($_POST['p1cert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1cert'], "END CERTIFICATE"))
132
			$input_errors[] = "This certificate does not appear to be valid.";
133
		if (!strstr($_POST['p1privatekey'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['p1privatekey'], "END RSA PRIVATE KEY"))
134
			$input_errors[] = "This key does not appear to be valid.";	
135
		if ($_POST['p1peercert']!="" && (!strstr($_POST['p1peercert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1peercert'], "END CERTIFICATE")))
136
			$input_errors[] = "This peer certificate does not appear to be valid.";	
137
	}
138
	
139
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
140
	
141
	if (!is_specialnet($_POST['localnettype'])) {
142
		if (($_POST['localnet'] && !is_ipaddr($_POST['localnet']))) {
143
			$input_errors[] = "A valid local network IP address must be specified.";
144
		}
145
		if (($_POST['localnetmask'] && !is_numeric($_POST['localnetmask']))) {
146
			$input_errors[] = "A valid local network bit count must be specified.";
147
		}
148
	}
149
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
150
		$input_errors[] = "The P1 lifetime must be an integer.";
151
	}
152
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
153
		$input_errors[] = "The P2 lifetime must be an integer.";
154
	}
155
	if ($_POST['remotebits'] && (!is_numeric($_POST['remotebits']) || ($_POST['remotebits'] < 0) || ($_POST['remotebits'] > 32))) {
156
		if(!$_POST['remotebits'] == "0.0.0.0")
157
			$input_errors[] = "The remote network bits are invalid.";
158
	}
159
	if (($_POST['remotenet'] && !is_ipaddr($_POST['remotenet'])) or $_POST['remotenet'] == "0.0.0.0") {
160
		/* allow 0.0.0.0 remote net usage */
161
		if($_POST['remotenet'] <> "0.0.0.0") 		
162
		$input_errors[] = "A valid remote network address must be specified.";
163
	}
164
	if (($_POST['remotegw'] && !is_ipaddr($_POST['remotegw']))) {
165
		if(is_domain($_POST['remotegw']) == false) 
166
			$input_errors[] = "A valid remote gateway address must be specified.";
167
	}
168
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
169
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
170
	}
171
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
172
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
173
	}
174
	if ($_POST['p1myidentt'] == "user_fqdn") {
175
		$ufqdn = explode("@",$_POST['p1myident']);
176
		if (is_domain($ufqdn[1]) == false) 
177
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
178
	}	
179
	if ($_POST['p1myidentt'] == "dyn_dns") {
180
		if (is_domain($_POST['p1myidentt']) == false) 
181
			$input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified.";
182
	}
183
	
184
	if ($_POST['p1myidentt'] == "myaddress")
185
		$_POST['p1myident'] = "";
186

    
187
	if (!$input_errors) {
188
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
189
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
190
		$ipsecent['interface'] = $pconfig['interface'];
191
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
192
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
193
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
194
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
195
		
196
		$ipsecent['p1']['myident'] = array();
197
		switch ($_POST['p1myidentt']) {
198
			case 'myaddress':
199
				$ipsecent['p1']['myident']['myaddress'] = true;
200
				break;
201
			case 'address':
202
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
203
				break;
204
			case 'fqdn':
205
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
206
				break;
207
			case 'user_fqdn':
208
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
209
				break;
210
			case 'dyn_dns':
211
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
212
				break;
213
		}
214
		
215
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
216
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
217
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
218
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
219
		$ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey'];
220
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
221
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
222
		$ipsecent['p1']['peercert'] = base64_encode($_POST['p1peercert']);
223
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
224
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
225
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
226
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
227
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
228
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
229
		$ipsecent['descr'] = $_POST['descr'];
230
		$ipsecent['pinghost'] = $_POST['pinghost'];
231
		
232
		if (isset($id) && $a_ipsec[$id])
233
			$a_ipsec[$id] = $ipsecent;
234
		else
235
			$a_ipsec[] = $ipsecent;
236
		
237
		write_config();
238
		touch($d_ipsecconfdirty_path);
239
		
240
		header("Location: vpn_ipsec.php");
241
		exit;
242
	}
243
}
244

    
245
$pgtitle = "VPN: IPsec: Edit tunnel";
246
include("head.inc");
247

    
248
?>
249

    
250
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
251
<?php include("fbegin.inc"); ?>
252
<p class="pgtitle"><?=$pgtitle?></p>
253
<script language="JavaScript">
254
<!--
255
function typesel_change() {
256
	switch (document.iform.localnettype.selectedIndex) {
257
		case 0:	/* single */
258
			document.iform.localnet.disabled = 0;
259
			document.iform.localnetmask.value = "";
260
			document.iform.localnetmask.disabled = 1;
261
			break;
262
		case 1:	/* network */
263
			document.iform.localnet.disabled = 0;
264
			document.iform.localnetmask.disabled = 0;
265
			break;
266
		default:
267
			document.iform.localnet.value = "";
268
			document.iform.localnet.disabled = 1;
269
			document.iform.localnetmask.value = "";
270
			document.iform.localnetmask.disabled = 1;
271
			break;
272
	}
273
}
274
function methodsel_change() {
275
	switch (document.iform.p1authentication_method.selectedIndex) {
276
		case 1:	/* rsa */
277
			document.iform.p1pskey.disabled = 1;
278
			document.iform.p1privatekey.disabled = 0;
279
			document.iform.p1cert.disabled = 0;
280
			document.iform.p1peercert.disabled = 0;
281
			break;
282
		default: /* pre-shared */
283
			document.iform.p1pskey.disabled = 0;
284
			document.iform.p1privatekey.disabled = 1;
285
			document.iform.p1cert.disabled = 1;
286
			document.iform.p1peercert.disabled = 1;
287
			break;
288
	}
289
}
290
//-->
291
</script>
292
<?php if ($input_errors) print_input_errors($input_errors); ?>
293
            <form action="vpn_ipsec_edit.php" method="post" name="iform" id="iform">
294
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
295
                <tr> 
296
                  <td width="22%" valign="top" class="vncellreq">Mode</td>
297
                  <td width="78%" class="vtable"> Tunnel</td>
298
                </tr>
299
				<tr> 
300
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
301
                  <td width="78%" class="vtable"> 
302
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
303
                    <strong>Disable this tunnel</strong><br>
304
                    <span class="vexpl">Set this option to disable this tunnel without
305
					removing it from the list.</span></td>
306
                </tr>
307
		<tr> 
308
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
309
                  <td width="78%" class="vtable"><select name="interface" class="formfld">
310
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
311
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
312
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
313
					  }
314
					  foreach ($interfaces as $iface => $ifacename): ?>
315
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
316
                      <?=htmlspecialchars($ifacename);?>
317
                      </option>
318
                      <?php endforeach; ?>
319
                    </select> <br>
320
                    <span class="vexpl">Select the interface for the local endpoint of this tunnel.</span></td>
321
                </tr>
322
                <tr> 
323
                  <td width="22%" valign="top" class="vncellreq">Local subnet</td>
324
                  <td width="78%" class="vtable"> 
325
                    <table border="0" cellspacing="0" cellpadding="0">
326
                      <tr> 
327
                        <td>Type:&nbsp;&nbsp;</td>
328
						<td></td>
329
                        <td><select name="localnettype" class="formfld" onChange="typesel_change()">
330
                            <?php $sel = is_specialnet($pconfig['localnet']); ?>
331
                            <option value="single" <?php if (($pconfig['localnetmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>> 
332
                            Single host</option>
333
                            <option value="network" <?php if (!$sel) echo "selected"; ?>> 
334
                            Network</option>
335
                            <option value="lan" <?php if ($pconfig['localnet'] == "lan") { echo "selected"; } ?>> 
336
                            LAN subnet</option>
337
                          </select></td>
338
                      </tr>
339
                      <tr> 
340
                        <td>Address:&nbsp;&nbsp;</td>
341
						<td><?=$mandfldhtmlspc;?></td>
342
                        <td><input name="localnet" type="text" class="formfld" id="localnet" size="20" value="<?php if (!is_specialnet($pconfig['localnet'])) echo htmlspecialchars($pconfig['localnet']);?>">
343
                          / 
344
                          <select name="localnetmask" class="formfld" id="localnetmask">
345
                            <?php for ($i = 31; $i >= 0; $i--): ?>
346
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['localnetmask']) echo "selected"; ?>>
347
                            <?=$i;?>
348
                            </option>
349
                            <?php endfor; ?>
350
                          </select> </td>
351
                      </tr>
352
                    </table></td>
353
                </tr>
354
                <tr> 
355
                  <td width="22%" valign="top" class="vncellreq">Remote subnet</td>
356
                  <td width="78%" class="vtable"> 
357
                    <?=$mandfldhtml;?><input name="remotenet" type="text" class="formfld" id="remotenet" size="20" value="<?=$pconfig['remotenet'];?>">
358
                    / 
359
                    <select name="remotebits" class="formfld" id="remotebits">
360
                      <?php for ($i = 32; $i >= 0; $i--): ?>
361
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['remotebits']) echo "selected"; ?>> 
362
                      <?=$i;?>
363
                      </option>
364
                      <?php endfor; ?>
365
                    </select></td>
366
                </tr>
367
                <tr> 
368
                  <td width="22%" valign="top" class="vncellreq">Remote gateway</td>
369
                  <td width="78%" class="vtable"> 
370
                    <?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld" id="remotegw" size="20" value="<?=$pconfig['remotegw'];?>"> 
371
                    <br>
372
                    Enter the public IP address of the remote gateway</td>
373
                </tr>
374
                <tr> 
375
                  <td width="22%" valign="top" class="vncell">Description</td>
376
                  <td width="78%" class="vtable"> 
377
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> 
378
                    <br> <span class="vexpl">You may enter a description here 
379
                    for your reference (not parsed).</span></td>
380
                </tr>
381
                <tr> 
382
                  <td colspan="2" class="list" height="12"></td>
383
                </tr>
384
                <tr> 
385
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal 
386
                    (Authentication)</td>
387
                </tr>
388
                <tr> 
389
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
390
                  <td width="78%" class="vtable">
391
					<select name="p1mode" class="formfld">
392
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
393
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>> 
394
                      <?=htmlspecialchars($mode);?>
395
                      </option>
396
                      <?php endforeach; ?>
397
                    </select> <br> <span class="vexpl">Aggressive is faster, but 
398
                    less secure.</span></td>
399
                </tr>
400
                <tr> 
401
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
402
                  <td width="78%" class="vtable">
403
					<select name="p1myidentt" class="formfld">
404
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
405
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>> 
406
                      <?=htmlspecialchars($modename);?>
407
                      </option>
408
                      <?php endforeach; ?>
409
                    </select> <input name="p1myident" type="text" class="formfld" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>"> 
410
                  </td>
411
                </tr>
412
                <tr> 
413
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
414
                  <td width="78%" class="vtable">
415
					<select name="p1ealgo" class="formfld">
416
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
417
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>> 
418
                      <?=htmlspecialchars($algoname);?>
419
                      </option>
420
                      <?php endforeach; ?>
421
                    </select> <br> <span class="vexpl">Must match the setting 
422
                    chosen on the remote side. </span></td>
423
                </tr>
424
                <tr> 
425
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
426
                  <td width="78%" class="vtable">
427
					<select name="p1halgo" class="formfld">
428
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
429
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>> 
430
                      <?=htmlspecialchars($algoname);?>
431
                      </option>
432
                      <?php endforeach; ?>
433
                    </select> <br> <span class="vexpl">Must match the setting 
434
                    chosen on the remote side. </span></td>
435
                </tr>
436
                <tr> 
437
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
438
                  <td width="78%" class="vtable">
439
					<select name="p1dhgroup" class="formfld">
440
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
441
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>> 
442
                      <?=htmlspecialchars($keygroup);?>
443
                      </option>
444
                      <?php endforeach; ?>
445
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
446
                    bit, 5 = 1536 bit</em><br>
447
                    Must match the setting chosen on the remote side. </span></td>
448
                </tr>
449
                <tr> 
450
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
451
                  <td width="78%" class="vtable"> 
452
                    <input name="p1lifetime" type="text" class="formfld" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
453
                    seconds</td>
454
                </tr>
455
                <tr> 
456
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
457
                  <td width="78%" class="vtable">
458
					<select name="p1authentication_method" class="formfld" onChange="methodsel_change()">
459
                      <?php foreach ($p1_authentication_methods as $method => $methodname): ?>
460
                      <option value="<?=$method;?>" <?php if ($method == $pconfig['p1authentication_method']) echo "selected"; ?>> 
461
                      <?=htmlspecialchars($methodname);?>
462
                      </option>
463
                      <?php endforeach; ?>
464
                    </select> <br> <span class="vexpl">Must match the setting 
465
                    chosen on the remote side.</span></td>
466
                </tr>
467
                <tr> 
468
                  <td width="22%" valign="top" class="vncellreq">Pre-Shared Key</td>
469
                  <td width="78%" class="vtable"> 
470
                    <?=$mandfldhtml;?><input name="p1pskey" type="text" class="formfld" id="p1pskey" size="40" value="<?=htmlspecialchars($pconfig['p1pskey']);?>"> 
471
                  </td>
472
                </tr>
473
                <tr> 
474
                  <td width="22%" valign="top" class="vncellreq">Certificate</td>
475
                  <td width="78%" class="vtable"> 
476
                    <textarea name="p1cert" cols="65" rows="7" id="p1cert" class="formpre"><?=htmlspecialchars($pconfig['p1cert']);?></textarea>
477
                    <br> 
478
                    Paste a certificate in X.509 PEM format here.</td>
479
                </tr>
480
                <tr> 
481
                  <td width="22%" valign="top" class="vncellreq">Key</td>
482
                  <td width="78%" class="vtable"> 
483
                    <textarea name="p1privatekey" cols="65" rows="7" id="p1privatekey" class="formpre"><?=htmlspecialchars($pconfig['p1privatekey']);?></textarea>
484
                    <br> 
485
                    Paste an RSA private key in PEM format here.</td>
486
                </tr>
487
                <tr> 
488
                  <td width="22%" valign="top" class="vncell">Peer certificate</td>
489
                  <td width="78%" class="vtable"> 
490
                    <textarea name="p1peercert" cols="65" rows="7" id="p1peercert" class="formpre"><?=htmlspecialchars($pconfig['p1peercert']);?></textarea>
491
                    <br> 
492
                    Paste the peer X.509 certificate in PEM format here.<br>
493
                    Leave this blank if you want to use a CA certificate for identity validation.</td>
494
                </tr>
495
                <tr> 
496
                  <td colspan="2" class="list" height="12"></td>
497
                </tr>
498
                <tr> 
499
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal 
500
                    (SA/Key Exchange)</td>
501
                </tr>
502
                <tr> 
503
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
504
                  <td width="78%" class="vtable">
505
					<select name="p2proto" class="formfld">
506
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
507
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>> 
508
                      <?=htmlspecialchars($protoname);?>
509
                      </option>
510
                      <?php endforeach; ?>
511
                    </select> <br> <span class="vexpl">ESP is encryption, AH is 
512
                    authentication only </span></td>
513
                </tr>
514
                <tr> 
515
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
516
                  <td width="78%" class="vtable"> 
517
                    <?php foreach ($p2_ealgos as $algo => $algoname): ?>
518
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>> 
519
                    <?=htmlspecialchars($algoname);?>
520
                    <br> 
521
                    <?php endforeach; ?>
522
                    <br>
523
                    Hint: use 3DES for best compatibility or if you have a hardware 
524
                    crypto accelerator card. Blowfish is usually the fastest in 
525
                    software encryption. </td>
526
                </tr>
527
                <tr> 
528
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
529
                  <td width="78%" class="vtable"> 
530
                    <?php foreach ($p2_halgos as $algo => $algoname): ?>
531
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>> 
532
                    <?=htmlspecialchars($algoname);?>
533
                    <br> 
534
                    <?php endforeach; ?>
535
				  </td>
536
                </tr>
537
                <tr> 
538
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
539
                  <td width="78%" class="vtable">
540
					<select name="p2pfsgroup" class="formfld">
541
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
542
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>> 
543
                      <?=htmlspecialchars($keygroupname);?>
544
                      </option>
545
                      <?php endforeach; ?>
546
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
547
                    bit, 5 = 1536 bit</em></span></td>
548
                </tr>
549
                <tr> 
550
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
551
                  <td width="78%" class="vtable"> 
552
                    <input name="p2lifetime" type="text" class="formfld" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
553
                    seconds</td>
554
                </tr>
555
                <tr> 
556
                  <td colspan="2" class="list" height="12"></td>
557
                </tr>
558
                <tr> 
559
                  <td colspan="2" valign="top" class="listtopic">Keep alive</td>
560
                </tr>
561
                <tr> 
562
                  <td width="22%" valign="top" class="vncell">Automatically ping host</td>
563
                  <td width="78%" class="vtable"> 
564
                    <input name="pinghost" type="text" class="formfld" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>"></td>
565
                </tr>		
566
                <tr> 
567
                  <td width="22%" valign="top">&nbsp;</td>
568
                  <td width="78%"> 
569
                    <input name="Submit" type="submit" class="formbtn" value="Save"> 
570
                    <?php if (isset($id) && $a_ipsec[$id]): ?>
571
                    <input name="id" type="hidden" value="<?=$id;?>"> 
572
                    <?php endif; ?>
573
                  </td>
574
                </tr>
575
              </table>
576
</form>
577
<script language="JavaScript">
578
<!--
579
typesel_change();
580
methodsel_change();
581
//-->
582
</script>
583
<?php include("fend.inc"); ?>
584

    
585

    
586
<?php
587

    
588
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
589

    
590
        if ($adr['network'])
591
                $padr = $adr['network'];
592
        else if ($adr['address']) {
593
                list($padr, $pmask) = explode("/", $adr['address']);
594
                if (is_null($pmask))
595
                        $pmask = 32;
596
        }
597
}
598

    
599
?>
(143-143/164)