Project

General

Profile

Download (5.13 KB) Statistics
| Branch: | Tag: | Revision:
1 cf7d1057 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	diag_ipsec.php
5
	Copyright (C) 2007 Scott Ullrich
6
	All rights reserved.
7
8
	Parts of this code was originally based on vpn_ipsec_sad.php
9
	Copyright (C) 2003-2004 Manuel Kasper
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33 d88c6a9f Scott Ullrich
$pgtitle = array("Status","IPsec");
34 cf7d1057 Scott Ullrich
35
require("guiconfig.inc");
36
include("head.inc");
37
?>
38
39
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
40
<?php include("fbegin.inc"); ?>
41
<div id="inputerrors"></div>
42
<table width="100%" border="0" cellpadding="0" cellspacing="0">
43
  <tr>
44
    <td>
45
<?php
46
	$tab_array = array();
47 a097d3c0 Seth Mos
	$tab_array[0] = array("Overview", true, "diag_ipsec.php");
48 cf7d1057 Scott Ullrich
	$tab_array[1] = array("SAD", false, "diag_ipsec_sad.php");
49
	$tab_array[2] = array("SPD", false, "diag_ipsec_spd.php");
50
	display_top_tabs($tab_array);
51
?>
52
    </td>
53
  </tr>
54
  <tr>
55
    <td>
56
<?php
57
58 be34f538 Seth Mos
if (!is_array($config['ipsec']['tunnel'])) {
59
	$config['ipsec']['tunnel'] = array();
60
}
61
62 cf7d1057 Scott Ullrich
/* query SAD */
63
$fd = @popen("/sbin/setkey -D", "r");
64
$sad = array();
65
if ($fd) {
66
	while (!feof($fd)) {
67
		$line = chop(fgets($fd));
68
		if (!$line)
69
			continue;
70
		if ($line == "No SAD entries.")
71
			break;
72
		if ($line[0] != "\t") {
73
			if (is_array($cursa))
74
				$sad[] = $cursa;
75
			$cursa = array();
76
			list($cursa['src'],$cursa['dst']) = explode(" ", $line);
77
			$i = 0;
78
		} else {
79
			$linea = explode(" ", trim($line));
80
			if ($i == 1) {
81
				$cursa['proto'] = $linea[0];
82
				$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
83
			} else if ($i == 2) {
84
				$cursa['ealgo'] = $linea[1];
85
			} else if ($i == 3) {
86
				$cursa['aalgo'] = $linea[1];
87
			}
88
		}
89
		$i++;
90
	}
91
	if (is_array($cursa) && count($cursa))
92
		$sad[] = $cursa;
93
	pclose($fd);
94
}
95
?>
96
	<div id="mainarea">
97
            <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
98
<?php if (count($sad)): ?>
99
  <tr>
100
                <td nowrap class="listhdrr">Source</td>
101
                <td nowrap class="listhdrr">Destination</a></td>
102 331aa57b Scott Ullrich
                <td nowrap class="listhdrr">Description</a></td>
103 cf7d1057 Scott Ullrich
                <td nowrap class="listhdrr">Status</td>
104
	</tr>
105
<?php
106 645140bb Seth Mos
foreach ($config['ipsec']['tunnel'] as $ipsec) {
107 b05248a9 Seth Mos
	if(! isset($ipsec['disabled'])) {
108 645140bb Seth Mos
?>
109 cf7d1057 Scott Ullrich
	<tr>
110 331aa57b Scott Ullrich
		<td class="listlr"><?=htmlspecialchars(get_ipsec_tunnel_src($ipsec));?>
111
		<br/>
112
        <?php	if ($ipsec['local-subnet']['network'])
113
					echo strtoupper($ipsecent['local-subnet']['network']);
114
				else
115
					echo $ipsec['local-subnet']['address'];
116
		?>		
117
		</td>
118
		<td class="listr"><?=htmlspecialchars($ipsec['remote-gateway']);?>
119
		<br/>
120
		<?=$ipsec['remote-subnet'];?>
121
		</td>
122
		<td class="listr"><?=htmlspecialchars($ipsec['descr']);?></td>
123 cf7d1057 Scott Ullrich
		<td class="listr"><?php echo output_ipsec_tunnel_status($ipsec); ?></td>
124
	</tr>
125 645140bb Seth Mos
<?php
126
	}
127
}
128
?>
129 cf7d1057 Scott Ullrich
<?php else: ?>
130
  <tr>
131
    <td>
132
      <p>
133
        <strong>No IPsec security associations.</strong>
134
      </p>
135
    </td>
136
  </tr>
137
<?php endif; ?>
138
  <tr>
139
    <td colspan="4">
140
		  <p>
141
        <span class="vexpl">
142
          <span class="red">
143
            <strong>
144
              Note:<br />
145
            </strong>
146
          </span>
147 6ec0830d Simon Cornelius P Umacob
          You can configure your IPsec 
148 cf7d1057 Scott Ullrich
          <a href="vpn_ipsec.php">here</a>.
149
        </span>
150
      </p>
151
		</td>
152
  </tr>
153
</table>
154
</div>
155
156
</td></tr>
157
158
</table>
159
160
<?php include("fend.inc"); ?>
161
</body>
162
</html>
163
164
<?php
165
166
function get_ipsec_tunnel_src($tunnel) {
167
	global $g, $config, $sad;
168
	$if = "WAN";
169
	if ($tunnel['interface']) {
170 e461fcfc Seth Mos
		$if = $tunnel['interface'];
171 cf7d1057 Scott Ullrich
		$realinterface = convert_friendly_interface_to_real_interface_name($if);
172
		$interfaceip = find_interface_ip($realinterface);
173
	}
174
	return $interfaceip;
175
}
176
177
function output_ipsec_tunnel_status($tunnel) {
178
	global $g, $config, $sad;
179
	$if = "WAN";
180
	$interfaceip = get_ipsec_tunnel_src($tunnel);
181
	$foundsrc = false;
182
	$founddst = false;
183
	foreach($sad as $sa) {
184
		if($sa['src'] == $interfaceip) 
185
			$foundsrc = true;
186
		if($sa['dst'] == $tunnel['remote-gateway']) 
187
			$founddst = true;
188
	}
189
	if($foundsrc && $founddst) { 
190
		/* tunnel is up */
191
		$iconfn = "pass";
192
	} else {
193
		/* tunnel is down */
194
		$iconfn = "reject";
195
	}
196
	echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif'>";
197
}
198
199 a097d3c0 Seth Mos
?>