Projet

Général

Profil

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

univnautes / usr / local / www / vpn_ipsec_phase2.php @ 3a50eb39

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
		if (substr($pconfig['mode'], 0, 6) != "tunnel")
193
			$input_errors[] = gettext("Mobile IPsec only supports Tunnel mode.");
194
		/* User is adding phase 2 for mobile phase1 */
195
		foreach($a_phase2 as $key => $name){
196
			if (isset($name['mobile'])){
197
				/* check duplicate localids only for mobile clents */
198
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
199
				$entered = array();
200
				$entered['type'] = $pconfig['localid_type'];
201
				if (isset($pconfig['localid_address'])) $entered['address'] = $pconfig['localid_address'];
202
				if (isset($pconfig['localid_netbits'])) $entered['netbits'] = $pconfig['localid_netbits'];
203
				$entered_localid_data = ipsec_idinfo_to_cidr($entered, false, $pconfig['mode']);
204
				if ($localid_data == $entered_localid_data){
205
					if (!isset($pconfig['p2index'])){
206
						/* adding new p2 entry */
207
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
208
						break;
209
					}else if ($pconfig['p2index'] != $key){
210
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
211
						$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
212
						break;
213
					}
214
				}
215
			}
216
		}
217
	}else{
218
		/* User is adding phase 2 for site-to-site phase1 */
219
		$input_error = 0;
220
		foreach($a_phase2 as $key => $name){
221
			if (!isset($name['mobile']) && $pconfig['ikeid'] == $name['ikeid']){
222
				/* check duplicate subnets only for given phase1 */
223
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
224
				$remoteid_data = ipsec_idinfo_to_cidr($name['remoteid'], false, $name['mode']);
225
				$entered_local = array();
226
				$entered_local['type'] = $pconfig['localid_type'];
227
				if (isset($pconfig['localid_address'])) $entered_local['address'] = $pconfig['localid_address'];
228
				if (isset($pconfig['localid_netbits'])) $entered_local['netbits'] = $pconfig['localid_netbits'];
229
				$entered_localid_data = ipsec_idinfo_to_cidr($entered_local, false, $pconfig['mode']);
230
				$entered_remote = array();
231
				$entered_remote['type'] = $pconfig['remoteid_type'];
232
				if (isset($pconfig['remoteid_address'])) $entered_remote['address'] = $pconfig['remoteid_address'];
233
				if (isset($pconfig['remoteid_netbits'])) $entered_remote['netbits'] = $pconfig['remoteid_netbits'];
234
				$entered_remoteid_data = ipsec_idinfo_to_cidr($entered_remote, false, $pconfig['mode']);
235
				if ($localid_data == $entered_localid_data && $remoteid_data == $entered_remoteid_data) { 
236
					if (!isset($pconfig['p2index'])){
237
						/* adding new p2 entry */
238
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
239
						break;
240
					}else if ($pconfig['p2index'] != $key){
241
						/* editing p2 and entered p2 networks match with different p2 for given p1 */
242
						$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
243
						break;
244
					}
245
				}
246
			}
247
		}
248
        }
249

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

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

    
262
	if (!$input_errors) {
263

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

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

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

    
283
		if (isset($pconfig['mobile']))
284
			$ph2ent['mobile'] = true;
285

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

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

    
299

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

    
307
		write_config();
308
		mark_subsystem_dirty('ipsec');
309

    
310
		header("Location: vpn_ipsec.php");
311
		exit;
312
	}
313
}
314

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

    
321

    
322
include("head.inc");
323

    
324
?>
325

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

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

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

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

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

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

    
469
<?php endif; ?>
470

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

    
480
//]]>
481
</script>
482

    
483
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
484

    
485
<?php
486
	if ($input_errors)
487
		print_input_errors($input_errors);
488
?>
489

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

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

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

    
817
<?php
818

    
819
/* local utility functions */
820

    
821
function pconfig_to_ealgos(& $pconfig) {
822

    
823
	global $p2_ealgos;
824

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

    
838
	return $ealgos;
839
}
840

    
841
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
842

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

    
850
	return $ealgos;
851
}
852

    
853
function pconfig_to_idinfo($prefix,& $pconfig) {
854

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

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

    
870
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
871

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

    
889
?>
(240-240/254)