Project

General

Profile

Download (22.5 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[] = gettext("A valid ikeid must be specified.");
110

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

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

    
121
	if(($pconfig['mode'] == "tunnel") || ($pconfig['mode'] == "tunnel6")) 
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[] = gettext("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[] = gettext("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[] = gettext("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[] = gettext("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[] = gettext("At least one encryption algorithm must be selected.");
150
	}
151
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
152
		$input_errors[] = gettext("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") || ($ph2ent['mode'] == "tunnel6")){
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
			$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
188
			reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent);
189
		}
190

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

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

    
199
if ($pconfig['mobile'])
200
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
201
else
202
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
203
$statusurl = "diag_ipsec.php";
204
$logurl = "diag_logs_ipsec.php";
205

    
206

    
207
include("head.inc");
208

    
209
?>
210

    
211
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
212
<?php include("fbegin.inc"); ?>
213
<script language="JavaScript">
214
<!--
215

    
216
function change_mode() {
217
	index = document.iform.mode.selectedIndex;
218
	value = document.iform.mode.options[index].value;
219
	if ((value == 'tunnel') || (value == 'tunnel6')) {
220
		document.getElementById('opt_localid').style.display = '';
221
<?php if (!isset($pconfig['mobile'])): ?>
222
		document.getElementById('opt_remoteid').style.display = '';
223
<?php endif; ?>
224
	} else {
225
		document.getElementById('opt_localid').style.display = 'none';
226
<?php if (!isset($pconfig['mobile'])): ?>
227
		document.getElementById('opt_remoteid').style.display = 'none';
228
<?php endif; ?>
229
	}
230
}
231

    
232
function typesel_change_local(bits) {
233

    
234
	if (typeof(bits)=="undefined") {
235
		if (value == 'tunnel') {
236
			bits = 24;
237
		}
238
		if (value == 'tunnel6') {
239
			bits = 64;
240
		}
241
	}
242

    
243
	switch (document.iform.localid_type.selectedIndex) {
244
		case 0:	/* single */
245
			document.iform.localid_address.disabled = 0;
246
			document.iform.localid_netbits.value = 0;
247
			document.iform.localid_netbits.disabled = 1;
248
			break;
249
		case 1:	/* network */
250
			document.iform.localid_address.disabled = 0;
251
			document.iform.localid_netbits.value = bits;
252
			document.iform.localid_netbits.disabled = 0;
253
			break;
254
		case 3:	/* none */
255
			document.iform.localid_address.disabled = 1;
256
			document.iform.localid_netbits.disabled = 1;
257
			break;
258
		default:
259
			document.iform.localid_address.value = "";
260
			document.iform.localid_address.disabled = 1;
261
			document.iform.localid_netbits.value = 0;
262
			document.iform.localid_netbits.disabled = 1;
263
			break;
264
	}
265
}
266

    
267
<?php if (!isset($pconfig['mobile'])): ?>
268

    
269
function typesel_change_remote(bits) {
270

    
271
	if (typeof(bits)=="undefined") {
272
		if (value == 'tunnel') {
273
			bits = 24;
274
		}
275
		if (value == 'tunnel6') {
276
			bits = 64;
277
		}
278
	}
279

    
280
	switch (document.iform.remoteid_type.selectedIndex) {
281
		case 0:	/* single */
282
			document.iform.remoteid_address.disabled = 0;
283
			document.iform.remoteid_netbits.value = 0;
284
			document.iform.remoteid_netbits.disabled = 1;
285
			break;
286
		case 1:	/* network */
287
			document.iform.remoteid_address.disabled = 0;
288
			document.iform.remoteid_netbits.value = bits;
289
			document.iform.remoteid_netbits.disabled = 0;
290
			break;
291
		default:
292
			document.iform.remoteid_address.value = "";
293
			document.iform.remoteid_address.disabled = 1;
294
			document.iform.remoteid_netbits.value = 0;
295
			document.iform.remoteid_netbits.disabled = 1;
296
			break;
297
	}
298
}
299

    
300
<?php endif; ?>
301

    
302
function change_protocol() {
303
	index = document.iform.proto.selectedIndex;
304
	value = document.iform.proto.options[index].value;
305
	if (value == 'esp')
306
		document.getElementById('opt_enc').style.display = '';
307
	else
308
		document.getElementById('opt_enc').style.display = 'none';
309
}
310

    
311
//-->
312
</script>
313

    
314
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
315

    
316
<?php
317
	if ($input_errors)
318
		print_input_errors($input_errors);
319
?>
320

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

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

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

    
617
<?php
618

    
619
/* local utility functions */
620

    
621
function pconfig_to_ealgos(& $pconfig) {
622

    
623
	global $p2_ealgos;
624

    
625
	$ealgos = array();
626
	foreach ($p2_ealgos as $algo_name => $algo_data) {
627
		if (in_array($algo_name,$pconfig['ealgos'])) {
628
			$ealg = array();
629
			$ealg['name'] = $algo_name;
630
			if (is_array($algo_data['keysel']))
631
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
632
			$ealgos[] = $ealg;
633
		}
634
	}
635

    
636
	return $ealgos;
637
}
638

    
639
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
640

    
641
	$pconfig['ealgos'] = array();
642
	foreach ($ealgos as $algo_data) {
643
		$pconfig['ealgos'][] = $algo_data['name'];
644
		if (isset($algo_data['keylen']))
645
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
646
	}
647

    
648
	return $ealgos;
649
}
650

    
651
function pconfig_to_idinfo($prefix,& $pconfig) {
652

    
653
	$type = $pconfig[$prefix."id_type"];
654
	$address = $pconfig[$prefix."id_address"];
655
	$netbits = $pconfig[$prefix."id_netbits"];
656

    
657
	switch( $type )
658
	{
659
		case "address":
660
			return array('type' => $type, 'address' => $address);
661
		case "network":
662
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
663
		default:
664
			return array('type' => $type );
665
	}
666
}
667

    
668
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
669

    
670
	switch( $idinfo['type'] )
671
	{
672
		case "address":
673
			$pconfig[$prefix."id_type"] = $idinfo['type'];
674
			$pconfig[$prefix."id_address"] = $idinfo['address'];
675
			break;
676
		case "network":
677
			$pconfig[$prefix."id_type"] = $idinfo['type'];
678
			$pconfig[$prefix."id_address"] = $idinfo['address'];
679
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
680
			break;
681
		default:
682
			$pconfig[$prefix."id_type"] = $idinfo['type'];
683
			break;
684
	}
685
}
686

    
687
?>
688

    
(218-218/231)