Project

General

Profile

Download (20.4 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
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
				display_top_tabs($tab_array);
311
			?>
312
		</td>
313
	</tr>
314
	<tr>
315
		<td id="mainarea">
316
			<div class="tabcont">
317
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
318
					<tr>
319
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
320
						<td width="78%" class="vtable">
321
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
322
							<strong>Disable this phase2 entry</strong>
323
							<br>
324
							<span class="vexpl">Set this option to disable this phase2 entry without
325
							  removing it from the list.
326
							</span>
327
						</td>
328
					</tr>
329
					<tr>
330 4b96b367 mgrooms
						<td width="22%" valign="top" class="vncellreq">Mode</td>
331
						<td width="78%" class="vtable">
332
							<select name="mode" class="formselect" onChange="change_mode()">
333
								<?php
334
									foreach($p2_modes as $name => $value):
335
										$selected = "";
336
										if ($name == $pconfig['mode'])
337
											$selected = "selected";
338
								?>
339
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
340
								<?php endforeach; ?>
341
							</select>
342
						</td>
343
					</tr>
344
					<tr id="opt_localid">
345 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Local Network</td>
346
						<td width="78%" class="vtable">
347
							<table border="0" cellspacing="0" cellpadding="0">
348
								<tr>
349
									<td>Type:&nbsp;&nbsp;</td>
350
									<td></td>
351
									<td>
352
										<select name="localid_type" class="formselect" onChange="typesel_change_local()">
353
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>>Address</option>
354
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>>Network</option>
355
											<option value="lan" <?php if ($pconfig['localid_type'] == "lan" ) echo "selected";?>>LAN subnet</option>
356
										</select>
357
									</td>
358
								</tr>
359
								<tr>
360
									<td>Address:&nbsp;&nbsp;</td>
361
									<td><?=$mandfldhtmlspc;?></td>
362
									<td>
363
										<input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=$pconfig['localid_address'];?>">
364
										/
365
										<select name="localid_netbits" class="formselect" id="localid_netbits">
366
										<?php for ($i = 32; $i >= 0; $i--): ?>
367
											<option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
368
												<?=$i;?>
369
											</option>
370
										<?php endfor; ?>
371
										</select>
372
									</td>
373
								</tr>
374
							</table>
375
						</td>
376
					</tr>
377
378
					<?php if (!isset($pconfig['mobile'])): ?>
379
					
380 4b96b367 mgrooms
					<tr id="opt_remoteid">
381 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Remote Network</td>
382
						<td width="78%" class="vtable">
383
							<table border="0" cellspacing="0" cellpadding="0">
384
								<tr>
385
									<td>Type:&nbsp;&nbsp;</td>
386
									<td></td>
387
									<td>
388
										<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
389
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>>Address</option>
390
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>>Network</option>
391
										</select>
392
									</td>
393
								</tr>
394
								<tr>
395
									<td>Address:&nbsp;&nbsp;</td>
396
									<td><?=$mandfldhtmlspc;?></td>
397
									<td>
398
										<input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=$pconfig['remoteid_address'];?>">
399
										/
400
										<select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
401
										<?php for ($i = 32; $i >= 0; $i--): ?>
402
											<option value="<?=$i;?>" <?php if ($i == $pconfig['remoteid_netbits']) echo "selected"; ?>>
403
												<?=$i;?>
404
											</option>
405
										<?php endfor; ?>
406
										</select>
407
									</td>
408
								</tr>
409
							</table>
410 a93e56c5 Matthew Grooms
						</td>
411 5a3b0d3b mgrooms
					</tr>
412
					
413 3462a529 Matthew Grooms
					<?php endif; ?>
414 5a3b0d3b mgrooms
					
415
					<tr>
416
						<td width="22%" valign="top" class="vncell">Description</td>
417
						<td width="78%" class="vtable">
418
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
419
							<br>
420
							<span class="vexpl">
421
								You may enter a description here
422
								for your reference (not parsed).
423
							</span>
424
						</td>
425
					</tr>
426
					<tr>
427
						<td colspan="2" class="list" height="12"></td>
428
					</tr>
429
					<tr>
430
						<td colspan="2" valign="top" class="listtopic">
431
							Phase 2 proposal (SA/Key Exchange)
432
						</td>
433
					</tr>
434
					<tr>
435
						<td width="22%" valign="top" class="vncellreq">Protocol</td>
436
						<td width="78%" class="vtable">
437 4b96b367 mgrooms
							<select name="proto" class="formselect" onChange="change_protocol()">
438 5a3b0d3b mgrooms
							<?php foreach ($p2_protos as $proto => $protoname): ?>
439
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
440
									<?=htmlspecialchars($protoname);?>
441
								</option>
442
							<?php endforeach; ?>
443
							</select>
444
							<br>
445
							<span class="vexpl">
446
								ESP is encryption, AH is authentication only
447
							</span>
448
						</td>
449
					</tr>
450 87e07f52 mgrooms
					<tr id="opt_enc">
451 5a3b0d3b mgrooms
						<td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
452
						<td width="78%" class="vtable">
453
							<table border="0" cellspacing="0" cellpadding="0">
454
							<?php
455
								foreach ($p2_ealgos as $algo => $algodata):
456
									$checked = '';
457
									if (in_array($algo,$pconfig['ealgos']))
458
										$checked = " checked";
459
								?>
460
								<tr>
461
									<td>
462
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?>>
463
									</td>
464
									<td>
465
										<?=htmlspecialchars($algodata['name']);?>
466
									</td>
467
									<td>
468
										<?php if(is_array($algodata['keysel'])): ?>
469
										&nbsp;&nbsp;
470
										<select name="keylen_<?=$algo;?>" class="formselect">
471
											<option value="auto">auto</option>
472
											<?php
473
												$key_hi = $algodata['keysel']['hi'];
474
												$key_lo = $algodata['keysel']['lo'];
475
												$key_step = $algodata['keysel']['step'];
476
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
477
													$selected = '';
478
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
479
													if ($keylen == $pconfig["keylen_".$algo])
480
														$selected = " selected";
481
											?>
482
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> bits</option>
483
											<?php endfor; ?>
484
										</select>
485
										<?php endif; ?>
486
									</td>
487
								</tr>
488
								
489
								<?php endforeach; ?>
490
								
491
							</table>
492
							<br>
493
							Hint: use 3DES for best compatibility or if you have a hardware
494
							crypto accelerator card. Blowfish is usually the fastest in
495
							software encryption.
496
						</td>
497
					</tr>
498
					<tr>
499
						<td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
500
						<td width="78%" class="vtable">
501
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
502
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
503
							<?=htmlspecialchars($algoname);?>
504
							<br>
505
						<?php endforeach; ?>
506
						</td>
507
					</tr>
508
					<tr>
509
						<td width="22%" valign="top" class="vncellreq">PFS key group</td>
510
						<td width="78%" class="vtable">
511
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
512
							<select name="pfsgroup" class="formselect">
513
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
514
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
515
									<?=htmlspecialchars($keygroupname);?>
516
								</option>
517
							<?php endforeach; ?>
518
							</select>
519
							<br>
520
							<span class="vexpl">
521
								<em>
522
									1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit
523
								</em>
524
							</span>
525
							
526
							<?php else: ?>
527
528
							<select class="formselect" disabled>
529
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
530
							</select>
531
							<input name="pfsgroup" type="hidden" value="<?=$pconfig['pfsgroup'];?>">
532
							<br>
533
							<span class="vexpl"><em>Set globally in mobile client options</em></span>
534
						<?php endif; ?>
535
						</td>
536
					</tr>
537
					<tr>
538
						<td width="22%" valign="top" class="vncell">Lifetime</td>
539
						<td width="78%" class="vtable">
540
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
541
							seconds
542
						</td>
543
					</tr>
544 87e07f52 mgrooms
					<tr>
545
						<td colspan="2" class="list" height="12"></td>
546
					</tr>
547
					<tr>
548
						<td colspan="2" valign="top" class="listtopic">Advanced Options</td>
549
					</tr>
550
					<tr>
551
						<td width="22%" valign="top" class="vncell">Automatically ping host</td>
552
						<td width="78%" class="vtable">
553
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>">
554
							IP address
555
						</td>
556
					</tr>
557 5a3b0d3b mgrooms
					<tr>
558
						<td width="22%" valign="top">&nbsp;</td>
559
						<td width="78%">
560
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
561
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
562
						<?php endif; ?>
563
						<?php if ($pconfig['mobile']): ?>
564
							<input name="mobile" type="hidden" value="true">
565
							<input name="remoteid_type" type="hidden" value="mobile">
566
						<?php endif; ?>
567
							<input name="Submit" type="submit" class="formbtn" value="Save">
568
							<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
569
						</td>
570
					</tr>
571
				</table>
572
			</div>
573
		</td>
574
	</tr>
575
</table>
576 a93e56c5 Matthew Grooms
</form>
577
<script lannguage="JavaScript">
578
<!--
579 4b96b367 mgrooms
change_mode('<?=$pconfig['mode']?>');
580
change_protocol('<?=$pconfig['proto']?>');
581 a93e56c5 Matthew Grooms
typesel_change_local(<?=$pconfig['localid_netbits']?>);
582
typesel_change_remote(<?=$pconfig['remoteid_netbits']?>);
583
//-->
584
</script>
585
<?php include("fend.inc"); ?>
586 3462a529 Matthew Grooms
</body>
587
</html>
588 a93e56c5 Matthew Grooms
589
<?php
590
591 3462a529 Matthew Grooms
/* local utility functions */
592
593 a93e56c5 Matthew Grooms
function pconfig_to_ealgos(& $pconfig) {
594
595
	global $p2_ealgos;
596
597
	$ealgos = array();
598
	foreach ($p2_ealgos as $algo_name => $algo_data) {
599
		if (in_array($algo_name,$pconfig['ealgos'])) {
600
			$ealg = array();
601
			$ealg['name'] = $algo_name;
602
			if (is_array($algo_data['keysel']))
603
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
604
			$ealgos[] = $ealg;
605
		}
606
	}
607
608
	return $ealgos;
609
}
610
611
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
612
613
	$pconfig['ealgos'] = array();
614
	foreach ($ealgos as $algo_data) {
615
		$pconfig['ealgos'][] = $algo_data['name'];
616
		if (isset($algo_data['keylen']))
617
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
618
	}
619
620
	return $ealgos;
621
}
622
623
function pconfig_to_idinfo($prefix,& $pconfig) {
624
625
	$type = $pconfig[$prefix."id_type"];
626
	$address = $pconfig[$prefix."id_address"];
627
	$netbits = $pconfig[$prefix."id_netbits"];
628
629
	switch( $type )
630
	{
631
		case "address":
632
			return array('type' => $type, 'address' => $address);
633
		case "network":
634
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
635
		default:
636
			return array('type' => $type );
637
	}
638
}
639
640
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
641
642
	switch( $idinfo['type'] )
643
	{
644
		case "address":
645
			$pconfig[$prefix."id_type"] = $idinfo['type'];
646
			$pconfig[$prefix."id_address"] = $idinfo['address'];
647
			break;
648
		case "network":
649
			$pconfig[$prefix."id_type"] = $idinfo['type'];
650
			$pconfig[$prefix."id_address"] = $idinfo['address'];
651
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
652
			break;
653
		default:
654
			$pconfig[$prefix."id_type"] = $idinfo['type'];
655
			break;
656
	}
657
}
658
659
?>