Project

General

Profile

Download (30.4 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
if($config['interfaces']['lan']) 
39
		$specialsrcdst = explode(" ", "lan");
40

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

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

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

    
53
	if (!isset($a_ipsec[$id]['local-subnet'])) {
54
		if($config['interfaces']['lan']) 
55
			$pconfig['localnet'] = "lan";
56
	} else {
57
		if($config['interfaces']['lan']) 
58
			address_to_pconfig_vpn($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask']);
59
	}
60
	
61
	if ($a_ipsec[$id]['interface'])
62
		$pconfig['interface'] = $a_ipsec[$id]['interface'];
63
	else
64
		$pconfig['interface'] = "wan";
65

    
66
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_ipsec[$id]['remote-subnet']);
67
	$pconfig['remotegw'] = $a_ipsec[$id]['remote-gateway'];
68
	$pconfig['p1mode'] = $a_ipsec[$id]['p1']['mode'];
69

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

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

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

    
124
if (isset($_GET['dup']))
125
	unset($id);
126

    
127
if ($_POST) {
128
	if (is_specialnet($_POST['localnettype'])) {
129
		$_POST['localnet'] = $_POST['localnettype'];
130
		$_POST['localnetmask'] = 0;
131
	} else if ($_POST['localnettype'] == "single") {
132
		$_POST['localnetmask'] = 32;
133
	}
134

    
135
	unset($input_errors);
136
	$pconfig = $_POST;
137

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

    
154
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
155

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

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

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

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

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

    
233
	if ($_POST['p1myidentt'] == "myaddress")
234
		$_POST['p1myident'] = "";
235

    
236
	if (!$input_errors) {
237
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
238
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
239
		$ipsecent['interface'] = $pconfig['interface'];
240
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
241
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
242
		/* if the remote gateway changed and the interface is not WAN then remove route */
243
		/* the vpn_ipsec_configure() handles adding the route */
244
		if($_POST['interface'] <> "wan") {
245
			if($ipsecent['remote-gateway'] <> $_POST['remotegw']) {
246
				mwexec("/sbin/route delete -host {$ipsecent['remote-gateway']}");
247
			}
248
		}
249
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
250
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
251

    
252
		$ipsecent['p1']['myident'] = array();
253
		switch ($_POST['p1myidentt']) {
254
			case 'myaddress':
255
				$ipsecent['p1']['myident']['myaddress'] = true;
256
				break;
257
			case 'address':
258
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
259
				break;
260
			case 'fqdn':
261
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
262
				break;
263
			case 'user_fqdn':
264
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
265
				break;
266
			case 'asn1dn':
267
				$ipsecent['p1']['myident']['asn1dn'] = $_POST['p1myident'];
268
				break;
269
			case 'dyn_dns':
270
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
271
				break;
272
		}
273

    
274
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
275
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
276
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
277
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
278
		$ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey'];
279
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
280
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
281
		$ipsecent['p1']['peercert'] = base64_encode($_POST['p1peercert']);
282
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
283
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
284
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
285
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
286
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
287
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
288
		$ipsecent['descr'] = $_POST['descr'];
289
		$ipsecent['pinghost'] = $_POST['pinghost'];
290

    
291
		if (isset($id) && $a_ipsec[$id])
292
			$a_ipsec[$id] = $ipsecent;
293
		else
294
			$a_ipsec[] = $ipsecent;
295

    
296
		write_config();
297
		touch($d_ipsecconfdirty_path);
298

    
299
		header("Location: vpn_ipsec.php");
300
		exit;
301
	}
302
}
303

    
304
$pgtitle = array("VPN","IPsec","Edit tunnel");
305
include("head.inc");
306

    
307
?>
308

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

    
648

    
649
<?php
650

    
651
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
652

    
653
        if ($adr['network'])
654
                $padr = $adr['network'];
655
        else if ($adr['address']) {
656
                list($padr, $pmask) = explode("/", $adr['address']);
657
                if (is_null($pmask))
658
                        $pmask = 32;
659
        }
660
}
661

    
662
?>
(173-173/197)