Project

General

Profile

Download (16.3 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 = pfSense_ipsec_list_sa();
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)) {
135
		foreach ($status as $ikeid => $ikesa) {
136
			$con_id = substr($ikeid, 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 ($ikesa['state'] == "ESTABLISHED") {
145
				$icon = "pass";
146
			} elseif (!isset($config['ipsec']['enable'])) {
147
				$icon = "block";
148
			} else {
149
				$icon = "reject";
150
			}
151
?>
152
			<tr>
153
				<td class="listlr">
154
<?php
155
					echo htmlspecialchars(ipsec_get_descr($ph1idx));
156
?>
157
				</td>
158
				<td class="listr">
159
<?php
160
				if (!empty($ikesa['local-id'])) {
161
					if ($ikesa['local-id'] == '%any') {
162
						echo gettext('Any identifier');
163
					} else {
164
						echo htmlspecialchars($ikesa['local-id']);
165
					}
166
				} else {
167
					echo gettext("Unknown");
168
				}
169
					
170
?>
171
				</td>
172
				<td class="listr">
173
<?php
174
				if (!empty($ikesa['local-host'])) {
175
					echo htmlspecialchars($ikesa['local-host']) . '<br/>' .
176
						gettext('Port: ') . htmlspecialchars($ikesa['local-port']);
177
				} else {
178
					echo gettext("Unknown");
179
				}
180
				if ($ikesa['local-port'] == '4500') {
181
					echo " NAT-T";
182
				}
183

    
184
?>
185
				</td>
186
				<td class="listr">
187
<?php
188
				$identity = "";
189
				if (!empty($ikesa['remote-id'])) {
190
					if ($ikesa['remote-id'] == '%any') {
191
						$identity = 'Any identifier';
192
					} else {
193
						$identity = htmlspecialchars($ikesa['remote-id']);
194
					}
195
				}
196
				if (!empty($ikesa['remote-xauth-id'])) {
197
					echo htmlspecialchars($ikesa['remote-xauth-id']);
198
					echo "<br/>{$identity}";
199
				} elseif (!empty($ikesa['remote-eap-id'])) {
200
					echo htmlspecialchars($ikesa['remote-eap-id']);
201
					echo "<br/>{$identity}";
202
				} else {
203
					if (empty($identity))
204
						echo gettext("Unknown");
205
					else
206
						echo $identity;
207
				}
208

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

    
350
?>
351
							</td>
352
							<td class="listr nowrap">
353
<?php
354
								echo htmlspecialchars($childsa['encr-alg']);
355
								echo "<br/>";
356
								echo htmlspecialchars($childsa['integ-alg']);
357
								echo "<br/>";
358
								if (!empty($childsa['prf-alg'])) {
359
									echo htmlspecialchars($childsa['prf-alg']);
360
									echo "<br/>";
361
								}
362
								if (!empty($childsa['dh-group'])) {
363
									echo htmlspecialchars($childsa['dh-group']);
364
									echo "<br/>";
365
								}
366
								if (!empty($childsa['esn'])) {
367
									echo htmlspecialchars($childsa['esn']);
368
									echo "<br/>";
369
								}
370
								echo gettext("IPComp: ");
371
								if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
372
									echo htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']);
373
								} else {
374
									echo gettext("none");
375
								}
376
?>
377
							</td>
378
							<td class="listr nowrap">
379
<?php
380
								echo gettext("Bytes-In: ") . htmlspecialchars($childsa['bytes-in']);
381
								echo "<br/>";
382
								echo gettext("Packets-In: ") . htmlspecialchars($childsa['packets-in']);
383
								echo "<br/>";
384
								echo gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytes-out']);
385
								echo "<br/>";
386
								echo gettext("Packets-Out: ") . htmlspecialchars($childsa['packets-out']);
387
?>
388
							</td>
389
							<td>
390
								<center>
391
									<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
392
									<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"/>
393
									</a>
394
								</center>
395
							</td>
396
							<td class="list nowrap">
397
								&nbsp;
398
							</td>
399
						</tr>
400
<?php
401
					}
402
				}
403
?>
404
						<tr style="display:none;"><td></td></tr>
405
					</tbody>
406
				</table>
407
				</td>
408
			</tr>
409
<?php
410
			}
411

    
412
			unset($con_id);
413
		}
414
	}
415

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

    
523
<p class="vexpl">
524
	<span class="red">
525
		<strong><?php echo gettext("Note:");?><br /></strong>
526
	</span>
527
	<?php echo gettext("You can configure IPsec");?>
528
	<a href="vpn_ipsec.php">here</a>.
529
</p>
530
<?php unset($status); include("fend.inc"); ?>
531
<script type="text/javascript">
532
//<![CDATA[
533
function show_childsa(id, buttonid) {
534
	document.getElementById(buttonid).innerHTML='';
535
	aodiv = document.getElementById(id);
536
	aodiv.style.display = "block";
537
}
538
//]]>
539
</script>
540
</body>
541
</html>
(14-14/252)