Project

General

Profile

Download (7.94 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
        $Id$
4
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
5

    
6
        Copyright 2007 Scott Dale
7
        Part of pfSense widgets (https://www.pfsense.org)
8
        originally based on m0n0wall (http://m0n0.ch/wall)
9

    
10
        Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
11
        and Jonathan Watt <jwatt@jwatt.org>.
12
        All rights reserved.
13

    
14
        Redistribution and use in source and binary forms, with or without
15
        modification, are permitted provided that the following conditions are met:
16

    
17
        1. Redistributions of source code must retain the above copyright notice,
18
           this list of conditions and the following disclaimer.
19

    
20
        2. Redistributions in binary form must reproduce the above copyright
21
           notice, this list of conditions and the following disclaimer in the
22
           documentation and/or other materials provided with the distribution.
23

    
24
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
        POSSIBILITY OF SUCH DAMAGE.
34
*/
35

    
36
$nocsrf = true;
37

    
38
require_once("guiconfig.inc");
39
require_once("functions.inc");
40
require_once("ipsec.inc");
41

    
42
if (isset($config['ipsec']['phase1'])) { ?>
43
	<div>&nbsp;</div>
44
	<?php
45
	$tab_array = array();
46
	$tab_array[0] = array("Overview", true, "ipsec-Overview");
47
	$tab_array[1] = array("Tunnels", false, "ipsec-tunnel");
48
	$tab_array[2] = array("Mobile", false, "ipsec-mobile");
49
	display_widget_tabs($tab_array);
50

    
51
	$spd = ipsec_dump_spd();
52
	$sad = ipsec_dump_sad();
53
	$mobile = ipsec_dump_mobile();
54
	$ipsec_status = ipsec_smp_dump_status();
55

    
56
	$activecounter = 0;
57
	$inactivecounter = 0;
58

    
59
	if (!is_array($ipsec_status['query'])) {
60
		$ipsec_status['query'] = array();
61
		$ipsec_status['query']['ikesalist'] = array();
62
		$ipsec_status['query']['ikesalist']['ikesa'] = array();
63
	} else if (!is_array($ipsec_status['query']['ikesalist'])) {
64
		$ipsec_status['query']['ikesalist'] = array();
65
		$ipsec_status['query']['ikesalist']['ikesa'] = array();
66
	} else if (!is_array($ipsec_status['query']['ikesalist']['ikesa']))
67
		$ipsec_status['query']['ikesalist']['ikesa'] = array();
68

    
69
	$ipsec_detail_array = array();
70
	$ikev1num = array();
71
	if (isset($config['ipsec']['phase2'])) {
72
		foreach ($config['ipsec']['phase2'] as $ph2ent) {
73
			if ($ph2ent['remoteid']['type'] == "mobile")
74
				continue;
75
			if (!ipsec_lookup_phase1($ph2ent,$ph1ent))
76
				continue;
77

    
78
			if (isset($ph1ent['disabled']) || isset($ph2ent['disabled']))
79
				continue;
80

    
81
			if ($ph1ent['iketype'] == 'ikev1') {
82
				if (!isset($ikev1num[$ph1ent['ikeid']]))
83
					$ikev1num[$ph1ent['ikeid']] = 0;
84
				else
85
					$ikev1num[$ph1ent['ikeid']]++;
86
				$ikeid = "con{$ph1ent['ikeid']}00" . $ikev1num[$ph1ent['ikeid']];
87
			} else
88
				$ikeid = "con{$ph1ent['ikeid']}";
89

    
90
			$found = false;
91
			foreach ($ipsec_status['query']['ikesalist']['ikesa'] as $ikesa) {
92
				if ($ikeid == $ikesa['peerconfig']) {
93
					$found = true;
94
					$ph2ikeid = $ikesa['id'];
95
					if (ipsec_phase1_status($ipsec_status['query']['ikesalist']['ikesa'], $ph2ikeid)) {
96
						/* tunnel is up */
97
						$iconfn = "true";
98
						$activecounter++;
99
					} else {
100
						/* tunnel is down */
101
						$iconfn = "false";
102
						$inactivecounter++;
103
					}
104
				}
105
			}
106

    
107
			if ($found === false) {
108
				/* tunnel is down */
109
				$iconfn = "false";
110
				$inactivecounter++;
111
			}
112

    
113
			$ipsec_detail_array[] = array('src' => convert_friendly_interface_to_friendly_descr($ph1ent['interface']),
114
					'dest' => $ph1ent['remote-gateway'],
115
					'remote-subnet' => ipsec_idinfo_to_text($ph2ent['remoteid']),
116
					'descr' => $ph2ent['descr'],
117
					'status' => $iconfn);
118
		}
119
	}
120
	unset($ikev1num);
121
}
122

    
123
	if (isset($config['ipsec']['phase2'])) { ?>
124

    
125
<div id="ipsec-Overview" style="display:block;background-color:#EEEEEE;">
126
	<div>
127
	<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="heading">
128
	<tr>
129
		<td class="listhdrr nowrap">Active Tunnels</td>
130
		<td class="listhdrr nowrap">Inactive Tunnels</td>
131
		<td class="listhdrr nowrap">Mobile Users</td>
132
	</tr>
133
	<tr>
134
		<td class="listlr"><?php echo $activecounter; ?></td>
135
		<td class="listr"><?php echo $inactivecounter; ?></td>
136
		<td class="listr"><?php if (is_array($mobile['pool'])) echo htmlspecialchars($mobile['pool'][0]['usage']); else echo 0; ?></td>
137
	</tr>
138
	</table>
139
	</div>
140
</div>
141

    
142
<div id="ipsec-tunnel" style="display:none;background-color:#EEEEEE;">
143
	<div style="padding: 10px">
144
		<div style="display:table-row;">
145
			<div class="widgetsubheader" style="display:table-cell;width:40px">Source</div>
146
			<div class="widgetsubheader" style="display:table-cell;width:100px">Destination</div>
147
			<div class="widgetsubheader" style="display:table-cell;width:90px">Description</div>
148
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
149
		</div>
150
		<div style="max-height:105px;overflow:auto;">
151

    
152
	<?php foreach ($ipsec_detail_array as $ipsec) : ?>
153
	
154
		<div style="display:table-row;">
155
			<div class="listlr" style="display:table-cell;width:39px">
156
				<?php echo htmlspecialchars($ipsec['src']);?>
157
			</div>
158
			<div class="listr"  style="display:table-cell;width:100px">
159
				<?php echo $ipsec['remote-subnet'];?>
160
				<br />
161
				(<?php echo htmlspecialchars($ipsec['dest']);?>)
162
			</div>
163
			<div class="listr"  style="display:table-cell;width:90px">
164
				<?php echo htmlspecialchars($ipsec['descr']);?>
165
			</div>
166
			<div class="listr"  style="display:table-cell;width:37px" align="center">
167
			<?php
168

    
169
			if ($ipsec['status'] == "true") {
170
				/* tunnel is up */
171
				$iconfn = "interface_up";
172
			} else {
173
				/* tunnel is down */
174
				$iconfn = "interface_down";
175
			}
176

    
177
			echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif' alt='Tunnel status' width='11' height='11' />";
178
			?>
179
			</div>
180
		</div>
181
	<?php endforeach; ?>
182
	</div>
183
 </div>
184
</div>
185
<div id="ipsec-mobile" style="display:none;background-color:#EEEEEE;">
186
	<div style="padding: 10px">
187
		<div style="display:table-row;">
188
			<div class="widgetsubheader" style="display:table-cell;width:140px">User</div>
189
			<div class="widgetsubheader" style="display:table-cell;width:130px">IP</div>
190
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
191
		</div>
192
		<div style="max-height:105px;overflow:auto;">
193
<?php
194
	if (is_array($mobile['pool'])):
195
	foreach ($mobile['pool'] as $pool):
196
		if (is_array($pool['lease'])): 
197
			foreach ($pool['lease'] as $muser) : ?>
198
		<div style="display:table-row;">
199
			<div class="listlr" style="display:table-cell;width:139px">
200
				<?php echo htmlspecialchars($muser['id']);?><br />
201
			</div>
202
			<div class="listr"  style="display:table-cell;width:130px">
203
				<?php echo htmlspecialchars($muser['host']);?><br />
204
			</div>
205
			<div class="listr"  style="display:table-cell;width:30px">
206
				<?php echo htmlspecialchars($muser['status']);?><br/>
207
			</div>
208
		</div>
209
<?php
210
			endforeach;
211
		endif;
212
	endforeach;
213
	endif;
214
?>
215
		</div>
216
	</div>
217
</div>
218
<?php //end ipsec tunnel
219
}//end if tunnels are configured, else show code below
220
else { ?>
221
<div style="display:block">
222
	 <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="note">
223
	  <tr>
224
	    <td colspan="4">
225
	        <span class="vexpl">
226
	          <span class="red">
227
	            <strong>
228
	              Note: There are no configured IPsec Tunnels<br />
229
	            </strong>
230
	          </span>
231
	          You can configure your IPsec
232
	          <a href="vpn_ipsec.php">here</a>.
233
	        </span>
234
		</td>
235
	  </tr>
236
	</table>
237
</div>
238
<?php } ?>
(9-9/21)