Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status_openvpn.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2008 Shrew Soft Inc.
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
##|+PRIV
26
##|*IDENT=page-status-openvpn
27
##|*NAME=Status: OpenVPN
28
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
29
##|*MATCH=status_openvpn.php*
30
##|-PRIV
31

    
32
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
33
$shortcut_section = "openvpn";
34

    
35
require_once("guiconfig.inc");
36
require_once("openvpn.inc");
37
require_once("shortcuts.inc");
38
require_once("service-utils.inc");
39

    
40
/* Handle AJAX */
41
if ($_REQUEST['action']) {
42
	if ($_REQUEST['action'] == "kill") {
43
		$port  = $_REQUEST['port'];
44
		$remipp  = $_REQUEST['remipp'];
45
		$client_id  = $_REQUEST['client_id'];
46
		if (!empty($port) and !empty($remipp)) {
47
			$retval = openvpn_kill_client($port, $remipp, $client_id);
48
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
49
		} else {
50
			echo gettext("invalid input");
51
		}
52
		exit;
53
	}
54
}
55
if ($_POST['action']) {
56
	if (($_POST['action'] == "showrule") && is_numeric($_POST['vpnid']) &&
57
	    !preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['username']) && is_port($_POST['port'])) {
58
		$rulesfile = "{$g['tmp_path']}/ovpn_ovpns{$_POST['vpnid']}_{$_POST['username']}_{$_POST['port']}.rules";
59
		if (file_exists($rulesfile)) {
60
			$rule_text = base64_encode(file_get_contents($rulesfile));
61
			echo $rule_text;
62
		}
63
		exit;
64
	}
65
}
66

    
67
$servers = openvpn_get_active_servers();
68
$sk_servers = openvpn_get_active_servers("p2p");
69
$clients = openvpn_get_active_clients();
70

    
71
include("head.inc"); ?>
72

    
73
<form action="status_openvpn.php" method="get" name="iform">
74
<script type="text/javascript">
75
//<![CDATA[
76
	function killClient(mport, remipp, client_id) {
77
		var busy = function(index,icon) {
78
			$(icon).bind("onclick","");
79
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
80
			$(icon).css("cursor","wait");
81
		}
82

    
83
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
84

    
85
		$.ajax(
86
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
87
				"?action=kill&port=" + mport + "&remipp=" + remipp + "&client_id=" + client_id,
88
			{ type: "get", complete: killComplete }
89
		);
90
	}
91

    
92
	function killComplete(req) {
93
		var values = req.responseText.split("|");
94
		if (values[3] != "0") {
95
	//		alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
96
			return;
97
		}
98

    
99
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
100
			function(index,row) { $(row).fadeOut(1000); }
101
		);
102
	}
103

    
104
	function showRuleContents(vpnid, username, port) {
105
			$('#rulesviewer_text').text("...Loading...");
106
			$('#rulesviewer').modal('show');
107

    
108
			$.ajax(
109
				"<?=$_SERVER['SCRIPT_NAME'];?>",
110
				{
111
					type: 'post',
112
					data: {
113
						vpnid:           vpnid,
114
						username:     username,
115
						port:             port,
116
						action:      'showrule'
117
					},
118
					complete: ruleComplete
119
				}
120
			);
121
	}
122

    
123
	function ruleComplete(req) {
124
			$('#rulesviewer_text').text(atob(req.responseText));
125
			$('#rulesviewer_text').attr('readonly', true);
126
	}
127

    
128
//]]>
129
</script>
130

    
131
<?php
132
	$i = 0;
133
	foreach ($servers as $server):
134
?>
135

    
136
<div class="panel panel-default">
137
		<div class="panel-heading"><h2 class="panel-title">ovpns<?= $server['vpnid'] ?>: <?=htmlspecialchars($server['name']);?> / <?=gettext('Client Connections') . ": " . ($server['conns'][0]['common_name'] != '[error]' ? sizeof($server['conns']) : '0');?></h2></div>
138
		<div class="panel-body table-responsive">
139
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
140
				<thead>
141
					<tr>
142
						<th><?=gettext("Common Name")?></th>
143
						<th><?=gettext("Real Address")?></th>
144
						<th><?=gettext("Virtual Address"); ?></th>
145
						<th><?=gettext("Last Change"); ?></th>
146
						<th><?=gettext("Bytes Sent")?></th>
147
						<th><?=gettext("Bytes Received")?></th>
148
						<th><?=gettext("Cipher")?></th>
149
						<th><?=gettext("Actions")?></th>
150
					</tr>
151
				</thead>
152
				<tbody>
153

    
154
					<?php
155
							foreach ($server['conns'] as $conn):
156
								$remote_port = substr($conn['remote_host'], strpos($conn['remote_host'], ':') + 1);
157
								$rulesfile = "{$g['tmp_path']}/ovpn_ovpns{$server['vpnid']}_{$conn['user_name']}_{$remote_port}.rules";
158
					?>
159
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
160
						<td>
161
							<?=$conn['common_name'];?>
162
					<?php if (!empty($conn['common_name']) && !empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
163
							<br />
164
					<?php endif; ?>
165
					<?php if (!empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
166
							<?=$conn['user_name'];?>
167
					<?php endif; ?>
168
						</td>
169
						<td><?=$conn['remote_host'];?></td>
170
						<td>
171
							<?=$conn['virtual_addr'];?>
172
					<?php if (!empty($conn['virtual_addr']) && !empty($conn['virtual_addr6'])): ?>
173
							<br />
174
					<?php endif; ?>
175
							<?=$conn['virtual_addr6'];?>
176
						</td>
177
						<td><?=$conn['connect_time'];?></td>
178
						<td data-value="<?=trim($conn['bytes_sent'])?>"><?=format_bytes($conn['bytes_sent']);?></td>
179
						<td data-value="<?=trim($conn['bytes_recv'])?>"><?=format_bytes($conn['bytes_recv']);?></td>
180
						<td data-value="<?=trim($conn['cipher'])?>"><?=$conn['cipher'];?></td>
181
						<td>
182

    
183
					<?php if (file_exists($rulesfile)): ?>
184
							<a
185
							onclick="showRuleContents('<?=$server['vpnid'];?>', '<?=$conn['user_name'];?>', '<?=$remote_port;?>');" style="cursor:pointer;"
186
							   title="<?php echo gettext("Show RADIUS ACL generated ruleset"); ?>">
187
							<i class="fa fa-info"></i>
188
							</a>&nbsp;
189
					<?php endif; ?>
190
							<a
191
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>', '');" style="cursor:pointer;"
192
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
193
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
194
							<i class="fa fa-times"></i>
195
							</a>&nbsp;
196
							<a
197
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>', '<?=$conn['client_id'];?>');" style="cursor:pointer;"
198
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
199
							   title="<?php echo sprintf(gettext("Halt client connection from %s"), $conn['remote_host']); ?>">
200
							<i class="fa fa-times-circle text-danger"></i>
201
							</a>
202
						</td>
203
					</tr>
204
					<?php
205
							endforeach;
206
					?>
207
				</tbody>
208
				<tfoot>
209
					<tr>
210
						<td colspan="7">
211
						</td>
212
						<td colspan="1">
213
							<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
214
							<?= get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
215
							<?= get_service_control_links($ssvc); ?>
216
						</td>
217
					</tr>
218
				</tfoot>
219
			</table>
220
		</div>
221
</div>
222
<?php
223
		if (is_array($server['routes']) && count($server['routes'])):
224
?>
225
<div id="shroutebut-<?= $i ?>">
226
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
227
		<i class="fa fa-plus-circle icon-embed-btn"></i>
228
		<?php echo gettext("Show Routing Table"); ?>
229
	</button>
230
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
231
	<br /><br />
232
</div>
233
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
234
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
235
		<div class="panel-body table-responsive">
236
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
237
				<thead>
238
					<tr>
239
						<th><?=gettext("Common Name"); ?></th>
240
						<th><?=gettext("Real Address"); ?></th>
241
						<th><?=gettext("Target Network"); ?></th>
242
						<th><?=gettext("Last Used"); ?></th>
243
					</tr>
244
				</thead>
245
				<tbody>
246

    
247
<?php
248
			foreach ($server['routes'] as $conn):
249
?>
250
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
251
						<td><?=$conn['common_name'];?></td>
252
						<td><?=$conn['remote_host'];?></td>
253
						<td><?=$conn['virtual_addr'];?></td>
254
						<td><?=$conn['last_time'];?></td>
255
					</tr>
256
<?php
257
			endforeach;
258
?>
259
				</tbody>
260
				<tfoot>
261
					<tr>
262
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
263
					</tr>
264
				</tfoot>
265
			</table>
266
		</div>
267
</div>
268
<?php
269
		endif;
270
?>
271
<br />
272
<?php
273
		$i++;
274
	endforeach;
275
?>
276
<br />
277

    
278
<?php
279
	if (!empty($sk_servers)) {
280
?>
281
<div class="panel panel-default">
282
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
283
		<div class="panel-body table-responsive">
284
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
285
				<thead>
286
					<tr>
287
						<th><?=gettext("Name"); ?></th>
288
						<th><?=gettext("Status"); ?></th>
289
						<th><?=gettext("Last Change"); ?></th>
290
						<th><?=gettext("Virtual Address"); ?></th>
291
						<th><?=gettext("Remote Host"); ?></th>
292
						<th><?=gettext("Bytes Sent"); ?></th>
293
						<th><?=gettext("Bytes Received"); ?></th>
294
						<th><?=gettext("Service"); ?></th>
295
					</tr>
296
				</thead>
297
				<tbody>
298

    
299
<?php
300
		foreach ($sk_servers as $sk_server):
301
?>
302
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
303
						<td>
304
							ovpns<?=$sk_server['vpnid'];?><br/>
305
							<?=htmlspecialchars($sk_server['name']);?>
306
						</td>
307
						<td><?=$sk_server['status'];?></td>
308
						<td><?=$sk_server['connect_time'];?></td>
309
						<td>
310
							<?=$sk_server['virtual_addr'];?>
311
					<?php if (!empty($sk_server['virtual_addr']) && !empty($sk_server['virtual_addr6'])): ?>
312
							<br />
313
					<?php endif; ?>
314
							<?=$sk_server['virtual_addr6'];?>
315
						</td>
316
						<td><?=$sk_server['remote_host'];?></td>
317
						<td data-value="<?=trim($sk_server['bytes_sent'])?>"><?=format_bytes($sk_server['bytes_sent']);?></td>
318
						<td data-value="<?=trim($sk_server['bytes_recv'])?>"><?=format_bytes($sk_server['bytes_recv']);?></td>
319
						<td>
320
							<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
321
							<?= get_service_status_icon($ssvc, false, true); ?>
322
							<?= get_service_control_links($ssvc, true); ?>
323
						</td>
324
					</tr>
325
<?php
326
		endforeach;
327
?>
328
				</tbody>
329
			</table>
330
		</div>
331
</div>
332

    
333
<?php
334
	}
335
?>
336
<br />
337
<?php
338
	if (!empty($clients)) {
339
?>
340
<div class="panel panel-default">
341
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
342
		<div class="panel-body table-responsive">
343
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
344
				<thead>
345
					<tr>
346
						<th><?=gettext("Name"); ?></th>
347
						<th><?=gettext("Status"); ?></th>
348
						<th><?=gettext("Last Change"); ?></th>
349
						<th><?=gettext("Local Address"); ?></th>
350
						<th><?=gettext("Virtual Address"); ?></th>
351
						<th><?=gettext("Remote Host"); ?></th>
352
						<th><?=gettext("Bytes Sent"); ?></th>
353
						<th><?=gettext("Bytes Received"); ?></th>
354
						<th><?=gettext("Service"); ?></th>
355
					</tr>
356
				</thead>
357
				<tbody>
358

    
359
<?php
360
		foreach ($clients as $client):
361
?>
362
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
363
						<td>
364
							ovpnc<?= $client['vpnid'] ?><br/>
365
							<?=htmlspecialchars($client['name']);?>
366
						</td>
367
						<td><?=$client['status'];?></td>
368
						<td><?=$client['connect_time'];?></td>
369
						<td>
370
					<?php if (empty($client['local_host']) && empty($client['local_port'])): ?>
371
							(pending)
372
					<?php else: ?>
373
							<?=$client['local_host'];?>:<?=$client['local_port'];?>
374
					<?php endif; ?>
375
						</td>
376
						<td>
377
							<?=$client['virtual_addr'];?>
378
					<?php if (!empty($client['virtual_addr']) && !empty($client['virtual_addr6'])): ?>
379
							<br />
380
					<?php endif; ?>
381
							<?=$client['virtual_addr6'];?>
382
						</td>
383
						<td>
384
					<?php if (empty($client['remote_host']) && empty($client['remote_port'])): ?>
385
							(pending)
386
					<?php else: ?>
387
							<?=$client['remote_host'];?>:<?=$client['remote_port'];?>
388
					<?php endif; ?>
389
						</td>
390
						<td data-value="<?=trim($client['bytes_sent'])?>"><?=format_bytes($client['bytes_sent']);?></td>
391
						<td data-value="<?=trim($client['bytes_recv'])?>"><?=format_bytes($client['bytes_recv']);?></td>
392
						<td>
393
							<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
394
							<?= get_service_status_icon($ssvc, false, true); ?>
395
							<?= get_service_control_links($ssvc, true); ?>
396
						</td>
397
					</tr>
398
<?php
399
		endforeach;
400
?>
401
				</tbody>
402
			</table>
403
		</div>
404
	</div>
405

    
406
<?php
407
}
408

    
409
if ($DisplayNote) {
410
 	print_info_box(gettext("If there are custom options that override the management features of OpenVPN on a client or server, they will cause that OpenVPN instance to not work correctly with this status page."));
411
}
412

    
413
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
414
	print_info_box(gettext("No OpenVPN instances defined."));
415
}
416

    
417
// Create a Modal object to display RADIUS ACL generated ruleset
418
$form = new Form(FALSE);
419
$modal = new Modal('RADIUS ACL Generated Ruleset', 'rulesviewer', 'large', 'Close');
420
$modal->addInput(new Form_Textarea (
421
	'rulesviewer_text',
422
	null,
423
	'...Loading...'
424
))->removeClass('form-control')->addClass('row-fluid col-sm-11')->setAttribute('rows', '10')->setAttribute('wrap', 'soft');
425
$form->add($modal);
426
print($form);
427
?>
428
</form>
429

    
430
<script type="text/javascript">
431
//<![CDATA[
432

    
433
function show_routes(id, buttonid) {
434
	document.getElementById(buttonid).innerHTML='';
435
	aodiv = document.getElementById(id);
436
	aodiv.style.display = "block";
437
}
438

    
439
//]]>
440
</script>
441

    
442
<?php include("foot.inc"); ?>
(178-178/228)