Project

General

Profile

Download (29.7 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['proposal_check'] = $a_phase1[$p1index]['proposal_check'];
93

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

    
101
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
102
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
103

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

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

    
130
if (isset($_GET['dup']))
131
	unset($p1index);
132

    
133
if ($_POST) {
134
	unset($input_errors);
135
	$pconfig = $_POST;
136

    
137
	/* input validation */
138

    
139
	$method = $pconfig['authentication_method'];
140
	// Only require PSK here for normal PSK tunnels (not mobile) or xauth.
141
	if ((($method == "pre_shared_key") && (!$pconfig['mobile']))||($method == "xauth_psk_server")) {
142
		$reqdfields = explode(" ", "pskey");
143
		$reqdfieldsn = array(gettext("Pre-Shared Key"));
144
	} else {
145
		$reqdfields = explode(" ", "certref");
146
		$reqdfieldsn = array(gettext("My Certificate"));
147
	}
148
	if (!$pconfig['mobile']) {
149
		$reqdfields[] = "remotegw";
150
		$reqdfieldsn[] = gettext("Remote gateway");
151
	}
152

    
153
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
154

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

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

    
161
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
162
		$t = 0;
163
		foreach ($a_phase1 as $ph1tmp) {
164
			if ($p1index <> $t) {
165
				$tremotegw = $pconfig['remotegw'];
166
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
167
					$input_errors[] = sprintf(gettext('The remote gateway "%1$s" is already used by phase1 "%2$s".'), $tremotegw, $ph1tmp['descr']);
168
				}
169
			}
170
			$t++;
171
		}
172
	}
173

    
174
	/* My identity */
175

    
176
	if ($pconfig['myid_type'] == "myaddress")
177
		$pconfig['myid_data'] = "";
178

    
179
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
180
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
181

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

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

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

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

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

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

    
200
	if ($pconfig['myid_type'] == "fqdn")
201
		if (is_domain($pconfig['myid_data']) == false)
202
			$input_errors[] = gettext("A valid FQDN for 'My identifier' must be specified.");
203

    
204
	if ($pconfig['myid_type'] == "user_fqdn") {
205
		$user_fqdn = explode("@",$pconfig['myid_data']);
206
		if (is_domain($user_fqdn[1]) == false)
207
			$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.");
208
	}
209

    
210
	if ($pconfig['myid_type'] == "dyn_dns")
211
		if (is_domain($pconfig['myid_data']) == false)
212
			$input_errors[] = gettext("A valid Dynamic DNS address for 'My identifier' must be specified.");
213

    
214
	/* Peer identity */
215

    
216
	if ($pconfig['myid_type'] == "peeraddress")
217
		$pconfig['peerid_data'] = "";
218

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

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

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

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

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

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

    
239
		if ($pconfig['peerid_type'] == "fqdn")
240
			if (is_domain($pconfig['peerid_data']) == false)
241
				$input_errors[] = gettext("A valid FQDN for 'Peer identifier' must be specified.");
242

    
243
		if ($pconfig['peerid_type'] == "user_fqdn") {
244
			$user_fqdn = explode("@",$pconfig['peerid_data']);
245
			if (is_domain($user_fqdn[1]) == false)
246
				$input_errors[] = gettext("A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.");
247
		}
248
	}
249

    
250
	if ($pconfig['dpd_enable']) {
251
		if (!is_numeric($pconfig['dpd_delay']))
252
			$input_errors[] = gettext("A numeric value must be specified for DPD delay.");
253

    
254
		if (!is_numeric($pconfig['dpd_maxfail']))
255
			$input_errors[] = gettext("A numeric value must be specified for DPD retries.");
256
	}
257

    
258
	/* build our encryption algorithms array */
259
	$pconfig['ealgo'] = array();
260
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
261
	if($pconfig['ealgo_keylen'])
262
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
263

    
264
	if (!$input_errors) {
265
		$ph1ent['ikeid'] = $pconfig['ikeid'];
266
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
267
		$ph1ent['interface'] = $pconfig['interface'];
268
		/* if the remote gateway changed and the interface is not WAN then remove route */
269
		/* the vpn_ipsec_configure() handles adding the route */
270
		if ($pconfig['interface'] <> "wan") {
271
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
272
				mwexec("/sbin/route delete -host {$oldph1ent['remote-gateway']}");
273
			}
274
		}
275

    
276
		if ($pconfig['mobile'])
277
			$ph1ent['mobile'] = true;
278
		else
279
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
280

    
281
		$ph1ent['mode'] = $pconfig['mode'];
282

    
283
		$ph1ent['myid_type'] = $pconfig['myid_type'];
284
		$ph1ent['myid_data'] = $pconfig['myid_data'];
285
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
286
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
287

    
288
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
289
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
290
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
291
		$ph1ent['lifetime'] = $pconfig['lifetime'];
292
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
293
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
294
		$ph1ent['certref'] = $pconfig['certref'];
295
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
296
		$ph1ent['proposal_check'] = $pconfig['proposal_check'];
297
		$ph1ent['descr'] = $pconfig['descr'];
298
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
299

    
300
		if (isset($pconfig['dpd_enable'])) {
301
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
302
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
303
		}
304

    
305
		/* generate unique phase1 ikeid */
306
		if ($ph1ent['ikeid'] == 0)
307
			$ph1ent['ikeid'] = ipsec_ikeid_next();
308

    
309
		if (isset($p1index) && $a_phase1[$p1index])
310
			$a_phase1[$p1index] = $ph1ent;
311
		else
312
			$a_phase1[] = $ph1ent;
313

    
314
		/* now we need to find all phase2 entries for this host */
315
		if (is_array($a_phase2) && (count($a_phase2))) {
316
			foreach ($a_phase2 as $phase2) {
317
				if($phase2['ikeid'] == $ph1ent['ikeid']) {
318
					log_error("Reload {$ph1ent['descr']} tunnel(s)");
319
					$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
320
					$old_phase2 = $phase2;
321
					reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2);
322
				}
323
			}
324
		}
325
		write_config();
326
		mark_subsystem_dirty('ipsec');
327

    
328
		header("Location: vpn_ipsec.php");
329
		exit;
330
	}
331
}
332

    
333
if ($pconfig['mobile'])
334
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
335
else
336
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
337
$statusurl = "diag_ipsec.php";
338
$logurl = "diag_logs_ipsec.php";
339

    
340

    
341
include("head.inc");
342

    
343
?>
344

    
345
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
346
<?php include("fbegin.inc"); ?>
347
<script language="JavaScript">
348
<!--
349

    
350
function myidsel_change() {
351
	index = document.iform.myid_type.selectedIndex;
352
	value = document.iform.myid_type.options[index].value;
353
	if (value == 'myaddress')
354
			document.getElementById('myid_data').style.visibility = 'hidden';
355
	else
356
			document.getElementById('myid_data').style.visibility = 'visible';
357
}
358

    
359
function peeridsel_change() {
360
	index = document.iform.peerid_type.selectedIndex;
361
	value = document.iform.peerid_type.options[index].value;
362
	if (value == 'peeraddress')
363
			document.getElementById('peerid_data').style.visibility = 'hidden';
364
	else
365
			document.getElementById('peerid_data').style.visibility = 'visible';
366
}
367

    
368
function methodsel_change() {
369
	index = document.iform.authentication_method.selectedIndex;
370
	value = document.iform.authentication_method.options[index].value;
371

    
372
	switch (value) {
373
		case 'hybrid_rsa_server':
374
			document.getElementById('opt_psk').style.display = 'none';
375
			document.getElementById('opt_peerid').style.display = '';
376
			document.getElementById('opt_cert').style.display = '';
377
			break;
378
		case 'xauth_rsa_server':
379
		case 'rsasig':
380
			document.getElementById('opt_psk').style.display = 'none';
381
			document.getElementById('opt_peerid').style.display = '';
382
			document.getElementById('opt_cert').style.display = '';
383
			break;
384
<?php if ($pconfig['mobile']) { ?>
385
		case 'pre_shared_key':
386
			document.getElementById('opt_psk').style.display = 'none';
387
			document.getElementById('opt_peerid').style.display = 'none';
388
			document.getElementById('opt_cert').style.display = 'none';
389
			break;
390
<?php } ?>
391
		default: /* psk modes*/
392
			document.getElementById('opt_psk').style.display = '';
393
			document.getElementById('opt_peerid').style.display = '';
394
			document.getElementById('opt_cert').style.display = 'none';
395
			break;
396
	}
397
}
398

    
399
/* PHP generated java script for variable length keys */
400
function ealgosel_change(bits) {
401
	switch (document.iform.ealgo.selectedIndex) {
402
<?php
403
  $i = 0;
404
  foreach ($p1_ealgos as $algo => $algodata) {
405
    if (is_array($algodata['keysel'])) {
406
      echo "		case {$i}:\n";
407
      echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
408
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
409
//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
410

    
411
      $key_hi = $algodata['keysel']['hi'];
412
      $key_lo = $algodata['keysel']['lo'];
413
      $key_step = $algodata['keysel']['step'];
414

    
415
      for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
416
        echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
417
      echo "			break;\n";
418
    } else {
419
      echo "		case {$i}:\n";
420
      echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
421
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
422
      echo "			break;\n";
423
    }
424
    $i++;
425
  }
426
?>
427
	}
428

    
429
	if( bits )
430
		document.iform.ealgo_keylen.value = bits;
431
}
432

    
433
function dpdchkbox_change() {
434
	if( document.iform.dpd_enable.checked )
435
		document.getElementById('opt_dpd').style.display = '';
436
	else
437
		document.getElementById('opt_dpd').style.display = 'none';
438

    
439
	if (!document.iform.dpd_delay.value)
440
		document.iform.dpd_delay.value = "10";
441

    
442
	if (!document.iform.dpd_maxfail.value)
443
		document.iform.dpd_maxfail.value = "5";
444
}
445

    
446
//-->
447
</script>
448

    
449
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
450

    
451
<?php
452
	if ($input_errors)
453
		print_input_errors($input_errors);
454
?>
455

    
456
<table width="100%" border="0" cellpadding="0" cellspacing="0">
457
	<tr class="tabnavtbl">
458
		<td id="tabnav">
459
			<?php
460
				$tab_array = array();
461
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
462
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
463
				$tab_array[2] = array(gettext("Pre-shared keys"), false, "vpn_ipsec_keys.php");
464
				display_top_tabs($tab_array);
465
			?>
466
		</td>
467
	</tr>
468
	<tr>
469
		<td id="mainarea">
470
			<div class="tabcont">
471
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
472
					<tr>
473
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
474
					</tr>
475
					<tr>
476
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
477
						<td width="78%" class="vtable">
478
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
479
							<strong><?=gettext("Disable this phase1 entry"); ?></strong><br>
480
							<span class="vexpl">
481
								<?=gettext("Set this option to disable this phase1 without " .
482
								"removing it from the list"); ?>.
483
							</span>
484
						</td>
485
					</tr>
486
					<tr>
487
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
488
						<td width="78%" class="vtable">
489
							<select name="interface" class="formselect">
490
							<?php 
491
								$interfaces = get_configured_interface_with_descr();
492
								$carplist = get_configured_carp_interface_list();
493
								foreach ($carplist as $cif => $carpip)
494
									$interfaces[$cif] = strtoupper($cif) . " ({$carpip})";
495
								foreach ($interfaces as $iface => $ifacename):
496
							?>
497
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
498
									<?=htmlspecialchars($ifacename);?>
499
								</option>
500
							<?php endforeach; ?>
501
							</select>
502
							<br>
503
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
504
						</td>
505
					</tr>
506

    
507
					<?php if (!$pconfig['mobile']): ?>
508

    
509
					<tr>
510
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
511
						<td width="78%" class="vtable">
512
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="20" value="<?=$pconfig['remotegw'];?>">
513
							<br>
514
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
515
						</td>
516
					</tr>
517

    
518
					<?php endif; ?>
519

    
520
					<tr>
521
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
522
						<td width="78%" class="vtable">
523
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
524
							<br>
525
							<span class="vexpl">
526
								<?=gettext("You may enter a description here " .
527
								"for your reference (not parsed)"); ?>.
528
							</span>
529
						</td>
530
					</tr>
531
					<tr>
532
						<td colspan="2" class="list" height="12"></td>
533
					</tr>
534
					<tr>
535
						<td colspan="2" valign="top" class="listtopic">
536
							<?=gettext("Phase 1 proposal (Authentication)"); ?>
537
						</td>
538
					</tr>
539
					<tr>
540
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication method"); ?></td>
541
						<td width="78%" class="vtable">
542
							<select name="authentication_method" class="formselect" onChange="methodsel_change()">
543
							<?php
544
								foreach ($p1_authentication_methods as $method_type => $method_params):
545
									if (!$pconfig['mobile'] && $method_params['mobile'])
546
										continue;
547
							?>
548
								<option value="<?=$method_type;?>" <?php if ($method_type == $pconfig['authentication_method']) echo "selected"; ?>>
549
									<?=htmlspecialchars($method_params['name']);?>
550
								</option>
551
							<?php endforeach; ?>
552
							</select>
553
							<br>
554
							<span class="vexpl">
555
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
556
							</span>
557
						</td>
558
					</tr>
559
					<tr>
560
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Negotiation mode"); ?></td>
561
						<td width="78%" class="vtable">
562
							<select name="mode" class="formselect">
563
							<?php
564
								$modes = array(gettext("main"),gettext("aggressive"));
565
								foreach ($modes as $mode):
566
							?>
567
								<option value="<?=$mode;?>" <?php if ($mode == $pconfig['mode']) echo "selected"; ?>>
568
									<?=htmlspecialchars($mode);?>
569
								</option>
570
							<?php endforeach; ?>
571
							</select> <br> <span class="vexpl"><?=gettext("Aggressive is more flexible, but less secure"); ?>.</span>
572
						</td>
573
					</tr>
574
					<tr>
575
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My identifier"); ?></td>
576
						<td width="78%" class="vtable">
577
							<select name="myid_type" class="formselect" onChange="myidsel_change()">
578
							<?php foreach ($my_identifier_list as $id_type => $id_params): ?>
579
								<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['myid_type']) echo "selected"; ?>>
580
									<?=htmlspecialchars($id_params['desc']);?>
581
								</option>
582
							<?php endforeach; ?>
583
							</select>
584
							<input name="myid_data" type="text" class="formfld unknown" id="myid_data" size="30" value="<?=$pconfig['myid_data'];?>">
585
						</td>
586
					</tr>
587
					<tr id="opt_peerid">
588
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer identifier"); ?></td>
589
						<td width="78%" class="vtable">
590
							<select name="peerid_type" class="formselect" onChange="peeridsel_change()">
591
							<?php
592
								foreach ($peer_identifier_list as $id_type => $id_params):
593
									if ($pconfig['mobile'] && !$id_params['mobile'])
594
										continue;
595
							?>
596
							<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['peerid_type']) echo "selected"; ?>>
597
								<?=htmlspecialchars($id_params['desc']);?>
598
							</option>
599
							<?php endforeach; ?>
600
							</select>
601
							<input name="peerid_data" type="text" class="formfld unknown" id="peerid_data" size="30" value="<?=$pconfig['peerid_data'];?>">
602
						<?php if ($pconfig['mobile']) { ?>
603
							<br/><br/><?=gettext("NOTE: This is known as the \"group\" setting on some VPN client implementations"); ?>.
604
						<?php } ?>
605
						</td>
606
					</tr>
607
					<tr id="opt_psk">
608
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Pre-Shared Key"); ?></td>
609
						<td width="78%" class="vtable">
610
							<?=$mandfldhtml;?>
611
							<input name="pskey" type="text" class="formfld unknown" id="pskey" size="40" value="<?=htmlspecialchars($pconfig['pskey']);?>">
612
							<span class="vexpl">
613
							<br>
614
								<?=gettext("Input your pre-shared key string"); ?>.
615
							</span>
616
						</td>
617
					</tr>
618
					<tr id="proposal_check">
619
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Proposal Checking"); ?></td>
620
						<td width="78%" class="vtable">
621
							<select name="proposal_check" class="formselect">
622
								<option value="" <?php if (empty($pconfig['proposal_check'])) echo "selected"; ?>>Default</option>
623
								<option value="obey" <?php if ($pconfig['proposal_check'] == "obey") echo "selected"; ?>>Obey</option>
624
								<option value="strict" <?php if ($pconfig['proposal_check'] == "strict") echo "selected"; ?>>Strict</option>
625
								<option value="claim" <?php if ($pconfig['proposal_check'] == "claim") echo "selected"; ?>>Claim</option>
626
								<option value="exact" <?php if ($pconfig['proposal_check'] == "exact") echo "selected"; ?>>Exact</option>
627
							</select>
628
							<br>
629
							<span class="vexpl">
630
								<?=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."); ?>
631
							</span>
632
						</td>
633
					</tr>
634
					<tr>
635
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithm"); ?></td>
636
						<td width="78%" class="vtable">
637
							<select name="ealgo" class="formselect" onChange="ealgosel_change()">
638
							<?php
639
								foreach ($p1_ealgos as $algo => $algodata):
640
									$selected = '';
641
									if ($algo == $pconfig['ealgo']['name'])
642
										$selected = ' selected';
643
							?>
644
								<option value="<?=$algo;?>"<?=$selected?>>
645
									<?=htmlspecialchars($algodata['name']);?>
646
								</option>
647
							<?php endforeach; ?>
648
							</select>
649
							<select name="ealgo_keylen" width="30" class="formselect">
650
							</select>
651
						</td>
652
					</tr>
653
					<tr>
654
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hash algorithm"); ?></td>
655
						<td width="78%" class="vtable">
656
							<select name="halgo" class="formselect">
657
							<?php foreach ($p1_halgos as $algo => $algoname): ?>
658
								<option value="<?=$algo;?>" <?php if ($algo == $pconfig['halgo']) echo "selected"; ?>>
659
									<?=htmlspecialchars($algoname);?>
660
								</option>
661
							<?php endforeach; ?>
662
							</select>
663
							<br>
664
							<span class="vexpl">
665
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
666
							</span>
667
						</td>
668
					</tr>
669
					<tr>
670
						<td width="22%" valign="top" class="vncellreq"><?=gettext("DH key group"); ?></td>
671
						<td width="78%" class="vtable">
672
							<select name="dhgroup" class="formselect">
673
							<?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
674
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['dhgroup']) echo "selected"; ?>>
675
									<?=htmlspecialchars($keygroup);?>
676
								</option>
677
							<?php endforeach; ?>
678
							</select>
679
							<br>
680
							<span class="vexpl">
681
								<em><?=gettext("1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit"); ?></em>
682
								<br>
683
								<?=gettext("Must match the setting chosen on the remote side"); ?>.
684
							</span>
685
						</td>
686
					</tr>
687
					<tr>
688
						<td width="22%" valign="top" class="vncell"><?=gettext("Lifetime"); ?></td>
689
						<td width="78%" class="vtable">
690
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
691
							<?=gettext("seconds"); ?>
692
						</td>
693
					</tr>
694
					<tr id="opt_cert">
695
						<td width="22%" valign="top" class="vncellreq"><?=gettext("My Certificate"); ?></td>
696
						<td width="78%" class="vtable">
697
							<select name='certref' class="formselect">
698
							<?php
699
								foreach ($config['system']['cert'] as $cert):
700
									$selected = "";
701
									if ($pconfig['certref'] == $cert['refid'])
702
										$selected = "selected";
703
							?>
704
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['name'];?></option>
705
							<?php endforeach; ?>
706
							</select>
707
							<br>
708
							<span class="vexpl">
709
								<?=gettext("Select a certificate previously configured in the Certificate Manager"); ?>.
710
							</span>
711
						</td>
712
					</tr>
713
					<tr>
714
						<td colspan="2" class="list" height="12"></td>
715
					</tr>
716
					<tr>
717
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced Options"); ?></td>
718
					</tr>
719
					<tr>
720
						<td width="22%" valign="top" class="vncell"><?=gettext("NAT Traversal"); ?></td>
721
						<td width="78%" class="vtable">
722
							<select name="nat_traversal" class="formselect">
723
								<option value="off" <?php if ($pconfig['nat_traversal'] == "off") echo "selected"; ?>><?=gettext("Disable"); ?></option>
724
								<option value="on" <?php if ($pconfig['nat_traversal'] == "on") echo "selected"; ?>><?=gettext("Enable"); ?></option>
725
								<option value="force" <?php if ($pconfig['nat_traversal'] == "force") echo "selected"; ?>><?=gettext("Force"); ?></option>
726
							</select>
727
							<br/>
728
							<span class="vexpl">
729
								<?=gettext("Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed, " .
730
								"which can help with clients that are behind restrictive firewalls"); ?>.
731
							</span>
732
						</td>
733
					</tr>
734
					<tr>
735
						<td width="22%" valign="top" class="vncell"><?=gettext("Dead Peer Detection"); ?></td>
736
						<td width="78%" class="vtable">
737
							<input name="dpd_enable" type="checkbox" id="dpd_enable" value="yes" <?php if (isset($pconfig['dpd_enable'])) echo "checked"; ?> onClick="dpdchkbox_change()">
738
							<?=gettext("Enable DPD"); ?><br>
739
							<div id="opt_dpd">
740
								<br>
741
								<input name="dpd_delay" type="text" class="formfld unknown" id="dpd_delay" size="5" value="<?=$pconfig['dpd_delay'];?>">
742
								<?=gettext("seconds"); ?><br>
743
								<span class="vexpl">
744
									<?=gettext("Delay between requesting peer acknowledgement"); ?>.
745
								</span><br>
746
								<br>
747
								<input name="dpd_maxfail" type="text" class="formfld unknown" id="dpd_maxfail" size="5" value="<?=$pconfig['dpd_maxfail'];?>">
748
								<?=gettext("retries"); ?><br>
749
								<span class="vexpl">
750
									<?=gettext("Number of consecutive failures allowed before disconnect"); ?>.
751
								</span>
752
								<br>
753
							</div>
754
						</td>
755
					</tr>
756
					<tr>
757
						<td width="22%" valign="top">&nbsp;</td>
758
						<td width="78%">
759
							<?php if (isset($p1index) && $a_phase1[$p1index]): ?>
760
							<input name="p1index" type="hidden" value="<?=$p1index;?>">
761
							<?php endif; ?>
762
							<?php if ($pconfig['mobile']): ?>
763
							<input name="mobile" type="hidden" value="true">
764
							<?php endif; ?>
765
							<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
766
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
767
						</td>
768
					</tr>
769
				</table>
770
			</div>
771
		</td>
772
	</tr>
773
</table>
774
</form>
775

    
776
<script lannguage="JavaScript">
777
<!--
778
<?php
779
	/* determine if we should init the key length */
780
	$keyset = '';
781
	if (isset($pconfig['ealgo']['keylen']))
782
		if (is_numeric($pconfig['ealgo']['keylen']))
783
			$keyset = $pconfig['ealgo']['keylen'];
784
?>
785
myidsel_change();
786
peeridsel_change();
787
methodsel_change();
788
ealgosel_change(<?=$keyset;?>);
789
dpdchkbox_change();
790
//-->
791
</script>
792
<?php include("fend.inc"); ?>
793
</body>
794
</html>
(207-207/222)