Project

General

Profile

Download (36.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_phase1.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2008 Shrew Soft Inc
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2014 Ermal LUÇI
9
        Copyright (C) 2013-2014 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'] = "aggressive";
127
	$pconfig['protocol'] = "inet";
128
	$pconfig['myid_type'] = "myaddress";
129
	$pconfig['peerid_type'] = "peeraddress";
130
	$pconfig['authentication_method'] = "pre_shared_key";
131
	$pconfig['ealgo'] = array( name => "3des" );
132
	$pconfig['halgo'] = "sha1";
133
	$pconfig['dhgroup'] = "2";
134
	$pconfig['lifetime'] = "28800";
135
	$pconfig['nat_traversal'] = 'on';
136
	$pconfig['dpd_enable'] = true;
137
	$pconfig['iketype'] = "ikev1";
138

    
139
	/* mobile client */
140
	if($_GET['mobile'])
141
		$pconfig['mobile']=true;
142
}
143

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

    
147
if ($_POST) {
148
	unset($input_errors);
149
	$pconfig = $_POST;
150

    
151
	/* input validation */
152

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

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

    
189
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
190

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

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

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

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

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

    
236
	/* My identity */
237

    
238
	if ($pconfig['myid_type'] == "myaddress")
239
		$pconfig['myid_data'] = "";
240

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

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

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

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

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

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

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

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

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

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

    
276
	/* Peer identity */
277

    
278
	if ($pconfig['myid_type'] == "peeraddress")
279
		$pconfig['peerid_data'] = "";
280

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
351
		$ph1ent['protocol'] = $pconfig['protocol'];
352

    
353
		$ph1ent['myid_type'] = $pconfig['myid_type'];
354
		$ph1ent['myid_data'] = $pconfig['myid_data'];
355
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
356
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
357

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

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

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

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

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

    
389
		write_config();
390
		mark_subsystem_dirty('ipsec');
391

    
392
		header("Location: vpn_ipsec.php");
393
		exit;
394
	}
395
}
396

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

    
403

    
404
include("head.inc");
405

    
406
?>
407

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

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

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

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

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

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

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

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

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

    
521
	if( bits )
522
		document.iform.ealgo_keylen.value = bits;
523
}
524

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

    
531
	if (!document.iform.dpd_delay.value)
532
		document.iform.dpd_delay.value = "10";
533

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

    
538
//]]>
539
</script>
540

    
541
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
542

    
543
<?php
544
	if ($input_errors)
545
		print_input_errors($input_errors);
546
?>
547

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

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

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

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

    
633

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

    
646
					<?php if (!$pconfig['mobile']): ?>
647

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

    
657
					<?php endif; ?>
658

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

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