Project

General

Profile

Download (5.03 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/*
4
	diag_ipsec_spd.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="tabinact"><a href="diag_ipsec_sad.php">SAD</a></li>
49
	<li class="tabact">SPD</li>
50
  </ul>
51
  </td></tr>
52
  <tr> 
53
    <td class="tabcont">
54
<?php
55

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

    
66
/* query SAD */
67
$fd = @popen("/usr/sbin/setkey -DP", "r");
68
$spd = array();
69
if ($fd) {
70
	while (!feof($fd)) {
71
		$line = chop(fgets($fd));
72
		if (!$line)
73
			continue;
74
		if ($line == "No SPD entries.")
75
			break;
76
		if ($line[0] != "\t") {
77
			if (is_array($cursp))
78
				$spd[] = $cursp;
79
			$cursp = array();
80
			$linea = explode(" ", $line);
81
			$cursp['src'] = substr($linea[0], 0, strpos($linea[0], "["));
82
			$cursp['dst'] = substr($linea[1], 0, strpos($linea[1], "["));
83
			$i = 0;
84
		} else if (is_array($cursp)) {
85
			$linea = explode(" ", trim($line));
86
			if ($i == 1) {
87
				if ($linea[1] == "none")	/* don't show default anti-lockout rule */
88
					unset($cursp);
89
				else
90
					$cursp['dir'] = $linea[0];
91
			} else if ($i == 2) {
92
				$upperspec = explode("/", $linea[0]);
93
				$cursp['proto'] = $upperspec[0];
94
				list($cursp['ep_src'], $cursp['ep_dst']) = explode("-", $upperspec[2]);
95
			}
96
		}
97
		$i++;
98
	}
99
	if (is_array($cursp) && count($cursp))
100
		$spd[] = $cursp;
101
	pclose($fd);
102
}
103
if (count($spd)):
104
?>
105
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
106
  <tr>
107
                <td nowrap class="listhdrr">Source</td>
108
                <td nowrap class="listhdrr">Destination</a></td>
109
                <td nowrap class="listhdrr">Direction</td>
110
                <td nowrap class="listhdrr">Protocol</td>
111
                <td nowrap class="listhdrr">Tunnel endpoints</td>
112
                <td nowrap class="list"></td>
113
	</tr>
114
<?php
115
foreach ($spd as $sp): ?>
116
	<tr>
117
		<td class="listlr" valign="top"><?=htmlspecialchars($sp['src']);?></td>
118
		<td class="listr" valign="top"><?=htmlspecialchars($sp['dst']);?></td>
119
		<td class="listr" valign="top"><img src="<?=$sp['dir'];?>.gif" width="11" height="11" style="margin-top: 2px"></td>
120
		<td class="listr" valign="top"><?=htmlspecialchars(strtoupper($sp['proto']));?></td>
121
		<td class="listr" valign="top"><?=htmlspecialchars($sp['ep_src']);?> - <br>
122
			<?=htmlspecialchars($sp['ep_dst']);?></td>
123
		<td class="list" nowrap>
124
		<?php
125
			$args = "src=" . rawurlencode($sp['src']);
126
			$args .= "&dst=" . rawurlencode($sp['dst']);
127
			$args .= "&dir=" . rawurlencode($sp['dir']);
128
		?>
129
		  <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>
130
		</td>
131
				
132
	</tr>
133
<?php endforeach; ?>
134
</table>
135
<br>
136
<table border="0" cellspacing="0" cellpadding="0">
137
  <tr> 
138
	<td width="16"><img src="in.gif" width="11" height="11"></td>
139
	<td>incoming (as seen by firewall)</td>
140
  </tr>
141
  <tr> 
142
	<td colspan="5" height="4"></td>
143
  </tr>
144
  <tr> 
145
	<td><img src="out.gif" width="11" height="11"></td>
146
	<td>outgoing (as seen by firewall)</td>
147
  </tr>
148
</table>
149
<?php else: ?>
150
<p><strong>No IPsec security policies.</strong></p>
151
<?php endif; ?>
152
</td></tr></table>
153
<?php include("fend.inc"); ?>
154
</body>
155
</html>
(5-5/86)