Project

General

Profile

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

    
148
</td></tr>
149

    
150
</table>
151

    
152
<?php include("fend.inc"); ?>
153
</body>
154
</html>
155

    
156
<?php
157

    
158
function get_ipsec_tunnel_src($tunnel) {
159
	global $g, $config, $sad;
160
	$if = "WAN";
161
	if ($tunnel['interface']) {
162
		$iflabels = array('lan' => 'LAN', 'wan' => 'WAN');
163
 		$carpips = find_number_of_needed_carp_interfaces();
164
	    for($j=0; $j<$carpips; $j++) {
165
   			$interfaceip = find_interface_ip("carp" . $j);
166
  			$iflabels['carp' . $j] = $interfaceip; 
167
		}
168
		for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
169
			$realinterface = convert_friendly_interface_to_real_interface_name('opt' . $j);
170
			$iflabels['opt' . $j] = find_interface_ip($realinterface);
171
		}
172
		$interfaceip = $iflabels[$tunnel['interface']];
173
	} else {
174
		$realinterface = convert_friendly_interface_to_real_interface_name($if);
175
		$interfaceip = find_interface_ip($realinterface);
176
	}
177
	return $interfaceip;
178
}
179

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

    
202
?>
(10-10/181)