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 fad728ab sullrich
if (isset($p1index) && $a_phase1[$p1index]) {
62 99bbd213 Matthew Grooms
	// don't copy the ikeid on dup
63
	if (!isset($_GET['dup']))
64
		$pconfig['ikeid'] = $a_phase1[$p1index]['ikeid'];
65 7fc26246 Seth Mos
66 647c7c48 Seth Mos
	$old_ph1ent = $a_phase1[$p1index];
67 99bbd213 Matthew Grooms
68 a93e56c5 Matthew Grooms
	$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 3462a529 Matthew Grooms
77
	if (isset($a_phase1[$p1index]['mobile']))
78
		$pconfig['mobile'] = 'true';
79
	else
80
		$pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway'];
81
82 a93e56c5 Matthew Grooms
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
83
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
84
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
85
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
86
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
87
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
88
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
89
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
90
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
91
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
92 4e2af464 Matthew Grooms
93 fad728ab sullrich
	if (($pconfig['authentication_method'] == "pre_shared_key") || 
94 4e2af464 Matthew Grooms
		($pconfig['authentication_method'] == "xauth_psk_server")) {
95
		$pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key'];
96
	} else {
97 73fbece8 mgrooms
		$pconfig['certref'] = $a_phase1[$p1index]['certref'];
98 4e2af464 Matthew Grooms
	}
99 a93e56c5 Matthew Grooms
100
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
101
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
102 3462a529 Matthew Grooms
103
	if ($a_phase1[$p1index]['dpd_delay'] &&	$a_phase1[$p1index]['dpd_maxfail']) {
104
		$pconfig['dpd_enable'] = true;
105
		$pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay'];
106
		$pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail'];
107
	}
108 fad728ab sullrich
} else {
109 a93e56c5 Matthew Grooms
	/* defaults */
110
	$pconfig['interface'] = "wan";
111
	if($config['interfaces']['lan']) 
112
		$pconfig['localnet'] = "lan";
113
	$pconfig['mode'] = "aggressive";
114
	$pconfig['myid_type'] = "myaddress";
115
	$pconfig['peerid_type'] = "peeraddress";
116
	$pconfig['authentication_method'] = "pre_shared_key";
117
	$pconfig['ealgo'] = array( name => "3des" );
118
	$pconfig['halgo'] = "sha1";
119
	$pconfig['dhgroup'] = "2";
120
	$pconfig['lifetime'] = "28800";
121
	$pconfig['nat_traversal'] = "on";
122 3462a529 Matthew Grooms
	$pconfig['dpd_enable'] = true;
123
124
	/* mobile client */
125
	if($_GET['mobile'])
126
		$pconfig['mobile']=true;
127 a93e56c5 Matthew Grooms
}
128
129
if (isset($_GET['dup']))
130
	unset($p1index);
131
132
if ($_POST) {
133
	unset($input_errors);
134
	$pconfig = $_POST;
135
136
	/* input validation */
137 3462a529 Matthew Grooms
138
	$method = $pconfig['authentication_method'];
139
	if (($method == "pre_shared_key")||($method == "xauth_psk_server")) {
140
		$reqdfields = explode(" ", "pskey");
141
		$reqdfieldsn = explode(",", "Pre-Shared Key");
142 73fbece8 mgrooms
	} else {
143
		$reqdfields = explode(" ", "certref");
144
		$reqdfieldsn = explode(",", "My Certificate");
145 a93e56c5 Matthew Grooms
	}
146 3462a529 Matthew Grooms
	if (!$pconfig['mobile']) {
147
		$reqdfields[] = "remotegw";
148
		$reqdfieldsn[] = "Remote gateway";
149
	}
150 a93e56c5 Matthew Grooms
151 3462a529 Matthew Grooms
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
152 a93e56c5 Matthew Grooms
153 3462a529 Matthew Grooms
	if (($pconfig['lifetime'] && !is_numeric($pconfig['lifetime'])))
154 a93e56c5 Matthew Grooms
		$input_errors[] = "The P1 lifetime must be an integer.";
155
156 3462a529 Matthew Grooms
	if (($pconfig['remotegw'] && !is_ipaddr($pconfig['remotegw']) && !is_domain($pconfig['remotegw']))) 
157 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid remote gateway address or host name must be specified.";
158
159 3462a529 Matthew Grooms
	if (($pconfig['remotegw'] && is_ipaddr($pconfig['remotegw']) && !isset($pconfig['disabled']) )) {
160 a93e56c5 Matthew Grooms
		$t = 0;
161
		foreach ($a_phase1 as $ph1tmp) {
162
			if ($p1index <> $t) {
163
				$tremotegw = $pconfig['remotegw'];
164
				if (($ph1tmp['remote-gateway'] == $tremotegw) && !isset($ph1tmp['disabled'])) {
165
					$input_errors[] = "The remote gateway \"$tremotegw\" is already used by phase1 \"${ph1tmp['descr']}\".";
166
				}
167
			}
168
			$t++;
169
		}
170
	}
171
172
	/* My identity */
173
174 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "myaddress")
175
		$pconfig['myid_data'] = "";
176 a93e56c5 Matthew Grooms
177 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
178 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
179
180 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "keyid tag" and $pconfig['myid_data'] == "")
181 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a keyid tag for 'My Identifier'");
182
183 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "fqdn" and $pconfig['myid_data'] == "")
184 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a fully qualified domain name for 'My Identifier'");
185
186 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "user_fqdn" and $pconfig['myid_data'] == "")
187 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'My Identifier'");
188
189 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "dyn_dns" and $pconfig['myid_data'] == "")
190 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a dynamic domain name for 'My Identifier'");
191
192 3462a529 Matthew Grooms
	if ((($pconfig['myid_type'] == "address") && !is_ipaddr($pconfig['myid_data'])))
193 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
194
195 3462a529 Matthew Grooms
	if ((($pconfig['myid_type'] == "fqdn") && !is_domain($pconfig['myid_data'])))
196 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
197
198 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "fqdn")
199
		if (is_domain($pconfig['myid_data']) == false)
200 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid FQDN for 'My identifier' must be specified.";
201
202 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "user_fqdn") {
203
		$user_fqdn = explode("@",$pconfig['myid_data']);
204 a93e56c5 Matthew Grooms
		if (is_domain($user_fqdn[1]) == false)
205
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
206
	}
207
208 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "dyn_dns")
209
		if (is_domain($pconfig['myid_data']) == false)
210 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified.";
211
212
	/* Peer identity */
213
214 3462a529 Matthew Grooms
	if ($pconfig['myid_type'] == "peeraddress")
215
		$pconfig['peerid_data'] = "";
216
217
	if ($pconfig['peerid_type'] == "address" and $pconfig['peerid_data'] == "")
218 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter an address for 'Peer Identifier'");
219
220 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "keyid tag" and $pconfig['peerid_data'] == "")
221 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a keyid tag for 'Peer Identifier'");
222
223 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "fqdn" and $pconfig['peerid_data'] == "")
224 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a fully qualified domain name for 'Peer Identifier'");
225
226 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "user_fqdn" and $pconfig['peerid_data'] == "")
227 a93e56c5 Matthew Grooms
		$input_errors[] = gettext("Please enter a user and fully qualified domain name for 'Peer Identifier'");
228
229 3462a529 Matthew Grooms
	if ((($pconfig['peerid_type'] == "address") && !is_ipaddr($pconfig['peerid_data'])))
230 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid IP address for 'Peer identifier' must be specified.";
231
232 3462a529 Matthew Grooms
	if ((($pconfig['peerid_type'] == "fqdn") && !is_domain($pconfig['peerid_data'])))
233 a93e56c5 Matthew Grooms
		$input_errors[] = "A valid domain name for 'Peer identifier' must be specified.";
234
235 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "fqdn")
236
		if (is_domain($pconfig['peerid_data']) == false)
237 a93e56c5 Matthew Grooms
			$input_errors[] = "A valid FQDN for 'Peer identifier' must be specified.";
238
239 3462a529 Matthew Grooms
	if ($pconfig['peerid_type'] == "user_fqdn") {
240
		$user_fqdn = explode("@",$pconfig['peerid_data']);
241 a93e56c5 Matthew Grooms
		if (is_domain($user_fqdn[1]) == false)
242
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.";
243
	}
244
245 3462a529 Matthew Grooms
	if ($pconfig['dpd_enable']) {
246
		if (!is_numeric($pconfig['dpd_delay']))
247 a93e56c5 Matthew Grooms
			$input_errors[] = "A numeric value must be specified for DPD delay.";
248
249 3462a529 Matthew Grooms
		if (!is_numeric($pconfig['dpd_maxfail']))
250 a93e56c5 Matthew Grooms
			$input_errors[] = "A numeric value must be specified for DPD retries.";
251
	}
252
253
	/* build our encryption algorithms array */
254
	$pconfig['ealgo'] = array();
255
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
256 3462a529 Matthew Grooms
	if($pconfig['ealgo_keylen'])
257 a93e56c5 Matthew Grooms
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
258
259
	if (!$input_errors) {
260 3462a529 Matthew Grooms
		$ph1ent['ikeid'] = $pconfig['ikeid'];
261
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
262 a93e56c5 Matthew Grooms
		$ph1ent['interface'] = $pconfig['interface'];
263
		/* if the remote gateway changed and the interface is not WAN then remove route */
264
		/* the vpn_ipsec_configure() handles adding the route */
265 3462a529 Matthew Grooms
		if ($pconfig['interface'] <> "wan") {
266 7fc26246 Seth Mos
			if($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
267
				mwexec("/sbin/route delete -host {$oldph1ent['remote-gateway']}");
268 a93e56c5 Matthew Grooms
			}
269
		}
270
271 3462a529 Matthew Grooms
		if ($pconfig['mobile'])
272
			$ph1ent['mobile'] = true;
273
		else
274
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
275
276
		$ph1ent['mode'] = $pconfig['mode'];
277
278
		$ph1ent['myid_type'] = $pconfig['myid_type'];
279
		$ph1ent['myid_data'] = $pconfig['myid_data'];
280
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
281
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
282 a93e56c5 Matthew Grooms
283
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
284 3462a529 Matthew Grooms
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
285
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
286
		$ph1ent['lifetime'] = $pconfig['lifetime'];
287
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
288
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
289 73fbece8 mgrooms
		$ph1ent['certref'] = $pconfig['certref'];
290 3462a529 Matthew Grooms
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
291
292
		$ph1ent['descr'] = $pconfig['descr'];
293
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
294
295
		if (isset($pconfig['dpd_enable'])) {
296
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
297
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
298
		}
299
300 a93e56c5 Matthew Grooms
		/* generate unique phase1 ikeid */
301 d799787e Matthew Grooms
		if ($ph1ent['ikeid'] == 0)
302
			$ph1ent['ikeid'] = ipsec_ikeid_next();
303 a93e56c5 Matthew Grooms
304
		if (isset($p1index) && $a_phase1[$p1index])
305
			$a_phase1[$p1index] = $ph1ent;
306
		else
307
			$a_phase1[] = $ph1ent;
308
309 647c7c48 Seth Mos
		/* now we need to find all phase2 entries for this host */
310
		if (is_array($a_phase2) && (count($a_phase2))) {
311
			foreach ($a_phase2 as $phase2) {
312
				if($phase2['ikeid'] == $ph1ent['ikeid']) {
313 7fc26246 Seth Mos
					log_error("Reload {$ph1ent['descr']} tunnel(s)");
314 647c7c48 Seth Mos
					$old_ph1ent['remote-gateway'] = resolve_retry($old_ph1ent['remote-gateway']);
315
					$old_phase2 = $phase2;
316
					reload_tunnel_spd_policy ($ph1ent, $phase2, $old_ph1ent, $old_phase2);
317
				}
318
			}
319
		}
320 a93e56c5 Matthew Grooms
		write_config();
321 a368a026 Ermal Lu?i
		mark_subsystem_dirty('ipsec');
322 a93e56c5 Matthew Grooms
323
		header("Location: vpn_ipsec.php");
324
		exit;
325
	}
326
}
327
328 3462a529 Matthew Grooms
if ($pconfig['mobile'])
329
	$pgtitle = array("VPN","IPsec","Edit Phase 1", "Mobile Client");
330
else
331
	$pgtitle = array("VPN","IPsec","Edit Phase 1");
332
333 a93e56c5 Matthew Grooms
include("head.inc");
334
335
?>
336
337
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
338
<?php include("fbegin.inc"); ?>
339
<script language="JavaScript">
340
<!--
341 3462a529 Matthew Grooms
342
function myidsel_change() {
343
	index = document.iform.myid_type.selectedIndex;
344
	value = document.iform.myid_type.options[index].value;
345
	if (value == 'myaddress')
346 5a3b0d3b mgrooms
			document.getElementById('myid_data').style.visibility = 'hidden';
347 3462a529 Matthew Grooms
	else
348 5a3b0d3b mgrooms
			document.getElementById('myid_data').style.visibility = 'visible';
349 3462a529 Matthew Grooms
}
350
351
function peeridsel_change() {
352
	index = document.iform.peerid_type.selectedIndex;
353
	value = document.iform.peerid_type.options[index].value;
354
	if (value == 'peeraddress')
355 5a3b0d3b mgrooms
			document.getElementById('peerid_data').style.visibility = 'hidden';
356 3462a529 Matthew Grooms
	else
357 5a3b0d3b mgrooms
			document.getElementById('peerid_data').style.visibility = 'visible';
358 3462a529 Matthew Grooms
}
359
360 a93e56c5 Matthew Grooms
function methodsel_change() {
361 3462a529 Matthew Grooms
	index = document.iform.authentication_method.selectedIndex;
362
	value = document.iform.authentication_method.options[index].value;
363
364
	switch (value) {
365
		case 'hybrid_rsa_server':
366 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = 'none';
367 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = '';
368 3462a529 Matthew Grooms
			break;
369
		case 'xauth_rsa_server':
370
		case 'rsasig':
371 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = 'none';
372 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = '';
373 a93e56c5 Matthew Grooms
			break;
374 3462a529 Matthew Grooms
		default: /* psk modes*/
375 5a3b0d3b mgrooms
			document.getElementById('opt_psk').style.display = '';
376 73fbece8 mgrooms
			document.getElementById('opt_cert').style.display = 'none';
377 a93e56c5 Matthew Grooms
			break;
378
	}
379
}
380
381
/* PHP generated java script for variable length keys */
382
function ealgosel_change(bits) {
383
	switch (document.iform.ealgo.selectedIndex) {
384
<?php
385
  $i = 0;
386
  foreach ($p1_ealgos as $algo => $algodata) {
387
    if (is_array($algodata['keysel'])) {
388
      echo "		case {$i}:\n";
389
      echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
390
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
391
//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
392
393
      $key_hi = $algodata['keysel']['hi'];
394
      $key_lo = $algodata['keysel']['lo'];
395
      $key_step = $algodata['keysel']['step'];
396
397
      for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
398
        echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
399
      echo "			break;\n";
400
    } else {
401
      echo "		case {$i}:\n";
402
      echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
403
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
404
      echo "			break;\n";
405
    }
406
    $i++;
407
  }
408
?>
409
	}
410
411
	if( bits )
412
		document.iform.ealgo_keylen.value = bits;
413
}
414 3462a529 Matthew Grooms
415 a93e56c5 Matthew Grooms
function dpdchkbox_change() {
416 5a3b0d3b mgrooms
	if( document.iform.dpd_enable.checked )
417
		document.getElementById('opt_dpd').style.display = '';
418
	else
419
		document.getElementById('opt_dpd').style.display = 'none';
420 3462a529 Matthew Grooms
421
	if (!document.iform.dpd_delay.value)
422
		document.iform.dpd_delay.value = "10";
423
424
	if (!document.iform.dpd_maxfail.value)
425
		document.iform.dpd_maxfail.value = "5";
426 a93e56c5 Matthew Grooms
}
427 3462a529 Matthew Grooms
428 a93e56c5 Matthew Grooms
//-->
429
</script>
430 5a3b0d3b mgrooms
431
<form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
432
433
<?php
434
	if ($input_errors)
435
		print_input_errors($input_errors);
436
?>
437
438
<table width="100%" border="0" cellpadding="0" cellspacing="0">
439
	<tr class="tabnavtbl">
440
		<td id="tabnav">
441
			<?php
442
				$tab_array = array();
443
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
444
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
445 09725e76 Chris Buechler
				$tab_array[2] = array("Logs", false, "diag_logs_ipsec.php");
446 5a3b0d3b mgrooms
				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>