Project

General

Profile

Download (35.3 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
	$pconfig['reqid'] = $ph2['reqid'];
97

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

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

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

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

    
127
if ($_POST) {
128

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

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

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

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

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

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

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

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

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

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

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

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

    
317
	if (!$input_errors) {
318

    
319
		$ph2ent = array();
320
		$ph2ent['ikeid'] = $pconfig['ikeid'];
321
		$ph2ent['uniqid'] = $pconfig['uniqid'];
322
		$ph2ent['mode'] = $pconfig['mode'];
323
		$ph2ent['disabled'] = $pconfig['disabled'] ? true : false;
324
		if (!isset($pconfig['reqid']))
325
			$ph2ent['reqid'] = ipsec_new_reqid();
326
		else
327
			$ph2ent['reqid'] = $pconfig['reqid'];
328

    
329
		if(($ph2ent['mode'] == "tunnel") || ($ph2ent['mode'] == "tunnel6")){
330
			if (!empty($pconfig['natlocalid_address']))
331
				$ph2ent['natlocalid'] = pconfig_to_idinfo("natlocal",$pconfig);
332
			$ph2ent['localid'] = pconfig_to_idinfo("local",$pconfig);
333
			$ph2ent['remoteid'] = pconfig_to_idinfo("remote",$pconfig);
334
		}
335

    
336
		$ph2ent['protocol'] = $pconfig['proto'];
337
		$ph2ent['encryption-algorithm-option'] = $ealgos;
338
		if (!empty($pconfig['halgos']))
339
			$ph2ent['hash-algorithm-option'] = $pconfig['halgos'];
340
		else
341
			unset($ph2ent['hash-algorithm-option']);
342
		$ph2ent['pfsgroup'] = $pconfig['pfsgroup'];
343
		$ph2ent['lifetime'] = $pconfig['lifetime'];
344
		$ph2ent['pinghost'] = $pconfig['pinghost'];
345
		$ph2ent['descr'] = $pconfig['descr'];
346

    
347
		if (isset($pconfig['mobile']))
348
			$ph2ent['mobile'] = true;
349

    
350
		if ($ph2found === true && $a_phase2[$p2index])
351
			$a_phase2[$p2index] = $ph2ent;
352
		else
353
			$a_phase2[] = $ph2ent;
354

    
355

    
356
		write_config();
357
		mark_subsystem_dirty('ipsec');
358

    
359
		header("Location: vpn_ipsec.php");
360
		exit;
361
	}
362
}
363

    
364
if ($pconfig['mobile'])
365
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"), gettext("Mobile Client"));
366
else
367
    $pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 2"));
368
$shortcut_section = "ipsec";
369

    
370

    
371
include("head.inc");
372

    
373
?>
374

    
375
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
376
<?php include("fbegin.inc"); ?>
377
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
378
<script type="text/javascript">
379
//<![CDATA[
380

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

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

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

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

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

    
518
<?php endif; ?>
519

    
520
function change_protocol() {
521
	index = document.iform.proto.selectedIndex;
522
	value = document.iform.proto.options[index].value;
523
	if (value == 'esp')
524
		document.getElementById('opt_enc').style.display = '';
525
	else
526
		document.getElementById('opt_enc').style.display = 'none';
527
}
528

    
529
//]]>
530
</script>
531

    
532
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
533

    
534
<?php
535
	if ($input_errors)
536
		print_input_errors($input_errors);
537
?>
538

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

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

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

    
867
<?php
868

    
869
/* local utility functions */
870

    
871
function pconfig_to_ealgos(& $pconfig) {
872
	global $p2_ealgos;
873

    
874
	$ealgos = array();
875
	if (is_array($pconfig['ealgos'])) {
876
		foreach ($p2_ealgos as $algo_name => $algo_data) {
877
			if (in_array($algo_name,$pconfig['ealgos'])) {
878
				$ealg = array();
879
				$ealg['name'] = $algo_name;
880
				if (is_array($algo_data['keysel']))
881
					$ealg['keylen'] = $_POST["keylen_".$algo_name];
882
				$ealgos[] = $ealg;
883
			}
884
		}
885
	}
886

    
887
	return $ealgos;
888
}
889

    
890
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
891

    
892
	$pconfig['ealgos'] = array();
893
	foreach ($ealgos as $algo_data) {
894
		$pconfig['ealgos'][] = $algo_data['name'];
895
		if (isset($algo_data['keylen']))
896
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
897
	}
898

    
899
	return $ealgos;
900
}
901

    
902
function pconfig_to_idinfo($prefix,& $pconfig) {
903

    
904
	$type = $pconfig[$prefix."id_type"];
905
	$address = $pconfig[$prefix."id_address"];
906
	$netbits = $pconfig[$prefix."id_netbits"];
907

    
908
	switch( $type )
909
	{
910
		case "address":
911
			return array('type' => $type, 'address' => $address);
912
		case "network":
913
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
914
		default:
915
			return array('type' => $type );
916
	}
917
}
918

    
919
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
920

    
921
	switch( $idinfo['type'] )
922
	{
923
		case "address":
924
			$pconfig[$prefix."id_type"] = $idinfo['type'];
925
			$pconfig[$prefix."id_address"] = $idinfo['address'];
926
			break;
927
		case "network":
928
			$pconfig[$prefix."id_type"] = $idinfo['type'];
929
			$pconfig[$prefix."id_address"] = $idinfo['address'];
930
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
931
			break;
932
		default:
933
			$pconfig[$prefix."id_type"] = $idinfo['type'];
934
			break;
935
	}
936
}
937

    
938
?>
(242-242/256)