Project

General

Profile

Download (36.5 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
require_once("filter.inc");
46

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
154
	/* input validation */
155

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

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

    
196
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
197

    
198
	if (isset($validate_pskey) && isset($pconfig['pskey']) && !preg_match('/^[[:ascii:]]*$/', $pconfig['pskey'])) {
199
		unset($validate_pskey);
200
		$input_errors[] = gettext("Pre-Shared Key contains invalid characters.");
201
	}
202

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

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

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

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

    
243
	/* My identity */
244

    
245
	if ($pconfig['myid_type'] == "myaddress")
246
		$pconfig['myid_data'] = "";
247

    
248
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
249
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
250

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

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

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

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

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

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

    
269
	if ($pconfig['myid_type'] == "fqdn")
270
		if (is_domain($pconfig['myid_data']) == false)
271
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
272

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

    
279
	if ($pconfig['myid_type'] == "dyn_dns")
280
		if (is_domain($pconfig['myid_data']) == false)
281
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
282

    
283
	/* Peer identity */
284

    
285
	if ($pconfig['myid_type'] == "peeraddress")
286
		$pconfig['peerid_data'] = "";
287

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

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

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

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

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

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

    
308
		if ($pconfig['peerid_type'] == "fqdn")
309
			if (is_domain($pconfig['peerid_data']) == false)
310
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
311

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

    
319
	if ($pconfig['dpd_enable']) {
320
		if (!is_numeric($pconfig['dpd_delay']))
321
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
322

    
323
		if (!is_numeric($pconfig['dpd_maxfail']))
324
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
325
	}
326

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

    
330
	/* build our encryption algorithms array */
331
	$pconfig['ealgo'] = array();
332
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
333
	if($pconfig['ealgo_keylen'])
334
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
335

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

    
353
		if ($pconfig['mobile'])
354
			$ph1ent['mobile'] = true;
355
		else
356
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
357

    
358
		$ph1ent['protocol'] = $pconfig['protocol'];
359

    
360
		$ph1ent['myid_type'] = $pconfig['myid_type'];
361
		$ph1ent['myid_data'] = $pconfig['myid_data'];
362
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
363
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
364

    
365
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
366
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
367
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
368
		$ph1ent['lifetime'] = $pconfig['lifetime'];
369
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
370
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
371
		$ph1ent['certref'] = $pconfig['certref'];
372
		$ph1ent['caref'] = $pconfig['caref'];
373
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
374
		$ph1ent['descr'] = $pconfig['descr'];
375
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
376

    
377
		if (isset($pconfig['reauth_enable']))
378
			$ph1ent['reauth_enable'] = true;
379
		else
380
			unset($ph1ent['reauth_enable']);
381
		if (isset($pconfig['rekey_enable']))
382
			$ph1ent['rekey_enable'] = true;
383
		else
384
			unset($ph1ent['rekey_enable']);
385

    
386
		if (isset($pconfig['dpd_enable'])) {
387
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
388
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
389
		}
390

    
391
		/* generate unique phase1 ikeid */
392
		if ($ph1ent['ikeid'] == 0)
393
			$ph1ent['ikeid'] = ipsec_ikeid_next();
394

    
395
		if (isset($p1index) && $a_phase1[$p1index])
396
			$a_phase1[$p1index] = $ph1ent;
397
		else
398
			$a_phase1[] = $ph1ent;
399

    
400
		write_config();
401
		mark_subsystem_dirty('ipsec');
402

    
403
		header("Location: vpn_ipsec.php");
404
		exit;
405
	}
406
}
407

    
408
if ($pconfig['mobile'])
409
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
410
else
411
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
412
$shortcut_section = "ipsec";
413

    
414

    
415
include("head.inc");
416

    
417
?>
418

    
419
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
420
<?php include("fbegin.inc"); ?>
421
<script type="text/javascript">
422
//<![CDATA[
423

    
424
function myidsel_change() {
425
	index = document.iform.myid_type.selectedIndex;
426
	value = document.iform.myid_type.options[index].value;
427
	if (value == 'myaddress')
428
			document.getElementById('myid_data').style.visibility = 'hidden';
429
	else
430
			document.getElementById('myid_data').style.visibility = 'visible';
431
}
432

    
433
function iketype_change() {
434
	index = document.iform.iketype.selectedIndex;
435
	value = document.iform.iketype.options[index].value;
436
	if (value == 'ikev2')
437
			document.getElementById('negmode').style.display= 'none';
438
	else
439
			document.getElementById('negmode').style.display = '';
440
}
441

    
442
function peeridsel_change() {
443
	index = document.iform.peerid_type.selectedIndex;
444
	value = document.iform.peerid_type.options[index].value;
445
	if (value == 'peeraddress')
446
			document.getElementById('peerid_data').style.visibility = 'hidden';
447
	else
448
			document.getElementById('peerid_data').style.visibility = 'visible';
449
}
450

    
451
function methodsel_change() {
452
	index = document.iform.authentication_method.selectedIndex;
453
	value = document.iform.authentication_method.options[index].value;
454

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

    
503
/* PHP generated java script for variable length keys */
504
function ealgosel_change(bits) {
505
	switch (document.iform.ealgo.selectedIndex) {
506
<?php
507
$i = 0;
508
foreach ($p1_ealgos as $algo => $algodata) {
509
	if (is_array($algodata['keysel'])) {
510
		echo "		case {$i}:\n";
511
		echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
512
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
513
	//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
514

    
515
		$key_hi = $algodata['keysel']['hi'];
516
		$key_lo = $algodata['keysel']['lo'];
517
		$key_step = $algodata['keysel']['step'];
518

    
519
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
520
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
521
		echo "			break;\n";
522
	} else {
523
		echo "		case {$i}:\n";
524
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
525
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
526
		echo "			break;\n";
527
	}
528
	$i++;
529
}
530
?>
531
	}
532

    
533
	if( bits )
534
		document.iform.ealgo_keylen.value = bits;
535
}
536

    
537
function dpdchkbox_change() {
538
	if( document.iform.dpd_enable.checked )
539
		document.getElementById('opt_dpd').style.display = '';
540
	else
541
		document.getElementById('opt_dpd').style.display = 'none';
542

    
543
	if (!document.iform.dpd_delay.value)
544
		document.iform.dpd_delay.value = "10";
545

    
546
	if (!document.iform.dpd_maxfail.value)
547
		document.iform.dpd_maxfail.value = "5";
548
}
549

    
550
//]]>
551
</script>
552

    
553
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
554

    
555
<?php
556
	if ($input_errors)
557
		print_input_errors($input_errors);
558
?>
559

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

    
628
								$carplist = get_configured_carp_interface_list();
629
								foreach ($carplist as $cif => $carpip)
630
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
631

    
632
								$aliaslist = get_configured_ip_aliases_list();
633
								foreach ($aliaslist as $aliasip => $aliasif)
634
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
635

    
636
								$grouplist = return_gateway_groups_array();
637
								foreach ($grouplist as $name => $group) {
638
									if($group[0]['vip'] <> "")
639
										$vipif = $group[0]['vip'];
640
									else
641
										$vipif = $group[0]['int'];
642
									$interfaces[$name] = "GW Group {$name}";
643
								}
644

    
645

    
646
								foreach ($interfaces as $iface => $ifacename):
647
							?>
648
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
649
									<?=htmlspecialchars($ifacename);?>
650
								</option>
651
							<?php endforeach; ?>
652
							</select>
653
							<br />
654
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
655
						</td>
656
					</tr>
657

    
658
					<?php if (!$pconfig['mobile']): ?>
659

    
660
					<tr>
661
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
662
						<td width="78%" class="vtable">
663
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>" />
664
							<br />
665
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
666
						</td>
667
					</tr>
668

    
669
					<?php endif; ?>
670

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

    
946
<script type="text/javascript">
947
//<![CDATA[
948
<?php
949
	/* determine if we should init the key length */
950
	$keyset = '';
951
	if (isset($pconfig['ealgo']['keylen']))
952
		if (is_numeric($pconfig['ealgo']['keylen']))
953
			$keyset = $pconfig['ealgo']['keylen'];
954
?>
955
myidsel_change();
956
peeridsel_change();
957
iketype_change();
958
methodsel_change();
959
ealgosel_change(<?=$keyset;?>);
960
dpdchkbox_change();
961
//]]>
962
</script>
963
<?php include("fend.inc"); ?>
964
</body>
965
</html>
(241-241/256)