Project

General

Profile

Download (26.4 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
		/* Check if the localid_type is an interface, to confirm if it has a valid subnet. */
134
		if (is_array($config['interfaces'][$pconfig['localid_type']])) {
135
			// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
136
			$address = get_interface_ip($pconfig['localid_type']);
137
			$netbits = get_interface_subnet($pconfig['localid_type']);
138

    
139
			if (empty($address) || empty($netbits))
140
				$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['localid_type']) . " " . gettext("has no subnet.");
141
		}
142

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

    
213
	if (!count($ealgos)) {
214
		$input_errors[] = gettext("At least one encryption algorithm must be selected.");
215
	}
216
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
217
		$input_errors[] = gettext("The P2 lifetime must be an integer.");
218
	}
219

    
220
	if (!$input_errors) {
221

    
222
		$ph2ent['ikeid'] = $pconfig['ikeid'];
223
		$ph2ent['mode'] = $pconfig['mode'];
224
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
225

    
226
		if(($ph2ent['mode'] == "tunnel") || ($ph2ent['mode'] == "tunnel6")){
227
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
228
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
229
		}
230

    
231
		$ph2ent['protocol'] = $pconfig['proto'];
232
		$ph2ent['encryption-algorithm-option'] = $ealgos;
233
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
234
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
235
		$ph2ent['lifetime'] = $pconfig['lifetime'];
236
		$ph2ent['pinghost'] = $pconfig['pinghost'];
237
		$ph2ent['descr'] = $pconfig['descr'];
238

    
239
		if (isset($pconfig['mobile']))
240
			$ph2ent['mobile'] = true;
241

    
242
		if (isset($p2index) && $a_phase2[$p2index])
243
			$a_phase2[$p2index] = $ph2ent;
244
		else
245
			$a_phase2[] = $ph2ent;
246

    
247

    
248
		/* now we need to find all phase2 entries for this host */
249
		if(is_array($ph2ent)) {
250
			ipsec_lookup_phase1($ph2ent, $ph1ent);
251
			$old_ph1ent = $ph1ent;
252
			$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
253
			reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent);
254
		}
255

    
256
		write_config();
257
		mark_subsystem_dirty('ipsec');
258

    
259
		header("Location: vpn_ipsec.php");
260
		exit;
261
	}
262
}
263

    
264
if ($pconfig['mobile'])
265
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
266
else
267
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
268
$statusurl = "diag_ipsec.php";
269
$logurl = "diag_logs_ipsec.php";
270

    
271

    
272
include("head.inc");
273

    
274
?>
275

    
276
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
277
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
278
<?php include("fbegin.inc"); ?>
279
<script language="JavaScript">
280
<!--
281

    
282
function change_mode() {
283
	index = document.iform.mode.selectedIndex;
284
	value = document.iform.mode.options[index].value;
285
	if ((value == 'tunnel') || (value == 'tunnel6')) {
286
		document.getElementById('opt_localid').style.display = '';
287
<?php if (!isset($pconfig['mobile'])): ?>
288
		document.getElementById('opt_remoteid').style.display = '';
289
<?php endif; ?>
290
	} else {
291
		document.getElementById('opt_localid').style.display = 'none';
292
<?php if (!isset($pconfig['mobile'])): ?>
293
		document.getElementById('opt_remoteid').style.display = 'none';
294
<?php endif; ?>
295
	}
296
}
297

    
298
function typesel_change_local(bits) {
299
	var value = document.iform.mode.options[index].value;
300
	if (typeof(bits) === "undefined") {
301
		if (value === "tunnel") {
302
			bits = 24;
303
		}
304
		else if (value === "tunnel6") {
305
			bits = 64;
306
		}
307
	}
308
	var address_is_blank = !/\S/.test(document.iform.localid_address.value);
309
	switch (document.iform.localid_type.selectedIndex) {
310
		case 0:	/* single */
311
			document.iform.localid_address.disabled = 0;
312
			if (address_is_blank) {
313
				document.iform.localid_netbits.value = 0;
314
			}
315
			document.iform.localid_netbits.disabled = 1;
316
			break;
317
		case 1:	/* network */
318
			document.iform.localid_address.disabled = 0;
319
			if (address_is_blank) {
320
				document.iform.localid_netbits.value = bits;
321
			}
322
			document.iform.localid_netbits.disabled = 0;
323
			break;
324
		case 3:	/* none */
325
			document.iform.localid_address.disabled = 1;
326
			document.iform.localid_netbits.disabled = 1;
327
			break;
328
		default:
329
			document.iform.localid_address.value = "";
330
			document.iform.localid_address.disabled = 1;
331
			if (address_is_blank) {
332
				document.iform.localid_netbits.value = 0;
333
			}
334
			document.iform.localid_netbits.disabled = 1;
335
			break;
336
	}
337
}
338

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

    
341
function typesel_change_remote(bits) {
342
	var value = document.iform.mode.options[index].value;
343
	if (typeof(bits) === "undefined") {
344
		if (value === "tunnel") {
345
			bits = 24;
346
		}
347
		else if (value === "tunnel6") {
348
			bits = 64;
349
		}
350
	}
351
	var address_is_blank = !/\S/.test(document.iform.remoteid_address.value);
352
	switch (document.iform.remoteid_type.selectedIndex) {
353
		case 0:	/* single */
354
			document.iform.remoteid_address.disabled = 0;
355
			if (address_is_blank) {
356
				document.iform.remoteid_netbits.value = 0;
357
			}
358
			document.iform.remoteid_netbits.disabled = 1;
359
			break;
360
		case 1:	/* network */
361
			document.iform.remoteid_address.disabled = 0;
362
			if (address_is_blank) {
363
				document.iform.remoteid_netbits.value = bits;
364
			}
365
			document.iform.remoteid_netbits.disabled = 0;
366
			break;
367
		default:
368
			document.iform.remoteid_address.value = "";
369
			document.iform.remoteid_address.disabled = 1;
370
			if (address_is_blank) {
371
				document.iform.remoteid_netbits.value = 0;
372
			}
373
			document.iform.remoteid_netbits.disabled = 1;
374
			break;
375
	}
376
}
377

    
378
<?php endif; ?>
379

    
380
function change_protocol() {
381
	index = document.iform.proto.selectedIndex;
382
	value = document.iform.proto.options[index].value;
383
	if (value == 'esp')
384
		document.getElementById('opt_enc').style.display = '';
385
	else
386
		document.getElementById('opt_enc').style.display = 'none';
387
}
388

    
389
//-->
390
</script>
391

    
392
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
393

    
394
<?php
395
	if ($input_errors)
396
		print_input_errors($input_errors);
397
?>
398

    
399
<table width="100%" border="0" cellpadding="0" cellspacing="0">
400
	<tr class="tabnavtbl">
401
		<td id="tabnav">
402
			<?php
403
				$tab_array = array();
404
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
405
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
406
				$tab_array[2] = array(gettext("Pre-shared keys"), false, "vpn_ipsec_keys.php");
407
				display_top_tabs($tab_array);
408
			?>
409
		</td>
410
	</tr>
411
	<tr>
412
		<td id="mainarea">
413
			<div class="tabcont">
414
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
415
					<tr>
416
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
417
						<td width="78%" class="vtable">
418
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
419
							<strong><?=gettext("Disable this phase2 entry"); ?></strong>
420
							<br>
421
							<span class="vexpl"><?=gettext("Set this option to disable this phase2 entry without " .
422
							  "removing it from the list"); ?>.
423
							</span>
424
						</td>
425
					</tr>
426
					<tr>
427
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
428
						<td width="78%" class="vtable">
429
							<select name="mode" class="formselect" onChange="change_mode()">
430
								<?php
431
									foreach($p2_modes as $name => $value):
432
										$selected = "";
433
										if ($name == $pconfig['mode'])
434
											$selected = "selected";
435
								?>
436
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
437
								<?php endforeach; ?>
438
							</select>
439
						</td>
440
					</tr>
441
					<tr id="opt_localid">
442
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local Network"); ?></td>
443
						<td width="78%" class="vtable">
444
							<table border="0" cellspacing="0" cellpadding="0">
445
								<tr>
446
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
447
									<td></td>
448
									<td>
449
										<select name="localid_type" class="formselect" onChange="typesel_change_local()">
450
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>><?=gettext("Address"); ?></option>
451
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>><?=gettext("Network"); ?></option>
452
											<?php
453
												$iflist = get_configured_interface_with_descr();
454
												foreach ($iflist as $ifname => $ifdescr):
455
											?>
456
											<option value="<?=$ifname; ?>" <?php if ($pconfig['localid_type'] == $ifname ) echo "selected";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
457
											<?php endforeach; ?>
458
											<option value="none" <?php if ($pconfig['localid_type'] == "none" ) echo "selected";?>><?=gettext("None"); ?></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="localid_address" type="text" class="formfld unknown ipv4v6" id="localid_address" size="28" value="<?=htmlspecialchars($pconfig['localid_address']);?>">
467
										/
468
										<select name="localid_netbits" class="formselect ipv4v6" id="localid_netbits">
469
										<?php for ($i = 128; $i >= 0; $i--): ?>
470
											<option value="<?=$i;?>" <?php if (isset($pconfig['localid_netbits']) && $i == $pconfig['localid_netbits']) echo "selected"; ?>>
471
												<?=$i;?>
472
											</option>
473
										<?php endfor; ?>
474
										</select>
475
									</td>
476
								</tr>
477
							</table>
478
						</td>
479
					</tr>
480

    
481
					<?php if (!isset($pconfig['mobile'])): ?>
482
					
483
					<tr id="opt_remoteid">
484
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote Network"); ?></td>
485
						<td width="78%" class="vtable">
486
							<table border="0" cellspacing="0" cellpadding="0">
487
								<tr>
488
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
489
									<td></td>
490
									<td>
491
										<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
492
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>><?=gettext("Address"); ?></option>
493
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>><?=gettext("Network"); ?></option>
494
										</select>
495
									</td>
496
								</tr>
497
								<tr>
498
									<td><?=gettext("Address"); ?>:&nbsp;&nbsp;</td>
499
									<td><?=$mandfldhtmlspc;?></td>
500
									<td>
501
										<input name="remoteid_address" type="text" class="formfld unknown ipv4v6" id="remoteid_address" size="28" value="<?=htmlspecialchars($pconfig['remoteid_address']);?>">
502
										/
503
										<select name="remoteid_netbits" class="formselect ipv4v6" id="remoteid_netbits">
504
										<?php for ($i = 128; $i >= 0; $i--) { 
505
											
506
											echo "<option value=\"{$i}\"";
507
											if (isset($pconfig['remoteid_netbits']) && $i == $pconfig['remoteid_netbits']) echo " selected";
508
											echo ">{$i}</option>\n";
509
											} ?>
510
										</select>
511
									</td>
512
								</tr>
513
							</table>
514
						</td>
515
					</tr>
516
					
517
					<?php endif; ?>
518
					
519
					<tr>
520
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
521
						<td width="78%" class="vtable">
522
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
523
							<br>
524
							<span class="vexpl">
525
								<?=gettext("You may enter a description here " .
526
								"for your reference (not parsed)"); ?>.
527
							</span>
528
						</td>
529
					</tr>
530
					<tr>
531
						<td colspan="2" class="list" height="12"></td>
532
					</tr>
533
					<tr>
534
						<td colspan="2" valign="top" class="listtopic">
535
							<?=gettext("Phase 2 proposal (SA/Key Exchange)"); ?>
536
						</td>
537
					</tr>
538
					<tr>
539
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
540
						<td width="78%" class="vtable">
541
							<select name="proto" class="formselect" onChange="change_protocol()">
542
							<?php foreach ($p2_protos as $proto => $protoname): ?>
543
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
544
									<?=htmlspecialchars($protoname);?>
545
								</option>
546
							<?php endforeach; ?>
547
							</select>
548
							<br>
549
							<span class="vexpl">
550
								<?=gettext("ESP is encryption, AH is authentication only"); ?>
551
							</span>
552
						</td>
553
					</tr>
554
					<tr id="opt_enc">
555
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithms"); ?></td>
556
						<td width="78%" class="vtable">
557
							<table border="0" cellspacing="0" cellpadding="0">
558
							<?php
559
								foreach ($p2_ealgos as $algo => $algodata):
560
									$checked = '';
561
									if (in_array($algo,$pconfig['ealgos']))
562
										$checked = " checked";
563
								?>
564
								<tr>
565
									<td>
566
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?>>
567
									</td>
568
									<td>
569
										<?=htmlspecialchars($algodata['name']);?>
570
									</td>
571
									<td>
572
										<?php if(is_array($algodata['keysel'])): ?>
573
										&nbsp;&nbsp;
574
										<select name="keylen_<?=$algo;?>" class="formselect">
575
											<option value="auto"><?=gettext("auto"); ?></option>
576
											<?php
577
												$key_hi = $algodata['keysel']['hi'];
578
												$key_lo = $algodata['keysel']['lo'];
579
												$key_step = $algodata['keysel']['step'];
580
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
581
													$selected = '';
582
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
583
													if ($keylen == $pconfig["keylen_".$algo])
584
														$selected = " selected";
585
											?>
586
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> <?=gettext("bits"); ?></option>
587
											<?php endfor; ?>
588
										</select>
589
										<?php endif; ?>
590
									</td>
591
								</tr>
592
								
593
								<?php endforeach; ?>
594
								
595
							</table>
596
							<br>
597
							<?=gettext("Hint: use 3DES for best compatibility or if you have a hardware " . 
598
							"crypto accelerator card. Blowfish is usually the fastest in " .
599
							"software encryption"); ?>.
600
						</td>
601
					</tr>
602
					<tr>
603
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithms"); ?></td>
604
						<td width="78%" class="vtable">
605
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
606
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
607
							<?=htmlspecialchars($algoname);?>
608
							<br>
609
						<?php endforeach; ?>
610
						</td>
611
					</tr>
612
					<tr>
613
						<td width="22%" valign="top" class="vncellreq"><?=gettext("PFS key group"); ?></td>
614
						<td width="78%" class="vtable">
615
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
616
							<select name="pfsgroup" class="formselect">
617
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
618
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
619
									<?=htmlspecialchars($keygroupname);?>
620
								</option>
621
							<?php endforeach; ?>
622
							</select>
623
							<br>
624
							<span class="vexpl">
625
								<em>
626
									<?=gettext("1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit"); ?>
627
								</em>
628
							</span>
629
							
630
							<?php else: ?>
631

    
632
							<select class="formselect" disabled>
633
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
634
							</select>
635
							<input name="pfsgroup" type="hidden" value="<?=htmlspecialchars($pconfig['pfsgroup']);?>">
636
							<br>
637
							<span class="vexpl"><em><?=gettext("Set globally in mobile client options"); ?></em></span>
638
						<?php endif; ?>
639
						</td>
640
					</tr>
641
					<tr>
642
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
643
						<td width="78%" class="vtable">
644
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>">
645
							<?=gettext("seconds"); ?>
646
						</td>
647
					</tr>
648
					<tr>
649
						<td colspan="2" class="list" height="12"></td>
650
					</tr>
651
					<tr>
652
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
653
					</tr>
654
					<tr>
655
						<td width="22%" valign="top" class="vncell"><?=gettext("Automatically ping host"); ?></td>
656
						<td width="78%" class="vtable">
657
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="28" value="<?=htmlspecialchars($pconfig['pinghost']);?>">
658
							<?=gettext("IP address"); ?>
659
						</td>
660
					</tr>
661
					<tr>
662
						<td width="22%" valign="top">&nbsp;</td>
663
						<td width="78%">
664
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
665
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
666
						<?php endif; ?>
667
						<?php if ($pconfig['mobile']): ?>
668
							<input name="mobile" type="hidden" value="true">
669
							<input name="remoteid_type" type="hidden" value="mobile">
670
						<?php endif; ?>
671
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
672
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>">
673
						</td>
674
					</tr>
675
				</table>
676
			</div>
677
		</td>
678
	</tr>
679
</table>
680
</form>
681
<script lannguage="JavaScript">
682
<!--
683
change_mode('<?=htmlspecialchars($pconfig['mode'])?>');
684
change_protocol('<?=htmlspecialchars($pconfig['proto'])?>');
685
typesel_change_local(<?=htmlspecialchars($pconfig['localid_netbits'])?>);
686
<?php if (!isset($pconfig['mobile'])): ?>
687
typesel_change_remote(<?=htmlspecialchars($pconfig['remoteid_netbits'])?>);
688
<?php endif; ?>
689
//-->
690
</script>
691
<?php include("fend.inc"); ?>
692
</body>
693
</html>
694

    
695
<?php
696

    
697
/* local utility functions */
698

    
699
function pconfig_to_ealgos(& $pconfig) {
700

    
701
	global $p2_ealgos;
702

    
703
	$ealgos = array();
704
	foreach ($p2_ealgos as $algo_name => $algo_data) {
705
		if (in_array($algo_name,$pconfig['ealgos'])) {
706
			$ealg = array();
707
			$ealg['name'] = $algo_name;
708
			if (is_array($algo_data['keysel']))
709
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
710
			$ealgos[] = $ealg;
711
		}
712
	}
713

    
714
	return $ealgos;
715
}
716

    
717
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
718

    
719
	$pconfig['ealgos'] = array();
720
	foreach ($ealgos as $algo_data) {
721
		$pconfig['ealgos'][] = $algo_data['name'];
722
		if (isset($algo_data['keylen']))
723
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
724
	}
725

    
726
	return $ealgos;
727
}
728

    
729
function pconfig_to_idinfo($prefix,& $pconfig) {
730

    
731
	$type = $pconfig[$prefix."id_type"];
732
	$address = $pconfig[$prefix."id_address"];
733
	$netbits = $pconfig[$prefix."id_netbits"];
734

    
735
	switch( $type )
736
	{
737
		case "address":
738
			return array('type' => $type, 'address' => $address);
739
		case "network":
740
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
741
		default:
742
			return array('type' => $type );
743
	}
744
}
745

    
746
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
747

    
748
	switch( $idinfo['type'] )
749
	{
750
		case "address":
751
			$pconfig[$prefix."id_type"] = $idinfo['type'];
752
			$pconfig[$prefix."id_address"] = $idinfo['address'];
753
			break;
754
		case "network":
755
			$pconfig[$prefix."id_type"] = $idinfo['type'];
756
			$pconfig[$prefix."id_address"] = $idinfo['address'];
757
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
758
			break;
759
		default:
760
			$pconfig[$prefix."id_type"] = $idinfo['type'];
761
			break;
762
	}
763
}
764

    
765
?>
766

    
(232-232/245)