diag_ipsec.php 13.9 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
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

	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";

37
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
38
include("head.inc");
39
require_once("ipsec.inc");
Ad Schellevis's avatar
Ad Schellevis committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

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']) . "}");
	}
}

60 61 62 63 64
if (!is_array($config['ipsec'])) {
    $config['ipsec'] = array();
}

if (!is_array($config['ipsec']['phase1'])) {
Ad Schellevis's avatar
Ad Schellevis committed
65
    $config['ipsec']['phase1'] = array();
66
}
Ad Schellevis's avatar
Ad Schellevis committed
67 68 69 70 71 72 73 74

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

$status = ipsec_smp_dump_status();

?>


75
<body>
Ad Schellevis's avatar
Ad Schellevis committed
76

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

79
	<section class="page-content-main">
80
		<div class="container-fluid">
81
			<div class="row">
82

83
				<?php if ($input_errors) print_input_errors($input_errors); ?>
84

85
			    <section class="col-xs-12">
86

87
				<? $active_tab = "/diag_ipsec.php"; include('diag_ipsec_tabs.inc'); ?>
88 89 90

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

91
							<div class="table-responsive">
92
								<table class="table table-striped table-sort">
93
									<thead>
94 95 96 97 98 99 100 101
									<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("Status");?></th>
102 103 104 105 106 107 108 109 110
									</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;
111

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

166 167 168 169 170 171 172 173 174 175
															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;
																}
															}
176
														}
177
													?>
178 179
													</td>
													<td class="listr">
180 181 182 183 184 185 186 187 188 189 190 191 192
													<?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";
															}
														}
													?>
193 194 195
													</td>
													<td class="listr">
														<?php echo htmlspecialchars($ikesa['role']);?>
196

197 198
													</td>
													<td class="listr">
199
															<span class="<?php echo $icon; ?>" title="<?php echo $ikesa['status']; ?>" alt=""></span>
200
															<small><?php echo htmlspecialchars($ikesa['status']);?></small>
201 202
													</td>
													<td >
203
													<?php if ($icon != "glyphicon glyphicon-play text-success"): ?>
204 205 206
														<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $con_id; ?>">
														<span class="glyphicon glyphicon-play text-default" alt="Connect VPN" title="Connect VPN"></span>
														</a>
207
													<?php else: ?>
208 209 210 211 212 213
														<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>">
														<span class="glyphicon glyphicon-stop text-default" alt="Disconnect VPN" title="Disconnect VPN"></span>
														</a>
														<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $ikesa['id']; ?>">
														<span class="glyphicon glyphicon-remove text-default" alt="Disconnect VPN Connection" title="Disconnect VPN Connection" border="0"></span>
														</a>
214 215 216 217 218
													<?php endif; ?>
													</td>
												</tr>
												<?php if (is_array($ikesa['childsalist'])): ?>
												<tr>
219
													<td class="listrborder" colspan="10">
220 221 222
													<div id="btnchildsa-<?=$ikeid;?>">
														<input  type="button" onclick="show_childsa('childsa-<?=$ikeid;?>','btnchildsa-<?=$ikeid;?>');" value="+" /> - Show child SA entries
													</div>
223
													<table class="table table-sort" id="childsa-<?=$ikeid;?>" style="display:none">
224 225
													<thead>
														<tr>
226
															<th> </th>
227 228 229 230 231 232 233 234 235 236 237
															<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>
														</tr>
													</thead>
													<tbody>
													<?php
														if (is_array($ikesa['childsalist']['childsa'])) {
															foreach ($ikesa['childsalist']['childsa'] as $childsa) {
													?>
														<tr valign="top">
238 239 240 241 242
															<td>
																<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?php echo $con_id; ?>&amp;ikesaid=<?php echo $childsa['reqid']; ?>">
																<span class="glyphicon glyphicon-remove text-default" alt="Disconnect Child SA" title="Disconnect Child SA"></span>
																</a>
															</td>
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
															<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>
														</tr>
													<?php } } ?>
														<tr style="display:none;"><td></td></tr>
													</tbody>
													</table>
													</td>
												</tr>
276 277
												<?php endif;

278 279 280
												unset($con_id);
											}
										}
281

282 283 284 285 286 287 288 289 290 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 325 326 327 328 329 330
										$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">
331 332
													<span class="glyphicon glyphicon-remove text-warning" title="Disconnected" alt=""></span>
													<small>Disconnected</small>
333 334
												</td>
												<td >
335 336 337
													<a href="diag_ipsec.php?act=connect&amp;ikeid=<?php echo $ph1ent['ikeid']; ?>">
													<span class="glyphicon glyphicon-play text-default" alt="Connect VPN" title="Connect VPN"></span>
													</a>
338 339 340 341 342 343 344 345 346
												</td>
											</tr>
									<?php
										endforeach;
										unset($ipsecconnected, $phase1, $rgmap);
									?>
												<tr style="display:none;"><td></td></tr>
											</tbody>
											</table>
347

Ad Schellevis's avatar
Ad Schellevis committed
348
											<div class="container-fluid">
349 350
											<p class="vexpl">
	<span class="text-danger">
Ad Schellevis's avatar
Ad Schellevis committed
351 352 353 354 355
		<strong><?php echo gettext("Note:");?><br /></strong>
	</span>
	<?php echo gettext("You can configure IPsec");?>
	<a href="vpn_ipsec.php">here</a>.
</p>
356 357 358
											</div>

				    </div>
359 360 361 362 363
					</div>
			    </section>
			</div>
		</div>
	</section>
364 365


366 367


Ad Schellevis's avatar
Ad Schellevis committed
368 369 370 371 372
<script type="text/javascript">
//<![CDATA[
function show_childsa(id, buttonid) {
	document.getElementById(buttonid).innerHTML='';
	aodiv = document.getElementById(id);
373
	aodiv.style.display = "";
Ad Schellevis's avatar
Ad Schellevis committed
374 375 376
}
//]]>
</script>
377
<?php unset($status); include("foot.inc"); ?>