Project

General

Profile

Download (29.1 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']['dyn_dns'])) {
78
		$pconfig['p1myidentt'] = 'dyn_dns';
79
		$pconfig['p1myident'] = $a_ipsec[$id]['p1']['myident']['dyn_dns'];
80
	}
81

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

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

    
116
if (isset($_GET['dup']))
117
	unset($id);
118

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

    
127
	unset($input_errors);
128
	$pconfig = $_POST;
129

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

    
146
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
147

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

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

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

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

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

    
203
	if ($_POST['p1myidentt'] == "myaddress")
204
		$_POST['p1myident'] = "";
205

    
206
	if (!$input_errors) {
207
		$ipsecent['disabled'] = $_POST['disabled'] ? true : false;
208
		//$ipsecent['auto'] = $_POST['auto'] ? true : false;
209
		$ipsecent['interface'] = $pconfig['interface'];
210
		pconfig_to_address($ipsecent['local-subnet'], $_POST['localnet'], $_POST['localnetmask']);
211
		$ipsecent['remote-subnet'] = $_POST['remotenet'] . "/" . $_POST['remotebits'];
212
		/* if the remote gateway changed and the interface is not WAN then remove route */
213
		/* the vpn_ipsec_configure() handles adding the route */
214
		if($_POST['interface'] <> "wan") {
215
			if($ipsecent['remote-gateway'] <> $_POST['remotegw']) {
216
				mwexec("/sbin/route delete -host {$ipsecent['remote-gateway']}");
217
			}
218
		}
219
		$ipsecent['remote-gateway'] = $_POST['remotegw'];
220
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
221

    
222
		$ipsecent['p1']['myident'] = array();
223
		switch ($_POST['p1myidentt']) {
224
			case 'myaddress':
225
				$ipsecent['p1']['myident']['myaddress'] = true;
226
				break;
227
			case 'address':
228
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
229
				break;
230
			case 'fqdn':
231
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
232
				break;
233
			case 'user_fqdn':
234
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
235
				break;
236
			case 'dyn_dns':
237
				$ipsecent['p1']['myident']['dyn_dns'] = $_POST['p1myident'];
238
				break;
239
		}
240

    
241
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
242
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
243
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
244
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
245
		$ipsecent['p1']['pre-shared-key'] = $_POST['p1pskey'];
246
		$ipsecent['p1']['private-key'] = base64_encode($_POST['p1privatekey']);
247
		$ipsecent['p1']['cert'] = base64_encode($_POST['p1cert']);
248
		$ipsecent['p1']['peercert'] = base64_encode($_POST['p1peercert']);
249
		$ipsecent['p1']['authentication_method'] = $_POST['p1authentication_method'];
250
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
251
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
252
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
253
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
254
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
255
		$ipsecent['descr'] = $_POST['descr'];
256
		$ipsecent['pinghost'] = $_POST['pinghost'];
257

    
258
		if (isset($id) && $a_ipsec[$id])
259
			$a_ipsec[$id] = $ipsecent;
260
		else
261
			$a_ipsec[] = $ipsecent;
262

    
263
		write_config();
264
		touch($d_ipsecconfdirty_path);
265

    
266
		header("Location: vpn_ipsec.php");
267
		exit;
268
	}
269
}
270

    
271
$pgtitle = "VPN: IPsec: Edit tunnel";
272
include("head.inc");
273

    
274
?>
275

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

    
617

    
618
<?php
619

    
620
function address_to_pconfig_vpn($adr, &$padr, &$pmask) {
621

    
622
        if ($adr['network'])
623
                $padr = $adr['network'];
624
        else if ($adr['address']) {
625
                list($padr, $pmask) = explode("/", $adr['address']);
626
                if (is_null($pmask))
627
                        $pmask = 32;
628
        }
629
}
630

    
631
?>
(152-152/173)