Project

General

Profile

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