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
|
function get_ipsec_tunnel_src($tunnel) {
|
39
|
global $g, $config, $sad;
|
40
|
$if = "WAN";
|
41
|
if ($tunnel['interface']) {
|
42
|
$if = $tunnel['interface'];
|
43
|
$realinterface = convert_friendly_interface_to_real_interface_name($if);
|
44
|
$interfaceip = find_interface_ip($realinterface);
|
45
|
}
|
46
|
return $interfaceip;
|
47
|
}
|
48
|
|
49
|
function output_ipsec_tunnel_status($tunnel) {
|
50
|
global $g, $config, $sad;
|
51
|
$if = "WAN";
|
52
|
$interfaceip = get_ipsec_tunnel_src($tunnel);
|
53
|
$foundsrc = false;
|
54
|
$founddst = false;
|
55
|
if(!is_ipaddr($tunnel['remote-gateway']))
|
56
|
$tunnel['remote-gateway'] = resolve_retry($tunnel['remote-gateway']);
|
57
|
|
58
|
foreach($sad as $sa) {
|
59
|
if($sa['src'] == $interfaceip)
|
60
|
$foundsrc = true;
|
61
|
if($sa['dst'] == $tunnel['remote-gateway'])
|
62
|
$founddst = true;
|
63
|
}
|
64
|
if($foundsrc && $founddst) {
|
65
|
/* tunnel is up */
|
66
|
$iconfn = "pass";
|
67
|
} else {
|
68
|
/* tunnel is down */
|
69
|
$iconfn = "reject";
|
70
|
}
|
71
|
echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif'>";
|
72
|
}
|
73
|
|
74
|
/* query SAD */
|
75
|
$sad = return_ipsec_sad_array();
|
76
|
|
77
|
if (!is_array($config['ipsec']['tunnel'])) {
|
78
|
$config['ipsec']['tunnel'] = array();
|
79
|
}
|
80
|
|
81
|
?>
|
82
|
|
83
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
84
|
<?php include("fbegin.inc"); ?>
|
85
|
<p class="pgtitle"><?=$pgtitle?></p>
|
86
|
<div id="inputerrors"></div>
|
87
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
88
|
<tr>
|
89
|
<td>
|
90
|
<?php
|
91
|
$tab_array = array();
|
92
|
$tab_array[0] = array("Overview", true, "diag_ipsec.php");
|
93
|
$tab_array[1] = array("SAD", false, "diag_ipsec_sad.php");
|
94
|
$tab_array[2] = array("SPD", false, "diag_ipsec_spd.php");
|
95
|
display_top_tabs($tab_array);
|
96
|
?>
|
97
|
</td>
|
98
|
</tr>
|
99
|
<tr>
|
100
|
<td>
|
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">Description</a></td>
|
108
|
<td nowrap class="listhdrr">Status</td>
|
109
|
</tr>
|
110
|
<?php
|
111
|
foreach ($config['ipsec']['tunnel'] as $ipsec) {
|
112
|
if(! isset($ipsec['disabled'])) {
|
113
|
?>
|
114
|
<tr>
|
115
|
<td class="listlr"><?=htmlspecialchars(get_ipsec_tunnel_src($ipsec));?>
|
116
|
<br/>
|
117
|
<?php if ($ipsec['local-subnet']['network'])
|
118
|
echo strtoupper($ipsecent['local-subnet']['network']);
|
119
|
else
|
120
|
echo $ipsec['local-subnet']['address'];
|
121
|
?>
|
122
|
</td>
|
123
|
<td class="listr"><?=htmlspecialchars($ipsec['remote-gateway']);?>
|
124
|
<br/>
|
125
|
<?=$ipsec['remote-subnet'];?>
|
126
|
</td>
|
127
|
<td class="listr"><?=htmlspecialchars($ipsec['descr']);?></td>
|
128
|
<td class="listr"><?php echo output_ipsec_tunnel_status($ipsec); ?></td>
|
129
|
</tr>
|
130
|
<?php
|
131
|
}
|
132
|
}
|
133
|
?>
|
134
|
<?php else: ?>
|
135
|
<tr>
|
136
|
<td>
|
137
|
<p>
|
138
|
<strong>No IPsec security associations.</strong>
|
139
|
</p>
|
140
|
</td>
|
141
|
</tr>
|
142
|
<?php endif; ?>
|
143
|
<tr>
|
144
|
<td colspan="4">
|
145
|
<p>
|
146
|
<span class="vexpl">
|
147
|
<span class="red">
|
148
|
<strong>
|
149
|
Note:<br />
|
150
|
</strong>
|
151
|
</span>
|
152
|
You can configure your IPsec
|
153
|
<a href="vpn_ipsec.php">here</a>.
|
154
|
</span>
|
155
|
</p>
|
156
|
</td>
|
157
|
</tr>
|
158
|
</table>
|
159
|
</div>
|
160
|
|
161
|
</td></tr>
|
162
|
|
163
|
</table>
|
164
|
|
165
|
<?php include("fend.inc"); ?>
|
166
|
</body>
|
167
|
</html>
|