Project

General

Profile

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

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

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

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

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

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

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['ipsec']['phase2']))
35
	$config['ipsec']['phase2'] = array();
36

    
37
$a_phase2 = &$config['ipsec']['phase2'];
38

    
39
if($config['interfaces']['lan'])
40
	$specialsrcdst = explode(" ", "lan");
41

    
42
$p2index = $_GET['p2index'];
43
if (isset($_POST['p2index']))
44
	$p2index = $_POST['p2index'];
45

    
46
if (isset($_GET['dup']))
47
	$p2index = $_GET['dup'];
48

    
49
if (isset($p2index) && $a_phase2[$p2index])
50
{
51
	$pconfig['ikeid'] = $a_phase2[$p2index]['ikeid'];
52
	$pconfig['disabled'] = isset($a_phase2[$p2index]['disabled']);
53
	$pconfig['descr'] = $a_phase2[$p2index]['descr'];
54

    
55
	idinfo_to_pconfig("local",$a_phase2[$p2index]['localid'],$pconfig);
56
	idinfo_to_pconfig("remote",$a_phase2[$p2index]['remoteid'],$pconfig);
57

    
58
	$pconfig['proto'] = $a_phase2[$p2index]['protocol'];
59
	ealgos_to_pconfig($a_phase2[$p2index]['encryption-algorithm-option'],$pconfig);
60
	$pconfig['halgos'] = $a_phase2[$p2index]['hash-algorithm-option'];
61
	$pconfig['pfsgroup'] = $a_phase2[$p2index]['pfsgroup'];
62
	$pconfig['lifetime'] = $a_phase2[$p2index]['lifetime'];
63
}
64
else
65
{
66
	$pconfig['ikeid'] = $_GET['ikeid'];
67

    
68
	/* defaults */
69
	$pconfig['localid_type'] = "lan";
70
	$pconfig['remoteid_type'] = "network";
71
	$pconfig['proto'] = "esp";
72
	$pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes");
73
	$pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5");
74
	$pconfig['pfsgroup'] = "0";
75
	$pconfig['lifetime'] = "3600";
76
}
77

    
78
if (isset($_GET['dup']))
79
	unset($p2index);
80

    
81
if ($_POST) {
82

    
83
	unset($input_errors);
84
	$pconfig = $_POST;
85

    
86
	$ealgos = pconfig_to_ealgos($pconfig);
87
	$localid = pconfig_to_idinfo("local",$pconfig);
88
	$remoteid = pconfig_to_idinfo("remote",$pconfig);
89

    
90
	if (!isset( $_POST['ikeid']))
91
		$input_errors[] = "A valid ikeid must be specified.";
92

    
93
	/* input validation */
94
	$reqdfields = explode(" ", "localid_type remoteid_type halgos");
95
	$reqdfieldsn = explode(",", "Local network type,Remote network type,P2 Hash Algorithms");
96

    
97
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
98

    
99
	switch ($_POST['localid_type']) {
100
		case "network":
101
			if (!$_POST['localid_netbits'] || !is_numeric($_POST['localid_netbits']))
102
				$input_errors[] = "A valid local network bit count must be specified..";
103
		case "address":
104
			if (!$_POST['localid_address'] || !is_ipaddr($_POST['localid_address']))
105
				$input_errors[] = "A valid local network IP address must be specified.";
106
			break;
107
	}
108

    
109
	switch ($_POST['remoteid_type']) {
110
		case "network":
111
			if (!$_POST['remoteid_netbits'] || !is_numeric($_POST['remoteid_netbits']))
112
				$input_errors[] = "A valid remote network bit count must be specified..";
113
		case "address":
114
			if (!$_POST['remoteid_address'] || !is_ipaddr($_POST['remoteid_address']))
115
				$input_errors[] = "A valid remote network IP address must be specified.";
116
			break;
117
	}
118

    
119
/* TODO : Validate enabled phase2's are not duplicates */
120

    
121
	if (!count($ealgos)) {
122
		$input_errors[] = "At least one encryption algorithm must be selected.";
123
	}
124
	if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
125
		$input_errors[] = "The P2 lifetime must be an integer.";
126
	}
127

    
128
	if (!$input_errors) {
129
		$ph2ent['ikeid'] = $_POST['ikeid'];
130
		$ph2ent['disabled'] = $_POST['disabled'] ? true : false;
131
		$ph2ent['localid'] = $localid;
132
		$ph2ent['remoteid'] = $remoteid;
133
		$ph2ent['protocol'] = $_POST['proto'];
134
		$ph2ent['encryption-algorithm-option'] = $ealgos;
135
		$ph2ent['hash-algorithm-option'] = $_POST['halgos'];
136
		$ph2ent['pfsgroup'] = $_POST['pfsgroup'];
137
		$ph2ent['lifetime'] = $_POST['lifetime'];
138
		$ph2ent['descr'] = $_POST['descr'];
139

    
140
		if (isset($p2index) && $a_phase2[$p2index])
141
			$a_phase2[$p2index] = $ph2ent;
142
		else
143
			$a_phase2[] = $ph2ent;
144

    
145
		write_config();
146
		touch($d_ipsecconfdirty_path);
147

    
148
		header("Location: vpn_ipsec.php");
149
		exit;
150
	}
151
}
152

    
153
$pgtitle = array("VPN","IPsec","Edit Phase 2");
154
include("head.inc");
155

    
156
?>
157

    
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<script language="JavaScript">
161
<!--
162
function typesel_change_local(bits) {
163

    
164
	if (!bits)
165
		bits = 24;
166

    
167
	switch (document.iform.localid_type.selectedIndex) {
168
		case 0:	/* single */
169
			document.iform.localid_address.disabled = 0;
170
			document.iform.localid_netbits.value = 0;
171
			document.iform.localid_netbits.disabled = 1;
172
			break;
173
		case 1:	/* network */
174
			document.iform.localid_address.disabled = 0;
175
			document.iform.localid_netbits.value = bits;
176
			document.iform.localid_netbits.disabled = 0;
177
			break;
178
		default:
179
			document.iform.localid_address.value = "";
180
			document.iform.localid_address.disabled = 1;
181
			document.iform.localid_netbits.value = 0;
182
			document.iform.localid_netbits.disabled = 1;
183
			break;
184
	}
185
}
186
function typesel_change_remote(bits) {
187

    
188
	if (!bits)
189
		bits = 24;
190

    
191
	switch (document.iform.remoteid_type.selectedIndex) {
192
		case 0:	/* single */
193
			document.iform.remoteid_address.disabled = 0;
194
			document.iform.remoteid_netbits.value = 0;
195
			document.iform.remoteid_netbits.disabled = 1;
196
			break;
197
		case 1:	/* network */
198
			document.iform.remoteid_address.disabled = 0;
199
			document.iform.remoteid_netbits.value = bits;
200
			document.iform.remoteid_netbits.disabled = 0;
201
			break;
202
		default:
203
			document.iform.remoteid_address.value = "";
204
			document.iform.remoteid_address.disabled = 1;
205
			document.iform.remoteid_netbits.value = 0;
206
			document.iform.remoteid_netbits.disabled = 1;
207
			break;
208
	}
209
}
210
//-->
211

    
212
</script>
213
<?php if ($input_errors) print_input_errors($input_errors); ?>
214
            <form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
215
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
216
                <tr>
217
                  <td width="22%" valign="top" class="vncellreq">Mode</td>
218
                  <td width="78%" class="vtable"> Tunnel</td>
219
                </tr>
220
                <tr>
221
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
222
                  <td width="78%" class="vtable">
223
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
224
                    <strong>Disable this phase2 entry</strong><br>
225
                    <span class="vexpl">Set this option to disable this phase2 entry without
226
                      removing it from the list.
227
                    </span>
228
                  </td>
229
                </tr>
230
                <tr>
231
                  <td width="22%" valign="top" class="vncellreq">Local Network</td>
232
                  <td width="78%" class="vtable">
233
                    <table border="0" cellspacing="0" cellpadding="0">
234
                      <tr>
235
                        <td>Type:&nbsp;&nbsp;</td>
236
                        <td></td>
237
                        <td>
238
                          <select name="localid_type" class="formselect" onChange="typesel_change_local()">
239
                            <option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>>Address</option>
240
                            <option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>>Network</option>
241
                            <option value="lan" <?php if ($pconfig['localid_type'] == "lan" ) echo "selected";?>>LAN subnet</option>
242
                          </select>
243
                        </td>
244
                      </tr>
245
                      <tr>
246
                        <td>Address:&nbsp;&nbsp;</td>
247
                        <td><?=$mandfldhtmlspc;?></td>
248
                        <td>
249
                          <input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=$pconfig['localid_address'];?>">
250
                          /
251
                          <select name="localid_netbits" class="formselect" id="localid_netbits">
252
                            <?php for ($i = 32; $i >= 0; $i--): ?>
253
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
254
                              <?=$i;?>
255
                            </option>
256
                            <?php endfor; ?>
257
                          </select>
258
                        </td>
259
                      </tr>
260
                    </table>
261
                  </td>
262
                </tr>
263
                  <td width="22%" valign="top" class="vncellreq">Remote Network</td>
264
                  <td width="78%" class="vtable">
265
                    <table border="0" cellspacing="0" cellpadding="0">
266
                      <tr>
267
                        <td>Type:&nbsp;&nbsp;</td>
268
                        <td></td>
269
                        <td>
270
                          <select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
271
                            <option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>>Address</option>
272
                            <option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>>Network</option>
273
                          </select>
274
                        </td>
275
                      </tr>
276
                      <tr>
277
                        <td>Address:&nbsp;&nbsp;</td>
278
                        <td><?=$mandfldhtmlspc;?></td>
279
                        <td>
280
                          <input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=$pconfig['remoteid_address'];?>">
281
                          /
282
                          <select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
283
                            <?php for ($i = 32; $i >= 0; $i--): ?>
284
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['remoteid_netbits']) echo "selected"; ?>>
285
                              <?=$i;?>
286
                            </option>
287
                            <?php endfor; ?>
288
                          </select>
289
                        </td>
290
                      </tr>
291
                    </table>
292
                  </td>
293
                </tr>
294
                <tr>
295
                  <td width="22%" valign="top" class="vncell">Description</td>
296
                  <td width="78%" class="vtable">
297
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
298
                    <br> <span class="vexpl">You may enter a description here
299
                    for your reference (not parsed).</span>
300
                  </td>
301
                </tr>
302
                <tr>
303
                  <td colspan="2" class="list" height="12"></td>
304
                </tr>
305
                <tr>
306
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal
307
                    (SA/Key Exchange)
308
                  </td>
309
                </tr>
310
                <tr>
311
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
312
                  <td width="78%" class="vtable">
313
                    <select name="proto" class="formselect">
314
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
315
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
316
                        <?=htmlspecialchars($protoname);?>
317
                      </option>
318
                      <?php endforeach; ?>
319
                    </select>
320
                    <br>
321
                    <span class="vexpl">ESP is encryption, AH is authentication only </span>
322
                  </td>
323
                </tr>
324
                <tr>
325
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
326
                  <td width="78%" class="vtable">
327
                    <table border="0" cellspacing="0" cellpadding="0">
328
                      <?php
329
                        foreach ($p2_ealgos as $algo => $algodata):
330
                        $checked = '';
331
                        if (in_array($algo,$pconfig['ealgos']))
332
                          $checked = " checked";
333
                      ?>
334
                      <tr>
335
                        <td>
336
                          <input type="checkbox" name="ealgos[]?>" value="<?=$algo;?>"<?=$checked?>>
337
						</td>
338
                        <td>
339
                          <?=htmlspecialchars($algodata['name']);?>
340
                        </td>
341
                        <td>
342
                          <?php if(is_array($algodata['keysel'])): ?>
343
                          &nbsp;&nbsp;
344
                          <select name="keylen_<?=$algo;?>" class="formselect">
345
                            <option value="auto">auto</option>
346
                            <?php
347
                              $key_hi = $algodata['keysel']['hi'];
348
                              $key_lo = $algodata['keysel']['lo'];
349
                              $key_step = $algodata['keysel']['step'];
350
                              for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
351
                                $selected = '';
352
//                                if ($checked && in_array("keylen_".$algo,$pconfig))
353
                                  if ($keylen == $pconfig["keylen_".$algo])
354
                                    $selected = " selected";
355
                             ?>
356
                            <option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> bits</option>
357
                            <?php endfor; ?>
358
                          </select>
359
                          <?php endif; ?>
360
                        </td>
361
                      </tr>
362
                      <?php endforeach; ?>
363
                    </table>
364
                    <br>
365
                    Hint: use 3DES for best compatibility or if you have a hardware
366
                    crypto accelerator card. Blowfish is usually the fastest in
367
                    software encryption.
368
                  </td>
369
                </tr>
370
                <tr>
371
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
372
                  <td width="78%" class="vtable">
373
                    <?php foreach ($p2_halgos as $algo => $algoname): ?>
374
                    <input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
375
                    <?=htmlspecialchars($algoname);?>
376
                    <br>
377
                    <?php endforeach; ?>
378
                  </td>
379
                </tr>
380
                <tr>
381
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
382
                  <td width="78%" class="vtable">
383
                    <select name="pfsgroup" class="formselect">
384
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
385
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
386
                        <?=htmlspecialchars($keygroupname);?>
387
                      </option>
388
                      <?php endforeach; ?>
389
                    </select>
390
                    <br>
391
                    <span class="vexpl"><em>1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit</em></span>
392
                  </td>
393
                </tr>
394
                <tr>
395
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
396
                  <td width="78%" class="vtable">
397
                    <input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
398
                    seconds
399
                  </td>
400
                </tr>
401
                <tr>
402
                  <td width="22%" valign="top">&nbsp;</td>
403
                  <td width="78%">
404
                    <input name="Submit" type="submit" class="formbtn" value="Save">
405
                    <input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
406
                    <?php if (isset($p2index) && $a_phase2[$p2index]): ?>
407
                    <input name="p2index" type="hidden" value="<?=$p2index;?>">
408
                    <?php endif; ?>
409
                  </td>
410
                </tr>
411
              </table>
412
</form>
413
<script lannguage="JavaScript">
414
<!--
415
typesel_change_local(<?=$pconfig['localid_netbits']?>);
416
typesel_change_remote(<?=$pconfig['remoteid_netbits']?>);
417
//-->
418
</script>
419
<?php include("fend.inc"); ?>
420

    
421
<?php
422

    
423
function pconfig_to_ealgos(& $pconfig) {
424

    
425
	global $p2_ealgos;
426

    
427
	$ealgos = array();
428
	foreach ($p2_ealgos as $algo_name => $algo_data) {
429
		if (in_array($algo_name,$pconfig['ealgos'])) {
430
			$ealg = array();
431
			$ealg['name'] = $algo_name;
432
			if (is_array($algo_data['keysel']))
433
				$ealg['keylen'] = $_POST["keylen_".$algo_name];
434
			$ealgos[] = $ealg;
435
		}
436
	}
437

    
438
	return $ealgos;
439
}
440

    
441
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
442

    
443
	$pconfig['ealgos'] = array();
444
	foreach ($ealgos as $algo_data) {
445
		$pconfig['ealgos'][] = $algo_data['name'];
446
		if (isset($algo_data['keylen']))
447
			$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
448
	}
449

    
450
	return $ealgos;
451
}
452

    
453
function pconfig_to_idinfo($prefix,& $pconfig) {
454

    
455
	$type = $pconfig[$prefix."id_type"];
456
	$address = $pconfig[$prefix."id_address"];
457
	$netbits = $pconfig[$prefix."id_netbits"];
458

    
459
	switch( $type )
460
	{
461
		case "address":
462
			return array('type' => $type, 'address' => $address);
463
		case "network":
464
			return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
465
		default:
466
			return array('type' => $type );
467
	}
468
}
469

    
470
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
471

    
472
	switch( $idinfo['type'] )
473
	{
474
		case "address":
475
			$pconfig[$prefix."id_type"] = $idinfo['type'];
476
			$pconfig[$prefix."id_address"] = $idinfo['address'];
477
			break;
478
		case "network":
479
			$pconfig[$prefix."id_type"] = $idinfo['type'];
480
			$pconfig[$prefix."id_address"] = $idinfo['address'];
481
			$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
482
			break;
483
		default:
484
			$pconfig[$prefix."id_type"] = $idinfo['type'];
485
			break;
486
	}
487
}
488

    
489
?>
(176-176/197)