Project

General

Profile

Download (33 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_phase1.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2008 Shrew Soft Inc
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8
	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
$p1index = $_GET['p1index'];
54
if (isset($_POST['p1index']))
55
	$p1index = $_POST['p1index'];
56

    
57
if (isset($_GET['dup'])) {
58
	$p1index = $_GET['dup'];
59
}
60

    
61
if (isset($p1index) && $a_phase1[$p1index]) {
62
	// don't copy the ikeid on dup
63
	if (!isset($_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['myid_type'] = $a_phase1[$p1index]['myid_type'];
84
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
85
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
86
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
87
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
88
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
89
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
90
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
91
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
92
	$pconfig['generate_policy'] = $a_phase1[$p1index]['generate_policy'];
93
	$pconfig['proposal_check'] = $a_phase1[$p1index]['proposal_check'];
94

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

    
103
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
104
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
105

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

    
127
	/* mobile client */
128
	if($_GET['mobile'])
129
		$pconfig['mobile']=true;
130
}
131

    
132
if (isset($_GET['dup']))
133
	unset($p1index);
134

    
135
if ($_POST) {
136
	unset($input_errors);
137
	$pconfig = $_POST;
138

    
139
	/* input validation */
140

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

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

    
172
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
173

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

    
177
	if (($pconfig['remotegw'] && !is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))) 
178
		$input_errors[] = gettext("A valid remote gateway address or host name must be specified.");
179

    
180
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
181
		$t = 0;
182
		foreach ($a_phase1 as $ph1tmp) {
183
			if ($p1index <> $t) {
184
				$tremotegw = $pconfig['remotegw'];
185
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
186
					$input_errors[] = sprintf(gettext('The remote gateway "%1$s" is already used by phase1 "%2$s".'), $tremotegw, $ph1tmp['descr']);
187
				}
188
			}
189
			$t++;
190
		}
191
	}
192

    
193
	/* My identity */
194

    
195
	if ($pconfig['myid_type'] == "myaddress")
196
		$pconfig['myid_data'] = "";
197

    
198
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
199
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
200

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

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

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

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

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

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

    
219
	if ($pconfig['myid_type'] == "fqdn")
220
		if (is_domain($pconfig['myid_data']) == false)
221
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
222

    
223
	if ($pconfig['myid_type'] == "user_fqdn") {
224
		$user_fqdn = explode("@",$pconfig['myid_data']);
225
		if (is_domain($user_fqdn[1]) == false)
226
			$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.");
227
	}
228

    
229
	if ($pconfig['myid_type'] == "dyn_dns")
230
		if (is_domain($pconfig['myid_data']) == false)
231
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
232

    
233
	/* Peer identity */
234

    
235
	if ($pconfig['myid_type'] == "peeraddress")
236
		$pconfig['peerid_data'] = "";
237

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

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

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

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

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

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

    
258
		if ($pconfig['peerid_type'] == "fqdn")
259
			if (is_domain($pconfig['peerid_data']) == false)
260
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
261

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

    
269
	if ($pconfig['dpd_enable']) {
270
		if (!is_numeric($pconfig['dpd_delay']))
271
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
272

    
273
		if (!is_numeric($pconfig['dpd_maxfail']))
274
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
275
	}
276

    
277
	/* build our encryption algorithms array */
278
	$pconfig['ealgo'] = array();
279
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
280
	if($pconfig['ealgo_keylen'])
281
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
282

    
283
	if (!$input_errors) {
284
		$ph1ent['ikeid'] = $pconfig['ikeid'];
285
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
286
		$ph1ent['interface'] = $pconfig['interface'];
287
		/* if the remote gateway changed and the interface is not WAN then remove route */
288
		/* the vpn_ipsec_configure() handles adding the route */
289
		if ($pconfig['interface'] <> "wan") {
290
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
291
				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']}");
292
			}
293
		}
294

    
295
		if ($pconfig['mobile'])
296
			$ph1ent['mobile'] = true;
297
		else
298
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
299

    
300
		$ph1ent['mode'] = $pconfig['mode'];
301

    
302
		$ph1ent['myid_type'] = $pconfig['myid_type'];
303
		$ph1ent['myid_data'] = $pconfig['myid_data'];
304
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
305
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
306

    
307
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
308
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
309
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
310
		$ph1ent['lifetime'] = $pconfig['lifetime'];
311
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
312
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
313
		$ph1ent['certref'] = $pconfig['certref'];
314
		$ph1ent['caref'] = $pconfig['caref'];
315
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
316
		$ph1ent['generate_policy'] = $pconfig['generate_policy'];
317
		$ph1ent['proposal_check'] = $pconfig['proposal_check'];
318
		$ph1ent['descr'] = $pconfig['descr'];
319
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
320

    
321
		if (isset($pconfig['dpd_enable'])) {
322
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
323
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
324
		}
325

    
326
		/* generate unique phase1 ikeid */
327
		if ($ph1ent['ikeid'] == 0)
328
			$ph1ent['ikeid'] = ipsec_ikeid_next();
329

    
330
		if (isset($p1index) && $a_phase1[$p1index])
331
			$a_phase1[$p1index] = $ph1ent;
332
		else
333
			$a_phase1[] = $ph1ent;
334

    
335
		/* now we need to find all phase2 entries for this host */
336
		if (is_array($a_phase2) && (count($a_phase2))) {
337
			foreach ($a_phase2 as $phase2) {
338
				if($phase2['ikeid'] == $ph1ent['ikeid']) {
339
					log_error("Reload {$ph1ent['descr']} tunnel(s)");
340
					$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
341
					$old_phase2 = $phase2;
342
					reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2);
343
				}
344
			}
345
		}
346
		write_config();
347
		mark_subsystem_dirty('ipsec');
348

    
349
		header("Location: vpn_ipsec.php");
350
		exit;
351
	}
352
}
353

    
354
if ($pconfig['mobile'])
355
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
356
else
357
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
358
$statusurl = "diag_ipsec.php";
359
$logurl = "diag_logs_ipsec.php";
360

    
361

    
362
include("head.inc");
363

    
364
?>
365

    
366
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
367
<?php include("fbegin.inc"); ?>
368
<script language="JavaScript">
369
<!--
370

    
371
function myidsel_change() {
372
	index = document.iform.myid_type.selectedIndex;
373
	value = document.iform.myid_type.options[index].value;
374
	if (value == 'myaddress')
375
			document.getElementById('myid_data').style.visibility = 'hidden';
376
	else
377
			document.getElementById('myid_data').style.visibility = 'visible';
378
}
379

    
380
function peeridsel_change() {
381
	index = document.iform.peerid_type.selectedIndex;
382
	value = document.iform.peerid_type.options[index].value;
383
	if (value == 'peeraddress')
384
			document.getElementById('peerid_data').style.visibility = 'hidden';
385
	else
386
			document.getElementById('peerid_data').style.visibility = 'visible';
387
}
388

    
389
function methodsel_change() {
390
	index = document.iform.authentication_method.selectedIndex;
391
	value = document.iform.authentication_method.options[index].value;
392

    
393
	switch (value) {
394
		case 'hybrid_rsa_server':
395
			document.getElementById('opt_psk').style.display = 'none';
396
			document.getElementById('opt_peerid').style.display = '';
397
			document.getElementById('opt_cert').style.display = '';
398
			document.getElementById('opt_ca').style.display = '';
399
			document.getElementById('opt_cert').disabled = false;
400
			document.getElementById('opt_ca').disabled = false;
401
			break;
402
		case 'xauth_rsa_server':
403
		case 'rsasig':
404
			document.getElementById('opt_psk').style.display = 'none';
405
			document.getElementById('opt_peerid').style.display = '';
406
			document.getElementById('opt_cert').style.display = '';
407
			document.getElementById('opt_ca').style.display = '';
408
			document.getElementById('opt_cert').disabled = false;
409
			document.getElementById('opt_ca').disabled = false;
410
			break;
411
<?php if ($pconfig['mobile']) { ?>
412
		case 'pre_shared_key':
413
			document.getElementById('opt_psk').style.display = 'none';
414
			document.getElementById('opt_peerid').style.display = 'none';
415
			document.getElementById('opt_cert').style.display = 'none';
416
			document.getElementById('opt_ca').style.display = 'none';
417
			document.getElementById('opt_cert').disabled = true;
418
			document.getElementById('opt_ca').disabled = true;
419
			break;
420
<?php } ?>
421
		default: /* psk modes*/
422
			document.getElementById('opt_psk').style.display = '';
423
			document.getElementById('opt_peerid').style.display = '';
424
			document.getElementById('opt_cert').style.display = 'none';
425
			document.getElementById('opt_ca').style.display = 'none';
426
			document.getElementById('opt_cert').disabled = true;
427
			document.getElementById('opt_ca').disabled = true;
428
			break;
429
	}
430
}
431

    
432
/* PHP generated java script for variable length keys */
433
function ealgosel_change(bits) {
434
	switch (document.iform.ealgo.selectedIndex) {
435
<?php
436
  $i = 0;
437
  foreach ($p1_ealgos as $algo => $algodata) {
438
    if (is_array($algodata['keysel'])) {
439
      echo "		case {$i}:\n";
440
      echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
441
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
442
//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
443

    
444
      $key_hi = $algodata['keysel']['hi'];
445
      $key_lo = $algodata['keysel']['lo'];
446
      $key_step = $algodata['keysel']['step'];
447

    
448
      for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
449
        echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
450
      echo "			break;\n";
451
    } else {
452
      echo "		case {$i}:\n";
453
      echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
454
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
455
      echo "			break;\n";
456
    }
457
    $i++;
458
  }
459
?>
460
	}
461

    
462
	if( bits )
463
		document.iform.ealgo_keylen.value = bits;
464
}
465

    
466
function dpdchkbox_change() {
467
	if( document.iform.dpd_enable.checked )
468
		document.getElementById('opt_dpd').style.display = '';
469
	else
470
		document.getElementById('opt_dpd').style.display = 'none';
471

    
472
	if (!document.iform.dpd_delay.value)
473
		document.iform.dpd_delay.value = "10";
474

    
475
	if (!document.iform.dpd_maxfail.value)
476
		document.iform.dpd_maxfail.value = "5";
477
}
478

    
479
//-->
480
</script>
481

    
482
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
483

    
484
<?php
485
	if ($input_errors)
486
		print_input_errors($input_errors);
487
?>
488

    
489
<table width="100%" border="0" cellpadding="0" cellspacing="0">
490
	<tr class="tabnavtbl">
491
		<td id="tabnav">
492
			<?php
493
				$tab_array = array();
494
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
495
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
496
				$tab_array[2] = array(gettext("Pre-shared keys"), false, "vpn_ipsec_keys.php");
497
				display_top_tabs($tab_array);
498
			?>
499
		</td>
500
	</tr>
501
	<tr>
502
		<td id="mainarea">
503
			<div class="tabcont">
504
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
505
					<tr>
506
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
507
					</tr>
508
					<tr>
509
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
510
						<td width="78%" class="vtable">
511
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
512
							<strong><?=gettext("Disable this phase1 entry"); ?></strong><br>
513
							<span class="vexpl">
514
								<?=gettext("Set this option to disable this phase1 without " .
515
								"removing it from the list"); ?>.
516
							</span>
517
						</td>
518
					</tr>
519
					<tr>
520
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
521
						<td width="78%" class="vtable">
522
							<select name="interface" class="formselect">
523
							<?php 
524
								$interfaces = get_configured_interface_with_descr();
525
								$carplist = get_configured_carp_interface_list();
526
								foreach ($carplist as $cif => $carpip)
527
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
528
								$aliaslist = get_configured_ip_aliases_list();
529
								foreach ($aliaslist as $aliasip => $aliasif)
530
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
531
								foreach ($interfaces as $iface => $ifacename):
532
							?>
533
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
534
									<?=htmlspecialchars($ifacename);?>
535
								</option>
536
							<?php endforeach; ?>
537
							</select>
538
							<br>
539
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
540
						</td>
541
					</tr>
542

    
543
					<?php if (!$pconfig['mobile']): ?>
544

    
545
					<tr>
546
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
547
						<td width="78%" class="vtable">
548
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="20" value="<?=htmlspecialchars($pconfig['remotegw']);?>">
549
							<br>
550
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
551
						</td>
552
					</tr>
553

    
554
					<?php endif; ?>
555

    
556
					<tr>
557
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
558
						<td width="78%" class="vtable">
559
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
560
							<br>
561
							<span class="vexpl">
562
								<?=gettext("You may enter a description here " .
563
								"for your reference (not parsed)"); ?>.
564
							</span>
565
						</td>
566
					</tr>
567
					<tr>
568
						<td colspan="2" class="list" height="12"></td>
569
					</tr>
570
					<tr>
571
						<td colspan="2" valign="top" class="listtopic">
572
							<?=gettext("Phase 1 proposal (Authentication)"); ?>
573
						</td>
574
					</tr>
575
					<tr>
576
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication method"); ?></td>
577
						<td width="78%" class="vtable">
578
							<select name="authentication_method" class="formselect" onChange="methodsel_change()">
579
							<?php
580
								foreach ($p1_authentication_methods as $method_type => $method_params):
581
									if (!$pconfig['mobile'] && $method_params['mobile'])
582
										continue;
583
							?>
584
								<option value="<?=$method_type;?>" <?php if ($method_type == $pconfig['authentication_method']) echo "selected"; ?>>
585
									<?=htmlspecialchars($method_params['name']);?>
586
								</option>
587
							<?php endforeach; ?>
588
							</select>
589
							<br>
590
							<span class="vexpl">
591
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
592
							</span>
593
						</td>
594
					</tr>
595
					<tr>
596
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Negotiation mode"); ?></td>
597
						<td width="78%" class="vtable">
598
							<select name="mode" class="formselect">
599
							<?php
600
								$modes = array(gettext("main"),gettext("aggressive"));
601
								foreach ($modes as $mode):
602
							?>
603
								<option value="<?=$mode;?>" <?php if ($mode == $pconfig['mode']) echo "selected"; ?>>
604
									<?=htmlspecialchars($mode);?>
605
								</option>
606
							<?php endforeach; ?>
607
							</select> <br> <span class="vexpl"><?=gettext("Aggressive is more flexible, but less secure"); ?>.</span>
608
						</td>
609
					</tr>
610
					<tr>
611
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My identifier"); ?></td>
612
						<td width="78%" class="vtable">
613
							<select name="myid_type" class="formselect" onChange="myidsel_change()">
614
							<?php foreach ($my_identifier_list as $id_type => $id_params): ?>
615
								<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['myid_type']) echo "selected"; ?>>
616
									<?=htmlspecialchars($id_params['desc']);?>
617
								</option>
618
							<?php endforeach; ?>
619
							</select>
620
							<input name="myid_data" type="text" class="formfld unknown" id="myid_data" size="30" value="<?=htmlspecialchars($pconfig['myid_data']);?>">
621
						</td>
622
					</tr>
623
					<tr id="opt_peerid">
624
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer identifier"); ?></td>
625
						<td width="78%" class="vtable">
626
							<select name="peerid_type" class="formselect" onChange="peeridsel_change()">
627
							<?php
628
								foreach ($peer_identifier_list as $id_type => $id_params):
629
									if ($pconfig['mobile'] && !$id_params['mobile'])
630
										continue;
631
							?>
632
							<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['peerid_type']) echo "selected"; ?>>
633
								<?=htmlspecialchars($id_params['desc']);?>
634
							</option>
635
							<?php endforeach; ?>
636
							</select>
637
							<input name="peerid_data" type="text" class="formfld unknown" id="peerid_data" size="30" value="<?=htmlspecialchars($pconfig['peerid_data']);?>">
638
						<?php if ($pconfig['mobile']) { ?>
639
							<br/><br/><?=gettext("NOTE: This is known as the \"group\" setting on some VPN client implementations"); ?>.
640
						<?php } ?>
641
						</td>
642
					</tr>
643
					<tr id="opt_psk">
644
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Pre-Shared Key"); ?></td>
645
						<td width="78%" class="vtable">
646
							<?=$mandfldhtml;?>
647
							<input name="pskey" type="text" class="formfld unknown" id="pskey" size="40" value="<?=htmlspecialchars($pconfig['pskey']);?>">
648
							<span class="vexpl">
649
							<br>
650
								<?=gettext("Input your pre-shared key string"); ?>.
651
							</span>
652
						</td>
653
					</tr>
654
					<tr id="generate_policy">
655
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Policy Generation"); ?></td>
656
						<td width="78%" class="vtable">
657
							<select name="generate_policy" class="formselect">
658
								<option value="" <?php if (empty($pconfig['generate_policy'])) echo "selected"; ?>>Default</option>
659
								<option value="on" <?php if ($pconfig['generate_policy'] == "on") echo "selected"; ?>>On</option>
660
								<option value="off" <?php if ($pconfig['generate_policy'] == "off") echo "selected"; ?>>Off</option>
661
								<option value="require" <?php if ($pconfig['generate_policy'] == "require") echo "selected"; ?>>Require</option>
662
								<option value="unique" <?php if ($pconfig['generate_policy'] == "unique") echo "selected"; ?>>Unique</option>
663
							</select>
664
							<br>
665
							<span class="vexpl">
666
								<?=gettext("When working as a responder (as with mobile clients), this controls how policies are generated based on SA proposals."); ?>
667
							</span>
668
						</td>
669
					</tr>
670
					<tr id="proposal_check">
671
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Proposal Checking"); ?></td>
672
						<td width="78%" class="vtable">
673
							<select name="proposal_check" class="formselect">
674
								<option value="" <?php if (empty($pconfig['proposal_check'])) echo "selected"; ?>>Default</option>
675
								<option value="obey" <?php if ($pconfig['proposal_check'] == "obey") echo "selected"; ?>>Obey</option>
676
								<option value="strict" <?php if ($pconfig['proposal_check'] == "strict") echo "selected"; ?>>Strict</option>
677
								<option value="claim" <?php if ($pconfig['proposal_check'] == "claim") echo "selected"; ?>>Claim</option>
678
								<option value="exact" <?php if ($pconfig['proposal_check'] == "exact") echo "selected"; ?>>Exact</option>
679
							</select>
680
							<br>
681
							<span class="vexpl">
682
								<?=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."); ?>
683
							</span>
684
						</td>
685
					</tr>
686
					<tr>
687
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithm"); ?></td>
688
						<td width="78%" class="vtable">
689
							<select name="ealgo" class="formselect" onChange="ealgosel_change()">
690
							<?php
691
								foreach ($p1_ealgos as $algo => $algodata):
692
									$selected = '';
693
									if ($algo == $pconfig['ealgo']['name'])
694
										$selected = ' selected';
695
							?>
696
								<option value="<?=$algo;?>"<?=$selected?>>
697
									<?=htmlspecialchars($algodata['name']);?>
698
								</option>
699
							<?php endforeach; ?>
700
							</select>
701
							<select name="ealgo_keylen" width="30" class="formselect">
702
							</select>
703
						</td>
704
					</tr>
705
					<tr>
706
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithm"); ?></td>
707
						<td width="78%" class="vtable">
708
							<select name="halgo" class="formselect">
709
							<?php foreach ($p1_halgos as $algo => $algoname): ?>
710
								<option value="<?=$algo;?>" <?php if ($algo == $pconfig['halgo']) echo "selected"; ?>>
711
									<?=htmlspecialchars($algoname);?>
712
								</option>
713
							<?php endforeach; ?>
714
							</select>
715
							<br>
716
							<span class="vexpl">
717
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
718
							</span>
719
						</td>
720
					</tr>
721
					<tr>
722
						<td width="22%" valign="top" class="vncellreq"><?=gettext("DH key group"); ?></td>
723
						<td width="78%" class="vtable">
724
							<select name="dhgroup" class="formselect">
725
							<?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
726
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['dhgroup']) echo "selected"; ?>>
727
									<?=htmlspecialchars($keygroup);?>
728
								</option>
729
							<?php endforeach; ?>
730
							</select>
731
							<br>
732
							<span class="vexpl">
733
								<em><?=gettext("1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit"); ?></em>
734
								<br>
735
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
736
							</span>
737
						</td>
738
					</tr>
739
					<tr>
740
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
741
						<td width="78%" class="vtable">
742
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=htmlspecialchars($pconfig['lifetime']);?>">
743
							<?=gettext("seconds"); ?>
744
						</td>
745
					</tr>
746
					<tr id="opt_cert">
747
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My Certificate"); ?></td>
748
						<td width="78%" class="vtable">
749
							<select name='certref' class="formselect">
750
							<?php
751
								foreach ($config['cert'] as $cert):
752
									$selected = "";
753
									if ($pconfig['certref'] == $cert['refid'])
754
										$selected = "selected";
755
							?>
756
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'];?></option>
757
							<?php endforeach; ?>
758
							</select>
759
							<br>
760
							<span class="vexpl">
761
								<?=gettext("Select a certificate previously configured in the Certificate Manager"); ?>.
762
							</span>
763
						</td>
764
					</tr>
765
					<tr id="opt_ca">
766
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My Certificate Authority"); ?></td>
767
						<td width="78%" class="vtable">
768
							<select name='caref' class="formselect">
769
							<?php
770
								foreach ($config['ca'] as $ca):
771
									$selected = "";
772
									if ($pconfig['caref'] == $ca['refid'])
773
										$selected = "selected";
774
							?>
775
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
776
							<?php endforeach; ?>
777
							</select>
778
							<br>
779
							<span class="vexpl">
780
								<?=gettext("Select a certificate authority previously configured in the Certificate Manager"); ?>.
781
							</span>
782
						</td>
783
					</tr>
784
					<tr>
785
						<td colspan="2" class="list" height="12"></td>
786
					</tr>
787
					<tr>
788
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
789
					</tr>
790
					<tr>
791
						<td width="22%" valign="top" class="vncell"><?=gettext("NAT Traversal"); ?></td>
792
						<td width="78%" class="vtable">
793
							<select name="nat_traversal" class="formselect">
794
								<option value="off" <?php if ($pconfig['nat_traversal'] == "off") echo "selected"; ?>><?=gettext("Disable"); ?></option>
795
								<option value="on" <?php if ($pconfig['nat_traversal'] == "on") echo "selected"; ?>><?=gettext("Enable"); ?></option>
796
								<option value="force" <?php if ($pconfig['nat_traversal'] == "force") echo "selected"; ?>><?=gettext("Force"); ?></option>
797
							</select>
798
							<br/>
799
							<span class="vexpl">
800
								<?=gettext("Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed, " .
801
								"which can help with clients that are behind restrictive firewalls"); ?>.
802
							</span>
803
						</td>
804
					</tr>
805
					<tr>
806
						<td width="22%" valign="top" class="vncell"><?=gettext("Dead Peer Detection"); ?></td>
807
						<td width="78%" class="vtable">
808
							<input name="dpd_enable" type="checkbox" id="dpd_enable" value="yes" <?php if (isset($pconfig['dpd_enable'])) echo "checked"; ?> onClick="dpdchkbox_change()">
809
							<?=gettext("Enable DPD"); ?><br>
810
							<div id="opt_dpd">
811
								<br>
812
								<input name="dpd_delay" type="text" class="formfld unknown" id="dpd_delay" size="5" value="<?=htmlspecialchars($pconfig['dpd_delay']);?>">
813
								<?=gettext("seconds"); ?><br>
814
								<span class="vexpl">
815
									<?=gettext("Delay between requesting peer acknowledgement"); ?>.
816
								</span><br>
817
								<br>
818
								<input name="dpd_maxfail" type="text" class="formfld unknown" id="dpd_maxfail" size="5" value="<?=htmlspecialchars($pconfig['dpd_maxfail']);?>">
819
								<?=gettext("retries"); ?><br>
820
								<span class="vexpl">
821
									<?=gettext("Number of consecutive failures allowed before disconnect"); ?>.
822
								</span>
823
								<br>
824
							</div>
825
						</td>
826
					</tr>
827
					<tr>
828
						<td width="22%" valign="top">&nbsp;</td>
829
						<td width="78%">
830
							<?php if (isset($p1index) && $a_phase1[$p1index]): ?>
831
							<input name="p1index" type="hidden" value="<?=$p1index;?>">
832
							<?php endif; ?>
833
							<?php if ($pconfig['mobile']): ?>
834
							<input name="mobile" type="hidden" value="true">
835
							<?php endif; ?>
836
							<input name="ikeid" type="hidden" value="<?=htmlspecialchars($pconfig['ikeid']);?>">
837
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
838
						</td>
839
					</tr>
840
				</table>
841
			</div>
842
		</td>
843
	</tr>
844
</table>
845
</form>
846

    
847
<script lannguage="JavaScript">
848
<!--
849
<?php
850
	/* determine if we should init the key length */
851
	$keyset = '';
852
	if (isset($pconfig['ealgo']['keylen']))
853
		if (is_numeric($pconfig['ealgo']['keylen']))
854
			$keyset = $pconfig['ealgo']['keylen'];
855
?>
856
myidsel_change();
857
peeridsel_change();
858
methodsel_change();
859
ealgosel_change(<?=$keyset;?>);
860
dpdchkbox_change();
861
//-->
862
</script>
863
<?php include("fend.inc"); ?>
864
</body>
865
</html>
(212-212/226)