1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
vpn_ipsec.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
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']['tunnel'])) {
|
35
|
$config['ipsec']['tunnel'] = array();
|
36
|
}
|
37
|
$a_ipsec = &$config['ipsec']['tunnel'];
|
38
|
$wancfg = &$config['interfaces']['wan'];
|
39
|
|
40
|
$pconfig['enable'] = isset($config['ipsec']['enable']);
|
41
|
|
42
|
if ($_POST) {
|
43
|
|
44
|
if ($_POST['apply']) {
|
45
|
$retval = 0;
|
46
|
$retval = vpn_ipsec_configure();
|
47
|
$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
|
|
55
|
$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
|
56
|
|
57
|
write_config();
|
58
|
|
59
|
$retval = 0;
|
60
|
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
|
$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
|
|
83
|
$pgtitle = "VPN: IPsec";
|
84
|
include("head.inc");
|
85
|
|
86
|
?>
|
87
|
|
88
|
|
89
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
90
|
<?php include("fbegin.inc"); ?>
|
91
|
<p class="pgtitle"><?=$pgtitle?></p>
|
92
|
<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
|
<tr><td class="tabnavtbl">
|
99
|
<?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
|
$tab_array[4] = array("Failover IPSEC", false, "/pkg_edit.php?xml=sasyncd.xml&id=0");
|
106
|
display_top_tabs($tab_array);
|
107
|
?>
|
108
|
</td></tr>
|
109
|
<tr>
|
110
|
<td>
|
111
|
<div id="mainarea">
|
112
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
113
|
<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
|
</td>
|
121
|
</tr>
|
122
|
</table>
|
123
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
124
|
<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
|
<td nowrap class="listlr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
144
|
<?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
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
153
|
<?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
|
|
161
|
echo $if . "<br>" . $ipsecent['remote-gateway'];
|
162
|
?>
|
163
|
<?=$spane;?></td>
|
164
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
165
|
<?=$ipsecent['p1']['mode'];?>
|
166
|
<?=$spane;?></td>
|
167
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
168
|
<?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
|
169
|
<?=$spane;?></td>
|
170
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?>
|
171
|
<?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
|
172
|
<?=$spane;?></td>
|
173
|
<td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php'"><?=$spans;?><font color="#FFFFFF">
|
174
|
<?=htmlspecialchars($ipsecent['descr']);?>
|
175
|
<?=$spane;?></td>
|
176
|
<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
|
</tr>
|
179
|
<?php $i++; endforeach; ?>
|
180
|
<tr>
|
181
|
<td class="list" colspan="6"></td>
|
182
|
<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
|
</tr>
|
184
|
<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
|
</table>
|
189
|
</div>
|
190
|
</td>
|
191
|
</tr>
|
192
|
</table>
|
193
|
</form>
|
194
|
<?php include("fend.inc"); ?>
|
195
|
</body>
|
196
|
</html>
|