Project

General

Profile

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