Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_ipsec.php
4
*/
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
##|+PRIV
61
##|*IDENT=page-status-ipsec
62
##|*NAME=Status: IPsec
63
##|*DESCR=Allow access to the 'Status: IPsec' page.
64
##|*MATCH=status_ipsec.php*
65
##|-PRIV
66

    
67

    
68
global $g;
69

    
70
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
71
$shortcut_section = "ipsec";
72

    
73
require("guiconfig.inc");
74
include("head.inc");
75
require_once("ipsec.inc");
76

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

    
110
if (!is_array($config['ipsec']['phase1'])) {
111
	$config['ipsec']['phase1'] = array();
112
}
113

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

    
116
$status = ipsec_list_sa();
117

    
118
$tab_array = array();
119
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
120
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
121
$tab_array[] = array(gettext("SAD"), false, "status_ipsec_sad.php");
122
$tab_array[] = array(gettext("SPD"), false, "status_ipsec_spd.php");
123
display_top_tabs($tab_array);
124
?>
125

    
126
<div class="panel panel-default">
127
	<div class="panel-heading">IPsec status</div>
128
	<div class="panel-body table responsive">
129
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
130
			<thead>
131
				<tr>
132
					<th><?=gettext("Description")?></th>
133
					<th><?=gettext("Local ID")?></th>
134
					<th><?=gettext("Local IP")?></th>
135
					<th><?=gettext("Remote ID")?></th>
136
					<th><?=gettext("Remote IP")?></th>
137
					<th><?=gettext("Role")?></th>
138
					<th><?=gettext("Reauth")?></th>
139
					<th><?=gettext("Algo")?></th>
140
					<th><?=gettext("Status")?></th>
141
					<th></th>
142
				</tr>
143
			</thead>
144
			<tbody>
145
<?php
146
$ipsecconnected = array();
147

    
148
if (is_array($status)) {
149
	foreach ($status as $ikeid => $ikesa) {
150
	$con_id = substr($ikeid, 3);
151

    
152
		if ($ikesa['version'] == 1) {
153
			$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
154
			$ipsecconnected[$ph1idx] = $ph1idx;
155
		} else {
156
			$ipsecconnected[$con_id] = $ph1idx = $con_id;
157
		}
158
?>
159
				<tr>
160
					<td>
161
						<?=htmlspecialchars(ipsec_get_descr($ph1idx))?>
162
					</td>
163
					<td>
164
<?php
165
		if (!empty($ikesa['local-id'])) {
166
			if ($ikesa['local-id'] == '%any') {
167
				print(gettext('Any identifier'));
168
			} else {
169
				print(htmlspecialchars($ikesa['local-id']));
170
			}
171
		} else {
172
			print(gettext("Unknown"));
173
		}
174

    
175
?>
176
					</td>
177
					<td>
178
<?php
179
		if (!empty($ikesa['local-host'])) {
180
			print(htmlspecialchars($ikesa['local-host']));
181
		} else {
182
			print(gettext("Unknown"));
183
		}
184
		/*
185
		 * XXX: local-nat-t was defined by pfSense
186
		 * When strongswan team accepted the change, they changed it to
187
		 * nat-local. Keep both for a while and remove local-nat-t in
188
		 * the future
189
		 */
190
		if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
191
			print(" NAT-T");
192
		}
193
?>
194
					</td>
195
					<td>
196
<?php
197
		$identity = "";
198
		if (!empty($ikesa['remote-id'])) {
199
			if ($ikesa['remote-id'] == '%any') {
200
				$identity = 'Any identifier';
201
			} else {
202
				$identity = htmlspecialchars($ikesa['remote']['identification']);
203
			}
204
		}
205
		if (!empty($ikesa['remote-xauth-id'])) {
206
			echo htmlspecialchars($ikesa['remote-xauth-id']);
207
			echo "<br/>{$identity}";
208
		} elseif (!empty($ikesa['remote-eap-id'])) {
209
			echo htmlspecialchars($ikesa['remote-eap-id']);
210
			echo "<br/>{$identity}";
211
		} else {
212
			if (empty($identity)) {
213
				print(gettext("Unknown"));
214
			} else {
215
				print($identity);
216
			}
217
		}
218
?>
219
					</td>
220
					<td>
221
<?php
222
		if (!empty($ikesa['remote-host'])) {
223
			print(htmlspecialchars($ikesa['remote-host']));
224
		} else {
225
			print(gettext("Unknown"));
226
		}
227
		/*
228
		 * XXX: remote-nat-t was defined by pfSense
229
		 * When strongswan team accepted the change, they changed it to
230
		 * nat-remote. Keep both for a while and remove remote-nat-t in
231
		 * the future
232
		 */
233
		if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
234
			print(" NAT-T");
235
		}
236
?>
237
					</td>
238
					<td>
239
						IKEv<?=htmlspecialchars($ikesa['version'])?>
240
						<br/>
241
<?php
242
		if ($ikesa['initiator'] == 'yes') {
243
			print("initiator");
244
		} else {
245
			print("responder");
246
		}
247
?>
248
					</td>
249
					<td>
250
						<?=htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_hms($ikesa['reauth-time']) . ")";?>
251
					</td>
252
					<td>
253
						<?=htmlspecialchars($ikesa['encr-alg'])?>
254
						<br/>
255
						<?=htmlspecialchars($ikesa['integ-alg'])?>
256
						<br/>
257
						<?=htmlspecialchars($ikesa['prf-alg'])?>
258
						<br/>
259
						<?=htmlspecialchars($ikesa['dh-group'])?>
260
					</td>
261
					<td>
262
<?php
263
		if ($ikesa['state'] == 'ESTABLISHED') {
264
			print('<span style="color:green">');
265
		} else {
266
			print('<span>');
267
		}
268
?>
269
						<?=ucfirst(htmlspecialchars($ikesa['state']))?>
270
						<br/><?=htmlspecialchars($ikesa['established']) . gettext(" seconds (" . convert_seconds_to_hms($ikesa['established']) . ") ago")?>
271
						</span>
272
					</td>
273
					<td >
274
<?php
275
		if ($ikesa['state'] != 'ESTABLISHED') {
276
?>
277
					<a href="status_ipsec.php?act=connect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-success" data-toggle="tooltip" title="Connect VPN" >
278
							<?=gettext("Connect VPN")?>
279
						</a>
280
<?php
281
		} else {
282
?>
283
						<a href="status_ipsec.php?act=ikedisconnect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-danger" data-toggle="tooltip" title="Disconnect VPN">
284
							<?=gettext("Disconnect")?>
285
						</a><br />
286
<?php
287
		}
288
?>
289
					</td>
290
				</tr>
291
				<tr>
292
					<td colspan = 10>
293
<?php
294
		if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
295
?>
296
						<div id="btnchildsa-<?=$ikeid?>">
297
							<a type="button" onclick="show_childsa('childsa-<?=$ikeid?>','btnchildsa-<?=$ikeid?>');" class="btn btn-sm btn-default" />
298
								<?=gettext('Show child SA entries')?>
299
							</a>
300
						</div>
301

    
302
						<table class="table table-hover table-condensed" id="childsa-<?=$ikeid?>" style="display:none">
303
							<thead>
304
								<tr class="info">
305
									<th><?=gettext("Local subnets")?></th>
306
									<th><?=gettext("Local SPI(s)")?></th>
307
									<th><?=gettext("Remote subnets")?></th>
308
									<th><?=gettext("Times")?></th>
309
									<th><?=gettext("Algo")?></th>
310
									<th><?=gettext("Stats")?></th>
311
									<th><!-- Buttons --></th>
312
								</tr>
313
							</thead>
314
							<tbody>
315
<?php
316
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
317
?>
318
								<tr>
319
									<td>
320
<?php
321
				if (is_array($childsa['local-ts'])) {
322
					foreach ($childsa['local-ts'] as $lnets) {
323
						print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
324
					}
325
				} else {
326
					print(gettext("Unknown"));
327
				}
328
?>
329
									</td>
330
									<td>
331
<?php
332
				if (isset($childsa['spi-in'])) {
333
					print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
334
				}
335

    
336
				if (isset($childsa['spi-out'])) {
337
					print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
338
				}
339
?>
340
									</td>
341
									<td>
342
<?php
343
				if (is_array($childsa['remote-ts'])) {
344
					foreach ($childsa['remote-ts'] as $rnets) {
345
						print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
346
					}
347
				} else {
348
					print(gettext("Unknown"));
349
				}
350
?>
351
									</td>
352
									<td>
353
<?php
354
				print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['rekey-time']) . ")");
355
				print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['life-time']) . ")");
356
				print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['install-time']) . ")");
357

    
358
?>
359
									</td>
360
									<td>
361
<?php
362
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
363
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
364

    
365
				if (!empty($childsa['prf-alg'])) {
366
					print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
367
				}
368
				if (!empty($childsa['dh-group'])) {
369
					print(htmlspecialchars($childsa['dh-group']) . '<br/>');
370
				}
371
				if (!empty($childsa['esn'])) {
372
					print(htmlspecialchars($childsa['esn']) . '<br/>');
373
				}
374

    
375
				print(gettext("IPComp: "));
376
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
377
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
378
				} else {
379
					print(gettext('none'));
380
				}
381
?>
382
									</td>
383
									<td>
384
<?php
385
				print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
386
				print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
387
				print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
388
				print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
389
?>
390
									</td>
391
									<td>
392
										<a href="status_ipsec.php?act=childdisconnect&amp;ikeid=<?=$con_id; ?>&amp;ikesaid=<?=$childsa['uniqueid']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="<?=gettext('Disconnect Child SA')?>">
393
											<?=gettext("Disconnect")?>
394
										</a>
395
									</td>
396
								</tr>
397
<?php
398
			}
399
?>
400

    
401
							</tbody>
402
						</table>
403
					</td>
404
				</tr>
405
<?php
406
		}
407

    
408
		unset($con_id);
409
	}
410

    
411
}
412

    
413
$rgmap = array();
414
foreach ($a_phase1 as $ph1ent) {
415
	if (isset($ph1ent['disabled'])) {
416
		continue;
417
	}
418

    
419
	$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
420

    
421
	if ($ipsecconnected[$ph1ent['ikeid']]) {
422
		continue;
423
	}
424
?>
425
				<tr>
426
					<td>
427
<?php
428
	print(htmlspecialchars($ph1ent['descr']));
429
?>
430
					</td>
431
					<td>
432
<?php
433
	list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
434
	if (empty($myid_data)) {
435
		print(gettext("Unknown"));
436
	} else {
437
		print(htmlspecialchars($myid_data));
438
	}
439
?>
440
					</td>
441
					<td>
442
<?php
443
	$ph1src = ipsec_get_phase1_src($ph1ent);
444

    
445
	if (empty($ph1src)) {
446
		print(gettext("Unknown"));
447
	} else {
448
		print(htmlspecialchars($ph1src));
449
	}
450
?>
451
					</td>
452
					<td>
453
<?php
454
	list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
455
	if (empty($peerid_data)) {
456
		print(gettext("Unknown"));
457
	} else {
458
		print(htmlspecialchars($peerid_data));
459
	}
460
?>
461
					</td>
462
					<td>
463
<?php
464
	$ph1src = ipsec_get_phase1_dst($ph1ent);
465
	if (empty($ph1src)) {
466
		print(gettext("Unknown"));
467
	} else {
468
		print(htmlspecialchars($ph1src));
469
	}
470
?>
471
					</td>
472
					<td>
473
					</td>
474
					<td>
475
					</td>
476
					<td>
477
					</td>
478
<?php
479
	if (isset($ph1ent['mobile'])) {
480
?>
481
					<td>
482
						<?=gettext("Awaiting connections")?>
483
					</td>
484
					<td>
485
					</td>
486
<?php
487
	} else {
488
?>
489
					<td>
490
						<?=gettext("Disconnected")?>
491
					</td>
492
					<td >
493
						<a href="status_ipsec.php?act=connect&amp;ikeid=<?=$ph1ent['ikeid']; ?>" class="btn btn-xs btn-success">
494
							<?=gettext("Connect VPN")?>
495
						</a>
496
					</td>
497
<?php
498
	}
499
?>
500
					<td>
501
					</td>
502
				</tr>
503
<?php
504
}
505
unset($ipsecconnected, $phase1, $rgmap);
506
?>
507
			</tbody>
508
		</table>
509
	</div>
510
</div>
511

    
512
<script type="text/javascript">
513
//<![CDATA[
514
function show_childsa(id, buttonid) {
515
	document.getElementById(buttonid).innerHTML='';
516
	aodiv = document.getElementById(id);
517
	aodiv.style.display = "block";
518
}
519
//]]>
520
</script>
521

    
522
<?php
523
unset($status);
524
print_info_box(gettext("You can configure IPsec ") . '<a href="vpn_ipsec.php">Here</a>');
525
include("foot.inc"); ?>
(164-164/228)