Project

General

Profile

Download (30.3 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
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
243
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
244

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

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

    
284
		if (isset($id) && $a_ipsec[$id])
285
			$a_ipsec[$id] = $ipsecent;
286
		else
287
			$a_ipsec[] = $ipsecent;
288

    
289
		write_config();
290
		touch($d_ipsecconfdirty_path);
291

    
292
		header("Location: vpn_ipsec.php");
293
		exit;
294
	}
295
}
296

    
297
$pgtitle = array("VPN","IPsec","Edit tunnel");
298
include("head.inc");
299

    
300
?>
301

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

    
647

    
648
<?php
649

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

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

    
661
?>
(169-169/193)