Project

General

Profile

Download (25 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")
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
	/* Validate enabled phase2's are not duplicates */
144
	if (isset($pconfig['mobile'])){
145
		/* User is adding phase 2 for mobile phase1 */
146
		foreach($a_phase2 as $key => $name){
147
			if (isset($name['mobile'])){
148
				/* check duplicate localids only for mobile clents */
149
				$localid_data = ipsec_idinfo_to_cidr($name['localid']);
150
				$entered = array();
151
				$entered['type'] = $pconfig['localid_type'];
152
				if (isset($pconfig['localid_address'])) $entered['address'] = $pconfig['localid_address'];
153
				if (isset($pconfig['localid_netbits'])) $entered['netbits'] = $pconfig['localid_netbits'];
154
				$entered_localid_data = ipsec_idinfo_to_cidr($entered);
155
				if ($localid_data == $entered_localid_data){
156
					if (!isset($pconfig['p2index'])){
157
						/* adding new p2 entry */
158
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
159
						break;
160
					}else if ($pconfig['p2index'] != $key){
161
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
162
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
163
						break;
164
					}
165
				}
166
			}
167
		}
168
	}else{
169
		/* User is adding phase 2 for site-to-site phase1 */
170
		$input_error = 0;
171
		foreach($a_phase2 as $key => $name){
172
			if (!isset($name['mobile']) && $pconfig['ikeid'] == $name['ikeid']){
173
				/* check duplicate subnets only for given phase1 */
174
				$localid_data = ipsec_idinfo_to_cidr($name['localid']);
175
				$remoteid_data = ipsec_idinfo_to_cidr($name['remoteid']);
176
				$entered_local = array();
177
				$entered_local['type'] = $pconfig['localid_type'];
178
				if (isset($pconfig['localid_address'])) $entered_local['address'] = $pconfig['localid_address'];
179
				if (isset($pconfig['localid_netbits'])) $entered_local['netbits'] = $pconfig['localid_netbits'];
180
				$entered_localid_data = ipsec_idinfo_to_cidr($entered_local);
181
				$entered_remote = array();
182
				$entered_remote['type'] = $pconfig['remoteid_type'];
183
				if (isset($pconfig['remoteid_address'])) $entered_remote['address'] = $pconfig['remoteid_address'];
184
				if (isset($pconfig['remoteid_netbits'])) $entered_remote['netbits'] = $pconfig['remoteid_netbits'];
185
				$entered_remoteid_data = ipsec_idinfo_to_cidr($entered_remote);
186
				if ($localid_data == $entered_localid_data && $remoteid_data == $entered_remoteid_data) { 
187
					if (!isset($pconfig['p2index'])){
188
						/* adding new p2 entry */
189
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
190
						break;
191
					}else if ($pconfig['p2index'] != $key){
192
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
193
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
194
						break;
195
					}
196
				}
197
			}
198
		}
199
        }
200
	
201
	$ealgos = pconfig_to_ealgos($pconfig);
202

    
203
	if (!count($ealgos)) {
204
		$input_errors[] = gettext("At least one encryption algorithm must be selected.");
205
	}
206
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
207
		$input_errors[] = gettext("The P2 lifetime must be an integer.");
208
	}
209

    
210
	if (!$input_errors) {
211

    
212
		$ph2ent['ikeid'] = $pconfig['ikeid'];
213
		$ph2ent['mode'] = $pconfig['mode'];
214
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
215

    
216
		if($ph2ent['mode'] == "tunnel") {
217
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
218
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
219
		}
220

    
221
		$ph2ent['protocol'] = $pconfig['proto'];
222
		$ph2ent['encryption-algorithm-option'] = $ealgos;
223
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
224
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
225
		$ph2ent['lifetime'] = $pconfig['lifetime'];
226
		$ph2ent['pinghost'] = $pconfig['pinghost'];
227
		$ph2ent['descr'] = $pconfig['descr'];
228

    
229
		if (isset($pconfig['mobile']))
230
			$ph2ent['mobile'] = true;
231

    
232
		if (isset($p2index) && $a_phase2[$p2index])
233
			$a_phase2[$p2index] = $ph2ent;
234
		else
235
			$a_phase2[] = $ph2ent;
236

    
237

    
238
		/* now we need to find all phase2 entries for this host */
239
		if(is_array($ph2ent)) {
240
			ipsec_lookup_phase1($ph2ent, $ph1ent);
241
			$old_ph1ent = $ph1ent;
242
			$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
243
			reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent);
244
		}
245

    
246
		write_config();
247
		mark_subsystem_dirty('ipsec');
248

    
249
		header("Location: vpn_ipsec.php");
250
		exit;
251
	}
252
}
253

    
254
if ($pconfig['mobile'])
255
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
256
else
257
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
258
$statusurl = "diag_ipsec.php";
259
$logurl = "diag_logs_ipsec.php";
260

    
261

    
262
include("head.inc");
263

    
264
?>
265

    
266
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
267
<?php include("fbegin.inc"); ?>
268
<script language="JavaScript">
269
<!--
270

    
271
function change_mode() {
272
	index = document.iform.mode.selectedIndex;
273
	value = document.iform.mode.options[index].value;
274
	if (value == 'tunnel') {
275
		document.getElementById('opt_localid').style.display = '';
276
<?php if (!isset($pconfig['mobile'])): ?>
277
		document.getElementById('opt_remoteid').style.display = '';
278
<?php endif; ?>
279
	} else {
280
		document.getElementById('opt_localid').style.display = 'none';
281
<?php if (!isset($pconfig['mobile'])): ?>
282
		document.getElementById('opt_remoteid').style.display = 'none';
283
<?php endif; ?>
284
	}
285
}
286

    
287
function typesel_change_local(bits) {
288

    
289
	if (typeof(bits)=="undefined")
290
		bits = 24;
291

    
292
	switch (document.iform.localid_type.selectedIndex) {
293
		case 0:	/* single */
294
			document.iform.localid_address.disabled = 0;
295
			document.iform.localid_netbits.value = 0;
296
			document.iform.localid_netbits.disabled = 1;
297
			break;
298
		case 1:	/* network */
299
			document.iform.localid_address.disabled = 0;
300
			document.iform.localid_netbits.value = bits;
301
			document.iform.localid_netbits.disabled = 0;
302
			break;
303
		case 3:	/* none */
304
			document.iform.localid_address.disabled = 1;
305
			document.iform.localid_netbits.disabled = 1;
306
			break;
307
		default:
308
			document.iform.localid_address.value = "";
309
			document.iform.localid_address.disabled = 1;
310
			document.iform.localid_netbits.value = 0;
311
			document.iform.localid_netbits.disabled = 1;
312
			break;
313
	}
314
}
315

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

    
318
function typesel_change_remote(bits) {
319

    
320
	if (typeof(bits)=="undefined")
321
		bits = 24;
322

    
323
	switch (document.iform.remoteid_type.selectedIndex) {
324
		case 0:	/* single */
325
			document.iform.remoteid_address.disabled = 0;
326
			document.iform.remoteid_netbits.value = 0;
327
			document.iform.remoteid_netbits.disabled = 1;
328
			break;
329
		case 1:	/* network */
330
			document.iform.remoteid_address.disabled = 0;
331
			document.iform.remoteid_netbits.value = bits;
332
			document.iform.remoteid_netbits.disabled = 0;
333
			break;
334
		default:
335
			document.iform.remoteid_address.value = "";
336
			document.iform.remoteid_address.disabled = 1;
337
			document.iform.remoteid_netbits.value = 0;
338
			document.iform.remoteid_netbits.disabled = 1;
339
			break;
340
	}
341
}
342

    
343
<?php endif; ?>
344

    
345
function change_protocol() {
346
	index = document.iform.proto.selectedIndex;
347
	value = document.iform.proto.options[index].value;
348
	if (value == 'esp')
349
		document.getElementById('opt_enc').style.display = '';
350
	else
351
		document.getElementById('opt_enc').style.display = 'none';
352
}
353

    
354
//-->
355
</script>
356

    
357
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
358

    
359
<?php
360
	if ($input_errors)
361
		print_input_errors($input_errors);
362
?>
363

    
364
<table width="100%" border="0" cellpadding="0" cellspacing="0">
365
	<tr class="tabnavtbl">
366
		<td id="tabnav">
367
			<?php
368
				$tab_array = array();
369
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
370
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
371
				$tab_array[2] = array(gettext("Pre-shared keys"), false, "vpn_ipsec_keys.php");
372
				display_top_tabs($tab_array);
373
			?>
374
		</td>
375
	</tr>
376
	<tr>
377
		<td id="mainarea">
378
			<div class="tabcont">
379
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
380
					<tr>
381
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
382
						<td width="78%" class="vtable">
383
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
384
							<strong><?=gettext("Disable this phase2 entry"); ?></strong>
385
							<br>
386
							<span class="vexpl"><?=gettext("Set this option to disable this phase2 entry without " .
387
							  "removing it from the list"); ?>.
388
							</span>
389
						</td>
390
					</tr>
391
					<tr>
392
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
393
						<td width="78%" class="vtable">
394
							<select name="mode" class="formselect" onChange="change_mode()">
395
								<?php
396
									foreach($p2_modes as $name => $value):
397
										$selected = "";
398
										if ($name == $pconfig['mode'])
399
											$selected = "selected";
400
								?>
401
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
402
								<?php endforeach; ?>
403
							</select>
404
						</td>
405
					</tr>
406
					<tr id="opt_localid">
407
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local Network"); ?></td>
408
						<td width="78%" class="vtable">
409
							<table border="0" cellspacing="0" cellpadding="0">
410
								<tr>
411
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
412
									<td></td>
413
									<td>
414
										<select name="localid_type" class="formselect" onChange="typesel_change_local()">
415
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>><?=gettext("Address"); ?></option>
416
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>><?=gettext("Network"); ?></option>
417
											<?php
418
												$iflist = get_configured_interface_with_descr();
419
												foreach ($iflist as $ifname => $ifdescr):
420
											?>
421
											<option value="<?=$ifname; ?>" <?php if ($pconfig['localid_type'] == $ifname ) echo "selected";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
422
											<?php endforeach; ?>
423
											<option value="none" <?php if ($pconfig['localid_type'] == "none" ) echo "selected";?>><?=gettext("None"); ?></option>
424
										</select>
425
									</td>
426
								</tr>
427
								<tr>
428
									<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
429
									<td><?=$mandfldhtmlspc;?></td>
430
									<td>
431
										<input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=htmlspecialchars($pconfig['localid_address']);?>">
432
										/
433
										<select name="localid_netbits" class="formselect" id="localid_netbits">
434
										<?php for ($i = 32; $i >= 0; $i--): ?>
435
											<option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
436
												<?=$i;?>
437
											</option>
438
										<?php endfor; ?>
439
										</select>
440
									</td>
441
								</tr>
442
							</table>
443
						</td>
444
					</tr>
445

    
446
					<?php if (!isset($pconfig['mobile'])): ?>
447
					
448
					<tr id="opt_remoteid">
449
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote Network"); ?></td>
450
						<td width="78%" class="vtable">
451
							<table border="0" cellspacing="0" cellpadding="0">
452
								<tr>
453
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
454
									<td></td>
455
									<td>
456
										<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
457
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>><?=gettext("Address"); ?></option>
458
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>><?=gettext("Network"); ?></option>
459
										</select>
460
									</td>
461
								</tr>
462
								<tr>
463
									<td><?=gettext("Address"); ?>:&nbsp;&nbsp;</td>
464
									<td><?=$mandfldhtmlspc;?></td>
465
									<td>
466
										<input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=htmlspecialchars($pconfig['remoteid_address']);?>">
467
										/
468
										<select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
469
										<?php for ($i = 32; $i >= 0; $i--) { 
470
											
471
											echo "<option value=\"{$i}\"";
472
											if ($i == $pconfig['remoteid_netbits']) echo " selected";
473
											echo ">{$i}</option>\n";
474
											} ?>
475
										</select>
476
									</td>
477
								</tr>
478
							</table>
479
						</td>
480
					</tr>
481
					
482
					<?php endif; ?>
483
					
484
					<tr>
485
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
486
						<td width="78%" class="vtable">
487
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
488
							<br>
489
							<span class="vexpl">
490
								<?=gettext("You may enter a description here " .
491
								"for your reference (not parsed)"); ?>.
492
							</span>
493
						</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">
500
							<?=gettext("Phase 2 proposal (SA/Key Exchange)"); ?>
501
						</td>
502
					</tr>
503
					<tr>
504
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
505
						<td width="78%" class="vtable">
506
							<select name="proto" class="formselect" onChange="change_protocol()">
507
							<?php foreach ($p2_protos as $proto => $protoname): ?>
508
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
509
									<?=htmlspecialchars($protoname);?>
510
								</option>
511
							<?php endforeach; ?>
512
							</select>
513
							<br>
514
							<span class="vexpl">
515
								<?=gettext("ESP is encryption, AH is authentication only"); ?>
516
							</span>
517
						</td>
518
					</tr>
519
					<tr id="opt_enc">
520
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithms"); ?></td>
521
						<td width="78%" class="vtable">
522
							<table border="0" cellspacing="0" cellpadding="0">
523
							<?php
524
								foreach ($p2_ealgos as $algo => $algodata):
525
									$checked = '';
526
									if (in_array($algo,$pconfig['ealgos']))
527
										$checked = " checked";
528
								?>
529
								<tr>
530
									<td>
531
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?>>
532
									</td>
533
									<td>
534
										<?=htmlspecialchars($algodata['name']);?>
535
									</td>
536
									<td>
537
										<?php if(is_array($algodata['keysel'])): ?>
538
										&nbsp;&nbsp;
539
										<select name="keylen_<?=$algo;?>" class="formselect">
540
											<option value="auto"><?=gettext("auto"); ?></option>
541
											<?php
542
												$key_hi = $algodata['keysel']['hi'];
543
												$key_lo = $algodata['keysel']['lo'];
544
												$key_step = $algodata['keysel']['step'];
545
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
546
													$selected = '';
547
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
548
													if ($keylen == $pconfig["keylen_".$algo])
549
														$selected = " selected";
550
											?>
551
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> <?=gettext("bits"); ?></option>
552
											<?php endfor; ?>
553
										</select>
554
										<?php endif; ?>
555
									</td>
556
								</tr>
557
								
558
								<?php endforeach; ?>
559
								
560
							</table>
561
							<br>
562
							<?=gettext("Hint: use 3DES for best compatibility or if you have a hardware " . 
563
							"crypto accelerator card. Blowfish is usually the fastest in " .
564
							"software encryption"); ?>.
565
						</td>
566
					</tr>
567
					<tr>
568
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithms"); ?></td>
569
						<td width="78%" class="vtable">
570
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
571
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
572
							<?=htmlspecialchars($algoname);?>
573
							<br>
574
						<?php endforeach; ?>
575
						</td>
576
					</tr>
577
					<tr>
578
						<td width="22%" valign="top" class="vncellreq"><?=gettext("PFS key group"); ?></td>
579
						<td width="78%" class="vtable">
580
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
581
							<select name="pfsgroup" class="formselect">
582
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
583
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
584
									<?=htmlspecialchars($keygroupname);?>
585
								</option>
586
							<?php endforeach; ?>
587
							</select>
588
							<br>
589
							<span class="vexpl">
590
								<em>
591
									<?=gettext("1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit"); ?>
592
								</em>
593
							</span>
594
							
595
							<?php else: ?>
596

    
597
							<select class="formselect" disabled>
598
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
599
							</select>
600
							<input name="pfsgroup" type="hidden" value="<?=htmlspecialchars($pconfig['pfsgroup']);?>">
601
							<br>
602
							<span class="vexpl"><em><?=gettext("Set globally in mobile client options"); ?></em></span>
603
						<?php endif; ?>
604
						</td>
605
					</tr>
606
					<tr>
607
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
608
						<td width="78%" class="vtable">
609
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>">
610
							<?=gettext("seconds"); ?>
611
						</td>
612
					</tr>
613
					<tr>
614
						<td colspan="2" class="list" height="12"></td>
615
					</tr>
616
					<tr>
617
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
618
					</tr>
619
					<tr>
620
						<td width="22%" valign="top" class="vncell"><?=gettext("Automatically ping host"); ?></td>
621
						<td width="78%" class="vtable">
622
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=htmlspecialchars($pconfig['pinghost']);?>">
623
							<?=gettext("IP address"); ?>
624
						</td>
625
					</tr>
626
					<tr>
627
						<td width="22%" valign="top">&nbsp;</td>
628
						<td width="78%">
629
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
630
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
631
						<?php endif; ?>
632
						<?php if ($pconfig['mobile']): ?>
633
							<input name="mobile" type="hidden" value="true">
634
							<input name="remoteid_type" type="hidden" value="mobile">
635
						<?php endif; ?>
636
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
637
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>">
638
						</td>
639
					</tr>
640
				</table>
641
			</div>
642
		</td>
643
	</tr>
644
</table>
645
</form>
646
<script lannguage="JavaScript">
647
<!--
648
change_mode('<?=htmlspecialchars($pconfig['mode'])?>');
649
change_protocol('<?=htmlspecialchars($pconfig['proto'])?>');
650
typesel_change_local(<?=htmlspecialchars($pconfig['localid_netbits'])?>);
651
<?php if (!isset($pconfig['mobile'])): ?>
652
typesel_change_remote(<?=htmlspecialchars($pconfig['remoteid_netbits'])?>);
653
<?php endif; ?>
654
//-->
655
</script>
656
<?php include("fend.inc"); ?>
657
</body>
658
</html>
659

    
660
<?php
661

    
662
/* local utility functions */
663

    
664
function pconfig_to_ealgos(& $pconfig) {
665

    
666
	global $p2_ealgos;
667

    
668
	$ealgos = array();
669
	foreach ($p2_ealgos as $algo_name => $algo_data) {
670
		if (in_array($algo_name,$pconfig['ealgos'])) {
671
			$ealg = array();
672
			$ealg['name'] = $algo_name;
673
			if (is_array($algo_data['keysel']))
674
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
675
			$ealgos[] = $ealg;
676
		}
677
	}
678

    
679
	return $ealgos;
680
}
681

    
682
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
683

    
684
	$pconfig['ealgos'] = array();
685
	foreach ($ealgos as $algo_data) {
686
		$pconfig['ealgos'][] = $algo_data['name'];
687
		if (isset($algo_data['keylen']))
688
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
689
	}
690

    
691
	return $ealgos;
692
}
693

    
694
function pconfig_to_idinfo($prefix,& $pconfig) {
695

    
696
	$type = $pconfig[$prefix."id_type"];
697
	$address = $pconfig[$prefix."id_address"];
698
	$netbits = $pconfig[$prefix."id_netbits"];
699

    
700
	switch( $type )
701
	{
702
		case "address":
703
			return array('type' => $type, 'address' => $address);
704
		case "network":
705
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
706
		default:
707
			return array('type' => $type );
708
	}
709
}
710

    
711
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
712

    
713
	switch( $idinfo['type'] )
714
	{
715
		case "address":
716
			$pconfig[$prefix."id_type"] = $idinfo['type'];
717
			$pconfig[$prefix."id_address"] = $idinfo['address'];
718
			break;
719
		case "network":
720
			$pconfig[$prefix."id_type"] = $idinfo['type'];
721
			$pconfig[$prefix."id_address"] = $idinfo['address'];
722
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
723
			break;
724
		default:
725
			$pconfig[$prefix."id_type"] = $idinfo['type'];
726
			break;
727
	}
728
}
729

    
730
?>
731

    
(215-215/228)