1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
<?php
/*
vpn_ipsec_phase2.php
part of m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2008 Shrew Soft Inc
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require("guiconfig.inc");
if (!is_array($config['ipsec']['phase2']))
$config['ipsec']['phase2'] = array();
$a_phase2 = &$config['ipsec']['phase2'];
if($config['interfaces']['lan'])
$specialsrcdst = explode(" ", "lan");
$p2index = $_GET['p2index'];
if (isset($_POST['p2index']))
$p2index = $_POST['p2index'];
if (isset($_GET['dup']))
$p2index = $_GET['dup'];
if (isset($p2index) && $a_phase2[$p2index])
{
$pconfig['ikeid'] = $a_phase2[$p2index]['ikeid'];
$pconfig['disabled'] = isset($a_phase2[$p2index]['disabled']);
$pconfig['descr'] = $a_phase2[$p2index]['descr'];
idinfo_to_pconfig("local",$a_phase2[$p2index]['localid'],$pconfig);
idinfo_to_pconfig("remote",$a_phase2[$p2index]['remoteid'],$pconfig);
$pconfig['proto'] = $a_phase2[$p2index]['protocol'];
ealgos_to_pconfig($a_phase2[$p2index]['encryption-algorithm-option'],$pconfig);
$pconfig['halgos'] = $a_phase2[$p2index]['hash-algorithm-option'];
$pconfig['pfsgroup'] = $a_phase2[$p2index]['pfsgroup'];
$pconfig['lifetime'] = $a_phase2[$p2index]['lifetime'];
}
else
{
$pconfig['ikeid'] = $_GET['ikeid'];
/* defaults */
$pconfig['localid_type'] = "lan";
$pconfig['remoteid_type'] = "network";
$pconfig['proto'] = "esp";
$pconfig['ealgos'] = explode(",", "3des,blowfish,cast128,aes");
$pconfig['halgos'] = explode(",", "hmac_sha1,hmac_md5");
$pconfig['pfsgroup'] = "0";
$pconfig['lifetime'] = "3600";
}
if (isset($_GET['dup']))
unset($p2index);
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
$ealgos = pconfig_to_ealgos($pconfig);
$localid = pconfig_to_idinfo("local",$pconfig);
$remoteid = pconfig_to_idinfo("remote",$pconfig);
if (!isset( $_POST['ikeid']))
$input_errors[] = "A valid ikeid must be specified.";
/* input validation */
$reqdfields = explode(" ", "localid_type remoteid_type halgos");
$reqdfieldsn = explode(",", "Local network type,Remote network type,P2 Hash Algorithms");
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
switch ($_POST['localid_type']) {
case "network":
if (!$_POST['localid_netbits'] || !is_numeric($_POST['localid_netbits']))
$input_errors[] = "A valid local network bit count must be specified..";
case "address":
if (!$_POST['localid_address'] || !is_ipaddr($_POST['localid_address']))
$input_errors[] = "A valid local network IP address must be specified.";
break;
}
switch ($_POST['remoteid_type']) {
case "network":
if (!$_POST['remoteid_netbits'] || !is_numeric($_POST['remoteid_netbits']))
$input_errors[] = "A valid remote network bit count must be specified..";
case "address":
if (!$_POST['remoteid_address'] || !is_ipaddr($_POST['remoteid_address']))
$input_errors[] = "A valid remote network IP address must be specified.";
break;
}
/* TODO : Validate enabled phase2's are not duplicates */
if (!count($ealgos)) {
$input_errors[] = "At least one encryption algorithm must be selected.";
}
if (($_POST['lifetime'] && !is_numeric($_POST['lifetime']))) {
$input_errors[] = "The P2 lifetime must be an integer.";
}
if (!$input_errors) {
$ph2ent['ikeid'] = $_POST['ikeid'];
$ph2ent['disabled'] = $_POST['disabled'] ? true : false;
$ph2ent['localid'] = $localid;
$ph2ent['remoteid'] = $remoteid;
$ph2ent['protocol'] = $_POST['proto'];
$ph2ent['encryption-algorithm-option'] = $ealgos;
$ph2ent['hash-algorithm-option'] = $_POST['halgos'];
$ph2ent['pfsgroup'] = $_POST['pfsgroup'];
$ph2ent['lifetime'] = $_POST['lifetime'];
$ph2ent['descr'] = $_POST['descr'];
if (isset($p2index) && $a_phase2[$p2index])
$a_phase2[$p2index] = $ph2ent;
else
$a_phase2[] = $ph2ent;
write_config();
touch($d_ipsecconfdirty_path);
header("Location: vpn_ipsec.php");
exit;
}
}
$pgtitle = array("VPN","IPsec","Edit Phase 2");
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<script language="JavaScript">
<!--
function typesel_change_local(bits) {
if (!bits)
bits = 24;
switch (document.iform.localid_type.selectedIndex) {
case 0: /* single */
document.iform.localid_address.disabled = 0;
document.iform.localid_netbits.value = 0;
document.iform.localid_netbits.disabled = 1;
break;
case 1: /* network */
document.iform.localid_address.disabled = 0;
document.iform.localid_netbits.value = bits;
document.iform.localid_netbits.disabled = 0;
break;
default:
document.iform.localid_address.value = "";
document.iform.localid_address.disabled = 1;
document.iform.localid_netbits.value = 0;
document.iform.localid_netbits.disabled = 1;
break;
}
}
function typesel_change_remote(bits) {
if (!bits)
bits = 24;
switch (document.iform.remoteid_type.selectedIndex) {
case 0: /* single */
document.iform.remoteid_address.disabled = 0;
document.iform.remoteid_netbits.value = 0;
document.iform.remoteid_netbits.disabled = 1;
break;
case 1: /* network */
document.iform.remoteid_address.disabled = 0;
document.iform.remoteid_netbits.value = bits;
document.iform.remoteid_netbits.disabled = 0;
break;
default:
document.iform.remoteid_address.value = "";
document.iform.remoteid_address.disabled = 1;
document.iform.remoteid_netbits.value = 0;
document.iform.remoteid_netbits.disabled = 1;
break;
}
}
//-->
</script>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<form action="vpn_ipsec_phase2.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td width="22%" valign="top" class="vncellreq">Mode</td>
<td width="78%" class="vtable"> Tunnel</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Disabled</td>
<td width="78%" class="vtable">
<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
<strong>Disable this phase2 entry</strong><br>
<span class="vexpl">Set this option to disable this phase2 entry without
removing it from the list.
</span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Local Network</td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Type: </td>
<td></td>
<td>
<select name="localid_type" class="formselect" onChange="typesel_change_local()">
<option value="address" <?php if ($pconfig['localid_type'] == "address") echo "selected";?>>Address</option>
<option value="network" <?php if ($pconfig['localid_type'] == "network") echo "selected";?>>Network</option>
<option value="lan" <?php if ($pconfig['localid_type'] == "lan" ) echo "selected";?>>LAN subnet</option>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><?=$mandfldhtmlspc;?></td>
<td>
<input name="localid_address" type="text" class="formfld unknown" id="localid_address" size="20" value="<?=$pconfig['localid_address'];?>">
/
<select name="localid_netbits" class="formselect" id="localid_netbits">
<?php for ($i = 32; $i >= 0; $i--): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['localid_netbits']) echo "selected"; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<td width="22%" valign="top" class="vncellreq">Remote Network</td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Type: </td>
<td></td>
<td>
<select name="remoteid_type" class="formselect" onChange="typesel_change_remote()">
<option value="address" <?php if ($pconfig['remoteid_type'] == "address") echo "selected"; ?>>Address</option>
<option value="network" <?php if ($pconfig['remoteid_type'] == "network") echo "selected"; ?>>Network</option>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><?=$mandfldhtmlspc;?></td>
<td>
<input name="remoteid_address" type="text" class="formfld unknown" id="remoteid_address" size="20" value="<?=$pconfig['remoteid_address'];?>">
/
<select name="remoteid_netbits" class="formselect" id="remoteid_netbits">
<?php for ($i = 32; $i >= 0; $i--): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['remoteid_netbits']) echo "selected"; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Description</td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
<br> <span class="vexpl">You may enter a description here
for your reference (not parsed).</span>
</td>
</tr>
<tr>
<td colspan="2" class="list" height="12"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic">Phase 2 proposal
(SA/Key Exchange)
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Protocol</td>
<td width="78%" class="vtable">
<select name="proto" class="formselect">
<?php foreach ($p2_protos as $proto => $protoname): ?>
<option value="<?=$proto;?>" <?php if ($proto == $pconfig['proto']) echo "selected"; ?>>
<?=htmlspecialchars($protoname);?>
</option>
<?php endforeach; ?>
</select>
<br>
<span class="vexpl">ESP is encryption, AH is authentication only </span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="0">
<?php
foreach ($p2_ealgos as $algo => $algodata):
$checked = '';
if (in_array($algo,$pconfig['ealgos']))
$checked = " checked";
?>
<tr>
<td>
<input type="checkbox" name="ealgos[]?>" value="<?=$algo;?>"<?=$checked?>>
</td>
<td>
<?=htmlspecialchars($algodata['name']);?>
</td>
<td>
<?php if(is_array($algodata['keysel'])): ?>
<select name="keylen_<?=$algo;?>" class="formselect">
<option value="auto">auto</option>
<?php
$key_hi = $algodata['keysel']['hi'];
$key_lo = $algodata['keysel']['lo'];
$key_step = $algodata['keysel']['step'];
for ($keylen = $key_hi; $keylen >= $key_lo; $keylen -= $key_step):
$selected = '';
// if ($checked && in_array("keylen_".$algo,$pconfig))
if ($keylen == $pconfig["keylen_".$algo])
$selected = " selected";
?>
<option value="<?=$keylen;?>"<?=$selected;?>><?=$keylen;?> bits</option>
<?php endfor; ?>
</select>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<br>
Hint: use 3DES for best compatibility or if you have a hardware
crypto accelerator card. Blowfish is usually the fastest in
software encryption.
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
<td width="78%" class="vtable">
<?php foreach ($p2_halgos as $algo => $algoname): ?>
<input type="checkbox" name="halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['halgos'])) echo "checked"; ?>>
<?=htmlspecialchars($algoname);?>
<br>
<?php endforeach; ?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">PFS key group</td>
<td width="78%" class="vtable">
<select name="pfsgroup" class="formselect">
<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['pfsgroup']) echo "selected"; ?>>
<?=htmlspecialchars($keygroupname);?>
</option>
<?php endforeach; ?>
</select>
<br>
<span class="vexpl"><em>1 = 768 bit, 2 = 1024 bit, 5 = 1536 bit</em></span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Lifetime</td>
<td width="78%" class="vtable">
<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="20" value="<?=$pconfig['lifetime'];?>">
seconds
</td>
</tr>
<tr>
<td width="22%" valign="top"> </td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="Save">
<input name="ikeid" type="hidden" value="<?=$pconfig['ikeid'];?>">
<?php if (isset($p2index) && $a_phase2[$p2index]): ?>
<input name="p2index" type="hidden" value="<?=$p2index;?>">
<?php endif; ?>
</td>
</tr>
</table>
</form>
<script lannguage="JavaScript">
<!--
typesel_change_local(<?=$pconfig['localid_netbits']?>);
typesel_change_remote(<?=$pconfig['remoteid_netbits']?>);
//-->
</script>
<?php include("fend.inc"); ?>
<?php
function pconfig_to_ealgos(& $pconfig) {
global $p2_ealgos;
$ealgos = array();
foreach ($p2_ealgos as $algo_name => $algo_data) {
if (in_array($algo_name,$pconfig['ealgos'])) {
$ealg = array();
$ealg['name'] = $algo_name;
if (is_array($algo_data['keysel']))
$ealg['keylen'] = $_POST["keylen_".$algo_name];
$ealgos[] = $ealg;
}
}
return $ealgos;
}
function ealgos_to_pconfig(& $ealgos,& $pconfig) {
$pconfig['ealgos'] = array();
foreach ($ealgos as $algo_data) {
$pconfig['ealgos'][] = $algo_data['name'];
if (isset($algo_data['keylen']))
$pconfig["keylen_".$algo_data['name']] = $algo_data['keylen'];
}
return $ealgos;
}
function pconfig_to_idinfo($prefix,& $pconfig) {
$type = $pconfig[$prefix."id_type"];
$address = $pconfig[$prefix."id_address"];
$netbits = $pconfig[$prefix."id_netbits"];
switch( $type )
{
case "address":
return array('type' => $type, 'address' => $address);
case "network":
return array('type' => $type, 'address' => $address, 'netbits' => $netbits);
default:
return array('type' => $type );
}
}
function idinfo_to_pconfig($prefix,& $idinfo,& $pconfig) {
switch( $idinfo['type'] )
{
case "address":
$pconfig[$prefix."id_type"] = $idinfo['type'];
$pconfig[$prefix."id_address"] = $idinfo['address'];
break;
case "network":
$pconfig[$prefix."id_type"] = $idinfo['type'];
$pconfig[$prefix."id_address"] = $idinfo['address'];
$pconfig[$prefix."id_netbits"] = $idinfo['netbits'];
break;
default:
$pconfig[$prefix."id_type"] = $idinfo['type'];
break;
}
}
?>
|