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
|
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
|
$wancfg = &$config['interfaces']['wan'];
|
38
|
|
39
|
$pconfig['enable'] = isset($config['ipsec']['enable']);
|
40
|
$pconfig['ipcomp'] = isset($config['ipsec']['ipcomp']);
|
41
|
|
42
|
if ($_POST) {
|
43
|
|
44
|
if ($_POST['apply']) {
|
45
|
$retval = 0;
|
46
|
$retval = vpn_ipsec_refresh_policies();
|
47
|
$retval = vpn_ipsec_configure();
|
48
|
/* reload the filter in the background */
|
49
|
filter_configure();
|
50
|
$savemsg = get_std_save_message($retval);
|
51
|
if ($retval == 0) {
|
52
|
if (file_exists($d_ipsecconfdirty_path))
|
53
|
unlink($d_ipsecconfdirty_path);
|
54
|
}
|
55
|
} else if ($_POST['submit']) {
|
56
|
$pconfig = $_POST;
|
57
|
|
58
|
$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
|
59
|
$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
|
60
|
|
61
|
write_config();
|
62
|
|
63
|
$retval = 0;
|
64
|
config_lock();
|
65
|
$retval = vpn_ipsec_refresh_policies();
|
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'] == "del") {
|
80
|
if ($a_ipsec[$_GET['id']]) {
|
81
|
/* remove static route if interface is not WAN */
|
82
|
if($a_ipsec[$_GET['id']]['interface'] <> "wan") {
|
83
|
$oldgw = resolve_retry($a_ipsec[$_GET['id']]['remote-gateway']);
|
84
|
mwexec("/sbin/route delete -host {$oldgw}");
|
85
|
}
|
86
|
unset($a_ipsec[$_GET['id']]);
|
87
|
vpn_ipsec_configure();
|
88
|
filter_configure();
|
89
|
write_config();
|
90
|
header("Location: vpn_ipsec.php");
|
91
|
exit;
|
92
|
}
|
93
|
}
|
94
|
|
95
|
$pgtitle = "VPN: IPsec";
|
96
|
include("head.inc");
|
97
|
|
98
|
?>
|
99
|
|
100
|
|
101
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
102
|
<?php include("fbegin.inc"); ?>
|
103
|
<p class="pgtitle"><?=$pgtitle?></p>
|
104
|
<form action="vpn_ipsec.php" method="post">
|
105
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
106
|
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
|
107
|
<?php if ($pconfig['enable'])
|
108
|
print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes
|
109
|
in order for them to take effect.");?><br>
|
110
|
<?php endif; ?>
|
111
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
112
|
<tr><td class="tabnavtbl">
|
113
|
<?php
|
114
|
$tab_array = array();
|
115
|
$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
|
116
|
$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
|
117
|
$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
|
118
|
$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
|
119
|
display_top_tabs($tab_array);
|
120
|
?>
|
121
|
</td></tr>
|
122
|
<tr>
|
123
|
<td>
|
124
|
<div id="mainarea">
|
125
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
126
|
<tr>
|
127
|
<td class="vtable">
|
128
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
|
129
|
<strong>Enable IPsec</strong></td>
|
130
|
</tr>
|
131
|
<tr>
|
132
|
<td> <input name="submit" type="submit" class="formbtn" value="Save">
|
133
|
</td>
|
134
|
</tr>
|
135
|
</table>
|
136
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
137
|
<tr>
|
138
|
<td nowrap class="listhdrr">Local net<br>
|
139
|
Remote net</td>
|
140
|
<td class="listhdrr">Interface<br>Remote gw</td>
|
141
|
<td class="listhdrr">P1 mode</td>
|
142
|
<td class="listhdrr">P1 Enc. Algo</td>
|
143
|
<td class="listhdrr">P1 Hash Algo</td>
|
144
|
<td class="listhdr">Description</td>
|
145
|
<td class="list" >
|
146
|
<table border="0" cellspacing="0" cellpadding="1">
|
147
|
<tr>
|
148
|
<td width="17" heigth="17"></td>
|
149
|
<td><a href="vpn_ipsec_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add tunnel" width="17" height="17" border="0"></a></td>
|
150
|
</tr>
|
151
|
</table>
|
152
|
</td>
|
153
|
</tr>
|
154
|
<?php $i = 0; foreach ($a_ipsec as $ipsecent):
|
155
|
if (isset($ipsecent['disabled'])) {
|
156
|
$spans = "<span class=\"gray\">";
|
157
|
$spane = "</span>";
|
158
|
} else {
|
159
|
$spans = $spane = "";
|
160
|
}
|
161
|
?>
|
162
|
<tr valign="top">
|
163
|
<td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
|
164
|
<?php if ($ipsecent['local-subnet']['network'])
|
165
|
echo strtoupper($ipsecent['local-subnet']['network']);
|
166
|
else
|
167
|
echo $ipsecent['local-subnet']['address'];
|
168
|
?>
|
169
|
<br>
|
170
|
<?=$ipsecent['remote-subnet'];?>
|
171
|
<?=$spane;?></td>
|
172
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
|
173
|
<?php if ($ipsecent['interface']) {
|
174
|
$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
|
175
|
$carpips = find_number_of_needed_carp_interfaces();
|
176
|
for($j=0; $j<$carpips; $j++) {
|
177
|
$carpip = find_interface_ip("carp" . $j);
|
178
|
$iflabels['carp' . $j] = "CARP{$j} ({$carpip})";
|
179
|
}
|
180
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
|
181
|
$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
182
|
$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
|
183
|
} else
|
184
|
$if = "WAN";
|
185
|
|
186
|
echo $if . "<br>" . $ipsecent['remote-gateway'];
|
187
|
?>
|
188
|
<?=$spane;?></td>
|
189
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
|
190
|
<?=$ipsecent['p1']['mode'];?>
|
191
|
<?=$spane;?></td>
|
192
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
|
193
|
<?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
|
194
|
<?=$spane;?></td>
|
195
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?>
|
196
|
<?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
|
197
|
<?=$spane;?></td>
|
198
|
<td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>'"><?=$spans;?><font color="#FFFFFF">
|
199
|
<?=htmlspecialchars($ipsecent['descr']);?>
|
200
|
<?=$spane;?></td>
|
201
|
<td valign="middle" nowrap class="list">
|
202
|
<table border="0" cellspacing="0" cellpadding="1">
|
203
|
<tr>
|
204
|
<td><a href="vpn_ipsec_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit tunnel" width="17" height="17" border="0"></a></td>
|
205
|
<td><a href="vpn_ipsec.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this tunnel?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete tunnel" width="17" height="17" border="0"></a></td>
|
206
|
</tr>
|
207
|
<tr>
|
208
|
<td></td>
|
209
|
<td><a href="vpn_ipsec_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a></td>
|
210
|
</tr>
|
211
|
</table>
|
212
|
</td>
|
213
|
</tr>
|
214
|
<?php $i++; endforeach; ?>
|
215
|
<tr>
|
216
|
<td class="list" colspan="6"></td>
|
217
|
<td class="list">
|
218
|
<table border="0" cellspacing="0" cellpadding="1">
|
219
|
<tr>
|
220
|
<td width="17"></td>
|
221
|
<td><a href="vpn_ipsec_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add tunnel" width="17" height="17" border="0"></a></td>
|
222
|
</tr>
|
223
|
</table>
|
224
|
<td>
|
225
|
</tr>
|
226
|
<td colspan="4">
|
227
|
<p><span class="vexpl"><span class="red"><strong>Note:<br>
|
228
|
</strong></span>You can check your IPsec status at <a href="diag_ipsec_sad.php">Status:IPsec</a>.</span></p>
|
229
|
</td>
|
230
|
</tr>
|
231
|
</table>
|
232
|
</div>
|
233
|
</td>
|
234
|
</tr>
|
235
|
</table>
|
236
|
</form>
|
237
|
<?php include("fend.inc"); ?>
|
238
|
</body>
|
239
|
</html>
|