Project

General

Profile

Download (26.5 KB) Statistics
| Branch: | Tag: | Revision:
1 a93e56c5 Matthew Grooms
<?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 6b07c15a Matthew Grooms
##|+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 0f84b741 Scott Ullrich
require("functions.inc");
40 a93e56c5 Matthew Grooms
require("guiconfig.inc");
41
42
if (!is_array($config['ipsec']['phase1']))
43
	$config['ipsec']['phase1'] = array();
44
45 647c7c48 Seth Mos
if (!is_array($config['ipsec']['phase2']))
46
	$config['ipsec']['phase2'] = array();
47
48 a93e56c5 Matthew Grooms
$a_phase1 = &$config['ipsec']['phase1'];
49 647c7c48 Seth Mos
$a_phase2 = &$config['ipsec']['phase2'];
50 a93e56c5 Matthew Grooms
51
$p1index = $_GET['p1index'];
52
if (isset($_POST['p1index']))
53
	$p1index = $_POST['p1index'];
54
55
if (isset($_GET['dup'])) {
56
	$p1index = $_GET['dup'];
57
}
58
59
if (isset($p1index) && $a_phase1[$p1index])
60
{
61 99bbd213 Matthew Grooms
	// don't copy the ikeid on dup
62
	if (!isset($_GET['dup']))
63
		$pconfig['ikeid'] = $a_phase1[$p1index]['ikeid'];
64 7fc26246 Seth Mos
65 647c7c48 Seth Mos
	$old_ph1ent = $a_phase1[$p1index];
66 99bbd213 Matthew Grooms
67 a93e56c5 Matthew Grooms
	$pconfig['disabled'] = isset($a_phase1[$p1index]['disabled']);
68
69
	if ($a_phase1[$p1index]['interface'])
70
		$pconfig['interface'] = $a_phase1[$p1index]['interface'];
71
	else
72
		$pconfig['interface'] = "wan";
73
74
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_phase1[$p1index]['remote-subnet']);
75 3462a529 Matthew Grooms
76
	if (isset($a_phase1[$p1index]['mobile']))
77
		$pconfig['mobile'] = 'true';
78
	else
79
		$pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway'];
80
81 a93e56c5 Matthew Grooms
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
82
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
83
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
84
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
85
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
86
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
87
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
88
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
89
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
90
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
91 4e2af464 Matthew Grooms
92
	if (($pconfig['authentication_method'] == "pre_shared_key")||
93
		($pconfig['authentication_method'] == "xauth_psk_server")) {
94
		$pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key'];
95
	} else {
96 73fbece8 mgrooms
		$pconfig['certref'] = $a_phase1[$p1index]['certref'];
97 4e2af464 Matthew Grooms
	}
98 a93e56c5 Matthew Grooms
99
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
100
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
101 3462a529 Matthew Grooms
102
	if ($a_phase1[$p1index]['dpd_delay'] &&	$a_phase1[$p1index]['dpd_maxfail']) {
103
		$pconfig['dpd_enable'] = true;
104
		$pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay'];
105
		$pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail'];
106
	}
107 a93e56c5 Matthew Grooms
}
108
else
109
{
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 3462a529 Matthew Grooms
	$pconfig['dpd_enable'] = true;
124
125
	/* mobile client */
126
	if($_GET['mobile'])
127
		$pconfig['mobile']=true;
128 a93e56c5 Matthew Grooms
}
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 3462a529 Matthew Grooms
139
	$method = $pconfig['authentication_method'];
140
	if (($method == "pre_shared_key")||($method == "xauth_psk_server")) {
141
		$reqdfields = explode(" ", "pskey");
142
		$reqdfieldsn = explode(",", "Pre-Shared Key");
143 73fbece8 mgrooms
	} else {
144
		$reqdfields = explode(" ", "certref");
145
		$reqdfieldsn = explode(",", "My Certificate");
146 a93e56c5 Matthew Grooms
	}
147 3462a529 Matthew Grooms
	if (!$pconfig['mobile']) {
148
		$reqdfields[] = "remotegw";
149
		$reqdfieldsn[] = "Remote gateway";
150
	}
151 a93e56c5 Matthew Grooms
152 3462a529 Matthew Grooms
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
153 a93e56c5 Matthew Grooms
154 3462a529 Matthew Grooms
	if (($pconfig['lifetime'] && !is_numeric($pconfig['lifetime'])))
155 a93e56c5 Matthew Grooms
		$input_errors[] = "The P1 lifetime must be an integer.";
156
157 3462a529 Matthew Grooms
	if (($pconfig['remotegw'] && !is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))) 
158 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid remote gateway address or host name must be specified.";
159
160 3462a529 Matthew Grooms
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
161 a93e56c5 Matthew Grooms
		$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[] = "The remote gateway \"$tremotegw\" is already used by phase1 \"${ph1tmp['descr']}\".";
167
				}
168
			}
169
			$t++;
170
		}
171
	}
172
173
	/* My identity */
174
175 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "myaddress")
176
		$pconfig['myid_data'] = "";
177 a93e56c5 Matthew Grooms
178 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
179 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
180
181 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "keyid tag" and $pconfig['myid_data'] == "")
182 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a keyid tag for 'My Identifier'");
183
184 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "fqdn" and $pconfig['myid_data'] == "")
185 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a fully qualified domain name for 'My Identifier'");
186
187 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "user_fqdn" and $pconfig['myid_data'] == "")
188 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'My Identifier'");
189
190 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "dyn_dns" and $pconfig['myid_data'] == "")
191 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a dynamic domain name for 'My Identifier'");
192
193 3462a529 Matthew Grooms
	if ((($pconfig['myid_type'] == "address") && !is_ipaddr($pconfig['myid_data'])))
194 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
195
196 3462a529 Matthew Grooms
	if ((($pconfig['myid_type'] == "fqdn") && !is_domain($pconfig['myid_data'])))
197 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
198
199 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "fqdn")
200
		if (is_domain($pconfig['myid_data']) == false)
201 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid FQDN for 'My identifier' must be specified.";
202
203 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "user_fqdn") {
204
		$user_fqdn = explode("@",$pconfig['myid_data']);
205 a93e56c5 Matthew Grooms
		if (is_domain($user_fqdn[1]) == false)
206
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
207
	}
208
209 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "dyn_dns")
210
		if (is_domain($pconfig['myid_data']) == false)
211 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified.";
212
213
	/* Peer identity */
214
215 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "peeraddress")
216
		$pconfig['peerid_data'] = "";
217
218
	if ($pconfig['peerid_type'] == "address" and $pconfig['peerid_data'] == "")
219 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter an address for 'Peer Identifier'");
220
221 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "keyid tag" and $pconfig['peerid_data'] == "")
222 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a keyid tag for 'Peer Identifier'");
223
224 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "fqdn" and $pconfig['peerid_data'] == "")
225 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a fully qualified domain name for 'Peer Identifier'");
226
227 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "user_fqdn" and $pconfig['peerid_data'] == "")
228 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'Peer Identifier'");
229
230 3462a529 Matthew Grooms
	if ((($pconfig['peerid_type'] == "address") && !is_ipaddr($pconfig['peerid_data'])))
231 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid IP address for 'Peer identifier' must be specified.";
232
233 3462a529 Matthew Grooms
	if ((($pconfig['peerid_type'] == "fqdn") && !is_domain($pconfig['peerid_data'])))
234 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid domain name for 'Peer identifier' must be specified.";
235
236 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "fqdn")
237
		if (is_domain($pconfig['peerid_data']) == false)
238 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid FQDN for 'Peer identifier' must be specified.";
239
240 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "user_fqdn") {
241
		$user_fqdn = explode("@",$pconfig['peerid_data']);
242 a93e56c5 Matthew Grooms
		if (is_domain($user_fqdn[1]) == false)
243
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.";
244
	}
245
246 3462a529 Matthew Grooms
	if ($pconfig['dpd_enable']) {
247
		if (!is_numeric($pconfig['dpd_delay']))
248 a93e56c5 Matthew Grooms
			$input_errors[] = "A numeric value must be specified for DPD delay.";
249
250 3462a529 Matthew Grooms
		if (!is_numeric($pconfig['dpd_maxfail']))
251 a93e56c5 Matthew Grooms
			$input_errors[] = "A numeric value must be specified for DPD retries.";
252
	}
253
254
	/* build our encryption algorithms array */
255
	$pconfig['ealgo'] = array();
256
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
257 3462a529 Matthew Grooms
	if($pconfig['ealgo_keylen'])
258 a93e56c5 Matthew Grooms
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
259
260
	if (!$input_errors) {
261 3462a529 Matthew Grooms
		$ph1ent['ikeid'] = $pconfig['ikeid'];
262
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
263 a93e56c5 Matthew Grooms
		$ph1ent['interface'] = $pconfig['interface'];
264
		/* if the remote gateway changed and the interface is not WAN then remove route */
265
		/* the vpn_ipsec_configure() handles adding the route */
266 3462a529 Matthew Grooms
		if ($pconfig['interface'] <> "wan") {
267 7fc26246 Seth Mos
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
268
				mwexec("/sbin/route delete -host {$oldph1ent['remote-gateway']}");
269 a93e56c5 Matthew Grooms
			}
270
		}
271
272 3462a529 Matthew Grooms
		if ($pconfig['mobile'])
273
			$ph1ent['mobile'] = true;
274
		else
275
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
276
277
		$ph1ent['mode'] = $pconfig['mode'];
278
279
		$ph1ent['myid_type'] = $pconfig['myid_type'];
280
		$ph1ent['myid_data'] = $pconfig['myid_data'];
281
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
282
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
283 a93e56c5 Matthew Grooms
284
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
285 3462a529 Matthew Grooms
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
286
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
287
		$ph1ent['lifetime'] = $pconfig['lifetime'];
288
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
289
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
290 73fbece8 mgrooms
		$ph1ent['certref'] = $pconfig['certref'];
291 3462a529 Matthew Grooms
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
292
293
		$ph1ent['descr'] = $pconfig['descr'];
294
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
295
296
		if (isset($pconfig['dpd_enable'])) {
297
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
298
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
299
		}
300
301 a93e56c5 Matthew Grooms
		/* generate unique phase1 ikeid */
302 d799787e Matthew Grooms
		if ($ph1ent['ikeid'] == 0)
303
			$ph1ent['ikeid'] = ipsec_ikeid_next();
304 a93e56c5 Matthew Grooms
305
		if (isset($p1index) && $a_phase1[$p1index])
306
			$a_phase1[$p1index] = $ph1ent;
307
		else
308
			$a_phase1[] = $ph1ent;
309
310 647c7c48 Seth Mos
		/* now we need to find all phase2 entries for this host */
311
		if (is_array($a_phase2) && (count($a_phase2))) {
312
			foreach ($a_phase2 as $phase2) {
313
				if($phase2['ikeid'] == $ph1ent['ikeid']) {
314 7fc26246 Seth Mos
					log_error("Reload {$ph1ent['descr']} tunnel(s)");
315 647c7c48 Seth Mos
					$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
316
					$old_phase2 = $phase2;
317
					reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2);
318
				}
319
			}
320
		}
321 a93e56c5 Matthew Grooms
		write_config();
322 a368a026 Ermal Lu?i
		mark_subsystem_dirty('ipsec');
323 a93e56c5 Matthew Grooms
324
		header("Location: vpn_ipsec.php");
325
		exit;
326
	}
327
}
328
329 3462a529 Matthew Grooms
if ($pconfig['mobile'])
330
	$pgtitle = array("VPN","IPsec","Edit Phase 1", "Mobile Client");
331
else
332
	$pgtitle = array("VPN","IPsec","Edit Phase 1");
333
334 a93e56c5 Matthew Grooms
include("head.inc");
335
336
?>
337
338
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
339
<?php include("fbegin.inc"); ?>
340
<script language="JavaScript">
341
<!--
342 3462a529 Matthew Grooms
343
function myidsel_change() {
344
	index = document.iform.myid_type.selectedIndex;
345
	value = document.iform.myid_type.options[index].value;
346
	if (value == 'myaddress')
347 5a3b0d3b mgrooms
			document.getElementById('myid_data').style.visibility = 'hidden';
348 3462a529 Matthew Grooms
	else
349 5a3b0d3b mgrooms
			document.getElementById('myid_data').style.visibility = 'visible';
350 3462a529 Matthew Grooms
}
351
352
function peeridsel_change() {
353
	index = document.iform.peerid_type.selectedIndex;
354
	value = document.iform.peerid_type.options[index].value;
355
	if (value == 'peeraddress')
356 5a3b0d3b mgrooms
			document.getElementById('peerid_data').style.visibility = 'hidden';
357 3462a529 Matthew Grooms
	else
358 5a3b0d3b mgrooms
			document.getElementById('peerid_data').style.visibility = 'visible';
359 3462a529 Matthew Grooms
}
360
361 a93e56c5 Matthew Grooms
function methodsel_change() {
362 3462a529 Matthew Grooms
	index = document.iform.authentication_method.selectedIndex;
363
	value = document.iform.authentication_method.options[index].value;
364
365
	switch (value) {
366
		case 'hybrid_rsa_server':
367 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = 'none';
368 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = '';
369 3462a529 Matthew Grooms
			break;
370
		case 'xauth_rsa_server':
371
		case 'rsasig':
372 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = 'none';
373 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = '';
374 a93e56c5 Matthew Grooms
			break;
375 3462a529 Matthew Grooms
		default: /* psk modes*/
376 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = '';
377 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = 'none';
378 a93e56c5 Matthew Grooms
			break;
379
	}
380
}
381
382
/* PHP generated java script for variable length keys */
383
function ealgosel_change(bits) {
384
	switch (document.iform.ealgo.selectedIndex) {
385
<?php
386
  $i = 0;
387
  foreach ($p1_ealgos as $algo => $algodata) {
388
    if (is_array($algodata['keysel'])) {
389
      echo "		case {$i}:\n";
390
      echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
391
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
392
//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
393
394
      $key_hi = $algodata['keysel']['hi'];
395
      $key_lo = $algodata['keysel']['lo'];
396
      $key_step = $algodata['keysel']['step'];
397
398
      for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
399
        echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
400
      echo "			break;\n";
401
    } else {
402
      echo "		case {$i}:\n";
403
      echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
404
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
405
      echo "			break;\n";
406
    }
407
    $i++;
408
  }
409
?>
410
	}
411
412
	if( bits )
413
		document.iform.ealgo_keylen.value = bits;
414
}
415 3462a529 Matthew Grooms
416 a93e56c5 Matthew Grooms
function dpdchkbox_change() {
417 5a3b0d3b mgrooms
	if( document.iform.dpd_enable.checked )
418
		document.getElementById('opt_dpd').style.display = '';
419
	else
420
		document.getElementById('opt_dpd').style.display = 'none';
421 3462a529 Matthew Grooms
422
	if (!document.iform.dpd_delay.value)
423
		document.iform.dpd_delay.value = "10";
424
425
	if (!document.iform.dpd_maxfail.value)
426
		document.iform.dpd_maxfail.value = "5";
427 a93e56c5 Matthew Grooms
}
428 3462a529 Matthew Grooms
429 a93e56c5 Matthew Grooms
//-->
430
</script>
431 5a3b0d3b mgrooms
432
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
433
434
<?php
435
	if ($input_errors)
436
		print_input_errors($input_errors);
437
?>
438
439
<table width="100%" border="0" cellpadding="0" cellspacing="0">
440
	<tr class="tabnavtbl">
441
		<td id="tabnav">
442
			<?php
443
				$tab_array = array();
444
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
445
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
446
				display_top_tabs($tab_array);
447
			?>
448
		</td>
449
	</tr>
450
	<tr>
451
		<td id="mainarea">
452
			<div class="tabcont">
453
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
454
					<tr>
455
						<td colspan="2" valign="top" class="listtopic">General information</td>
456
					</tr>
457
					<tr>
458
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
459
						<td width="78%" class="vtable">
460
							<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
461
							<strong>Disable this phase1 entry</strong><br>
462
							<span class="vexpl">
463
								Set this option to disable this phase1 without
464
								removing it from the list.
465
							</span>
466
						</td>
467
					</tr>
468
					<tr>
469
						<td width="22%" valign="top" class="vncellreq">Interface</td>
470
						<td width="78%" class="vtable">
471
							<select name="interface" class="formselect">
472
							<?php 
473
								$interfaces = get_configured_interface_with_descr();
474 abcb2bed Ermal Lu?i
								$carplist = get_configured_carp_interface_list();
475
								foreach ($carplist as $cif => $carpip)
476
									$interfaces[$cif] = strtoupper($cif) . " ({$carpip})";
477 5a3b0d3b mgrooms
								foreach ($interfaces as $iface => $ifacename):
478
							?>
479
								<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
480
									<?=htmlspecialchars($ifacename);?>
481
								</option>
482
							<?php endforeach; ?>
483
							</select>
484
							<br>
485
							<span class="vexpl">Select the interface for the local endpoint of this phase1 entry.</span>
486
						</td>
487
					</tr>
488
489
					<?php if (!$pconfig['mobile']): ?>
490
491
					<tr>
492
						<td width="22%" valign="top" class="vncellreq">Remote gateway</td>
493
						<td width="78%" class="vtable">
494
							<?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="20" value="<?=$pconfig['remotegw'];?>">
495
							<br>
496
							Enter the public IP address or host name of the remote gateway
497
						</td>
498
					</tr>
499
500
					<?php endif; ?>
501
502
					<tr>
503
						<td width="22%" valign="top" class="vncell">Description</td>
504
						<td width="78%" class="vtable">
505
							<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
506
							<br>
507
							<span class="vexpl">
508
								You may enter a description here
509
								for your reference (not parsed).
510
							</span>
511
						</td>
512
					</tr>
513
					<tr>
514
						<td colspan="2" class="list" height="12"></td>
515
					</tr>
516
					<tr>
517
						<td colspan="2" valign="top" class="listtopic">
518
							Phase 1 proposal (Authentication)
519
						</td>
520
					</tr>
521
					<tr>
522
						<td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
523
						<td width="78%" class="vtable">
524
							<select name="mode" class="formselect">
525
							<?php
526
								$modes = explode(" ", "main aggressive");
527
								foreach ($modes as $mode):
528
							?>
529
								<option value="<?=$mode;?>" <?php if ($mode == $pconfig['mode']) echo "selected"; ?>>
530
									<?=htmlspecialchars($mode);?>
531
								</option>
532
							<?php endforeach; ?>
533
							</select> <br> <span class="vexpl">Aggressive is more flexible, but less secure.</span>
534
						</td>
535
					</tr>
536
					<tr>
537
						<td width="22%" valign="top" class="vncellreq">My identifier</td>
538
						<td width="78%" class="vtable">
539
							<select name="myid_type" class="formselect" onChange="myidsel_change()">
540
							<?php foreach ($my_identifier_list as $id_type => $id_params): ?>
541
								<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['myid_type']) echo "selected"; ?>>
542
									<?=htmlspecialchars($id_params['desc']);?>
543
								</option>
544
							<?php endforeach; ?>
545
							</select>
546
							<input name="myid_data" type="text" class="formfld unknown" id="myid_data" size="30" value="<?=$pconfig['myid_data'];?>">
547
						</td>
548
					</tr>
549
					<tr>
550
						<td width="22%" valign="top" class="vncellreq">Peer identifier</td>
551
						<td width="78%" class="vtable">
552
							<select name="peerid_type" class="formselect" onChange="peeridsel_change()">
553
							<?php
554
								foreach ($peer_identifier_list as $id_type => $id_params):
555
									if ($pconfig['mobile'] && !$id_params['mobile'])
556
										continue;
557
							?>
558
							<option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['peerid_type']) echo "selected"; ?>>
559
								<?=htmlspecialchars($id_params['desc']);?>
560
							</option>
561
							<?php endforeach; ?>
562
							</select>
563
							<input name="peerid_data" type="text" class="formfld unknown" id="peerid_data" size="30" value="<?=$pconfig['peerid_data'];?>">
564
						</td>
565
					</tr>
566
					<tr>
567
						<td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
568
						<td width="78%" class="vtable">
569
							<select name="ealgo" class="formselect" onChange="ealgosel_change()">
570
							<?php
571
								foreach ($p1_ealgos as $algo => $algodata):
572
									$selected = '';
573
									if ($algo == $pconfig['ealgo']['name'])
574
										$selected = ' selected';
575
							?>
576
								<option value="<?=$algo;?>"<?=$selected?>>
577
									<?=htmlspecialchars($algodata['name']);?>
578
								</option>
579
							<?php endforeach; ?>
580
							</select>
581
							<select name="ealgo_keylen" width="30" class="formselect">
582
							</select>
583
						</td>
584
					</tr>
585
					<tr>
586
						<td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
587
						<td width="78%" class="vtable">
588
							<select name="halgo" class="formselect">
589
							<?php foreach ($p1_halgos as $algo => $algoname): ?>
590
								<option value="<?=$algo;?>" <?php if ($algo == $pconfig['halgo']) echo "selected"; ?>>
591
									<?=htmlspecialchars($algoname);?>
592
								</option>
593
							<?php endforeach; ?>
594
							</select>
595
							<br>
596
							<span class="vexpl">
597
								Must match the setting chosen on the remote side.
598
							</span>
599
						</td>
600
					</tr>
601
					<tr>
602
						<td width="22%" valign="top" class="vncellreq">DH key group</td>
603
						<td width="78%" class="vtable">
604
							<select name="dhgroup" class="formselect">
605
							<?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
606
								<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['dhgroup']) echo "selected"; ?>>
607
									<?=htmlspecialchars($keygroup);?>
608
								</option>
609
							<?php endforeach; ?>
610
							</select>
611
							<br>
612
							<span class="vexpl">
613
								<em>1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit</em>
614
								<br>
615
								Must match the setting chosen on the remote side.
616
							</span>
617
						</td>
618
					</tr>
619
					<tr>
620
						<td width="22%" valign="top" class="vncell">Lifetime</td>
621
						<td width="78%" class="vtable">
622
							<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
623
							seconds
624
						</td>
625
					</tr>
626
					<tr>
627
						<td width="22%" valign="top" class="vncellreq">Authentication method</td>
628
						<td width="78%" class="vtable">
629
							<select name="authentication_method" class="formselect" onChange="methodsel_change()">
630
							<?php
631
								foreach ($p1_authentication_methods as $method_type => $method_params):
632
									if (!$pconfig['mobile'] && $method_params['mobile'])
633
										continue;
634
							?>
635
								<option value="<?=$method_type;?>" <?php if ($method_type == $pconfig['authentication_method']) echo "selected"; ?>>
636
									<?=htmlspecialchars($method_params['name']);?>
637
								</option>
638
							<?php endforeach; ?>
639
							</select>
640
							<br>
641 73fbece8 mgrooms
							<span class="vexpl">
642
								Must match the setting chosen on the remote side.
643
							</span>
644 5a3b0d3b mgrooms
						</td>
645
					</tr>
646
					<tr id="opt_psk">
647
						<td width="22%" valign="top" class="vncellreq">Pre-Shared Key</td>
648
						<td width="78%" class="vtable">
649
							<?=$mandfldhtml;?>
650
							<input name="pskey" type="text" class="formfld unknown" id="pskey" size="40" value="<?=htmlspecialchars($pconfig['pskey']);?>">
651 73fbece8 mgrooms
							<span class="vexpl">
652 5a3b0d3b mgrooms
							<br>
653 73fbece8 mgrooms
								Input your pre-shared key string.
654
							</span>
655 5a3b0d3b mgrooms
						</td>
656
					</tr>
657 73fbece8 mgrooms
					<tr id="opt_cert">
658
						<td width="22%" valign="top" class="vncellreq">My Certificate</td>
659 5a3b0d3b mgrooms
						<td width="78%" class="vtable">
660 73fbece8 mgrooms
							<select name='certref' class="formselect">
661
							<?php
662
								foreach ($config['system']['cert'] as $cert):
663
									$selected = "";
664
									if ($pconfig['certref'] == $cert['refid'])
665
										$selected = "selected";
666
							?>
667
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['name'];?></option>
668
							<?php endforeach; ?>
669
							</select>
670 5a3b0d3b mgrooms
							<br>
671 73fbece8 mgrooms
							<span class="vexpl">
672
								Select a certificate previously configured in the Certificate Manager.
673
							</span>
674 5a3b0d3b mgrooms
						</td>
675
					</tr>
676
					<tr>
677
						<td colspan="2" class="list" height="12"></td>
678
					</tr>
679
					<tr>
680
						<td colspan="2" valign="top" class="listtopic">Advanced Options</td>
681
					</tr>
682
					<tr>
683
						<td width="22%" valign="top" class="vncell">NAT Traversal</td>
684
						<td width="78%" class="vtable">
685
							<select name="nat_traversal" class="formselect">
686
								<option value="off" <?php if ($pconfig['nat_traversal'] == "off") echo "selected"; ?>>Disable</option>
687
								<option value="on" <?php if ($pconfig['nat_traversal'] == "on") echo "selected"; ?>>Enable</option>
688
								<option value="force" <?php if ($pconfig['nat_traversal'] == "force") echo "selected"; ?>>Force</option>
689
							</select>
690
							<br/>
691
							<span class="vexpl">
692
								Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed,
693
								which can help with clients that are behind restrictive firewalls.
694
							</span>
695
						</td>
696
					</tr>
697
					<tr>
698
						<td width="22%" valign="top" class="vncell">Dead Peer Detection</td>
699
						<td width="78%" class="vtable">
700
							<input name="dpd_enable" type="checkbox" id="dpd_enable" value="yes" <?php if (isset($pconfig['dpd_enable'])) echo "checked"; ?> onClick="dpdchkbox_change()">
701
							Enable DPD<br>
702
							<div id="opt_dpd">
703
								<br>
704
								<input name="dpd_delay" type="text" class="formfld unknown" id="dpd_delay" size="5" value="<?=$pconfig['dpd_delay'];?>">
705
								seconds<br>
706
								<span class="vexpl">
707
									Delay between requesting peer acknowledgement.
708
								</span><br>
709
								<br>
710
								<input name="dpd_maxfail" type="text" class="formfld unknown" id="dpd_maxfail" size="5" value="<?=$pconfig['dpd_maxfail'];?>">
711
								retries<br>
712
								<span class="vexpl">
713 73fbece8 mgrooms
									Number of consecutive failures allowed before disconnect.
714 5a3b0d3b mgrooms
								</span>
715
								<br>
716
							</div>
717
						</td>
718
					</tr>
719
					<tr>
720
						<td width="22%" valign="top">&nbsp;</td>
721
						<td width="78%">
722
							<?php if (isset($p1index) && $a_phase1[$p1index]): ?>
723
							<input name="p1index" type="hidden" value="<?=$p1index;?>">
724
							<?php endif; ?>
725
							<?php if ($pconfig['mobile']): ?>
726
							<input name="mobile" type="hidden" value="true">
727
							<?php endif; ?>
728
							<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
729
							<input name="Submit" type="submit" class="formbtn" value="Save">
730
						</td>
731
					</tr>
732
				</table>
733
			</div>
734
		</td>
735
	</tr>
736
</table>
737 a93e56c5 Matthew Grooms
</form>
738 5a3b0d3b mgrooms
739 a93e56c5 Matthew Grooms
<script lannguage="JavaScript">
740
<!--
741
<?php
742
	/* determine if we should init the key length */
743
	$keyset = '';
744
	if (isset($pconfig['ealgo']['keylen']))
745
		if (is_numeric($pconfig['ealgo']['keylen']))
746
			$keyset = $pconfig['ealgo']['keylen'];
747
?>
748 3462a529 Matthew Grooms
myidsel_change();
749
peeridsel_change();
750 a93e56c5 Matthew Grooms
methodsel_change();
751
ealgosel_change(<?=$keyset;?>);
752
dpdchkbox_change();
753
//-->
754
</script>
755
<?php include("fend.inc"); ?>
756 3462a529 Matthew Grooms
</body>
757
</html>