Project

General

Profile

Download (4.8 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 b63695db Scott Ullrich
37 0f10aee4 Bill Marquette
$pgtitle = "Diagnostics: IPSec: SA";
38 b63695db Scott Ullrich
include("head.inc");
39
40 5b237745 Scott Ullrich
?>
41
42
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
43
<?php include("fbegin.inc"); ?>
44 310b2c06 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
45 5b237745 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
46
  <tr><td>
47 b63695db Scott Ullrich
<?php
48
	$tab_array = array();
49
	$tab_array[0] = array("SAD", true, "diag_ipsec_sad.php");
50
	$tab_array[1] = array("SPD", false, "diag_ipsec_spd.php");
51
	display_top_tabs($tab_array);
52
?>
53 5b237745 Scott Ullrich
  </td></tr>
54 4d875b4f Scott Ullrich
  <tr>
55 0f10aee4 Bill Marquette
    <td>
56 5b237745 Scott Ullrich
<?php
57
58
/* delete any SA? */
59
if ($_GET['act'] == "del") {
60
	$fd = @popen("/usr/sbin/setkey -c > /dev/null 2>&1", "w");
61
	if ($fd) {
62
		fwrite($fd, "delete {$_GET['src']} {$_GET['dst']} {$_GET['proto']} {$_GET['spi']} ;\n");
63
		pclose($fd);
64
		sleep(1);
65
	}
66
}
67
68
/* query SAD */
69
$fd = @popen("/usr/sbin/setkey -D", "r");
70
$sad = array();
71
if ($fd) {
72
	while (!feof($fd)) {
73
		$line = chop(fgets($fd));
74
		if (!$line)
75
			continue;
76
		if ($line == "No SAD entries.")
77
			break;
78
		if ($line[0] != "\t") {
79
			if (is_array($cursa))
80
				$sad[] = $cursa;
81
			$cursa = array();
82
			list($cursa['src'],$cursa['dst']) = explode(" ", $line);
83
			$i = 0;
84
		} else {
85
			$linea = explode(" ", trim($line));
86
			if ($i == 1) {
87
				$cursa['proto'] = $linea[0];
88
				$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
89
			} else if ($i == 2) {
90
				$cursa['ealgo'] = $linea[1];
91
			} else if ($i == 3) {
92
				$cursa['aalgo'] = $linea[1];
93
			}
94
		}
95
		$i++;
96
	}
97
	if (is_array($cursa) && count($cursa))
98
		$sad[] = $cursa;
99
	pclose($fd);
100
}
101
?>
102 0f10aee4 Bill Marquette
	<div id="mainarea">
103
            <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
104
<?php if (count($sad)): ?>
105 5b237745 Scott Ullrich
  <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 5c990bf4 Scott Ullrich
		  <a href="diag_ipsec_sad.php?act=del&<?=$args;?>" onclick="return confirm('Do you really want to delete this security association?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a>
131 5b237745 Scott Ullrich
		</td>
132 4d875b4f Scott Ullrich
133 5b237745 Scott Ullrich
	</tr>
134
<?php endforeach; ?>
135
<?php else: ?>
136 0f10aee4 Bill Marquette
<tr><td><p><strong>No IPsec security associations.</strong></p></td></tr>
137 5b237745 Scott Ullrich
<?php endif; ?>
138 c55a8ab9 Holger Bauer
<td colspan="4">
139
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
140
                      </strong></span>You can configure your IPSEC <a href="vpn_ipsec.php">here</a>.</span></p>
141
		  </td>
142 0f10aee4 Bill Marquette
</table>
143 12af52d9 Scott Ullrich
</div>
144 c55a8ab9 Holger Bauer
145
</td></tr>
146
147
</table>
148 fda1fdae Scott Ullrich
149
<meta http-equiv="refresh" content="120;url=<?php print $_SERVER['PHP_SELF']; ?>">
150
151 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
152
</body>
153
</html>