Project

General

Profile

Download (21 KB) Statistics
| Branch: | Tag: | Revision:
1 a93e56c5 Matthew Grooms
<?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 6b07c15a Matthew Grooms
##|+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 0f84b741 Scott Ullrich
require("functions.inc");
40 a93e56c5 Matthew Grooms
require("guiconfig.inc");
41 483e6de8 Scott Ullrich
require_once("ipsec.inc");
42
require_once("vpn.inc");
43 a93e56c5 Matthew Grooms
44 3462a529 Matthew Grooms
if (!is_array($config['ipsec']['client']))
45
	$config['ipsec']['client'] = array();
46
47
$a_client = &$config['ipsec']['client'];
48
49 a93e56c5 Matthew Grooms
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 4b96b367 mgrooms
	$pconfig['mode'] = $a_phase2[$p2index]['mode'];
66 a93e56c5 Matthew Grooms
	$pconfig['descr'] = $a_phase2[$p2index]['descr'];
67 e92fb875 Seth Mos
	$old_ph2ent = $a_phase2[$p2index];
68 a93e56c5 Matthew Grooms
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 87e07f52 mgrooms
	$pconfig['pinghost'] = $a_phase2[$p2index]['pinghost'];
78 3462a529 Matthew Grooms
79
	if (isset($a_phase2[$p2index]['mobile']))
80
		$pconfig['mobile'] = true;
81 a93e56c5 Matthew Grooms
}
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 3462a529 Matthew Grooms
95
    /* mobile client */
96
    if($_GET['mobile'])
97
        $pconfig['mobile']=true;
98 a93e56c5 Matthew Grooms
}
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 3462a529 Matthew Grooms
	$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 a93e56c5 Matthew Grooms
119
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
120
121 4b96b367 mgrooms
	if($pconfig['mode'] == "tunnel")
122
	{
123
		switch ($pconfig['localid_type']) {
124
			case "network":
125 184d50b5 Ermal Lu?i
				if (($pconfig['localid_netbits'] != 0 && !$pconfig['localid_netbits']) || !is_numeric($pconfig['localid_netbits']))
126 27e9e518 Chris Buechler
					$input_errors[] = "A valid local network bit count must be specified.";
127 4b96b367 mgrooms
			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 a93e56c5 Matthew Grooms
133 4b96b367 mgrooms
		switch ($pconfig['remoteid_type']) {
134
			case "network":
135 184d50b5 Ermal Lu?i
				if (($pconfig['remoteid_netbits'] != 0 && !$pconfig['remoteid_netbits']) || !is_numeric($pconfig['remoteid_netbits']))
136 27e9e518 Chris Buechler
					$input_errors[] = "A valid remote network bit count must be specified.";
137 4b96b367 mgrooms
			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 a93e56c5 Matthew Grooms
	}
143
144
/* TODO : Validate enabled phase2's are not duplicates */
145
146 3462a529 Matthew Grooms
	$ealgos = pconfig_to_ealgos($pconfig);
147
148 a93e56c5 Matthew Grooms
	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 3462a529 Matthew Grooms
157
		$ph2ent['ikeid'] = $pconfig['ikeid'];
158 4b96b367 mgrooms
		$ph2ent['mode'] = $pconfig['mode'];
159 3462a529 Matthew Grooms
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
160
161 4b96b367 mgrooms
		if($ph2ent['mode'] == "tunnel") {
162
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
163
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
164
		}
165 3462a529 Matthew Grooms
166
		$ph2ent['protocol'] = $pconfig['proto'];
167 a93e56c5 Matthew Grooms
		$ph2ent['encryption-algorithm-option'] = $ealgos;
168 3462a529 Matthew Grooms
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
169
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
170
		$ph2ent['lifetime'] = $pconfig['lifetime'];
171 87e07f52 mgrooms
		$ph2ent['pinghost'] = $pconfig['pinghost'];
172 3462a529 Matthew Grooms
		$ph2ent['descr'] = $pconfig['descr'];
173
174
		if (isset($pconfig['mobile']))
175
			$ph2ent['mobile'] = true;
176 a93e56c5 Matthew Grooms
177
		if (isset($p2index) && $a_phase2[$p2index])
178
			$a_phase2[$p2index] = $ph2ent;
179
		else
180
			$a_phase2[] = $ph2ent;
181
182 e92fb875 Seth Mos
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 a93e56c5 Matthew Grooms
		write_config();
191 a368a026 Ermal Lu?i
		mark_subsystem_dirty('ipsec');
192 a93e56c5 Matthew Grooms
193
		header("Location: vpn_ipsec.php");
194
		exit;
195
	}
196
}
197
198 3462a529 Matthew Grooms
if ($pconfig['mobile'])
199
    $pgtitle = array("VPN","IPsec","Edit Phase 2", "Mobile Client");
200
else
201
    $pgtitle = array("VPN","IPsec","Edit Phase 2");
202 6deedfde jim-p
$statusurl = "diag_ipsec.php";
203
$logurl = "diag_logs_ipsec.php";
204
205 3462a529 Matthew Grooms
206 a93e56c5 Matthew Grooms
include("head.inc");
207
208
?>
209
210
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
211
<?php include("fbegin.inc"); ?>
212
<script language="JavaScript">
213
<!--
214 4b96b367 mgrooms
215
function change_mode() {
216
	index = document.iform.mode.selectedIndex;
217
	value = document.iform.mode.options[index].value;
218
	if (value == 'tunnel') {
219
		document.getElementById('opt_localid').style.display = '';
220
		document.getElementById('opt_remoteid').style.display = '';
221
	} else {
222
		document.getElementById('opt_localid').style.display = 'none';
223
		document.getElementById('opt_remoteid').style.display = 'none';
224
	}
225
}
226
227 a93e56c5 Matthew Grooms
function typesel_change_local(bits) {
228
229 744187e8 pierrepomes
	if (typeof(bits)=="undefined")
230 a93e56c5 Matthew Grooms
		bits = 24;
231
232
	switch (document.iform.localid_type.selectedIndex) {
233
		case 0:	/* single */
234
			document.iform.localid_address.disabled = 0;
235
			document.iform.localid_netbits.value = 0;
236
			document.iform.localid_netbits.disabled = 1;
237
			break;
238
		case 1:	/* network */
239
			document.iform.localid_address.disabled = 0;
240
			document.iform.localid_netbits.value = bits;
241
			document.iform.localid_netbits.disabled = 0;
242
			break;
243 63017a73 Ermal Lu?i
		case 3:	/* none */
244
			document.iform.localid_address.disabled = 1;
245
			document.iform.localid_netbits.disabled = 1;
246
			break;
247 a93e56c5 Matthew Grooms
		default:
248
			document.iform.localid_address.value = "";
249
			document.iform.localid_address.disabled = 1;
250
			document.iform.localid_netbits.value = 0;
251
			document.iform.localid_netbits.disabled = 1;
252
			break;
253
	}
254
}
255 3462a529 Matthew Grooms
256
<?php if (isset($pconfig['mobile'])): ?>
257
258
function typesel_change_remote(bits) {
259
260
	document.iform.remoteid_address.disabled = 1;
261
	document.iform.remoteid_netbits.disabled = 1;
262
}
263
264
<?php else: ?>
265
266 a93e56c5 Matthew Grooms
function typesel_change_remote(bits) {
267
268 744187e8 pierrepomes
	if (typeof(bits)=="undefined")
269 a93e56c5 Matthew Grooms
		bits = 24;
270
271
	switch (document.iform.remoteid_type.selectedIndex) {
272
		case 0:	/* single */
273
			document.iform.remoteid_address.disabled = 0;
274
			document.iform.remoteid_netbits.value = 0;
275
			document.iform.remoteid_netbits.disabled = 1;
276
			break;
277
		case 1:	/* network */
278
			document.iform.remoteid_address.disabled = 0;
279
			document.iform.remoteid_netbits.value = bits;
280
			document.iform.remoteid_netbits.disabled = 0;
281
			break;
282
		default:
283
			document.iform.remoteid_address.value = "";
284
			document.iform.remoteid_address.disabled = 1;
285
			document.iform.remoteid_netbits.value = 0;
286
			document.iform.remoteid_netbits.disabled = 1;
287
			break;
288
	}
289
}
290 3462a529 Matthew Grooms
291
<?php endif; ?>
292
293 4b96b367 mgrooms
function change_protocol() {
294 87e07f52 mgrooms
	index = document.iform.proto.selectedIndex;
295
	value = document.iform.proto.options[index].value;
296
	if (value == 'esp')
297
		document.getElementById('opt_enc').style.display = '';
298
	else
299
		document.getElementById('opt_enc').style.display = 'none';
300
}
301
302 a93e56c5 Matthew Grooms
//-->
303
</script>
304 5a3b0d3b mgrooms
305
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
306
307
<?php
308
	if ($input_errors)
309
		print_input_errors($input_errors);
310
?>
311
312
<table width="100%" border="0" cellpadding="0" cellspacing="0">
313
	<tr class="tabnavtbl">
314
		<td id="tabnav">
315
			<?php
316
				$tab_array = array();
317
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
318
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
319 6894b25a jim-p
				$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
320 5a3b0d3b mgrooms
				display_top_tabs($tab_array);
321
			?>
322
		</td>
323
	</tr>
324
	<tr>
325
		<td id="mainarea">
326
			<div class="tabcont">
327
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
328
					<tr>
329
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
330
						<td width="78%" class="vtable">
331
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
332
							<strong>Disable this phase2 entry</strong>
333
							<br>
334
							<span class="vexpl">Set this option to disable this phase2 entry without
335
							  removing it from the list.
336
							</span>
337
						</td>
338
					</tr>
339
					<tr>
340 4b96b367 mgrooms
						<td width="22%" valign="top" class="vncellreq">Mode</td>
341
						<td width="78%" class="vtable">
342
							<select name="mode" class="formselect" onChange="change_mode()">
343
								<?php
344
									foreach($p2_modes as $name => $value):
345
										$selected = "";
346
										if ($name == $pconfig['mode'])
347
											$selected = "selected";
348
								?>
349
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
350
								<?php endforeach; ?>
351
							</select>
352
						</td>
353
					</tr>
354
					<tr id="opt_localid">
355 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Local Network</td>
356
						<td width="78%" class="vtable">
357
							<table border="0" cellspacing="0" cellpadding="0">
358
								<tr>
359
									<td>Type:&nbsp;&nbsp;</td>
360
									<td></td>
361
									<td>
362
										<select name="localid_type" class="formselect" onChange="typesel_change_local()">
363
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>>Address</option>
364
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>>Network</option>
365
											<option value="lan" <?php if ($pconfig['localid_type'] == "lan" ) echo "selected";?>>LAN subnet</option>
366 63017a73 Ermal Lu?i
											<option value="none" <?php if ($pconfig['localid_type'] == "none" ) echo "selected";?>>None</option>
367 5a3b0d3b mgrooms
										</select>
368
									</td>
369
								</tr>
370
								<tr>
371
									<td>Address:&nbsp;&nbsp;</td>
372
									<td><?=$mandfldhtmlspc;?></td>
373
									<td>
374
										<input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=$pconfig['localid_address'];?>">
375
										/
376
										<select name="localid_netbits" class="formselect" id="localid_netbits">
377
										<?php for ($i = 32; $i >= 0; $i--): ?>
378
											<option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
379
												<?=$i;?>
380
											</option>
381
										<?php endfor; ?>
382
										</select>
383
									</td>
384
								</tr>
385
							</table>
386
						</td>
387
					</tr>
388
389
					<?php if (!isset($pconfig['mobile'])): ?>
390
					
391 4b96b367 mgrooms
					<tr id="opt_remoteid">
392 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Remote Network</td>
393
						<td width="78%" class="vtable">
394
							<table border="0" cellspacing="0" cellpadding="0">
395
								<tr>
396
									<td>Type:&nbsp;&nbsp;</td>
397
									<td></td>
398
									<td>
399
										<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
400
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>>Address</option>
401
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>>Network</option>
402
										</select>
403
									</td>
404
								</tr>
405
								<tr>
406
									<td>Address:&nbsp;&nbsp;</td>
407
									<td><?=$mandfldhtmlspc;?></td>
408
									<td>
409
										<input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=$pconfig['remoteid_address'];?>">
410
										/
411
										<select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
412 184d50b5 Ermal Lu?i
										<?php for ($i = 32; $i >= 0; $i--) { 
413
											
414
											echo "<option value=\"{$i}\"";
415
											if ($i == $pconfig['remoteid_netbits']) echo " selected";
416
											echo ">{$i}</option>\n";
417
											} ?>
418 5a3b0d3b mgrooms
										</select>
419
									</td>
420
								</tr>
421
							</table>
422 a93e56c5 Matthew Grooms
						</td>
423 5a3b0d3b mgrooms
					</tr>
424
					
425 3462a529 Matthew Grooms
					<?php endif; ?>
426 5a3b0d3b mgrooms
					
427
					<tr>
428
						<td width="22%" valign="top" class="vncell">Description</td>
429
						<td width="78%" class="vtable">
430
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
431
							<br>
432
							<span class="vexpl">
433
								You may enter a description here
434
								for your reference (not parsed).
435
							</span>
436
						</td>
437
					</tr>
438
					<tr>
439
						<td colspan="2" class="list" height="12"></td>
440
					</tr>
441
					<tr>
442
						<td colspan="2" valign="top" class="listtopic">
443
							Phase 2 proposal (SA/Key Exchange)
444
						</td>
445
					</tr>
446
					<tr>
447
						<td width="22%" valign="top" class="vncellreq">Protocol</td>
448
						<td width="78%" class="vtable">
449 4b96b367 mgrooms
							<select name="proto" class="formselect" onChange="change_protocol()">
450 5a3b0d3b mgrooms
							<?php foreach ($p2_protos as $proto => $protoname): ?>
451
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
452
									<?=htmlspecialchars($protoname);?>
453
								</option>
454
							<?php endforeach; ?>
455
							</select>
456
							<br>
457
							<span class="vexpl">
458
								ESP is encryption, AH is authentication only
459
							</span>
460
						</td>
461
					</tr>
462 87e07f52 mgrooms
					<tr id="opt_enc">
463 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
464
						<td width="78%" class="vtable">
465
							<table border="0" cellspacing="0" cellpadding="0">
466
							<?php
467
								foreach ($p2_ealgos as $algo => $algodata):
468
									$checked = '';
469
									if (in_array($algo,$pconfig['ealgos']))
470
										$checked = " checked";
471
								?>
472
								<tr>
473
									<td>
474
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?>>
475
									</td>
476
									<td>
477
										<?=htmlspecialchars($algodata['name']);?>
478
									</td>
479
									<td>
480
										<?php if(is_array($algodata['keysel'])): ?>
481
										&nbsp;&nbsp;
482
										<select name="keylen_<?=$algo;?>" class="formselect">
483
											<option value="auto">auto</option>
484
											<?php
485
												$key_hi = $algodata['keysel']['hi'];
486
												$key_lo = $algodata['keysel']['lo'];
487
												$key_step = $algodata['keysel']['step'];
488
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
489
													$selected = '';
490
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
491
													if ($keylen == $pconfig["keylen_".$algo])
492
														$selected = " selected";
493
											?>
494
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> bits</option>
495
											<?php endfor; ?>
496
										</select>
497
										<?php endif; ?>
498
									</td>
499
								</tr>
500
								
501
								<?php endforeach; ?>
502
								
503
							</table>
504
							<br>
505
							Hint: use 3DES for best compatibility or if you have a hardware
506
							crypto accelerator card. Blowfish is usually the fastest in
507
							software encryption.
508
						</td>
509
					</tr>
510
					<tr>
511
						<td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
512
						<td width="78%" class="vtable">
513
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
514
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
515
							<?=htmlspecialchars($algoname);?>
516
							<br>
517
						<?php endforeach; ?>
518
						</td>
519
					</tr>
520
					<tr>
521
						<td width="22%" valign="top" class="vncellreq">PFS key group</td>
522
						<td width="78%" class="vtable">
523
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
524
							<select name="pfsgroup" class="formselect">
525
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
526
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
527
									<?=htmlspecialchars($keygroupname);?>
528
								</option>
529
							<?php endforeach; ?>
530
							</select>
531
							<br>
532
							<span class="vexpl">
533
								<em>
534
									1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit
535
								</em>
536
							</span>
537
							
538
							<?php else: ?>
539
540
							<select class="formselect" disabled>
541
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
542
							</select>
543
							<input name="pfsgroup" type="hidden" value="<?=$pconfig['pfsgroup'];?>">
544
							<br>
545
							<span class="vexpl"><em>Set globally in mobile client options</em></span>
546
						<?php endif; ?>
547
						</td>
548
					</tr>
549
					<tr>
550
						<td width="22%" valign="top" class="vncell">Lifetime</td>
551
						<td width="78%" class="vtable">
552
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
553
							seconds
554
						</td>
555
					</tr>
556 87e07f52 mgrooms
					<tr>
557
						<td colspan="2" class="list" height="12"></td>
558
					</tr>
559
					<tr>
560
						<td colspan="2" valign="top" class="listtopic">Advanced Options</td>
561
					</tr>
562
					<tr>
563
						<td width="22%" valign="top" class="vncell">Automatically ping host</td>
564
						<td width="78%" class="vtable">
565
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>">
566
							IP address
567
						</td>
568
					</tr>
569 5a3b0d3b mgrooms
					<tr>
570
						<td width="22%" valign="top">&nbsp;</td>
571
						<td width="78%">
572
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
573
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
574
						<?php endif; ?>
575
						<?php if ($pconfig['mobile']): ?>
576
							<input name="mobile" type="hidden" value="true">
577
							<input name="remoteid_type" type="hidden" value="mobile">
578
						<?php endif; ?>
579
							<input name="Submit" type="submit" class="formbtn" value="Save">
580
							<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
581
						</td>
582
					</tr>
583
				</table>
584
			</div>
585
		</td>
586
	</tr>
587
</table>
588 a93e56c5 Matthew Grooms
</form>
589
<script lannguage="JavaScript">
590
<!--
591 4b96b367 mgrooms
change_mode('<?=$pconfig['mode']?>');
592
change_protocol('<?=$pconfig['proto']?>');
593 a93e56c5 Matthew Grooms
typesel_change_local(<?=$pconfig['localid_netbits']?>);
594
typesel_change_remote(<?=$pconfig['remoteid_netbits']?>);
595
//-->
596
</script>
597
<?php include("fend.inc"); ?>
598 3462a529 Matthew Grooms
</body>
599
</html>
600 a93e56c5 Matthew Grooms
601
<?php
602
603 3462a529 Matthew Grooms
/* local utility functions */
604
605 a93e56c5 Matthew Grooms
function pconfig_to_ealgos(& $pconfig) {
606
607
	global $p2_ealgos;
608
609
	$ealgos = array();
610
	foreach ($p2_ealgos as $algo_name => $algo_data) {
611
		if (in_array($algo_name,$pconfig['ealgos'])) {
612
			$ealg = array();
613
			$ealg['name'] = $algo_name;
614
			if (is_array($algo_data['keysel']))
615
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
616
			$ealgos[] = $ealg;
617
		}
618
	}
619
620
	return $ealgos;
621
}
622
623
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
624
625
	$pconfig['ealgos'] = array();
626
	foreach ($ealgos as $algo_data) {
627
		$pconfig['ealgos'][] = $algo_data['name'];
628
		if (isset($algo_data['keylen']))
629
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
630
	}
631
632
	return $ealgos;
633
}
634
635
function pconfig_to_idinfo($prefix,& $pconfig) {
636
637
	$type = $pconfig[$prefix."id_type"];
638
	$address = $pconfig[$prefix."id_address"];
639
	$netbits = $pconfig[$prefix."id_netbits"];
640
641
	switch( $type )
642
	{
643
		case "address":
644
			return array('type' => $type, 'address' => $address);
645
		case "network":
646
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
647
		default:
648
			return array('type' => $type );
649
	}
650
}
651
652
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
653
654
	switch( $idinfo['type'] )
655
	{
656
		case "address":
657
			$pconfig[$prefix."id_type"] = $idinfo['type'];
658
			$pconfig[$prefix."id_address"] = $idinfo['address'];
659
			break;
660
		case "network":
661
			$pconfig[$prefix."id_type"] = $idinfo['type'];
662
			$pconfig[$prefix."id_address"] = $idinfo['address'];
663
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
664
			break;
665
		default:
666
			$pconfig[$prefix."id_type"] = $idinfo['type'];
667
			break;
668
	}
669
}
670
671
?>