Projet

Général

Profil

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

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

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("Status");?></th>
113
				<td class="list nowrap"></td>
114
		</tr>
115
		</thead>
116
		<tbody>
117
<?php
118
	$ipsecconnected = array();
119
	if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])) {
120
		foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa) {
121
			$con_id = substr($ikesa['peerconfig'], 3);
122
			$ipsecconnected[$con_id] = $con_id;
123

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

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

    
322
			unset($con_id);
323
		}
324
	}
325

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

    
404
<p class="vexpl">
405
	<span class="red">
406
		<strong><?php echo gettext("Note:");?><br /></strong>
407
	</span>
408
	<?php echo gettext("You can configure IPsec");?>
409
	<a href="vpn_ipsec.php">here</a>.
410
</p>
411
<?php unset($status); include("fend.inc"); ?>
412
<script type="text/javascript">
413
//<![CDATA[
414
function show_childsa(id, buttonid) {
415
	document.getElementById(buttonid).innerHTML='';
416
	aodiv = document.getElementById(id);
417
	aodiv.style.display = "block";
418
}
419
//]]>
420
</script>
421
</body>
422
</html>
(14-14/255)