1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
4d875b4f
|
Scott Ullrich
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
diag_ipsec_spd.php
|
6 |
4d875b4f
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
10 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11 |
|
|
All rights reserved.
|
12 |
4d875b4f
|
Scott Ullrich
|
|
13 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
14 |
|
|
modification, are permitted provided that the following conditions are met:
|
15 |
4d875b4f
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
17 |
|
|
this list of conditions and the following disclaimer.
|
18 |
4d875b4f
|
Scott Ullrich
|
|
19 |
5b237745
|
Scott Ullrich
|
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 |
4d875b4f
|
Scott Ullrich
|
|
23 |
5b237745
|
Scott Ullrich
|
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 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
38 |
|
|
<html>
|
39 |
|
|
<head>
|
40 |
|
|
<title><?=gentitle("Diagnostics: IPsec");?></title>
|
41 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
42 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
43 |
|
|
</head>
|
44 |
|
|
|
45 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
46 |
|
|
<?php include("fbegin.inc"); ?>
|
47 |
|
|
<p class="pgtitle">Diagnostics: IPsec</p>
|
48 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
49 |
|
|
<tr><td>
|
50 |
|
|
<ul id="tabnav">
|
51 |
|
|
<li class="tabinact"><a href="diag_ipsec_sad.php">SAD</a></li>
|
52 |
|
|
<li class="tabact">SPD</li>
|
53 |
|
|
</ul>
|
54 |
|
|
</td></tr>
|
55 |
4d875b4f
|
Scott Ullrich
|
<tr>
|
56 |
5b237745
|
Scott Ullrich
|
<td class="tabcont">
|
57 |
|
|
<?php
|
58 |
|
|
|
59 |
|
|
/* delete any SP? */
|
60 |
|
|
if ($_GET['act'] == "del") {
|
61 |
|
|
$fd = @popen("/usr/sbin/setkey -c > /dev/null 2>&1", "w");
|
62 |
|
|
if ($fd) {
|
63 |
|
|
fwrite($fd, "spddelete {$_GET['src']} {$_GET['dst']} any -P {$_GET['dir']} ;\n");
|
64 |
|
|
pclose($fd);
|
65 |
|
|
sleep(1);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/* query SAD */
|
70 |
|
|
$fd = @popen("/usr/sbin/setkey -DP", "r");
|
71 |
|
|
$spd = array();
|
72 |
|
|
if ($fd) {
|
73 |
|
|
while (!feof($fd)) {
|
74 |
|
|
$line = chop(fgets($fd));
|
75 |
|
|
if (!$line)
|
76 |
|
|
continue;
|
77 |
|
|
if ($line == "No SPD entries.")
|
78 |
|
|
break;
|
79 |
|
|
if ($line[0] != "\t") {
|
80 |
|
|
if (is_array($cursp))
|
81 |
|
|
$spd[] = $cursp;
|
82 |
|
|
$cursp = array();
|
83 |
|
|
$linea = explode(" ", $line);
|
84 |
|
|
$cursp['src'] = substr($linea[0], 0, strpos($linea[0], "["));
|
85 |
|
|
$cursp['dst'] = substr($linea[1], 0, strpos($linea[1], "["));
|
86 |
|
|
$i = 0;
|
87 |
|
|
} else if (is_array($cursp)) {
|
88 |
|
|
$linea = explode(" ", trim($line));
|
89 |
|
|
if ($i == 1) {
|
90 |
|
|
if ($linea[1] == "none") /* don't show default anti-lockout rule */
|
91 |
|
|
unset($cursp);
|
92 |
|
|
else
|
93 |
|
|
$cursp['dir'] = $linea[0];
|
94 |
|
|
} else if ($i == 2) {
|
95 |
|
|
$upperspec = explode("/", $linea[0]);
|
96 |
|
|
$cursp['proto'] = $upperspec[0];
|
97 |
|
|
list($cursp['ep_src'], $cursp['ep_dst']) = explode("-", $upperspec[2]);
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
$i++;
|
101 |
|
|
}
|
102 |
|
|
if (is_array($cursp) && count($cursp))
|
103 |
|
|
$spd[] = $cursp;
|
104 |
|
|
pclose($fd);
|
105 |
|
|
}
|
106 |
|
|
if (count($spd)):
|
107 |
|
|
?>
|
108 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
109 |
|
|
<tr>
|
110 |
|
|
<td nowrap class="listhdrr">Source</td>
|
111 |
|
|
<td nowrap class="listhdrr">Destination</a></td>
|
112 |
|
|
<td nowrap class="listhdrr">Direction</td>
|
113 |
|
|
<td nowrap class="listhdrr">Protocol</td>
|
114 |
|
|
<td nowrap class="listhdrr">Tunnel endpoints</td>
|
115 |
|
|
<td nowrap class="list"></td>
|
116 |
|
|
</tr>
|
117 |
|
|
<?php
|
118 |
|
|
foreach ($spd as $sp): ?>
|
119 |
|
|
<tr>
|
120 |
|
|
<td class="listlr" valign="top"><?=htmlspecialchars($sp['src']);?></td>
|
121 |
|
|
<td class="listr" valign="top"><?=htmlspecialchars($sp['dst']);?></td>
|
122 |
|
|
<td class="listr" valign="top"><img src="<?=$sp['dir'];?>.gif" width="11" height="11" style="margin-top: 2px"></td>
|
123 |
|
|
<td class="listr" valign="top"><?=htmlspecialchars(strtoupper($sp['proto']));?></td>
|
124 |
|
|
<td class="listr" valign="top"><?=htmlspecialchars($sp['ep_src']);?> - <br>
|
125 |
|
|
<?=htmlspecialchars($sp['ep_dst']);?></td>
|
126 |
|
|
<td class="list" nowrap>
|
127 |
|
|
<?php
|
128 |
|
|
$args = "src=" . rawurlencode($sp['src']);
|
129 |
|
|
$args .= "&dst=" . rawurlencode($sp['dst']);
|
130 |
|
|
$args .= "&dir=" . rawurlencode($sp['dir']);
|
131 |
|
|
?>
|
132 |
|
|
<a href="diag_ipsec_spd.php?act=del&<?=$args;?>" onclick="return confirm('Do you really want to delete this security policy?')"><img src="x.gif" width="17" height="17" border="0"></a>
|
133 |
|
|
</td>
|
134 |
4d875b4f
|
Scott Ullrich
|
|
135 |
5b237745
|
Scott Ullrich
|
</tr>
|
136 |
|
|
<?php endforeach; ?>
|
137 |
|
|
</table>
|
138 |
|
|
<br>
|
139 |
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
140 |
4d875b4f
|
Scott Ullrich
|
<tr>
|
141 |
5b237745
|
Scott Ullrich
|
<td width="16"><img src="in.gif" width="11" height="11"></td>
|
142 |
|
|
<td>incoming (as seen by firewall)</td>
|
143 |
|
|
</tr>
|
144 |
4d875b4f
|
Scott Ullrich
|
<tr>
|
145 |
5b237745
|
Scott Ullrich
|
<td colspan="5" height="4"></td>
|
146 |
|
|
</tr>
|
147 |
4d875b4f
|
Scott Ullrich
|
<tr>
|
148 |
5b237745
|
Scott Ullrich
|
<td><img src="out.gif" width="11" height="11"></td>
|
149 |
|
|
<td>outgoing (as seen by firewall)</td>
|
150 |
|
|
</tr>
|
151 |
|
|
</table>
|
152 |
|
|
<?php else: ?>
|
153 |
|
|
<p><strong>No IPsec security policies.</strong></p>
|
154 |
|
|
<?php endif; ?>
|
155 |
|
|
</td></tr></table>
|
156 |
|
|
<?php include("fend.inc"); ?>
|
157 |
|
|
</body>
|
158 |
|
|
</html>
|