Projet

Général

Profil

Télécharger (33,3 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_ipsec_phase2.php @ 8d9a95f9

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
if (is_numericint($_GET['p2index']))
55
	$p2index = $_GET['p2index'];
56
if (isset($_POST['p2index']) && is_numericint($_POST['p2index']))
57
	$p2index = $_POST['p2index'];
58

    
59
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
60
	$p2index = $_GET['dup'];
61

    
62
if (isset($p2index) && $a_phase2[$p2index])
63
{
64
	$pconfig['ikeid'] = $a_phase2[$p2index]['ikeid'];
65
	$pconfig['disabled'] = isset($a_phase2[$p2index]['disabled']);
66
	$pconfig['mode'] = $a_phase2[$p2index]['mode'];
67
	$pconfig['descr'] = $a_phase2[$p2index]['descr'];
68
	$old_ph2ent = $a_phase2[$p2index];
69

    
70
	if (!empty($a_phase2[$p2index]['natlocalid']))
71
		idinfo_to_pconfig("natlocal",$a_phase2[$p2index]['natlocalid'],$pconfig);
72
	idinfo_to_pconfig("local",$a_phase2[$p2index]['localid'],$pconfig);
73
	idinfo_to_pconfig("remote",$a_phase2[$p2index]['remoteid'],$pconfig);
74

    
75
	$pconfig['proto'] = $a_phase2[$p2index]['protocol'];
76
	ealgos_to_pconfig($a_phase2[$p2index]['encryption-algorithm-option'],$pconfig);
77
	$pconfig['halgos'] = $a_phase2[$p2index]['hash-algorithm-option'];
78
	$pconfig['pfsgroup'] = $a_phase2[$p2index]['pfsgroup'];
79
	$pconfig['lifetime'] = $a_phase2[$p2index]['lifetime'];
80
	$pconfig['pinghost'] = $a_phase2[$p2index]['pinghost'];
81

    
82
	if (isset($a_phase2[$p2index]['mobile']))
83
		$pconfig['mobile'] = true;
84
}
85
else
86
{
87
	$pconfig['ikeid'] = $_GET['ikeid'];
88

    
89
	/* defaults */
90
	$pconfig['localid_type'] = "lan";
91
	$pconfig['remoteid_type'] = "network";
92
	$pconfig['proto'] = "esp";
93
	$pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes");
94
	$pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5");
95
	$pconfig['pfsgroup'] = "0";
96
	$pconfig['lifetime'] = "3600";
97

    
98
    /* mobile client */
99
    if($_GET['mobile'])
100
        $pconfig['mobile']=true;
101
}
102

    
103
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
104
	unset($p2index);
105

    
106
if ($_POST) {
107

    
108
	unset($input_errors);
109
	$pconfig = $_POST;
110

    
111
	if (!isset( $_POST['ikeid']))
112
		$input_errors[] = gettext("A valid ikeid must be specified.");
113

    
114
	/* input validation */
115
	$reqdfields = explode(" ", "localid_type halgos");
116
	$reqdfieldsn = array(gettext("Local network type"),gettext("P2 Hash Algorithms"));
117
	if (!isset($pconfig['mobile'])){
118
		$reqdfields[] = "remoteid_type";
119
		$reqdfieldsn[] = gettext("Remote network type");
120
	}
121

    
122
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
123

    
124
	if(($pconfig['mode'] == "tunnel") || ($pconfig['mode'] == "tunnel6")) 
125
	{
126
		switch ($pconfig['localid_type']) {
127
			case "network":
128
				if (($pconfig['localid_netbits'] != 0 && !$pconfig['localid_netbits']) || !is_numeric($pconfig['localid_netbits']))
129
					$input_errors[] = gettext("A valid local network bit count must be specified.");
130
			case "address":
131
				if (!$pconfig['localid_address'] || !is_ipaddr($pconfig['localid_address']))
132
					$input_errors[] = gettext("A valid local network IP address must be specified.");
133
				elseif (is_ipaddrv4($pconfig['localid_address']) && ($pconfig['mode'] != "tunnel"))
134
					$input_errors[] = gettext("A valid local network IPv4 address must be specified or you need to change Mode to IPv6");
135
				elseif (is_ipaddrv6($pconfig['localid_address']) && ($pconfig['mode'] != "tunnel6"))
136
					$input_errors[] = gettext("A valid local network IPv6 address must be specified or you need to change Mode to IPv4");
137
				break;
138
		}
139
		/* Check if the localid_type is an interface, to confirm if it has a valid subnet. */
140
		if (is_array($config['interfaces'][$pconfig['localid_type']])) {
141
			// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
142
			$address = get_interface_ip($pconfig['localid_type']);
143
			$netbits = get_interface_subnet($pconfig['localid_type']);
144

    
145
			if (empty($address) || empty($netbits))
146
				$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['localid_type']) . " " . gettext("has no subnet.");
147
		}
148

    
149
		if (!empty($pconfig['natlocalid_address'])) {
150
			switch ($pconfig['natlocalid_type']) {
151
				case "network":
152
					if (($pconfig['natlocalid_netbits'] != 0 && !$pconfig['natlocalid_netbits']) || !is_numeric($pconfig['natlocalid_netbits']))
153
						$input_errors[] = gettext("A valid NAT local network bit count must be specified.");
154
					if ($pconfig['localid_type'] == "address")
155
						$input_errors[] = gettext("You cannot configure a network type address for NAT while only an address type is selected for local source."); 
156
				case "address":
157
					if (!empty($pconfig['natlocalid_address']) && !is_ipaddr($pconfig['natlocalid_address']))
158
						$input_errors[] = gettext("A valid NAT local network IP address must be specified.");
159
					elseif (is_ipaddrv4($pconfig['natlocalid_address']) && ($pconfig['mode'] != "tunnel"))
160
						$input_errors[] = gettext("A valid NAT local network IPv4 address must be specified or you need to change Mode to IPv6");
161
					elseif (is_ipaddrv6($pconfig['natlocalid_address']) && ($pconfig['mode'] != "tunnel6"))
162
						$input_errors[] = gettext("A valid NAT local network IPv6 address must be specified or you need to change Mode to IPv4");
163
					break;
164
			}
165

    
166
			if (is_array($config['interfaces'][$pconfig['natlocalid_type']])) {
167
				// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
168
				$address = get_interface_ip($pconfig['natlocalid_type']);
169
				$netbits = get_interface_subnet($pconfig['natlocalid_type']);
170

    
171
				if (empty($address) || empty($netbits))
172
					$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['natlocalid_type']) . " " . gettext("has no subnet.");
173
			}
174
		}
175

    
176
		switch ($pconfig['remoteid_type']) {
177
			case "network":
178
				if (($pconfig['remoteid_netbits'] != 0 && !$pconfig['remoteid_netbits']) || !is_numeric($pconfig['remoteid_netbits']))
179
					$input_errors[] = gettext("A valid remote network bit count must be specified.");
180
			case "address":
181
				if (!$pconfig['remoteid_address'] || !is_ipaddr($pconfig['remoteid_address']))
182
					$input_errors[] = gettext("A valid remote network IP address must be specified.");
183
				elseif (is_ipaddrv4($pconfig['remoteid_address']) && ($pconfig['mode'] != "tunnel"))
184
					$input_errors[] = gettext("A valid remote network IPv4 address must be specified or you need to change Mode to IPv6");
185
				elseif (is_ipaddrv6($pconfig['remoteid_address']) && ($pconfig['mode'] != "tunnel6"))
186
					$input_errors[] = gettext("A valid remote network IPv6 address must be specified or you need to change Mode to IPv4");
187
				break;
188
		}
189
	}
190
	/* Validate enabled phase2's are not duplicates */
191
	if (isset($pconfig['mobile'])){
192
		/* User is adding phase 2 for mobile phase1 */
193
		foreach($a_phase2 as $key => $name){
194
			if (isset($name['mobile'])){
195
				/* check duplicate localids only for mobile clents */
196
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
197
				$entered = array();
198
				$entered['type'] = $pconfig['localid_type'];
199
				if (isset($pconfig['localid_address'])) $entered['address'] = $pconfig['localid_address'];
200
				if (isset($pconfig['localid_netbits'])) $entered['netbits'] = $pconfig['localid_netbits'];
201
				$entered_localid_data = ipsec_idinfo_to_cidr($entered, false, $pconfig['mode']);
202
				if ($localid_data == $entered_localid_data){
203
					if (!isset($pconfig['p2index'])){
204
						/* adding new p2 entry */
205
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
206
						break;
207
					}else if ($pconfig['p2index'] != $key){
208
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
209
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
210
						break;
211
					}
212
				}
213
			}
214
		}
215
	}else{
216
		/* User is adding phase 2 for site-to-site phase1 */
217
		$input_error = 0;
218
		foreach($a_phase2 as $key => $name){
219
			if (!isset($name['mobile']) && $pconfig['ikeid'] == $name['ikeid']){
220
				/* check duplicate subnets only for given phase1 */
221
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
222
				$remoteid_data = ipsec_idinfo_to_cidr($name['remoteid'], false, $name['mode']);
223
				$entered_local = array();
224
				$entered_local['type'] = $pconfig['localid_type'];
225
				if (isset($pconfig['localid_address'])) $entered_local['address'] = $pconfig['localid_address'];
226
				if (isset($pconfig['localid_netbits'])) $entered_local['netbits'] = $pconfig['localid_netbits'];
227
				$entered_localid_data = ipsec_idinfo_to_cidr($entered_local, false, $pconfig['mode']);
228
				$entered_remote = array();
229
				$entered_remote['type'] = $pconfig['remoteid_type'];
230
				if (isset($pconfig['remoteid_address'])) $entered_remote['address'] = $pconfig['remoteid_address'];
231
				if (isset($pconfig['remoteid_netbits'])) $entered_remote['netbits'] = $pconfig['remoteid_netbits'];
232
				$entered_remoteid_data = ipsec_idinfo_to_cidr($entered_remote, false, $pconfig['mode']);
233
				if ($localid_data == $entered_localid_data && $remoteid_data == $entered_remoteid_data) { 
234
					if (!isset($pconfig['p2index'])){
235
						/* adding new p2 entry */
236
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
237
						break;
238
					}else if ($pconfig['p2index'] != $key){
239
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
240
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
241
						break;
242
					}
243
				}
244
			}
245
		}
246
        }
247

    
248
	/* For ESP protocol, handle encryption algorithms */
249
	if ( $pconfig['proto'] == "esp") {
250
		$ealgos = pconfig_to_ealgos($pconfig);
251

    
252
		if (!count($ealgos)) {
253
			$input_errors[] = gettext("At least one encryption algorithm must be selected.");
254
		}
255
	}
256
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
257
		$input_errors[] = gettext("The P2 lifetime must be an integer.");
258
	}
259

    
260
	if (!$input_errors) {
261

    
262
		$ph2ent['ikeid'] = $pconfig['ikeid'];
263
		$ph2ent['mode'] = $pconfig['mode'];
264
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
265

    
266
		if(($ph2ent['mode'] == "tunnel") || ($ph2ent['mode'] == "tunnel6")){
267
			if (!empty($pconfig['natlocalid_address']))
268
				$ph2ent['natlocalid'] = pconfig_to_idinfo("natlocal",$pconfig);
269
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
270
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
271
		}
272

    
273
		$ph2ent['protocol'] = $pconfig['proto'];
274
		$ph2ent['encryption-algorithm-option'] = $ealgos;
275
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
276
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
277
		$ph2ent['lifetime'] = $pconfig['lifetime'];
278
		$ph2ent['pinghost'] = $pconfig['pinghost'];
279
		$ph2ent['descr'] = $pconfig['descr'];
280

    
281
		if (isset($pconfig['mobile']))
282
			$ph2ent['mobile'] = true;
283

    
284
		ipsec_lookup_phase1($ph2ent, $ph1ent);
285
		if (($ph1ent['protocol'] == "inet") && ($ph2ent['mode'] == "tunnel6"))
286
			$input_errors[] = gettext("Phase 1 is using IPv4. You cannot use Tunnel IPv6 on Phase 2.");
287
		if (($ph1ent['protocol'] == "inet6") && ($ph2ent['mode'] == "tunnel"))
288
			$input_errors[] = gettext("Phase 1 is using IPv6. You cannot use Tunnel IPv4 on Phase 2.");
289
	}
290

    
291
	if (!$input_errors) {
292
		if (isset($p2index) && $a_phase2[$p2index])
293
			$a_phase2[$p2index] = $ph2ent;
294
		else
295
			$a_phase2[] = $ph2ent;
296

    
297

    
298
		/* now we need to find all phase2 entries for this host */
299
		if(is_array($ph2ent)) {
300
			ipsec_lookup_phase1($ph2ent, $ph1ent);
301
			$old_ph1ent = $ph1ent;
302
			$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
303
		}
304

    
305
		write_config();
306
		mark_subsystem_dirty('ipsec');
307

    
308
		header("Location: vpn_ipsec.php");
309
		exit;
310
	}
311
}
312

    
313
if ($pconfig['mobile'])
314
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
315
else
316
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
317
$shortcut_section = "ipsec";
318

    
319

    
320
include("head.inc");
321

    
322
?>
323

    
324
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
325
<?php include("fbegin.inc"); ?>
326
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
327
<script type="text/javascript">
328
//<![CDATA[
329

    
330
function change_mode() {
331
	index = document.iform.mode.selectedIndex;
332
	value = document.iform.mode.options[index].value;
333
	if ((value == 'tunnel') || (value == 'tunnel6')) {
334
		document.getElementById('opt_localid').style.display = '';
335
<?php if (!isset($pconfig['mobile'])): ?>
336
		document.getElementById('opt_remoteid').style.display = '';
337
<?php endif; ?>
338
	} else {
339
		document.getElementById('opt_localid').style.display = 'none';
340
<?php if (!isset($pconfig['mobile'])): ?>
341
		document.getElementById('opt_remoteid').style.display = 'none';
342
<?php endif; ?>
343
	}
344
}
345

    
346
function typesel_change_natlocal(bits) {
347
	var value = document.iform.mode.options[index].value;
348
	if (typeof(bits) === "undefined") {
349
		if (value === "tunnel") {
350
			bits = 24;
351
		}
352
		else if (value === "tunnel6") {
353
			bits = 64;
354
		}
355
	}
356
	var address_is_blank = !/\S/.test(document.iform.natlocalid_address.value);
357
	switch (document.iform.natlocalid_type.selectedIndex) {
358
		case 0:	/* single */
359
			document.iform.natlocalid_address.disabled = 0;
360
			if (address_is_blank) {
361
				document.iform.natlocalid_netbits.value = 0;
362
			}
363
			document.iform.natlocalid_netbits.disabled = 1;
364
			break;
365
		case 1:	/* network */
366
			document.iform.natlocalid_address.disabled = 0;
367
			if (address_is_blank) {
368
				document.iform.natlocalid_netbits.value = bits;
369
			}
370
			document.iform.natlocalid_netbits.disabled = 0;
371
			break;
372
		case 3:	/* none */
373
			document.iform.natlocalid_address.disabled = 1;
374
			document.iform.natlocalid_netbits.disabled = 1;
375
			break;
376
		default:
377
			document.iform.natlocalid_address.value = "";
378
			document.iform.natlocalid_address.disabled = 1;
379
			if (address_is_blank) {
380
				document.iform.natlocalid_netbits.value = 0;
381
			}
382
			document.iform.natlocalid_netbits.disabled = 1;
383
			break;
384
	}
385
}
386

    
387
function typesel_change_local(bits) {
388
	var value = document.iform.mode.options[index].value;
389
	if (typeof(bits) === "undefined") {
390
		if (value === "tunnel") {
391
			bits = 24;
392
		}
393
		else if (value === "tunnel6") {
394
			bits = 64;
395
		}
396
	}
397
	var address_is_blank = !/\S/.test(document.iform.localid_address.value);
398
	switch (document.iform.localid_type.selectedIndex) {
399
		case 0:	/* single */
400
			document.iform.localid_address.disabled = 0;
401
			if (address_is_blank) {
402
				document.iform.localid_netbits.value = 0;
403
			}
404
			document.iform.localid_netbits.disabled = 1;
405
			break;
406
		case 1:	/* network */
407
			document.iform.localid_address.disabled = 0;
408
			if (address_is_blank) {
409
				document.iform.localid_netbits.value = bits;
410
			}
411
			document.iform.localid_netbits.disabled = 0;
412
			break;
413
		case 3:	/* none */
414
			document.iform.localid_address.disabled = 1;
415
			document.iform.localid_netbits.disabled = 1;
416
			break;
417
		default:
418
			document.iform.localid_address.value = "";
419
			document.iform.localid_address.disabled = 1;
420
			if (address_is_blank) {
421
				document.iform.localid_netbits.value = 0;
422
			}
423
			document.iform.localid_netbits.disabled = 1;
424
			break;
425
	}
426
}
427

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

    
430
function typesel_change_remote(bits) {
431
	var value = document.iform.mode.options[index].value;
432
	if (typeof(bits) === "undefined") {
433
		if (value === "tunnel") {
434
			bits = 24;
435
		}
436
		else if (value === "tunnel6") {
437
			bits = 64;
438
		}
439
	}
440
	var address_is_blank = !/\S/.test(document.iform.remoteid_address.value);
441
	switch (document.iform.remoteid_type.selectedIndex) {
442
		case 0:	/* single */
443
			document.iform.remoteid_address.disabled = 0;
444
			if (address_is_blank) {
445
				document.iform.remoteid_netbits.value = 0;
446
			}
447
			document.iform.remoteid_netbits.disabled = 1;
448
			break;
449
		case 1:	/* network */
450
			document.iform.remoteid_address.disabled = 0;
451
			if (address_is_blank) {
452
				document.iform.remoteid_netbits.value = bits;
453
			}
454
			document.iform.remoteid_netbits.disabled = 0;
455
			break;
456
		default:
457
			document.iform.remoteid_address.value = "";
458
			document.iform.remoteid_address.disabled = 1;
459
			if (address_is_blank) {
460
				document.iform.remoteid_netbits.value = 0;
461
			}
462
			document.iform.remoteid_netbits.disabled = 1;
463
			break;
464
	}
465
}
466

    
467
<?php endif; ?>
468

    
469
function change_protocol() {
470
	index = document.iform.proto.selectedIndex;
471
	value = document.iform.proto.options[index].value;
472
	if (value == 'esp')
473
		document.getElementById('opt_enc').style.display = '';
474
	else
475
		document.getElementById('opt_enc').style.display = 'none';
476
}
477

    
478
//]]>
479
</script>
480

    
481
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
482

    
483
<?php
484
	if ($input_errors)
485
		print_input_errors($input_errors);
486
?>
487

    
488
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="vpn ipsec phase-2">
489
	<tr class="tabnavtbl">
490
		<td id="tabnav">
491
			<?php
492
				$tab_array = array();
493
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
494
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
495
				$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
496
				$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
497
				display_top_tabs($tab_array);
498
			?>
499
		</td>
500
	</tr>
501
	<tr>
502
		<td id="mainarea">
503
			<div class="tabcont">
504
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
505
					<tr>
506
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
507
						<td width="78%" class="vtable">
508
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
509
							<strong><?=gettext("Disable this phase2 entry"); ?></strong>
510
							<br />
511
							<span class="vexpl"><?=gettext("Set this option to disable this phase2 entry without " .
512
							  "removing it from the list"); ?>.
513
							</span>
514
						</td>
515
					</tr>
516
					<tr>
517
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
518
						<td width="78%" class="vtable">
519
							<select name="mode" class="formselect" onchange="change_mode()">
520
								<?php
521
									foreach($p2_modes as $name => $value):
522
										$selected = "";
523
										if ($name == $pconfig['mode'])
524
											$selected = "selected=\"selected\"";
525
								?>
526
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
527
								<?php endforeach; ?>
528
							</select>
529
						</td>
530
					</tr>
531
					<tr id="opt_localid">
532
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local Network"); ?></td>
533
						<td width="78%" class="vtable">
534
							<table border="0" cellspacing="0" cellpadding="0" summary="local network">
535
								<tr>
536
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
537
									<td></td>
538
									<td>
539
										<select name="localid_type" class="formselect" onchange="typesel_change_local()">
540
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected=\"selected\"";?>><?=gettext("Address"); ?></option>
541
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected=\"selected\"";?>><?=gettext("Network"); ?></option>
542
											<?php
543
												$iflist = get_configured_interface_with_descr();
544
												foreach ($iflist as $ifname => $ifdescr):
545
											?>
546
											<option value="<?=$ifname; ?>" <?php if ($pconfig['localid_type'] == $ifname ) echo "selected=\"selected\"";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
547
											<?php endforeach; ?>
548
										</select>
549
									</td>
550
								</tr>
551
								<tr>
552
									<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
553
									<td><?=$mandfldhtmlspc;?></td>
554
									<td>
555
										<input name="localid_address" type="text" class="formfld unknown ipv4v6" id="localid_address" size="28" value="<?=htmlspecialchars($pconfig['localid_address']);?>" />
556
										/
557
										<select name="localid_netbits" class="formselect ipv4v6" id="localid_netbits">
558
										<?php for ($i = 128; $i >= 0; $i--): ?>
559
											<option value="<?=$i;?>" <?php if (isset($pconfig['localid_netbits']) && $i == $pconfig['localid_netbits']) echo "selected=\"selected\""; ?>>
560
												<?=$i;?>
561
											</option>
562
										<?php endfor; ?>
563
										</select>
564
									</td>
565
								</tr>
566
								<tr> <td colspan="3">
567
								<br />
568
								<?php echo gettext("In case you need NAT/BINAT on this network specify the address to be translated"); ?>
569
								</td></tr>
570
								<tr>
571
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
572
									<td></td>
573
									<td>
574
										<select name="natlocalid_type" class="formselect" onchange="typesel_change_natlocal()">
575
											<option value="address" <?php if ($pconfig['natlocalid_type'] == "address") echo "selected=\"selected\"";?>><?=gettext("Address"); ?></option>
576
											<option value="network" <?php if ($pconfig['natlocalid_type'] == "network") echo "selected=\"selected\"";?>><?=gettext("Network"); ?></option>
577
											<?php
578
												$iflist = get_configured_interface_with_descr();
579
												foreach ($iflist as $ifname => $ifdescr):
580
											?>
581
											<option value="<?=$ifname; ?>" <?php if ($pconfig['natlocalid_type'] == $ifname ) echo "selected=\"selected\"";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
582
											<?php endforeach; ?>
583
											<option value="none" <?php if (empty($pconfig['natlocalid_type']) || $pconfig['natlocalid_type'] == "none" ) echo "selected=\"selected\"";?>><?=gettext("None"); ?></option>
584
										</select>
585
									</td>
586
								</tr>
587
								<tr>
588
									<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
589
									<td><?=$mandfldhtmlspc;?></td>
590
									<td>
591
										<input name="natlocalid_address" type="text" class="formfld unknown ipv4v6" id="natlocalid_address" size="28" value="<?=htmlspecialchars($pconfig['natlocalid_address']);?>" />
592
										/
593
										<select name="natlocalid_netbits" class="formselect ipv4v6" id="natlocalid_netbits">
594
										<?php for ($i = 128; $i >= 0; $i--): ?>
595
											<option value="<?=$i;?>" <?php if (isset($pconfig['natlocalid_netbits']) && $i == $pconfig['natlocalid_netbits']) echo "selected=\"selected\""; ?>>
596
												<?=$i;?>
597
											</option>
598
										<?php endfor; ?>
599
										</select>
600
									</td>
601
								</tr>
602
							</table>
603
						</td>
604
					</tr>
605

    
606
					<?php if (!isset($pconfig['mobile'])): ?>
607
					
608
					<tr id="opt_remoteid">
609
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote Network"); ?></td>
610
						<td width="78%" class="vtable">
611
							<table border="0" cellspacing="0" cellpadding="0" summary="remote network">
612
								<tr>
613
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
614
									<td></td>
615
									<td>
616
										<select name="remoteid_type" class="formselect" onchange="typesel_change_remote()">
617
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected=\"selected\""; ?>><?=gettext("Address"); ?></option>
618
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network"); ?></option>
619
										</select>
620
									</td>
621
								</tr>
622
								<tr>
623
									<td><?=gettext("Address"); ?>:&nbsp;&nbsp;</td>
624
									<td><?=$mandfldhtmlspc;?></td>
625
									<td>
626
										<input name="remoteid_address" type="text" class="formfld unknown ipv4v6" id="remoteid_address" size="28" value="<?=htmlspecialchars($pconfig['remoteid_address']);?>" />
627
										/
628
										<select name="remoteid_netbits" class="formselect ipv4v6" id="remoteid_netbits">
629
										<?php for ($i = 128; $i >= 0; $i--) { 
630
											
631
											echo "<option value=\"{$i}\"";
632
											if (isset($pconfig['remoteid_netbits']) && $i == $pconfig['remoteid_netbits']) echo " selected=\"selected\"";
633
											echo ">{$i}</option>\n";
634
											} ?>
635
										</select>
636
									</td>
637
								</tr>
638
							</table>
639
						</td>
640
					</tr>
641
					
642
					<?php endif; ?>
643
					
644
					<tr>
645
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
646
						<td width="78%" class="vtable">
647
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
648
							<br />
649
							<span class="vexpl">
650
								<?=gettext("You may enter a description here " .
651
								"for your reference (not parsed)"); ?>.
652
							</span>
653
						</td>
654
					</tr>
655
					<tr>
656
						<td colspan="2" class="list" height="12"></td>
657
					</tr>
658
					<tr>
659
						<td colspan="2" valign="top" class="listtopic">
660
							<?=gettext("Phase 2 proposal (SA/Key Exchange)"); ?>
661
						</td>
662
					</tr>
663
					<tr>
664
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
665
						<td width="78%" class="vtable">
666
							<select name="proto" class="formselect" onchange="change_protocol()">
667
							<?php foreach ($p2_protos as $proto => $protoname): ?>
668
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected=\"selected\""; ?>>
669
									<?=htmlspecialchars($protoname);?>
670
								</option>
671
							<?php endforeach; ?>
672
							</select>
673
							<br />
674
							<span class="vexpl">
675
								<?=gettext("ESP is encryption, AH is authentication only"); ?>
676
							</span>
677
						</td>
678
					</tr>
679
					<tr id="opt_enc">
680
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithms"); ?></td>
681
						<td width="78%" class="vtable">
682
							<table border="0" cellspacing="0" cellpadding="0" summary="encryption">
683
							<?php
684
								foreach ($p2_ealgos as $algo => $algodata):
685
									$checked = '';
686
									if (is_array($pconfig['ealgos']) && in_array($algo,$pconfig['ealgos']))
687
										$checked = " checked=\"checked\"";
688
								?>
689
								<tr>
690
									<td>
691
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?> />
692
									</td>
693
									<td>
694
										<?=htmlspecialchars($algodata['name']);?>
695
									</td>
696
									<td>
697
										<?php if(is_array($algodata['keysel'])): ?>
698
										&nbsp;&nbsp;
699
										<select name="keylen_<?=$algo;?>" class="formselect">
700
											<option value="auto"><?=gettext("auto"); ?></option>
701
											<?php
702
												$key_hi = $algodata['keysel']['hi'];
703
												$key_lo = $algodata['keysel']['lo'];
704
												$key_step = $algodata['keysel']['step'];
705
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
706
													$selected = "";
707
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
708
													if ($keylen == $pconfig["keylen_".$algo])
709
														$selected = " selected=\"selected\"";
710
											?>
711
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> <?=gettext("bits"); ?></option>
712
											<?php endfor; ?>
713
										</select>
714
										<?php endif; ?>
715
									</td>
716
								</tr>
717
								
718
								<?php endforeach; ?>
719
								
720
							</table>
721
							<br />
722
							<?=gettext("Hint: use 3DES for best compatibility or if you have a hardware " . 
723
							"crypto accelerator card. Blowfish is usually the fastest in " .
724
							"software encryption"); ?>.
725
						</td>
726
					</tr>
727
					<tr>
728
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithms"); ?></td>
729
						<td width="78%" class="vtable">
730
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
731
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked=\"checked\""; ?> />
732
							<?=htmlspecialchars($algoname);?>
733
							<br />
734
						<?php endforeach; ?>
735
						</td>
736
					</tr>
737
					<tr>
738
						<td width="22%" valign="top" class="vncellreq"><?=gettext("PFS key group"); ?></td>
739
						<td width="78%" class="vtable">
740
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
741
							<select name="pfsgroup" class="formselect">
742
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
743
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected=\"selected\""; ?>>
744
									<?=htmlspecialchars($keygroupname);?>
745
								</option>
746
							<?php endforeach; ?>
747
							</select>
748
							<br />
749
							<?php else: ?>
750

    
751
							<select class="formselect" disabled="disabled">
752
								<option selected="selected"><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
753
							</select>
754
							<input name="pfsgroup" type="hidden" value="<?=htmlspecialchars($pconfig['pfsgroup']);?>" />
755
							<br />
756
							<span class="vexpl"><em><?=gettext("Set globally in mobile client options"); ?></em></span>
757
						<?php endif; ?>
758
						</td>
759
					</tr>
760
					<tr>
761
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
762
						<td width="78%" class="vtable">
763
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />
764
							<?=gettext("seconds"); ?>
765
						</td>
766
					</tr>
767
					<tr>
768
						<td colspan="2" class="list" height="12"></td>
769
					</tr>
770
					<tr>
771
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
772
					</tr>
773
					<tr>
774
						<td width="22%" valign="top" class="vncell"><?=gettext("Automatically ping host"); ?></td>
775
						<td width="78%" class="vtable">
776
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="28" value="<?=htmlspecialchars($pconfig['pinghost']);?>" />
777
							<?=gettext("IP address"); ?>
778
						</td>
779
					</tr>
780
					<tr>
781
						<td width="22%" valign="top">&nbsp;</td>
782
						<td width="78%">
783
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
784
							<input name="p2index" type="hidden" value="<?=htmlspecialchars($p2index);?>" />
785
						<?php endif; ?>
786
						<?php if ($pconfig['mobile']): ?>
787
							<input name="mobile" type="hidden" value="true" />
788
							<input name="remoteid_type" type="hidden" value="mobile" />
789
						<?php endif; ?>
790
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
791
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>" />
792
						</td>
793
					</tr>
794
				</table>
795
			</div>
796
		</td>
797
	</tr>
798
</table>
799
</form>
800
<script type="text/javascript">
801
//<![CDATA[
802
change_mode('<?=htmlspecialchars($pconfig['mode'])?>');
803
change_protocol('<?=htmlspecialchars($pconfig['proto'])?>');
804
typesel_change_local(<?=htmlspecialchars($pconfig['localid_netbits'])?>);
805
typesel_change_natlocal(<?=htmlspecialchars($pconfig['natlocalid_netbits'])?>);
806
<?php if (!isset($pconfig['mobile'])): ?>
807
typesel_change_remote(<?=htmlspecialchars($pconfig['remoteid_netbits'])?>);
808
<?php endif; ?>
809
//]]>
810
</script>
811
<?php include("fend.inc"); ?>
812
</body>
813
</html>
814

    
815
<?php
816

    
817
/* local utility functions */
818

    
819
function pconfig_to_ealgos(& $pconfig) {
820

    
821
	global $p2_ealgos;
822

    
823
	$ealgos = array();
824
	if (is_array($pconfig['ealgos'])) {
825
		foreach ($p2_ealgos as $algo_name => $algo_data) {
826
			if (in_array($algo_name,$pconfig['ealgos'])) {
827
				$ealg = array();
828
				$ealg['name'] = $algo_name;
829
				if (is_array($algo_data['keysel']))
830
					$ealg['keylen'] = $_POST["keylen_".$algo_name];
831
				$ealgos[] = $ealg;
832
			}
833
		}
834
	}
835

    
836
	return $ealgos;
837
}
838

    
839
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
840

    
841
	$pconfig['ealgos'] = array();
842
	foreach ($ealgos as $algo_data) {
843
		$pconfig['ealgos'][] = $algo_data['name'];
844
		if (isset($algo_data['keylen']))
845
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
846
	}
847

    
848
	return $ealgos;
849
}
850

    
851
function pconfig_to_idinfo($prefix,& $pconfig) {
852

    
853
	$type = $pconfig[$prefix."id_type"];
854
	$address = $pconfig[$prefix."id_address"];
855
	$netbits = $pconfig[$prefix."id_netbits"];
856

    
857
	switch( $type )
858
	{
859
		case "address":
860
			return array('type' => $type, 'address' => $address);
861
		case "network":
862
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
863
		default:
864
			return array('type' => $type );
865
	}
866
}
867

    
868
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
869

    
870
	switch( $idinfo['type'] )
871
	{
872
		case "address":
873
			$pconfig[$prefix."id_type"] = $idinfo['type'];
874
			$pconfig[$prefix."id_address"] = $idinfo['address'];
875
			break;
876
		case "network":
877
			$pconfig[$prefix."id_type"] = $idinfo['type'];
878
			$pconfig[$prefix."id_address"] = $idinfo['address'];
879
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
880
			break;
881
		default:
882
			$pconfig[$prefix."id_type"] = $idinfo['type'];
883
			break;
884
	}
885
}
886

    
887
?>
(240-240/254)