Project

General

Profile

Download (37.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
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
	if (isset($a_phase1[$p1index]['responderonly']))
117
		$pconfig['responderonly'] = true;
118

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

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

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

    
152
if ($_POST) {
153
	unset($input_errors);
154
	$pconfig = $_POST;
155

    
156
	/* input validation */
157

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

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

    
198
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
199

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

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

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

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

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

    
245
	/* My identity */
246

    
247
	if ($pconfig['myid_type'] == "myaddress")
248
		$pconfig['myid_data'] = "";
249

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

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

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

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

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

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

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

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

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

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

    
285
	/* Peer identity */
286

    
287
	if ($pconfig['myid_type'] == "peeraddress")
288
		$pconfig['peerid_data'] = "";
289

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
360
		$ph1ent['protocol'] = $pconfig['protocol'];
361

    
362
		$ph1ent['myid_type'] = $pconfig['myid_type'];
363
		$ph1ent['myid_data'] = $pconfig['myid_data'];
364
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
365
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
366

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

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

    
388
		if (isset($pconfig['responderonly']))
389
			$ph1ent['responderonly'] = true;
390
		else
391
			unset($ph1ent['responderonly']);
392

    
393
		if (isset($pconfig['dpd_enable'])) {
394
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
395
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
396
		}
397

    
398
		/* generate unique phase1 ikeid */
399
		if ($ph1ent['ikeid'] == 0)
400
			$ph1ent['ikeid'] = ipsec_ikeid_next();
401

    
402
		if (isset($p1index) && $a_phase1[$p1index])
403
			$a_phase1[$p1index] = $ph1ent;
404
		else
405
			$a_phase1[] = $ph1ent;
406

    
407
		write_config();
408
		mark_subsystem_dirty('ipsec');
409

    
410
		header("Location: vpn_ipsec.php");
411
		exit;
412
	}
413
}
414

    
415
if ($pconfig['mobile'])
416
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
417
else
418
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
419
$shortcut_section = "ipsec";
420

    
421

    
422
include("head.inc");
423

    
424
?>
425

    
426
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
427
<?php include("fbegin.inc"); ?>
428
<script type="text/javascript">
429
//<![CDATA[
430

    
431
function myidsel_change() {
432
	index = document.iform.myid_type.selectedIndex;
433
	value = document.iform.myid_type.options[index].value;
434
	if (value == 'myaddress')
435
			document.getElementById('myid_data').style.visibility = 'hidden';
436
	else
437
			document.getElementById('myid_data').style.visibility = 'visible';
438
}
439

    
440
function iketype_change() {
441
	index = document.iform.iketype.selectedIndex;
442
	value = document.iform.iketype.options[index].value;
443
	if (value == 'ikev2')
444
			document.getElementById('negmode').style.display= 'none';
445
	else
446
			document.getElementById('negmode').style.display = '';
447
}
448

    
449
function peeridsel_change() {
450
	index = document.iform.peerid_type.selectedIndex;
451
	value = document.iform.peerid_type.options[index].value;
452
	if (value == 'peeraddress')
453
			document.getElementById('peerid_data').style.visibility = 'hidden';
454
	else
455
			document.getElementById('peerid_data').style.visibility = 'visible';
456
}
457

    
458
function methodsel_change() {
459
	index = document.iform.authentication_method.selectedIndex;
460
	value = document.iform.authentication_method.options[index].value;
461

    
462
	switch (value) {
463
	case 'eap-mschapv2':
464
	case 'eap-tls':
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
	case 'hybrid_rsa_server':
473
		document.getElementById('opt_psk').style.display = 'none';
474
		document.getElementById('opt_peerid').style.display = '';
475
		document.getElementById('opt_cert').style.display = '';
476
		document.getElementById('opt_ca').style.display = '';
477
		document.getElementById('opt_cert').disabled = false;
478
		document.getElementById('opt_ca').disabled = false;
479
		break;
480
	case 'xauth_rsa_server':
481
	case 'rsasig':
482
		document.getElementById('opt_psk').style.display = 'none';
483
		document.getElementById('opt_peerid').style.display = '';
484
		document.getElementById('opt_cert').style.display = '';
485
		document.getElementById('opt_ca').style.display = '';
486
		document.getElementById('opt_cert').disabled = false;
487
		document.getElementById('opt_ca').disabled = false;
488
		break;
489
<?php if ($pconfig['mobile']) { ?>
490
	case 'pre_shared_key':
491
		document.getElementById('opt_psk').style.display = 'none';
492
		document.getElementById('opt_peerid').style.display = 'none';
493
		document.getElementById('opt_cert').style.display = 'none';
494
		document.getElementById('opt_ca').style.display = 'none';
495
		document.getElementById('opt_cert').disabled = true;
496
		document.getElementById('opt_ca').disabled = true;
497
		break;
498
<?php } ?>
499
	default: /* psk modes*/
500
		document.getElementById('opt_psk').style.display = '';
501
		document.getElementById('opt_peerid').style.display = '';
502
		document.getElementById('opt_cert').style.display = 'none';
503
		document.getElementById('opt_ca').style.display = 'none';
504
		document.getElementById('opt_cert').disabled = true;
505
		document.getElementById('opt_ca').disabled = true;
506
		break;
507
	}
508
}
509

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

    
522
		$key_hi = $algodata['keysel']['hi'];
523
		$key_lo = $algodata['keysel']['lo'];
524
		$key_step = $algodata['keysel']['step'];
525

    
526
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
527
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
528
		echo "			break;\n";
529
	} else {
530
		echo "		case {$i}:\n";
531
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
532
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
533
		echo "			break;\n";
534
	}
535
	$i++;
536
}
537
?>
538
	}
539

    
540
	if( bits )
541
		document.iform.ealgo_keylen.value = bits;
542
}
543

    
544
function dpdchkbox_change() {
545
	if( document.iform.dpd_enable.checked )
546
		document.getElementById('opt_dpd').style.display = '';
547
	else
548
		document.getElementById('opt_dpd').style.display = 'none';
549

    
550
	if (!document.iform.dpd_delay.value)
551
		document.iform.dpd_delay.value = "10";
552

    
553
	if (!document.iform.dpd_maxfail.value)
554
		document.iform.dpd_maxfail.value = "5";
555
}
556

    
557
//]]>
558
</script>
559

    
560
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
561

    
562
<?php
563
	if ($input_errors)
564
		print_input_errors($input_errors);
565
?>
566

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

    
635
								$carplist = get_configured_carp_interface_list();
636
								foreach ($carplist as $cif => $carpip)
637
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
638

    
639
								$aliaslist = get_configured_ip_aliases_list();
640
								foreach ($aliaslist as $aliasip => $aliasif)
641
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
642

    
643
								$grouplist = return_gateway_groups_array();
644
								foreach ($grouplist as $name => $group) {
645
									if($group[0]['vip'] <> "")
646
										$vipif = $group[0]['vip'];
647
									else
648
										$vipif = $group[0]['int'];
649
									$interfaces[$name] = "GW Group {$name}";
650
								}
651

    
652

    
653
								foreach ($interfaces as $iface => $ifacename):
654
							?>
655
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
656
									<?=htmlspecialchars($ifacename);?>
657
								</option>
658
							<?php endforeach; ?>
659
							</select>
660
							<br />
661
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
662
						</td>
663
					</tr>
664

    
665
					<?php if (!$pconfig['mobile']): ?>
666

    
667
					<tr>
668
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
669
						<td width="78%" class="vtable">
670
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>" />
671
							<br />
672
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
673
						</td>
674
					</tr>
675

    
676
					<?php endif; ?>
677

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

    
960
<script type="text/javascript">
961
//<![CDATA[
962
<?php
963
	/* determine if we should init the key length */
964
	$keyset = '';
965
	if (isset($pconfig['ealgo']['keylen']))
966
		if (is_numeric($pconfig['ealgo']['keylen']))
967
			$keyset = $pconfig['ealgo']['keylen'];
968
?>
969
myidsel_change();
970
peeridsel_change();
971
iketype_change();
972
methodsel_change();
973
ealgosel_change(<?=$keyset;?>);
974
dpdchkbox_change();
975
//]]>
976
</script>
977
<?php include("fend.inc"); ?>
978
</body>
979
</html>
(241-241/256)