Projet

Général

Profil

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

univnautes / usr / local / www / diag_ipsec.php @ 6795e0da

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
				<th class="list nowrap"></th>
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
			<tr>
134
				<td class="listlr">
135
<?php
136
					echo htmlspecialchars(ipsec_get_descr($con_id));
137
?>
138
				</td>
139
				<td class="listr">
140
<?php
141
				if (!is_array($ikesa['local']))
142
					echo "Unknown";
143
				else {
144
					if (!empty($ikesa['local']['identification'])) {
145
						if ($ikesa['local']['identification'] == '%any')
146
							echo 'Any identifier';
147
						else
148
							echo htmlspecialchars($ikesa['local']['identification']);
149
					} else
150
						echo 'Unknown';
151
				}
152
?>
153
				</td>
154
				<td class="listr">
155
<?php
156
				if (!is_array($ikesa['local']))
157
					echo "Unknown";
158
				else {
159
					if (!empty($ikesa['local']['address']))
160
						echo htmlspecialchars($ikesa['local']['address']) . '<br/>Port:' . htmlspecialchars($ikesa['local']['port']);
161
					else
162
						echo 'Unknown';
163
					if ($ikesa['local']['nat'] != 'false')
164
						echo " NAT-T";
165
				}
166
?>
167
				</td>
168
				<td class="listr">
169
<?php
170
				if (!is_array($ikesa['remote']))
171
					echo "Unknown";
172
				else {
173
					$identity = "";
174
					if (!empty($ikesa['remote']['identification'])) {
175
						if ($ikesa['remote']['identification'] == '%any')
176
							$identity = 'Any identifier';
177
						else
178
							$identity = htmlspecialchars($ikesa['remote']['identification']);
179
					}
180

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

    
327
?>
328
							</td>
329
							<td class="listr nowrap">
330
<?php
331
								echo htmlspecialchars($childsa['encalg']);
332
								echo "<br/>";
333
								echo htmlspecialchars($childsa['intalg']);
334
								echo "<br/>";
335
								if (!empty($childsa['prfalg'])) {
336
									echo htmlspecialchars($childsa['prfalg']);
337
									echo "<br/>";
338
								}
339
								if (!empty($childsa['dhgroup'])) {
340
									echo htmlspecialchars($childsa['dhgroup']);
341
									echo "<br/>";
342
								}
343
								if (!empty($childsa['esn'])) {
344
									echo htmlspecialchars($childsa['esn']);
345
									echo "<br/>";
346
								}
347
								echo "IPComp: " . htmlspecialchars($childsa['ipcomp']);
348
?>
349
							</td>
350
							<td class="listr nowrap">
351
<?php
352
								echo "Bytes-In: " . htmlspecialchars($childsa['bytesin']) . "<br/>Packets-In: " . htmlspecialchars($childsa['packetsin']);;
353
								echo "<br/>";
354
								echo "Bytes-Out: " . htmlspecialchars($childsa['bytesout']) . "<br/>Packets-Out: " . htmlspecialchars($childsa['packetsout']);;
355
?>
356
							</td>
357
							<td>
358
								<center>
359
									<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
360
									<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" alt="Disconnect Child SA" title="Disconnect Child SA" border="0"/>
361
									</a>
362
								</center>
363
							</td>
364
							<td class="list nowrap">
365
								&nbsp;
366
							</td>
367
						</tr>
368
<?php
369
					endforeach;
370
				endif;
371
?>
372
						<tr style="display:none;"><td></td></tr>
373
					</tbody>
374
				</table>
375
				</td>
376
			</tr>
377
<?php
378
			endif;
379

    
380
			unset($con_id);
381
		endforeach;
382
	endif;
383

    
384
	$rgmap = array();
385
	foreach ($a_phase1 as $ph1ent):
386
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
387
		if ($ipsecconnected[$ph1ent['ikeid']])
388
			continue;
389
?>
390
			<tr>
391
				<td class="listlr">
392
<?php
393
					echo htmlspecialchars($ph1ent['descr']);
394
?>
395
				</td>
396
				<td class="listr">
397
<?php
398
				list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
399
				if (empty($myid_data))
400
					echo "Unknown";
401
				else
402
					echo htmlspecialchars($myid_data);
403
?>
404
				</td>
405
				<td class="listr">
406
<?php
407
				$ph1src = ipsec_get_phase1_src($ph1ent);
408
				if (empty($ph1src))
409
					echo "Unknown";
410
				else
411
					echo htmlspecialchars($ph1src);
412
?>
413
				</td>
414
				<td class="listr">
415
<?php
416
				list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
417
				if (empty($peerid_data))
418
					echo "Unknown";
419
				else
420
					echo htmlspecialchars($peerid_data);
421
?>
422
				</td>
423
				<td class="listr">
424
<?php
425
				$ph1src = ipsec_get_phase1_dst($ph1ent);
426
				if (empty($ph1src))
427
					echo "Unknown";
428
				else
429
					echo htmlspecialchars($ph1src);
430
?>
431
				</td>
432
				<td class="listr" >
433
				</td>
434
				<td class="listr" >
435
				</td>
436
				<td class="listr" >
437
				</td>
438
				<td class="listr">
439
					<center>
440
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_reject.gif" title="Disconnected" alt=""/>
441
						<br/>Disconnected
442
					</center>
443
				</td>
444
				<td >
445
					<center>
446
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
447
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_start.gif" alt="Connect VPN" title="Connect VPN" border="0"/>
448
						</a>
449
					</center>
450
				</td>
451
				<td valign="middle" class="list nowrap">
452
					<table border="0" cellspacing="0" cellpadding="1" summary="">
453
					</table>
454
				</td>
455
			</tr>
456
<?php
457
	endforeach;
458
	unset($ipsecconnected, $phase1, $rgmap);
459
?>
460
			<tr style="display:none;"><td></td></tr>
461
		</tbody>
462
		</table>
463
	</div>
464
	</td>
465
	</tr>
466
</table>
467

    
468
<p class="vexpl">
469
	<span class="red">
470
		<strong><?php echo gettext("Note:");?><br /></strong>
471
	</span>
472
	<?php echo gettext("You can configure IPsec");?>
473
	<a href="vpn_ipsec.php">here</a>.
474
</p>
475
<?php unset($status); include("fend.inc"); ?>
476
<script type="text/javascript">
477
//<![CDATA[
478
function show_childsa(id, buttonid) {
479
	document.getElementById(buttonid).innerHTML='';
480
	aodiv = document.getElementById(id);
481
	aodiv.style.display = "block";
482
}
483
//]]>
484
</script>
485
</body>
486
</html>
(14-14/256)