Projet

Général

Profil

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

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

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
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
63
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
64
		else
65
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
66
	}
67
} else if ($_GET['act'] == 'childdisconnect') {
68
	if (ctype_digit($_GET['ikeid'])) {
69
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
70
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
71
	}
72
}
73

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

    
77
$a_phase1 = &$config['ipsec']['phase1'];
78

    
79
$status = ipsec_smp_dump_status();
80

    
81
?>
82

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

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

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

    
307
							?>
308
						</td>
309
						<td class="listr nowrap">
310
						<?php
311
							echo htmlspecialchars($childsa['encalg']);
312
							echo "<br/>";
313
							echo htmlspecialchars($childsa['intalg']);
314
							echo "<br/>";
315
							if (!empty($childsa['prfalg'])) {
316
								echo htmlspecialchars($childsa['prfalg']);
317
								echo "<br/>";
318
							}
319
							if (!empty($childsa['dhgroup'])) {
320
								echo htmlspecialchars($childsa['dhgroup']);
321
								echo "<br/>";
322
							}
323
							if (!empty($childsa['esn'])) {
324
								echo htmlspecialchars($childsa['esn']);
325
								echo "<br/>";
326
							}
327
							echo "IPComp: " . htmlspecialchars($childsa['ipcomp']);
328
						?>
329
						</td>
330
						<td class="listr nowrap">
331
						<?php
332
							echo "Bytes-In: " . htmlspecialchars($childsa['bytesin']) . "<br/>Packets-In: " . htmlspecialchars($childsa['packetsin']);;
333
							echo "<br/>";
334
							echo "Bytes-Out: " . htmlspecialchars($childsa['bytesout']) . "<br/>Packets-Out: " . htmlspecialchars($childsa['packetsout']);;
335
						?>
336
						</td>
337
						<td>
338
							<center>
339
								<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
340
								<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" alt="Disconnect Child SA" title="Disconnect Child SA" border="0"/>
341
								</a>
342
							</center>
343
						</td>
344
						<td class="list nowrap">
345
							&nbsp;
346
						</td>
347
					</tr>
348
				<?php } } ?>
349
					<tr style="display:none;"><td></td></tr>
350
				</tbody>
351
				</table>
352
				</td>
353
			</tr>
354
			<?php endif; 
355

    
356
			unset($con_id);
357
		}
358
	}
359

    
360
	$rgmap = array();
361
	foreach ($a_phase1 as $ph1ent):
362
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
363
		if ($ipsecconnected[$ph1ent['ikeid']])
364
			continue;
365
?>
366
		<tr>
367
			<td class="listlr">
368
				<?php echo htmlspecialchars($ph1ent['descr']);?>
369
			</td>
370
			<td class="listr">
371
		<?php
372
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
373
			if (empty($myid_data))
374
				echo "Unknown";
375
			else
376
				echo htmlspecialchars($myid_data);
377
		?>
378
			</td>
379
			<td class="listr">
380
		<?php
381
			$ph1src = ipsec_get_phase1_src($ph1ent);
382
			if (empty($ph1src))
383
				echo "Unknown";
384
			else
385
				echo htmlspecialchars($ph1src);
386
		?>
387
			</td>
388
			<td class="listr">
389
		<?php
390
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
391
			if (empty($peerid_data))
392
				echo "Unknown";
393
			else
394
				echo htmlspecialchars($peerid_data);
395
		?>
396
			</td>
397
			<td class="listr">
398
		<?php
399
			$ph1src = ipsec_get_phase1_dst($ph1ent);
400
			if (empty($ph1src))
401
				echo "Unknown";
402
			else
403
				echo htmlspecialchars($ph1src);
404
		?>
405
			</td>
406
			<td class="listr" >
407
			</td>
408
			<td class="listr" >
409
			</td>
410
			<td class="listr" >
411
			</td>
412
			<td class="listr">
413
				<center>
414
					<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_reject.gif" title="Disconnected" alt=""/>
415
					<br/>Disconnected
416
				</center>
417
			</td>
418
			<td >
419
				<center>
420
					<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
421
					<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_start.gif" alt="Connect VPN" title="Connect VPN" border="0"/>
422
					</a>
423
				</center>
424
			</td>
425
			<td valign="middle" class="list nowrap">
426
				<table border="0" cellspacing="0" cellpadding="1" summary="">
427
				</table>
428
			</td>
429
		</tr>
430
<?php
431
	endforeach;
432
	unset($ipsecconnected, $phase1, $rgmap);
433
?>
434
			<tr style="display:none;"><td></td></tr>
435
		</tbody>
436
		</table>
437
	</div>
438
	</td>
439
	</tr>
440
</table>
441

    
442
<p class="vexpl">
443
	<span class="red">
444
		<strong><?php echo gettext("Note:");?><br /></strong>
445
	</span>
446
	<?php echo gettext("You can configure IPsec");?>
447
	<a href="vpn_ipsec.php">here</a>.
448
</p>
449
<?php unset($status); include("fend.inc"); ?>
450
<script type="text/javascript">
451
//<![CDATA[
452
function show_childsa(id, buttonid) {
453
	document.getElementById(buttonid).innerHTML='';
454
	aodiv = document.getElementById(id);
455
	aodiv.style.display = "block";
456
}
457
//]]>
458
</script>
459
</body>
460
</html>
(14-14/256)