Project

General

Profile

Download (4.56 KB) Statistics
| Branch: | Tag: | Revision:
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_sad.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="tabact">SAD</li>
52
	<li class="tabinact"><a href="diag_ipsec_spd.php">SPD</a></li>
53
  </ul>
54
  </td></tr>
55 4d875b4f Scott Ullrich
  <tr>
56 5b237745 Scott Ullrich
    <td class="tabcont">
57
<?php
58
59
/* delete any SA? */
60
if ($_GET['act'] == "del") {
61
	$fd = @popen("/usr/sbin/setkey -c > /dev/null 2>&1", "w");
62
	if ($fd) {
63
		fwrite($fd, "delete {$_GET['src']} {$_GET['dst']} {$_GET['proto']} {$_GET['spi']} ;\n");
64
		pclose($fd);
65
		sleep(1);
66
	}
67
}
68
69
/* query SAD */
70
$fd = @popen("/usr/sbin/setkey -D", "r");
71
$sad = array();
72
if ($fd) {
73
	while (!feof($fd)) {
74
		$line = chop(fgets($fd));
75
		if (!$line)
76
			continue;
77
		if ($line == "No SAD entries.")
78
			break;
79
		if ($line[0] != "\t") {
80
			if (is_array($cursa))
81
				$sad[] = $cursa;
82
			$cursa = array();
83
			list($cursa['src'],$cursa['dst']) = explode(" ", $line);
84
			$i = 0;
85
		} else {
86
			$linea = explode(" ", trim($line));
87
			if ($i == 1) {
88
				$cursa['proto'] = $linea[0];
89
				$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
90
			} else if ($i == 2) {
91
				$cursa['ealgo'] = $linea[1];
92
			} else if ($i == 3) {
93
				$cursa['aalgo'] = $linea[1];
94
			}
95
		}
96
		$i++;
97
	}
98
	if (is_array($cursa) && count($cursa))
99
		$sad[] = $cursa;
100
	pclose($fd);
101
}
102
if (count($sad)):
103
?>
104
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
105
  <tr>
106
                <td nowrap class="listhdrr">Source</td>
107
                <td nowrap class="listhdrr">Destination</a></td>
108
                <td nowrap class="listhdrr">Protocol</td>
109
                <td nowrap class="listhdrr">SPI</td>
110
                <td nowrap class="listhdrr">Enc. alg.</td>
111
                <td nowrap class="listhdr">Auth. alg.</td>
112
                <td nowrap class="list"></td>
113
	</tr>
114
<?php
115
foreach ($sad as $sa): ?>
116
	<tr>
117
		<td class="listlr"><?=htmlspecialchars($sa['src']);?></td>
118
		<td class="listr"><?=htmlspecialchars($sa['dst']);?></td>
119
		<td class="listr"><?=htmlspecialchars(strtoupper($sa['proto']));?></td>
120
		<td class="listr"><?=htmlspecialchars($sa['spi']);?></td>
121
		<td class="listr"><?=htmlspecialchars($sa['ealgo']);?></td>
122
		<td class="listr"><?=htmlspecialchars($sa['aalgo']);?></td>
123
		<td class="list" nowrap>
124
		<?php
125
			$args = "src=" . rawurlencode($sa['src']);
126
			$args .= "&dst=" . rawurlencode($sa['dst']);
127
			$args .= "&proto=" . rawurlencode($sa['proto']);
128
			$args .= "&spi=" . rawurlencode("0x" . $sa['spi']);
129
		?>
130
		  <a href="diag_ipsec_sad.php?act=del&<?=$args;?>" onclick="return confirm('Do you really want to delete this security association?')"><img src="x.gif" width="17" height="17" border="0"></a>
131
		</td>
132 4d875b4f Scott Ullrich
133 5b237745 Scott Ullrich
	</tr>
134
<?php endforeach; ?>
135
</table>
136
<?php else: ?>
137
<p><strong>No IPsec security associations.</strong></p>
138
<?php endif; ?>
139
</td></tr></table>
140
<?php include("fend.inc"); ?>
141
</body>
142
</html>