Project

General

Profile

Download (4.5 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/*
4
	diag_ipsec_sad.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
35
<html>
36
<head>
37
<title><?=gentitle("Diagnostics: IPsec");?></title>
38
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
39
<link href="gui.css" rel="stylesheet" type="text/css">
40
</head>
41

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

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

    
66
/* query SAD */
67
$fd = @popen("/usr/sbin/setkey -D", "r");
68
$sad = array();
69
if ($fd) {
70
	while (!feof($fd)) {
71
		$line = chop(fgets($fd));
72
		if (!$line)
73
			continue;
74
		if ($line == "No SAD entries.")
75
			break;
76
		if ($line[0] != "\t") {
77
			if (is_array($cursa))
78
				$sad[] = $cursa;
79
			$cursa = array();
80
			list($cursa['src'],$cursa['dst']) = explode(" ", $line);
81
			$i = 0;
82
		} else {
83
			$linea = explode(" ", trim($line));
84
			if ($i == 1) {
85
				$cursa['proto'] = $linea[0];
86
				$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
87
			} else if ($i == 2) {
88
				$cursa['ealgo'] = $linea[1];
89
			} else if ($i == 3) {
90
				$cursa['aalgo'] = $linea[1];
91
			}
92
		}
93
		$i++;
94
	}
95
	if (is_array($cursa) && count($cursa))
96
		$sad[] = $cursa;
97
	pclose($fd);
98
}
99
if (count($sad)):
100
?>
101
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
102
  <tr>
103
                <td nowrap class="listhdrr">Source</td>
104
                <td nowrap class="listhdrr">Destination</a></td>
105
                <td nowrap class="listhdrr">Protocol</td>
106
                <td nowrap class="listhdrr">SPI</td>
107
                <td nowrap class="listhdrr">Enc. alg.</td>
108
                <td nowrap class="listhdr">Auth. alg.</td>
109
                <td nowrap class="list"></td>
110
	</tr>
111
<?php
112
foreach ($sad as $sa): ?>
113
	<tr>
114
		<td class="listlr"><?=htmlspecialchars($sa['src']);?></td>
115
		<td class="listr"><?=htmlspecialchars($sa['dst']);?></td>
116
		<td class="listr"><?=htmlspecialchars(strtoupper($sa['proto']));?></td>
117
		<td class="listr"><?=htmlspecialchars($sa['spi']);?></td>
118
		<td class="listr"><?=htmlspecialchars($sa['ealgo']);?></td>
119
		<td class="listr"><?=htmlspecialchars($sa['aalgo']);?></td>
120
		<td class="list" nowrap>
121
		<?php
122
			$args = "src=" . rawurlencode($sa['src']);
123
			$args .= "&dst=" . rawurlencode($sa['dst']);
124
			$args .= "&proto=" . rawurlencode($sa['proto']);
125
			$args .= "&spi=" . rawurlencode("0x" . $sa['spi']);
126
		?>
127
		  <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>
128
		</td>
129
				
130
	</tr>
131
<?php endforeach; ?>
132
</table>
133
<?php else: ?>
134
<p><strong>No IPsec security associations.</strong></p>
135
<?php endif; ?>
136
</td></tr></table>
137
<?php include("fend.inc"); ?>
138
</body>
139
</html>
(4-4/86)