Project

General

Profile

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

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

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

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

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

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

    
31
require("guiconfig.inc");
32

    
33
if (!is_array($config['ipsec']['tunnel'])) {
34
	$config['ipsec']['tunnel'] = array();
35
}
36
$a_ipsec = &$config['ipsec']['tunnel'];
37

    
38
$specialsrcdst = explode(" ", "lan");
39

    
40
$id = $_GET['id'];
41
if (isset($_POST['id']))
42
	$id = $_POST['id'];
43

    
44
if (isset($_GET['dup'])) {
45
	$id = $_GET['dup'];
46
}
47

    
48
if (isset($id) && $a_ipsec[$id]) {
49
	$pconfig['disabled'] = isset($a_ipsec[$id]['disabled']);
50
	$pconfig['auto'] = isset($a_ipsec[$id]['auto']);
51

    
52
	if (!isset($a_ipsec[$id]['local-subnet']))
53
		$pconfig['localnet'] = "lan";
54
	else
55
		address_to_pconfig_vpn($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask']);
56

    
57
	if ($a_ipsec[$id]['interface'])
58
		$pconfig['interface'] = $a_ipsec[$id]['interface'];
59
	else
60
		$pconfig['interface'] = "wan";
61

    
62
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_ipsec[$id]['remote-subnet']);
63
	$pconfig['remotegw'] = $a_ipsec[$id]['remote-gateway'];
64
	$pconfig['p1mode'] = $a_ipsec[$id]['p1']['mode'];
65

    
66
	if (isset($a_ipsec[$id]['p1']['myident']['myaddress']))
67
		$pconfig['p1myidentt'] = 'myaddress';
68
	else if (isset($a_ipsec[$id]['p1']['myident']['address'])) {
69
		$pconfig['p1myidentt'] = 'address';
70
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['address'];
71
	} else if (isset($a_ipsec[$id]['p1']['myident']['fqdn'])) {
72
		$pconfig['p1myidentt'] = 'fqdn';
73
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['fqdn'];
74
	} else if (isset($a_ipsec[$id]['p1']['myident']['ufqdn'])) {
75
		$pconfig['p1myidentt'] = 'user_fqdn';
76
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['ufqdn'];
77
	} else if (isset($a_ipsec[$id]['p1']['myident']['asn1dn'])) {
78
		$pconfig['p1myidentt'] = 'asn1dn';
79
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['asn1dn'];
80
 	} else if (isset($a_ipsec[$id]['p1']['myident']['dyn_dns'])) {
81
		$pconfig['p1myidentt'] = 'dyn_dns';
82
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['dyn_dns'];
83
	}
84

    
85
	$pconfig['p1ealgo'] = $a_ipsec[$id]['p1']['encryption-algorithm'];
86
	$pconfig['p1halgo'] = $a_ipsec[$id]['p1']['hash-algorithm'];
87
	$pconfig['p1dhgroup'] = $a_ipsec[$id]['p1']['dhgroup'];
88
	$pconfig['p1lifetime'] = $a_ipsec[$id]['p1']['lifetime'];
89
	$pconfig['p1authentication_method'] = $a_ipsec[$id]['p1']['authentication_method'];
90
	$pconfig['p1pskey'] = $a_ipsec[$id]['p1']['pre-shared-key'];
91
	$pconfig['p1cert'] = base64_decode($a_ipsec[$id]['p1']['cert']);
92
	$pconfig['p1peercert'] = base64_decode($a_ipsec[$id]['p1']['peercert']);
93
	$pconfig['p1privatekey'] = base64_decode($a_ipsec[$id]['p1']['private-key']);
94
	$pconfig['p2proto'] = $a_ipsec[$id]['p2']['protocol'];
95
	$pconfig['p2ealgos'] = $a_ipsec[$id]['p2']['encryption-algorithm-option'];
96
	$pconfig['p2halgos'] = $a_ipsec[$id]['p2']['hash-algorithm-option'];
97
	$pconfig['p2pfsgroup'] = $a_ipsec[$id]['p2']['pfsgroup'];
98
	$pconfig['p2lifetime'] = $a_ipsec[$id]['p2']['lifetime'];
99
	$pconfig['descr'] = $a_ipsec[$id]['descr'];
100
	$pconfig['pinghost'] = $a_ipsec[$id]['pinghost'];
101

    
102
} else {
103
	/* defaults */
104
	$pconfig['interface'] = "wan";
105
	$pconfig['localnet'] = "lan";
106
	$pconfig['p1mode'] = "aggressive";
107
	$pconfig['p1myidentt'] = "myaddress";
108
	$pconfig['p1authentication_method'] = "pre_shared_key";
109
	$pconfig['p1ealgo'] = "3des";
110
	$pconfig['p1halgo'] = "sha1";
111
	$pconfig['p1dhgroup'] = "2";
112
	$pconfig['p2proto'] = "esp";
113
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael,rijndael 256");
114
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
115
	$pconfig['p2pfsgroup'] = "0";
116
	$pconfig['remotebits'] = 32;
117
}
118

    
119
if (isset($_GET['dup']))
120
	unset($id);
121

    
122
if ($_POST) {
123
	if (is_specialnet($_POST['localnettype'])) {
124
		$_POST['localnet'] = $_POST['localnettype'];
125
		$_POST['localnetmask'] = 0;
126
	} else if ($_POST['localnettype'] == "single") {
127
		$_POST['localnetmask'] = 32;
128
	}
129

    
130
	unset($input_errors);
131
	$pconfig = $_POST;
132

    
133
	/* input validation */
134
	if ($_POST['p1authentication_method'] == "pre_shared_key") {
135
		$reqdfields = explode(" ", "localnet remotenet remotebits remotegw p1pskey p2ealgos p2halgos");
136
		$reqdfieldsn = explode(",", "Local network,Remote network,Remote network bits,Remote gateway,Pre-Shared Key,P2 Encryption Algorithms,P2 Hash Algorithms");
137
	}
138
	else {
139
		$reqdfields = explode(" ", "localnet remotenet remotebits remotegw p2ealgos p2halgos");
140
		$reqdfieldsn = explode(",", "Local network,Remote network,Remote network bits,Remote gateway,P2 Encryption Algorithms,P2 Hash Algorithms");
141
		if (!strstr($_POST['p1cert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1cert'], "END CERTIFICATE"))
142
			$input_errors[] = "This certificate does not appear to be valid.";
143
		if (!strstr($_POST['p1privatekey'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['p1privatekey'], "END RSA PRIVATE KEY"))
144
			$input_errors[] = "This key does not appear to be valid.";
145
		if ($_POST['p1peercert']!="" && (!strstr($_POST['p1peercert'], "BEGIN CERTIFICATE") || !strstr($_POST['p1peercert'], "END CERTIFICATE")))
146
			$input_errors[] = "This peer certificate does not appear to be valid.";
147
	}
148

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

    
151
	if (!is_specialnet($_POST['localnettype'])) {
152
		if (($_POST['localnet'] && !is_ipaddr($_POST['localnet']))) {
153
			$input_errors[] = "A valid local network IP address must be specified.";
154
		}
155
		if (($_POST['localnetmask'] && !is_numeric($_POST['localnetmask']))) {
156
			$input_errors[] = "A valid local network bit count must be specified.";
157
		}
158
	}
159
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
160
		$input_errors[] = "The P1 lifetime must be an integer.";
161
	}
162
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
163
		$input_errors[] = "The P2 lifetime must be an integer.";
164
	}
165
	if ($_POST['remotebits'] && (!is_numeric($_POST['remotebits']) || ($_POST['remotebits'] < 0) || ($_POST['remotebits'] > 32))) {
166
		if(!$_POST['remotebits'] == "0.0.0.0")
167
			$input_errors[] = "The remote network bits are invalid.";
168
	}
169
	if (($_POST['remotenet'] && !is_ipaddr($_POST['remotenet'])) or $_POST['remotenet'] == "0.0.0.0") {
170
		/* allow 0.0.0.0 remote net usage */
171
		if($_POST['remotenet'] <> "0.0.0.0")
172
			$input_errors[] = "A valid remote network address must be specified.";
173
	}
174
	if (($_POST['remotenet'] && is_ipaddr($_POST['remotenet']) && !isset($_POST['disabled']) )) {
175
		$t = 0;
176
		foreach($a_ipsec as $tunnel) {
177
			if($id <> $t) {
178
				$tremotecidr = $pconfig['remotenet'] ."/". $pconfig['remotebits'];
179
				if(($tunnel['remote-subnet'] == $tremotecidr) && !isset($tunnel['disabled'])) {
180
					$input_errors[] = "The remote network \"$tremotecidr\" is already used by tunnel \"${tunnel['descr']}\".";
181
 				}
182
			}
183
			$t++;
184
		}
185
	}
186
	if (($_POST['remotegw'] && !is_ipaddr($_POST['remotegw']) && !is_domain($_POST['remotegw']))) 
187
		$input_errors[] = "A valid remote gateway address or host name must be specified.";
188
	if (($_POST['remotegw'] && is_ipaddr($_POST['remotegw']) && !isset($_POST['disabled']) )) {
189
		$t = 0;
190
		foreach($a_ipsec as $tunnel) {
191
			if($id <> $t) {
192
				$tremotegw = $pconfig['remotegw'];
193
				if(($tunnel['remote-gateway'] == $tremotegw) && !isset($tunnel['disabled'])) {
194
					$input_errors[] = "The remote gateway \"$tremotegw\" is already used by tunnel \"${tunnel['descr']}\".";
195
				}
196
			}
197
			$t++;
198
		}
199
	}
200
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
201
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
202
	}
203
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
204
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
205
	}
206
	if ($_POST['p1myidentt'] == "user_fqdn") {
207
		$ufqdn = explode("@",$_POST['p1myident']);
208
		if (is_domain($ufqdn[1]) == false)
209
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
210
	}
211
	if ($_POST['p1myidentt'] == "dyn_dns") {
212
		if (is_domain($_POST['p1myidentt']) == false)
213
			$input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified.";
214
	}
215

    
216
	if($_POST['p1myidentt'] == "fqdn" and $_POST['p1myident'] == "")
217
		$input_errors[] = gettext("Please enter a domain name for 'My Identifier'");
218

    
219
	if($_POST['p1myidentt'] == "dyn_dns" and $_POST['p1myident'] == "")
220
		$input_errors[] = gettext("Please enter a domain name for 'My Identifier'");
221

    
222
	if($_POST['p1myidentt'] == "address" and $_POST['p1myident'] == "")
223
		$input_errors[] = gettext("Please enter a domain name for 'My Identifier'");
224

    
225
	if($_POST['p1myidentt'] == "user_fqdn" and $_POST['p1myident'] == "")
226
		$input_errors[] = gettext("Please enter a domain name for 'My Identifier'");
227

    
228
	if ($_POST['p1myidentt'] == "myaddress")
229
		$_POST['p1myident'] = "";
230

    
231
	if (!$input_errors) {
232
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
233
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
234
		$ipsecent['interface'] = $pconfig['interface'];
235
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
236
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
237
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
238
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
239

    
240
		$ipsecent['p1']['myident'] = array();
241
		switch ($_POST['p1myidentt']) {
242
			case 'myaddress':
243
				$ipsecent['p1']['myident']['myaddress'] = true;
244
				break;
245
			case 'address':
246
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
247
				break;
248
			case 'fqdn':
249
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
250
				break;
251
			case 'user_fqdn':
252
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
253
				break;
254
			case 'asn1dn':
255
				$ipsecent['p1']['myident']['asn1dn'] = $_POST['p1myident'];
256
				break;
257
			case 'dyn_dns':
258
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
259
				break;
260
		}
261

    
262
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
263
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
264
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
265
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
266
		$ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey'];
267
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
268
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
269
		$ipsecent['p1']['peercert'] = base64_encode($_POST['p1peercert']);
270
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
271
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
272
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
273
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
274
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
275
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
276
		$ipsecent['descr'] = $_POST['descr'];
277
		$ipsecent['pinghost'] = $_POST['pinghost'];
278

    
279
		if (isset($id) && $a_ipsec[$id])
280
			$a_ipsec[$id] = $ipsecent;
281
		else
282
			$a_ipsec[] = $ipsecent;
283

    
284
		write_config();
285
		touch($d_ipsecconfdirty_path);
286

    
287
		header("Location: vpn_ipsec.php");
288
		exit;
289
	}
290
}
291

    
292
$pgtitle = array("VPN","IPsec","Edit tunnel");
293
include("head.inc");
294

    
295
?>
296

    
297
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
298
<?php include("fbegin.inc"); ?>
299
<script language="JavaScript">
300
<!--
301
function typesel_change() {
302
	switch (document.iform.localnettype.selectedIndex) {
303
		case 0:	/* single */
304
			document.iform.localnet.disabled = 0;
305
			document.iform.localnetmask.value = "";
306
			document.iform.localnetmask.disabled = 1;
307
			break;
308
		case 1:	/* network */
309
			document.iform.localnet.disabled = 0;
310
			document.iform.localnetmask.disabled = 0;
311
			break;
312
		default:
313
			document.iform.localnet.value = "";
314
			document.iform.localnet.disabled = 1;
315
			document.iform.localnetmask.value = "";
316
			document.iform.localnetmask.disabled = 1;
317
			break;
318
	}
319
}
320
function methodsel_change() {
321
	switch (document.iform.p1authentication_method.selectedIndex) {
322
		case 1:	/* rsa */
323
			document.iform.p1pskey.disabled = 1;
324
			document.iform.p1privatekey.disabled = 0;
325
			document.iform.p1cert.disabled = 0;
326
			document.iform.p1peercert.disabled = 0;
327
			break;
328
		default: /* pre-shared */
329
			document.iform.p1pskey.disabled = 0;
330
			document.iform.p1privatekey.disabled = 1;
331
			document.iform.p1cert.disabled = 1;
332
			document.iform.p1peercert.disabled = 1;
333
			break;
334
	}
335
}
336
//-->
337
</script>
338
<?php if ($input_errors) print_input_errors($input_errors); ?>
339
            <form action="vpn_ipsec_edit.php" method="post" name="iform" id="iform">
340
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
341
                <tr>
342
                  <td width="22%" valign="top" class="vncellreq">Mode</td>
343
                  <td width="78%" class="vtable"> Tunnel</td>
344
                </tr>
345
				<tr>
346
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
347
                  <td width="78%" class="vtable">
348
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
349
                    <strong>Disable this tunnel</strong><br>
350
                    <span class="vexpl">Set this option to disable this tunnel without
351
					removing it from the list.</span></td>
352
                </tr>
353
			   <tr>
354
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
355
                  <td width="78%" class="vtable"><select name="interface" class="formselect">
356
                      <?php 
357
                       $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
358
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
359
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
360
					  }
361
                       $carpips = find_number_of_needed_carp_interfaces();
362
                       for($i=0; $i<$carpips; $i++) {
363
                       	$carpip = find_interface_ip("carp" . $i);
364
                       	$interfaces['carp' . $i] = "CARP{$i} ({$carpip})"; 
365
                       }
366
					  foreach ($interfaces as $iface => $ifacename): ?>
367
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
368
                      <?=htmlspecialchars($ifacename);?>
369
                      </option>
370
                      <?php endforeach; ?>
371
                    </select> <br>
372
                    <span class="vexpl">Select the interface for the local endpoint of this tunnel.</span></td>
373
                </tr>
374
                <tr>
375
                  <td width="22%" valign="top" class="vncellreq">Local subnet</td>
376
                  <td width="78%" class="vtable">
377
                    <table border="0" cellspacing="0" cellpadding="0">
378
                      <tr>
379
                        <td>Type:&nbsp;&nbsp;</td>
380
						<td></td>
381
                        <td><select name="localnettype" class="formselect" onChange="typesel_change()">
382
                            <?php $sel = is_specialnet($pconfig['localnet']); ?>
383
                            <option value="single" <?php if (($pconfig['localnetmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
384
                            Single host</option>
385
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
386
                            Network</option>
387
                            <option value="lan" <?php if ($pconfig['localnet'] == "lan") { echo "selected"; } ?>>
388
                            LAN subnet</option>
389
                          </select></td>
390
                      </tr>
391
                      <tr>
392
                        <td>Address:&nbsp;&nbsp;</td>
393
						<td><?=$mandfldhtmlspc;?></td>
394
                        <td><input name="localnet" type="text" class="formfld unknown" id="localnet" size="20" value="<?php if (!is_specialnet($pconfig['localnet'])) echo htmlspecialchars($pconfig['localnet']);?>">
395
                          /
396
                          <select name="localnetmask" class="formselect" id="localnetmask">
397
                            <?php for ($i = 31; $i >= 0; $i--): ?>
398
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['localnetmask']) echo "selected"; ?>>
399
                            <?=$i;?>
400
                            </option>
401
                            <?php endfor; ?>
402
                          </select> </td>
403
                      </tr>
404
                    </table></td>
405
                </tr>
406
                <tr>
407
                  <td width="22%" valign="top" class="vncellreq">Remote subnet</td>
408
                  <td width="78%" class="vtable">
409
                    <?=$mandfldhtml;?><input name="remotenet" type="text" class="formfld unknown" id="remotenet" size="20" value="<?=$pconfig['remotenet'];?>">
410
                    /
411
                    <select name="remotebits" class="formselect" id="remotebits">
412
                      <?php for ($i = 32; $i >= 0; $i--): ?>
413
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['remotebits']) echo "selected"; ?>>
414
                      <?=$i;?>
415
                      </option>
416
                      <?php endfor; ?>
417
                    </select></td>
418
                </tr>
419
                <tr>
420
                  <td width="22%" valign="top" class="vncellreq">Remote gateway</td>
421
                  <td width="78%" class="vtable">
422
                    <?=$mandfldhtml;?><input name="remotegw" type="text" class="formfld unknown" id="remotegw" size="20" value="<?=$pconfig['remotegw'];?>">
423
                    <br>
424
                    Enter the public IP address or host name of the remote gateway</td>
425
                </tr>
426
                <tr>
427
                  <td width="22%" valign="top" class="vncell">Description</td>
428
                  <td width="78%" class="vtable">
429
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
430
                    <br> <span class="vexpl">You may enter a description here
431
                    for your reference (not parsed).</span></td>
432
                </tr>
433
                <tr>
434
                  <td colspan="2" class="list" height="12"></td>
435
                </tr>
436
                <tr>
437
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal
438
                    (Authentication)</td>
439
                </tr>
440
                <tr>
441
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
442
                  <td width="78%" class="vtable">
443
					<select name="p1mode" class="formfld unknown">
444
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
445
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>>
446
                      <?=htmlspecialchars($mode);?>
447
                      </option>
448
                      <?php endforeach; ?>
449
                    </select> <br> <span class="vexpl">Aggressive is faster, but
450
                    less secure.</span></td>
451
                </tr>
452
                <tr>
453
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
454
                  <td width="78%" class="vtable">
455
					<select name="p1myidentt" class="formselect">
456
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
457
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>>
458
                      <?=htmlspecialchars($modename);?>
459
                      </option>
460
                      <?php endforeach; ?>
461
                    </select> <input name="p1myident" type="text" class="formfld unknown" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>">
462
                  </td>
463
                </tr>
464
                <tr>
465
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
466
                  <td width="78%" class="vtable">
467
					<select name="p1ealgo" class="formselect">
468
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
469
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>>
470
                      <?=htmlspecialchars($algoname);?>
471
                      </option>
472
                      <?php endforeach; ?>
473
                    </select> <br> <span class="vexpl">Must match the setting
474
                    chosen on the remote side. </span></td>
475
                </tr>
476
                <tr>
477
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
478
                  <td width="78%" class="vtable">
479
					<select name="p1halgo" class="formselect">
480
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
481
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>>
482
                      <?=htmlspecialchars($algoname);?>
483
                      </option>
484
                      <?php endforeach; ?>
485
                    </select> <br> <span class="vexpl">Must match the setting
486
                    chosen on the remote side. </span></td>
487
                </tr>
488
                <tr>
489
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
490
                  <td width="78%" class="vtable">
491
					<select name="p1dhgroup" class="formselect">
492
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
493
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>>
494
                      <?=htmlspecialchars($keygroup);?>
495
                      </option>
496
                      <?php endforeach; ?>
497
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024
498
                    bit, 5 = 1536 bit</em><br>
499
                    Must match the setting chosen on the remote side. </span></td>
500
                </tr>
501
                <tr>
502
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
503
                  <td width="78%" class="vtable">
504
                    <input name="p1lifetime" type="text" class="formfld unknown" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
505
                    seconds</td>
506
                </tr>
507
                <tr>
508
                  <td width="22%" valign="top" class="vncellreq">Authentication method</td>
509
                  <td width="78%" class="vtable">
510
					<select name="p1authentication_method" class="formselect" onChange="methodsel_change()">
511
                      <?php foreach ($p1_authentication_methods as $method => $methodname): ?>
512
                      <option value="<?=$method;?>" <?php if ($method == $pconfig['p1authentication_method']) echo "selected"; ?>>
513
                      <?=htmlspecialchars($methodname);?>
514
                      </option>
515
                      <?php endforeach; ?>
516
                    </select> <br> <span class="vexpl">Must match the setting
517
                    chosen on the remote side.</span></td>
518
                </tr>
519
                <tr>
520
                  <td width="22%" valign="top" class="vncellreq">Pre-Shared Key</td>
521
                  <td width="78%" class="vtable">
522
                    <?=$mandfldhtml;?><input name="p1pskey" type="text" class="formfld unknown" id="p1pskey" size="40" value="<?=htmlspecialchars($pconfig['p1pskey']);?>">
523
                  </td>
524
                </tr>
525
                <tr>
526
                  <td width="22%" valign="top" class="vncellreq">Certificate</td>
527
                  <td width="78%" class="vtable">
528
                    <textarea name="p1cert" cols="65" rows="7" id="p1cert" class="formpre"><?=htmlspecialchars($pconfig['p1cert']);?></textarea>
529
                    <br>
530
                    Paste a certificate in X.509 PEM format here.</td>
531
                </tr>
532
                <tr>
533
                  <td width="22%" valign="top" class="vncellreq">Key</td>
534
                  <td width="78%" class="vtable">
535
                    <textarea name="p1privatekey" cols="65" rows="7" id="p1privatekey" class="formpre"><?=htmlspecialchars($pconfig['p1privatekey']);?></textarea>
536
                    <br>
537
                    Paste an RSA private key in PEM format here.</td>
538
                </tr>
539
                <tr>
540
                  <td width="22%" valign="top" class="vncell">Peer certificate</td>
541
                  <td width="78%" class="vtable">
542
                    <textarea name="p1peercert" cols="65" rows="7" id="p1peercert" class="formpre"><?=htmlspecialchars($pconfig['p1peercert']);?></textarea>
543
                    <br>
544
                    Paste the peer X.509 certificate in PEM format here.<br>
545
                    Leave this blank if you want to use a CA certificate for identity validation.</td>
546
                </tr>
547
                <tr>
548
                  <td colspan="2" class="list" height="12"></td>
549
                </tr>
550
                <tr>
551
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal
552
                    (SA/Key Exchange)</td>
553
                </tr>
554
                <tr>
555
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
556
                  <td width="78%" class="vtable">
557
					<select name="p2proto" class="formselect">
558
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
559
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>>
560
                      <?=htmlspecialchars($protoname);?>
561
                      </option>
562
                      <?php endforeach; ?>
563
                    </select> <br> <span class="vexpl">ESP is encryption, AH is
564
                    authentication only </span></td>
565
                </tr>
566
                <tr>
567
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
568
                  <td width="78%" class="vtable">
569
                    <?php foreach ($p2_ealgos as $algo => $algoname): ?>
570
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>>
571
                    <?=htmlspecialchars($algoname);?>
572
                    <br>
573
                    <?php endforeach; ?>
574
                    <br>
575
                    Hint: use 3DES for best compatibility or if you have a hardware
576
                    crypto accelerator card. Blowfish is usually the fastest in
577
                    software encryption. </td>
578
                </tr>
579
                <tr>
580
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
581
                  <td width="78%" class="vtable">
582
                    <?php foreach ($p2_halgos as $algo => $algoname): ?>
583
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>>
584
                    <?=htmlspecialchars($algoname);?>
585
                    <br>
586
                    <?php endforeach; ?>
587
				  </td>
588
                </tr>
589
                <tr>
590
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
591
                  <td width="78%" class="vtable">
592
					<select name="p2pfsgroup" class="formselect">
593
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
594
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>>
595
                      <?=htmlspecialchars($keygroupname);?>
596
                      </option>
597
                      <?php endforeach; ?>
598
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024
599
                    bit, 5 = 1536 bit</em></span></td>
600
                </tr>
601
                <tr>
602
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
603
                  <td width="78%" class="vtable">
604
                    <input name="p2lifetime" type="text" class="formfld unknown" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
605
                    seconds</td>
606
                </tr>
607
                <tr>
608
                  <td colspan="2" class="list" height="12"></td>
609
                </tr>
610
                <tr>
611
                  <td colspan="2" valign="top" class="listtopic">Keep alive</td>
612
                </tr>
613
                <tr>
614
                  <td width="22%" valign="top" class="vncell">Automatically ping host</td>
615
                  <td width="78%" class="vtable">
616
                    <input name="pinghost" type="text" class="formfld unknown" id="pinghost" size="20" value="<?=$pconfig['pinghost'];?>"> IP address</td>
617
                </tr>
618
                <tr>
619
                  <td width="22%" valign="top">&nbsp;</td>
620
                  <td width="78%">
621
                    <input name="Submit" type="submit" class="formbtn" value="Save">
622
                    <?php if (isset($id) && $a_ipsec[$id]): ?>
623
                    <input name="id" type="hidden" value="<?=$id;?>">
624
                    <?php endif; ?>
625
                  </td>
626
                </tr>
627
              </table>
628
</form>
629
<script language="JavaScript">
630
<!--
631
typesel_change();
632
methodsel_change();
633
//-->
634
</script>
635
<?php include("fend.inc"); ?>
636

    
637

    
638
<?php
639

    
640
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
641

    
642
        if ($adr['network'])
643
                $padr = $adr['network'];
644
        else if ($adr['address']) {
645
                list($padr, $pmask) = explode("/", $adr['address']);
646
                if (is_null($pmask))
647
                        $pmask = 32;
648
        }
649
}
650

    
651
?>
(165-165/186)