Projet

Général

Profil

Télécharger (36,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_ipsec_phase1.php @ 2d1e985d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
82
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
83
	$pconfig['protocol'] = $a_phase1[$p1index]['protocol'];
84
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
85
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
86
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
87
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
88
	$pconfig['verify_identifier'] = isset($a_phase1[$p1index]['verify_identifier']);
89
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
90
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
91
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
92
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
93
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
94
	$pconfig['generate_policy'] = $a_phase1[$p1index]['generate_policy'];
95
	$pconfig['proposal_check'] = $a_phase1[$p1index]['proposal_check'];
96

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

    
105
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
106
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
107

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

    
130
	/* mobile client */
131
	if($_GET['mobile'])
132
		$pconfig['mobile']=true;
133
}
134

    
135
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
136
	unset($p1index);
137

    
138
if ($_POST) {
139
	unset($input_errors);
140
	$pconfig = $_POST;
141

    
142
	/* input validation */
143

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

    
151
	// Only require PSK here for normal PSK tunnels (not mobile) or xauth.
152
	// For RSA methods, require the CA/Cert.
153
	switch ($method) {
154
		case "pre_shared_key":
155
			// If this is a mobile PSK tunnel the user PSKs go on
156
			//    the PSK tab, not here, so skip the check.
157
			if ($pconfig['mobile'])
158
				break;
159
		case "xauth_psk_server":
160
			$reqdfields = explode(" ", "pskey");
161
			$reqdfieldsn = array(gettext("Pre-Shared Key"));
162
			break;
163
		case "hybrid_rsa_server":
164
		case "xauth_rsa_server":
165
		case "rsasig":
166
			$reqdfields = explode(" ", "caref certref");
167
			$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
168
			break;
169
	}
170
	if (!$pconfig['mobile']) {
171
		$reqdfields[] = "remotegw";
172
		$reqdfieldsn[] = gettext("Remote gateway");
173
	}
174

    
175
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
176

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

    
180
	if ($pconfig['remotegw']) {
181
		if (!is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))
182
			$input_errors[] = gettext("A valid remote gateway address or host name must be specified.");
183
		elseif (is_ipaddrv4($pconfig['remotegw']) && ($pconfig['protocol'] != "inet"))
184
			$input_errors[] = gettext("A valid remote gateway IPv4 address must be specified or you need to change protocol to IPv6");
185
		elseif (is_ipaddrv6($pconfig['remotegw']) && ($pconfig['protocol'] != "inet6"))
186
			$input_errors[] = gettext("A valid remote gateway IPv6 address must be specified or you need to change protocol to IPv4");
187
	}
188

    
189
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
190
		$t = 0;
191
		foreach ($a_phase1 as $ph1tmp) {
192
			if ($p1index <> $t) {
193
				$tremotegw = $pconfig['remotegw'];
194
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
195
					$input_errors[] = sprintf(gettext('The remote gateway "%1$s" is already used by phase1 "%2$s".'), $tremotegw, $ph1tmp['descr']);
196
				}
197
			}
198
			$t++;
199
		}
200
	}
201

    
202
	if (is_array($a_phase2) && (count($a_phase2))) {
203
		foreach ($a_phase2 as $phase2) {
204
			if($phase2['ikeid'] == $pconfig['ikeid']) {
205
				if (($pconfig['protocol'] == "inet") && ($phase2['mode'] == "tunnel6")) {
206
					$input_errors[] = gettext("There is a Phase 2 using IPv6, you cannot use IPv4.");
207
					break;
208
				}
209
				if (($pconfig['protocol'] == "inet6") && ($phase2['mode'] == "tunnel")) {
210
					$input_errors[] = gettext("There is a Phase 2 using IPv4, you cannot use IPv6.");
211
					break;
212
				}
213
			}
214
		}
215
	}
216

    
217
	/* My identity */
218

    
219
	if ($pconfig['myid_type'] == "myaddress")
220
		$pconfig['myid_data'] = "";
221

    
222
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
223
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
224

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

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

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

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

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

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

    
243
	if ($pconfig['myid_type'] == "fqdn")
244
		if (is_domain($pconfig['myid_data']) == false)
245
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
246

    
247
	if ($pconfig['myid_type'] == "user_fqdn") {
248
		$user_fqdn = explode("@",$pconfig['myid_data']);
249
		if (is_domain($user_fqdn[1]) == false)
250
			$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.");
251
	}
252

    
253
	if ($pconfig['myid_type'] == "dyn_dns")
254
		if (is_domain($pconfig['myid_data']) == false)
255
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
256

    
257
	/* Peer identity */
258

    
259
	if ($pconfig['myid_type'] == "peeraddress")
260
		$pconfig['peerid_data'] = "";
261

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

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

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

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

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

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

    
282
		if ($pconfig['peerid_type'] == "fqdn")
283
			if (is_domain($pconfig['peerid_data']) == false)
284
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
285

    
286
		if ($pconfig['peerid_type'] == "user_fqdn") {
287
			$user_fqdn = explode("@",$pconfig['peerid_data']);
288
			if (is_domain($user_fqdn[1]) == false)
289
				$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.");
290
		}
291
	}
292

    
293
	if ($pconfig['dpd_enable']) {
294
		if (!is_numeric($pconfig['dpd_delay']))
295
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
296

    
297
		if (!is_numeric($pconfig['dpd_maxfail']))
298
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
299
	}
300

    
301
	/* build our encryption algorithms array */
302
	$pconfig['ealgo'] = array();
303
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
304
	if($pconfig['ealgo_keylen'])
305
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
306

    
307
	if (!$input_errors) {
308
		$ph1ent['ikeid'] = $pconfig['ikeid'];
309
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
310
		$ph1ent['interface'] = $pconfig['interface'];
311
		/* if the remote gateway changed and the interface is not WAN then remove route */
312
		/* the vpn_ipsec_configure() handles adding the route */
313
		if ($pconfig['interface'] <> "wan") {
314
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
315
				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']}");
316
			}
317
		}
318

    
319
		if ($pconfig['mobile'])
320
			$ph1ent['mobile'] = true;
321
		else
322
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
323

    
324
		$ph1ent['mode'] = $pconfig['mode'];
325
		$ph1ent['protocol'] = $pconfig['protocol'];
326

    
327
		$ph1ent['myid_type'] = $pconfig['myid_type'];
328
		$ph1ent['myid_data'] = $pconfig['myid_data'];
329
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
330
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
331
		if (isset($pconfig['verify_identifier']))
332
			$ph1ent['verify_identifier'] = true;
333
		else
334
			unset($ph1ent['verify_identifier']);
335

    
336
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
337
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
338
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
339
		$ph1ent['lifetime'] = $pconfig['lifetime'];
340
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
341
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
342
		$ph1ent['certref'] = $pconfig['certref'];
343
		$ph1ent['caref'] = $pconfig['caref'];
344
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
345
		$ph1ent['generate_policy'] = $pconfig['generate_policy'];
346
		$ph1ent['proposal_check'] = $pconfig['proposal_check'];
347
		$ph1ent['descr'] = $pconfig['descr'];
348
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
349

    
350
		if (isset($pconfig['dpd_enable'])) {
351
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
352
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
353
		}
354

    
355
		/* generate unique phase1 ikeid */
356
		if ($ph1ent['ikeid'] == 0)
357
			$ph1ent['ikeid'] = ipsec_ikeid_next();
358

    
359
		if (isset($p1index) && $a_phase1[$p1index])
360
			$a_phase1[$p1index] = $ph1ent;
361
		else
362
			$a_phase1[] = $ph1ent;
363

    
364
		/* now we need to find all phase2 entries for this host */
365
		if (is_array($a_phase2) && (count($a_phase2))) {
366
			foreach ($a_phase2 as $phase2) {
367
				if($phase2['ikeid'] == $ph1ent['ikeid']) {
368
					log_error("Reload {$ph1ent['descr']} tunnel(s)");
369
					$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
370
					$old_phase2 = $phase2;
371
					reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2);
372
				}
373
			}
374
		}
375
		write_config();
376
		mark_subsystem_dirty('ipsec');
377

    
378
		header("Location: vpn_ipsec.php");
379
		exit;
380
	}
381
}
382

    
383
if ($pconfig['mobile'])
384
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
385
else
386
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
387
$shortcut_section = "ipsec";
388

    
389

    
390
include("head.inc");
391

    
392
?>
393

    
394
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
395
<?php include("fbegin.inc"); ?>
396
<script type="text/JavaScript">
397
<!--
398

    
399
function myidsel_change() {
400
	index = document.iform.myid_type.selectedIndex;
401
	value = document.iform.myid_type.options[index].value;
402
	if (value == 'myaddress')
403
			document.getElementById('myid_data').style.visibility = 'hidden';
404
	else
405
			document.getElementById('myid_data').style.visibility = 'visible';
406
}
407

    
408
function peeridsel_change() {
409
	index = document.iform.peerid_type.selectedIndex;
410
	value = document.iform.peerid_type.options[index].value;
411
	if (value == 'peeraddress')
412
			document.getElementById('peerid_data').style.visibility = 'hidden';
413
	else
414
			document.getElementById('peerid_data').style.visibility = 'visible';
415

    
416
	if (value == 'asn1dn')
417
		document.getElementById('opt_verify_identifier').style.visibility = 'visible';
418
	else
419
		document.getElementById('opt_verify_identifier').style.visibility = 'hidden';
420
}
421

    
422
function methodsel_change() {
423
	index = document.iform.authentication_method.selectedIndex;
424
	value = document.iform.authentication_method.options[index].value;
425

    
426
	switch (value) {
427
		case 'hybrid_rsa_server':
428
			document.getElementById('opt_psk').style.display = 'none';
429
			document.getElementById('opt_peerid').style.display = '';
430
			document.getElementById('opt_cert').style.display = '';
431
			document.getElementById('opt_ca').style.display = '';
432
			document.getElementById('opt_cert').disabled = false;
433
			document.getElementById('opt_ca').disabled = false;
434
			break;
435
		case 'xauth_rsa_server':
436
		case 'rsasig':
437
			document.getElementById('opt_psk').style.display = 'none';
438
			document.getElementById('opt_peerid').style.display = '';
439
			document.getElementById('opt_cert').style.display = '';
440
			document.getElementById('opt_ca').style.display = '';
441
			document.getElementById('opt_cert').disabled = false;
442
			document.getElementById('opt_ca').disabled = false;
443
			break;
444
<?php if ($pconfig['mobile']) { ?>
445
		case 'pre_shared_key':
446
			document.getElementById('opt_psk').style.display = 'none';
447
			document.getElementById('opt_peerid').style.display = 'none';
448
			document.getElementById('opt_cert').style.display = 'none';
449
			document.getElementById('opt_ca').style.display = 'none';
450
			document.getElementById('opt_cert').disabled = true;
451
			document.getElementById('opt_ca').disabled = true;
452
			break;
453
<?php } ?>
454
		default: /* psk modes*/
455
			document.getElementById('opt_psk').style.display = '';
456
			document.getElementById('opt_peerid').style.display = '';
457
			document.getElementById('opt_cert').style.display = 'none';
458
			document.getElementById('opt_ca').style.display = 'none';
459
			document.getElementById('opt_cert').disabled = true;
460
			document.getElementById('opt_ca').disabled = true;
461
			break;
462
	}
463
}
464

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

    
477
		$key_hi = $algodata['keysel']['hi'];
478
		$key_lo = $algodata['keysel']['lo'];
479
		$key_step = $algodata['keysel']['step'];
480

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

    
495
	if( bits )
496
		document.iform.ealgo_keylen.value = bits;
497
}
498

    
499
function dpdchkbox_change() {
500
	if( document.iform.dpd_enable.checked )
501
		document.getElementById('opt_dpd').style.display = '';
502
	else
503
		document.getElementById('opt_dpd').style.display = 'none';
504

    
505
	if (!document.iform.dpd_delay.value)
506
		document.iform.dpd_delay.value = "10";
507

    
508
	if (!document.iform.dpd_maxfail.value)
509
		document.iform.dpd_maxfail.value = "5";
510
}
511

    
512
//-->
513
</script>
514

    
515
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
516

    
517
<?php
518
	if ($input_errors)
519
		print_input_errors($input_errors);
520
?>
521

    
522
<table width="100%" border="0" cellpadding="0" cellspacing="0">
523
	<tr class="tabnavtbl">
524
		<td id="tabnav">
525
			<?php
526
				$tab_array = array();
527
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
528
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
529
				$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
530
				display_top_tabs($tab_array);
531
			?>
532
		</td>
533
	</tr>
534
	<tr>
535
		<td id="mainarea">
536
			<div class="tabcont">
537
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
538
					<tr>
539
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
540
					</tr>
541
					<tr>
542
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
543
						<td width="78%" class="vtable">
544
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?>/>
545
							<strong><?=gettext("Disable this phase1 entry"); ?></strong><br />
546
							<span class="vexpl">
547
								<?=gettext("Set this option to disable this phase1 without " .
548
								"removing it from the list"); ?>.
549
							</span>
550
						</td>
551
					</tr>
552
					<tr>
553
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Internet Protocol"); ?></td>
554
						<td width="78%" class="vtable">
555
							<select name="protocol" class="formselect">
556
							<?php
557
								$protocols = array("inet" => "IPv4", "inet6" => "IPv6");
558
								foreach ($protocols as $protocol => $name):
559
							?>
560
								<option value="<?=$protocol;?>" <?php if ($protocol == $pconfig['protocol']) echo "selected=\"selected\""; ?>>
561
									<?=htmlspecialchars($name);?>
562
								</option>
563
							<?php endforeach; ?>
564
							</select> <br /> <span class="vexpl"><?=gettext("Select the Internet Protocol family from this dropdown"); ?>.</span>
565
						</td>
566
					</tr>
567
					<tr>
568
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
569
						<td width="78%" class="vtable">
570
							<select name="interface" class="formselect">
571
							<?php
572
								$interfaces = get_configured_interface_with_descr();
573

    
574
								$carplist = get_configured_carp_interface_list();
575
								foreach ($carplist as $cif => $carpip)
576
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
577

    
578
								$aliaslist = get_configured_ip_aliases_list();
579
								foreach ($aliaslist as $aliasip => $aliasif)
580
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
581

    
582
								$grouplist = return_gateway_groups_array();
583
								foreach ($grouplist as $name => $group) {
584
									if($group[0]['vip'] <> "")
585
										$vipif = $group[0]['vip'];
586
									else
587
										$vipif = $group[0]['int'];
588
									$interfaces[$name] = "GW Group {$name}";
589
								}
590

    
591

    
592
								foreach ($interfaces as $iface => $ifacename):
593
							?>
594
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
595
									<?=htmlspecialchars($ifacename);?>
596
								</option>
597
							<?php endforeach; ?>
598
							</select>
599
							<br />
600
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
601
						</td>
602
					</tr>
603

    
604
					<?php if (!$pconfig['mobile']): ?>
605

    
606
					<tr>
607
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
608
						<td width="78%" class="vtable">
609
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>"/>
610
							<br />
611
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
612
						</td>
613
					</tr>
614

    
615
					<?php endif; ?>
616

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

    
911
<script type="text/JavaScript">
912
<!--
913
<?php
914
	/* determine if we should init the key length */
915
	$keyset = '';
916
	if (isset($pconfig['ealgo']['keylen']))
917
		if (is_numeric($pconfig['ealgo']['keylen']))
918
			$keyset = $pconfig['ealgo']['keylen'];
919
?>
920
myidsel_change();
921
peeridsel_change();
922
methodsel_change();
923
ealgosel_change(<?=$keyset;?>);
924
dpdchkbox_change();
925
//-->
926
</script>
927
<?php include("fend.inc"); ?>
928
</body>
929
</html>
(232-232/246)