Project

General

Profile

Download (16.6 KB) Statistics
| Branch: | Tag: | Revision:
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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	All rights reserved.
9

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

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

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

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

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

    
35
/*
36
	pfSense_MODULE:	ipsec
37
*/
38

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

    
46

    
47
global $g;
48

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

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

    
56
if ($_GET['act'] == 'connect') {
57
	if (ctype_digit($_GET['ikeid'])) {
58
		$ph1ent = ipsec_get_phase1($_GET['ikeid']);
59
		if (!empty($ph1ent)) {
60
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1') {
61
				$ph2entries = ipsec_get_number_of_phase2($_GET['ikeid']);
62
				for ($i = 0; $i < $ph2entries; $i++) {
63
					$connid = escapeshellarg("con{$_GET['ikeid']}00{$i}");
64
					mwexec("/usr/local/sbin/ipsec down {$connid}");
65
					mwexec("/usr/local/sbin/ipsec up {$connid}");
66
				}
67
			} else {
68
				mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
69
				mwexec("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
70
			}
71
		}
72
	}
73
} else if ($_GET['act'] == 'ikedisconnect') {
74
	if (ctype_digit($_GET['ikeid'])) {
75
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
76
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
77
		else
78
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
79
	}
80
} else if ($_GET['act'] == 'childdisconnect') {
81
	if (ctype_digit($_GET['ikeid'])) {
82
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
83
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
84
	}
85
}
86

    
87
if (!is_array($config['ipsec']['phase1']))
88
    $config['ipsec']['phase1'] = array();
89

    
90
$a_phase1 = &$config['ipsec']['phase1'];
91

    
92
$status = ipsec_smp_dump_status();
93

    
94
?>
95

    
96
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?php echo $jsevents["body"]["onload"]; ?>">
97
<?php include("fbegin.inc"); ?>
98
<div id="inputerrors"></div>
99
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ipsec">
100
	<tr>
101
		<td>
102
<?php
103
			$tab_array = array();
104
			$tab_array[0] = array(gettext("Overview"), true, "diag_ipsec.php");
105
			$tab_array[1] = array(gettext("Leases"), false, "diag_ipsec_leases.php");
106
			$tab_array[2] = array(gettext("SAD"), false, "diag_ipsec_sad.php");
107
			$tab_array[3] = array(gettext("SPD"), false, "diag_ipsec_spd.php");
108
			$tab_array[4] = array(gettext("Logs"), false, "diag_logs_ipsec.php");
109
			display_top_tabs($tab_array);
110
?>
111
		</td>
112
	</tr>
113
	<tr>
114
		<td>
115
		<div id="mainarea">
116
		<table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabcont sortable" summary="status">
117
		<thead>
118
			<tr>
119
				<th class="listhdrr nowrap"><?php echo gettext("Description");?></th>
120
				<th class="listhdrr nowrap"><?php echo gettext("Local ID");?></th>
121
				<th class="listhdrr nowrap"><?php echo gettext("Local IP");?></th>
122
				<th class="listhdrr nowrap"><?php echo gettext("Remote ID");?></th>
123
				<th class="listhdrr nowrap"><?php echo gettext("Remote IP");?></th>
124
				<th class="listhdrr nowrap"><?php echo gettext("Role");?></th>
125
				<th class="listhdrr nowrap"><?php echo gettext("Reauth");?></th>
126
				<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
127
				<th class="listhdrr nowrap"><?php echo gettext("Status");?></th>
128
				<th class="list nowrap"></th>
129
			</tr>
130
		</thead>
131
		<tbody>
132
<?php
133
	$ipsecconnected = array();
134
	if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])):
135
		foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa):
136
			$con_id = substr($ikesa['peerconfig'], 3);
137
			if ($ikesa['version'] == 1) {
138
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
139
				$ipsecconnected[$ph1idx] = $ph1idx;
140
			} else {
141
				$ipsecconnected[$con_id] = $ph1idx = $con_id;
142
			}
143

    
144
			if (ipsec_phase1_status($status['query']['ikesalist']['ikesa'], $ikesa['id']))
145
				$icon = "pass";
146
			elseif (!isset($config['ipsec']['enable']))
147
				$icon = "block";
148
			else
149
				$icon = "reject";
150
?>
151
			<tr>
152
				<td class="listlr">
153
<?php
154
					echo htmlspecialchars(ipsec_get_descr($ph1idx));
155
?>
156
				</td>
157
				<td class="listr">
158
<?php
159
				if (!is_array($ikesa['local']))
160
					echo gettext("Unknown");
161
				else {
162
					if (!empty($ikesa['local']['identification'])) {
163
						if ($ikesa['local']['identification'] == '%any')
164
							echo gettext('Any identifier');
165
						else
166
							echo htmlspecialchars($ikesa['local']['identification']);
167
					} else
168
						echo gettext("Unknown");
169
				}
170
?>
171
				</td>
172
				<td class="listr">
173
<?php
174
				if (!is_array($ikesa['local']))
175
					echo gettext("Unknown");
176
				else {
177
					if (!empty($ikesa['local']['address']))
178
						echo htmlspecialchars($ikesa['local']['address']) . '<br/>' .
179
							gettext('Port: ') . htmlspecialchars($ikesa['local']['port']);
180
					else
181
						echo gettext("Unknown");
182
					if ($ikesa['local']['port'] == '4500')
183
						echo " NAT-T";
184
				}
185
?>
186
				</td>
187
				<td class="listr">
188
<?php
189
				if (!is_array($ikesa['remote']))
190
					echo gettext("Unknown");
191
				else {
192
					$identity = "";
193
					if (!empty($ikesa['remote']['identification'])) {
194
						if ($ikesa['remote']['identification'] == '%any')
195
							$identity = 'Any identifier';
196
						else
197
							$identity = htmlspecialchars($ikesa['remote']['identification']);
198
					}
199

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

    
347
?>
348
							</td>
349
							<td class="listr nowrap">
350
<?php
351
								echo htmlspecialchars($childsa['encalg']);
352
								echo "<br/>";
353
								echo htmlspecialchars($childsa['intalg']);
354
								echo "<br/>";
355
								if (!empty($childsa['prfalg'])) {
356
									echo htmlspecialchars($childsa['prfalg']);
357
									echo "<br/>";
358
								}
359
								if (!empty($childsa['dhgroup'])) {
360
									echo htmlspecialchars($childsa['dhgroup']);
361
									echo "<br/>";
362
								}
363
								if (!empty($childsa['esn'])) {
364
									echo htmlspecialchars($childsa['esn']);
365
									echo "<br/>";
366
								}
367
								echo gettext("IPComp: ") . htmlspecialchars($childsa['ipcomp']);
368
?>
369
							</td>
370
							<td class="listr nowrap">
371
<?php
372
								echo gettext("Bytes-In: ") . htmlspecialchars($childsa['bytesin']);
373
								echo "<br/>";
374
								echo gettext("Packets-In: ") . htmlspecialchars($childsa['packetsin']);
375
								echo "<br/>";
376
								echo gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytesout']);
377
								echo "<br/>";
378
								echo gettext("Packets-Out: ") . htmlspecialchars($childsa['packetsout']);
379
?>
380
							</td>
381
							<td>
382
								<center>
383
									<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
384
									<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" alt=<?php echo gettext("Disconnect Child SA");?> title=<?php echo gettext("Disconnect Child SA");?> border="0"/>
385
									</a>
386
								</center>
387
							</td>
388
							<td class="list nowrap">
389
								&nbsp;
390
							</td>
391
						</tr>
392
<?php
393
					endforeach;
394
				endif;
395
?>
396
						<tr style="display:none;"><td></td></tr>
397
					</tbody>
398
				</table>
399
				</td>
400
			</tr>
401
<?php
402
			endif;
403

    
404
			unset($con_id);
405
		endforeach;
406
	endif;
407

    
408
	$rgmap = array();
409
	foreach ($a_phase1 as $ph1ent):
410
		if (isset($ph1ent['disabled']))
411
			continue;
412
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
413
		if ($ipsecconnected[$ph1ent['ikeid']])
414
			continue;
415
?>
416
			<tr>
417
				<td class="listlr">
418
<?php
419
					echo htmlspecialchars($ph1ent['descr']);
420
?>
421
				</td>
422
				<td class="listr">
423
<?php
424
				list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
425
				if (empty($myid_data))
426
					echo gettext("Unknown");
427
				else
428
					echo htmlspecialchars($myid_data);
429
?>
430
				</td>
431
				<td class="listr">
432
<?php
433
				$ph1src = ipsec_get_phase1_src($ph1ent);
434
				if (empty($ph1src))
435
					echo gettext("Unknown");
436
				else
437
					echo htmlspecialchars($ph1src);
438
?>
439
				</td>
440
				<td class="listr">
441
<?php
442
				list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
443
				if (empty($peerid_data))
444
					echo gettext("Unknown");
445
				else
446
					echo htmlspecialchars($peerid_data);
447
?>
448
				</td>
449
				<td class="listr">
450
<?php
451
				$ph1src = ipsec_get_phase1_dst($ph1ent);
452
				if (empty($ph1src))
453
					echo gettext("Unknown");
454
				else
455
					echo htmlspecialchars($ph1src);
456
?>
457
				</td>
458
				<td class="listr" >
459
				</td>
460
				<td class="listr" >
461
				</td>
462
				<td class="listr" >
463
				</td>
464
<?php
465
			if (isset($ph1ent['mobile'])):
466
?>
467
				<td class="listr">
468
					<center>
469
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_pass.gif" title=<?php echo gettext("Awaiting connections");?> alt=""/>
470
						<br/><?php echo gettext("Awaiting connections");?>
471
					</center>
472
				</td>
473
				<td valign="middle" class="list nowrap">
474
					<table border="0" cellspacing="0" cellpadding="1" summary="">
475
					</table>
476
				</td>
477
<?php
478
			else:
479
?>
480
				<td class="listr">
481
					<center>
482
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_reject.gif" title=<?php echo gettext("Disconnected");?> alt=""/>
483
						<br/><?php echo gettext("Disconnected");?>
484
					</center>
485
				</td>
486
				<td >
487
					<center>
488
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
489
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_service_start.gif" alt=<?php echo gettext("Connect VPN");?> title=<?php echo gettext("Connect VPN");?> border="0"/>
490
						</a>
491
					</center>
492
				</td>
493
<?php
494
			endif;
495
?>
496
				<td valign="middle" class="list nowrap">
497
					<table border="0" cellspacing="0" cellpadding="1" summary="">
498
					</table>
499
				</td>
500
			</tr>
501
<?php
502
	endforeach;
503
	unset($ipsecconnected, $phase1, $rgmap);
504
?>
505
			<tr style="display:none;"><td></td></tr>
506
		</tbody>
507
		</table>
508
	</div>
509
	</td>
510
	</tr>
511
</table>
512

    
513
<p class="vexpl">
514
	<span class="red">
515
		<strong><?php echo gettext("Note:");?><br /></strong>
516
	</span>
517
	<?php echo gettext("You can configure IPsec");?>
518
	<a href="vpn_ipsec.php">here</a>.
519
</p>
520
<?php unset($status); include("fend.inc"); ?>
521
<script type="text/javascript">
522
//<![CDATA[
523
function show_childsa(id, buttonid) {
524
	document.getElementById(buttonid).innerHTML='';
525
	aodiv = document.getElementById(id);
526
	aodiv.style.display = "block";
527
}
528
//]]>
529
</script>
530
</body>
531
</html>
(14-14/256)