Project

General

Profile

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

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

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

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

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

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

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

    
238
	/* My identity */
239

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

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

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

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

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

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

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

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

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

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

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

    
278
	/* Peer identity */
279

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
372
		if (isset($pconfig['reauth_enable']))
373
			$ph1ent['reauth_enable'] = true;
374
		else
375
			unset($ph1ent['reauth_enable']);
376
		if (isset($pconfig['rekey_enable']))
377
			$ph1ent['rekey_enable'] = true;
378
		else
379
			unset($ph1ent['rekey_enable']);
380

    
381
		if (isset($pconfig['dpd_enable'])) {
382
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
383
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
384
		}
385

    
386
		/* generate unique phase1 ikeid */
387
		if ($ph1ent['ikeid'] == 0)
388
			$ph1ent['ikeid'] = ipsec_ikeid_next();
389

    
390
		if (isset($p1index) && $a_phase1[$p1index])
391
			$a_phase1[$p1index] = $ph1ent;
392
		else
393
			$a_phase1[] = $ph1ent;
394

    
395
		write_config();
396
		mark_subsystem_dirty('ipsec');
397

    
398
		header("Location: vpn_ipsec.php");
399
		exit;
400
	}
401
}
402

    
403
if ($pconfig['mobile'])
404
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
405
else
406
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
407
$shortcut_section = "ipsec";
408

    
409

    
410
include("head.inc");
411

    
412
?>
413

    
414
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
415
<?php include("fbegin.inc"); ?>
416
<script type="text/javascript">
417
//<![CDATA[
418

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

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

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

    
446
function methodsel_change() {
447
	index = document.iform.authentication_method.selectedIndex;
448
	value = document.iform.authentication_method.options[index].value;
449

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

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

    
509
		$key_hi = $algodata['keysel']['hi'];
510
		$key_lo = $algodata['keysel']['lo'];
511
		$key_step = $algodata['keysel']['step'];
512

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

    
527
	if( bits )
528
		document.iform.ealgo_keylen.value = bits;
529
}
530

    
531
function dpdchkbox_change() {
532
	if( document.iform.dpd_enable.checked )
533
		document.getElementById('opt_dpd').style.display = '';
534
	else
535
		document.getElementById('opt_dpd').style.display = 'none';
536

    
537
	if (!document.iform.dpd_delay.value)
538
		document.iform.dpd_delay.value = "10";
539

    
540
	if (!document.iform.dpd_maxfail.value)
541
		document.iform.dpd_maxfail.value = "5";
542
}
543

    
544
//]]>
545
</script>
546

    
547
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
548

    
549
<?php
550
	if ($input_errors)
551
		print_input_errors($input_errors);
552
?>
553

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

    
622
								$carplist = get_configured_carp_interface_list();
623
								foreach ($carplist as $cif => $carpip)
624
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
625

    
626
								$aliaslist = get_configured_ip_aliases_list();
627
								foreach ($aliaslist as $aliasip => $aliasif)
628
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
629

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

    
639

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

    
652
					<?php if (!$pconfig['mobile']): ?>
653

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

    
663
					<?php endif; ?>
664

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

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