Project

General

Profile

Download (21 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_phase2.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2008 Shrew Soft Inc
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
##|+PRIV
33
##|*IDENT=page-vpn-ipsec-editphase2
34
##|*NAME=VPN: IPsec: Edit Phase 2 page
35
##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 2' page.
36
##|*MATCH=vpn_ipsec_phase2.php*
37
##|-PRIV
38

    
39
require("functions.inc");
40
require("guiconfig.inc");
41
require_once("ipsec.inc");
42
require_once("vpn.inc");
43

    
44
if (!is_array($config['ipsec']['client']))
45
	$config['ipsec']['client'] = array();
46

    
47
$a_client = &$config['ipsec']['client'];
48

    
49
if (!is_array($config['ipsec']['phase2']))
50
	$config['ipsec']['phase2'] = array();
51

    
52
$a_phase2 = &$config['ipsec']['phase2'];
53

    
54
$p2index = $_GET['p2index'];
55
if (isset($_POST['p2index']))
56
	$p2index = $_POST['p2index'];
57

    
58
if (isset($_GET['dup']))
59
	$p2index = $_GET['dup'];
60

    
61
if (isset($p2index) && $a_phase2[$p2index])
62
{
63
	$pconfig['ikeid'] = $a_phase2[$p2index]['ikeid'];
64
	$pconfig['disabled'] = isset($a_phase2[$p2index]['disabled']);
65
	$pconfig['mode'] = $a_phase2[$p2index]['mode'];
66
	$pconfig['descr'] = $a_phase2[$p2index]['descr'];
67
	$old_ph2ent = $a_phase2[$p2index];
68

    
69
	idinfo_to_pconfig("local",$a_phase2[$p2index]['localid'],$pconfig);
70
	idinfo_to_pconfig("remote",$a_phase2[$p2index]['remoteid'],$pconfig);
71

    
72
	$pconfig['proto'] = $a_phase2[$p2index]['protocol'];
73
	ealgos_to_pconfig($a_phase2[$p2index]['encryption-algorithm-option'],$pconfig);
74
	$pconfig['halgos'] = $a_phase2[$p2index]['hash-algorithm-option'];
75
	$pconfig['pfsgroup'] = $a_phase2[$p2index]['pfsgroup'];
76
	$pconfig['lifetime'] = $a_phase2[$p2index]['lifetime'];
77
	$pconfig['pinghost'] = $a_phase2[$p2index]['pinghost'];
78

    
79
	if (isset($a_phase2[$p2index]['mobile']))
80
		$pconfig['mobile'] = true;
81
}
82
else
83
{
84
	$pconfig['ikeid'] = $_GET['ikeid'];
85

    
86
	/* defaults */
87
	$pconfig['localid_type'] = "lan";
88
	$pconfig['remoteid_type'] = "network";
89
	$pconfig['proto'] = "esp";
90
	$pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes");
91
	$pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5");
92
	$pconfig['pfsgroup'] = "0";
93
	$pconfig['lifetime'] = "3600";
94

    
95
    /* mobile client */
96
    if($_GET['mobile'])
97
        $pconfig['mobile']=true;
98
}
99

    
100
if (isset($_GET['dup']))
101
	unset($p2index);
102

    
103
if ($_POST) {
104

    
105
	unset($input_errors);
106
	$pconfig = $_POST;
107

    
108
	if (!isset( $_POST['ikeid']))
109
		$input_errors[] = "A valid ikeid must be specified.";
110

    
111
	/* input validation */
112
	$reqdfields = explode(" ", "localid_type halgos");
113
	$reqdfieldsn = explode(",", "Local network type,P2 Hash Algorithms");
114
	if (!isset($pconfig['mobile'])){
115
		$reqdfields[] = "remoteid_type";
116
		$reqdfieldsn[] = "Remote network type";
117
	}
118

    
119
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
120

    
121
	if($pconfig['mode'] == "tunnel")
122
	{
123
		switch ($pconfig['localid_type']) {
124
			case "network":
125
				if (($pconfig['localid_netbits'] != 0 && !$pconfig['localid_netbits']) || !is_numeric($pconfig['localid_netbits']))
126
					$input_errors[] = "A valid local network bit count must be specified.";
127
			case "address":
128
				if (!$pconfig['localid_address'] || !is_ipaddr($pconfig['localid_address']))
129
					$input_errors[] = "A valid local network IP address must be specified.";
130
				break;
131
		}
132

    
133
		switch ($pconfig['remoteid_type']) {
134
			case "network":
135
				if (($pconfig['remoteid_netbits'] != 0 && !$pconfig['remoteid_netbits']) || !is_numeric($pconfig['remoteid_netbits']))
136
					$input_errors[] = "A valid remote network bit count must be specified.";
137
			case "address":
138
				if (!$pconfig['remoteid_address'] || !is_ipaddr($pconfig['remoteid_address']))
139
					$input_errors[] = "A valid remote network IP address must be specified.";
140
				break;
141
		}
142
	}
143

    
144
/* TODO : Validate enabled phase2's are not duplicates */
145

    
146
	$ealgos = pconfig_to_ealgos($pconfig);
147

    
148
	if (!count($ealgos)) {
149
		$input_errors[] = "At least one encryption algorithm must be selected.";
150
	}
151
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
152
		$input_errors[] = "The P2 lifetime must be an integer.";
153
	}
154

    
155
	if (!$input_errors) {
156

    
157
		$ph2ent['ikeid'] = $pconfig['ikeid'];
158
		$ph2ent['mode'] = $pconfig['mode'];
159
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
160

    
161
		if($ph2ent['mode'] == "tunnel") {
162
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
163
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
164
		}
165

    
166
		$ph2ent['protocol'] = $pconfig['proto'];
167
		$ph2ent['encryption-algorithm-option'] = $ealgos;
168
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
169
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
170
		$ph2ent['lifetime'] = $pconfig['lifetime'];
171
		$ph2ent['pinghost'] = $pconfig['pinghost'];
172
		$ph2ent['descr'] = $pconfig['descr'];
173

    
174
		if (isset($pconfig['mobile']))
175
			$ph2ent['mobile'] = true;
176

    
177
		if (isset($p2index) && $a_phase2[$p2index])
178
			$a_phase2[$p2index] = $ph2ent;
179
		else
180
			$a_phase2[] = $ph2ent;
181

    
182

    
183
		/* now we need to find all phase2 entries for this host */
184
		if(is_array($ph2ent)) {
185
			ipsec_lookup_phase1($ph2ent, $ph1ent);
186
			$old_ph1ent = $ph1ent;
187
			reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent);
188
		}
189

    
190
		write_config();
191
		mark_subsystem_dirty('ipsec');
192

    
193
		header("Location: vpn_ipsec.php");
194
		exit;
195
	}
196
}
197

    
198
if ($pconfig['mobile'])
199
    $pgtitle = array("VPN","IPsec","Edit Phase 2", "Mobile Client");
200
else
201
    $pgtitle = array("VPN","IPsec","Edit Phase 2");
202

    
203
include("head.inc");
204

    
205
?>
206

    
207
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
208
<?php include("fbegin.inc"); ?>
209
<script language="JavaScript">
210
<!--
211

    
212
function change_mode() {
213
	index = document.iform.mode.selectedIndex;
214
	value = document.iform.mode.options[index].value;
215
	if (value == 'tunnel') {
216
		document.getElementById('opt_localid').style.display = '';
217
		document.getElementById('opt_remoteid').style.display = '';
218
	} else {
219
		document.getElementById('opt_localid').style.display = 'none';
220
		document.getElementById('opt_remoteid').style.display = 'none';
221
	}
222
}
223

    
224
function typesel_change_local(bits) {
225

    
226
	if (typeof(bits)=="undefined")
227
		bits = 24;
228

    
229
	switch (document.iform.localid_type.selectedIndex) {
230
		case 0:	/* single */
231
			document.iform.localid_address.disabled = 0;
232
			document.iform.localid_netbits.value = 0;
233
			document.iform.localid_netbits.disabled = 1;
234
			break;
235
		case 1:	/* network */
236
			document.iform.localid_address.disabled = 0;
237
			document.iform.localid_netbits.value = bits;
238
			document.iform.localid_netbits.disabled = 0;
239
			break;
240
		case 3:	/* none */
241
			document.iform.localid_address.disabled = 1;
242
			document.iform.localid_netbits.disabled = 1;
243
			break;
244
		default:
245
			document.iform.localid_address.value = "";
246
			document.iform.localid_address.disabled = 1;
247
			document.iform.localid_netbits.value = 0;
248
			document.iform.localid_netbits.disabled = 1;
249
			break;
250
	}
251
}
252

    
253
<?php if (isset($pconfig['mobile'])): ?>
254

    
255
function typesel_change_remote(bits) {
256

    
257
	document.iform.remoteid_address.disabled = 1;
258
	document.iform.remoteid_netbits.disabled = 1;
259
}
260

    
261
<?php else: ?>
262

    
263
function typesel_change_remote(bits) {
264

    
265
	if (typeof(bits)=="undefined")
266
		bits = 24;
267

    
268
	switch (document.iform.remoteid_type.selectedIndex) {
269
		case 0:	/* single */
270
			document.iform.remoteid_address.disabled = 0;
271
			document.iform.remoteid_netbits.value = 0;
272
			document.iform.remoteid_netbits.disabled = 1;
273
			break;
274
		case 1:	/* network */
275
			document.iform.remoteid_address.disabled = 0;
276
			document.iform.remoteid_netbits.value = bits;
277
			document.iform.remoteid_netbits.disabled = 0;
278
			break;
279
		default:
280
			document.iform.remoteid_address.value = "";
281
			document.iform.remoteid_address.disabled = 1;
282
			document.iform.remoteid_netbits.value = 0;
283
			document.iform.remoteid_netbits.disabled = 1;
284
			break;
285
	}
286
}
287

    
288
<?php endif; ?>
289

    
290
function change_protocol() {
291
	index = document.iform.proto.selectedIndex;
292
	value = document.iform.proto.options[index].value;
293
	if (value == 'esp')
294
		document.getElementById('opt_enc').style.display = '';
295
	else
296
		document.getElementById('opt_enc').style.display = 'none';
297
}
298

    
299
//-->
300
</script>
301

    
302
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
303

    
304
<?php
305
	if ($input_errors)
306
		print_input_errors($input_errors);
307
?>
308

    
309
<table width="100%" border="0" cellpadding="0" cellspacing="0">
310
	<tr class="tabnavtbl">
311
		<td id="tabnav">
312
			<?php
313
				$tab_array = array();
314
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
315
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
316
				$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
317
				$tab_array[3] = array("Logs", false, "diag_logs_ipsec.php");
318
				display_top_tabs($tab_array);
319
			?>
320
		</td>
321
	</tr>
322
	<tr>
323
		<td id="mainarea">
324
			<div class="tabcont">
325
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
326
					<tr>
327
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
328
						<td width="78%" class="vtable">
329
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
330
							<strong>Disable this phase2 entry</strong>
331
							<br>
332
							<span class="vexpl">Set this option to disable this phase2 entry without
333
							  removing it from the list.
334
							</span>
335
						</td>
336
					</tr>
337
					<tr>
338
						<td width="22%" valign="top" class="vncellreq">Mode</td>
339
						<td width="78%" class="vtable">
340
							<select name="mode" class="formselect" onChange="change_mode()">
341
								<?php
342
									foreach($p2_modes as $name => $value):
343
										$selected = "";
344
										if ($name == $pconfig['mode'])
345
											$selected = "selected";
346
								?>
347
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
348
								<?php endforeach; ?>
349
							</select>
350
						</td>
351
					</tr>
352
					<tr id="opt_localid">
353
						<td width="22%" valign="top" class="vncellreq">Local Network</td>
354
						<td width="78%" class="vtable">
355
							<table border="0" cellspacing="0" cellpadding="0">
356
								<tr>
357
									<td>Type:&nbsp;&nbsp;</td>
358
									<td></td>
359
									<td>
360
										<select name="localid_type" class="formselect" onChange="typesel_change_local()">
361
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>>Address</option>
362
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>>Network</option>
363
											<option value="lan" <?php if ($pconfig['localid_type'] == "lan" ) echo "selected";?>>LAN subnet</option>
364
											<option value="none" <?php if ($pconfig['localid_type'] == "none" ) echo "selected";?>>None</option>
365
										</select>
366
									</td>
367
								</tr>
368
								<tr>
369
									<td>Address:&nbsp;&nbsp;</td>
370
									<td><?=$mandfldhtmlspc;?></td>
371
									<td>
372
										<input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=$pconfig['localid_address'];?>">
373
										/
374
										<select name="localid_netbits" class="formselect" id="localid_netbits">
375
										<?php for ($i = 32; $i >= 0; $i--): ?>
376
											<option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
377
												<?=$i;?>
378
											</option>
379
										<?php endfor; ?>
380
										</select>
381
									</td>
382
								</tr>
383
							</table>
384
						</td>
385
					</tr>
386

    
387
					<?php if (!isset($pconfig['mobile'])): ?>
388
					
389
					<tr id="opt_remoteid">
390
						<td width="22%" valign="top" class="vncellreq">Remote Network</td>
391
						<td width="78%" class="vtable">
392
							<table border="0" cellspacing="0" cellpadding="0">
393
								<tr>
394
									<td>Type:&nbsp;&nbsp;</td>
395
									<td></td>
396
									<td>
397
										<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
398
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>>Address</option>
399
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>>Network</option>
400
										</select>
401
									</td>
402
								</tr>
403
								<tr>
404
									<td>Address:&nbsp;&nbsp;</td>
405
									<td><?=$mandfldhtmlspc;?></td>
406
									<td>
407
										<input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=$pconfig['remoteid_address'];?>">
408
										/
409
										<select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
410
										<?php for ($i = 32; $i >= 0; $i--) { 
411
											
412
											echo "<option value=\"{$i}\"";
413
											if ($i == $pconfig['remoteid_netbits']) echo " selected";
414
											echo ">{$i}</option>\n";
415
											} ?>
416
										</select>
417
									</td>
418
								</tr>
419
							</table>
420
						</td>
421
					</tr>
422
					
423
					<?php endif; ?>
424
					
425
					<tr>
426
						<td width="22%" valign="top" class="vncell">Description</td>
427
						<td width="78%" class="vtable">
428
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
429
							<br>
430
							<span class="vexpl">
431
								You may enter a description here
432
								for your reference (not parsed).
433
							</span>
434
						</td>
435
					</tr>
436
					<tr>
437
						<td colspan="2" class="list" height="12"></td>
438
					</tr>
439
					<tr>
440
						<td colspan="2" valign="top" class="listtopic">
441
							Phase 2 proposal (SA/Key Exchange)
442
						</td>
443
					</tr>
444
					<tr>
445
						<td width="22%" valign="top" class="vncellreq">Protocol</td>
446
						<td width="78%" class="vtable">
447
							<select name="proto" class="formselect" onChange="change_protocol()">
448
							<?php foreach ($p2_protos as $proto => $protoname): ?>
449
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
450
									<?=htmlspecialchars($protoname);?>
451
								</option>
452
							<?php endforeach; ?>
453
							</select>
454
							<br>
455
							<span class="vexpl">
456
								ESP is encryption, AH is authentication only
457
							</span>
458
						</td>
459
					</tr>
460
					<tr id="opt_enc">
461
						<td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
462
						<td width="78%" class="vtable">
463
							<table border="0" cellspacing="0" cellpadding="0">
464
							<?php
465
								foreach ($p2_ealgos as $algo => $algodata):
466
									$checked = '';
467
									if (in_array($algo,$pconfig['ealgos']))
468
										$checked = " checked";
469
								?>
470
								<tr>
471
									<td>
472
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?>>
473
									</td>
474
									<td>
475
										<?=htmlspecialchars($algodata['name']);?>
476
									</td>
477
									<td>
478
										<?php if(is_array($algodata['keysel'])): ?>
479
										&nbsp;&nbsp;
480
										<select name="keylen_<?=$algo;?>" class="formselect">
481
											<option value="auto">auto</option>
482
											<?php
483
												$key_hi = $algodata['keysel']['hi'];
484
												$key_lo = $algodata['keysel']['lo'];
485
												$key_step = $algodata['keysel']['step'];
486
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
487
													$selected = '';
488
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
489
													if ($keylen == $pconfig["keylen_".$algo])
490
														$selected = " selected";
491
											?>
492
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> bits</option>
493
											<?php endfor; ?>
494
										</select>
495
										<?php endif; ?>
496
									</td>
497
								</tr>
498
								
499
								<?php endforeach; ?>
500
								
501
							</table>
502
							<br>
503
							Hint: use 3DES for best compatibility or if you have a hardware
504
							crypto accelerator card. Blowfish is usually the fastest in
505
							software encryption.
506
						</td>
507
					</tr>
508
					<tr>
509
						<td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
510
						<td width="78%" class="vtable">
511
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
512
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
513
							<?=htmlspecialchars($algoname);?>
514
							<br>
515
						<?php endforeach; ?>
516
						</td>
517
					</tr>
518
					<tr>
519
						<td width="22%" valign="top" class="vncellreq">PFS key group</td>
520
						<td width="78%" class="vtable">
521
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
522
							<select name="pfsgroup" class="formselect">
523
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
524
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
525
									<?=htmlspecialchars($keygroupname);?>
526
								</option>
527
							<?php endforeach; ?>
528
							</select>
529
							<br>
530
							<span class="vexpl">
531
								<em>
532
									1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit
533
								</em>
534
							</span>
535
							
536
							<?php else: ?>
537

    
538
							<select class="formselect" disabled>
539
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
540
							</select>
541
							<input name="pfsgroup" type="hidden" value="<?=$pconfig['pfsgroup'];?>">
542
							<br>
543
							<span class="vexpl"><em>Set globally in mobile client options</em></span>
544
						<?php endif; ?>
545
						</td>
546
					</tr>
547
					<tr>
548
						<td width="22%" valign="top" class="vncell">Lifetime</td>
549
						<td width="78%" class="vtable">
550
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
551
							seconds
552
						</td>
553
					</tr>
554
					<tr>
555
						<td colspan="2" class="list" height="12"></td>
556
					</tr>
557
					<tr>
558
						<td colspan="2" valign="top" class="listtopic">Advanced Options</td>
559
					</tr>
560
					<tr>
561
						<td width="22%" valign="top" class="vncell">Automatically ping host</td>
562
						<td width="78%" class="vtable">
563
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>">
564
							IP address
565
						</td>
566
					</tr>
567
					<tr>
568
						<td width="22%" valign="top">&nbsp;</td>
569
						<td width="78%">
570
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
571
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
572
						<?php endif; ?>
573
						<?php if ($pconfig['mobile']): ?>
574
							<input name="mobile" type="hidden" value="true">
575
							<input name="remoteid_type" type="hidden" value="mobile">
576
						<?php endif; ?>
577
							<input name="Submit" type="submit" class="formbtn" value="Save">
578
							<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
579
						</td>
580
					</tr>
581
				</table>
582
			</div>
583
		</td>
584
	</tr>
585
</table>
586
</form>
587
<script lannguage="JavaScript">
588
<!--
589
change_mode('<?=$pconfig['mode']?>');
590
change_protocol('<?=$pconfig['proto']?>');
591
typesel_change_local(<?=$pconfig['localid_netbits']?>);
592
typesel_change_remote(<?=$pconfig['remoteid_netbits']?>);
593
//-->
594
</script>
595
<?php include("fend.inc"); ?>
596
</body>
597
</html>
598

    
599
<?php
600

    
601
/* local utility functions */
602

    
603
function pconfig_to_ealgos(& $pconfig) {
604

    
605
	global $p2_ealgos;
606

    
607
	$ealgos = array();
608
	foreach ($p2_ealgos as $algo_name => $algo_data) {
609
		if (in_array($algo_name,$pconfig['ealgos'])) {
610
			$ealg = array();
611
			$ealg['name'] = $algo_name;
612
			if (is_array($algo_data['keysel']))
613
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
614
			$ealgos[] = $ealg;
615
		}
616
	}
617

    
618
	return $ealgos;
619
}
620

    
621
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
622

    
623
	$pconfig['ealgos'] = array();
624
	foreach ($ealgos as $algo_data) {
625
		$pconfig['ealgos'][] = $algo_data['name'];
626
		if (isset($algo_data['keylen']))
627
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
628
	}
629

    
630
	return $ealgos;
631
}
632

    
633
function pconfig_to_idinfo($prefix,& $pconfig) {
634

    
635
	$type = $pconfig[$prefix."id_type"];
636
	$address = $pconfig[$prefix."id_address"];
637
	$netbits = $pconfig[$prefix."id_netbits"];
638

    
639
	switch( $type )
640
	{
641
		case "address":
642
			return array('type' => $type, 'address' => $address);
643
		case "network":
644
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
645
		default:
646
			return array('type' => $type );
647
	}
648
}
649

    
650
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
651

    
652
	switch( $idinfo['type'] )
653
	{
654
		case "address":
655
			$pconfig[$prefix."id_type"] = $idinfo['type'];
656
			$pconfig[$prefix."id_address"] = $idinfo['address'];
657
			break;
658
		case "network":
659
			$pconfig[$prefix."id_type"] = $idinfo['type'];
660
			$pconfig[$prefix."id_address"] = $idinfo['address'];
661
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
662
			break;
663
		default:
664
			$pconfig[$prefix."id_type"] = $idinfo['type'];
665
			break;
666
	}
667
}
668

    
669
?>
670

    
(204-204/218)