Project

General

Profile

Download (16.9 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
	}
81
} else if ($_GET['act'] == 'childdisconnect') {
82
	if (ctype_digit($_GET['ikeid'])) {
83
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
84
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
85
		}
86
	}
87
}
88

    
89
if (!is_array($config['ipsec']['phase1'])) {
90
	$config['ipsec']['phase1'] = array();
91
}
92

    
93
$a_phase1 = &$config['ipsec']['phase1'];
94

    
95
$status = ipsec_smp_dump_status();
96

    
97
?>
98

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

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

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

    
365
?>
366
							</td>
367
							<td class="listr nowrap">
368
<?php
369
								echo htmlspecialchars($childsa['encalg']);
370
								echo "<br/>";
371
								echo htmlspecialchars($childsa['intalg']);
372
								echo "<br/>";
373
								if (!empty($childsa['prfalg'])) {
374
									echo htmlspecialchars($childsa['prfalg']);
375
									echo "<br/>";
376
								}
377
								if (!empty($childsa['dhgroup'])) {
378
									echo htmlspecialchars($childsa['dhgroup']);
379
									echo "<br/>";
380
								}
381
								if (!empty($childsa['esn'])) {
382
									echo htmlspecialchars($childsa['esn']);
383
									echo "<br/>";
384
								}
385
								echo gettext("IPComp: ") . htmlspecialchars($childsa['ipcomp']);
386
?>
387
							</td>
388
							<td class="listr nowrap">
389
<?php
390
								echo gettext("Bytes-In: ") . htmlspecialchars($childsa['bytesin']);
391
								echo "<br/>";
392
								echo gettext("Packets-In: ") . htmlspecialchars($childsa['packetsin']);
393
								echo "<br/>";
394
								echo gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytesout']);
395
								echo "<br/>";
396
								echo gettext("Packets-Out: ") . htmlspecialchars($childsa['packetsout']);
397
?>
398
							</td>
399
							<td>
400
								<center>
401
									<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
402
									<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"/>
403
									</a>
404
								</center>
405
							</td>
406
							<td class="list nowrap">
407
								&nbsp;
408
							</td>
409
						</tr>
410
<?php
411
					endforeach;
412
				endif;
413
?>
414
						<tr style="display:none;"><td></td></tr>
415
					</tbody>
416
				</table>
417
				</td>
418
			</tr>
419
<?php
420
			endif;
421

    
422
			unset($con_id);
423
		endforeach;
424
	endif;
425

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

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