Project

General

Profile

Download (27.3 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
	
94
} else {
95
	/* defaults */
96
	$pconfig['interface'] = "wan";
97
	$pconfig['localnet'] = "lan";
98
	$pconfig['p1mode'] = "aggressive";
99
	$pconfig['p1myidentt'] = "myaddress";
100
	$pconfig['p1authentication_method'] = "pre_shared_key";
101
	$pconfig['p1ealgo'] = "3des";
102
	$pconfig['p1halgo'] = "sha1";
103
	$pconfig['p1dhgroup'] = "2";
104
	$pconfig['p2proto'] = "esp";
105
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael");
106
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
107
	$pconfig['p2pfsgroup'] = "0";
108
	$pconfig['remotebits'] = 32;
109
}
110

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

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

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

    
247
?>
248

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

    
573

    
574
<?php
575

    
576
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
577

    
578
        if ($adr['network'])
579
                $padr = $adr['network'];
580
        else if ($adr['address']) {
581
                list($padr, $pmask) = explode("/", $adr['address']);
582
                if (is_null($pmask))
583
                        $pmask = 32;
584
        }
585
}
586

    
587
?>
(134-134/155)