Project

General

Profile

Download (29.6 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['auto'] = isset($a_ipsec[$id]['auto']);
52

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

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

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

    
66
	$pconfig['p1mode'] = $a_ipsec[$id]['p1']['mode'];
67

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

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

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

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

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

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

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

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

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

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

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

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

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

    
205
	if ($_POST['p1myidentt'] == "myaddress")
206
		$_POST['p1myident'] = "";
207

    
208
	if (!$input_errors) {
209
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
210
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
211
		$ipsecent['interface'] = $pconfig['interface'];
212
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
213
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
214

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

    
232
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
233
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
234

    
235
		$ipsecent['p1']['myident'] = array();
236
		switch ($_POST['p1myidentt']) {
237
			case 'myaddress':
238
				$ipsecent['p1']['myident']['myaddress'] = true;
239
				break;
240
			case 'address':
241
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
242
				break;
243
			case 'fqdn':
244
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
245
				break;
246
			case 'user_fqdn':
247
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
248
				break;
249
			case 'dyn_dns':
250
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
251
				break;
252
		}
253

    
254
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
255
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
256
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
257
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
258
		$ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey'];
259
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
260
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
261
		$ipsecent['p1']['peercert'] = base64_encode($_POST['p1peercert']);
262
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
263
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
264
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
265
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
266
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
267
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
268
		$ipsecent['descr'] = $_POST['descr'];
269
		$ipsecent['pinghost'] = $_POST['pinghost'];
270

    
271
		if (isset($id) && $a_ipsec[$id])
272
			$a_ipsec[$id] = $ipsecent;
273
		else
274
			$a_ipsec[] = $ipsecent;
275

    
276
		write_config();
277
		reload_tunnel_spd_policy($ipsecent, $oldipsecent);
278
		touch($d_ipsecconfdirty_path);
279

    
280
		header("Location: vpn_ipsec.php");
281
		exit;
282
	}
283
}
284

    
285
$pgtitle = "VPN: IPsec: Edit tunnel";
286
include("head.inc");
287

    
288
?>
289

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

    
631

    
632
<?php
633

    
634
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
635

    
636
        if ($adr['network'])
637
                $padr = $adr['network'];
638
        else if ($adr['address']) {
639
                list($padr, $pmask) = explode("/", $adr['address']);
640
                if (is_null($pmask))
641
                        $pmask = 32;
642
        }
643
}
644

    
645
?>
(152-152/173)