1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
vpn_ipsec.php
|
6
|
Copyright (C) 2004 Scott Ullrich
|
7
|
All rights reserved.
|
8
|
|
9
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
|
35
|
require("guiconfig.inc");
|
36
|
|
37
|
if (!is_array($config['ipsec']['tunnel'])) {
|
38
|
$config['ipsec']['tunnel'] = array();
|
39
|
}
|
40
|
$a_ipsec = &$config['ipsec']['tunnel'];
|
41
|
|
42
|
$pconfig['enable'] = isset($config['ipsec']['enable']);
|
43
|
$pconfig['preferredoldsa'] = isset($config['ipsec']['preferredoldsa']);
|
44
|
$pconfig['ipcomp'] = isset($config['ipsec']['ipcomp']);
|
45
|
|
46
|
if ($_POST) {
|
47
|
|
48
|
if ($_POST['apply']) {
|
49
|
$retval = 0;
|
50
|
if (!file_exists($d_sysrebootreqd_path))
|
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
|
$config['ipsec']['preferredoldsa'] = $_POST['preferredoldsa'] ? true : false;
|
62
|
$config['ipsec']['ipcomp'] = $_POST['ipcomp'] ? true : false;
|
63
|
if($_POST['interface'] <> "")
|
64
|
$config['ipsec']['interface'] = $_POST['interface'];
|
65
|
|
66
|
write_config();
|
67
|
|
68
|
$retval = 0;
|
69
|
if (!file_exists($d_sysrebootreqd_path)) {
|
70
|
config_lock();
|
71
|
$retval = vpn_ipsec_configure();
|
72
|
config_unlock();
|
73
|
}
|
74
|
$savemsg = get_std_save_message($retval);
|
75
|
if ($retval == 0) {
|
76
|
if (file_exists($d_ipsecconfdirty_path))
|
77
|
unlink($d_ipsecconfdirty_path);
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
if ($_GET['act'] == "del") {
|
83
|
if ($a_ipsec[$_GET['id']]) {
|
84
|
unset($a_ipsec[$_GET['id']]);
|
85
|
write_config();
|
86
|
touch($d_ipsecconfdirty_path);
|
87
|
header("Location: vpn_ipsec.php");
|
88
|
exit;
|
89
|
}
|
90
|
}
|
91
|
?>
|
92
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
93
|
<html>
|
94
|
<head>
|
95
|
<title><?=gentitle("VPN: IPsec");?></title>
|
96
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
97
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
98
|
</head>
|
99
|
|
100
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
101
|
<?php include("fbegin.inc"); ?>
|
102
|
<p class="pgtitle">VPN: IPsec</p>
|
103
|
<form action="vpn_ipsec.php" method="post">
|
104
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
105
|
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
|
106
|
<?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>
|
107
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
108
|
<?php endif; ?>
|
109
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
110
|
<tr><td>
|
111
|
<ul id="tabnav">
|
112
|
<li class="tabact">Tunnels</li>
|
113
|
<li class="tabinact"><a href="vpn_ipsec_mobile.php">Mobile clients</a></li>
|
114
|
<li class="tabinact"><a href="vpn_ipsec_keys.php">Pre-shared keys</a></li>
|
115
|
</ul>
|
116
|
</td></tr>
|
117
|
<tr>
|
118
|
<td class="tabcont">
|
119
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
120
|
<tr>
|
121
|
<td class="vtable"><p><span class="vexpl"> </span>
|
122
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
|
123
|
<strong>Enable IPsec<br>
|
124
|
</strong></p>
|
125
|
</td>
|
126
|
<td class="vtable"><p><span class="vexpl"> </span>
|
127
|
<input name="preferredoldsa" type="checkbox" id="preferredoldsa" value="yes" <?php if ($pconfig['preferredoldsa'] == "yes") echo "checked";?>>
|
128
|
<strong>Prefer newer SA's.<br>
|
129
|
</strong></p>
|
130
|
</td>
|
131
|
<td class="vtable"><p><span class="vexpl"> </span>
|
132
|
<input name="ipcomp" type="checkbox" id="ipcomp" value="yes" <?php if ($pconfig['ipcomp'] == "yes") echo "checked";?>>
|
133
|
<strong>Enable VPN IP Compression<br>
|
134
|
</strong></p>
|
135
|
</td>
|
136
|
</tr>
|
137
|
<tr>
|
138
|
<td> <input name="submit" type="submit" class="formbtn" value="Save">
|
139
|
</td>
|
140
|
</tr>
|
141
|
</table>
|
142
|
<br>
|
143
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
144
|
<tr>
|
145
|
<td nowrap class="listhdrr">Local net<br>
|
146
|
Remote net</td>
|
147
|
<td class="listhdrr">Interface<br>Remote gw</td>
|
148
|
<td class="listhdrr">P1 mode</td>
|
149
|
<td class="listhdrr">P1 Enc. Algo</td>
|
150
|
<td class="listhdrr">P1 Hash Algo</td>
|
151
|
<td class="listhdr">Description</td>
|
152
|
<td class="list"></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
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
|
176
|
$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
177
|
$if = htmlspecialchars($iflabels[$ipsecent['interface']]);
|
178
|
} else
|
179
|
$if = "WAN";
|
180
|
|
181
|
echo $if . "<br>" . $ipsecent['remote-gateway'];
|
182
|
?>
|
183
|
<?=$spane;?></td>
|
184
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
|
185
|
<?=$ipsecent['p1']['mode'];?>
|
186
|
<?=$spane;?></td>
|
187
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
|
188
|
<?=$p1_ealgos[$ipsecent['p1']['encryption-algorithm']];?>
|
189
|
<?=$spane;?></td>
|
190
|
<td class="listr" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
|
191
|
<?=$p1_halgos[$ipsecent['p1']['hash-algorithm']];?>
|
192
|
<?=$spane;?></td>
|
193
|
<td class="listbg" ondblclick="document.location='vpn_ipsec_edit.php?id=<?=$i;?>';"><?=$spans;?>
|
194
|
<font color="#FFFFFF"><?=htmlspecialchars($ipsecent['descr']);?>
|
195
|
<?=$spane;?></td>
|
196
|
<td valign="middle" nowrap class="list">
|
197
|
<table border="0" cellspacing="0" cellpadding="1">
|
198
|
<tr>
|
199
|
<td valign="middle"><a href="vpn_ipsec_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
|
200
|
<td valign="middle"><a href="vpn_ipsec.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this tunnel?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
|
201
|
</tr>
|
202
|
</table>
|
203
|
</td>
|
204
|
</tr>
|
205
|
<?php $i++; endforeach; ?>
|
206
|
<tr>
|
207
|
<td class="list" colspan="6"></td>
|
208
|
<td class="list">
|
209
|
<table border="0" cellspacing="0" cellpadding="1">
|
210
|
<tr>
|
211
|
<td valign="middle"><a href="vpn_ipsec_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
212
|
</tr>
|
213
|
</table>
|
214
|
</td>
|
215
|
</tr>
|
216
|
</table>
|
217
|
</td>
|
218
|
</tr>
|
219
|
</table>
|
220
|
</form>
|
221
|
<?php include("fend.inc"); ?>
|
222
|
</body>
|
223
|
</html>
|