Project

General

Profile

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

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

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

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

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

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

    
31
require("guiconfig.inc");
32

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
230
	if ($_POST['p1myidentt'] == "myaddress")
231
		$_POST['p1myident'] = "";
232

    
233
	if (!$input_errors) {
234
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
235
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
236
		$ipsecent['interface'] = $pconfig['interface'];
237
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
238
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
239
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
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 'asn1dn':
257
				$ipsecent['p1']['myident']['asn1dn'] = $_POST['p1myident'];
258
				break;
259
			case 'dyn_dns':
260
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
261
				break;
262
		}
263

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

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

    
286
		write_config();
287
		touch($d_ipsecconfdirty_path);
288

    
289
		header("Location: vpn_ipsec.php");
290
		exit;
291
	}
292
}
293

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

    
297
?>
298

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

    
639

    
640
<?php
641

    
642
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
643

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

    
653
?>
(165-165/186)