Project

General

Profile

Download (35.8 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
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
333
		$ph1ent['interface'] = $pconfig['interface'];
334
		/* if the remote gateway changed and the interface is not WAN then remove route */
335
		/* the vpn_ipsec_configure() handles adding the route */
336
		if ($pconfig['interface'] <> "wan") {
337
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
338
				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']}");
339
			}
340
		}
341

    
342
		if ($pconfig['mobile'])
343
			$ph1ent['mobile'] = true;
344
		else
345
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
346

    
347
		$ph1ent['mode'] = $pconfig['mode'];
348
		$ph1ent['protocol'] = $pconfig['protocol'];
349

    
350
		$ph1ent['myid_type'] = $pconfig['myid_type'];
351
		$ph1ent['myid_data'] = $pconfig['myid_data'];
352
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
353
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
354

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

    
367
		if (isset($pconfig['reauth_enable']))
368
			$ph1ent['reauth_enable'] = true;
369
		if (isset($pconfig['rekey_enable']))
370
			$ph1ent['rekey_enable'] = true;
371

    
372
		if (isset($pconfig['dpd_enable'])) {
373
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
374
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
375
		}
376

    
377
		/* generate unique phase1 ikeid */
378
		if ($ph1ent['ikeid'] == 0)
379
			$ph1ent['ikeid'] = ipsec_ikeid_next();
380

    
381
		if (isset($p1index) && $a_phase1[$p1index])
382
			$a_phase1[$p1index] = $ph1ent;
383
		else
384
			$a_phase1[] = $ph1ent;
385

    
386
		write_config();
387
		mark_subsystem_dirty('ipsec');
388

    
389
		header("Location: vpn_ipsec.php");
390
		exit;
391
	}
392
}
393

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

    
400

    
401
include("head.inc");
402

    
403
?>
404

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

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

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

    
428
function methodsel_change() {
429
	index = document.iform.authentication_method.selectedIndex;
430
	value = document.iform.authentication_method.options[index].value;
431

    
432
	switch (value) {
433
	case 'eap-tls':
434
		document.getElementById('opt_psk').style.display = 'none';
435
		document.getElementById('opt_peerid').style.display = '';
436
		document.getElementById('opt_cert').style.display = '';
437
		document.getElementById('opt_ca').style.display = '';
438
		document.getElementById('opt_cert').disabled = false;
439
		document.getElementById('opt_ca').disabled = false;
440
		break;
441
	case 'hybrid_rsa_server':
442
		document.getElementById('opt_psk').style.display = 'none';
443
		document.getElementById('opt_peerid').style.display = '';
444
		document.getElementById('opt_cert').style.display = '';
445
		document.getElementById('opt_ca').style.display = '';
446
		document.getElementById('opt_cert').disabled = false;
447
		document.getElementById('opt_ca').disabled = false;
448
		break;
449
	case 'xauth_rsa_server':
450
	case 'rsasig':
451
		document.getElementById('opt_psk').style.display = 'none';
452
		document.getElementById('opt_peerid').style.display = '';
453
		document.getElementById('opt_cert').style.display = '';
454
		document.getElementById('opt_ca').style.display = '';
455
		document.getElementById('opt_cert').disabled = false;
456
		document.getElementById('opt_ca').disabled = false;
457
		break;
458
<?php if ($pconfig['mobile']) { ?>
459
	case 'pre_shared_key':
460
		document.getElementById('opt_psk').style.display = 'none';
461
		document.getElementById('opt_peerid').style.display = 'none';
462
		document.getElementById('opt_cert').style.display = 'none';
463
		document.getElementById('opt_ca').style.display = 'none';
464
		document.getElementById('opt_cert').disabled = true;
465
		document.getElementById('opt_ca').disabled = true;
466
		break;
467
<?php } ?>
468
	default: /* psk modes*/
469
		document.getElementById('opt_psk').style.display = '';
470
		document.getElementById('opt_peerid').style.display = '';
471
		document.getElementById('opt_cert').style.display = 'none';
472
		document.getElementById('opt_ca').style.display = 'none';
473
		document.getElementById('opt_cert').disabled = true;
474
		document.getElementById('opt_ca').disabled = true;
475
		break;
476
	}
477
}
478

    
479
/* PHP generated java script for variable length keys */
480
function ealgosel_change(bits) {
481
	switch (document.iform.ealgo.selectedIndex) {
482
<?php
483
$i = 0;
484
foreach ($p1_ealgos as $algo => $algodata) {
485
	if (is_array($algodata['keysel'])) {
486
		echo "		case {$i}:\n";
487
		echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
488
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
489
	//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
490

    
491
		$key_hi = $algodata['keysel']['hi'];
492
		$key_lo = $algodata['keysel']['lo'];
493
		$key_step = $algodata['keysel']['step'];
494

    
495
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
496
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
497
		echo "			break;\n";
498
	} else {
499
		echo "		case {$i}:\n";
500
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
501
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
502
		echo "			break;\n";
503
	}
504
	$i++;
505
}
506
?>
507
	}
508

    
509
	if( bits )
510
		document.iform.ealgo_keylen.value = bits;
511
}
512

    
513
function dpdchkbox_change() {
514
	if( document.iform.dpd_enable.checked )
515
		document.getElementById('opt_dpd').style.display = '';
516
	else
517
		document.getElementById('opt_dpd').style.display = 'none';
518

    
519
	if (!document.iform.dpd_delay.value)
520
		document.iform.dpd_delay.value = "10";
521

    
522
	if (!document.iform.dpd_maxfail.value)
523
		document.iform.dpd_maxfail.value = "5";
524
}
525

    
526
//]]>
527
</script>
528

    
529
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
530

    
531
<?php
532
	if ($input_errors)
533
		print_input_errors($input_errors);
534
?>
535

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

    
604
								$carplist = get_configured_carp_interface_list();
605
								foreach ($carplist as $cif => $carpip)
606
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
607

    
608
								$aliaslist = get_configured_ip_aliases_list();
609
								foreach ($aliaslist as $aliasip => $aliasif)
610
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
611

    
612
								$grouplist = return_gateway_groups_array();
613
								foreach ($grouplist as $name => $group) {
614
									if($group[0]['vip'] <> "")
615
										$vipif = $group[0]['vip'];
616
									else
617
										$vipif = $group[0]['int'];
618
									$interfaces[$name] = "GW Group {$name}";
619
								}
620

    
621

    
622
								foreach ($interfaces as $iface => $ifacename):
623
							?>
624
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
625
									<?=htmlspecialchars($ifacename);?>
626
								</option>
627
							<?php endforeach; ?>
628
							</select>
629
							<br />
630
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
631
						</td>
632
					</tr>
633

    
634
					<?php if (!$pconfig['mobile']): ?>
635

    
636
					<tr>
637
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
638
						<td width="78%" class="vtable">
639
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>" />
640
							<br />
641
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
642
						</td>
643
					</tr>
644

    
645
					<?php endif; ?>
646

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

    
922
<script type="text/javascript">
923
//<![CDATA[
924
<?php
925
	/* determine if we should init the key length */
926
	$keyset = '';
927
	if (isset($pconfig['ealgo']['keylen']))
928
		if (is_numeric($pconfig['ealgo']['keylen']))
929
			$keyset = $pconfig['ealgo']['keylen'];
930
?>
931
myidsel_change();
932
peeridsel_change();
933
methodsel_change();
934
ealgosel_change(<?=$keyset;?>);
935
dpdchkbox_change();
936
//]]>
937
</script>
938
<?php include("fend.inc"); ?>
939
</body>
940
</html>
(241-241/256)