Projet

Général

Profil

Télécharger (35,7 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_ipsec_phase1.php @ 20452c68

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['iketype'] = $a_phase1[$p1index]['iketype'];
83
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
84
	$pconfig['protocol'] = $a_phase1[$p1index]['protocol'];
85
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
86
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
87
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
88
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
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
	$pconfig['iketype'] = "ikev1";
130

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

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

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

    
143
	/* input validation */
144

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

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

    
176
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
177

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

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

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

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

    
218
	/* My identity */
219

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

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

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

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

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

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

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

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

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

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

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

    
258
	/* Peer identity */
259

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

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

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

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

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

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

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

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

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

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

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

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

    
305
	/* build our encryption algorithms array */
306
	$pconfig['ealgo'] = array();
307
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
308
	if($pconfig['ealgo_keylen'])
309
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
310

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

    
324
		if ($pconfig['mobile'])
325
			$ph1ent['mobile'] = true;
326
		else
327
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
328

    
329
		$ph1ent['mode'] = $pconfig['mode'];
330
		$ph1ent['protocol'] = $pconfig['protocol'];
331

    
332
		$ph1ent['myid_type'] = $pconfig['myid_type'];
333
		$ph1ent['myid_data'] = $pconfig['myid_data'];
334
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
335
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
336

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

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

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

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

    
365
		write_config();
366
		mark_subsystem_dirty('ipsec');
367

    
368
		header("Location: vpn_ipsec.php");
369
		exit;
370
	}
371
}
372

    
373
if ($pconfig['mobile'])
374
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
375
else
376
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
377
$shortcut_section = "ipsec";
378

    
379

    
380
include("head.inc");
381

    
382
?>
383

    
384
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
385
<?php include("fbegin.inc"); ?>
386
<script type="text/javascript">
387
<!--
388

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

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

    
407
function methodsel_change() {
408
	index = document.iform.authentication_method.selectedIndex;
409
	value = document.iform.authentication_method.options[index].value;
410

    
411
	switch (value) {
412
		case 'hybrid_rsa_server':
413
			document.getElementById('opt_psk').style.display = 'none';
414
			document.getElementById('opt_peerid').style.display = '';
415
			document.getElementById('opt_cert').style.display = '';
416
			document.getElementById('opt_ca').style.display = '';
417
			document.getElementById('opt_cert').disabled = false;
418
			document.getElementById('opt_ca').disabled = false;
419
			break;
420
		case 'xauth_rsa_server':
421
		case 'rsasig':
422
			document.getElementById('opt_psk').style.display = 'none';
423
			document.getElementById('opt_peerid').style.display = '';
424
			document.getElementById('opt_cert').style.display = '';
425
			document.getElementById('opt_ca').style.display = '';
426
			document.getElementById('opt_cert').disabled = false;
427
			document.getElementById('opt_ca').disabled = false;
428
			break;
429
<?php if ($pconfig['mobile']) { ?>
430
		case 'pre_shared_key':
431
			document.getElementById('opt_psk').style.display = 'none';
432
			document.getElementById('opt_peerid').style.display = 'none';
433
			document.getElementById('opt_cert').style.display = 'none';
434
			document.getElementById('opt_ca').style.display = 'none';
435
			document.getElementById('opt_cert').disabled = true;
436
			document.getElementById('opt_ca').disabled = true;
437
			break;
438
<?php } ?>
439
		default: /* psk modes*/
440
			document.getElementById('opt_psk').style.display = '';
441
			document.getElementById('opt_peerid').style.display = '';
442
			document.getElementById('opt_cert').style.display = 'none';
443
			document.getElementById('opt_ca').style.display = 'none';
444
			document.getElementById('opt_cert').disabled = true;
445
			document.getElementById('opt_ca').disabled = true;
446
			break;
447
	}
448
}
449

    
450
/* PHP generated java script for variable length keys */
451
function ealgosel_change(bits) {
452
	switch (document.iform.ealgo.selectedIndex) {
453
<?php
454
$i = 0;
455
foreach ($p1_ealgos as $algo => $algodata) {
456
	if (is_array($algodata['keysel'])) {
457
		echo "		case {$i}:\n";
458
		echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
459
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
460
	//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
461

    
462
		$key_hi = $algodata['keysel']['hi'];
463
		$key_lo = $algodata['keysel']['lo'];
464
		$key_step = $algodata['keysel']['step'];
465

    
466
		for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
467
			echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
468
		echo "			break;\n";
469
	} else {
470
		echo "		case {$i}:\n";
471
		echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
472
		echo "			document.iform.ealgo_keylen.options.length = 0;\n";
473
		echo "			break;\n";
474
	}
475
	$i++;
476
}
477
?>
478
	}
479

    
480
	if( bits )
481
		document.iform.ealgo_keylen.value = bits;
482
}
483

    
484
function dpdchkbox_change() {
485
	if( document.iform.dpd_enable.checked )
486
		document.getElementById('opt_dpd').style.display = '';
487
	else
488
		document.getElementById('opt_dpd').style.display = 'none';
489

    
490
	if (!document.iform.dpd_delay.value)
491
		document.iform.dpd_delay.value = "10";
492

    
493
	if (!document.iform.dpd_maxfail.value)
494
		document.iform.dpd_maxfail.value = "5";
495
}
496

    
497
//-->
498
</script>
499

    
500
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
501

    
502
<?php
503
	if ($input_errors)
504
		print_input_errors($input_errors);
505
?>
506

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

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

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

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

    
592

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

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

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

    
616
					<?php endif; ?>
617

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

    
907
<script lannguage="JavaScript">
908
<!--
909
<?php
910
	/* determine if we should init the key length */
911
	$keyset = '';
912
	if (isset($pconfig['ealgo']['keylen']))
913
		if (is_numeric($pconfig['ealgo']['keylen']))
914
			$keyset = $pconfig['ealgo']['keylen'];
915
?>
916
myidsel_change();
917
peeridsel_change();
918
methodsel_change();
919
ealgosel_change(<?=$keyset;?>);
920
dpdchkbox_change();
921
//-->
922
</script>
923
<?php include("fend.inc"); ?>
924
</body>
925
</html>
(239-239/254)