Project

General

Profile

Download (5.16 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
$pgtitle = "Status: IPsec";
34

    
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
<p class="pgtitle"><?=$pgtitle?></p>
42
<div id="inputerrors"></div>
43
<table width="100%" border="0" cellpadding="0" cellspacing="0">
44
  <tr>
45
    <td>
46
<?php
47
	$tab_array = array();
48
	$tab_array[0] = array("Overview", true, "diag_ipsec.php");
49
	$tab_array[1] = array("SAD", false, "diag_ipsec_sad.php");
50
	$tab_array[2] = array("SPD", false, "diag_ipsec_spd.php");
51
	display_top_tabs($tab_array);
52
?>
53
    </td>
54
  </tr>
55
  <tr>
56
    <td>
57
<?php
58

    
59
/* query SAD */
60
$fd = @popen("/sbin/setkey -D", "r");
61
$sad = array();
62
if ($fd) {
63
	while (!feof($fd)) {
64
		$line = chop(fgets($fd));
65
		if (!$line)
66
			continue;
67
		if ($line == "No SAD entries.")
68
			break;
69
		if ($line[0] != "\t") {
70
			if (is_array($cursa))
71
				$sad[] = $cursa;
72
			$cursa = array();
73
			list($cursa['src'],$cursa['dst']) = explode(" ", $line);
74
			$i = 0;
75
		} else {
76
			$linea = explode(" ", trim($line));
77
			if ($i == 1) {
78
				$cursa['proto'] = $linea[0];
79
				$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
80
			} else if ($i == 2) {
81
				$cursa['ealgo'] = $linea[1];
82
			} else if ($i == 3) {
83
				$cursa['aalgo'] = $linea[1];
84
			}
85
		}
86
		$i++;
87
	}
88
	if (is_array($cursa) && count($cursa))
89
		$sad[] = $cursa;
90
	pclose($fd);
91
}
92

    
93
if (!is_array($config['ipsec']['tunnel'])) {
94
	$config['ipsec']['tunnel'] = array();
95
}
96

    
97
?>
98
	<div id="mainarea">
99
            <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
100
<?php if (count($sad)): ?>
101
  <tr>
102
                <td nowrap class="listhdrr">Source</td>
103
                <td nowrap class="listhdrr">Destination</a></td>
104
                <td nowrap class="listhdrr">Description</a></td>
105
                <td nowrap class="listhdrr">Status</td>
106
	</tr>
107
<?php
108
foreach ($config['ipsec']['tunnel'] as $ipsec) {
109
	if(! isset($ipsec['disabled'])) {
110
?>
111
	<tr>
112
		<td class="listlr"><?=htmlspecialchars(get_ipsec_tunnel_src($ipsec));?>
113
		<br/>
114
        <?php	if ($ipsec['local-subnet']['network'])
115
					echo strtoupper($ipsecent['local-subnet']['network']);
116
				else
117
					echo $ipsec['local-subnet']['address'];
118
		?>		
119
		</td>
120
		<td class="listr"><?=htmlspecialchars($ipsec['remote-gateway']);?>
121
		<br/>
122
		<?=$ipsec['remote-subnet'];?>
123
		</td>
124
		<td class="listr"><?=htmlspecialchars($ipsec['descr']);?></td>
125
		<td class="listr"><?php echo output_ipsec_tunnel_status($ipsec); ?></td>
126
	</tr>
127
<?php 
128
	}
129
}
130
?>
131
<?php else: ?>
132
  <tr>
133
    <td>
134
      <p>
135
        <strong>No IPsec security associations.</strong>
136
      </p>
137
    </td>
138
  </tr>
139
<?php endif; ?>
140
  <tr>
141
    <td colspan="4">
142
		  <p>
143
        <span class="vexpl">
144
          <span class="red">
145
            <strong>
146
              Note:<br />
147
            </strong>
148
          </span>
149
          You can configure your IPsec 
150
          <a href="vpn_ipsec.php">here</a>.
151
        </span>
152
      </p>
153
		</td>
154
  </tr>
155
</table>
156
</div>
157

    
158
</td></tr>
159

    
160
</table>
161

    
162
<?php include("fend.inc"); ?>
163
</body>
164
</html>
165

    
166
<?php
167

    
168
function get_ipsec_tunnel_src($tunnel) {
169
	global $g, $config, $sad;
170
	$if = "WAN";
171
	if ($tunnel['interface']) {
172
		$if = $tunnel['interface'];
173
		$realinterface = convert_friendly_interface_to_real_interface_name($if);
174
		$interfaceip = find_interface_ip($realinterface);
175
	}
176
	return $interfaceip;
177
}
178

    
179
function output_ipsec_tunnel_status($tunnel) {
180
	global $g, $config, $sad;
181
	$if = "WAN";
182
	$interfaceip = get_ipsec_tunnel_src($tunnel);
183
	$foundsrc = false;
184
	$founddst = false;
185
	foreach($sad as $sa) {
186
		if($sa['src'] == $interfaceip) 
187
			$foundsrc = true;
188
		if($sa['dst'] == $tunnel['remote-gateway']) 
189
			$founddst = true;
190
	}
191
	if($foundsrc && $founddst) { 
192
		/* tunnel is up */
193
		$iconfn = "pass";
194
	} else {
195
		/* tunnel is down */
196
		$iconfn = "reject";
197
	}
198
	echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif'>";
199
}
200

    
201
?>
(10-10/173)