Projet

Général

Profil

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

univnautes / usr / local / www / vpn_ipsec_phase1.php @ 0e7aad67

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 (isset($a_phase1[$p1index]['reauth_enable']))
111
		$pconfig['reauth_enable'] = true;
112
	if (isset($a_phase1[$p1index]['rekey_enable']))
113
		$pconfig['rekey_enable'] = true;
114

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

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

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

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

    
152
	/* input validation */
153

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

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

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

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

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

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

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

    
231
	/* My identity */
232

    
233
	if ($pconfig['myid_type'] == "myaddress")
234
		$pconfig['myid_data'] = "";
235

    
236
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
237
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
238

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

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

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

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

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

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

    
257
	if ($pconfig['myid_type'] == "fqdn")
258
		if (is_domain($pconfig['myid_data']) == false)
259
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
260

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

    
267
	if ($pconfig['myid_type'] == "dyn_dns")
268
		if (is_domain($pconfig['myid_data']) == false)
269
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
270

    
271
	/* Peer identity */
272

    
273
	if ($pconfig['myid_type'] == "peeraddress")
274
		$pconfig['peerid_data'] = "";
275

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

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

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

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

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

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

    
296
		if ($pconfig['peerid_type'] == "fqdn")
297
			if (is_domain($pconfig['peerid_data']) == false)
298
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
299

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

    
307
	if ($pconfig['dpd_enable']) {
308
		if (!is_numeric($pconfig['dpd_delay']))
309
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
310

    
311
		if (!is_numeric($pconfig['dpd_maxfail']))
312
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
313
	}
314

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

    
318
	/* build our encryption algorithms array */
319
	$pconfig['ealgo'] = array();
320
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
321
	if($pconfig['ealgo_keylen'])
322
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
323

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

    
337
		if ($pconfig['mobile'])
338
			$ph1ent['mobile'] = true;
339
		else
340
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
341

    
342
		$ph1ent['mode'] = $pconfig['mode'];
343
		$ph1ent['protocol'] = $pconfig['protocol'];
344

    
345
		$ph1ent['myid_type'] = $pconfig['myid_type'];
346
		$ph1ent['myid_data'] = $pconfig['myid_data'];
347
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
348
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
349

    
350
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
351
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
352
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
353
		$ph1ent['lifetime'] = $pconfig['lifetime'];
354
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
355
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
356
		$ph1ent['certref'] = $pconfig['certref'];
357
		$ph1ent['caref'] = $pconfig['caref'];
358
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
359
		$ph1ent['descr'] = $pconfig['descr'];
360
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
361

    
362
		if (isset($pconfig['reauth_enable']))
363
			$ph1ent['reauth_enable'] = true;
364
		if (isset($pconfig['rekey_enable']))
365
			$ph1ent['rekey_enable'] = true;
366

    
367
		if (isset($pconfig['dpd_enable'])) {
368
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
369
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
370
		}
371

    
372
		/* generate unique phase1 ikeid */
373
		if ($ph1ent['ikeid'] == 0)
374
			$ph1ent['ikeid'] = ipsec_ikeid_next();
375

    
376
		if (isset($p1index) && $a_phase1[$p1index])
377
			$a_phase1[$p1index] = $ph1ent;
378
		else
379
			$a_phase1[] = $ph1ent;
380

    
381
		write_config();
382
		mark_subsystem_dirty('ipsec');
383

    
384
		header("Location: vpn_ipsec.php");
385
		exit;
386
	}
387
}
388

    
389
if ($pconfig['mobile'])
390
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
391
else
392
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
393
$shortcut_section = "ipsec";
394

    
395

    
396
include("head.inc");
397

    
398
?>
399

    
400
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
401
<?php include("fbegin.inc"); ?>
402
<script type="text/javascript">
403
//<![CDATA[
404

    
405
function myidsel_change() {
406
	index = document.iform.myid_type.selectedIndex;
407
	value = document.iform.myid_type.options[index].value;
408
	if (value == 'myaddress')
409
			document.getElementById('myid_data').style.visibility = 'hidden';
410
	else
411
			document.getElementById('myid_data').style.visibility = 'visible';
412
}
413

    
414
function peeridsel_change() {
415
	index = document.iform.peerid_type.selectedIndex;
416
	value = document.iform.peerid_type.options[index].value;
417
	if (value == 'peeraddress')
418
			document.getElementById('peerid_data').style.visibility = 'hidden';
419
	else
420
			document.getElementById('peerid_data').style.visibility = 'visible';
421
}
422

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

    
427
	switch (value) {
428
	case 'eap-tls':
429
		document.getElementById('opt_psk').style.display = 'none';
430
		document.getElementById('opt_peerid').style.display = '';
431
		document.getElementById('opt_cert').style.display = '';
432
		document.getElementById('opt_ca').style.display = '';
433
		document.getElementById('opt_cert').disabled = false;
434
		document.getElementById('opt_ca').disabled = false;
435
		break;
436
	case 'hybrid_rsa_server':
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
	case 'xauth_rsa_server':
445
	case 'rsasig':
446
		document.getElementById('opt_psk').style.display = 'none';
447
		document.getElementById('opt_peerid').style.display = '';
448
		document.getElementById('opt_cert').style.display = '';
449
		document.getElementById('opt_ca').style.display = '';
450
		document.getElementById('opt_cert').disabled = false;
451
		document.getElementById('opt_ca').disabled = false;
452
		break;
453
<?php if ($pconfig['mobile']) { ?>
454
	case 'pre_shared_key':
455
		document.getElementById('opt_psk').style.display = 'none';
456
		document.getElementById('opt_peerid').style.display = 'none';
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
<?php } ?>
463
	default: /* psk modes*/
464
		document.getElementById('opt_psk').style.display = '';
465
		document.getElementById('opt_peerid').style.display = '';
466
		document.getElementById('opt_cert').style.display = 'none';
467
		document.getElementById('opt_ca').style.display = 'none';
468
		document.getElementById('opt_cert').disabled = true;
469
		document.getElementById('opt_ca').disabled = true;
470
		break;
471
	}
472
}
473

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

    
486
		$key_hi = $algodata['keysel']['hi'];
487
		$key_lo = $algodata['keysel']['lo'];
488
		$key_step = $algodata['keysel']['step'];
489

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

    
504
	if( bits )
505
		document.iform.ealgo_keylen.value = bits;
506
}
507

    
508
function dpdchkbox_change() {
509
	if( document.iform.dpd_enable.checked )
510
		document.getElementById('opt_dpd').style.display = '';
511
	else
512
		document.getElementById('opt_dpd').style.display = 'none';
513

    
514
	if (!document.iform.dpd_delay.value)
515
		document.iform.dpd_delay.value = "10";
516

    
517
	if (!document.iform.dpd_maxfail.value)
518
		document.iform.dpd_maxfail.value = "5";
519
}
520

    
521
//]]>
522
</script>
523

    
524
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
525

    
526
<?php
527
	if ($input_errors)
528
		print_input_errors($input_errors);
529
?>
530

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

    
599
								$carplist = get_configured_carp_interface_list();
600
								foreach ($carplist as $cif => $carpip)
601
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
602

    
603
								$aliaslist = get_configured_ip_aliases_list();
604
								foreach ($aliaslist as $aliasip => $aliasif)
605
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
606

    
607
								$grouplist = return_gateway_groups_array();
608
								foreach ($grouplist as $name => $group) {
609
									if($group[0]['vip'] <> "")
610
										$vipif = $group[0]['vip'];
611
									else
612
										$vipif = $group[0]['int'];
613
									$interfaces[$name] = "GW Group {$name}";
614
								}
615

    
616

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

    
629
					<?php if (!$pconfig['mobile']): ?>
630

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

    
640
					<?php endif; ?>
641

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

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