Project

General

Profile

Download (31.2 KB) Statistics
| Branch: | Tag: | Revision:
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
$p2index = $_GET['p2index'];
55
if (isset($_POST['p2index']))
56
	$p2index = $_POST['p2index'];
57

    
58
if (isset($_GET['dup']))
59
	$p2index = $_GET['dup'];
60

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

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

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

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

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

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

    
102
if (isset($_GET['dup']))
103
	unset($p2index);
104

    
105
if ($_POST) {
106

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

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

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

    
121
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
122

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

    
140
			if (empty($address) || empty($netbits))
141
				$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['localid_type']) . " " . gettext("has no subnet.");
142
		}
143

    
144
		if (!empty($pconfig['natlocalid_address'])) {
145
			switch ($pconfig['natlocalid_type']) {
146
				case "network":
147
					if (($pconfig['natlocalid_netbits'] != 0 && !$pconfig['natlocalid_netbits']) || !is_numeric($pconfig['natlocalid_netbits']))
148
						$input_errors[] = gettext("A valid nat local network bit count must be specified.");
149
					if ($pconfig['localid_type'] == "address")
150
						$input_errors[] = gettext("You cannot configure a network type address for NAT while only an address type is selected for local source."); 
151
				case "address":
152
					if (!empty($pconfig['natlocalid_address']) && !is_ipaddr($pconfig['natlocalid_address']))
153
						$input_errors[] = gettext("A valid nat local network IP address must be specified.");
154
					break;
155
			}
156

    
157
			if (is_array($config['interfaces'][$pconfig['natlocalid_type']])) {
158
				// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
159
				$address = get_interface_ip($pconfig['natlocalid_type']);
160
				$netbits = get_interface_subnet($pconfig['natlocalid_type']);
161

    
162
				if (empty($address) || empty($netbits))
163
					$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['natlocalid_type']) . " " . gettext("has no subnet.");
164
			}
165
		}
166

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

    
237
	/* For ESP protocol, handle encryption algorithms */
238
	if ( $pconfig['proto'] == "esp") {
239
		$ealgos = pconfig_to_ealgos($pconfig);
240

    
241
		if (!count($ealgos)) {
242
			$input_errors[] = gettext("At least one encryption algorithm must be selected.");
243
		}
244
	}
245
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
246
		$input_errors[] = gettext("The P2 lifetime must be an integer.");
247
	}
248

    
249
	if (!$input_errors) {
250

    
251
		$ph2ent['ikeid'] = $pconfig['ikeid'];
252
		$ph2ent['mode'] = $pconfig['mode'];
253
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
254

    
255
		if(($ph2ent['mode'] == "tunnel") || ($ph2ent['mode'] == "tunnel6")){
256
			if (!empty($pconfig['natlocalid_address']))
257
				$ph2ent['natlocalid'] = pconfig_to_idinfo("natlocal",$pconfig);
258
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
259
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
260
		}
261

    
262
		$ph2ent['protocol'] = $pconfig['proto'];
263
		$ph2ent['encryption-algorithm-option'] = $ealgos;
264
		$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
265
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
266
		$ph2ent['lifetime'] = $pconfig['lifetime'];
267
		$ph2ent['pinghost'] = $pconfig['pinghost'];
268
		$ph2ent['descr'] = $pconfig['descr'];
269

    
270
		if (isset($pconfig['mobile']))
271
			$ph2ent['mobile'] = true;
272

    
273
		if (isset($p2index) && $a_phase2[$p2index])
274
			$a_phase2[$p2index] = $ph2ent;
275
		else
276
			$a_phase2[] = $ph2ent;
277

    
278

    
279
		/* now we need to find all phase2 entries for this host */
280
		if(is_array($ph2ent)) {
281
			ipsec_lookup_phase1($ph2ent, $ph1ent);
282
			$old_ph1ent = $ph1ent;
283
			$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
284
			reload_tunnel_spd_policy ($ph1ent, $ph2ent, $old_ph1ent, $old_ph2ent);
285
		}
286

    
287
		write_config();
288
		mark_subsystem_dirty('ipsec');
289

    
290
		header("Location: vpn_ipsec.php");
291
		exit;
292
	}
293
}
294

    
295
if ($pconfig['mobile'])
296
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
297
else
298
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
299
$shortcut_section = "ipsec";
300

    
301

    
302
include("head.inc");
303

    
304
?>
305

    
306
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
307
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
308
<?php include("fbegin.inc"); ?>
309
<script language="JavaScript">
310
<!--
311

    
312
function change_mode() {
313
	index = document.iform.mode.selectedIndex;
314
	value = document.iform.mode.options[index].value;
315
	if ((value == 'tunnel') || (value == 'tunnel6')) {
316
		document.getElementById('opt_localid').style.display = '';
317
<?php if (!isset($pconfig['mobile'])): ?>
318
		document.getElementById('opt_remoteid').style.display = '';
319
<?php endif; ?>
320
	} else {
321
		document.getElementById('opt_localid').style.display = 'none';
322
<?php if (!isset($pconfig['mobile'])): ?>
323
		document.getElementById('opt_remoteid').style.display = 'none';
324
<?php endif; ?>
325
	}
326
}
327

    
328
function typesel_change_natlocal(bits) {
329
	var value = document.iform.mode.options[index].value;
330
	if (typeof(bits) === "undefined") {
331
		if (value === "tunnel") {
332
			bits = 24;
333
		}
334
		else if (value === "tunnel6") {
335
			bits = 64;
336
		}
337
	}
338
	var address_is_blank = !/\S/.test(document.iform.natlocalid_address.value);
339
	switch (document.iform.natlocalid_type.selectedIndex) {
340
		case 0:	/* single */
341
			document.iform.natlocalid_address.disabled = 0;
342
			if (address_is_blank) {
343
				document.iform.natlocalid_netbits.value = 0;
344
			}
345
			document.iform.natlocalid_netbits.disabled = 1;
346
			break;
347
		case 1:	/* network */
348
			document.iform.natlocalid_address.disabled = 0;
349
			if (address_is_blank) {
350
				document.iform.natlocalid_netbits.value = bits;
351
			}
352
			document.iform.natlocalid_netbits.disabled = 0;
353
			break;
354
		case 3:	/* none */
355
			document.iform.natlocalid_address.disabled = 1;
356
			document.iform.natlocalid_netbits.disabled = 1;
357
			break;
358
		default:
359
			document.iform.natlocalid_address.value = "";
360
			document.iform.natlocalid_address.disabled = 1;
361
			if (address_is_blank) {
362
				document.iform.natlocalid_netbits.value = 0;
363
			}
364
			document.iform.natlocalid_netbits.disabled = 1;
365
			break;
366
	}
367
}
368

    
369
function typesel_change_local(bits) {
370
	var value = document.iform.mode.options[index].value;
371
	if (typeof(bits) === "undefined") {
372
		if (value === "tunnel") {
373
			bits = 24;
374
		}
375
		else if (value === "tunnel6") {
376
			bits = 64;
377
		}
378
	}
379
	var address_is_blank = !/\S/.test(document.iform.localid_address.value);
380
	switch (document.iform.localid_type.selectedIndex) {
381
		case 0:	/* single */
382
			document.iform.localid_address.disabled = 0;
383
			if (address_is_blank) {
384
				document.iform.localid_netbits.value = 0;
385
			}
386
			document.iform.localid_netbits.disabled = 1;
387
			break;
388
		case 1:	/* network */
389
			document.iform.localid_address.disabled = 0;
390
			if (address_is_blank) {
391
				document.iform.localid_netbits.value = bits;
392
			}
393
			document.iform.localid_netbits.disabled = 0;
394
			break;
395
		case 3:	/* none */
396
			document.iform.localid_address.disabled = 1;
397
			document.iform.localid_netbits.disabled = 1;
398
			break;
399
		default:
400
			document.iform.localid_address.value = "";
401
			document.iform.localid_address.disabled = 1;
402
			if (address_is_blank) {
403
				document.iform.localid_netbits.value = 0;
404
			}
405
			document.iform.localid_netbits.disabled = 1;
406
			break;
407
	}
408
}
409

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

    
412
function typesel_change_remote(bits) {
413
	var value = document.iform.mode.options[index].value;
414
	if (typeof(bits) === "undefined") {
415
		if (value === "tunnel") {
416
			bits = 24;
417
		}
418
		else if (value === "tunnel6") {
419
			bits = 64;
420
		}
421
	}
422
	var address_is_blank = !/\S/.test(document.iform.remoteid_address.value);
423
	switch (document.iform.remoteid_type.selectedIndex) {
424
		case 0:	/* single */
425
			document.iform.remoteid_address.disabled = 0;
426
			if (address_is_blank) {
427
				document.iform.remoteid_netbits.value = 0;
428
			}
429
			document.iform.remoteid_netbits.disabled = 1;
430
			break;
431
		case 1:	/* network */
432
			document.iform.remoteid_address.disabled = 0;
433
			if (address_is_blank) {
434
				document.iform.remoteid_netbits.value = bits;
435
			}
436
			document.iform.remoteid_netbits.disabled = 0;
437
			break;
438
		default:
439
			document.iform.remoteid_address.value = "";
440
			document.iform.remoteid_address.disabled = 1;
441
			if (address_is_blank) {
442
				document.iform.remoteid_netbits.value = 0;
443
			}
444
			document.iform.remoteid_netbits.disabled = 1;
445
			break;
446
	}
447
}
448

    
449
<?php endif; ?>
450

    
451
function change_protocol() {
452
	index = document.iform.proto.selectedIndex;
453
	value = document.iform.proto.options[index].value;
454
	if (value == 'esp')
455
		document.getElementById('opt_enc').style.display = '';
456
	else
457
		document.getElementById('opt_enc').style.display = 'none';
458
}
459

    
460
//-->
461
</script>
462

    
463
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
464

    
465
<?php
466
	if ($input_errors)
467
		print_input_errors($input_errors);
468
?>
469

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

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

    
733
							<select class="formselect" disabled>
734
								<option selected><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
735
							</select>
736
							<input name="pfsgroup" type="hidden" value="<?=htmlspecialchars($pconfig['pfsgroup']);?>">
737
							<br>
738
							<span class="vexpl"><em><?=gettext("Set globally in mobile client options"); ?></em></span>
739
						<?php endif; ?>
740
						</td>
741
					</tr>
742
					<tr>
743
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
744
						<td width="78%" class="vtable">
745
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>">
746
							<?=gettext("seconds"); ?>
747
						</td>
748
					</tr>
749
					<tr>
750
						<td colspan="2" class="list" height="12"></td>
751
					</tr>
752
					<tr>
753
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
754
					</tr>
755
					<tr>
756
						<td width="22%" valign="top" class="vncell"><?=gettext("Automatically ping host"); ?></td>
757
						<td width="78%" class="vtable">
758
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="28" value="<?=htmlspecialchars($pconfig['pinghost']);?>">
759
							<?=gettext("IP address"); ?>
760
						</td>
761
					</tr>
762
					<tr>
763
						<td width="22%" valign="top">&nbsp;</td>
764
						<td width="78%">
765
						<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
766
							<input name="p2index" type="hidden" value="<?=$p2index;?>">
767
						<?php endif; ?>
768
						<?php if ($pconfig['mobile']): ?>
769
							<input name="mobile" type="hidden" value="true">
770
							<input name="remoteid_type" type="hidden" value="mobile">
771
						<?php endif; ?>
772
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
773
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>">
774
						</td>
775
					</tr>
776
				</table>
777
			</div>
778
		</td>
779
	</tr>
780
</table>
781
</form>
782
<script lannguage="JavaScript">
783
<!--
784
change_mode('<?=htmlspecialchars($pconfig['mode'])?>');
785
change_protocol('<?=htmlspecialchars($pconfig['proto'])?>');
786
typesel_change_local(<?=htmlspecialchars($pconfig['localid_netbits'])?>);
787
typesel_change_natlocal(<?=htmlspecialchars($pconfig['natlocalid_netbits'])?>);
788
<?php if (!isset($pconfig['mobile'])): ?>
789
typesel_change_remote(<?=htmlspecialchars($pconfig['remoteid_netbits'])?>);
790
<?php endif; ?>
791
//-->
792
</script>
793
<?php include("fend.inc"); ?>
794
</body>
795
</html>
796

    
797
<?php
798

    
799
/* local utility functions */
800

    
801
function pconfig_to_ealgos(& $pconfig) {
802

    
803
	global $p2_ealgos;
804

    
805
	$ealgos = array();
806
	if (is_array($pconfig['ealgos'])) {
807
		foreach ($p2_ealgos as $algo_name => $algo_data) {
808
			if (in_array($algo_name,$pconfig['ealgos'])) {
809
				$ealg = array();
810
				$ealg['name'] = $algo_name;
811
				if (is_array($algo_data['keysel']))
812
					$ealg['keylen'] = $_POST["keylen_".$algo_name];
813
				$ealgos[] = $ealg;
814
			}
815
		}
816
	}
817

    
818
	return $ealgos;
819
}
820

    
821
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
822

    
823
	$pconfig['ealgos'] = array();
824
	foreach ($ealgos as $algo_data) {
825
		$pconfig['ealgos'][] = $algo_data['name'];
826
		if (isset($algo_data['keylen']))
827
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
828
	}
829

    
830
	return $ealgos;
831
}
832

    
833
function pconfig_to_idinfo($prefix,& $pconfig) {
834

    
835
	$type = $pconfig[$prefix."id_type"];
836
	$address = $pconfig[$prefix."id_address"];
837
	$netbits = $pconfig[$prefix."id_netbits"];
838

    
839
	switch( $type )
840
	{
841
		case "address":
842
			return array('type' => $type, 'address' => $address);
843
		case "network":
844
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
845
		default:
846
			return array('type' => $type );
847
	}
848
}
849

    
850
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
851

    
852
	switch( $idinfo['type'] )
853
	{
854
		case "address":
855
			$pconfig[$prefix."id_type"] = $idinfo['type'];
856
			$pconfig[$prefix."id_address"] = $idinfo['address'];
857
			break;
858
		case "network":
859
			$pconfig[$prefix."id_type"] = $idinfo['type'];
860
			$pconfig[$prefix."id_address"] = $idinfo['address'];
861
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
862
			break;
863
		default:
864
			$pconfig[$prefix."id_type"] = $idinfo['type'];
865
			break;
866
	}
867
}
868

    
869
?>
870

    
(236-236/249)