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
/*
61
	pfSense_MODULE: ipsec
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-status-ipsec
66
##|*NAME=Status: IPsec
67
##|*DESCR=Allow access to the 'Status: IPsec' page.
68
##|*MATCH=status_ipsec.php*
69
##|-PRIV
70

    
71

    
72
global $g;
73

    
74
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
75
$shortcut_section = "ipsec";
76

    
77
require("guiconfig.inc");
78
include("head.inc");
79
require_once("ipsec.inc");
80

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

    
114
if (!is_array($config['ipsec']['phase1'])) {
115
	$config['ipsec']['phase1'] = array();
116
}
117

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

    
120
$status = ipsec_list_sa();
121

    
122
$tab_array = array();
123
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
124
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
125
$tab_array[] = array(gettext("SAD"), false, "status_ipsec_sad.php");
126
$tab_array[] = array(gettext("SPD"), false, "status_ipsec_spd.php");
127
display_top_tabs($tab_array);
128
?>
129

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

    
152
if (is_array($status)) {
153
	foreach ($status as $ikeid => $ikesa) {
154
	$con_id = substr($ikeid, 3);
155

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

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

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

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

    
362
?>
363
									</td>
364
									<td>
365
<?php
366
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
367
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
368

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

    
379
				print(gettext("IPComp: "));
380
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
381
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
382
				} else {
383
					print(gettext('none'));
384
				}
385
?>
386
									</td>
387
									<td>
388
<?php
389
				print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
390
				print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
391
				print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
392
				print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
393
?>
394
									</td>
395
									<td>
396
										<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')?>">
397
											<?=gettext("Disconnect")?>
398
										</a>
399
									</td>
400
								</tr>
401
<?php
402
			}
403
?>
404

    
405
							</tbody>
406
						</table>
407
					</td>
408
				</tr>
409
<?php
410
		}
411

    
412
		unset($con_id);
413
	}
414

    
415
}
416

    
417
$rgmap = array();
418
foreach ($a_phase1 as $ph1ent) {
419
	if (isset($ph1ent['disabled'])) {
420
		continue;
421
	}
422

    
423
	$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
424

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

    
448
	if (empty($ph1src))
449
		print(gettext("Unknown"));
450
	else
451
		print(htmlspecialchars($ph1src));
452
?>
453
					</td>
454
					<td>
455
<?php
456
	list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
457
	if (empty($peerid_data))
458
		print(gettext("Unknown"));
459
	else
460
		print(htmlspecialchars($peerid_data));
461
?>
462
					</td>
463
					<td>
464
<?php
465
	$ph1src = ipsec_get_phase1_dst($ph1ent);
466
	if (empty($ph1src))
467
		print(gettext("Unknown"));
468
	else
469
		print(htmlspecialchars($ph1src));
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)