Project

General

Profile

Download (30.9 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
	$oldipsecent = $a_ipsec[$id];
50
	$pconfig['disabled'] = isset($a_ipsec[$id]['disabled']);
51
	$pconfig['natt'] = isset($a_ipsec[$id]['natt']);
52
	$pconfig['auto'] = isset($a_ipsec[$id]['auto']);
53

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

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

    
64
	list($pconfig['remotenet'],$pconfig['remotebits']) = explode("/", $a_ipsec[$id]['remote-subnet']);
65
	$pconfig['remotegw'] = $a_ipsec[$id]['remote-gateway'];
66
	$pconfig['dpddelay'] = $a_ipsec[$id]['dpddelay'];
67

    
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']['dyn_dns'])) {
82
		$pconfig['p1myidentt'] = 'dyn_dns';
83
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['dyn_dns'];
84
	}
85

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

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

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

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

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

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

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

    
152
	if (!is_specialnet($_POST['localnettype'])) {
153
		if (($_POST['localnet'] && !is_ipaddr($_POST['localnet']))) {
154
			$input_errors[] = "A valid local network IP address must be specified.";
155
		}
156
		if (($_POST['localnetmask'] && !is_numeric($_POST['localnetmask']))) {
157
			$input_errors[] = "A valid local network bit count must be specified.";
158
		}
159
	}
160
	if (($_POST['dpddelay'] && !is_numeric($_POST['dpddelay']))) {
161
		$input_errors[] = "The DPD interval delay must be an integer.";
162
	}
163
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
164
		$input_errors[] = "The P1 lifetime must be an integer.";
165
	}
166
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
167
		$input_errors[] = "The P2 lifetime must be an integer.";
168
	}
169
	if ($_POST['remotebits'] && (!is_numeric($_POST['remotebits']) || ($_POST['remotebits'] < 0) || ($_POST['remotebits'] > 32))) {
170
		if(!$_POST['remotebits'] == "0.0.0.0")
171
			$input_errors[] = "The remote network bits are invalid.";
172
	}
173
	if (($_POST['remotenet'] && !is_ipaddr($_POST['remotenet'])) or $_POST['remotenet'] == "0.0.0.0") {
174
		/* allow 0.0.0.0 remote net usage */
175
		if($_POST['remotenet'] <> "0.0.0.0")
176
		$input_errors[] = "A valid remote network address must be specified.";
177
	}
178
	if (($_POST['remotegw'] && !is_ipaddr($_POST['remotegw']))) {
179
		if(is_domain($_POST['remotegw']) == false)
180
			$input_errors[] = "A valid remote gateway address must be specified.";
181
	}
182
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
183
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
184
	}
185
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
186
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
187
	}
188
	if ($_POST['p1myidentt'] == "user_fqdn") {
189
		$ufqdn = explode("@",$_POST['p1myident']);
190
		if (is_domain($ufqdn[1]) == false)
191
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
192
	}
193
	if ($_POST['p1myidentt'] == "dyn_dns") {
194
		if (is_domain($_POST['p1myidentt']) == false)
195
			$input_errors[] = "A valid Dynamic DNS address for 'My identifier' must be specified.";
196
	}
197

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

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

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

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

    
210
	if ($_POST['p1myidentt'] == "myaddress")
211
		$_POST['p1myident'] = "";
212

    
213
	if (!$input_errors) {
214
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
215
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
216
		$ipsecent['interface'] = $pconfig['interface'];
217
		$ipsecent['natt'] = $_POST['natt'] ? true : false;
218
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
219
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
220

    
221
		/* if the old endpoint is different from the new one we make sure to purge
222
		 * the old policy and add a new one. If the old endpoint IP is empty we 
223
		 * only add new SPD entries. */
224
		if(!is_ipaddr($oldipsecent['remote-gateway'])) {
225
			$oldipsecent['remote-gateway'] = resolve_retry($oldipsecent['remote-gateway']);
226
		}
227
		if($ipsecent['remote-gateway'] <> $_POST['remotegw']) {
228
			if(!is_ipaddr($ipsecent['remote-gateway'])) {
229
				$ipsecent['remote-gateway'] = resolve_retry($ipsecent['remote-gateway']);
230
			}
231
			/* if the remote gateway changed and the interface is not WAN then remove route */
232
			/* the vpn_ipsec_configure() handles adding the route */
233
			if($_POST['interface'] <> "wan") {
234
				mwexec("/sbin/route delete -host {$ipsecent['remote-gateway']}");
235
			}
236
		}
237

    
238
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
239
		$ipsecent['dpddelay'] = $_POST['dpddelay'];
240
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
241

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

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

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

    
283
		write_config();
284
		reload_tunnel_spd_policy($ipsecent, $oldipsecent);
285
		touch($d_ipsecconfdirty_path);
286

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

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

    
655

    
656
<?php
657

    
658
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
659

    
660
        if ($adr['network'])
661
                $padr = $adr['network'];
662
        else if ($adr['address']) {
663
                list($padr, $pmask) = explode("/", $adr['address']);
664
                if (is_null($pmask))
665
                        $pmask = 32;
666
        }
667
}
668

    
669
?>
(155-155/176)