Project

General

Profile

Download (5.08 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	diag_ipsec_spd.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
require("guiconfig.inc");
35
?>
36
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
37
<html>
38
<head>
39
<title><?=gentitle("Diagnostics: IPsec");?></title>
40
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
41
<link href="gui.css" rel="stylesheet" type="text/css">
42
</head>
43

    
44
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
45
<?php include("fbegin.inc"); ?>
46
<p class="pgtitle">Diagnostics: IPsec</p>
47
<table width="100%" border="0" cellpadding="0" cellspacing="0">
48
  <tr><td>
49
  <ul id="tabnav">
50
	<li class="tabinact"><a href="diag_ipsec_sad.php">SAD</a></li>
51
	<li class="tabact">SPD</li>
52
  </ul>
53
  </td></tr>
54
  <tr>
55
    <td class="tabcont">
56
<?php
57

    
58
/* delete any SP? */
59
if ($_GET['act'] == "del") {
60
	$fd = @popen("/usr/sbin/setkey -c > /dev/null 2>&1", "w");
61
	if ($fd) {
62
		fwrite($fd, "spddelete {$_GET['src']} {$_GET['dst']} any -P {$_GET['dir']} ;\n");
63
		pclose($fd);
64
		sleep(1);
65
	}
66
}
67

    
68
/* query SAD */
69
$fd = @popen("/usr/sbin/setkey -DP", "r");
70
$spd = array();
71
if ($fd) {
72
	while (!feof($fd)) {
73
		$line = chop(fgets($fd));
74
		if (!$line)
75
			continue;
76
		if ($line == "No SPD entries.")
77
			break;
78
		if ($line[0] != "\t") {
79
			if (is_array($cursp))
80
				$spd[] = $cursp;
81
			$cursp = array();
82
			$linea = explode(" ", $line);
83
			$cursp['src'] = substr($linea[0], 0, strpos($linea[0], "["));
84
			$cursp['dst'] = substr($linea[1], 0, strpos($linea[1], "["));
85
			$i = 0;
86
		} else if (is_array($cursp)) {
87
			$linea = explode(" ", trim($line));
88
			if ($i == 1) {
89
				if ($linea[1] == "none")	/* don't show default anti-lockout rule */
90
					unset($cursp);
91
				else
92
					$cursp['dir'] = $linea[0];
93
			} else if ($i == 2) {
94
				$upperspec = explode("/", $linea[0]);
95
				$cursp['proto'] = $upperspec[0];
96
				list($cursp['ep_src'], $cursp['ep_dst']) = explode("-", $upperspec[2]);
97
			}
98
		}
99
		$i++;
100
	}
101
	if (is_array($cursp) && count($cursp))
102
		$spd[] = $cursp;
103
	pclose($fd);
104
}
105
if (count($spd)):
106
?>
107
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
108
  <tr>
109
                <td nowrap class="listhdrr">Source</td>
110
                <td nowrap class="listhdrr">Destination</a></td>
111
                <td nowrap class="listhdrr">Direction</td>
112
                <td nowrap class="listhdrr">Protocol</td>
113
                <td nowrap class="listhdrr">Tunnel endpoints</td>
114
                <td nowrap class="list"></td>
115
	</tr>
116
<?php
117
foreach ($spd as $sp): ?>
118
	<tr>
119
		<td class="listlr" valign="top"><?=htmlspecialchars($sp['src']);?></td>
120
		<td class="listr" valign="top"><?=htmlspecialchars($sp['dst']);?></td>
121
		<td class="listr" valign="top"><img src="<?=$sp['dir'];?>.gif" width="11" height="11" style="margin-top: 2px"></td>
122
		<td class="listr" valign="top"><?=htmlspecialchars(strtoupper($sp['proto']));?></td>
123
		<td class="listr" valign="top"><?=htmlspecialchars($sp['ep_src']);?> - <br>
124
			<?=htmlspecialchars($sp['ep_dst']);?></td>
125
		<td class="list" nowrap>
126
		<?php
127
			$args = "src=" . rawurlencode($sp['src']);
128
			$args .= "&dst=" . rawurlencode($sp['dst']);
129
			$args .= "&dir=" . rawurlencode($sp['dir']);
130
		?>
131
		  <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>
132
		</td>
133

    
134
	</tr>
135
<?php endforeach; ?>
136
</table>
137
<br>
138
<table border="0" cellspacing="0" cellpadding="0">
139
  <tr>
140
	<td width="16"><img src="in.gif" width="11" height="11"></td>
141
	<td>incoming (as seen by firewall)</td>
142
  </tr>
143
  <tr>
144
	<td colspan="5" height="4"></td>
145
  </tr>
146
  <tr>
147
	<td><img src="out.gif" width="11" height="11"></td>
148
	<td>outgoing (as seen by firewall)</td>
149
  </tr>
150
</table>
151
<?php else: ?>
152
<p><strong>No IPsec security policies.</strong></p>
153
<?php endif; ?>
154
</td></tr></table>
155
<?php include("fend.inc"); ?>
156
</body>
157
</html>
(5-5/97)