Project

General

Profile

Download (35 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) 2003-2005 Manuel Kasper <mk@neon1.net>.
7
	Copyright (C) 2008 Shrew Soft Inc
8
        Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
##|+PRIV
34
##|*IDENT=page-vpn-ipsec-editphase2
35
##|*NAME=VPN: IPsec: Edit Phase 2 page
36
##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 2' page.
37
##|*MATCH=vpn_ipsec_phase2.php*
38
##|-PRIV
39

    
40
require("functions.inc");
41
require("guiconfig.inc");
42
require_once("ipsec.inc");
43
require_once("vpn.inc");
44

    
45
if (!is_array($config['ipsec']['client']))
46
	$config['ipsec']['client'] = array();
47

    
48
$a_client = &$config['ipsec']['client'];
49

    
50
if (!is_array($config['ipsec']['phase1']))
51
	$config['ipsec']['phase1'] = array();
52

    
53
if (!is_array($config['ipsec']['phase2']))
54
	$config['ipsec']['phase2'] = array();
55

    
56
$a_phase1 = &$config['ipsec']['phase1'];
57
$a_phase2 = &$config['ipsec']['phase2'];
58

    
59
if (!empty($_GET['p2index']))
60
	$uindex = $_GET['p2index'];
61
if (!empty($_POST['uniqid']))
62
	$uindex = $_POST['uniqid'];
63

    
64
if (!empty($_GET['dup']))
65
	$uindex = $_GET['dup'];
66

    
67
$ph2found = false;
68
if (isset($uindex)) {
69
	foreach ($a_phase2 as $p2index => $ph2) {
70
		if ($ph2['uniqid'] == $uindex) {
71
			$ph2found = true;
72
			break;
73
		}
74
	}
75
}
76

    
77
if ($ph2found === true)
78
{
79
	$pconfig['ikeid'] = $ph2['ikeid'];
80
	$pconfig['disabled'] = isset($ph2['disabled']);
81
	$pconfig['mode'] = $ph2['mode'];
82
	$pconfig['descr'] = $ph2['descr'];
83
	$pconfig['uniqid'] = $ph2['uniqid'];
84

    
85
	if (!empty($ph2['natlocalid']))
86
		idinfo_to_pconfig("natlocal",$ph2['natlocalid'],$pconfig);
87
	idinfo_to_pconfig("local",$ph2['localid'],$pconfig);
88
	idinfo_to_pconfig("remote",$ph2['remoteid'],$pconfig);
89

    
90
	$pconfig['proto'] = $ph2['protocol'];
91
	ealgos_to_pconfig($ph2['encryption-algorithm-option'],$pconfig);
92
	$pconfig['halgos'] = $ph2['hash-algorithm-option'];
93
	$pconfig['pfsgroup'] = $ph2['pfsgroup'];
94
	$pconfig['lifetime'] = $ph2['lifetime'];
95
	$pconfig['pinghost'] = $ph2['pinghost'];
96

    
97
	if (isset($ph2['mobile']))
98
		$pconfig['mobile'] = true;
99
}
100
else
101
{
102
	$pconfig['ikeid'] = $_GET['ikeid'];
103

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

    
114
	/* mobile client */
115
	if($_GET['mobile'])
116
		$pconfig['mobile']=true;
117
}
118

    
119
unset($ph2);
120
if (!empty($_GET['dup'])) {
121
	unset($uindex);
122
	unset($p2index);
123
	$pconfig['uniqid'] = uniqid();
124
}
125

    
126
if ($_POST) {
127

    
128
	unset($input_errors);
129
	$pconfig = $_POST;
130

    
131
	if (!isset( $_POST['ikeid']))
132
		$input_errors[] = gettext("A valid ikeid must be specified.");
133

    
134
	/* input validation */
135
	$reqdfields = explode(" ", "localid_type uniqid");
136
	$reqdfieldsn = array(gettext("Local network type"), gettext("Unique Identifier"));
137
	if (!isset($pconfig['mobile'])){
138
		$reqdfields[] = "remoteid_type";
139
		$reqdfieldsn[] = gettext("Remote network type");
140
	}
141

    
142
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
143

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

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

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

    
186
			if (is_array($config['interfaces'][$pconfig['natlocalid_type']])) {
187
				// Don't let an empty subnet into racoon.conf, it can cause parse errors. Ticket #2201.
188
				$address = get_interface_ip($pconfig['natlocalid_type']);
189
				$netbits = get_interface_subnet($pconfig['natlocalid_type']);
190

    
191
				if (empty($address) || empty($netbits))
192
					$input_errors[] = gettext("Invalid Local Network.") . " " . convert_friendly_interface_to_friendly_descr($pconfig['natlocalid_type']) . " " . gettext("has no subnet.");
193
			}
194
		}
195

    
196
		switch ($pconfig['remoteid_type']) {
197
			case "network":
198
				if (($pconfig['remoteid_netbits'] != 0 && !$pconfig['remoteid_netbits']) || !is_numeric($pconfig['remoteid_netbits']))
199
					$input_errors[] = gettext("A valid remote network bit count must be specified.");
200
			case "address":
201
				if (!$pconfig['remoteid_address'] || !is_ipaddr($pconfig['remoteid_address']))
202
					$input_errors[] = gettext("A valid remote network IP address must be specified.");
203
				elseif (is_ipaddrv4($pconfig['remoteid_address']) && ($pconfig['mode'] != "tunnel"))
204
					$input_errors[] = gettext("A valid remote network IPv4 address must be specified or you need to change Mode to IPv6");
205
				elseif (is_ipaddrv6($pconfig['remoteid_address']) && ($pconfig['mode'] != "tunnel6"))
206
					$input_errors[] = gettext("A valid remote network IPv6 address must be specified or you need to change Mode to IPv4");
207
				break;
208
		}
209
	}
210
	/* Validate enabled phase2's are not duplicates */
211
	if (isset($pconfig['mobile'])){
212
		/* User is adding phase 2 for mobile phase1 */
213
		foreach($a_phase2 as $key => $name){
214
			if (isset($name['mobile']) && $name['uniqid'] != $pconfig['uniqid']) {
215
				/* check duplicate localids only for mobile clents */
216
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
217
				$entered = array();
218
				$entered['type'] = $pconfig['localid_type'];
219
				if (isset($pconfig['localid_address'])) $entered['address'] = $pconfig['localid_address'];
220
				if (isset($pconfig['localid_netbits'])) $entered['netbits'] = $pconfig['localid_netbits'];
221
				$entered_localid_data = ipsec_idinfo_to_cidr($entered, false, $pconfig['mode']);
222
				if ($localid_data == $entered_localid_data){
223
					/* adding new p2 entry */
224
					$input_errors[] = gettext("Phase2 with this Local Network is already defined for mobile clients.");
225
					break;
226
				}
227
			}
228
		}
229
	}else{
230
		/* User is adding phase 2 for site-to-site phase1 */
231
		$input_error = 0;
232
		foreach($a_phase2 as $key => $name){
233
			if (!isset($name['mobile']) && $pconfig['ikeid'] == $name['ikeid'] && $pconfig['uniqid'] != $name['uniqid']) {
234
				/* check duplicate subnets only for given phase1 */
235
				$localid_data = ipsec_idinfo_to_cidr($name['localid'], false, $name['mode']);
236
				$remoteid_data = ipsec_idinfo_to_cidr($name['remoteid'], false, $name['mode']);
237
				$entered_local = array();
238
				$entered_local['type'] = $pconfig['localid_type'];
239
				if (isset($pconfig['localid_address'])) $entered_local['address'] = $pconfig['localid_address'];
240
				if (isset($pconfig['localid_netbits'])) $entered_local['netbits'] = $pconfig['localid_netbits'];
241
				$entered_localid_data = ipsec_idinfo_to_cidr($entered_local, false, $pconfig['mode']);
242
				$entered_remote = array();
243
				$entered_remote['type'] = $pconfig['remoteid_type'];
244
				if (isset($pconfig['remoteid_address'])) $entered_remote['address'] = $pconfig['remoteid_address'];
245
				if (isset($pconfig['remoteid_netbits'])) $entered_remote['netbits'] = $pconfig['remoteid_netbits'];
246
				$entered_remoteid_data = ipsec_idinfo_to_cidr($entered_remote, false, $pconfig['mode']);
247
				if ($localid_data == $entered_localid_data && $remoteid_data == $entered_remoteid_data) { 
248
					/* adding new p2 entry */
249
					$input_errors[] = gettext("Phase2 with this Local/Remote networks combination is already defined for this Phase1.");
250
					break;
251
				}
252
			}
253
		}
254
		foreach ($a_phase1 as $phase1) {
255
			if($phase1['ikeid'] == $pconfig['ikeid']) {
256
				/* This is the P1 for this entry, validate its remote-gateway and local interface isn't within tunnel */
257
				$entered_local = array();
258
				$entered_local['type'] = $pconfig['localid_type'];
259
				if (isset($pconfig['localid_address'])) $entered_local['address'] = $pconfig['localid_address'];
260
				if (isset($pconfig['localid_netbits'])) $entered_local['netbits'] = $pconfig['localid_netbits'];
261
				$entered_localid_data = ipsec_idinfo_to_cidr($entered_local, false, $pconfig['mode']);
262
				list($entered_local_network, $entered_local_mask) = split("/", $entered_localid_data);
263
				$entered_remote = array();
264
				$entered_remote['type'] = $pconfig['remoteid_type'];
265
				if (isset($pconfig['remoteid_address'])) $entered_remote['address'] = $pconfig['remoteid_address'];
266
				if (isset($pconfig['remoteid_netbits'])) $entered_remote['netbits'] = $pconfig['remoteid_netbits'];
267
				$entered_remoteid_data = ipsec_idinfo_to_cidr($entered_remote, false, $pconfig['mode']);
268
				list($entered_remote_network, $entered_remote_mask) = split("/", $entered_remoteid_data);
269
				if ($phase1['protocol'] == "inet6") { 
270
					$if = get_failover_interface($phase1['interface'], "inet6");
271
					$interfaceip = get_interface_ipv6($if);
272
				} else {
273
					$if = get_failover_interface($phase1['interface']);
274
					$interfaceip = get_interface_ip($if);
275
				}
276
				/* skip validation for hostnames, they're subject to change anyway */
277
				if (is_ipaddr($phase1['remote-gateway'])) {
278
					if ($pconfig['mode'] == "tunnel") {
279
						if(check_subnets_overlap($interfaceip, 32, $entered_local_network, $entered_local_mask) && check_subnets_overlap($phase1['remote-gateway'], 32, $entered_remote_network, $entered_remote_mask)) {
280
							$input_errors[] = gettext("The local and remote networks of a phase 2 entry cannot overlap the outside of the tunnel (interface and remote gateway) configured in its phase 1.");
281
							break;
282
						}
283
					} else if ($pconfig['mode'] == "tunnel6") {
284
						if(check_subnetsv6_overlap($interfaceip, 128, $entered_local_network, $entered_local_mask) && check_subnets_overlap($phase1['remote-gateway'], 128, $entered_remote_network, $entered_remote_mask)) {
285
							$input_errors[] = gettext("The local and remote networks of a phase 2 entry cannot overlap the outside of the tunnel (interface and remote gateway) configured in its phase 1.");
286
							break;
287
						}							
288
					}				
289
				}
290
			}
291
		}
292
        }
293

    
294
	/* For ESP protocol, handle encryption algorithms */
295
	if ( $pconfig['proto'] == "esp") {
296
		$ealgos = pconfig_to_ealgos($pconfig);
297

    
298
		if (!count($ealgos)) {
299
			$input_errors[] = gettext("At least one encryption algorithm must be selected.");
300
		} else {
301
			if (empty($pconfig['halgos'])) {
302
				foreach ($ealgos as $ealgo) {
303
					if (!strpos($ealgo['name'], "gcm")) {
304
						$input_errors[] = gettext("At least one hashing algorithm needs to be selected.");
305
						break;
306
					}
307
				}
308
			}
309
		}
310
		
311
	}
312
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
313
		$input_errors[] = gettext("The P2 lifetime must be an integer.");
314
	}
315

    
316
	if (!$input_errors) {
317

    
318
		$ph2ent = array();
319
		$ph2ent['ikeid'] = $pconfig['ikeid'];
320
		$ph2ent['uniqid'] = $pconfig['uniqid'];
321
		$ph2ent['mode'] = $pconfig['mode'];
322
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
323

    
324
		if(($ph2ent['mode'] == "tunnel") || ($ph2ent['mode'] == "tunnel6")){
325
			if (!empty($pconfig['natlocalid_address']))
326
				$ph2ent['natlocalid'] = pconfig_to_idinfo("natlocal",$pconfig);
327
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
328
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
329
		}
330

    
331
		$ph2ent['protocol'] = $pconfig['proto'];
332
		$ph2ent['encryption-algorithm-option'] = $ealgos;
333
		if (!empty($pconfig['halgos']))
334
			$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
335
		else
336
			unset($ph2ent['hash-algorithm-option']);
337
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
338
		$ph2ent['lifetime'] = $pconfig['lifetime'];
339
		$ph2ent['pinghost'] = $pconfig['pinghost'];
340
		$ph2ent['descr'] = $pconfig['descr'];
341

    
342
		if (isset($pconfig['mobile']))
343
			$ph2ent['mobile'] = true;
344

    
345
		if ($ph2found === true && $a_phase2[$p2index])
346
			$a_phase2[$p2index] = $ph2ent;
347
		else
348
			$a_phase2[] = $ph2ent;
349

    
350

    
351
		write_config();
352
		mark_subsystem_dirty('ipsec');
353

    
354
		header("Location: vpn_ipsec.php");
355
		exit;
356
	}
357
}
358

    
359
if ($pconfig['mobile'])
360
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
361
else
362
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
363
$shortcut_section = "ipsec";
364

    
365

    
366
include("head.inc");
367

    
368
?>
369

    
370
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
371
<?php include("fbegin.inc"); ?>
372
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
373
<script type="text/javascript">
374
//<![CDATA[
375

    
376
function change_mode() {
377
	index = document.iform.mode.selectedIndex;
378
	value = document.iform.mode.options[index].value;
379
	if ((value == 'tunnel') || (value == 'tunnel6')) {
380
		document.getElementById('opt_localid').style.display = '';
381
<?php if (!isset($pconfig['mobile'])): ?>
382
		document.getElementById('opt_remoteid').style.display = '';
383
<?php endif; ?>
384
	} else {
385
		document.getElementById('opt_localid').style.display = 'none';
386
<?php if (!isset($pconfig['mobile'])): ?>
387
		document.getElementById('opt_remoteid').style.display = 'none';
388
<?php endif; ?>
389
	}
390
}
391

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

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

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

    
476
function typesel_change_remote(bits) {
477
	var value = document.iform.mode.options[index].value;
478
	if (typeof(bits) === "undefined") {
479
		if (value === "tunnel") {
480
			bits = 24;
481
		}
482
		else if (value === "tunnel6") {
483
			bits = 64;
484
		}
485
	}
486
	var address_is_blank = !/\S/.test(document.iform.remoteid_address.value);
487
	switch (document.iform.remoteid_type.selectedIndex) {
488
		case 0:	/* single */
489
			document.iform.remoteid_address.disabled = 0;
490
			if (address_is_blank) {
491
				document.iform.remoteid_netbits.value = 0;
492
			}
493
			document.iform.remoteid_netbits.disabled = 1;
494
			break;
495
		case 1:	/* network */
496
			document.iform.remoteid_address.disabled = 0;
497
			if (address_is_blank) {
498
				document.iform.remoteid_netbits.value = bits;
499
			}
500
			document.iform.remoteid_netbits.disabled = 0;
501
			break;
502
		default:
503
			document.iform.remoteid_address.value = "";
504
			document.iform.remoteid_address.disabled = 1;
505
			if (address_is_blank) {
506
				document.iform.remoteid_netbits.value = 0;
507
			}
508
			document.iform.remoteid_netbits.disabled = 1;
509
			break;
510
	}
511
}
512

    
513
<?php endif; ?>
514

    
515
function change_protocol() {
516
	index = document.iform.proto.selectedIndex;
517
	value = document.iform.proto.options[index].value;
518
	if (value == 'esp')
519
		document.getElementById('opt_enc').style.display = '';
520
	else
521
		document.getElementById('opt_enc').style.display = 'none';
522
}
523

    
524
//]]>
525
</script>
526

    
527
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
528

    
529
<?php
530
	if ($input_errors)
531
		print_input_errors($input_errors);
532
?>
533

    
534
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="vpn ipsec phase-2">
535
	<tr class="tabnavtbl">
536
		<td id="tabnav">
537
			<?php
538
				$tab_array = array();
539
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
540
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
541
				$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
542
				$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
543
				display_top_tabs($tab_array);
544
			?>
545
		</td>
546
	</tr>
547
	<tr>
548
		<td id="mainarea">
549
			<div class="tabcont">
550
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
551
					<tr>
552
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
553
						<td width="78%" class="vtable">
554
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
555
							<strong><?=gettext("Disable this phase2 entry"); ?></strong>
556
							<br />
557
							<span class="vexpl"><?=gettext("Set this option to disable this phase2 entry without " .
558
							  "removing it from the list"); ?>.
559
							</span>
560
						</td>
561
					</tr>
562
					<tr>
563
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
564
						<td width="78%" class="vtable">
565
							<select name="mode" class="formselect" onchange="change_mode()">
566
								<?php
567
									foreach($p2_modes as $name => $value):
568
										$selected = "";
569
										if ($name == $pconfig['mode'])
570
											$selected = "selected=\"selected\"";
571
								?>
572
								<option value="<?=$name;?>" <?=$selected;?>><?=$value;?></option>
573
								<?php endforeach; ?>
574
							</select>
575
						</td>
576
					</tr>
577
					<tr id="opt_localid">
578
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local Network"); ?></td>
579
						<td width="78%" class="vtable">
580
							<table border="0" cellspacing="0" cellpadding="0" summary="local network">
581
								<tr>
582
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
583
									<td></td>
584
									<td>
585
										<select name="localid_type" class="formselect" onchange="typesel_change_local()">
586
											<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected=\"selected\"";?>><?=gettext("Address"); ?></option>
587
											<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected=\"selected\"";?>><?=gettext("Network"); ?></option>
588
											<?php
589
												$iflist = get_configured_interface_with_descr();
590
												foreach ($iflist as $ifname => $ifdescr):
591
											?>
592
											<option value="<?=$ifname; ?>" <?php if ($pconfig['localid_type'] == $ifname ) echo "selected=\"selected\"";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
593
											<?php endforeach; ?>
594
										</select>
595
									</td>
596
								</tr>
597
								<tr>
598
									<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
599
									<td><?=$mandfldhtmlspc;?></td>
600
									<td>
601
										<input name="localid_address" type="text" class="formfld unknown ipv4v6" id="localid_address" size="28" value="<?=htmlspecialchars($pconfig['localid_address']);?>" />
602
										/
603
										<select name="localid_netbits" class="formselect ipv4v6" id="localid_netbits">
604
										<?php for ($i = 128; $i >= 0; $i--): ?>
605
											<option value="<?=$i;?>" <?php if (isset($pconfig['localid_netbits']) && $i == $pconfig['localid_netbits']) echo "selected=\"selected\""; ?>>
606
												<?=$i;?>
607
											</option>
608
										<?php endfor; ?>
609
										</select>
610
									</td>
611
								</tr>
612
								<tr> <td colspan="3">
613
								<br />
614
								<?php echo gettext("In case you need NAT/BINAT on this network specify the address to be translated"); ?>
615
								</td></tr>
616
								<tr>
617
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
618
									<td></td>
619
									<td>
620
										<select name="natlocalid_type" class="formselect" onchange="typesel_change_natlocal()">
621
											<option value="address" <?php if ($pconfig['natlocalid_type'] == "address") echo "selected=\"selected\"";?>><?=gettext("Address"); ?></option>
622
											<option value="network" <?php if ($pconfig['natlocalid_type'] == "network") echo "selected=\"selected\"";?>><?=gettext("Network"); ?></option>
623
											<?php
624
												$iflist = get_configured_interface_with_descr();
625
												foreach ($iflist as $ifname => $ifdescr):
626
											?>
627
											<option value="<?=$ifname; ?>" <?php if ($pconfig['natlocalid_type'] == $ifname ) echo "selected=\"selected\"";?>><?=sprintf(gettext("%s subnet"), $ifdescr); ?></option>
628
											<?php endforeach; ?>
629
											<option value="none" <?php if (empty($pconfig['natlocalid_type']) || $pconfig['natlocalid_type'] == "none" ) echo "selected=\"selected\"";?>><?=gettext("None"); ?></option>
630
										</select>
631
									</td>
632
								</tr>
633
								<tr>
634
									<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
635
									<td><?=$mandfldhtmlspc;?></td>
636
									<td>
637
										<input name="natlocalid_address" type="text" class="formfld unknown ipv4v6" id="natlocalid_address" size="28" value="<?=htmlspecialchars($pconfig['natlocalid_address']);?>" />
638
										/
639
										<select name="natlocalid_netbits" class="formselect ipv4v6" id="natlocalid_netbits">
640
										<?php for ($i = 128; $i >= 0; $i--): ?>
641
											<option value="<?=$i;?>" <?php if (isset($pconfig['natlocalid_netbits']) && $i == $pconfig['natlocalid_netbits']) echo "selected=\"selected\""; ?>>
642
												<?=$i;?>
643
											</option>
644
										<?php endfor; ?>
645
										</select>
646
									</td>
647
								</tr>
648
							</table>
649
						</td>
650
					</tr>
651

    
652
					<?php if (!isset($pconfig['mobile'])): ?>
653
					
654
					<tr id="opt_remoteid">
655
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote Network"); ?></td>
656
						<td width="78%" class="vtable">
657
							<table border="0" cellspacing="0" cellpadding="0" summary="remote network">
658
								<tr>
659
									<td><?=gettext("Type"); ?>:&nbsp;&nbsp;</td>
660
									<td></td>
661
									<td>
662
										<select name="remoteid_type" class="formselect" onchange="typesel_change_remote()">
663
											<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected=\"selected\""; ?>><?=gettext("Address"); ?></option>
664
											<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network"); ?></option>
665
										</select>
666
									</td>
667
								</tr>
668
								<tr>
669
									<td><?=gettext("Address"); ?>:&nbsp;&nbsp;</td>
670
									<td><?=$mandfldhtmlspc;?></td>
671
									<td>
672
										<input name="remoteid_address" type="text" class="formfld unknown ipv4v6" id="remoteid_address" size="28" value="<?=htmlspecialchars($pconfig['remoteid_address']);?>" />
673
										/
674
										<select name="remoteid_netbits" class="formselect ipv4v6" id="remoteid_netbits">
675
										<?php for ($i = 128; $i >= 0; $i--) { 
676
											
677
											echo "<option value=\"{$i}\"";
678
											if (isset($pconfig['remoteid_netbits']) && $i == $pconfig['remoteid_netbits']) echo " selected=\"selected\"";
679
											echo ">{$i}</option>\n";
680
											} ?>
681
										</select>
682
									</td>
683
								</tr>
684
							</table>
685
						</td>
686
					</tr>
687
					
688
					<?php endif; ?>
689
					
690
					<tr>
691
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
692
						<td width="78%" class="vtable">
693
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
694
							<br />
695
							<span class="vexpl">
696
								<?=gettext("You may enter a description here " .
697
								"for your reference (not parsed)"); ?>.
698
							</span>
699
						</td>
700
					</tr>
701
					<tr>
702
						<td colspan="2" class="list" height="12"></td>
703
					</tr>
704
					<tr>
705
						<td colspan="2" valign="top" class="listtopic">
706
							<?=gettext("Phase 2 proposal (SA/Key Exchange)"); ?>
707
						</td>
708
					</tr>
709
					<tr>
710
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
711
						<td width="78%" class="vtable">
712
							<select name="proto" class="formselect" onchange="change_protocol()">
713
							<?php foreach ($p2_protos as $proto => $protoname): ?>
714
								<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected=\"selected\""; ?>>
715
									<?=htmlspecialchars($protoname);?>
716
								</option>
717
							<?php endforeach; ?>
718
							</select>
719
							<br />
720
							<span class="vexpl">
721
								<?=gettext("ESP is encryption, AH is authentication only"); ?>
722
							</span>
723
						</td>
724
					</tr>
725
					<tr id="opt_enc">
726
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithms"); ?></td>
727
						<td width="78%" class="vtable">
728
							<table border="0" cellspacing="0" cellpadding="0" summary="encryption">
729
							<?php
730
								foreach ($p2_ealgos as $algo => $algodata):
731
									$checked = '';
732
									if (is_array($pconfig['ealgos']) && in_array($algo,$pconfig['ealgos']))
733
										$checked = " checked=\"checked\"";
734
								?>
735
								<tr>
736
									<td>
737
										<input type="checkbox" name="ealgos[]" value="<?=$algo;?>"<?=$checked?> />
738
									</td>
739
									<td>
740
										<?=htmlspecialchars($algodata['name']);?>
741
									</td>
742
									<td>
743
										<?php if(is_array($algodata['keysel'])): ?>
744
										&nbsp;&nbsp;
745
										<select name="keylen_<?=$algo;?>" class="formselect">
746
											<option value="auto"><?=gettext("auto"); ?></option>
747
											<?php
748
												$key_hi = $algodata['keysel']['hi'];
749
												$key_lo = $algodata['keysel']['lo'];
750
												$key_step = $algodata['keysel']['step'];
751
												for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
752
													$selected = "";
753
				//									if ($checked && in_array("keylen_".$algo,$pconfig))
754
													if ($keylen == $pconfig["keylen_".$algo])
755
														$selected = " selected=\"selected\"";
756
											?>
757
											<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> <?=gettext("bits"); ?></option>
758
											<?php endfor; ?>
759
										</select>
760
										<?php endif; ?>
761
									</td>
762
								</tr>
763
								
764
								<?php endforeach; ?>
765
								
766
							</table>
767
							<br />
768
							<?=gettext("Hint: use 3DES for best compatibility or if you have a hardware " . 
769
							"crypto accelerator card. Blowfish is usually the fastest in " .
770
							"software encryption"); ?>.
771
						</td>
772
					</tr>
773
					<tr>
774
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithms"); ?></td>
775
						<td width="78%" class="vtable">
776
						<?php foreach ($p2_halgos as $algo => $algoname): ?>
777
							<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked=\"checked\""; ?> />
778
							<?=htmlspecialchars($algoname);?>
779
							<br />
780
						<?php endforeach; ?>
781
						</td>
782
					</tr>
783
					<tr>
784
						<td width="22%" valign="top" class="vncellreq"><?=gettext("PFS key group"); ?></td>
785
						<td width="78%" class="vtable">
786
						<?php if (!isset($pconfig['mobile']) || !isset($a_client['pfs_group'])): ?>
787
							<select name="pfsgroup" class="formselect">
788
							<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
789
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected=\"selected\""; ?>>
790
									<?=htmlspecialchars($keygroupname);?>
791
								</option>
792
							<?php endforeach; ?>
793
							</select>
794
							<br />
795
							<?php else: ?>
796

    
797
							<select class="formselect" disabled="disabled">
798
								<option selected="selected"><?=$p2_pfskeygroups[$a_client['pfs_group']];?></option>
799
							</select>
800
							<input name="pfsgroup" type="hidden" value="<?=htmlspecialchars($pconfig['pfsgroup']);?>" />
801
							<br />
802
							<span class="vexpl"><em><?=gettext("Set globally in mobile client options"); ?></em></span>
803
						<?php endif; ?>
804
						</td>
805
					</tr>
806
					<tr>
807
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
808
						<td width="78%" class="vtable">
809
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />
810
							<?=gettext("seconds"); ?>
811
						</td>
812
					</tr>
813
					<tr>
814
						<td colspan="2" class="list" height="12"></td>
815
					</tr>
816
					<tr>
817
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
818
					</tr>
819
					<tr>
820
						<td width="22%" valign="top" class="vncell"><?=gettext("Automatically ping host"); ?></td>
821
						<td width="78%" class="vtable">
822
							<input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="28" value="<?=htmlspecialchars($pconfig['pinghost']);?>" />
823
							<?=gettext("IP address"); ?>
824
						</td>
825
					</tr>
826
					<tr>
827
						<td width="22%" valign="top">&nbsp;</td>
828
						<td width="78%">
829
						<?php if ($pconfig['mobile']): ?>
830
							<input name="mobile" type="hidden" value="true" />
831
							<input name="remoteid_type" type="hidden" value="mobile" />
832
						<?php endif; ?>
833
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
834
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>" />
835
							<input name="uniqid" type="hidden" value="<?=htmlspecialchars($pconfig['uniqid']);?>" />
836
						</td>
837
					</tr>
838
				</table>
839
			</div>
840
		</td>
841
	</tr>
842
</table>
843
</form>
844
<script type="text/javascript">
845
//<![CDATA[
846
change_mode('<?=htmlspecialchars($pconfig['mode'])?>');
847
change_protocol('<?=htmlspecialchars($pconfig['proto'])?>');
848
typesel_change_local(<?=htmlspecialchars($pconfig['localid_netbits'])?>);
849
typesel_change_natlocal(<?=htmlspecialchars($pconfig['natlocalid_netbits'])?>);
850
<?php if (!isset($pconfig['mobile'])): ?>
851
typesel_change_remote(<?=htmlspecialchars($pconfig['remoteid_netbits'])?>);
852
<?php endif; ?>
853
//]]>
854
</script>
855
<?php include("fend.inc"); ?>
856
</body>
857
</html>
858

    
859
<?php
860

    
861
/* local utility functions */
862

    
863
function pconfig_to_ealgos(& $pconfig) {
864
	global $p2_ealgos;
865

    
866
	$ealgos = array();
867
	if (is_array($pconfig['ealgos'])) {
868
		foreach ($p2_ealgos as $algo_name => $algo_data) {
869
			if (in_array($algo_name,$pconfig['ealgos'])) {
870
				$ealg = array();
871
				$ealg['name'] = $algo_name;
872
				if (is_array($algo_data['keysel']))
873
					$ealg['keylen'] = $_POST["keylen_".$algo_name];
874
				$ealgos[] = $ealg;
875
			}
876
		}
877
	}
878

    
879
	return $ealgos;
880
}
881

    
882
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
883

    
884
	$pconfig['ealgos'] = array();
885
	foreach ($ealgos as $algo_data) {
886
		$pconfig['ealgos'][] = $algo_data['name'];
887
		if (isset($algo_data['keylen']))
888
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
889
	}
890

    
891
	return $ealgos;
892
}
893

    
894
function pconfig_to_idinfo($prefix,& $pconfig) {
895

    
896
	$type = $pconfig[$prefix."id_type"];
897
	$address = $pconfig[$prefix."id_address"];
898
	$netbits = $pconfig[$prefix."id_netbits"];
899

    
900
	switch( $type )
901
	{
902
		case "address":
903
			return array('type' => $type, 'address' => $address);
904
		case "network":
905
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
906
		default:
907
			return array('type' => $type );
908
	}
909
}
910

    
911
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
912

    
913
	switch( $idinfo['type'] )
914
	{
915
		case "address":
916
			$pconfig[$prefix."id_type"] = $idinfo['type'];
917
			$pconfig[$prefix."id_address"] = $idinfo['address'];
918
			break;
919
		case "network":
920
			$pconfig[$prefix."id_type"] = $idinfo['type'];
921
			$pconfig[$prefix."id_address"] = $idinfo['address'];
922
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
923
			break;
924
		default:
925
			$pconfig[$prefix."id_type"] = $idinfo['type'];
926
			break;
927
	}
928
}
929

    
930
?>
(242-242/256)