diag_ipsec.php 17.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2 3
<?php
/* $Id$ */
/*
4
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
5 6 7
	Copyright (C) 2004-2009 Scott Ullrich
	Copyright (C) 2008 Shrew Soft Inc <mgrooms@shrew.net>.
	Copyright (C) 2003-2004 Manuel Kasper
8
	All rights reserved.
Ad Schellevis's avatar
Ad Schellevis committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

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

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

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

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

global $g;

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

require("guiconfig.inc");
include("head.inc");
require("ipsec.inc");

if ($_GET['act'] == 'connect') {
	if (ctype_digit($_GET['ikeid'])) {
		mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
		mwexec("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
	}
} else if ($_GET['act'] == 'ikedisconnect') {
	if (ctype_digit($_GET['ikeid'])) {
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
		else
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
	}
} else if ($_GET['act'] == 'childdisconnect') {
	if (ctype_digit($_GET['ikeid'])) {
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid']))
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
	}
}

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

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

$status = ipsec_smp_dump_status();

?>


70
<body>
Ad Schellevis's avatar
Ad Schellevis committed
71

72
<?php include("fbegin.inc"); ?>
Ad Schellevis's avatar
Ad Schellevis committed
73

74
	<section class="page-content-main">
75
		<div class="container-fluid">
76
			<div class="row">
77

78
				<?php if ($input_errors) print_input_errors($input_errors); ?>
79

80
			    <section class="col-xs-12">
81 82 83 84 85

				<? $active_tab = "/diag_ipsec.php"; include('diag_ipsec_tabs.php'); ?>

					<div class="tab-content content-box col-xs-12">

86
							<div class="table-responsive">
87
								<table class="table table-striped table-sort">
Ad Schellevis's avatar
Ad Schellevis committed
88

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
									<thead>
										<tr>
											<th class="listhdrr nowrap"><?php echo gettext("Description");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Local ID");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Local IP");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Remote ID");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Remote IP");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Role");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Reauth");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
											<th class="listhdrr nowrap"><?php echo gettext("Status");?></th>
											<td class="list nowrap"></td>
									</tr>
									</thead>
									<tbody>
									<?php
										$ipsecconnected = array();
										if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])) {
											foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa) {
												$con_id = substr($ikesa['peerconfig'], 3);
												$ipsecconnected[$con_id] = $con_id;
110

111
												if (ipsec_phase1_status($status['query']['ikesalist']['ikesa'], $ikesa['id'])) {
112
													$icon = "glyphicon glyphicon-play text-success";
113
												} elseif(!isset($config['ipsec']['enable'])) {
114
													$icon = "glyphicon glyphicon-remove text-danger";
115
												} else {
116
													$icon = "glyphicon glyphicon-remove text-warning";
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
												}
									?>
												<tr>
													<td class="listlr">
														<?php echo htmlspecialchars(ipsec_get_descr($con_id));?>
													</td>
													<td class="listr">
												<?php   if (!is_array($ikesa['local']))
														echo "Unknown";
													else {
														if (!empty($ikesa['local']['identification'])) {
															if ($ikesa['local']['identification'] == '%any')
																echo 'Any identifier';
															else
																echo htmlspecialchars($ikesa['local']['identification']);
														} else
															echo 'Unknown';
													}
												?>
													</td>
													<td class="listr">
												<?php   if (!is_array($ikesa['local']))
														echo "Unknown";
													else {
														if (!empty($ikesa['local']['address']))
															echo htmlspecialchars($ikesa['local']['address']) . '<br/>Port:' . htmlspecialchars($ikesa['local']['port']);
														else
															echo 'Unknown';
														if ($ikesa['local']['nat'] != 'false')
															echo " NAT-T";
													}
												?>
													</td>
													<td class="listr">
												<?php   if (!is_array($ikesa['remote']))
														echo "Unknown";
													else {
														$identity = "";
														if (!empty($ikesa['remote']['identification'])) {
															if ($ikesa['remote']['identification'] == '%any')
																$identity = 'Any identifier';
															else
																$identity = htmlspecialchars($ikesa['remote']['identification']);
														}
161

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
														if (is_array($ikesa['remote']['auth']) && !empty($ikesa['remote']['auth'][0]['identity'])) {
															echo htmlspecialchars($ikesa['remote']['auth'][0]['identity']);
															echo "<br/>{$identity}";
														} else {
															if (empty($identity))
																echo "Unknown";
															else
																echo $identity;
														}
													}
												?>
													</td>
													<td class="listr">
												<?php   if (!is_array($ikesa['remote']))
														echo "Unknown";
													else {
														if (!empty($ikesa['remote']['address']))
															echo htmlspecialchars($ikesa['remote']['address']) . '<br/>Port:' . htmlspecialchars($ikesa['remote']['port']);
														else
															echo 'Unknown';
														if ($ikesa['remote']['nat'] != 'false')
															echo " NAT-T";
													}
												?>
													</td>
													<td class="listr">
														IKEv<?php echo htmlspecialchars($ikesa['version']);?>
														<br/>
														<?php echo htmlspecialchars($ikesa['role']);?>
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
													</td>
													<td class="listr">
														<?php echo htmlspecialchars($ikesa['reauth']);?>
													</td>
													<td class="listr">
														<?php
															echo htmlspecialchars($ikesa['encalg']);
															echo "<br/>";
															echo htmlspecialchars($ikesa['intalg']);
															echo "<br/>";
															echo htmlspecialchars($ikesa['prfalg']);
															echo "<br/>";
															echo htmlspecialchars($ikesa['dhgroup']);
														?>
													</td>
													<td class="listr">
														<center>
209
															<span class="<?php echo $icon; ?>" title="<?php echo $ikesa['status']; ?>" alt=""></span>
210 211 212 213 214
															<br/><?php echo htmlspecialchars($ikesa['status']);?>
															<br/><?php echo htmlspecialchars($ikesa['established']);?>
														</center>
													</td>
													<td >
215
													<?php if ($icon != "glyphicon glyphicon-play text-success"): ?>
216 217
														<center>
															<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $con_id; ?>">
218
															<span class="glyphicon glyphicon-play text-default" alt="Connect VPN" title="Connect VPN"></span>
219 220 221 222 223
															</a>
														</center>
													<?php else: ?>
														<center>
															<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>">
224
															<span class="glyphicon glyphicon-stop text-default" alt="Disconnect VPN" title="Disconnect VPN"></span>
225 226
															</a>
															<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $ikesa['id']; ?>">
227
															<span class="glyphicon glyphicon-remove text-default" alt="Disconnect VPN Connection" title="Disconnect VPN Connection" border="0"></span>
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
															</a>
														</center>
													<?php endif; ?>
													</td>
													<td valign="middle" class="list nowrap">
														<table border="0" cellspacing="0" cellpadding="1" summary="">
														</table>
													</td>
												</tr>
												<?php if (is_array($ikesa['childsalist'])): ?>
												<tr>
													<td class="listrborder" colspan="9">
													<div id="btnchildsa-<?=$ikeid;?>">
														<input  type="button" onclick="show_childsa('childsa-<?=$ikeid;?>','btnchildsa-<?=$ikeid;?>');" value="+" /> - Show child SA entries
													</div>
													<table class="tabcont" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="childsa-<?=$ikeid;?>" style="display:none" summary="">
													<thead>
														<tr>
															<th class="listhdrr nowrap"><?php echo gettext("Local subnets");?></th>
															<th class="listhdrr nowrap"><?php echo gettext("Local SPI(s)");?></th>
															<th class="listhdrr nowrap"><?php echo gettext("Remote subnets");?></th>
															<th class="listhdrr nowrap"><?php echo gettext("Times");?></th>
															<th class="listhdrr nowrap"><?php echo gettext("Algo");?></th>
															<th class="listhdrr nowrap"><?php echo gettext("Stats");?></th>
														</tr>
													</thead>
													<tbody>
													<?php
														if (is_array($ikesa['childsalist']['childsa'])) {
															foreach ($ikesa['childsalist']['childsa'] as $childsa) {
													?>
														<tr valign="top">
															<td class="listlr nowrap">
													<?php	if (is_array($childsa['local']) && is_array($childsa['local']['networks']) && is_array($childsa['local']['networks']['network'])) {
															foreach ($childsa['local']['networks']['network'] as $lnets) {
																echo htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />";
															}
														} else
															echo "Unknown";
													?>
															</td>
															<td class="listr nowrap">
													<?php	if (is_array($childsa['local']))
															echo "Local: " . htmlspecialchars($childsa['local']['spi']);
													?>
													<?php	if (is_array($childsa['remote']))
															echo "<br/>Remote: " . htmlspecialchars($childsa['remote']['spi']);
													?>
															</td>
															<td class="listr nowrap">
													<?php	if (is_array($childsa['remote']) && is_array($childsa['remote']['networks']) && is_array($childsa['remote']['networks']['network'])) {
															foreach ($childsa['remote']['networks']['network'] as $rnets) {
																echo htmlspecialchars(ipsec_fixup_network($rnets)) . "<br />";
															}
														} else
															echo "Unknown";
													?>
															</td>
															<td class="listr nowrap">
																<?php
																	echo "Rekey: " . htmlspecialchars($childsa['rekey']);
																	echo "<br/>Life: " . htmlspecialchars($childsa['lifetime']);
																	echo "<br/>Install: " .htmlspecialchars($childsa['installtime']);
291

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
																?>
															</td>
															<td class="listr nowrap">
															<?php
																echo htmlspecialchars($childsa['encalg']);
																echo "<br/>";
																echo htmlspecialchars($childsa['intalg']);
																echo "<br/>";
																if (!empty($childsa['prfalg'])) {
																	echo htmlspecialchars($childsa['prfalg']);
																	echo "<br/>";
																}
																if (!empty($childsa['dhgroup'])) {
																	echo htmlspecialchars($childsa['dhgroup']);
																	echo "<br/>";
																}
																if (!empty($childsa['esn'])) {
																	echo htmlspecialchars($childsa['esn']);
																	echo "<br/>";
																}
																echo "IPComp: " . htmlspecialchars($childsa['ipcomp']);
															?>
															</td>
															<td class="listr nowrap">
															<?php
																echo "Bytes-In: " . htmlspecialchars($childsa['bytesin']) . "<br/>Packets-In: " . htmlspecialchars($childsa['packetsin']);;
																echo "<br/>";
																echo "Bytes-Out: " . htmlspecialchars($childsa['bytesout']) . "<br/>Packets-Out: " . htmlspecialchars($childsa['packetsout']);;
															?>
															</td>
															<td>
																<center>
																	<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
325
																	<span class="glyphicon glyphicon-remove text-default" alt="Disconnect Child SA" title="Disconnect Child SA"></span>
326 327 328 329 330 331 332 333 334 335 336 337 338
																	</a>
																</center>
															</td>
															<td class="list nowrap">
																&nbsp;
															</td>
														</tr>
													<?php } } ?>
														<tr style="display:none;"><td></td></tr>
													</tbody>
													</table>
													</td>
												</tr>
339 340
												<?php endif;

341 342 343
												unset($con_id);
											}
										}
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
										$rgmap = array();
										foreach ($a_phase1 as $ph1ent):
											$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
											if ($ipsecconnected[$ph1ent['ikeid']])
												continue;
									?>
											<tr>
												<td class="listlr">
													<?php echo htmlspecialchars($ph1ent['descr']);?>
												</td>
												<td class="listr">
											<?php
												list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
												if (empty($myid_data))
													echo "Unknown";
												else
													echo htmlspecialchars($myid_data);
											?>
												</td>
												<td class="listr">
											<?php
												$ph1src = ipsec_get_phase1_src($ph1ent);
												if (empty($ph1src))
													echo "Unknown";
												else
													echo htmlspecialchars($ph1src);
											?>
												</td>
												<td class="listr">
											<?php
												list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
												if (empty($peerid_data))
													echo "Unknown";
												else
													echo htmlspecialchars($peerid_data);
											?>
												</td>
												<td class="listr">
											<?php
												$ph1src = ipsec_get_phase1_dst($ph1ent);
												if (empty($ph1src))
													echo "Unknown";
												else
													echo htmlspecialchars($ph1src);
											?>
												</td>
												<td class="listr" >
												</td>
												<td class="listr" >
												</td>
												<td class="listr" >
												</td>
												<td class="listr">
													<center>
399 400
														<span class="glyphicon glyphicon-remove text-warning" title="Disconnected" alt=""></span>
														<small>Disconnected</small>
401 402 403 404 405
													</center>
												</td>
												<td >
													<center>
														<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
406
														<span class="glyphicon glyphicon-play text-default" alt="Connect VPN" title="Connect VPN"></span>
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
														</a>
													</center>
												</td>
												<td valign="middle" class="list nowrap">
													<table border="0" cellspacing="0" cellpadding="1" summary="">
													</table>
												</td>
											</tr>
									<?php
										endforeach;
										unset($ipsecconnected, $phase1, $rgmap);
									?>
												<tr style="display:none;"><td></td></tr>
											</tbody>
											</table>
422

Ad Schellevis's avatar
Ad Schellevis committed
423
											<div class="container-fluid">
424 425
											<p class="vexpl">
	<span class="text-danger">
Ad Schellevis's avatar
Ad Schellevis committed
426 427 428 429 430
		<strong><?php echo gettext("Note:");?><br /></strong>
	</span>
	<?php echo gettext("You can configure IPsec");?>
	<a href="vpn_ipsec.php">here</a>.
</p>
431 432 433
											</div>

				    </div>
434 435 436 437 438
					</div>
			    </section>
			</div>
		</div>
	</section>
439 440


441 442


Ad Schellevis's avatar
Ad Schellevis committed
443 444 445 446 447 448 449 450 451
<script type="text/javascript">
//<![CDATA[
function show_childsa(id, buttonid) {
	document.getElementById(buttonid).innerHTML='';
	aodiv = document.getElementById(id);
	aodiv.style.display = "block";
}
//]]>
</script>
452
<?php unset($status); include("foot.inc"); ?>