Project

General

Profile

Download (30.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	vpn_ipsec_phase1.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2008 Shrew Soft Inc
7
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
##|+PRIV
33
##|*IDENT=page-vpn-ipsec-editphase1
34
##|*NAME=VPN: IPsec: Edit Phase 1 page
35
##|*DESCR=Allow access to the 'VPN: IPsec: Edit Phase 1' page.
36
##|*MATCH=vpn_ipsec_phase1.php*
37
##|-PRIV
38

    
39

    
40
require("guiconfig.inc");
41

    
42
if (!is_array($config['ipsec']['phase1']))
43
	$config['ipsec']['phase1'] = array();
44

    
45
$a_phase1 = &$config['ipsec']['phase1'];
46

    
47
if($config['interfaces']['lan']) 
48
		$specialsrcdst = explode(" ", "lan");
49

    
50
$p1index = $_GET['p1index'];
51
if (isset($_POST['p1index']))
52
	$p1index = $_POST['p1index'];
53

    
54
if (isset($_GET['dup'])) {
55
	$p1index = $_GET['dup'];
56
}
57

    
58
if (isset($p1index) && $a_phase1[$p1index])
59
{
60
	$pconfig['ikeid'] = $a_phase1[$p1index]['ikeid'];
61
	$pconfig['disabled'] = isset($a_phase1[$p1index]['disabled']);
62

    
63
	if ($a_phase1[$p1index]['interface'])
64
		$pconfig['interface'] = $a_phase1[$p1index]['interface'];
65
	else
66
		$pconfig['interface'] = "wan";
67

    
68
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_phase1[$p1index]['remote-subnet']);
69

    
70
	if (isset($a_phase1[$p1index]['mobile']))
71
		$pconfig['mobile'] = 'true';
72
	else
73
		$pconfig['remotegw'] = $a_phase1[$p1index]['remote-gateway'];
74

    
75
	$pconfig['mode'] = $a_phase1[$p1index]['mode'];
76
	$pconfig['myid_type'] = $a_phase1[$p1index]['myid_type'];
77
	$pconfig['myid_data'] = $a_phase1[$p1index]['myid_data'];
78
	$pconfig['peerid_type'] = $a_phase1[$p1index]['peerid_type'];
79
	$pconfig['peerid_data'] = $a_phase1[$p1index]['peerid_data'];
80
	$pconfig['ealgo'] = $a_phase1[$p1index]['encryption-algorithm'];
81
	$pconfig['halgo'] = $a_phase1[$p1index]['hash-algorithm'];
82
	$pconfig['dhgroup'] = $a_phase1[$p1index]['dhgroup'];
83
	$pconfig['lifetime'] = $a_phase1[$p1index]['lifetime'];
84
	$pconfig['authentication_method'] = $a_phase1[$p1index]['authentication_method'];
85
	$pconfig['pskey'] = $a_phase1[$p1index]['pre-shared-key'];
86
	$pconfig['cert'] = base64_decode($a_phase1[$p1index]['cert']);
87
	$pconfig['peercert'] = base64_decode($a_phase1[$p1index]['peercert']);
88
	$pconfig['privatekey'] = base64_decode($a_phase1[$p1index]['private-key']);
89

    
90
	$pconfig['descr'] = $a_phase1[$p1index]['descr'];
91
	$pconfig['nat_traversal'] = $a_phase1[$p1index]['nat_traversal'];
92

    
93
	if ($a_phase1[$p1index]['dpd_delay'] &&	$a_phase1[$p1index]['dpd_maxfail']) {
94
		$pconfig['dpd_enable'] = true;
95
		$pconfig['dpd_delay'] = $a_phase1[$p1index]['dpd_delay'];
96
		$pconfig['dpd_maxfail'] = $a_phase1[$p1index]['dpd_maxfail'];
97
	}
98

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

    
118
	/* mobile client */
119
	if($_GET['mobile'])
120
		$pconfig['mobile']=true;
121
}
122

    
123
if (isset($_GET['dup']))
124
	unset($p1index);
125

    
126
if ($_POST) {
127
	unset($input_errors);
128
	$pconfig = $_POST;
129

    
130
	/* input validation */
131

    
132
	$method = $pconfig['authentication_method'];
133
	if (($method == "pre_shared_key")||($method == "xauth_psk_server")) {
134
		$reqdfields = explode(" ", "pskey");
135
		$reqdfieldsn = explode(",", "Pre-Shared Key");
136
	} else	{
137
		if (!strstr($pconfig['cert'], "BEGIN CERTIFICATE") || !strstr($pconfig['cert'], "END CERTIFICATE"))
138
			$input_errors[] = "This certificate does not appear to be valid.";
139
		if (!strstr($pconfig['privatekey'], "BEGIN RSA PRIVATE KEY") || !strstr($pconfig['privatekey'], "END RSA PRIVATE KEY"))
140
			$input_errors[] = "This key does not appear to be valid.";
141
		if ($pconfig['peercert']!="" && (!strstr($pconfig['peercert'], "BEGIN CERTIFICATE") || !strstr($pconfig['peercert'], "END CERTIFICATE")))
142
			$input_errors[] = "This peer certificate does not appear to be valid.";
143
	}
144
	if (!$pconfig['mobile']) {
145
		$reqdfields[] = "remotegw";
146
		$reqdfieldsn[] = "Remote gateway";
147
	}
148

    
149
	do_input_validation($pconfig, $reqdfields, $reqdfieldsn, &$input_errors);
150

    
151
	if (($pconfig['lifetime'] && !is_numeric($pconfig['lifetime'])))
152
		$input_errors[] = "The P1 lifetime must be an integer.";
153

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

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

    
170
	/* My identity */
171

    
172
	if ($pconfig['myid_type'] == "myaddress")
173
		$pconfig['myid_data'] = "";
174

    
175
	if ($pconfig['myid_type'] == "address" and $pconfig['myid_data'] == "")
176
		$input_errors[] = gettext("Please enter an address for 'My Identifier'");
177

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

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

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

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

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

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

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

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

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

    
210
	/* Peer identity */
211

    
212
	if ($pconfig['myid_type'] == "peeraddress")
213
		$pconfig['peerid_data'] = "";
214

    
215
	if ($pconfig['peerid_type'] == "address" and $pconfig['peerid_data'] == "")
216
		$input_errors[] = gettext("Please enter an address for 'Peer Identifier'");
217

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

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

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

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

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

    
233
	if ($pconfig['peerid_type'] == "fqdn")
234
		if (is_domain($pconfig['peerid_data']) == false)
235
			$input_errors[] = "A valid FQDN for 'Peer identifier' must be specified.";
236

    
237
	if ($pconfig['peerid_type'] == "user_fqdn") {
238
		$user_fqdn = explode("@",$pconfig['peerid_data']);
239
		if (is_domain($user_fqdn[1]) == false)
240
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'Peer identifier' must be specified.";
241
	}
242

    
243
	if ($pconfig['dpd_enable']) {
244
		if (!is_numeric($pconfig['dpd_delay']))
245
			$input_errors[] = "A numeric value must be specified for DPD delay.";
246

    
247
		if (!is_numeric($pconfig['dpd_maxfail']))
248
			$input_errors[] = "A numeric value must be specified for DPD retries.";
249
	}
250

    
251
	/* build our encryption algorithms array */
252
	$pconfig['ealgo'] = array();
253
	$pconfig['ealgo']['name'] = $_POST['ealgo'];
254
	if($pconfig['ealgo_keylen'])
255
		$pconfig['ealgo']['keylen'] = $_POST['ealgo_keylen'];
256

    
257
	if (!$input_errors) {
258
		$ph1ent['ikeid'] = $pconfig['ikeid'];
259
		$ph1ent['disabled'] = $pconfig['disabled'] ? true : false;
260
		$ph1ent['interface'] = $pconfig['interface'];
261
		/* if the remote gateway changed and the interface is not WAN then remove route */
262
		/* the vpn_ipsec_configure() handles adding the route */
263
		if ($pconfig['interface'] <> "wan") {
264
			if($ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
265
				mwexec("/sbin/route delete -host {$ph1ent['remote-gateway']}");
266
			}
267
		}
268

    
269
		if ($pconfig['mobile'])
270
			$ph1ent['mobile'] = true;
271
		else
272
			$ph1ent['remote-gateway'] = $pconfig['remotegw'];
273

    
274
		$ph1ent['mode'] = $pconfig['mode'];
275

    
276
		$ph1ent['myid_type'] = $pconfig['myid_type'];
277
		$ph1ent['myid_data'] = $pconfig['myid_data'];
278
		$ph1ent['peerid_type'] = $pconfig['peerid_type'];
279
		$ph1ent['peerid_data'] = $pconfig['peerid_data'];
280

    
281
		$ph1ent['encryption-algorithm'] = $pconfig['ealgo'];
282
		$ph1ent['hash-algorithm'] = $pconfig['halgo'];
283
		$ph1ent['dhgroup'] = $pconfig['dhgroup'];
284
		$ph1ent['lifetime'] = $pconfig['lifetime'];
285
		$ph1ent['pre-shared-key'] = $pconfig['pskey'];
286
		$ph1ent['private-key'] = base64_encode($pconfig['privatekey']);
287
		$ph1ent['cert'] = base64_encode($pconfig['cert']);
288
		$ph1ent['peercert'] = base64_encode($pconfig['peercert']);
289
		$ph1ent['authentication_method'] = $pconfig['authentication_method'];
290

    
291
		$ph1ent['descr'] = $pconfig['descr'];
292
		$ph1ent['nat_traversal'] = $pconfig['nat_traversal'];
293

    
294
		if (isset($pconfig['dpd_enable'])) {
295
			$ph1ent['dpd_delay'] = $pconfig['dpd_delay'];
296
			$ph1ent['dpd_maxfail'] = $pconfig['dpd_maxfail'];
297
		}
298

    
299
		$ph1ent['pinghost'] = $pconfig['pinghost'];
300

    
301
		/* generate unique phase1 ikeid */
302
		if ($ph1ent['ikeid'] == 0) {
303
			while (true) {
304
				$ph1ent['ikeid']++;
305
				foreach ($a_phase1 as $ph1tmp)
306
					if( $ph1ent['ikeid'] == $ph1tmp['ikeid'] )
307
						break;
308

    
309
				if( $ph1ent['ikeid'] != $ph1tmp['ikeid'] )
310
					break;
311
			}
312
		}
313

    
314
		if (isset($p1index) && $a_phase1[$p1index])
315
			$a_phase1[$p1index] = $ph1ent;
316
		else
317
			$a_phase1[] = $ph1ent;
318

    
319
		write_config();
320
		touch($d_ipsecconfdirty_path);
321

    
322
		header("Location: vpn_ipsec.php");
323
		exit;
324
	}
325
}
326

    
327
if ($pconfig['mobile'])
328
	$pgtitle = array("VPN","IPsec","Edit Phase 1", "Mobile Client");
329
else
330
	$pgtitle = array("VPN","IPsec","Edit Phase 1");
331

    
332
include("head.inc");
333

    
334
?>
335

    
336
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
337
<?php include("fbegin.inc"); ?>
338
<script language="JavaScript">
339
<!--
340

    
341
function myidsel_change() {
342
	index = document.iform.myid_type.selectedIndex;
343
	value = document.iform.myid_type.options[index].value;
344
	if (value == 'myaddress')
345
			document.iform.myid_data.style.visibility = 'hidden';
346
	else
347
			document.iform.myid_data.style.visibility = 'visible';
348
}
349

    
350
function peeridsel_change() {
351
	index = document.iform.peerid_type.selectedIndex;
352
	value = document.iform.peerid_type.options[index].value;
353
	if (value == 'peeraddress')
354
			document.iform.peerid_data.style.visibility = 'hidden';
355
	else
356
			document.iform.peerid_data.style.visibility = 'visible';
357
}
358

    
359
function methodsel_change() {
360
	index = document.iform.authentication_method.selectedIndex;
361
	value = document.iform.authentication_method.options[index].value;
362

    
363
	switch (value) {
364
		case 'hybrid_rsa_server':
365
			document.iform.pskey.disabled = 1;
366
			document.iform.privatekey.disabled = 0;
367
			document.iform.cert.disabled = 0;
368
			document.iform.peercert.disabled = 1;
369
			break;
370
		case 'xauth_rsa_server':
371
		case 'rsasig':
372
			document.iform.pskey.disabled = 1;
373
			document.iform.privatekey.disabled = 0;
374
			document.iform.cert.disabled = 0;
375
			document.iform.peercert.disabled = 0;
376
			break;
377
		default: /* psk modes*/
378
			document.iform.pskey.disabled = 0;
379
			document.iform.privatekey.disabled = 1;
380
			document.iform.cert.disabled = 1;
381
			document.iform.peercert.disabled = 1;
382
			break;
383
	}
384
}
385

    
386
/* PHP generated java script for variable length keys */
387
function ealgosel_change(bits) {
388
	switch (document.iform.ealgo.selectedIndex) {
389
<?php
390
  $i = 0;
391
  foreach ($p1_ealgos as $algo => $algodata) {
392
    if (is_array($algodata['keysel'])) {
393
      echo "		case {$i}:\n";
394
      echo "			document.iform.ealgo_keylen.style.visibility = 'visible';\n";
395
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
396
//      echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( 'auto', 'auto' );\n";
397

    
398
      $key_hi = $algodata['keysel']['hi'];
399
      $key_lo = $algodata['keysel']['lo'];
400
      $key_step = $algodata['keysel']['step'];
401

    
402
      for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step)
403
        echo "			document.iform.ealgo_keylen.options[document.iform.ealgo_keylen.options.length] = new Option( '{$keylen} bits', '{$keylen}' );\n";
404
      echo "			break;\n";
405
    } else {
406
      echo "		case {$i}:\n";
407
      echo "			document.iform.ealgo_keylen.style.visibility = 'hidden';\n";
408
      echo "			document.iform.ealgo_keylen.options.length = 0;\n";
409
      echo "			break;\n";
410
    }
411
    $i++;
412
  }
413
?>
414
	}
415

    
416
	if( bits )
417
		document.iform.ealgo_keylen.value = bits;
418
}
419

    
420
function dpdchkbox_change() {
421
	if( document.iform.dpd_enable.checked ) {
422
			document.iform.dpd_delay.disabled = 0;
423
			document.iform.dpd_maxfail.disabled = 0;
424
	} else {
425
			document.iform.dpd_delay.disabled = 1;
426
			document.iform.dpd_maxfail.disabled = 1;
427
	}
428

    
429
	if (!document.iform.dpd_delay.value)
430
		document.iform.dpd_delay.value = "10";
431

    
432
	if (!document.iform.dpd_maxfail.value)
433
		document.iform.dpd_maxfail.value = "5";
434
}
435

    
436
//-->
437
</script>
438
<?php if ($input_errors) print_input_errors($input_errors); ?>
439
            <form action="vpn_ipsec_phase1.php" method="post" name="iform" id="iform">
440
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
441
                <tr>
442
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
443
                  <td width="78%" class="vtable">
444
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
445
                    <strong>Disable this phase1 entry</strong><br>
446
                    <span class="vexpl">Set this option to disable this phase1 without
447
                      removing it from the list.
448
                    </span>
449
                  </td>
450
                </tr>
451
                <tr>
452
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
453
                  <td width="78%" class="vtable">
454
                    <select name="interface" class="formselect">
455
                      <?php 
456
                        $interfaces = get_configured_interface_with_descr();
457
                        $carpips = find_number_of_needed_carp_interfaces();
458
                        for ($i=0; $i<$carpips; $i++) {
459
                          $carpip = find_interface_ip("carp" . $i);
460
                          $interfaces['carp' . $i] = "CARP{$i} ({$carpip})"; 
461
                        }
462
                        foreach ($interfaces as $iface => $ifacename):
463
                      ?>
464
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
465
                        <?=htmlspecialchars($ifacename);?>
466
                      </option>
467
                      <?php endforeach; ?>
468
                    </select> <br>
469
                    <span class="vexpl">Select the interface for the local endpoint of this phase1 entry.</span>
470
                  </td>
471
                </tr>
472
				<?php if (!$pconfig['mobile']): ?>
473
                <tr>
474
                  <td width="22%" valign="top" class="vncellreq">Remote gateway</td>
475
                  <td width="78%" class="vtable">
476
                    <?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="20" value="<?=$pconfig['remotegw'];?>">
477
                    <br>
478
                    Enter the public IP address or host name of the remote gateway
479
                  </td>
480
                </tr>
481
				<?php endif; ?>
482
                <tr>
483
                  <td width="22%" valign="top" class="vncell">Description</td>
484
                  <td width="78%" class="vtable">
485
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
486
                    <br> <span class="vexpl">You may enter a description here
487
                    for your reference (not parsed).</span>
488
                  </td>
489
                </tr>
490
                <tr>
491
                  <td colspan="2" class="list" height="12"></td>
492
                </tr>
493
                <tr>
494
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal
495
                    (Authentication)
496
                  </td>
497
                </tr>
498
                <tr>
499
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
500
                  <td width="78%" class="vtable">
501
                    <select name="mode" class="formselect">
502
                      <?php
503
                        $modes = explode(" ", "main aggressive");
504
                        foreach ($modes as $mode):
505
                      ?>
506
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['mode']) echo "selected"; ?>>
507
                        <?=htmlspecialchars($mode);?>
508
                      </option>
509
                      <?php endforeach; ?>
510
                    </select> <br> <span class="vexpl">Aggressive is more flexible, but less secure.</span>
511
                  </td>
512
                </tr>
513
                <tr>
514
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
515
                  <td width="78%" class="vtable">
516
                    <select name="myid_type" class="formselect" onChange="myidsel_change()">
517
                      <?php foreach ($my_identifier_list as $id_type => $id_params): ?>
518
                        <option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['myid_type']) echo "selected"; ?>>
519
                          <?=htmlspecialchars($id_params['desc']);?>
520
                        </option>
521
                      <?php endforeach; ?>
522
                    </select>
523
                    <input name="myid_data" type="text" class="formfld unknown" id="myid_data" size="30" value="<?=$pconfig['myid_data'];?>">
524
                  </td>
525
                </tr>
526
                <tr>
527
                  <td width="22%" valign="top" class="vncellreq">Peer identifier</td>
528
                  <td width="78%" class="vtable">
529
                    <select name="peerid_type" class="formselect" onChange="peeridsel_change()">
530
                      <?php
531
                        foreach ($peer_identifier_list as $id_type => $id_params):
532
                          if ($pconfig['mobile'] && !$id_params['mobile'])
533
                            continue;
534
                      ?>
535
                      <option value="<?=$id_type;?>" <?php if ($id_type == $pconfig['peerid_type']) echo "selected"; ?>>
536
                        <?=htmlspecialchars($id_params['desc']);?>
537
                      </option>
538
                      <?php endforeach; ?>
539
                    </select>
540
                    <input name="peerid_data" type="text" class="formfld unknown" id="peerid_data" size="30" value="<?=$pconfig['peerid_data'];?>">
541
                  </td>
542
                </tr>
543
                <tr>
544
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
545
                  <td width="78%" class="vtable">
546
                    <select name="ealgo" class="formselect" onChange="ealgosel_change()">
547
                      <?php
548
                        foreach ($p1_ealgos as $algo => $algodata):
549
                        $selected = '';
550
                        if ($algo == $pconfig['ealgo']['name'])
551
                          $selected = ' selected';
552
                      ?>
553
                      <option value="<?=$algo;?>"<?=$selected?>>
554
                        <?=htmlspecialchars($algodata['name']);?>
555
                      </option>
556
                    <?php endforeach; ?>
557
                    </select>
558
                    <select name="ealgo_keylen" width="30" class="formselect">
559
                    </select>
560
                  </td>
561
                </tr>
562
                <tr>
563
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
564
                  <td width="78%" class="vtable">
565
                    <select name="halgo" class="formselect">
566
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
567
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['halgo']) echo "selected"; ?>>
568
                        <?=htmlspecialchars($algoname);?>
569
                      </option>
570
                      <?php endforeach; ?>
571
                    </select>
572
                    <br>
573
                    <span class="vexpl">
574
                      Must match the setting chosen on the remote side.
575
                    </span>
576
                  </td>
577
                </tr>
578
                <tr>
579
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
580
                  <td width="78%" class="vtable">
581
                    <select name="dhgroup" class="formselect">
582
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
583
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['dhgroup']) echo "selected"; ?>>
584
                        <?=htmlspecialchars($keygroup);?>
585
                      </option>
586
                      <?php endforeach; ?>
587
                    </select>
588
                    <br>
589
                    <span class="vexpl">
590
                      <em>1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit</em>
591
                      <br>
592
                      Must match the setting chosen on the remote side.
593
                    </span>
594
                  </td>
595
                </tr>
596
                <tr>
597
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
598
                  <td width="78%" class="vtable">
599
                    <input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
600
                    seconds
601
                  </td>
602
                </tr>
603
                <tr>
604
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
605
                  <td width="78%" class="vtable">
606
                    <select name="authentication_method" class="formselect" onChange="methodsel_change()">
607
                      <?php
608
                        foreach ($p1_authentication_methods as $method_type => $method_params):
609
                          if (!$pconfig['mobile'] && $method_params['mobile'])
610
                            continue;
611
                      ?>
612
                      <option value="<?=$method_type;?>" <?php if ($method_type == $pconfig['authentication_method']) echo "selected"; ?>>
613
                        <?=htmlspecialchars($method_params['name']);?>
614
                      </option>
615
                      <?php endforeach; ?>
616
                    </select>
617
                    <br>
618
                    <span class="vexpl">Must match the setting chosen on the remote side.</span>
619
                  </td>
620
                </tr>
621
                <tr>
622
                  <td width="22%" valign="top" class="vncellreq">Pre-Shared Key</td>
623
                  <td width="78%" class="vtable">
624
                    <?=$mandfldhtml;?><input name="pskey" type="text" class="formfld unknown" id="pskey" size="40" value="<?=htmlspecialchars($pconfig['pskey']);?>">
625
                  </td>
626
                </tr>
627
                <tr>
628
                  <td width="22%" valign="top" class="vncellreq">My Certificate</td>
629
                  <td width="78%" class="vtable">
630
                    <textarea name="cert" cols="65" rows="7" id="cert" class="formpre"><?=htmlspecialchars($pconfig['cert']);?></textarea>
631
                    <br>
632
                    Paste a certificate in X.509 PEM format here.</td>
633
                </tr>
634
                <tr>
635
                  <td width="22%" valign="top" class="vncellreq">My Private Key</td>
636
                  <td width="78%" class="vtable">
637
                    <textarea name="privatekey" cols="65" rows="7" id="privatekey" class="formpre"><?=htmlspecialchars($pconfig['privatekey']);?></textarea>
638
                    <br>
639
                    Paste an RSA private key in PEM format here.
640
                  </td>
641
                </tr>
642
                <tr>
643
                  <td width="22%" valign="top" class="vncell">Peer certificate</td>
644
                  <td width="78%" class="vtable">
645
                    <textarea name="peercert" cols="65" rows="7" id="peercert" class="formpre"><?=htmlspecialchars($pconfig['peercert']);?></textarea>
646
                    <br>
647
                    Paste the peer X.509 certificate in PEM format here.<br>
648
                    Leave this blank if you want to use a CA certificate for identity validation.
649
                  </td>
650
                </tr>
651
                <tr>
652
                  <td colspan="2" class="list" height="12"></td>
653
                </tr>
654
                <tr>
655
                  <td colspan="2" valign="top" class="listtopic">Advanced Options</td>
656
                </tr>
657
                <tr>
658
                  <td width="22%" valign="top" class="vncell">NAT Traversal</td>
659
                  <td width="78%" class="vtable">
660
                    <select name="nat_traversal" class="formselect">
661
                      <option value="off" <?php if ($pconfig['nat_traversal'] == "off") echo "selected"; ?>>Disable</option>
662
                      <option value="on" <?php if ($pconfig['nat_traversal'] == "on") echo "selected"; ?>>Enable</option>
663
                      <option value="force" <?php if ($pconfig['nat_traversal'] == "force") echo "selected"; ?>>Force</option>
664
                    </select>
665
                    <br/>
666
                    <span class="vexpl">
667
                      Set this option to enable the use of NAT-T (i.e. the encapsulation of ESP in UDP packets) if needed,
668
                      which can help with clients that are behind restrictive firewalls.
669
                    </span>
670
                  </td>
671
                </tr>
672
                <tr>
673
                  <td width="22%" valign="top" class="vncell">Dead Peer Detection</td>
674
                  <td width="78%" class="vtable">
675
                    <input name="dpd_enable" type="checkbox" id="dpd_enable" value="yes" <?php if (isset($pconfig['dpd_enable'])) echo "checked"; ?> onClick="dpdchkbox_change()">
676
                    Enable DPD<br>
677
                    <br>
678
                    <input name="dpd_delay" type="text" class="formfld unknown" id="dpd_delay" size="5" value="<?=$pconfig['dpd_delay'];?>">
679
                    seconds<br>
680
                    <span class="vexpl">Delay between requesting peer acknowledgement.</span><br>
681
                    <br>
682
                    <input name="dpd_maxfail" type="text" class="formfld unknown" id="dpd_maxfail" size="5" value="<?=$pconfig['dpd_maxfail'];?>">
683
                    retries<br>
684
                    <span class="vexpl">Number consecutive failures allowed before disconnect.</span><br>
685
                  </td>
686
                </tr>
687
                <tr>
688
                  <td width="22%" valign="top" class="vncell">Automatically ping host</td>
689
                  <td width="78%" class="vtable">
690
                    <input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>">
691
                    IP address
692
                  </td>
693
                </tr>
694
                <tr>
695
                  <td width="22%" valign="top">&nbsp;</td>
696
                  <td width="78%">
697
                    <?php if (isset($p1index) && $a_phase1[$p1index]): ?>
698
                    <input name="p1index" type="hidden" value="<?=$p1index;?>">
699
                    <?php endif; ?>
700
					<?php if ($pconfig['mobile']): ?>
701
                    <input name="mobile" type="hidden" value="true">
702
                    <?php endif; ?>
703
                    <input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
704
                    <input name="Submit" type="submit" class="formbtn" value="Save">
705
                  </td>
706
                </tr>
707
              </table>
708
</form>
709
<script lannguage="JavaScript">
710
<!--
711
<?php
712
	/* determine if we should init the key length */
713
	$keyset = '';
714
	if (isset($pconfig['ealgo']['keylen']))
715
		if (is_numeric($pconfig['ealgo']['keylen']))
716
			$keyset = $pconfig['ealgo']['keylen'];
717
?>
718
myidsel_change();
719
peeridsel_change();
720
methodsel_change();
721
ealgosel_change(<?=$keyset;?>);
722
dpdchkbox_change();
723
//-->
724
</script>
725
<?php include("fend.inc"); ?>
726
</body>
727
</html>
(192-192/214)