Project

General

Profile

Download (36.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_phase1.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
	Copyright (C) 2014 Ermal LUÇI
9
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10
	All rights reserved.
11

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

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

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

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

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

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

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

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

    
52
$a_phase1 = &$config['ipsec']['phase1'];
53
$a_phase2 = &$config['ipsec']['phase2'];
54

    
55
if (is_numericint($_GET['p1index']))
56
	$p1index = $_GET['p1index'];
57
if (isset($_POST['p1index']) && is_numericint($_POST['p1index']))
58
	$p1index = $_POST['p1index'];
59

    
60
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
61
	$p1index = $_GET['dup'];
62

    
63
if (isset($p1index) && $a_phase1[$p1index]) {
64
	// don't copy the ikeid on dup
65
	if (!isset($_GET['dup']) || !is_numericint($_GET['dup']))
66
		$pconfig['ikeid'] = $a_phase1[$p1index]['ikeid'];
67

    
68
	$old_ph1ent = $a_phase1[$p1index];
69

    
70
	$pconfig['disabled'] = isset($a_phase1[$p1index]['disabled']);
71

    
72
	if ($a_phase1[$p1index]['interface'])
73
		$pconfig['interface'] = $a_phase1[$p1index]['interface'];
74
	else
75
		$pconfig['interface'] = "wan";
76

    
77
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_phase1[$p1index]['remote-subnet']);
78

    
79
	if (isset($a_phase1[$p1index]['mobile']))
80
		$pconfig['mobile'] = 'true';
81
	else
82
		$pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway'];
83

    
84
	if (empty($a_phase1[$p1index]['iketype']))
85
		$pconfig['iketype'] = "ikev1";
86
	else
87
		$pconfig['iketype'] = $a_phase1[$p1index]['iketype'];
88
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
89
	$pconfig['protocol'] = $a_phase1[$p1index]['protocol'];
90
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
91
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
92
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
93
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
94
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
95
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
96
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
97
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
98
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
99

    
100
	if (($pconfig['authentication_method'] == "pre_shared_key") ||
101
		($pconfig['authentication_method'] == "xauth_psk_server")) {
102
		$pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key'];
103
	} else {
104
		$pconfig['certref'] = $a_phase1[$p1index]['certref'];
105
		$pconfig['caref'] = $a_phase1[$p1index]['caref'];
106
	}
107

    
108
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
109
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
110

    
111
	if (isset($a_phase1[$p1index]['reauth_enable']))
112
		$pconfig['reauth_enable'] = true;
113
	if (isset($a_phase1[$p1index]['rekey_enable']))
114
		$pconfig['rekey_enable'] = true;
115

    
116
	if ($a_phase1[$p1index]['dpd_delay'] &&	$a_phase1[$p1index]['dpd_maxfail']) {
117
		$pconfig['dpd_enable'] = true;
118
		$pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay'];
119
		$pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail'];
120
	}
121
} else {
122
	/* defaults */
123
	$pconfig['interface'] = "wan";
124
	if($config['interfaces']['lan'])
125
		$pconfig['localnet'] = "lan";
126
	$pconfig['mode'] = "main";
127
	$pconfig['protocol'] = "inet";
128
	$pconfig['myid_type'] = "myaddress";
129
	$pconfig['peerid_type'] = "peeraddress";
130
	$pconfig['authentication_method'] = "pre_shared_key";
131
	$pconfig['ealgo'] = array( name => "3des" );
132
	$pconfig['halgo'] = "sha1";
133
	$pconfig['dhgroup'] = "2";
134
	$pconfig['lifetime'] = "28800";
135
	$pconfig['nat_traversal'] = 'on';
136
	$pconfig['dpd_enable'] = true;
137
	$pconfig['iketype'] = "ikev1";
138

    
139
	/* mobile client */
140
	if($_GET['mobile']) {
141
		$pconfig['mobile']=true;
142
                $pconfig['mode'] = "aggressive";
143
	}
144
}
145

    
146
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
147
	unset($p1index);
148

    
149
if ($_POST) {
150
	unset($input_errors);
151
	$pconfig = $_POST;
152

    
153
	/* input validation */
154

    
155
	$method = $pconfig['authentication_method'];
156
	// Unset ca and cert if not required to avaoid storing in config
157
	if ($method == "pre_shared_key" || $method == "xauth_psk_server"){
158
		unset($pconfig['caref']);
159
		unset($pconfig['certref']);
160
	}
161

    
162
	// Only require PSK here for normal PSK tunnels (not mobile) or xauth.
163
	// For RSA methods, require the CA/Cert.
164
	switch ($method) {
165
		case "eap-tls":
166
			if ($pconfig['iketype'] != 'ikev2')
167
				$input_errors[] = gettext("EAP-TLS can only be used with IKEv2 type VPNs.");
168
			break;
169
		case "pre_shared_key":
170
			// If this is a mobile PSK tunnel the user PSKs go on
171
			//    the PSK tab, not here, so skip the check.
172
			if ($pconfig['mobile'])
173
				break;
174
		case "xauth_psk_server":
175
			$reqdfields = explode(" ", "pskey");
176
			$reqdfieldsn = array(gettext("Pre-Shared Key"));
177
			$validate_pskey = true;
178
			break;
179
		case "hybrid_rsa_server":
180
		case "xauth_rsa_server":
181
		case "rsasig":
182
			$reqdfields = explode(" ", "caref certref");
183
			$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
184
			break;
185
	}
186
	if (!$pconfig['mobile']) {
187
		$reqdfields[] = "remotegw";
188
		$reqdfieldsn[] = gettext("Remote gateway");
189
	}
190

    
191
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
192

    
193
	if (isset($validate_pskey) && isset($pconfig['pskey']) && !preg_match('/^[[:ascii:]]*$/', $pconfig['pskey'])) {
194
		unset($validate_pskey);
195
		$input_errors[] = gettext("Pre-Shared Key contains invalid characters.");
196
	}
197

    
198
	if (($pconfig['lifetime'] && !is_numeric($pconfig['lifetime'])))
199
		$input_errors[] = gettext("The P1 lifetime must be an integer.");
200

    
201
	if ($pconfig['remotegw']) {
202
		if (!is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))
203
			$input_errors[] = gettext("A valid remote gateway address or host name must be specified.");
204
		elseif (is_ipaddrv4($pconfig['remotegw']) && ($pconfig['protocol'] != "inet"))
205
			$input_errors[] = gettext("A valid remote gateway IPv4 address must be specified or you need to change protocol to IPv6");
206
		elseif (is_ipaddrv6($pconfig['remotegw']) && ($pconfig['protocol'] != "inet6"))
207
			$input_errors[] = gettext("A valid remote gateway IPv6 address must be specified or you need to change protocol to IPv4");
208
	}
209

    
210
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
211
		$t = 0;
212
		foreach ($a_phase1 as $ph1tmp) {
213
			if ($p1index <> $t) {
214
				$tremotegw = $pconfig['remotegw'];
215
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
216
					$input_errors[] = sprintf(gettext('The remote gateway "%1$s" is already used by phase1 "%2$s".'), $tremotegw, $ph1tmp['descr']);
217
				}
218
			}
219
			$t++;
220
		}
221
	}
222

    
223
	if (is_array($a_phase2) && (count($a_phase2))) {
224
		foreach ($a_phase2 as $phase2) {
225
			if($phase2['ikeid'] == $pconfig['ikeid']) {
226
				if (($pconfig['protocol'] == "inet") && ($phase2['mode'] == "tunnel6")) {
227
					$input_errors[] = gettext("There is a Phase 2 using IPv6, you cannot use IPv4.");
228
					break;
229
				}
230
				if (($pconfig['protocol'] == "inet6") && ($phase2['mode'] == "tunnel")) {
231
					$input_errors[] = gettext("There is a Phase 2 using IPv4, you cannot use IPv6.");
232
					break;
233
				}
234
			}
235
		}
236
	}
237

    
238
	/* My identity */
239

    
240
	if ($pconfig['myid_type'] == "myaddress")
241
		$pconfig['myid_data'] = "";
242

    
243
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
244
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
245

    
246
	if ($pconfig['myid_type'] == "keyid tag" and $pconfig['myid_data'] == "")
247
		$input_errors[] = gettext("Please enter a keyid tag for 'My Identifier'");
248

    
249
	if ($pconfig['myid_type'] == "fqdn" and $pconfig['myid_data'] == "")
250
		$input_errors[] = gettext("Please enter a fully qualified domain name for 'My Identifier'");
251

    
252
	if ($pconfig['myid_type'] == "user_fqdn" and $pconfig['myid_data'] == "")
253
		$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'My Identifier'");
254

    
255
	if ($pconfig['myid_type'] == "dyn_dns" and $pconfig['myid_data'] == "")
256
		$input_errors[] = gettext("Please enter a dynamic domain name for 'My Identifier'");
257

    
258
	if ((($pconfig['myid_type'] == "address") && !is_ipaddr($pconfig['myid_data'])))
259
		$input_errors[] = gettext("A valid IP address for 'My identifier' must be specified.");
260

    
261
	if ((($pconfig['myid_type'] == "fqdn") && !is_domain($pconfig['myid_data'])))
262
		$input_errors[] = gettext("A valid domain name for 'My identifier' must be specified.");
263

    
264
	if ($pconfig['myid_type'] == "fqdn")
265
		if (is_domain($pconfig['myid_data']) == false)
266
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
267

    
268
	if ($pconfig['myid_type'] == "user_fqdn") {
269
		$user_fqdn = explode("@",$pconfig['myid_data']);
270
		if (is_domain($user_fqdn[1]) == false)
271
			$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.");
272
	}
273

    
274
	if ($pconfig['myid_type'] == "dyn_dns")
275
		if (is_domain($pconfig['myid_data']) == false)
276
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
277

    
278
	/* Peer identity */
279

    
280
	if ($pconfig['myid_type'] == "peeraddress")
281
		$pconfig['peerid_data'] = "";
282

    
283
	// Only enforce peer ID if we are not dealing with a pure-psk mobile config.
284
	if (!(($pconfig['authentication_method'] == "pre_shared_key") && ($pconfig['mobile']))) {
285
		if ($pconfig['peerid_type'] == "address" and $pconfig['peerid_data'] == "")
286
			$input_errors[] = gettext("Please enter an address for 'Peer Identifier'");
287

    
288
		if ($pconfig['peerid_type'] == "keyid tag" and $pconfig['peerid_data'] == "")
289
			$input_errors[] = gettext("Please enter a keyid tag for 'Peer Identifier'");
290

    
291
		if ($pconfig['peerid_type'] == "fqdn" and $pconfig['peerid_data'] == "")
292
			$input_errors[] = gettext("Please enter a fully qualified domain name for 'Peer Identifier'");
293

    
294
		if ($pconfig['peerid_type'] == "user_fqdn" and $pconfig['peerid_data'] == "")
295
			$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'Peer Identifier'");
296

    
297
		if ((($pconfig['peerid_type'] == "address") && !is_ipaddr($pconfig['peerid_data'])))
298
			$input_errors[] = gettext("A valid IP address for 'Peer identifier' must be specified.");
299

    
300
		if ((($pconfig['peerid_type'] == "fqdn") && !is_domain($pconfig['peerid_data'])))
301
			$input_errors[] = gettext("A valid domain name for 'Peer identifier' must be specified.");
302

    
303
		if ($pconfig['peerid_type'] == "fqdn")
304
			if (is_domain($pconfig['peerid_data']) == false)
305
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
306

    
307
		if ($pconfig['peerid_type'] == "user_fqdn") {
308
			$user_fqdn = explode("@",$pconfig['peerid_data']);
309
			if (is_domain($user_fqdn[1]) == false)
310
				$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.");
311
		}
312
	}
313

    
314
	if ($pconfig['dpd_enable']) {
315
		if (!is_numeric($pconfig['dpd_delay']))
316
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
317

    
318
		if (!is_numeric($pconfig['dpd_maxfail']))
319
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
320
	}
321

    
322
	if (!empty($pconfig['iketype']) && $pconfig['iketype'] != "ikev1" && $pconfig['iketype'] != "ikev2" && $pconfig['iketype'] != "auto")
323
		$input_errors[] = gettext("Valid arguments for IKE type is v1 or v2 or auto");
324

    
325
	/* build our encryption algorithms array */
326
	$pconfig['ealgo'] = array();
327
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
328
	if($pconfig['ealgo_keylen'])
329
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
330

    
331
	if (!$input_errors) {
332
		$ph1ent['ikeid'] = $pconfig['ikeid'];
333
		$ph1ent['iketype'] = $pconfig['iketype'];
334
		if ($pconfig['iketype'] != 'ikev1')
335
			unset($ph1ent['mode']);
336
		else
337
			$ph1ent['mode'] = $pconfig['mode'];
338
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
339
		$ph1ent['interface'] = $pconfig['interface'];
340
		/* if the remote gateway changed and the interface is not WAN then remove route */
341
		/* the vpn_ipsec_configure() handles adding the route */
342
		if ($pconfig['interface'] <> "wan") {
343
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
344
				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']}");
345
			}
346
		}
347

    
348
		if ($pconfig['mobile'])
349
			$ph1ent['mobile'] = true;
350
		else
351
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
352

    
353
		$ph1ent['protocol'] = $pconfig['protocol'];
354

    
355
		$ph1ent['myid_type'] = $pconfig['myid_type'];
356
		$ph1ent['myid_data'] = $pconfig['myid_data'];
357
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
358
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
359

    
360
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
361
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
362
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
363
		$ph1ent['lifetime'] = $pconfig['lifetime'];
364
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
365
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
366
		$ph1ent['certref'] = $pconfig['certref'];
367
		$ph1ent['caref'] = $pconfig['caref'];
368
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
369
		$ph1ent['descr'] = $pconfig['descr'];
370
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
371

    
372
		if (isset($pconfig['reauth_enable']))
373
			$ph1ent['reauth_enable'] = true;
374
		if (isset($pconfig['rekey_enable']))
375
			$ph1ent['rekey_enable'] = true;
376

    
377
		if (isset($pconfig['dpd_enable'])) {
378
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
379
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
380
		}
381

    
382
		/* generate unique phase1 ikeid */
383
		if ($ph1ent['ikeid'] == 0)
384
			$ph1ent['ikeid'] = ipsec_ikeid_next();
385

    
386
		if (isset($p1index) && $a_phase1[$p1index])
387
			$a_phase1[$p1index] = $ph1ent;
388
		else
389
			$a_phase1[] = $ph1ent;
390

    
391
		write_config();
392
		mark_subsystem_dirty('ipsec');
393

    
394
		header("Location: vpn_ipsec.php");
395
		exit;
396
	}
397
}
398

    
399
if ($pconfig['mobile'])
400
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
401
else
402
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
403
$shortcut_section = "ipsec";
404

    
405

    
406
include("head.inc");
407

    
408
?>
409

    
410
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
411
<?php include("fbegin.inc"); ?>
412
<script type="text/javascript">
413
//<![CDATA[
414

    
415
function myidsel_change() {
416
	index = document.iform.myid_type.selectedIndex;
417
	value = document.iform.myid_type.options[index].value;
418
	if (value == 'myaddress')
419
			document.getElementById('myid_data').style.visibility = 'hidden';
420
	else
421
			document.getElementById('myid_data').style.visibility = 'visible';
422
}
423

    
424
function iketype_change() {
425
	index = document.iform.iketype.selectedIndex;
426
	value = document.iform.iketype.options[index].value;
427
	if (value == 'ikev2')
428
			document.getElementById('negmode').style.display= 'none';
429
	else
430
			document.getElementById('negmode').style.display = '';
431
}
432

    
433
function peeridsel_change() {
434
	index = document.iform.peerid_type.selectedIndex;
435
	value = document.iform.peerid_type.options[index].value;
436
	if (value == 'peeraddress')
437
			document.getElementById('peerid_data').style.visibility = 'hidden';
438
	else
439
			document.getElementById('peerid_data').style.visibility = 'visible';
440
}
441

    
442
function methodsel_change() {
443
	index = document.iform.authentication_method.selectedIndex;
444
	value = document.iform.authentication_method.options[index].value;
445

    
446
	switch (value) {
447
	case 'eap-tls':
448
		document.getElementById('opt_psk').style.display = 'none';
449
		document.getElementById('opt_peerid').style.display = '';
450
		document.getElementById('opt_cert').style.display = '';
451
		document.getElementById('opt_ca').style.display = '';
452
		document.getElementById('opt_cert').disabled = false;
453
		document.getElementById('opt_ca').disabled = false;
454
		break;
455
	case 'hybrid_rsa_server':
456
		document.getElementById('opt_psk').style.display = 'none';
457
		document.getElementById('opt_peerid').style.display = '';
458
		document.getElementById('opt_cert').style.display = '';
459
		document.getElementById('opt_ca').style.display = '';
460
		document.getElementById('opt_cert').disabled = false;
461
		document.getElementById('opt_ca').disabled = false;
462
		break;
463
	case 'xauth_rsa_server':
464
	case 'rsasig':
465
		document.getElementById('opt_psk').style.display = 'none';
466
		document.getElementById('opt_peerid').style.display = '';
467
		document.getElementById('opt_cert').style.display = '';
468
		document.getElementById('opt_ca').style.display = '';
469
		document.getElementById('opt_cert').disabled = false;
470
		document.getElementById('opt_ca').disabled = false;
471
		break;
472
<?php if ($pconfig['mobile']) { ?>
473
	case 'pre_shared_key':
474
		document.getElementById('opt_psk').style.display = 'none';
475
		document.getElementById('opt_peerid').style.display = 'none';
476
		document.getElementById('opt_cert').style.display = 'none';
477
		document.getElementById('opt_ca').style.display = 'none';
478
		document.getElementById('opt_cert').disabled = true;
479
		document.getElementById('opt_ca').disabled = true;
480
		break;
481
<?php } ?>
482
	default: /* psk modes*/
483
		document.getElementById('opt_psk').style.display = '';
484
		document.getElementById('opt_peerid').style.display = '';
485
		document.getElementById('opt_cert').style.display = 'none';
486
		document.getElementById('opt_ca').style.display = 'none';
487
		document.getElementById('opt_cert').disabled = true;
488
		document.getElementById('opt_ca').disabled = true;
489
		break;
490
	}
491
}
492

    
493
/* PHP generated java script for variable length keys */
494
function ealgosel_change(bits) {
495
	switch (document.iform.ealgo.selectedIndex) {
496
<?php
497
$i = 0;
498
foreach ($p1_ealgos as $algo => $algodata) {
499
	if (is_array($algodata['keysel'])) {
500
		echo "		case {$i}:\n";
501
		echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
502
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
503
	//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
504

    
505
		$key_hi = $algodata['keysel']['hi'];
506
		$key_lo = $algodata['keysel']['lo'];
507
		$key_step = $algodata['keysel']['step'];
508

    
509
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
510
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
511
		echo "			break;\n";
512
	} else {
513
		echo "		case {$i}:\n";
514
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
515
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
516
		echo "			break;\n";
517
	}
518
	$i++;
519
}
520
?>
521
	}
522

    
523
	if( bits )
524
		document.iform.ealgo_keylen.value = bits;
525
}
526

    
527
function dpdchkbox_change() {
528
	if( document.iform.dpd_enable.checked )
529
		document.getElementById('opt_dpd').style.display = '';
530
	else
531
		document.getElementById('opt_dpd').style.display = 'none';
532

    
533
	if (!document.iform.dpd_delay.value)
534
		document.iform.dpd_delay.value = "10";
535

    
536
	if (!document.iform.dpd_maxfail.value)
537
		document.iform.dpd_maxfail.value = "5";
538
}
539

    
540
//]]>
541
</script>
542

    
543
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
544

    
545
<?php
546
	if ($input_errors)
547
		print_input_errors($input_errors);
548
?>
549

    
550
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="vpn ipsec phase-1">
551
	<tr class="tabnavtbl">
552
		<td id="tabnav">
553
			<?php
554
				$tab_array = array();
555
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
556
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
557
				$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
558
				$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
559
				display_top_tabs($tab_array);
560
			?>
561
		</td>
562
	</tr>
563
	<tr>
564
		<td id="mainarea">
565
			<div class="tabcont">
566
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
567
					<tr>
568
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
569
					</tr>
570
					<tr>
571
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
572
						<td width="78%" class="vtable">
573
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
574
							<strong><?=gettext("Disable this phase1 entry"); ?></strong><br />
575
							<span class="vexpl">
576
								<?=gettext("Set this option to disable this phase1 without " .
577
								"removing it from the list"); ?>.
578
							</span>
579
						</td>
580
					</tr>
581
					<tr>
582
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Key Exchange version"); ?></td>
583
						<td width="78%" class="vtable">
584
							<select name="iketype" class="formselect" onchange='iketype_change()'>
585
							<?php
586
								$keyexchange = array("ikev1" => "V1", "ikev2" => "V2", "auto" => "Auto");
587
								foreach ($keyexchange as $kidx => $name):
588
							?>
589
								<option value="<?=$kidx;?>" <?php if ($kidx == $pconfig['iketype']) echo "selected=\"selected\""; ?>>
590
									<?=htmlspecialchars($name);?>
591
								</option>
592
							<?php endforeach; ?>
593
							</select> <br /> <span class="vexpl"><?=gettext("Select the Internet Key Exchange protocol version to be used, IKEv1 or IKEv2"); ?>.</span>
594
						</td>
595
					</tr>
596
					<tr>
597
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Internet Protocol"); ?></td>
598
						<td width="78%" class="vtable">
599
							<select name="protocol" class="formselect">
600
							<?php
601
								$protocols = array("inet" => "IPv4", "inet6" => "IPv6");
602
								foreach ($protocols as $protocol => $name):
603
							?>
604
								<option value="<?=$protocol;?>" <?php if ($protocol == $pconfig['protocol']) echo "selected=\"selected\""; ?>>
605
									<?=htmlspecialchars($name);?>
606
								</option>
607
							<?php endforeach; ?>
608
							</select> <br /> <span class="vexpl"><?=gettext("Select the Internet Protocol family from this dropdown"); ?>.</span>
609
						</td>
610
					</tr>
611
					<tr>
612
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
613
						<td width="78%" class="vtable">
614
							<select name="interface" class="formselect">
615
							<?php
616
								$interfaces = get_configured_interface_with_descr();
617

    
618
								$carplist = get_configured_carp_interface_list();
619
								foreach ($carplist as $cif => $carpip)
620
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
621

    
622
								$aliaslist = get_configured_ip_aliases_list();
623
								foreach ($aliaslist as $aliasip => $aliasif)
624
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
625

    
626
								$grouplist = return_gateway_groups_array();
627
								foreach ($grouplist as $name => $group) {
628
									if($group[0]['vip'] <> "")
629
										$vipif = $group[0]['vip'];
630
									else
631
										$vipif = $group[0]['int'];
632
									$interfaces[$name] = "GW Group {$name}";
633
								}
634

    
635

    
636
								foreach ($interfaces as $iface => $ifacename):
637
							?>
638
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
639
									<?=htmlspecialchars($ifacename);?>
640
								</option>
641
							<?php endforeach; ?>
642
							</select>
643
							<br />
644
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
645
						</td>
646
					</tr>
647

    
648
					<?php if (!$pconfig['mobile']): ?>
649

    
650
					<tr>
651
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
652
						<td width="78%" class="vtable">
653
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>" />
654
							<br />
655
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
656
						</td>
657
					</tr>
658

    
659
					<?php endif; ?>
660

    
661
					<tr>
662
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
663
						<td width="78%" class="vtable">
664
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
665
							<br />
666
							<span class="vexpl">
667
								<?=gettext("You may enter a description here " .
668
								"for your reference (not parsed)"); ?>.
669
							</span>
670
						</td>
671
					</tr>
672
					<tr>
673
						<td colspan="2" class="list" height="12"></td>
674
					</tr>
675
					<tr>
676
						<td colspan="2" valign="top" class="listtopic">
677
							<?=gettext("Phase 1 proposal (Authentication)"); ?>
678
						</td>
679
					</tr>
680
					<tr>
681
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication method"); ?></td>
682
						<td width="78%" class="vtable">
683
							<select name="authentication_method" class="formselect" onchange="methodsel_change()">
684
							<?php
685
								foreach ($p1_authentication_methods as $method_type => $method_params):
686
									if (!$pconfig['mobile'] && $method_params['mobile'])
687
										continue;
688
							?>
689
								<option value="<?=$method_type;?>" <?php if ($method_type == $pconfig['authentication_method']) echo "selected=\"selected\""; ?>>
690
									<?=htmlspecialchars($method_params['name']);?>
691
								</option>
692
							<?php endforeach; ?>
693
							</select>
694
							<br />
695
							<span class="vexpl">
696
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
697
							</span>
698
						</td>
699
					</tr>
700
					<tr id='negmode' >
701
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Negotiation mode"); ?></td>
702
						<td width="78%" class="vtable">
703
							<select name="mode" class="formselect">
704
							<?php
705
								$modes = array("main" => "Main", "aggressive" => "Aggressive");
706
								foreach ($modes as $mode => $mdescr):
707
							?>
708
								<option value="<?=$mode;?>" <?php if ($mode == $pconfig['mode']) echo "selected=\"selected\""; ?>>
709
									<?=htmlspecialchars($mdescr);?>
710
								</option>
711
							<?php endforeach; ?>
712
							</select> <br /> <span class="vexpl"><?=gettext("Aggressive is more flexible, but less secure"); ?>.</span>
713
						</td>
714
					</tr>
715
					<tr>
716
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My identifier"); ?></td>
717
						<td width="78%" class="vtable">
718
							<select name="myid_type" class="formselect" onchange="myidsel_change()">
719
							<?php foreach ($my_identifier_list as $id_type => $id_params): ?>
720
								<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['myid_type']) echo "selected=\"selected\""; ?>>
721
									<?=htmlspecialchars($id_params['desc']);?>
722
								</option>
723
							<?php endforeach; ?>
724
							</select>
725
							<input name="myid_data" type="text" class="formfld unknown" id="myid_data" size="30" value="<?=htmlspecialchars($pconfig['myid_data']);?>" />
726
						</td>
727
					</tr>
728
					<tr id="opt_peerid">
729
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer identifier"); ?></td>
730
						<td width="78%" class="vtable">
731
							<select name="peerid_type" class="formselect" onchange="peeridsel_change()">
732
							<?php
733
								foreach ($peer_identifier_list as $id_type => $id_params):
734
									if ($pconfig['mobile'] && !$id_params['mobile'])
735
										continue;
736
							?>
737
							<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['peerid_type']) echo "selected=\"selected\""; ?>>
738
								<?=htmlspecialchars($id_params['desc']);?>
739
							</option>
740
							<?php endforeach; ?>
741
							</select>
742
							<input name="peerid_data" type="text" class="formfld unknown" id="peerid_data" size="30" value="<?=htmlspecialchars($pconfig['peerid_data']);?>" />
743
						<?php if ($pconfig['mobile']) { ?>
744
							<br /><br /><?=gettext("NOTE: This is known as the \"group\" setting on some VPN client implementations"); ?>.
745
						<?php } ?>
746
						</td>
747
					</tr>
748
					<tr id="opt_psk">
749
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Pre-Shared Key"); ?></td>
750
						<td width="78%" class="vtable">
751
							<?=$mandfldhtml;?>
752
							<input name="pskey" type="text" class="formfld unknown" id="pskey" size="40" value="<?=htmlspecialchars($pconfig['pskey']);?>" />
753
							<span class="vexpl">
754
							<br />
755
								<?=gettext("Input your Pre-Shared Key string"); ?>.
756
							</span>
757
						</td>
758
					</tr>
759
					<tr id="opt_cert">
760
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My Certificate"); ?></td>
761
						<td width="78%" class="vtable">
762
							<select name="certref" class="formselect">
763
							<?php
764
								foreach ($config['cert'] as $cert):
765
									$selected = "";
766
									if ($pconfig['certref'] == $cert['refid'])
767
										$selected = "selected=\"selected\"";
768
							?>
769
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'];?></option>
770
							<?php endforeach; ?>
771
							</select>
772
							<br />
773
							<span class="vexpl">
774
								<?=gettext("Select a certificate previously configured in the Certificate Manager"); ?>.
775
							</span>
776
						</td>
777
					</tr>
778
					<tr id="opt_ca">
779
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My Certificate Authority"); ?></td>
780
						<td width="78%" class="vtable">
781
							<select name="caref" class="formselect">
782
							<?php
783
								foreach ($config['ca'] as $ca):
784
									$selected = "";
785
									if ($pconfig['caref'] == $ca['refid'])
786
										$selected = "selected=\"selected\"";
787
							?>
788
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
789
							<?php endforeach; ?>
790
							</select>
791
							<br />
792
							<span class="vexpl">
793
								<?=gettext("Select a certificate authority previously configured in the Certificate Manager"); ?>.
794
							</span>
795
						</td>
796
					</tr>
797
					<tr>
798
						<td colspan="2" valign="top" class="listtopic">
799
							<?=gettext("Phase 1 proposal (Algorithms)"); ?>
800
						</td>
801
					</tr>
802
					<tr>
803
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithm"); ?></td>
804
						<td width="78%" class="vtable">
805
							<select name="ealgo" class="formselect" onchange="ealgosel_change()">
806
							<?php
807
								foreach ($p1_ealgos as $algo => $algodata):
808
									$selected = "";
809
									if ($algo == $pconfig['ealgo']['name'])
810
										$selected = " selected=\"selected\"";
811
							?>
812
								<option value="<?=$algo;?>"<?=$selected?>>
813
									<?=htmlspecialchars($algodata['name']);?>
814
								</option>
815
							<?php endforeach; ?>
816
							</select>
817
							<select name="ealgo_keylen" width="30" class="formselect">
818
							</select>
819
						</td>
820
					</tr>
821
					<tr>
822
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithm"); ?></td>
823
						<td width="78%" class="vtable">
824
							<select name="halgo" class="formselect">
825
							<?php foreach ($p1_halgos as $algo => $algoname): ?>
826
								<option value="<?=$algo;?>" <?php if ($algo == $pconfig['halgo']) echo "selected=\"selected\""; ?>>
827
									<?=htmlspecialchars($algoname);?>
828
								</option>
829
							<?php endforeach; ?>
830
							</select>
831
							<br />
832
							<span class="vexpl">
833
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
834
							</span>
835
						</td>
836
					</tr>
837
					<tr>
838
						<td width="22%" valign="top" class="vncellreq"><?=gettext("DH key group"); ?></td>
839
						<td width="78%" class="vtable">
840
							<select name="dhgroup" class="formselect">
841
							<?php foreach ($p1_dhgroups as $keygroup => $keygroupname): ?>
842
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['dhgroup']) echo "selected=\"selected\""; ?>>
843
									<?=htmlspecialchars($keygroupname);?>
844
								</option>
845
							<?php endforeach; ?>
846
							</select>
847
							<br />
848
							<span class="vexpl">
849
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
850
							</span>
851
						</td>
852
					</tr>
853
					<tr>
854
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
855
						<td width="78%" class="vtable">
856
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />
857
							<?=gettext("seconds"); ?>
858
						</td>
859
					</tr>
860
					<tr>
861
						<td colspan="2" class="list" height="12"></td>
862
					</tr>
863
					<tr>
864
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
865
					</tr>
866
					<tr>
867
						<td width="22%" valign="top" class="vncell"><?=gettext("Disable Rekey");?></td>
868
						<td width="78%" class="vtable">
869
							<input name="rekey_enable" type="checkbox" id="rekey_enable" value="yes" <?php if (isset($pconfig['rekey_enable'])) echo "checked=\"checked\""; ?> />
870
							<?=gettext("Whether a connection should be renegotiated when it is about to expire."); ?><br />
871
						</td>
872
					</tr>
873
					<tr>
874
						<td width="22%" valign="top" class="vncell"><?=gettext("Disable Reauth");?></td>
875
						<td width="78%" class="vtable">
876
							<input name="reauth_enable" type="checkbox" id="reauth_enable" value="yes" <?php if (isset($pconfig['reauth_enable'])) echo "checked=\"checked\""; ?> />
877
							<?=gettext("Whether rekeying of an IKE_SA should also reauthenticate the peer. In IKEv1, reauthentication is always done."); ?><br />
878
						</td>
879
					</tr>
880
					<tr>
881
						<td width="22%" valign="top" class="vncell"><?=gettext("NAT Traversal"); ?></td>
882
						<td width="78%" class="vtable">
883
							<select name="nat_traversal" class="formselect">
884
								<option value="on" <?php if ($pconfig['nat_traversal'] != 'on') echo "selected=\"selected\""; ?>><?=gettext("Auto"); ?></option>
885
								<option value="force" <?php if ($pconfig['nat_traversal'] == 'force') echo "selected=\"selected\""; ?>><?=gettext("Force"); ?></option>
886
							</select>
887
							<br />
888
							<span class="vexpl">
889
								<?=gettext("Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed, " .
890
								"which can help with clients that are behind restrictive firewalls"); ?>.
891
							</span>
892
						</td>
893
					</tr>
894
					<tr>
895
						<td width="22%" valign="top" class="vncell"><?=gettext("Dead Peer Detection"); ?></td>
896
						<td width="78%" class="vtable">
897
							<input name="dpd_enable" type="checkbox" id="dpd_enable" value="yes" <?php if (isset($pconfig['dpd_enable'])) echo "checked=\"checked\""; ?> onclick="dpdchkbox_change()" />
898
							<?=gettext("Enable DPD"); ?><br />
899
							<div id="opt_dpd">
900
								<br />
901
								<input name="dpd_delay" type="text" class="formfld unknown" id="dpd_delay" size="5" value="<?=htmlspecialchars($pconfig['dpd_delay']);?>" />
902
								<?=gettext("seconds"); ?><br />
903
								<span class="vexpl">
904
									<?=gettext("Delay between requesting peer acknowledgement"); ?>.
905
								</span><br />
906
								<br />
907
								<input name="dpd_maxfail" type="text" class="formfld unknown" id="dpd_maxfail" size="5" value="<?=htmlspecialchars($pconfig['dpd_maxfail']);?>" />
908
								<?=gettext("retries"); ?><br />
909
								<span class="vexpl">
910
									<?=gettext("Number of consecutive failures allowed before disconnect"); ?>.
911
								</span>
912
								<br />
913
							</div>
914
						</td>
915
					</tr>
916
					<tr>
917
						<td width="22%" valign="top">&nbsp;</td>
918
						<td width="78%">
919
							<?php if (isset($p1index) && $a_phase1[$p1index]): ?>
920
							<input name="p1index" type="hidden" value="<?=htmlspecialchars($p1index);?>" />
921
							<?php endif; ?>
922
							<?php if ($pconfig['mobile']): ?>
923
							<input name="mobile" type="hidden" value="true" />
924
							<?php endif; ?>
925
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>" />
926
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
927
						</td>
928
					</tr>
929
				</table>
930
			</div>
931
		</td>
932
	</tr>
933
</table>
934
</form>
935

    
936
<script type="text/javascript">
937
//<![CDATA[
938
<?php
939
	/* determine if we should init the key length */
940
	$keyset = '';
941
	if (isset($pconfig['ealgo']['keylen']))
942
		if (is_numeric($pconfig['ealgo']['keylen']))
943
			$keyset = $pconfig['ealgo']['keylen'];
944
?>
945
myidsel_change();
946
peeridsel_change();
947
iketype_change();
948
methodsel_change();
949
ealgosel_change(<?=$keyset;?>);
950
dpdchkbox_change();
951
//]]>
952
</script>
953
<?php include("fend.inc"); ?>
954
</body>
955
</html>
(241-241/256)