Project

General

Profile

Download (32.1 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
if (!empty($_GET['p2index']))
55
	$uindex = $_GET['p2index'];
56
if (!empty($_POST['uniqid']))
57
	$uindex = $_POST['uniqid'];
58

    
59
if (!empty($_GET['dup']))
60
	$uindex = $_GET['dup'];
61

    
62
$ph2found = false;
63
if (isset($uindex)) {
64
	foreach ($a_phase2 as $p2index => $ph2) {
65
		if ($ph2['uniqid'] == $uindex) {
66
			$ph2found = true;
67
			break;
68
		}
69
	}
70
}
71

    
72
if ($ph2found === true)
73
{
74
	$pconfig['ikeid'] = $ph2['ikeid'];
75
	$pconfig['disabled'] = isset($ph2['disabled']);
76
	$pconfig['mode'] = $ph2['mode'];
77
	$pconfig['descr'] = $ph2['descr'];
78
	$pconfig['uniqid'] = $ph2['uniqid'];
79

    
80
	if (!empty($ph2['natlocalid']))
81
		idinfo_to_pconfig("natlocal",$ph2['natlocalid'],$pconfig);
82
	idinfo_to_pconfig("local",$ph2['localid'],$pconfig);
83
	idinfo_to_pconfig("remote",$ph2['remoteid'],$pconfig);
84

    
85
	$pconfig['proto'] = $ph2['protocol'];
86
	ealgos_to_pconfig($ph2['encryption-algorithm-option'],$pconfig);
87
	$pconfig['halgos'] = $ph2['hash-algorithm-option'];
88
	$pconfig['pfsgroup'] = $ph2['pfsgroup'];
89
	$pconfig['lifetime'] = $ph2['lifetime'];
90
	$pconfig['pinghost'] = $ph2['pinghost'];
91

    
92
	if (isset($ph2['mobile']))
93
		$pconfig['mobile'] = true;
94
}
95
else
96
{
97
	$pconfig['ikeid'] = $_GET['ikeid'];
98

    
99
	/* defaults */
100
	$pconfig['localid_type'] = "lan";
101
	$pconfig['remoteid_type'] = "network";
102
	$pconfig['proto'] = "esp";
103
	$pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes");
104
	$pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5");
105
	$pconfig['pfsgroup'] = "0";
106
	$pconfig['lifetime'] = "3600";
107
	$pconfig['uniqid'] = uniqid();
108

    
109
	/* mobile client */
110
	if($_GET['mobile'])
111
		$pconfig['mobile']=true;
112
}
113

    
114
unset($ph2);
115
if (!empty($_GET['dup'])) {
116
	unset($uindex);
117
	unset($p2index);
118
	$pconfig['uniqid'] = uniqid();
119
}
120

    
121
if ($_POST) {
122

    
123
	unset($input_errors);
124
	$pconfig = $_POST;
125

    
126
	if (!isset( $_POST['ikeid']))
127
		$input_errors[] = gettext("A valid ikeid must be specified.");
128

    
129
	/* input validation */
130
	$reqdfields = explode(" ", "localid_type halgos uniqid");
131
	$reqdfieldsn = array(gettext("Local network type"),gettext("P2 Hash Algorithms"), gettext("Unique Identifier"));
132
	if (!isset($pconfig['mobile'])){
133
		$reqdfields[] = "remoteid_type";
134
		$reqdfieldsn[] = gettext("Remote network type");
135
	}
136

    
137
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
138

    
139
	if(($pconfig['mode'] == "tunnel") || ($pconfig['mode'] == "tunnel6")) 
140
	{
141
		switch ($pconfig['localid_type']) {
142
			case "network":
143
				if (($pconfig['localid_netbits'] != 0 && !$pconfig['localid_netbits']) || !is_numeric($pconfig['localid_netbits']))
144
					$input_errors[] = gettext("A valid local network bit count must be specified.");
145
			case "address":
146
				if (!$pconfig['localid_address'] || !is_ipaddr($pconfig['localid_address']))
147
					$input_errors[] = gettext("A valid local network IP address must be specified.");
148
				elseif (is_ipaddrv4($pconfig['localid_address']) && ($pconfig['mode'] != "tunnel"))
149
					$input_errors[] = gettext("A valid local network IPv4 address must be specified or you need to change Mode to IPv6");
150
				elseif (is_ipaddrv6($pconfig['localid_address']) && ($pconfig['mode'] != "tunnel6"))
151
					$input_errors[] = gettext("A valid local network IPv6 address must be specified or you need to change Mode to IPv4");
152
				break;
153
		}
154
		/* Check if the localid_type is an interface, to confirm if it has a valid subnet. */
155
		if (is_array($config['interfaces'][$pconfig['localid_type']])) {
156
			// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
157
			$address = get_interface_ip($pconfig['localid_type']);
158
			$netbits = get_interface_subnet($pconfig['localid_type']);
159

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

    
164
		if (!empty($pconfig['natlocalid_address'])) {
165
			switch ($pconfig['natlocalid_type']) {
166
				case "network":
167
					if (($pconfig['natlocalid_netbits'] != 0 && !$pconfig['natlocalid_netbits']) || !is_numeric($pconfig['natlocalid_netbits']))
168
						$input_errors[] = gettext("A valid NAT local network bit count must be specified.");
169
					if ($pconfig['localid_type'] == "address")
170
						$input_errors[] = gettext("You cannot configure a network type address for NAT while only an address type is selected for local source."); 
171
				case "address":
172
					if (!empty($pconfig['natlocalid_address']) && !is_ipaddr($pconfig['natlocalid_address']))
173
						$input_errors[] = gettext("A valid NAT local network IP address must be specified.");
174
					elseif (is_ipaddrv4($pconfig['natlocalid_address']) && ($pconfig['mode'] != "tunnel"))
175
						$input_errors[] = gettext("A valid NAT local network IPv4 address must be specified or you need to change Mode to IPv6");
176
					elseif (is_ipaddrv6($pconfig['natlocalid_address']) && ($pconfig['mode'] != "tunnel6"))
177
						$input_errors[] = gettext("A valid NAT local network IPv6 address must be specified or you need to change Mode to IPv4");
178
					break;
179
			}
180

    
181
			if (is_array($config['interfaces'][$pconfig['natlocalid_type']])) {
182
				// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
183
				$address = get_interface_ip($pconfig['natlocalid_type']);
184
				$netbits = get_interface_subnet($pconfig['natlocalid_type']);
185

    
186
				if (empty($address) || empty($netbits))
187
					$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['natlocalid_type']) . " " . gettext("has no subnet.");
188
			}
189
		}
190

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

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

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

    
263
	if (!$input_errors) {
264

    
265
		$ph2ent = array();
266
		$ph2ent['ikeid'] = $pconfig['ikeid'];
267
		$ph2ent['uniqid'] = $pconfig['uniqid'];
268
		$ph2ent['mode'] = $pconfig['mode'];
269
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
270

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

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

    
286
		if (isset($pconfig['mobile']))
287
			$ph2ent['mobile'] = true;
288

    
289
		if ($ph2found === true && $a_phase2[$p2index])
290
			$a_phase2[$p2index] = $ph2ent;
291
		else
292
			$a_phase2[] = $ph2ent;
293

    
294

    
295
		write_config();
296
		mark_subsystem_dirty('ipsec');
297

    
298
		header("Location: vpn_ipsec.php");
299
		exit;
300
	}
301
}
302

    
303
if ($pconfig['mobile'])
304
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
305
else
306
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
307
$shortcut_section = "ipsec";
308

    
309

    
310
include("head.inc");
311

    
312
?>
313

    
314
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
315
<?php include("fbegin.inc"); ?>
316
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
317
<script type="text/javascript">
318
//<![CDATA[
319

    
320
function change_mode() {
321
	index = document.iform.mode.selectedIndex;
322
	value = document.iform.mode.options[index].value;
323
	if ((value == 'tunnel') || (value == 'tunnel6')) {
324
		document.getElementById('opt_localid').style.display = '';
325
<?php if (!isset($pconfig['mobile'])): ?>
326
		document.getElementById('opt_remoteid').style.display = '';
327
<?php endif; ?>
328
	} else {
329
		document.getElementById('opt_localid').style.display = 'none';
330
<?php if (!isset($pconfig['mobile'])): ?>
331
		document.getElementById('opt_remoteid').style.display = 'none';
332
<?php endif; ?>
333
	}
334
}
335

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

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

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

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

    
457
<?php endif; ?>
458

    
459
function change_protocol() {
460
	index = document.iform.proto.selectedIndex;
461
	value = document.iform.proto.options[index].value;
462
	if (value == 'esp')
463
		document.getElementById('opt_enc').style.display = '';
464
	else
465
		document.getElementById('opt_enc').style.display = 'none';
466
}
467

    
468
//]]>
469
</script>
470

    
471
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
472

    
473
<?php
474
	if ($input_errors)
475
		print_input_errors($input_errors);
476
?>
477

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

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

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

    
803
<?php
804

    
805
/* local utility functions */
806

    
807
function pconfig_to_ealgos(& $pconfig) {
808
	global $p2_ealgos;
809

    
810
	$ealgos = array();
811
	if (is_array($pconfig['ealgos'])) {
812
		foreach ($p2_ealgos as $algo_name => $algo_data) {
813
			if (in_array($algo_name,$pconfig['ealgos'])) {
814
				$ealg = array();
815
				$ealg['name'] = $algo_name;
816
				if (is_array($algo_data['keysel']))
817
					$ealg['keylen'] = $_POST["keylen_".$algo_name];
818
				$ealgos[] = $ealg;
819
			}
820
		}
821
	}
822

    
823
	return $ealgos;
824
}
825

    
826
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
827

    
828
	$pconfig['ealgos'] = array();
829
	foreach ($ealgos as $algo_data) {
830
		$pconfig['ealgos'][] = $algo_data['name'];
831
		if (isset($algo_data['keylen']))
832
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
833
	}
834

    
835
	return $ealgos;
836
}
837

    
838
function pconfig_to_idinfo($prefix,& $pconfig) {
839

    
840
	$type = $pconfig[$prefix."id_type"];
841
	$address = $pconfig[$prefix."id_address"];
842
	$netbits = $pconfig[$prefix."id_netbits"];
843

    
844
	switch( $type )
845
	{
846
		case "address":
847
			return array('type' => $type, 'address' => $address);
848
		case "network":
849
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
850
		default:
851
			return array('type' => $type );
852
	}
853
}
854

    
855
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
856

    
857
	switch( $idinfo['type'] )
858
	{
859
		case "address":
860
			$pconfig[$prefix."id_type"] = $idinfo['type'];
861
			$pconfig[$prefix."id_address"] = $idinfo['address'];
862
			break;
863
		case "network":
864
			$pconfig[$prefix."id_type"] = $idinfo['type'];
865
			$pconfig[$prefix."id_address"] = $idinfo['address'];
866
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
867
			break;
868
		default:
869
			$pconfig[$prefix."id_type"] = $idinfo['type'];
870
			break;
871
	}
872
}
873

    
874
?>
(241-241/255)