Project

General

Profile

Download (28.6 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

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

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

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

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

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

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

    
136
	/* input validation */
137

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

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

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

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

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

    
173
	/* My identity */
174

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

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

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

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

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

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

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

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

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

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

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

    
213
	/* Peer identity */
214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
296
		$ph1ent['descr'] = $pconfig['descr'];
297
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
298

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

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

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

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

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

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

    
339

    
340
include("head.inc");
341

    
342
?>
343

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

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

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

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

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

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

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

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

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

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

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

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

    
445
//-->
446
</script>
447

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

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

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

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

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

    
517
					<?php endif; ?>
518

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

    
759
<script lannguage="JavaScript">
760
<!--
761
<?php
762
	/* determine if we should init the key length */
763
	$keyset = '';
764
	if (isset($pconfig['ealgo']['keylen']))
765
		if (is_numeric($pconfig['ealgo']['keylen']))
766
			$keyset = $pconfig['ealgo']['keylen'];
767
?>
768
myidsel_change();
769
peeridsel_change();
770
methodsel_change();
771
ealgosel_change(<?=$keyset;?>);
772
dpdchkbox_change();
773
//-->
774
</script>
775
<?php include("fend.inc"); ?>
776
</body>
777
</html>
(207-207/222)