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

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

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

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

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

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

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

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

    
242
	/* My identity */
243

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

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

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

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

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

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

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

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

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

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

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

    
282
	/* Peer identity */
283

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
413

    
414
include("head.inc");
415

    
416
?>
417

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

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

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

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

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

    
454
	switch (value) {
455
	case 'eap-mschapv2':
456
	case 'eap-tls':
457
		document.getElementById('opt_psk').style.display = 'none';
458
		document.getElementById('opt_peerid').style.display = '';
459
		document.getElementById('opt_cert').style.display = '';
460
		document.getElementById('opt_ca').style.display = '';
461
		document.getElementById('opt_cert').disabled = false;
462
		document.getElementById('opt_ca').disabled = false;
463
		break;
464
	case 'hybrid_rsa_server':
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 'xauth_rsa_server':
473
	case 'rsasig':
474
		document.getElementById('opt_psk').style.display = 'none';
475
		document.getElementById('opt_peerid').style.display = '';
476
		document.getElementById('opt_cert').style.display = '';
477
		document.getElementById('opt_ca').style.display = '';
478
		document.getElementById('opt_cert').disabled = false;
479
		document.getElementById('opt_ca').disabled = false;
480
		break;
481
<?php if ($pconfig['mobile']) { ?>
482
	case 'pre_shared_key':
483
		document.getElementById('opt_psk').style.display = 'none';
484
		document.getElementById('opt_peerid').style.display = 'none';
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
<?php } ?>
491
	default: /* psk modes*/
492
		document.getElementById('opt_psk').style.display = '';
493
		document.getElementById('opt_peerid').style.display = '';
494
		document.getElementById('opt_cert').style.display = 'none';
495
		document.getElementById('opt_ca').style.display = 'none';
496
		document.getElementById('opt_cert').disabled = true;
497
		document.getElementById('opt_ca').disabled = true;
498
		break;
499
	}
500
}
501

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

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

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

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

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

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

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

    
549
//]]>
550
</script>
551

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

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

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

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

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

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

    
644

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

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

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

    
668
					<?php endif; ?>
669

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

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