1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
|
|
vpn_ipsec.php
|
5 |
e2411886
|
Scott Ullrich
|
part of m0n0wall (http://m0n0.ch/wall)
|
6 |
|
|
|
7 |
|
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
8 |
cfc707f7
|
Scott Ullrich
|
All rights reserved.
|
9 |
e2411886
|
Scott Ullrich
|
|
10 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
e2411886
|
Scott Ullrich
|
|
13 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
e2411886
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
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 |
e2411886
|
Scott Ullrich
|
|
20 |
5b237745
|
Scott Ullrich
|
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']['tunnel'])) {
|
35 |
|
|
$config['ipsec']['tunnel'] = array();
|
36 |
|
|
}
|
37 |
|
|
$a_ipsec = &$config['ipsec']['tunnel'];
|
38 |
e2411886
|
Scott Ullrich
|
$wancfg = &$config['interfaces']['wan'];
|
39 |
5b237745
|
Scott Ullrich
|
|
40 |
|
|
$pconfig['enable'] = isset($config['ipsec']['enable']);
|
41 |
|
|
|
42 |
|
|
if ($_POST) {
|
43 |
|
|
|
44 |
|
|
if ($_POST['apply']) {
|
45 |
|
|
$retval = 0;
|
46 |
3851094f
|
Scott Ullrich
|
$retval = vpn_ipsec_configure();
|
47 |
5b237745
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
48 |
|
|
if ($retval == 0) {
|
49 |
|
|
if (file_exists($d_ipsecconfdirty_path))
|
50 |
|
|
unlink($d_ipsecconfdirty_path);
|
51 |
|
|
}
|
52 |
|
|
} else if ($_POST['submit']) {
|
53 |
|
|
$pconfig = $_POST;
|
54 |
e2411886
|
Scott Ullrich
|
|
55 |
5b237745
|
Scott Ullrich
|
$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
|
56 |
e2411886
|
Scott Ullrich
|
|
57 |
5b237745
|
Scott Ullrich
|
write_config();
|
58 |
e2411886
|
Scott Ullrich
|
|
59 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
60 |
3851094f
|
Scott Ullrich
|
config_lock();
|
61 |
|
|
$retval = vpn_ipsec_configure();
|
62 |
|
|
config_unlock();
|
63 |
|
|
/* reload the filter in the background */
|
64 |
|
|
mwexec_bg("/etc/rc.filter_configure");
|
65 |
|
|
|
66 |
5b237745
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
67 |
|
|
if ($retval == 0) {
|
68 |
|
|
if (file_exists($d_ipsecconfdirty_path))
|
69 |
|
|
unlink($d_ipsecconfdirty_path);
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
if ($_GET['act'] == "del") {
|
75 |
|
|
if ($a_ipsec[$_GET['id']]) {
|
76 |
|
|
unset($a_ipsec[$_GET['id']]);
|
77 |
|
|
write_config();
|
78 |
|
|
header("Location: vpn_ipsec.php");
|
79 |
|
|
exit;
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
4df96eff
|
Scott Ullrich
|
|
83 |
b128368a
|
Bill Marquette
|
$pgtitle = "VPN: IPsec";
|
84 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
85 |
|
|
|
86 |
5b237745
|
Scott Ullrich
|
?>
|
87 |
4df96eff
|
Scott Ullrich
|
|
88 |
422f27c0
|
Scott Ullrich
|
|
89 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
90 |
5b237745
|
Scott Ullrich
|
<?php include("fbegin.inc"); ?>
|
91 |
b128368a
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
92 |
5b237745
|
Scott Ullrich
|
<form action="vpn_ipsec.php" method="post">
|
93 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
94 |
|
|
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
|
95 |
|
|
<?php print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
96 |
|
|
<?php endif; ?>
|
97 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
98 |
e2411886
|
Scott Ullrich
|
<tr><td class="tabnavtbl">
|
99 |
323d040b
|
Scott Ullrich
|
<?php
|
100 |
|
|
$tab_array = array();
|
101 |
|
|
$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
|
102 |
|
|
$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
|
103 |
|
|
$tab_array[2] = array("Pre-shared keys", false, "vpn_ipsec_keys.php");
|
104 |
|
|
$tab_array[3] = array("CAs", false, "vpn_ipsec_ca.php");
|
105 |
83c5299b
|
Scott Ullrich
|
$tab_array[4] = array("Failover IPSEC", false, "/pkg_edit.php?xml=sasyncd.xml&id=0");
|
106 |
323d040b
|
Scott Ullrich
|
display_top_tabs($tab_array);
|
107 |
|
|
?>
|
108 |
5b237745
|
Scott Ullrich
|
</td></tr>
|
109 |
e2411886
|
Scott Ullrich
|
<tr>
|
110 |
0f10aee4
|
Bill Marquette
|
<td>
|
111 |
|
|
<div id="mainarea">
|
112 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
113 |
e2411886
|
Scott Ullrich
|
<tr>
|
114 |
|
|
<td class="vtable">
|
115 |
|
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
|
116 |
|
|
<strong>Enable IPsec</strong></td>
|
117 |
|
|
</tr>
|
118 |
|
|
<tr>
|
119 |
|
|
<td> <input name="submit" type="submit" class="formbtn" value="Save">
|
120 |
5b237745
|
Scott Ullrich
|
</td>
|
121 |
|
|
</tr>
|
122 |
0f10aee4
|
Bill Marquette
|
</table>
|
123 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
124 |
5b237745
|
Scott Ullrich
|
<tr>
|
125 |
|
|
<td nowrap class="listhdrr">Local net<br>
|
126 |
|
|
Remote net</td>
|
127 |
|
|
<td class="listhdrr">Interface<br>Remote gw</td>
|
128 |
|
|
<td class="listhdrr">P1 mode</td>
|
129 |
|
|
<td class="listhdrr">P1 Enc. Algo</td>
|
130 |
|
|
<td class="listhdrr">P1 Hash Algo</td>
|
131 |
|
|
<td class="listhdr">Description</td>
|
132 |
|
|
<td class="list"></td>
|
133 |
|
|
</tr>
|
134 |
|
|
<?php $i = 0; foreach ($a_ipsec as $ipsecent):
|
135 |
|
|
if (isset($ipsecent['disabled'])) {
|
136 |
|
|
$spans = "<span class=\"gray\">";
|
137 |
|
|
$spane = "</span>";
|
138 |
|
|
} else {
|
139 |
|
|
$spans = $spane = "";
|
140 |
|
|
}
|
141 |
|
|
?>
|
142 |
|
|
<tr valign="top">
|
143 |
fdc24e47
|
Bill Marquette
|
<td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
144 |
5b237745
|
Scott Ullrich
|
<?php if ($ipsecent['local-subnet']['network'])
|
145 |
|
|
echo strtoupper($ipsecent['local-subnet']['network']);
|
146 |
|
|
else
|
147 |
|
|
echo $ipsecent['local-subnet']['address'];
|
148 |
|
|
?>
|
149 |
|
|
<br>
|
150 |
|
|
<?=$ipsecent['remote-subnet'];?>
|
151 |
|
|
<?=$spane;?></td>
|
152 |
fdc24e47
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
153 |
5b237745
|
Scott Ullrich
|
<?php if ($ipsecent['interface']) {
|
154 |
|
|
$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
|
155 |
|
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
|
156 |
|
|
$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
157 |
|
|
$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
|
158 |
|
|
} else
|
159 |
|
|
$if = "WAN";
|
160 |
e2411886
|
Scott Ullrich
|
|
161 |
5b237745
|
Scott Ullrich
|
echo $if . "<br>" . $ipsecent['remote-gateway'];
|
162 |
|
|
?>
|
163 |
|
|
<?=$spane;?></td>
|
164 |
fdc24e47
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
165 |
5b237745
|
Scott Ullrich
|
<?=$ipsecent['p1']['mode'];?>
|
166 |
|
|
<?=$spane;?></td>
|
167 |
fdc24e47
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
168 |
5b237745
|
Scott Ullrich
|
<?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
|
169 |
|
|
<?=$spane;?></td>
|
170 |
fdc24e47
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
171 |
5b237745
|
Scott Ullrich
|
<?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
|
172 |
|
|
<?=$spane;?></td>
|
173 |
fdc24e47
|
Bill Marquette
|
<td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?><font color="#FFFFFF">
|
174 |
e2411886
|
Scott Ullrich
|
<?=htmlspecialchars($ipsecent['descr']);?>
|
175 |
5b237745
|
Scott Ullrich
|
<?=$spane;?></td>
|
176 |
677c0869
|
Erik Kristensen
|
<td valign="middle" nowrap class="list"> <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>
|
177 |
|
|
<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>
|
178 |
e2411886
|
Scott Ullrich
|
</tr>
|
179 |
|
|
<?php $i++; endforeach; ?>
|
180 |
|
|
<tr>
|
181 |
5b237745
|
Scott Ullrich
|
<td class="list" colspan="6"></td>
|
182 |
677c0869
|
Erik Kristensen
|
<td class="list"> <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>
|
183 |
e2411886
|
Scott Ullrich
|
</tr>
|
184 |
c55a8ab9
|
Holger Bauer
|
<td colspan="4">
|
185 |
|
|
<p><span class="vexpl"><span class="red"><strong>Note:<br>
|
186 |
|
|
</strong></span>You can check your IPSEC status at <a href="diag_ipsec_sad.php">Status:IPSEC</a>.</span></p>
|
187 |
|
|
</td>
|
188 |
5b237745
|
Scott Ullrich
|
</table>
|
189 |
0f10aee4
|
Bill Marquette
|
</div>
|
190 |
|
|
</td>
|
191 |
5b237745
|
Scott Ullrich
|
</tr>
|
192 |
|
|
</table>
|
193 |
|
|
</form>
|
194 |
|
|
<?php include("fend.inc"); ?>
|
195 |
323d040b
|
Scott Ullrich
|
</body>
|
196 |
|
|
</html>
|