Project

General

Profile

Download (17.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_ipsec.php
5
 * ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
7
 *  portions Copyright (C) 2008 Shrew Soft Inc <mgrooms@shrew.net>.
8
 * 
9
 *  Parts of this code originally based on vpn_ipsec_sad.php from m0n0wall,
10
 *  Copyright (C) 2003-2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *  Redistribution and use in source and binary forms, with or without modification, 
13
 *  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
20
 *      the documentation and/or other materials provided with the
21
 *      distribution. 
22
 *
23
 *  3. All advertising materials mentioning features or use of this software 
24
 *      must display the following acknowledgment:
25
 *      "This product includes software developed by the pfSense Project
26
 *       for use in the pfSense® software distribution. (http://www.pfsense.org/). 
27
 *
28
 *  4. The names "pfSense" and "pfSense Project" must not be used to
29
 *       endorse or promote products derived from this software without
30
 *       prior written permission. For written permission, please contact
31
 *       coreteam@pfsense.org.
32
 *
33
 *  5. Products derived from this software may not be called "pfSense"
34
 *      nor may "pfSense" appear in their names without prior written
35
 *      permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *  6. Redistributions of any form whatsoever must retain the following
38
 *      acknowledgment:
39
 *
40
 *  "This product includes software developed by the pfSense Project
41
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
42
  *
43
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *  ====================================================================
57
 *
58
 */
59

    
60
/*
61
	pfSense_MODULE:	ipsec
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-status-ipsec
66
##|*NAME=Status: IPsec page
67
##|*DESCR=Allow access to the 'Status: IPsec' page.
68
##|*MATCH=diag_ipsec.php*
69
##|-PRIV
70

    
71

    
72
global $g;
73

    
74
$pgtitle = array(gettext("Status"),gettext("IPsec"));
75
$shortcut_section = "ipsec";
76

    
77
require("guiconfig.inc");
78
include("head.inc");
79
require("ipsec.inc");
80

    
81
if ($_GET['act'] == 'connect') {
82
	if (ctype_digit($_GET['ikeid'])) {
83
		$ph1ent = ipsec_get_phase1($_GET['ikeid']);
84
		if (!empty($ph1ent)) {
85
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1') {
86
				$ph2entries = ipsec_get_number_of_phase2($_GET['ikeid']);
87
				for ($i = 0; $i < $ph2entries; $i++) {
88
					$connid = escapeshellarg("con{$_GET['ikeid']}00{$i}");
89
					mwexec("/usr/local/sbin/ipsec down {$connid}");
90
					mwexec("/usr/local/sbin/ipsec up {$connid}");
91
				}
92
			} else {
93
				mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
94
				mwexec("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
95
			}
96
		}
97
	}
98
} else if ($_GET['act'] == 'ikedisconnect') {
99
	if (ctype_digit($_GET['ikeid'])) {
100
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
101
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
102
		else
103
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
104
	}
105
} else if ($_GET['act'] == 'childdisconnect') {
106
	if (ctype_digit($_GET['ikeid'])) {
107
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
108
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
109
	}
110
}
111

    
112
if (!is_array($config['ipsec']['phase1']))
113
    $config['ipsec']['phase1'] = array();
114

    
115
$a_phase1 = &$config['ipsec']['phase1'];
116

    
117
$status = pfSense_ipsec_list_sa();
118

    
119
?>
120

    
121
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?php echo $jsevents["body"]["onload"]; ?>">
122
<?php include("fbegin.inc"); ?>
123
<div id="inputerrors"></div>
124
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ipsec">
125
	<tr>
126
		<td>
127
<?php
128
			$tab_array = array();
129
			$tab_array[0] = array(gettext("Overview"), true, "diag_ipsec.php");
130
			$tab_array[1] = array(gettext("Leases"), false, "diag_ipsec_leases.php");
131
			$tab_array[2] = array(gettext("SAD"), false, "diag_ipsec_sad.php");
132
			$tab_array[3] = array(gettext("SPD"), false, "diag_ipsec_spd.php");
133
			$tab_array[4] = array(gettext("Logs"), false, "diag_logs_ipsec.php");
134
			display_top_tabs($tab_array);
135
?>
136
		</td>
137
	</tr>
138
	<tr>
139
		<td>
140
		<div id="mainarea">
141
		<table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabcont sortable" summary="status">
142
		<thead>
143
			<tr>
144
				<th class="listhdrr nowrap"><?php echo gettext("Description");?></th>
145
				<th class="listhdrr nowrap"><?php echo gettext("Local ID");?></th>
146
				<th class="listhdrr nowrap"><?php echo gettext("Local IP");?></th>
147
				<th class="listhdrr nowrap"><?php echo gettext("Remote ID");?></th>
148
				<th class="listhdrr nowrap"><?php echo gettext("Remote IP");?></th>
149
				<th class="listhdrr nowrap"><?php echo gettext("Role");?></th>
150
				<th class="listhdrr nowrap"><?php echo gettext("Reauth");?></th>
151
				<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
152
				<th class="listhdrr nowrap"><?php echo gettext("Status");?></th>
153
				<th class="list nowrap"></th>
154
			</tr>
155
		</thead>
156
		<tbody>
157
<?php
158
	$ipsecconnected = array();
159
	if (is_array($status)) {
160
		foreach ($status as $ikeid => $ikesa) {
161
			$con_id = substr($ikeid, 3);
162
			if ($ikesa['version'] == 1) {
163
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
164
				$ipsecconnected[$ph1idx] = $ph1idx;
165
			} else {
166
				$ipsecconnected[$con_id] = $ph1idx = $con_id;
167
			}
168

    
169
			if ($ikesa['state'] == "ESTABLISHED") {
170
				$icon = "pass";
171
			} elseif (!isset($config['ipsec']['enable'])) {
172
				$icon = "block";
173
			} else {
174
				$icon = "reject";
175
			}
176
?>
177
			<tr>
178
				<td class="listlr">
179
<?php
180
					echo htmlspecialchars(ipsec_get_descr($ph1idx));
181
?>
182
				</td>
183
				<td class="listr">
184
<?php
185
				if (!empty($ikesa['local-id'])) {
186
					if ($ikesa['local-id'] == '%any') {
187
						echo gettext('Any identifier');
188
					} else {
189
						echo htmlspecialchars($ikesa['local-id']);
190
					}
191
				} else {
192
					echo gettext("Unknown");
193
				}
194
					
195
?>
196
				</td>
197
				<td class="listr">
198
<?php
199
				if (!empty($ikesa['local-host'])) {
200
					echo htmlspecialchars($ikesa['local-host']);
201
				} else {
202
					echo gettext("Unknown");
203
				}
204
				if (isset($ikesa['local-nat-t'])) {
205
					echo " NAT-T";
206
				}
207

    
208
?>
209
				</td>
210
				<td class="listr">
211
<?php
212
				$identity = "";
213
				if (!empty($ikesa['remote-id'])) {
214
					if ($ikesa['remote-id'] == '%any') {
215
						$identity = 'Any identifier';
216
					} else {
217
						$identity = htmlspecialchars($ikesa['remote-id']);
218
					}
219
				}
220
				if (!empty($ikesa['remote-xauth-id'])) {
221
					echo htmlspecialchars($ikesa['remote-xauth-id']);
222
					echo "<br/>{$identity}";
223
				} elseif (!empty($ikesa['remote-eap-id'])) {
224
					echo htmlspecialchars($ikesa['remote-eap-id']);
225
					echo "<br/>{$identity}";
226
				} else {
227
					if (empty($identity))
228
						echo gettext("Unknown");
229
					else
230
						echo $identity;
231
				}
232

    
233
?>
234
				</td>
235
				<td class="listr">
236
<?php
237
				if (!empty($ikesa['remote-host'])) {
238
					echo htmlspecialchars($ikesa['remote-host']);
239
				} else {
240
					echo gettext("Unknown");
241
				}
242
				if (isset($ikesa['remote-nat-t'])) {
243
					echo " NAT-T";
244
				}
245
?>
246
				</td>
247
				<td class="listr">
248
					IKEv<?php echo htmlspecialchars($ikesa['version']);?>
249
					<br/>
250
<?php
251
				if ($ikesa['initiator'] == 'yes') {
252
					echo 'initiator';
253
				} else {
254
					echo 'responder';
255
				}
256
?>
257
				</td>
258
				<td class="listr">
259
<?php
260
					echo htmlspecialchars($ikesa['reauth-time']) . " " . gettext("seconds");
261
?>
262
				</td>
263
				<td class="listr">
264
<?php
265
					echo htmlspecialchars($ikesa['encr-alg']);
266
					echo "<br/>";
267
					echo htmlspecialchars($ikesa['integ-alg']);
268
					echo "<br/>";
269
					echo htmlspecialchars($ikesa['prf-alg']);
270
					echo "<br/>";
271
					echo htmlspecialchars($ikesa['dh-group']);
272
?>
273
				</td>
274
				<td class="listr">
275
					<center>
276
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_<?php echo $icon; ?>.gif" title="<?php echo $ikesa['status']; ?>" alt=""/>
277
						<br/><?php echo htmlspecialchars($ikesa['state']);?>
278
						<br/><?php echo htmlspecialchars($ikesa['established']) . " " . gettext("seconds ago");?>
279
					</center>
280
				</td>
281
				<td >
282
<?php
283
				if ($icon != "pass") {
284
?>
285
					<center>
286
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $con_id; ?>">
287
						<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"/>
288
						</a>
289
					</center>
290
<?php
291
				} else {
292
?>
293
					<center>
294
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>">
295
						<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"/>
296
						</a>
297
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $ikesa['uniqueid']; ?>">
298
						<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"/>
299
						</a>
300
					</center>
301
<?php
302
				}
303
?>
304
				</td>
305
				<td valign="middle" class="list nowrap">
306
					<table border="0" cellspacing="0" cellpadding="1" summary="">
307
					</table>
308
				</td>
309
			</tr>
310
<?php
311
			if (is_array($ikesa['child-sas'])) {
312
?>
313
			<tr>
314
				<td class="listrborder" colspan="9">
315
				<div id="btnchildsa-<?=$ikeid;?>">
316
					<input  type="button" onclick="show_childsa('childsa-<?=$ikeid;?>','btnchildsa-<?=$ikeid;?>');" value="+" /> - Show child SA entries
317
				</div>
318
				<table class="tabcont" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="childsa-<?=$ikeid;?>" style="display:none" summary="">
319
					<thead>
320
						<tr>
321
							<th class="listhdrr nowrap"><?php echo gettext("Local subnets");?></th>
322
							<th class="listhdrr nowrap"><?php echo gettext("Local SPI(s)");?></th>
323
							<th class="listhdrr nowrap"><?php echo gettext("Remote subnets");?></th>
324
							<th class="listhdrr nowrap"><?php echo gettext("Times");?></th>
325
							<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
326
							<th class="listhdrr nowrap"><?php echo gettext("Stats");?></th>
327
						</tr>
328
					</thead>
329
					<tbody>
330
<?php
331
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
332
?>
333
						<tr valign="top">
334
							<td class="listlr nowrap">
335
<?php
336
						if (is_array($childsa['local-ts'])) {
337
							foreach ($childsa['local-ts'] as $lnets) {
338
								echo htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />";
339
							}
340
						} else {
341
							echo gettext("Unknown");
342
						}
343
?>
344
							</td>
345
							<td class="listr nowrap">
346
<?php
347
						if (isset($childsa['spi-in'])) {
348
							echo gettext("Local: ") . htmlspecialchars($childsa['spi-in']);
349
						}
350
						if (isset($childsa['spi-out'])) {
351
							echo "<br/>" . gettext("Remote: ") . htmlspecialchars($childsa['spi-out']);
352
						}
353
?>
354
							</td>
355
							<td class="listr nowrap">
356
<?php
357
						if (is_array($childsa['remote-ts'])) {
358
							foreach ($childsa['remote-ts'] as $rnets) {
359
								echo htmlspecialchars(ipsec_fixup_network($rnets)) . "<br />";
360
							}
361
						} else {
362
							echo gettext("Unknown");
363
						}
364
?>
365
							</td>
366
							<td class="listr nowrap">
367
<?php
368
							echo gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds");
369
							echo "<br/>" . gettext("Life: ") . htmlspecialchars($childsa['life-time']) . gettext(" seconds");
370
							echo "<br/>" . gettext("Install: ") .htmlspecialchars($childsa['install-time']) . gettext(" seconds");
371

    
372
?>
373
							</td>
374
							<td class="listr nowrap">
375
<?php
376
							echo htmlspecialchars($childsa['encr-alg']);
377
							echo "<br/>";
378
							echo htmlspecialchars($childsa['integ-alg']);
379
							echo "<br/>";
380
							if (!empty($childsa['prf-alg'])) {
381
								echo htmlspecialchars($childsa['prf-alg']);
382
								echo "<br/>";
383
							}
384
							if (!empty($childsa['dh-group'])) {
385
								echo htmlspecialchars($childsa['dh-group']);
386
								echo "<br/>";
387
							}
388
							if (!empty($childsa['esn'])) {
389
								echo htmlspecialchars($childsa['esn']);
390
								echo "<br/>";
391
							}
392
							echo gettext("IPComp: ");
393
							if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
394
								echo htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']);
395
							} else {
396
								echo gettext("none");
397
							}
398
?>
399
							</td>
400
							<td class="listr nowrap">
401
<?php
402
							echo gettext("Bytes-In: ") . htmlspecialchars($childsa['bytes-in']);
403
							echo "<br/>";
404
							echo gettext("Packets-In: ") . htmlspecialchars($childsa['packets-in']);
405
							echo "<br/>";
406
							echo gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytes-out']);
407
							echo "<br/>";
408
							echo gettext("Packets-Out: ") . htmlspecialchars($childsa['packets-out']);
409
?>
410
							</td>
411
							<td>
412
								<center>
413
									<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
414
									<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"/>
415
									</a>
416
								</center>
417
							</td>
418
							<td class="list nowrap">
419
								&nbsp;
420
							</td>
421
						</tr>
422
<?php
423
					}
424
?>
425
						<tr style="display:none;"><td></td></tr>
426
					</tbody>
427
				</table>
428
				</td>
429
			</tr>
430
<?php
431
			}
432

    
433
			unset($con_id);
434
		}
435
	}
436

    
437
	$rgmap = array();
438
	foreach ($a_phase1 as $ph1ent) {
439
		if (isset($ph1ent['disabled'])) {
440
			continue;
441
		}
442
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
443
		if ($ipsecconnected[$ph1ent['ikeid']]) {
444
			continue;
445
		}
446
?>
447
			<tr>
448
				<td class="listlr">
449
<?php
450
					echo htmlspecialchars($ph1ent['descr']);
451
?>
452
				</td>
453
				<td class="listr">
454
<?php
455
				list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
456
				if (empty($myid_data))
457
					echo gettext("Unknown");
458
				else
459
					echo htmlspecialchars($myid_data);
460
?>
461
				</td>
462
				<td class="listr">
463
<?php
464
				$ph1src = ipsec_get_phase1_src($ph1ent);
465
				if (empty($ph1src))
466
					echo gettext("Unknown");
467
				else
468
					echo htmlspecialchars($ph1src);
469
?>
470
				</td>
471
				<td class="listr">
472
<?php
473
				list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
474
				if (empty($peerid_data))
475
					echo gettext("Unknown");
476
				else
477
					echo htmlspecialchars($peerid_data);
478
?>
479
				</td>
480
				<td class="listr">
481
<?php
482
				$ph1src = ipsec_get_phase1_dst($ph1ent);
483
				if (empty($ph1src))
484
					echo gettext("Unknown");
485
				else
486
					echo htmlspecialchars($ph1src);
487
?>
488
				</td>
489
				<td class="listr" >
490
				</td>
491
				<td class="listr" >
492
				</td>
493
				<td class="listr" >
494
				</td>
495
<?php
496
			if (isset($ph1ent['mobile'])) {
497
?>
498
				<td class="listr">
499
					<center>
500
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_pass.gif" title=<?php echo gettext("Awaiting connections");?> alt=""/>
501
						<br/><?php echo gettext("Awaiting connections");?>
502
					</center>
503
				</td>
504
				<td valign="middle" class="list nowrap">
505
					<table border="0" cellspacing="0" cellpadding="1" summary="">
506
					</table>
507
				</td>
508
<?php
509
			} else {
510
?>
511
				<td class="listr">
512
					<center>
513
						<img src ="/themes/<?php echo $g['theme']; ?>/images/icons/icon_reject.gif" title=<?php echo gettext("Disconnected");?> alt=""/>
514
						<br/><?php echo gettext("Disconnected");?>
515
					</center>
516
				</td>
517
				<td >
518
					<center>
519
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
520
						<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"/>
521
						</a>
522
					</center>
523
				</td>
524
<?php
525
			}
526
?>
527
				<td valign="middle" class="list nowrap">
528
					<table border="0" cellspacing="0" cellpadding="1" summary="">
529
					</table>
530
				</td>
531
			</tr>
532
<?php
533
	}
534
	unset($ipsecconnected, $phase1, $rgmap);
535
?>
536
			<tr style="display:none;"><td></td></tr>
537
		</tbody>
538
		</table>
539
	</div>
540
	</td>
541
	</tr>
542
</table>
543

    
544
<p class="vexpl">
545
	<span class="red">
546
		<strong><?php echo gettext("Note:");?><br /></strong>
547
	</span>
548
	<?php echo gettext("You can configure IPsec");?>
549
	<a href="vpn_ipsec.php">here</a>.
550
</p>
551
<?php unset($status); include("fend.inc"); ?>
552
<script type="text/javascript">
553
//<![CDATA[
554
function show_childsa(id, buttonid) {
555
	document.getElementById(buttonid).innerHTML='';
556
	aodiv = document.getElementById(id);
557
	aodiv.style.display = "block";
558
}
559
//]]>
560
</script>
561
</body>
562
</html>
(14-14/251)