Projet

Général

Profil

Télécharger (34,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_ipsec_phase1.php @ fa4e059e

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
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
##|+PRIV
34
##|*IDENT=page-vpn-ipsec-editphase1
35
##|*NAME=VPN: IPsec: Edit Phase 1 page
36
##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 1' page.
37
##|*MATCH=vpn_ipsec_phase1.php*
38
##|-PRIV
39

    
40
require("functions.inc");
41
require("guiconfig.inc");
42
require_once("ipsec.inc");
43
require_once("vpn.inc");
44

    
45
if (!is_array($config['ipsec']['phase1']))
46
	$config['ipsec']['phase1'] = array();
47

    
48
if (!is_array($config['ipsec']['phase2']))
49
	$config['ipsec']['phase2'] = array();
50

    
51
$a_phase1 = &$config['ipsec']['phase1'];
52
$a_phase2 = &$config['ipsec']['phase2'];
53

    
54
if (is_numericint($_GET['p1index']))
55
	$p1index = $_GET['p1index'];
56
if (isset($_POST['p1index']) && is_numericint($_POST['p1index']))
57
	$p1index = $_POST['p1index'];
58

    
59
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
60
	$p1index = $_GET['dup'];
61

    
62
if (isset($p1index) && $a_phase1[$p1index]) {
63
	// don't copy the ikeid on dup
64
	if (!isset($_GET['dup']) || !is_numericint($_GET['dup']))
65
		$pconfig['ikeid'] = $a_phase1[$p1index]['ikeid'];
66

    
67
	$old_ph1ent = $a_phase1[$p1index];
68

    
69
	$pconfig['disabled'] = isset($a_phase1[$p1index]['disabled']);
70

    
71
	if ($a_phase1[$p1index]['interface'])
72
		$pconfig['interface'] = $a_phase1[$p1index]['interface'];
73
	else
74
		$pconfig['interface'] = "wan";
75

    
76
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_phase1[$p1index]['remote-subnet']);
77

    
78
	if (isset($a_phase1[$p1index]['mobile']))
79
		$pconfig['mobile'] = 'true';
80
	else
81
		$pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway'];
82

    
83
	if (empty($a_phase1[$p1index]['iketype']))
84
		$pconfig['iketype'] = "ikev1";
85
	else
86
		$pconfig['iketype'] = $a_phase1[$p1index]['iketype'];
87
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
88
	$pconfig['protocol'] = $a_phase1[$p1index]['protocol'];
89
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
90
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
91
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
92
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
93
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
94
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
95
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
96
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
97
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
98

    
99
	if (($pconfig['authentication_method'] == "pre_shared_key") ||
100
		($pconfig['authentication_method'] == "xauth_psk_server")) {
101
		$pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key'];
102
	} else {
103
		$pconfig['certref'] = $a_phase1[$p1index]['certref'];
104
		$pconfig['caref'] = $a_phase1[$p1index]['caref'];
105
	}
106

    
107
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
108
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
109

    
110
	if ($a_phase1[$p1index]['dpd_delay'] &&	$a_phase1[$p1index]['dpd_maxfail']) {
111
		$pconfig['dpd_enable'] = true;
112
		$pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay'];
113
		$pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail'];
114
	}
115
} else {
116
	/* defaults */
117
	$pconfig['interface'] = "wan";
118
	if($config['interfaces']['lan'])
119
		$pconfig['localnet'] = "lan";
120
	$pconfig['mode'] = "aggressive";
121
	$pconfig['protocol'] = "inet";
122
	$pconfig['myid_type'] = "myaddress";
123
	$pconfig['peerid_type'] = "peeraddress";
124
	$pconfig['authentication_method'] = "pre_shared_key";
125
	$pconfig['ealgo'] = array( name => "3des" );
126
	$pconfig['halgo'] = "sha1";
127
	$pconfig['dhgroup'] = "2";
128
	$pconfig['lifetime'] = "28800";
129
	$pconfig['nat_traversal'] = "on";
130
	$pconfig['dpd_enable'] = true;
131
	$pconfig['iketype'] = "ikev1";
132

    
133
	/* mobile client */
134
	if($_GET['mobile'])
135
		$pconfig['mobile']=true;
136
}
137

    
138
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
139
	unset($p1index);
140

    
141
if ($_POST) {
142
	unset($input_errors);
143
	$pconfig = $_POST;
144

    
145
	/* input validation */
146

    
147
	$method = $pconfig['authentication_method'];
148
	// Unset ca and cert if not required to avaoid storing in config
149
	if ($method == "pre_shared_key" || $method == "xauth_psk_server"){
150
		unset($pconfig['caref']);
151
		unset($pconfig['certref']);
152
	}
153

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

    
182
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
183

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

    
187
	if ($pconfig['remotegw']) {
188
		if (!is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))
189
			$input_errors[] = gettext("A valid remote gateway address or host name must be specified.");
190
		elseif (is_ipaddrv4($pconfig['remotegw']) && ($pconfig['protocol'] != "inet"))
191
			$input_errors[] = gettext("A valid remote gateway IPv4 address must be specified or you need to change protocol to IPv6");
192
		elseif (is_ipaddrv6($pconfig['remotegw']) && ($pconfig['protocol'] != "inet6"))
193
			$input_errors[] = gettext("A valid remote gateway IPv6 address must be specified or you need to change protocol to IPv4");
194
	}
195

    
196
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
197
		$t = 0;
198
		foreach ($a_phase1 as $ph1tmp) {
199
			if ($p1index <> $t) {
200
				$tremotegw = $pconfig['remotegw'];
201
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
202
					$input_errors[] = sprintf(gettext('The remote gateway "%1$s" is already used by phase1 "%2$s".'), $tremotegw, $ph1tmp['descr']);
203
				}
204
			}
205
			$t++;
206
		}
207
	}
208

    
209
	if (is_array($a_phase2) && (count($a_phase2))) {
210
		foreach ($a_phase2 as $phase2) {
211
			if($phase2['ikeid'] == $pconfig['ikeid']) {
212
				if (($pconfig['protocol'] == "inet") && ($phase2['mode'] == "tunnel6")) {
213
					$input_errors[] = gettext("There is a Phase 2 using IPv6, you cannot use IPv4.");
214
					break;
215
				}
216
				if (($pconfig['protocol'] == "inet6") && ($phase2['mode'] == "tunnel")) {
217
					$input_errors[] = gettext("There is a Phase 2 using IPv4, you cannot use IPv6.");
218
					break;
219
				}
220
			}
221
		}
222
	}
223

    
224
	/* My identity */
225

    
226
	if ($pconfig['myid_type'] == "myaddress")
227
		$pconfig['myid_data'] = "";
228

    
229
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
230
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
231

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

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

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

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

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

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

    
250
	if ($pconfig['myid_type'] == "fqdn")
251
		if (is_domain($pconfig['myid_data']) == false)
252
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
253

    
254
	if ($pconfig['myid_type'] == "user_fqdn") {
255
		$user_fqdn = explode("@",$pconfig['myid_data']);
256
		if (is_domain($user_fqdn[1]) == false)
257
			$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.");
258
	}
259

    
260
	if ($pconfig['myid_type'] == "dyn_dns")
261
		if (is_domain($pconfig['myid_data']) == false)
262
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
263

    
264
	/* Peer identity */
265

    
266
	if ($pconfig['myid_type'] == "peeraddress")
267
		$pconfig['peerid_data'] = "";
268

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

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

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

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

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

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

    
289
		if ($pconfig['peerid_type'] == "fqdn")
290
			if (is_domain($pconfig['peerid_data']) == false)
291
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
292

    
293
		if ($pconfig['peerid_type'] == "user_fqdn") {
294
			$user_fqdn = explode("@",$pconfig['peerid_data']);
295
			if (is_domain($user_fqdn[1]) == false)
296
				$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.");
297
		}
298
	}
299

    
300
	if ($pconfig['dpd_enable']) {
301
		if (!is_numeric($pconfig['dpd_delay']))
302
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
303

    
304
		if (!is_numeric($pconfig['dpd_maxfail']))
305
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
306
	}
307

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

    
311
	/* build our encryption algorithms array */
312
	$pconfig['ealgo'] = array();
313
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
314
	if($pconfig['ealgo_keylen'])
315
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
316

    
317
	if (!$input_errors) {
318
		$ph1ent['ikeid'] = $pconfig['ikeid'];
319
		$ph1ent['iketype'] = $pconfig['iketype'];
320
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
321
		$ph1ent['interface'] = $pconfig['interface'];
322
		/* if the remote gateway changed and the interface is not WAN then remove route */
323
		/* the vpn_ipsec_configure() handles adding the route */
324
		if ($pconfig['interface'] <> "wan") {
325
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
326
				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']}");
327
			}
328
		}
329

    
330
		if ($pconfig['mobile'])
331
			$ph1ent['mobile'] = true;
332
		else
333
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
334

    
335
		$ph1ent['mode'] = $pconfig['mode'];
336
		$ph1ent['protocol'] = $pconfig['protocol'];
337

    
338
		$ph1ent['myid_type'] = $pconfig['myid_type'];
339
		$ph1ent['myid_data'] = $pconfig['myid_data'];
340
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
341
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
342

    
343
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
344
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
345
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
346
		$ph1ent['lifetime'] = $pconfig['lifetime'];
347
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
348
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
349
		$ph1ent['certref'] = $pconfig['certref'];
350
		$ph1ent['caref'] = $pconfig['caref'];
351
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
352
		$ph1ent['descr'] = $pconfig['descr'];
353
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
354

    
355
		if (isset($pconfig['dpd_enable'])) {
356
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
357
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
358
		}
359

    
360
		/* generate unique phase1 ikeid */
361
		if ($ph1ent['ikeid'] == 0)
362
			$ph1ent['ikeid'] = ipsec_ikeid_next();
363

    
364
		if (isset($p1index) && $a_phase1[$p1index])
365
			$a_phase1[$p1index] = $ph1ent;
366
		else
367
			$a_phase1[] = $ph1ent;
368

    
369
		write_config();
370
		mark_subsystem_dirty('ipsec');
371

    
372
		header("Location: vpn_ipsec.php");
373
		exit;
374
	}
375
}
376

    
377
if ($pconfig['mobile'])
378
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
379
else
380
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
381
$shortcut_section = "ipsec";
382

    
383

    
384
include("head.inc");
385

    
386
?>
387

    
388
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
389
<?php include("fbegin.inc"); ?>
390
<script type="text/javascript">
391
//<![CDATA[
392

    
393
function myidsel_change() {
394
	index = document.iform.myid_type.selectedIndex;
395
	value = document.iform.myid_type.options[index].value;
396
	if (value == 'myaddress')
397
			document.getElementById('myid_data').style.visibility = 'hidden';
398
	else
399
			document.getElementById('myid_data').style.visibility = 'visible';
400
}
401

    
402
function peeridsel_change() {
403
	index = document.iform.peerid_type.selectedIndex;
404
	value = document.iform.peerid_type.options[index].value;
405
	if (value == 'peeraddress')
406
			document.getElementById('peerid_data').style.visibility = 'hidden';
407
	else
408
			document.getElementById('peerid_data').style.visibility = 'visible';
409
}
410

    
411
function methodsel_change() {
412
	index = document.iform.authentication_method.selectedIndex;
413
	value = document.iform.authentication_method.options[index].value;
414

    
415
	switch (value) {
416
	case 'eap-tls':
417
		document.getElementById('opt_psk').style.display = 'none';
418
		document.getElementById('opt_peerid').style.display = '';
419
		document.getElementById('opt_cert').style.display = '';
420
		document.getElementById('opt_ca').style.display = '';
421
		document.getElementById('opt_cert').disabled = false;
422
		document.getElementById('opt_ca').disabled = false;
423
		break;
424
	case 'hybrid_rsa_server':
425
		document.getElementById('opt_psk').style.display = 'none';
426
		document.getElementById('opt_peerid').style.display = '';
427
		document.getElementById('opt_cert').style.display = '';
428
		document.getElementById('opt_ca').style.display = '';
429
		document.getElementById('opt_cert').disabled = false;
430
		document.getElementById('opt_ca').disabled = false;
431
		break;
432
	case 'xauth_rsa_server':
433
	case 'rsasig':
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
<?php if ($pconfig['mobile']) { ?>
442
	case 'pre_shared_key':
443
		document.getElementById('opt_psk').style.display = 'none';
444
		document.getElementById('opt_peerid').style.display = 'none';
445
		document.getElementById('opt_cert').style.display = 'none';
446
		document.getElementById('opt_ca').style.display = 'none';
447
		document.getElementById('opt_cert').disabled = true;
448
		document.getElementById('opt_ca').disabled = true;
449
		break;
450
<?php } ?>
451
	default: /* psk modes*/
452
		document.getElementById('opt_psk').style.display = '';
453
		document.getElementById('opt_peerid').style.display = '';
454
		document.getElementById('opt_cert').style.display = 'none';
455
		document.getElementById('opt_ca').style.display = 'none';
456
		document.getElementById('opt_cert').disabled = true;
457
		document.getElementById('opt_ca').disabled = true;
458
		break;
459
	}
460
}
461

    
462
/* PHP generated java script for variable length keys */
463
function ealgosel_change(bits) {
464
	switch (document.iform.ealgo.selectedIndex) {
465
<?php
466
$i = 0;
467
foreach ($p1_ealgos as $algo => $algodata) {
468
	if (is_array($algodata['keysel'])) {
469
		echo "		case {$i}:\n";
470
		echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
471
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
472
	//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
473

    
474
		$key_hi = $algodata['keysel']['hi'];
475
		$key_lo = $algodata['keysel']['lo'];
476
		$key_step = $algodata['keysel']['step'];
477

    
478
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
479
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
480
		echo "			break;\n";
481
	} else {
482
		echo "		case {$i}:\n";
483
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
484
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
485
		echo "			break;\n";
486
	}
487
	$i++;
488
}
489
?>
490
	}
491

    
492
	if( bits )
493
		document.iform.ealgo_keylen.value = bits;
494
}
495

    
496
function dpdchkbox_change() {
497
	if( document.iform.dpd_enable.checked )
498
		document.getElementById('opt_dpd').style.display = '';
499
	else
500
		document.getElementById('opt_dpd').style.display = 'none';
501

    
502
	if (!document.iform.dpd_delay.value)
503
		document.iform.dpd_delay.value = "10";
504

    
505
	if (!document.iform.dpd_maxfail.value)
506
		document.iform.dpd_maxfail.value = "5";
507
}
508

    
509
//]]>
510
</script>
511

    
512
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
513

    
514
<?php
515
	if ($input_errors)
516
		print_input_errors($input_errors);
517
?>
518

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

    
587
								$carplist = get_configured_carp_interface_list();
588
								foreach ($carplist as $cif => $carpip)
589
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
590

    
591
								$aliaslist = get_configured_ip_aliases_list();
592
								foreach ($aliaslist as $aliasip => $aliasif)
593
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
594

    
595
								$grouplist = return_gateway_groups_array();
596
								foreach ($grouplist as $name => $group) {
597
									if($group[0]['vip'] <> "")
598
										$vipif = $group[0]['vip'];
599
									else
600
										$vipif = $group[0]['int'];
601
									$interfaces[$name] = "GW Group {$name}";
602
								}
603

    
604

    
605
								foreach ($interfaces as $iface => $ifacename):
606
							?>
607
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
608
									<?=htmlspecialchars($ifacename);?>
609
								</option>
610
							<?php endforeach; ?>
611
							</select>
612
							<br />
613
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
614
						</td>
615
					</tr>
616

    
617
					<?php if (!$pconfig['mobile']): ?>
618

    
619
					<tr>
620
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
621
						<td width="78%" class="vtable">
622
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>" />
623
							<br />
624
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
625
						</td>
626
					</tr>
627

    
628
					<?php endif; ?>
629

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

    
892
<script type="text/javascript">
893
//<![CDATA[
894
<?php
895
	/* determine if we should init the key length */
896
	$keyset = '';
897
	if (isset($pconfig['ealgo']['keylen']))
898
		if (is_numeric($pconfig['ealgo']['keylen']))
899
			$keyset = $pconfig['ealgo']['keylen'];
900
?>
901
myidsel_change();
902
peeridsel_change();
903
methodsel_change();
904
ealgosel_change(<?=$keyset;?>);
905
dpdchkbox_change();
906
//]]>
907
</script>
908
<?php include("fend.inc"); ?>
909
</body>
910
</html>
(241-241/256)