Projet

Général

Profil

Télécharger (12,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_ipsec.php @ fe0430f7

1
<?php
2
/* $Id$ */
3
/*
4
	diag_ipsec.php
5
	Copyright (C) 2004-2009 Scott Ullrich
6
	Copyright (C) 2008 Shrew Soft Inc <mgrooms@shrew.net>.
7
	All rights reserved.
8

    
9
	Parts of this code was originally based on vpn_ipsec_sad.php
10
	Copyright (C) 2003-2004 Manuel Kasper
11

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

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

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

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

    
34
/*
35
	pfSense_MODULE:	ipsec
36
*/
37

    
38
##|+PRIV
39
##|*IDENT=page-status-ipsec
40
##|*NAME=Status: IPsec page
41
##|*DESCR=Allow access to the 'Status: IPsec' page.
42
##|*MATCH=diag_ipsec.php*
43
##|-PRIV
44

    
45

    
46
global $g;
47

    
48
$pgtitle = array(gettext("Status"),gettext("IPsec"));
49
$shortcut_section = "ipsec";
50

    
51
require("guiconfig.inc");
52
include("head.inc");
53
require("ipsec.inc");
54

    
55
if ($_GET['act'] == 'connect') {
56
	if (ctype_digit($_GET['ikeid'])) {
57
		mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
58
		mwexec("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
59
	}
60
} else if ($_GET['act'] == 'ikedisconnect') {
61
	if (ctype_digit($_GET['ikeid'])) {
62
		mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
63
	}
64
} else if ($_GET['act'] == 'disconnect') {
65
	if (!empty($_GET['user'])) {
66
		ipsec_disconnect_mobile($_GET['user']);
67
		sleep(1);
68
		$savemsg = gettext("Disconnected user") . " " . $_GET['user'];
69
	}
70
}
71

    
72
if (!is_array($config['ipsec']['phase1']))
73
    $config['ipsec']['phase1'] = array();
74

    
75
$a_phase1 = &$config['ipsec']['phase1'];
76

    
77
$status = ipsec_smp_dump_status();
78

    
79
?>
80

    
81
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?php echo $jsevents["body"]["onload"]; ?>">
82
<?php include("fbegin.inc"); ?>
83
<div id="inputerrors"></div>
84
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ipsec">
85
	<tr>
86
		<td>
87
			<?php
88
				$tab_array = array();
89
				$tab_array[0] = array(gettext("Overview"), true, "diag_ipsec.php");
90
				$tab_array[1] = array(gettext("SAD"), false, "diag_ipsec_sad.php");
91
				$tab_array[2] = array(gettext("SPD"), false, "diag_ipsec_spd.php");
92
				$tab_array[3] = array(gettext("Logs"), false, "diag_logs_ipsec.php");
93
				display_top_tabs($tab_array);
94
			?>
95
		</td>
96
	</tr>
97
	<tr>
98
	<td>
99
	<div id="mainarea">
100
		<table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabcont sortable" summary="status">
101
		<thead>
102
			<tr>
103
				<th class="listhdrr nowrap"><?php echo gettext("Description");?></th>
104
				<th class="listhdrr nowrap"><?php echo gettext("Local ID");?></th>
105
				<th class="listhdrr nowrap"><?php echo gettext("Local IP");?></th>
106
				<th class="listhdrr nowrap"><?php echo gettext("Remote ID");?></th>
107
				<th class="listhdrr nowrap"><?php echo gettext("Remote IP");?></th>
108
				<th class="listhdrr nowrap"><?php echo gettext("Role");?></th>
109
				<th class="listhdrr nowrap"><?php echo gettext("Reauth");?></th>
110
				<th class="listhdrr nowrap"><?php echo gettext("Status");?></th>
111
				<td class="list nowrap"></td>
112
		</tr>
113
		</thead>
114
		<tbody>
115
<?php
116
	$ipsecconnected = array();
117
	if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])) {
118
		foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa) {
119
			$con_id = substr($ikesa['peerconfig'], 3);
120
			$ipsecconnected[$con_id] = $con_id;
121

    
122
			if (ipsec_phase1_status($status['query']['ikesalist']['ikesa'], $ikesa['id'])) {
123
				$icon = "pass";
124
			} elseif(!isset($config['ipsec']['enable'])) {
125
				$icon = "block";
126
			} else {
127
				$icon = "reject";
128
			}
129
?>
130
			<tr>
131
				<td class="listlr">
132
					<?php echo htmlspecialchars(ipsec_get_descr($con_id));?>
133
				</td>
134
				<td class="listr">
135
			<?php   if (!is_array($ikesa['local']))
136
					echo "Unknown";
137
				else {
138
					if (!empty($ikesa['local']['identification'])) {
139
						if ($ikesa['local']['identification'] == '%any')
140
							echo 'Any identifier';
141
						else
142
							echo htmlspecialchars($ikesa['local']['identification']);
143
					} else
144
						echo 'Unknown';
145
				}
146
			?>
147
				</td>
148
				<td class="listr">
149
			<?php   if (!is_array($ikesa['local']))
150
					echo "Unknown";
151
				else {
152
					if (!empty($ikesa['local']['address']))
153
						echo htmlspecialchars($ikesa['local']['address']) . ':' . htmlspecialchars($ikesa['local']['port']);
154
					else
155
						echo 'Unknown';
156
					if ($ikesa['local']['nat'] != 'false')
157
						echo " NAT-T";
158
				}
159
			?>
160
				</td>
161
				<td class="listr">
162
			<?php   if (!is_array($ikesa['remote']))
163
					echo "Unknown";
164
				else {
165
					if (!empty($ikesa['remote']['identification'])) {
166
						if ($ikesa['remote']['identification'] == '%any')
167
							echo 'Any identifier';
168
						else
169
							echo htmlspecialchars($ikesa['remote']['identification']);
170
					} else
171
						echo 'Unknown';
172

    
173
					if (is_array($ikesa['remote']['auth']) && !empty($ikesa['remote']['auth']['identity'])) {
174
						echo "<br/> {$ikesa['remote']['auth']['identity']}";
175
					}
176
				}
177
			?>
178
				</td>
179
				<td class="listr">
180
			<?php   if (!is_array($ikesa['remote']))
181
					echo "Unknown";
182
				else {
183
					if (!empty($ikesa['remote']['address']))
184
						echo htmlspecialchars($ikesa['remote']['address']) . ':' . htmlspecialchars($ikesa['remote']['port']);
185
					else
186
						echo 'Unknown';
187
					if ($ikesa['remote']['nat'] != 'false')
188
						echo " NAT-T";
189
				}
190
			?>
191
				</td>
192
				<td class="listr">
193
					<?php echo htmlspecialchars($ikesa['role']);?>
194
				</td>
195
				<td class="listr">
196
					<?php echo htmlspecialchars($ikesa['reauth']);?>
197
				</td>
198
				<td class="listr">
199
					<center>
200
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_<?php echo $icon; ?>.gif" title="<?php echo $ikesa['status']; ?>" alt=""/>
201
						<br/><?php echo htmlspecialchars($ikesa['status']);?>
202
					</center>
203
				</td>
204
				<td >
205
				<?php if ($icon != "pass"): ?>
206
					<center>
207
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $con_id; ?>">
208
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_start.gif" alt="Connect VPN" title="Connect VPN" border="0"/>
209
						</a>
210
					</center>
211
				<?php else: ?>
212
					<center>
213
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>">
214
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_stop.gif" alt="Disconnect VPN" title="Disconnect VPN" border="0"/>
215
						</a>
216
					</center>
217
				<?php endif; ?>
218
				</td>
219
				<td valign="middle" class="list nowrap">
220
					<table border="0" cellspacing="0" cellpadding="1" summary="">
221
					</table>
222
				</td>
223
			</tr>
224
			<?php if (is_array($ikesa['childsalist'])): ?>
225
			<tr>
226
				<td class="listrborder" colspan="8">
227
				<div id="btnchildsa-<?=$ikeid;?>">
228
					<input  type="button" onclick="show_childsa('childsa-<?=$ikeid;?>','btnchildsa-<?=$ikeid;?>');" value="+" /> - Show child SA entries
229
				</div>
230
				<table class="tabcont" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="childsa-<?=$ikeid;?>" style="display:none" summary="">
231
				<thead>
232
					<tr>
233
						<th class="listhdrr nowrap"><?php echo gettext("Local subnets");?></th>
234
						<th class="listhdrr nowrap"><?php echo gettext("Local SPI");?></th>
235
						<th class="listhdrr nowrap"><?php echo gettext("Remote SPI");?></th>
236
						<th class="listhdrr nowrap"><?php echo gettext("Remote subnets");?></th>
237
						<th class="listhdrr nowrap"><?php echo gettext("Rekey");?></th>
238
						<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
239
						<th class="listhdrr nowrap"><?php echo gettext("Stats");?></th>
240
					</tr>
241
				</thead>
242
				<tbody>
243
				<?php
244
					if (is_array($ikesa['childsalist']['childsa'])) {
245
						foreach ($ikesa['childsalist']['childsa'] as $childsa) {
246
				?>
247
					<tr valign="top">
248
						<td class="listlr nowrap">
249
				<?php	if (is_array($childsa['local']) && is_array($childsa['local']['networks']) && is_array($childsa['local']['networks']['network'])) {
250
						foreach ($childsa['local']['networks']['network'] as $lnets) {
251
							echo htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />";
252
						}
253
					} else
254
						echo "Unknown";
255
				?>
256
						</td>
257
						<td class="listr nowrap">
258
				<?php	if (is_array($childsa['local']))
259
						echo htmlspecialchars($childsa['local']['spi']);
260
				?>
261
						</td>
262
						<td class="listr nowrap">
263
				<?php	if (is_array($childsa['remote']))
264
						echo htmlspecialchars($childsa['remote']['spi']);
265
				?>
266
						</td>
267
						<td class="listr nowrap">
268
				<?php	if (is_array($childsa['remote']) && is_array($childsa['remote']['networks']) && is_array($childsa['remote']['networks']['network'])) {
269
						foreach ($childsa['remote']['networks']['network'] as $rnets) {
270
							echo htmlspecialchars(ipsec_fixup_network($rnets)) . "<br />";
271
						}
272
					} else
273
						echo "Unknown";
274
				?>
275
						</td>
276
						<td class="listr nowrap">
277
							<?php echo htmlspecialchars($childsa['rekey']); ?>
278
						</td>
279
						<td class="listr nowrap">
280
						<?php
281
							echo htmlspecialchars($childsa['encalg']);
282
							echo "<br/>";
283
							echo htmlspecialchars($childsa['intalg']);
284
							echo "<br/>";
285
							if (!empty($childsa['esn']))
286
								echo htmlspecialchars($childsa['rekey']);
287
						?>
288
						</td>
289
						<td class="listr nowrap">
290
						<?php
291
							echo "IPComp: " . htmlspecialchars($childsa['ipcomp']);
292
							echo "<br/>";
293
							echo "Bytes-In: " . htmlspecialchars($childsa['bytesin']) . "/Packets-In: " . htmlspecialchars($childsa['packetsin']);;
294
							echo "<br/>";
295
							echo "Bytes-Out: " . htmlspecialchars($childsa['bytesout']) . "/Packets-Out: " . htmlspecialchars($childsa['packetsout']);;
296
						?>
297
						</td>
298
						<td class="list nowrap">
299
							&nbsp;
300
						</td>
301
					</tr>
302
				<?php } } ?>
303
					<tr style="display:none;"><td></td></tr>
304
				</tbody>
305
				</table>
306
				</td>
307
			</tr>
308
			<?php endif; 
309

    
310
			unset($con_id);
311
		}
312
	}
313

    
314
	$rgmap = array();
315
	foreach ($a_phase1 as $ph1ent):
316
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
317
		if ($ipsecconnected[$ph1ent['ikeid']])
318
			continue;
319
?>
320
		<tr>
321
			<td class="listlr">
322
				<?php echo htmlspecialchars($ph1ent['descr']);?>
323
			</td>
324
			<td class="listr">
325
		<?php
326
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
327
			if (empty($myid_data))
328
				echo "Unknown";
329
			else
330
				echo htmlspecialchars($myid_data);
331
		?>
332
			</td>
333
			<td class="listr">
334
		<?php
335
			$ph1src = ipsec_get_phase1_src($ph1ent);
336
			if (empty($ph1src))
337
				echo "Unknown";
338
			else
339
				echo htmlspecialchars($ph1src);
340
		?>
341
			</td>
342
			<td class="listr">
343
		<?php
344
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
345
			if (empty($peerid_data))
346
				echo "Unknown";
347
			else
348
				echo htmlspecialchars($peerid_data);
349
		?>
350
			</td>
351
			<td class="listr">
352
		<?php
353
			$ph1src = ipsec_get_phase1_dst($ph1ent);
354
			if (empty($ph1src))
355
				echo "Unknown";
356
			else
357
				echo htmlspecialchars($ph1src);
358
		?>
359
			</td>
360
			<td class="listr">
361
			</td>
362
			<td class="listr">
363
				<center>
364
					<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_reject.gif" title="Disconnected" alt=""/>
365
					<br/>Disconnected
366
				</center>
367
			</td>
368
			<td >
369
				<center>
370
					<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
371
					<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_start.gif" alt="Connect VPN" title="Connect VPN" border="0"/>
372
					</a>
373
				</center>
374
			</td>
375
			<td valign="middle" class="list nowrap">
376
				<table border="0" cellspacing="0" cellpadding="1" summary="">
377
				</table>
378
			</td>
379
		</tr>
380
<?php
381
	endforeach;
382
	unset($ipsecconnected, $phase1, $rgmap);
383
?>
384
			<tr style="display:none;"><td></td></tr>
385
		</tbody>
386
		</table>
387
	</div>
388
	</td>
389
	</tr>
390
</table>
391

    
392
<p class="vexpl">
393
	<span class="red">
394
		<strong><?php echo gettext("Note:");?><br /></strong>
395
	</span>
396
	<?php echo gettext("You can configure IPsec");?>
397
	<a href="vpn_ipsec.php">here</a>.
398
</p>
399
<?php unset($status); include("fend.inc"); ?>
400
<script type="text/javascript">
401
//<![CDATA[
402
function show_childsa(id, buttonid) {
403
	document.getElementById(buttonid).innerHTML='';
404
	aodiv = document.getElementById(id);
405
	aodiv.style.display = "block";
406
}
407
//]]>
408
</script>
409
</body>
410
</html>
(14-14/255)