Project

General

Profile

Download (4.72 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_ipsec_sad.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
$pgtitle = array("Status","IPsec","SA");
37
include("head.inc");
38

    
39
?>
40

    
41
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
42
<?php include("fbegin.inc"); ?>
43
<table width="100%" border="0" cellpadding="0" cellspacing="0">
44
  <tr><td>
45
<?php
46
	$tab_array = array();
47
	$tab_array[0] = array("Overview", false, "diag_ipsec.php");
48
	$tab_array[1] = array("SAD", true, "diag_ipsec_sad.php");
49
	$tab_array[2] = array("SPD", false, "diag_ipsec_spd.php");
50
	display_top_tabs($tab_array);
51
?>
52
  </td></tr>
53
  <tr>
54
    <td>
55
<?php
56

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

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

    
132
	</tr>
133
<?php endforeach; ?>
134
<?php else: ?>
135
<tr><td><p><strong>No IPsec security associations.</strong></p></td></tr>
136
<?php endif; ?>
137
<td colspan="4">
138
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
139
                      </strong></span>You can configure your IPsec <a href="vpn_ipsec.php">here</a>.</span></p>
140
		  </td>
141
</table>
142
</div>
143

    
144
</td></tr>
145

    
146
</table>
147

    
148
<?php include("fend.inc"); ?>
149
</body>
150
</html>
(11-11/187)