1
|
<?php
|
2
|
/*
|
3
|
vpn_ipsec.php
|
4
|
part of m0n0wall (http://m0n0.ch/wall)
|
5
|
|
6
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
7
|
Copyright (C) 2008 Shrew Soft Inc
|
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']['phase1']))
|
35
|
$config['ipsec']['phase1'] = array();
|
36
|
|
37
|
if (!is_array($config['ipsec']['phase2']))
|
38
|
$config['ipsec']['phase2'] = array();
|
39
|
|
40
|
$a_phase1 = &$config['ipsec']['phase1'];
|
41
|
$a_phase2 = &$config['ipsec']['phase2'];
|
42
|
|
43
|
$wancfg = &$config['interfaces']['wan'];
|
44
|
|
45
|
$pconfig['enable'] = isset($config['ipsec']['enable']);
|
46
|
|
47
|
if ($_POST) {
|
48
|
|
49
|
if ($_POST['apply']) {
|
50
|
$retval = 0;
|
51
|
$retval = vpn_ipsec_configure();
|
52
|
$savemsg = get_std_save_message($retval);
|
53
|
if ($retval == 0) {
|
54
|
if (file_exists($d_ipsecconfdirty_path))
|
55
|
unlink($d_ipsecconfdirty_path);
|
56
|
}
|
57
|
} else if ($_POST['submit']) {
|
58
|
$pconfig = $_POST;
|
59
|
|
60
|
$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
|
61
|
|
62
|
write_config();
|
63
|
|
64
|
$retval = 0;
|
65
|
config_lock();
|
66
|
$retval = vpn_ipsec_configure();
|
67
|
config_unlock();
|
68
|
/* reload the filter in the background */
|
69
|
filter_configure();
|
70
|
|
71
|
$savemsg = get_std_save_message($retval);
|
72
|
if ($retval == 0) {
|
73
|
if (file_exists($d_ipsecconfdirty_path))
|
74
|
unlink($d_ipsecconfdirty_path);
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
|
79
|
if ($_GET['act'] == "delph1")
|
80
|
{
|
81
|
if ($a_phase1[$_GET['p1index']]) {
|
82
|
/* remove static route if interface is not WAN */
|
83
|
if ($a_phase1[$_GET['p1index']]['interface'] <> "wan") {
|
84
|
mwexec("/sbin/route delete -host {$$a_phase1[$_GET['p1index']]['remote-gateway']}");
|
85
|
}
|
86
|
|
87
|
/* remove all phase2 entries that match the ikeid */
|
88
|
$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
|
89
|
$p2index = 0;
|
90
|
foreach ($a_phase2 as $ph2tmp) {
|
91
|
if ($ph2tmp['ikeid'] == $ikeid) {
|
92
|
/* remove the phase2 entry */
|
93
|
unset($a_phase2[$p2index]);
|
94
|
continue;
|
95
|
}
|
96
|
/* only skip if we remove an entry */
|
97
|
$p2index++;
|
98
|
}
|
99
|
|
100
|
/* remove the phase1 entry */
|
101
|
unset($a_phase1[$_GET['p1index']]);
|
102
|
filter_configure();
|
103
|
write_config();
|
104
|
header("Location: vpn_ipsec.php");
|
105
|
exit;
|
106
|
}
|
107
|
}
|
108
|
|
109
|
if ($_GET['act'] == "delph2")
|
110
|
{
|
111
|
if ($a_phase2[$_GET['p2index']]) {
|
112
|
/* remove the phase2 entry */
|
113
|
unset($a_phase2[$_GET['p2index']]);
|
114
|
filter_configure();
|
115
|
write_config();
|
116
|
header("Location: vpn_ipsec.php");
|
117
|
exit;
|
118
|
}
|
119
|
}
|
120
|
|
121
|
$pgtitle = array("VPN","IPsec");
|
122
|
include("head.inc");
|
123
|
|
124
|
?>
|
125
|
|
126
|
|
127
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
128
|
<?php include("fbegin.inc"); ?>
|
129
|
<form action="vpn_ipsec.php" method="post">
|
130
|
<?php
|
131
|
if ($savemsg)
|
132
|
print_info_box($savemsg);
|
133
|
if ($pconfig['enable'] && file_exists($d_ipsecconfdirty_path))
|
134
|
print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
|
135
|
?>
|
136
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
137
|
<tr>
|
138
|
<td class="tabnavtbl">
|
139
|
<?php
|
140
|
$tab_array = array();
|
141
|
$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
|
142
|
$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
|
143
|
$tab_array[2] = array("CAs", false, "vpn_ipsec_ca.php");
|
144
|
display_top_tabs($tab_array);
|
145
|
?>
|
146
|
</td>
|
147
|
</tr>
|
148
|
<tr>
|
149
|
<td>
|
150
|
<div id="mainarea">
|
151
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
152
|
<tr>
|
153
|
<td class="vtable">
|
154
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
|
155
|
<strong>Enable IPsec</strong>
|
156
|
</td>
|
157
|
</tr>
|
158
|
<tr>
|
159
|
<td>
|
160
|
<input name="submit" type="submit" class="formbtn" value="Save">
|
161
|
</td>
|
162
|
</tr>
|
163
|
</table>
|
164
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
165
|
<tr>
|
166
|
<td class="listhdrr">Interface<br>Remote gw</td>
|
167
|
<td class="listhdrr">P1 mode</td>
|
168
|
<td class="listhdrr">P1 Enc. Algo</td>
|
169
|
<td class="listhdrr">P1 Hash Algo</td>
|
170
|
<td class="listhdr">Description</td>
|
171
|
<td class="list" >
|
172
|
<table border="0" cellspacing="0" cellpadding="o">
|
173
|
<tr>
|
174
|
<td width="17" heigth="17"></td>
|
175
|
<td>
|
176
|
<a href="vpn_ipsec_phase1.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0"></a>
|
177
|
</td>
|
178
|
</tr>
|
179
|
</table>
|
180
|
</td>
|
181
|
</tr>
|
182
|
|
183
|
<?php
|
184
|
$i = 0;
|
185
|
foreach ($a_phase1 as $ph1ent) {
|
186
|
if (isset( $ph1ent['disabled'])) {
|
187
|
$spans = "<span class=\"gray\">";
|
188
|
$spane = "</span>";
|
189
|
}
|
190
|
else
|
191
|
$spans = $spane = "";
|
192
|
?>
|
193
|
<tr valign="top">
|
194
|
<td class="listlr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
|
195
|
<?=$spans;?>
|
196
|
<?php
|
197
|
if ($ph1ent['interface']) {
|
198
|
$iflabels = get_configured_interface_with_descr();
|
199
|
$carpips = find_number_of_needed_carp_interfaces();
|
200
|
for( $j=0; $j<$carpips; $j++ ) {
|
201
|
$carpip = find_interface_ip("carp" . $j);
|
202
|
$iflabels['carp' . $j] = "CARP{$j} ({$carpip})";
|
203
|
}
|
204
|
$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
|
205
|
}
|
206
|
else
|
207
|
$if = "WAN";
|
208
|
|
209
|
if (!isset($ph1ent['mobile']))
|
210
|
echo $if."<br>".$ph1ent['remote-gateway'];
|
211
|
else
|
212
|
echo $if."<br><strong>Mobile Client</strong>";
|
213
|
?>
|
214
|
<?=$spane;?>
|
215
|
</td>
|
216
|
<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
|
217
|
<?=$spans;?>
|
218
|
<?=$ph1ent['mode'];?>
|
219
|
<?=$spane;?>
|
220
|
</td>
|
221
|
<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
|
222
|
<?=$spans;?>
|
223
|
<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name'];?>
|
224
|
<?php
|
225
|
if ($ph1ent['encryption-algorithm']['keylen']) {
|
226
|
if ($ph1ent['encryption-algorithm']['keylen']=="auto")
|
227
|
echo " (auto)";
|
228
|
else
|
229
|
echo " ({$ph1ent['encryption-algorithm']['keylen']} bits)";
|
230
|
}
|
231
|
?>
|
232
|
<?=$spane;?>
|
233
|
</td>
|
234
|
<td class="listr" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
|
235
|
<?=$spans;?>
|
236
|
<?=$p1_halgos[$ph1ent['hash-algorithm']];?>
|
237
|
<?=$spane;?>
|
238
|
</td>
|
239
|
<td class="listtopic" ondblclick="document.location='vpn_ipsec_phase1.php?id=<?=$i;?>'">
|
240
|
<?=$spans;?>
|
241
|
<font color="#FFFFFF">
|
242
|
<?=htmlspecialchars($ph1ent['descr']);?>
|
243
|
</font>
|
244
|
<?=$spane;?>
|
245
|
</td>
|
246
|
<td valign="middle" nowrap class="list">
|
247
|
<table border="0" cellspacing="0" cellpadding="1">
|
248
|
<tr>
|
249
|
<td>
|
250
|
<a href="vpn_ipsec_phase1.php?p1index=<?=$i;?>">
|
251
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase1 entry" width="17" height="17" border="0">
|
252
|
</a>
|
253
|
</td>
|
254
|
<td>
|
255
|
<a href="vpn_ipsec.php?act=delph1&p1index=<?=$i;?>" onclick="return confirm('Do you really want to delete this phase1 and all associated phase2 entries?')">
|
256
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase1 entry" width="17" height="17" border="0">
|
257
|
</a>
|
258
|
</td>
|
259
|
</tr>
|
260
|
<tr>
|
261
|
<td>
|
262
|
</td>
|
263
|
<td>
|
264
|
<a href="vpn_ipsec_phase1.php?dup=<?=$i;?>">
|
265
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="copy phase1 entry" width="17" height="17" border="0">
|
266
|
</a>
|
267
|
</td>
|
268
|
</tr>
|
269
|
</table>
|
270
|
</td>
|
271
|
</tr>
|
272
|
<tr>
|
273
|
<td class="listbg" colspan="5">
|
274
|
<table width="100%" height="100%"border="0" cellspacing="0" cellpadding="0">
|
275
|
<tr>
|
276
|
<td class="listhdrr">Local Network</td>
|
277
|
<td class="listhdrr">Remote Network</td>
|
278
|
<td class="listhdrr">P2 Protocol</td>
|
279
|
<td class="listhdrr">P2 Transforms</td>
|
280
|
<td class="listhdrr">P2 Auth Methods</td>
|
281
|
<td class ="list">
|
282
|
<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&mobile=true";?>">
|
283
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
|
284
|
</a>
|
285
|
</td>
|
286
|
</tr>
|
287
|
<?php
|
288
|
$j = 0;
|
289
|
foreach ($a_phase2 as $ph2ent) {
|
290
|
if ($ph2ent['ikeid'] != $ph1ent['ikeid']) {
|
291
|
$j++;
|
292
|
continue;
|
293
|
}
|
294
|
|
295
|
if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
|
296
|
$spans = "<span class=\"gray\">";
|
297
|
$spane = "</span>";
|
298
|
}
|
299
|
else
|
300
|
$spans = $spane = "";
|
301
|
?>
|
302
|
<tr valign="top">
|
303
|
|
304
|
<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
|
305
|
<?=$spans;?>
|
306
|
<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
|
307
|
<?=$spane;?>
|
308
|
</td>
|
309
|
<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
|
310
|
<?=$spans;?>
|
311
|
<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
|
312
|
<?=$spane;?>
|
313
|
</td>
|
314
|
<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
|
315
|
<?=$spans;?>
|
316
|
<?php echo $p2_protos[$ph2ent['protocol']]; ?>
|
317
|
<?=$spane;?>
|
318
|
</td>
|
319
|
<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
|
320
|
<?=$spans;?>
|
321
|
<?php
|
322
|
$k = 0;
|
323
|
foreach ($ph2ent['encryption-algorithm-option'] as $ph2ea) {
|
324
|
if ($k++)
|
325
|
echo ", ";
|
326
|
echo $p2_ealgos[$ph2ea['name']]['name'];
|
327
|
if ($ph2ea['keylen']) {
|
328
|
if ($ph2ea['keylen']=="auto")
|
329
|
echo " (auto)";
|
330
|
else
|
331
|
echo " ({$ph2ea['keylen']} bits)";
|
332
|
}
|
333
|
}
|
334
|
?>
|
335
|
<?=$spane;?>
|
336
|
</td>
|
337
|
<td nowrap class="listr" ondblclick="document.location='vpn_ipsec_phase2.php?id=<?=$i;?>'">
|
338
|
<?=$spans;?>
|
339
|
<?php
|
340
|
$k = 0;
|
341
|
foreach ($ph2ent['hash-algorithm-option'] as $ph2ha) {
|
342
|
if ($k++)
|
343
|
echo ", ";
|
344
|
echo $p2_halgos[$ph2ha];
|
345
|
}
|
346
|
?>
|
347
|
<?=$spane;?>
|
348
|
</td>
|
349
|
<td nowrap class="list">
|
350
|
<a href="vpn_ipsec_phase2.php?p2index=<?=$j;?>">
|
351
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase2 entry" width="17" height="17" border="0">
|
352
|
</a>
|
353
|
<a href="vpn_ipsec.php?act=delph2&p2index=<?=$j;?>" onclick="return confirm('Do you really want to delete this phase2 entry?')">
|
354
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase2 entry" width="17" height="17" border="0">
|
355
|
</a>
|
356
|
</td>
|
357
|
</tr>
|
358
|
|
359
|
<?php
|
360
|
$j++;
|
361
|
}
|
362
|
?>
|
363
|
</table>
|
364
|
</td>
|
365
|
</tr>
|
366
|
<?php
|
367
|
$i++;
|
368
|
}
|
369
|
?>
|
370
|
|
371
|
<tr>
|
372
|
<td class="list" colspan="5"></td>
|
373
|
<td class="list">
|
374
|
<table border="0" cellspacing="0" cellpadding="1">
|
375
|
<tr>
|
376
|
<td width="17"></td>
|
377
|
<td>
|
378
|
<a href="vpn_ipsec_phase1.php">
|
379
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0">
|
380
|
</a>
|
381
|
</td>
|
382
|
</tr>
|
383
|
</table>
|
384
|
<td>
|
385
|
</tr>
|
386
|
<tr>
|
387
|
<td colspan="4">
|
388
|
<p>
|
389
|
<span class="vexpl">
|
390
|
<span class="red">
|
391
|
<strong>Note:<br></strong>
|
392
|
</span>
|
393
|
You can check your IPsec status at <a href="diag_ipsec.php">Status:IPsec</a>.
|
394
|
</span>
|
395
|
</p>
|
396
|
</td>
|
397
|
</tr>
|
398
|
</table>
|
399
|
</div>
|
400
|
</td>
|
401
|
</tr>
|
402
|
</table>
|
403
|
</form>
|
404
|
<?php include("fend.inc"); ?>
|
405
|
</body>
|
406
|
</html>
|