Projet

Général

Profil

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

univnautes / usr / local / www / diag_ipsec.php @ 6da9a160

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("SAD"), false, "diag_ipsec_sad.php");
93
				$tab_array[2] = array(gettext("SPD"), false, "diag_ipsec_spd.php");
94
				$tab_array[3] = array(gettext("Logs"), false, "diag_logs_ipsec.php");
95
				display_top_tabs($tab_array);
96
			?>
97
		</td>
98
	</tr>
99
	<tr>
100
	<td>
101
	<div id="mainarea">
102
		<table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabcont sortable" summary="status">
103
		<thead>
104
			<tr>
105
				<th class="listhdrr nowrap"><?php echo gettext("Description");?></th>
106
				<th class="listhdrr nowrap"><?php echo gettext("Local ID");?></th>
107
				<th class="listhdrr nowrap"><?php echo gettext("Local IP");?></th>
108
				<th class="listhdrr nowrap"><?php echo gettext("Remote ID");?></th>
109
				<th class="listhdrr nowrap"><?php echo gettext("Remote IP");?></th>
110
				<th class="listhdrr nowrap"><?php echo gettext("Role");?></th>
111
				<th class="listhdrr nowrap"><?php echo gettext("Reauth");?></th>
112
				<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
113
				<th class="listhdrr nowrap"><?php echo gettext("Status");?></th>
114
				<td class="list nowrap"></td>
115
		</tr>
116
		</thead>
117
		<tbody>
118
<?php
119
	$ipsecconnected = array();
120
	if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])) {
121
		foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa) {
122
			$con_id = substr($ikesa['peerconfig'], 3);
123
			$ipsecconnected[$con_id] = $con_id;
124

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

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

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

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

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

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