Project

General

Profile

Download (34 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['protocol'] = $a_phase1[$p1index]['protocol'];
84
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
85
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
86
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
87
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
88
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
89
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
90
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
91
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
92
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
93
	$pconfig['generate_policy'] = $a_phase1[$p1index]['generate_policy'];
94
	$pconfig['proposal_check'] = $a_phase1[$p1index]['proposal_check'];
95

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

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

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

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

    
134
if (isset($_GET['dup']))
135
	unset($p1index);
136

    
137
if ($_POST) {
138
	unset($input_errors);
139
	$pconfig = $_POST;
140

    
141
	/* input validation */
142

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

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

    
174
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
175

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

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

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

    
195
	/* My identity */
196

    
197
	if ($pconfig['myid_type'] == "myaddress")
198
		$pconfig['myid_data'] = "";
199

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

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

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

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

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

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

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

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

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

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

    
235
	/* Peer identity */
236

    
237
	if ($pconfig['myid_type'] == "peeraddress")
238
		$pconfig['peerid_data'] = "";
239

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
		$ph1ent['mode'] = $pconfig['mode'];
303
		$ph1ent['protocol'] = $pconfig['protocol'];
304

    
305
		$ph1ent['myid_type'] = $pconfig['myid_type'];
306
		$ph1ent['myid_data'] = $pconfig['myid_data'];
307
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
308
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
309

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

    
324
		if (isset($pconfig['dpd_enable'])) {
325
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
326
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
327
		}
328

    
329
		/* generate unique phase1 ikeid */
330
		if ($ph1ent['ikeid'] == 0)
331
			$ph1ent['ikeid'] = ipsec_ikeid_next();
332

    
333
		if (isset($p1index) && $a_phase1[$p1index])
334
			$a_phase1[$p1index] = $ph1ent;
335
		else
336
			$a_phase1[] = $ph1ent;
337

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

    
352
		header("Location: vpn_ipsec.php");
353
		exit;
354
	}
355
}
356

    
357
if ($pconfig['mobile'])
358
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"), gettext("Mobile Client"));
359
else
360
	$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Edit Phase 1"));
361
$shortcut_section = "ipsec";
362

    
363

    
364
include("head.inc");
365

    
366
?>
367

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

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

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

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

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

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

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

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

    
464
	if( bits )
465
		document.iform.ealgo_keylen.value = bits;
466
}
467

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

    
474
	if (!document.iform.dpd_delay.value)
475
		document.iform.dpd_delay.value = "10";
476

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

    
481
//-->
482
</script>
483

    
484
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
485

    
486
<?php
487
	if ($input_errors)
488
		print_input_errors($input_errors);
489
?>
490

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

    
543
								$carplist = get_configured_carp_interface_list();
544
								foreach ($carplist as $cif => $carpip)
545
									$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
546

    
547
								$aliaslist = get_configured_ip_aliases_list();
548
								foreach ($aliaslist as $aliasip => $aliasif)
549
									$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
550

    
551
								$grouplist = return_gateway_groups_array();
552
								foreach ($grouplist as $name => $group) {
553
									if($group[0]['vip'] <> "")
554
										$vipif = $group[0]['vip'];
555
									else
556
										$vipif = $group[0]['int'];
557
									$interfaces[$name] = "GW Group {$name}";
558
								}
559

    
560

    
561
								foreach ($interfaces as $iface => $ifacename):
562
							?>
563
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
564
									<?=htmlspecialchars($ifacename);?>
565
								</option>
566
							<?php endforeach; ?>
567
							</select>
568
							<br>
569
							<span class="vexpl"><?=gettext("Select the interface for the local endpoint of this phase1 entry"); ?>.</span>
570
						</td>
571
					</tr>
572

    
573
					<?php if (!$pconfig['mobile']): ?>
574

    
575
					<tr>
576
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Remote gateway"); ?></td>
577
						<td width="78%" class="vtable">
578
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="28" value="<?=htmlspecialchars($pconfig['remotegw']);?>">
579
							<br>
580
							<?=gettext("Enter the public IP address or host name of the remote gateway"); ?>
581
						</td>
582
					</tr>
583

    
584
					<?php endif; ?>
585

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

    
875
<script lannguage="JavaScript">
876
<!--
877
<?php
878
	/* determine if we should init the key length */
879
	$keyset = '';
880
	if (isset($pconfig['ealgo']['keylen']))
881
		if (is_numeric($pconfig['ealgo']['keylen']))
882
			$keyset = $pconfig['ealgo']['keylen'];
883
?>
884
myidsel_change();
885
peeridsel_change();
886
methodsel_change();
887
ealgosel_change(<?=$keyset;?>);
888
dpdchkbox_change();
889
//-->
890
</script>
891
<?php include("fend.inc"); ?>
892
</body>
893
</html>
(237-237/251)